From: Tollef Fog Heen Date: Mon, 5 Jan 2009 10:41:10 +0000 (+0100) Subject: Start working on format fix X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fvarnishncsa_format;p=varnish Start working on format fix --- diff --git a/varnish-cache/bin/varnishncsa/varnishncsa.c b/varnish-cache/bin/varnishncsa/varnishncsa.c index 7cf88a55..7d0622c3 100644 --- a/varnish-cache/bin/varnishncsa/varnishncsa.c +++ b/varnish-cache/bin/varnishncsa/varnishncsa.c @@ -84,6 +84,12 @@ static volatile sig_atomic_t reopen; +static struct matcher { + enum shmlogtag tag; + char *fieldname; + char *format; +} *matchers; + static struct logline { char *df_H; /* %H, Protocol version */ char *df_Host; /* %{Host}i */ @@ -507,6 +513,41 @@ open_log(const char *ofn, int append) /*--------------------------------------------------------------------*/ +static int +parse_format(char *format, struct matchers **m) { + char *t = format; + struct matcher *tmp; + int num_matchers = 0; + while (*t != NULL) { + tmp = malloc(sizeof struct struct matcher); + num_matchers++; + if (t[0] == '%') { + t++; + switch (*t) { + case 'h': + tmp->tag = SLT_ReqStart; + break; + case 'H': + tmp->tag = SLT_RxProtocol; + break; + default: + /* XXX Error out */ + break; + } + } else { + char *end = strchr(t, '%'); + int i; + if (end == NULL) + end = t + strlen(t); + i = asprintf(&tmp->format, "%*s", (end - t), t); + assert(i > 0); + t += i; + } + } + m = malloc(sizeof tmp * num_matchers); +} +/*--------------------------------------------------------------------*/ + static void usage(void) { @@ -528,7 +569,8 @@ main(int argc, char *argv[]) struct pidfh *pfh = NULL; struct VSL_data *vd; FILE *of; - + char *format = "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""; + vd = VSL_New(); while ((c = getopt(argc, argv, VSL_ARGS "aDn:P:Vw:f")) != -1) { @@ -561,6 +603,9 @@ main(int argc, char *argv[]) } } + if (parse_format(format, &matchers)) + exit(1); + if (VSL_OpenLog(vd, n_arg)) exit(1);