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

Commit ce3f10b

Browse files
committed
Rewrite the example to be a hello world vmod
1 parent 6506b60 commit ce3f10b

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

src/tests/test01.vtc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ varnish v1 -vcl+backend {
99
import example from "${vmod_topbuild}/src/.libs/libvmod_example.so";
1010

1111
sub vcl_deliver {
12-
set resp.http.val = example.abs(2-3);
12+
set resp.http.hello = example.hello("World!");
1313
}
1414
} -start
1515

1616
client c1 {
1717
txreq -url "/"
1818
rxresp
19-
expect resp.http.val == "1"
19+
expect resp.http.hello == "Hello, World!"
2020
}
2121

2222
client c1 -run

src/vmod_example.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,22 @@ init_function(struct vmod_priv *priv, const struct VCL_conf *conf)
1111
return (0);
1212
}
1313

14-
int
15-
vmod_abs(struct sess *sp, int val)
14+
const char *
15+
vmod_hello(struct sess *sp, const char *name)
1616
{
17-
return (abs(val));
17+
char *p;
18+
unsigned u, v;
19+
20+
u = WS_Reserve(sp->wrk->ws, 0); /* Reserve some work space */
21+
p = sp->wrk->ws->f; /* Front of workspace area */
22+
v = snprintf(p, u, "Hello, %s", name);
23+
v++;
24+
if (v > u) {
25+
/* No space, reset and leave */
26+
WS_Release(sp->wrk->ws, 0);
27+
return (NULL);
28+
}
29+
/* Update work space with what we've used */
30+
WS_Release(sp->wrk->ws, v);
31+
return (p);
1832
}

src/vmod_example.vcc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Module example
22
Init init_function
3-
Function INT abs(INT)
3+
Function STRING hello(STRING)

0 commit comments

Comments
 (0)