From 7975ad200caa994fdb0e6804c7ec5249cd168745 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Fri, 18 Mar 2011 18:56:28 +0200 Subject: [PATCH 1/3] Handle RPL_WHOISREGNICK messages in response to RequestContactInfo The RPL_WHOISREGNICK message indicates that the nick has identified itself. This is an extension of RFC 2812 implemented by some IRC daemons. eg., IRC-Hispano (http://ur1.ca/43e55) and UnrealIRCd (http://ur1.ca/43e4r). It seems that some daemons also use the same numeric for RPL_USERIP (http://www.alien.net.au/irc/irc2numerics.html) even though I could not find an actual example. However, some of them, like UnrealIRCd, actually use 340 for RPL_USERIP and the message has a format different enough to be detected by our parser. Therefore we should be reasonably safe. Fixes: https://bugs.freedesktop.org/34796 --- src/idle-contact-info.c | 20 ++++++++++++++++++++ src/idle-parser.c | 1 + src/idle-parser.h | 1 + 3 files changed, 22 insertions(+), 0 deletions(-) diff --git a/src/idle-contact-info.c b/src/idle-contact-info.c index fc193f5..da7136b 100644 --- a/src/idle-contact-info.c +++ b/src/idle-contact-info.c @@ -34,6 +34,7 @@ struct _ContactInfoRequest { guint handle; const gchar *nick; gboolean is_away; + gboolean is_reg_nick; GPtrArray *contact_info; DBusGMethodInvocation *context; }; @@ -101,6 +102,7 @@ static void _queue_request_contact_info(IdleConnection *conn, guint handle, cons request->handle = handle; request->nick = nick; request->is_away = FALSE; + request->is_reg_nick = FALSE; request->contact_info = NULL; request->context = context; @@ -184,6 +186,9 @@ static IdleParserHandlerResult _end_of_whois_handler(IdleParser *parser, IdlePar _insert_contact_field(request->contact_info, "x-presence-status-message", NULL, field_values); } + field_values[0] = (request->is_reg_nick) ? "true" : "false"; + _insert_contact_field(request->contact_info, "x-irc-registered-nick", NULL, field_values); + _return_from_request_contact_info(conn); return IDLE_PARSER_HANDLER_RESULT_NOT_HANDLED; } @@ -354,6 +359,20 @@ static IdleParserHandlerResult _whois_logged_in_handler(IdleParser *parser, Idle field_values[0] = nick; _insert_contact_field(request->contact_info, "nickname", NULL, field_values); + request->is_reg_nick = TRUE; + + return IDLE_PARSER_HANDLER_RESULT_NOT_HANDLED; +} + +static IdleParserHandlerResult _whois_reg_nick_handler(IdleParser *parser, IdleParserMessageCode code, GValueArray *args, gpointer user_data) { + IdleConnection *conn = IDLE_CONNECTION(user_data); + ContactInfoRequest *request = _get_matching_request(conn, args); + + if (request == NULL) + return IDLE_PARSER_HANDLER_RESULT_NOT_HANDLED; + + request->is_reg_nick = TRUE; + return IDLE_PARSER_HANDLER_RESULT_NOT_HANDLED; } @@ -440,6 +459,7 @@ void idle_contact_info_init (IdleConnection *conn) { idle_parser_add_handler(conn->parser, IDLE_PARSER_NUMERIC_WHOISSERVER, _whois_server_handler, conn); idle_parser_add_handler(conn->parser, IDLE_PARSER_NUMERIC_AWAY, _away_handler, conn); idle_parser_add_handler(conn->parser, IDLE_PARSER_NUMERIC_WHOISHOST, _whois_host_handler, conn); + idle_parser_add_handler(conn->parser, IDLE_PARSER_NUMERIC_WHOISREGNICK, _whois_reg_nick_handler, conn); idle_parser_add_handler(conn->parser, IDLE_PARSER_NUMERIC_WHOISIDLE, _whois_idle_handler, conn); idle_parser_add_handler(conn->parser, IDLE_PARSER_NUMERIC_WHOISLOGGEDIN, _whois_logged_in_handler, conn); idle_parser_add_handler(conn->parser, IDLE_PARSER_NUMERIC_ENDOFWHOIS, _end_of_whois_handler, conn); diff --git a/src/idle-parser.c b/src/idle-parser.c index 581a41e..0610416 100644 --- a/src/idle-parser.c +++ b/src/idle-parser.c @@ -113,6 +113,7 @@ static const MessageSpec message_specs[] = { {"319", "IIIc.", IDLE_PARSER_NUMERIC_WHOISCHANNELS}, {"378", "IIIc:", IDLE_PARSER_NUMERIC_WHOISHOST}, {"330", "IIIcs:", IDLE_PARSER_NUMERIC_WHOISLOGGEDIN}, + {"307", "IIIc:", IDLE_PARSER_NUMERIC_WHOISREGNICK}, {"312", "IIIcs:", IDLE_PARSER_NUMERIC_WHOISSERVER}, {"311", "IIIcssI:", IDLE_PARSER_NUMERIC_WHOISUSER}, {"317", "IIIcd", IDLE_PARSER_NUMERIC_WHOISIDLE}, diff --git a/src/idle-parser.h b/src/idle-parser.h index dbb9e0d..b756224 100644 --- a/src/idle-parser.h +++ b/src/idle-parser.h @@ -86,6 +86,7 @@ typedef enum { IDLE_PARSER_NUMERIC_WHOISCHANNELS, IDLE_PARSER_NUMERIC_WHOISHOST, IDLE_PARSER_NUMERIC_WHOISLOGGEDIN, + IDLE_PARSER_NUMERIC_WHOISREGNICK, IDLE_PARSER_NUMERIC_WHOISSERVER, IDLE_PARSER_NUMERIC_WHOISUSER, IDLE_PARSER_NUMERIC_WHOISIDLE, -- 1.7.4.4