Commit a20b6af4 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add a new VMOD.debug and move the stuff varnishtest uses to get out

into the obscure corners over there, making vmod.std a better copy&
paste example and removing things like "panic" from the VCC.
parent a15dd15d
......@@ -384,21 +384,6 @@ VRT_Rollback(const struct sess *sp)
/*--------------------------------------------------------------------*/
void
VRT_panic(struct req *req, const char *str, ...)
{
va_list ap;
char *b;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
va_start(ap, str);
b = VRT_String(req->http->ws, "PANIC: ", str, ap);
va_end(ap);
VAS_Fail("VCL", "", 0, b, 0, 2);
}
/*--------------------------------------------------------------------*/
void
VRT_synth_page(struct req *req, unsigned flags, const char *str, ...)
{
......
......@@ -25,6 +25,7 @@ flexelint \
../../lib/libvarnishcompat/execinfo.c \
../../lib/libvcl/*.c \
../../lib/libvmod_std/*.c \
../../lib/libvmod_debug/*.c \
2>&1 | tee _.fl
if [ -f _.fl.old ] ; then
......
varnishtest "Test std vmod"
varnishtest "Test std & debug vmod"
server s1 {
rxreq
......@@ -7,11 +7,14 @@ server s1 {
varnish v1 -vcl+backend {
import std from "${topbuild}/lib/libvmod_std/.libs/libvmod_std.so" ;
import debug from "${topbuild}/lib/libvmod_debug/.libs/libvmod_debug.so" ;
sub vcl_deliver {
set resp.http.foo = std.toupper(resp.http.foo);
set resp.http.bar = std.tolower(resp.http.bar);
set resp.http.who = std.author(phk);
set resp.http.who = debug.author(phk);
debug.test_priv_call();
debug.test_priv_vcl();
std.log("VCL initiated log");
std.syslog(8 + 7, "Somebody runs varnishtest");
}
......@@ -27,9 +30,9 @@ client c1 {
} -run
varnish v1 -badvcl {
import std from "${topbuild}/lib/libvmod_std/.libs/libvmod_std.so.1" ;
import debug from "${topbuild}/lib/libvmod_debug/.libs/libvmod_debug.so.1" ;
sub vcl_deliver {
set resp.http.who = std.author(jfk);
set resp.http.who = debug.author(jfk);
}
}
......
......@@ -6,9 +6,9 @@ server s1 {
} -start
varnish v1 -vcl+backend {
import std from "${topbuild}/lib/libvmod_std/.libs/libvmod_std.so" ;
import debug from "${topbuild}/lib/libvmod_debug/.libs/libvmod_debug.so" ;
sub vcl_deliver {
set resp.http.who = std.author(phk);
set resp.http.who = debug.author(phk);
}
} -start
......@@ -18,9 +18,9 @@ client c1 {
rxresp
} -run
varnish v1 -vcl+backend {
import std from "${topbuild}/lib/libvmod_std/.libs/libvmod_std.so" ;
import debug from "${topbuild}/lib/libvmod_debug/.libs/libvmod_debug.so" ;
sub vcl_deliver {
set resp.http.who = std.author(des);
set resp.http.who = debug.author(des);
}
}
......@@ -30,9 +30,9 @@ client c1 {
} -run
varnish v1 -vcl+backend {
import std from "${topbuild}/lib/libvmod_std/.libs/libvmod_std.so" ;
import debug from "${topbuild}/lib/libvmod_debug/.libs/libvmod_debug.so" ;
sub vcl_deliver {
set resp.http.who = std.author(kristian);
set resp.http.who = debug.author(kristian);
}
}
......
......@@ -15,9 +15,11 @@ server s1 {
varnish v1 -storage "-smalloc,1m" -vcl+backend {
import debug from "${topbuild}/lib/libvmod_debug/.libs/libvmod_debug.so";
sub vcl_deliver {
if (resp.http.panic) {
panic "Had Panic header: " + resp.http.panic;
debug.panic("Had Panic header: " + resp.http.panic);
}
}
} -start
......
......@@ -99,11 +99,6 @@ varnish v1 -vcl {
sub vcl_recv { ban_url ("foo"); }
}
varnish v1 -badvcl {
backend b { .host = "127.0.0.1"; }
sub vcl_recv { panic if; }
}
varnish v1 -badvcl {
backend b { .host = "127.0.0.1"; }
sub vcl_recv { kluf ; }
......
......@@ -550,6 +550,7 @@ AC_CONFIG_FILES([
lib/libvarnishcompat/Makefile
lib/libvcl/Makefile
lib/libvgz/Makefile
lib/libvmod_debug/Makefile
lib/libvmod_std/Makefile
lib/libjemalloc/Makefile
man/Makefile
......
......@@ -150,7 +150,6 @@ int VRT_re_match(struct req *, const char *, void *re);
const char *VRT_regsub(struct req *, int all, const char *,
void *, const char *);
void VRT_panic(struct req *req, const char *, ...);
void VRT_ban(struct sess *sp, char *, ...);
void VRT_ban_string(struct sess *sp, const char *);
void VRT_purge(const struct sess *sp, double ttl, double grace);
......
......@@ -6,6 +6,7 @@ SUBDIRS = \
libvarnishapi \
libvcl \
libvgz \
libvmod_debug \
libvmod_std \
@JEMALLOC_SUBDIR@
......
......@@ -233,19 +233,6 @@ parse_hash_data(struct vcc *tl)
/*--------------------------------------------------------------------*/
static void
parse_panic(struct vcc *tl)
{
vcc_NextToken(tl);
Fb(tl, 1, "VRT_panic(req, ");
vcc_Expr(tl, STRING);
ERRCHK(tl);
Fb(tl, 0, ", vrt_magic_string_end);\n");
}
/*--------------------------------------------------------------------*/
static void
parse_return(struct vcc *tl)
{
......@@ -331,7 +318,6 @@ static struct action_table {
/* Keep list sorted from here */
{ "call", parse_call },
{ "hash_data", parse_hash_data, VCL_MET_HASH },
{ "panic", parse_panic },
{ "ban", parse_ban },
{ "ban_url", parse_ban_url },
{ "remove", parse_unset }, /* backward compatibility */
......
#
INCLUDES = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/bin/varnishd \
-I$(top_builddir)/include
vmoddir = $(pkglibdir)/vmods
vmod_srcdir = $(top_srcdir)/lib/libvmod_debug
vmodtool = $(top_srcdir)/lib/libvcl/vmodtool.py
vmod_LTLIBRARIES = libvmod_debug.la
libvmod_debug_la_LDFLAGS = -module -export-dynamic -avoid-version
libvmod_debug_la_SOURCES = \
vcc_if.c \
vcc_if.h \
vmod_debug.c
vcc_if.c vcc_if.h: $(vmodtool) $(vmod_srcdir)/vmod.vcc
@PYTHON@ $(vmodtool) $(vmod_srcdir)/vmod.vcc
EXTRA_DIST = vmod.vcc
CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h
#-
# Copyright (c) 2010-2011 Varnish Software AS
# All rights reserved.
#
# Author: Poul-Henning Kamp <phk@FreeBSD.org>
#
# 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.
Module debug
Init init_function
Function VOID panic(STRING_LIST)
Function STRING author(ENUM { phk, des, kristian, mithrandir })
Function VOID test_priv_call(PRIV_CALL)
Function VOID test_priv_vcl(PRIV_VCL)
/*-
* Copyright (c) 2012 Varnish Software AS
* All rights reserved.
*
* Author: Poul-Henning Kamp <phk@FreeBSD.org>
*
* 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 <stdlib.h>
#include "cache/cache.h"
#include "vrt.h"
#include "vcc_if.h"
void
vmod_panic(struct sess *sp, const char *str, ...)
{
va_list ap;
char *b;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
va_start(ap, str);
b = VRT_String(sp->req->http->ws, "PANIC: ", str, ap);
va_end(ap);
VAS_Fail("VCL", "", 0, b, 0, 2);
}
const char * __match_proto__()
vmod_author(struct sess *sp, const char *id)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
if (!strcmp(id, "phk"))
return ("Poul-Henning");
if (!strcmp(id, "des"))
return ("Dag-Erling");
if (!strcmp(id, "kristian"))
return ("Kristian");
if (!strcmp(id, "mithrandir"))
return ("Tollef");
WRONG("Illegal VMOD enum");
}
int
init_function(struct vmod_priv *priv, const struct VCL_conf *cfg)
{
(void)cfg;
priv->priv = strdup("FOO");
priv->free = free;
return (0);
}
void
vmod_test_priv_call(struct sess *sp, struct vmod_priv *priv)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
if (priv->priv == NULL) {
priv->priv = strdup("BAR");
priv->free = free;
} else {
assert(!strcmp(priv->priv, "BAR"));
}
}
void
vmod_test_priv_vcl(struct sess *sp, struct vmod_priv *priv)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
assert(!strcmp(priv->priv, "FOO"));
}
......@@ -26,15 +26,13 @@
# SUCH DAMAGE.
Module std
Init init_function
Function STRING toupper(PRIV_CALL, STRING_LIST)
Function STRING tolower(PRIV_VCL, STRING_LIST)
Function STRING toupper(STRING_LIST)
Function STRING tolower(STRING_LIST)
Function VOID set_ip_tos(INT)
Function REAL random(REAL, REAL)
Function VOID log(STRING_LIST)
Function VOID syslog(INT, STRING_LIST)
Function STRING fileread(PRIV_CALL, STRING)
Function STRING author(ENUM { phk, des, kristian, mithrandir })
Function DURATION duration(STRING, DURATION)
Function INT integer(STRING, INT)
Function VOID collect(HEADER)
......@@ -89,18 +89,12 @@ vmod_updown(struct sess *sp, int up, const char *s, va_list ap)
}
const char * __match_proto__()
vmod_toupper(struct sess *sp, struct vmod_priv *priv, const char *s, ...)
vmod_toupper(struct sess *sp, const char *s, ...)
{
const char *p;
va_list ap;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
if (priv->priv == NULL) {
priv->priv = strdup("BAR");
priv->free = free;
} else {
assert(!strcmp(priv->priv, "BAR"));
}
va_start(ap, s);
p = vmod_updown(sp, 1, s, ap);
va_end(ap);
......@@ -108,29 +102,18 @@ vmod_toupper(struct sess *sp, struct vmod_priv *priv, const char *s, ...)
}
const char * __match_proto__()
vmod_tolower(struct sess *sp, struct vmod_priv *priv, const char *s, ...)
vmod_tolower(struct sess *sp, const char *s, ...)
{
const char *p;
va_list ap;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
assert(!strcmp(priv->priv, "FOO"));
va_start(ap, s);
p = vmod_updown(sp, 0, s, ap);
va_end(ap);
return (p);
}
int
init_function(struct vmod_priv *priv, const struct VCL_conf *cfg)
{
(void)cfg;
priv->priv = strdup("FOO");
priv->free = free;
return (0);
}
double
vmod_random(struct sess *sp, double lo, double hi)
{
......@@ -181,21 +164,6 @@ vmod_syslog(struct sess *sp, int fac, const char *fmt, ...)
WS_Release(sp->req->ws, 0);
}
const char * __match_proto__()
vmod_author(struct sess *sp, const char *id)
{
(void)sp;
if (!strcmp(id, "phk"))
return ("Poul-Henning");
if (!strcmp(id, "des"))
return ("Dag-Erling");
if (!strcmp(id, "kristian"))
return ("Kristian");
if (!strcmp(id, "mithrandir"))
return ("Tollef");
WRONG("Illegal VMOD enum");
}
void __match_proto__()
vmod_collect(struct sess *sp, enum gethdr_e e, const char *h)
{
......
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