Commit bc13d834 authored by Nils Goroll's avatar Nils Goroll

vmodtool.py: support default value also for the last argument

closes #1976
parent dbfb06d4
...@@ -22,12 +22,12 @@ client c1 { ...@@ -22,12 +22,12 @@ client c1 {
txreq txreq
rxresp rxresp
expect resp.bodylen == "6" expect resp.bodylen == "6"
expect resp.http.foo1 == "1 2 3 ," expect resp.http.foo1 == "1 2 3 , 4"
expect resp.http.foo2 == "1 2 3 ," expect resp.http.foo2 == "1 2 3 , 4"
expect resp.http.foo3 == "1 2 3 ," expect resp.http.foo3 == "1 2 3 , 4"
expect resp.http.foo4 == "1 2 3 ," expect resp.http.foo4 == "1 2 3 , 4"
expect resp.http.foo5 == "1 2 3 ," expect resp.http.foo5 == "1 2 3 , 4"
expect resp.http.foo6 == "1 2 3 ," expect resp.http.foo6 == "1 2 3 , 4"
} -run } -run
delay .1 delay .1
...@@ -48,10 +48,10 @@ varnish v1 -errvcl {Argument 'one' missing} { ...@@ -48,10 +48,10 @@ varnish v1 -errvcl {Argument 'one' missing} {
} }
} }
varnish v1 -errvcl {Unknown argument 'four'} { varnish v1 -errvcl {Unknown argument 'five'} {
import debug; import debug;
backend b1 {.host = "127.0.0.1";} backend b1 {.host = "127.0.0.1";}
sub vcl_deliver { sub vcl_deliver {
set resp.http.foo5 = debug.argtest("1", two=2.0, four="3"); set resp.http.foo5 = debug.argtest("1", two=2.0, five="3");
} }
} }
...@@ -235,7 +235,9 @@ def arg(txt): ...@@ -235,7 +235,9 @@ def arg(txt):
i = s.find('=') i = s.find('=')
j = s.find(',') j = s.find(',')
if j >= 0 and j < i: if j < 0:
j = len(s)
if j < i:
i = -1 i = -1
if i < 0: if i < 0:
i = s.find(',') i = s.find(',')
...@@ -255,11 +257,14 @@ def arg(txt): ...@@ -255,11 +257,14 @@ def arg(txt):
s = s[m.end():] s = s[m.end():]
else: else:
i = s.find(',') i = s.find(',')
if i < 0:
i = len(s)
a.defval = s[:i] a.defval = s[:i]
s = s[i:] s = s[i:]
return a,s return a,s
# XXX cant have ( or ) in an argument default value
class prototype(object): class prototype(object):
def __init__(self, st, retval=True, prefix=""): def __init__(self, st, retval=True, prefix=""):
l = st.line[1] l = st.line[1]
......
...@@ -95,7 +95,7 @@ Encrypt the HTTP header with quad-ROT13 encryption, ...@@ -95,7 +95,7 @@ Encrypt the HTTP header with quad-ROT13 encryption,
(this is approx 33% better than triple-DES). (this is approx 33% better than triple-DES).
$Function STRING argtest(STRING one, REAL two=2, STRING three="3", $Function STRING argtest(STRING one, REAL two=2, STRING three="3",
STRING comma=",") STRING comma=",", INT four=4)
$Function INT vre_limit() $Function INT vre_limit()
......
...@@ -186,11 +186,11 @@ vmod_rot52(VRT_CTX, VCL_HTTP hp) ...@@ -186,11 +186,11 @@ vmod_rot52(VRT_CTX, VCL_HTTP hp)
VCL_STRING VCL_STRING
vmod_argtest(VRT_CTX, VCL_STRING one, VCL_REAL two, VCL_STRING three, vmod_argtest(VRT_CTX, VCL_STRING one, VCL_REAL two, VCL_STRING three,
VCL_STRING comma) VCL_STRING comma, VCL_INT four)
{ {
char buf[100]; char buf[100];
bprintf(buf, "%s %g %s %s", one, two, three, comma); bprintf(buf, "%s %g %s %s %ld", one, two, three, comma, four);
return (WS_Copy(ctx->ws, buf, -1)); return (WS_Copy(ctx->ws, buf, -1));
} }
......
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