Commit 7faebd28 authored by Geoff Simmons's avatar Geoff Simmons

initial commit

parents
Pipeline #13 skipped
((nil . ((indent-tabs-mode . t)))
(c-mode . ((c-file-style . "BSD"))))
Makefile
Makefile.in
.deps/
.libs/
*.o
*.lo
*.la
*~
*.[1-9]
.dirstamp
/aclocal.m4
/autom4te.cache/
/compile
/config.guess
/config.h
/config.h.in
/config.log
/config.status
/config.sub
/configure
/depcomp
/install-sh
/libtool
/ltmain.sh
/missing
/stamp-h1
/m4/
/src/vcc_if.c
/src/vcc_if.h
/src/vmod_*rst
See LICENSE for details.
Copyright (c) 2016 UPLEX Nils Goroll Systemoptimierung
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
ACLOCAL_AMFLAGS = -I m4 -I ${LIBVARNISHAPI_DATAROOTDIR}/aclocal
SUBDIRS = src
DISTCHECK_CONFIGURE_FLAGS = \
VMOD_DIR='$${libdir}/varnish/vmods'
EXTRA_DIST = README.rst LICENSE COPYING
doc_DATA = README.rst LICENSE COPYING
dist_man_MANS = vmod_blob.3
MAINTAINERCLEANFILES = $(dist_man_MANS)
vmod_blob.3: README.rst
README.rst: src/vmod_blob.man.rst
cp src/vmod_blob.man.rst README.rst
src/vmod_blob.man.rst:
make -C src vmod_blob.man.rst
%.1 %.2 %.3 %.4 %.5 %.6 %.7 %.8 %.9:
if HAVE_RST2MAN
${RST2MAN} $< $@
else
@echo "========================================"
@echo "You need rst2man installed to make dist"
@echo "========================================"
@false
endif
..
.. NB: This file is machine generated, DO NOT EDIT!
..
.. Edit vmod.vcc and run make instead
..
.. role:: ref(emphasis)
.. _vmod_blob(3):
=========
vmod_blob
=========
--------------------------------------
basic operations for the VCL blob type
--------------------------------------
:Manual section: 3
SYNOPSIS
========
import blob [from "path"] ;
CONTENTS
========
* BOOL same(BLOB, BLOB)
* BOOL equal(BLOB, BLOB)
* INT length(BLOB)
* STRING version()
.. _func_same:
same
----
::
BOOL same(BLOB, BLOB)
Description
Returns true if and only if the two BLOB arguments are the
same object, i.e. they specify exactly the same region of
memory.
.. _func_equal:
equal
-----
::
BOOL equal(BLOB, BLOB)
Description
Returns true if and only if the two BLOB arguments have equal
contents (possibly in different memory regions).
.. _func_length:
length
------
::
INT length(BLOB)
Description
Returns the length of the BLOB.
.. _func_version:
version
-------
::
STRING version()
Description
Returns the version string for this VMOD.
Example
std.log("Using VMOD blob version " + blob.version());
COPYRIGHT
=========
::
Copyright (c) 2016 UPLEX Nils Goroll Systemoptimierung
All rights reserved
Author: Geoffrey Simmons <geoffrey.simmons@uplex.de>
See LICENSE
#!/bin/sh
warn() {
echo "WARNING: $@" 1>&2
}
case `uname -s` in
Darwin)
LIBTOOLIZE=glibtoolize
;;
FreeBSD)
LIBTOOLIZE=libtoolize
;;
Linux)
LIBTOOLIZE=libtoolize
;;
SunOS)
LIBTOOLIZE=libtoolize
;;
*)
warn "unrecognized platform:" `uname -s`
LIBTOOLIZE=libtoolize
esac
automake_version=`automake --version | tr ' ' '\n' | egrep '^[0-9]\.[0-9a-z.-]+'`
if [ -z "$automake_version" ] ; then
warn "unable to determine automake version"
else
case $automake_version in
0.*|1.[0-8]|1.[0-8][.-]*)
warn "automake ($automake_version) detected; 1.9 or newer recommended"
;;
*)
;;
esac
fi
# check for varnishapi.m4 in custom paths
dataroot=$(pkg-config --variable=datarootdir varnishapi 2>/dev/null)
if [ -z "$dataroot" ] ; then
cat >&2 <<'EOF'
Package varnishapi was not found in the pkg-config search path.
Perhaps you should add the directory containing `varnishapi.pc'
to the PKG_CONFIG_PATH environment variable
EOF
exit 1
fi
set -ex
aclocal -I m4 -I ${dataroot}/aclocal
$LIBTOOLIZE --copy --force
autoheader
automake --add-missing --copy --foreign
autoconf
AC_PREREQ(2.59)
AC_COPYRIGHT([Copyright (c) 2016 UPLEX - Nils Goroll Systemoptimierung])
AC_INIT([libvmod-blob], [trunk], [varnish-support@uplex.de])
AC_CONFIG_MACRO_DIR([m4])
m4_ifndef([VARNISH_VMOD_INCLUDES], AC_MSG_ERROR([Need varnish.m4 -- see README.rst]))
AC_CONFIG_SRCDIR(src/vmod_blob.vcc)
AM_CONFIG_HEADER(config.h)
AC_CANONICAL_SYSTEM
AC_LANG(C)
AM_INIT_AUTOMAKE([foreign])
AC_GNU_SOURCE
AC_PROG_CC
AC_PROG_CC_STDC
if test "x$ac_cv_prog_cc_c99" = xno; then
AC_MSG_ERROR([Could not find a C99 compatible compiler])
fi
AC_PROG_CPP
# XXX need pthread?
AX_PTHREAD(,[AC_MSG_ERROR([Could not configure pthreads support])])
LIBS="$PTHREAD_LIBS $LIBS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
CC="$PTHREAD_CC"
AC_PROG_INSTALL
AC_PROG_LIBTOOL
AC_PROG_MAKE_SET
# Check for rst utilities
AC_CHECK_PROGS(RST2MAN, [rst2man rst2man.py], "no")
if test "x$RST2MAN" = "xno"; then
AC_MSG_WARN([rst2man not found - not building man pages])
fi
AM_CONDITIONAL(HAVE_RST2MAN, [test "x$RST2MAN" != "xno"])
# XXX Checks for C sources
AC_C_INLINE
AC_C_RESTRICT
AC_TYPE_UINT8_T
# backwards compat with older pkg-config
# - pull in AC_DEFUN from pkg.m4
m4_ifndef([PKG_CHECK_VAR], [
# PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
# -------------------------------------------
# Retrieves the value of the pkg-config variable for the given module.
AC_DEFUN([PKG_CHECK_VAR],
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
_PKG_CONFIG([$1], [variable="][$3]["], [$2])
AS_VAR_COPY([$1], [pkg_cv_][$1])
AS_VAR_IF([$1], [""], [$5], [$4])dnl
])# PKG_CHECK_VAR
])
PKG_CHECK_MODULES([libvarnishapi], [varnishapi])
PKG_CHECK_VAR([LIBVARNISHAPI_DATAROOTDIR], [varnishapi], [datarootdir])
PKG_CHECK_VAR([LIBVARNISHAPI_BINDIR], [varnishapi], [bindir])
PKG_CHECK_VAR([LIBVARNISHAPI_SBINDIR], [varnishapi], [sbindir])
AC_SUBST([LIBVARNISHAPI_DATAROOTDIR])
# Varnish include files tree
VARNISH_VMOD_INCLUDES
VARNISH_VMOD_DIR
VARNISH_VMODTOOL
AC_PATH_PROG([VARNISHTEST], [varnishtest], [],
[$LIBVARNISHAPI_BINDIR:$LIBVARNISHAPI_SBINDIR:$PATH])
AC_PATH_PROG([VARNISHD], [varnishd], [],
[$LIBVARNISHAPI_SBINDIR:$LIBVARNISHAPI_BINDIR:$PATH])
# --enable-stack-protector
AC_ARG_ENABLE(stack-protector,
AS_HELP_STRING([--enable-stack-protector],[enable stack protector (default is YES)]),
[],
[enable_stack_protector=yes])
if test "x$enable_stack_protector" != "xno"; then
AX_CHECK_COMPILE_FLAG([-fstack-protector],
AX_CHECK_LINK_FLAG([-fstack-protector],
[CFLAGS="${CFLAGS} -fstack-protector"], [], []),
[], [])
fi
# --enable-debugging
AC_ARG_ENABLE(debugging,
AS_HELP_STRING([--enable-debugging],[enable debugging (default is NO)]),
[],
[enable_debugging=no])
# AC_PROG_CC sets CFLAGS to '-g -O2' unless already set, so there's no
# need to add -g. Disable or change by explicitly setting CFLAGS. If
# this option is enabled, then -Og or -O0 becomes the last
# optimization option, and hence takes precedence.
if test "x$enable_debugging" != "xno"; then
CFLAGS="${CFLAGS} -fno-inline"
AX_CHECK_COMPILE_FLAG([-Og],
[CFLAGS="${CFLAGS} -Og"],
[CFLAGS="${CFLAGS} -O0"],
[])
fi
AC_CONFIG_FILES([
Makefile
src/Makefile
])
AC_OUTPUT
AM_CPPFLAGS = @VMOD_INCLUDES@ -Wall -Werror
CFLAGS += -std=c99
vmoddir = @VMOD_DIR@
vmod_LTLIBRARIES = libvmod_blob.la
libvmod_blob_la_LDFLAGS = -module -export-dynamic -avoid-version -shared
libvmod_blob_la_SOURCES = \
vmod_blob.c
nodist_libvmod_blob_la_SOURCES = \
vcc_if.c \
vcc_if.h
# XXX need pthread?
libvmod_blob_la_LIBADD = \
${PTHREAD_LIBS}
vmod_blob.lo: vcc_if.c vcc_if.h
vcc_if.c: vcc_if.h
vcc_if.h vmod_blob.man.rst: @VMODTOOL@ $(top_srcdir)/src/vmod_blob.vcc
@VMODTOOL@ $(top_srcdir)/src/vmod_blob.vcc
VMOD_TESTS = $(top_srcdir)/src/tests/*.vtc
.PHONY: $(VMOD_TESTS)
$(top_srcdir)/src/tests/*.vtc: libvmod_blob.la
@VARNISHTEST@ -Dvarnishd=@VARNISHD@ -Dvmod_topbuild=$(abs_top_builddir) $@
check: $(VMOD_TESTS)
EXTRA_DIST = \
vmod_blob.vcc \
$(VMOD_TESTS)
CLEANFILES = \
$(builddir)/vcc_if.c \
$(builddir)/vcc_if.h \
$(builddir)/vmod_blob.rst \
$(builddir)/vmod_blob.man.rst
# looks like -*- vcl -*-
varnishtest "vcl.use and .discard, and version string"
server s1 {} -start
varnish v1 -vcl+backend {
import blob from "${vmod_topbuild}/src/.libs/libvmod_blob.so";
} -start
varnish v1 -vcl+backend {}
varnish v1 -cli "vcl.list"
varnish v1 -cli "vcl.use vcl1"
varnish v1 -cli "vcl.use vcl2"
varnish v1 -cli "vcl.use vcl1"
varnish v1 -cli "vcl.show vcl1"
varnish v1 -cli "vcl.use vcl2"
varnish v1 -cli "vcl.discard vcl1"
varnish v1 -cli "vcl.list"
varnish v1 -vcl {
import blob from "${vmod_topbuild}/src/.libs/libvmod_blob.so";
backend b { .host = "${bad_ip}"; }
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
set resp.http.x-version = blob.version();
if (!resp.http.x-version) {
set resp.status = 500;
}
return(deliver);
}
}
client c1 {
txreq -url "/"
rxresp
expect resp.status == 200
expect resp.http.x-version ~ "^.+$"
} -run
# looks like -*- vcl -*-
varnishtest "same(), equal() and length()"
# VMOD blobcode must be installed
varnish v1 -vcl {
import blob from "${vmod_topbuild}/src/.libs/libvmod_blob.so";
import blobcode;
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new foo1 = blobcode.blob(IDENTITY, "foobarbazquux");
new foo2 = blobcode.blob(IDENTITY, "foobarbazquux");
new hobbes1 = blobcode.blob(IDENTITY,
{"Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure."});
new hobbes2 = blobcode.blob(IDENTITY,
{"Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure."});
new empty1 = blobcode.blob(IDENTITY, "");
new empty2 = blobcode.blob(IDENTITY, "");
}
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
if (blob.same(foo1.get(), foo1.get())) {
set resp.http.foo1same = "true";
}
if (blob.same(foo2.get(), foo2.get())) {
set resp.http.foo2same = "true";
}
if (blob.same(foo1.get(), foo2.get())) {
set resp.http.foo12same = "true";
}
if (blob.same(foo2.get(), foo1.get())) {
set resp.http.foo21same = "true";
}
if (blob.same(foo1.get(), hobbes1.get())) {
set resp.http.foohobbessame = "true";
}
if (blob.same(foo1.get(), empty1.get())) {
set resp.http.fooemptysame = "true";
}
if (blob.equal(foo1.get(), foo1.get())) {
set resp.http.foo1equal = "true";
}
if (blob.equal(foo1.get(), foo2.get())) {
set resp.http.foo12equal = "true";
}
if (blob.equal(foo2.get(), foo1.get())) {
set resp.http.foo21equal = "true";
}
if (blob.equal(foo1.get(), hobbes1.get())) {
set resp.http.foohobbesequal = "true";
}
if (blob.equal(foo1.get(), empty1.get())) {
set resp.http.fooemptyequal = "true";
}
set resp.http.foo1len = blob.length(foo1.get());
set resp.http.foo2len = blob.length(foo2.get());
if (blob.same(hobbes1.get(), hobbes1.get())) {
set resp.http.hobbes1same = "true";
}
if (blob.same(hobbes2.get(), hobbes2.get())) {
set resp.http.hobbes2same = "true";
}
if (blob.same(hobbes1.get(), hobbes2.get())) {
set resp.http.hobbes12same = "true";
}
if (blob.same(hobbes2.get(), hobbes1.get())) {
set resp.http.hobbes21same = "true";
}
if (blob.same(hobbes1.get(), empty1.get())) {
set resp.http.hobbesemptysame = "true";
}
if (blob.equal(hobbes1.get(), hobbes1.get())) {
set resp.http.hobbes1equal = "true";
}
if (blob.equal(hobbes1.get(), hobbes2.get())) {
set resp.http.hobbes12equal = "true";
}
if (blob.equal(hobbes2.get(), hobbes1.get())) {
set resp.http.hobbes21equal = "true";
}
if (blob.equal(hobbes1.get(), empty1.get())) {
set resp.http.hobbesemptyequal = "true";
}
set resp.http.hobbes1len = blob.length(hobbes1.get());
set resp.http.hobbes2len = blob.length(hobbes2.get());
if (blob.same(empty1.get(), empty1.get())) {
set resp.http.empty1same = "true";
}
if (blob.same(empty2.get(), empty2.get())) {
set resp.http.empty2same = "true";
}
if (blob.same(empty1.get(), empty2.get())) {
set resp.http.empty12same = "true";
}
if (blob.same(empty2.get(), empty1.get())) {
set resp.http.empty21same = "true";
}
if (blob.equal(empty1.get(), empty1.get())) {
set resp.http.empty1equal = "true";
}
if (blob.equal(empty1.get(), empty2.get())) {
set resp.http.empty12equal = "true";
}
if (blob.equal(empty2.get(), empty1.get())) {
set resp.http.empty21equal = "true";
}
set resp.http.empty1len = blob.length(empty1.get());
set resp.http.empty2len = blob.length(empty2.get());
return(deliver);
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.foo1same == "true"
expect resp.http.foo2same == "true"
expect resp.http.foo12same == <undef>
expect resp.http.foo21same == <undef>
expect resp.http.foohobbessame == <undef>
expect resp.http.fooemptysame == <undef>
expect resp.http.foo1equal == "true"
expect resp.http.foo12equal == "true"
expect resp.http.foo21equal == "true"
expect resp.http.foohobbesequal == <undef>
expect resp.http.fooemptyequal == <undef>
expect resp.http.foo1len == "13"
expect resp.http.foo2len == "13"
expect resp.http.hobbes1same == "true"
expect resp.http.hobbes2same == "true"
expect resp.http.hobbes12same == <undef>
expect resp.http.hobbes21same == <undef>
expect resp.http.hobbesemptysame == <undef>
expect resp.http.hobbes1equal == "true"
expect resp.http.hobbes12equal == "true"
expect resp.http.hobbes21equal == "true"
expect resp.http.hobbesemptyequal == <undef>
expect resp.http.hobbes1len == "269"
expect resp.http.hobbes2len == "269"
expect resp.http.empty1same == "true"
expect resp.http.empty2same == "true"
# VMOD blobcode uses a statically allocated empty blob for
# empty blobs. So the empty blobs from different objects
# evaluate as true for same().
expect resp.http.empty12same == "true"
expect resp.http.empty21same == "true"
expect resp.http.empty1equal == "true"
expect resp.http.empty12equal == "true"
expect resp.http.empty21equal == "true"
expect resp.http.empty1len == "0"
expect resp.http.empty2len == "0"
} -run
/*-
* Copyright 2016 UPLEX - Nils Goroll Systemoptimierung
* All rights reserved.
*
* Author: Geoffrey Simmons <geoffrey.simmons@uplex.de>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <string.h>
#include "config.h"
#include "vrt.h"
#include "vcc_if.h"
VCL_BOOL
vmod_same(VRT_CTX __attribute__((unused)), VCL_BLOB b1, VCL_BLOB b2)
{
return b1->len == b2->len && b1->priv == b2->priv;
}
VCL_BOOL
vmod_equal(VRT_CTX __attribute__((unused)), VCL_BLOB b1, VCL_BLOB b2)
{
if (b1->len != b2->len)
return 0;
return (memcmp(b1->priv, b2->priv, b1->len) == 0);
}
VCL_INT
vmod_length(VRT_CTX __attribute__((unused)), VCL_BLOB b)
{
return b->len;
}
VCL_STRING
vmod_version(VRT_CTX __attribute__((unused)))
{
return VERSION;
}
#-
# Copyright (c) 2016 UPLEX Nils Goroll Systemoptimierung
# All rights reserved
#
# Author: Geoffrey Simmons <geoffrey.simmons@uplex.de>
#
# See LICENSE
#
$Module blob 3 basic operations for the VCL blob type
$Function BOOL same(BLOB, BLOB)
Description
Returns true if and only if the two BLOB arguments are the
same object, i.e. they specify exactly the same region of
memory.
$Function BOOL equal(BLOB, BLOB)
Description
Returns true if and only if the two BLOB arguments have equal
contents (possibly in different memory regions).
$Function INT length(BLOB)
Description
Returns the length of the BLOB.
$Function STRING version()
Description
Returns the version string for this VMOD.
Example
std.log("Using VMOD blob version " + blob.version());
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