# HG changeset patch # User Jeffrey Connelly # Date 1183584085 0 # Node ID d0c8b774806580fd866ef87c176bea99ded93038 # Parent 87b77f1ea086970909f405cf0753a4021f57fd94 Add msim_check_alive(), called every MSIM_KEEPALIVE_INTERVAL_CHECK milliseconds, to recognize the server disconnection if no data was received within MSIM_KEEPALIVE_INTERVAL seconds. This is support for keep-alives. diff -r 87b77f1ea086 -r d0c8b7748065 libpurple/protocols/myspace/CHANGES --- a/libpurple/protocols/myspace/CHANGES Wed Jul 04 19:05:21 2007 +0000 +++ b/libpurple/protocols/myspace/CHANGES Wed Jul 04 21:21:25 2007 +0000 @@ -1,6 +1,8 @@ 2007-07-xx Jeff Connelly - 0.11 * Allow going idle (tested with I'dle Ma'ker) and viewing idle status of buddies - (thanks to Scott Ellis for finding the idle status code.) + (thanks to Scott Ellis, developing a MySpaceIM plugin for Miranda IM, + for finding the idle status code.) +* Time out if no data from server within a certain amount of time (keep alives). 2007-07-03 Jeff Connelly - 0.10 * On incoming instant messages, add support for: diff -r 87b77f1ea086 -r d0c8b7748065 libpurple/protocols/myspace/myspace.c --- a/libpurple/protocols/myspace/myspace.c Wed Jul 04 19:05:21 2007 +0000 +++ b/libpurple/protocols/myspace/myspace.c Wed Jul 04 21:21:25 2007 +0000 @@ -1421,6 +1421,36 @@ } } +/** Check if the connection is still alive, based on last communication. */ +gboolean +msim_check_alive(gpointer data) +{ + MsimSession *session; + time_t delta; + gchar *errmsg; + + session = (MsimSession *)data; + + delta = time(NULL) - session->last_comm; + purple_debug_info("msim", "msim_check_alive: delta=%d\n", delta); + if (delta >= MSIM_KEEPALIVE_INTERVAL) + { + errmsg = g_strdup_printf(_("Connection to server lost (no data received within %d seconds)"), delta); + + purple_debug_info("msim", "msim_check_alive: %s > interval of %d, presumed dead\n", + errmsg, MSIM_KEEPALIVE_INTERVAL); + purple_connection_error(session->gc, errmsg); + + purple_notify_error(session->gc, NULL, errmsg, NULL); + + g_free(errmsg); + + return FALSE; + } + + return TRUE; +} + /** Called when the session key arrives. */ gboolean msim_we_are_logged_on(MsimSession *session, MsimMessage *msg) @@ -1449,11 +1479,15 @@ #endif /* Set status depending on preference. */ + /* TODO: set status to current status, change status to hidden if sign on as hidden. + * Or remove this preference alltogether, and set status to current status? */ msim_set_status_code(session, purple_account_get_bool(session->account, "hidden", FALSE) ? PURPLE_STATUS_INVISIBLE : PURPLE_STATUS_AVAILABLE); + purple_timeout_add(MSIM_KEEPALIVE_INTERVAL_CHECK, msim_check_alive, session); + return TRUE; } @@ -2148,6 +2182,9 @@ g_return_if_fail(cond == PURPLE_INPUT_READ); g_return_if_fail(MSIM_SESSION_VALID(session)); + /* Mark down that we got data, so don't timeout. */ + session->last_comm = time(NULL); + /* Only can handle so much data at once... * If this happens, try recompiling with a higher MSIM_READ_BUF_SIZE. * Should be large enough to hold the largest protocol message. @@ -2345,6 +2382,7 @@ session->rxoff = 0; session->rxbuf = g_new0(gchar, MSIM_READ_BUF_SIZE); session->next_rid = 1; + session->last_comm = time(NULL); return session; } diff -r 87b77f1ea086 -r d0c8b7748065 libpurple/protocols/myspace/myspace.h --- a/libpurple/protocols/myspace/myspace.h Wed Jul 04 19:05:21 2007 +0000 +++ b/libpurple/protocols/myspace/myspace.h Wed Jul 04 21:21:25 2007 +0000 @@ -83,11 +83,16 @@ /* Build version of MySpaceIM to report to servers (1.0.xxx.0) */ #define MSIM_CLIENT_VERSION 673 -/* Server */ +/* Default server */ #define MSIM_SERVER "im.myspace.akadns.net" -//#define MSIM_SERVER "localhost" #define MSIM_PORT 1863 /* TODO: alternate ports and automatic */ +/* Time between keepalives (seconds) - if no data within this time, is dead. */ +#define MSIM_KEEPALIVE_INTERVAL (3 * 60) + +/* Time to check if alive (milliseconds) */ +#define MSIM_KEEPALIVE_INTERVAL_CHECK (MSIM_KEEPALIVE_INTERVAL * 1000 / 5) + /* Constants */ #define HASH_SIZE 0x14 /**< Size of SHA-1 hash for login */ #define NONCE_SIZE 0x20 /**< Half of decoded 'nc' field */ @@ -156,6 +161,7 @@ gchar *rxbuf; /**< Receive buffer */ guint rxoff; /**< Receive buffer offset */ guint next_rid; /**< Next request/response ID */ + time_t last_comm; /**< Time received last communication */ } MsimSession; /* Check if an MsimSession is valid */ @@ -213,6 +219,7 @@ gboolean msim_preprocess_incoming(MsimSession *session, MsimMessage *msg); +gboolean msim_check_alive(gpointer data); gboolean msim_we_are_logged_on(MsimSession *session, MsimMessage *msg); gboolean msim_process(MsimSession *session, MsimMessage *msg);