Mailing List Archive

r1553 - trunk/varnish-cache/lib/libvcl
Author: phk
Date: 2007-06-25 10:57:09 +0200 (Mon, 25 Jun 2007)
New Revision: 1553

Added:
trunk/varnish-cache/lib/libvcl/vcc_var.c
Modified:
trunk/varnish-cache/lib/libvcl/Makefile.am
trunk/varnish-cache/lib/libvcl/vcc_action.c
trunk/varnish-cache/lib/libvcl/vcc_backend.c
trunk/varnish-cache/lib/libvcl/vcc_compile.c
trunk/varnish-cache/lib/libvcl/vcc_compile.h
trunk/varnish-cache/lib/libvcl/vcc_parse.c
Log:
Move variable related stuff to vcc_var.c


Modified: trunk/varnish-cache/lib/libvcl/Makefile.am
===================================================================
--- trunk/varnish-cache/lib/libvcl/Makefile.am 2007-06-25 08:17:25 UTC (rev 1552)
+++ trunk/varnish-cache/lib/libvcl/Makefile.am 2007-06-25 08:57:09 UTC (rev 1553)
@@ -17,6 +17,7 @@
vcc_fixed_token.c \
vcc_obj.c \
vcc_token.c \
+ vcc_var.c \
vcc_xref.c

libvcl_la_CFLAGS = -include config.h

Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-06-25 08:17:25 UTC (rev 1552)
+++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-06-25 08:57:09 UTC (rev 1553)
@@ -39,44 +39,6 @@

/*--------------------------------------------------------------------*/

-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 @@
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 @@
case HASH:
ExpectErr(tl, T_INCR);
vcc_NextToken(tl);
- StringVal(tl);
+ vcc_StringVal(tl);
Fb(tl, 0, ");\n");
return;
default:

Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2007-06-25 08:17:25 UTC (rev 1552)
+++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2007-06-25 08:57:09 UTC (rev 1553)
@@ -100,7 +100,7 @@
}
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);

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-06-25 08:17:25 UTC (rev 1552)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-06-25 08:57:09 UTC (rev 1553)
@@ -232,64 +232,6 @@
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.

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-06-25 08:17:25 UTC (rev 1552)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-06-25 08:57:09 UTC (rev 1553)
@@ -151,7 +151,6 @@
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_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);

Modified: trunk/varnish-cache/lib/libvcl/vcc_parse.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_parse.c 2007-06-25 08:17:25 UTC (rev 1552)
+++ trunk/varnish-cache/lib/libvcl/vcc_parse.c 2007-06-25 08:57:09 UTC (rev 1553)
@@ -348,7 +348,7 @@
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);

Added: trunk/varnish-cache/lib/libvcl/vcc_var.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_var.c (rev 0)
+++ trunk/varnish-cache/lib/libvcl/vcc_var.c 2007-06-25 08:57:09 UTC (rev 1553)
@@ -0,0 +1,136 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2007 Linpro AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at 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);
+}
+