r4993 - in trunk/varnish-cache: bin/varnishd include lib/libvcl

phk at varnish-cache.org phk at varnish-cache.org
Tue Jun 29 14:29:00 CEST 2010


Author: phk
Date: 2010-06-29 14:29:00 +0200 (Tue, 29 Jun 2010)
New Revision: 4993

Modified:
   trunk/varnish-cache/bin/varnishd/mgt_vcc.c
   trunk/varnish-cache/include/libvcl.h
   trunk/varnish-cache/lib/libvcl/vcc_compile.c
   trunk/varnish-cache/lib/libvcl/vcc_compile.h
Log:
Change API to VCC to be handle/object based.



Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_vcc.c	2010-06-29 12:19:22 UTC (rev 4992)
+++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c	2010-06-29 12:29:00 UTC (rev 4993)
@@ -69,6 +69,8 @@
 char *mgt_cc_cmd;
 char *mgt_vcl_dir;
 
+static struct vcc *vcc;
+
 /*--------------------------------------------------------------------*/
 
 /*
@@ -151,7 +153,7 @@
 	vp = priv;
 	sb = vsb_newauto();
 	XXXAN(sb);
-	csrc = VCC_Compile(sb, vp->vcl, NULL);
+	csrc = VCC_Compile(vcc, sb, vp->vcl);
 	vsb_finish(sb);
 	AZ(vsb_overflowed(sb));
 	if (vsb_len(sb))
@@ -449,7 +451,9 @@
 mgt_vcc_init(void)
 {
 
-	VCC_InitCompile(default_vcl);
+	vcc = VCC_New();
+	AN(vcc);
+	VCC_Default_VCL(vcc, default_vcl);
 	AZ(atexit(mgt_vcc_atexit));
 }
 

Modified: trunk/varnish-cache/include/libvcl.h
===================================================================
--- trunk/varnish-cache/include/libvcl.h	2010-06-29 12:19:22 UTC (rev 4992)
+++ trunk/varnish-cache/include/libvcl.h	2010-06-29 12:29:00 UTC (rev 4993)
@@ -29,7 +29,11 @@
  * $Id$
  */
 
-char *VCC_Compile(struct vsb *sb, const char *b, const char *e);
-void VCC_InitCompile(const char *default_vcl);
+struct vcc;
+
+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);
-

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.c	2010-06-29 12:19:22 UTC (rev 4992)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.c	2010-06-29 12:29:00 UTC (rev 4993)
@@ -84,10 +84,6 @@
 
 /*--------------------------------------------------------------------*/
 
-static const char *vcc_default_vcl_b, *vcc_default_vcl_e;
-
-/*--------------------------------------------------------------------*/
-
 static void
 TlDoFree(struct vcc *tl, void *p)
 {
@@ -454,13 +450,17 @@
 /*--------------------------------------------------------------------*/
 
 static struct vcc *
-vcc_NewTokenList(void)
+vcc_NewVcc(const struct vcc *tl0)
 {
 	struct vcc *tl;
 	int i;
 
-	tl = calloc(sizeof *tl, 1);
-	assert(tl != NULL);
+	ALLOC_OBJ(tl, VCC_MAGIC);
+	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->membits);
 	VTAILQ_INIT(&tl->tokens);
@@ -532,13 +532,13 @@
  */
 
 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;
 	char *of;
 	int i;
 
-	tl = vcc_NewTokenList();
+	tl = vcc_NewVcc(tl0);
 	tl->sb = sb;
 
 	vcl_output_lang_h(tl->fh);
@@ -556,7 +556,7 @@
 		return (vcc_DestroyTokenList(tl, NULL));
 
 	/* 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);
 	VTAILQ_INSERT_TAIL(&tl->sources, sp, list);
 	sp->idx = tl->nsources++;
@@ -646,15 +646,15 @@
  */
 
 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;
 	char *r;
 
-	sp = vcc_new_source(b, e, "input");
+	sp = vcc_new_source(b, NULL, "input");
 	if (sp == NULL)
 		return (NULL);
-	r = vcc_CompileSource(sb, sp);
+	r = vcc_CompileSource(tl, sb, sp);
 	return (r);
 }
 
@@ -674,15 +674,38 @@
 }
 
 /*--------------------------------------------------------------------
- * Initialize the compiler and register the default VCL code for later
- * compilation runs.
+ * Allocate a compiler instance
  */
 
+struct vcc *
+VCC_New(void)
+{
+	struct vcc *tl;
+
+	tl = vcc_NewVcc(NULL);
+	return (tl);
+}
+
+/*--------------------------------------------------------------------
+ * Configure default VCL source code
+ */
+
 void
-VCC_InitCompile(const char *default_vcl)
+VCC_Default_VCL(struct vcc *tl, const char *str)
 {
 
-	vcc_default_vcl_b = default_vcl;
-	vcc_default_vcl_e = strchr(default_vcl, '\0');
-	assert(vcc_default_vcl_e != NULL);
+	CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
+	REPLACE(tl->default_vcl, str);
 }
+
+/*--------------------------------------------------------------------
+ * Configure default VCL source directory
+ */
+
+void
+VCC_VCL_dir(struct vcc *tl, const char *str)
+{
+
+	CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
+	REPLACE(tl->vcl_dir, str);
+}

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.h	2010-06-29 12:19:22 UTC (rev 4992)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.h	2010-06-29 12:29:00 UTC (rev 4993)
@@ -31,6 +31,7 @@
 
 #include "vqueue.h"
 
+#include "miniobj.h"
 #include "vcl.h"
 
 #define INDENT		2
@@ -64,6 +65,14 @@
 VTAILQ_HEAD(tokenhead, token);
 
 struct vcc {
+	unsigned		magic;
+#define VCC_MAGIC		0x24ad719d
+
+	/* Parameter/Template section */
+	char			*default_vcl;
+	char			*vcl_dir;
+
+	/* Instance section */
 	struct tokenhead	tokens;
 	VTAILQ_HEAD(, source)	sources;
 	VTAILQ_HEAD(, membit)	membits;




More information about the varnish-commit mailing list