Comparison

util/xmppstream.lua @ 6978:30c96a5db360

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)
author Matthew Wild <mwild1@gmail.com>
date Tue, 08 Dec 2015 23:15:42 +0000
parent 6777:5de6b93d0190
child 7240:bf8aa0d1951c
comparison
equal deleted inserted replaced
6977:450db0b83fe9 6978:30c96a5db360
194 cb_streamclosed(session); 194 cb_streamclosed(session);
195 end 195 end
196 end 196 end
197 end 197 end
198 198
199 if stream_callbacks.track_namespaces then
200 local namespaces = {}
201 function xml_handlers:StartNamespaceDecl(prefix, url)
202 if prefix ~= nil then
203 namespaces[prefix] = url
204 end
205 end
206 function xml_handlers:EndNamespaceDecl(prefix)
207 if prefix ~= nil then
208 namespaces[prefix] = nil
209 end
210 end
211 local old_startelement = xml_handlers.StartElement
212 function xml_handlers:StartElement(tagname, attr)
213 old_startelement(self, tagname, attr)
214 local n = {}
215 for prefix, url in pairs(namespaces) do
216 n[prefix] = url
217 end
218 stanza.namespaces = n
219 end
220 end
221
199 local function restricted_handler(parser) 222 local function restricted_handler(parser)
200 cb_error(session, "parse-error", "restricted-xml", "Restricted XML, see RFC 6120 section 11.1."); 223 cb_error(session, "parse-error", "restricted-xml", "Restricted XML, see RFC 6120 section 11.1.");
201 if not parser.stop or not parser:stop() then 224 if not parser.stop or not parser:stop() then
202 error("Failed to abort parsing"); 225 error("Failed to abort parsing");
203 end 226 end