static void chatnet_read(CONFIG_NODE *node) { CHAT_PROTOCOL_REC *proto; CHATNET_REC *rec; char *type; if (node == NULL || node->key == NULL) return; type = config_node_get_str(node, "type", NULL); proto = type == NULL ? NULL : chat_protocol_find(type); if (proto == NULL) { proto = type == NULL ? chat_protocol_get_default() : chat_protocol_get_unknown(type); } if (type == NULL) iconfig_node_set_str(node, "type", proto->name); rec = proto->create_chatnet(); rec->type = module_get_uniq_id("CHATNET", 0); rec->chat_type = proto->id; rec->name = g_strdup(node->key); rec->nick = g_strdup(config_node_get_str(node, "nick", NULL)); rec->username = g_strdup(config_node_get_str(node, "username", NULL)); rec->realname = g_strdup(config_node_get_str(node, "realname", NULL)); rec->own_host = g_strdup(config_node_get_str(node, "host", NULL)); rec->autosendcmd = g_strdup(config_node_get_str(node, "autosendcmd", NULL)); chatnets = g_slist_append(chatnets, rec); signal_emit("chatnet read", 2, rec, node); }
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; }
SERVER_REC *server_connect(SERVER_CONNECT_REC *conn) { CHAT_PROTOCOL_REC *proto; SERVER_REC *server; proto = CHAT_PROTOCOL(conn); server = proto->server_init_connect(conn); proto->server_connect(server); return server; }
static void test_server_destroy_flood(ServerDestroyFloodData *fixture, const void *data) { SERVER_REC *server; /* = g_new0(IRC_SERVER_REC, 1); */ CHAT_PROTOCOL_REC *proto; SERVER_CONNECT_REC *conn; GLogLevelFlags loglev; g_test_bug("796"); /* for the purpose of this exercise, we are ignoring the errors of g_hash_table_lookup failure */ loglev = g_log_set_always_fatal(G_LOG_FATAL_MASK); proto = chat_protocol_find("IRC"); conn = server_create_conn(proto->id, "localhost", 0, "", "", "user"); server = proto->server_init_connect(conn); server->session_reconnect = TRUE; server->tag = g_strdup("testserver"); g_test_message("created server: %p", server); /* we skip some initialisations that would try to send data */ /* irc_servers_deinit(); */ irc_session_deinit(); irc_irc_deinit(); server_connect_finished(server); /* make up for the skipped session init */ irc_server_init_bare_minimum(IRC_SERVER(server)); irc_irc_init(); irc_session_init(); /* irc_servers_init(); */ /* simulate failing irc_server_send_data() */ server->connection_lost = TRUE; /* chat_completion_deinit(); fe_messages_deinit(); irc_notifylist_deinit(); */ server_ref(server); signal_emit("event privmsg", 4, server, "#someroom :test message", "nick", "user@host"); server_unref(server); g_log_set_always_fatal(loglev); }
static void sig_layout_restore_item(WINDOW_REC *window, const char *type, CONFIG_NODE *node) { char *name, *tag, *chat_type; chat_type = config_node_get_str(node, "chat_type", NULL); name = config_node_get_str(node, "name", NULL); tag = config_node_get_str(node, "tag", NULL); if (name == NULL || tag == NULL) return; if (g_ascii_strcasecmp(type, "CHANNEL") == 0) { /* bind channel to window */ WINDOW_BIND_REC *rec = window_bind_add(window, tag, name); rec->sticky = TRUE; } else if (g_ascii_strcasecmp(type, "QUERY") == 0 && chat_type != NULL) { CHAT_PROTOCOL_REC *protocol; /* create query immediately */ signal_add("query created", (SIGNAL_FUNC) signal_query_created_curwin); restore_win = window; protocol = chat_protocol_find(chat_type); if (protocol == NULL) window_bind_add(window, tag, name); else if (protocol->query_create != NULL) protocol->query_create(tag, name, TRUE); else { QUERY_REC *query; query = g_new0(QUERY_REC, 1); query->chat_type = chat_protocol_lookup(chat_type); query->name = g_strdup(name); query->server_tag = g_strdup(tag); query_init(query, TRUE); } signal_remove("query created", (SIGNAL_FUNC) signal_query_created_curwin); } }
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 void session_restore_server(CONFIG_NODE *node) { CHAT_PROTOCOL_REC *proto; SERVER_CONNECT_REC *conn; SERVER_REC *server; const char *chat_type, *address, *chatnet, *password, *nick; int port, handle; chat_type = config_node_get_str(node, "chat_type", NULL); address = config_node_get_str(node, "address", NULL); port = config_node_get_int(node, "port", 0); chatnet = config_node_get_str(node, "chatnet", NULL); password = config_node_get_str(node, "password", NULL); nick = config_node_get_str(node, "nick", NULL); handle = config_node_get_int(node, "handle", -1); if (chat_type == NULL || address == NULL || nick == NULL || handle < 0) return; proto = chat_protocol_find(chat_type); if (proto == NULL || proto->not_initialized) { if (handle < 0) close(handle); return; } conn = server_create_conn(proto->id, address, port, chatnet, password, nick); if (conn != NULL) { conn->reconnection = TRUE; conn->connect_handle = g_io_channel_new(handle); server = proto->server_init_connect(conn); server->version = g_strdup(config_node_get_str(node, "version", NULL)); server->session_reconnect = TRUE; signal_emit("session restore server", 2, server, node); proto->server_connect(server); } }