X-Git-Url: http://git.maemo.org/git/?p=browser-switch;a=blobdiff_plain;f=config.c;h=2dcbfae26593ebaab7be61b098c01f67cf393f91;hp=727287fd3632cd27abc9a931e4e28c0600e0338c;hb=refs%2Ftags%2Ffremantle-package-3.3-2fremantle2;hpb=477b01a24f842c98e8abac56e3fe2ffb3d3a56db diff --git a/config.c b/config.c index 727287f..2dcbfae 100644 --- a/config.c +++ b/config.c @@ -21,6 +21,7 @@ */ #include +#include #include #include "configfile.h" @@ -32,16 +33,18 @@ struct swb_config_option swb_config_options[] = { { "default_browser", SWB_CONFIG_OPT_STRING, SWB_CONFIG_DEFAULT_BROWSER_SET }, { "other_browser_cmd", SWB_CONFIG_OPT_STRING, SWB_CONFIG_OTHER_BROWSER_CMD_SET }, { "logging", SWB_CONFIG_OPT_STRING, SWB_CONFIG_LOGGING_SET }, + { "autostart_microb", SWB_CONFIG_OPT_INT, SWB_CONFIG_AUTOSTART_MICROB_SET }, { NULL, 0, 0 }, }; /* 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", + .autostart_microb = -1, }; @@ -55,6 +58,7 @@ void swb_config_copy(struct swb_config *dst, struct swb_config *src) { dst->entries[1] = &(dst->default_browser); dst->entries[2] = &(dst->other_browser_cmd); dst->entries[3] = &(dst->logging); + dst->entries[4] = &(dst->autostart_microb); dst->flags = src->flags; @@ -62,6 +66,7 @@ void swb_config_copy(struct swb_config *dst, struct swb_config *src) { dst->default_browser = src->default_browser; dst->other_browser_cmd = src->other_browser_cmd; dst->logging = src->logging; + dst->autostart_microb = src->autostart_microb; } /* Initialize a swb_config struct with configuration defaults */ @@ -72,22 +77,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; @@ -96,35 +103,37 @@ void swb_config_free(struct swb_config *cfg) { /* Load a value into the part of a struct swb_config indicated by name */ static int swb_config_load_option(struct swb_config *cfg, char *name, char *value) { - int i; - struct swb_config_option opt; - int retval = 0; + struct swb_config_option *opt; + ptrdiff_t i; - for (i = 0; swb_config_options[i].name; ++i) { - opt = swb_config_options[i]; - if (strcmp(name, opt.name)) + /* Search through list of recognized config options for a match */ + for (opt = swb_config_options; opt->name; ++opt) { + if (strcmp(name, opt->name)) continue; - if (!(cfg->flags & opt.set_mask)) { - switch (opt.type) { + if (!(cfg->flags & opt->set_mask)) { + i = opt - swb_config_options; + switch (opt->type) { case SWB_CONFIG_OPT_STRING: - *(char **)cfg->entries[i] = value; - break; + *(char **)cfg->entries[i] = value; + break; case SWB_CONFIG_OPT_INT: - *(int *)cfg->entries[i] = atoi(value); - free(value); - break; + *(int *)cfg->entries[i] = atoi(value); + free(value); + break; } - cfg->flags |= opt.set_mask; + 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