From 07049b3d25cbc397dd39c71d32422bfd7c39d814 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 10 Sep 2010 09:19:10 -0400 Subject: Support mutli-line torrc options via the usual backslash syntax --- src/test/test_util.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/test/test_util.c') diff --git a/src/test/test_util.c b/src/test/test_util.c index 8a1359797..84bb5a67f 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -100,6 +100,9 @@ test_util_config_line(void) "k4#a\n" "k5#abc\n" "k6 val #with comment\n" "kseven \"a quoted 'string\"\n" "k8 \"a \\x71uoted\\n\\\"str\\\\ing\\t\\001\\01\\1\\\"\"\n" + "k9 a line that\\\n spans two lines.\n\n" + "k10 more than\\\n one contin\\\nuation\n" + "k11 \\\ncontinuation at the start\n" , sizeof(buf)); str = buf; @@ -161,7 +164,24 @@ test_util_config_line(void) test_streq(k, "k8"); test_streq(v, "a quoted\n\"str\\ing\t\x01\x01\x01\""); tor_free(k); tor_free(v); + + str = parse_config_line_from_str(str, &k, &v); + test_streq(k, "k9"); + test_streq(v, "a line that spans two lines."); + tor_free(k); tor_free(v); + + str = parse_config_line_from_str(str, &k, &v); + test_streq(k, "k10"); + test_streq(v, "more than one continuation"); + tor_free(k); tor_free(v); + + str = parse_config_line_from_str(str, &k, &v); + test_streq(k, "k11"); + test_streq(v, "continuation at the start"); + tor_free(k); tor_free(v); + test_streq(str, ""); + done: tor_free(k); tor_free(v); -- cgit v1.2.3 From a05ef55b66684d3355b213f8df366c23d0128eca Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Sat, 11 Sep 2010 01:25:48 +0200 Subject: Allow comments for multi-line torrc options --- src/common/util.c | 21 +++++++++++++++------ src/or/circuitbuild.c | 3 ++- src/or/relay.c | 1 + src/test/test_util.c | 12 ++++++++++++ 4 files changed, 30 insertions(+), 7 deletions(-) (limited to 'src/test/test_util.c') diff --git a/src/common/util.c b/src/common/util.c index 6b9455ddd..e47ac78d3 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 == '#') { diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c index 5567b246a..ef1bab320 100644 --- a/src/or/circuitbuild.c +++ b/src/or/circuitbuild.c @@ -1752,7 +1752,8 @@ circuit_deliver_create_cell(circuit_t *circ, uint8_t cell_type, cell.circ_id = circ->n_circ_id; memcpy(cell.payload, payload, ONIONSKIN_CHALLENGE_LEN); - append_cell_to_circuit_queue(circ, circ->n_conn, &cell, CELL_DIRECTION_OUT, 0); + append_cell_to_circuit_queue(circ, circ->n_conn, &cell, + CELL_DIRECTION_OUT, 0); if (CIRCUIT_IS_ORIGIN(circ)) { /* mark it so it gets better rate limiting treatment. */ diff --git a/src/or/relay.c b/src/or/relay.c index 0d51ea406..0b0b7067a 100644 --- a/src/or/relay.c +++ b/src/or/relay.c @@ -2446,3 +2446,4 @@ circuit_queue_streams_are_blocked(circuit_t *circ) return circ->streams_blocked_on_p_conn; } } + diff --git a/src/test/test_util.c b/src/test/test_util.c index 84bb5a67f..49823fde7 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -103,6 +103,8 @@ test_util_config_line(void) "k9 a line that\\\n spans two lines.\n\n" "k10 more than\\\n one contin\\\nuation\n" "k11 \\\ncontinuation at the start\n" + "k12 line with a\\\n#comment\n embedded\n" + "k13\\\ncontinuation at the very start\n" , sizeof(buf)); str = buf; @@ -180,6 +182,16 @@ test_util_config_line(void) test_streq(v, "continuation at the start"); tor_free(k); tor_free(v); + str = parse_config_line_from_str(str, &k, &v); + test_streq(k, "k12"); + test_streq(v, "line with a embedded"); + tor_free(k); tor_free(v); + + str = parse_config_line_from_str(str, &k, &v); + test_streq(k, "k13"); + test_streq(v, "continuation at the very start"); + tor_free(k); tor_free(v); + test_streq(str, ""); done: -- cgit v1.2.3 From 1d29ad891e848dcb48120331e0d2f78bd6777746 Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Thu, 23 Sep 2010 22:39:58 +0200 Subject: Add new torrc line continuation unit tests We want to make sure that we don't break old torrc files that might have used something like this made-up example: ContactInfo UberUser # /// Fake email! \\\ Log info file /home/nick.mathewson/projects/tor-info.log And we also want to support the following style of writing your torrc: ExcludeNodes \ # Node1337 is run by the Bavarian Illuminati Node1337, \ # The operator of Node99 looked at me funny Node99 The code already handles both cases, but the unit test should help prove it. --- src/test/test_util.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/test/test_util.c') diff --git a/src/test/test_util.c b/src/test/test_util.c index 49823fde7..d90927b35 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -105,6 +105,10 @@ test_util_config_line(void) "k11 \\\ncontinuation at the start\n" "k12 line with a\\\n#comment\n embedded\n" "k13\\\ncontinuation at the very start\n" + "k14 a line that has a comment and # ends with a slash \\\n" + "k15 this should be the next new line\n" + "k16 a line that has a comment and # ends without a slash \n" + "k17 this should be the next new line\n" , sizeof(buf)); str = buf; @@ -192,6 +196,26 @@ test_util_config_line(void) test_streq(v, "continuation at the very start"); tor_free(k); tor_free(v); + str = parse_config_line_from_str(str, &k, &v); + test_streq(k, "k14"); + test_streq(v, "a line that has a comment and" ); + tor_free(k); tor_free(v); + + str = parse_config_line_from_str(str, &k, &v); + test_streq(k, "k15"); + test_streq(v, "this should be the next new line"); + tor_free(k); tor_free(v); + + str = parse_config_line_from_str(str, &k, &v); + test_streq(k, "k16"); + test_streq(v, "a line that has a comment and" ); + tor_free(k); tor_free(v); + + str = parse_config_line_from_str(str, &k, &v); + test_streq(k, "k17"); + test_streq(v, "this should be the next new line"); + tor_free(k); tor_free(v); + test_streq(str, ""); done: -- cgit v1.2.3