Commit 89f297cd authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Use the already decoded CSTR where applicable and use

EncString() to encode strings for C source usage.


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@811 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 21561d09
...@@ -53,7 +53,6 @@ vcc_Acl(struct tokenlist *tl) ...@@ -53,7 +53,6 @@ vcc_Acl(struct tokenlist *tl)
{ {
unsigned mask, para, not; unsigned mask, para, not;
struct token *t, *an; struct token *t, *an;
char *p;
vcc_NextToken(tl); vcc_NextToken(tl);
...@@ -93,14 +92,16 @@ vcc_Acl(struct tokenlist *tl) ...@@ -93,14 +92,16 @@ vcc_Acl(struct tokenlist *tl)
ExpectErr(tl, CNUM); ExpectErr(tl, CNUM);
mask = UintVal(tl); mask = UintVal(tl);
} }
Fc(tl, 1, "{ %u, %u, %u, %.*s, \"", not, mask, para, PF(t)); Fc(tl, 1, "{ %u, %u, %u, ", not, mask, para);
EncString(tl->fc, t);
Fc(tl, 0, ", \"");
if (para) if (para)
Fc(tl, 0, "("); Fc(tl, 0, "(");
if (not) if (not)
Fc(tl, 0, "!"); Fc(tl, 0, "!");
p = EncString(t); Fc(tl, 0, "\\\"\" ");
Fc(tl, 0, "%s", p); EncString(tl->fc, t);
free(p); Fc(tl, 0, " \"\\\"");
if (mask) if (mask)
Fc(tl, 0, "/%u", mask); Fc(tl, 0, "/%u", mask);
if (para) if (para)
......
...@@ -142,53 +142,22 @@ Ff(struct tokenlist *tl, int indent, const char *fmt, ...) ...@@ -142,53 +142,22 @@ Ff(struct tokenlist *tl, int indent, const char *fmt, ...)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
char * void
EncString(struct token *t) EncString(struct vsb *sb, struct token *t)
{ {
char *p, *q; const char *p;
const char *r;
unsigned u;
assert(t->tok == CSTR); assert(t->tok == CSTR);
p = malloc(t->e - t->b); vsb_cat(sb, "\"");
assert(p != NULL); for (p = t->dec; *p != '\0'; p++) {
q = p; if (*p == '\\' || *p == '"')
for (r = t->b + 1; r < t->e - 1; ) { vsb_printf(sb, "\\%c", *p);
if (*r != '\\') { else if (isgraph(*p))
*q++ = *r++; vsb_printf(sb, "%c", *p);
continue; else
} vsb_printf(sb, "\\%03o", *p);
switch (r[1]) {
case 'n': *q++ = '\n'; r += 2; break;
case 'r': *q++ = '\r'; r += 2; break;
case 'v': *q++ = '\v'; r += 2; break;
case 'f': *q++ = '\f'; r += 2; break;
case 't': *q++ = '\t'; r += 2; break;
case 'b': *q++ = '\b'; r += 2; break;
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
u = r[1] - '0';
r += 2;
if (isdigit(r[0]) && (r[0] - '0') < 8) {
u <<= 3;
u |= r[0] - '0';
r++;
if (isdigit(r[0]) && (r[0] - '0') < 8) {
u <<= 3;
u |= r[0] - '0';
r++;
}
}
*q++ = u;
break;
default:
*q++ = r[1];
r += 2;
break;
}
} }
*q = '\0'; vsb_cat(sb, "\"");
return (p);
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
...@@ -492,19 +461,20 @@ RateVal(struct tokenlist *tl) ...@@ -492,19 +461,20 @@ RateVal(struct tokenlist *tl)
static void static void
vcc_re(struct tokenlist *tl, const char *str, struct token *re) vcc_re(struct tokenlist *tl, const char *str, struct token *re)
{ {
char buf[32], *p; char buf[32];
p = EncString(re); assert(re->tok == CSTR);
if (VRT_re_test(tl->sb, p)) { if (VRT_re_test(tl->sb, re->dec)) {
vcc_ErrWhere(tl, re); vcc_ErrWhere(tl, re);
return; return;
} }
free(p);
sprintf(buf, "VGC_re_%u", tl->recnt++); sprintf(buf, "VGC_re_%u", tl->recnt++);
Fc(tl, 1, "VRT_re_match(%s, %s)\n", str, buf); Fc(tl, 1, "VRT_re_match(%s, %s)\n", str, buf);
Fh(tl, 0, "void *%s;\n", buf); Fh(tl, 0, "void *%s;\n", buf);
Fi(tl, 0, "\tVRT_re_init(&%s, %.*s);\n", buf, PF(re)); Fi(tl, 0, "\tVRT_re_init(&%s, ",buf);
EncString(tl->fi, re);
Fi(tl, 0, ");\n");
Ff(tl, 0, "\tVRT_re_fini(%s);\n", buf); Ff(tl, 0, "\tVRT_re_fini(%s);\n", buf);
} }
...@@ -528,7 +498,8 @@ Cond_String(struct var *vp, struct tokenlist *tl) ...@@ -528,7 +498,8 @@ Cond_String(struct var *vp, struct tokenlist *tl)
tl->t->tok == T_EQ ? "!" : "", vp->rname); tl->t->tok == T_EQ ? "!" : "", vp->rname);
vcc_NextToken(tl); vcc_NextToken(tl);
ExpectErr(tl, CSTR); ExpectErr(tl, CSTR);
Fc(tl, 0, "%.*s)\n", PF(tl->t)); EncString(tl->fc, tl->t);
Fc(tl, 0, ")\n");
vcc_NextToken(tl); vcc_NextToken(tl);
break; break;
default: default:
...@@ -931,8 +902,6 @@ Backend(struct tokenlist *tl) ...@@ -931,8 +902,6 @@ Backend(struct tokenlist *tl)
struct token *t_be = NULL; struct token *t_be = NULL;
struct token *t_host = NULL; struct token *t_host = NULL;
struct token *t_port = NULL; struct token *t_port = NULL;
char *host = NULL;
char *port = NULL;
const char *ep; const char *ep;
vcc_NextToken(tl); vcc_NextToken(tl);
...@@ -969,13 +938,17 @@ Backend(struct tokenlist *tl) ...@@ -969,13 +938,17 @@ Backend(struct tokenlist *tl)
case HOSTNAME: case HOSTNAME:
ExpectErr(tl, CSTR); ExpectErr(tl, CSTR);
t_host = tl->t; t_host = tl->t;
Fc(tl, 1, "\t%s %.*s);\n", vp->lname, PF(tl->t)); Fc(tl, 1, "\t%s ", vp->lname);
EncString(tl->fc, t_host);
Fc(tl, 0, ");\n");
vcc_NextToken(tl); vcc_NextToken(tl);
break; break;
case PORTNAME: case PORTNAME:
ExpectErr(tl, CSTR); ExpectErr(tl, CSTR);
t_port = tl->t; t_port = tl->t;
Fc(tl, 1, "\t%s %.*s);\n", vp->lname, PF(tl->t)); Fc(tl, 1, "\t%s ", vp->lname);
EncString(tl->fc, t_port);
Fc(tl, 0, ");\n");
vcc_NextToken(tl); vcc_NextToken(tl);
break; break;
default: default:
...@@ -994,18 +967,17 @@ Backend(struct tokenlist *tl) ...@@ -994,18 +967,17 @@ Backend(struct tokenlist *tl)
vcc_ErrWhere(tl, tl->t); vcc_ErrWhere(tl, tl->t);
return; return;
} }
host = EncString(t_host); ep = CheckHostPort(t_host->dec, "80");
ep = CheckHostPort(host, "80");
if (ep != NULL) { if (ep != NULL) {
vsb_printf(tl->sb, "Backend '%.*s': %s\n", PF(t_be), ep); vsb_printf(tl->sb, "Backend '%.*s': %s\n", PF(t_be), ep);
vcc_ErrWhere(tl, t_host); vcc_ErrWhere(tl, t_host);
return; return;
} }
if (t_port != NULL) { if (t_port != NULL) {
port = EncString(t_port); ep = CheckHostPort(t_host->dec, t_port->dec);
ep = CheckHostPort(host, port);
if (ep != NULL) { if (ep != NULL) {
vsb_printf(tl->sb, "Backend '%.*s': %s\n", PF(t_be), ep); vsb_printf(tl->sb,
"Backend '%.*s': %s\n", PF(t_be), ep);
vcc_ErrWhere(tl, t_port); vcc_ErrWhere(tl, t_port);
return; return;
} }
......
...@@ -111,7 +111,7 @@ void Ff(struct tokenlist *tl, int indent, const char *fmt, ...); ...@@ -111,7 +111,7 @@ void Ff(struct tokenlist *tl, int indent, const char *fmt, ...);
unsigned UintVal(struct tokenlist *tl); unsigned UintVal(struct tokenlist *tl);
void AddDef(struct tokenlist *tl, struct token *t, enum ref_type type); void AddDef(struct tokenlist *tl, struct token *t, enum ref_type type);
void AddRef(struct tokenlist *tl, struct token *t, enum ref_type type); void AddRef(struct tokenlist *tl, struct token *t, enum ref_type type);
char *EncString(struct token *t); void EncString(struct vsb *sb, struct token *t);
/* vcc_obj.c */ /* vcc_obj.c */
......
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