Commit b68cc125 authored by Geoff Simmons's avatar Geoff Simmons

initial commit, only the version() function

parents
((nil . ((indent-tabs-mode . t)))
(c-mode . ((c-file-style . "BSD"))))
Makefile
Makefile.in
.deps/
.libs/
*.o
*.lo
*.la
*~
*.[1-9]
/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
/src/parse_encoding.c
/src/parse_encoding.h
language: c
before_install:
- sudo apt-get update -q
- sudo apt-get install -qq apt-transport-https python-docutils
- curl https://repo.varnish-cache.org/debian/GPG-key.txt | sudo apt-key add -
- echo "deb https://repo.varnish-cache.org/ubuntu/ precise varnish-4.0" | sudo tee /etc/apt/sources.list.d/varnish-cache.list
- sudo apt-get -q update
- sudo apt-get install varnish libvarnishapi-dev
before_script:
- ./autogen.sh
- ./configure --prefix=/usr
- make -j4
script:
- make check -j4
compiler:
- clang
- gcc
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 # vmod-blobdigest.spec debian
doc_DATA = README.rst LICENSE COPYING
dist_man_MANS = vmod_blobdigest.3
MAINTAINERCLEANFILES = $(dist_man_MANS)
vmod_blobdigest.3: README.rst
README.rst: src/vmod_blobdigest.man.rst
cp src/vmod_blobdigest.man.rst README.rst
src/vmod_blobdigest.man.rst:
make -C src vmod_blobdigest.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_blobdigest(3):
===============
vmod_blobdigest
===============
---------------------------------------
digests and hmacs for the VCL blob type
---------------------------------------
:Manual section: 3
SYNOPSIS
========
import blobdigest [from "path"] ;
CONTENTS
========
* STRING version()
.. _func_version:
STRING version()
----------------
Prototype
STRING version()
Description
Returns the version string for this VMOD.
Example
``std.log("Using VMOD blobdigest version " + blobdigest.version());``
#!/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-blobdigest], [trunk])
AC_CONFIG_MACRO_DIR([m4])
m4_ifndef([VARNISH_VMOD_INCLUDES], AC_MSG_ERROR([Need varnish.m4 -- see README.rst]))
AC_CONFIG_SRCDIR(src/vmod_blobdigest.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
AC_PROG_CC_C99
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: pthread only if we need mutex or etc.
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"])
# Checks for header files.
# XXX: review
AC_HEADER_STDC
AC_CHECK_HEADERS([sys/types.h])
AC_CHECK_HEADERS([errno.h])
AC_CHECK_HEADERS([stdint.h])
AC_CHECK_HEADERS([pthread.h])
AC_CHECK_HEADERS([stdbool.h])
AC_CHECK_HEADERS([unistd.h])
# 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])
AC_PATH_PROG([PERL], [perl])
# --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 it is 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 -std=c99
vmoddir = @VMOD_DIR@
vmod_LTLIBRARIES = libvmod_blobdigest.la
libvmod_blobdigest_la_LDFLAGS = -module -export-dynamic -avoid-version -shared
libvmod_blobdigest_la_SOURCES = \
vmod_blobdigest.c \
vmod_blobdigest.h
nodist_libvmod_blobdigest_la_SOURCES = \
vcc_if.c \
vcc_if.h \
parse_encoding.h \
parse_encoding.c
parse_encoding.h: parse_encoding.c
parse_encoding.c: gen_enum_parse.pl
@PERL@ $(srcdir)/gen_enum_parse.pl parse_encoding.c parse_encoding.h
vmod_blobdigest.lo: vcc_if.c vcc_if.h parse_encoding.h
vcc_if.c: vcc_if.h
vcc_if.h vmod_blobdigest.man.rst: @VMODTOOL@ $(top_srcdir)/src/vmod_blobdigest.vcc
@VMODTOOL@ $(top_srcdir)/src/vmod_blobdigest.vcc
VMOD_TESTS = $(top_srcdir)/src/tests/*.vtc
.PHONY: $(VMOD_TESTS)
$(top_srcdir)/src/tests/*.vtc: libvmod_blobdigest.la
@VARNISHTEST@ -Dvarnishd=@VARNISHD@ -Dvmod_topbuild=$(abs_top_builddir) $@
check: $(VMOD_TESTS)
EXTRA_DIST = \
gen_enum_parse.pl \
vmod_blobdigest.vcc \
$(VMOD_TESTS)
CLEANFILES = \
$(builddir)/vcc_if.c \
$(builddir)/vcc_if.h \
$(builddir)/vmod_blobdigest.rst \
$(builddir)/vmod_blobdigest.man.rst \
$(builddir)/parse_encoding.h \
$(builddir)/parse_encoding.c
#!/usr/bin/perl
use strict;
use warnings;
my @vals = (qw(
SHA256));
sub assert {
unless($_[0]) {
require Carp;
Carp::confess();
}
return undef;
}
sub _OUT {
my $fd = shift;
print $fd @_;
}
sub parse_token_code_gen {
my $fd = shift;
my $prevpos = shift; # 0, 1 ...
my $prev = shift; # "G", "GE", ...
my $term = shift; # function(macro) name to check if a symbol is terminator
assert ((scalar(@_) % 2) == 0);
my %symbs = @_; # symbol => result, ...
my $pos = $prevpos + 1;
# label
if ($prevpos != -1) {
_OUT ($fd, ' _'.$prevpos.$prev.":\n");
}
my $nsymbs = scalar(keys %symbs);
assert ($nsymbs);
if ($nsymbs == 1) {
my ($m, $r) = %symbs;
my @cond;
# optimize for just this one string
my $i;
for ($i = $pos; $i < length($m); $i++) {
push @cond, '(m['.$i."] == '".substr($m, $i, 1)."')";
}
push @cond, '('.$term.'(m['.$i."]))";
_OUT ($fd, "\t//".$m."\n");
_OUT ($fd, "\t".'if ('.join(" && ", @cond).') {'."\n");
_OUT ($fd, "\t".' r = '.$r.";\n");
_OUT ($fd, "\t".' p = '.$i.";\n");
_OUT ($fd, "\t".' goto ok;'."\n");
_OUT ($fd, "\t"."}\n");
_OUT ($fd, "\t".'goto invalid;'."\n");
} else {
my @case;
my @tocall;
{
## terminating keys
foreach my $m (grep { (length($_) == $pos) } sort keys %symbs) {
my $r = delete $symbs{$m};
_OUT ($fd, "\t//".$m."\n");
_OUT ($fd, "\t".'if ('.$term.'(m['.$pos.'])) {'."\n");
_OUT ($fd, "\t".' r = '.$r.";\n");
_OUT ($fd, "\t".' p = '.$pos.";\n");
_OUT ($fd, "\t".' goto ok;'."\n");
_OUT ($fd, "\t"."}\n");
}
}
{
## non-terminating keys
my @keys = (sort keys %symbs);
# hash by this char
my %h;
foreach my $k (@keys) {
assert( length($k) > $pos );
push @{$h{substr($k, $pos, 1)}}, ($k);
}
foreach my $k (sort keys %h) {
my $la = '_'.$pos.$prev.$k;
my @me = @{$h{$k}};
push @case, ("case '".$k."':\tgoto ".$la.";\t// ".
join(", ",@me));
push @tocall, [$prev.$k, \@me];
}
}
push @case, ("default:\tgoto invalid;");
_OUT ($fd, "\t".'switch (m['.$pos."]) {\n\t");
_OUT ($fd, join("\n\t", @case)."\n");
_OUT ($fd, "\t}\n");
if (scalar(@tocall)) {
map {
parse_token_code_gen($fd, $pos, $_->[0],
$term,
(map { $_ => $symbs{$_}; }
@{$_->[1]}));
} @tocall;
}
}
}
unless ($#ARGV == 1) {
printf(STDERR 'Usage: '.$0." <c-file> <h-file>\n");
exit 1;
}
my ($c_file, $h_file) = @ARGV;
open(my $c_out, '>', $c_file) || die('cannot open '.$c_file.': '.$!);
open(my $h_out, '>', $h_file) || die('cannot open '.$h_file.': '.$!);
_OUT($h_out, <<'EOF');
/* AUTO-GENERATED, DO NOT EDIT */
EOF
_OUT($h_out,
"enum encoding {\n\t_INVALID = 0,\n\t".
join(",\n\t", @vals).",\n\t__MAX_ENCODING\n};\n");
_OUT($h_out, <<'EOF');
enum encoding parse_encoding (const char *);
EOF
_OUT($c_out, <<EOF);
/* AUTO-GENERATED, DO NOT EDIT */
#include "$h_file"
#define term(c) ((c) == '\\0')
EOF
_OUT($c_out, <<'EOF');
enum encoding
parse_encoding (const char *m) {
int p;
enum encoding r;
EOF
parse_token_code_gen($c_out, -1, '', 'term',
map { ($_ => $_) } @vals);
_OUT($c_out, <<EOF);
ok:
return r;
invalid:
return _INVALID;
(void)p;
}
EOF
close($c_out) || die('error closing '.$c_file.': '.$!);
close($h_out) || die('error closing '.$h_file.': '.$!);
# looks like -*- vcl -*-
varnishtest "vcl.use and .discard, and version string"
server s1 {} -start
varnish v1 -vcl+backend {
import blobdigest from "${vmod_topbuild}/src/.libs/libvmod_blobdigest.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 blobdigest from "${vmod_topbuild}/src/.libs/libvmod_blobdigest.so";
backend b { .host = "${bad_ip}"; }
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
set resp.http.x-version = blobdigest.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
/*-
* 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 "config.h"
#include "vcl.h"
#include "vrt.h"
#include "vcc_if.h"
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 blobdigest 3 digests and hmacs for the VCL blob type
$Function STRING version()
Description
Returns the version string for this VMOD.
Example
``std.log("Using VMOD blobdigest version " + blobdigest.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