]> err.no Git - varnish/commitdiff
Start working on format fix varnishncsa_format
authorTollef Fog Heen <tfheen@err.no>
Mon, 5 Jan 2009 10:41:10 +0000 (11:41 +0100)
committerTollef Fog Heen <tfheen@err.no>
Mon, 5 Jan 2009 10:41:18 +0000 (10:41 +0000)
varnish-cache/bin/varnishncsa/varnishncsa.c

index 7cf88a55df645e2501b8eec1e5fd963d82cc3b62..7d0622c3a81450cbe94b747ce16912aa47a2eecc 100644 (file)
 
 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);