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, ...)
/*--------------------------------------------------------------------*/
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);
b = vrt_assemble_string(sp->http, NULL, str, ap);
va_end(ap);
WSP(sp, SLT_VCL_Log, "%s", b);
WSP(sp, SLT_VCL_Log, "%s", str);
}
/*--------------------------------------------------------------------*/
......@@ -1056,22 +1051,16 @@ VRT_ban(struct sess *sp, char *cmds, ...)
/*--------------------------------------------------------------------*/
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;
va_list ap;
struct ban *b;
int good;
int i;
va_start(ap, str);
p = vrt_assemble_string(sp->http, NULL, str, ap);
if (p == NULL)
/* XXX: report error how ? */
return;
av = ParseArgv(p, 0);
(void)sp;
av = ParseArgv(str, 0);
if (av[0] != NULL) {
/* XXX: report error how ? */
FreeArgv(av);
......
......@@ -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_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_log(struct sess *, const char *msg, ...);
void VRT_log(struct sess *, const char *msg);
void VRT_count(const struct sess *, unsigned);
int VRT_rewrite(const char *, const char *);
......
......@@ -146,10 +146,12 @@ parse_set(struct vcc *tl)
}
if (ap->type == VOID)
SkipToken(tl, ap->oper);
vcc_Expr(tl, fmt);
if (vp->fmt == STRING)
Fb(tl, 1, ", vrt_magic_string_end");
Fb(tl, 0, ");\n");
if (fmt == STRING) {
vcc_Expr(tl, STRING_LIST);
} else {
vcc_Expr(tl, fmt);
}
Fb(tl, 1, ");\n");
}
/*--------------------------------------------------------------------*/
......@@ -253,8 +255,7 @@ parse_purge(struct vcc *tl)
Fb(tl, 1, "VRT_ban_string(sp, ");
vcc_Expr(tl, STRING);
ERRCHK(tl);
Fb(tl, 0, ", ");
Fb(tl, 0, "vrt_magic_string_end);\n");
Fb(tl, 0, ");\n");
}
ExpectErr(tl, ')');
......@@ -309,9 +310,9 @@ parse_hash_data(struct vcc *tl)
SkipToken(tl, '(');
Fb(tl, 1, "VRT_hashdata(sp, ");
vcc_Expr(tl, STRING);
vcc_Expr(tl, STRING_LIST);
ERRCHK(tl);
Fb(tl, 0, ", vrt_magic_string_end);\n");
Fb(tl, 0, ");\n");
SkipToken(tl, ')');
}
......@@ -378,9 +379,9 @@ parse_synthetic(struct vcc *tl)
vcc_NextToken(tl);
Fb(tl, 1, "VRT_synth_page(sp, 0, ");
vcc_Expr(tl, STRING);
vcc_Expr(tl, STRING_LIST);
ERRCHK(tl);
Fb(tl, 0, ", vrt_magic_string_end);\n");
Fb(tl, 0, ");\n");
}
/*--------------------------------------------------------------------*/
......@@ -392,7 +393,7 @@ parse_log(struct vcc *tl)
Fb(tl, 1, "VRT_log(sp, ");
vcc_Expr(tl, STRING);
ERRCHK(tl);
Fb(tl, 0, ", vrt_magic_string_end);\n");
Fb(tl, 0, ");\n");
}
/*--------------------------------------------------------------------*/
......
......@@ -247,38 +247,68 @@ vcc_delete_expr(struct expr *e)
* 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 *
vcc_expr_edit(enum var_type fmt, const char *p, struct expr *e1, struct expr *e2)
{
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();
while (*p != '\0') {
if (*p == '\n') {
if (!nl)
vsb_putc(e->vsb, *p);
nl = 1;
p++;
continue;
}
nl = 0;
if (*p != '\v') {
vsb_putc(e->vsb, *p);
p++;
continue;
}
assert(*p == '\v');
p++;
switch(*p) {
case '+': vsb_cat(e->vsb, "\v+"); break;
case '-': vsb_cat(e->vsb, "\v-"); break;
case '1':
case '2':
if (q != NULL)
vsb_cat(e->vsb, "\v+\n");
if (*p == '1')
vsb_cat(e->vsb, vsb_data(e1->vsb));
else {
AN(e2);
vsb_cat(e->vsb, vsb_data(e2->vsb));
}
if (q != NULL)
vsb_cat(e->vsb, "\v-\n");
break;
default:
assert(__LINE__ == 0);
......@@ -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(e2);
e->fmt = fmt;
fprintf(stderr, "RESULT:");
vcc_show(vsb_data(e->vsb));
return (e);
}
......@@ -479,7 +511,7 @@ vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
*e = NULL;
vcc_expr5(tl, e, fmt);
ERRCHK(tl);
if (fmt == STRING) {
if (fmt == STRING || fmt == STRING_LIST) {
p = NULL;
switch((*e)->fmt) {
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)
default: break;
}
if (p != NULL) {
*e = vcc_expr_edit(STRING, p, *e, NULL);
*e = vcc_expr_edit(fmt, p, *e, NULL);
return;
}
}
......@@ -521,16 +553,16 @@ vcc_expr_mul(struct vcc *tl, struct expr **e, enum var_type fmt)
default:
return;
}
while (tl->t->tok == '+' || tl->t->tok == '-') {
while (tl->t->tok == '*' || tl->t->tok == '/') {
tk = tl->t;
vcc_NextToken(tl);
vcc_expr4(tl, &e2, f2);
assert(e2->fmt == f2);
ERRCHK(tl);
if (tk->tok == '+')
*e = vcc_expr_edit(f3, "(\v1+\v2)", *e, e2);
if (tk->tok == '*')
*e = vcc_expr_edit(f3, "(\v1*\v2)", *e, e2);
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)
ERRCHK(tl);
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 == '+') {
*e = vcc_expr_edit(STRING, "\v+VRT_String(sp,\n\v1", *e, NULL);
while (tl->t->tok == '+') {
......@@ -735,14 +778,16 @@ vcc_expr_cand(struct vcc *tl, struct expr **e, enum var_type fmt)
*e = NULL;
vcc_expr_cmp(tl, e, fmt);
ERRCHK(tl);
if ((*e)->fmt != BOOL)
if ((*e)->fmt != BOOL || tl->t->tok != T_CAND)
return;
*e = vcc_expr_edit(BOOL, "(\v+\n\v1", *e, NULL);
while (tl->t->tok == T_CAND) {
vcc_NextToken(tl);
vcc_expr_cmp(tl, &e2, fmt);
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)
tl->err = 1;
}
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);
vsb_putc(tl->fb, '\n');
} else {
......
......@@ -69,8 +69,8 @@ vcc_Conditional(struct vcc *tl)
{
SkipToken(tl, '(');
Fb(tl, 1, "(\n");
vcc_Expr(tl, BOOL);
Fb(tl, 0, "(\n");
L(tl, vcc_Expr(tl, BOOL));
ERRCHK(tl);
Fb(tl, 1, ")\n");
SkipToken(tl, ')');
......@@ -92,8 +92,8 @@ vcc_IfStmt(struct vcc *tl)
{
SkipToken(tl, T_IF);
Fb(tl, 1, "if \n");
L(tl, vcc_Conditional(tl));
Fb(tl, 1, "if ");
vcc_Conditional(tl);
ERRCHK(tl);
L(tl, vcc_Compound(tl));
ERRCHK(tl);
......@@ -110,9 +110,9 @@ vcc_IfStmt(struct vcc *tl)
/* FALLTHROUGH */
case T_ELSEIF:
case T_ELSIF:
Fb(tl, 1, "else if \n");
Fb(tl, 1, "else if ");
vcc_NextToken(tl);
L(tl, vcc_Conditional(tl));
vcc_Conditional(tl);
ERRCHK(tl);
L(tl, vcc_Compound(tl));
ERRCHK(tl);
......
......@@ -35,6 +35,7 @@ VCC_TYPE(INT)
VCC_TYPE(TIME)
VCC_TYPE(DURATION)
VCC_TYPE(STRING)
VCC_TYPE(STRING_LIST)
VCC_TYPE(IP)
VCC_TYPE(HEADER)
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