Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-file
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-file
Commits
8c9b7615
Commit
8c9b7615
authored
Feb 26, 2021
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the .id() method.
parent
fab4fff9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
2 deletions
+103
-2
README.rst
README.rst
+9
-2
info.vtc
src/tests/info.vtc
+34
-0
vmod_file.c
src/vmod_file.c
+56
-0
vmod_file.vcc
src/vmod_file.vcc
+4
-0
No files found.
README.rst
View file @
8c9b7615
..
.. NB: This file is machine generated, DO NOT EDIT!
..
.. Edit
vmod
.vcc and run make instead
.. Edit
./vmod_file
.vcc and run make instead
..
.. role:: ref(emphasis)
=========
VMOD
file
vmod_
file
=========
-----------------------------------------------------------------
...
...
@@ -452,6 +452,13 @@ Example::
set resp.http.Cache-Control = "public, max-age="
+ std.integer(duration=rdr.next_check());
.. _xreader.id():
BLOB xreader.id()
-----------------
XXX ...
.. _file.version():
STRING version()
...
...
src/tests/info.vtc
View file @
8c9b7615
...
...
@@ -178,3 +178,37 @@ client c1 {
expect resp.http.Error == "false"
expect resp.http.Deleted == "true"
} -run
shell {touch ${tmpdir}/id}
varnish v1 -vcl {
import ${vmod_file};
import blob;
backend b None;
sub vcl_init {
new rdr = file.reader("${tmpdir}/id", ttl=0.1s);
}
sub vcl_recv {
return (synth(200));
}
sub vcl_synth {
set resp.http.ETag = blob.encode(BASE64, blob=rdr.id());
return (deliver);
}
}
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.ETag ~ {^[[:alnum:]+/]+=*$}
} -run
shell {touch ${tmpdir}/id}
delay .1
# Check the log to verify that ETag changes.
client c1 -run
src/vmod_file.c
View file @
8c9b7615
...
...
@@ -58,6 +58,9 @@
/* Other VMODs may check the result of .blob() for this value, see vrt.h */
#define VMOD_FILE_BLOB_MAGIC 0x069392c4
/* For the result of .id() */
#define VMOD_FILE_ID_MAGIC 0x001122d7
#define INIT_SLEEP_INTERVAL 0.001
#define ERRMSG_LEN 128
#define NO_ERR ("No error")
...
...
@@ -663,6 +666,59 @@ vmod_reader_next_check(VRT_CTX, struct VPFX(file_reader) *rdr)
return
(
t
.
it_value
.
tv_sec
+
1e-9
*
t
.
it_value
.
tv_nsec
);
}
/*
* Note that the contents of the BLOB returned from .id() are
* undocumented, any may change in any new version.
*/
VCL_BLOB
vmod_reader_id
(
VRT_CTX
,
struct
VPFX
(
file_reader
)
*
rdr
)
{
time_t
secs
;
long
nsecs
;
dev_t
dev
;
ino_t
ino
;
uintptr_t
snap
;
struct
vrt_blob
*
blob
;
char
*
data
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
ctx
->
ws
,
WS_MAGIC
);
CHECK_OBJ_NOTNULL
(
rdr
,
FILE_READER_MAGIC
);
CHECK_OBJ_NOTNULL
(
rdr
->
info
,
FILE_INFO_MAGIC
);
AZ
(
pthread_rwlock_rdlock
(
&
rdr
->
lock
));
ERRCHK
(
ctx
,
rdr
,
"rdr"
,
NULL
);
secs
=
rdr
->
info
->
mtime
.
tv_sec
;
nsecs
=
rdr
->
info
->
mtime
.
tv_nsec
;
dev
=
rdr
->
info
->
dev
;
ino
=
rdr
->
info
->
ino
;
AZ
(
pthread_rwlock_unlock
(
&
rdr
->
lock
));
snap
=
WS_Snapshot
(
ctx
->
ws
);
if
((
blob
=
WS_Alloc
(
ctx
->
ws
,
sizeof
(
*
blob
)))
==
NULL
)
{
VFAIL
(
ctx
,
"%s.id(): insufficient workspace for blob structure"
,
rdr
->
obj_name
);
return
NULL
;
}
if
((
data
=
WS_Alloc
(
ctx
->
ws
,
sizeof
(
secs
)
+
sizeof
(
nsecs
)
+
sizeof
(
dev
)
+
sizeof
(
ino
)))
==
NULL
)
{
WS_Reset
(
ctx
->
ws
,
snap
);
VFAIL
(
ctx
,
"%s.id(): insufficient workspace for blob data"
,
rdr
->
obj_name
);
return
NULL
;
}
blob
->
type
=
VMOD_FILE_ID_MAGIC
;
blob
->
len
=
sizeof
(
secs
)
+
sizeof
(
nsecs
)
+
sizeof
(
dev
)
+
sizeof
(
ino
);
blob
->
blob
=
data
;
memcpy
(
data
,
&
secs
,
sizeof
(
secs
));
memcpy
(
data
+
sizeof
(
secs
),
&
nsecs
,
sizeof
(
nsecs
));
memcpy
(
data
+
sizeof
(
secs
)
+
sizeof
(
nsecs
),
&
dev
,
sizeof
(
dev
));
memcpy
(
data
+
sizeof
(
secs
)
+
sizeof
(
nsecs
)
+
sizeof
(
dev
),
&
ino
,
sizeof
(
ino
));
return
(
blob
);
}
VCL_STRING
vmod_version
(
VRT_CTX
)
{
...
...
src/vmod_file.vcc
View file @
8c9b7615
...
...
@@ -411,6 +411,10 @@ Example::
set resp.http.Cache-Control = "public, max-age="
+ std.integer(duration=rdr.next_check());
$Method BLOB .id()
XXX ...
$Function STRING version()
Return the version string for this VMOD.
...
...
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