diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-11-01 16:28:19 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-11-01 16:34:10 +0200 |
commit | fffbbfb089847644e2b0281faba2fa892df4f8b9 (patch) | |
tree | 83899ca03d92bdb4100c413904c83385ca0c7d6c /src | |
parent | c16de06862f9b2106dcb7810fc20856689ef2aa6 (diff) | |
download | vmod-binlog-fffbbfb089847644e2b0281faba2fa892df4f8b9.tar.gz vmod-binlog-fffbbfb089847644e2b0281faba2fa892df4f8b9.tar.bz2 |
Support for VCL 4.0
* configure.ac: Version 1.0.91
Detect varnish version and set variables and conditionals accordingly.
* NEWS: Update.
* src/.gitignore: Update.
* src/Makefile.am: Always build vcc_if.c and vcc_if.h. Don't
distribute them.
* src/binlog.c: Use VCL data type. Define them for VCL 3.0.
(vmod_init): Fix premature memory deallocation.
* src/vmod.vcc: Rewrite in VCL 4.0 syntax.
* tests/atlocal.in (ret_vcl_recv): New variable.
* tests/test01.at (vcl_recv): Return $ret_vcl_recv.
* tests/test02.at: Likewise.
Diffstat (limited to 'src')
-rw-r--r-- | src/.gitignore | 2 | ||||
-rw-r--r-- | src/Makefile.am | 37 | ||||
-rw-r--r-- | src/binlog.c | 66 | ||||
-rw-r--r-- | src/vmod-binlog.h | 3 | ||||
-rw-r--r-- | src/vmod.vcc | 111 |
5 files changed, 173 insertions, 46 deletions
diff --git a/src/.gitignore b/src/.gitignore index 8f5a6ab..bae35ac 100644 --- a/src/.gitignore +++ b/src/.gitignore | |||
@@ -5 +5,3 @@ vcc_if.c | |||
5 | vcc_if.h | 5 | vcc_if.h |
6 | *.rst | ||
7 | *.vcc3 | ||
diff --git a/src/Makefile.am b/src/Makefile.am index a20f9cb..7917730 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -1,3 +1,3 @@ | |||
1 | # This file is part of vmod-binlog | 1 | # This file is part of vmod-binlog |
2 | # Copyright (C) 2013 Sergey Poznyakoff | 2 | # Copyright (C) 2013-2014 Sergey Poznyakoff |
3 | # | 3 | # |
@@ -16,3 +16,6 @@ | |||
16 | 16 | ||
17 | AM_CPPFLAGS = -I$(VARNISHSRC)/include -I$(VARNISHSRC) | 17 | AM_CPPFLAGS =\ |
18 | -I$(VARNISHSRC)/include\ | ||
19 | -I$(VARNISHSRC)/bin/varnishd\ | ||
20 | -I$(VARNISHSRC) | ||
18 | 21 | ||
@@ -40,11 +43,28 @@ libvmod_binlog_la_SOURCES = \ | |||
40 | pack.c\ | 43 | pack.c\ |
41 | vmod-binlog.h\ | 44 | vmod-binlog.h |
42 | vcc_if.c vcc_if.h | 45 | nodist_libvmod_binlog_la_SOURCES = vcc_if.c vcc_if.h |
43 | |||
44 | noinst_HEADERS = pack.h err.h parse-datetime.h xalloc.h | 46 | noinst_HEADERS = pack.h err.h parse-datetime.h xalloc.h |
45 | 47 | ||
46 | BUILT_SOURCES = vcc_if.c vcc_if.h | 48 | binlog.lo: vcc_if.c vcc_if.h |
49 | |||
50 | CLEANFILES = vcc_if.c vcc_if.h *.rst | ||
51 | |||
52 | if VARNISH4 | ||
53 | vmodtool = $(VARNISHSRC)/lib/libvcc/vmodtool.py | ||
54 | vmodtoolargs = --strict | ||
55 | vccfile = $(top_srcdir)/src/vmod.vcc | ||
56 | else | ||
57 | vmodtool = $(VARNISHSRC)/lib/libvmod_std/vmod.py | ||
58 | vmodtoolargs = | ||
59 | vccfile = vmod.vcc3 | ||
60 | |||
61 | vmod.vcc3: $(top_srcdir)/src/vmod.vcc | ||
62 | CLEANFILES += vmod.vcc3 | ||
63 | endif | ||
64 | |||
65 | .vcc.vcc3: | ||
66 | sed -n '/^\$$/{s///;s/\(Module *[^ ][^ ]*\).*/\1/;p}' $< > $@ | ||
47 | 67 | ||
48 | vcc_if.c vcc_if.h: $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod.vcc | 68 | vcc_if.c vcc_if.h: $(vmodtool) $(vccfile) |
49 | @PYTHON@ $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod.vcc | 69 | @PYTHON@ $(vmodtool) $(vmodtoolargs) $(vccfile) |
50 | 70 | ||
@@ -52,3 +72,2 @@ EXTRA_DIST = vmod.vcc | |||
52 | 72 | ||
53 | CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h | ||
54 | 73 | ||
diff --git a/src/binlog.c b/src/binlog.c index 45299f2..e9fb16e 100644 --- a/src/binlog.c +++ b/src/binlog.c | |||
@@ -31,5 +31,16 @@ | |||
31 | #include "vcc_if.h" | 31 | #include "vcc_if.h" |
32 | #include "bin/varnishd/cache.h" | 32 | #if VARNISHVERSION == 3 |
33 | # include "bin/varnishd/cache.h" | ||
34 | # define VCL_VOID void | ||
35 | # define VCL_STRING const char * | ||
36 | # define MOD_CTX struct sess * | ||
37 | # define WSPTR(s) ((s)->wrk->ws) | ||
38 | #else | ||
39 | # include "bin/varnishd/cache/cache.h" | ||
40 | # define MOD_CTX const struct vrt_ctx * | ||
41 | # define WSPTR(s) ((s)->ws) | ||
42 | #endif | ||
33 | #include "vmod-binlog.h" | 43 | #include "vmod-binlog.h" |
34 | #include "pack.h" | 44 | #include "pack.h" |
45 | #include "pthread.h" | ||
35 | 46 | ||
@@ -264,3 +275,3 @@ make_key() | |||
264 | void | 275 | void |
265 | vmod_init(struct sess *sp, struct vmod_priv *priv, | 276 | vmod_init(MOD_CTX ctx, struct vmod_priv *priv, |
266 | const char *dir, const char *format, const char *param) | 277 | const char *dir, const char *format, const char *param) |
@@ -354,3 +365,2 @@ vmod_init(struct sess *sp, struct vmod_priv *priv, | |||
354 | } | 365 | } |
355 | free(p); | ||
356 | switch (*q) { | 366 | switch (*q) { |
@@ -371,2 +381,3 @@ vmod_init(struct sess *sp, struct vmod_priv *priv, | |||
371 | conf->size = u; | 381 | conf->size = u; |
382 | free(p); | ||
372 | } else | 383 | } else |
@@ -428,3 +439,3 @@ vmod_init(struct sess *sp, struct vmod_priv *priv, | |||
428 | static char * | 439 | static char * |
429 | mkfilename(struct sess *sp, struct binlog_config *conf) | 440 | mkfilename(MOD_CTX ctx, struct binlog_config *conf) |
430 | { | 441 | { |
@@ -436,7 +447,7 @@ mkfilename(struct sess *sp, struct binlog_config *conf) | |||
436 | ts -= ts % conf->interval; | 447 | ts -= ts % conf->interval; |
437 | u = WS_Reserve(sp->wrk->ws, 0); | 448 | u = WS_Reserve(WSPTR(ctx), 0); |
438 | p = sp->wrk->ws->f; | 449 | p = WSPTR(ctx)->f; |
439 | n = strftime(p, u, conf->pattern, gmtime(&ts)); | 450 | n = strftime(p, u, conf->pattern, gmtime(&ts)); |
440 | if (n == 0) { | 451 | if (n == 0) { |
441 | WS_Release(sp->wrk->ws, 0); | 452 | WS_Release(WSPTR(ctx), 0); |
442 | return NULL; | 453 | return NULL; |
@@ -445,3 +456,3 @@ mkfilename(struct sess *sp, struct binlog_config *conf) | |||
445 | AN(q); | 456 | AN(q); |
446 | WS_Release(sp->wrk->ws, 0); | 457 | WS_Release(WSPTR(ctx), 0); |
447 | return q; | 458 | return q; |
@@ -483,3 +494,3 @@ mkdir_p(struct binlog_config *conf, char *dir) | |||
483 | static int | 494 | static int |
484 | createfile(struct sess *sp, struct binlog_config *conf) | 495 | createfile(MOD_CTX ctx, struct binlog_config *conf) |
485 | { | 496 | { |
@@ -491,3 +502,3 @@ createfile(struct sess *sp, struct binlog_config *conf) | |||
491 | 502 | ||
492 | fname = mkfilename(sp, conf); | 503 | fname = mkfilename(ctx, conf); |
493 | if (!fname) | 504 | if (!fname) |
@@ -593,3 +604,3 @@ checkheader(struct binlog_config *conf, size_t hdrsize) | |||
593 | static int | 604 | static int |
594 | newfile(struct sess *sp, struct binlog_config *conf) | 605 | newfile(MOD_CTX ctx, struct binlog_config *conf) |
595 | { | 606 | { |
@@ -603,3 +614,3 @@ newfile(struct sess *sp, struct binlog_config *conf) | |||
603 | 614 | ||
604 | if (createfile(sp, conf)) | 615 | if (createfile(ctx, conf)) |
605 | return -1; | 616 | return -1; |
@@ -659,3 +670,4 @@ newfile(struct sess *sp, struct binlog_config *conf) | |||
659 | } else { | 670 | } else { |
660 | debug(conf,1,("created new log file %s",conf->fname)); | 671 | debug(conf,1,("created new log file %s, size %lu",conf->fname, |
672 | (unsigned long)conf->size)); | ||
661 | memcpy(conf->base->magic, BINLOG_MAGIC_STR, BINLOG_MAGIC_LEN); | 673 | memcpy(conf->base->magic, BINLOG_MAGIC_STR, BINLOG_MAGIC_LEN); |
@@ -676,3 +688,3 @@ newfile(struct sess *sp, struct binlog_config *conf) | |||
676 | static void | 688 | static void |
677 | closefile(struct sess *sp, struct binlog_config *conf) | 689 | closefile(MOD_CTX ctx, struct binlog_config *conf) |
678 | { | 690 | { |
@@ -693,4 +705,4 @@ closefile(struct sess *sp, struct binlog_config *conf) | |||
693 | 705 | ||
694 | void | 706 | VCL_VOID |
695 | vmod_start(struct sess *sp, struct vmod_priv *priv) | 707 | vmod_start(MOD_CTX ctx, struct vmod_priv *priv) |
696 | { | 708 | { |
@@ -707,4 +719,4 @@ vmod_start(struct sess *sp, struct vmod_priv *priv) | |||
707 | AZ(pthread_mutex_lock(&conf->mutex)); | 719 | AZ(pthread_mutex_lock(&conf->mutex)); |
708 | closefile(sp, conf); | 720 | closefile(ctx, conf); |
709 | newfile(sp, conf); | 721 | newfile(ctx, conf); |
710 | AZ(pthread_mutex_unlock(&conf->mutex)); | 722 | AZ(pthread_mutex_unlock(&conf->mutex)); |
@@ -716,4 +728,4 @@ vmod_start(struct sess *sp, struct vmod_priv *priv) | |||
716 | 728 | ||
717 | void | 729 | VCL_VOID |
718 | vmod_pack(struct sess *sp, struct vmod_priv *priv, const char *str) | 730 | vmod_pack(MOD_CTX ctx, struct vmod_priv *priv, VCL_STRING str) |
719 | { | 731 | { |
@@ -751,4 +763,4 @@ vmod_pack(struct sess *sp, struct vmod_priv *priv, const char *str) | |||
751 | 763 | ||
752 | void | 764 | VCL_VOID |
753 | vmod_commit(struct sess *sp, struct vmod_priv *priv) | 765 | vmod_commit(MOD_CTX ctx, struct vmod_priv *priv) |
754 | { | 766 | { |
@@ -791,4 +803,4 @@ vmod_commit(struct sess *sp, struct vmod_priv *priv) | |||
791 | 803 | ||
792 | void | 804 | VCL_VOID |
793 | vmod_sync(struct sess *sp, struct vmod_priv *priv) | 805 | vmod_sync(MOD_CTX ctx, struct vmod_priv *priv) |
794 | { | 806 | { |
@@ -805,4 +817,4 @@ vmod_sync(struct sess *sp, struct vmod_priv *priv) | |||
805 | 817 | ||
806 | void | 818 | VCL_VOID |
807 | vmod_close(struct sess *sp, struct vmod_priv *priv) | 819 | vmod_close(MOD_CTX ctx, struct vmod_priv *priv) |
808 | { | 820 | { |
@@ -815,3 +827,3 @@ vmod_close(struct sess *sp, struct vmod_priv *priv) | |||
815 | AZ(pthread_mutex_lock(&mutex)); | 827 | AZ(pthread_mutex_lock(&mutex)); |
816 | closefile(sp, conf); | 828 | closefile(ctx, conf); |
817 | close(conf->dd); | 829 | close(conf->dd); |
diff --git a/src/vmod-binlog.h b/src/vmod-binlog.h index d67f1cd..fec8d24 100644 --- a/src/vmod-binlog.h +++ b/src/vmod-binlog.h | |||
@@ -1,3 +1,3 @@ | |||
1 | /* This file is part of vmod-binlog | 1 | /* This file is part of vmod-binlog |
2 | Copyright (C) 2013 Sergey Poznyakoff | 2 | Copyright (C) 2013-2014 Sergey Poznyakoff |
3 | 3 | ||
@@ -16,3 +16,2 @@ | |||
16 | */ | 16 | */ |
17 | |||
18 | #include <stdint.h> | 17 | #include <stdint.h> |
diff --git a/src/vmod.vcc b/src/vmod.vcc index 45da354..b090797 100644 --- a/src/vmod.vcc +++ b/src/vmod.vcc | |||
@@ -1,8 +1,103 @@ | |||
1 | Module binlog | 1 | # This file is part of vmod-binlog |
2 | Init module_init | 2 | # Copyright (C) 2013-2014 Sergey Poznyakoff |
3 | Function VOID init(PRIV_VCL, STRING, STRING, STRING) | 3 | # |
4 | Function VOID start(PRIV_VCL) | 4 | # Vmod-binlog is free software; you can redistribute it and/or modify |
5 | Function VOID commit(PRIV_VCL) | 5 | # it under the terms of the GNU General Public License as published by |
6 | Function VOID pack(PRIV_VCL, STRING) | 6 | # the Free Software Foundation; either version 3, or (at your option) |
7 | Function VOID sync(PRIV_VCL) | 7 | # any later version. |
8 | Function VOID close(PRIV_VCL) | 8 | # |
9 | # Vmod-binlog 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. |