aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-01-15 00:24:59 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2016-01-23 22:34:17 +0200
commitb946286617a36e74b5ee6efd09930ed18683afd7 (patch)
treefa7d72320520bc9b0681c3058f8b2777d49f190b
parentc90ba2a863a446b51b9ee960cead69a4b2884045 (diff)
downloadvmod-variable-b946286617a36e74b5ee6efd09930ed18683afd7.tar.gz
vmod-variable-b946286617a36e74b5ee6efd09930ed18683afd7.tar.bz2
Store per-session symtabs in private storage. Drop v.3 support.
* src/variable.c (symtabv, symtabc) (symtab_mtx): Remove globals. (get_symtab): Save symtab in private data pointer. (vmod_clear, vmod_get_string) (vmod_set_string, vmod_get, vmod_set) (DEFGET, DEFSET) (vmod_defined, vmod_type_of) (vmod_unset, vmod_regset) (vmod_queryset): Expect struct vmod_priv * as 2nd argument. * src/variable.vcc: Change prototypes. * NEWS: Version 1.0.90 * configure.ac: Update.
-rw-r--r--NEWS11
-rw-r--r--configure.ac53
-rw-r--r--src/Makefile.am19
-rw-r--r--src/variable.c108
-rw-r--r--src/variable.vcc32
5 files changed, 111 insertions, 112 deletions
diff --git a/NEWS b/NEWS
index 1c3e867..c0d662a 100644
--- a/NEWS
+++ b/NEWS
@@ -1,21 +1,26 @@
-vmod-variable -- history of user-visible changes. 2015-02-16
-Copyright (C) 2015 Sergey Poznyakoff
+vmod-variable -- history of user-visible changes. 2016-01-15
+Copyright (C) 2015-2016 Sergey Poznyakoff
See the end of file for copying conditions.
Please send vmod-variable bug reports to <gray@gnu.org>
+Version 1.0.90, (Git)
+
+Fix coredumps.
+
+
Version 1.0, 2015-02-16
Initial release
=========================================================================
Copyright information:
-Copyright (C) 2015 Sergey Poznyakoff
+Copyright (C) 2015-2016 Sergey Poznyakoff
Permission is granted to anyone to make or distribute verbatim copies
of this document as received, in any medium, provided that the
copyright notice and this permission notice are preserved,
thus giving the recipient permission to redistribute in turn.
diff --git a/configure.ac b/configure.ac
index 9a69658..4f328e7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,8 +1,8 @@
# This file is part of vmod-variable -*- autoconf -*-
-# Copyright (C) 2015 Sergey Poznyakoff
+# Copyright (C) 2015-2016 Sergey Poznyakoff
#
# Vmod-variable 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.
#
@@ -11,13 +11,13 @@
# 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-variable. If not, see <http://www.gnu.org/licenses/>.
AC_PREREQ(2.69)
-AC_INIT([vmod-variable], [1.0], [gray@gnu.org])
+AC_INIT([vmod-variable], [1.0.90], [gray@gnu.org])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR(src/variable.vcc)
AM_CONFIG_HEADER(config.h)
AC_CANONICAL_SYSTEM
@@ -68,23 +68,42 @@ fi
case "$VARNISHSRC" in
/*) ;;
*) AC_MSG_ERROR([varnish source path must be absolute pathname])
esac
VARNISHSRC=`cd $VARNISHSRC && pwd`
-VARNISHVERSION=
-AC_CHECK_FILE([$VARNISHSRC/include/varnishapi.h],
- [VARNISHVERSION=3],
- [AC_CHECK_FILE([$VARNISHSRC/include/vapi/vsm.h],
- [VARNISHVERSION=4],
- [AC_MSG_FAILURE(["$VARNISHSRC" is not a Varnish source directory])]) ])
-AC_SUBST([VARNISHVERSION],$VARNISHVERSION)
-
-AC_DEFINE_UNQUOTED([VARNISHVERSION],$VARNISHVERSION,[Varnish major version number])
-AM_CONDITIONAL([VARNISH3],[test $VARNISHVERSION -eq 3])
-AM_CONDITIONAL([VARNISH4],[test $VARNISHVERSION -eq 4])
+
+# pkg-config
+PKG_PROG_PKG_CONFIG
+PKG_CHECK_MODULES([libvarnishapi], [varnishapi])
+
+varnishapi_version() {
+ VARNISHAPI_MAJOR=$1
+ VARNISHAPI_MINOR=$2
+ VARNISHAPI_PATCH=$3
+}
+
+v=$($PKG_CONFIG --modversion varnishapi)
+if test -n "$v"; then
+ save_IFS=$IFS
+ IFS='.'
+ varnishapi_version $v
+ IFS=$save_IFS
+else
+ AC_MSG_ERROR([unknown varnishapi version])
+fi
+
+if test $VARNISHAPI_MAJOR -ne 4; then
+ AC_MSG_ERROR([unsupported varnishapi version])
+fi
+
+case $VARNISHAPI_MINOR in
+0) AC_MSG_ERROR([unsupported varnishapi version]);;
+1) ;;
+*) AC_MSG_WARN([varnishapi minor version probably unsupported])
+esac
# Check that varnishtest is built in the varnish source directory
AC_CHECK_FILE([$VARNISHSRC/bin/varnishtest/varnishtest],
[],
[AC_MSG_FAILURE([cannot find "$VARNISHSRC/bin/varnishtest/varnishtest". Please build your varnish source directory])]
)
@@ -95,13 +114,13 @@ AC_ARG_WITH([vmoddir],
AC_HELP_STRING([--with-vmoddir=DIR],
[install modules to DIR]),
[case "$withval" in
/*) VMODDIR=$withval;;
no) unset VMODDIR;;
*) AC_MSG_ERROR([argument to --with-vmoddir must be absolute pathname])
- esac],[VMODDIR=`pkg-config --variable=vmoddir varnishapi`
+ esac],[VMODDIR=$($PKG_CONFIG --variable=vmoddir varnishapi)
if test -z "$VMODDIR"; then
AC_MSG_FAILURE([cannot determine vmod installation directory])
fi])
if test -z "$VMODDIR"; then
@@ -109,16 +128,18 @@ if test -z "$VMODDIR"; then
fi
AC_CONFIG_COMMANDS([status],[
delim="-------------------------------------------------------------------"
echo ""
echo $delim
-echo "Building for Varnish version $VARNISHVERSION"
+echo "Building for Varnish version $VARNISHAPI_MAJOR.$VARNISHAPI_MINOR"
echo $delim
],
-[VARNISHVERSION=$VARNISHVERSION])
+[VARNISHAPI_MAJOR=$VARNISHAPI_MAJOR
+VARNISHAPI_MINOR=$VARNISHAPI_MINOR
+])
AC_CONFIG_TESTDIR(tests)
AC_CONFIG_FILES([tests/Makefile tests/atlocal])
AM_MISSING_PROG([AUTOM4TE], [autom4te])
AC_CONFIG_FILES([
diff --git a/src/Makefile.am b/src/Makefile.am
index ee04055..81c5b4e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -35,27 +35,16 @@ nodist_libvmod_variable_la_SOURCES = \
vcc_if.c vcc_if.h
variable.lo: 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/variable.vcc
-else
- vmodtool = $(VARNISHSRC)/lib/libvmod_std/vmod.py
- vmodtoolargs =
- vccfile = variable.vcc3
-
-variable.vcc3: $(top_srcdir)/src/variable.vcc
- CLEANFILES += variable.vcc3
-endif
-
-.vcc.vcc3:
- sed -n '/^\$$/{s///;s/\(Module *[^ ][^ ]*\).*/\1/;p}' $< > $@
+vmodtool = $(VARNISHSRC)/lib/libvcc/vmodtool.py
+vmodtoolargs = --strict
+vccfile = $(top_srcdir)/src/variable.vcc
+
vcc_if.c vcc_if.h: $(vmodtool) $(vccfile)
@PYTHON@ $(vmodtool) $(vmodtoolargs) $(vccfile)
EXTRA_DIST = \
variable.vcc
diff --git a/src/variable.c b/src/variable.c
index e6bad1a..d9030a3 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -15,31 +15,22 @@
along with vmod-tbf. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdlib.h>
#include <stdarg.h>
#include <syslog.h>
+#include <errno.h>
#include <ctype.h>
#include <pcre.h>
#include "vrt.h"
#include "vcc_if.h"
#include "pthread.h"
-#if VARNISHVERSION == 3
-# include "bin/varnishd/cache.h"
-# define VCL_VOID void
-# define VCL_STRING const char *
-# define VCL_REAL double
-# define VCL_DURATION double
-# define WS_Copy(w,s,l) WS_Dup(w,s)
-# define VARIABLE_CTX struct sess *
-# define WSPTR(s) ((s)->wrk->ws)
-#else
-# include "bin/varnishd/cache/cache.h"
-# define VARIABLE_CTX const struct vrt_ctx *
-# define WSPTR(s) ((s)->ws)
-#endif
+
+#include "bin/varnishd/cache/cache.h"
+#define VARIABLE_CTX const struct vrt_ctx *
+#define WSPTR(s) ((s)->ws)
/* |hash_size| defines a sequence of symbol table sizes. These are prime
numbers, each of which is approximately twice its predecessor. */
static unsigned int hash_size[] = {
7, 17, 37, 101, 229, 487, 1009, 2039, 4091, 8191, 16411
@@ -307,16 +298,12 @@ symtab_free(struct symtab *st)
free(st->tab);
free(st);
}
}
-static struct symtab **symtabv;
-static size_t symtabc;
-static pthread_mutex_t symtab_mtx = PTHREAD_MUTEX_INITIALIZER;
-
static struct symtab *global_symtab;
static pthread_mutex_t global_mtx = PTHREAD_MUTEX_INITIALIZER;
VCL_VOID
vmod_global_set(VARIABLE_CTX ctx, VCL_STRING name, VCL_STRING value)
{
@@ -378,34 +365,26 @@ vmod_global_unset(VARIABLE_CTX ctx, VCL_STRING name)
{
AZ(pthread_mutex_lock(&global_mtx));
symtab_remove(global_symtab, name);
AZ(pthread_mutex_unlock(&global_mtx));
}
+static void
+priv_symtab_free(void *p)
+{
+ symtab_free(p);
+}
+
static struct symtab *
-get_symtab(VARIABLE_CTX ctx)
+get_symtab(struct vmod_priv *priv)
{
- struct symtab *st;
- int fd = ctx->req->sp->fd;
-
- assert(fd >= 0);
- AZ(pthread_mutex_lock(&symtab_mtx));
- if (symtabc <= fd) {
- size_t n = fd + 1;
- symtabv = realloc(symtabv, n * sizeof(symtabv[0]));
- while (symtabc < n)
- symtabv[symtabc++] = NULL;
+ if (!priv->priv) {
+ priv->priv = symtab_create();
+ priv->free = priv_symtab_free;
}
- if (!symtabv[fd])
- symtabv[fd] = symtab_create();
- st = symtabv[fd];
- if (st->vxid != ctx->req->sp->vxid)
- symtab_clear(st);
- st->vxid = ctx->req->sp->vxid;
- AZ(pthread_mutex_unlock(&symtab_mtx));
- return st;
+ return priv->priv;
}
#define getvar(vt, name) symtab_lookup_or_install(vt, name, NULL)
static struct variable *
defvar(struct symtab *vt, const char *name, enum variable_type t,
@@ -421,65 +400,69 @@ defvar(struct symtab *vt, const char *name, enum variable_type t,
} else
var->type = variable_unset;
return var;
}
VCL_VOID
-vmod_clear(VARIABLE_CTX ctx)
+vmod_clear(VARIABLE_CTX ctx, struct vmod_priv *priv)
{
- symtab_clear(get_symtab(ctx));
+ symtab_clear(get_symtab(priv));
}
VCL_STRING
-vmod_get_string(VARIABLE_CTX ctx, VCL_STRING name)
+vmod_get_string(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name)
{
- struct variable *var = getvar(get_symtab(ctx), name);
+ struct variable *var = getvar(get_symtab(priv), name);
if (var && var->type == variable_string)
return var->v.s;
return NULL;
}
VCL_VOID
-vmod_set_string(VARIABLE_CTX ctx, VCL_STRING name, VCL_STRING value)
+vmod_set_string(VARIABLE_CTX ctx, struct vmod_priv *priv,
+ VCL_STRING name, VCL_STRING value)
{
- struct symtab *vt = get_symtab(ctx);
+ struct symtab *vt = get_symtab(priv);
struct variable *var = defvar(vt, name, variable_unset, NULL);
var->type = variable_string;
var->v.s = strdup(value ? value : "");
AN(var->v.s);
}
VCL_STRING
-vmod_get(VARIABLE_CTX ctx, VCL_STRING name)
+vmod_get(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name)
{
- return vmod_get_string(ctx, name);
+ return vmod_get_string(ctx, priv, name);
}
VCL_VOID
-vmod_set(VARIABLE_CTX ctx, VCL_STRING name, VCL_STRING value)
+vmod_set(VARIABLE_CTX ctx, struct vmod_priv *priv,
+ VCL_STRING name, VCL_STRING value)
{
- vmod_set_string(ctx, name, value);
+ vmod_set_string(ctx, priv, name, value);
}
#define __cat__(a,b) a ## b
#define DEFGET(r_type, vcl_type, memb) \
vcl_type \
-__cat__(vmod_get_,r_type)(VARIABLE_CTX ctx, VCL_STRING name) \
+__cat__(vmod_get_,r_type)(VARIABLE_CTX ctx, struct vmod_priv *priv, \
+ VCL_STRING name) \
{ \
- struct variable *var = getvar(get_symtab(ctx), name); \
+ struct variable *var = getvar(get_symtab(priv), name); \
if (var && var->type == __cat__(variable_,r_type)) \
return var->v.memb; \
return 0; \
}
#define DEFSET(r_type, vcl_type, memb) \
VCL_VOID \
-__cat__(vmod_set_,r_type)(VARIABLE_CTX ctx, VCL_STRING name, \
+__cat__(vmod_set_,r_type)(VARIABLE_CTX ctx, struct vmod_priv *priv, \
+ VCL_STRING name, \
vcl_type value) \
{ \
- struct symtab *vt = get_symtab(ctx); \
+ struct symtab *vt = get_symtab(priv); \
struct variable *var = defvar(vt, name, variable_unset, NULL); \
var->type = __cat__(variable_,r_type); \
var->v.memb = value; \
}
#define DEF(name, vcl_type, memb) \
@@ -488,28 +471,28 @@ DEFSET(name, vcl_type, memb)
DEF(int, VCL_INT, i)
DEF(real, VCL_REAL, r)
DEF(duration, VCL_DURATION, d)
VCL_BOOL
-vmod_defined(VARIABLE_CTX ctx, VCL_STRING name)
+vmod_defined(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name)
{
- return !!getvar(get_symtab(ctx), name);
+ return !!getvar(get_symtab(priv), name);
}
VCL_STRING
-vmod_type_of(VARIABLE_CTX ctx, VCL_STRING name)
+vmod_type_of(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name)
{
- struct variable *var = getvar(get_symtab(ctx), name);
+ struct variable *var = getvar(get_symtab(priv), name);
return typestr[var ? var->type : variable_unset];
}
VCL_VOID
-vmod_unset(VARIABLE_CTX ctx, VCL_STRING name)
+vmod_unset(VARIABLE_CTX ctx, struct vmod_priv *priv, VCL_STRING name)
{
- symtab_remove(get_symtab(ctx), name);
+ symtab_remove(get_symtab(priv), name);
}
static void
log_error(const char *fmt, ...)
{
va_list ap;
@@ -715,16 +698,16 @@ setval(union value *val, const char *s, enum variable_type type, char **err)
default:
abort();
}
}
VCL_VOID
-vmod_regset(VARIABLE_CTX ctx, VCL_STRING vars, VCL_STRING rxs,
- VCL_STRING input)
+vmod_regset(VARIABLE_CTX ctx, struct vmod_priv *priv,
+ VCL_STRING vars, VCL_STRING rxs, VCL_STRING input)
{
- struct symtab *vt = get_symtab(ctx);
+ struct symtab *vt = get_symtab(priv);
struct vardef *head = NULL, *tail = NULL, *def;
size_t count = 0;
size_t n;
const char *v = vars;
const char *error_ptr;
int error_offset;
@@ -891,15 +874,16 @@ define_param(struct symtab *vt, struct vardef *def,
log_error("variable.queryset: %s", err);
defvar(vt, def->name, def->type, &value);
free(s);
}
VCL_VOID
-vmod_queryset(VARIABLE_CTX ctx, VCL_STRING vars, VCL_STRING query)
+vmod_queryset(VARIABLE_CTX ctx, struct vmod_priv *priv,
+ VCL_STRING vars, VCL_STRING query)
{
- struct symtab *vt = get_symtab(ctx);
+ struct symtab *vt = get_symtab(priv);
struct vardef *head = NULL, *tail = NULL, *def;
size_t count = 0;
const char *v = vars;
while (*v) {
char const *nameptr = v;
diff --git a/src/variable.vcc b/src/variable.vcc
index 3745a8d..7a3151f 100644
--- a/src/variable.vcc
+++ b/src/variable.vcc
@@ -19,29 +19,29 @@ $Module variable 3 Variable Support for Varnish
COLOPHON
========
Due to limitations of the vmodtool.py utility, this document contains
only prototypes of the functions provided by the **vmod-variable** module.
For a detailed documentation, please see vmod-variable(3) manual page.
-$Function VOID set(STRING, STRING)
-$Function STRING get(STRING)
+$Function VOID set(PRIV_TASK, STRING, STRING)
+$Function STRING get(PRIV_TASK, STRING)
$Function VOID global_set(STRING, STRING)
$Function STRING global_get(STRING)
-$Function VOID set_int(STRING, INT)
-$Function INT get_int(STRING)
-$Function VOID set_string(STRING, STRING)
-$Function STRING get_string(STRING)
-$Function VOID set_real(STRING, REAL)
-$Function REAL get_real(STRING)
-$Function VOID set_duration(STRING, DURATION)
-$Function DURATION get_duration(STRING)
-$Function VOID clear()
+$Function VOID set_int(PRIV_TASK, STRING, INT)
+$Function INT get_int(PRIV_TASK, STRING)
+$Function VOID set_string(PRIV_TASK, STRING, STRING)
+$Function STRING get_string(PRIV_TASK, STRING)
+$Function VOID set_real(PRIV_TASK, STRING, REAL)
+$Function REAL get_real(PRIV_TASK, STRING)
+$Function VOID set_duration(PRIV_TASK, STRING, DURATION)
+$Function DURATION get_duration(PRIV_TASK, STRING)
+$Function VOID clear(PRIV_TASK)
$Function VOID global_clear()
$Function BOOL global_defined(STRING)
$Function VOID global_unset(STRING)
-$Function BOOL defined(STRING)
-$Function STRING type_of(STRING)
-$Function VOID unset(STRING)
-$Function VOID regset(STRING, STRING, STRING)
-$Function VOID queryset(STRING, STRING)
+$Function BOOL defined(PRIV_TASK, STRING)
+$Function STRING type_of(PRIV_TASK, STRING)
+$Function VOID unset(PRIV_TASK, STRING)
+$Function VOID regset(PRIV_TASK, STRING, STRING, STRING)
+$Function VOID queryset(PRIV_TASK, STRING, STRING)

Return to:

Send suggestions and report system problems to the System administrator.