r4176 - in trunk/varnish-cache: bin/varnishd include lib/libvarnish
phk at projects.linpro.no
phk at projects.linpro.no
Fri Aug 7 19:32:03 CEST 2009
Author: phk
Date: 2009-08-07 19:32:03 +0200 (Fri, 07 Aug 2009)
New Revision: 4176
Modified:
trunk/varnish-cache/bin/varnishd/cache_ban.c
trunk/varnish-cache/include/vsb.h
trunk/varnish-cache/lib/libvarnish/cli_common.c
trunk/varnish-cache/lib/libvarnish/vsb.c
Log:
Give vsb_quote() an optional length paramter (Pass -1 for strlen).
Add a complementary vsb_unquote() function.
Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-08-06 10:53:17 UTC (rev 4175)
+++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-08-07 17:32:03 UTC (rev 4176)
@@ -291,7 +291,7 @@
}
vsb_printf(b->vsb, "%s %s ", a1, a2);
- vsb_quote(b->vsb, a3, 0);
+ vsb_quote(b->vsb, a3, -1, 0);
return (0);
}
Modified: trunk/varnish-cache/include/vsb.h
===================================================================
--- trunk/varnish-cache/include/vsb.h 2009-08-06 10:53:17 UTC (rev 4175)
+++ trunk/varnish-cache/include/vsb.h 2009-08-07 17:32:03 UTC (rev 4176)
@@ -77,7 +77,8 @@
int vsb_len(struct vsb *);
int vsb_done(const struct vsb *);
void vsb_delete(struct vsb *);
-void vsb_quote(struct vsb *s, const char *p, int how);
+void vsb_quote(struct vsb *s, const char *p, int len, int how);
+const char *vsb_unquote(struct vsb *s, const char *p, int len, int how);
#ifdef __cplusplus
};
#endif
Modified: trunk/varnish-cache/lib/libvarnish/cli_common.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/cli_common.c 2009-08-06 10:53:17 UTC (rev 4175)
+++ trunk/varnish-cache/lib/libvarnish/cli_common.c 2009-08-07 17:32:03 UTC (rev 4176)
@@ -74,7 +74,7 @@
cli_quote(struct cli *cli, const char *s)
{
- vsb_quote(cli->sb, s, 0);
+ vsb_quote(cli->sb, s, -1, 0);
}
void
Modified: trunk/varnish-cache/lib/libvarnish/vsb.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/vsb.c 2009-08-06 10:53:17 UTC (rev 4175)
+++ trunk/varnish-cache/lib/libvarnish/vsb.c 2009-08-07 17:32:03 UTC (rev 4176)
@@ -482,25 +482,27 @@
* Quote a string
*/
void
-vsb_quote(struct vsb *s, const char *p, int how)
+vsb_quote(struct vsb *s, const char *p, int len, int how)
{
const char *q;
int quote = 0;
(void)how; /* For future enhancements */
+ if (len == -1)
+ len = strlen(p);
- for (q = p; *q != '\0'; q++) {
+ for (q = p; q < p + len; q++) {
if (!isgraph(*q) || *q == '"') {
quote++;
break;
}
}
if (!quote) {
- (void)vsb_cat(s, p);
+ (void)vsb_bcat(s, p, len);
return;
}
(void)vsb_putc(s, '"');
- for (q = p; *q != '\0'; q++) {
+ for (q = p; q < p + len; q++) {
switch (*q) {
case ' ':
(void)vsb_putc(s, *q);
@@ -523,9 +525,66 @@
if (isgraph(*q))
(void)vsb_putc(s, *q);
else
- (void)vsb_printf(s, "\\%o", *q);
+ (void)vsb_printf(s, "\\%o", *q & 0xff);
break;
}
}
(void)vsb_putc(s, '"');
}
+
+/*
+ * Unquote a string
+ */
+const char *
+vsb_unquote(struct vsb *s, const char *p, int len, int how)
+{
+ const char *q;
+ char *r;
+ unsigned long u;
+ char c;
+
+ (void)how; /* For future enhancements */
+
+ if (len == -1)
+ len = strlen(p);
+
+ for (q = p; q < p + len; q++) {
+ if (*q != '\\') {
+ (void)vsb_bcat(s, q, 1);
+ continue;
+ }
+ if (++q >= p + len)
+ return ("Incomplete '\\'-sequence at end of string");
+
+ switch(*q) {
+ case 'n':
+ (void)vsb_bcat(s, "\n", 1);
+ continue;
+ case 'r':
+ (void)vsb_bcat(s, "\r", 1);
+ continue;
+ case 't':
+ (void)vsb_bcat(s, "\t", 1);
+ continue;
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ errno = 0;
+ u = strtoul(q, &r, 8);
+ if (errno != 0 || (u & ~0xff))
+ return ("\\ooo sequence out of range");
+ c = (char)u;
+ (void)vsb_bcat(s, &c, 1);
+ q = r - 1;
+ continue;
+ default:
+ (void)vsb_bcat(s, q, 1);
+ }
+ }
+ return (NULL);
+}
More information about the varnish-commit
mailing list