aboutsummaryrefslogtreecommitdiffstats
path: root/util/xmppstream.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2015-12-08 23:15:42 +0000
committerMatthew Wild <mwild1@gmail.com>2015-12-08 23:15:42 +0000
commitdd37beeff9f229dee36da04d625d5200b69f945c (patch)
tree92b42e2b3bb371b3273c61157e86d553f20700a6 /util/xmppstream.lua
parentbb0ad8d2a9da64ab00fa01b047031e8256554e89 (diff)
downloadprosody-dd37beeff9f229dee36da04d625d5200b69f945c.tar.gz
prosody-dd37beeff9f229dee36da04d625d5200b69f945c.zip
util.stanza, util.xml, util.xmppstream: Add support for tracking defined namespaces and their prefix (stanza.namespaces), knowing/preserving prefix names is required for some applications (thanks daurnimator)
Diffstat (limited to 'util/xmppstream.lua')
-rw-r--r--util/xmppstream.lua23
1 files changed, 23 insertions, 0 deletions
diff --git a/util/xmppstream.lua b/util/xmppstream.lua
index 7be63285..3d97acef 100644
--- a/util/xmppstream.lua
+++ b/util/xmppstream.lua
@@ -196,6 +196,29 @@ local function new_sax_handlers(session, stream_callbacks, cb_handleprogress)
end
end
+ if stream_callbacks.track_namespaces then
+ local namespaces = {}
+ function xml_handlers:StartNamespaceDecl(prefix, url)
+ if prefix ~= nil then
+ namespaces[prefix] = url
+ end
+ end
+ function xml_handlers:EndNamespaceDecl(prefix)
+ if prefix ~= nil then
+ namespaces[prefix] = nil
+ end
+ end
+ local old_startelement = xml_handlers.StartElement
+ function xml_handlers:StartElement(tagname, attr)
+ old_startelement(self, tagname, attr)
+ local n = {}
+ for prefix, url in pairs(namespaces) do
+ n[prefix] = url
+ end
+ stanza.namespaces = n
+ end
+ end
+
local function restricted_handler(parser)
cb_error(session, "parse-error", "restricted-xml", "Restricted XML, see RFC 6120 section 11.1.");
if not parser.stop or not parser:stop() then