r5146 - in trunk/varnish-cache: . bin/varnishd include

phk at varnish-cache.org phk at varnish-cache.org
Mon Aug 30 11:15:16 CEST 2010


Author: phk
Date: 2010-08-30 11:15:15 +0200 (Mon, 30 Aug 2010)
New Revision: 5146

Added:
   trunk/varnish-cache/bin/varnishd/cache_vrt_vmod.c
Modified:
   trunk/varnish-cache/bin/varnishd/Makefile.am
   trunk/varnish-cache/configure.ac
   trunk/varnish-cache/include/vrt.h
Log:

Add the VRT functions for importing a module.

Tie the vmod_std module into the build.

The initial VCC bits for modules snug into the previous commit.


Modified: trunk/varnish-cache/bin/varnishd/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishd/Makefile.am	2010-08-30 09:12:44 UTC (rev 5145)
+++ trunk/varnish-cache/bin/varnishd/Makefile.am	2010-08-30 09:15:15 UTC (rev 5146)
@@ -42,6 +42,7 @@
 	cache_vcl.c \
 	cache_vrt.c \
 	cache_vrt_re.c \
+	cache_vrt_vmod.c \
 	cache_wrw.c \
 	cache_ws.c \
 	hash_classic.c \

Copied: trunk/varnish-cache/bin/varnishd/cache_vrt_vmod.c (from rev 5144, trunk/varnish-cache/bin/varnishd/cache_vrt.c)
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt_vmod.c	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt_vmod.c	2010-08-30 09:15:15 UTC (rev 5146)
@@ -0,0 +1,108 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2009 Linpro AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at 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
+ */
+
+#include "config.h"
+
+#include "svnid.h"
+SVNID("$Id$")
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+
+#include "vrt.h"
+#include "cache.h"
+
+/*--------------------------------------------------------------------
+ * Modules stuff
+ */
+
+struct vmod {
+	char 			*nm;
+	char 			*path;
+	void 			*hdl;
+	const void		*funcs;
+	int			funclen;
+};
+
+void
+VRT_Vmod_Init(void **hdl, void *ptr, int len, const char *nm, const char *path)
+{
+	struct vmod *v;
+	void *x;
+	const int *i;
+	const char *p;
+
+	v = calloc(sizeof *v, 1);
+	AN(v);
+	REPLACE(v->nm, nm);
+	REPLACE(v->path, path);
+	fprintf(stderr, "LOAD MODULE %s (%s)\n", v->nm, v->path);
+	v->hdl = dlopen(v->path, RTLD_NOW | RTLD_LOCAL);
+	if (v->hdl == NULL)
+		fprintf(stderr, "Err: %s\n", dlerror());
+	AN(v->hdl);
+
+	x = dlsym(v->hdl, "Vmod_Name");
+	AN(x);
+	p = x;
+	fprintf(stderr, "Loaded name: %p\n", p);
+	fprintf(stderr, "Loaded name: %s\n", p);
+
+	x = dlsym(v->hdl, "Vmod_Len");
+	AN(x);
+	i = x;
+	fprintf(stderr, "Loaded len: %p\n", i);
+	fprintf(stderr, "Loaded len: %d\n", *i);
+	assert(len == *i);
+
+	x = dlsym(v->hdl, "Vmod_Func");
+	AN(x);
+	fprintf(stderr, "Loaded Funcs at: %p\n", x);
+	memcpy(ptr, x, len);
+
+	v->funcs = x;
+	v->funclen = *i;
+
+	*hdl = v;
+}
+
+void
+VRT_Vmod_Fini(void **hdl)
+{
+	struct vmod *v;
+
+	AN(*hdl);
+	v = *hdl;
+	fprintf(stderr, "UNLOAD MODULE %s\n", v->nm);
+	free(*hdl);
+	*hdl = NULL;
+}

Modified: trunk/varnish-cache/configure.ac
===================================================================
--- trunk/varnish-cache/configure.ac	2010-08-30 09:12:44 UTC (rev 5145)
+++ trunk/varnish-cache/configure.ac	2010-08-30 09:15:15 UTC (rev 5146)
@@ -462,6 +462,7 @@
     lib/libvarnishapi/Makefile
     lib/libvarnishcompat/Makefile
     lib/libvcl/Makefile
+    lib/libvmod_std/Makefile
     lib/libjemalloc/Makefile
     man/Makefile
     redhat/Makefile

Modified: trunk/varnish-cache/include/vrt.h
===================================================================
--- trunk/varnish-cache/include/vrt.h	2010-08-30 09:12:44 UTC (rev 5145)
+++ trunk/varnish-cache/include/vrt.h	2010-08-30 09:15:15 UTC (rev 5146)
@@ -185,6 +185,13 @@
     int idx, const void *priv);
 void VRT_fini_dir(struct cli *, struct director *);
 
+/* Modules related */
+void VRT_Vmod_Init(void **hdl, void *ptr, int len, const char *nm,
+    const char *path);
+void VRT_Vmod_Fini(void **hdl);
+
+/* Convert things to string */
+
 char *VRT_IP_string(const struct sess *sp, const struct sockaddr *sa);
 char *VRT_int_string(const struct sess *sp, int);
 char *VRT_double_string(const struct sess *sp, double);




More information about the varnish-commit mailing list