Software /
code /
prosody
Comparison
tools/openfire2prosody.lua @ 5217:f2becd36d1d0
tools/openfire2prosody: Use util.xml.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 03 Dec 2012 05:42:17 +0500 |
parent | 5089:a5b683909f79 |
child | 5696:9fba74a28e0c |
comparison
equal
deleted
inserted
replaced
5216:63db6f281708 | 5217:f2becd36d1d0 |
---|---|
16 prosody.platform = "windows"; | 16 prosody.platform = "windows"; |
17 elseif package.config:sub(1,1) == "/" then | 17 elseif package.config:sub(1,1) == "/" then |
18 prosody.platform = "posix"; | 18 prosody.platform = "posix"; |
19 end | 19 end |
20 | 20 |
21 local lxp = require "lxp"; | 21 local parse_xml = require "util.xml".parse; |
22 local st = require "util.stanza"; | |
23 | |
24 local parse_xml = (function() | |
25 local ns_prefixes = { | |
26 ["http://www.w3.org/XML/1998/namespace"] = "xml"; | |
27 }; | |
28 local ns_separator = "\1"; | |
29 local ns_pattern = "^([^"..ns_separator.."]*)"..ns_separator.."?(.*)$"; | |
30 return function(xml) | |
31 local handler = {}; | |
32 local stanza = st.stanza("root"); | |
33 function handler:StartElement(tagname, attr) | |
34 local curr_ns,name = tagname:match(ns_pattern); | |
35 if name == "" then | |
36 curr_ns, name = "", curr_ns; | |
37 end | |
38 if curr_ns ~= "" then | |
39 attr.xmlns = curr_ns; | |
40 end | |
41 for i=1,#attr do | |
42 local k = attr[i]; | |
43 attr[i] = nil; | |
44 local ns, nm = k:match(ns_pattern); | |
45 if nm ~= "" then | |
46 ns = ns_prefixes[ns]; | |
47 if ns then | |
48 attr[ns..":"..nm] = attr[k]; | |
49 attr[k] = nil; | |
50 end | |
51 end | |
52 end | |
53 stanza:tag(name, attr); | |
54 end | |
55 function handler:CharacterData(data) | |
56 stanza:text(data); | |
57 end | |
58 function handler:EndElement(tagname) | |
59 stanza:up(); | |
60 end | |
61 local parser = lxp.new(handler, "\1"); | |
62 local ok, err, line, col = parser:parse(xml); | |
63 if ok then ok, err, line, col = parser:parse(); end | |
64 --parser:close(); | |
65 if ok then | |
66 return stanza.tags[1]; | |
67 else | |
68 return ok, err.." (line "..line..", col "..col..")"; | |
69 end | |
70 end; | |
71 end)(); | |
72 | 22 |
73 ----------------------------------------------------------------------- | 23 ----------------------------------------------------------------------- |
74 | 24 |
75 package.loaded["util.logger"] = {init = function() return function() end; end} | 25 package.loaded["util.logger"] = {init = function() return function() end; end} |
76 local dm = require "util.datamanager" | 26 local dm = require "util.datamanager" |