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 #include <stdio.h>
30 #include <stdlib.h>
31
32 #include "addlog.h"
33
34 #include "../daemon/request.h"
35 #include "../daemon/vserver.h"
36 #include "../daemon/log.h"
37 #include "../util/util.h"
38
39 int common_log(pblock *pb, Session *sn, Request *rq) {
40 NSAPIRequest *request = (NSAPIRequest*)rq;
41 VirtualServer *vs = request->vs;
42 AccessLog *log = vs->log;
43
44 char *combined_str = pblock_findval(
"combined", pb);
45 WSBool combined =
FALSE;
46 if(combined_str) {
47 combined = util_getboolean(combined_str,
FALSE);
48 }
49
50 if(log ==
NULL) {
51 return REQ_NOACTION;
52 }
53
54 char *ip = pblock_findval(
"ip", sn->client);
55 char *user = pblock_findval(
"auth-user", rq->vars);
56 time_t t = time(
NULL);
57 char *time = ctime(&t);
58 char *req = pblock_findval(
"clf-request", rq->reqpb);
59
60
61
62 char *len = pblock_findval(
"Content-length", rq->srvhdrs);
63
64 if(!ip) {
65 ip =
"-";
66 }
67 if(!user) {
68 user =
"-";
69 }
70 if(!len) {
71 len =
"0";
72 }
73
74
75 sstr_t tmstr = sstr(time);
76 if(tmstr.ptr[tmstr.length-
1] ==
'\n') {
77 tmstr.length--;
78 }
79 tmstr = sstrdup_pool(sn->pool, tmstr);
80
81 if(combined) {
82 char *referer = pblock_findval(
"referer", rq->headers);
83 char *user_agent = pblock_findval(
"user-agent", rq->headers);
84 int refq =
1;
85 int uaq =
1;
86 if(!referer) {
87 referer =
"-";
88 refq =
0;
89 }
90 if(!user_agent) {
91 user_agent =
"-";
92 uaq =
0;
93 }
94 fprintf(
95 log->log->file,
96 "%s - %s [%s] \"%s\" %d %s %.*s%s%.*s %.*s%s%.*s\n",
97 ip,
98 user,
99 tmstr.ptr,
100 req,
101 rq->status_num,
102 len,
103 refq,
104 "\"",
105 referer,
106 refq,
107 "\"",
108 uaq,
109 "\"",
110 user_agent,
111 uaq,
112 "\""
113 );
114 }
else {
115 fprintf(
116 log->log->file,
117 "%s - %s [%s] \"%s\" %d %s\n",
118 ip,
119 user,
120 tmstr.ptr,
121 req,
122 rq->status_num,
123 len);
124 }
125 fflush(log->log->file);
126
127
128 return REQ_PROCEED;
129 }
130
131