static void theme_read_replaces(CONFIG_REC *config, THEME_REC *theme) { GSList *tmp; CONFIG_NODE *node; const char *p; int index; /* reset replace keys */ for (index = 0; index < 256; index++) theme->replace_keys[index] = -1; index = 0; node = config_node_traverse(config, "replaces", FALSE); if (node == NULL || node->type != NODE_TYPE_BLOCK) return; for (tmp = node->value; tmp != NULL; tmp = tmp->next) { node = tmp->data; if (node->key != NULL && node->value != NULL) { for (p = node->key; *p != '\0'; p++) theme->replace_keys[(int) (unsigned char) *p] = index; theme->replace_values = g_slist_append(theme->replace_values, g_strdup(node->value)); index++; } } }
static void theme_read_abstracts(CONFIG_REC *config, THEME_REC *theme) { GSList *tmp; CONFIG_NODE *node; gpointer oldkey, oldvalue; node = config_node_traverse(config, "abstracts", FALSE); if (node == NULL || node->type != NODE_TYPE_BLOCK) return; for (tmp = node->value; tmp != NULL; tmp = tmp->next) { node = tmp->data; if (node->key == NULL || node->value == NULL) continue; if (g_hash_table_lookup_extended(theme->abstracts, node->key, &oldkey, &oldvalue)) { /* new values override old ones */ g_hash_table_remove(theme->abstracts, oldkey); g_free(oldkey); g_free(oldvalue); } g_hash_table_insert(theme->abstracts, g_strdup(node->key), g_strdup(node->value)); } }
/* Like config_list_find(), but return node instead of it's value */ CONFIG_NODE *config_list_find_node(CONFIG_REC *rec, const char *section, const char *key, const char *value, const char *value_key) { CONFIG_NODE *node, *keynode; GSList *tmp; g_return_val_if_fail(rec != NULL, NULL); g_return_val_if_fail(key != NULL, NULL); g_return_val_if_fail(value_key != NULL, NULL); node = config_node_traverse(rec, section, FALSE); if (node == NULL || !is_node_list(node)) return NULL; for (tmp = node->value; tmp != NULL; tmp = tmp->next) { node = tmp->data; if (node->type != NODE_TYPE_BLOCK) continue; /* key matches value? */ keynode = config_node_find(node, key); if (keynode == NULL || keynode->type != NODE_TYPE_KEY || g_strcasecmp(keynode->value, value) != 0) continue; return config_node_find(node, value_key); } return NULL; }
static void module_save(const char *module, MODULE_THEME_REC *rec, THEME_SAVE_REC *data) { CONFIG_NODE *fnode, *node; FORMAT_REC *formats; int n; formats = g_hash_table_lookup(default_formats, rec->name); if (formats == NULL) return; fnode = config_node_traverse(data->config, "formats", TRUE); node = config_node_section(fnode, rec->name, NODE_TYPE_BLOCK); for (n = 1; formats[n].def != NULL; n++) { if (rec->formats[n] != NULL) { config_node_set_str(data->config, node, formats[n].tag, rec->formats[n]); } else if (data->save_all && formats[n].tag != NULL) { config_node_set_str(data->config, node, formats[n].tag, formats[n].def); } } if (node->value == NULL) { /* not modified, don't keep the empty section */ config_node_remove(data->config, fnode, node); if (fnode->value == NULL) { config_node_remove(data->config, data->config->mainnode, fnode); } } }
char *config_get_str(CONFIG_REC *rec, const char *section, const char *key, const char *def) { CONFIG_NODE *parent, *node; char *path; g_return_val_if_fail(rec != NULL, (char *) def); g_return_val_if_fail(key != NULL, (char *) def); /* check if it already exists in cache */ path = g_strconcat(section == NULL ? "" : section, "/", key, NULL); node = g_hash_table_lookup(rec->cache, path); if (node != NULL) g_free(path); else { parent = config_node_traverse(rec, section, FALSE); node = parent == NULL ? NULL : config_node_find(parent, key); /* save to cache */ if (node == NULL) 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; }
int config_set_str(CONFIG_REC *rec, const char *section, const char *key, const char *value) { CONFIG_NODE *parent; g_return_val_if_fail(rec != NULL, -1); parent = config_node_traverse(rec, section, TRUE); if (parent == NULL) return -1; config_node_set_str(rec, parent, key, value); return 0; }
static CONFIG_NODE *config_sbar_node(CONFIG_REC *config, const char *name, gboolean create) { CONFIG_NODE *node; node = config_node_traverse(config, "statusbar", create); if (node != NULL) { node = config_node_section(config, node, active_statusbar_group->name, create ? NODE_TYPE_BLOCK : -1); } if (node != NULL) { node = config_node_section(config, node, name, create ? NODE_TYPE_BLOCK : -1); } return node; }
static void botuser_config_save(USER_REC *user) { CONFIG_NODE *node, *subnode, *noderec; GSList *tmp; char *str; user->last_modify = time(NULL); node = config_node_traverse(userconfig, "users", TRUE); node = config_node_section(node, user->nick, NODE_TYPE_BLOCK); str = user->flags == 0 ? NULL : botuser_value2flags(user->flags); config_node_set_str(userconfig, node, "flags", str); g_free_not_null(str); config_node_set_str(userconfig, node, "password", user->password); config_node_set_int(userconfig, node, "last_modify", (int) user->last_modify); /* Save masks */ if (user->masks == NULL) config_node_set_str(userconfig, node, "masks", NULL); else { subnode = config_node_section(node, "masks", NODE_TYPE_LIST); for (tmp = user->masks; tmp != NULL; tmp = tmp->next) { USER_MASK_REC *rec = tmp->data; noderec = config_node_section(subnode, NULL, NODE_TYPE_BLOCK); config_node_set_str(userconfig, noderec, "mask", rec->mask); str = user->flags == 0 ? NULL : botuser_value2flags(rec->not_flags); config_node_set_str(userconfig, noderec, "not_flags", str); g_free_not_null(str); } } /* Save channels */ if (g_hash_table_size(user->channels) == 0) config_node_set_str(userconfig, node, "channels", NULL); else { subnode = config_node_section(node, "channels", NODE_TYPE_LIST); g_hash_table_foreach(user->channels, (GHFunc) botuser_save_chan, subnode); } }
static void statusbar_reset_defaults(void) { CONFIG_REC *config; CONFIG_NODE *node; while (statusbar_groups != NULL) statusbar_group_destroy(statusbar_groups->data); active_statusbar_group = NULL; /* read the default statusbar settings from internal config */ config = config_open(NULL, -1); config_parse_data(config, default_config, "internal"); node = config_node_traverse(config, "statusbar", FALSE); if (node != NULL) read_statusbar_config_from_node(node); config_close(config); }
static void sig_session_save(CONFIG_REC *config) { CONFIG_NODE *node; GSList *tmp; GString *str; /* save servers */ node = config_node_traverse(config, "(servers", TRUE); while (servers != NULL) session_save_server(servers->data, config, node); /* save pids */ str = g_string_new(NULL); for (tmp = pidwait_get_pids(); tmp != NULL; tmp = tmp->next) g_string_append_printf(str, "%d ", GPOINTER_TO_INT(tmp->data)); config_node_set_str(config, config->mainnode, "pids", str->str); g_string_free(str, TRUE); }
static void theme_read_formats(THEME_REC *theme, const char *module, CONFIG_REC *config, MODULE_THEME_REC *rec) { CONFIG_NODE *node; GSList *tmp; node = config_node_traverse(config, "formats", FALSE); if (node == NULL) return; node = config_node_section(node, module, -1); if (node == NULL) return; for (tmp = node->value; tmp != NULL; tmp = tmp->next) { node = tmp->data; if (node->key != NULL && node->value != NULL) { theme_set_format(theme, rec, module, node->key, node->value); } } }
static void sig_session_restore(CONFIG_REC *config) { CONFIG_NODE *node; GSList *tmp; char **pids, **pid; /* restore servers */ node = config_node_traverse(config, "(servers", FALSE); if (node != NULL) { tmp = config_node_first(node->value); for (; tmp != NULL; tmp = config_node_next(tmp)) session_restore_server(tmp->data); } /* restore pids (so we don't leave zombies) */ pids = g_strsplit(config_node_get_str(config->mainnode, "pids", ""), " ", -1); for (pid = pids; *pid != NULL; pid++) pidwait_add(atoi(*pid)); g_strfreev(pids); }
static void botuser_config_read(void) { CONFIG_NODE *node; GSList *tmp; char *fname; /* Read users from ~/.irssi/users */ fname = g_strdup_printf("%s/users", get_irssi_dir()); userconfig = config_open(fname, 0600); g_free(fname); if (userconfig == NULL) return; /* access denied?! */ config_parse(userconfig); node = config_node_traverse(userconfig, "users", FALSE); tmp = node == NULL ? NULL : node->value; for (; tmp != NULL; tmp = tmp->next) botuser_config_read_user(tmp->data); }
static void botnet_config_read(void) { CONFIG_REC *config; CONFIG_NODE *node; GSList *tmp; char *fname; /* Read botnets from ~/.irssi/botnets */ fname = g_strdup_printf("%s/.irssi/botnets", g_get_home_dir()); config = config_open(fname, -1); g_free(fname); if (config == NULL) return; config_parse(config); node = config_node_traverse(config, "botnets", FALSE); tmp = node == NULL ? NULL : node->value; for (; tmp != NULL; tmp = tmp->next) botnet_config_read_botnet(tmp->data); config_close(config); }