aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2009-11-12 13:42:44 +0500
committerWaqas Hussain <waqas20@gmail.com>2009-11-12 13:42:44 +0500
commit316bc45e71aa55d276b11986115d5e40661bd607 (patch)
treeeae786040e13eb74d13aaf41e66d3f3f9b8b8e8f
parent41079afbb43ebd56b5aa5cc43da2e84120c0b012 (diff)
downloadprosody-316bc45e71aa55d276b11986115d5e40661bd607.tar.gz
prosody-316bc45e71aa55d276b11986115d5e40661bd607.zip
Changed separator between attribute names and prefixes from '|' to '\1' (optimization and cleanup).
-rw-r--r--core/xmlhandlers.lua7
-rw-r--r--net/xmppclient_listener.lua6
-rw-r--r--net/xmppcomponent_listener.lua6
-rw-r--r--net/xmppserver_listener.lua6
-rw-r--r--plugins/mod_bosh.lua4
-rw-r--r--util/stanza.lua21
6 files changed, 30 insertions, 20 deletions
diff --git a/core/xmlhandlers.lua b/core/xmlhandlers.lua
index 9ded74c3..d679af97 100644
--- a/core/xmlhandlers.lua
+++ b/core/xmlhandlers.lua
@@ -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
diff --git a/net/xmppclient_listener.lua b/net/xmppclient_listener.lua
index 6cea43f2..417dfd4a 100644
--- a/net/xmppclient_listener.lua
+++ b/net/xmppclient_listener.lua
@@ -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
diff --git a/net/xmppcomponent_listener.lua b/net/xmppcomponent_listener.lua
index bee05967..c16f41a0 100644
--- a/net/xmppcomponent_listener.lua
+++ b/net/xmppcomponent_listener.lua
@@ -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;
diff --git a/net/xmppserver_listener.lua b/net/xmppserver_listener.lua
index fa6acbb7..c7e02ec5 100644
--- a/net/xmppserver_listener.lua
+++ b/net/xmppserver_listener.lua
@@ -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
diff --git a/plugins/mod_bosh.lua b/plugins/mod_bosh.lua
index fddd5c11..af13bde9 100644
--- a/plugins/mod_bosh.lua
+++ b/plugins/mod_bosh.lua
@@ -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);
diff --git a/util/stanza.lua b/util/stanza.lua
index 1e0b1517..d295d5cc 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -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