summaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorSebastian Hahn <sebastian@torproject.org>2010-09-11 01:25:48 +0200
committerSebastian Hahn <sebastian@torproject.org>2010-09-11 01:41:23 +0200
commita05ef55b66684d3355b213f8df366c23d0128eca (patch)
treece899d00b4d26a0a02617f27c6a86aa48254ab9b /src/common/util.c
parent07049b3d25cbc397dd39c71d32422bfd7c39d814 (diff)
downloadtor-a05ef55b66684d3355b213f8df366c23d0128eca.tar.gz
tor-a05ef55b66684d3355b213f8df366c23d0128eca.zip
Allow comments for multi-line torrc options
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 6b9455ddd7..e47ac78d35 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -2309,9 +2309,10 @@ parse_config_line_from_str(const char *line, char **key_out, char **value_out)
return line;
}
- /* Skip until the next space. */
+ /* Skip until the next space or \ followed by newline. */
key = line;
- while (*line && !TOR_ISSPACE(*line) && *line != '#')
+ while (*line && !TOR_ISSPACE(*line) && *line != '#' &&
+ ! (line[0] == '\\' && line[1] == '\n'))
++line;
*key_out = tor_strndup(key, line-key);
@@ -2322,7 +2323,7 @@ parse_config_line_from_str(const char *line, char **key_out, char **value_out)
val = line;
/* Find the end of the line. */
- if (*line == '\"') {
+ if (*line == '\"') { // XXX No continuation here
if (!(line = unescape_string(line, value_out, NULL)))
return NULL;
while (*line == ' ' || *line == '\t')
@@ -2330,10 +2331,14 @@ parse_config_line_from_str(const char *line, char **key_out, char **value_out)
if (*line && *line != '#' && *line != '\n')
return NULL;
} else {
- while (*line && *line != '\n' && *line != '#') {
+ while (*line && *line != '\n' && (*line != '#' || continuation)) {
if (*line == '\\' && line[1] == '\n') {
continuation = 1;
++line;
+ } else if (*line == '#') {
+ do {
+ ++line;
+ } while (*line && *line != '\n');
}
++line;
}
@@ -2352,7 +2357,12 @@ parse_config_line_from_str(const char *line, char **key_out, char **value_out)
char *v_out, *v_in;
v_out = v_in = *value_out;
while (*v_in) {
- if (v_in[0] == '\\' && v_in[1] == '\n') {
+ if (*v_in == '#') {
+ do {
+ ++v_in;
+ } while (*v_in && *v_in != '\n');
+ ++v_in;
+ } else if (v_in[0] == '\\' && v_in[1] == '\n') {
v_in += 2;
} else {
*v_out++ = *v_in++;
@@ -2360,7 +2370,6 @@ parse_config_line_from_str(const char *line, char **key_out, char **value_out)
}
*v_out = '\0';
}
-
}
if (*line == '#') {