static SERVER_CONNECT_REC * create_addr_conn(int chat_type, const char *address, int port, const char *chatnet, const char *password, const char *nick) { CHAT_PROTOCOL_REC *proto; SERVER_CONNECT_REC *conn; SERVER_SETUP_REC *sserver; CHATNET_REC *chatnetrec; g_return_val_if_fail(address != NULL, NULL); sserver = server_setup_find(address, port, chatnet); if (sserver != NULL) { if (chat_type < 0) chat_type = sserver->chat_type; else if (chat_type != sserver->chat_type) sserver = NULL; } proto = chat_type >= 0 ? chat_protocol_find_id(chat_type) : chat_protocol_get_default(); conn = proto->create_server_connect(); server_connect_ref(conn); conn->chat_type = proto->id; if (chatnet != NULL && *chatnet != '\0') conn->chatnet = g_strdup(chatnet); /* fill in the defaults */ server_setup_fill(conn, address, port); /* fill the rest from chat network settings */ chatnetrec = chatnet != NULL ? chatnet_find(chatnet) : (sserver == NULL || sserver->chatnet == NULL ? NULL : chatnet_find(sserver->chatnet)); if (chatnetrec != NULL) server_setup_fill_chatnet(conn, chatnetrec); /* fill the information from setup */ if (sserver != NULL) server_setup_fill_server(conn, sserver); /* nick / password given in command line overrides all settings */ if (password && *password) { g_free_not_null(conn->password); conn->password = g_strdup(password); } if (nick && *nick) { g_free_not_null(conn->nick); conn->nick = g_strdup(nick); } return conn; }
static void cmd_channel_add_modify(const char *data, gboolean add) { GHashTable *optlist; CHATNET_REC *chatnetrec; CHANNEL_SETUP_REC *rec; char *botarg, *botcmdarg, *chatnet, *channel, *password; void *free_arg; if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS, "channel add", &optlist, &channel, &chatnet, &password)) return; if (*chatnet == '\0' || *channel == '\0') { cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); } chatnetrec = chatnet_find(chatnet); if (chatnetrec == NULL) { printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_UNKNOWN_CHATNET, chatnet); cmd_params_free(free_arg); return; } botarg = g_hash_table_lookup(optlist, "bots"); botcmdarg = g_hash_table_lookup(optlist, "botcmd"); rec = channel_setup_find(channel, chatnet); if (rec == NULL) { if (add == FALSE) { printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_CHANSETUP_NOT_FOUND, channel, chatnet); cmd_params_free(free_arg); return; } rec = CHAT_PROTOCOL(chatnetrec)->create_channel_setup(); rec->name = g_strdup(channel); rec->chatnet = g_strdup(chatnet); } else { if (g_hash_table_lookup(optlist, "bots")) g_free_and_null(rec->botmasks); if (g_hash_table_lookup(optlist, "botcmd")) g_free_and_null(rec->autosendcmd); if (*password != '\0') g_free_and_null(rec->password); } if (g_hash_table_lookup(optlist, "auto")) rec->autojoin = TRUE; if (g_hash_table_lookup(optlist, "noauto")) rec->autojoin = FALSE; if (botarg != NULL && *botarg != '\0') rec->botmasks = g_strdup(botarg); if (botcmdarg != NULL && *botcmdarg != '\0') rec->autosendcmd = g_strdup(botcmdarg); if (*password != '\0' && g_strcmp0(password, "-") != 0) rec->password = g_strdup(password); signal_emit("channel add fill", 2, rec, optlist); channel_setup_create(rec); printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_CHANSETUP_ADDED, channel, chatnet); cmd_params_free(free_arg); }
static void sig_connected(SERVER_REC *server) { CHATNET_REC *rec; g_return_if_fail(IS_SERVER(server)); if (server->connrec->chatnet == NULL || server->session_reconnect) return; rec = chatnet_find(server->connrec->chatnet); if (!server->connrec->no_autosendcmd && rec != NULL && rec->autosendcmd) eval_special_string(rec->autosendcmd, "", server, NULL); }
/* Create server connection record. `dest' is required, rest can be NULL. `dest' is either a server address or chat network */ SERVER_CONNECT_REC * server_create_conn(int chat_type, const char *dest, int port, const char *chatnet, const char *password, const char *nick) { SERVER_CONNECT_REC *rec; CHATNET_REC *chatrec; g_return_val_if_fail(dest != NULL, NULL); chatrec = chatnet_find(dest); if (chatrec != NULL) { rec = create_chatnet_conn(chatrec->name, port, password, nick); if (rec != NULL) return rec; } chatrec = chatnet == NULL ? NULL : chatnet_find(chatnet); if (chatrec != NULL) chatnet = chatrec->name; return create_addr_conn(chat_type, dest, port, chatnet, password, nick); }
static SERVER_SETUP_REC *create_server_setup(GHashTable *optlist) { CHAT_PROTOCOL_REC *rec; SERVER_SETUP_REC *server; char *chatnet; rec = chat_protocol_find_net(optlist); if (rec == NULL) rec = chat_protocol_get_default(); else { chatnet = g_hash_table_lookup(optlist, rec->chatnet); if (chatnet_find(chatnet) == NULL) { printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_UNKNOWN_CHATNET, chatnet); return NULL; } } server = rec->create_server_setup(); server->chat_type = rec->id; return server; }
static CHANNEL_SETUP_REC *channel_setup_read(CONFIG_NODE *node) { CHANNEL_SETUP_REC *rec; CHATNET_REC *chatnetrec; char *channel, *chatnet; g_return_val_if_fail(node != NULL, NULL); channel = config_node_get_str(node, "name", NULL); chatnet = config_node_get_str(node, "chatnet", NULL); if (chatnet == NULL) /* FIXME: remove this after .98... */ { chatnet = g_strdup(config_node_get_str(node, "ircnet", NULL)); if (chatnet != NULL) { iconfig_node_set_str(node, "chatnet", chatnet); iconfig_node_set_str(node, "ircnet", NULL); } } chatnetrec = chatnet == NULL ? NULL : chatnet_find(chatnet); if (channel == NULL || chatnetrec == NULL) { /* missing information.. */ return NULL; } rec = CHAT_PROTOCOL(chatnetrec)->create_channel_setup(); rec->type = module_get_uniq_id("CHANNEL SETUP", 0); rec->chat_type = CHAT_PROTOCOL(chatnetrec)->id; rec->autojoin = config_node_get_bool(node, "autojoin", FALSE); rec->name = g_strdup(channel); rec->chatnet = g_strdup(chatnetrec != NULL ? chatnetrec->name : chatnet); rec->password = g_strdup(config_node_get_str(node, "password", NULL)); rec->botmasks = g_strdup(config_node_get_str(node, "botmasks", NULL)); rec->autosendcmd = g_strdup(config_node_get_str(node, "autosendcmd", NULL)); setupchannels = g_slist_append(setupchannels, rec); signal_emit("channel setup created", 2, rec, node); return rec; }
static SERVER_SETUP_REC *server_setup_read(CONFIG_NODE *node) { SERVER_SETUP_REC *rec; CHATNET_REC *chatnetrec; char *server, *chatnet, *family; int port; g_return_val_if_fail(node != NULL, NULL); server = config_node_get_str(node, "address", NULL); if (server == NULL) return NULL; port = config_node_get_int(node, "port", 0); chatnet = config_node_get_str(node, "chatnet", NULL); if (server_setup_find(server, port, chatnet) != NULL) { return NULL; } rec = NULL; chatnetrec = chatnet == NULL ? NULL : chatnet_find(chatnet); if (chatnetrec == NULL && chatnet != NULL) { /* chat network not found, create it. */ chatnetrec = chat_protocol_get_default()->create_chatnet(); chatnetrec->chat_type = chat_protocol_get_default()->id; chatnetrec->name = g_strdup(chatnet); chatnet_create(chatnetrec); } family = config_node_get_str(node, "family", ""); rec = CHAT_PROTOCOL(chatnetrec)->create_server_setup(); rec->type = module_get_uniq_id("SERVER SETUP", 0); rec->chat_type = CHAT_PROTOCOL(chatnetrec)->id; rec->chatnet = chatnetrec == NULL ? NULL : g_strdup(chatnetrec->name); rec->family = g_ascii_strcasecmp(family, "inet6") == 0 ? AF_INET6 : (g_ascii_strcasecmp(family, "inet") == 0 ? AF_INET : 0); rec->address = g_strdup(server); rec->password = g_strdup(config_node_get_str(node, "password", NULL)); rec->use_ssl = config_node_get_bool(node, "use_ssl", FALSE); rec->ssl_cert = g_strdup(config_node_get_str(node, "ssl_cert", NULL)); rec->ssl_pkey = g_strdup(config_node_get_str(node, "ssl_pkey", NULL)); rec->ssl_verify = config_node_get_bool(node, "ssl_verify", FALSE); rec->ssl_cafile = g_strdup(config_node_get_str(node, "ssl_cafile", NULL)); rec->ssl_capath = g_strdup(config_node_get_str(node, "ssl_capath", NULL)); if (rec->ssl_cafile || rec->ssl_capath) rec->ssl_verify = TRUE; if (rec->ssl_cert != NULL || rec->ssl_verify) rec->use_ssl = TRUE; rec->port = port; rec->autoconnect = config_node_get_bool(node, "autoconnect", FALSE); rec->no_proxy = config_node_get_bool(node, "no_proxy", FALSE); rec->own_host = g_strdup(config_node_get_str(node, "own_host", NULL)); signal_emit("server setup read", 2, rec, node); setupservers = g_slist_append(setupservers, rec); return rec; }