r196 - in trunk/varnish-cache: include lib/libvcl

phk at projects.linpro.no phk at projects.linpro.no
Sun Jun 18 11:12:00 CEST 2006


Author: phk
Date: 2006-06-18 11:11:59 +0200 (Sun, 18 Jun 2006)
New Revision: 196

Modified:
   trunk/varnish-cache/include/vcl_lang.h
   trunk/varnish-cache/lib/libvcl/vcl_compile.c
   trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c
   trunk/varnish-cache/lib/libvcl/vcl_gen_fixed_token.tcl
   trunk/varnish-cache/lib/libvcl/vcl_token_defs.h
Log:
Correctly handle \ sequences in .h files in vcl_gen_fixed_token.tcl

Make handling a named enum, and use it as a bitmap.

Add "lookup" reserved word

Add VCL_done() macro to use in compiled code to set handling and drop
the per-handling callbacks (apart from VCL_error())




Modified: trunk/varnish-cache/include/vcl_lang.h
===================================================================
--- trunk/varnish-cache/include/vcl_lang.h	2006-06-18 07:28:19 UTC (rev 195)
+++ trunk/varnish-cache/include/vcl_lang.h	2006-06-18 09:11:59 UTC (rev 196)
@@ -38,6 +38,15 @@
 
 	TAILQ_HEAD(, storage)	store;
 };
+enum handling {
+	HND_Error	= (1 << 0),
+	HND_Pipe	= (1 << 1),
+	HND_Pass	= (1 << 2),
+	HND_Lookup	= (1 << 3),
+	HND_Fetch	= (1 << 4),
+	HND_Insert	= (1 << 5),
+	HND_Deliver	= (1 << 6),
+};
 
 struct sess {
 	int			fd;
@@ -48,15 +57,7 @@
 	/* HTTP request */
 	struct http		*http;
 
-	enum {
-		HND_Unclass,
-		HND_Deliver,
-		HND_Pass,
-		HND_Pipe,
-		HND_Lookup,
-		HND_Fetch,
-		HND_Insert
-	}			handling;
+	enum handling		handling;
 
 	char			done;
 
@@ -97,9 +98,6 @@
 int string_match(const char *, const char *);
 int VCL_rewrite(const char *, const char *);
 void VCL_error(VCL_FARGS, unsigned, const char *);
-void VCL_pass(VCL_FARGS);
-void VCL_fetch(VCL_FARGS);
-void VCL_insert(VCL_FARGS);
 int VCL_switch_config(const char *);
 
 typedef void vcl_init_f(void);
@@ -118,3 +116,10 @@
 	unsigned	nref;
 	unsigned	busy;
 };
+
+#define VCL_done(sess, hand)			\
+	do {					\
+		sess->handling = hand;		\
+		sess->done = 1;			\
+		return;				\
+	} while (0)

Modified: trunk/varnish-cache/lib/libvcl/vcl_compile.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcl_compile.c	2006-06-18 07:28:19 UTC (rev 195)
+++ trunk/varnish-cache/lib/libvcl/vcl_compile.c	2006-06-18 09:11:59 UTC (rev 196)
@@ -893,28 +893,19 @@
 		sbuf_printf(tl->fc, "VCL_no_cache(VCL_PASS_ARGS);\n");
 		return;
 	case T_DELIVER:
-		I(tl);
-		sbuf_printf(tl->fc, "VCL_deliver(VCL_PASS_ARGS);\n");
-		I(tl); sbuf_printf(tl->fc, "sess->done = 1;\n");
-		I(tl); sbuf_printf(tl->fc, "return;\n");
+		I(tl); sbuf_printf(tl->fc, "VCL_done(sess, HND_Deliver);\n");
 		return;
+	case T_LOOKUP:
+		I(tl); sbuf_printf(tl->fc, "VCL_done(sess, HND_Lookup);\n");
+		return;
 	case T_PASS:
-		I(tl);
-		sbuf_printf(tl->fc, "VCL_pass(VCL_PASS_ARGS);\n");
-		I(tl); sbuf_printf(tl->fc, "sess->done = 1;\n");
-		I(tl); sbuf_printf(tl->fc, "return;\n");
+		I(tl); sbuf_printf(tl->fc, "VCL_done(sess, HND_Pass);\n");
 		return;
 	case T_FETCH:
