Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-weightadjust
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-weightadjust
Commits
680baec9
Commit
680baec9
authored
Aug 26, 2016
by
Nils Goroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update $Init to $Event and add a usage example
parent
5171433e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
3 deletions
+71
-3
test01.vtc
src/tests/test01.vtc
+14
-0
vmod_example.c
src/vmod_example.c
+51
-2
vmod_example.vcc
src/vmod_example.vcc
+6
-1
No files found.
src/tests/test01.vtc
View file @
680baec9
...
@@ -6,17 +6,31 @@ server s1 {
...
@@ -6,17 +6,31 @@ server s1 {
} -start
} -start
varnish v1 -vcl+backend {
varnish v1 -vcl+backend {
import std;
import example from "${vmod_topbuild}/src/.libs/libvmod_example.so";
import example from "${vmod_topbuild}/src/.libs/libvmod_example.so";
sub vcl_init {
std.log(example.info());
}
sub vcl_deliver {
sub vcl_deliver {
set resp.http.hello = example.hello("World");
set resp.http.hello = example.hello("World");
set resp.http.info = example.info();
}
}
} -start
} -start
logexpect l1 -v v1 -g raw -d 1 {
expect 0 0 CLI {^Rd vcl.load}
expect 0 = VCL_Log {^vmod_example loaded at }
} -start
client c1 {
client c1 {
txreq -url "/"
txreq -url "/"
rxresp
rxresp
expect resp.http.hello == "Hello, World"
expect resp.http.hello == "Hello, World"
expect resp.http.info ~ "^vmod_example warmed at "
}
}
client c1 -run
client c1 -run
logexpect l1 -wait
src/vmod_example.c
View file @
680baec9
...
@@ -3,17 +3,66 @@
...
@@ -3,17 +3,66 @@
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
/* need vcl.h before vrt.h for vmod_evet_f typedef */
#include "vcl.h"
#include "vrt.h"
#include "vrt.h"
#include "cache/cache.h"
#include "cache/cache.h"
#include "vtim.h"
#include "vcc_if.h"
#include "vcc_if.h"
int
const
size_t
infosz
=
64
;
init_function
(
struct
vmod_priv
*
priv
,
const
struct
VCL_conf
*
conf
)
char
*
info
;
/*
* handle vmod internal state, vmod init/fini and/or varnish callback
* (un)registration here.
*
* malloc'ing the info buffer is only indended as a demonstration, for any
* real-world vmod, a fixed-sized buffer should be a global variable
*/
int
__match_proto__
(
vmod_event_f
)
event_function
(
VRT_CTX
,
struct
vmod_priv
*
priv
,
enum
vcl_event_e
e
)
{
{
char
ts
[
VTIM_FORMAT_SIZE
];
const
char
*
event
=
NULL
;
(
void
)
priv
;
switch
(
e
)
{
case
VCL_EVENT_LOAD
:
info
=
malloc
(
infosz
);
if
(
!
info
)
return
(
-
1
);
event
=
"loaded"
;
break
;
case
VCL_EVENT_WARM
:
event
=
"warmed"
;
break
;
case
VCL_EVENT_COLD
:
event
=
"cooled"
;
break
;
case
VCL_EVENT_DISCARD
:
free
(
info
);
return
(
0
);
break
;
default:
return
(
0
);
}
AN
(
event
);
VTIM_format
(
VTIM_real
(),
ts
);
snprintf
(
info
,
infosz
,
"vmod_example %s at %s"
,
event
,
ts
);
return
(
0
);
return
(
0
);
}
}
VCL_STRING
vmod_info
(
VRT_CTX
)
{
return
(
info
);
}
VCL_STRING
VCL_STRING
vmod_hello
(
const
struct
vrt_ctx
*
ctx
,
VCL_STRING
name
)
vmod_hello
(
const
struct
vrt_ctx
*
ctx
,
VCL_STRING
name
)
{
{
...
...
src/vmod_example.vcc
View file @
680baec9
...
@@ -20,7 +20,12 @@ You can even have links and lists in here:
...
@@ -20,7 +20,12 @@ You can even have links and lists in here:
The init-function declared next does not have documentation.
The init-function declared next does not have documentation.
$Init init_function
$Event event_function
$Function STRING info()
Returns a string set by the last VCL event, demonstrating the use of
event functions.
$Function STRING hello(STRING)
$Function STRING hello(STRING)
The different functions provided by the VMOD should also have their own
The different functions provided by the VMOD should also have their own
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment