/*
 * NB:  This file is machine generated, DO NOT EDIT!
 *
 * Edit and run generate.py instead
 */

struct sess;
struct cli;

typedef void vcl_init_f(struct cli *);
typedef void vcl_fini_f(struct cli *);
typedef int vcl_func_f(struct sess *sp);

/* VCL Methods */
#define VCL_MET_RECV		(1U << 0)
#define VCL_MET_PIPE		(1U << 1)
#define VCL_MET_PASS		(1U << 2)
#define VCL_MET_HASH		(1U << 3)
#define VCL_MET_MISS		(1U << 4)
#define VCL_MET_HIT		(1U << 5)
#define VCL_MET_FETCH		(1U << 6)
#define VCL_MET_DELIVER		(1U << 7)
#define VCL_MET_ERROR		(1U << 8)

#define VCL_MET_MAX		9

#define VCL_MET_MASK		0x1ff

/* VCL Returns */
#define VCL_RET_DELIVER		0
#define VCL_RET_ERROR		1
#define VCL_RET_FETCH		2
#define VCL_RET_HASH		3
#define VCL_RET_LOOKUP		4
#define VCL_RET_PASS		5
#define VCL_RET_PIPE		6
#define VCL_RET_RESTART		7

#define VCL_RET_MAX		8

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_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	*deliver_func;
	vcl_func_f	*error_func;

};
/*-
 * Copyright (c) 2006 Verdens Gang AS
 * Copyright (c) 2006-2010 Linpro 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.
 *
 * $Id$
 *
 * Runtime support for compiled VCL programs.
 *
 * XXX: When this file is changed, lib/libvcl/generate.py *MUST* be rerun.
 */

struct sess;
struct vsb;
struct cli;
struct director;
struct VCL_conf;
struct sockaddr_storage;

/*
 * A backend probe specification
 */

extern const void * const vrt_magic_string_end;

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 unsigned char		*ipv4_sockaddr;
	const unsigned char		*ipv6_sockaddr;

	const char			*hosthdr;

	double				connect_timeout;
	double				first_byte_timeout;
	double				between_bytes_timeout;
	unsigned			max_connections;
	unsigned			saintmode_threshold;
	const struct vrt_backend_probe	*probe;
};

/*
 * A director with an unpredictable reply
 */

struct vrt_dir_random_entry {
	int					host;
	double					weight;
};

struct vrt_dir_random {
	const char				*name;
	unsigned				retries;
	unsigned				nmember;
	const struct vrt_dir_random_entry	*members;
};

/*
 * A director with round robin selection
 */

struct vrt_dir_round_robin_entry {
	int					host;
};

struct vrt_dir_round_robin {
	const char				*name;
	unsigned				nmember;
	const struct vrt_dir_round_robin_entry	*members;
};

/*
 * A director with dns-based selection
 */

struct vrt_dir_dns_entry {
	int					host;
};

struct vrt_dir_dns {
	const char				*name;
	const char				*suffix;
	const double				ttl;
	unsigned				nmember;
	const struct vrt_dir_dns_entry		*members;
};

/*
 * 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 sess *, const char *msg);

/* Regexp related */
void VRT_re_init(void **, const char *);
void VRT_re_fini(void *);
int VRT_re_match(const char *, void *re);
const char *VRT_regsub(const struct sess *sp, int all, const char *,
    void *, const char *);

void VRT_panic(const struct sess *sp, const char *, ...);
void VRT_ban(struct sess *sp, char *, ...);
void VRT_ban_string(struct sess *sp, const char *);
void VRT_purge(const struct sess *sp, double ttl, double grace);

void VRT_count(const struct sess *, unsigned);
int VRT_rewrite(const char *, const char *);
void VRT_error(struct sess *, unsigned, const char *);
int VRT_switch_config(const char *);

enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ, HDR_BERESP };
char *VRT_GetHdr(const struct sess *, enum gethdr_e where, const char *);
void VRT_SetHdr(const struct sess *, enum gethdr_e where, const char *,
    const char *, ...);
void VRT_handling(struct sess *sp, unsigned hand);

