[or-cvs] Backport fix for bug 50
Nick Mathewson
nickm at seul.org
Wed Jan 5 06:09:13 UTC 2005
Update of /home/or/cvsroot/tor/src/or
In directory moria.mit.edu:/tmp/cvs-serv13079
Modified Files:
Tag: tor-0_0_9-patches
config.c or.h
Log Message:
Backport fix for bug 50
Index: config.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/config.c,v
retrieving revision 1.286.2.2
retrieving revision 1.286.2.3
diff -u -d -r1.286.2.2 -r1.286.2.3
--- config.c 5 Jan 2005 02:58:05 -0000 1.286.2.2
+++ config.c 5 Jan 2005 06:09:09 -0000 1.286.2.3
@@ -173,6 +173,8 @@
/** Largest allowed config line */
#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 options_free(or_options_t *options);
static int option_is_same(or_options_t *o1, or_options_t *o2,const char *name);
@@ -423,19 +425,22 @@
}
/** Helper: allocate a new configuration option mapping 'key' to 'val',
- * prepend it to 'front', and return the newly allocated config_line_t */
-struct config_line_t *
-config_line_prepend(struct config_line_t *front,
- const char *key,
- const char *val)
+ * append it to *<b>lst</b>. */
+static void
+config_line_append(struct config_line_t **lst,
+ const char *key,
+ const char *val)
{
struct config_line_t *newline;
newline = tor_malloc(sizeof(struct config_line_t));
newline->key = tor_strdup(key);
newline->value = tor_strdup(val);
- newline->next = front;
- return newline;
+ newline->next = NULL;
+ while (*lst)
+ lst = &((*lst)->next);
+
+ (*lst) = newline;
}
/** Helper: parse the config string and strdup into key/value
@@ -445,17 +450,26 @@
int
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;
+ next = &list;
do {
string = parse_line_from_str(string, &k, &v);
if (!string) {
config_free_lines(list);
return -1;
}
- if (k && v)
- list = config_line_prepend(list, k, v);
+ if (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);
*result = list;
@@ -598,11 +612,7 @@
case CONFIG_TYPE_LINELIST:
case CONFIG_TYPE_LINELIST_S:
- /* Note: this reverses the order that the lines appear in. That's
- * 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);
+ config_line_append((struct config_line_t**)lvalue, c->key, c->value);
break;
case CONFIG_TYPE_OBSOLETE:
@@ -859,13 +869,13 @@
add_default_trusted_dirservers(or_options_t *options)
{
/* 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");
/* 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");
/* 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");
// "tor.noreply.org:9030 847B 1F85 0344 D787 6491 A548 92F9 0493 4E4E B85D");
}
@@ -1183,7 +1193,7 @@
/* Special case if no options are given. */
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) */
@@ -1670,6 +1680,7 @@
fname = fn;
} else {
tor_free(fn);
+#ifndef MS_WINDOWS
fn = expand_filename("~/.torrc");
if (fn && file_status(fn) == FN_FILE) {
fname = fn;
@@ -1677,13 +1688,16 @@
tor_free(fn);
fname = get_default_conf_file();
}
+#else
+ fname = get_default_conf_file();
+#endif
}
}
tor_assert(fname);
log(LOG_DEBUG, "Opening config file '%s'", fname);
- cf = read_file_to_str(fname, 0);
- if (!cf) {
+ if (file_status(fname) != FN_FILE ||
+ !(cf = read_file_to_str(fname,0))) {
if (using_default_torrc == 1) {
log(LOG_NOTICE, "Configuration file '%s' not present, "
"using reasonable defaults.", fname);
@@ -1918,7 +1932,7 @@
}
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;
}
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.508.2.4
retrieving revision 1.508.2.5
diff -u -d -r1.508.2.4 -r1.508.2.5
--- or.h 4 Jan 2005 01:11:08 -0000 1.508.2.4
+++ or.h 5 Jan 2005 06:09:10 -0000 1.508.2.5
@@ -1131,8 +1131,6 @@
int config_option_is_recognized(const char *key);
struct config_line_t *config_get_assigned_option(or_options_t *options,
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);
int save_current_config(void);
More information about the tor-commits
mailing list