diff options
author | Matthew Wild <mwild1@gmail.com> | 2021-09-12 10:31:02 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2021-09-12 10:31:02 +0100 |
commit | eba0bacfdaeaddd47c323f6681c79d57228d93a5 (patch) | |
tree | a2cf45d410616f3dc87a5449aa815fb910db50f1 /util/stanza.lua | |
parent | bee45656d7fe68ebc8009d50f4572e6e194dafe1 (diff) | |
download | prosody-eba0bacfdaeaddd47c323f6681c79d57228d93a5.tar.gz prosody-eba0bacfdaeaddd47c323f6681c79d57228d93a5.zip |
util.stanza: Add :get_child_with_attr() + tests
Diffstat (limited to 'util/stanza.lua')
-rw-r--r-- | util/stanza.lua | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/util/stanza.lua b/util/stanza.lua index 7f321da8..d03558ce 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -191,6 +191,14 @@ function stanza_mt:child_with_ns(ns) 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) |