From e33a98e498cff5318b29a46e8def2855ef4dc786 Mon Sep 17 00:00:00 2001 From: Codewalker Date: Fri, 23 Jan 2015 11:02:42 -0600 Subject: [PATCH] Streamline xmpp_stanza_to_text for the namespace patch by following XML namespace scoping guidelines and not outputting the xmlns attribute in contexts where it can be inferred from the parent element. --- src/stanza.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/stanza.c b/src/stanza.c index 2085929..5e3c7f7 100644 --- a/src/stanza.c +++ b/src/stanza.c @@ -317,6 +317,20 @@ static int _render_stanza_recursive(xmpp_stanza_t *stanza, if (stanza->attributes && hash_num_keys(stanza->attributes) > 0) { iter = hash_iter_new(stanza->attributes); while ((key = hash_iter_next(iter))) { + if (!strcmp(key, "xmlns")) { + /* don't output namespace if parent stanza is the same */ + if (stanza->parent && + stanza->parent->attributes && + hash_get(stanza->parent->attributes, key) && + !strcmp((char*)hash_get(stanza->attributes, key), + (char*)hash_get(stanza->parent->attributes, key))) + continue; + /* or if this is the stream namespace */ + if (!stanza->parent && + !strcmp((char*)hash_get(stanza->attributes, key), + XMPP_NS_CLIENT)) + continue; + } tmp = _escape_xml(stanza->ctx, (char *)hash_get(stanza->attributes, key)); if (tmp == NULL) return XMPP_EMEM;