mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
iconfig's caching was a bit buggy - it didn't notice if some config node was
removed. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@213 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
afc4fbc223
commit
bb4d7566c2
@ -246,15 +246,15 @@ static void log_set_config(LOG_REC *log)
|
|||||||
if (log->autoopen)
|
if (log->autoopen)
|
||||||
config_node_set_bool(node, "auto_open", TRUE);
|
config_node_set_bool(node, "auto_open", TRUE);
|
||||||
else
|
else
|
||||||
config_node_set_str(node, "auto_open", NULL);
|
iconfig_node_set_str(node, "auto_open", NULL);
|
||||||
|
|
||||||
config_node_set_str(node, "rotate", log_rotate2str(log->rotate));
|
iconfig_node_set_str(node, "rotate", log_rotate2str(log->rotate));
|
||||||
|
|
||||||
levelstr = bits2level(log->level);
|
levelstr = bits2level(log->level);
|
||||||
config_node_set_str(node, "level", levelstr);
|
iconfig_node_set_str(node, "level", levelstr);
|
||||||
g_free(levelstr);
|
g_free(levelstr);
|
||||||
|
|
||||||
config_node_set_str(node, "items", NULL);
|
iconfig_node_set_str(node, "items", NULL);
|
||||||
|
|
||||||
if (log->items != NULL && *log->items != NULL) {
|
if (log->items != NULL && *log->items != NULL) {
|
||||||
node = config_node_section(node, "items", NODE_TYPE_LIST);
|
node = config_node_section(node, "items", NODE_TYPE_LIST);
|
||||||
|
@ -29,6 +29,9 @@ typedef struct {
|
|||||||
#define iconfig_set_bool(a, b, c) config_set_bool(mainconfig, a, b, c)
|
#define iconfig_set_bool(a, b, c) config_set_bool(mainconfig, a, b, c)
|
||||||
|
|
||||||
#define iconfig_node_traverse(a, b) config_node_traverse(mainconfig, a, b)
|
#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_list_remove(a, b) config_node_list_remove(mainconfig, a, b)
|
||||||
|
#define iconfig_node_remove(a, b) config_node_remove(mainconfig, a, b)
|
||||||
|
|
||||||
extern CONFIG_REC *mainconfig;
|
extern CONFIG_REC *mainconfig;
|
||||||
|
|
||||||
|
@ -46,9 +46,9 @@ static void hilight_add_config(HILIGHT_REC *rec)
|
|||||||
node = iconfig_node_traverse("(hilights", TRUE);
|
node = iconfig_node_traverse("(hilights", TRUE);
|
||||||
node = config_node_section(node, NULL, NODE_TYPE_BLOCK);
|
node = config_node_section(node, NULL, NODE_TYPE_BLOCK);
|
||||||
|
|
||||||
config_node_set_str(node, "text", rec->text);
|
iconfig_node_set_str(node, "text", rec->text);
|
||||||
if (rec->level > 0) config_node_set_int(node, "level", rec->level);
|
if (rec->level > 0) config_node_set_int(node, "level", rec->level);
|
||||||
if (rec->color) config_node_set_str(node, "color", rec->color);
|
if (rec->color) iconfig_node_set_str(node, "color", rec->color);
|
||||||
if (rec->nickmask) config_node_set_bool(node, "nickmask", TRUE);
|
if (rec->nickmask) config_node_set_bool(node, "nickmask", TRUE);
|
||||||
if (rec->fullword) config_node_set_bool(node, "fullword", TRUE);
|
if (rec->fullword) config_node_set_bool(node, "fullword", TRUE);
|
||||||
if (rec->regexp) config_node_set_bool(node, "regexp", TRUE);
|
if (rec->regexp) config_node_set_bool(node, "regexp", TRUE);
|
||||||
@ -66,7 +66,7 @@ static void hilight_remove_config(HILIGHT_REC *rec)
|
|||||||
g_return_if_fail(rec != NULL);
|
g_return_if_fail(rec != NULL);
|
||||||
|
|
||||||
node = iconfig_node_traverse("hilights", FALSE);
|
node = iconfig_node_traverse("hilights", FALSE);
|
||||||
if (node != NULL) config_node_list_remove(node, g_slist_index(hilights, rec));
|
if (node != NULL) iconfig_node_list_remove(node, g_slist_index(hilights, rec));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hilight_destroy(HILIGHT_REC *rec)
|
static void hilight_destroy(HILIGHT_REC *rec)
|
||||||
|
@ -205,7 +205,7 @@ void keyboard_save(void)
|
|||||||
GSList *tmp, *tmp2;
|
GSList *tmp, *tmp2;
|
||||||
|
|
||||||
/* remove old keyboard settings */
|
/* remove old keyboard settings */
|
||||||
config_node_set_str(NULL, "(keyboard", NULL);
|
iconfig_node_set_str(NULL, "(keyboard", NULL);
|
||||||
keyboard = iconfig_node_traverse("(keyboard", TRUE);
|
keyboard = iconfig_node_traverse("(keyboard", TRUE);
|
||||||
|
|
||||||
for (tmp = keyinfos; tmp != NULL; tmp = tmp->next) {
|
for (tmp = keyinfos; tmp != NULL; tmp = tmp->next) {
|
||||||
@ -217,8 +217,8 @@ void keyboard_save(void)
|
|||||||
|
|
||||||
listnode = config_node_section(node, NULL, NODE_TYPE_BLOCK);
|
listnode = config_node_section(node, NULL, NODE_TYPE_BLOCK);
|
||||||
if (key->data != NULL)
|
if (key->data != NULL)
|
||||||
config_node_set_str(listnode, "data", key->data);
|
iconfig_node_set_str(listnode, "data", key->data);
|
||||||
config_node_set_str(listnode, "key", key->key);
|
iconfig_node_set_str(listnode, "key", key->key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,15 +43,15 @@ static void channel_config_add(SETUP_CHANNEL_REC *channel)
|
|||||||
node = iconfig_node_traverse("(channels", TRUE);
|
node = iconfig_node_traverse("(channels", TRUE);
|
||||||
node = config_node_section(node, NULL, NODE_TYPE_BLOCK);
|
node = config_node_section(node, NULL, NODE_TYPE_BLOCK);
|
||||||
|
|
||||||
config_node_set_str(node, "name", channel->name);
|
iconfig_node_set_str(node, "name", channel->name);
|
||||||
config_node_set_str(node, "ircnet", channel->ircnet);
|
iconfig_node_set_str(node, "ircnet", channel->ircnet);
|
||||||
if (channel->autojoin)
|
if (channel->autojoin)
|
||||||
config_node_set_bool(node, "autojoin", TRUE);
|
config_node_set_bool(node, "autojoin", TRUE);
|
||||||
config_node_set_str(node, "password", channel->password);
|
iconfig_node_set_str(node, "password", channel->password);
|
||||||
config_node_set_str(node, "botmasks", channel->botmasks);
|
iconfig_node_set_str(node, "botmasks", channel->botmasks);
|
||||||
config_node_set_str(node, "autosendcmd", channel->autosendcmd);
|
iconfig_node_set_str(node, "autosendcmd", channel->autosendcmd);
|
||||||
config_node_set_str(node, "background", channel->background);
|
iconfig_node_set_str(node, "background", channel->background);
|
||||||
config_node_set_str(node, "font", channel->font);
|
iconfig_node_set_str(node, "font", channel->font);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void channel_config_remove(SETUP_CHANNEL_REC *channel)
|
static void channel_config_remove(SETUP_CHANNEL_REC *channel)
|
||||||
@ -59,7 +59,7 @@ static void channel_config_remove(SETUP_CHANNEL_REC *channel)
|
|||||||
CONFIG_NODE *node;
|
CONFIG_NODE *node;
|
||||||
|
|
||||||
node = iconfig_node_traverse("channels", FALSE);
|
node = iconfig_node_traverse("channels", FALSE);
|
||||||
if (node != NULL) config_node_list_remove(node, g_slist_index(setupchannels, channel));
|
if (node != NULL) iconfig_node_list_remove(node, g_slist_index(setupchannels, channel));
|
||||||
}
|
}
|
||||||
|
|
||||||
void channels_setup_create(SETUP_CHANNEL_REC *channel)
|
void channels_setup_create(SETUP_CHANNEL_REC *channel)
|
||||||
|
@ -164,18 +164,18 @@ static void ignore_set_config(IGNORE_REC *rec)
|
|||||||
node = iconfig_node_traverse("(ignores", TRUE);
|
node = iconfig_node_traverse("(ignores", TRUE);
|
||||||
node = config_node_section(node, NULL, NODE_TYPE_BLOCK);
|
node = config_node_section(node, NULL, NODE_TYPE_BLOCK);
|
||||||
|
|
||||||
if (rec->mask != NULL) config_node_set_str(node, "mask", rec->mask);
|
if (rec->mask != NULL) iconfig_node_set_str(node, "mask", rec->mask);
|
||||||
if (rec->level) {
|
if (rec->level) {
|
||||||
levelstr = bits2level(rec->level);
|
levelstr = bits2level(rec->level);
|
||||||
config_node_set_str(node, "level", levelstr);
|
iconfig_node_set_str(node, "level", levelstr);
|
||||||
g_free(levelstr);
|
g_free(levelstr);
|
||||||
}
|
}
|
||||||
if (rec->except_level) {
|
if (rec->except_level) {
|
||||||
levelstr = bits2level(rec->except_level);
|
levelstr = bits2level(rec->except_level);
|
||||||
config_node_set_str(node, "except_level", levelstr);
|
iconfig_node_set_str(node, "except_level", levelstr);
|
||||||
g_free(levelstr);
|
g_free(levelstr);
|
||||||
}
|
}
|
||||||
config_node_set_str(node, "pattern", rec->pattern);
|
iconfig_node_set_str(node, "pattern", rec->pattern);
|
||||||
if (rec->regexp) config_node_set_bool(node, "regexp", TRUE);
|
if (rec->regexp) config_node_set_bool(node, "regexp", TRUE);
|
||||||
if (rec->fullword) config_node_set_bool(node, "fullword", TRUE);
|
if (rec->fullword) config_node_set_bool(node, "fullword", TRUE);
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ static void ignore_remove_config(IGNORE_REC *rec)
|
|||||||
CONFIG_NODE *node;
|
CONFIG_NODE *node;
|
||||||
|
|
||||||
node = iconfig_node_traverse("ignores", FALSE);
|
node = iconfig_node_traverse("ignores", FALSE);
|
||||||
if (node != NULL) config_node_list_remove(node, ignore_index(rec));
|
if (node != NULL) iconfig_node_list_remove(node, ignore_index(rec));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ignore_add_rec(IGNORE_REC *rec)
|
void ignore_add_rec(IGNORE_REC *rec)
|
||||||
|
@ -261,12 +261,12 @@ void setupserver_config_add(SETUP_SERVER_REC *rec)
|
|||||||
node = iconfig_node_traverse("(servers", TRUE);
|
node = iconfig_node_traverse("(servers", TRUE);
|
||||||
node = config_node_section(node, NULL, NODE_TYPE_BLOCK);
|
node = config_node_section(node, NULL, NODE_TYPE_BLOCK);
|
||||||
|
|
||||||
config_node_set_str(node, "address", rec->address);
|
iconfig_node_set_str(node, "address", rec->address);
|
||||||
config_node_set_str(node, "ircnet", rec->ircnet);
|
iconfig_node_set_str(node, "ircnet", rec->ircnet);
|
||||||
|
|
||||||
config_node_set_int(node, "port", rec->port);
|
config_node_set_int(node, "port", rec->port);
|
||||||
config_node_set_str(node, "password", rec->password);
|
iconfig_node_set_str(node, "password", rec->password);
|
||||||
config_node_set_str(node, "own_host", rec->own_host);
|
iconfig_node_set_str(node, "own_host", rec->own_host);
|
||||||
|
|
||||||
if (rec->autoconnect)
|
if (rec->autoconnect)
|
||||||
config_node_set_bool(node, "autoconnect", TRUE);
|
config_node_set_bool(node, "autoconnect", TRUE);
|
||||||
@ -282,7 +282,7 @@ void setupserver_config_remove(SETUP_SERVER_REC *rec)
|
|||||||
CONFIG_NODE *node;
|
CONFIG_NODE *node;
|
||||||
|
|
||||||
node = iconfig_node_traverse("servers", FALSE);
|
node = iconfig_node_traverse("servers", FALSE);
|
||||||
if (node != NULL) config_node_list_remove(node, g_slist_index(setupservers, rec));
|
if (node != NULL) iconfig_node_list_remove(node, g_slist_index(setupservers, rec));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setupserver_destroy(SETUP_SERVER_REC *rec)
|
static void setupserver_destroy(SETUP_SERVER_REC *rec)
|
||||||
|
@ -35,14 +35,14 @@ void notifylist_add_config(NOTIFYLIST_REC *rec)
|
|||||||
if (rec->away_check)
|
if (rec->away_check)
|
||||||
config_node_set_bool(node, "away_check", TRUE);
|
config_node_set_bool(node, "away_check", TRUE);
|
||||||
else
|
else
|
||||||
config_node_set_str(node, "away_check", NULL);
|
iconfig_node_set_str(node, "away_check", NULL);
|
||||||
|
|
||||||
if (rec->idle_check_time > 0)
|
if (rec->idle_check_time > 0)
|
||||||
config_node_set_int(node, "idle_check_time", rec->idle_check_time/60);
|
config_node_set_int(node, "idle_check_time", rec->idle_check_time/60);
|
||||||
else
|
else
|
||||||
config_node_set_str(node, "idle_check_time", NULL);
|
iconfig_node_set_str(node, "idle_check_time", NULL);
|
||||||
|
|
||||||
config_node_set_str(node, "ircnets", NULL);
|
iconfig_node_set_str(node, "ircnets", NULL);
|
||||||
if (rec->ircnets != NULL && *rec->ircnets != NULL) {
|
if (rec->ircnets != NULL && *rec->ircnets != NULL) {
|
||||||
node = config_node_section(node, "ircnets", NODE_TYPE_LIST);
|
node = config_node_section(node, "ircnets", NODE_TYPE_LIST);
|
||||||
config_node_add_list(node, rec->ircnets);
|
config_node_add_list(node, rec->ircnets);
|
||||||
|
@ -70,7 +70,7 @@ CONFIG_NODE *config_node_section(CONFIG_NODE *parent, const char *key, int new_t
|
|||||||
CONFIG_NODE *config_node_traverse(CONFIG_REC *rec, const char *section, int create)
|
CONFIG_NODE *config_node_traverse(CONFIG_REC *rec, const char *section, int create)
|
||||||
{
|
{
|
||||||
CONFIG_NODE *node;
|
CONFIG_NODE *node;
|
||||||
char **list, **tmp;
|
char **list, **tmp, *str;
|
||||||
int is_list, new_type;
|
int is_list, new_type;
|
||||||
|
|
||||||
g_return_val_if_fail(rec != NULL, NULL);
|
g_return_val_if_fail(rec != NULL, NULL);
|
||||||
@ -96,7 +96,9 @@ CONFIG_NODE *config_node_traverse(CONFIG_REC *rec, const char *section, int crea
|
|||||||
g_strfreev(list);
|
g_strfreev(list);
|
||||||
|
|
||||||
/* save to cache */
|
/* save to cache */
|
||||||
g_hash_table_insert(rec->cache, g_strdup(section), node);
|
str = g_strdup(section);
|
||||||
|
g_hash_table_insert(rec->cache, str, node);
|
||||||
|
g_hash_table_insert(rec->cache_nodes, node, str);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,10 +122,12 @@ char *config_get_str(CONFIG_REC *rec, const char *section, const char *key, cons
|
|||||||
config_node_find(parent, key);
|
config_node_find(parent, key);
|
||||||
|
|
||||||
/* save to cache */
|
/* save to cache */
|
||||||
if (node != NULL)
|
if (node == NULL)
|
||||||
g_hash_table_insert(rec->cache, path, node);
|
|
||||||
else
|
|
||||||
g_free(path);
|
g_free(path);
|
||||||
|
else {
|
||||||
|
g_hash_table_insert(rec->cache, path, node);
|
||||||
|
g_hash_table_insert(rec->cache_nodes, node, path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (node == NULL || !has_node_value(node)) ? (char *) def : node->value;
|
return (node == NULL || !has_node_value(node)) ? (char *) def : node->value;
|
||||||
|
@ -50,7 +50,8 @@ struct _config_rec {
|
|||||||
|
|
||||||
char *last_error;
|
char *last_error;
|
||||||
CONFIG_NODE *mainnode;
|
CONFIG_NODE *mainnode;
|
||||||
GHashTable *cache;
|
GHashTable *cache; /* path -> node (for querying) */
|
||||||
|
GHashTable *cache_nodes; /* node -> path (for removing) */
|
||||||
|
|
||||||
GScanner *scanner;
|
GScanner *scanner;
|
||||||
|
|
||||||
@ -124,17 +125,15 @@ char *config_node_get_str(CONFIG_NODE *parent, const char *key, const char *def)
|
|||||||
int config_node_get_int(CONFIG_NODE *parent, const char *key, int def);
|
int config_node_get_int(CONFIG_NODE *parent, const char *key, int def);
|
||||||
int config_node_get_bool(CONFIG_NODE *parent, const char *key, int def);
|
int config_node_get_bool(CONFIG_NODE *parent, const char *key, int def);
|
||||||
|
|
||||||
void config_node_set_str(CONFIG_NODE *parent, const char *key, const char *value);
|
void config_node_set_str(CONFIG_REC *rec, CONFIG_NODE *parent, const char *key, const char *value);
|
||||||
void config_node_set_int(CONFIG_NODE *parent, const char *key, int value);
|
void config_node_set_int(CONFIG_NODE *parent, const char *key, int value);
|
||||||
void config_node_set_bool(CONFIG_NODE *parent, const char *key, int value);
|
void config_node_set_bool(CONFIG_NODE *parent, const char *key, int value);
|
||||||
|
|
||||||
/* Add/change the value of the `key' */
|
|
||||||
void config_node_set_str(CONFIG_NODE *parent, const char *key, const char *value);
|
|
||||||
/* Remove one node from block/list.
|
/* Remove one node from block/list.
|
||||||
..set_str() with value = NULL does the same. */
|
..set_str() with value = NULL does the same. */
|
||||||
void config_node_remove(CONFIG_NODE *parent, CONFIG_NODE *node);
|
void config_node_remove(CONFIG_REC *rec, CONFIG_NODE *parent, CONFIG_NODE *node);
|
||||||
/* Remove n'th node from a list */
|
/* Remove n'th node from a list */
|
||||||
void config_node_list_remove(CONFIG_NODE *node, int index);
|
void config_node_list_remove(CONFIG_REC *rec, CONFIG_NODE *node, int index);
|
||||||
|
|
||||||
/* Clear the entire configuration */
|
/* Clear the entire configuration */
|
||||||
void config_nodes_remove_all(CONFIG_REC *rec);
|
void config_nodes_remove_all(CONFIG_REC *rec);
|
||||||
|
@ -20,6 +20,29 @@
|
|||||||
|
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
|
|
||||||
|
static int g_istr_equal(gconstpointer v, gconstpointer v2)
|
||||||
|
{
|
||||||
|
return g_strcasecmp((const char *) v, (const char *) v2) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* a char* hash function from ASU */
|
||||||
|
static unsigned int g_istr_hash(gconstpointer v)
|
||||||
|
{
|
||||||
|
const char *s = (char *) v;
|
||||||
|
unsigned int h = 0, g;
|
||||||
|
|
||||||
|
while (*s != '\0') {
|
||||||
|
h = (h << 4) + toupper(*s);
|
||||||
|
if ((g = h & 0xf0000000)) {
|
||||||
|
h = h ^ (g >> 24);
|
||||||
|
h = h ^ g;
|
||||||
|
}
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return h /* % M */;
|
||||||
|
}
|
||||||
|
|
||||||
int config_error(CONFIG_REC *rec, const char *msg)
|
int config_error(CONFIG_REC *rec, const char *msg)
|
||||||
{
|
{
|
||||||
g_free_and_null(rec->last_error);
|
g_free_and_null(rec->last_error);
|
||||||
@ -138,7 +161,7 @@ static int config_parse_symbol(CONFIG_REC *rec, CONFIG_NODE *node)
|
|||||||
switch (rec->scanner->token) {
|
switch (rec->scanner->token) {
|
||||||
case G_TOKEN_STRING:
|
case G_TOKEN_STRING:
|
||||||
/* value */
|
/* value */
|
||||||
config_node_set_str(node, key, rec->scanner->value.v_string);
|
config_node_set_str(rec, node, key, rec->scanner->value.v_string);
|
||||||
g_free_not_null(key);
|
g_free_not_null(key);
|
||||||
|
|
||||||
print_warning = TRUE;
|
print_warning = TRUE;
|
||||||
@ -303,7 +326,8 @@ CONFIG_REC *config_open(const char *fname, int create_mode)
|
|||||||
rec->create_mode = create_mode;
|
rec->create_mode = create_mode;
|
||||||
rec->mainnode = g_new0(CONFIG_NODE, 1);
|
rec->mainnode = g_new0(CONFIG_NODE, 1);
|
||||||
rec->mainnode->type = NODE_TYPE_BLOCK;
|
rec->mainnode->type = NODE_TYPE_BLOCK;
|
||||||
rec->cache = g_hash_table_new((GHashFunc) g_str_hash, (GCompareFunc) g_str_equal);
|
rec->cache = g_hash_table_new((GHashFunc) g_istr_hash, (GCompareFunc) g_istr_equal);
|
||||||
|
rec->cache_nodes = g_hash_table_new((GHashFunc) g_direct_hash, (GCompareFunc) g_direct_equal);
|
||||||
|
|
||||||
return rec;
|
return rec;
|
||||||
}
|
}
|
||||||
@ -319,6 +343,7 @@ void config_close(CONFIG_REC *rec)
|
|||||||
if (rec->handle != -1) close(rec->handle);
|
if (rec->handle != -1) close(rec->handle);
|
||||||
g_hash_table_foreach(rec->cache, (GHFunc) g_free, NULL);
|
g_hash_table_foreach(rec->cache, (GHFunc) g_free, NULL);
|
||||||
g_hash_table_destroy(rec->cache);
|
g_hash_table_destroy(rec->cache);
|
||||||
|
g_hash_table_destroy(rec->cache_nodes);
|
||||||
g_free_not_null(rec->last_error);
|
g_free_not_null(rec->last_error);
|
||||||
g_free(rec->fname);
|
g_free(rec->fname);
|
||||||
g_free(rec);
|
g_free(rec);
|
||||||
|
@ -20,11 +20,24 @@
|
|||||||
|
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
|
|
||||||
void config_node_remove(CONFIG_NODE *parent, CONFIG_NODE *node)
|
static void cache_remove(CONFIG_REC *rec, CONFIG_NODE *node)
|
||||||
|
{
|
||||||
|
char *path;
|
||||||
|
|
||||||
|
path = g_hash_table_lookup(rec->cache_nodes, node);
|
||||||
|
if (path != NULL) {
|
||||||
|
g_hash_table_remove(rec->cache, path);
|
||||||
|
g_hash_table_remove(rec->cache_nodes, node);
|
||||||
|
g_free(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void config_node_remove(CONFIG_REC *rec, CONFIG_NODE *parent, CONFIG_NODE *node)
|
||||||
{
|
{
|
||||||
g_return_if_fail(parent != NULL);
|
g_return_if_fail(parent != NULL);
|
||||||
g_return_if_fail(node != NULL);
|
g_return_if_fail(node != NULL);
|
||||||
|
|
||||||
|
cache_remove(rec, node);
|
||||||
parent->value = g_slist_remove(parent->value, node);
|
parent->value = g_slist_remove(parent->value, node);
|
||||||
|
|
||||||
switch (node->type) {
|
switch (node->type) {
|
||||||
@ -36,7 +49,7 @@ void config_node_remove(CONFIG_NODE *parent, CONFIG_NODE *node)
|
|||||||
case NODE_TYPE_BLOCK:
|
case NODE_TYPE_BLOCK:
|
||||||
case NODE_TYPE_LIST:
|
case NODE_TYPE_LIST:
|
||||||
while (node->value != NULL)
|
while (node->value != NULL)
|
||||||
config_node_remove(node, ((GSList *) node->value)->data);
|
config_node_remove(rec, node, ((GSList *) node->value)->data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
g_free_not_null(node->key);
|
g_free_not_null(node->key);
|
||||||
@ -44,7 +57,7 @@ void config_node_remove(CONFIG_NODE *parent, CONFIG_NODE *node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Remove n'th node from a list */
|
/* Remove n'th node from a list */
|
||||||
void config_node_list_remove(CONFIG_NODE *node, int index)
|
void config_node_list_remove(CONFIG_REC *rec, CONFIG_NODE *node, int index)
|
||||||
{
|
{
|
||||||
GSList *tmp;
|
GSList *tmp;
|
||||||
|
|
||||||
@ -53,7 +66,7 @@ void config_node_list_remove(CONFIG_NODE *node, int index)
|
|||||||
|
|
||||||
for (tmp = node->value; tmp != NULL; tmp = tmp->next, index--) {
|
for (tmp = node->value; tmp != NULL; tmp = tmp->next, index--) {
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
config_node_remove(node, tmp->data);
|
config_node_remove(rec, node, tmp->data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,15 +77,15 @@ void config_nodes_remove_all(CONFIG_REC *rec)
|
|||||||
g_return_if_fail(rec != NULL);
|
g_return_if_fail(rec != NULL);
|
||||||
|
|
||||||
while (rec->mainnode->value != NULL)
|
while (rec->mainnode->value != NULL)
|
||||||
config_node_remove(rec->mainnode, ((GSList *) rec->mainnode->value)->data);
|
config_node_remove(rec, rec->mainnode, ((GSList *) rec->mainnode->value)->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void config_node_set_str(CONFIG_REC *rec, CONFIG_NODE *parent, const char *key, const char *value)
|
||||||
void config_node_set_str(CONFIG_NODE *parent, const char *key, const char *value)
|
|
||||||
{
|
{
|
||||||
CONFIG_NODE *node;
|
CONFIG_NODE *node;
|
||||||
int no_key;
|
int no_key;
|
||||||
|
|
||||||
|
g_return_if_fail(rec != NULL || value != NULL);
|
||||||
g_return_if_fail(parent != NULL);
|
g_return_if_fail(parent != NULL);
|
||||||
|
|
||||||
no_key = key == NULL;
|
no_key = key == NULL;
|
||||||
@ -80,7 +93,7 @@ void config_node_set_str(CONFIG_NODE *parent, const char *key, const char *value
|
|||||||
|
|
||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
/* remove the key */
|
/* remove the key */
|
||||||
if (node != NULL) config_node_remove(parent, node);
|
if (node != NULL) config_node_remove(rec, parent, node);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,12 +115,12 @@ void config_node_set_int(CONFIG_NODE *parent, const char *key, int value)
|
|||||||
char str[MAX_INT_STRLEN];
|
char str[MAX_INT_STRLEN];
|
||||||
|
|
||||||
g_snprintf(str, sizeof(str), "%d", value);
|
g_snprintf(str, sizeof(str), "%d", value);
|
||||||
config_node_set_str(parent, key, str);
|
config_node_set_str(NULL, parent, key, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void config_node_set_bool(CONFIG_NODE *parent, const char *key, int value)
|
void config_node_set_bool(CONFIG_NODE *parent, const char *key, int value)
|
||||||
{
|
{
|
||||||
config_node_set_str(parent, key, value ? "yes" : "no");
|
config_node_set_str(NULL, parent, key, value ? "yes" : "no");
|
||||||
}
|
}
|
||||||
|
|
||||||
int config_set_str(CONFIG_REC *rec, const char *section, const char *key, const char *value)
|
int config_set_str(CONFIG_REC *rec, const char *section, const char *key, const char *value)
|
||||||
@ -120,7 +133,7 @@ int config_set_str(CONFIG_REC *rec, const char *section, const char *key, const
|
|||||||
parent = config_node_traverse(rec, section, TRUE);
|
parent = config_node_traverse(rec, section, TRUE);
|
||||||
if (parent == NULL) return -1;
|
if (parent == NULL) return -1;
|
||||||
|
|
||||||
config_node_set_str(parent, key, value);
|
config_node_set_str(rec, parent, key, value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,5 +156,5 @@ void config_node_add_list(CONFIG_NODE *node, char **array)
|
|||||||
char **tmp;
|
char **tmp;
|
||||||
|
|
||||||
for (tmp = array; *tmp != NULL; tmp++)
|
for (tmp = array; *tmp != NULL; tmp++)
|
||||||
config_node_set_str(node, NULL, *tmp);
|
config_node_set_str(NULL, node, NULL, *tmp);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user