mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-01 08:03:31 +01:00
Stop reversing and re-reversing config lines: keep them in order all the time. Removes needless confusion and fixes bug #50.
svn:r3305
This commit is contained in:
parent
2e8f15a567
commit
b4fedc7f14
@ -173,6 +173,8 @@ static config_var_t config_vars[] = {
|
|||||||
/** Largest allowed config line */
|
/** Largest allowed config line */
|
||||||
#define CONFIG_LINE_T_MAXLEN 4096
|
#define CONFIG_LINE_T_MAXLEN 4096
|
||||||
|
|
||||||
|
static void config_line_append(struct config_line_t **lst,
|
||||||
|
const char *key, const char *val);
|
||||||
static void option_reset(or_options_t *options, config_var_t *var);
|
static void option_reset(or_options_t *options, config_var_t *var);
|
||||||
static void options_free(or_options_t *options);
|
static void options_free(or_options_t *options);
|
||||||
static int option_is_same(or_options_t *o1, or_options_t *o2,const char *name);
|
static int option_is_same(or_options_t *o1, or_options_t *o2,const char *name);
|
||||||
@ -421,9 +423,9 @@ config_get_commandlines(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Helper: allocate a new configuration option mapping 'key' to 'val',
|
/** Helper: allocate a new configuration option mapping 'key' to 'val',
|
||||||
* prepend it to 'front', and return the newly allocated config_line_t */
|
* append it to *<b>lst</b>. */
|
||||||
struct config_line_t *
|
static void
|
||||||
config_line_prepend(struct config_line_t *front,
|
config_line_append(struct config_line_t **lst,
|
||||||
const char *key,
|
const char *key,
|
||||||
const char *val)
|
const char *val)
|
||||||
{
|
{
|
||||||
@ -432,8 +434,11 @@ config_line_prepend(struct config_line_t *front,
|
|||||||
newline = tor_malloc(sizeof(struct config_line_t));
|
newline = tor_malloc(sizeof(struct config_line_t));
|
||||||
newline->key = tor_strdup(key);
|
newline->key = tor_strdup(key);
|
||||||
newline->value = tor_strdup(val);
|
newline->value = tor_strdup(val);
|
||||||
newline->next = front;
|
newline->next = NULL;
|
||||||
return newline;
|
while (*lst)
|
||||||
|
lst = &((*lst)->next);
|
||||||
|
|
||||||
|
(*lst) = newline;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Helper: parse the config string and strdup into key/value
|
/** Helper: parse the config string and strdup into key/value
|
||||||
@ -443,17 +448,26 @@ config_line_prepend(struct config_line_t *front,
|
|||||||
int
|
int
|
||||||
config_get_lines(char *string, struct config_line_t **result)
|
config_get_lines(char *string, struct config_line_t **result)
|
||||||
{
|
{
|
||||||
struct config_line_t *list = NULL;
|
struct config_line_t *list = NULL, **next;
|
||||||
char *k, *v;
|
char *k, *v;
|
||||||
|
|
||||||
|
next = &list;
|
||||||
do {
|
do {
|
||||||
string = parse_line_from_str(string, &k, &v);
|
string = parse_line_from_str(string, &k, &v);
|
||||||
if (!string) {
|
if (!string) {
|
||||||
config_free_lines(list);
|
config_free_lines(list);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (k && v)
|
if (k && v) {
|
||||||
list = config_line_prepend(list, k, v);
|
/* This list can get long, so we keep a pointer to the end of it
|
||||||
|
* rather than using config_line_append over and over and getting n^2
|
||||||
|
* performance. This is the only really long list. */
|
||||||
|
*next = tor_malloc(sizeof(struct config_line_t));
|
||||||
|
(*next)->key = tor_strdup(k);
|
||||||
|
(*next)->value = tor_strdup(v);
|
||||||
|
(*next)->next = NULL;
|
||||||
|
next = &((*next)->next);
|
||||||
|
}
|
||||||
} while (*string);
|
} while (*string);
|
||||||
|
|
||||||
*result = list;
|
*result = list;
|
||||||
@ -596,11 +610,7 @@ config_assign_line(or_options_t *options, struct config_line_t *c, int reset)
|
|||||||
|
|
||||||
case CONFIG_TYPE_LINELIST:
|
case CONFIG_TYPE_LINELIST:
|
||||||
case CONFIG_TYPE_LINELIST_S:
|
case CONFIG_TYPE_LINELIST_S:
|
||||||
/* Note: this reverses the order that the lines appear in. That's
|
config_line_append((struct config_line_t**)lvalue, c->key, c->value);
|
||||||
* just fine, since we build up the list of lines reversed in the
|
|
||||||
* first place. */
|
|
||||||
*(struct config_line_t**)lvalue =
|
|
||||||
config_line_prepend(*(struct config_line_t**)lvalue, c->key, c->value);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CONFIG_TYPE_OBSOLETE:
|
case CONFIG_TYPE_OBSOLETE:
|
||||||
@ -857,13 +867,13 @@ static void
|
|||||||
add_default_trusted_dirservers(or_options_t *options)
|
add_default_trusted_dirservers(or_options_t *options)
|
||||||
{
|
{
|
||||||
/* moria1 */
|
/* moria1 */
|
||||||
options->DirServers = config_line_prepend(options->DirServers, "DirServer",
|
config_line_append(&options->DirServers, "DirServer",
|
||||||
"18.244.0.188:9031 FFCB 46DB 1339 DA84 674C 70D7 CB58 6434 C437 0441");
|
"18.244.0.188:9031 FFCB 46DB 1339 DA84 674C 70D7 CB58 6434 C437 0441");
|
||||||
/* moria2 */
|
/* moria2 */
|
||||||
options->DirServers = config_line_prepend(options->DirServers, "DirServer",
|
config_line_append(&options->DirServers, "DirServer",
|
||||||
"18.244.0.114:80 719B E45D E224 B607 C537 07D0 E214 3E2D 423E 74CF");
|
"18.244.0.114:80 719B E45D E224 B607 C537 07D0 E214 3E2D 423E 74CF");
|
||||||
/* tor26 */
|
/* tor26 */
|
||||||
options->DirServers = config_line_prepend(options->DirServers, "DirServer",
|
config_line_append(&options->DirServers, "DirServer",
|
||||||
"62.116.124.106:9030 847B 1F85 0344 D787 6491 A548 92F9 0493 4E4E B85D");
|
"62.116.124.106:9030 847B 1F85 0344 D787 6491 A548 92F9 0493 4E4E B85D");
|
||||||
// "tor.noreply.org:9030 847B 1F85 0344 D787 6491 A548 92F9 0493 4E4E B85D");
|
// "tor.noreply.org:9030 847B 1F85 0344 D787 6491 A548 92F9 0493 4E4E B85D");
|
||||||
}
|
}
|
||||||
@ -1181,7 +1191,7 @@ options_validate(or_options_t *options)
|
|||||||
|
|
||||||
/* Special case if no options are given. */
|
/* Special case if no options are given. */
|
||||||
if (!options->Logs) {
|
if (!options->Logs) {
|
||||||
options->Logs = config_line_prepend(NULL, "Log", "notice stdout");
|
config_line_append(&options->Logs, "Log", "notice stdout");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_init_logs(options, 1)<0) /* Validate the log(s) */
|
if (config_init_logs(options, 1)<0) /* Validate the log(s) */
|
||||||
@ -1925,7 +1935,7 @@ add_single_log_option(or_options_t *options, int minSeverity, int maxSeverity,
|
|||||||
}
|
}
|
||||||
|
|
||||||
log(LOG_WARN, "The old LogLevel/LogFile/DebugLogFile/SysLog options are deprecated, and will go away soon. Your new torrc line should be: 'Log %s'", buf);
|
log(LOG_WARN, "The old LogLevel/LogFile/DebugLogFile/SysLog options are deprecated, and will go away soon. Your new torrc line should be: 'Log %s'", buf);
|
||||||
options->Logs = config_line_prepend(options->Logs, "Log", buf);
|
config_line_append(&options->Logs, "Log", buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1130,8 +1130,6 @@ void addr_policy_free(addr_policy_t *p);
|
|||||||
int config_option_is_recognized(const char *key);
|
int config_option_is_recognized(const char *key);
|
||||||
struct config_line_t *config_get_assigned_option(or_options_t *options,
|
struct config_line_t *config_get_assigned_option(or_options_t *options,
|
||||||
const char *key);
|
const char *key);
|
||||||
struct config_line_t *config_line_prepend(struct config_line_t *front,
|
|
||||||
const char *key, const char *val);
|
|
||||||
char *config_dump_options(or_options_t *options, int minimal);
|
char *config_dump_options(or_options_t *options, int minimal);
|
||||||
int save_current_config(void);
|
int save_current_config(void);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user