]> err.no Git - varnish/commitdiff
Add support for investigating random HTTP headers.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 18 Jun 2006 10:02:35 +0000 (10:02 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 18 Jun 2006 10:02:35 +0000 (10:02 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@199 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/include/vcl_lang.h
varnish-cache/lib/libvcl/vcl_compile.c
varnish-cache/lib/libvcl/vcl_fixed_token.c

index 31d995cae1fc57e049b0aad383e4ec2503a6f40a..5242ce7e2b5b73dc84de1a2ad8ef872fbe83129f 100644 (file)
@@ -100,6 +100,8 @@ int VCL_rewrite(const char *, const char *);
 void VCL_error(VCL_FARGS, unsigned, const char *);
 int VCL_switch_config(const char *);
 
+char *VCL_GetHdr(VCL_FARGS, const char *);
+
 typedef void vcl_init_f(void);
 typedef void vcl_func_f(VCL_FARGS);
 
index c538dea08e33ba1fc96288772d12176102268aae..febd4e4a8e3094c8b43bee3ea6a37cd402984b00 100644 (file)
@@ -89,7 +89,8 @@ enum var_type {
        STRING,
        IP,
        HOSTNAME,
-       PORTNAME
+       PORTNAME,
+       HEADER
 };
 
 struct var {
@@ -124,6 +125,7 @@ static struct var vars[] = {
        { "req.request",                STRING,   0,  "\"GET\""      },
        { "obj.valid",                  BOOL,     0,  "sess->obj->valid"     },
        { "obj.cacheable",              BOOL,     0,  "sess->obj->cacheable" },
+       { "req.http.",                  HEADER,   0,  NULL },
 #if 0
        { "req.ttlfactor",              FLOAT, 0,   "req->ttlfactor" },
        { "req.url.host",               STRING, 0,  "req->url.host" },
@@ -549,6 +551,28 @@ IpVal(struct tokenlist *tl)
        return (0);
 }
 
+/*--------------------------------------------------------------------*/
+static struct var *
+HeaderVar(struct tokenlist *tl, struct token *t, struct var *vh)
+{
+       char *p;
+       struct var *v;
+       int i;
+
+       v = calloc(sizeof *v, 1);
+       i = t->e - t->b;
+       p = malloc(i + 1);
+       assert(p != NULL);
+       memcpy(p, t->b, i);
+       p[i] = '\0';
+       v->name = p;
+       v->fmt = STRING;
+       asprintf(&p, "VCL_GetHdr(VCL_PASS_ARGS, \"%s\")", v->name + vh->len);
+       assert(p != NULL);
+       v->cname = p;
+       return (v);
+}
+
 /*--------------------------------------------------------------------*/
 
 static struct var *
@@ -557,10 +581,15 @@ FindVar(struct tokenlist *tl, struct token *t, struct var *vl)
        struct var *v;
 
        for (v = vl; v->name != NULL; v++) {
-               if (t->e - t->b != v->len)
+               if (v->fmt == HEADER  && t->e - t->b <= v->len)
+                       continue;
+               if (v->fmt != HEADER  && t->e - t->b != v->len)
                        continue;
-               if (!memcmp(t->b, v->name, v->len))
+               if (memcmp(t->b, v->name, v->len))
+                       continue;
+               if (v->fmt != HEADER)
                        return (v);
+               return (HeaderVar(tl, t, v));
        }
        sbuf_printf(tl->sb, "Unknown variable ");
        ErrToken(tl, t);
@@ -651,7 +680,6 @@ static void
 Cond_String(struct var *vp, struct tokenlist *tl)
 {
 
-       (void)vp;
        switch (tl->t->tok) {
        case '~':
                I(tl); sbuf_printf(tl->fc, "string_match(%s, ", vp->cname);
@@ -662,8 +690,11 @@ Cond_String(struct var *vp, struct tokenlist *tl)
                        tl->t->e - tl->t->b, tl->t->b);
                NextToken(tl);
                break;
+       case T_EQ:
        case T_NEQ:
-               I(tl); sbuf_printf(tl->fc, "strcmp(%s, ", vp->cname);
+               I(tl);
+               sbuf_printf(tl->fc, "%sstrcmp(%s, ",
+                   tl->t->tok == T_EQ ? "" : "!", vp->cname);
                NextToken(tl);
                ExpectErr(tl, CSTR);
                sbuf_printf(tl->fc, "%*.*s)\n",
@@ -672,11 +703,7 @@ Cond_String(struct var *vp, struct tokenlist *tl)
                NextToken(tl);
                break;
        default:
-               sbuf_printf(tl->sb, "Illegal condition ");
-               ErrToken(tl, tl->t);
-               sbuf_printf(tl->sb, " on string variable\n");
-               sbuf_printf(tl->sb, "  only '~' is legal\n");
-               ErrWhere(tl, tl->t);
+               I(tl); sbuf_printf(tl->fc, "%s != (void*)0", vp->cname);
                break;
        }
 }
index 520fb0e39e70522f9043f57350879a0dca080b68..e677105cc90aba0ba0fb56dfd05417710ed4212f 100644 (file)
@@ -499,6 +499,8 @@ vcl_output_lang_h(FILE *f)
        fputs("void VCL_error(VCL_FARGS, unsigned, const char *);\n", f);
        fputs("int VCL_switch_config(const char *);\n", f);
        fputs("\n", f);
+       fputs("char *VCL_GetHdr(VCL_FARGS, const char *);\n", f);
+       fputs("\n", f);
        fputs("typedef void vcl_init_f(void);\n", f);
        fputs("typedef void vcl_func_f(VCL_FARGS);\n", f);
        fputs("\n", f);