aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2014-10-31 15:55:19 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2014-10-31 15:55:19 +0200
commit7965195e932d5ed4844dbef1e2da6e871aea6fe1 (patch)
tree11a30844929feeb08fd5fc9299f17c51583d52b3
parent5d7657a6b0c7c5f72dbee90f1025e9facab0b4c9 (diff)
downloadvmod-dbrw-7965195e932d5ed4844dbef1e2da6e871aea6fe1.tar.gz
vmod-dbrw-7965195e932d5ed4844dbef1e2da6e871aea6fe1.tar.bz2
Build for both v3 and v4
* NEWS: Update version number. * configure.ac: Version 1.9.90 (VARNISHVERSION): New variable. (VARNISH3,VARNISH4): New conditionals. * src/Makefile.am (nodist_libvmod_dbrw_la_SOURCES): New variable. (vmodtool,vmodtoolargs,vccfile): Define depending on Varnish version. (.vcc.vcc3): New rule (vcc_if.c vcc_if.h): Depend on $(vccfile) Don't distribute vcc_if.c and vcc_if.h. * src/vmod_dbrw.c: Provide data types and access macros depending on the version of Varnish.
-rw-r--r--NEWS4
-rw-r--r--configure.ac17
-rw-r--r--src/Makefile.am28
-rw-r--r--src/vmod_dbrw.c39
-rw-r--r--src/vmod_dbrw.vcc26
5 files changed, 75 insertions, 39 deletions
diff --git a/NEWS b/NEWS
index d36806a..b359d0e 100644
--- a/NEWS
+++ b/NEWS
@@ -7,5 +7,5 @@ Please send vmod-dbrw bug reports to <gray@gnu.org>
-Version 1.0.91-vcl4, (git)
+Version 1.9.90, (git)
-Rewritten for Varnish v4.x
+Builds for both Varnish v3.x and v4.x
diff --git a/configure.ac b/configure.ac
index e1c55eb..ce9087c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,3 +16,3 @@
AC_PREREQ(2.69)
-AC_INIT([vmod-dbrw], 1.0.91-vcl4, [gray@gnu.org])
+AC_INIT([vmod-dbrw], 1.9.90, [gray@gnu.org])
AC_CONFIG_AUX_DIR([build-aux])
@@ -66,6 +66,13 @@ esac
VARNISHSRC=`cd $VARNISHSRC && pwd`
-AC_CHECK_FILE([$VARNISHSRC/include/vapi/vsm.h],
- [],
- [AC_MSG_FAILURE(["$VARNISHSRC" is not a Varnish source directory])])
-
+VARNISHVERSION=
+AC_CHECK_FILE([$VARNISHSRC/include/varnishapi.h],
+ [VARNISHVERSION=3],
+ [AC_CHECK_FILE([$VARNISHSRC/include/vapi/vsm.h],
+ [VARNISHVERSION=4],
+ [AC_MSG_FAILURE(["$VARNISHSRC" is not a Varnish source directory])]) ])
+
+AC_DEFINE_UNQUOTED([VARNISHVERSION],$VARNISHVERSION,[Varnish major version number])
+AM_CONDITIONAL([VARNISH3],[test $VARNISHVERSION -eq 3])
+AM_CONDITIONAL([VARNISH4],[test $VARNISHVERSION -eq 4])
+
# Check that varnishtest is built in the varnish source directory
diff --git a/src/Makefile.am b/src/Makefile.am
index dde9116..f7a5a45 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -28,5 +28,7 @@ libvmod_dbrw_la_SOURCES = \
vmod_dbrw.c\
- vcc_if.c vcc_if.h\
wordsplit.h\
wordsplit.c
+nodist_libvmod_dbrw_la_SOURCES = vcc_if.c vcc_if.h
+
+vmod_dbrw.lo: vcc_if.h
@@ -40,9 +42,22 @@ endif
-BUILT_SOURCES = vcc_if.c vcc_if.h
+CLEANFILES = vcc_if.c vcc_if.h *.rst
+
+if VARNISH4
+ vmodtool = $(VARNISHSRC)/lib/libvcc/vmodtool.py
+ vmodtoolargs = --strict
+ vccfile = $(top_srcdir)/src/vmod_dbrw.vcc
+else
+ vmodtool = $(VARNISHSRC)/lib/libvmod_std/vmod.py
+ vmodtoolargs =
+ vccfile = vmod_dbrw.vcc3
+
+vmod_dbrw.vcc3: $(top_srcdir)/src/vmod_dbrw.vcc
+ CLEANFILES += vmod_dbrw.vcc3
+endif
-vmodtool = $(VARNISHSRC)/lib/libvcc/vmodtool.py
-vmodtoolargs = --strict
+.vcc.vcc3:
+ sed -n '/^\$$/{s///;s/\(Module *[^ ][^ ]*\).*/\1/;p}' $< > $@
-vcc_if.c vcc_if.h: $(vmodtool) $(top_srcdir)/src/vmod_dbrw.vcc
- @PYTHON@ $(vmodtool) $(vmodtoolargs) $(top_srcdir)/src/vmod_dbrw.vcc
+vcc_if.c vcc_if.h: $(vmodtool) $(vccfile)
+ @PYTHON@ $(vmodtool) $(vmodtoolargs) $(vccfile)
@@ -51,3 +66,2 @@ EXTRA_DIST = \
-CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h
diff --git a/src/vmod_dbrw.c b/src/vmod_dbrw.c
index 284376f..9db6a0b 100644
--- a/src/vmod_dbrw.c
+++ b/src/vmod_dbrw.c
@@ -22,3 +22,14 @@
#include "pthread.h"
-#include "bin/varnishd/cache/cache.h"
+#if VARNISHVERSION == 3
+# include "bin/varnishd/cache.h"
+# define VCL_VOID void
+# define VCL_STRING const char *
+# define WS_Copy(w,s,l) WS_Dup(w,l)
+# define DBRW_CTX struct sess *
+# define WSPTR(s) ((s)->wrk->ws)
+#else
+# include "bin/varnishd/cache/cache.h"
+# define DBRW_CTX const struct vrt_ctx *
+# define WSPTR(s) ((s)->ws)
+#endif
@@ -206,3 +217,3 @@ parse_flags(const char *arg, int *qdisp, int *flags, char status[])
VCL_VOID
-vmod_config(const struct vrt_ctx *ctx, struct vmod_priv *priv,
+vmod_config(DBRW_CTX ctx, struct vmod_priv *priv,
VCL_STRING bkname, VCL_STRING param, VCL_STRING query)
@@ -263,3 +274,3 @@ vmod_config(const struct vrt_ctx *ctx, struct vmod_priv *priv,
static char *
-expand_backref(const struct vrt_ctx *ctx, const char *str, const char *val,
+expand_backref(DBRW_CTX ctx, const char *str, const char *val,
size_t matchcount, regmatch_t *matches, char *qry)
@@ -269,4 +280,4 @@ expand_backref(const struct vrt_ctx *ctx, const char *str, const char *val,
- u = WS_Reserve(ctx->ws, 0);
- p = b = ctx->ws->f;
+ u = WS_Reserve(WSPTR(ctx), 0);
+ p = b = WSPTR(ctx)->f;
@@ -274,3 +285,3 @@ expand_backref(const struct vrt_ctx *ctx, const char *str, const char *val,
if (u == 0) {
- WS_Release(ctx->ws, 0);
+ WS_Release(WSPTR(ctx), 0);
return NULL;
@@ -287,3 +298,3 @@ expand_backref(const struct vrt_ctx *ctx, const char *str, const char *val,
if (len > u) {
- WS_Release(ctx->ws, 0);
+ WS_Release(WSPTR(ctx), 0);
return NULL;
@@ -313,3 +324,3 @@ expand_backref(const struct vrt_ctx *ctx, const char *str, const char *val,
if (len + 1 >= u) {
- WS_Release(ctx->ws, 0);
+ WS_Release(WSPTR(ctx), 0);
return NULL;
@@ -326,3 +337,3 @@ expand_backref(const struct vrt_ctx *ctx, const char *str, const char *val,
if (u == 0) {
- WS_Release(ctx->ws, 0);
+ WS_Release(WSPTR(ctx), 0);
return NULL;
@@ -331,3 +342,3 @@ expand_backref(const struct vrt_ctx *ctx, const char *str, const char *val,
- WS_ReleaseP(ctx->ws, p);
+ WS_ReleaseP(WSPTR(ctx), p);
@@ -339,3 +350,3 @@ expand_backref(const struct vrt_ctx *ctx, const char *str, const char *val,
static char *
-findmatch(const struct vrt_ctx *ctx, struct dbrw_connection *conn, char **param)
+findmatch(DBRW_CTX ctx, struct dbrw_connection *conn, char **param)
{
@@ -356,3 +367,3 @@ findmatch(const struct vrt_ctx *ctx, struct dbrw_connection *conn, char **param)
if (nf < 3)
- return WS_Copy(ctx->ws, sql_get_column(conn, 0, 0), -1);
+ return WS_Copy(WSPTR(ctx), sql_get_column(conn, 0, 0), -1);
@@ -378,3 +389,3 @@ findmatch(const struct vrt_ctx *ctx, struct dbrw_connection *conn, char **param)
if (ISEMPTY(pat)) {
- res = WS_Copy(ctx->ws, sql_get_column(conn, i, 0), -1);
+ res = WS_Copy(WSPTR(ctx), sql_get_column(conn, i, 0), -1);
break;
@@ -500,3 +511,3 @@ get_connection(struct dbrw_config *conf)
VCL_STRING
-vmod_rewrite(const struct vrt_ctx *ctx, struct vmod_priv *priv, VCL_STRING arg)
+vmod_rewrite(DBRW_CTX ctx, struct vmod_priv *priv, VCL_STRING arg)
{
diff --git a/src/vmod_dbrw.vcc b/src/vmod_dbrw.vcc
index a2ec9d2..10fef6f 100644
--- a/src/vmod_dbrw.vcc
+++ b/src/vmod_dbrw.vcc
@@ -33,13 +33,15 @@ $Function VOID config(PRIV_VCL, STRING, STRING, STRING)
Description
- Configures the module and provides it with the data
- necessary to connect and use the database. It is normally called
- from the **vcl_init** subroutine.
+ Configures the module and provides it with the data
+ necessary to connect and use the database. It is normally called
+ from the **vcl_init** subroutine.
Example
- dbrw.config("mysql",
- "database=rewrite;user=varnish;password=guessme",
- {"SELECT dest
- FROM redirects
- WHERE host='$host'
- AND url='$url'"});
+ ::
+
+ dbrw.config("mysql",
+ "database=rewrite;user=varnish;password=guessme",
+ {"SELECT dest
+ FROM redirects
+ WHERE host='$host'
+ AND url='$url'"});
@@ -50,6 +52,8 @@ Description
Rewrites its argument using the database configured in the previous
- call to `**config** and returns the obtained value.
+ call to **config** and returns the obtained value.
Example
- set req.http.X-Redirect-To =
+ ::
+
+ set req.http.X-Redirect-To =
dbrw.rewrite("host=" + req.http.Host + ";" +

Return to:

Send suggestions and report system problems to the System administrator.