Changed separator between attribute names and prefixes from '|' to '\1' (optimization...
authorWaqas Hussain <waqas20@gmail.com>
Thu, 12 Nov 2009 08:42:44 +0000 (13:42 +0500)
committerWaqas Hussain <waqas20@gmail.com>
Thu, 12 Nov 2009 08:42:44 +0000 (13:42 +0500)
core/xmlhandlers.lua
net/xmppclient_listener.lua
net/xmppcomponent_listener.lua
net/xmppserver_listener.lua
plugins/mod_bosh.lua
util/stanza.lua

index 9ded74c338c2129b3399352ae3577531dd3fc5fa..d679af973798b605a4b590659ecd3ceab319f038 100644 (file)
@@ -29,7 +29,6 @@ local ns_prefixes = {
 
 function init_xmlhandlers(session, stream_callbacks)
                local ns_stack = { "" };
-               local curr_ns, name = "";
                local curr_tag;
                local chardata = {};
                local xml_handlers = {};
@@ -50,7 +49,7 @@ function init_xmlhandlers(session, stream_callbacks)
                                stanza:text(t_concat(chardata));
                                chardata = {};
                        end
-                       local curr_ns,name = tagname:match("^(.-)|?([^%|]-)$");
+                       local curr_ns,name = tagname:match("^([^\1]*)\1?(.*)$");
                        if not name then
                                curr_ns, name = "", curr_ns;
                        end
@@ -63,7 +62,7 @@ function init_xmlhandlers(session, stream_callbacks)
                        for i=1,#attr do
                                local k = attr[i];
                                attr[i] = nil;
-                               local ns, nm = k:match("^([^|]+)|?([^|]-)$")
+                               local ns, nm = k:match("^([^\1]*)\1?(.*)$");
                                if ns and nm then
                                        ns = ns_prefixes[ns]; 
                                        if ns then 
@@ -105,7 +104,7 @@ function init_xmlhandlers(session, stream_callbacks)
                        end
                end
                function xml_handlers:EndElement(tagname)
-                       curr_ns,name = tagname:match("^(.-)|?([^%|]-)$");
+                       local curr_ns,name = tagname:match("^([^\1]*)\1?(.*)$");
                        if not name then
                                curr_ns, name = "", curr_ns;
                        end
index 6cea43f2ecd7c75226f66b16dc3c54b7493e5da5..417dfd4a43dff5d659f9de251ca1b63a961f5d55 100644 (file)
@@ -27,7 +27,7 @@ local sm_streamopened = sessionmanager.streamopened;
 local sm_streamclosed = sessionmanager.streamclosed;
 local st = require "util.stanza";
 
-local stream_callbacks = { stream_tag = "http://etherx.jabber.org/streams|stream", 
+local stream_callbacks = { stream_tag = "http://etherx.jabber.org/streams\1stream", 
                default_ns = "jabber:client",
                streamopened = sm_streamopened, streamclosed = sm_streamclosed, handlestanza = core_process_stanza };
 
@@ -53,7 +53,7 @@ local xmppclient = { default_port = 5222, default_mode = "*a" };
 
 local function session_reset_stream(session)
        -- Reset stream
-               local parser = lxp.new(init_xmlhandlers(session, stream_callbacks), "|");
+               local parser = lxp.new(init_xmlhandlers(session, stream_callbacks), "\1");
                session.parser = parser;
                
                session.notopen = true;
@@ -70,7 +70,7 @@ end
 
 
 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'};
-local default_stream_attr = { ["xmlns:stream"] = stream_callbacks.stream_tag:gsub("%|[^|]+$", ""), xmlns = stream_callbacks.default_ns, version = "1.0", id = "" };
+local default_stream_attr = { ["xmlns:stream"] = stream_callbacks.stream_tag:match("[^\1]*"), xmlns = stream_callbacks.default_ns, version = "1.0", id = "" };
 local function session_close(session, reason)
        local log = session.log or log;
        if session.conn then
index bee05967cd048d7147d581d9c61c2a7bb4b4add3..c16f41a09f988c5d7324d67a05d71b710d195c43 100644 (file)
@@ -32,7 +32,7 @@ local xmlns_component = 'jabber:component:accept';
 
 --- Callbacks/data for xmlhandlers to handle streams for us ---
 
-local stream_callbacks = { stream_tag = "http://etherx.jabber.org/streams|stream", default_ns = xmlns_component };
+local stream_callbacks = { stream_tag = "http://etherx.jabber.org/streams\1stream", default_ns = xmlns_component };
 
 function stream_callbacks.error(session, error, data, data2)
        log("warn", "Error processing component stream: "..tostring(error));
@@ -87,7 +87,7 @@ end
 
 --- Closing a component connection
 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'};
-local default_stream_attr = { ["xmlns:stream"] = stream_callbacks.stream_tag:gsub("%|[^|]+$", ""), xmlns = stream_callbacks.default_ns, version = "1.0", id = "" };
+local default_stream_attr = { ["xmlns:stream"] = stream_callbacks.stream_tag:match("[^\1]*"), xmlns = stream_callbacks.default_ns, version = "1.0", id = "" };
 local function session_close(session, reason)
        local log = session.log or log;
        if session.conn then
@@ -138,7 +138,7 @@ function component_listener.listener(conn, data)
                
                session.log("info", "Incoming Jabber component connection");
                
-               local parser = lxp.new(init_xmlhandlers(session, stream_callbacks), "|");
+               local parser = lxp.new(init_xmlhandlers(session, stream_callbacks), "\1");
                session.parser = parser;
                
                session.notopen = true;
index fa6acbb7b75592d231f3c74e38c4e8dc56645292..c7e02ec5a7809b1d0f92b3254d0ac4143bef347b 100644 (file)
@@ -17,7 +17,7 @@ local s2s_streamopened = require "core.s2smanager".streamopened;
 local s2s_streamclosed = require "core.s2smanager".streamclosed;
 local s2s_destroy_session = require "core.s2smanager".destroy_session;
 local s2s_attempt_connect = require "core.s2smanager".attempt_connection;
-local stream_callbacks = { stream_tag = "http://etherx.jabber.org/streams|stream", 
+local stream_callbacks = { stream_tag = "http://etherx.jabber.org/streams\1stream", 
                default_ns = "jabber:server",
                streamopened = s2s_streamopened, streamclosed = s2s_streamclosed, handlestanza =  core_process_stanza };
 
@@ -53,7 +53,7 @@ local xmppserver = { default_port = 5269, default_mode = "*a" };
 
 local function session_reset_stream(session)
        -- Reset stream
-               local parser = lxp.new(init_xmlhandlers(session, stream_callbacks), "|");
+               local parser = lxp.new(init_xmlhandlers(session, stream_callbacks), "\1");
                session.parser = parser;
                
                session.notopen = true;
@@ -70,7 +70,7 @@ local function session_reset_stream(session)
 end
 
 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'};
-local default_stream_attr = { ["xmlns:stream"] = stream_callbacks.stream_tag:gsub("%|[^|]+$", ""), xmlns = stream_callbacks.default_ns, version = "1.0", id = "" };
+local default_stream_attr = { ["xmlns:stream"] = stream_callbacks.stream_tag:match("[^\1]*"), xmlns = stream_callbacks.default_ns, version = "1.0", id = "" };
 local function session_close(session, reason)
        local log = session.log or log;
        if session.conn then
index fddd5c111090108f3506e1e83b6814b11a7d7fac..af13bde9ac6854064b80f24e4df0b7091854ddae 100644 (file)
@@ -23,7 +23,7 @@ local logger = require "util.logger";
 local log = logger.init("mod_bosh");
 
 local xmlns_bosh = "http://jabber.org/protocol/httpbind"; -- (hard-coded into a literal in session.send)
-local stream_callbacks = { stream_tag = "http://jabber.org/protocol/httpbind|body", default_ns = xmlns_bosh };
+local stream_callbacks = { stream_tag = "http://jabber.org/protocol/httpbind\1body", default_ns = xmlns_bosh };
 
 local BOSH_DEFAULT_HOLD = tonumber(module:get_option("bosh_default_hold")) or 1;
 local BOSH_DEFAULT_INACTIVITY = tonumber(module:get_option("bosh_max_inactivity")) or 60;
@@ -70,7 +70,7 @@ function handle_request(method, body, request)
        --log("debug", "Handling new request %s: %s\n----------", request.id, tostring(body));
        request.notopen = true;
        request.log = log;
-       local parser = lxp.new(init_xmlhandlers(request, stream_callbacks), "|");
+       local parser = lxp.new(init_xmlhandlers(request, stream_callbacks), "\1");
        
        parser:parse(body);
        
index 1e0b15179268d12dea0c2cb0cfcb60fb3809bfb4..d295d5cc35a5fb5453d2fd5906d79b0ec84fe2e4 100644 (file)
@@ -136,11 +136,11 @@ local function _dostring(t, buf, self, xml_escape, parentns)
        local name = t.name
        t_insert(buf, "<"..name);
        for k, v in pairs(t.attr) do
-               if s_find(k, "|", 1, true) then
-                       local ns, attrk = s_match(k, "^([^|]+)|(.+)$");
+               if s_find(k, "\1", 1, true) then
+                       local ns, attrk = s_match(k, "^([^\1]*)\1?(.*)$");
                        nsid = nsid + 1;
                        t_insert(buf, " xmlns:ns"..nsid.."='"..xml_escape(ns).."' ".."ns"..nsid..":"..attrk.."='"..xml_escape(v).."'");
-               elseif not(k == "xmlns" and v == parentns) then
+               elseif not(k == "xmlns" and v == parentns) then
                        t_insert(buf, " "..k.."='"..xml_escape(v).."'");
                end
        end
@@ -152,7 +152,7 @@ local function _dostring(t, buf, self, xml_escape, parentns)
                for n=1,len do
                        local child = t[n];
                        if child.name then
-                               self(child, buf, self, xml_escape, t.attr.xmlns);
+                               self(child, buf, self, xml_escape, t.attr.xmlns);
                        else
                                t_insert(buf, xml_escape(child));
                        end
@@ -162,7 +162,7 @@ local function _dostring(t, buf, self, xml_escape, parentns)
 end
 function stanza_mt.__tostring(t)
        local buf = {};
-       _dostring(t, buf, _dostring, xml_escape, nil);
+       _dostring(t, buf, _dostring, xml_escape, nil);
        return t_concat(buf);
 end
 
@@ -210,6 +210,17 @@ function deserialize(stanza)
        if stanza then
                local attr = stanza.attr;
                for i=1,#attr do attr[i] = nil; end
+               local attrx = {};
+               for att in pairs(attr) do
+                       if s_find(att, "|", 1, true) and not s_find(k, "\1", 1, true) then
+                               local ns,na = s_match(k, "^([^|]+)|(.+)$");
+                               attrx[ns.."\1"..na] = attr[att];
+                               attr[att] = nil;
+                       end
+               end
+               for a,v in pairs(attrx) do
+                       attr[x] = v;
+               end
                setmetatable(stanza, stanza_mt);
                for _, child in ipairs(stanza) do
                        if type(child) == "table" then