Commit ce3f10b6 authored by Martin Blix Grydeland's avatar Martin Blix Grydeland

Rewrite the example to be a hello world vmod

parent 6506b603
......@@ -9,14 +9,14 @@ varnish v1 -vcl+backend {
import example from "${vmod_topbuild}/src/.libs/libvmod_example.so";
sub vcl_deliver {
set resp.http.val = example.abs(2-3);
set resp.http.hello = example.hello("World!");
}
} -start
client c1 {
txreq -url "/"
rxresp
expect resp.http.val == "1"
expect resp.http.hello == "Hello, World!"
}
client c1 -run
......@@ -11,8 +11,22 @@ init_function(struct vmod_priv *priv, const struct VCL_conf *conf)
return (0);
}
int
vmod_abs(struct sess *sp, int val)
const char *
vmod_hello(struct sess *sp, const char *name)
{
return (abs(val));
char *p;
unsigned u, v;
u = WS_Reserve(sp->wrk->ws, 0); /* Reserve some work space */
p = sp->wrk->ws->f; /* Front of workspace area */
v = snprintf(p, u, "Hello, %s", name);
v++;
if (v > u) {
/* No space, reset and leave */
WS_Release(sp->wrk->ws, 0);
return (NULL);
}
/* Update work space with what we've used */
WS_Release(sp->wrk->ws, v);
return (p);
}
Module example
Init init_function
Function INT abs(INT)
Function STRING hello(STRING)
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