Commit 533be287 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Change API to VCC to be handle/object based.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4993 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent c62ef04e
...@@ -69,6 +69,8 @@ static VTAILQ_HEAD(, vclprog) vclhead = VTAILQ_HEAD_INITIALIZER(vclhead); ...@@ -69,6 +69,8 @@ static VTAILQ_HEAD(, vclprog) vclhead = VTAILQ_HEAD_INITIALIZER(vclhead);
char *mgt_cc_cmd; char *mgt_cc_cmd;
char *mgt_vcl_dir; char *mgt_vcl_dir;
static struct vcc *vcc;
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
/* /*
...@@ -151,7 +153,7 @@ run_vcc(void *priv) ...@@ -151,7 +153,7 @@ run_vcc(void *priv)
vp = priv; vp = priv;
sb = vsb_newauto(); sb = vsb_newauto();
XXXAN(sb); XXXAN(sb);
csrc = VCC_Compile(sb, vp->vcl, NULL); csrc = VCC_Compile(vcc, sb, vp->vcl);
vsb_finish(sb); vsb_finish(sb);
AZ(vsb_overflowed(sb)); AZ(vsb_overflowed(sb));
if (vsb_len(sb)) if (vsb_len(sb))
...@@ -449,7 +451,9 @@ void ...@@ -449,7 +451,9 @@ void
mgt_vcc_init(void) mgt_vcc_init(void)
{ {
VCC_InitCompile(default_vcl); vcc = VCC_New();
AN(vcc);
VCC_Default_VCL(vcc, default_vcl);
AZ(atexit(mgt_vcc_atexit)); AZ(atexit(mgt_vcc_atexit));
} }
......
...@@ -29,7 +29,11 @@ ...@@ -29,7 +29,11 @@
* $Id$ * $Id$
*/ */
char *VCC_Compile(struct vsb *sb, const char *b, const char *e); struct vcc;
void VCC_InitCompile(const char *default_vcl);
const char *VCC_Return_Name(unsigned action); struct vcc *VCC_New(void);
void VCC_Default_VCL(struct vcc *, const char *str);
void VCC_VCL_dir(struct vcc *, const char *str);
char *VCC_Compile(const struct vcc *, struct vsb *sb, const char *b);
const char *VCC_Return_Name(unsigned action);
...@@ -84,10 +84,6 @@ struct method method_tab[] = { ...@@ -84,10 +84,6 @@ struct method method_tab[] = {
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static const char *vcc_default_vcl_b, *vcc_default_vcl_e;
/*--------------------------------------------------------------------*/
static void static void
TlDoFree(struct vcc *tl, void *p) TlDoFree(struct vcc *tl, void *p)
{ {
...@@ -454,13 +450,17 @@ vcc_resolve_includes(struct vcc *tl) ...@@ -454,13 +450,17 @@ vcc_resolve_includes(struct vcc *tl)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static struct vcc * static struct vcc *
vcc_NewTokenList(void) vcc_NewVcc(const struct vcc *tl0)
{ {
struct vcc *tl; struct vcc *tl;
int i; int i;
tl = calloc(sizeof *tl, 1); ALLOC_OBJ(tl, VCC_MAGIC);
assert(tl != NULL); AN(tl);
if (tl0 != NULL) {
REPLACE(tl->default_vcl, tl0->default_vcl);
REPLACE(tl->vcl_dir, tl0->vcl_dir);
}
VTAILQ_INIT(&tl->hosts); VTAILQ_INIT(&tl->hosts);
VTAILQ_INIT(&tl->membits); VTAILQ_INIT(&tl->membits);
VTAILQ_INIT(&tl->tokens); VTAILQ_INIT(&tl->tokens);
...@@ -532,13 +532,13 @@ vcc_DestroyTokenList(struct vcc *tl, char *ret) ...@@ -532,13 +532,13 @@ vcc_DestroyTokenList(struct vcc *tl, char *ret)
*/ */
static char * static char *
vcc_CompileSource(struct vsb *sb, struct source *sp) vcc_CompileSource(const struct vcc *tl0, struct vsb *sb, struct source *sp)
{ {
struct vcc *tl; struct vcc *tl;
char *of; char *of;
int i; int i;
tl = vcc_NewTokenList(); tl = vcc_NewVcc(tl0);
tl->sb = sb; tl->sb = sb;
vcl_output_lang_h(tl->fh); vcl_output_lang_h(tl->fh);
...@@ -556,7 +556,7 @@ vcc_CompileSource(struct vsb *sb, struct source *sp) ...@@ -556,7 +556,7 @@ vcc_CompileSource(struct vsb *sb, struct source *sp)
return (vcc_DestroyTokenList(tl, NULL)); return (vcc_DestroyTokenList(tl, NULL));
/* Register and lex the default VCL */ /* Register and lex the default VCL */
sp = vcc_new_source(vcc_default_vcl_b, vcc_default_vcl_e, "Default"); sp = vcc_new_source(tl->default_vcl, NULL, "Default");
assert(sp != NULL); assert(sp != NULL);
VTAILQ_INSERT_TAIL(&tl->sources, sp, list); VTAILQ_INSERT_TAIL(&tl->sources, sp, list);
sp->idx = tl->nsources++; sp->idx = tl->nsources++;
...@@ -646,15 +646,15 @@ vcc_CompileSource(struct vsb *sb, struct source *sp) ...@@ -646,15 +646,15 @@ vcc_CompileSource(struct vsb *sb, struct source *sp)
*/ */
char * char *
VCC_Compile(struct vsb *sb, const char *b, const char *e) VCC_Compile(const struct vcc *tl, struct vsb *sb, const char *b)
{ {
struct source *sp; struct source *sp;
char *r; char *r;
sp = vcc_new_source(b, e, "input"); sp = vcc_new_source(b, NULL, "input");
if (sp == NULL) if (sp == NULL)
return (NULL); return (NULL);
r = vcc_CompileSource(sb, sp); r = vcc_CompileSource(tl, sb, sp);
return (r); return (r);
} }
...@@ -674,15 +674,38 @@ VCC_Return_Name(unsigned method) ...@@ -674,15 +674,38 @@ VCC_Return_Name(unsigned method)
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* Initialize the compiler and register the default VCL code for later * Allocate a compiler instance
* compilation runs. */
struct vcc *
VCC_New(void)
{
struct vcc *tl;
tl = vcc_NewVcc(NULL);
return (tl);
}
/*--------------------------------------------------------------------
* Configure default VCL source code
*/
void
VCC_Default_VCL(struct vcc *tl, const char *str)
{
CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
REPLACE(tl->default_vcl, str);
}
/*--------------------------------------------------------------------
* Configure default VCL source directory
*/ */
void void
VCC_InitCompile(const char *default_vcl) VCC_VCL_dir(struct vcc *tl, const char *str)
{ {
vcc_default_vcl_b = default_vcl; CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
vcc_default_vcl_e = strchr(default_vcl, '\0'); REPLACE(tl->vcl_dir, str);
assert(vcc_default_vcl_e != NULL);
} }
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "vqueue.h" #include "vqueue.h"
#include "miniobj.h"
#include "vcl.h" #include "vcl.h"
#define INDENT 2 #define INDENT 2
...@@ -64,6 +65,14 @@ struct token { ...@@ -64,6 +65,14 @@ struct token {
VTAILQ_HEAD(tokenhead, token); VTAILQ_HEAD(tokenhead, token);
struct vcc { struct vcc {
unsigned magic;
#define VCC_MAGIC 0x24ad719d
/* Parameter/Template section */
char *default_vcl;
char *vcl_dir;
/* Instance section */
struct tokenhead tokens; struct tokenhead tokens;
VTAILQ_HEAD(, source) sources; VTAILQ_HEAD(, source) sources;
VTAILQ_HEAD(, membit) membits; VTAILQ_HEAD(, membit) membits;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment