diff options
author | Waqas Hussain <waqas20@gmail.com> | 2009-11-12 13:42:44 +0500 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2009-11-12 13:42:44 +0500 |
commit | 316bc45e71aa55d276b11986115d5e40661bd607 (patch) | |
tree | eae786040e13eb74d13aaf41e66d3f3f9b8b8e8f /util/stanza.lua | |
parent | 41079afbb43ebd56b5aa5cc43da2e84120c0b012 (diff) | |
download | prosody-316bc45e71aa55d276b11986115d5e40661bd607.tar.gz prosody-316bc45e71aa55d276b11986115d5e40661bd607.zip |
Changed separator between attribute names and prefixes from '|' to '\1' (optimization and cleanup).
Diffstat (limited to 'util/stanza.lua')
-rw-r--r-- | util/stanza.lua | 21 |
1 files changed, 16 insertions, 5 deletions
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 |