-		I(tl);
-		sbuf_printf(tl->fc, "VCL_fetch(VCL_PASS_ARGS);\n");
-		I(tl); sbuf_printf(tl->fc, "sess->done = 1;\n");
-		I(tl); sbuf_printf(tl->fc, "return;\n");
+		I(tl); sbuf_printf(tl->fc, "VCL_done(sess, HND_Fetch);\n");
 		return;
 	case T_INSERT:
-		I(tl);
-		sbuf_printf(tl->fc, "VCL_insert(VCL_PASS_ARGS);\n");
-		I(tl); sbuf_printf(tl->fc, "sess->done = 1;\n");
-		I(tl); sbuf_printf(tl->fc, "return;\n");
+		I(tl); sbuf_printf(tl->fc, "VCL_done(sess, HND_Insert);\n");
 		return;
 	case T_ERROR:
 		if (tl->t->tok == CNUM)
@@ -930,8 +921,7 @@
 			NextToken(tl);
 		} else
 			sbuf_printf(tl->fc, "(const char *)0);\n");
-		I(tl); sbuf_printf(tl->fc, "sess->done = 1;\n");
-		I(tl); sbuf_printf(tl->fc, "return;\n");
+		I(tl); sbuf_printf(tl->fc, "VCL_done(sess, HND_Error);\n");
 		return;
 	case T_SWITCH_CONFIG:
 		ExpectErr(tl, ID);

Modified: trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c	2006-06-18 07:28:19 UTC (rev 195)
+++ trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c	2006-06-18 09:11:59 UTC (rev 196)
@@ -231,6 +231,14 @@
 			return (T_IF);
 		}
 		return (0);
+	case 'l':
+		if (p[0] == 'l' && p[1] == 'o' && p[2] == 'o' && 
+		    p[3] == 'k' && p[4] == 'u' && p[5] == 'p'
+		     && !isvar(p[6])) {
+			*q = p + 6;
+			return (T_LOOKUP);
+		}
+		return (0);
 	case 'n':
 		if (p[0] == 'n' && p[1] == 'o' && p[2] == '_' && 
 		    p[3] == 'n' && p[4] == 'e' && p[5] == 'w' && 
@@ -370,6 +378,7 @@
 	vcl_tnames[T_INCR] = "+=";
 	vcl_tnames[T_INSERT] = "insert";
 	vcl_tnames[T_LEQ] = "<=";
+	vcl_tnames[T_LOOKUP] = "lookup";
 	vcl_tnames[T_MUL] = "*=";
 	vcl_tnames[T_NEQ] = "!=";
 	vcl_tnames[T_NO_CACHE] = "no_cache";
@@ -428,6 +437,15 @@
 	fputs("\n", f);
 	fputs("	TAILQ_HEAD(, storage)	store;\n", f);
 	fputs("};\n", f);
+	fputs("enum handling {\n", f);
+	fputs("	HND_Error	= (1 << 0),\n", f);
+	fputs("	HND_Pipe	= (1 << 1),\n", f);
+	fputs("	HND_Pass	= (1 << 2),\n", f);
+	fputs("	HND_Lookup	= (1 << 3),\n", f);
+	fputs("	HND_Fetch	= (1 << 4),\n", f);
+	fputs("	HND_Insert	= (1 << 5),\n", f);
+	fputs("	HND_Deliver	= (1 << 6),\n", f);
+	fputs("};\n", f);
 	fputs("\n", f);
 	fputs("struct sess {\n", f);
 	fputs("	int			fd;\n", f);
@@ -438,15 +456,7 @@
 	fputs("	/* HTTP request */\n", f);
 	fputs("	struct http		*http;\n", f);
 	fputs("\n", f);
-	fputs("	enum {\n", f);
-	fputs("		HND_Unclass,\n", f);
-	fputs("		HND_Deliver,\n", f);
-	fputs("		HND_Pass,\n", f);
-	fputs("		HND_Pipe,\n", f);
-	fputs("		HND_Lookup,\n", f);
-	fputs("		HND_Fetch,\n", f);
-	fputs("		HND_Insert\n", f);
-	fputs("	}			handling;\n", f);
+	fputs("	enum handling		handling;\n", f);
 	fputs("\n", f);
 	fputs("	char			done;\n", f);
 	fputs("\n", f);
@@ -487,9 +497,6 @@
 	fputs("int string_match(const char *, const char *);\n", f);
 	fputs("int VCL_rewrite(const char *, const char *);\n", f);
 	fputs("void VCL_error(VCL_FARGS, unsigned, const char *);\n", f);
-	fputs("void VCL_pass(VCL_FARGS);\n", f);
-	fputs("void VCL_fetch(VCL_FARGS);\n", f);
-	fputs("void VCL_insert(VCL_FARGS);\n", f);
 	fputs("int VCL_switch_config(const char *);\n", f);
 	fputs("\n", f);
 	fputs("typedef void vcl_init_f(void);\n", f);
@@ -508,4 +515,11 @@
 	fputs("	unsigned	nref;\n", f);
 	fputs("	unsigned	busy;\n", f);
 	fputs("};\n", f);
+	fputs("\n", f);
+	fputs("#define VCL_done(sess, hand)			\\\n", f);
+	fputs("	do {					\\\n", f);
+	fputs("		sess->handling = hand;		\\\n", f);
+	fputs("		sess->done = 1;			\\\n", f);
+	fputs("		return;				\\\n", f);
+	fputs("	} while (0)\n", f);
 }

