summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2014-10-31 13:55:19 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2014-10-31 13:55:19 (GMT)
commit7965195e932d5ed4844dbef1e2da6e871aea6fe1 (patch) (side-by-side diff)
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.
Diffstat (more/less context) (ignore whitespace changes)
-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
@@ -5,9 +5,9 @@ See the end of file for copying conditions.
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
Version 1.0, 2013-07-20
diff --git a/configure.ac b/configure.ac
index e1c55eb..ce9087c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with vmod-dbrw. If not, see <http://www.gnu.org/licenses/>.
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])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR(src/vmod_dbrw.vcc)
@@ -64,10 +64,17 @@ case "$VARNISHSRC" in
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
AC_CHECK_FILE([$VARNISHSRC/bin/varnishtest/varnishtest],
[],
diff --git a/src/Makefile.am b/src/Makefile.am
index dde9116..f7a5a45 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -26,9 +26,11 @@ libvmod_dbrw_la_SOURCES = \
dbrw.h\
sql.c\
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
if USE_MYSQL
libvmod_dbrw_la_SOURCES += mysql.c
@@ -38,16 +40,28 @@ if USE_PGSQL
libvmod_dbrw_la_SOURCES += pgsql.c
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)
EXTRA_DIST = \
vmod_dbrw.vcc
-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
@@ -20,7 +20,18 @@
#include "vrt.h"
#include "vcc_if.h"
#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
static pthread_once_t thread_once = PTHREAD_ONCE_INIT;
static pthread_key_t thread_key;
@@ -204,7 +215,7 @@ parse_flags(const char *arg, int *qdisp, int *flags, char status[])
QUERY - Query to obtain the redirection target
*/
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)
{
char *s;
@@ -261,18 +272,18 @@ 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)
{
unsigned u;
char *b, *p;
- u = WS_Reserve(ctx->ws, 0);
- p = b = ctx->ws->f;
+ u = WS_Reserve(WSPTR(ctx), 0);
+ p = b = WSPTR(ctx)->f;
while (*val) {
if (u == 0) {
- WS_Release(ctx->ws, 0);
+ WS_Release(WSPTR(ctx), 0);
return NULL;
}
if (*val == '\\' || *val == '$') {
@@ -285,7 +296,7 @@ expand_backref(const struct vrt_ctx *ctx, const char *str, const char *val,
matches[n].rm_so;
if (len > u) {
- WS_Release(ctx->ws, 0);
+ WS_Release(WSPTR(ctx), 0);
return NULL;
}
@@ -311,7 +322,7 @@ expand_backref(const struct vrt_ctx *ctx, const char *str, const char *val,
if (qry) {
size_t len = strlen(qry);
if (len + 1 >= u) {
- WS_Release(ctx->ws, 0);
+ WS_Release(WSPTR(ctx), 0);
return NULL;
}
if (strchr(b, '?'))
@@ -324,12 +335,12 @@ 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;
}
*p = 0;
- WS_ReleaseP(ctx->ws, p);
+ WS_ReleaseP(WSPTR(ctx), p);
return b;
}
@@ -337,7 +348,7 @@ expand_backref(const struct vrt_ctx *ctx, const char *str, const char *val,
#define ISEMPTY(s) ((s) == NULL || (s)[0] == 0)
static char *
-findmatch(const struct vrt_ctx *ctx, struct dbrw_connection *conn, char **param)
+findmatch(DBRW_CTX ctx, struct dbrw_connection *conn, char **param)
{
unsigned i;
unsigned nt, nf;
@@ -354,7 +365,7 @@ findmatch(const struct vrt_ctx *ctx, struct dbrw_connection *conn, char **param)
debug(conn->conf, 2, ("query returned %u tuples, %u columns", nt, nf));
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);
/* Three or four fields:
result
@@ -376,7 +387,7 @@ findmatch(const struct vrt_ctx *ctx, struct dbrw_connection *conn, char **param)
char *qry = NULL;
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;
}
@@ -498,7 +509,7 @@ 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)
{
struct dbrw_config *conf = priv->priv;
struct dbrw_connection *cp;
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
@@ -31,27 +31,31 @@ $Init dbrw_init
$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'"});
$Function STRING rewrite(PRIV_VCL, STRING)
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 + ";" +
"url=" + req.url);

Return to:

Send suggestions and report system problems to the System administrator.