void lost_connection_clears_chat_sessions(void **state) { chat_sessions_init(); chat_session_recipient_active("*****@*****.**", "laptop", FALSE); chat_session_recipient_active("*****@*****.**", "mobile", FALSE); expect_any_cons_show_error(); sv_ev_lost_connection(); ChatSession *session1 = chat_session_get("*****@*****.**"); ChatSession *session2 = chat_session_get("*****@*****.**"); assert_null(session1); assert_null(session2); }
void handle_offline_removes_chat_session(void **state) { chat_sessions_init(); char *barejid = "*****@*****.**"; char *resource = "home"; roster_init(); roster_add(barejid, "bob", NULL, "both", FALSE); Resource *resourcep = resource_new(resource, RESOURCE_ONLINE, NULL, 10); roster_update_presence(barejid, resourcep, NULL); chat_session_recipient_active(barejid, resource, FALSE); sv_ev_contact_offline(barejid, resource, NULL); ChatSession *session = chat_session_get(barejid); assert_null(session); roster_clear(); chat_sessions_clear(); }
void clears_chat_sessions(void **state) { chat_sessions_init(); roster_create(); chat_session_recipient_active("*****@*****.**", "laptop", FALSE); chat_session_recipient_active("*****@*****.**", "work", FALSE); will_return(connection_get_status, JABBER_CONNECTED); will_return(connection_get_fulljid, "*****@*****.**"); expect_any_cons_show(); gboolean result = cmd_disconnect(NULL, CMD_DISCONNECT, NULL); assert_true(result); ChatSession *session1 = chat_session_get("*****@*****.**"); ChatSession *session2 = chat_session_get("*****@*****.**"); assert_null(session1); assert_null(session2); }
void handle_offline_removes_chat_session(void **state) { plugins_init(); roster_create(); chat_sessions_init(); char *barejid = "*****@*****.**"; char *resource = "home"; roster_add(barejid, "bob", NULL, "both", FALSE); Resource *resourcep = resource_new(resource, RESOURCE_ONLINE, NULL, 10); roster_update_presence(barejid, resourcep, NULL); chat_session_recipient_active(barejid, resource, FALSE); ProfConsoleWin *console = malloc(sizeof(ProfConsoleWin)); will_return(win_create_console, &console->window); wins_init(); sv_ev_contact_offline(barejid, resource, NULL); ChatSession *session = chat_session_get(barejid); assert_null(session); roster_destroy(); chat_sessions_clear(); plugins_shutdown(); }
static void _connection_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status, const int error, xmpp_stream_error_t * const stream_error, void * const userdata) { // login success if (status == XMPP_CONN_CONNECT) { log_debug("Connection handler: XMPP_CONN_CONNECT"); // logged in with account if (saved_account.name != NULL) { log_debug("Connection handler: logged in with account name: %s", saved_account.name); handle_login_account_success(saved_account.name); // logged in without account, use details to create new account } else { log_debug("Connection handler: logged in with jid: %s", saved_details.name); accounts_add(saved_details.name, saved_details.altdomain, saved_details.port); accounts_set_jid(saved_details.name, saved_details.jid); handle_login_account_success(saved_details.name); saved_account.name = strdup(saved_details.name); saved_account.passwd = strdup(saved_details.passwd); _connection_free_saved_details(); } Jid *myJid = jid_create(jabber_get_fulljid()); jabber_conn.domain = strdup(myJid->domainpart); jid_destroy(myJid); chat_sessions_init(); roster_add_handlers(); message_add_handlers(); presence_add_handlers(); iq_add_handlers(); roster_request(); bookmark_request(); jabber_conn.conn_status = JABBER_CONNECTED; if (prefs_get_reconnect() != 0) { if (reconnect_timer != NULL) { g_timer_destroy(reconnect_timer); reconnect_timer = NULL; } } } else if (status == XMPP_CONN_DISCONNECT) { log_debug("Connection handler: XMPP_CONN_DISCONNECT"); // lost connection for unkown reason if (jabber_conn.conn_status == JABBER_CONNECTED) { log_debug("Connection handler: Lost connection for unknown reason"); handle_lost_connection(); if (prefs_get_reconnect() != 0) { assert(reconnect_timer == NULL); reconnect_timer = g_timer_new(); // free resources but leave saved_user untouched _connection_free_session_data(); } else { _connection_free_saved_account(); _connection_free_saved_details(); _connection_free_session_data(); } // login attempt failed } else if (jabber_conn.conn_status != JABBER_DISCONNECTING) { log_debug("Connection handler: Login failed"); if (reconnect_timer == NULL) { log_debug("Connection handler: No reconnect timer"); handle_failed_login(); _connection_free_saved_account(); _connection_free_saved_details(); _connection_free_session_data(); } else { log_debug("Connection handler: Restarting reconnect timer"); if (prefs_get_reconnect() != 0) { g_timer_start(reconnect_timer); } // free resources but leave saved_user untouched _connection_free_session_data(); } } // close stream response from server after disconnect is handled too jabber_conn.conn_status = JABBER_DISCONNECTED; } else if (status == XMPP_CONN_FAIL) { log_debug("Connection handler: XMPP_CONN_FAIL"); } else { log_error("Connection handler: Unknown status"); } }