#define VCL_RET_ERROR (1 << 0) #define VCL_RET_LOOKUP (1 << 1) #define VCL_RET_HASH (1 << 2) #define VCL_RET_PIPE (1 << 3) #define VCL_RET_PASS (1 << 4) #define VCL_RET_FETCH (1 << 5) #define VCL_RET_INSERT (1 << 6) #define VCL_RET_DELIVER (1 << 7) #define VCL_RET_DISCARD (1 << 8) /* * $Id: vcc_fixed_token.c 1301 2007-04-01 15:33:56Z phk $ * * NB: This file is machine generated, DO NOT EDIT! * * Edit vcc_gen_fixed_token.tcl instead */ struct sess; typedef void vcl_init_f(void); typedef void vcl_fini_f(void); typedef int vcl_func_f(struct sess *sp); struct VCL_conf { unsigned magic; #define VCL_CONF_MAGIC 0x7406c509 /* from /dev/random */ struct backend **backend; unsigned nbackend; struct vrt_ref *ref; unsigned nref; unsigned busy; unsigned nsrc; const char **srcname; const char **srcbody; void *priv; vcl_init_f *init_func; vcl_fini_f *fini_func; vcl_func_f *recv_func; vcl_func_f *pipe_func; vcl_func_f *pass_func; vcl_func_f *hash_func; vcl_func_f *miss_func; vcl_func_f *hit_func; vcl_func_f *fetch_func; vcl_func_f *timeout_func; }; /*- * Copyright (c) 2006 Verdens Gang AS * Copyright (c) 2006 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp * * 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 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: vcc_fixed_token.c 1301 2007-04-01 15:33:56Z phk $ * * Runtime support for compiled VCL programs. * * XXX: When this file is changed, lib/libvcl/vcc_gen_fixed_token.tcl * XXX: *MUST* be rerun. */ struct sess; struct vsb; struct backend; struct VCL_conf; struct vrt_ref { unsigned source; unsigned offset; unsigned line; unsigned pos; unsigned count; const char *token; }; struct vrt_acl { unsigned char not; unsigned char mask; unsigned char paren; const char *name; const char *desc; void *priv; }; /* ACL related */ int VRT_acl_match(struct sess *, const char *, struct vrt_acl *); void VRT_acl_init(struct vrt_acl *); void VRT_acl_fini(struct vrt_acl *); /* Regexp related */ void VRT_re_init(void **, const char *); void VRT_re_fini(void *); int VRT_re_match(const char *, void *re); int VRT_re_test(struct vsb *, const char *); void VRT_count(struct sess *, unsigned); int VRT_rewrite(const char *, const char *); void VRT_error(struct sess *, unsigned, const char *); int VRT_switch_config(const char *); char *VRT_GetHdr(struct sess *, int where, const char *); void VRT_handling(struct sess *sp, unsigned hand); /* Backend related */ void VRT_set_backend_name(struct backend *, const char *); void VRT_alloc_backends(struct VCL_conf *cp); void VRT_free_backends(struct VCL_conf *cp); void VRT_fini_backend(struct backend *be); #define VRT_done(sp, hand) \ do { \ VRT_handling(sp, hand); \ return (1); \ } while (0) /* * $Id: vcc_fixed_token.c 1301 2007-04-01 15:33:56Z phk $ * * NB: This file is machine generated, DO NOT EDIT! * * Edit vcc_gen_obj.tcl instead */ const char * VRT_r_backend_host(struct backend *); void VRT_l_backend_host(struct backend *, const char *); const char * VRT_r_backend_port(struct backend *); void VRT_l_backend_port(struct backend *, const char *); double VRT_r_backend_dnsttl(struct backend *); void VRT_l_backend_dnsttl(struct backend *, double); const unsigned char * VRT_r_client_ip(struct sess *); void VRT_l_client_ip(struct sess *, const unsigned char *); const char * VRT_r_req_request(struct sess *); void VRT_l_req_request(struct sess *, const char *); const char * VRT_r_req_host(struct sess *); void VRT_l_req_host(struct sess *, const char *); const char * VRT_r_req_url(struct sess *); void VRT_l_req_url(struct sess *, const char *); const char * VRT_r_req_proto(struct sess *); void VRT_l_req_proto(struct sess *, const char *); struct backend * VRT_r_req_backend(struct sess *); void VRT_l_req_backend(struct sess *, struct backend *); double VRT_r_obj_valid(struct sess *); void VRT_l_obj_valid(struct sess *, double); double VRT_r_obj_cacheable(struct sess *); void VRT_l_obj_cacheable(struct sess *, double); double VRT_r_obj_ttl(struct sess *); void VRT_l_obj_ttl(struct sess *, double); const char * VRT_r_req_http_(struct sess *); void VRT_l_req_http_(struct sess *, const char *); const char * VRT_r_resp_http_(struct sess *); void VRT_l_resp_http_(struct sess *, const char *); extern struct VCL_conf VCL_conf; #define VGC_backend_default (VCL_conf.backend[0]) static struct vrt_acl acl_purge[]; #define VGC_NREFS 61 static void VGC_init_backend_default (void) { struct backend *backend = VGC_backend_default; VRT_set_backend_name(backend, "default"); VRT_l_backend_host(backend, "10.0.0.25"); VRT_l_backend_port(backend, "80"); } static struct vrt_acl acl_purge[] = { { 0, 0, 0, "localhost", "\"" "localhost" "\"" }, { 0, 0, 0, "195.159.128.0/27", "\"" "195.159.128.0/27" "\"" }, { 0, 0, 0, "195.159.7.8/29", "\"" "195.159.7.8/29" "\"" }, { 0, 0, 0, "10.0.0.0/24", "\"" "10.0.0.0/24" "\"" }, { 0, 0, 0, (void*)0, } }; VRT_acl_match(sp, "purge", acl_purge) static int VGC_function_vcl_recv (struct sess *sp) { { { VRT_count(sp, 1); if ( ( ( VRT_count(sp, 2), ( !strcmp(VRT_r_req_request(sp), "POST") ) ) ) ) { VRT_count(sp, 3); VRT_done(sp, VCL_RET_PIPE); } VRT_count(sp, 4); if ( ( ( VRT_count(sp, 5), ( !strcmp(VRT_r_req_request(sp), "PURGE") ) ) ) ) { VRT_count(sp, 6); if ( ( ( VRT_count(sp, 7), !( ) ) ) ) { VRT_count(sp, 8); VRT_error(sp, 405, "Not allowed."); VRT_done(sp, VCL_RET_ERROR); } VRT_count(sp, 9); VRT_done(sp, VCL_RET_LOOKUP); } VRT_count(sp, 10); if ( ( ( VRT_count(sp, 11), ( !strcmp(VRT_r_req_request(sp), "GET") ) ) && ( VRT_count(sp, 12), ( VRT_GetHdr(sp, 1, "\007cookie:") != (void*)0 ) ) ) ) { VRT_count(sp, 13); VRT_done(sp, VCL_RET_LOOKUP); } VRT_count(sp, 14); } } { { VRT_count(sp, 30); if ( ( ( VRT_count(sp, 31), ( strcmp(VRT_r_req_request(sp), "GET") ) ) && ( VRT_count(sp, 32), ( strcmp(VRT_r_req_request(sp), "HEAD") ) ) ) ) { VRT_count(sp, 33); VRT_done(sp, VCL_RET_PIPE); } VRT_count(sp, 34); if ( ( ( VRT_count(sp, 35), ( VRT_GetHdr(sp, 1, "\007Expect:") != (void*)0 ) ) ) ) { VRT_count(sp, 36); VRT_done(sp, VCL_RET_PIPE); } VRT_count(sp, 37); if ( ( ( VRT_count(sp, 38), ( VRT_GetHdr(sp, 1, "\015Authenticate:") != (void*)0 ) ) ) || ( ( VRT_count(sp, 39), ( VRT_GetHdr(sp, 1, "\007Cookie:") != (void*)0 ) ) ) ) { VRT_count(sp, 40); VRT_done(sp, VCL_RET_PASS); } VRT_count(sp, 41); VRT_done(sp, VCL_RET_LOOKUP); } } } static int VGC_function_vcl_pipe (struct sess *sp) { { { VRT_count(sp, 42); VRT_done(sp, VCL_RET_PIPE); } } } static int VGC_function_vcl_pass (struct sess *sp) { { { VRT_count(sp, 43); VRT_done(sp, VCL_RET_PASS); } } } static int VGC_function_vcl_hash (struct sess *sp) { { { VRT_count(sp, 44); VRT_done(sp, VCL_RET_HASH); } } } static int VGC_function_vcl_miss (struct sess *sp) { { { VRT_count(sp, 26); if ( ( ( VRT_count(sp, 27), ( !strcmp(VRT_r_req_request(sp), "PURGE") ) ) ) ) { VRT_count(sp, 28); VRT_error(sp, 404, "Not in cache."); VRT_done(sp, VCL_RET_ERROR); } VRT_count(sp, 29); } } { { VRT_count(sp, 49); VRT_done(sp, VCL_RET_FETCH); } } } static int VGC_function_vcl_hit (struct sess *sp) { { { VRT_count(sp, 15); if ( ( ( VRT_count(sp, 16), !( VRT_r_obj_cacheable(sp) ) ) ) ) { VRT_count(sp, 17); VRT_done(sp, VCL_RET_PASS); } VRT_count(sp, 18); if ( ( ( VRT_count(sp, 19), ( !strcmp(VRT_r_req_request(sp), "PURGE") ) ) ) ) { VRT_count(sp, 20); VRT_l_obj_ttl(sp, (0 * 1)); VRT_error(sp, 200, "Purged."); VRT_done(sp, VCL_RET_ERROR); } VRT_count(sp, 21); } } { { VRT_count(sp, 45); if ( ( ( VRT_count(sp, 46), !( VRT_r_obj_cacheable(sp) ) ) ) ) { VRT_count(sp, 47); VRT_done(sp, VCL_RET_PASS); } VRT_count(sp, 48); VRT_done(sp, VCL_RET_DELIVER); } } } static int VGC_function_vcl_fetch (struct sess *sp) { { { VRT_count(sp, 22); VRT_l_obj_ttl(sp, (1200 * 1)); if ( ( ( VRT_count(sp, 23), ( VRT_GetHdr(sp, 2, "\010nocache:") != (void*)0 ) ) ) ) { VRT_count(sp, 24); VRT_done(sp, VCL_RET_PASS); } VRT_count(sp, 25); } } { { VRT_count(sp, 50); if ( ( ( VRT_count(sp, 51), !( VRT_r_obj_valid(sp) ) ) ) ) { VRT_count(sp, 52); VRT_error(sp, 0, (const char *)0); VRT_done(sp, VCL_RET_ERROR); } VRT_count(sp, 53); if ( ( ( VRT_count(sp, 54), !( VRT_r_obj_cacheable(sp) ) ) ) ) { VRT_count(sp, 55); VRT_done(sp, VCL_RET_PASS); } VRT_count(sp, 56); if ( ( ( VRT_count(sp, 57), ( VRT_GetHdr(sp, 2, "\013Set-Cookie:") != (void*)0 ) ) ) ) { VRT_count(sp, 58); VRT_done(sp, VCL_RET_PASS); } VRT_count(sp, 59); VRT_done(sp, VCL_RET_INSERT); } } } static int VGC_function_vcl_timeout (struct sess *sp) { { { VRT_count(sp, 60); VRT_done(sp, VCL_RET_DISCARD); } } } static struct vrt_ref VGC_ref[VGC_NREFS] = { [ 1] = { 0, 199, 13, 14, 0, "{" }, [ 2] = { 0, 213, 14, 13, 0, "req.request" }, [ 3] = { 0, 236, 14, 36, 0, "{" }, [ 4] = { 0, 279, 18, 9, 0, "if" }, [ 5] = { 0, 283, 18, 13, 0, "req.request" }, [ 6] = { 0, 307, 18, 37, 0, "{" }, [ 7] = { 0, 329, 19, 21, 0, "!" }, [ 8] = { 0, 349, 19, 41, 0, "{" }, [ 9] = { 0, 435, 22, 17, 0, "lookup" }, [ 10] = { 0, 462, 25, 9, 0, "if" }, [ 11] = { 0, 466, 25, 13, 0, "req.request" }, [ 12] = { 0, 490, 25, 37, 0, "req.http.cookie" }, [ 13] = { 0, 507, 25, 54, 0, "{" }, [ 14] = { 0, 544, 29, 1, 0, "}" }, [ 15] = { 0, 559, 31, 13, 0, "{" }, [ 16] = { 0, 566, 32, 13, 0, "!" }, [ 17] = { 0, 582, 32, 29, 0, "{" }, [ 18] = { 0, 624, 36, 9, 0, "if" }, [ 19] = { 0, 628, 36, 13, 0, "req.request" }, [ 20] = { 0, 652, 36, 37, 0, "{" }, [ 21] = { 0, 735, 40, 1, 0, "}" }, [ 22] = { 0, 752, 42, 15, 0, "{" }, [ 23] = { 0, 796, 44, 21, 0, "resp.http.nocache" }, [ 24] = { 0, 815, 44, 40, 0, "{" }, [ 25] = { 0, 850, 48, 1, 0, "}" }, [ 26] = { 0, 866, 50, 14, 0, "{" }, [ 27] = { 0, 880, 51, 13, 0, "req.request" }, [ 28] = { 0, 904, 51, 37, 0, "{" }, [ 29] = { 0, 959, 54, 1, 0, "}" }, [ 30] = { 1, 13, 1, 14, 0, "{" }, [ 31] = { 1, 23, 2, 9, 0, "req.request" }, [ 32] = { 1, 47, 2, 33, 0, "req.request" }, [ 33] = { 1, 70, 2, 56, 0, "{" }, [ 34] = { 1, 96, 5, 5, 0, "if" }, [ 35] = { 1, 100, 5, 9, 0, "req.http.Expect" }, [ 36] = { 1, 117, 5, 26, 0, "{" }, [ 37] = { 1, 143, 8, 5, 0, "if" }, [ 38] = { 1, 147, 8, 9, 0, "req.http.Authenticate" }, [ 39] = { 1, 172, 8, 34, 0, "req.http.Cookie" }, [ 40] = { 1, 189, 8, 51, 0, "{" }, [ 41] = { 1, 215, 11, 5, 0, "lookup" }, [ 42] = { 1, 239, 14, 14, 0, "{" }, [ 43] = { 1, 267, 18, 14, 0, "{" }, [ 44] = { 1, 295, 22, 14, 0, "{" }, [ 45] = { 1, 322, 26, 13, 0, "{" }, [ 46] = { 1, 332, 27, 9, 0, "!" }, [ 47] = { 1, 348, 27, 25, 0, "{" }, [ 48] = { 1, 374, 30, 5, 0, "deliver" }, [ 49] = { 1, 399, 33, 14, 0, "{" }, [ 50] = { 1, 429, 37, 15, 0, "{" }, [ 51] = { 1, 439, 38, 9, 0, "!" }, [ 52] = { 1, 451, 38, 21, 0, "{" }, [ 53] = { 1, 478, 41, 5, 0, "if" }, [ 54] = { 1, 482, 41, 9, 0, "!" }, [ 55] = { 1, 498, 41, 25, 0, "{" }, [ 56] = { 1, 524, 44, 5, 0, "if" }, [ 57] = { 1, 528, 44, 9, 0, "resp.http.Set-Cookie" }, [ 58] = { 1, 550, 44, 31, 0, "{" }, [ 59] = { 1, 576, 47, 5, 0, "insert" }, [ 60] = { 1, 602, 49, 17, 0, "{" }, }; static void VGC_Init(void) { VRT_alloc_backends(&VCL_conf); VGC_init_backend_default(); VRT_acl_init(acl_purge); } static void VGC_Fini(void) { VRT_fini_backend(VGC_backend_default); VRT_acl_fini(acl_purge); VRT_free_backends(&VCL_conf); } const char *srcname[2] = { "/etc/varnish.vcl", "Default", }; const char *srcbody[2] = { /* "/etc/varnish.vcl"*/ "backend default {\n" "\tset backend.host = \"10.0.0.25\";\n" "\tset backend.port = \"80\";\n" "}\n" "\n" "acl purge {\n" " \"localhost\";\n" " \"195.159.128.0/27\";\n" " \"195.159.7.8/29\";\n" "\t\"10.0.0.0/24\";\n" "}\n" "\n" "sub vcl_recv {\n" " if (req.request == \"POST\") {\n" " pipe;\n" " }\n" "\n" " if (req.request == \"PURGE\") {\n" " if (!client.ip ~ purge) {\n" " error 405 \"Not allowed.\";\n" " }\n" " lookup;\n" " }\n" "\n" " if (req.request == \"GET\" && req.http.cookie) {\n" " lookup;\n" " }\n" "\n" "}\n" "\n" "sub vcl_hit {\n" "\tif (!obj.cacheable) {\n" " pass;\n" " }\n" "\n" " if (req.request == \"PURGE\") {\n" " set obj.ttl = 0s;\n" " error 200 \"Purged.\";\n" " }\n" "}\n" "\n" "sub vcl_fetch {\n" " set obj.ttl = 1200s;\n" "\t if (resp.http.nocache) {\n" " pass;\n" " }\n" "\n" "}\n" "\n" "sub vcl_miss {\n" " if (req.request == \"PURGE\") {\n" " error 404 \"Not in cache.\";\n" " }\n" "}\n" "", /* "Default"*/ "sub vcl_recv {\n" " if (req.request != \"GET\" && req.request != \"HEAD\") {\n" " pipe;\n" " }\n" " if (req.http.Expect) {\n" " pipe;\n" " }\n" " if (req.http.Authenticate || req.http.Cookie) {\n" " pass;\n" " }\n" " lookup;\n" "}\n" "\n" "sub vcl_pipe {\n" " pipe;\n" "}\n" "\n" "sub vcl_pass {\n" " pass;\n" "}\n" "\n" "sub vcl_hash {\n" " hash;\n" "}\n" "\n" "sub vcl_hit {\n" " if (!obj.cacheable) {\n" " pass;\n" " }\n" " deliver;\n" "}\n" "\n" "sub vcl_miss {\n" " fetch;\n" "}\n" "\n" "sub vcl_fetch {\n" " if (!obj.valid) {\n" " error;\n" " }\n" " if (!obj.cacheable) {\n" " pass;\n" " }\n" " if (resp.http.Set-Cookie) {\n" " pass;\n" " }\n" " insert;\n" "}\n" "sub vcl_timeout {\n" " discard;\n" "}\n" "", }; struct VCL_conf VCL_conf = { .magic = VCL_CONF_MAGIC, .init_func = VGC_Init, .fini_func = VGC_Fini, .nbackend = 1, .ref = VGC_ref, .nref = VGC_NREFS, .nsrc = 2, .srcname = srcname, .srcbody = srcbody, .recv_func = VGC_function_vcl_recv, .pipe_func = VGC_function_vcl_pipe, .pass_func = VGC_function_vcl_pass, .hash_func = VGC_function_vcl_hash, .miss_func = VGC_function_vcl_miss, .hit_func = VGC_function_vcl_hit, .fetch_func = VGC_function_vcl_fetch, .timeout_func = VGC_function_vcl_timeout, };