void gaim_connection_disconnect(GaimConnection *gc) { GaimAccount *account; GList *wins; g_return_if_fail(gc != NULL); account = gaim_connection_get_account(gc); if (gaim_account_get_connection(account) != NULL) { gaim_account_disconnect(account); return; } gaim_debug(GAIM_DEBUG_INFO, "connection", "Disconnecting connection %p\n", gc); if (gaim_connection_get_state(gc) != GAIM_DISCONNECTED) { if (gaim_connection_get_state(gc) != GAIM_CONNECTING) gaim_blist_remove_account(gaim_connection_get_account(gc)); gaim_signal_emit(gaim_connections_get_handle(), "signing-off", gc); serv_close(gc); connections = g_list_remove(connections, gc); gaim_connection_set_state(gc, GAIM_DISCONNECTED); gaim_signal_emit(gaim_connections_get_handle(), "signed-off", gc); system_log(log_signoff, gc, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); /* * XXX This is a hack! Remove this and replace it with a better event * notification system. */ for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) { GaimWindow *win = (GaimWindow *)wins->data; gaim_conversation_update(gaim_window_get_conversation_at(win, 0), GAIM_CONV_ACCOUNT_OFFLINE); } gaim_request_close_with_handle(gc); gaim_notify_close_with_handle(gc); } gaim_connection_destroy(gc); }
void gaim_connection_destroy(GaimConnection *gc) { GaimAccount *account; GSList *buddies, *tmp; #if 0 GList *wins; #endif GaimPluginProtocolInfo *prpl_info = NULL; gboolean remove = FALSE; g_return_if_fail(gc != NULL); account = gaim_connection_get_account(gc); gaim_debug_info("connection", "Disconnecting connection %p\n", gc); if (gaim_connection_get_state(gc) != GAIM_CONNECTING) remove = TRUE; gaim_signal_emit(gaim_connections_get_handle(), "signing-off", gc); while (gc->buddy_chats) { GaimConversation *b = gc->buddy_chats->data; gc->buddy_chats = g_slist_remove(gc->buddy_chats, b); gaim_conv_chat_left(GAIM_CONV_CHAT(b)); } update_keepalive(gc, FALSE); gaim_proxy_connect_cancel_with_handle(gc); prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); if (prpl_info->close) (prpl_info->close)(gc); /* Clear out the proto data that was freed in the prpl close method*/ buddies = gaim_find_buddies(account, NULL); for (tmp = buddies; tmp; tmp = tmp->next) { GaimBuddy *buddy = tmp->data; buddy->proto_data = NULL; } g_slist_free(buddies); connections = g_list_remove(connections, gc); gaim_connection_set_state(gc, GAIM_DISCONNECTED); if (remove) gaim_blist_remove_account(account); gaim_signal_emit(gaim_connections_get_handle(), "signed-off", gc); #if 0 /* see comment later in file on if 0'd same code */ /* * XXX This is a hack! Remove this and replace it with a better event * notification system. */ for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) { GaimConvWindow *win = (GaimConvWindow *)wins->data; gaim_conversation_update(gaim_conv_window_get_conversation_at(win, 0), GAIM_CONV_ACCOUNT_OFFLINE); } #endif gaim_request_close_with_handle(gc); gaim_notify_close_with_handle(gc); gaim_debug_info("connection", "Destroying connection %p\n", gc); gaim_account_set_connection(account, NULL); g_free(gc->password); g_free(gc->display_name); if (gc->disconnect_timeout) gaim_timeout_remove(gc->disconnect_timeout); GAIM_DBUS_UNREGISTER_POINTER(gc); g_free(gc); }