aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2014-10-31 12:38:57 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2014-10-31 14:27:22 +0200
commit5d7657a6b0c7c5f72dbee90f1025e9facab0b4c9 (patch)
treecd4898922f8bd73d514bcb2f132b9ceaf30d1e45
parenta478d2eddea7eaae06291af5dc5dfc93e6f75904 (diff)
downloadvmod-dbrw-5d7657a6b0c7c5f72dbee90f1025e9facab0b4c9.tar.gz
vmod-dbrw-5d7657a6b0c7c5f72dbee90f1025e9facab0b4c9.tar.bz2
Initial rewrite for Varnish 4.x
* configure.ac: Check for include/vapi/vsm.h in varnish source tree. Change version number to 1.0.91-vcl4 * NEWS: Update version number. * src/Makefile.am (AM_CPPFLAGS): Add $(VARNISHSRC)/bin/varnishd (vmodtool,vmodtoolargs): New variables. (vcc_if.c vcc_if.h): Rewrite the rule. * src/vmod_dbrw.c: Include pthread.h Change path to cache.h (vmod_config,vmod_rewrite): Change declaration. (expand_backref,findmatch): Change declaration. Use WS_Copy instead of WS_Dup. * src/vmod_dbrw.vcc: Rewrite.
-rw-r--r--NEWS4
-rw-r--r--configure.ac4
-rw-r--r--src/Makefile.am9
-rw-r--r--src/vmod_dbrw.c41
-rw-r--r--src/vmod_dbrw.vcc66
5 files changed, 94 insertions, 30 deletions
diff --git a/NEWS b/NEWS
index 933c3de..d36806a 100644
--- a/NEWS
+++ b/NEWS
@@ -7,3 +7,5 @@ Please send vmod-dbrw bug reports to <gray@gnu.org>
-Version 1.0.91, (git)
+Version 1.0.91-vcl4, (git)
+
+Rewritten for Varnish v4.x
diff --git a/configure.ac b/configure.ac
index 618f304..e1c55eb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,3 +16,3 @@
AC_PREREQ(2.69)
-AC_INIT([vmod-dbrw], 1.0.91, [gray@gnu.org])
+AC_INIT([vmod-dbrw], 1.0.91-vcl4, [gray@gnu.org])
AC_CONFIG_AUX_DIR([build-aux])
@@ -66,3 +66,3 @@ esac
VARNISHSRC=`cd $VARNISHSRC && pwd`
-AC_CHECK_FILE([$VARNISHSRC/include/varnishapi.h],
+AC_CHECK_FILE([$VARNISHSRC/include/vapi/vsm.h],
[],
diff --git a/src/Makefile.am b/src/Makefile.am
index ed7d376..dde9116 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -16,3 +16,3 @@
-AM_CPPFLAGS = -I$(VARNISHSRC)/include -I$(VARNISHSRC)
+AM_CPPFLAGS = -I$(VARNISHSRC)/include -I$(VARNISHSRC)/bin/varnishd -I$(VARNISHSRC)
@@ -42,4 +42,7 @@ BUILT_SOURCES = vcc_if.c vcc_if.h
-vcc_if.c vcc_if.h: $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod_dbrw.vcc
- @PYTHON@ $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod_dbrw.vcc
+vmodtool = $(VARNISHSRC)/lib/libvcc/vmodtool.py
+vmodtoolargs = --strict
+
+vcc_if.c vcc_if.h: $(vmodtool) $(top_srcdir)/src/vmod_dbrw.vcc
+ @PYTHON@ $(vmodtool) $(vmodtoolargs) $(top_srcdir)/src/vmod_dbrw.vcc
diff --git a/src/vmod_dbrw.c b/src/vmod_dbrw.c
index f7723a2..284376f 100644
--- a/src/vmod_dbrw.c
+++ b/src/vmod_dbrw.c
@@ -21,3 +21,4 @@
#include "vcc_if.h"
-#include "bin/varnishd/cache.h"
+#include "pthread.h"
+#include "bin/varnishd/cache/cache.h"
@@ -204,5 +205,5 @@ parse_flags(const char *arg, int *qdisp, int *flags, char status[])
*/
-void
-vmod_config(struct sess *sp, struct vmod_priv *priv, const char *bkname,
- const char *param, const char *query)
+VCL_VOID
+vmod_config(const struct vrt_ctx *ctx, struct vmod_priv *priv,
+ VCL_STRING bkname, VCL_STRING param, VCL_STRING query)
{
@@ -262,3 +263,3 @@ vmod_config(struct sess *sp, struct vmod_priv *priv, const char *bkname,
static char *
-expand_backref(struct sess *sp, const char *str, const char *val,
+expand_backref(const struct vrt_ctx *ctx, const char *str, const char *val,
size_t matchcount, regmatch_t *matches, char *qry)
@@ -268,4 +269,4 @@ expand_backref(struct sess *sp, const char *str, const char *val,
- u = WS_Reserve(sp->wrk->ws, 0);
- p = b = sp->wrk->ws->f;
+ u = WS_Reserve(ctx->ws, 0);
+ p = b = ctx->ws->f;
@@ -273,3 +274,3 @@ expand_backref(struct sess *sp, const char *str, const char *val,
if (u == 0) {
- WS_Release(sp->wrk->ws, 0);
+ WS_Release(ctx->ws, 0);
return NULL;
@@ -286,3 +287,3 @@ expand_backref(struct sess *sp, const char *str, const char *val,
if (len > u) {
- WS_Release(sp->wrk->ws, 0);
+ WS_Release(ctx->ws, 0);
return NULL;
@@ -312,3 +313,3 @@ expand_backref(struct sess *sp, const char *str, const char *val,
if (len + 1 >= u) {
- WS_Release(sp->wrk->ws, 0);
+ WS_Release(ctx->ws, 0);
return NULL;
@@ -325,3 +326,3 @@ expand_backref(struct sess *sp, const char *str, const char *val,
if (u == 0) {
- WS_Release(sp->wrk->ws, 0);
+ WS_Release(ctx->ws, 0);
return NULL;
@@ -330,3 +331,3 @@ expand_backref(struct sess *sp, const char *str, const char *val,
- WS_ReleaseP(sp->wrk->ws, p);
+ WS_ReleaseP(ctx->ws, p);
@@ -338,3 +339,3 @@ expand_backref(struct sess *sp, const char *str, const char *val,
static char *
-findmatch(struct sess *sp, struct dbrw_connection *conn, char **param)
+findmatch(const struct vrt_ctx *ctx, struct dbrw_connection *conn, char **param)
{
@@ -355,3 +356,3 @@ findmatch(struct sess *sp, struct dbrw_connection *conn, char **param)
if (nf < 3)
- return WS_Dup(sp->ws, sql_get_column(conn, 0, 0));
+ return WS_Copy(ctx->ws, sql_get_column(conn, 0, 0), -1);
@@ -377,3 +378,3 @@ findmatch(struct sess *sp, struct dbrw_connection *conn, char **param)
if (ISEMPTY(pat)) {
- res = WS_Dup(sp->ws, sql_get_column(conn, i, 0));
+ res = WS_Copy(ctx->ws, sql_get_column(conn, i, 0), -1);
break;
@@ -444,3 +445,3 @@ findmatch(struct sess *sp, struct dbrw_connection *conn, char **param)
if (rc == 0)
- res = expand_backref(sp, val,
+ res = expand_backref(ctx, val,
sql_get_column(conn, i, 0),
@@ -454,3 +455,3 @@ findmatch(struct sess *sp, struct dbrw_connection *conn, char **param)
("setting status %s", status));
- VRT_SetHdr(sp, HDR_REQ,
+ VRT_SetHdr(ctx, HDR_REQ,
"\023X-VMOD-DBRW-Status:",
@@ -498,4 +499,4 @@ get_connection(struct dbrw_config *conf)
-const char *
-vmod_rewrite(struct sess *sp, struct vmod_priv *priv, const char *arg)
+VCL_STRING
+vmod_rewrite(const struct vrt_ctx *ctx, struct vmod_priv *priv, VCL_STRING arg)
{
@@ -566,3 +567,3 @@ vmod_rewrite(struct sess *sp, struct vmod_priv *priv, const char *arg)
- res = findmatch(sp, cp, wsenv.ws_wordv);
+ res = findmatch(ctx, cp, wsenv.ws_wordv);
wordsplit_free(&wsenv);
diff --git a/src/vmod_dbrw.vcc b/src/vmod_dbrw.vcc
index 515883f..a2ec9d2 100644
--- a/src/vmod_dbrw.vcc
+++ b/src/vmod_dbrw.vcc
@@ -1,5 +1,63 @@
-Module dbrw
-Init dbrw_init
-Function STRING rewrite(PRIV_VCL, STRING)
-Function VOID config(PRIV_VCL, STRING, STRING, STRING)
+# This file is part of vmod-dbrw
+# Copyright (C) 2013-2014 Sergey Poznyakoff
+#
+# Vmod-dbrw is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Vmod-dbrw is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with vmod-dbrw. If not, see <http://www.gnu.org/licenses/>.
+$Module dbrw 3 Database-driven rewrite rules for Varnish Cache
+
+DESCRIPTION
+===========
+
+This module for Varnish Cache implements database-driven rewrite rules.
+These rules may be similar to *RewriteRule* directives implemented by
+**mod_rewrite** module in Apache or to *Redirect* directives of its
+**mod_alias** module. What distinguishes the **vmod-dbrw** rules from
+these, is that they are handled by Varnish, before the request reaches the
+httpd server, and that they are stored in an SQL database, which makes
+them easily manageable.
+
+$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.
+
+Example
+ 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.
+
+Example
+ set req.http.X-Redirect-To =
+ dbrw.rewrite("host=" + req.http.Host + ";" +
+ "url=" + req.url);
+
+SEE ALSO
+========
+
+* vcl(7)
+* varnishd(1)
+

Return to:

Send suggestions and report system problems to the System administrator.