# HG changeset patch # User Matthew Wild # Date 1259447104 0 # Node ID f8e0ab90d84e1ba0a70620ead94a3b7c2aa1322e # Parent 93970910d064d9bbbd8dea5f31a00d775fc33861 util.xstanza: New library to extend util.stanza with XMPP-specific helpers diff -r 93970910d064 -r f8e0ab90d84e libs/xstanza.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libs/xstanza.lua Sat Nov 28 22:25:04 2009 +0000 @@ -0,0 +1,25 @@ +local stanza_mt = getmetatable(require "util.stanza".stanza()); + +function stanza_mt:error_from_stanza() + local type, condition, text; + + local error_tag = self:get_child("error", "urn:ietf:params:xml:ns:xmpp-stanzas"); + if not error_tag then + return nil, nil; + end + type = error.attr.type; + + for child in error_tag:children() do + if child.attr.xmlns == xmlns_stanzas then + if child.name == "text" then + text = child:get_text(); + else + condition = child.name; + end + if condition and text then + break; + end + end + end + return type, condition, text; +end