]> err.no Git - varnish/commitdiff
Move variable related stuff to vcc_var.c
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 25 Jun 2007 08:57:09 +0000 (08:57 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 25 Jun 2007 08:57:09 +0000 (08:57 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1553 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/lib/libvcl/Makefile.am
varnish-cache/lib/libvcl/vcc_action.c
varnish-cache/lib/libvcl/vcc_backend.c
varnish-cache/lib/libvcl/vcc_compile.c
varnish-cache/lib/libvcl/vcc_compile.h
varnish-cache/lib/libvcl/vcc_parse.c
varnish-cache/lib/libvcl/vcc_var.c [new file with mode: 0644]

index ecf716986e24b3799d818e6237ee1eef3d1fe42d..9a8a4d7ab37bdb444a9f4cf4b712ae164c36fd37 100644 (file)
@@ -17,6 +17,7 @@ libvcl_la_SOURCES = \
        vcc_fixed_token.c \
        vcc_obj.c \
        vcc_token.c \
+       vcc_var.c \
        vcc_xref.c
 
 libvcl_la_CFLAGS = -include config.h
index 3ef3f74e389e1a97ce0863687b04858fcd876ef0..2b5db2cc5e739a4b959feb5034a07ef44a41b23b 100644 (file)
 
 /*--------------------------------------------------------------------*/
 
-static void
-StringVal(struct tokenlist *tl) 
-{
-       struct var *vp;
-       struct token *vt;
-
-       if (tl->t->tok == CSTR) {
-               EncToken(tl->fb, tl->t);
-               vcc_NextToken(tl);
-               return;
-       } 
-       ExpectErr(tl, VAR);
-       ERRCHK(tl);
-       vt = tl->t;
-       vp = FindVar(tl, tl->t, vcc_vars);
-       ERRCHK(tl);
-       if (!vp->has_string) {
-               vsb_printf(tl->sb,
-                   "No string representation of '%s'\n", vp->name);
-               vcc_ErrWhere(tl, tl->t);
-               return;
-       }
-       switch (vp->fmt) {
-       case STRING:
-               Fb(tl, 0, "%s", vp->rname);
-               break;
-       default:
-               vsb_printf(tl->sb,
-                   "String representation of '%s' not implemented yet.\n",
-                       vp->name);
-               vcc_ErrWhere(tl, tl->t);
-               return;
-       }
-       vcc_NextToken(tl);
-}
-
-/*--------------------------------------------------------------------*/
-
 #define VCL_RET_MAC(l,u,b,i)                           \
 static void                                            \
 parse_##l(struct tokenlist *tl)                                \
@@ -140,7 +102,7 @@ parse_set(struct tokenlist *tl)
        vcc_NextToken(tl);
        ExpectErr(tl, VAR);
        vt = tl->t;
-       vp = FindVar(tl, tl->t, vcc_vars);
+       vp = vcc_FindVar(tl, tl->t, vcc_vars);
        ERRCHK(tl);
        assert(vp != NULL);
        Fb(tl, 1, "%s", vp->lname);
@@ -222,7 +184,7 @@ parse_set(struct tokenlist *tl)
        case HASH:
                ExpectErr(tl, T_INCR);
                vcc_NextToken(tl);
-               StringVal(tl);
+               vcc_StringVal(tl);
                Fb(tl, 0, ");\n");
                return;
        default:
index 6b1bb69fce3e6fe9c423bfd0a620ae4b1ffdfc18..35f7ff093db76f31360bcdb7247ab1d8076d93bf 100644 (file)
@@ -100,7 +100,7 @@ vcc_ParseBackend(struct tokenlist *tl)
                }
                vcc_NextToken(tl);
                ExpectErr(tl, VAR);
-               vp = FindVar(tl, tl->t, vcc_be_vars);
+               vp = vcc_FindVar(tl, tl->t, vcc_be_vars);
                ERRCHK(tl);
                assert(vp != NULL);
                vcc_NextToken(tl);
index 59e5f76a0e1d192cd75c43f9f4c13c1f2118aa79..14fe8e81efc5f9f532f194126b10b831de01e18a 100644 (file)
@@ -232,64 +232,6 @@ EncToken(struct vsb *sb, const struct token *t)
        EncString(sb, t->dec, NULL, 0);
 }
 
