diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-10-10 08:06:46 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-10-10 08:06:46 +0000 |
commit | 541325d00c7078d063ea97333d3c9c64d6b6c7b6 (patch) | |
tree | 86453b9f547359546d74988b04ab33ec10b4000c /src/libtipidee/tipidee_log_request.c | |
parent | d9f5cb7a28ee79e299e41d3ce325171f01e1a3d7 (diff) | |
download | tipidee-541325d00c7078d063ea97333d3c9c64d6b6c7b6.tar.xz |
Add new logging functions, change method_conv for bsearch
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libtipidee/tipidee_log_request.c')
-rw-r--r-- | src/libtipidee/tipidee_log_request.c | 60 |
1 files changed, 60 insertions, 0 deletions
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") ; +} |