blob: d633f0b5e8761e67183eb3f658e8dba589e6942a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
/* ISC license. */
#include <stddef.h>
#include <skalibs/strerr.h>
#include <skalibs/stralloc.h>
#include <skalibs/skamisc.h>
#include <tipidee/method.h>
#include <tipidee/headers.h>
#include <tipidee/log.h>
void tipidee_log_request (uint32_t v, tipidee_rql const *rql, tipidee_headers const *hdr, stralloc *sa)
{
char const *a[16] = { PROG, ": info:" } ;
size_t m = 2 ;
size_t start = sa->len ; /* assert: not zero */
size_t refpos = 0, uapos = 0 ;
if (!(v & TIPIDEE_LOG_REQUEST)) return ;
if (!string_quotes(sa, rql->uri.path) || !stralloc_0(sa)) goto eerr ;
if (v & TIPIDEE_LOG_REFERRER)
{
char const *x = tipidee_headers_search(hdr, "Referrer") ;
if (x)
{
refpos = sa->len ;
if (!string_quotes(sa, x) || !stralloc_0(sa)) goto err ;
}
}
if (v & TIPIDEE_LOG_UA)
{
char const *x = tipidee_headers_search(hdr, "User-Agent") ;
if (x)
{
uapos = sa->len ;
if (!string_quotes(sa, x) || !stralloc_0(sa)) goto err ;
}
}
if (v & TIPIDEE_LOG_HOSTASPREFIX)
{
a[m++] = " host " ;
a[m++] = rql->uri.host ;
}
a[m++] = " request " ;
a[m++] = tipidee_method_tostr(rql->m) ;
if (!(v & TIPIDEE_LOG_HOSTASPREFIX))
{
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 (refpos)
{
a[m++] = " referrer " ;
a[m++] = sa->s + refpos ;
}
if (uapos)
{
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") ;
}
|