diff plugins/plugin_xep_0077.py @ 39:2e3411a6baad

Wix: external server management in gateways manager, SàT: bug fixes in gateway management - SàT: from twisted.words.protocols.jabber.error module imported as jab_error to avoir name colision with error log method - XEP_0100 plugin: added errback for disco info - XEP_0077 plugin: registration callback now look for "x" element (data form: see XEP-0004), and send an error message if it can't find it. - Wix: added fields for browsing external server gateways
author Goffi <goffi@goffi.org>
date Thu, 17 Dec 2009 17:29:02 +1100
parents a61beb21d16d
children 6f0699ba0329
line wrap: on
line diff
--- a/plugins/plugin_xep_0077.py	Thu Dec 17 13:13:13 2009 +1100
+++ b/plugins/plugin_xep_0077.py	Thu Dec 17 17:29:02 2009 +1100
@@ -20,7 +20,8 @@
 """
 
 from logging import debug, info, error
-from twisted.words.protocols.jabber import client, jid, xmlstream, error
+from twisted.words.protocols.jabber import client, jid, xmlstream
+from twisted.words.protocols.jabber import error as jab_error
 from twisted.words.protocols.jabber.xmlstream import IQ
 from twisted.internet import reactor
 from tools.xml_tools import XMLTools
@@ -54,7 +55,18 @@
     
     def reg_ok(self, answer):
         """Called after the first get IQ"""
-        form = data_form.Form.fromElement(answer.firstChildElement().firstChildElement())
+        try:
+            x_elem = filter (lambda x:x.name == "x", answer.firstChildElement().elements())[0] #We only want the "x" element (data form)
+        except IndexError:
+            info("No data form found")
+            #TODO: manage registration without data form
+            answer_data = {}
+            answer_data={"reason": "unmanaged", "message":"This gateway can't be managed by SàT, sorry :("}
+            answer_type = "ERROR"
+            self.host.bridge.actionResult(answer_type, answer['id'], answer_data)
+            return
+        
+        form = data_form.Form.fromElement(x_elem)
         xml_data = XMLTools.dataForm2xml(form)
         self.host.bridge.actionResult("FORM", answer['id'], {"target":answer["from"], "type":"registration", "xml":xml_data})