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); } } }
static void session_save_server(SERVER_REC *server, CONFIG_REC *config, CONFIG_NODE *node) { int handle; node = config_node_section(node, NULL, NODE_TYPE_BLOCK); config_node_set_str(config, node, "chat_type", chat_protocol_find_id(server->chat_type)->name); config_node_set_str(config, node, "address", server->connrec->address); config_node_set_int(config, node, "port", server->connrec->port); config_node_set_str(config, node, "chatnet", server->connrec->chatnet); config_node_set_str(config, node, "password", server->connrec->password); config_node_set_str(config, node, "nick", server->nick); config_node_set_bool(config, node, "use_ssl", server->connrec->use_ssl); handle = g_io_channel_unix_get_fd(net_sendbuffer_handle(server->handle)); config_node_set_int(config, node, "handle", handle); signal_emit("session save server", 3, server, config, node); /* fake the server disconnection */ g_io_channel_unref(net_sendbuffer_handle(server->handle)); net_sendbuffer_destroy(server->handle, FALSE); server->handle = NULL; server->connection_lost = TRUE; server->no_reconnect = TRUE; server_disconnect(server); }
static void session_save_nick(CHANNEL_REC *channel, NICK_REC *nick, CONFIG_REC *config, CONFIG_NODE *node) { 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); config_node_set_bool(config, node, "halfop", nick->halfop); config_node_set_bool(config, node, "voice", nick->voice); config_node_set_str(config, node, "prefixes", nick->prefixes); signal_emit("session save nick", 4, channel, nick, config, node); }
static void session_save_channel(CHANNEL_REC *channel, CONFIG_REC *config, CONFIG_NODE *node) { 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); config_node_set_str(config, node, "topic", channel->topic); config_node_set_str(config, node, "topic_by", channel->topic_by); config_node_set_int(config, node, "topic_time", channel->topic_time); config_node_set_str(config, node, "key", channel->key); signal_emit("session save channel", 3, channel, config, node); }
/* Add all values in `array' to `node' */ void config_node_add_list(CONFIG_REC *rec, CONFIG_NODE *node, char **array) { char **tmp; for (tmp = array; *tmp != NULL; tmp++) config_node_set_str(rec, node, NULL, *tmp); }
void config_node_set_int(CONFIG_REC *rec, CONFIG_NODE *parent, const char *key, int value) { char str[MAX_INT_STRLEN]; g_snprintf(str, sizeof(str), "%d", value); config_node_set_str(rec, parent, key, str); }
/* save channel specific user record */ static void botuser_save_chan(const char *key, USER_CHAN_REC *rec, CONFIG_NODE *node) { CONFIG_NODE *noderec; char *str; if (rec->flags == 0) { /* no flags in this channel - no need to save to config */ config_node_set_str(userconfig, node, rec->channel, NULL); return; } noderec = config_node_section(node, rec->channel, NODE_TYPE_BLOCK); str = botuser_value2flags(rec->flags); config_node_set_str(userconfig, noderec, "flags", str); g_free_not_null(str); }
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 int backwards_compatibility(const char *module, CONFIG_NODE *node, CONFIG_NODE *parent) { const char *new_key, *new_module; CONFIG_NODE *new_node; char *new_value; new_value = NULL; new_key = NULL; new_module = NULL; /* fe-text term_type -> fe-common/core term_charset - for 0.8.10-> */ if (g_strcmp0(module, "fe-text") == 0) { if (g_ascii_strcasecmp(node->key, "term_type") == 0 || /* kludge for cvs-version where term_charset was in fe-text */ g_ascii_strcasecmp(node->key, "term_charset") == 0) { new_module = "fe-common/core"; new_key = "term_charset"; new_value = !is_valid_charset(node->value) ? NULL : g_strdup(node->value); new_node = iconfig_node_traverse("settings", FALSE); new_node = new_node == NULL ? NULL : iconfig_node_section(new_node, new_module, -1); config_node_set_str(mainconfig, new_node, new_key, new_value); /* remove old */ config_node_set_str(mainconfig, parent, node->key, NULL); g_free(new_value); config_changed = TRUE; return new_key != NULL; } else if (g_ascii_strcasecmp(node->key, "actlist_moves") == 0 && node->value != NULL && g_ascii_strcasecmp(node->value, "yes") == 0) { config_node_set_str(mainconfig, parent, "actlist_sort", "recent"); config_node_set_str(mainconfig, parent, node->key, NULL); config_changed = TRUE; return TRUE; } } return new_key != NULL; }
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 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); } }
void config_node_set_bool(CONFIG_REC *rec, CONFIG_NODE *parent, const char *key, int value) { config_node_set_str(rec, parent, key, value ? "yes" : "no"); }
static int backwards_compatibility(const char *module, CONFIG_NODE *node, CONFIG_NODE *parent) { const char *new_key, *new_module; CONFIG_NODE *new_node; char *new_value; int old_value; new_value = NULL; new_key = NULL; new_module = NULL; /* fe-text term_type -> fe-common/core term_charset - for 0.8.10-> */ if (strcmp(module, "fe-text") == 0) { if (strcasecmp(node->key, "term_type") == 0 || /* kludge for cvs-version where term_charset was in fe-text */ strcasecmp(node->key, "term_charset") == 0) { new_module = "fe-common/core"; new_key = "term_charset"; new_value = !is_valid_charset(node->value) ? NULL : 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); config_node_set_str(mainconfig, new_node, new_key, new_value); /* remove old */ config_node_set_str(mainconfig, parent, node->key, NULL); g_free(new_value); config_changed = TRUE; return new_key != NULL; } } new_value = NULL, new_key = NULL; /* FIXME: remove later - for 0.8.6 -> */ if (node->value == NULL || !is_numeric(node->value, '\0')) return FALSE; old_value = atoi(node->value); if (strcmp(module, "fe-text") == 0) { if (strcasecmp(node->key, "lag_min_show") == 0) new_value = g_strdup_printf("%dms", old_value*10); else if (strcasecmp(node->key, "scrollback_hours") == 0) { new_value = g_strdup_printf("%dh", old_value); new_key = "scrollback_time"; } } else if (strcmp(module, "irc/core") == 0) { if (strcasecmp(node->key, "cmd_queue_speed") == 0) new_value = g_strdup_printf("%dms", old_value); } else if (strcmp(module, "irc/dcc") == 0) { if (strcasecmp(node->key, "dcc_autoget_max_size") == 0) new_value = g_strdup_printf("%dk", old_value); } else if (strcmp(module, "irc/notify") == 0) { if (strcasecmp(node->key, "notify_idle_time") == 0) new_value = g_strdup_printf("%dmin", old_value); } else if (strcmp(module, "core") == 0) { if (strcasecmp(node->key, "write_buffer_mins") == 0) { new_value = g_strdup_printf("%dmin", old_value); new_key = "write_buffer_timeout"; } else if (strcasecmp(node->key, "write_buffer_kb") == 0) { new_value = g_strdup_printf("%dk", old_value); new_key = "write_buffer_size"; } } if (new_key != NULL || new_value != NULL) { config_node_set_str(mainconfig, parent, new_key != NULL ? new_key : node->key, new_value != NULL ? new_value : node->value); if (new_key != NULL) { /* remove old */ config_node_set_str(mainconfig, parent, node->key, NULL); } config_changed = TRUE; g_free(new_value); } return new_key != NULL; }