From 657a4755d7dc1034635cb1a3a9ddf5b0d00061d0 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Fri, 18 Mar 2011 04:02:29 +0200 Subject: [PATCH] Handle RPL_WHOISCHANNELS messages in response to RequestContactInfo Fixes: https://bugs.freedesktop.org/34796 --- src/idle-contact-info.c | 32 ++++++++++++++++++++++++++++++++ src/idle-parser.c | 1 + src/idle-parser.h | 1 + 3 files changed, 34 insertions(+), 0 deletions(-) diff --git a/src/idle-contact-info.c b/src/idle-contact-info.c index afd3598..cc20e87 100644 --- a/src/idle-contact-info.c +++ b/src/idle-contact-info.c @@ -284,6 +284,37 @@ cleanup: return IDLE_PARSER_HANDLER_RESULT_NOT_HANDLED; } +static IdleParserHandlerResult _whois_channels_handler(IdleParser *parser, IdleParserMessageCode code, GValueArray *args, gpointer user_data) { + IdleConnection *conn = IDLE_CONNECTION(user_data); + ContactInfoRequest *request; + gchar *channels; + gchar **channelsv; + const gchar *field_values[2] = {NULL, NULL}; + guint i; + + 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); + + channels = g_value_dup_string(g_value_array_get_nth(args, 1)); + g_strchomp(channels); + channelsv = g_strsplit(channels, " ", -1); + + for (i = 0; channelsv[i] != NULL; i++) { + field_values[0] = channelsv[i]; + _insert_contact_field(request->contact_info, "x-irc-channel", NULL, field_values); + } + + g_strfreev(channelsv); + g_free(channels); + + 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; @@ -364,6 +395,7 @@ void idle_contact_info_init (IdleConnection *conn) { conn->contact_info_requests = g_queue_new(); idle_parser_add_handler(conn->parser, IDLE_PARSER_NUMERIC_WHOISUSER, _whois_user_handler, conn); + idle_parser_add_handler(conn->parser, IDLE_PARSER_NUMERIC_WHOISCHANNELS, _whois_channels_handler, conn); idle_parser_add_handler(conn->parser, IDLE_PARSER_NUMERIC_AWAY, _away_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_ENDOFWHOIS, _end_of_whois_handler, conn); diff --git a/src/idle-parser.c b/src/idle-parser.c index f595553..8110757 100644 --- a/src/idle-parser.c +++ b/src/idle-parser.c @@ -108,6 +108,7 @@ static const MessageSpec message_specs[] = { {"333", "IIIrcd", IDLE_PARSER_NUMERIC_TOPIC_STAMP}, {"305", "III", IDLE_PARSER_NUMERIC_UNAWAY}, {"001", "IIc", IDLE_PARSER_NUMERIC_WELCOME}, + {"319", "IIIc.", IDLE_PARSER_NUMERIC_WHOISCHANNELS}, {"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 f586380..8aa3a78 100644 --- a/src/idle-parser.h +++ b/src/idle-parser.h @@ -82,6 +82,7 @@ typedef enum { IDLE_PARSER_NUMERIC_TOPIC_STAMP, IDLE_PARSER_NUMERIC_UNAWAY, IDLE_PARSER_NUMERIC_WELCOME, + IDLE_PARSER_NUMERIC_WHOISCHANNELS, IDLE_PARSER_NUMERIC_WHOISUSER, IDLE_PARSER_NUMERIC_WHOISIDLE, -- 1.7.4