Commit 39694dfa authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Expose the good string backslash implementation from argv.c and

replace a half-baked one in vtc.c with it.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4219 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent ed02f4f0
...@@ -133,19 +133,9 @@ parse_string(char *buf, const struct cmds *cmd, void *priv, struct vtclog *vl) ...@@ -133,19 +133,9 @@ parse_string(char *buf, const struct cmds *cmd, void *priv, struct vtclog *vl)
for (; *p != '\0'; p++) { for (; *p != '\0'; p++) {
if (*p == '"') if (*p == '"')
break; break;
if (*p == '\\') {
if (*p == '\\' && p[1] == 'n') { p += BackSlash(p, q) - 1;
*q++ = '\n'; q++;
p++;
} else if (*p == '\\' && p[1] == 'r') {
*q++ = '\r';
p++;
} else if (*p == '\\' && p[1] == '\\') {
*q++ = '\\';
p++;
} else if (*p == '\\' && p[1] == '"') {
*q++ = '"';
p++;
} else { } else {
if (*p == '\n') if (*p == '\n')
fprintf(stderr, fprintf(stderr,
......
...@@ -42,6 +42,8 @@ struct vsb; ...@@ -42,6 +42,8 @@ struct vsb;
/* from libvarnish/argv.c */ /* from libvarnish/argv.c */
void FreeArgv(char **argv); void FreeArgv(char **argv);
char **ParseArgv(const char *s, int flag); 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_COMMENT (1 << 0)
#define ARGV_COMMA (1 << 1) #define ARGV_COMMA (1 << 1)
......
...@@ -44,11 +44,12 @@ SVNID("$Id$") ...@@ -44,11 +44,12 @@ SVNID("$Id$")
#include <ctype.h> #include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <stdint.h> #include <stdint.h>
#include "libvarnish.h" #include "libvarnish.h"
static int int
BackSlash(const char *s, char *res) BackSlash(const char *s, char *res)
{ {
int r; int r;
...@@ -104,13 +105,16 @@ BackSlash(const char *s, char *res) ...@@ -104,13 +105,16 @@ BackSlash(const char *s, char *res)
return (r); return (r);
} }
static char * char *
BackSlashDecode(const char *s, const char *e) BackSlashDecode(const char *s, const char *e)
{ {
const char *q; const char *q;
char *p, *r; char *p, *r;
int i; int i;
if (e == NULL)
e = strchr(s, '\0');
assert(e != NULL);
p = calloc((e - s) + 1, 1); p = calloc((e - s) + 1, 1);
if (p == NULL) if (p == NULL)
return (p); return (p);
......
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