diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-11-01 14:10:23 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-11-01 14:10:23 +0200 |
commit | dacdfd20c9e59e088bfb23c2852b566acc6ad06f (patch) | |
tree | 9c8acf2e253afd9593d5f6fccd560f7173485d48 | |
parent | 4d452a770122daf33fdbe0a549e2804b6f2db086 (diff) | |
download | vmod-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-- | NEWS | 11 | ||||
-rw-r--r-- | configure.ac | 14 | ||||
-rw-r--r-- | src/.gitignore | 1 | ||||
-rw-r--r-- | src/Makefile.am | 31 | ||||
-rw-r--r-- | src/getla.c | 11 | ||||
-rw-r--r-- | src/sleep.c | 8 | ||||
-rw-r--r-- | src/tbf.c | 30 | ||||
-rw-r--r-- | src/tbf.h | 38 | ||||
-rw-r--r-- | src/time.c | 23 | ||||
-rw-r--r-- | src/vmod_tbf.vcc | 47 | ||||
-rw-r--r-- | tests/.gitignore | 2 | ||||
-rw-r--r-- | tests/Makefile.am | 31 | ||||
-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
@@ -1,3 +1,3 @@ | |||
1 | vmod-tbf -- history of user-visible changes. 2013-10-19 | 1 | vmod-tbf -- history of user-visible changes. 2014-10-31 |
2 | Copyright (C) 2013 Sergey Poznyakoff | 2 | Copyright (C) 2013-2014 Sergey Poznyakoff |
3 | See the end of file for copying conditions. | 3 | See the end of file for copying conditions. |
@@ -7,2 +7,7 @@ Please send vmod-tbf bug reports to <gray@gnu.org> | |||
7 | 7 | ||
8 | Version 1.0.90 (git) | ||
9 | |||
10 | Support for VCL 4.0 | ||
11 | |||
12 | |||
8 | Version 1.0, 2013-10-19 | 13 | Version 1.0, 2013-10-19 |
@@ -14,3 +19,3 @@ Copyright information: | |||
14 | 19 | ||
15 | Copyright (C) 2013 Sergey Poznyakoff | 20 | Copyright (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 @@ | |||
16 | AC_PREREQ(2.69) | 16 | AC_PREREQ(2.69) |
17 | AC_INIT([vmod-tbf], 1.0, [gray@gnu.org]) | 17 | AC_INIT([vmod-tbf], 1.0.90, [gray@gnu.org]) |
18 | AC_CONFIG_AUX_DIR([build-aux]) | 18 | AC_CONFIG_AUX_DIR([build-aux]) |
@@ -69,5 +69,13 @@ esac | |||
69 | VARNISHSRC=`cd $VARNISHSRC && pwd` | 69 | VARNISHSRC=`cd $VARNISHSRC && pwd` |
70 | VARNISHVERSION= | ||
70 | AC_CHECK_FILE([$VARNISHSRC/include/varnishapi.h], | 71 | AC_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])]) ]) | ||
76 | AC_SUBST([VARNISHVERSION],$VARNISHVERSION) | ||
77 | |||
78 | AC_DEFINE_UNQUOTED([VARNISHVERSION],$VARNISHVERSION,[Varnish major version number]) | ||
79 | AM_CONDITIONAL([VARNISH3],[test $VARNISHVERSION -eq 3]) | ||
80 | AM_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 | |||
2 | vcc_if.h | 2 | vcc_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= | |||
30 | libvmod_tbf_la_SOURCES = \ | 31 | libvmod_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\ | 37 | nodist_libvmod_tbf_la_SOURCES = \ |
35 | vcc_if.c vcc_if.h | 38 | vcc_if.c vcc_if.h |
36 | 39 | ||
37 | BUILT_SOURCES = vcc_if.c vcc_if.h | 40 | tbf.lo: vcc_if.h |
41 | |||
42 | CLEANFILES = vcc_if.c vcc_if.h *.rst | ||
43 | |||
44 | if VARNISH4 | ||
45 | vmodtool = $(VARNISHSRC)/lib/libvcc/vmodtool.py | ||
46 | vmodtoolargs = --strict | ||
47 | vccfile = $(top_srcdir)/src/vmod_tbf.vcc | ||
48 | else | ||
49 | vmodtool = $(VARNISHSRC)/lib/libvmod_std/vmod.py | ||
50 | vmodtoolargs = | ||
51 | vccfile = vmod_tbf.vcc3 | ||
52 | |||
53 | vmod_tbf.vcc3: $(top_srcdir)/src/vmod_tbf.vcc | ||
54 | CLEANFILES += vmod_tbf.vcc3 | ||
55 | endif | ||
38 | 56 | ||
39 | vcc_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}' $< > $@ |
59 | vcc_if.c vcc_if.h: $(vmodtool) $(vccfile) | ||
60 | @PYTHON@ $(vmodtool) $(vmodtoolargs) $(vccfile) | ||
41 | 61 | ||
@@ -44,3 +64,2 @@ EXTRA_DIST = \ | |||
44 | 64 | ||
45 | CLEANFILES = $(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 | ||
53 | double | 48 | VCL_REAL |
54 | vmod_getla(struct sess *sp, int what) | 49 | vmod_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 | ||
23 | void | 21 | VCL_VOID |
24 | vmod_sleep(struct sess *sp, double t) | 22 | vmod_sleep(MOD_CTX ctx, VCL_REAL t) |
25 | { | 23 | { |
@@ -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) | |||
353 | void | 348 | void |
354 | vmod_open(struct sess *sp, const char *dir, const char *params) | 349 | vmod_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) | |||
364 | void | 359 | void |
365 | vmod_close(struct sess *sp) | 360 | vmod_close(MOD_CTX ctx) |
366 | { | 361 | { |
@@ -379,3 +374,3 @@ vmod_close(struct sess *sp) | |||
379 | void | 374 | void |
380 | vmod_sync(struct sess *sp) | 375 | vmod_sync(MOD_CTX ctx) |
381 | { | 376 | { |
@@ -412,3 +407,3 @@ struct tbf_bucket { | |||
412 | int | 407 | int |
413 | tbf_proc(struct sess *sp, DB *db, const char *key, int cost, | 408 | tbf_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 | ||
502 | unsigned | 497 | VCL_BOOL |
503 | vmod_rate(struct sess *sp, const char *key, int cost, double t, int burst_size) | 498 | vmod_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 | ||
542 | unsigned | 538 | VCL_BOOL |
543 | vmod_check(struct sess *sp, const char *key, const char *spec) | 539 | vmod_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/>. | ||