Commit bf6fcc45 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Introduce STRING_LIST type so we don't needlessly assemble strings on

the thrad workspace.

Fix multiplication.

Cleanup indentation in C-source output




git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5134 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 901d2e06
...@@ -1007,15 +1007,10 @@ VRT_synth_page(struct sess *sp, unsigned flags, const char *str, ...) ...@@ -1007,15 +1007,10 @@ VRT_synth_page(struct sess *sp, unsigned flags, const char *str, ...)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
void void
VRT_log(struct sess *sp, const char *str, ...) VRT_log(struct sess *sp, const char *str)
{ {
va_list ap;
char *b;
va_start(ap, str); WSP(sp, SLT_VCL_Log, "%s", str);
b = vrt_assemble_string(sp->http, NULL, str, ap);
va_end(ap);
WSP(sp, SLT_VCL_Log, "%s", b);
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
...@@ -1056,22 +1051,16 @@ VRT_ban(struct sess *sp, char *cmds, ...) ...@@ -1056,22 +1051,16 @@ VRT_ban(struct sess *sp, char *cmds, ...)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
void void
VRT_ban_string(struct sess *sp, const char *str, ...) VRT_ban_string(struct sess *sp, const char *str)
{ {
char *p, *a1, *a2, *a3; char *a1, *a2, *a3;
char **av; char **av;
va_list ap;
struct ban *b; struct ban *b;
int good; int good;
int i; int i;
va_start(ap, str); (void)sp;
p = vrt_assemble_string(sp->http, NULL, str, ap); av = ParseArgv(str, 0);
if (p == NULL)
/* XXX: report error how ? */
return;
av = ParseArgv(p, 0);
if (av[0] != NULL) { if (av[0] != NULL) {
/* XXX: report error how ? */ /* XXX: report error how ? */
FreeArgv(av); FreeArgv(av);
......
...@@ -153,9 +153,9 @@ const char *VRT_regsub(const struct sess *sp, int all, const char *, ...@@ -153,9 +153,9 @@ const char *VRT_regsub(const struct sess *sp, int all, const char *,
void VRT_panic(struct sess *sp, const char *, ...); void VRT_panic(struct sess *sp, const char *, ...);
void VRT_ban(struct sess *sp, char *, ...); void VRT_ban(struct sess *sp, char *, ...);
void VRT_ban_string(struct sess *sp, const char *, ...); void VRT_ban_string(struct sess *sp, const char *);
void VRT_purge(struct sess *sp, double ttl, double grace); void VRT_purge(struct sess *sp, double ttl, double grace);
void VRT_log(struct sess *, const char *msg, ...); void VRT_log(struct sess *, const char *msg);
void VRT_count(const struct sess *, unsigned); void VRT_count(const struct sess *, unsigned);
int VRT_rewrite(const char *, const char *); int VRT_rewrite(const char *, const char *);
......
...@@ -146,10 +146,12 @@ parse_set(struct vcc *tl) ...@@ -146,10 +146,12 @@ parse_set(struct vcc *tl)
} }
if (ap->type == VOID) if (ap->type == VOID)
SkipToken(tl, ap->oper); SkipToken(tl, ap->oper);
vcc_Expr(tl, fmt); if (fmt == STRING) {
if (vp->fmt == STRING) vcc_Expr(tl, STRING_LIST);
Fb(tl, 1, ", vrt_magic_string_end"); } else {
Fb(tl, 0, ");\n"); vcc_Expr(tl, fmt);
}
Fb(tl, 1, ");\n");
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
...@@ -253,8 +255,7 @@ parse_purge(struct vcc *tl) ...@@ -253,8 +255,7 @@ parse_purge(struct vcc *tl)
Fb(tl, 1, "VRT_ban_string(sp, "); Fb(tl, 1, "VRT_ban_string(sp, ");
vcc_Expr(tl, STRING); vcc_Expr(tl, STRING);
ERRCHK(tl); ERRCHK(tl);
Fb(tl, 0, ", "); Fb(tl, 0, ");\n");
Fb(tl, 0, "vrt_magic_string_end);\n");
} }
ExpectErr(tl, ')'); ExpectErr(tl, ')');
...@@ -309,9 +310,9 @@ parse_hash_data(struct vcc *tl) ...@@ -309,9 +310,9 @@ parse_hash_data(struct vcc *tl)
SkipToken(tl, '('); SkipToken(tl, '(');
Fb(tl, 1, "VRT_hashdata(sp, "); Fb(tl, 1, "VRT_hashdata(sp, ");
vcc_Expr(tl, STRING); vcc_Expr(tl, STRING_LIST);
ERRCHK(tl); ERRCHK(tl);
Fb(tl, 0, ", vrt_magic_string_end);\n"); Fb(tl, 0, ");\n");
SkipToken(tl, ')'); SkipToken(tl, ')');
} }
...@@ -378,9 +379,9 @@ parse_synthetic(struct vcc *tl) ...@@ -378,9 +379,9 @@ parse_synthetic(struct vcc *tl)
vcc_NextToken(tl); vcc_NextToken(tl);
Fb(tl, 1, "VRT_synth_page(sp, 0, "); Fb(tl, 1, "VRT_synth_page(sp, 0, ");
vcc_Expr(tl, STRING); vcc_Expr(tl, STRING_LIST);
ERRCHK(tl); ERRCHK(tl);
Fb(tl, 0, ", vrt_magic_string_end);\n"); Fb(tl, 0, ");\n");
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
...@@ -392,7 +393,7 @@ parse_log(struct vcc *tl) ...@@ -392,7 +393,7 @@ parse_log(struct vcc *tl)
Fb(tl, 1, "VRT_log(sp, "); Fb(tl, 1, "VRT_log(sp, ");
vcc_Expr(tl, STRING); vcc_Expr(tl, STRING);
ERRCHK(tl); ERRCHK(tl);
Fb(tl, 0, ", vrt_magic_string_end);\n"); Fb(tl, 0, ");\n");
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
......
...@@ -247,38 +247,68 @@ vcc_delete_expr(struct expr *e) ...@@ -247,38 +247,68 @@ vcc_delete_expr(struct expr *e)
* XXX: check line lengths in edit, should pass indent in for this * XXX: check line lengths in edit, should pass indent in for this
*/ */
static void
vcc_show(const char *p)
{
fprintf(stderr, "<");
for (; *p; p++) {
if (*p == '\n')
fprintf(stderr, "\\n");
else if (*p == '\v')
fprintf(stderr, "\\v");
else
fprintf(stderr, "%c", *p);
}
fprintf(stderr, ">\n");
}
static struct expr * static struct expr *
vcc_expr_edit(enum var_type fmt, const char *p, struct expr *e1, struct expr *e2) vcc_expr_edit(enum var_type fmt, const char *p, struct expr *e1, struct expr *e2)
{ {
struct expr *e; struct expr *e;
char *q; int nl = 1;
fprintf(stderr, "EDIT:");
vcc_show(p);
if (e1 != NULL) {
fprintf(stderr, "E1:");
vcc_show(vsb_data(e1->vsb));
}
if (e2 != NULL) {
fprintf(stderr, "E2:");
vcc_show(vsb_data(e2->vsb));
}
q = strchr(vsb_data(e1->vsb), '\n');
if (q == NULL && e2 != NULL)
q = strchr(vsb_data(e2->vsb), '\n');
e = vcc_new_expr(); e = vcc_new_expr();
while (*p != '\0') { while (*p != '\0') {
if (*p == '\n') {
if (!nl)
vsb_putc(e->vsb, *p);
nl = 1;
p++;
continue;
}
nl = 0;
if (*p != '\v') { if (*p != '\v') {
vsb_putc(e->vsb, *p); vsb_putc(e->vsb, *p);
p++; p++;
continue; continue;
} }
assert(*p == '\v');
p++; p++;
switch(*p) { switch(*p) {
case '+': vsb_cat(e->vsb, "\v+"); break; case '+': vsb_cat(e->vsb, "\v+"); break;
case '-': vsb_cat(e->vsb, "\v-"); break; case '-': vsb_cat(e->vsb, "\v-"); break;
case '1': case '1':
case '2': case '2':
if (q != NULL)
vsb_cat(e->vsb, "\v+\n");
if (*p == '1') if (*p == '1')
vsb_cat(e->vsb, vsb_data(e1->vsb)); vsb_cat(e->vsb, vsb_data(e1->vsb));
else { else {
AN(e2); AN(e2);
vsb_cat(e->vsb, vsb_data(e2->vsb)); vsb_cat(e->vsb, vsb_data(e2->vsb));
} }
if (q != NULL)
vsb_cat(e->vsb, "\v-\n");
break; break;
default: default:
assert(__LINE__ == 0); assert(__LINE__ == 0);
...@@ -290,6 +320,8 @@ vcc_expr_edit(enum var_type fmt, const char *p, struct expr *e1, struct expr *e2 ...@@ -290,6 +320,8 @@ vcc_expr_edit(enum var_type fmt, const char *p, struct expr *e1, struct expr *e2
vcc_delete_expr(e1); vcc_delete_expr(e1);
vcc_delete_expr(e2); vcc_delete_expr(e2);
e->fmt = fmt; e->fmt = fmt;
fprintf(stderr, "RESULT:");
vcc_show(vsb_data(e->vsb));
return (e); return (e);
} }
...@@ -479,7 +511,7 @@ vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt) ...@@ -479,7 +511,7 @@ vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
*e = NULL; *e = NULL;
vcc_expr5(tl, e, fmt); vcc_expr5(tl, e, fmt);
ERRCHK(tl); ERRCHK(tl);
if (fmt == STRING) { if (fmt == STRING || fmt == STRING_LIST) {
p = NULL; p = NULL;
switch((*e)->fmt) { switch((*e)->fmt) {
case BACKEND: p = "VRT_backend_string(sp, \v1)"; break; case BACKEND: p = "VRT_backend_string(sp, \v1)"; break;
...@@ -491,7 +523,7 @@ vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt) ...@@ -491,7 +523,7 @@ vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
default: break; default: break;
} }
if (p != NULL) { if (p != NULL) {
*e = vcc_expr_edit(STRING, p, *e, NULL); *e = vcc_expr_edit(fmt, p, *e, NULL);
return; return;
} }
} }
...@@ -521,16 +553,16 @@ vcc_expr_mul(struct vcc *tl, struct expr **e, enum var_type fmt) ...@@ -521,16 +553,16 @@ vcc_expr_mul(struct vcc *tl, struct expr **e, enum var_type fmt)
default: default:
return; return;
} }
while (tl->t->tok == '+' || tl->t->tok == '-') { while (tl->t->tok == '*' || tl->t->tok == '/') {
tk = tl->t; tk = tl->t;
vcc_NextToken(tl); vcc_NextToken(tl);
vcc_expr4(tl, &e2, f2); vcc_expr4(tl, &e2, f2);
assert(e2->fmt == f2); assert(e2->fmt == f2);
ERRCHK(tl); ERRCHK(tl);
if (tk->tok == '+') if (tk->tok == '*')
*e = vcc_expr_edit(f3, "(\v1+\v2)", *e, e2); *e = vcc_expr_edit(f3, "(\v1*\v2)", *e, e2);
else else
*e = vcc_expr_edit(f3, "(\v1-\v2)", *e, e2); *e = vcc_expr_edit(f3, "(\v1/\v2)", *e, e2);
} }
} }
...@@ -551,6 +583,17 @@ vcc_expr_add(struct vcc *tl, struct expr **e, enum var_type fmt) ...@@ -551,6 +583,17 @@ vcc_expr_add(struct vcc *tl, struct expr **e, enum var_type fmt)
ERRCHK(tl); ERRCHK(tl);
f2 = (*e)->fmt; f2 = (*e)->fmt;
if (fmt == STRING_LIST && f2 == STRING) {
if (f2 == STRING)
(*e)->fmt = STRING_LIST;
while (tl->t->tok == '+') {
vcc_NextToken(tl);
vcc_expr_mul(tl, &e2, STRING);
*e = vcc_expr_edit(STRING_LIST, "\v1,\n\v2", *e, e2);
}
return;
}
if (f2 == STRING && tl->t->tok == '+') { if (f2 == STRING && tl->t->tok == '+') {
*e = vcc_expr_edit(STRING, "\v+VRT_String(sp,\n\v1", *e, NULL); *e = vcc_expr_edit(STRING, "\v+VRT_String(sp,\n\v1", *e, NULL);
while (tl->t->tok == '+') { while (tl->t->tok == '+') {
...@@ -735,14 +778,16 @@ vcc_expr_cand(struct vcc *tl, struct expr **e, enum var_type fmt) ...@@ -735,14 +778,16 @@ vcc_expr_cand(struct vcc *tl, struct expr **e, enum var_type fmt)
*e = NULL; *e = NULL;
vcc_expr_cmp(tl, e, fmt); vcc_expr_cmp(tl, e, fmt);
ERRCHK(tl); ERRCHK(tl);
if ((*e)->fmt != BOOL) if ((*e)->fmt != BOOL || tl->t->tok != T_CAND)
return; return;
*e = vcc_expr_edit(BOOL, "(\v+\n\v1", *e, NULL);
while (tl->t->tok == T_CAND) { while (tl->t->tok == T_CAND) {
vcc_NextToken(tl); vcc_NextToken(tl);
vcc_expr_cmp(tl, &e2, fmt); vcc_expr_cmp(tl, &e2, fmt);
ERRCHK(tl); ERRCHK(tl);
*e = vcc_expr_edit(BOOL, "(\v1&&\v2)", *e, e2); *e = vcc_expr_edit(BOOL, "\v1\v-\n&&\v+\n\v2", *e, e2);
} }
*e = vcc_expr_edit(BOOL, "\v1\v-\n)", *e, NULL);
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
...@@ -792,6 +837,10 @@ vcc_Expr(struct vcc *tl, enum var_type fmt) ...@@ -792,6 +837,10 @@ vcc_Expr(struct vcc *tl, enum var_type fmt)
tl->err = 1; tl->err = 1;
} }
if (!tl->err) { if (!tl->err) {
if (e->fmt == STRING_LIST) {
e = vcc_expr_edit(STRING_LIST,
"\v+\n\v1,\nvrt_magic_string_end\v-", e, NULL);
}
vcc_expr_fmt(tl->fb, tl->indent, e); vcc_expr_fmt(tl->fb, tl->indent, e);
vsb_putc(tl->fb, '\n'); vsb_putc(tl->fb, '\n');
} else { } else {
......
...@@ -69,8 +69,8 @@ vcc_Conditional(struct vcc *tl) ...@@ -69,8 +69,8 @@ vcc_Conditional(struct vcc *tl)
{ {
SkipToken(tl, '('); SkipToken(tl, '(');
Fb(tl, 1, "(\n"); Fb(tl, 0, "(\n");
vcc_Expr(tl, BOOL); L(tl, vcc_Expr(tl, BOOL));
ERRCHK(tl); ERRCHK(tl);
Fb(tl, 1, ")\n"); Fb(tl, 1, ")\n");
SkipToken(tl, ')'); SkipToken(tl, ')');
...@@ -92,8 +92,8 @@ vcc_IfStmt(struct vcc *tl) ...@@ -92,8 +92,8 @@ vcc_IfStmt(struct vcc *tl)
{ {
SkipToken(tl, T_IF); SkipToken(tl, T_IF);
Fb(tl, 1, "if \n"); Fb(tl, 1, "if ");
L(tl, vcc_Conditional(tl)); vcc_Conditional(tl);
ERRCHK(tl); ERRCHK(tl);
L(tl, vcc_Compound(tl)); L(tl, vcc_Compound(tl));
ERRCHK(tl); ERRCHK(tl);
...@@ -110,9 +110,9 @@ vcc_IfStmt(struct vcc *tl) ...@@ -110,9 +110,9 @@ vcc_IfStmt(struct vcc *tl)
/* FALLTHROUGH */ /* FALLTHROUGH */
case T_ELSEIF: case T_ELSEIF:
case T_ELSIF: case T_ELSIF:
Fb(tl, 1, "else if \n"); Fb(tl, 1, "else if ");
vcc_NextToken(tl); vcc_NextToken(tl);
L(tl, vcc_Conditional(tl)); vcc_Conditional(tl);
ERRCHK(tl); ERRCHK(tl);
L(tl, vcc_Compound(tl)); L(tl, vcc_Compound(tl));
ERRCHK(tl); ERRCHK(tl);
......
...@@ -35,6 +35,7 @@ VCC_TYPE(INT) ...@@ -35,6 +35,7 @@ VCC_TYPE(INT)
VCC_TYPE(TIME) VCC_TYPE(TIME)
VCC_TYPE(DURATION) VCC_TYPE(DURATION)
VCC_TYPE(STRING) VCC_TYPE(STRING)
VCC_TYPE(STRING_LIST)
VCC_TYPE(IP) VCC_TYPE(IP)
VCC_TYPE(HEADER) VCC_TYPE(HEADER)
VCC_TYPE(REAL) VCC_TYPE(REAL)
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