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_set_state(GaimConnection *gc, GaimConnectionState state) { GaimConnectionUiOps *ops; g_return_if_fail(gc != NULL); if (gc->state == state) return; gc->state = state; ops = gaim_get_connection_ui_ops(); if (gc->state == GAIM_CONNECTING) { connections_connecting = g_list_append(connections_connecting, gc); } else { connections_connecting = g_list_remove(connections_connecting, gc); } if (gc->state == GAIM_CONNECTED) { GaimBlistNode *gnode,*cnode,*bnode; GList *wins; GList *add_buds=NULL; /* Set the time the account came online */ time(&gc->login_time); if (ops != NULL && ops->connected != NULL) ops->connected(gc); gaim_blist_show(); gaim_blist_add_account(gc->account); /* * 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_ONLINE); } gaim_signal_emit(gaim_connections_get_handle(), "signed-on", gc); system_log(log_signon, gc, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); #if 0 /* away option given? */ if (opt_away) { away_on_login(opt_away_arg); /* don't do it again */ opt_away = 0; } else if (awaymessage) { serv_set_away(gc, GAIM_AWAY_CUSTOM, awaymessage->message); } if (opt_away_arg != NULL) { g_free(opt_away_arg); opt_away_arg = NULL; } #endif /* let the prpl know what buddies we pulled out of the local list */ for (gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) continue; for(cnode = gnode->child; cnode; cnode = cnode->next) { if(!GAIM_BLIST_NODE_IS_CONTACT(cnode)) continue; for(bnode = cnode->child; bnode; bnode = bnode->next) { GaimBuddy *b; if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) continue; b = (GaimBuddy *)bnode; if(b->account == gc->account) { add_buds = g_list_append(add_buds, b->name); } } } } if(add_buds) { serv_add_buddies(gc, add_buds); g_list_free(add_buds); } serv_set_permit_deny(gc); } else if (gc->state == GAIM_DISCONNECTED) { if (ops != NULL && ops->disconnected != NULL) ops->disconnected(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); }