diff options
author | Alexander Færøy <ahf@0x90.dk> | 2015-04-17 21:23:03 +0200 |
---|---|---|
committer | Alexander Færøy <ahf@0x90.dk> | 2015-04-17 21:23:03 +0200 |
commit | eb0f09073cf15eb033f098d716006a9a1d67fdef (patch) | |
tree | 8b1d63dc022a99731f7ff285a805ce984abc75d7 /src/core | |
parent | 03be2861dcec9e8d088be6a0cae2848388923dab (diff) | |
parent | ee3eaa5428c7a574ad3d34602230f3168f204414 (diff) | |
download | irssi-eb0f09073cf15eb033f098d716006a9a1d67fdef.zip |
Merge pull request #199 from ailin-nemui/config-parser
Make config parser more robust
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/channels-setup.c | 2 | ||||
-rw-r--r-- | src/core/chatnets.c | 2 | ||||
-rw-r--r-- | src/core/ignore.c | 6 | ||||
-rw-r--r-- | src/core/log.c | 8 | ||||
-rw-r--r-- | src/core/servers-setup.c | 2 | ||||
-rw-r--r-- | src/core/session.c | 14 | ||||
-rw-r--r-- | src/core/settings.c | 14 | ||||
-rw-r--r-- | src/core/settings.h | 2 |
8 files changed, 26 insertions, 24 deletions
diff --git a/src/core/channels-setup.c b/src/core/channels-setup.c index e1289c23..b2d971dd 100644 --- a/src/core/channels-setup.c +++ b/src/core/channels-setup.c @@ -40,7 +40,7 @@ static void channel_setup_save(CHANNEL_SETUP_REC *channel) parentnode = iconfig_node_traverse("(channels", TRUE); node = config_node_nth(parentnode, index); if (node == NULL) - node = config_node_section(parentnode, NULL, NODE_TYPE_BLOCK); + node = iconfig_node_section(parentnode, NULL, NODE_TYPE_BLOCK); iconfig_node_clear(node); iconfig_node_set_str(node, "name", channel->name); diff --git a/src/core/chatnets.c b/src/core/chatnets.c index 3c794ab4..dd4d94b3 100644 --- a/src/core/chatnets.c +++ b/src/core/chatnets.c @@ -36,7 +36,7 @@ static void chatnet_config_save(CHATNET_REC *chatnet) CONFIG_NODE *node; node = iconfig_node_traverse("chatnets", TRUE); - node = config_node_section(node, chatnet->name, NODE_TYPE_BLOCK); + node = iconfig_node_section(node, chatnet->name, NODE_TYPE_BLOCK); iconfig_node_clear(node); iconfig_node_set_str(node, "type", chat_protocol_find_id(chatnet->chat_type)->name); diff --git a/src/core/ignore.c b/src/core/ignore.c index beca1427..e70b741b 100644 --- a/src/core/ignore.c +++ b/src/core/ignore.c @@ -263,7 +263,7 @@ static void ignore_set_config(IGNORE_REC *rec) return; node = iconfig_node_traverse("(ignores", TRUE); - node = config_node_section(node, NULL, NODE_TYPE_BLOCK); + node = iconfig_node_section(node, NULL, NODE_TYPE_BLOCK); if (rec->mask != NULL) iconfig_node_set_str(node, "mask", rec->mask); if (rec->level) { @@ -281,7 +281,7 @@ static void ignore_set_config(IGNORE_REC *rec) iconfig_node_set_str(node, "servertag", rec->servertag); if (rec->channels != NULL && *rec->channels != NULL) { - node = config_node_section(node, "channels", NODE_TYPE_LIST); + node = iconfig_node_section(node, "channels", NODE_TYPE_LIST); iconfig_node_add_list(node, rec->channels); } } @@ -436,7 +436,7 @@ static void read_ignores(void) rec->unignore_time = config_node_get_int(node, "unignore_time", 0); rec->servertag = g_strdup(config_node_get_str(node, "servertag", 0)); - node = config_node_section(node, "channels", -1); + node = iconfig_node_section(node, "channels", -1); if (node != NULL) rec->channels = config_node_get_list(node); ignore_init_rec(rec); diff --git a/src/core/log.c b/src/core/log.c index 35e42544..8306d2df 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -332,11 +332,11 @@ static void log_items_update_config(LOG_REC *log, CONFIG_NODE *parent) GSList *tmp; CONFIG_NODE *node; - parent = config_node_section(parent, "items", NODE_TYPE_LIST); + parent = iconfig_node_section(parent, "items", NODE_TYPE_LIST); for (tmp = log->items; tmp != NULL; tmp = tmp->next) { LOG_ITEM_REC *rec = tmp->data; - node = config_node_section(parent, NULL, NODE_TYPE_BLOCK); + node = iconfig_node_section(parent, NULL, NODE_TYPE_BLOCK); iconfig_node_set_str(node, "type", log_item_types[rec->type]); iconfig_node_set_str(node, "name", rec->name); iconfig_node_set_str(node, "server", rec->servertag); @@ -352,7 +352,7 @@ static void log_update_config(LOG_REC *log) return; node = iconfig_node_traverse("logs", TRUE); - node = config_node_section(node, log->fname, NODE_TYPE_BLOCK); + node = iconfig_node_section(node, log->fname, NODE_TYPE_BLOCK); if (log->autoopen) iconfig_node_set_bool(node, "auto_open", TRUE); @@ -544,7 +544,7 @@ static void log_read_config(void) signal_emit("log config read", 2, log, node); - node = config_node_section(node, "items", -1); + node = iconfig_node_section(node, "items", -1); if (node != NULL) log_items_read_config(node, log); diff --git a/src/core/servers-setup.c b/src/core/servers-setup.c index e88e85c7..90a447d4 100644 --- a/src/core/servers-setup.c +++ b/src/core/servers-setup.c @@ -433,7 +433,7 @@ static void server_setup_save(SERVER_SETUP_REC *rec) parentnode = iconfig_node_traverse("(servers", TRUE); node = config_node_nth(parentnode, index); if (node == NULL) - node = config_node_section(parentnode, NULL, NODE_TYPE_BLOCK); + node = iconfig_node_section(parentnode, NULL, NODE_TYPE_BLOCK); iconfig_node_clear(node); iconfig_node_set_str(node, "address", rec->address); diff --git a/src/core/session.c b/src/core/session.c index e49162b2..17d80076 100644 --- a/src/core/session.c +++ b/src/core/session.c @@ -92,7 +92,7 @@ static void cmd_upgrade(const char *data) static void session_save_nick(CHANNEL_REC *channel, NICK_REC *nick, CONFIG_REC *config, CONFIG_NODE *node) { - node = config_node_section(node, NULL, NODE_TYPE_BLOCK); + node = config_node_section(config, node, NULL, NODE_TYPE_BLOCK); config_node_set_str(config, node, "nick", nick->nick); config_node_set_bool(config, node, "op", nick->op); @@ -109,7 +109,7 @@ static void session_save_channel_nicks(CHANNEL_REC *channel, CONFIG_REC *config, { GSList *tmp, *nicks; - node = config_node_section(node, "nicks", NODE_TYPE_LIST); + node = config_node_section(config, node, "nicks", NODE_TYPE_LIST); nicks = nicklist_getnicks(channel); for (tmp = nicks; tmp != NULL; tmp = tmp->next) session_save_nick(channel, tmp->data, config, node); @@ -119,7 +119,7 @@ static void session_save_channel_nicks(CHANNEL_REC *channel, CONFIG_REC *config, static void session_save_channel(CHANNEL_REC *channel, CONFIG_REC *config, CONFIG_NODE *node) { - node = config_node_section(node, NULL, NODE_TYPE_BLOCK); + node = config_node_section(config, node, NULL, NODE_TYPE_BLOCK); config_node_set_str(config, node, "name", channel->name); config_node_set_str(config, node, "visible_name", channel->visible_name); @@ -138,7 +138,7 @@ static void session_save_server_channels(SERVER_REC *server, GSList *tmp; /* save channels */ - node = config_node_section(node, "channels", NODE_TYPE_LIST); + node = config_node_section(config, node, "channels", NODE_TYPE_LIST); for (tmp = server->channels; tmp != NULL; tmp = tmp->next) session_save_channel(tmp->data, config, node); } @@ -148,7 +148,7 @@ static void session_save_server(SERVER_REC *server, CONFIG_REC *config, { int handle; - node = config_node_section(node, NULL, NODE_TYPE_BLOCK); + node = config_node_section(config, node, NULL, NODE_TYPE_BLOCK); config_node_set_str(config, node, "chat_type", chat_protocol_find_id(server->chat_type)->name); @@ -188,7 +188,7 @@ static void session_restore_channel_nicks(CHANNEL_REC *channel, GSList *tmp; /* restore nicks */ - node = config_node_section(node, "nicks", -1); + node = config_node_section(NULL, node, "nicks", -1); if (node != NULL && node->type == NODE_TYPE_LIST) { tmp = config_node_first(node->value); for (; tmp != NULL; tmp = config_node_next(tmp)) { @@ -224,7 +224,7 @@ static void session_restore_server_channels(SERVER_REC *server, GSList *tmp; /* restore channels */ - node = config_node_section(node, "channels", -1); + node = config_node_section(NULL, node, "channels", -1); if (node != NULL && node->type == NODE_TYPE_LIST) { tmp = config_node_first(node->value); for (; tmp != NULL; tmp = config_node_next(tmp)) diff --git a/src/core/settings.c b/src/core/settings.c index 2c43fd10..b34a5766 100644 --- a/src/core/settings.c +++ b/src/core/settings.c @@ -77,7 +77,7 @@ settings_get_str_type(const char *key, SettingType type) if (rec == NULL) return NULL; node = iconfig_node_traverse("settings", FALSE); - node = node == NULL ? NULL : config_node_section(node, rec->module, -1); + node = node == NULL ? NULL : iconfig_node_section(node, rec->module, -1); return node == NULL ? rec->default_value.v_string : config_node_get_str(node, key, rec->default_value.v_string); @@ -97,7 +97,7 @@ int settings_get_int(const char *key) if (rec == NULL) return 0; node = iconfig_node_traverse("settings", FALSE); - node = node == NULL ? NULL : config_node_section(node, rec->module, -1); + node = node == NULL ? NULL : iconfig_node_section(node, rec->module, -1); return node == NULL ? rec->default_value.v_int : config_node_get_int(node, key, rec->default_value.v_int); @@ -112,7 +112,7 @@ int settings_get_bool(const char *key) if (rec == NULL) return FALSE; node = iconfig_node_traverse("settings", FALSE); - node = node == NULL ? NULL : config_node_section(node, rec->module, -1); + node = node == NULL ? NULL : iconfig_node_section(node, rec->module, -1); return node == NULL ? rec->default_value.v_bool : config_node_get_bool(node, key, rec->default_value.v_bool); @@ -324,7 +324,7 @@ static CONFIG_NODE *settings_get_node(const char *key) } node = iconfig_node_traverse("settings", TRUE); - return config_node_section(node, rec->module, NODE_TYPE_BLOCK); + return iconfig_node_section(node, rec->module, NODE_TYPE_BLOCK); } void settings_set_str(const char *key, const char *value) @@ -420,7 +420,7 @@ static void settings_clean_invalid_module(const char *module) node = iconfig_node_traverse("settings", FALSE); if (node == NULL) return; - node = config_node_section(node, module, -1); + node = iconfig_node_section(node, module, -1); if (node == NULL) return; for (tmp = config_node_first(node->value); tmp != NULL; tmp = next) { @@ -468,7 +468,7 @@ static int backwards_compatibility(const char *module, CONFIG_NODE *node, g_strdup(node->value); new_node = iconfig_node_traverse("settings", FALSE); new_node = new_node == NULL ? NULL : - config_node_section(new_node, new_module, -1); + iconfig_node_section(new_node, new_module, -1); config_node_set_str(mainconfig, new_node, new_key, new_value); @@ -502,7 +502,7 @@ void settings_check_module(const char *module) g_return_if_fail(module != NULL); node = iconfig_node_traverse("settings", FALSE); - node = node == NULL ? NULL : config_node_section(node, module, -1); + node = node == NULL ? NULL : iconfig_node_section(node, module, -1); if (node == NULL) return; errors = g_string_new(NULL); diff --git a/src/core/settings.h b/src/core/settings.h index f8d9f68f..af00cc80 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -36,6 +36,8 @@ typedef struct { #define iconfig_set_int(a, b, c) config_set_int(mainconfig, a, b, c) #define iconfig_set_bool(a, b, c) config_set_bool(mainconfig, a, b, c) +#define iconfig_node_section(a, b, c) config_node_section(mainconfig, a, b, c) +#define iconfig_node_section_index(a, b, c, d) config_node_section_index(mainconfig, a, b, c, d) #define iconfig_node_traverse(a, b) config_node_traverse(mainconfig, a, b) #define iconfig_node_set_str(a, b, c) config_node_set_str(mainconfig, a, b, c) #define iconfig_node_set_int(a, b, c) config_node_set_int(mainconfig, a, b, c) |