From 1423ee7a75a494e57dded274296bec11e58eeb92 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 2 Oct 2014 22:12:41 +0100 Subject: [PATCH] Handle roster set and result when item name is empty string fixed #431 --- src/xmpp/roster.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index 63729e7c..5f9fa6f9 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -245,6 +245,11 @@ _roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, const char *sub = xmpp_stanza_get_attribute(item, STANZA_ATTR_SUBSCRIPTION); const char *ask = xmpp_stanza_get_attribute(item, STANZA_ATTR_ASK); + // do not set nickname to empty string, set to NULL instead + if (name && (strlen(name) == 0)) { + name = NULL; + } + // remove from roster if (g_strcmp0(sub, "remove") == 0) { // remove barejid and name @@ -290,17 +295,18 @@ _roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, // handle initial roster response if (g_strcmp0(id, "roster") == 0) { - xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, - STANZA_NAME_QUERY); + xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); xmpp_stanza_t *item = xmpp_stanza_get_children(query); while (item != NULL) { - const char *barejid = - xmpp_stanza_get_attribute(item, STANZA_ATTR_JID); - const char *name = - xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME); - const char *sub = - xmpp_stanza_get_attribute(item, STANZA_ATTR_SUBSCRIPTION); + const char *barejid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID); + const char *name = xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME); + const char *sub = xmpp_stanza_get_attribute(item, STANZA_ATTR_SUBSCRIPTION); + + // do not set nickname to empty string, set to NULL instead + if (name && (strlen(name) == 0)) { + name = NULL; + } gboolean pending_out = FALSE; const char *ask = xmpp_stanza_get_attribute(item, STANZA_ATTR_ASK); @@ -319,8 +325,7 @@ _roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, item = xmpp_stanza_get_next(item); } - resource_presence_t conn_presence = - accounts_get_login_presence(jabber_get_account_name()); + resource_presence_t conn_presence = accounts_get_login_presence(jabber_get_account_name()); presence_update(conn_presence, NULL, 0); }