util.encodings: Fix small typo introduced in 7f789266b741
[prosody.git] / tools / xep227toprosody.lua
old mode 100644 (file)
new mode 100755 (executable)
index d3c8924..23e5948
@@ -36,13 +36,15 @@ end
 
 local lxp = require "lxp";
 local st = require "util.stanza";
-local init_xmlhandlers = require "core.xmlhandlers";
+local xmppstream = require "util.xmppstream";
+local new_xmpp_handlers = xmppstream.new_sax_handlers;
 local dm = require "util.datamanager"
 dm.set_data_path("data");
 
-local ns_separator = "\1";
-local ns_pattern = "^([^"..ns_separator.."]*)"..ns_separator.."?(.*)$";
-local ns_xep227 = "http://www.xmpp.org/extensions/xep-0227.html#ns";
+local ns_separator = xmppstream.ns_separator;
+local ns_pattern = xmppstream.ns_pattern;
+
+local xmlns_xep227 = "http://www.xmpp.org/extensions/xep-0227.html#ns";
 
 -----------------------------------------------------------------------
 
@@ -114,7 +116,7 @@ function store_offline_messages(username, host, offline_messages)
                --print("message :"..ch:pretty_print());
                local ret, err = dm.list_append(username, host, "offline", st.preserialize(ch));
                print("["..(err or "success").."] stored offline message: " ..username.."@"..host.." - "..ch.attr.from);
-       end
+       end
 end
 
 
@@ -141,13 +143,12 @@ end
 -----------------------------------------------------------------------
 
 local curr_host = "";
-
+local user_name = "";
 
 
 local cb = {
        stream_tag = "user",
-       stream_ns = ns_xep227,
-       user_name = ""
+       stream_ns = xmlns_xep227,
 };
 function cb.streamopened(session, attr)
        session.notopen = false;
@@ -177,7 +178,7 @@ function cb.handlestanza(session, stanza)
        end
 end
 
-local user_handlers = init_xmlhandlers({ notopen = true, }, cb);
+local user_handlers = new_xmpp_handlers({ notopen = true }, cb);
 
 -----------------------------------------------------------------------
 
@@ -196,10 +197,10 @@ function lxp_handlers.StartElement(parser, elementname, attributes)
        if curr_host ~= "" then
                -- forward to xmlhandlers
                user_handlers:StartElement(elementname, attributes);
-       elseif (curr_ns == ns_xep227) and (name == "host") then
+       elseif (curr_ns == xmlns_xep227) and (name == "host") then
                curr_host = attributes["jid"]; -- start of host element
                print("Begin parsing host "..curr_host);
-       elseif (curr_ns ~= ns_xep227) or (name ~= "server-data") then
+       elseif (curr_ns ~= xmlns_xep227) or (name ~= "server-data") then
                io.stderr:write("Unhandled XML element: ", name, "\n");
                os.exit(1);
        end
@@ -214,14 +215,14 @@ function lxp_handlers.EndElement(parser, elementname)
        --count = count - 1;
        --io.write("- ", string.rep(" ", count), name, "  (", curr_ns, ")", "\n")
        if curr_host ~= "" then
-               if (curr_ns == ns_xep227) and (name == "host") then
+               if (curr_ns == xmlns_xep227) and (name == "host") then
                        print("End parsing host "..curr_host);
                        curr_host = "" -- end of host element
                else
                        -- forward to xmlhandlers
-                       user_handlers:EndElement(elementname, attributes);
+                       user_handlers:EndElement(elementname);
                end
-       elseif (curr_ns ~= ns_xep227) or (name ~= "server-data") then
+       elseif (curr_ns ~= xmlns_xep227) or (name ~= "server-data") then
                io.stderr:write("Unhandled XML element: ", name, "\n");
                os.exit(1);
        end