Commit 0d278dbd authored by Geoff Simmons's avatar Geoff Simmons

Add the vdp.arg() method.

parent b1dea62c
......@@ -65,6 +65,13 @@ new xvdp = pipe.vdp(STRING path, STRING name, BYTES bufsz)
XXX ...
.. _xvdp.arg():
VOID xvdp.arg(STRING)
---------------------
XXX ...
.. _pipe.version():
STRING version()
......
......@@ -23,6 +23,8 @@ AC_PROG_CPP
# To get absolute paths in the vtc tests.
AC_PATH_PROG([CAT], [cat], [])
AC_PATH_PROG([TR], [tr], [])
AC_PATH_PROG([SED], [sed], [])
AX_PTHREAD(,[AC_MSG_ERROR([Could not configure pthreads support])])
......
......@@ -29,7 +29,8 @@ AM_TESTS_ENVIRONMENT = \
LD_LIBRARY_PATH="$(VARNISH_LIBRARY_PATH)"
TEST_EXTENSIONS = .vtc
VTC_LOG_COMPILER = varnishtest -v
AM_VTC_LOG_FLAGS = -Dvmod_pipe="$(VMOD_PIPE)" -Dcat="$(CAT)"
AM_VTC_LOG_FLAGS = -Dvmod_pipe="$(VMOD_PIPE)" -Dcat="$(CAT)" -Dtr="$(TR)" \
-Dsed="$(SED)"
TESTS = @VMOD_TESTS@
# To test an individual VTC test named test.vtc:
......
# looks like -*- vcl -*-
varnishtest "vdp .arg() method"
server s1 {
rxreq
txresp -body {foo bar baz quux}
rxreq
txresp -body {Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.}
rxreq
txresp -body {Lorem ipsum dolor sit amet, leo ornare nulla, eu malesuada. Cras turpis pretium consectetuer mauris urna sodales, aliquet morbi malesuada potenti velit hendrerit, ut rhoncus lorem vitae neque sed, feugiat nec tellus gravida magna sit. Pretium ac massa arcu viverra, diam velit in aliqua adipiscing vehicula, aliquet iaculis a lobortis enim sit, ligula nisl ultricies, magna volutpat eros suspendisse massa. Ut mauris, purus mi arcu faucibus pretium elit. Pulvinar enim eu, et orci leo tortor parturient magna, commodo ut pellentesque, justo lorem vestibulum non lacinia odio. Consequatur diam volutpat.
Lacus donec libero venenatis venenatis, egestas pretium ut urna vehicula, ac eget ac, amet maecenas turpis viverra blandit. Ullamcorper massa sed in, nec velit nec aenean justo, nullam cras, ullamcorper eros pharetra magna urna metus, ultricies rutrum neque nunc eleifend. Pretium consequat leo in, amet varius integer, eros non et ut sit ac, magnis quis nibh dolor ornare sed. Turpis nec morbi, nunc a mauris faucibus molestie, dolor velit tincidunt, amet ac erat eros massa pede. Vitae venenatis volutpat eget vestibulum. In nam pharetra in vivamus pretium, nulla nunc sociosqu, aliquam nullam ligula, ut sed vestibulum quam morbi turpis mattis, wisi at per lorem aliquam ante sed. Mauris taciti ligula venenatis vehicula, morbi eget nec. Amet id sodales eos, diam suspendisse pulvinar, at vestibulum torquent nec eget risus est. Mauris sapien tortor eget nesciunt.
Ridiculus congue erat velit, nulla felis, viverra non tempor cum nulla, quis quisque enim at sociosqu vestibulum sit. Donec molestie. Cursus pretium donec phasellus lacinia velit nulla, quis sapien dapibus suscipit viverra magni commodo, viverra vel eros lectus tristique lorem vivamus. Tortor mi ante, aut elit, metus ante voluptatem nisl aenean eget amet, felis at et. Posuere lorem ridiculus, et leo viverra pellentesque neque, ullamcorper neque volutpat pretium amet laoreet. Sapien at, phasellus ullamco wisi, arcu fermentum fringilla nam turpis mi. Congue et donec rutrum, voluptatem et duis neque eget elit. Mus sit luctus est, nullam fringilla magna vel massa, vivamus vel adipiscing quis dolor quam. Risus laoreet consequat fusce suspendisse vitae, felis aliquet.
Enim per accumsan, augue id maecenas bibendum ullamcorper in fermentum, platea fermentum. Convallis pulvinar tortor eros sit cras nascetur, quam dis elit sed aliquam ac, nulla morbi suscipit egestas placerat pretium. Vehicula elementum duis, turpis wisi nascetur velit. Senectus aenean ipsum blandit, eleifend leo donec nunc, ut vel sagittis sed nam, ut aliquam quam aliquam at tellus. Vivamus donec libero feugiat amet gravida, felis id aliquam nullam consequat, aut eget suspendisse rutrum in. Orci tellus. A sapien scelerisque diam, ornare laoreet lobortis blandit in. Aliquam at suscipit, id risus. Leo lacus quam mollis erat morbi vel, ut adipiscing cillum dui. Elit bibendum tristique et non eros libero, egestas lectus turpis, quis gravida dolor volutpat, purus eu, consectetuer pharetra per vehicula quam tellus.}
} -start
varnish v1 -vcl+backend {
import ${vmod_pipe};
sub vcl_init {
new rot13 = pipe.vdp(path="${tr}");
rot13.arg("A-Za-z");
rot13.arg("N-ZA-Mn-za-m");
}
sub vcl_backend_response {
set beresp.uncacheable = true;
}
sub vcl_deliver {
set resp.filters = "rot13";
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.body == "sbb one onm dhhk"
txreq
rxresp
expect resp.status == 200
expect resp.body == {Zna vf qvfgvathvfurq, abg bayl ol uvf ernfba, ohg ol guvf fvathyne cnffvba sebz bgure navznyf, juvpu vf n yhfg bs gur zvaq, gung ol n crefrirenapr bs qryvtug va gur pbagvahrq naq vaqrsngvtnoyr trarengvba bs xabjyrqtr, rkprrqf gur fubeg irurzrapr bs nal pneany cyrnfher.}
txreq
rxresp
expect resp.status == 200
expect resp.body == {Yberz vcfhz qbybe fvg nzrg, yrb beaner ahyyn, rh znyrfhnqn. Penf ghecvf cergvhz pbafrpgrghre znhevf hean fbqnyrf, nyvdhrg zbeov znyrfhnqn cbgragv iryvg uraqerevg, hg eubaphf yberz ivgnr ardhr frq, srhtvng arp gryyhf tenivqn zntan fvg. Cergvhz np znffn neph ivireen, qvnz iryvg va nyvdhn nqvcvfpvat iruvphyn, nyvdhrg vnphyvf n ybobegvf ravz fvg, yvthyn avfy hygevpvrf, zntan ibyhgcng rebf fhfcraqvffr znffn. Hg znhevf, chehf zv neph snhpvohf cergvhz ryvg. Chyivane ravz rh, rg bepv yrb gbegbe cneghevrag zntan, pbzzbqb hg cryyragrfdhr, whfgb yberz irfgvohyhz aba ynpvavn bqvb. Pbafrdhnghe qvnz ibyhgcng.
Ynphf qbarp yvoreb irarangvf irarangvf, rtrfgnf cergvhz hg hean iruvphyn, np rtrg np, nzrg znrpranf ghecvf ivireen oynaqvg. Hyynzpbecre znffn frq va, arp iryvg arp nrarna whfgb, ahyynz penf, hyynzpbecre rebf cunergen zntan hean zrghf, hygevpvrf ehgehz ardhr ahap ryrvsraq. Cergvhz pbafrdhng yrb va, nzrg inevhf vagrtre, rebf aba rg hg fvg np, zntavf dhvf avou qbybe beaner frq. Ghecvf arp zbeov, ahap n znhevf snhpvohf zbyrfgvr, qbybe iryvg gvapvqhag, nzrg np reng rebf znffn crqr. Ivgnr irarangvf ibyhgcng rtrg irfgvohyhz. Va anz cunergen va ivinzhf cergvhz, ahyyn ahap fbpvbfdh, nyvdhnz ahyynz yvthyn, hg frq irfgvohyhz dhnz zbeov ghecvf znggvf, jvfv ng cre yberz nyvdhnz nagr frq. Znhevf gnpvgv yvthyn irarangvf iruvphyn, zbeov rtrg arp. Nzrg vq fbqnyrf rbf, qvnz fhfcraqvffr chyivane, ng irfgvohyhz gbedhrag arp rtrg evfhf rfg. Znhevf fncvra gbegbe rtrg arfpvhag.
Evqvphyhf pbathr reng iryvg, ahyyn sryvf, ivireen aba grzcbe phz ahyyn, dhvf dhvfdhr ravz ng fbpvbfdh irfgvohyhz fvg. Qbarp zbyrfgvr. Phefhf cergvhz qbarp cunfryyhf ynpvavn iryvg ahyyn, dhvf fncvra qncvohf fhfpvcvg ivireen zntav pbzzbqb, ivireen iry rebf yrpghf gevfgvdhr yberz ivinzhf. Gbegbe zv nagr, nhg ryvg, zrghf nagr ibyhcgngrz avfy nrarna rtrg nzrg, sryvf ng rg. Cbfhrer yberz evqvphyhf, rg yrb ivireen cryyragrfdhr ardhr, hyynzpbecre ardhr ibyhgcng cergvhz nzrg ynberrg. Fncvra ng, cunfryyhf hyynzpb jvfv, neph srezraghz sevatvyyn anz ghecvf zv. Pbathr rg qbarp ehgehz, ibyhcgngrz rg qhvf ardhr rtrg ryvg. Zhf fvg yhpghf rfg, ahyynz sevatvyyn zntan iry znffn, ivinzhf iry nqvcvfpvat dhvf qbybe dhnz. Evfhf ynberrg pbafrdhng shfpr fhfcraqvffr ivgnr, sryvf nyvdhrg.
Ravz cre npphzfna, nhthr vq znrpranf ovoraqhz hyynzpbecre va srezraghz, cyngrn srezraghz. Pbainyyvf chyivane gbegbe rebf fvg penf anfprghe, dhnz qvf ryvg frq nyvdhnz np, ahyyn zbeov fhfpvcvg rtrfgnf cynpreng cergvhz. Iruvphyn ryrzraghz qhvf, ghecvf jvfv anfprghe iryvg. Frarpghf nrarna vcfhz oynaqvg, ryrvsraq yrb qbarp ahap, hg iry fntvggvf frq anz, hg nyvdhnz dhnz nyvdhnz ng gryyhf. Ivinzhf qbarp yvoreb srhtvng nzrg tenivqn, sryvf vq nyvdhnz ahyynz pbafrdhng, nhg rtrg fhfcraqvffr ehgehz va. Bepv gryyhf. N fncvra fpryrevfdhr qvnz, beaner ynberrg ybobegvf oynaqvg va. Nyvdhnz ng fhfpvcvg, vq evfhf. Yrb ynphf dhnz zbyyvf reng zbeov iry, hg nqvcvfpvat pvyyhz qhv. Ryvg ovoraqhz gevfgvdhr rg aba rebf yvoreb, rtrfgnf yrpghf ghecvf, dhvf tenivqn qbybe ibyhgcng, chehf rh, pbafrpgrghre cunergen cre iruvphyn dhnz gryyhf.}
} -run
server s1 -wait
server s1 -start
varnish v1 -vcl+backend {
import ${vmod_pipe};
sub vcl_init {
new upcaseA = pipe.vdp(path="${sed}");
upcaseA.arg("-e");
upcaseA.arg("s/a/A/g");
}
sub vcl_backend_response {
set beresp.uncacheable = true;
}
sub vcl_deliver {
set resp.filters = "upcaseA";
}
}
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.body == "foo bAr bAz quux"
txreq
rxresp
expect resp.status == 200
expect resp.body == {MAn is distinguished, not only by his reAson, but by this singulAr pAssion from other AnimAls, which is A lust of the mind, thAt by A perseverAnce of delight in the continued And indefAtigAble generAtion of knowledge, exceeds the short vehemence of Any cArnAl pleAsure.}
txreq
rxresp
expect resp.status == 200
expect resp.body == {Lorem ipsum dolor sit Amet, leo ornAre nullA, eu mAlesuAdA. CrAs turpis pretium consectetuer mAuris urnA sodAles, Aliquet morbi mAlesuAdA potenti velit hendrerit, ut rhoncus lorem vitAe neque sed, feugiAt nec tellus grAvidA mAgnA sit. Pretium Ac mAssA Arcu viverrA, diAm velit in AliquA Adipiscing vehiculA, Aliquet iAculis A lobortis enim sit, ligulA nisl ultricies, mAgnA volutpAt eros suspendisse mAssA. Ut mAuris, purus mi Arcu fAucibus pretium elit. PulvinAr enim eu, et orci leo tortor pArturient mAgnA, commodo ut pellentesque, justo lorem vestibulum non lAciniA odio. ConsequAtur diAm volutpAt.
LAcus donec libero venenAtis venenAtis, egestAs pretium ut urnA vehiculA, Ac eget Ac, Amet mAecenAs turpis viverrA blAndit. UllAmcorper mAssA sed in, nec velit nec AeneAn justo, nullAm crAs, ullAmcorper eros phAretrA mAgnA urnA metus, ultricies rutrum neque nunc eleifend. Pretium consequAt leo in, Amet vArius integer, eros non et ut sit Ac, mAgnis quis nibh dolor ornAre sed. Turpis nec morbi, nunc A mAuris fAucibus molestie, dolor velit tincidunt, Amet Ac erAt eros mAssA pede. VitAe venenAtis volutpAt eget vestibulum. In nAm phAretrA in vivAmus pretium, nullA nunc sociosqu, AliquAm nullAm ligulA, ut sed vestibulum quAm morbi turpis mAttis, wisi At per lorem AliquAm Ante sed. MAuris tAciti ligulA venenAtis vehiculA, morbi eget nec. Amet id sodAles eos, diAm suspendisse pulvinAr, At vestibulum torquent nec eget risus est. MAuris sApien tortor eget nesciunt.
Ridiculus congue erAt velit, nullA felis, viverrA non tempor cum nullA, quis quisque enim At sociosqu vestibulum sit. Donec molestie. Cursus pretium donec phAsellus lAciniA velit nullA, quis sApien dApibus suscipit viverrA mAgni commodo, viverrA vel eros lectus tristique lorem vivAmus. Tortor mi Ante, Aut elit, metus Ante voluptAtem nisl AeneAn eget Amet, felis At et. Posuere lorem ridiculus, et leo viverrA pellentesque neque, ullAmcorper neque volutpAt pretium Amet lAoreet. SApien At, phAsellus ullAmco wisi, Arcu fermentum fringillA nAm turpis mi. Congue et donec rutrum, voluptAtem et duis neque eget elit. Mus sit luctus est, nullAm fringillA mAgnA vel mAssA, vivAmus vel Adipiscing quis dolor quAm. Risus lAoreet consequAt fusce suspendisse vitAe, felis Aliquet.
Enim per AccumsAn, Augue id mAecenAs bibendum ullAmcorper in fermentum, plAteA fermentum. ConvAllis pulvinAr tortor eros sit crAs nAscetur, quAm dis elit sed AliquAm Ac, nullA morbi suscipit egestAs plAcerAt pretium. VehiculA elementum duis, turpis wisi nAscetur velit. Senectus AeneAn ipsum blAndit, eleifend leo donec nunc, ut vel sAgittis sed nAm, ut AliquAm quAm AliquAm At tellus. VivAmus donec libero feugiAt Amet grAvidA, felis id AliquAm nullAm consequAt, Aut eget suspendisse rutrum in. Orci tellus. A sApien scelerisque diAm, ornAre lAoreet lobortis blAndit in. AliquAm At suscipit, id risus. Leo lAcus quAm mollis erAt morbi vel, ut Adipiscing cillum dui. Elit bibendum tristique et non eros libero, egestAs lectus turpis, quis grAvidA dolor volutpAt, purus eu, consectetuer phAretrA per vehiculA quAm tellus.}
} -run
varnish v1 -vcl { backend b None; }
# Tests oject finalization, freeing argv
varnish v1 -cli "vcl.discard vcl1"
varnish v1 -cli "vcl.discard vcl2"
varnish v1 -cli "vcl.list"
......@@ -68,7 +68,9 @@ struct VPFX(pipe_vdp) {
char *name;
char *path;
struct vdp *vdp;
char **argv;
size_t bufsz;
int argc;
};
struct vdp_map {
......@@ -205,7 +207,6 @@ vdp_init(struct req *req, void **priv)
if (state->chldpid == 0) {
char *envp[] = { NULL };
char *argv[2];
close(STDIN_FILENO);
close(STDOUT_FILENO);
......@@ -220,10 +221,8 @@ vdp_init(struct req *req, void **priv)
if (mk_dup(err[1], STDERR_FILENO, obj->name, req->vsl) != 0)
exit(EXIT_FAILURE);
argv[0] = obj->path;
argv[1] = NULL;
errno = 0;
if (execve(obj->path, argv, envp) == -1) {
if (execve(obj->path, obj->argv, envp) == -1) {
VSLb(req->vsl, SLT_Error, "vdfp_pipe: vdp %s: cannot "
"exec %s: %s", obj->name, obj->path,
vstrerror(errno));
......@@ -585,6 +584,17 @@ vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name,
map->obj = vdp_obj;
AZ(VRBT_INSERT(vdp_tree, &tree_h, map));
errno = 0;
vdp_obj->argv = malloc(2 * sizeof(*vdp_obj->argv));
if (vdp_obj->argv == NULL) {
VDPFAIL(ctx, "new %s: cannot allocate argv: %s", obj_name,
vstrerror(errno));
return;
}
vdp_obj->argv[0] = vdp_obj->path;
vdp_obj->argv[1] = NULL;
vdp_obj->argc = 1;
return;
}
......@@ -602,9 +612,40 @@ vmod_vdp__fini(struct VPFX(pipe_vdp) **vdpp)
free(vdp_obj->name);
if (vdp_obj->path != NULL)
free(vdp_obj->path);
if (vdp_obj->argv != NULL) {
for (int i = 1; vdp_obj->argv[i] != NULL; i++)
free(vdp_obj->argv[i]);
free(vdp_obj->argv);
}
FREE_OBJ(vdp_obj);
}
/* XXX currently only for vcl_init */
VCL_VOID
vmod_vdp_arg(VRT_CTX, struct VPFX(pipe_vdp) *obj, VCL_STRING arg)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(obj, PIPE_VDP_MAGIC);
if (arg == NULL) {
VDPFAIL(ctx, "%s.arg(): arg is NULL", obj->name);
return;
}
errno = 0;
obj->argv = realloc(obj->argv, (obj->argc + 2) * sizeof(*obj->argv));
if (obj->argv == NULL) {
VDPFAIL(ctx, "%s.arg(): cannot re-allocate argv: %s",
obj->name, vstrerror(errno));
return;
}
obj->argv[obj->argc] = strdup(arg);
obj->argv[obj->argc + 1] = NULL;
obj->argc++;
return;
}
VCL_STRING
vmod_version(VRT_CTX)
{
......
......@@ -54,6 +54,10 @@ $Object vdp(STRING path, STRING name=0, BYTES bufsz=0)
XXX ...
$Method VOID .arg(STRING)
XXX ...
$Function STRING version()
Return the version string for this library.
......
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