Modified: trunk/varnish-cache/lib/libvcl/vcl_gen_fixed_token.tcl
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcl_gen_fixed_token.tcl	2006-06-18 07:28:19 UTC (rev 195)
+++ trunk/varnish-cache/lib/libvcl/vcl_gen_fixed_token.tcl	2006-06-18 09:11:59 UTC (rev 196)
@@ -13,6 +13,7 @@
 	backend
 
 	error
+	lookup
 	pass
 	fetch
 	insert
@@ -192,6 +193,7 @@
 		close $fx
 		continue
 	}
+	regsub -all {\\} $a {\\\\} a
 	puts $fo "\tfputs(\"$a\\n\", f);"
 }
 puts $fo "}"

Modified: trunk/varnish-cache/lib/libvcl/vcl_token_defs.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcl_token_defs.h	2006-06-18 07:28:19 UTC (rev 195)
+++ trunk/varnish-cache/lib/libvcl/vcl_token_defs.h	2006-06-18 09:11:59 UTC (rev 196)
@@ -14,32 +14,33 @@
 #define T_ACL 135
 #define T_BACKEND 136
 #define T_ERROR 137
-#define T_PASS 138
-#define T_FETCH 139
-#define T_INSERT 140
-#define T_DELIVER 141
-#define T_CALL 142
-#define T_NO_CACHE 143
-#define T_NO_NEW_CACHE 144
-#define T_SET 145
-#define T_REWRITE 146
-#define T_SWITCH_CONFIG 147
-#define T_INC 148
-#define T_DEC 149
-#define T_CAND 150
-#define T_COR 151
-#define T_LEQ 152
-#define T_EQ 153
-#define T_NEQ 154
-#define T_GEQ 155
-#define T_SHR 156
-#define T_SHL 157
-#define T_INCR 158
-#define T_DECR 159
-#define T_MUL 160
-#define T_DIV 161
-#define ID 162
-#define VAR 163
-#define CNUM 164
-#define CSTR 165
-#define EOI 166
+#define T_LOOKUP 138
+#define T_PASS 139
+#define T_FETCH 140
+#define T_INSERT 141
+#define T_DELIVER 142
+#define T_CALL 143
+#define T_NO_CACHE 144
+#define T_NO_NEW_CACHE 145
+#define T_SET 146
+#define T_REWRITE 147
+#define T_SWITCH_CONFIG 148
+#define T_INC 149
+#define T_DEC 150
+#define T_CAND 151
+#define T_COR 152
+#define T_LEQ 153
+#define T_EQ 154
+#define T_NEQ 155
+#define T_GEQ 156
+#define T_SHR 157
+#define T_SHL 158
+#define T_INCR 159
+#define T_DECR 160
+#define T_MUL 161
+#define T_DIV 162
+#define ID 163
+#define VAR 164
+#define CNUM 165
+#define CSTR 166
+#define EOI 167




More information about the varnish-commit mailing list