From 67574b0adbd6fc92e1435c13ec37d645122504c6 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Fri, 18 Mar 2011 18:56:28 +0200 Subject: [PATCH] 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), ShadowIRCd (http://ur1.ca/3khsr) and UnrealIRCd (http://ur1.ca/43e4r). It seems that some daemons also use the same numeric for RPL_BANEXPIRED (http://www.alien.net.au/irc/irc2numerics.html) even though I could not find an actual example. Therefore, to be safe, we only consider a message to be RPL_WHOISHOST if the trailing part has "is connecting from " as a prefix, followed by some non-whitespace characters. However this will adversely affect some versions of IRC-Hispano's daemon (http://ur1.ca/43e55), which uses Spanish text, but we can live with that. Fixes: https://bugs.freedesktop.org/34796 --- src/idle-contact-info.c | 33 +++++++++++++++++++++++++++++++++ src/idle-parser.c | 1 + src/idle-parser.h | 1 + 3 files changed, 35 insertions(+), 0 deletions(-) diff --git a/src/idle-contact-info.c b/src/idle-contact-info.c index 13ab770..db24587 100644 --- a/src/idle-contact-info.c +++ b/src/idle-contact-info.c @@ -304,6 +304,38 @@ 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; + + msg = g_value_dup_string(g_value_array_get_nth(args, 1)); + g_strchomp(msg); + + if (!g_str_has_prefix(msg, "is connecting from ")) + goto cleanup; + + 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); + + 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); + +cleanup: + 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; @@ -440,6 +472,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