diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-08-05 19:50:12 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-08-05 20:21:05 +0300 |
commit | 625b9a4fa3c302715b06fcde8da3544f71cfe8b0 (patch) | |
tree | aa56be3b3129c8bfba769cfc9ec763ee3b1f9b69 | |
parent | aa3bfb206b14da4de737394d73098fb069b3d8ac (diff) | |
download | vmod-dbrw-625b9a4fa3c302715b06fcde8da3544f71cfe8b0.tar.gz vmod-dbrw-625b9a4fa3c302715b06fcde8da3544f71cfe8b0.tar.bz2 |
Switch to new acvmod. Remove the --with-varnish-source option. Fix the testsuite.
-rw-r--r-- | Makefile.am | 13 | ||||
-rw-r--r-- | NEWS | 17 | ||||
-rw-r--r-- | README | 64 | ||||
m--------- | acvmod | 0 | ||||
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | doc/vmod-dbrw.3 | 105 | ||||
-rw-r--r-- | doc/vmod-dbrw.texi | 62 | ||||
-rw-r--r-- | git2chg.awk | 75 | ||||
-rw-r--r-- | src/Makefile.am | 11 | ||||
-rw-r--r-- | src/dbrw.h | 4 | ||||
-rw-r--r-- | src/vmod_dbrw.c | 10 | ||||
-rw-r--r-- | tests/Makefile.am | 4 | ||||
-rw-r--r-- | tests/atlocal.in | 13 |
13 files changed, 72 insertions, 312 deletions
diff --git a/Makefile.am b/Makefile.am index e2af33e..a5248b8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ # This file is part of vmod-dbrw -# Copyright (C) 2013-2014, 2016 Sergey Poznyakoff +# Copyright (C) 2013-2017 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 @@ -17,14 +17,5 @@ ACLOCAL_AMFLAGS = -I m4 -I acvmod SUBDIRS = src doc tests -AM_DISTCHECK_CONFIGURE_FLAGS=--without-vmoddir - -EXTRA_DIST=git2chg.awk - -.PHONY: ChangeLog -ChangeLog: - $(AM_V_GEN)if test -d .git; then \ - git log --pretty='format:%ct %an <%ae>%n%n%s%n%n%b%n' | \ - awk -f $(top_srcdir)/git2chg.awk > ChangeLog; \ - fi +include acvmod/top.am @@ -1,18 +1,17 @@ -vmod-dbrw -- history of user-visible changes. 2016-01-24 -Copyright (C) 2013-2016 Sergey Poznyakoff +vmod-dbrw -- history of user-visible changes. 2017-08-05 +Copyright (C) 2013-2017 Sergey Poznyakoff See the end of file for copying conditions. Please send vmod-dbrw bug reports to <gray@gnu.org> -Version 2.0.90-4.1.0, (Git) +Version 2.0.92, (Git) -* Support for Varnish 4.1 +* Requires Varnish 4.1 -* Versioning changes - -Starting with this release, the version number includes version -of Varnish API the release was designed for. +* The --with-varnish-source option has been withdrawn +The configure script relies on pkg-config to determine the location of +Varnish header files and libraries. Version 2.0, 2014-11-13 @@ -27,7 +26,7 @@ Initial release ========================================================================= Copyright information: -Copyright (C) 2013-2016 Sergey Poznyakoff +Copyright (C) 2013-2017 Sergey Poznyakoff Permission is granted to anyone to make or distribute verbatim copies of this document as received, in any medium, provided that the @@ -1,5 +1,5 @@ Vmod-dbrw README -Copyright (C) 2013-2014 Sergey Poznyakoff +Copyright (C) 2013-2017 Sergey Poznyakoff See the end of file for copying conditions. * Introduction @@ -46,42 +46,13 @@ The redirection database has the following structure PRIMARY KEY (host,url) ); -VCL 3.x code: +The VCL code: import dbrw; - sub vcl_init { - dbrw.config("mysql", "database=dbname;user=varnish;debug=1", - "SELECT dest FROM redirects WHERE host='$host' AND url='$url'"); - } - sub vcl_recv { - set req.http.X-Redirect-To = - dbrw.rewrite("host=" + req.http.Host + ";" + - "url=" + req.url); - if (req.http.X-Redirect-To != "") { - error(750, "Redirect"); - } - } - - sub vcl_error { - if (obj.status == 750) { - set obj.http.Location = req.http.X-Redirect-To; - set obj.status = 301; - return (deliver); - } - } - -VCL 4.0 code: - - import dbrw; - - sub vcl_init { dbrw.config("mysql", "database=dbname;user=varnish;debug=1", "SELECT dest FROM redirects WHERE host='$host' AND url='$url'"); - } - - sub vcl_recv { set req.http.X-Redirect-To = dbrw.rewrite("host=" + req.http.Host + ";" + "url=" + req.url); @@ -110,9 +81,9 @@ Table structure: KEY source (host,url) ) -VCL code differs only in definition of the vcl_init: +The VCL code differs only in the call to dbrw.config in vcl_recv: - sub vcl_init { + sub vcl_recv { dbrw.config("mysql", "database=varnish;user=varnish;debug=10", {"SELECT dest,pattern,value FROM rewrite WHERE host='$host' and '$url' like url"}); @@ -120,17 +91,32 @@ VCL code differs only in definition of the vcl_init: * Installation -In order to compile the package you need to have Varnish source tree. -Both Varnish 3.x and 4.x are supported. Supposing that the Varnish -source tree is available under /usr/src/varnish-3.0.1, run: +In order to compile the package you need to have installed +varnishd and varnishapi package. + +Supposing that condition is met, run: + + ./configure - ./configure --with-varnish-source=/usr/src/varnish-3.0.1 +It should be able to automatically find the necessary components. In case +it doesn't, tweak the configuration variables as necessary. The most +important one is PKG_CONFIG_PATH, which contains a path (in the UNIX sense) +where the .pc files are located. It should contain a directory where the +'varnishapi.pc' file lives. Example usage: + + ./configure PKG_CONFIG_PATH=/usr/local/varnish/lib/pkgconfig:$PKG_CONFIG_PATH + +Please read the file INSTALL for a detailed discussion of available variables +and command line options. Once configured, do make -This will build the module. Finally, do the following command as root: +This will build the module. After this step you can optionally run +'make test' to test the package. + +Finally, run the following command as root: make install @@ -237,7 +223,7 @@ Send bug reports and suggestions to <gray@gnu.org> * Copyright information: -Copyright (C) 2013-2014 Sergey Poznyakoff +Copyright (C) 2013-2017 Sergey Poznyakoff Permission is granted to anyone to make or distribute verbatim copies of this document as received, in any medium, provided that the diff --git a/acvmod b/acvmod -Subproject f064cf4d7aa1ead1f8607b8b72baf883f015ffc +Subproject ba32780019480b89cd9d796b93a76cae6afe99a diff --git a/configure.ac b/configure.ac index becaeef..681d471 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ # This file is part of vmod-dbrw -*- autoconf -*- -# Copyright (C) 2013-2014, 2016 Sergey Poznyakoff +# Copyright (C) 2013-2017 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 @@ -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], 2.0.91-4.1.0, [gray@gnu.org]) +AC_INIT([vmod-dbrw], 2.0.92, [gray@gnu.org]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_SRCDIR(src/vmod_dbrw.vcc) @@ -42,7 +42,7 @@ AC_PROG_MAKE_SET AC_HEADER_STDC AC_CHECK_HEADERS([sys/stdlib.h]) -AM_VARNISHAPI +AM_VARNISHAPI([4.1]) ########### # Check for SQL support diff --git a/doc/vmod-dbrw.3 b/doc/vmod-dbrw.3 index 8c89cc4..139fbab 100644 --- a/doc/vmod-dbrw.3 +++ b/doc/vmod-dbrw.3 @@ -1,5 +1,5 @@ .\" This file is part of Vmod-dbrw -*- nroff -*- -.\" Copyright (C) 2013-2014 Sergey Poznyakoff +.\" Copyright (C) 2013-2017 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 @@ -13,7 +13,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/>. -.TH VMOD-DBRW 1 "April 21, 2016" "VMOD-DBRW" "User Reference" +.TH VMOD-DBRW 1 "August 5, 2017" "VMOD-DBRW" "User Reference" .SH NAME vmod-dbrw \- Database-driven rewrite rules for Varnish Cache .SH SYNOPSIS @@ -188,7 +188,7 @@ CREATE TABLE redirects ( ); .EE .PP -VCL 3.0 code: +The VCL code: .PP .EX sub vcl_recv { @@ -201,38 +201,6 @@ sub vcl_recv { dbrw.rewrite("host=" + req.http.Host + ";" + "url=" + req.url); if (req.http.X-Redirect-To != "") { - error(750, "Redirect"); - } -} - -sub vcl_error { - if (obj.status == 750) { - set obj.http.Location = req.http.X-Redirect-To; - set obj.status = 301; - return (deliver); - } -} -.EE -.PP -Notice the use of concatenation to build the argument to -\fBdbrw.rewrite\fR. -.PP -The following is the same code for VCL 4.0: -.PP -.EX -sub vcl_init { - dbrw.config("mysql", "database=dbname;user=varnish", - {"SELECT dest - FROM redirects - WHERE host='$host' - AND url='$url'"}); -} - -sub vcl_recv { - set req.http.X-Redirect-To = - dbrw.rewrite("host=" + req.http.Host + ";" + - "url=" + req.url); - if (req.http.X-Redirect-To != "") { return(synth(301, "Redirect")); } } @@ -260,50 +228,15 @@ CREATE TABLE rewrite ( ) .EE .PP -VCL 3.0 code: +The VCL: .PP .EX -import std; -import dbrw; - -sub vcl_init { +sub vcl_recv { # It is supposed that the url column contains an SQL-style # wildcard pattern. dbrw.config("mysql", "database=varnish;user=varnish;debug=10", {"SELECT dest,pattern,value,flags FROM rewrite WHERE host='$host' and '$url' like url"}); -} - -sub vcl_recv { - set req.http.X-Redirect-To = - dbrw.rewrite("host=" + req.http.Host + ";" + - "url=" + req.url); - if (req.http.X-Redirect-To != "") { - error(750, "Redirect"); - } -} -.EE -.PP -The \fBvcl_error\fR function uses the \fBX\-VMOD\-DBRW\-Status\fR -header, which may be set by \fBredirect=\fR flag in the -\fBflags\fR column. Its value is converted to integer using the -\fBinteger\fR function from the \fBstd\fR module. If the header is -not set, permanent redirect is assumed: -.PP -.EX -sub vcl_error { - if (obj.status == 750) { - set obj.http.Location = req.http.X-Redirect-To; - set obj.status = std.integer(req.http.X-VMOD-DBRW-Status, 301); - return (deliver); - } -} -.EE -.PP -For VCL 4.0, \fBvcl_synth\fR is used instead of \fBvcl_error\fR: -.PP -.EX -sub vcl_recv { set req.http.X-Redirect-To = dbrw.rewrite("host=" + req.http.Host + ";" + "url=" + req.url); @@ -320,34 +253,6 @@ sub vcl_synth { } } .EE -.SS Use of vmod-dbrw and vmod-redirect -.PP -.ie "\*[.T]"html" \{\ -For VCL 3.0 you can use the -.URL https://www.varnish-cache.org/vmod/redirect \fBvmod-redirect\fR " module" -\} -.el \{\ -For VCL 3.0 you can use the \fBvmod-redirect\fR module -.BR ( https://www.varnish-cache.org/vmod/redirect ) -\} -and get rid of the \fBvcl_error\fR subroutine: -.PP -.EX -import std; -import dbrw; -import redirect; - -sub vcl_recv { - set req.http.X-Redirect-To = - dbrw.rewrite("host=" + req.http.Host + ";" + - "url=" + req.url); - if (req.http.X-Redirect-To != "") { - error(redirect.location( - std.integer(req.http.X-VMOD-DBRW-Status, 301), - req.http.X-Redirect-To), "Redirection"); - } -} -.EE .\" The MANCGI variable is set by man.cgi script on Ulysses. .\" The download.inc file contains the default DOWNLOAD section .\" for man-based doc pages. diff --git a/doc/vmod-dbrw.texi b/doc/vmod-dbrw.texi index c0dbbea..82adda2 100644 --- a/doc/vmod-dbrw.texi +++ b/doc/vmod-dbrw.texi @@ -30,7 +30,7 @@ Published by the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -Copyright @copyright{} 2013-2016 Sergey Poznyakoff +Copyright @copyright{} 2013-2017 Sergey Poznyakoff Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -545,11 +545,17 @@ caller. @cindex vcl_recv Assuming the database structure similar to the one discussed in the previous chapter, the following example illustrates how to use -@code{rewrite} to redirect the incoming request. It assumes VCL 4.0: +@code{rewrite} to redirect the incoming request. @example @group sub vcl_recv @{ + dbrw.config("mysql", + "database=rewrite;user=varnish;password=guessme", + @{"SELECT dest + FROM redirects + WHERE host='$host' + AND url='$url'"@}); set req.http.X-Redirect-To = dbrw.rewrite("host=" + req.http.Host + ";" + "url=" + req.url); @@ -587,58 +593,6 @@ The @code{X-VMOD-DBRW-Status} header, if set, contains the status code to be returned to the client (@pxref{X-VMOD-DBRW-Status}). Notice the use of the @command{vmod_std} module to cast it to integer. -The example below shows the same code for VCL 3.0: - -@example -@group -import std; - -sub vcl_recv @{ - set req.http.X-Redirect-To = - dbrw.rewrite("host=" + req.http.Host + ";" + - "url=" + req.url); - if (req.http.X-Redirect-To != "") @{ - error(750, "Redirect"); - @} -@} - -sub vcl_error @{ - if (obj.status == 750) @{ - set obj.http.Location = req.http.X-Redirect-To; - set obj.status = - std.integer(req.http.X-VMOD-DBRW-Status, 301); - return (deliver); - @} -@} -@end group -@end example - -@cindex vmod_redirect -For VCL 3.0, you can use @command{libvmod_redirect} to simplify the -code: - -@example -@group -import std; -import dbrw; -import redirect; - -sub vcl_recv @{ - set req.http.X-Redirect-To = - dbrw.rewrite("host=" + req.http.Host + ";" + - "url=" + req.url); - if (req.http.X-Redirect-To != "") @{ - error(redirect.location( - std.integer(req.http.X-VMOD-DBRW-Status, 301), - req.http.X-Redirect-To), "Redirection"); - @} -@} -@end group -@end example - -@noindent -The @code{vcl_error} subroutine is not needed in this case. - @node Reporting Bugs @chapter How to Report a Bug diff --git a/git2chg.awk b/git2chg.awk deleted file mode 100644 index 48c0ec9..0000000 --- a/git2chg.awk +++ /dev/null @@ -1,75 +0,0 @@ -# This file is part of grecs -# Copyright (C) 2007, 2009-2014 Sergey Poznyakoff -# -# Grecs 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. -# -# Grecs 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 Grecs. If not, see <http://www.gnu.org/licenses/>. - -BEGIN { - if (since) - split(since,since_a,"-") -} - -function timeok(t, a) { - if (!since) - return 1 - split(t,a,"-") - if (a[1] < since_a[1]) - return 0 - if (a[1] > since_a[1]) - return 1 - if (a[2] < since_a[2]) - return 0 - if (a[2] > since_a[2]) - return 1 - return a[3] > since_a[3] -} - -/^[0-9]+ .* +<[^>]+>/ { - s = strftime("%F", $1) - if (!timeok(s)) - exit - sub(/^[0-9]+ +/,"") - if (s == datestr && author == $0) - next - datestr = s - author = $0 - if (runlen) { runlen = 0; print "" } - printf("%s %s\n", datestr, author) - next -} -/^Signed-off-by:/ { next } -/^<unknown>$/ { next } -NF==0 { - runlen++ - next -} -{ if (runlen) { runlen = 0; print "" } - print "\t" $0 } - -END { - if (append) { - print "" - while ((getline < append) > 0) { - if (match($0, /^Local *Variables:/)) - break - print - } - } - print "\f" - # Make sure Emacs won't recognize this line: - print "Local", "Variables:" - print "mode: change-log" - print "version-control: never" - print "buffer-read-only: t" - print "End:" -} diff --git a/src/Makefile.am b/src/Makefile.am index 00110d9..f971354 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ # This file is part of vmod-dbrw -# Copyright (C) 2013-2014, 2016 Sergey Poznyakoff +# Copyright (C) 2013-2017 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 @@ -14,11 +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/>. -AM_CPPFLAGS =\ - -I$(VARNISHSRC)/include\ - -I$(VARNISHSRC)/bin/varnishd\ - -I$(VARNISHSRC) - +AM_CPPFLAGS=$(VARNISHAPI_CFLAGS) -I. noinst_LTLIBRARIES = libsql.la libsql_la_SOURCES = \ be.c\ @@ -50,12 +46,11 @@ vmod_dbrw.lo: vcc_if.h CLEANFILES = vcc_if.c vcc_if.h *.rst -vmodtool = $(VARNISHSRC)/lib/libvcc/vmodtool.py vmodtoolargs = --strict vccfile = $(top_srcdir)/src/vmod_dbrw.vcc vcc_if.c vcc_if.h: $(vmodtool) $(vccfile) - $(AM_V_GEN)$(PYTHON) $(vmodtool) $(vmodtoolargs) $(vccfile) + $(AM_V_GEN)$(PYTHON) $(VARNISHAPI_VMODTOOL) $(vmodtoolargs) $(vccfile) EXTRA_DIST = \ vmod_dbrw.vcc @@ -1,5 +1,5 @@ /* This file is part of vmod-dbrw - Copyright (C) 2013-2014 Sergey Poznyakoff + Copyright (C) 2013-2017 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 @@ -24,7 +24,7 @@ #include "vcl.h" #include "vrt.h" #include "vcc_if.h" -#include "bin/varnishd/cache/cache.h" +#include "cache/cache.h" #define WSPTR(s) ((s)->ws) struct dbrw_connection; diff --git a/src/vmod_dbrw.c b/src/vmod_dbrw.c index c3436f8..9e6af1e 100644 --- a/src/vmod_dbrw.c +++ b/src/vmod_dbrw.c @@ -1,5 +1,5 @@ /* This file is part of vmod-dbrw - Copyright (C) 2013-2014 Sergey Poznyakoff + Copyright (C) 2013-2017 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 @@ -198,7 +198,6 @@ parse_flags(const char *arg, int *qdisp, int *flags, char status[]) return rc; } - /* Configure the module. BACKEND - "mysql" or "pgsql" PARAM - VAR=VALUE*: @@ -571,3 +570,10 @@ vmod_rewrite(VRT_CTX, struct vmod_priv *priv, VCL_STRING arg) debug(conf, 1, ("vmod_rewrite: res=%s", res ? res : "(NULL)")); return res; } +wd() +{ + int volatile _st=0; + while (!_st) { + _st=_st; + } +} diff --git a/tests/Makefile.am b/tests/Makefile.am index 4ca2c94..0da98e8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,5 @@ # This file is part of vmod-dbrw -# Copyright (C) 2013-2014, 2016 Sergey Poznyakoff +# Copyright (C) 2013-2017 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 @@ -76,7 +76,7 @@ check_PROGRAMS = initdb initdb_SOURCES = initdb.c initdb_LDADD = ../src/libsql.la initdb_CFLAGS = $(AM_CFLAGS) -AM_CPPFLAGS = -I$(top_srcdir)/src +AM_CPPFLAGS = $(VARNISHAPI_CFLAGS) -I$(top_srcdir)/src diff --git a/tests/atlocal.in b/tests/atlocal.in index c5ee511..b8b4066 100644 --- a/tests/atlocal.in +++ b/tests/atlocal.in @@ -1,12 +1,13 @@ # @configure_input@ -*- shell-script -*- # Configurable variable values for vmod-dbrw test suite. -# Copyright (C) 2013-2014, 2016 Sergey Poznyakoff +# Copyright (C) 2013-2017 Sergey Poznyakoff PATH=@abs_builddir@:@abs_top_builddir@/src:@abs_top_srcdir@/build-aux:$top_srcdir:$srcdir:$PATH INITFILE=@abs_builddir@/.TESTINIT FAILFILE=@abs_builddir@/FAILURE -VARNISHTEST="@VARNISHSRC@/bin/varnishtest/varnishtest -Dvarnishd=@VARNISHSRC@/bin/varnishd/varnishd" -VARNISHVERSION=@VARNISHVERSION@ +VARNISHD=@VARNISHD@ +VARNISHTEST="@VARNISHTEST@ -Dvarnishd=$VARNISHD" +VARNISHVERSION=@VARNISH_MAJOR@ : ${DBRW_TEST_DBTYPE=@DBRW_TEST_DBTYPE@} : ${DBRW_TEST_PARAMS=@DBRW_TEST_PARAMS@} : ${DBRW_TEST_SERVER=@DBRW_TEST_SERVER@} @@ -41,12 +42,10 @@ server s1 { varnish v1 -vcl+backend { import std; import dbrw from "$abs_top_builddir/src/.libs/libvmod_dbrw.so"; - sub vcl_init { - dbrw.config("$DBRW_TEST_DBTYPE", "$DBRW_TEST_PARAMS", - {"$1"}); - } sub vcl_recv { + dbrw.config("$DBRW_TEST_DBTYPE", "$DBRW_TEST_PARAMS", + {"$1"}); set req.http.X-Redirect-To = dbrw.rewrite("host=" + req.http.Host + ";" + "url=" + req.url); |