Loading changes/torrc_continuation 0 → 100644 +5 −0 Original line number Diff line number Diff line o Minor features: - Support line continuations in torrc. If a line ends with a single backslash character, the newline is ignored, and the configuration value is treated as continuing on the next line. src/common/util.c +21 −1 Original line number Diff line number Diff line Loading @@ -2285,6 +2285,7 @@ const char * parse_config_line_from_str(const char *line, char **key_out, char **value_out) { const char *key, *val, *cp; int continuation = 0; tor_assert(key_out); tor_assert(value_out); Loading Loading @@ -2329,8 +2330,13 @@ 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 != '#') { if (*line == '\\' && line[1] == '\n') { continuation = 1; ++line; } ++line; } if (*line == '\n') { cp = line++; } else { Loading @@ -2340,7 +2346,21 @@ parse_config_line_from_str(const char *line, char **key_out, char **value_out) --cp; tor_assert(cp >= val); *value_out = tor_strndup(val, cp-val); if (continuation) { char *v_out, *v_in; v_out = v_in = *value_out; while (*v_in) { if (v_in[0] == '\\' && v_in[1] == '\n') { v_in += 2; } else { *v_out++ = *v_in++; } } *v_out = '\0'; } } if (*line == '#') { Loading src/test/test_util.c +20 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading Loading
changes/torrc_continuation 0 → 100644 +5 −0 Original line number Diff line number Diff line o Minor features: - Support line continuations in torrc. If a line ends with a single backslash character, the newline is ignored, and the configuration value is treated as continuing on the next line.
src/common/util.c +21 −1 Original line number Diff line number Diff line Loading @@ -2285,6 +2285,7 @@ const char * parse_config_line_from_str(const char *line, char **key_out, char **value_out) { const char *key, *val, *cp; int continuation = 0; tor_assert(key_out); tor_assert(value_out); Loading Loading @@ -2329,8 +2330,13 @@ 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 != '#') { if (*line == '\\' && line[1] == '\n') { continuation = 1; ++line; } ++line; } if (*line == '\n') { cp = line++; } else { Loading @@ -2340,7 +2346,21 @@ parse_config_line_from_str(const char *line, char **key_out, char **value_out) --cp; tor_assert(cp >= val); *value_out = tor_strndup(val, cp-val); if (continuation) { char *v_out, *v_in; v_out = v_in = *value_out; while (*v_in) { if (v_in[0] == '\\' && v_in[1] == '\n') { v_in += 2; } else { *v_out++ = *v_in++; } } *v_out = '\0'; } } if (*line == '#') { Loading
src/test/test_util.c +20 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading