comparison 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
comparison
equal deleted inserted replaced
38:3e24753b9e0b 39:2e3411a6baad
18 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """ 20 """
21 21
22 from logging import debug, info, error 22 from logging import debug, info, error
23 from twisted.words.protocols.jabber import client, jid, xmlstream, error 23 from twisted.words.protocols.jabber import client, jid, xmlstream
24 from twisted.words.protocols.jabber import error as jab_error
24 from twisted.words.protocols.jabber.xmlstream import IQ 25 from twisted.words.protocols.jabber.xmlstream import IQ
25 from twisted.internet import reactor 26 from twisted.internet import reactor
26 from tools.xml_tools import XMLTools 27 from tools.xml_tools import XMLTools
27 import pdb 28 import pdb
28 29
52 """Add a callback which is called when registration to target is successful""" 53 """Add a callback which is called when registration to target is successful"""
53 self.triggers[target] = cb 54 self.triggers[target] = cb
54 55
55 def reg_ok(self, answer): 56 def reg_ok(self, answer):
56 """Called after the first get IQ""" 57 """Called after the first get IQ"""
57 form = data_form.Form.fromElement(answer.firstChildElement().firstChildElement()) 58 try:
59 x_elem = filter (lambda x:x.name == "x", answer.firstChildElement().elements())[0] #We only want the "x" element (data form)
60 except IndexError:
61 info("No data form found")
62 #TODO: manage registration without data form
63 answer_data = {}
64 answer_data={"reason": "unmanaged", "message":"This gateway can't be managed by SàT, sorry :("}
65 answer_type = "ERROR"
66 self.host.bridge.actionResult(answer_type, answer['id'], answer_data)
67 return
68
69 form = data_form.Form.fromElement(x_elem)
58 xml_data = XMLTools.dataForm2xml(form) 70 xml_data = XMLTools.dataForm2xml(form)
59 self.host.bridge.actionResult("FORM", answer['id'], {"target":answer["from"], "type":"registration", "xml":xml_data}) 71 self.host.bridge.actionResult("FORM", answer['id'], {"target":answer["from"], "type":"registration", "xml":xml_data})
60 72
61 def reg_err(self, failure): 73 def reg_err(self, failure):
62 """Called when something is wrong with registration""" 74 """Called when something is wrong with registration"""