summaryrefslogtreecommitdiff
path: root/src/libtipidee
diff options
context:
space:
mode:
Diffstat (limited to 'src/libtipidee')
-rw-r--r--src/libtipidee/deps-lib/tipidee9
-rw-r--r--src/libtipidee/tipidee_log_answer.c24
-rw-r--r--src/libtipidee/tipidee_log_exit.c14
-rw-r--r--src/libtipidee/tipidee_log_request.c60
-rw-r--r--src/libtipidee/tipidee_log_resource.c11
-rw-r--r--src/libtipidee/tipidee_log_start.c25
-rw-r--r--src/libtipidee/tipidee_method.c46
-rw-r--r--src/libtipidee/tipidee_method_conv_table.c19
-rw-r--r--src/libtipidee/tipidee_method_tonum.c12
-rw-r--r--src/libtipidee/tipidee_method_tostr.c8
10 files changed, 186 insertions, 42 deletions
diff --git a/src/libtipidee/deps-lib/tipidee b/src/libtipidee/deps-lib/tipidee
index b7f88cc..cba7e43 100644
--- a/src/libtipidee/deps-lib/tipidee
+++ b/src/libtipidee/deps-lib/tipidee
@@ -10,9 +10,12 @@ tipidee_headers_get_content_length.o
tipidee_headers_init.o
tipidee_headers_parse.o
tipidee_headers_search.o
-tipidee_method_conv_table.o
-tipidee_method_tonum.o
-tipidee_method_tostr.o
+tipidee_log_answer.o
+tipidee_log_exit.o
+tipidee_log_resource.o
+tipidee_log_request.o
+tipidee_log_start.o
+tipidee_method.o
tipidee_response_error.o
tipidee_response_header_builtin.o
tipidee_response_header_common_put.o
diff --git a/src/libtipidee/tipidee_log_answer.c b/src/libtipidee/tipidee_log_answer.c
new file mode 100644
index 0000000..beedb61
--- /dev/null
+++ b/src/libtipidee/tipidee_log_answer.c
@@ -0,0 +1,24 @@
+/* ISC license. */
+
+#include <sys/types.h>
+
+#include <skalibs/uint64.h>
+#include <skalibs/types.h>
+#include <skalibs/strerr.h>
+
+#include <tipidee/log.h>
+
+void tipidee_log_answer (uint32_t v, unsigned int status, off_t size)
+{
+ char fmtstatus[UINT_FMT] ;
+ if (!(v & TIPIDEE_LOG_ANSWER)) return ;
+ fmtstatus[uint_fmt(fmtstatus, status)] = 0 ;
+ if (size)
+ {
+ char fmtsize[UINT64_FMT] ;
+ fmtsize[uint64_fmt(fmtsize, size)] = 0 ;
+ strerr_warni4x("answer ", fmtstatus, " size ", fmtsize) ;
+ }
+ else
+ strerr_warni2x("answer ", fmtstatus) ;
+}
diff --git a/src/libtipidee/tipidee_log_exit.c b/src/libtipidee/tipidee_log_exit.c
new file mode 100644
index 0000000..7d7b3e0
--- /dev/null
+++ b/src/libtipidee/tipidee_log_exit.c
@@ -0,0 +1,14 @@
+/* ISC license. */
+
+#include <skalibs/types.h>
+#include <skalibs/strerr.h>
+
+#include <tipidee/log.h>
+
+void tipidee_log_exit (uint32_t v, unsigned int e)
+{
+ char fmt[UINT_FMT] ;
+ if (!(v & TIPIDEE_LOG_START)) return ;
+ fmt[uint_fmt(fmt, e)] = 0 ;
+ strerr_warni2x("exit ", fmt) ;
+}
diff --git a/src/libtipidee/tipidee_log_request.c b/src/libtipidee/tipidee_log_request.c
new file mode 100644
index 0000000..666297d
--- /dev/null
+++ b/src/libtipidee/tipidee_log_request.c
@@ -0,0 +1,60 @@
+/* ISC license. */
+
+#include <stddef.h>
+
+#include <skalibs/strerr.h>
+#include <skalibs/stralloc.h>
+#include <skalibs/skamisc.h>
+
+#include <tipidee/method.h>
+#include <tipidee/log.h>
+
+void tipidee_log_request (uint32_t v, tipidee_rql const *rql, char const *referrer, char const *ua, stralloc *sa)
+{
+ char const *a[14] = { "info: request " } ;
+ size_t m = 1 ;
+ size_t start = sa->len ;
+ size_t refpos = start, uapos = start ;
+ if (!(v & TIPIDEE_LOG_REQUEST)) return ;
+ if (!string_quotes(sa, rql->uri.path)) goto eerr ;
+ if (v & TIPIDEE_LOG_REFERRER)
+ {
+ refpos = sa->len ;
+ if (!string_quotes(sa, referrer) || !stralloc_0(sa)) goto err ;
+ }
+ if (v & TIPIDEE_LOG_UA)
+ {
+ uapos = sa->len ;
+ if (!string_quotes(sa, ua) || !stralloc_0(sa)) goto err ;
+ }
+ a[m++] = tipidee_method_tostr(rql->m) ;
+ a[m++] = " host " ;
+ a[m++] = rql->uri.host ;
+ a[m++] = " path " ;
+ a[m++] = sa->s + start ;
+ if (rql->uri.query)
+ {
+ a[m++] = " query " ;
+ a[m++] = rql->uri.query ;
+ }
+ a[m++] = " http 1." ;
+ a[m++] = rql->http_minor ? "1" : "0" ;
+ if (v & TIPIDEE_LOG_REFERRER)
+ {
+ a[m++] = " referrer " ;
+ a[m++] = sa->s + refpos ;
+ }
+ if (v & TIPIDEE_LOG_UA)
+ {
+ a[m++] = " user-agent " ;
+ a[m++] = sa->s + uapos ;
+ }
+ strerr_warnv(a, m) ;
+ sa->len = start ;
+ return ;
+
+ err:
+ sa->len = start ;
+ eerr:
+ strerr_warnwu1sys("log request") ;
+}
diff --git a/src/libtipidee/tipidee_log_resource.c b/src/libtipidee/tipidee_log_resource.c
new file mode 100644
index 0000000..dc525a5
--- /dev/null
+++ b/src/libtipidee/tipidee_log_resource.c
@@ -0,0 +1,11 @@
+/* ISC license. */
+
+#include <skalibs/strerr.h>
+
+#include <tipidee/log.h>
+
+void tipidee_log_resource (uint32_t v, char const *docroot, char const *file, tipidee_resattr const *ra)
+{
+ if (!(v & TIPIDEE_LOG_RESOURCE)) return ;
+ strerr_warni6x("docroot ", docroot, " file ", file, " type ", ra->iscgi ? ra->isnph ? "nph" : "cgi" : ra->content_type) ;
+}
diff --git a/src/libtipidee/tipidee_log_start.c b/src/libtipidee/tipidee_log_start.c
new file mode 100644
index 0000000..34284af
--- /dev/null
+++ b/src/libtipidee/tipidee_log_start.c
@@ -0,0 +1,25 @@
+/* ISC license. */
+
+#include <stddef.h>
+
+#include <skalibs/strerr.h>
+
+#include <tipidee/log.h>
+
+void tipidee_log_start (uint32_t v, char const *ip, char const *host)
+{
+ char const *a[5] = { "info: start" } ;
+ size_t m = 1 ;
+ if (!(v & TIPIDEE_LOG_START)) return ;
+ if (v & TIPIDEE_LOG_CLIENTIP)
+ {
+ a[m++] = " ip " ;
+ a[m++] = ip ;
+ }
+ if (v & TIPIDEE_LOG_CLIENTHOST)
+ {
+ a[m++] = " host " ;
+ a[m++] = host ;
+ }
+ strerr_warnv(a, m) ;
+}
diff --git a/src/libtipidee/tipidee_method.c b/src/libtipidee/tipidee_method.c
new file mode 100644
index 0000000..c5e7195
--- /dev/null
+++ b/src/libtipidee/tipidee_method.c
@@ -0,0 +1,46 @@
+/* ISC license. */
+
+#include <string.h>
+#include <stdlib.h>
+
+#include <tipidee/method.h>
+
+struct blah_s
+{
+ tipidee_method num ;
+ char const *str ;
+} ;
+
+static struct blah_s const table[] =
+{
+ { .num = TIPIDEE_METHOD_CONNECT, .str = "CONNECT" },
+ { .num = TIPIDEE_METHOD_DELETE, .str = "DELETE" },
+ { .num = TIPIDEE_METHOD_GET, .str = "GET" },
+ { .num = TIPIDEE_METHOD_HEAD, .str = "HEAD" },
+ { .num = TIPIDEE_METHOD_OPTIONS, .str = "OPTIONS" },
+ { .num = TIPIDEE_METHOD_POST, .str = "POST" },
+ { .num = TIPIDEE_METHOD_PRI, .str = "PRI" },
+ { .num = TIPIDEE_METHOD_PUT, .str = "PUT" },
+ { .num = TIPIDEE_METHOD_TRACE, .str = "TRACE" },
+} ;
+
+static int blah_cmp (void const *key, void const *el)
+{
+ return strcmp((char const *)key, ((struct blah_s const *)el)->str) ;
+}
+
+tipidee_method tipidee_method_tonum (char const *s)
+{
+ struct blah_s const *p = bsearch(
+ s,
+ table,
+ sizeof(table) / sizeof(struct blah_s),
+ sizeof(struct blah_s),
+ &blah_cmp) ;
+ return p ? p->num : TIPIDEE_METHOD_UNKNOWN ;
+}
+
+char const *tipidee_method_tostr (tipidee_method m)
+{
+ return m < TIPIDEE_METHOD_UNKNOWN ? table[m].str : 0 ;
+}
diff --git a/src/libtipidee/tipidee_method_conv_table.c b/src/libtipidee/tipidee_method_conv_table.c
deleted file mode 100644
index 892e5b5..0000000
--- a/src/libtipidee/tipidee_method_conv_table.c
+++ /dev/null
@@ -1,19 +0,0 @@
-/* ISC license. */
-
-#include <tipidee/method.h>
-
-static tipidee_method_conv const table[] =
-{
- { .num = TIPIDEE_METHOD_GET, .str = "GET" },
- { .num = TIPIDEE_METHOD_HEAD, .str = "HEAD" },
- { .num = TIPIDEE_METHOD_OPTIONS, .str = "OPTIONS" },
- { .num = TIPIDEE_METHOD_POST, .str = "POST" },
- { .num = TIPIDEE_METHOD_PUT, .str = "PUT" },
- { .num = TIPIDEE_METHOD_DELETE, .str = "DELETE" },
- { .num = TIPIDEE_METHOD_TRACE, .str = "TRACE" },
- { .num = TIPIDEE_METHOD_CONNECT, .str = "CONNECT" },
- { .num = TIPIDEE_METHOD_PRI, .str = "PRI" },
- { .num = TIPIDEE_METHOD_UNKNOWN, .str = 0 }
-} ;
-
-tipidee_method_conv const *tipidee_method_conv_table = table ;
diff --git a/src/libtipidee/tipidee_method_tonum.c b/src/libtipidee/tipidee_method_tonum.c
deleted file mode 100644
index 7c88e45..0000000
--- a/src/libtipidee/tipidee_method_tonum.c
+++ /dev/null
@@ -1,12 +0,0 @@
-/* ISC license. */
-
-#include <string.h>
-
-#include <tipidee/method.h>
-
-tipidee_method tipidee_method_tonum (char const *s)
-{
- tipidee_method_conv const *p = tipidee_method_conv_table ;
- for (; p->str ; p++) if (!strcmp(s, p->str)) break ;
- return p->num ;
-}
diff --git a/src/libtipidee/tipidee_method_tostr.c b/src/libtipidee/tipidee_method_tostr.c
deleted file mode 100644
index 8a3831d..0000000
--- a/src/libtipidee/tipidee_method_tostr.c
+++ /dev/null
@@ -1,8 +0,0 @@
-/* ISC license. */
-
-#include <tipidee/method.h>
-
-char const *tipidee_method_tostr (tipidee_method m)
-{
- return m < TIPIDEE_METHOD_UNKNOWN ? tipidee_method_conv_table[m].str : 0 ;
-}