Software /
code /
prosody
Diff
util/stanza.lua @ 11786:39164ea2ab9e
util.stanza: Add :get_child_with_attr() + tests
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 12 Sep 2021 10:31:02 +0100 |
parent | 11642:7f2dee4249aa |
child | 11960:12a3c05aa12d |
line wrap: on
line diff
--- a/util/stanza.lua Sat Sep 11 13:59:35 2021 +0100 +++ b/util/stanza.lua Sun Sep 12 10:31:02 2021 +0100 @@ -191,6 +191,14 @@ end end +function stanza_mt:get_child_with_attr(name, xmlns, attr_name, attr_value, normalize) + for tag in self:childtags(name, xmlns) do + if (normalize and normalize(tag.attr[attr_name]) or tag.attr[attr_name]) == attr_value then + return tag; + end + end +end + function stanza_mt:children() local i = 0; return function (a)