X-Git-Url: http://git.maemo.org/git/?p=browser-switch;a=blobdiff_plain;f=config.c;h=7fe6874d1c86a1e1617a9ea0c6ae509158de6046;hp=289374b2b29eda998a1a80baca17a85554cfdaa1;hb=b9e875dc67dbb0b2be8c04f7c9aa44a5bb4f52b7;hpb=38de05f23e8556012be028c25f7a7a1571e34e1a diff --git a/config.c b/config.c index 289374b..7fe6874 100644 --- a/config.c +++ b/config.c @@ -39,7 +39,7 @@ struct swb_config_option swb_config_options[] = { /* Browser Switchboard configuration defaults */ static struct swb_config swb_config_defaults = { .flags = SWB_CONFIG_INITIALIZED, - .continuous_mode = 0, + .continuous_mode = 1, .default_browser = "microb", .other_browser_cmd = NULL, .logging = "stdout", @@ -73,22 +73,24 @@ void swb_config_init(struct swb_config *cfg) { /* Free all heap memory used in an swb_config struct This MUST NOT be done if any of the strings are being used elsewhere! */ void swb_config_free(struct swb_config *cfg) { + int i; + if (!cfg) return; if (!(cfg->flags & SWB_CONFIG_INITIALIZED)) return; - if (cfg->flags & SWB_CONFIG_DEFAULT_BROWSER_SET) { - free(cfg->default_browser); - cfg->default_browser = NULL; - } - if (cfg->flags & SWB_CONFIG_OTHER_BROWSER_CMD_SET) { - free(cfg->other_browser_cmd); - cfg->other_browser_cmd = NULL; - } - if (cfg->flags & SWB_CONFIG_LOGGING_SET) { - free(cfg->logging); - cfg->logging = NULL; + for (i = 0; swb_config_options[i].name; ++i) { + if (cfg->flags & swb_config_options[i].set_mask) { + switch (swb_config_options[i].type) { + case SWB_CONFIG_OPT_STRING: + free(*(char **)cfg->entries[i]); + *(char **)cfg->entries[i] = NULL; + break; + default: + break; + } + } } cfg->flags = 0; @@ -99,8 +101,8 @@ static int swb_config_load_option(struct swb_config *cfg, char *name, char *value) { struct swb_config_option *opt; ptrdiff_t i; - int retval = 0; + /* Search through list of recognized config options for a match */ for (opt = swb_config_options; opt->name; ++opt) { if (strcmp(name, opt->name)) continue; @@ -117,15 +119,17 @@ static int swb_config_load_option(struct swb_config *cfg, break; } cfg->flags |= opt->set_mask; + } else { + /* Option was repeated in the config file + We want the first value, so ignore this one */ + free(value); } - retval = 1; - break; + return 1; } - if (!retval) - free(value); - - return retval; + /* Unrecognized config option */ + free(value); + return 0; } /* Read the config file and load settings into the provided swb_config struct