# HG changeset patch # User Daniel Atallah # Date 1157830771 0 # Node ID a5c7db7be826ba7107d00dd675924486885aab0c # Parent 452007468387ad6335fce05f79fa3ea4139599b6 [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 diff -r 452007468387 -r a5c7db7be826 libgaim/protocols/irc/cmds.c --- 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 - * + * * 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); diff -r 452007468387 -r a5c7db7be826 libgaim/protocols/irc/irc.c --- 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 */ diff -r 452007468387 -r a5c7db7be826 libgaim/protocols/irc/irc.h --- 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 { diff -r 452007468387 -r a5c7db7be826 libgaim/protocols/irc/parse.c --- 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);