#include <stdio.h>
#include <stdlib.h>
#include "addlog.h"
#include "../daemon/request.h"
#include "../daemon/vserver.h"
#include "../daemon/log.h"
#include "../util/util.h"
int common_log(pblock *pb, Session *sn, Request *rq) {
NSAPIRequest *request = (NSAPIRequest*)rq;
VirtualServer *vs = request->vs;
AccessLog *log = vs->log;
char *combined_str = pblock_findval(
"combined", pb);
WSBool combined =
FALSE;
if(combined_str) {
combined = util_getboolean(combined_str,
FALSE);
}
if(log ==
NULL) {
return REQ_NOACTION;
}
char *ip = pblock_findval(
"ip", sn->client);
char *user = pblock_findval(
"auth-user", rq->vars);
time_t t = time(
NULL);
char *time = ctime(&t);
char *req = pblock_findval(
"clf-request", rq->reqpb);
char *len = pblock_findval(
"Content-length", rq->srvhdrs);
if(!ip) {
ip =
"-";
}
if(!user) {
user =
"-";
}
if(!len) {
len =
"0";
}
cxstring tmstr = cx_str(time);
if(tmstr.ptr[tmstr.length-
1] ==
'\n') {
tmstr.length--;
}
if(combined) {
char *referer = pblock_findval(
"referer", rq->headers);
char *user_agent = pblock_findval(
"user-agent", rq->headers);
int refq =
1;
int uaq =
1;
if(!referer) {
referer =
"-";
refq =
0;
}
if(!user_agent) {
user_agent =
"-";
uaq =
0;
}
fprintf(
log->log->file,
"%s - %s [%.*s] \"%s\" %d %s %.*s%s%.*s %.*s%s%.*s\n",
ip,
user,
(
int)tmstr.length,
tmstr.ptr,
req,
rq->status_num,
len,
refq,
"\"",
referer,
refq,
"\"",
uaq,
"\"",
user_agent,
uaq,
"\""
);
}
else {
fprintf(
log->log->file,
"%s - %s [%.*s] \"%s\" %d %s\n",
ip,
user,
(
int)tmstr.length,
tmstr.ptr,
req,
rq->status_num,
len);
}
fflush(log->log->file);
return REQ_PROCEED;
}