summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2012-10-30 16:56:48 +0000
committerWill Thompson <will.thompson@collabora.co.uk>2012-10-30 16:59:03 +0000
commitf7766957dbb4ea80ac86d65b83f361b8c82aab45 (patch)
treed4fd718ae64e20fb2eecbf66b4073491c4084354
parent339c7273dcb604a639ea2b54461b24bd4f252dd6 (diff)
Disable keepalive pings if server doesn't support PING.
I don't know which servers don't support PING, but irssi does this, so I figure we may as well do it too. I tested this by making Idle send and check for PNNING, which Freenode doesn't support. It's not obvious how to write a good automated test for this.
-rw-r--r--src/idle-connection.c19
-rw-r--r--src/idle-parser.c1
-rw-r--r--src/idle-parser.h1
3 files changed, 21 insertions, 0 deletions
diff --git a/src/idle-connection.c b/src/idle-connection.c
index a7c4f73..07adc92 100644
--- a/src/idle-connection.c
+++ b/src/idle-connection.c
@@ -214,6 +214,7 @@ static IdleParserHandlerResult _nick_handler(IdleParser *parser, IdleParserMessa
static IdleParserHandlerResult _nickname_in_use_handler(IdleParser *parser, IdleParserMessageCode code, GValueArray *args, gpointer user_data);
static IdleParserHandlerResult _ping_handler(IdleParser *parser, IdleParserMessageCode code, GValueArray *args, gpointer user_data);
static IdleParserHandlerResult _pong_handler(IdleParser *parser, IdleParserMessageCode code, GValueArray *args, gpointer user_data);
+static IdleParserHandlerResult _unknown_command_handler(IdleParser *parser, IdleParserMessageCode code, GValueArray *args, gpointer user_data);
static IdleParserHandlerResult _version_privmsg_handler(IdleParser *parser, IdleParserMessageCode code, GValueArray *args, gpointer user_data);
static IdleParserHandlerResult _welcome_handler(IdleParser *parser, IdleParserMessageCode code, GValueArray *args, gpointer user_data);
static IdleParserHandlerResult _whois_user_handler(IdleParser *parser, IdleParserMessageCode code, GValueArray *args, gpointer user_data);
@@ -713,6 +714,7 @@ static void _connection_connect_ready(GObject *source_object, GAsyncResult *res,
idle_parser_add_handler(conn->parser, IDLE_PARSER_CMD_PING, _ping_handler, conn);
idle_parser_add_handler(conn->parser, IDLE_PARSER_PREFIXCMD_PONG, _pong_handler, conn);
+ idle_parser_add_handler(conn->parser, IDLE_PARSER_NUMERIC_UNKNOWNCOMMAND, _unknown_command_handler, conn);
idle_parser_add_handler_with_priority(conn->parser, IDLE_PARSER_PREFIXCMD_NICK, _nick_handler, conn, IDLE_PARSER_HANDLER_PRIORITY_FIRST);
idle_parser_add_handler(conn->parser, IDLE_PARSER_PREFIXCMD_PRIVMSG_USER, _version_privmsg_handler, conn);
@@ -1105,6 +1107,23 @@ static IdleParserHandlerResult _pong_handler(IdleParser *parser, IdleParserMessa
return IDLE_PARSER_HANDLER_RESULT_HANDLED;
}
+static IdleParserHandlerResult _unknown_command_handler(IdleParser *parser, IdleParserMessageCode code, GValueArray *args, gpointer user_data) {
+ IdleConnection *conn = IDLE_CONNECTION(user_data);
+ IdleConnectionPrivate *priv = conn->priv;
+ const gchar *command = g_value_get_string(g_value_array_get_nth(args, 0));
+
+ if (!tp_strdiff(command, "PING")) {
+ IDLE_DEBUG("PING not supported, disabling keepalive.");
+ g_source_remove(priv->keepalive_timeout);
+ priv->keepalive_timeout = 0;
+ priv->ping_time = 0;
+
+ return IDLE_PARSER_HANDLER_RESULT_HANDLED;
+ }
+
+ return IDLE_PARSER_HANDLER_RESULT_NOT_HANDLED;
+}
+
static IdleParserHandlerResult _version_privmsg_handler(IdleParser *parser, IdleParserMessageCode code, GValueArray *args, gpointer user_data) {
IdleConnection *conn = IDLE_CONNECTION(user_data);
const gchar *msg = g_value_get_string(g_value_array_get_nth(args, 2));
diff --git a/src/idle-parser.c b/src/idle-parser.c
index 47ac0e5..1699774 100644
--- a/src/idle-parser.c
+++ b/src/idle-parser.c
@@ -122,6 +122,7 @@ static const MessageSpec message_specs[] = {
{"317", "IIIcd", IDLE_PARSER_NUMERIC_WHOISIDLE},
{"322", "IIIrd.", IDLE_PARSER_NUMERIC_LIST},
{"323", "I", IDLE_PARSER_NUMERIC_LISTEND},
+ {"421", "IIIs:", IDLE_PARSER_NUMERIC_UNKNOWNCOMMAND},
{NULL, NULL, IDLE_PARSER_LAST_MESSAGE_CODE}
};
diff --git a/src/idle-parser.h b/src/idle-parser.h
index 1216054..7ba333e 100644
--- a/src/idle-parser.h
+++ b/src/idle-parser.h
@@ -97,6 +97,7 @@ typedef enum {
IDLE_PARSER_NUMERIC_WHOISIDLE,
IDLE_PARSER_NUMERIC_LIST,
IDLE_PARSER_NUMERIC_LISTEND,
+ IDLE_PARSER_NUMERIC_UNKNOWNCOMMAND,
IDLE_PARSER_LAST_MESSAGE_CODE
} IdleParserMessageCode;