From: <dat...@us...> - 2006-09-09 19:39:36
|
Revision: 17201 http://svn.sourceforge.net/gaim/?rev=17201&view=rev Author: datallah Date: 2006-09-09 12:39:31 -0700 (Sat, 09 Sep 2006) Log Message: ----------- 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. Modified Paths: -------------- trunk/libgaim/protocols/irc/cmds.c trunk/libgaim/protocols/irc/irc.c trunk/libgaim/protocols/irc/irc.h trunk/libgaim/protocols/irc/parse.c Modified: trunk/libgaim/protocols/irc/cmds.c =================================================================== --- trunk/libgaim/protocols/irc/cmds.c 2006-09-09 19:31:45 UTC (rev 17200) +++ trunk/libgaim/protocols/irc/cmds.c 2006-09-09 19:39:31 UTC (rev 17201) @@ -1,10 +1,10 @@ /** * @file cmds.c - * + * * gaim * * Copyright (C) 2003, Ethan Blanton <ebl...@cs...> - * + * * 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); Modified: trunk/libgaim/protocols/irc/irc.c =================================================================== --- trunk/libgaim/protocols/irc/irc.c 2006-09-09 19:31:45 UTC (rev 17200) +++ trunk/libgaim/protocols/irc/irc.c 2006-09-09 19:39:31 UTC (rev 17201) @@ -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 */ Modified: trunk/libgaim/protocols/irc/irc.h =================================================================== --- trunk/libgaim/protocols/irc/irc.h 2006-09-09 19:31:45 UTC (rev 17200) +++ trunk/libgaim/protocols/irc/irc.h 2006-09-09 19:39:31 UTC (rev 17201) @@ -83,6 +83,8 @@ GaimCircBuffer *outbuf; guint writeh; + + time_t recv_time; }; struct irc_buddy { Modified: trunk/libgaim/protocols/irc/parse.c =================================================================== --- trunk/libgaim/protocols/irc/parse.c 2006-09-09 19:31:45 UTC (rev 17200) +++ trunk/libgaim/protocols/irc/parse.c 2006-09-09 19:39:31 UTC (rev 17201) @@ -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); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sea...@us...> - 2006-09-25 21:08:42
|
Revision: 17350 http://svn.sourceforge.net/gaim/?rev=17350&view=rev Author: seanegan Date: 2006-09-25 14:08:39 -0700 (Mon, 25 Sep 2006) Log Message: ----------- IRC signals for scripting IRC. Richard, you should use these for irchelper! Modified Paths: -------------- trunk/libgaim/protocols/irc/irc.c trunk/libgaim/protocols/irc/parse.c Modified: trunk/libgaim/protocols/irc/irc.c =================================================================== --- trunk/libgaim/protocols/irc/irc.c 2006-09-25 14:47:33 UTC (rev 17349) +++ trunk/libgaim/protocols/irc/irc.c 2006-09-25 21:08:39 UTC (rev 17350) @@ -61,7 +61,7 @@ static gboolean irc_nick_equal(const char *nick1, const char *nick2); static void irc_buddy_free(struct irc_buddy *ib); -static GaimPlugin *_irc_plugin = NULL; +GaimPlugin *_irc_plugin = NULL; static const char *status_chars = "@+%&"; @@ -141,18 +141,26 @@ int irc_send(struct irc_conn *irc, const char *buf) { - int ret, buflen = strlen(buf); + int ret, buflen; + char *tosend= g_strdup(buf); + gaim_signal_emit(_irc_plugin, "irc-sending_text", gaim_account_get_connection(irc->account), &tosend); + if (tosend == NULL) + return 0; + + buflen = strlen(tosend); + + /* If we're not buffering writes, try to send immediately */ if (!irc->writeh) - ret = do_send(irc, buf, buflen); + ret = do_send(irc, tosend, buflen); else { ret = -1; errno = EAGAIN; } /* gaim_debug(GAIM_DEBUG_MISC, "irc", "sent%s: %s", - irc->gsc ? " (ssl)" : "", buf); */ + irc->gsc ? " (ssl)" : "", tosend); */ if (ret <= 0 && errno != EAGAIN) { gaim_connection_error(gaim_account_get_connection(irc->account), _("Server has disconnected")); @@ -163,10 +171,10 @@ irc->writeh = gaim_input_add( irc->gsc ? irc->gsc->fd : irc->fd, GAIM_INPUT_WRITE, irc_send_cb, irc); - gaim_circ_buffer_append(irc->outbuf, buf + ret, + gaim_circ_buffer_append(irc->outbuf, tosend + ret, buflen - ret); } - + g_free(tosend); return ret; } @@ -869,7 +877,20 @@ irc_send_raw, /* send_raw */ }; +static gboolean load_plugin (GaimPlugin *plugin) { + gaim_signal_register(plugin, "irc-sending-text", + gaim_marshal_VOID__POINTER_POINTER, NULL, 2, + gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_CONNECTION), + gaim_value_new_outgoing(GAIM_TYPE_STRING)); + gaim_signal_register(plugin, "irc-receiving-text", + gaim_marshal_VOID__POINTER_POINTER, NULL, 2, + gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_CONNECTION), + gaim_value_new_outgoing(GAIM_TYPE_STRING)); + return TRUE; +} + + static GaimPluginInfo info = { GAIM_PLUGIN_MAGIC, @@ -889,7 +910,7 @@ NULL, /**< author */ GAIM_WEBSITE, /**< homepage */ - NULL, /**< load */ + load_plugin, /**< load */ NULL, /**< unload */ NULL, /**< destroy */ Modified: trunk/libgaim/protocols/irc/parse.c =================================================================== --- trunk/libgaim/protocols/irc/parse.c 2006-09-25 14:47:33 UTC (rev 17349) +++ trunk/libgaim/protocols/irc/parse.c 2006-09-25 21:08:39 UTC (rev 17350) @@ -44,6 +44,8 @@ "orange", "yellow", "green", "teal", "cyan", "light blue", "pink", "grey", "light grey" }; +extern GaimPlugin *_irc_plugin; + /*typedef void (*IRCMsgCallback)(struct irc_conn *irc, char *from, char *name, char **args);*/ static struct _irc_msg { char *name; @@ -534,7 +536,8 @@ guint i; irc->recv_time = time(NULL); - + gaim_signal_emit(_irc_plugin, "irc-receiving-text", gaim_account_get_connection(irc->account), &input); + if (!strncmp(input, "PING ", 5)) { msg = irc_format(irc, "vv", "PONG", input + 5); irc_send(irc, msg); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |