r4219 - in trunk/varnish-cache: bin/varnishtest include lib/libvarnish

phk at projects.linpro.no phk at projects.linpro.no
Wed Sep 2 10:40:35 CEST 2009


Author: phk
Date: 2009-09-02 10:40:34 +0200 (Wed, 02 Sep 2009)
New Revision: 4219

Modified:
   trunk/varnish-cache/bin/varnishtest/vtc.c
   trunk/varnish-cache/include/libvarnish.h
   trunk/varnish-cache/lib/libvarnish/argv.c
Log:
Expose the good string backslash implementation from argv.c and
replace a half-baked one in vtc.c with it.



Modified: trunk/varnish-cache/bin/varnishtest/vtc.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.c	2009-09-01 10:39:49 UTC (rev 4218)
+++ trunk/varnish-cache/bin/varnishtest/vtc.c	2009-09-02 08:40:34 UTC (rev 4219)
@@ -133,19 +133,9 @@
 				for (; *p != '\0'; p++) {
 					if (*p == '"')
 						break;
-
-					if (*p == '\\' && p[1] == 'n') {
-						*q++ = '\n';
-						p++;
-					} else if (*p == '\\' && p[1] == 'r') {
-						*q++ = '\r';
-						p++;
-					} else if (*p == '\\' && p[1] == '\\') {
-						*q++ = '\\';
-						p++;
-					} else if (*p == '\\' && p[1] == '"') {
-						*q++ = '"';
-						p++;
+					if (*p == '\\') {
+						p += BackSlash(p, q) - 1;
+						q++;
 					} else {
 						if (*p == '\n')
 							fprintf(stderr,

Modified: trunk/varnish-cache/include/libvarnish.h
===================================================================
--- trunk/varnish-cache/include/libvarnish.h	2009-09-01 10:39:49 UTC (rev 4218)
+++ trunk/varnish-cache/include/libvarnish.h	2009-09-02 08:40:34 UTC (rev 4219)
@@ -42,6 +42,8 @@
 /* from libvarnish/argv.c */
 void FreeArgv(char **argv);
 char **ParseArgv(const char *s, int flag);
+char *BackSlashDecode(const char *s, const char *e);
+int BackSlash(const char *s, char *res);
 #define ARGV_COMMENT	(1 << 0)
 #define ARGV_COMMA	(1 << 1)
 

Modified: trunk/varnish-cache/lib/libvarnish/argv.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/argv.c	2009-09-01 10:39:49 UTC (rev 4218)
+++ trunk/varnish-cache/lib/libvarnish/argv.c	2009-09-02 08:40:34 UTC (rev 4219)
@@ -44,11 +44,12 @@
 #include <ctype.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
 #include <stdint.h>
 
 #include "libvarnish.h"
 
-static int
+int
 BackSlash(const char *s, char *res)
 {
 	int r;
@@ -104,13 +105,16 @@
 	return (r);
 }
 
-static char *
+char *
 BackSlashDecode(const char *s, const char *e)
 {
 	const char *q;
 	char *p, *r;
 	int i;
 
+	if (e == NULL)
+		e = strchr(s, '\0');
+	assert(e != NULL);
 	p = calloc((e - s) + 1, 1);
 	if (p == NULL)
 		return (p);



More information about the varnish-commit mailing list