mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 06:13:31 +01:00
r12213@Kushana: nickm | 2007-02-10 16:25:39 -0500
Refactor setconf implementation to be a little slower, but far less error prone. svn:r9549
This commit is contained in:
parent
2c521d9804
commit
24e7b9b983
@ -802,40 +802,55 @@ control_setconf_helper(control_connection_t *conn, uint32_t len, char *body,
|
|||||||
int v0 = STATE_IS_V0(conn->_base.state);
|
int v0 = STATE_IS_V0(conn->_base.state);
|
||||||
|
|
||||||
if (!v0) {
|
if (!v0) {
|
||||||
char *config = tor_malloc(len+1);
|
char *config;
|
||||||
char *outp = config;
|
smartlist_t *entries = smartlist_create();
|
||||||
|
/* We have a string, "body", of the format '(key(=val|="val")?)' entries
|
||||||
|
* separated by space. break it into a list of configuration entries. */
|
||||||
while (*body) {
|
while (*body) {
|
||||||
char *eq = body;
|
char *eq = body;
|
||||||
|
char *key;
|
||||||
|
char *entry;
|
||||||
while (!TOR_ISSPACE(*eq) && *eq != '=')
|
while (!TOR_ISSPACE(*eq) && *eq != '=')
|
||||||
++eq;
|
++eq;
|
||||||
memcpy(outp, body, eq-body);
|
key = tor_strndup(body, eq-body);
|
||||||
outp += (eq-body);
|
|
||||||
body = eq+1;
|
body = eq+1;
|
||||||
if (*eq == '=') {
|
if (*eq == '=') {
|
||||||
*outp++ = ' ';
|
|
||||||
if (*body != '\"') {
|
|
||||||
while (!TOR_ISSPACE(*body))
|
|
||||||
*outp++ = *body++;
|
|
||||||
} else {
|
|
||||||
char *val;
|
char *val;
|
||||||
size_t val_len;
|
size_t val_len;
|
||||||
|
size_t ent_len;
|
||||||
|
if (*body != '\"') {
|
||||||
|
char *val_start = body;
|
||||||
|
while (!TOR_ISSPACE(*body))
|
||||||
|
body++;
|
||||||
|
val = tor_strndup(val_start, body-val_start);
|
||||||
|
val_len = strlen(val);
|
||||||
|
} else {
|
||||||
body = (char*)get_escaped_string(body, (len - (body-start)),
|
body = (char*)get_escaped_string(body, (len - (body-start)),
|
||||||
&val, &val_len);
|
&val, &val_len);
|
||||||
if (!body) {
|
if (!body) {
|
||||||
connection_write_str_to_buf("551 Couldn't parse string\r\n", conn);
|
connection_write_str_to_buf("551 Couldn't parse string\r\n", conn);
|
||||||
tor_free(config);
|
SMARTLIST_FOREACH(entries, char *, cp, tor_free(cp));
|
||||||
|
smartlist_free(entries);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memcpy(outp, val, val_len);
|
}
|
||||||
outp += val_len;
|
ent_len = strlen(key)+val_len+3;
|
||||||
|
entry = tor_malloc(ent_len+1);
|
||||||
|
tor_snprintf(entry, ent_len, "%s %s", key, val);
|
||||||
|
tor_free(key);
|
||||||
tor_free(val);
|
tor_free(val);
|
||||||
|
} else {
|
||||||
|
entry = key;
|
||||||
}
|
}
|
||||||
}
|
smartlist_add(entries, entry);
|
||||||
while (TOR_ISSPACE(*body))
|
while (TOR_ISSPACE(*body))
|
||||||
++body;
|
++body;
|
||||||
*outp++ = '\n';
|
|
||||||
}
|
}
|
||||||
*outp = '\0';
|
|
||||||
|
smartlist_add(entries, tor_strdup(""));
|
||||||
|
config = smartlist_join_strings(entries, "\n", 0, NULL);
|
||||||
|
SMARTLIST_FOREACH(entries, char *, cp, tor_free(cp));
|
||||||
|
smartlist_free(entries);
|
||||||
|
|
||||||
if (config_get_lines(config, &lines) < 0) {
|
if (config_get_lines(config, &lines) < 0) {
|
||||||
log_warn(LD_CONTROL,"Controller gave us config lines we can't parse.");
|
log_warn(LD_CONTROL,"Controller gave us config lines we can't parse.");
|
||||||
|
Loading…
Reference in New Issue
Block a user