Commit d4bdf68d authored by Geoff Simmons's avatar Geoff Simmons

Refactor config/build to build against an installed Varnish instance,

as is common for Varnish 4 VMODs, rather than against a source
directory, This necessitated using SHA256 for hashing rather then
CRC32, since vsha256.h is available in the "public" VRT, but not
vgz.h. For now, we just use the first 32 bits (MSB's) from the
SHA256 hash.
parent b663b4de
AC_PREREQ(2.59) AC_PREREQ(2.59)
AC_COPYRIGHT([Copyright (c) 2013-2015 UPLEX - Nils Goroll Systemoptimierung, 2011 Varnish Software AS]) AC_COPYRIGHT([Copyright (c) 2015 UPLEX - Nils Goroll Systemoptimierung])
AC_INIT([libvmod-vtstor], [master]) AC_INIT([libvmod-vtstor], [4.0])
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR(src/vmod_vtstor.vcc) AC_CONFIG_SRCDIR(src/vmod_vtstor.vcc)
AM_CONFIG_HEADER(config.h) AM_CONFIG_HEADER(config.h)
...@@ -39,30 +39,22 @@ AC_CHECK_HEADERS([sys/stdlib.h]) ...@@ -39,30 +39,22 @@ AC_CHECK_HEADERS([sys/stdlib.h])
# Check for python # Check for python
AC_CHECK_PROGS(PYTHON, [python3 python3.1 python3.2 python2.7 python2.6 python2.5 python2 python], [AC_MSG_ERROR([Python is needed to build this vmod, please install python.])]) AC_CHECK_PROGS(PYTHON, [python3 python3.1 python3.2 python2.7 python2.6 python2.5 python2 python], [AC_MSG_ERROR([Python is needed to build this vmod, please install python.])])
# Varnish source tree # Varnish include files tree
AC_ARG_VAR([VARNISHSRC], [path to Varnish source tree (mandatory)]) VARNISH_VMOD_INCLUDES
if test "x$VARNISHSRC" = x; then VARNISH_VMOD_DIR
AC_MSG_ERROR([No Varnish source tree specified]) VARNISH_VMODTOOL
# Check paths to varnishd and varnishtest
AC_ARG_VAR([VARNISHTEST], [path to varnishtest (mandatory for make check)])
AC_ARG_VAR([VARNISHD], [path to varnishd (mandatory for make check)])
AC_PATH_PROG([VARNISHTEST], [varnishtest])
AC_PATH_PROG([VARNISHD], [varnishd], [/bin/false],
[${PATH}${PATH_SEPARATOR}/usr/local/sbin${PATH_SEPARATOR}/usr/sbin])
if test "x$VARNISHD" = x; then
AC_MSG_FAILURE([Can't locate varnishd])
fi fi
VARNISHSRC=`cd $VARNISHSRC && pwd` if test "x$VARNISHTEST" = x; then
AC_CHECK_FILE([$VARNISHSRC/include/vrt.h], AC_MSG_FAILURE([Can't locate varnishtest])
[],
[AC_MSG_FAILURE(["$VARNISHSRC" is not a Varnish source directory])]
)
# Check that varnishtest is built in the varnish source directory
AC_CHECK_FILE([$VARNISHSRC/bin/varnishtest/varnishtest],
[],
[AC_MSG_FAILURE([Can't find "$VARNISHSRC/bin/varnishtest/varnishtest". Please build your varnish source directory])]
)
# vmod installation dir
AC_ARG_VAR([VMODDIR], [vmod installation directory @<:@LIBDIR/varnish/vmods@:>@])
if test "x$VMODDIR" = x; then
VMODDIR=`pkg-config --variable=vmoddir varnishapi`
if test "x$VMODDIR" = x; then
AC_MSG_FAILURE([Can't determine vmod installation directory])
fi
fi fi
# This corresponds to FreeBSD's WARNS level 6 # This corresponds to FreeBSD's WARNS level 6
......
AM_CPPFLAGS = \ AM_CPPFLAGS = @VMOD_INCLUDES@
-I$(VARNISHSRC)/include \
-I$(VARNISHSRC)/bin/varnishd \
-I$(VARNISHSRC)/lib/libvgz
AM_LDFLAGS = $(AM_LT_LDFLAGS) AM_LDFLAGS = $(AM_LT_LDFLAGS)
vmoddir = $(VMODDIR) vmoddir = @VMOD_DIR@
vmod_LTLIBRARIES = libvmod_vtstor.la vmod_LTLIBRARIES = libvmod_vtstor.la
vmod_srcdir = $(top_srcdir)/src
vmodtool = $(VARNISHSRC)/lib/libvcc/vmodtool.py
libvmod_vtstor_la_LDFLAGS = $(AM_LDFLAGS) -module -export-dynamic -avoid-version -shared libvmod_vtstor_la_LDFLAGS = $(AM_LDFLAGS) -module -export-dynamic -avoid-version -shared
...@@ -21,20 +16,18 @@ nodist_libvmod_vtstor_la_SOURCES = \ ...@@ -21,20 +16,18 @@ nodist_libvmod_vtstor_la_SOURCES = \
vcc_if.c \ vcc_if.c \
vcc_if.h vcc_if.h
# BUILT_SOURCES is only a hack and dependency tracking does not help for the first build
vmod_vtstor.lo: vcc_if.h vmod_vtstor.lo: vcc_if.h
vcc_if.c vcc_if.h: $(vmodtool) $(vmod_srcdir)/vmod_vtstor.vcc vcc_if.c vcc_if.h: @VMODTOOL@ $(top_srcdir)/src/vmod_vtstor.vcc
@PYTHON@ $(vmodtool) $(vmod_srcdir)/vmod_vtstor.vcc @VMODTOOL@ $(top_srcdir)/src/vmod_vtstor.vcc
VMOD_TESTS = tests/*.vtc VMOD_TESTS = tests/*.vtc
.PHONY: $(VMOD_TESTS)
tests/*.vtc:
@VARNISHTEST@ -Dvarnishd=@VARNISHD@ -Dvmod_topbuild=$(abs_top_builddir) $@
check: $(VARNISHSRC)/bin/varnishtest/varnishtest check: $(VMOD_TESTS)
$(VARNISHSRC)/bin/varnishtest/varnishtest \
-Dvarnishd=$(VARNISHSRC)/bin/varnishd/varnishd \
-Dvmod_topbuild=$(abs_top_builddir) \
tests/*.vtc
EXTRA_DIST = \ EXTRA_DIST = \
vmod_vtstor.vcc \ vmod_vtstor.vcc \
......
...@@ -38,26 +38,26 @@ ...@@ -38,26 +38,26 @@
static struct http * static struct http *
selecthttp(VRT_CTX, enum gethdr_e where) selecthttp(VRT_CTX, enum gethdr_e where)
{ {
struct http *hp; struct http *hp;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
switch (where) { switch (where) {
case HDR_REQ: case HDR_REQ:
hp = ctx->http_req; hp = ctx->http_req;
break; break;
case HDR_BEREQ: case HDR_BEREQ:
hp = ctx->http_bereq; hp = ctx->http_bereq;
break; break;
case HDR_BERESP: case HDR_BERESP:
hp = ctx->http_beresp; hp = ctx->http_beresp;
break; break;
case HDR_RESP: case HDR_RESP:
hp = ctx->http_resp; hp = ctx->http_resp;
break; break;
default: default:
WRONG("selecthttp 'where' invalid"); WRONG("selecthttp 'where' invalid");
} }
return (hp); return (hp);
} }
VCL_VOID __match_proto__(td_vmod_vtstor__init) VCL_VOID __match_proto__(td_vmod_vtstor__init)
...@@ -72,7 +72,7 @@ vmod_vtstor__init(VRT_CTX, ...@@ -72,7 +72,7 @@ vmod_vtstor__init(VRT_CTX,
AZ(*vmip); AZ(*vmip);
ALLOC_OBJ(vmi, VMOD_VTSTOR_VTSTOR_MAGIC); ALLOC_OBJ(vmi, VMOD_VTSTOR_VTSTOR_MAGIC);
AN(vmi); AN(vmi);
vmi->hash = vtstor_hash_crc32; vmi->hash = vtstor_hash_sha256;
vmi->alloc = vtstor_alloc; vmi->alloc = vtstor_alloc;
vmi->dealloc = vtstor_dealloc; vmi->dealloc = vtstor_dealloc;
vmi->buckets = 1024; vmi->buckets = 1024;
...@@ -159,22 +159,22 @@ vmod_vtstor_delete(VRT_CTX, struct vmod_vtstor_vtstor *vmi, VCL_HEADER hdr) ...@@ -159,22 +159,22 @@ vmod_vtstor_delete(VRT_CTX, struct vmod_vtstor_vtstor *vmi, VCL_HEADER hdr)
VCL_STRING __match_proto__(td_vmod_vxid) VCL_STRING __match_proto__(td_vmod_vxid)
vmod_vxid(VRT_CTX) vmod_vxid(VRT_CTX)
{ {
char *p; char *p;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req->sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(ctx->req->sp, SESS_MAGIC);
p = WS_Printf(ctx->ws, "%u", ctx->req->sp->vxid); p = WS_Printf(ctx->ws, "%u", ctx->req->sp->vxid);
if (p == NULL) if (p == NULL)
VSLb(ctx->vsl, SLT_VCL_Error, VSLb(ctx->vsl, SLT_VCL_Error,
"vmod vtstor: insufficient workspace in vxid()"); "vmod vtstor: insufficient workspace in vxid()");
return p; return p;
} }
VCL_STRING __match_proto__(td_vmod_version) VCL_STRING __match_proto__(td_vmod_version)
vmod_version(VRT_CTX) vmod_version(VRT_CTX)
{ {
return VERSION; return VERSION;
} }
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include "vtstor.h" #include "vtstor.h"
#include "vgz.h" #include "vsha256.h"
struct vtstor_node { struct vtstor_node {
unsigned magic; unsigned magic;
...@@ -188,14 +188,18 @@ static int vtstor_set_value(struct vmod_vtstor_vtstor *vmi, struct vtstor_node * ...@@ -188,14 +188,18 @@ static int vtstor_set_value(struct vmod_vtstor_vtstor *vmi, struct vtstor_node *
return node->value_capacity; return node->value_capacity;
} }
uint32_t vtstor_hash_crc32(VCL_STRING s) uint32_t vtstor_hash_sha256(VCL_STRING s)
{ {
uint32_t crc; SHA256_CTX ctx;
crc = crc32(~0U, (const unsigned char*)s, strlen(s)); unsigned char sha[SHA256_LEN];
crc ^= ~0U; uint32_t hash;
crc++;
return (crc ? crc : 1); SHA256_Init(&ctx);
SHA256_Update(&ctx, (const void *) s, strlen(s));
SHA256_Final(sha, &ctx);
memcpy(&hash, sha, 4);
return (hash ? hash : 1);
} }
size_t vtstor_alloc(struct vmod_vtstor_vtstor *vmi, size_t size, char** ptrp) size_t vtstor_alloc(struct vmod_vtstor_vtstor *vmi, size_t size, char** ptrp)
......
...@@ -56,7 +56,7 @@ struct vmod_vtstor_vtstor { ...@@ -56,7 +56,7 @@ struct vmod_vtstor_vtstor {
struct vtstor_map *map; struct vtstor_map *map;
}; };
uint32_t vtstor_hash_crc32(VCL_STRING); uint32_t vtstor_hash_sha256(VCL_STRING);
size_t vtstor_alloc(struct vmod_vtstor_vtstor *, size_t, char **); size_t vtstor_alloc(struct vmod_vtstor_vtstor *, size_t, char **);
void vtstor_dealloc(struct vmod_vtstor_vtstor *, char **); void vtstor_dealloc(struct vmod_vtstor_vtstor *, char **);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment