aboutsummaryrefslogtreecommitdiffstats
path: root/util/stanza.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2013-04-05 10:05:18 +0100
committerMatthew Wild <mwild1@gmail.com>2013-04-05 10:05:18 +0100
commit6f71d38f1f92ef51fd9d82cbfb8c33a518010651 (patch)
tree60c4be5a40bd2c13dcfb8435083d1b23619523a4 /util/stanza.lua
parenta5ccb8a860924f48570242e468267885137e3e9a (diff)
parenta115da90578ef0e91e7fb911421142552a4e8e4a (diff)
downloadprosody-6f71d38f1f92ef51fd9d82cbfb8c33a518010651.tar.gz
prosody-6f71d38f1f92ef51fd9d82cbfb8c33a518010651.zip
Merge 0.9->trunk
Diffstat (limited to 'util/stanza.lua')
-rw-r--r--util/stanza.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/util/stanza.lua b/util/stanza.lua
index 213ed506..59c88c4e 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -18,6 +18,7 @@ local pairs = pairs;
local ipairs = ipairs;
local type = type;
local s_gsub = string.gsub;
+local s_sub = string.sub;
local s_find = string.find;
local os = os;
@@ -174,6 +175,31 @@ function stanza_mt:maptags(callback)
return self;
end
+function stanza_mt:find(path)
+ local pos = 1;
+ local len = #path + 1;
+
+ repeat
+ local xmlns, name, text;
+ local char = s_sub(path, pos, pos);
+ if char == "@" then
+ return self.attr[s_sub(path, pos + 1)];
+ elseif char == "{" then
+ xmlns, pos = s_match(path, "^([^}]+)}()", pos + 1);
+ end
+ name, text, pos = s_match(path, "^([^@/#]*)([/#]?)()", pos);
+ name = name ~= "" and name or nil;
+ if pos == len then
+ if text == "#" then
+ return self:get_child_text(name, xmlns);
+ end
+ return self:get_child(name, xmlns);
+ end
+ self = self:get_child(name, xmlns);
+ until not self
+end
+
+
local xml_escape
do
local escape_table = { ["'"] = "&apos;", ["\""] = "&quot;", ["<"] = "&lt;", [">"] = "&gt;", ["&"] = "&amp;" };