Merge hoelzro->trunk
[prosody.git] / util / stanza.lua
index 3ab4bb42f8cad52daf20b5da27a74df938f73225..28e26e0a407232701ce7b2bdc8af0efa41e473e3 100644 (file)
@@ -126,7 +126,7 @@ function stanza_mt:children()
                end, self, i;
 end
 
-function stanza_mt:matched_children(name, xmlns)
+function stanza_mt:matching_tags(name, xmlns)
        xmlns = xmlns or self.attr.xmlns;
        local tags = self.tags;
        local start_i, max_i = 1, #tags;
@@ -151,6 +151,30 @@ function stanza_mt:childtags()
                end, self.tags[1], i;
 end
 
+function stanza_mt:maptags(callback)
+       local tags, curr_tag = self.tags, 1;
+       local n_children, n_tags = #self, #tags;
+       
+       local i = 1;
+       while curr_tag <= n_tags do
+               if self[i] == tags[curr_tag] then
+                       local ret = callback(self[i]);
+                       if ret == nil then
+                               t_remove(self, i);
+                               t_remove(tags, curr_tag);
+                               n_children = n_children - 1;
+                               n_tags = n_tags - 1;
+                       else
+                               self[i] = ret;
+                               tags[i] = ret;
+                       end
+                       i = i + 1;
+                       curr_tag = curr_tag + 1;
+               end
+       end
+       return self;
+end
+
 local xml_escape
 do
        local escape_table = { ["'"] = "&apos;", ["\""] = "&quot;", ["<"] = "&lt;", [">"] = "&gt;", ["&"] = "&amp;" };
@@ -319,7 +343,7 @@ function message(attr, body)
        if not body then
                return stanza("message", attr);
        else
-               return stanza("message", attr):tag("body"):text(body);
+               return stanza("message", attr):tag("body"):text(body):up();
        end
 end
 function iq(attr)