From dc891db9e8499ecafb1f3a2403ad836a514f6945 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_WHOISHOST messages in response to RequestContactInfo The RPL_WHOISHOST message indicates the host name and IP address from which the nick is connected to the server. This message is received only if the nick against which the WHOIS message was sent is the one that sent the it. This is an extension of RFC 2812 implemented by some IRC daemons. eg., ircd-seven (http://ur1.ca/3khrh) and ShadowIRCd (http://ur1.ca/3khsr). Fixes: https://bugs.freedesktop.org/34796 --- src/idle-contact-info.c | 28 ++++++++++++++++++++++++++++ src/idle-parser.c | 1 + src/idle-parser.h | 1 + 3 files changed, 30 insertions(+), 0 deletions(-) diff --git a/src/idle-contact-info.c b/src/idle-contact-info.c index b91e93d..987ec30 100644 --- a/src/idle-contact-info.c +++ b/src/idle-contact-info.c @@ -301,6 +301,33 @@ static IdleParserHandlerResult _whois_channels_handler(IdleParser *parser, IdleP return IDLE_PARSER_HANDLER_RESULT_NOT_HANDLED; } +static IdleParserHandlerResult _whois_host_handler(IdleParser *parser, IdleParserMessageCode code, GValueArray *args, gpointer user_data) { + IdleConnection *conn = IDLE_CONNECTION(user_data); + ContactInfoRequest *request; + gchar *msg; + gchar **msgv; + + if (!_is_valid_response(conn, args)) + return IDLE_PARSER_HANDLER_RESULT_NOT_HANDLED; + + request = g_queue_peek_head(conn->contact_info_requests); + + if (request->contact_info == NULL) + request->contact_info = dbus_g_type_specialized_construct(TP_ARRAY_TYPE_CONTACT_INFO_FIELD_LIST); + + msg = g_value_dup_string(g_value_array_get_nth(args, 1)); + g_strchomp(msg); + msgv = g_strsplit(msg, " ", -1); + + /* msg == "is connecting from *@ " */ + _insert_contact_field(request->contact_info, "x-host", NULL, (const gchar **) (msgv + 3)); + + g_strfreev(msgv); + g_free(msg); + + return IDLE_PARSER_HANDLER_RESULT_NOT_HANDLED; +} + static IdleParserHandlerResult _whois_idle_handler(IdleParser *parser, IdleParserMessageCode code, GValueArray *args, gpointer user_data) { IdleConnection *conn = IDLE_CONNECTION(user_data); ContactInfoRequest *request; @@ -437,6 +464,7 @@ void idle_contact_info_init (IdleConnection *conn) { idle_parser_add_handler(conn->parser, IDLE_PARSER_NUMERIC_WHOISCHANNELS, _whois_channels_handler, 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_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 afb58f3..581a41e 100644 --- a/src/idle-parser.c +++ b/src/idle-parser.c @@ -111,6 +111,7 @@ static const MessageSpec message_specs[] = { {"305", "III", IDLE_PARSER_NUMERIC_UNAWAY}, {"001", "IIc", IDLE_PARSER_NUMERIC_WELCOME}, {"319", "IIIc.", IDLE_PARSER_NUMERIC_WHOISCHANNELS}, + {"378", "IIIc:", IDLE_PARSER_NUMERIC_WHOISHOST}, {"330", "IIIcs:", IDLE_PARSER_NUMERIC_WHOISLOGGEDIN}, {"312", "IIIcs:", IDLE_PARSER_NUMERIC_WHOISSERVER}, {"311", "IIIcssI:", IDLE_PARSER_NUMERIC_WHOISUSER}, diff --git a/src/idle-parser.h b/src/idle-parser.h index 4a91241..dbb9e0d 100644 --- a/src/idle-parser.h +++ b/src/idle-parser.h @@ -84,6 +84,7 @@ typedef enum { IDLE_PARSER_NUMERIC_UNAWAY, IDLE_PARSER_NUMERIC_WELCOME, IDLE_PARSER_NUMERIC_WHOISCHANNELS, + IDLE_PARSER_NUMERIC_WHOISHOST, IDLE_PARSER_NUMERIC_WHOISLOGGEDIN, IDLE_PARSER_NUMERIC_WHOISSERVER, IDLE_PARSER_NUMERIC_WHOISUSER, -- 1.7.4.4