mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Allow comments for multi-line torrc options
This commit is contained in:
parent
07049b3d25
commit
a05ef55b66
@ -2309,9 +2309,10 @@ parse_config_line_from_str(const char *line, char **key_out, char **value_out)
|
|||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip until the next space. */
|
/* Skip until the next space or \ followed by newline. */
|
||||||
key = line;
|
key = line;
|
||||||
while (*line && !TOR_ISSPACE(*line) && *line != '#')
|
while (*line && !TOR_ISSPACE(*line) && *line != '#' &&
|
||||||
|
! (line[0] == '\\' && line[1] == '\n'))
|
||||||
++line;
|
++line;
|
||||||
*key_out = tor_strndup(key, line-key);
|
*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;
|
val = line;
|
||||||
|
|
||||||
/* Find the end of the line. */
|
/* Find the end of the line. */
|
||||||
if (*line == '\"') {
|
if (*line == '\"') { // XXX No continuation here
|
||||||
if (!(line = unescape_string(line, value_out, NULL)))
|
if (!(line = unescape_string(line, value_out, NULL)))
|
||||||
return NULL;
|
return NULL;
|
||||||
while (*line == ' ' || *line == '\t')
|
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')
|
if (*line && *line != '#' && *line != '\n')
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
while (*line && *line != '\n' && *line != '#') {
|
while (*line && *line != '\n' && (*line != '#' || continuation)) {
|
||||||
if (*line == '\\' && line[1] == '\n') {
|
if (*line == '\\' && line[1] == '\n') {
|
||||||
continuation = 1;
|
continuation = 1;
|
||||||
++line;
|
++line;
|
||||||
|
} else if (*line == '#') {
|
||||||
|
do {
|
||||||
|
++line;
|
||||||
|
} while (*line && *line != '\n');
|
||||||
}
|
}
|
||||||
++line;
|
++line;
|
||||||
}
|
}
|
||||||
@ -2352,7 +2357,12 @@ parse_config_line_from_str(const char *line, char **key_out, char **value_out)
|
|||||||
char *v_out, *v_in;
|
char *v_out, *v_in;
|
||||||
v_out = v_in = *value_out;
|
v_out = v_in = *value_out;
|
||||||
while (*v_in) {
|
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;
|
v_in += 2;
|
||||||
} else {
|
} else {
|
||||||
*v_out++ = *v_in++;
|
*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';
|
*v_out = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*line == '#') {
|
if (*line == '#') {
|
||||||
|
@ -1752,7 +1752,8 @@ circuit_deliver_create_cell(circuit_t *circ, uint8_t cell_type,
|
|||||||
cell.circ_id = circ->n_circ_id;
|
cell.circ_id = circ->n_circ_id;
|
||||||
|
|
||||||
memcpy(cell.payload, payload, ONIONSKIN_CHALLENGE_LEN);
|
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)) {
|
if (CIRCUIT_IS_ORIGIN(circ)) {
|
||||||
/* mark it so it gets better rate limiting treatment. */
|
/* mark it so it gets better rate limiting treatment. */
|
||||||
|
@ -2446,3 +2446,4 @@ circuit_queue_streams_are_blocked(circuit_t *circ)
|
|||||||
return circ->streams_blocked_on_p_conn;
|
return circ->streams_blocked_on_p_conn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,6 +103,8 @@ test_util_config_line(void)
|
|||||||
"k9 a line that\\\n spans two lines.\n\n"
|
"k9 a line that\\\n spans two lines.\n\n"
|
||||||
"k10 more than\\\n one contin\\\nuation\n"
|
"k10 more than\\\n one contin\\\nuation\n"
|
||||||
"k11 \\\ncontinuation at the start\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));
|
, sizeof(buf));
|
||||||
str = buf;
|
str = buf;
|
||||||
|
|
||||||
@ -180,6 +182,16 @@ test_util_config_line(void)
|
|||||||
test_streq(v, "continuation at the start");
|
test_streq(v, "continuation at the start");
|
||||||
tor_free(k); tor_free(v);
|
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, "");
|
test_streq(str, "");
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
Loading…
Reference in New Issue
Block a user