changeset 14482:a5c7db7be826

[gaim-migrate @ 17201] Prevent irc accounts from being disconnected for long periods without us noticing. Use the prpl keepalive cb to ping the server if we haven't received anything in at least 60 seconds. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Sat, 09 Sep 2006 19:39:31 +0000
parents 452007468387
children af856551902b
files libgaim/protocols/irc/cmds.c libgaim/protocols/irc/irc.c libgaim/protocols/irc/irc.h libgaim/protocols/irc/parse.c
diffstat 4 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libgaim/protocols/irc/cmds.c	Sat Sep 09 19:31:45 2006 +0000
+++ b/libgaim/protocols/irc/cmds.c	Sat Sep 09 19:39:31 2006 +0000
@@ -1,10 +1,10 @@
 /**
  * @file cmds.c
- * 
+ *
  * gaim
  *
  * Copyright (C) 2003, Ethan Blanton <eblanton@cs.purdue.edu>
- * 
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
@@ -336,10 +336,14 @@
 		stamp = g_strdup_printf("\001PING %lu\001", time(NULL));
 		buf = irc_format(irc, "vn:", "PRIVMSG", args[0], stamp);
 		g_free(stamp);
-	} else {
+	} else if (target) {
 		stamp = g_strdup_printf("%s %lu", target, time(NULL));
 		buf = irc_format(irc, "v:", "PING", stamp);
 		g_free(stamp);
+	} else {
+		stamp = g_strdup_printf("%lu", time(NULL));
+		buf = irc_format(irc, "vv", "PING", stamp);
+		g_free(stamp);
 	}
 	irc_send(irc, buf);
 	g_free(buf);
--- a/libgaim/protocols/irc/irc.c	Sat Sep 09 19:31:45 2006 +0000
+++ b/libgaim/protocols/irc/irc.c	Sat Sep 09 19:39:31 2006 +0000
@@ -37,6 +37,8 @@
 
 #include "irc.h"
 
+#define PING_TIMEOUT 60
+
 static void irc_buddy_append(char *name, struct irc_buddy *ib, GString *string);
 
 static const char *irc_blist_icon(GaimAccount *a, GaimBuddy *b);
@@ -373,6 +375,8 @@
 	}
 	g_free(buf);
 
+	irc->recv_time = time(NULL);
+
 	return TRUE;
 }
 
@@ -787,6 +791,13 @@
 	}
 }
 
+static void irc_keepalive(GaimConnection *gc)
+{
+	struct irc_conn *irc = gc->proto_data;
+	if ((time(NULL) - irc->recv_time) > PING_TIMEOUT)
+		irc_cmd_ping(irc, NULL, NULL, NULL);
+}
+
 static GaimPluginProtocolInfo prpl_info =
 {
 	OPT_PROTO_CHAT_TOPIC | OPT_PROTO_PASSWORD_OPTIONAL,
@@ -826,7 +837,7 @@
 	irc_chat_leave,		/* chat_leave */
 	NULL,					/* chat_whisper */
 	irc_chat_send,		/* chat_send */
-	NULL,					/* keepalive */
+	irc_keepalive,		/* keepalive */
 	NULL,					/* register_user */
 	NULL,					/* get_cb_info */
 	NULL,					/* get_cb_away */
--- a/libgaim/protocols/irc/irc.h	Sat Sep 09 19:31:45 2006 +0000
+++ b/libgaim/protocols/irc/irc.h	Sat Sep 09 19:39:31 2006 +0000
@@ -83,6 +83,8 @@
 
 	GaimCircBuffer *outbuf;
 	guint writeh;
+
+	time_t recv_time;
 };
 
 struct irc_buddy {
--- a/libgaim/protocols/irc/parse.c	Sat Sep 09 19:31:45 2006 +0000
+++ b/libgaim/protocols/irc/parse.c	Sat Sep 09 19:39:31 2006 +0000
@@ -533,6 +533,8 @@
 	char *cur, *end, *tmp, *from, *msgname, *fmt, **args, *msg;
 	guint i;
 
+	irc->recv_time = time(NULL);
+
 	if (!strncmp(input, "PING ", 5)) {
 		msg = irc_format(irc, "vv", "PONG", input + 5);
 		irc_send(irc, msg);