From: phk Date: Sun, 18 Jun 2006 09:11:59 +0000 (+0000) Subject: Correctly handle \ sequences in .h files in vcl_gen_fixed_token.tcl X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=37a494a15daf61c54f60dfb0b50b30765b06b42d;p=varnish 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()) git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@196 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/include/vcl_lang.h b/varnish-cache/include/vcl_lang.h index 59e19033..31d995ca 100644 --- a/varnish-cache/include/vcl_lang.h +++ b/varnish-cache/include/vcl_lang.h @@ -38,6 +38,15 @@ struct object { 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 @@ struct sess { /* 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 ip_match(unsigned, struct vcl_acl *); 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 @@ struct VCL_conf { unsigned nref; unsigned busy; }; + +#define VCL_done(sess, hand) \ + do { \ + sess->handling = hand; \ + sess->done = 1; \ + return; \ + } while (0) diff --git a/varnish-cache/lib/libvcl/vcl_compile.c b/varnish-cache/lib/libvcl/vcl_compile.c index 6fb03a0a..c538dea0 100644 --- a/varnish-cache/lib/libvcl/vcl_compile.c +++ b/varnish-cache/lib/libvcl/vcl_compile.c @@ -893,28 +893,19 @@ Action(struct tokenlist *tl) 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 @@ Action(struct tokenlist *tl) 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); diff --git a/varnish-cache/lib/libvcl/vcl_fixed_token.c b/varnish-cache/lib/libvcl/vcl_fixed_token.c index 402332e7..520fb0e3 100644 --- a/varnish-cache/lib/libvcl/vcl_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcl_fixed_token.c @@ -231,6 +231,14 @@ vcl_fixed_token(const char *p, const char **q) 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_init_tnames(void) 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 @@ vcl_output_lang_h(FILE *f) 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 @@ vcl_output_lang_h(FILE *f) 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 @@ vcl_output_lang_h(FILE *f) 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 @@ vcl_output_lang_h(FILE *f) 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); } diff --git a/varnish-cache/lib/libvcl/vcl_gen_fixed_token.tcl b/varnish-cache/lib/libvcl/vcl_gen_fixed_token.tcl index 30c3e527..85e1b961 100755 --- a/varnish-cache/lib/libvcl/vcl_gen_fixed_token.tcl +++ b/varnish-cache/lib/libvcl/vcl_gen_fixed_token.tcl @@ -13,6 +13,7 @@ set keywords { backend error + lookup pass fetch insert @@ -192,6 +193,7 @@ while {[gets $fi a] >= 0} { close $fx continue } + regsub -all {\\} $a {\\\\} a puts $fo "\tfputs(\"$a\\n\", f);" } puts $fo "}" diff --git a/varnish-cache/lib/libvcl/vcl_token_defs.h b/varnish-cache/lib/libvcl/vcl_token_defs.h index dde25c19..c97f389c 100644 --- a/varnish-cache/lib/libvcl/vcl_token_defs.h +++ b/varnish-cache/lib/libvcl/vcl_token_defs.h @@ -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