if you give a config option in the torrc or the commandline with no

value, and reset is false, then it clears it entirely.


svn:r4926
This commit is contained in:
Roger Dingledine 2005-09-08 06:55:53 +00:00
parent 36fa360c11
commit 74fb086210

View File

@ -770,8 +770,11 @@ config_assign_line(config_format_t *fmt,
c->key = tor_strdup(var->name); c->key = tor_strdup(var->name);
} }
if (reset && !strlen(c->value)) { if (!strlen(c->value)) { /* reset or clear it, then return */
if (reset)
option_reset(fmt, options, var); option_reset(fmt, options, var);
else
option_clear(fmt, options, var);
return 0; return 0;
} }
@ -1012,8 +1015,10 @@ get_assigned_option(config_format_t *fmt, or_options_t *options, const char *key
* *
* If <b>reset</b>, then interpret empty lines as meaning "restore to * If <b>reset</b>, then interpret empty lines as meaning "restore to
* default value", and interpret LINELIST* options as replacing (not * default value", and interpret LINELIST* options as replacing (not
* extending) their previous values. Return 0 on success, -1 on bad key, * extending) their previous values. Otherwise, interpret empty lines
* -2 on bad value. * as meaning "make the value 0 or null".
*
* Return 0 on success, -1 on bad key, -2 on bad value.
*/ */
static int static int
config_assign(config_format_t *fmt, config_assign(config_format_t *fmt,
@ -1080,17 +1085,12 @@ options_trial_assign(config_line_t *list, int reset)
return 0; return 0;
} }
/** Replace the option indexed by <b>var</b> in <b>options</b> with its /** Reset config option <b>var</b> to 0, 0.0, "", or the equivalent. */
* default value. */
static void static void
option_reset(config_format_t *fmt, or_options_t *options, config_var_t *var) option_clear(config_format_t *fmt, or_options_t *options, config_var_t *var)
{ {
config_line_t *c; config_line_t *c;
void *lvalue; void *lvalue = ((char*)options) + var->var_offset;
CHECK(fmt, options);
lvalue = ((char*)options) + var->var_offset;
switch (var->type) { switch (var->type) {
case CONFIG_TYPE_STRING: case CONFIG_TYPE_STRING:
tor_free(*(char**)lvalue); tor_free(*(char**)lvalue);
@ -1126,6 +1126,17 @@ option_reset(config_format_t *fmt, or_options_t *options, config_var_t *var)
case CONFIG_TYPE_OBSOLETE: case CONFIG_TYPE_OBSOLETE:
break; break;
} }
/** Replace the option indexed by <b>var</b> in <b>options</b> with its
* default value. */
static void
option_reset(config_format_t *fmt, or_options_t *options, config_var_t *var)
{
config_line_t *c;
void *lvalue;
CHECK(fmt, options);
option_clear(fmt, options, var); /* clear it first */
lvalue = ((char*)options) + var->var_offset;
if (var->initvalue) { if (var->initvalue) {
c = tor_malloc_zero(sizeof(config_line_t)); c = tor_malloc_zero(sizeof(config_line_t));
c->key = tor_strdup(var->name); c->key = tor_strdup(var->name);