static void _jabber_lost_connection(void) { sv_ev_lost_connection(); if (prefs_get_reconnect() != 0) { assert(reconnect_timer == NULL); reconnect_timer = g_timer_new(); } else { _connection_free_saved_account(); _connection_free_saved_details(); } _connection_free_session_data(); }
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); }
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) { log_debug("Connection handler: logged in with account name: %s", saved_account.name); sv_ev_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); sv_ev_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 *my_jid = jid_create(jabber_get_fulljid()); jabber_conn.domain = strdup(my_jid->domainpart); jid_destroy(my_jid); chat_sessions_init(); roster_add_handlers(); message_add_handlers(); presence_add_handlers(); iq_add_handlers(); roster_request(); bookmark_request(); if (prefs_get_boolean(PREF_CARBONS)){ iq_enable_carbons(); } jabber_conn.conn_status = JABBER_CONNECTED; if (prefs_get_reconnect() != 0) { if (reconnect_timer) { g_timer_destroy(reconnect_timer); reconnect_timer = NULL; } } } else if (status == XMPP_CONN_DISCONNECT) { log_debug("Connection handler: XMPP_CONN_DISCONNECT"); // lost connection for unknown reason if (jabber_conn.conn_status == JABBER_CONNECTED) { log_debug("Connection handler: Lost connection for unknown reason"); sv_ev_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"); sv_ev_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"); } }