src/server/safs/addlog.c

changeset 196
0459c94a60ed
parent 77
f1cff81e425a
child 415
d938228c382e
equal deleted inserted replaced
195:d367b687bc74 196:0459c94a60ed
32 #include "addlog.h" 32 #include "addlog.h"
33 33
34 #include "../daemon/request.h" 34 #include "../daemon/request.h"
35 #include "../daemon/vserver.h" 35 #include "../daemon/vserver.h"
36 #include "../daemon/log.h" 36 #include "../daemon/log.h"
37 #include "../util/util.h"
37 38
38 int common_log(pblock *pb, Session *sn, Request *rq) { 39 int common_log(pblock *pb, Session *sn, Request *rq) {
39 NSAPIRequest *request = (NSAPIRequest*)rq; 40 NSAPIRequest *request = (NSAPIRequest*)rq;
40 VirtualServer *vs = request->vs; 41 VirtualServer *vs = request->vs;
41 AccessLog *log = vs->log; 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 }
42 49
43 if(log == NULL) { 50 if(log == NULL) {
44 return REQ_NOACTION; 51 return REQ_NOACTION;
45 } 52 }
46 53
69 if(tmstr.ptr[tmstr.length-1] == '\n') { 76 if(tmstr.ptr[tmstr.length-1] == '\n') {
70 tmstr.length--; 77 tmstr.length--;
71 } 78 }
72 tmstr = sstrdup_pool(sn->pool, tmstr); 79 tmstr = sstrdup_pool(sn->pool, tmstr);
73 80
74 fprintf( 81 if(combined) {
75 log->log->file, 82 char *referer = pblock_findval("referer", rq->headers);
76 "%s - %s [%s] \"%s\" %d %s\n", 83 char *user_agent = pblock_findval("user-agent", rq->headers);
77 ip, 84 int refq = 1;
78 user, 85 int uaq = 1;
79 tmstr.ptr, 86 if(!referer) {
80 req, 87 referer = "-";
81 rq->status_num, 88 refq = 0;
82 len); 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 }
83 fflush(log->log->file); 125 fflush(log->log->file);
84 126
85 127
86 return REQ_PROCEED; 128 return REQ_PROCEED;
87 } 129 }

mercurial