-/*--------------------------------------------------------------------*/
-
-static struct var *
-HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh)
-{
-       char *p;
-       struct var *v;
-       int i, w;
-
-       (void)tl;
-
-       v = TlAlloc(tl, sizeof *v);
-       assert(v != NULL);
-       i = t->e - t->b;
-       p = TlAlloc(tl, i + 1);
-       assert(p != NULL);
-       memcpy(p, t->b, i);
-       p[i] = '\0';
-       v->name = p;
-       v->fmt = STRING;
-       v->has_string = vh->has_string;
-       if (!memcmp(vh->name, "req.", 4))
-               w = 1;
-       else
-               w = 2;
-       asprintf(&p, "VRT_GetHdr(sp, %d, \"\\%03o%s:\")", w,
-           (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len);
-       assert(p != NULL);
-       v->rname = p;
-       return (v);
-}
-
-/*--------------------------------------------------------------------*/
-
-struct var *
-FindVar(struct tokenlist *tl, const struct token *t, struct var *vl)
-{
-       struct var *v;
-
-       for (v = vl; v->name != NULL; v++) {
-               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))
-                       continue;
-               vcc_AddUses(tl, v);
-               if (v->fmt != HEADER)
-                       return (v);
-               return (HeaderVar(tl, t, v));
-       }
-       vsb_printf(tl->sb, "Unknown variable ");
-       vcc_ErrToken(tl, t);
-       vsb_cat(tl->sb, "\nAt: ");
-       vcc_ErrWhere(tl, t);
-       return (NULL);
-}
-
 /*--------------------------------------------------------------------
  * Output the location/profiling table.  For each counted token, we
  * record source+line+charpos for the first character in the token.
index de76960524f6cc459cbc00fe3c5511745ba265c2..8f89c31d1613630680b88eb94c5f5b3c60198d05 100644 (file)
@@ -151,7 +151,6 @@ void Fb(const struct tokenlist *tl, int indent, const char *fmt, ...);
 void Fi(const struct tokenlist *tl, int indent, const char *fmt, ...);
 void Ff(const struct tokenlist *tl, int indent, const char *fmt, ...);
 void EncToken(struct vsb *sb, const struct token *t);
-struct var *FindVar(struct tokenlist *tl, const struct token *t, struct var *vl);
 int IsMethod(const struct token *t);
 void *TlAlloc(struct tokenlist *tl, unsigned len);
 
@@ -179,6 +178,10 @@ void vcc__ErrInternal(struct tokenlist *tl, const char *func, unsigned line);
 void vcc_AddToken(struct tokenlist *tl, unsigned tok, const char *b, const char *e);
 void vcc_FreeToken(struct token *t);
 
+/* vcc_var.c */
+void vcc_StringVal(struct tokenlist *tl);
+struct var *vcc_FindVar(struct tokenlist *tl, const struct token *t, struct var *vl);
+
 /* vcc_xref.c */
 void vcc_AddDef(struct tokenlist *tl, struct token *t, enum ref_type type);
 void vcc_AddRef(struct tokenlist *tl, struct token *t, enum ref_type type);
index 91fa793a09d18f4f7d5a6ecbfb419844f90bc1a7..a0860d0dfcdbd97debac7dbea48e5805f988e539 100644 (file)
@@ -348,7 +348,7 @@ Cond_2(struct tokenlist *tl)
                ExpectErr(tl, ')');
                vcc_NextToken(tl);
        } else if (tl->t->tok == VAR) {
-               vp = FindVar(tl, tl->t, vcc_vars);
+               vp = vcc_FindVar(tl, tl->t, vcc_vars);
                ERRCHK(tl);
                assert(vp != NULL);
                vcc_NextToken(tl);
diff --git a/varnish-cache/lib/libvcl/vcc_var.c b/varnish-cache/lib/libvcl/vcc_var.c
new file mode 100644 (file)
index 0000000..9e6749c
--- /dev/null
@@ -0,0 +1,136 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2007 Linpro AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "vsb.h"
+
+#include "vcc_priv.h"
+#include "vcc_compile.h"
+#include "libvarnish.h"
+
+/*--------------------------------------------------------------------*/
+
+void
+vcc_StringVal(struct tokenlist *tl) 
+{
+       struct var *vp;
+       struct token *vt;
+
+       if (tl->t->tok == CSTR) {
+               EncToken(tl->fb, tl->t);
+               vcc_NextToken(tl);
+               return;
+       } 
+       ExpectErr(tl, VAR);
+       ERRCHK(tl);
+       vt = tl->t;
+       vp = vcc_FindVar(tl, tl->t, vcc_vars);
+       ERRCHK(tl);
+       if (!vp->has_string) {
+               vsb_printf(tl->sb,
+                   "No string representation of '%s'\n", vp->name);
+               vcc_ErrWhere(tl, tl->t);
+               return;
+       }
+       switch (vp->fmt) {
+       case STRING:
+               Fb(tl, 0, "%s", vp->rname);
+               break;
+       default:
+               vsb_printf(tl->sb,
+                   "String representation of '%s' not implemented yet.\n",
+                       vp->name);
+               vcc_ErrWhere(tl, tl->t);
+               return;
+       }
+       vcc_NextToken(tl);
+}
+
+/*--------------------------------------------------------------------*/
+
+static struct var *
+HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh)
+{
+       char *p;
+       struct var *v;
+       int i, w;
+
+       (void)tl;
+
+       v = TlAlloc(tl, sizeof *v);
+       assert(v != NULL);
+       i = t->e - t->b;
+       p = TlAlloc(tl, i + 1);
+       assert(p != NULL);
+       memcpy(p, t->b, i);
+       p[i] = '\0';
+       v->name = p;
+       v->fmt = STRING;
+       v->has_string = vh->has_string;
+       if (!memcmp(vh->name, "req.", 4))
+               w = 1;
+       else
+               w = 2;
+       asprintf(&p, "VRT_GetHdr(sp, %d, \"\\%03o%s:\")", w,
+           (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len);
+       assert(p != NULL);
+       v->rname = p;
+       return (v);
+}
+
+/*--------------------------------------------------------------------*/
+
+struct var *
+vcc_FindVar(struct tokenlist *tl, const struct token *t, struct var *vl)
+{
+       struct var *v;
+
+       for (v = vl; v->name != NULL; v++) {
+               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))
+                       continue;
+               vcc_AddUses(tl, v);
+               if (v->fmt != HEADER)
+                       return (v);
+               return (HeaderVar(tl, t, v));
+       }
+       vsb_printf(tl->sb, "Unknown variable ");
+       vcc_ErrToken(tl, t);
+       vsb_cat(tl->sb, "\nAt: ");
+       vcc_ErrWhere(tl, t);
+       return (NULL);
+}
+