Skip to content

Instantly share code, notes, and snippets.

@CantonBolo
Created November 12, 2014 01:57
Show Gist options
  • Save CantonBolo/e3ce5d38e8d9d4ae9ad9 to your computer and use it in GitHub Desktop.
Save CantonBolo/e3ce5d38e8d9d4ae9ad9 to your computer and use it in GitHub Desktop.
varnish.vcc
/* ---===### include/vcl.h ###===--- */
/*
* NB: This file is machine generated, DO NOT EDIT!
*
* Edit and run generate.py instead
*/
struct vrt_ctx;
struct req;
struct busyobj;
struct ws;
struct cli;
struct worker;
typedef int vcl_init_f(struct cli *);
typedef void vcl_fini_f(struct cli *);
typedef int vcl_func_f(const struct vrt_ctx *ctx);
/* VCL Methods */
#define VCL_MET_RECV (1U << 1)
#define VCL_MET_PIPE (1U << 2)
#define VCL_MET_PASS (1U << 3)
#define VCL_MET_HASH (1U << 4)
#define VCL_MET_PURGE (1U << 5)
#define VCL_MET_MISS (1U << 6)
#define VCL_MET_HIT (1U << 7)
#define VCL_MET_DELIVER (1U << 8)
#define VCL_MET_SYNTH (1U << 9)
#define VCL_MET_BACKEND_FETCH (1U << 10)
#define VCL_MET_BACKEND_RESPONSE (1U << 11)
#define VCL_MET_BACKEND_ERROR (1U << 12)
#define VCL_MET_INIT (1U << 13)
#define VCL_MET_FINI (1U << 14)
#define VCL_MET_MAX 15
#define VCL_MET_MASK 0x7fff
/* VCL Returns */
#define VCL_RET_ABANDON 0
#define VCL_RET_DELIVER 1
#define VCL_RET_FETCH 2
#define VCL_RET_HASH 3
#define VCL_RET_LOOKUP 4
#define VCL_RET_OK 5
#define VCL_RET_PASS 6
#define VCL_RET_PIPE 7
#define VCL_RET_PURGE 8
#define VCL_RET_RESTART 9
#define VCL_RET_RETRY 10
#define VCL_RET_SYNTH 11
#define VCL_RET_MAX 12
struct VCL_conf {
unsigned magic;
#define VCL_CONF_MAGIC 0x7406c509 /* from /dev/random */
struct director **director;
unsigned ndirector;
struct vrt_ref *ref;
unsigned nref;
unsigned busy;
unsigned discard;
unsigned nsrc;
const char **srcname;
const char **srcbody;
vcl_init_f *init_vcl;
vcl_fini_f *fini_vcl;
vcl_func_f *recv_func;
vcl_func_f *pipe_func;
vcl_func_f *pass_func;
vcl_func_f *hash_func;
vcl_func_f *purge_func;
vcl_func_f *miss_func;
vcl_func_f *hit_func;
vcl_func_f *deliver_func;
vcl_func_f *synth_func;
vcl_func_f *backend_fetch_func;
vcl_func_f *backend_response_func;
vcl_func_f *backend_error_func;
vcl_func_f *init_func;
vcl_func_f *fini_func;
};
/* ---===### include/vrt.h ###===--- */
/*-
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-2014 Varnish Software 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.
*
* Runtime support for compiled VCL programs and VMODs.
*
* NB: When this file is changed, lib/libvcc/generate.py *MUST* be rerun.
*/
/***********************************************************************
* Major and minor VRT API versions.
*
* Whenever something is added, increment MINOR version
* Whenever something is deleted or changed in a way which is not
* binary/load-time compatible, increment MAJOR version
*/
#define VRT_MAJOR_VERSION 1U
#define VRT_MINOR_VERSION 2U
/***********************************************************************/
struct req;
struct busyobj;
struct vsl_log;
struct http;
struct ws;
struct cli;
struct director;
struct VCL_conf;
struct suckaddr;
/***********************************************************************
* This is the central definition of the mapping from VCL types to
* C-types. The python scripts read these from here.
* (alphabetic order)
*/
typedef struct director * VCL_BACKEND;
typedef const struct vmod_priv * VCL_BLOB;
typedef unsigned VCL_BOOL;
typedef double VCL_BYTES;
typedef double VCL_DURATION;
typedef const char * VCL_ENUM;
typedef const struct gethdr_s * VCL_HEADER;
typedef struct http * VCL_HTTP;
typedef long VCL_INT;
typedef const struct suckaddr * VCL_IP;
typedef double VCL_REAL;
typedef const char * VCL_STRING;
typedef double VCL_TIME;
typedef void VCL_VOID;
/***********************************************************************
* This is the composite argument we pass to compiled VCL and VRT
* functions.
*/
struct vrt_ctx {
unsigned magic;
#define VRT_CTX_MAGIC 0x6bb8f0db
unsigned method;
unsigned *handling;
struct vsl_log *vsl;
struct VCL_conf *vcl;
struct ws *ws;
struct req *req;
struct http *http_req;
struct http *http_obj;
struct http *http_resp;
struct busyobj *bo;
struct http *http_bereq;
struct http *http_beresp;
double now;
};
/***********************************************************************/
struct vmod_data {
/* The version/id fields must be first, they protect the rest */
unsigned vrt_major;
unsigned vrt_minor;
const char *file_id;
const char *name;
const void *func;
int func_len;
const char *proto;
const char * const *spec;
const char *abi;
};
/***********************************************************************/
enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ, HDR_BERESP };
struct gethdr_s {
enum gethdr_e where;
const char *what;
};
/*
* A backend probe specification
*/
extern const void * const vrt_magic_string_end;
extern const void * const vrt_magic_string_unset;
struct vrt_backend_probe {
const char *url;
const char *request;
double timeout;
double interval;
unsigned exp_status;
unsigned window;
unsigned threshold;
unsigned initial;
};
/*
* A backend is a host+port somewhere on the network
*/
struct vrt_backend {
const char *vcl_name;
const char *ipv4_addr;
const char *ipv6_addr;
const char *port;
const struct suckaddr *ipv4_suckaddr;
const struct suckaddr *ipv6_suckaddr;
const char *hosthdr;
double connect_timeout;
double first_byte_timeout;
double between_bytes_timeout;
unsigned max_connections;
const struct vrt_backend_probe *probe;
};
/*
* other stuff.
* XXX: document when bored
*/
struct vrt_ref {
unsigned source;
unsigned offset;
unsigned line;
unsigned pos;
unsigned count;
const char *token;
};
/* ACL related */
#define VRT_ACL_MAXADDR 16 /* max(IPv4, IPv6) */
void VRT_acl_log(const struct vrt_ctx *, const char *msg);
/* req related */
int VRT_CacheReqBody(const struct vrt_ctx *, long long maxsize);
/* Regexp related */
void VRT_re_init(void **, const char *);
void VRT_re_fini(void *);
int VRT_re_match(const struct vrt_ctx *, const char *, void *re);
const char *VRT_regsub(const struct vrt_ctx *, int all, const char *,
void *, const char *);
void VRT_ban_string(const struct vrt_ctx *, const char *);
void VRT_purge(const struct vrt_ctx *, double ttl, double grace, double keep);
void VRT_count(const struct vrt_ctx *, unsigned);
int VRT_rewrite(const char *, const char *);
void VRT_error(const struct vrt_ctx *, unsigned, const char *);
int VRT_switch_config(const char *);
char *VRT_GetHdr(const struct vrt_ctx *, const struct gethdr_s *);
void VRT_SetHdr(const struct vrt_ctx *, const struct gethdr_s *,
const char *, ...);
void VRT_handling(const struct vrt_ctx *, unsigned hand);
void VRT_hashdata(const struct vrt_ctx *, const char *str, ...);
/* Simple stuff */
int VRT_strcmp(const char *s1, const char *s2);
void VRT_memmove(void *dst, const void *src, unsigned len);
void VRT_Rollback(const struct vrt_ctx *, const struct http *);
/* Synthetic pages */
void VRT_synth_page(const struct vrt_ctx *, const char *, ...);
/* Backend related */
void VRT_init_dir(struct cli *, struct director **, int idx, const void *priv);
void VRT_fini_dir(struct cli *, struct director *);
/* Suckaddr related */
int VRT_VSA_GetPtr(const struct suckaddr *sua, const unsigned char ** dst);
/* VMOD/Modules related */
int VRT_Vmod_Init(void **hdl, void *ptr, int len, const char *nm,
const char *path, const char *file_id, struct cli *cli);
void VRT_Vmod_Fini(void **hdl);
struct vmod_priv;
typedef void vmod_priv_free_f(void *);
struct vmod_priv {
void *priv;
int len;
vmod_priv_free_f *free;
};
typedef int vmod_init_f(struct vmod_priv *, const struct VCL_conf *);
void VRT_priv_fini(const struct vmod_priv *p);
/* Stevedore related functions */
int VRT_Stv(const char *nm);
/* Convert things to string */
char *VRT_IP_string(const struct vrt_ctx *, VCL_IP);
char *VRT_INT_string(const struct vrt_ctx *, VCL_INT);
char *VRT_REAL_string(const struct vrt_ctx *, VCL_REAL);
char *VRT_TIME_string(const struct vrt_ctx *, VCL_TIME);
const char *VRT_BOOL_string(VCL_BOOL);
const char *VRT_BACKEND_string(VCL_BACKEND);
const char *VRT_CollectString(const struct vrt_ctx *, const char *p, ...);
/* ---===### include/vrt_obj.h ###===--- */
/*
* NB: This file is machine generated, DO NOT EDIT!
*
* Edit and run generate.py instead
*/
VCL_HTTP VRT_r_bereq(const struct vrt_ctx *);
VCL_BACKEND VRT_r_bereq_backend(const struct vrt_ctx *);
void VRT_l_bereq_backend(const struct vrt_ctx *, VCL_BACKEND);
VCL_DURATION VRT_r_bereq_between_bytes_timeout(const struct vrt_ctx *);
void VRT_l_bereq_between_bytes_timeout(const struct vrt_ctx *, VCL_DURATION);
VCL_DURATION VRT_r_bereq_connect_timeout(const struct vrt_ctx *);
void VRT_l_bereq_connect_timeout(const struct vrt_ctx *, VCL_DURATION);
VCL_DURATION VRT_r_bereq_first_byte_timeout(const struct vrt_ctx *);
void VRT_l_bereq_first_byte_timeout(const struct vrt_ctx *, VCL_DURATION);
VCL_STRING VRT_r_bereq_method(const struct vrt_ctx *);
void VRT_l_bereq_method(const struct vrt_ctx *, const char *, ...);
VCL_STRING VRT_r_bereq_proto(const struct vrt_ctx *);
void VRT_l_bereq_proto(const struct vrt_ctx *, const char *, ...);
VCL_INT VRT_r_bereq_retries(const struct vrt_ctx *);
VCL_BOOL VRT_r_bereq_uncacheable(const struct vrt_ctx *);
void VRT_l_bereq_uncacheable(const struct vrt_ctx *, VCL_BOOL);
VCL_STRING VRT_r_bereq_url(const struct vrt_ctx *);
void VRT_l_bereq_url(const struct vrt_ctx *, const char *, ...);
VCL_STRING VRT_r_bereq_xid(const struct vrt_ctx *);
VCL_HTTP VRT_r_beresp(const struct vrt_ctx *);
VCL_IP VRT_r_beresp_backend_ip(const struct vrt_ctx *);
VCL_STRING VRT_r_beresp_backend_name(const struct vrt_ctx *);
VCL_BOOL VRT_r_beresp_do_esi(const struct vrt_ctx *);
void VRT_l_beresp_do_esi(const struct vrt_ctx *, VCL_BOOL);
VCL_BOOL VRT_r_beresp_do_gunzip(const struct vrt_ctx *);
void VRT_l_beresp_do_gunzip(const struct vrt_ctx *, VCL_BOOL);
VCL_BOOL VRT_r_beresp_do_gzip(const struct vrt_ctx *);
void VRT_l_beresp_do_gzip(const struct vrt_ctx *, VCL_BOOL);
VCL_BOOL VRT_r_beresp_do_stream(const struct vrt_ctx *);
void VRT_l_beresp_do_stream(const struct vrt_ctx *, VCL_BOOL);
VCL_DURATION VRT_r_beresp_grace(const struct vrt_ctx *);
void VRT_l_beresp_grace(const struct vrt_ctx *, VCL_DURATION);
VCL_DURATION VRT_r_beresp_keep(const struct vrt_ctx *);
void VRT_l_beresp_keep(const struct vrt_ctx *, VCL_DURATION);
VCL_STRING VRT_r_beresp_proto(const struct vrt_ctx *);
void VRT_l_beresp_proto(const struct vrt_ctx *, const char *, ...);
VCL_STRING VRT_r_beresp_reason(const struct vrt_ctx *);
void VRT_l_beresp_reason(const struct vrt_ctx *, const char *, ...);
VCL_INT VRT_r_beresp_status(const struct vrt_ctx *);
void VRT_l_beresp_status(const struct vrt_ctx *, VCL_INT);
VCL_STRING VRT_r_beresp_storage_hint(const struct vrt_ctx *);
void VRT_l_beresp_storage_hint(const struct vrt_ctx *, const char *, ...);
VCL_DURATION VRT_r_beresp_ttl(const struct vrt_ctx *);
void VRT_l_beresp_ttl(const struct vrt_ctx *, VCL_DURATION);
VCL_BOOL VRT_r_beresp_uncacheable(const struct vrt_ctx *);
void VRT_l_beresp_uncacheable(const struct vrt_ctx *, VCL_BOOL);
VCL_STRING VRT_r_client_identity(const struct vrt_ctx *);
void VRT_l_client_identity(const struct vrt_ctx *, const char *, ...);
VCL_IP VRT_r_client_ip(const struct vrt_ctx *);
VCL_TIME VRT_r_now(const struct vrt_ctx *);
VCL_DURATION VRT_r_obj_grace(const struct vrt_ctx *);
VCL_INT VRT_r_obj_hits(const struct vrt_ctx *);
VCL_DURATION VRT_r_obj_keep(const struct vrt_ctx *);
VCL_STRING VRT_r_obj_proto(const struct vrt_ctx *);
VCL_STRING VRT_r_obj_reason(const struct vrt_ctx *);
VCL_INT VRT_r_obj_status(const struct vrt_ctx *);
VCL_DURATION VRT_r_obj_ttl(const struct vrt_ctx *);
VCL_BOOL VRT_r_obj_uncacheable(const struct vrt_ctx *);
VCL_HTTP VRT_r_req(const struct vrt_ctx *);
VCL_BACKEND VRT_r_req_backend_hint(const struct vrt_ctx *);
void VRT_l_req_backend_hint(const struct vrt_ctx *, VCL_BACKEND);
VCL_BOOL VRT_r_req_can_gzip(const struct vrt_ctx *);
VCL_BOOL VRT_r_req_esi(const struct vrt_ctx *);
void VRT_l_req_esi(const struct vrt_ctx *, VCL_BOOL);
VCL_INT VRT_r_req_esi_level(const struct vrt_ctx *);
VCL_BOOL VRT_r_req_hash_always_miss(const struct vrt_ctx *);
void VRT_l_req_hash_always_miss(const struct vrt_ctx *, VCL_BOOL);
VCL_BOOL VRT_r_req_hash_ignore_busy(const struct vrt_ctx *);
void VRT_l_req_hash_ignore_busy(const struct vrt_ctx *, VCL_BOOL);
VCL_STRING VRT_r_req_method(const struct vrt_ctx *);
void VRT_l_req_method(const struct vrt_ctx *, const char *, ...);
VCL_STRING VRT_r_req_proto(const struct vrt_ctx *);
void VRT_l_req_proto(const struct vrt_ctx *, const char *, ...);
VCL_INT VRT_r_req_restarts(const struct vrt_ctx *);
VCL_DURATION VRT_r_req_ttl(const struct vrt_ctx *);
void VRT_l_req_ttl(const struct vrt_ctx *, VCL_DURATION);
VCL_STRING VRT_r_req_url(const struct vrt_ctx *);
void VRT_l_req_url(const struct vrt_ctx *, const char *, ...);
VCL_STRING VRT_r_req_xid(const struct vrt_ctx *);
VCL_HTTP VRT_r_resp(const struct vrt_ctx *);
VCL_STRING VRT_r_resp_proto(const struct vrt_ctx *);
void VRT_l_resp_proto(const struct vrt_ctx *, const char *, ...);
VCL_STRING VRT_r_resp_reason(const struct vrt_ctx *);
void VRT_l_resp_reason(const struct vrt_ctx *, const char *, ...);
VCL_INT VRT_r_resp_status(const struct vrt_ctx *);
void VRT_l_resp_status(const struct vrt_ctx *, VCL_INT);
VCL_STRING VRT_r_server_hostname(const struct vrt_ctx *);
VCL_STRING VRT_r_server_identity(const struct vrt_ctx *);
VCL_IP VRT_r_server_ip(const struct vrt_ctx *);
double VRT_Stv_free_space(const char *);
double VRT_Stv_used_space(const char *);
unsigned VRT_Stv_happy(const char *);
/* ---===### VCC generated code ###===---*/
extern const struct VCL_conf VCL_conf;
#define VGCDIR(n) VCL_conf.director[VGC_backend_##n]
#define __match_proto__(xxx) /*lint -e{818} */
/* --- BEGIN VMOD std --- */
static void *VGC_vmod_std;
static struct vmod_priv vmod_priv_std;
/* Functions */
typedef VCL_STRING td_std_toupper(const struct vrt_ctx *,
const char *, ...);
typedef VCL_STRING td_std_tolower(const struct vrt_ctx *,
const char *, ...);
typedef VCL_VOID td_std_set_ip_tos(const struct vrt_ctx *,
VCL_INT);
typedef VCL_REAL td_std_random(const struct vrt_ctx *, VCL_REAL,
VCL_REAL);
typedef VCL_VOID td_std_log(const struct vrt_ctx *,
const char *, ...);
typedef VCL_VOID td_std_syslog(const struct vrt_ctx *, VCL_INT,
const char *, ...);
typedef VCL_STRING td_std_fileread(const struct vrt_ctx *,
struct vmod_priv *, VCL_STRING);
typedef VCL_VOID td_std_collect(const struct vrt_ctx *,
VCL_HEADER);
typedef VCL_DURATION td_std_duration(const struct vrt_ctx *,
VCL_STRING, VCL_DURATION);
typedef VCL_INT td_std_integer(const struct vrt_ctx *,
VCL_STRING, VCL_INT);
typedef VCL_IP td_std_ip(const struct vrt_ctx *, VCL_STRING,
VCL_IP);
typedef VCL_REAL td_std_real(const struct vrt_ctx *, VCL_STRING,
VCL_REAL);
typedef VCL_TIME td_std_real2time(const struct vrt_ctx *,
VCL_REAL);
typedef VCL_INT td_std_time2integer(const struct vrt_ctx *,
VCL_TIME);
typedef VCL_REAL td_std_time2real(const struct vrt_ctx *,
VCL_TIME);
typedef VCL_BOOL td_std_healthy(const struct vrt_ctx *,
VCL_BACKEND);
typedef VCL_INT td_std_port(const struct vrt_ctx *, VCL_IP);
typedef VCL_VOID td_std_rollback(const struct vrt_ctx *,
VCL_HTTP);
typedef VCL_VOID td_std_timestamp(const struct vrt_ctx *,
VCL_STRING);
typedef VCL_STRING td_std_querysort(const struct vrt_ctx *,
VCL_STRING);
typedef VCL_STRING td_std_strstr(const struct vrt_ctx *,
VCL_STRING, VCL_STRING);
struct Vmod_std_Func {
/* Functions */
td_std_toupper *toupper;
td_std_tolower *tolower;
td_std_set_ip_tos *set_ip_tos;
td_std_random *random;
td_std_log *log;
td_std_syslog *syslog;
td_std_fileread *fileread;
td_std_collect *collect;
td_std_duration *duration;
td_std_integer *integer;
td_std_ip *ip;
td_std_real *real;
td_std_real2time *real2time;
td_std_time2integer *time2integer;
td_std_time2real *time2real;
td_std_healthy *healthy;
td_std_port *port;
td_std_rollback *rollback;
td_std_timestamp *timestamp;
td_std_querysort *querysort;
td_std_strstr *strstr;
/* Init/Fini */
};
static struct Vmod_std_Func Vmod_std_Func;
/* --- END VMOD std --- */
/* --- BEGIN VMOD directors --- */
static void *VGC_vmod_directors;
static struct vmod_priv vmod_priv_directors;
/* Object round_robin */
struct vmod_directors_round_robin;
typedef VCL_VOID td_directors_round_robin__init(
const struct vrt_ctx *, struct vmod_directors_round_robin **,
const char *);
typedef VCL_VOID td_directors_round_robin__fini(
struct vmod_directors_round_robin **);
typedef VCL_VOID td_directors_round_robin_add_backend(
const struct vrt_ctx *, struct vmod_directors_round_robin *,
VCL_BACKEND);
typedef VCL_BACKEND td_directors_round_robin_backend(
const struct vrt_ctx *, struct vmod_directors_round_robin *);
/* Object fallback */
struct vmod_directors_fallback;
typedef VCL_VOID td_directors_fallback__init(
const struct vrt_ctx *, struct vmod_directors_fallback **,
const char *);
typedef VCL_VOID td_directors_fallback__fini(
struct vmod_directors_fallback **);
typedef VCL_VOID td_directors_fallback_add_backend(
const struct vrt_ctx *, struct vmod_directors_fallback *,
VCL_BACKEND);
typedef VCL_BACKEND td_directors_fallback_backend(
const struct vrt_ctx *, struct vmod_directors_fallback *);
/* Object random */
struct vmod_directors_random;
typedef VCL_VOID td_directors_random__init(
const struct vrt_ctx *, struct vmod_directors_random **,
const char *);
typedef VCL_VOID td_directors_random__fini(
struct vmod_directors_random **);
typedef VCL_VOID td_directors_random_add_backend(
const struct vrt_ctx *, struct vmod_directors_random *,
VCL_BACKEND, VCL_REAL);
typedef VCL_BACKEND td_directors_random_backend(
const struct vrt_ctx *, struct vmod_directors_random *);
/* Object hash */
struct vmod_directors_hash;
typedef VCL_VOID td_directors_hash__init(const struct vrt_ctx *,
struct vmod_directors_hash **, const char *);
typedef VCL_VOID td_directors_hash__fini(
struct vmod_directors_hash **);
typedef VCL_VOID td_directors_hash_add_backend(
const struct vrt_ctx *, struct vmod_directors_hash *,
VCL_BACKEND, VCL_REAL);
typedef VCL_BACKEND td_directors_hash_backend(
const struct vrt_ctx *, struct vmod_directors_hash *,
const char *, ...);
struct Vmod_directors_Func {
/* Object round_robin */
td_directors_round_robin__init *round_robin__init;
td_directors_round_robin__fini *round_robin__fini;
td_directors_round_robin_add_backend
*round_robin_add_backend;
td_directors_round_robin_backend
*round_robin_backend;
/* Object fallback */
td_directors_fallback__init *fallback__init;
td_directors_fallback__fini *fallback__fini;
td_directors_fallback_add_backend
*fallback_add_backend;
td_directors_fallback_backend *fallback_backend;
/* Object random */
td_directors_random__init *random__init;
td_directors_random__fini *random__fini;
td_directors_random_add_backend *random_add_backend;
td_directors_random_backend *random_backend;
/* Object hash */
td_directors_hash__init *hash__init;
td_directors_hash__fini *hash__fini;
td_directors_hash_add_backend *hash_add_backend;
td_directors_hash_backend *hash_backend;
/* Functions */
/* Init/Fini */
};
static struct Vmod_directors_Func Vmod_directors_Func;
/* --- END VMOD directors --- */
#define VGC_backend__nginx 1
/* "127.0.0.1" -> 127.0.0.1 */
static const unsigned long long sockaddr_0[4] = {
0x901f00024b1e9335LL,
0x000000000100007fLL,
0x0000000000000000LL,
0x0000000000000000LL
};
static const struct vrt_backend vgc_dir_priv__nginx = {
.vcl_name = "nginx",
.ipv4_suckaddr = (const struct suckaddr *)(const void*)sockaddr_0,
.ipv4_addr = "127.0.0.1",
.port = "8080",
.hosthdr = "127.0.0.1",
};
#define VGC_backend__apache 2
/* "127.0.0.1" -> 127.0.0.1 */
static const unsigned long long sockaddr_1[4] = {
0x580000024b1e9335LL,
0x000000000100007fLL,
0x0000000000000000LL,
0x0000000000000000LL
};
static const struct vrt_backend vgc_dir_priv__apache = {
.vcl_name = "apache",
.ipv4_suckaddr = (const struct suckaddr *)(const void*)sockaddr_1,
.ipv4_addr = "127.0.0.1",
.port = "88",
.hosthdr = "127.0.0.1",
};
static struct vmod_directors_hash *vo_vdir;
static const struct gethdr_s VGC_HDR_REQ_header_X_Forwarded_For =
{ HDR_REQ, "\027header.X-Forwarded-For:"};
static const struct gethdr_s VGC_HDR_REQ_Authorization =
{ HDR_REQ, "\016Authorization:"};
static void *VGC_re_2;
static const struct gethdr_s VGC_HDR_REQ_Cookie =
{ HDR_REQ, "\007Cookie:"};
static void *VGC_re_3;
static const struct gethdr_s VGC_HDR_REQ_host =
{ HDR_REQ, "\005host:"};
static void *VGC_re_4;
static const struct gethdr_s VGC_HDR_REQ_FilterURL =
{ HDR_REQ, "\012FilterURL:"};
static void *VGC_re_5;
static void *VGC_re_6;
static void *VGC_re_7;
static void *VGC_re_8;
static const struct gethdr_s VGC_HDR_REQ_upgrade =
{ HDR_REQ, "\010upgrade:"};
static const struct gethdr_s VGC_HDR_BEREQ_upgrade =
{ HDR_BEREQ, "\010upgrade:"};
static const struct gethdr_s VGC_HDR_BERESP_content_type =
{ HDR_BERESP, "\015content-type:"};
static void *VGC_re_9;
static const struct gethdr_s VGC_HDR_RESP_X_Varnish_Backend =
{ HDR_RESP, "\022X-Varnish-Backend:"};
static const struct gethdr_s VGC_HDR_RESP_X_Varnish_FilterURL =
{ HDR_RESP, "\024X-Varnish-FilterURL:"};
static const struct gethdr_s VGC_HDR_RESP_Content_Type =
{ HDR_RESP, "\015Content-Type:"};
static const struct gethdr_s VGC_HDR_RESP_Retry_After =
{ HDR_RESP, "\014Retry-After:"};
static const struct gethdr_s VGC_HDR_BERESP_Set_Cookie =
{ HDR_BERESP, "\013Set-Cookie:"};
static const struct gethdr_s VGC_HDR_BERESP_Surrogate_control =
{ HDR_BERESP, "\022Surrogate-control:"};
static void *VGC_re_10;
static const struct gethdr_s VGC_HDR_BERESP_Surrogate_Control =
{ HDR_BERESP, "\022Surrogate-Control:"};
static const struct gethdr_s VGC_HDR_BERESP_Cache_Control =
{ HDR_BERESP, "\016Cache-Control:"};
static void *VGC_re_11;
static const struct gethdr_s VGC_HDR_BERESP_Vary =
{ HDR_BERESP, "\005Vary:"};
static const struct gethdr_s VGC_HDR_BERESP_Content_Type =
{ HDR_BERESP, "\015Content-Type:"};
static const struct gethdr_s VGC_HDR_BERESP_Retry_After =
{ HDR_BERESP, "\014Retry-After:"};
int __match_proto__(vcl_func_f)
VGC_function_vcl_recv(const struct vrt_ctx *ctx);
int __match_proto__(vcl_func_f)
VGC_function_vcl_pipe(const struct vrt_ctx *ctx);
int __match_proto__(vcl_func_f)
VGC_function_vcl_pass(const struct vrt_ctx *ctx);
int __match_proto__(vcl_func_f)
VGC_function_vcl_hash(const struct vrt_ctx *ctx);
int __match_proto__(vcl_func_f)
VGC_function_vcl_purge(const struct vrt_ctx *ctx);
int __match_proto__(vcl_func_f)
VGC_function_vcl_miss(const struct vrt_ctx *ctx);
int __match_proto__(vcl_func_f)
VGC_function_vcl_hit(const struct vrt_ctx *ctx);
int __match_proto__(vcl_func_f)
VGC_function_vcl_deliver(const struct vrt_ctx *ctx);
int __match_proto__(vcl_func_f)
VGC_function_vcl_synth(const struct vrt_ctx *ctx);
int __match_proto__(vcl_func_f)
VGC_function_vcl_backend_fetch(const struct vrt_ctx *ctx);
int __match_proto__(vcl_func_f)
VGC_function_vcl_backend_response(const struct vrt_ctx *ctx);
int __match_proto__(vcl_func_f)
VGC_function_vcl_backend_error(const struct vrt_ctx *ctx);
int __match_proto__(vcl_func_f)
VGC_function_vcl_init(const struct vrt_ctx *ctx);
int __match_proto__(vcl_func_f)
VGC_function_vcl_fini(const struct vrt_ctx *ctx);
#define VGC_NREFS 67
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <hiredis.h>
int __match_proto__(vcl_func_f)
VGC_function_vcl_recv(const struct vrt_ctx *ctx)
{
/* ... from ('input' Line 45 Pos 5) */
{
{
VRT_count(ctx, 2);
VRT_l_req_backend_hint(ctx,
Vmod_directors_Func.hash_backend(ctx, vo_vdir,
VRT_r_req_url(ctx),
vrt_magic_string_end)
);
VRT_SetHdr(ctx, &VGC_HDR_REQ_header_X_Forwarded_For,
"14.18.151.170",
vrt_magic_string_end
);
if (
(
VRT_strcmp(VRT_r_req_method(ctx), "GET")&&
VRT_strcmp(VRT_r_req_method(ctx), "HEAD")&&
VRT_strcmp(VRT_r_req_method(ctx), "PUT")&&
VRT_strcmp(VRT_r_req_method(ctx), "POST")&&
VRT_strcmp(VRT_r_req_method(ctx), "TRACE")&&
VRT_strcmp(VRT_r_req_method(ctx), "OPTIONS")&&
VRT_strcmp(VRT_r_req_method(ctx), "PATCH")&&
VRT_strcmp(VRT_r_req_method(ctx), "DELETE"))
)
{
VRT_count(ctx, 3);
VRT_handling(ctx, VCL_RET_PIPE);
return (1);
}
VRT_count(ctx, 4);
if (
(
VRT_strcmp(VRT_r_req_method(ctx), "GET")&&
VRT_strcmp(VRT_r_req_method(ctx), "HEAD"))
)
{
VRT_count(ctx, 5);
VRT_handling(ctx, VCL_RET_PASS);
return (1);
}
VRT_count(ctx, 6);
if (
(VRT_GetHdr(ctx, &VGC_HDR_REQ_Authorization) != 0)
)
{
VRT_count(ctx, 7);
VRT_handling(ctx, VCL_RET_PASS);
return (1);
}
VRT_count(ctx, 8);
if (
VRT_re_match(ctx, VRT_r_req_url(ctx), VGC_re_2)
)
{
VRT_count(ctx, 9);
VRT_l_req_backend_hint(ctx,
VGCDIR(_nginx)
);
VRT_SetHdr(ctx, &VGC_HDR_REQ_Cookie, vrt_magic_string_unset);
VRT_handling(ctx, VCL_RET_PASS);
return (1);
}
VRT_count(ctx, 10);
if (
VRT_re_match(ctx, VRT_r_req_url(ctx), VGC_re_3)
)
{
VRT_count(ctx, 11);
VRT_l_req_backend_hint(ctx,
VGCDIR(_nginx)
);
}
VRT_count(ctx, 12);
if (
!VRT_strcmp(VRT_GetHdr(ctx, &VGC_HDR_REQ_host), "papi_dev.mama.cn")
)
{
VRT_count(ctx, 13);
if (
VRT_re_match(ctx, VRT_r_req_url(ctx), VGC_re_4)
)
{
VRT_count(ctx, 14);
VRT_handling(ctx, VCL_RET_PIPE);
return (1);
}
VRT_count(ctx, 15);
VRT_SetHdr(ctx, &VGC_HDR_REQ_FilterURL,
VRT_regsub(ctx, 1,
VRT_r_req_url(ctx),
VGC_re_5,
""),
vrt_magic_string_end
);
VRT_l_req_backend_hint(ctx,
Vmod_directors_Func.hash_backend(ctx, vo_vdir,
VRT_GetHdr(ctx, &VGC_HDR_REQ_FilterURL),
vrt_magic_string_end)
);
if (
VRT_re_match(ctx, VRT_r_req_url(ctx), VGC_re_6)
)
{
VRT_count(ctx, 16);
VRT_handling(ctx, VCL_RET_PIPE);
return (1);
}
VRT_count(ctx, 17);
if (
VRT_re_match(ctx, VRT_r_req_url(ctx), VGC_re_7)
)
{
VRT_count(ctx, 18);
VRT_handling(ctx, VCL_RET_PIPE);
return (1);
}
VRT_count(ctx, 19);
if (
VRT_re_match(ctx, VRT_r_req_url(ctx), VGC_re_8)
)
{
VRT_count(ctx, 20);
VRT_handling(ctx, VCL_RET_PIPE);
return (1);
}
VRT_count(ctx, 21);
}
VRT_count(ctx, 22);
if (
VRT_strcmp(VRT_GetHdr(ctx, &VGC_HDR_REQ_host), "papi_dev.mama.cn")
)
{
VRT_count(ctx, 23);
VRT_handling(ctx, VCL_RET_PIPE);
return (1);
}
VRT_count(ctx, 24);
VRT_handling(ctx, VCL_RET_HASH);
return (1);
}
}
/* ... from ('Builtin' Line 47 Pos 5) */
{
{
VRT_count(ctx, 37);
if (
!VRT_strcmp(VRT_r_req_method(ctx), "PRI")
)
{
VRT_count(ctx, 38);
VRT_error(ctx,
405
,
(const char*)0
);
VRT_handling(ctx, VCL_RET_SYNTH);
return (1);
}
VRT_count(ctx, 39);
if (
(
VRT_strcmp(VRT_r_req_method(ctx), "GET")&&
VRT_strcmp(VRT_r_req_method(ctx), "HEAD")&&
VRT_strcmp(VRT_r_req_method(ctx), "PUT")&&
VRT_strcmp(VRT_r_req_method(ctx), "POST")&&
VRT_strcmp(VRT_r_req_method(ctx), "TRACE")&&
VRT_strcmp(VRT_r_req_method(ctx), "OPTIONS")&&
VRT_strcmp(VRT_r_req_method(ctx), "DELETE"))
)
{
VRT_count(ctx, 40);
VRT_handling(ctx, VCL_RET_PIPE);
return (1);
}
VRT_count(ctx, 41);
if (
(
VRT_strcmp(VRT_r_req_method(ctx), "GET")&&
VRT_strcmp(VRT_r_req_method(ctx), "HEAD"))
)
{
VRT_count(ctx, 42);
VRT_handling(ctx, VCL_RET_PASS);
return (1);
}
VRT_count(ctx, 43);
if (
(
(VRT_GetHdr(ctx, &VGC_HDR_REQ_Authorization) != 0)||
(VRT_GetHdr(ctx, &VGC_HDR_REQ_Cookie) != 0))
)
{
VRT_count(ctx, 44);
VRT_handling(ctx, VCL_RET_PASS);
return (1);
}
VRT_count(ctx, 45);
VRT_handling(ctx, VCL_RET_HASH);
return (1);
}
}
}
int __match_proto__(vcl_func_f)
VGC_function_vcl_pipe(const struct vrt_ctx *ctx)
{
/* ... from ('input' Line 104 Pos 5) */
{
{
VRT_count(ctx, 28);
if (
(VRT_GetHdr(ctx, &VGC_HDR_REQ_upgrade) != 0)
)
{
VRT_count(ctx, 29);
VRT_SetHdr(ctx, &VGC_HDR_BEREQ_upgrade,
VRT_GetHdr(ctx, &VGC_HDR_REQ_upgrade),
vrt_magic_string_end
);
}
VRT_count(ctx, 30);
VRT_handling(ctx, VCL_RET_PIPE);
return (1);
}
}
/* ... from ('Builtin' Line 74 Pos 5) */
{
{
VRT_count(ctx, 46);
VRT_handling(ctx, VCL_RET_PIPE);
return (1);
}
}
}
int __match_proto__(vcl_func_f)
VGC_function_vcl_pass(const struct vrt_ctx *ctx)
{
/* ... from ('input' Line 111 Pos 5) */
{
{
VRT_count(ctx, 31);
}
}
/* ... from ('Builtin' Line 83 Pos 5) */
{
{
VRT_count(ctx, 47);
VRT_handling(ctx, VCL_RET_FETCH);
return (1);
}
}
}
int __match_proto__(vcl_func_f)
VGC_function_vcl_hash(const struct vrt_ctx *ctx)
{
/* ... from ('input' Line 97 Pos 5) */
{
{
VRT_count(ctx, 25);
if (
!VRT_strcmp(VRT_GetHdr(ctx, &VGC_HDR_REQ_host), "papi_dev.mama.cn")
)
{
VRT_count(ctx, 26);
VRT_hashdata(ctx,
VRT_GetHdr(ctx, &VGC_HDR_REQ_FilterURL),
vrt_magic_string_end
);
}
VRT_count(ctx, 27);
VRT_handling(ctx, VCL_RET_LOOKUP);
return (1);
}
}
/* ... from ('Builtin' Line 87 Pos 5) */
{
{
VRT_count(ctx, 48);
VRT_hashdata(ctx,
VRT_r_req_url(ctx),
vrt_magic_string_end
);
if (
(VRT_GetHdr(ctx, &VGC_HDR_REQ_host) != 0)
)
{
VRT_count(ctx, 49);
VRT_hashdata(ctx,
VRT_GetHdr(ctx, &VGC_HDR_REQ_host),
vrt_magic_string_end
);
}
else
{
VRT_count(ctx, 50);
VRT_hashdata(ctx,
VRT_IP_string(ctx, VRT_r_server_ip(ctx)),
vrt_magic_string_end
);
}
VRT_handling(ctx, VCL_RET_LOOKUP);
return (1);
}
}
}
int __match_proto__(vcl_func_f)
VGC_function_vcl_purge(const struct vrt_ctx *ctx)
{
/* ... from ('Builtin' Line 97 Pos 5) */
{
{
VRT_count(ctx, 51);
VRT_error(ctx,
200
,
"Purged"
);
VRT_handling(ctx, VCL_RET_SYNTH);
return (1);
}
}
}
int __match_proto__(vcl_func_f)
VGC_function_vcl_miss(const struct vrt_ctx *ctx)
{
/* ... from ('Builtin' Line 115 Pos 5) */
{
{
VRT_count(ctx, 57);
VRT_handling(ctx, VCL_RET_FETCH);
return (1);
}
}
}
int __match_proto__(vcl_func_f)
VGC_function_vcl_hit(const struct vrt_ctx *ctx)
{
/* ... from ('Builtin' Line 101 Pos 5) */
{
{
VRT_count(ctx, 52);
if (
(VRT_r_obj_ttl(ctx) >= 0)
)
{
VRT_count(ctx, 53);
VRT_handling(ctx, VCL_RET_DELIVER);
return (1);
}
VRT_count(ctx, 54);
if (
((VRT_r_obj_ttl(ctx)+VRT_r_obj_grace(ctx)) > 0)
)
{
VRT_count(ctx, 55);
VRT_handling(ctx, VCL_RET_DELIVER);
return (1);
}
VRT_count(ctx, 56);
VRT_handling(ctx, VCL_RET_FETCH);
return (1);
}
}
}
int __match_proto__(vcl_func_f)
VGC_function_vcl_deliver(const struct vrt_ctx *ctx)
{
/* ... from ('input' Line 139 Pos 5) */
{
{
VRT_count(ctx, 36);
VRT_SetHdr(ctx, &VGC_HDR_RESP_X_Varnish_Backend,
VRT_BACKEND_string(VRT_r_req_backend_hint(ctx)),
vrt_magic_string_end
);
VRT_SetHdr(ctx, &VGC_HDR_RESP_X_Varnish_FilterURL,
VRT_GetHdr(ctx, &VGC_HDR_REQ_FilterURL),
vrt_magic_string_end
);
}
}
/* ... from ('Builtin' Line 119 Pos 5) */
{
{
VRT_count(ctx, 58);
VRT_handling(ctx, VCL_RET_DELIVER);
return (1);
}
}
}
int __match_proto__(vcl_func_f)
VGC_function_vcl_synth(const struct vrt_ctx *ctx)
{
/* ... from ('Builtin' Line 126 Pos 5) */
{
{
VRT_count(ctx, 59);
VRT_SetHdr(ctx, &VGC_HDR_RESP_Content_Type,
"text/html; charset=utf-8",
vrt_magic_string_end
);
VRT_SetHdr(ctx, &VGC_HDR_RESP_Retry_After,
"5",
vrt_magic_string_end
);
VRT_synth_page(ctx, "<!DOCTYPE html>\n"
"<html>\n"
" <head>\n"
" <title>",
VRT_INT_string(ctx, VRT_r_resp_status(ctx)),
" ",
VRT_r_resp_reason(ctx),
"</title>\n"
" </head>\n"
" <body>\n"
" <h1>Error ",
VRT_INT_string(ctx, VRT_r_resp_status(ctx)),
" ",
VRT_r_resp_reason(ctx),
"</h1>\n"
" <p>",
VRT_r_resp_reason(ctx),
"</p>\n"
" <h3>Guru Meditation:</h3>\n"
" <p>XID: ",
VRT_r_req_xid(ctx),
"</p>\n"
" <hr>\n"
" <p>Varnish cache server</p>\n"
" </body>\n"
"</html>\n"
"",
vrt_magic_string_end
);
VRT_handling(ctx, VCL_RET_DELIVER);
return (1);
}
}
}
int __match_proto__(vcl_func_f)
VGC_function_vcl_backend_fetch(const struct vrt_ctx *ctx)
{
/* ... from ('input' Line 128 Pos 5) */
{
{
VRT_count(ctx, 35);
}
}
/* ... from ('Builtin' Line 150 Pos 5) */
{
{
VRT_count(ctx, 60);
VRT_handling(ctx, VCL_RET_FETCH);
return (1);
}
}
}
int __match_proto__(vcl_func_f)
VGC_function_vcl_backend_response(const struct vrt_ctx *ctx)
{
/* ... from ('input' Line 114 Pos 5) */
{
{
VRT_count(ctx, 32);
if (
VRT_re_match(ctx, VRT_GetHdr(ctx, &VGC_HDR_BERESP_content_type), VGC_re_9)
)
{
VRT_count(ctx, 33);
VRT_l_beresp_do_gzip(ctx,
(0==0)
);
}
VRT_count(ctx, 34);
VRT_handling(ctx, VCL_RET_DELIVER);
return (1);
}
}
/* ... from ('Builtin' Line 154 Pos 5) */
{
{
VRT_count(ctx, 61);
if (
(
(VRT_r_beresp_ttl(ctx) <= 0)||
(VRT_GetHdr(ctx, &VGC_HDR_BERESP_Set_Cookie) != 0)||
VRT_re_match(ctx, VRT_GetHdr(ctx, &VGC_HDR_BERESP_Surrogate_control), VGC_re_10)||
((
!((VRT_GetHdr(ctx, &VGC_HDR_BERESP_Surrogate_Control) != 0))&&
VRT_re_match(ctx, VRT_GetHdr(ctx, &VGC_HDR_BERESP_Cache_Control), VGC_re_11)))||
!VRT_strcmp(VRT_GetHdr(ctx, &VGC_HDR_BERESP_Vary), "*"))
)
{
VRT_count(ctx, 62);
VRT_l_beresp_ttl(ctx,
120
);
VRT_l_beresp_uncacheable(ctx,
(0==0)
);
}
VRT_count(ctx, 63);
VRT_handling(ctx, VCL_RET_DELIVER);
return (1);
}
}
}
int __match_proto__(vcl_func_f)
VGC_function_vcl_backend_error(const struct vrt_ctx *ctx)
{
/* ... from ('Builtin' Line 170 Pos 5) */
{
{
VRT_count(ctx, 64);
VRT_SetHdr(ctx, &VGC_HDR_BERESP_Content_Type,
"text/html; charset=utf-8",
vrt_magic_string_end
);
VRT_SetHdr(ctx, &VGC_HDR_BERESP_Retry_After,
"5",
vrt_magic_string_end
);
VRT_synth_page(ctx, "<!DOCTYPE html>\n"
"<html>\n"
" <head>\n"
" <title>",
VRT_INT_string(ctx, VRT_r_beresp_status(ctx)),
" ",
VRT_r_beresp_reason(ctx),
"</title>\n"
" </head>\n"
" <body>\n"
" <h1>Error ",
VRT_INT_string(ctx, VRT_r_beresp_status(ctx)),
" ",
VRT_r_beresp_reason(ctx),
"</h1>\n"
" <p>",
VRT_r_beresp_reason(ctx),
"</p>\n"
" <h3>Guru Meditation:</h3>\n"
" <p>XID: ",
VRT_r_bereq_xid(ctx),
"</p>\n"
" <hr>\n"
" <p>Varnish cache server</p>\n"
" </body>\n"
"</html>\n"
"",
vrt_magic_string_end
);
VRT_handling(ctx, VCL_RET_DELIVER);
return (1);
}
}
}
int __match_proto__(vcl_func_f)
VGC_function_vcl_init(const struct vrt_ctx *ctx)
{
/* ... from ('input' Line 35 Pos 5) */
{
{
VRT_count(ctx, 1);
Vmod_directors_Func.hash__init(ctx, &vo_vdir, "vdir");
Vmod_directors_Func.hash_add_backend(ctx, vo_vdir,
VGCDIR(_nginx),
1.000000);
Vmod_directors_Func.hash_add_backend(ctx, vo_vdir,
VGCDIR(_apache),
1.000000);
{
redisContext *c;
c = redisConnect("127.0.0.1", 6379);
}
}
}
/* ... from ('Builtin' Line 194 Pos 5) */
{
{
VRT_count(ctx, 65);
VRT_handling(ctx, VCL_RET_OK);
return (1);
}
}
}
int __match_proto__(vcl_func_f)
VGC_function_vcl_fini(const struct vrt_ctx *ctx)
{
/* ... from ('Builtin' Line 198 Pos 5) */
{
{
VRT_count(ctx, 66);
VRT_handling(ctx, VCL_RET_OK);
return (1);
}
}
}
static struct vrt_ref VGC_ref[VGC_NREFS] = {
[ 1] = { 0, 806, 36, 5, 0, "new" },
[ 2] = { 0, 999, 46, 5, 0, "set" },
[ 3] = { 0, 1373, 56, 9, 0, "return" },
[ 4] = { 0, 1398, 58, 5, 0, "if" },
[ 5] = { 0, 1457, 59, 9, 0, "return" },
[ 6] = { 0, 1482, 61, 5, 0, "if" },
[ 7] = { 0, 1520, 62, 9, 0, "return" },
[ 8] = { 0, 1545, 64, 5, 0, "if" },
[ 9] = { 0, 1671, 65, 9, 0, "set" },
[ 10] = { 0, 1830, 72, 5, 0, "if" },
[ 11] = { 0, 1867, 73, 9, 0, "set" },
[ 12] = { 0, 1907, 75, 5, 0, "if" },
[ 13] = { 0, 1958, 76, 9, 0, "if" },
[ 14] = { 0, 1987, 77, 13, 0, "return" },
[ 15] = { 0, 2013, 79, 9, 0, "set" },
[ 16] = { 0, 2198, 82, 13, 0, "return" },
[ 17] = { 0, 2217, 84, 9, 0, "if" },
[ 18] = { 0, 2253, 85, 13, 0, "return" },
[ 19] = { 0, 2272, 87, 9, 0, "if" },
[ 20] = { 0, 2306, 88, 13, 0, "return" },
[ 21] = { 0, 2328, 90, 5, 0, "}" },
[ 22] = { 0, 2334, 91, 5, 0, "if" },
[ 23] = { 0, 2385, 92, 9, 0, "return" },
[ 24] = { 0, 2410, 94, 5, 0, "return" },
[ 25] = { 0, 2447, 98, 5, 0, "if" },
[ 26] = { 0, 2499, 99, 10, 0, "hash_data" },
[ 27] = { 0, 2540, 101, 5, 0, "return" },
[ 28] = { 0, 2579, 105, 5, 0, "if" },
[ 29] = { 0, 2611, 106, 9, 0, "set" },
[ 30] = { 0, 2664, 108, 5, 0, "return" },
[ 31] = { 0, 2697, 112, 1, 0, "}" },
[ 32] = { 0, 2931, 119, 5, 0, "if" },
[ 33] = { 0, 2980, 120, 9, 0, "set" },
[ 34] = { 0, 3143, 125, 5, 0, "return" },
[ 35] = { 0, 3512, 137, 1, 0, "}" },
[ 36] = { 0, 3715, 144, 5, 0, "set" },
[ 37] = { 1, 1960, 48, 5, 0, "if" },
[ 38] = { 1, 2030, 50, 9, 0, "return" },
[ 39] = { 1, 2061, 52, 5, 0, "if" },
[ 40] = { 1, 2334, 60, 9, 0, "return" },
[ 41] = { 1, 2360, 63, 5, 0, "if" },
[ 42] = { 1, 2475, 65, 9, 0, "return" },
[ 43] = { 1, 2500, 67, 5, 0, "if" },
[ 44] = { 1, 2596, 69, 9, 0, "return" },
[ 45] = { 1, 2621, 71, 5, 0, "return" },
[ 46] = { 1, 2928, 80, 5, 0, "return" },
[ 47] = { 1, 2965, 84, 5, 0, "return" },
[ 48] = { 1, 3003, 88, 5, 0, "hash_data" },
[ 49] = { 1, 3056, 90, 9, 0, "hash_data" },
[ 50] = { 1, 3103, 92, 9, 0, "hash_data" },
[ 51] = { 1, 3175, 98, 5, 0, "return" },
[ 52] = { 1, 3227, 102, 5, 0, "if" },
[ 53] = { 1, 3302, 104, 9, 0, "return" },
[ 54] = { 1, 3330, 106, 5, 0, "if" },
[ 55] = { 1, 3465, 109, 9, 0, "return" },
[ 56] = { 1, 3539, 112, 5, 0, "return" },
[ 57] = { 1, 3577, 116, 5, 0, "return" },
[ 58] = { 1, 3618, 120, 5, 0, "return" },
[ 59] = { 1, 3740, 127, 5, 0, "set" },
[ 60] = { 1, 4328, 151, 5, 0, "return" },
[ 61] = { 1, 4378, 155, 5, 0, "if" },
[ 62] = { 1, 4714, 164, 9, 0, "set" },
[ 63] = { 1, 4786, 167, 5, 0, "return" },
[ 64] = { 1, 4835, 171, 5, 0, "set" },
[ 65] = { 1, 5429, 195, 5, 0, "return" },
[ 66] = { 1, 5464, 199, 5, 0, "return" },
};
static int
VGC_Init(struct cli *cli)
{
/* 1 */
if (VRT_Vmod_Init(&VGC_vmod_std,
&Vmod_std_Func,
sizeof(Vmod_std_Func),
"std",
"/usr/local/lib/varnish/vmods/libvmod_std.so",
"LUTPJVXPH@SICJX@@EZJWDJYKMXMAHKP",
cli))
return(1);
/* 2 */
if (VRT_Vmod_Init(&VGC_vmod_directors,
&Vmod_directors_Func,
sizeof(Vmod_directors_Func),
"directors",
"/usr/local/lib/varnish/vmods/libvmod_directors.so",
"RTMK@QXSH@EVHVHYTLKYXRFFMAMTVVVQ",
cli))
return(1);
/* 3 */
VRT_init_dir(cli, VCL_conf.director,
VGC_backend__nginx, &vgc_dir_priv__nginx);
/* 4 */
VRT_init_dir(cli, VCL_conf.director,
VGC_backend__apache, &vgc_dir_priv__apache);
/* 6 */
VRT_re_init(&VGC_re_2, "^[^?]*\\.(bmp|bz2|css|doc|eot|flv|gif|gz|ico|jpeg|jpg|js|less|pdf|png|rtf|swf|txt|woff|xml)(\\?.*)?$");
/* 7 */
VRT_re_init(&VGC_re_3, "^/typecho");
/* 8 */
VRT_re_init(&VGC_re_4, "&dy=c");
/* 9 */
VRT_re_init(&VGC_re_5, "(t|token|json|check_token|dy|dg)=[^&]+&*");
/* 10 */
VRT_re_init(&VGC_re_6, "[&\\?]dy=c");
/* 11 */
VRT_re_init(&VGC_re_7, "[&\\?]json=no");
/* 12 */
VRT_re_init(&VGC_re_8, "[&\\?]dg=ml");
/* 13 */
VRT_re_init(&VGC_re_9, "text");
/* 14 */
VRT_re_init(&VGC_re_10, "no-store");
/* 15 */
VRT_re_init(&VGC_re_11, "no-cache|no-store|private");
/* 16 */
VCL_conf.director[0] = VCL_conf.director[1];
return(0);
}
static void
VGC_Fini(struct cli *cli)
{
/* 15 */
VRT_re_fini(VGC_re_11);
/* 14 */
VRT_re_fini(VGC_re_10);
/* 13 */
VRT_re_fini(VGC_re_9);
/* 12 */
VRT_re_fini(VGC_re_8);
/* 11 */
VRT_re_fini(VGC_re_7);
/* 10 */
VRT_re_fini(VGC_re_6);
/* 9 */
VRT_re_fini(VGC_re_5);
/* 8 */
VRT_re_fini(VGC_re_4);
/* 7 */
VRT_re_fini(VGC_re_3);
/* 6 */
VRT_re_fini(VGC_re_2);
/* 5 */
Vmod_directors_Func.hash__fini(&vo_vdir);
/* 4 */
VRT_fini_dir(cli, VGCDIR(_apache));
/* 3 */
VRT_fini_dir(cli, VGCDIR(_nginx));
/* 2 */
VRT_priv_fini(&vmod_priv_directors);
VRT_Vmod_Fini(&VGC_vmod_directors);
/* 1 */
VRT_priv_fini(&vmod_priv_std);
VRT_Vmod_Fini(&VGC_vmod_std);
}
extern const char *srcname[];
const char *srcname[2] = {
"input",
"Builtin",
};
extern const char *srcbody[];
const char *srcbody[2] = {
/* "input"*/
"#\n"
"# This is an example VCL file for Varnish.\n"
"#\n"
"# It does not do anything by default, delegating control to the\n"
"# builtin VCL. The builtin VCL is called when there is no explicit\n"
"# return statement.\n"
"#\n"
"# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/\n"
"# and http://varnish-cache.org/trac/wiki/VCLExamples for more examples.\n"
"\n"
"# Marker to tell the VCL compiler that this VCL has been adapted to the\n"
"# new 4.0 format.\n"
"vcl 4.0;\n"
"\n"
"import std; \n"
"import directors;\n"
"C{\n"
" #include <stdio.h>\n"
" #include <stdlib.h>\n"
" #include <string.h>\n"
" #include <hiredis.h>\n"
"}C\n"
"\n"
"# Default backend definition. Set this to point to your content server.\n"
"backend nginx {\n"
" .host = \"127.0.0.1\";\n"
" .port = \"8080\";\n"
"}\n"
"\n"
"backend apache {\n"
" .host = \"127.0.0.1\";\n"
" .port = \"88\";\n"
"}\n"
"\n"
"sub vcl_init {\n"
" new vdir = directors.hash();\n"
" vdir.add_backend(nginx, 1);\n"
" vdir.add_backend(apache, 1);\n"
" C{\n"
" redisContext *c;\n"
"\tc = redisConnect(\"127.0.0.1\", 6379);\n"
" }C\n"
"}\n"
"\n"
"sub vcl_recv {\n"
" set req.backend_hint = vdir.backend(req.url);\n"
" set req.http.header.X-Forwarded-For = \"14.18.151.170\";\n"
" if (req.method != \"GET\" &&\n"
" req.method != \"HEAD\" &&\n"
" req.method != \"PUT\" &&\n"
" req.method != \"POST\" &&\n"
" req.method != \"TRACE\" &&\n"
" req.method != \"OPTIONS\" &&\n"
" req.method != \"PATCH\" &&\n"
" req.method != \"DELETE\") {\n"
" return (pipe);\n"
" }\n"
" if (req.method != \"GET\" && req.method != \"HEAD\") {\n"
" return (pass);\n"
" }\n"
" if (req.http.Authorization) {\n"
" return (pass);\n"
" }\n"
" if (req.url ~ \"^[^?]*\\.(bmp|bz2|css|doc|eot|flv|gif|gz|ico|jpeg|jpg|js|less|pdf|png|rtf|swf|txt|woff|xml)(\\?.*)?$\") {\n"
" set req.backend_hint = nginx;\n"
" unset req.http.Cookie;\n"
" return (pass);\n"
" }\n"
" #if (req.url ~ \"^/default\") {\n"
" # return (pipe);\n"
" #}\n"
" if (req.url ~ \"^/typecho\") {\n"
" set req.backend_hint = nginx;\n"
" }\n"
" if (req.http.host == \"papi_dev.mama.cn\") {\n"
" if(req.url ~ \"&dy=c\") {\n"
"\t return (pipe);\n"
"\t}\n"
" set req.http.FilterURL = regsuball(req.url, \"(t|token|json|check_token|dy|dg)=[^&]+&*\", \"\");\n"
"\tset req.backend_hint = vdir.backend(req.http.FilterURL);\n"
"\tif(req.url ~ \"[&\\?]dy=c\") {\n"
"\t return (pipe);\n"
"\t}\n"
"\tif(req.url ~ \"[&\\?]json=no\") {\n"
"\t return (pipe);\n"
"\t}\n"
"\tif(req.url ~ \"[&\\?]dg=ml\") {\n"
"\t return (pipe);\n"
"\t}\n"
" }\n"
" if (req.http.host != \"papi_dev.mama.cn\") {\n"
" return (pipe);\n"
" }\n"
" return (hash);\n"
"}\n"
"\n"
"sub vcl_hash {\n"
" if (req.http.host == \"papi_dev.mama.cn\") {\n"
" hash_data(req.http.FilterURL);\n"
" }\n"
" return (lookup);\n"
"}\n"
"\n"
"sub vcl_pipe {\n"
" if (req.http.upgrade) {\n"
" set bereq.http.upgrade = req.http.upgrade;\n"
" }\n"
" return (pipe);\n"
"}\n"
"\n"
"sub vcl_pass {\n"
"}\n"
"\n"
"sub vcl_backend_response {\n"
" # Happens after we have read the response headers from the backend.\n"
" # \n"
" # Here you clean the response headers, removing silly Set-Cookie headers\n"
" # and other mistakes your backend does.\n"
" if (beresp.http.content-type ~ \"text\") {\n"
" set beresp.do_gzip = true;\n"
" }\n"
" #if (beresp.http.Varnish-TTL != \"\") {\n"
" #set beresp.ttl = std.duration(beresp.http.Varnish-TTL, beresp.ttl);\n"
" #}\n"
" return (deliver);\n"
"}\n"
"\n"
"sub vcl_backend_fetch {\n"
" #if (beresp.http.header.Varnish-Do-Cache != \"Yes\") {\n"
" # set beresp.uncacheable = true;\n"
" # set beresp.http.header.Varnish-No-Cache = \"Yes\";\n"
" # return (fetch);\n"
" #}\n"
" #if (beresp.http.header.Varnish-TTL != \"\") {\n"
" # set beresp.ttl = std.duration(beresp.http.header.Varnish-TTL, obj.ttl);\n"
" #}\n"
"}\n"
"\n"
"sub vcl_deliver {\n"
" # Happens when we have all the pieces we need, and are about to send the\n"
" # response to the client.\n"
" # \n"
" # You can do accounting or modifying the final object here.\n"
" set resp.http.X-Varnish-Backend = req.backend_hint;\n"
" set resp.http.X-Varnish-FilterURL = req.http.FilterURL;\n"
"}\n"
"",
/* "Builtin"*/
"/*-\n"
" * Copyright (c) 2006 Verdens Gang AS\n"
" * Copyright (c) 2006-2014 Varnish Software AS\n"
" * All rights reserved.\n"
" *\n"
" * Author: Poul-Henning Kamp <phk@phk.freebsd.dk>\n"
" *\n"
" * Redistribution and use in source and binary forms, with or without\n"
" * modification, are permitted provided that the following conditions\n"
" * are met:\n"
" * 1. Redistributions of source code must retain the above copyright\n"
" * notice, this list of conditions and the following disclaimer.\n"
" * 2. Redistributions in binary form must reproduce the above copyright\n"
" * notice, this list of conditions and the following disclaimer in the\n"
" * documentation and/or other materials provided with the distribution.\n"
" *\n"
" * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\n"
" * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n"
" * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n"
" * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE\n"
" * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n"
" * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n"
" * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n"
" * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n"
" * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n"
" * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n"
" * SUCH DAMAGE.\n"
" *\n"
"\n"
" *\n"
" * The built-in (previously called default) VCL code.\n"
" *\n"
" * NB! You do NOT need to copy & paste all of these functions into your\n"
" * own vcl code, if you do not provide a definition of one of these\n"
" * functions, the compiler will automatically fall back to the default\n"
" * code from this file.\n"
" *\n"
" * This code will be prefixed with a backend declaration built from the\n"
" * -b argument.\n"
" */\n"
"\n"
"vcl 4.0;\n"
"\n"
"#######################################################################\n"
"# Client side\n"
"\n"
"sub vcl_recv {\n"
" if (req.method == \"PRI\") {\n"
"\t/* We do not support SPDY or HTTP/2.0 */\n"
"\treturn (synth(405));\n"
" }\n"
" if (req.method != \"GET\" &&\n"
" req.method != \"HEAD\" &&\n"
" req.method != \"PUT\" &&\n"
" req.method != \"POST\" &&\n"
" req.method != \"TRACE\" &&\n"
" req.method != \"OPTIONS\" &&\n"
" req.method != \"DELETE\") {\n"
" /* Non-RFC2616 or CONNECT which is weird. */\n"
" return (pipe);\n"
" }\n"
"\n"
" if (req.method != \"GET\" && req.method != \"HEAD\") {\n"
" /* We only deal with GET and HEAD by default */\n"
" return (pass);\n"
" }\n"
" if (req.http.Authorization || req.http.Cookie) {\n"
" /* Not cacheable by default */\n"
" return (pass);\n"
" }\n"
" return (hash);\n"
"}\n"
"\n"
"sub vcl_pipe {\n"
" # By default Connection: close is set on all piped requests, to stop\n"
" # connection reuse from sending future requests directly to the\n"
" # (potentially) wrong backend. If you do want this to happen, you can undo\n"
" # it here.\n"
" # unset bereq.http.connection;\n"
" return (pipe);\n"
"}\n"
"\n"
"sub vcl_pass {\n"
" return (fetch);\n"
"}\n"
"\n"
"sub vcl_hash {\n"
" hash_data(req.url);\n"
" if (req.http.host) {\n"
" hash_data(req.http.host);\n"
" } else {\n"
" hash_data(server.ip);\n"
" }\n"
" return (lookup);\n"
"}\n"
"\n"
"sub vcl_purge {\n"
" return (synth(200, \"Purged\"));\n"
"}\n"
"\n"
"sub vcl_hit {\n"
" if (obj.ttl >= 0s) {\n"
" // A pure unadultered hit, deliver it\n"
" return (deliver);\n"
" }\n"
" if (obj.ttl + obj.grace > 0s) {\n"
" // Object is in grace, deliver it\n"
" // Automatically triggers a background fetch\n"
" return (deliver);\n"
" }\n"
" // fetch & deliver once we get the result\n"
" return (fetch);\n"
"}\n"
"\n"
"sub vcl_miss {\n"
" return (fetch);\n"
"}\n"
"\n"
"sub vcl_deliver {\n"
" return (deliver);\n"
"}\n"
"\n"
"/*\n"
" * We can come here \"invisibly\" with the following errors: 413, 417 & 503\n"
" */\n"
"sub vcl_synth {\n"
" set resp.http.Content-Type = \"text/html; charset=utf-8\";\n"
" set resp.http.Retry-After = \"5\";\n"
" synthetic( {\"<!DOCTYPE html>\n"
"<html>\n"
" <head>\n"
" <title>\"} + resp.status + \" \" + resp.reason + {\"</title>\n"
" </head>\n"
" <body>\n"
" <h1>Error \"} + resp.status + \" \" + resp.reason + {\"</h1>\n"
" <p>\"} + resp.reason + {\"</p>\n"
" <h3>Guru Meditation:</h3>\n"
" <p>XID: \"} + req.xid + {\"</p>\n"
" <hr>\n"
" <p>Varnish cache server</p>\n"
" </body>\n"
"</html>\n"
"\"} );\n"
" return (deliver);\n"
"}\n"
"\n"
"#######################################################################\n"
"# Backend Fetch\n"
"\n"
"sub vcl_backend_fetch {\n"
" return (fetch);\n"
"}\n"
"\n"
"sub vcl_backend_response {\n"
" if (beresp.ttl <= 0s ||\n"
" beresp.http.Set-Cookie ||\n"
" beresp.http.Surrogate-control ~ \"no-store\" ||\n"
" (!beresp.http.Surrogate-Control &&\n"
" beresp.http.Cache-Control ~ \"no-cache|no-store|private\") ||\n"
" beresp.http.Vary == \"*\") {\n"
" /*\n"
" * Mark as \"Hit-For-Pass\" for the next 2 minutes\n"
" */\n"
" set beresp.ttl = 120s;\n"
" set beresp.uncacheable = true;\n"
" }\n"
" return (deliver);\n"
"}\n"
"\n"
"sub vcl_backend_error {\n"
" set beresp.http.Content-Type = \"text/html; charset=utf-8\";\n"
" set beresp.http.Retry-After = \"5\";\n"
" synthetic( {\"<!DOCTYPE html>\n"
"<html>\n"
" <head>\n"
" <title>\"} + beresp.status + \" \" + beresp.reason + {\"</title>\n"
" </head>\n"
" <body>\n"
" <h1>Error \"} + beresp.status + \" \" + beresp.reason + {\"</h1>\n"
" <p>\"} + beresp.reason + {\"</p>\n"
" <h3>Guru Meditation:</h3>\n"
" <p>XID: \"} + bereq.xid + {\"</p>\n"
" <hr>\n"
" <p>Varnish cache server</p>\n"
" </body>\n"
"</html>\n"
"\"} );\n"
" return (deliver);\n"
"}\n"
"\n"
"#######################################################################\n"
"# Housekeeping\n"
"\n"
"sub vcl_init {\n"
" return (ok);\n"
"}\n"
"\n"
"sub vcl_fini {\n"
" return (ok);\n"
"}\n"
"",
};
static struct director *directors[3];
const struct VCL_conf VCL_conf = {
.magic = VCL_CONF_MAGIC,
.init_vcl = VGC_Init,
.fini_vcl = VGC_Fini,
.ndirector = 3,
.director = directors,
.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,
.purge_func = VGC_function_vcl_purge,
.miss_func = VGC_function_vcl_miss,
.hit_func = VGC_function_vcl_hit,
.deliver_func = VGC_function_vcl_deliver,
.synth_func = VGC_function_vcl_synth,
.backend_fetch_func = VGC_function_vcl_backend_fetch,
.backend_response_func = VGC_function_vcl_backend_response,
.backend_error_func = VGC_function_vcl_backend_error,
.init_func = VGC_function_vcl_init,
.fini_func = VGC_function_vcl_fini,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment