changeset 10745:ca69d597a5e2

[gaim-migrate @ 12347] Get rid of serv_close (I got rid of serv_login earlier today). committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 27 Mar 2005 01:59:39 +0000
parents 1b927566fcc4
children 1f51dd1a7f87
files src/connection.c src/connection.h src/server.c src/server.h
diffstat 4 files changed, 59 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/src/connection.c	Sun Mar 27 01:14:41 2005 +0000
+++ b/src/connection.c	Sun Mar 27 01:59:39 2005 +0000
@@ -41,6 +41,37 @@
 
 static int connections_handle;
 
+static gboolean
+send_keepalive(gpointer data)
+{
+	GaimConnection *gc = data;
+	GaimPluginProtocolInfo *prpl_info = NULL;
+
+	if (gc != NULL && gc->prpl != NULL)
+		prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
+
+	if (prpl_info && prpl_info->keepalive)
+		prpl_info->keepalive(gc);
+
+	return TRUE;
+}
+
+static void
+update_keepalive(GaimConnection *gc, gboolean on)
+{
+	if (on && !gc->keepalive)
+	{
+		gaim_debug_info("connection", "Activating keepalive.\n");
+		gc->keepalive = gaim_timeout_add(30000, send_keepalive, gc);
+	}
+	else if (!on && gc->keepalive > 0)
+	{
+		gaim_debug_info("connection", "Deactivating keepalive.\n");
+		gaim_timeout_remove(gc->keepalive);
+		gc->keepalive = 0;
+	}
+}
+
 void
 gaim_connection_new(GaimAccount *account, gboolean regist, const char *password)
 {
@@ -119,18 +150,40 @@
 
 	account = gaim_connection_get_account(gc);
 
-	if (gaim_connection_get_state(gc) != GAIM_DISCONNECTED) {
+	if (gaim_connection_get_state(gc) != GAIM_DISCONNECTED)
+	{
 		GList *wins;
 		GaimPresence *presence = NULL;
+		GaimPluginProtocolInfo *prpl_info = NULL;
 
 		gaim_debug_info("connection", "Disconnecting connection %p\n", gc);
 
 		if (gaim_connection_get_state(gc) != GAIM_CONNECTING)
-			gaim_blist_remove_account(gaim_connection_get_account(gc));
+			gaim_blist_remove_account(account);
 
 		gaim_signal_emit(gaim_connections_get_handle(), "signing-off", gc);
 
-		serv_close(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));
+		}
+
+		if (gc->idle_timer > 0)
+			gaim_timeout_remove(gc->idle_timer);
+		gc->idle_timer = 0;
+
+		update_keepalive(gc, FALSE);
+
+		if (gc->prpl != NULL)
+		{
+			prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
+
+			if (prpl_info->close)
+				(prpl_info->close)(gc);
+		}
 
 		connections = g_list_remove(connections, gc);
 
@@ -276,6 +329,8 @@
 		}
 
 		serv_set_permit_deny(gc);
+
+		update_keepalive(gc, TRUE);
 	}
 	else if (gc->state == GAIM_DISCONNECTED) {
 		GaimAccount *account = gaim_connection_get_account(gc);
--- a/src/connection.h	Sun Mar 27 01:14:41 2005 +0000
+++ b/src/connection.h	Sun Mar 27 01:59:39 2005 +0000
@@ -86,7 +86,7 @@
 	void *proto_data;            /**< Protocol-specific data.            */
 
 	char *display_name;          /**< The name displayed.                */
-	guint keep_alive;            /**< Keep-alive.                        */
+	guint keepalive;             /**< Keep-alive.                        */
 
 	guint idle_timer;            /**< The idle timer.                    */
 	time_t login_time;           /**< Time of login.                     */
--- a/src/server.c	Sun Mar 27 01:14:41 2005 +0000
+++ b/src/server.c	Sun Mar 27 01:59:39 2005 +0000
@@ -44,57 +44,6 @@
 #define SECS_BEFORE_RESENDING_AUTORESPONSE 600
 #define SEX_BEFORE_RESENDING_AUTORESPONSE "Only after you're married"
 
-static gboolean send_keepalive(gpointer d)
-{
-	GaimConnection *gc = d;
-	GaimPluginProtocolInfo *prpl_info = NULL;
-
-	if (gc != NULL && gc->prpl != NULL)
-		prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
-
-	if (prpl_info && prpl_info->keepalive)
-		prpl_info->keepalive(gc);
-
-	return TRUE;
-}
-
-static void update_keepalive(GaimConnection *gc, gboolean on)
-{
-	if (on && !gc->keep_alive) {
-		gaim_debug(GAIM_DEBUG_INFO, "server", "allowing NOP\n");
-		gc->keep_alive = gaim_timeout_add(60000, send_keepalive, gc);
-	} else if (!on && gc->keep_alive > 0) {
-		gaim_debug(GAIM_DEBUG_INFO, "server", "removing NOP\n");
-		gaim_timeout_remove(gc->keep_alive);
-		gc->keep_alive = 0;
-	}
-}
-
-void serv_close(GaimConnection *gc)
-{
-	GaimPluginProtocolInfo *prpl_info = NULL;
-
-	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));
-	}
-
-	if (gc->idle_timer > 0)
-		gaim_timeout_remove(gc->idle_timer);
-	gc->idle_timer = 0;
-
-	update_keepalive(gc, FALSE);
-
-	if (gc->prpl != NULL) {
-		prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
-
-		if (prpl_info->close)
-			(prpl_info->close)(gc);
-	}
-}
-
 void serv_touch_idle(GaimConnection *gc)
 {
 	/* Are we idle?  If so, not anymore */
@@ -125,8 +74,6 @@
 
 	gc->idle_timer = gaim_timeout_add(20000, check_idle, gc);
 	serv_touch_idle(gc);
-
-	update_keepalive(gc, TRUE);
 }
 
 /* This should return the elapsed time in seconds in which Gaim will not send
--- a/src/server.h	Sun Mar 27 01:14:41 2005 +0000
+++ b/src/server.h	Sun Mar 27 01:59:39 2005 +0000
@@ -33,7 +33,6 @@
 extern "C" {
 #endif
 
-void serv_close(GaimConnection *);
 void serv_touch_idle(GaimConnection *);
 int  serv_send_im(GaimConnection *, const char *, const char *, GaimConvImFlags);
 void serv_get_info(GaimConnection *, const char *);