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