summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org.ua>2014-11-01 14:28:19 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2014-11-01 14:34:10 (GMT)
commitfffbbfb089847644e2b0281faba2fa892df4f8b9 (patch) (side-by-side diff)
tree83899ca03d92bdb4100c413904c83385ca0c7d6c /src
parentc16de06862f9b2106dcb7810fc20856689ef2aa6 (diff)
downloadvmod-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') (more/less context) (show whitespace changes)
-rw-r--r--src/.gitignore2
-rw-r--r--src/Makefile.am37
-rw-r--r--src/binlog.c64
-rw-r--r--src/vmod-binlog.h3
-rw-r--r--src/vmod.vcc111
5 files changed, 172 insertions, 45 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
vcc_if.h
+*.rst
+*.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 @@
# This file is part of vmod-binlog
-# Copyright (C) 2013 Sergey Poznyakoff
+# Copyright (C) 2013-2014 Sergey Poznyakoff
#
@@ -16,3 +16,6 @@
-AM_CPPFLAGS = -I$(VARNISHSRC)/include -I$(VARNISHSRC)
+AM_CPPFLAGS =\
+ -I$(VARNISHSRC)/include\
+ -I$(VARNISHSRC)/bin/varnishd\
+ -I$(VARNISHSRC)
@@ -40,11 +43,28 @@ libvmod_binlog_la_SOURCES = \
pack.c\
- vmod-binlog.h\
- vcc_if.c vcc_if.h
-
+ vmod-binlog.h
+nodist_libvmod_binlog_la_SOURCES = vcc_if.c vcc_if.h
noinst_HEADERS = pack.h err.h parse-datetime.h xalloc.h
-BUILT_SOURCES = vcc_if.c vcc_if.h
+binlog.lo: vcc_if.c vcc_if.h
+
+CLEANFILES = vcc_if.c vcc_if.h *.rst
+
+if VARNISH4
+ vmodtool = $(VARNISHSRC)/lib/libvcc/vmodtool.py
+ vmodtoolargs = --strict
+ vccfile = $(top_srcdir)/src/vmod.vcc
+else
+ vmodtool = $(VARNISHSRC)/lib/libvmod_std/vmod.py
+ vmodtoolargs =
+ vccfile = vmod.vcc3
+
+vmod.vcc3: $(top_srcdir)/src/vmod.vcc
+ CLEANFILES += vmod.vcc3
+endif
+
+.vcc.vcc3:
+ sed -n '/^\$$/{s///;s/\(Module *[^ ][^ ]*\).*/\1/;p}' $< > $@
-vcc_if.c vcc_if.h: $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod.vcc
- @PYTHON@ $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod.vcc
+vcc_if.c vcc_if.h: $(vmodtool) $(vccfile)
+ @PYTHON@ $(vmodtool) $(vmodtoolargs) $(vccfile)
@@ -52,3 +72,2 @@ EXTRA_DIST = vmod.vcc
-CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h
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 @@
#include "vcc_if.h"
+#if VARNISHVERSION == 3
#include "bin/varnishd/cache.h"
+# define VCL_VOID void
+# define VCL_STRING const char *
+# define MOD_CTX struct sess *
+# define WSPTR(s) ((s)->wrk->ws)
+#else
+# include "bin/varnishd/cache/cache.h"
+# define MOD_CTX const struct vrt_ctx *
+# define WSPTR(s) ((s)->ws)
+#endif
#include "vmod-binlog.h"
#include "pack.h"
+#include "pthread.h"
@@ -264,3 +275,3 @@ make_key()
void
-vmod_init(struct sess *sp, struct vmod_priv *priv,
+vmod_init(MOD_CTX ctx, struct vmod_priv *priv,
const char *dir, const char *format, const char *param)
@@ -354,3 +365,2 @@ vmod_init(struct sess *sp, struct vmod_priv *priv,
}
- free(p);
switch (*q) {
@@ -371,2 +381,3 @@ vmod_init(struct sess *sp, struct vmod_priv *priv,
conf->size = u;
+ free(p);
} else
@@ -428,3 +439,3 @@ vmod_init(struct sess *sp, struct vmod_priv *priv,
static char *
-mkfilename(struct sess *sp, struct binlog_config *conf)
+mkfilename(MOD_CTX ctx, struct binlog_config *conf)
{
@@ -436,7 +447,7 @@ mkfilename(struct sess *sp, struct binlog_config *conf)
ts -= ts % conf->interval;
- u = WS_Reserve(sp->wrk->ws, 0);
- p = sp->wrk->ws->f;
+ u = WS_Reserve(WSPTR(ctx), 0);
+ p = WSPTR(ctx)->f;
n = strftime(p, u, conf->pattern, gmtime(&ts));
if (n == 0) {
- WS_Release(sp->wrk->ws, 0);
+ WS_Release(WSPTR(ctx), 0);
return NULL;
@@ -445,3 +456,3 @@ mkfilename(struct sess *sp, struct binlog_config *conf)
AN(q);
- WS_Release(sp->wrk->ws, 0);
+ WS_Release(WSPTR(ctx), 0);
return q;
@@ -483,3 +494,3 @@ mkdir_p(struct binlog_config *conf, char *dir)
static int
-createfile(struct sess *sp, struct binlog_config *conf)
+createfile(MOD_CTX ctx, struct binlog_config *conf)
{
@@ -491,3 +502,3 @@ createfile(struct sess *sp, struct binlog_config *conf)
- fname = mkfilename(sp, conf);
+ fname = mkfilename(ctx, conf);
if (!fname)
@@ -593,3 +604,3 @@ checkheader(struct binlog_config *conf, size_t hdrsize)
static int
-newfile(struct sess *sp, struct binlog_config *conf)
+newfile(MOD_CTX ctx, struct binlog_config *conf)
{
@@ -603,3 +614,3 @@ newfile(struct sess *sp, struct binlog_config *conf)
- if (createfile(sp, conf))
+ if (createfile(ctx, conf))
return -1;
@@ -659,3 +670,4 @@ newfile(struct sess *sp, struct binlog_config *conf)
} else {
- debug(conf,1,("created new log file %s",conf->fname));
+ debug(conf,1,("created new log file %s, size %lu",conf->fname,
+ (unsigned long)conf->size));
memcpy(conf->base->magic, BINLOG_MAGIC_STR, BINLOG_MAGIC_LEN);
@@ -676,3 +688,3 @@ newfile(struct sess *sp, struct binlog_config *conf)
static void
-closefile(struct sess *sp, struct binlog_config *conf)
+closefile(MOD_CTX ctx, struct binlog_config *conf)
{
@@ -693,4 +705,4 @@ closefile(struct sess *sp, struct binlog_config *conf)
-void
-vmod_start(struct sess *sp, struct vmod_priv *priv)
+VCL_VOID
+vmod_start(MOD_CTX ctx, struct vmod_priv *priv)
{
@@ -707,4 +719,4 @@ vmod_start(struct sess *sp, struct vmod_priv *priv)
AZ(pthread_mutex_lock(&conf->mutex));
- closefile(sp, conf);
- newfile(sp, conf);
+ closefile(ctx, conf);
+ newfile(ctx, conf);
AZ(pthread_mutex_unlock(&conf->mutex));
@@ -716,4 +728,4 @@ vmod_start(struct sess *sp, struct vmod_priv *priv)
-void
-vmod_pack(struct sess *sp, struct vmod_priv *priv, const char *str)
+VCL_VOID
+vmod_pack(MOD_CTX ctx, struct vmod_priv *priv, VCL_STRING str)
{
@@ -751,4 +763,4 @@ vmod_pack(struct sess *sp, struct vmod_priv *priv, const char *str)
-void
-vmod_commit(struct sess *sp, struct vmod_priv *priv)
+VCL_VOID
+vmod_commit(MOD_CTX ctx, struct vmod_priv *priv)
{
@@ -791,4 +803,4 @@ vmod_commit(struct sess *sp, struct vmod_priv *priv)
-void
-vmod_sync(struct sess *sp, struct vmod_priv *priv)
+VCL_VOID
+vmod_sync(MOD_CTX ctx, struct vmod_priv *priv)
{
@@ -805,4 +817,4 @@ vmod_sync(struct sess *sp, struct vmod_priv *priv)
-void
-vmod_close(struct sess *sp, struct vmod_priv *priv)
+VCL_VOID
+vmod_close(MOD_CTX ctx, struct vmod_priv *priv)
{
@@ -815,3 +827,3 @@ vmod_close(struct sess *sp, struct vmod_priv *priv)
AZ(pthread_mutex_lock(&mutex));
- closefile(sp, conf);
+ closefile(ctx, conf);
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 @@
/* This file is part of vmod-binlog
- Copyright (C) 2013 Sergey Poznyakoff
+ Copyright (C) 2013-2014 Sergey Poznyakoff
@@ -16,3 +16,2 @@
*/
-
#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 @@
-Module binlog
-Init module_init
-Function VOID init(PRIV_VCL, STRING, STRING, STRING)
-Function VOID start(PRIV_VCL)
-Function VOID commit(PRIV_VCL)
-Function VOID pack(PRIV_VCL, STRING)
-Function VOID sync(PRIV_VCL)
-Function VOID close(PRIV_VCL)
+# This file is part of vmod-binlog
+# Copyright (C) 2013-2014 Sergey Poznyakoff
+#
+# Vmod-binlog 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-binlog 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-binlog. If not, see <http://www.gnu.org/licenses/>.
+
+$Module binlog 3 Binary Log File Support
+
+COLOPHON
+========
+This document provides a short description of the **vmod-binlog** module.
+For a detailed documentation, please see the vmod-binlog(3) manual page.
+
+You will find documentation sources in subdirectory **doc** of the
+**vmod-binlog** source tree.
+
+DESCRIPTION
+===========
+This module adds binary log files support to Varnish Cache.
+
+Binary log file consists of an arbitrary number of equally sized
+records. Each record contains a UNIX timestamp in binary form and
+user-defined data. The file begins with a header containing auxiliary
+information.
+
+Binary log files are rotated at preconfigured time intervals. In order
+to speed up searches, their names follow the strftime(3) pattern:
+
+%Y%m%dT%H%M%S.log
+
+Binary logs can be viewed using the binlogcat(1) and binlogsel(1) utilities.
+
+$Init module_init
+$Function VOID init(PRIV_VCL, STRING, STRING, STRING)
+
+Description
+ Initializes binary log engine.
+Example
+ ::
+
+ binlog.init("/var/lib/varnish/binlog", "LZ[64]L",
+ "size=1G;index=1;umask=027;roundts=1;debug=2");
+
+
+$Function VOID start(PRIV_VCL)
+
+Description
+ Initialize new binary record. It should be followed by one or
+ more calls to **binlog.pack** and a final call to **binlog.commit**.
+Example
+ ::
+ binlog.start();
+
+$Function VOID pack(PRIV_VCL, STRING)
+
+Description
+ Pack next data item into the binary log record. The item is
+ converted according to the second argument of **binlog.init**.
+ The conversion specifier is selected using the ordinal number
+ of this **pack** call after the latest **binlog.start**.
+
+$Function VOID commit(PRIV_VCL)
+
+Description
+ Finalize the binary log record and commit it. Any uninitialized
+ fields will be set to 0.
+
+Example
+ ::
+
+ binlog.start();
+ binlog.pack(http.X-Id);
+ binlog.pack(http.req.url);
+ binlog.pack(http.X-Node);
+ binlog.commit();
+
+$Function VOID sync(PRIV_VCL)
+
+Description
+ Synchronize the binary log with the disk file.
+
+$Function VOID close(PRIV_VCL)
+
+Description
+ Close the log. This is supposed to be called from **vcl_fini**.
+
+SEE ALSO
+========
+
+* binlogcat(1)
+* binlogsel(1)
+* vcl(7)
+* varnishd(1)

Return to:

Send suggestions and report system problems to the System administrator.