Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit ee2a24f

Browse files
committed
Merge pull request #1 from daghf/varn-4.0
Migrate to Varnish 4.0
2 parents 1efe2b3 + efb5d03 commit ee2a24f

File tree

5 files changed

+32
-52
lines changed

5 files changed

+32
-52
lines changed

configure.ac

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,13 @@ AC_CHECK_HEADERS([sys/stdlib.h])
3939
# Check for python
4040
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.])])
4141

42-
# Varnish source tree
43-
AC_ARG_VAR([VARNISHSRC], [path to Varnish source tree (mandatory)])
44-
if test "x$VARNISHSRC" = x; then
45-
AC_MSG_ERROR([No Varnish source tree specified])
46-
fi
47-
VARNISHSRC=`cd $VARNISHSRC && pwd`
48-
AC_CHECK_FILE([$VARNISHSRC/include/varnishapi.h],
49-
[],
50-
[AC_MSG_FAILURE(["$VARNISHSRC" is not a Varnish source directory])]
51-
)
52-
53-
# Check that varnishtest is built in the varnish source directory
54-
AC_CHECK_FILE([$VARNISHSRC/bin/varnishtest/varnishtest],
55-
[],
56-
[AC_MSG_FAILURE([Can't find "$VARNISHSRC/bin/varnishtest/varnishtest". Please build your varnish source directory])]
57-
)
42+
# Varnish include files tree
43+
VARNISH_VMOD_INCLUDES
44+
VARNISH_VMOD_DIR
45+
VARNISH_VMODTOOL
5846

59-
# vmod installation dir
60-
AC_ARG_VAR([VMODDIR], [vmod installation directory @<:@LIBDIR/varnish/vmods@:>@])
61-
if test "x$VMODDIR" = x; then
62-
VMODDIR=`pkg-config --variable=vmoddir varnishapi`
63-
if test "x$VMODDIR" = x; then
64-
AC_MSG_FAILURE([Can't determine vmod installation directory])
65-
fi
66-
fi
47+
AC_PATH_PROG([VARNISHTEST], [varnishtest])
48+
AC_PATH_PROG([VARNISHD], [varnishd])
6749

6850
AC_CONFIG_FILES([
6951
Makefile

src/Makefile.am

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
INCLUDES = -I$(VARNISHSRC)/include -I$(VARNISHSRC)
1+
AM_CPPFLAGS = @VMOD_INCLUDES@
22

3-
vmoddir = $(VMODDIR)
3+
vmoddir = @VMOD_DIR@
44
vmod_LTLIBRARIES = libvmod_urlcode.la
55

66
libvmod_urlcode_la_LDFLAGS = -module -export-dynamic -avoid-version
@@ -10,14 +10,14 @@ libvmod_urlcode_la_SOURCES = \
1010
vcc_if.h \
1111
vmod_urlcode.c
1212

13-
vcc_if.c vcc_if.h: $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod_urlcode.vcc
14-
@PYTHON@ $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod_urlcode.vcc
13+
vcc_if.c vcc_if.h: @VMODTOOL@ $(top_srcdir)/src/vmod_urlcode.vcc
14+
@VMODTOOL@ $(top_srcdir)/src/vmod_urlcode.vcc
1515

1616
VMOD_TESTS = tests/*.vtc
1717
.PHONY: $(VMOD_TESTS)
1818

1919
tests/*.vtc:
20-
$(VARNISHSRC)/bin/varnishtest/varnishtest -Dvarnishd=$(VARNISHSRC)/bin/varnishd/varnishd -Dvmod_topbuild=$(abs_top_builddir) $@
20+
@VARNISHTEST@ -Dvarnishd=@VARNISHD@ -Dvmod_topbuild=$(abs_top_builddir) $@
2121

2222
check: $(VMOD_TESTS)
2323

src/tests/urlcode01.vtc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ server s1 {
1717
varnish v1 -vcl+backend {
1818
import urlcode from "${vmod_topbuild}/src/.libs/libvmod_urlcode.so";
1919

20-
sub vcl_fetch {
20+
sub vcl_backend_response {
2121
set beresp.http.Bar1 = urlcode.encode(beresp.http.Foo1);
2222
set beresp.http.Baz1 = urlcode.decode(beresp.http.Bar1);
2323
set beresp.http.Bar2 = urlcode.encode(beresp.http.Foo2);

src/vmod_urlcode.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <stdlib.h>
22

33
#include "vrt.h"
4-
#include "bin/varnishd/cache.h"
4+
#include "cache/cache.h"
55

66
#include "vcc_if.h"
77

@@ -12,17 +12,16 @@ static char hexchars[] = "0123456789ABCDEF";
1212
((c >= '0' && c <= '9') || visalpha(c))
1313

1414
const char *
15-
vmod_encode(struct sess *sp, const char *str, ...)
15+
vmod_encode(const struct vrt_ctx *ctx, const char *str, ...)
1616
{
1717
char *b, *e;
1818
unsigned u;
1919
va_list ap;
2020

21-
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
22-
CHECK_OBJ_NOTNULL(sp->http, HTTP_MAGIC);
23-
CHECK_OBJ_NOTNULL(sp->http->ws, WS_MAGIC);
24-
u = WS_Reserve(sp->http->ws, 0);
25-
e = b = sp->http->ws->f;
21+
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
22+
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
23+
u = WS_Reserve(ctx->ws, 0);
24+
e = b = ctx->ws->f;
2625
e += u;
2726
va_start(ap, str);
2827
while (b < e && str != vrt_magic_string_end) {
@@ -46,12 +45,12 @@ vmod_encode(struct sess *sp, const char *str, ...)
4645
*b = '\0';
4746
b++;
4847
if (b > e) {
49-
WS_Release(sp->http->ws, 0);
48+
WS_Release(ctx->ws, 0);
5049
return (NULL);
5150
} else {
5251
e = b;
53-
b = sp->http->ws->f;
54-
WS_Release(sp->http->ws, e - b);
52+
b = ctx->ws->f;
53+
WS_Release(ctx->ws, e - b);
5554
return (b);
5655
}
5756
}
@@ -69,19 +68,18 @@ vmod_hex_to_int(char c)
6968
}
7069

7170
const char *
72-
vmod_decode(struct sess *sp, const char *str, ...)
71+
vmod_decode(const struct vrt_ctx *ctx, const char *str, ...)
7372
{
7473
char *b, *e;
7574
int h, l;
7675
unsigned u;
7776
va_list ap;
7877
int percent = 0;
7978

80-
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
81-
CHECK_OBJ_NOTNULL(sp->http, HTTP_MAGIC);
82-
CHECK_OBJ_NOTNULL(sp->http->ws, WS_MAGIC);
83-
u = WS_Reserve(sp->http->ws, 0);
84-
e = b = sp->http->ws->f;
79+
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
80+
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
81+
u = WS_Reserve(ctx->ws, 0);
82+
e = b = ctx->ws->f;
8583
e += u;
8684
va_start(ap, str);
8785
while (b < e && str != vrt_magic_string_end) {
@@ -118,12 +116,12 @@ vmod_decode(struct sess *sp, const char *str, ...)
118116
*b = '\0';
119117
b++;
120118
if (b > e) {
121-
WS_Release(sp->http->ws, 0);
119+
WS_Release(ctx->ws, 0);
122120
return (NULL);
123121
} else {
124122
e = b;
125-
b = sp->http->ws->f;
126-
WS_Release(sp->http->ws, e - b);
123+
b = ctx->ws->f;
124+
WS_Release(ctx->ws, e - b);
127125
return (b);
128126
}
129127
}

src/vmod_urlcode.vcc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Module urlcode
2-
Function STRING encode(STRING_LIST)
3-
Function STRING decode(STRING_LIST)
1+
$Module urlcode 3 urlencode/urldecode functions vmod
2+
$Function STRING encode(STRING_LIST)
3+
$Function STRING decode(STRING_LIST)

0 commit comments

Comments
 (0)