Commit 37fc91f2 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Change the macro expansion syntax to ${foobar}, it's much easier to

parse.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4365 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 417e8502
......@@ -9,7 +9,7 @@ server s1 {
server s1 -start
client c1 -connect $s1_sock {
client c1 -connect ${s1_sock} {
txreq
rxresp
}
......
......@@ -12,7 +12,7 @@ server s1 {
server s1 -start
client c1 -connect $s1_sock {
client c1 -connect ${s1_sock} {
txreq
rxresp
expect resp.proto == HTTP/1.1
......
......@@ -12,7 +12,7 @@ server s1 {
server s1 -start
client c1 -connect $s1_sock {
client c1 -connect ${s1_sock} {
txreq -req PUT -proto HTTP/1.0 -url /foo
rxresp
expect resp.proto == HTTP/1.2
......
......@@ -21,7 +21,7 @@ server s2 {
server s1 -start
server s2 -start
client c1 -connect $s1_sock {
client c1 -connect ${s1_sock} {
txreq -req PUT -proto HTTP/1.0 -url /foo
rxresp
expect resp.proto == HTTP/1.2
......@@ -29,7 +29,7 @@ client c1 -connect $s1_sock {
expect resp.msg == Foo
}
client c2 -connect $s2_sock {
client c2 -connect ${s2_sock} {
txreq
rxresp
expect resp.proto == HTTP/1.1
......
......@@ -12,7 +12,7 @@ server s1 -repeat 2 {
server s1 -start
client c1 -connect $s1_sock {
client c1 -connect ${s1_sock} {
txreq -req PUT -proto HTTP/1.0 -url /foo
rxresp
expect resp.proto == HTTP/1.2
......@@ -20,7 +20,7 @@ client c1 -connect $s1_sock {
expect resp.msg == Foo
}
client c2 -connect $s1_sock {
client c2 -connect ${s1_sock} {
txreq -req PUT -proto HTTP/1.0 -url /foo
rxresp
expect resp.proto == HTTP/1.2
......
......@@ -21,7 +21,7 @@ server s2 {
server s1 -start
server s2 -start
client c1 -connect $s1_sock {
client c1 -connect ${s1_sock} {
txreq -req PUT -proto HTTP/1.0 -url /foo
rxresp
expect resp.proto == HTTP/1.2
......@@ -31,7 +31,7 @@ client c1 -connect $s1_sock {
client c1 -run
client c1 -connect $s2_sock {
client c1 -connect ${s2_sock} {
txreq
rxresp
expect resp.proto == HTTP/1.1
......
......@@ -13,7 +13,7 @@ server s1 {
server s1 -start
client c1 -connect $s1_sock {
client c1 -connect ${s1_sock} {
txreq -req PUT -proto HTTP/1.0 -url /foo \
-body "123456789\n"
rxresp
......
......@@ -13,7 +13,7 @@ server s1 {
server s1 -start
client c1 -connect $s1_sock {
client c1 -connect ${s1_sock} {
txreq -url "/1" -req "POST" -body "abcdefghi\n"
rxresp
txreq -url "/2" -req "POST" -body "ihgfedcba\n"
......
......@@ -23,21 +23,21 @@ server s3 {
txresp
} -start
client c1 -connect $s1_sock {
client c1 -connect ${s1_sock} {
delay .2
txreq
rxresp
sema r1 sync 4
} -start
client c2 -connect $s2_sock {
client c2 -connect ${s2_sock} {
delay .6
txreq
rxresp
sema r1 sync 4
} -start
client c3 -connect $s3_sock {
client c3 -connect ${s3_sock} {
delay .9
txreq
rxresp
......
......@@ -10,7 +10,7 @@ server s1 {
server s1 -start
client c1 -connect $s1_sock {
client c1 -connect ${s1_sock} {
txreq
rxresp
......
......@@ -136,6 +136,38 @@ macro_get(const char *name)
return (retval);
}
static struct vsb *
macro_expand(char *name)
{
struct vsb *vsb;
char *p, *q;
vsb = vsb_newauto();
AN(vsb);
while (*name != '\0') {
p = strstr(name, "${");
if (p == NULL) {
vsb_cat(vsb, name);
break;
}
vsb_bcat(vsb, name, p - name);
q = strchr(p, '}');
if (q == NULL) {
vsb_cat(vsb, name);
break;
}
assert(p[0] == '$');
assert(p[1] == '{');
assert(q[0] == '}');
p += 2;
*q = '\0';
vsb_cat(vsb, macro_get(p));
name = q + 1;
}
vsb_finish(vsb);
return (vsb);
}
/**********************************************************************
* Read a file into memory
*/
......@@ -174,6 +206,7 @@ void
parse_string(char *buf, const struct cmds *cmd, void *priv, struct vtclog *vl)
{
char *token_s[MAX_TOKENS], *token_e[MAX_TOKENS];
struct vsb *token_exp[MAX_TOKENS];
char *p, *q;
int nest_brace;
int tn;
......@@ -251,16 +284,14 @@ parse_string(char *buf, const struct cmds *cmd, void *priv, struct vtclog *vl)
assert(tn < MAX_TOKENS);
token_s[tn] = NULL;
for (tn = 0; token_s[tn] != NULL; tn++) {
token_exp[tn] = NULL;
AN(token_e[tn]); /*lint !e771 */
*token_e[tn] = '\0'; /*lint !e771 */
if (token_s[tn][0] == '$') {
q = macro_get(token_s[tn] + 1);
if (q == NULL)
vtc_log(vl, 0,
"Unknown macro: \"%s\"", token_s[tn]);
token_s[tn] = q;
token_e[tn] = strchr(token_s[tn], '\0');
}
if (NULL == strstr(token_s[tn], "${"))
continue;
token_exp[tn] = macro_expand(token_s[tn]);
token_s[tn] = vsb_data(token_exp[tn]);
token_e[tn] = strchr(token_s[tn], '\0');
}
for (cp = cmd; cp->name != NULL; cp++)
......
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