diff options
author | Matthew Wild <mwild1@gmail.com> | 2010-01-29 14:22:03 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2010-01-29 14:22:03 +0000 |
commit | 35d65ca55b849e4cd36853dbee802fa1b78e7856 (patch) | |
tree | 32482beab406752facfa24a6c2b0b8c4d9df5346 /util/stanza.lua | |
parent | 0d85845a9747742e9e446512848927787a078a7b (diff) | |
download | prosody-35d65ca55b849e4cd36853dbee802fa1b78e7856.tar.gz prosody-35d65ca55b849e4cd36853dbee802fa1b78e7856.zip |
util.stanza: Add stanza:get_error() to return type, condition and text of a stanza error
Diffstat (limited to 'util/stanza.lua')
-rw-r--r-- | util/stanza.lua | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/util/stanza.lua b/util/stanza.lua index c817f93b..d223d53f 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -38,6 +38,8 @@ if do_pretty_printing then end end +local xmlns_stanzas = "urn:ietf:params:xml:ns:xmpp-stanzas"; + module "stanza" stanza_mt = { __type = "stanza" }; @@ -189,6 +191,30 @@ function stanza_mt.get_text(t) end end +function stanza_mt.get_error(stanza) + local type, condition, text; + + local error_tag = stanza:get_child("error"); + if not error_tag then + return nil, nil, nil; + end + type = error_tag.attr.type; + + for child in error_tag:children() do + if child.attr.xmlns == xmlns_stanzas then + if not text and child.name == "text" then + text = child:get_text(); + elseif not condition then + condition = child.name; + end + if condition and text then + break; + end + end + end + return type, condition or "undefined-condition", text or ""; +end + function stanza_mt.__add(s1, s2) return s1:add_direct_child(s2); end |