aboutsummaryrefslogtreecommitdiffstats
path: root/src/libtipidee/tipidee_response_error_nofile.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-10-18 13:07:23 +0000
committerLaurent Bercot <ska@appnovation.com>2023-10-18 13:07:23 +0000
commit1a7e3d00588725da3d8764fa9d624bc8611be070 (patch)
tree65d28b52bd1d4ccdbeb418d4d681b1999ed46b7a /src/libtipidee/tipidee_response_error_nofile.c
parent24fb88dbb023ae08adc9989bf19e0c6c569a6607 (diff)
downloadtipidee-1a7e3d00588725da3d8764fa9d624bc8611be070.tar.gz
Add infrastructure for custom error files
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libtipidee/tipidee_response_error_nofile.c')
-rw-r--r--src/libtipidee/tipidee_response_error_nofile.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/libtipidee/tipidee_response_error_nofile.c b/src/libtipidee/tipidee_response_error_nofile.c
new file mode 100644
index 0000000..4f628ac
--- /dev/null
+++ b/src/libtipidee/tipidee_response_error_nofile.c
@@ -0,0 +1,35 @@
+/* ISC license. */
+
+#include <string.h>
+
+#include <skalibs/types.h>
+#include <skalibs/buffer.h>
+
+#include <tipidee/method.h>
+#include <tipidee/response.h>
+
+size_t tipidee_response_error_nofile (buffer *b, tipidee_rql const *rql, unsigned int status, char const *reason, char const *text, uint32_t options, tain const *stamp)
+{
+ static char const txt1[] = "<html>\n<head><title>" ;
+ static char const txt2[] = "</title></head>\n<body>\n<h1> " ;
+ static char const txt3[] = " </h1>\n<p>\n" ;
+ static char const txt4[] = "\n</p>\n</body>\n</html>\n" ;
+ char fmt[SIZE_FMT] ;
+ size_t n = tipidee_response_status(b, rql, status, reason) ;
+ n += tipidee_response_header_common_put(b, options, stamp) ;
+ n += buffer_putsnoflush(b, "Content-Type: text/html; charset=UTF-8\r\n") ;
+ n += buffer_putsnoflush(b, "Content-Length: ") ;
+ n += buffer_putnoflush(b, fmt, size_fmt(fmt, text ? sizeof(txt1) + sizeof(txt2) + sizeof(txt3) + sizeof(txt4) - 4 + 2 * strlen(reason) + strlen(text) : 0)) ;
+ n += buffer_putnoflush(b, "\r\n\r\n", 4) ;
+ if (text && rql->m != TIPIDEE_METHOD_HEAD)
+ {
+ n += buffer_putsnoflush(b, txt1) ;
+ n += buffer_putsnoflush(b, reason) ;
+ n += buffer_putsnoflush(b, txt2) ;
+ n += buffer_putsnoflush(b, reason) ;
+ n += buffer_putsnoflush(b, txt3) ;
+ n += buffer_putsnoflush(b, text) ;
+ n += buffer_putsnoflush(b, txt4) ;
+ }
+ return n ;
+}