aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2014-11-01 14:10:23 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2014-11-01 14:10:23 +0200
commitdacdfd20c9e59e088bfb23c2852b566acc6ad06f (patch)
tree9c8acf2e253afd9593d5f6fccd560f7173485d48
parent4d452a770122daf33fdbe0a549e2804b6f2db086 (diff)
downloadvmod-tbf-dacdfd20c9e59e088bfb23c2852b566acc6ad06f.tar.gz
vmod-tbf-dacdfd20c9e59e088bfb23c2852b566acc6ad06f.tar.bz2
Support for VCL 4.0
* NEWS: Update. * configure.ac: Version 1.0.90 Detect Varnish version, set up the C defines and automake conditionals to indicate it. * src/.gitignore: Update. * src/Makefile.am: Don't distribute vcc_if.c and vcc_if.h, build them for the current Varnish version. * src/tbf.h: New file. * src/getla.c: Include tbf.h, rewrite to compile with both 3.0 and 4.0 * src/sleep.c: Likewise. * src/tbf.c: Likewise. * src/time.c: Likewise. * src/vmod_tbf.vcc: Rewrite using v4.0 format. * tests/.gitignore: New file. * tests/Makefile.am: Build test00.vtc and test02.vtc * tests/test00.vtc: Rename to tests/test00.vti, add conditional compilation directives. * tests/test02.vtc: Rename to tests/test02.vti, add conditional compilation directives.
-rw-r--r--NEWS11
-rw-r--r--configure.ac14
-rw-r--r--src/.gitignore1
-rw-r--r--src/Makefile.am31
-rw-r--r--src/getla.c11
-rw-r--r--src/sleep.c8
-rw-r--r--src/tbf.c30
-rw-r--r--src/tbf.h38
-rw-r--r--src/time.c23
-rw-r--r--src/vmod_tbf.vcc47
-rw-r--r--tests/.gitignore2
-rw-r--r--tests/Makefile.am31
-rw-r--r--tests/test00.vti (renamed from tests/test00.vtc)6
-rw-r--r--tests/test02.vti (renamed from tests/test02.vtc)6
14 files changed, 183 insertions, 76 deletions
diff --git a/NEWS b/NEWS
index 9c771b3..f5bcc13 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,3 @@
1vmod-tbf -- history of user-visible changes. 2013-10-19 1vmod-tbf -- history of user-visible changes. 2014-10-31
2Copyright (C) 2013 Sergey Poznyakoff 2Copyright (C) 2013-2014 Sergey Poznyakoff
3See the end of file for copying conditions. 3See the end of file for copying conditions.
@@ -7,2 +7,7 @@ Please send vmod-tbf bug reports to <gray@gnu.org>
7 7
8Version 1.0.90 (git)
9
10Support for VCL 4.0
11
12
8Version 1.0, 2013-10-19 13Version 1.0, 2013-10-19
@@ -14,3 +19,3 @@ Copyright information:
14 19
15Copyright (C) 2013 Sergey Poznyakoff 20Copyright (C) 2013-2014 Sergey Poznyakoff
16 21
diff --git a/configure.ac b/configure.ac
index 6af8fd6..70fd78d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,3 +16,3 @@
16AC_PREREQ(2.69) 16AC_PREREQ(2.69)
17AC_INIT([vmod-tbf], 1.0, [gray@gnu.org]) 17AC_INIT([vmod-tbf], 1.0.90, [gray@gnu.org])
18AC_CONFIG_AUX_DIR([build-aux]) 18AC_CONFIG_AUX_DIR([build-aux])
@@ -69,5 +69,13 @@ esac
69VARNISHSRC=`cd $VARNISHSRC && pwd` 69VARNISHSRC=`cd $VARNISHSRC && pwd`
70VARNISHVERSION=
70AC_CHECK_FILE([$VARNISHSRC/include/varnishapi.h], 71AC_CHECK_FILE([$VARNISHSRC/include/varnishapi.h],
71 [], 72 [VARNISHVERSION=3],
72 [AC_MSG_FAILURE(["$VARNISHSRC" is not a Varnish source directory])]) 73 [AC_CHECK_FILE([$VARNISHSRC/include/vapi/vsm.h],
74 [VARNISHVERSION=4],
75 [AC_MSG_FAILURE(["$VARNISHSRC" is not a Varnish source directory])]) ])
76AC_SUBST([VARNISHVERSION],$VARNISHVERSION)
77
78AC_DEFINE_UNQUOTED([VARNISHVERSION],$VARNISHVERSION,[Varnish major version number])
79AM_CONDITIONAL([VARNISH3],[test $VARNISHVERSION -eq 3])
80AM_CONDITIONAL([VARNISH4],[test $VARNISHVERSION -eq 4])
73 81
diff --git a/src/.gitignore b/src/.gitignore
index 7f6e438..ce7aef0 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -2 +2,2 @@ vcc_if.c
2vcc_if.h 2vcc_if.h
3*.rst
diff --git a/src/Makefile.am b/src/Makefile.am
index 727d33b..f4e3bec 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -18,2 +18,3 @@ AM_CPPFLAGS=\
18 -I$(VARNISHSRC)/include\ 18 -I$(VARNISHSRC)/include\
19 -I$(VARNISHSRC)/bin/varnishd\
19 -I$(VARNISHSRC)\ 20 -I$(VARNISHSRC)\
@@ -30,12 +31,31 @@ libvmod_tbf_la_LIBADD=
30libvmod_tbf_la_SOURCES = \ 31libvmod_tbf_la_SOURCES = \
32 tbf.c\
33 tbf.h\
31 getla.c\ 34 getla.c\
32 sleep.c\ 35 sleep.c\
33 time.c\ 36 time.c
34 tbf.c\ 37nodist_libvmod_tbf_la_SOURCES = \
35 vcc_if.c vcc_if.h 38 vcc_if.c vcc_if.h
36 39
37BUILT_SOURCES = vcc_if.c vcc_if.h 40tbf.lo: vcc_if.h
41
42CLEANFILES = vcc_if.c vcc_if.h *.rst
43
44if VARNISH4
45 vmodtool = $(VARNISHSRC)/lib/libvcc/vmodtool.py
46 vmodtoolargs = --strict
47 vccfile = $(top_srcdir)/src/vmod_tbf.vcc
48else
49 vmodtool = $(VARNISHSRC)/lib/libvmod_std/vmod.py
50 vmodtoolargs =
51 vccfile = vmod_tbf.vcc3
52
53vmod_tbf.vcc3: $(top_srcdir)/src/vmod_tbf.vcc
54 CLEANFILES += vmod_tbf.vcc3
55endif
38 56
39vcc_if.c vcc_if.h: $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod_tbf.vcc 57.vcc.vcc3:
40 @PYTHON@ $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod_tbf.vcc 58 sed -n '/^\$$/{s///;s/\(Module *[^ ][^ ]*\).*/\1/;p}' $< > $@
59vcc_if.c vcc_if.h: $(vmodtool) $(vccfile)
60 @PYTHON@ $(vmodtool) $(vmodtoolargs) $(vccfile)
41 61
@@ -44,3 +64,2 @@ EXTRA_DIST = \
44 64
45CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h
46 65
diff --git a/src/getla.c b/src/getla.c
index c735956..51791c4 100644
--- a/src/getla.c
+++ b/src/getla.c
@@ -17,6 +17,3 @@
17#define _BSD_SOURCE 17#define _BSD_SOURCE
18#include <config.h> 18#include "tbf.h"
19#include <stdlib.h>
20#include <stdio.h>
21#include <syslog.h>
22#if defined(HAVE_SYSINFO) && defined(HAVE_SYS_SYSINFO_H) 19#if defined(HAVE_SYSINFO) && defined(HAVE_SYS_SYSINFO_H)
@@ -24,4 +21,2 @@
24#endif 21#endif
25#include "vrt.h"
26#include "vcc_if.h"
27 22
@@ -52,4 +47,4 @@ sys_getla(int what)
52 47
53double 48VCL_REAL
54vmod_getla(struct sess *sp, int what) 49vmod_getla(MOD_CTX ctx, VCL_INT what)
55{ 50{
diff --git a/src/sleep.c b/src/sleep.c
index 70c4337..9242475 100644
--- a/src/sleep.c
+++ b/src/sleep.c
@@ -16,10 +16,8 @@
16*/ 16*/
17#include <config.h> 17#include "tbf.h"
18#include <errno.h> 18#include <errno.h>
19#include <time.h> 19#include <time.h>
20#include "vrt.h"
21#include "vcc_if.h"
22 20
23void 21VCL_VOID
24vmod_sleep(struct sess *sp, double t) 22vmod_sleep(MOD_CTX ctx, VCL_REAL t)
25{ 23{
diff --git a/src/tbf.c b/src/tbf.c
index 7050fc7..56a4ad1 100644
--- a/src/tbf.c
+++ b/src/tbf.c
@@ -16,6 +16,3 @@
16*/ 16*/
17#include <config.h> 17#include "tbf.h"
18#include <stdlib.h>
19#include <stdio.h>
20#include <stdbool.h>
21#include <syslog.h> 18#include <syslog.h>
@@ -23,6 +20,4 @@
23#include <sys/stat.h> 20#include <sys/stat.h>
21#include <sys/time.h>
24#include <db.h> 22#include <db.h>
25#include "vrt.h"
26#include "vcc_if.h"
27#include "bin/varnishd/cache.h"
28 23
@@ -353,3 +348,3 @@ tbf_init(struct vmod_priv *priv, const struct VCL_conf *vclconf)
353void 348void
354vmod_open(struct sess *sp, const char *dir, const char *params) 349vmod_open(MOD_CTX ctx, const char *dir, const char *params)
355{ 350{
@@ -364,3 +359,3 @@ vmod_open(struct sess *sp, const char *dir, const char *params)
364void 359void
365vmod_close(struct sess *sp) 360vmod_close(MOD_CTX ctx)
366{ 361{
@@ -379,3 +374,3 @@ vmod_close(struct sess *sp)
379void 374void
380vmod_sync(struct sess *sp) 375vmod_sync(MOD_CTX ctx)
381{ 376{
@@ -412,3 +407,3 @@ struct tbf_bucket {
412int 407int
413tbf_proc(struct sess *sp, DB *db, const char *key, int cost, 408tbf_proc(MOD_CTX ctx, DB *db, const char *key, int cost,
414 unsigned long interval, int burst_size) 409 unsigned long interval, int burst_size)
@@ -501,4 +496,5 @@ tbf_proc(struct sess *sp, DB *db, const char *key, int cost,
501 496
502unsigned 497VCL_BOOL
503vmod_rate(struct sess *sp, const char *key, int cost, double t, int burst_size) 498vmod_rate(MOD_CTX ctx, VCL_STRING key, VCL_INT cost, VCL_REAL t,
499 VCL_INT burst_size)
504{ 500{
@@ -529,3 +525,3 @@ vmod_rate(struct sess *sp, const char *key, int cost, double t, int burst_size)
529 AZ(pthread_mutex_lock(&kp->mutex)); 525 AZ(pthread_mutex_lock(&kp->mutex));
530 rc = tbf_proc(sp, db, key, cost, interval, burst_size); 526 rc = tbf_proc(ctx, db, key, cost, interval, burst_size);
531 if (--kp->refcnt == 0) 527 if (--kp->refcnt == 0)
@@ -541,4 +537,4 @@ vmod_rate(struct sess *sp, const char *key, int cost, double t, int burst_size)
541 537
542unsigned 538VCL_BOOL
543vmod_check(struct sess *sp, const char *key, const char *spec) 539vmod_check(MOD_CTX ctx, VCL_STRING key, VCL_STRING spec)
544{ 540{
@@ -603,3 +599,3 @@ vmod_check(struct sess *sp, const char *key, const char *spec)
603 599
604 return vmod_rate(sp, key, 1, n/v, v/n+1); 600 return vmod_rate(ctx, key, 1, n/v, v/n+1);
605} 601}
diff --git a/src/tbf.h b/src/tbf.h
new file mode 100644
index 0000000..3c7a118
--- /dev/null
+++ b/src/tbf.h
@@ -0,0 +1,38 @@
1/* This file is part of vmod-tbf
2 Copyright (C) 2013-2014 Sergey Poznyakoff
3
4 Vmod-tbf is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 Vmod-tbf is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with vmod-tbf. If not, see <http://www.gnu.org/licenses/>.