void VRT_hashdata(const struct sess *sp, 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_ESI(const struct sess *sp);
void VRT_Rollback(struct sess *sp);

/* Synthetic pages */
void VRT_synth_page(const struct sess *sp, unsigned flags, const char *, ...);

/* Backend related */
void VRT_init_dir(struct cli *, struct director **, const char *name,
    int idx, const void *priv);
void VRT_fini_dir(struct cli *, struct director *);

/* VMOD/Modules related */
void VRT_Vmod_Init(void **hdl, void *ptr, int len, const char *nm,
    const char *path);
void VRT_Vmod_Fini(void **hdl);

struct vmod_priv;
typedef void vmod_priv_free_f(void *);
struct vmod_priv {
	void			*priv;
	vmod_priv_free_f	*free;
};

typedef int vmod_init_f(struct vmod_priv *,  const struct VCL_conf *);

static inline void
vmod_priv_fini(const struct vmod_priv *p)
{

	if (p->priv != (void*)0 && p->free != (void*)0)
		p->free(p->priv);
}

/* Stevedore related functions */
int VRT_Stv(const char *nm);

/* Convert things to string */

char *VRT_IP_string(const struct sess *sp, const struct sockaddr_storage *sa);
char *VRT_int_string(const struct sess *sp, int);
char *VRT_double_string(const struct sess *sp, double);
char *VRT_time_string(const struct sess *sp, double);
const char *VRT_bool_string(const struct sess *sp, unsigned);
const char *VRT_backend_string(const struct sess *sp, const struct director *d);

#define VRT_done(sp, hand)			\
	do {					\
		VRT_handling(sp, hand);		\
		return (1);			\
	} while (0)

const char *VRT_WrkString(const struct sess *sp, const char *p, ...);
/*
 * NB:  This file is machine generated, DO NOT EDIT!
 *
 * Edit and run generate.py instead
 */
struct sockaddr_storage * VRT_r_client_ip(const struct sess *);
const char * VRT_r_client_identity(struct sess *);
void VRT_l_client_identity(struct sess *, const char *, ...);
struct sockaddr_storage * VRT_r_server_ip(struct sess *);
const char * VRT_r_server_hostname(struct sess *);
const char * VRT_r_server_identity(struct sess *);
int VRT_r_server_port(struct sess *);
const char * VRT_r_req_request(const struct sess *);
void VRT_l_req_request(const struct sess *, const char *, ...);
const char * VRT_r_req_url(const struct sess *);
void VRT_l_req_url(const struct sess *, const char *, ...);
const char * VRT_r_req_proto(const struct sess *);
void VRT_l_req_proto(const struct sess *, const char *, ...);
struct director * VRT_r_req_backend(struct sess *);
void VRT_l_req_backend(struct sess *, struct director *);
int VRT_r_req_restarts(const struct sess *);
int VRT_r_req_esi_level(const struct sess *);
double VRT_r_req_grace(struct sess *);
void VRT_l_req_grace(struct sess *, double);
const char * VRT_r_req_xid(struct sess *);
unsigned VRT_r_req_esi(struct sess *);
void VRT_l_req_esi(struct sess *, unsigned);
unsigned VRT_r_req_can_gzip(struct sess *);
unsigned VRT_r_req_backend_healthy(const struct sess *);
unsigned VRT_r_req_hash_ignore_busy(struct sess *);
void VRT_l_req_hash_ignore_busy(struct sess *, unsigned);
unsigned VRT_r_req_hash_always_miss(struct sess *);
void VRT_l_req_hash_always_miss(struct sess *, unsigned);
const char * VRT_r_bereq_request(const struct sess *);
void VRT_l_bereq_request(const struct sess *, const char *, ...);
const char * VRT_r_bereq_url(const struct sess *);
void VRT_l_bereq_url(const struct sess *, const char *, ...);
const char * VRT_r_bereq_proto(const struct sess *);
void VRT_l_bereq_proto(const struct sess *, const char *, ...);
double VRT_r_bereq_connect_timeout(struct sess *);
void VRT_l_bereq_connect_timeout(struct sess *, double);
double VRT_r_bereq_first_byte_timeout(struct sess *);
void VRT_l_bereq_first_byte_timeout(struct sess *, double);
double VRT_r_bereq_between_bytes_timeout(struct sess *);
void VRT_l_bereq_between_bytes_timeout(struct sess *, double);
const char * VRT_r_beresp_proto(const struct sess *);
void VRT_l_beresp_proto(const struct sess *, const char *, ...);
void VRT_l_beresp_saintmode(const struct sess *, double);
int VRT_r_beresp_status(const struct sess *);
void VRT_l_beresp_status(const struct sess *, int);
const char * VRT_r_beresp_response(const struct sess *);
void VRT_l_beresp_response(const struct sess *, const char *, ...);
unsigned VRT_r_beresp_cacheable(const struct sess *);
void VRT_l_beresp_cacheable(const struct sess *, unsigned);
unsigned VRT_r_beresp_do_esi(const struct sess *);
void VRT_l_beresp_do_esi(const struct sess *, unsigned);
unsigned VRT_r_beresp_do_gzip(const struct sess *);
void VRT_l_beresp_do_gzip(const struct sess *, unsigned);
unsigned VRT_r_beresp_do_gunzip(const struct sess *);
void VRT_l_beresp_do_gunzip(const struct sess *, unsigned);
double VRT_r_beresp_ttl(const struct sess *);
void VRT_l_beresp_ttl(const struct sess *, double);
double VRT_r_beresp_grace(struct sess *);
void VRT_l_beresp_grace(struct sess *, double);
const char * VRT_r_beresp_backend_name(const struct sess *);
struct sockaddr_storage * VRT_r_beresp_backend_ip(const struct sess *);
int VRT_r_beresp_backend_port(const struct sess *);
const char * VRT_r_beresp_storage(struct sess *);
void VRT_l_beresp_storage(struct sess *, const char *, ...);
const char * VRT_r_obj_proto(const struct sess *);
void VRT_l_obj_proto(const struct sess *, const char *, ...);
int VRT_r_obj_status(const struct sess *);
void VRT_l_obj_status(const struct sess *, int);
const char * VRT_r_obj_response(const struct sess *);
void VRT_l_obj_response(const struct sess *, const char *, ...);
int VRT_r_obj_hits(const struct sess *);
unsigned VRT_r_obj_cacheable(const struct sess *);
void VRT_l_obj_cacheable(const struct sess *, unsigned);
double VRT_r_obj_ttl(const struct sess *);
void VRT_l_obj_ttl(const struct sess *, double);
double VRT_r_obj_grace(struct sess *);
void VRT_l_obj_grace(struct sess *, double);
double VRT_r_obj_lastuse(const struct sess *);
const char * VRT_r_resp_proto(const struct sess *);
void VRT_l_resp_proto(const struct sess *, const char *, ...);
int VRT_r_resp_status(const struct sess *);
void VRT_l_resp_status(const struct sess *, int);
const char * VRT_r_resp_response(const struct sess *);
void VRT_l_resp_response(const struct sess *, const char *, ...);
double VRT_r_now(const struct sess *);
double VRT_Stv_free_space(const char *);
double VRT_Stv_used_space(const char *);
unsigned VRT_Stv_happy(const char *);

/* ---===### VCC generated below here ###===---*/

extern const struct VCL_conf VCL_conf;
#define VGCDIR(n) VCL_conf.director[VGC_backend_##n]

#define VGC_backend__vc 1

static const unsigned char sockaddr0[17] = {
     16, /* Length */
      2,   0,   0,  80,  87, 238,  37,   5,
      0,   0,   0,   0,   0,   0,   0,   0

};

static const struct vrt_backend vgc_dir_priv__vc = {
	.vcl_name = "vc",
	.ipv4_sockaddr = sockaddr0,
	.ipv4_addr = "87.238.37.5",
	.port = "80",
	.hosthdr = "varnish-cache.org",
	.saintmode_threshold = -1,
};

#define VGC_NREFS 31
 #include <stdio.h> 

static int
VGC_function_vcl_recv (struct sess *sp)
{
  /* ... from ('input' Line 4 Pos 5) */
  {
    {
      VRT_count(sp, 1);
      {
		printf("Hello mom, I'm on the internett!\n");
	}
      VRT_SetHdr(sp, HDR_REQ, "\005host:",       
        "www.varnish-cache.org",
        vrt_magic_string_end
      );
    }
  }
  /* ... from ('Default' Line 42 Pos 5) */
  {
    {
      VRT_count(sp, 2);
      if (
        (VRT_r_req_restarts(sp) == 0)
      )
        {
          VRT_count(sp, 3);
          if (
            (VRT_GetHdr(sp, HDR_REQ, "\020x-forwarded-for:") != 0)
          )
            {
              VRT_count(sp, 4);
              VRT_SetHdr(sp, HDR_REQ, "\020X-Forwarded-For:",               
                VRT_GetHdr(sp, HDR_REQ, "\020X-Forwarded-For:"),
                ", ",
                VRT_IP_string(sp, VRT_r_client_ip(sp)),
                vrt_magic_string_end
              );
            }
          else
            {
              VRT_count(sp, 5);
              VRT_SetHdr(sp, HDR_REQ, "\020X-Forwarded-For:",               
                VRT_IP_string(sp, VRT_r_client_ip(sp)),
                vrt_magic_string_end
              );
            }
        }
      VRT_count(sp, 6);
      if (
        (
          VRT_strcmp(VRT_r_req_request(sp), "GET")
        &&
          VRT_strcmp(VRT_r_req_request(sp), "HEAD")
        &&
          VRT_strcmp(VRT_r_req_request(sp), "PUT")
        &&
          VRT_strcmp(VRT_r_req_request(sp), "POST")
        &&
          VRT_strcmp(VRT_r_req_request(sp), "TRACE")
        &&
          VRT_strcmp(VRT_r_req_request(sp), "OPTIONS")
        &&
          VRT_strcmp(VRT_r_req_request(sp), "DELETE")
        )
      )
        {
          VRT_count(sp, 7);
          VRT_done(sp, VCL_RET_PIPE);
        }
      VRT_count(sp, 8);
      if (
        (
          VRT_strcmp(VRT_r_req_request(sp), "GET")
        &&
          VRT_strcmp(VRT_r_req_request(sp), "HEAD")
        )
      )
        {
          VRT_count(sp, 9);
          VRT_done(sp, VCL_RET_PASS);
        }
      VRT_count(sp, 10);
      if (
        (
          (VRT_GetHdr(sp, HDR_REQ, "\016Authorization:") != 0)
        ||
          (VRT_GetHdr(sp, HDR_REQ, "\007Cookie:") != 0)
        )
      )
        {
          VRT_count(sp, 11);
          VRT_done(sp, VCL_RET_PASS);
        }
      VRT_count(sp, 12);
      VRT_done(sp, VCL_RET_LOOKUP);
    }
  }
}

static int
VGC_function_vcl_pipe (struct sess *sp)
{
  /* ... from ('Default' Line 72 Pos 5) */
  {
    {
      VRT_count(sp, 13);
      VRT_done(sp, VCL_RET_PIPE);
    }
  }
}

static int
VGC_function_vcl_pass (struct sess *sp)
{
  /* ... from ('Default' Line 82 Pos 5) */
  {
    {
      VRT_count(sp, 14);
      VRT_done(sp, VCL_RET_PASS);
    }
  }
}

static int
VGC_function_vcl_hash (struct sess *sp)
{
  /* ... from ('Default' Line 86 Pos 5) */
  {
    {
      VRT_count(sp, 15);
      VRT_hashdata(sp,       
        VRT_r_req_url(sp),
        vrt_magic_string_end
);
      if (
        (VRT_GetHdr(sp, HDR_REQ, "\005host:") != 0)
      )
        {
          VRT_count(sp, 16);
          VRT_hashdata(sp,           
            VRT_GetHdr(sp, HDR_REQ, "\005host:"),
            vrt_magic_string_end
);
        }
      else
        {
          VRT_count(sp, 17);
          VRT_hashdata(sp,           
            VRT_IP_string(sp, VRT_r_server_ip(sp)),
            vrt_magic_string_end
);
        }
      VRT_done(sp, VCL_RET_HASH);
    }
  }
}

static int
VGC_function_vcl_miss (struct sess *sp)
{
  /* ... from ('Default' Line 103 Pos 5) */
  {
    {
      VRT_count(sp, 21);
      VRT_done(sp, VCL_RET_FETCH);
    }
  }
}

static int
VGC_function_vcl_hit (struct sess *sp)
{
  /* ... from ('Default' Line 96 Pos 5) */
  {
    {
      VRT_count(sp, 18);
      if (
        !(VRT_r_obj_cacheable(sp))
      )
        {
          VRT_count(sp, 19);
          VRT_done(sp, VCL_RET_PASS);
        }
      VRT_count(sp, 20);
      VRT_done(sp, VCL_RET_DELIVER);
    }
  }
}

static int
VGC_function_vcl_fetch (struct sess *sp)
{
  /* ... from ('Default' Line 107 Pos 5) */
  {
    {
      VRT_count(sp, 22);
      if (
        !(VRT_r_beresp_cacheable(sp))
      )
        {
          VRT_count(sp, 23);
          VRT_done(sp, VCL_RET_PASS);
        }
      VRT_count(sp, 24);
      if (
        (VRT_GetHdr(sp, HDR_BERESP, "\013Set-Cookie:") != 0)
      )
        {
          VRT_count(sp, 25);
          VRT_done(sp, VCL_RET_PASS);
        }
      VRT_count(sp, 26);
      if (
        !VRT_strcmp(VRT_GetHdr(sp, HDR_BERESP, "\005Vary:"), "*")
      )
        {
          VRT_count(sp, 27);
          VRT_done(sp, VCL_RET_PASS);
        }
      VRT_count(sp, 28);
      VRT_done(sp, VCL_RET_DELIVER);
    }
  }
}

static int
VGC_function_vcl_deliver (struct sess *sp)
{
  /* ... from ('Default' Line 120 Pos 5) */
  {
    {
      VRT_count(sp, 29);
      VRT_done(sp, VCL_RET_DELIVER);
    }
  }
}

static int
VGC_function_vcl_error (struct sess *sp)
{
  /* ... from ('Default' Line 124 Pos 5) */
  {
    {
      VRT_count(sp, 30);
      VRT_SetHdr(sp, HDR_OBJ, "\015Content-Type:",       
        "text/html; charset=utf-8",
        vrt_magic_string_end
      );
      VRT_synth_page(sp, 0,       
        "\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html>\n  <head>\n    <title>",
        VRT_int_string(sp, VRT_r_obj_status(sp)),
        " ",
        VRT_r_obj_response(sp),
        "</title>\n  </head>\n  <body>\n    <h1>Error ",
        VRT_int_string(sp, VRT_r_obj_status(sp)),
        " ",
        VRT_r_obj_response(sp),
        "</h1>\n    <p>",
        VRT_r_obj_response(sp),
        "</p>\n    <h3>Guru Meditation:</h3>\n    <p>XID: ",
        VRT_r_req_xid(sp),
        "</p>\n    <hr>\n    <p>Varnish cache server</p>\n  </body>\n</html>\n",
        vrt_magic_string_end
);
      VRT_done(sp, VCL_RET_DELIVER);
    }
  }
}

static struct vrt_ref VGC_ref[VGC_NREFS] = {
  [  1] = { 0,       86,    5,   9, 0,  "C{"},
  [  2] = { 1,     1832,   43,   5, 0,  "if" },
  [  3] = { 1,     1858,   44,   9, 0,  "if" },
  [  4] = { 1,     1895,   45,  13, 0,  "set" },
  [  5] = { 1,     1988,   48,  13, 0,  "set" },
  [  6] = { 1,     2043,   51,   5, 0,  "if" },
  [  7] = { 1,     2323,   59,   9, 0,  "return" },
  [  8] = { 1,     2348,   61,   5, 0,  "if" },
  [  9] = { 1,     2465,   63,   9, 0,  "return" },
  [ 10] = { 1,     2490,   65,   5, 0,  "if" },
  [ 11] = { 1,     2586,   67,   9, 0,  "return" },
  [ 12] = { 1,     2611,   69,   5, 0,  "return" },
  [ 13] = { 1,     3006,   79,   5, 0,  "return" },
  [ 14] = { 1,     3043,   83,   5, 0,  "return" },
  [ 15] = { 1,     3080,   87,   5, 0,  "hash_data" },
  [ 16] = { 1,     3133,   89,   9, 0,  "hash_data" },
  [ 17] = { 1,     3180,   91,   9, 0,  "hash_data" },
  [ 18] = { 1,     3248,   97,   5, 0,  "if" },
  [ 19] = { 1,     3278,   98,   9, 0,  "return" },
  [ 20] = { 1,     3303,  100,   5, 0,  "return" },
  [ 21] = { 1,     3343,  104,   5, 0,  "return" },
  [ 22] = { 1,     3382,  108,   5, 0,  "if" },
  [ 23] = { 1,     3415,  109,   9, 0,  "return" },
  [ 24] = { 1,     3440,  111,   5, 0,  "if" },
  [ 25] = { 1,     3478,  112,   9, 0,  "return" },
  [ 26] = { 1,     3503,  114,   5, 0,  "if" },
  [ 27] = { 1,     3542,  115,   9, 0,  "return" },
  [ 28] = { 1,     3567,  117,   5, 0,  "return" },
  [ 29] = { 1,     3610,  121,   5, 0,  "return" },
  [ 30] = { 1,     3651,  125,   5, 0,  "set" },
};

static void
VGC_Init(struct cli *cli)
{

	VRT_init_dir(cli, VCL_conf.director, "simple",
	    VGC_backend__vc, &vgc_dir_priv__vc);
	VCL_conf.director[0] = VCL_conf.director[1];
}

static void
VGC_Fini(struct cli *cli)
{

	VRT_fini_dir(cli, VGCDIR(_vc));
}

const char *srcname[2] = {
	"input",
	"Default",
};

const char *srcbody[2] = {
    /* "input"*/
	"backend vc { .host = \"varnish-cache.org\"; }\n"
	"\n"
	"C{ #include <stdio.h> }C\n"
	"sub vcl_recv {\n"
	"\tC{\n"
	"\t\tprintf(\"Hello mom, I'm on the internett!\\n\");\n"
	"\t}C\n"
	"\tset req.http.host = \"www.varnish-cache.org\";\n"
	"}\n"
	"",
    /* "Default"*/
	"/*-\n"
	" * Copyright (c) 2006 Verdens Gang AS\n"
	" * Copyright (c) 2006-2010 Linpro 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\n"
	" * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE\n"
	" * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n"
	" * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n"
	" * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR \n"
	" * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n"
	" * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\n"
	" * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n"
	" * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
	" *\n"
	" * $Id$\n"
	" *\n"
	" * The 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"
	"sub vcl_recv {\n"
	"    if (req.restarts == 0) {\n"
	"\tif (req.http.x-forwarded-for) {\n"
	"\t    set req.http.X-Forwarded-For =\n"
	"\t\treq.http.X-Forwarded-For + \", \" + client.ip;\n"
	"\t} else {\n"
	"\t    set req.http.X-Forwarded-For = client.ip;\n"
	"\t}\n"
	"    }\n"
	"    if (req.request != \"GET\" &&\n"
	"      req.request != \"HEAD\" &&\n"
	"      req.request != \"PUT\" &&\n"
	"      req.request != \"POST\" &&\n"
	"      req.request != \"TRACE\" &&\n"
	"      req.request != \"OPTIONS\" &&\n"
	"      req.request != \"DELETE\") {\n"
	"        /* Non-RFC2616 or CONNECT which is weird. */\n"
	"        return (pipe);\n"
	"    }\n"
	"    if (req.request != \"GET\" && req.request != \"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 (lookup);\n"
	"}\n"
	"\n"
	"sub vcl_pipe {\n"
	"    # Note that only the first request to the backend will have\n"
	"    # X-Forwarded-For set.  If you use X-Forwarded-For and want to\n"
	"    # have it set for all requests, make sure to have:\n"
	"    # set bereq.http.connection = \"close\";\n"
	"    # here.  It is not set by default as it might break some broken web\n"
	"    # applications, like IIS with NTLM authentication.\n"
	"    return (pipe);\n"
	"}\n"
	"\n"
	"sub vcl_pass {\n"
	"    return (pass);\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 (hash);\n"
	"}\n"
	"\n"
	"sub vcl_hit {\n"
	"    if (!obj.cacheable) {\n"
	"        return (pass);\n"
	"    }\n"
	"    return (deliver);\n"
	"}\n"
	"\n"
	"sub vcl_miss {\n"
	"    return (fetch);\n"
	"}\n"
	"\n"
	"sub vcl_fetch {\n"
	"    if (!beresp.cacheable) {\n"
	"        return (pass);\n"
	"    }\n"
	"    if (beresp.http.Set-Cookie) {\n"
	"        return (pass);\n"
	"    }\n"
	"    if (beresp.http.Vary == \"*\") {\n"
	"        return (pass);\n"
	"    }\n"
	"    return (deliver);\n"
	"}\n"
	"\n"
	"sub vcl_deliver {\n"
	"    return (deliver);\n"
	"}\n"
	"\n"
	"sub vcl_error {\n"
	"    set obj.http.Content-Type = \"text/html; charset=utf-8\";\n"
	"    synthetic {\"\n"
	"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
	"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
	" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
	"<html>\n"
	"  <head>\n"
	"    <title>\"} + obj.status + \" \" + obj.response + {\"</title>\n"
	"  </head>\n"
	"  <body>\n"
	"    <h1>Error \"} + obj.status + \" \" + obj.response + {\"</h1>\n"
	"    <p>\"} + obj.response + {\"</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"
	"",
};

static struct director	*directors[2];

const struct VCL_conf VCL_conf = {
	.magic = VCL_CONF_MAGIC,
	.init_func = VGC_Init,
	.fini_func = VGC_Fini,
	.ndirector = 2,
	.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,
	.miss_func = VGC_function_vcl_miss,
	.hit_func = VGC_function_vcl_hit,
	.fetch_func = VGC_function_vcl_fetch,
	.deliver_func = VGC_function_vcl_deliver,
	.error_func = VGC_function_vcl_error,
};
