summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/core.c1
-rw-r--r--src/core/modules.c1
-rw-r--r--src/core/settings.c198
-rw-r--r--src/core/settings.h9
-rw-r--r--src/fe-common/core/fe-common-core.c2
-rw-r--r--src/fe-common/core/fe-settings.c10
-rw-r--r--src/fe-common/irc/fe-common-irc.c5
-rw-r--r--src/fe-text/irssi.c3
-rw-r--r--src/irc/core/irc-servers-setup.c15
9 files changed, 196 insertions, 48 deletions
diff --git a/src/core/core.c b/src/core/core.c
index fab78fa4..804c6ba7 100644
--- a/src/core/core.c
+++ b/src/core/core.c
@@ -71,6 +71,7 @@ void core_init(void)
nicklist_init();
chat_commands_init();
+ settings_check();
}
void core_deinit(void)
diff --git a/src/core/modules.c b/src/core/modules.c
index e45a05b5..8696b973 100644
--- a/src/core/modules.c
+++ b/src/core/modules.c
@@ -305,6 +305,7 @@ static int module_load_name(const char *path, const char *name)
modules = g_slist_append(modules, rec);
module_init();
+ settings_check_module(name);
signal_emit("module loaded", 1, rec);
return TRUE;
diff --git a/src/core/settings.c b/src/core/settings.c
index fbf46164..5baf7a70 100644
--- a/src/core/settings.c
+++ b/src/core/settings.c
@@ -31,8 +31,11 @@
CONFIG_REC *mainconfig;
+static GString *last_errors;
+static char *last_config_error_msg;
+static int fe_initialized;
+
static GHashTable *settings;
-static char *last_error_msg;
static int timeout_tag;
static int config_last_modifycounter;
@@ -40,7 +43,7 @@ static time_t config_last_mtime;
static long config_last_size;
static unsigned int config_last_checksum;
-static const char *settings_get_default_str(const char *key)
+static SETTINGS_REC *settings_find(const char *key)
{
SETTINGS_REC *rec;
@@ -53,39 +56,62 @@ static const char *settings_get_default_str(const char *key)
return NULL;
}
- return rec->def;
+ return rec;
}
-static int settings_get_default_int(const char *key)
+const char *settings_get_str(const char *key)
{
SETTINGS_REC *rec;
+ CONFIG_NODE *setnode, *node;
- g_return_val_if_fail(key != NULL, -1);
+ rec = settings_find(key);
+ g_return_val_if_fail(rec != NULL, NULL);
- rec = g_hash_table_lookup(settings, key);
- if (rec == NULL) {
- g_warning("settings_get_default_int(%s) : "
- "unknown setting", key);
- return -1;
- }
+ setnode = iconfig_node_traverse("settings", FALSE);
+ if (setnode == NULL)
+ return rec->def;
- return GPOINTER_TO_INT(rec->def);
-}
-
-const char *settings_get_str(const char *key)
-{
- return iconfig_get_str("settings", key, settings_get_default_str(key));
+ node = config_node_section(setnode, rec->module, -1);
+ return node == NULL ? rec->def :
+ config_node_get_str(node, key, rec->def);
}
int settings_get_int(const char *key)
{
- return iconfig_get_int("settings", key, settings_get_default_int(key));
+ SETTINGS_REC *rec;
+ CONFIG_NODE *setnode, *node;
+ int def;
+
+ rec = settings_find(key);
+ g_return_val_if_fail(rec != NULL, 0);
+ def = GPOINTER_TO_INT(rec->def);
+
+ setnode = iconfig_node_traverse("settings", FALSE);
+ if (setnode == NULL)
+ return def;
+
+ node = config_node_section(setnode, rec->module, -1);
+ return node == NULL ? def :
+ config_node_get_int(node, key, def);
}
int settings_get_bool(const char *key)
{
- return iconfig_get_bool("settings", key,
- settings_get_default_int(key));
+ SETTINGS_REC *rec;
+ CONFIG_NODE *setnode, *node;
+ int def;
+
+ rec = settings_find(key);
+ g_return_val_if_fail(rec != NULL, 0);
+ def = GPOINTER_TO_INT(rec->def);
+
+ setnode = iconfig_node_traverse("settings", FALSE);
+ if (setnode == NULL)
+ return def;
+
+ node = config_node_section(setnode, rec->module, -1);
+ return node == NULL ? def :
+ config_node_get_bool(node, key, def);
}
void settings_add_str_module(const char *module, const char *section,
@@ -191,6 +217,35 @@ void settings_remove_module(const char *module)
(void *) module);
}
+static CONFIG_NODE *settings_get_node(const char *key)
+{
+ SETTINGS_REC *rec;
+ CONFIG_NODE *node;
+
+ g_return_val_if_fail(key != NULL, NULL);
+
+ rec = g_hash_table_lookup(settings, key);
+ g_return_val_if_fail(rec != NULL, NULL);
+
+ node = iconfig_node_traverse("settings", TRUE);
+ return config_node_section(node, rec->module, NODE_TYPE_BLOCK);
+}
+
+void settings_set_str(const char *key, const char *value)
+{
+ iconfig_node_set_str(settings_get_node(key), key, value);
+}
+
+void settings_set_int(const char *key, int value)
+{
+ iconfig_node_set_int(settings_get_node(key), key, value);
+}
+
+void settings_set_bool(const char *key, int value)
+{
+ iconfig_node_set_bool(settings_get_node(key), key, value);
+}
+
int settings_get_type(const char *key)
{
SETTINGS_REC *rec;
@@ -209,6 +264,89 @@ SETTINGS_REC *settings_get_record(const char *key)
return g_hash_table_lookup(settings, key);
}
+static void sig_init_finished(void)
+{
+ fe_initialized = TRUE;
+ if (last_errors != NULL) {
+ signal_emit("gui dialog", 2, "error", last_errors->str);
+ g_string_free(last_errors, TRUE);
+ }
+
+ if (last_config_error_msg != NULL) {
+ signal_emit("gui dialog", 2, "error", last_config_error_msg);
+ g_free_and_null(last_config_error_msg);
+ }
+}
+
+/* FIXME: remove after 0.7.98 - only for backward compatibility */
+static void settings_move(SETTINGS_REC *rec, char *value)
+{
+ CONFIG_NODE *setnode, *node;
+
+ setnode = iconfig_node_traverse("settings", TRUE);
+ node = config_node_section(setnode, rec->module, NODE_TYPE_BLOCK);
+
+ iconfig_node_set_str(node, rec->key, value);
+ iconfig_node_set_str(setnode, rec->key, NULL);
+}
+
+/* verify that all settings in config file for `module' are actually found
+ from /SET list */
+void settings_check_module(const char *module)
+{
+ SETTINGS_REC *set;
+ CONFIG_NODE *node;
+ GString *errors;
+ GSList *tmp, *next;
+ int count;
+
+ g_return_if_fail(module != NULL);
+
+ node = iconfig_node_traverse("settings", TRUE);
+ if (node != NULL) {
+ /* FIXME: remove after 0.7.98 */
+ for (tmp = node->value; tmp != NULL; tmp = next) {
+ CONFIG_NODE *node = tmp->data;
+
+ next = tmp->next;
+ if (node->type != NODE_TYPE_KEY)
+ continue;
+ set = g_hash_table_lookup(settings, node->key);
+ if (set != NULL)
+ settings_move(set, node->value);
+ }
+ }
+ node = node == NULL ? NULL : config_node_section(node, module, -1);
+ if (node == NULL) return;
+
+ errors = g_string_new(NULL);
+ g_string_sprintf(errors, "Unknown settings in configuration "
+ "file for module %s:", module);
+
+ count = 0;
+ for (tmp = node->value; tmp != NULL; tmp = tmp->next) {
+ node = tmp->data;
+
+ set = g_hash_table_lookup(settings, node->key);
+ if (set == NULL || strcmp(set->module, module) != 0) {
+ g_string_sprintfa(errors, " %s", node->key);
+ count++;
+ }
+ }
+ if (count > 0) {
+ if (fe_initialized)
+ signal_emit("gui dialog", 2, "error", errors->str);
+ else {
+ if (last_errors == NULL)
+ last_errors = g_string_new(NULL);
+ else
+ g_string_append_c(last_errors, '\n');
+ g_string_append(last_errors, errors->str);
+ }
+ }
+ g_string_free(errors, TRUE);
+}
+
static int settings_compare(SETTINGS_REC *v1, SETTINGS_REC *v2)
{
return strcmp(v1->section, v2->section);
@@ -321,15 +459,6 @@ static CONFIG_REC *parse_configfile(const char *fname)
return config;
}
-static void sig_print_config_error(void)
-{
- signal_emit("gui dialog", 2, "error", last_error_msg);
- signal_remove("irssi init finished",
- (SIGNAL_FUNC) sig_print_config_error);
-
- g_free_and_null(last_error_msg);
-}
-
static void init_configfile(void)
{
struct stat statbuf;
@@ -354,12 +483,10 @@ static void init_configfile(void)
/* any errors? */
if (config_last_error(mainconfig) != NULL) {
- last_error_msg =
+ last_config_error_msg =
g_strdup_printf(_("Ignored errors in configuration "
"file:\n%s"),
config_last_error(mainconfig));
- signal_add("irssi init finished",
- (SIGNAL_FUNC) sig_print_config_error);
}
signal(SIGTERM, sig_term);
@@ -450,12 +577,17 @@ void settings_init(void)
settings = g_hash_table_new((GHashFunc) g_str_hash,
(GCompareFunc) g_str_equal);
+ last_errors = NULL;
+ last_config_error_msg = NULL;
+ fe_initialized = FALSE;
+
config_last_mtime = 0;
config_last_modifycounter = 0;
init_configfile();
settings_add_bool("misc", "settings_autosave", TRUE);
timeout_tag = g_timeout_add(1000*60*60, (GSourceFunc) sig_autosave, NULL);
+ signal_add("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
signal_add("gui exit", (SIGNAL_FUNC) sig_autosave);
}
@@ -467,9 +599,9 @@ static void settings_hash_free(const char *key, SETTINGS_REC *rec)
void settings_deinit(void)
{
g_source_remove(timeout_tag);
+ signal_remove("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
signal_remove("gui exit", (SIGNAL_FUNC) sig_autosave);
- g_free_not_null(last_error_msg);
g_hash_table_foreach(settings, (GHFunc) settings_hash_free, NULL);
g_hash_table_destroy(settings);
diff --git a/src/core/settings.h b/src/core/settings.h
index bd4c5b94..a878fcfb 100644
--- a/src/core/settings.h
+++ b/src/core/settings.h
@@ -62,6 +62,10 @@ void settings_remove_module(const char *module);
#define settings_add_bool(section, key, def) \
settings_add_bool_module(MODULE_NAME, section, key, def)
+void settings_set_str(const char *key, const char *value);
+void settings_set_int(const char *key, int value);
+void settings_set_bool(const char *key, int value);
+
/* Get the type (SETTING_TYPE_xxx) of `key' */
int settings_get_type(const char *key);
/* Get all settings sorted by section. Free the result with g_slist_free() */
@@ -69,6 +73,11 @@ GSList *settings_get_sorted(void);
/* Get the record of the setting */
SETTINGS_REC *settings_get_record(const char *key);
+/* verify that all settings in config file for `module' are actually found
+ from /SET list */
+void settings_check_module(const char *module);
+#define settings_check() settings_check_module(MODULE_NAME)
+
/* if `fname' is NULL, the default is used */
int settings_reread(const char *fname);
int settings_save(const char *fname);
diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c
index aa099401..2b524dce 100644
--- a/src/fe-common/core/fe-common-core.c
+++ b/src/fe-common/core/fe-common-core.c
@@ -128,6 +128,8 @@ void fe_common_core_init(void)
fe_messages_init();
fe_ignore_messages_init();
+
+ settings_check();
}
void fe_common_core_deinit(void)
diff --git a/src/fe-common/core/fe-settings.c b/src/fe-common/core/fe-settings.c
index 8bb09a72..a4abc7b8 100644
--- a/src/fe-common/core/fe-settings.c
+++ b/src/fe-common/core/fe-settings.c
@@ -55,11 +55,11 @@ static void set_print(SETTINGS_REC *rec)
static void set_boolean(const char *key, const char *value)
{
if (g_strcasecmp(value, "ON") == 0)
- iconfig_set_bool("settings", key, TRUE);
+ settings_set_bool(key, TRUE);
else if (g_strcasecmp(value, "OFF") == 0)
- iconfig_set_bool("settings", key, FALSE);
+ settings_set_bool(key, FALSE);
else if (g_strcasecmp(value, "TOGGLE") == 0)
- iconfig_set_bool("settings", key, !settings_get_bool(key));
+ settings_set_bool(key, !settings_get_bool(key));
else
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_NOT_TOGGLE);
}
@@ -102,10 +102,10 @@ static void cmd_set(char *data)
set_boolean(key, clear ? FALSE : value);
break;
case SETTING_TYPE_INT:
- iconfig_set_int("settings", key, clear ? 0 : atoi(value));
+ settings_set_int(key, clear ? 0 : atoi(value));
break;
case SETTING_TYPE_STRING:
- iconfig_set_str("settings", key, clear ? "" : value);
+ settings_set_str(key, clear ? "" : value);
break;
}
signal_emit("setup changed", 0);
diff --git a/src/fe-common/irc/fe-common-irc.c b/src/fe-common/irc/fe-common-irc.c
index 2c26a44e..e3d23556 100644
--- a/src/fe-common/irc/fe-common-irc.c
+++ b/src/fe-common/irc/fe-common-irc.c
@@ -110,6 +110,7 @@ void fe_common_irc_init(void)
fe_netjoin_init();
fe_irc_modules_init();
+ settings_check();
}
void fe_common_irc_deinit(void)
@@ -138,12 +139,12 @@ void fe_common_irc_finish_init(void)
if (cmdline_nick != NULL) {
/* override nick found from setup */
- iconfig_set_str("settings", "nick", cmdline_nick);
+ settings_set_str("nick", cmdline_nick);
}
if (cmdline_hostname != NULL) {
/* override host name found from setup */
- iconfig_set_str("settings", "hostname", cmdline_hostname);
+ settings_set_str("hostname", cmdline_hostname);
}
if (autocon_server != NULL) {
diff --git a/src/fe-text/irssi.c b/src/fe-text/irssi.c
index a7e91274..9d8f3603 100644
--- a/src/fe-text/irssi.c
+++ b/src/fe-text/irssi.c
@@ -24,6 +24,7 @@
#include "signals.h"
#include "levels.h"
#include "core.h"
+#include "settings.h"
#include "printtext.h"
#include "fe-common-core.h"
@@ -124,6 +125,8 @@ static void textui_finish_init(void)
gui_windows_init();
statusbar_init();
+ settings_check();
+
fe_common_core_finish_init();
fe_common_irc_finish_init();
diff --git a/src/irc/core/irc-servers-setup.c b/src/irc/core/irc-servers-setup.c
index 4049eeda..ec07420e 100644
--- a/src/irc/core/irc-servers-setup.c
+++ b/src/irc/core/irc-servers-setup.c
@@ -95,16 +95,16 @@ static void init_userinfo(void)
set = settings_get_str("real_name");
if (set == NULL || *set == '\0') {
str = g_getenv("IRCNAME");
- iconfig_set_str("settings", "real_name",
- str != NULL ? str : g_get_real_name());
+ settings_set_str("real_name",
+ str != NULL ? str : g_get_real_name());
}
/* username */
user_name = settings_get_str("user_name");
if (user_name == NULL || *user_name == '\0') {
str = g_getenv("IRCUSER");
- iconfig_set_str("settings", "user_name",
- str != NULL ? str : g_get_user_name());
+ settings_set_str("user_name",
+ str != NULL ? str : g_get_user_name());
user_name = settings_get_str("user_name");
}
@@ -113,8 +113,7 @@ static void init_userinfo(void)
nick = settings_get_str("nick");
if (nick == NULL || *nick == '\0') {
str = g_getenv("IRCNICK");
- iconfig_set_str("settings", "nick",
- str != NULL ? str : user_name);
+ settings_set_str("nick", str != NULL ? str : user_name);
nick = settings_get_str("nick");
}
@@ -128,7 +127,7 @@ static void init_userinfo(void)
str = g_strdup(nick);
str[strlen(str)-1] = '_';
}
- iconfig_set_str("settings", "alternate_nick", str);
+ settings_set_str("alternate_nick", str);
g_free(str);
}
@@ -137,7 +136,7 @@ static void init_userinfo(void)
if (set == NULL || *set == '\0') {
str = g_getenv("IRCHOST");
if (str != NULL)
- iconfig_set_str("settings", "hostname", str);
+ settings_set_str("hostname", str);
}
}