Mercurial > libervia-backend
changeset 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 | 3e24753b9e0b |
children | 6f0699ba0329 |
files | frontends/wix/gateways.py plugins/plugin_xep_0077.py plugins/plugin_xep_0096.py plugins/plugin_xep_0100.py sat.tac tools/xml_tools.py |
diffstat | 6 files changed, 75 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/wix/gateways.py Thu Dec 17 13:13:13 2009 +1100 +++ b/frontends/wix/gateways.py Thu Dec 17 17:29:02 2009 +1100 @@ -31,15 +31,18 @@ But when you do this, all your messages go throught the external legacy IM server, it is a huge privacy issue (i.e.: all your messages throught the gateway can be monitored, recorded, analyzed by the external server, most of time a private company).""" class GatewaysManager(wx.Frame): - def __init__(self, host, gateways, title="Gateways manager"): + def __init__(self, host, gateways, title="Gateways manager", server=None): super(GatewaysManager, self).__init__(None, title=title) self.host = host + if server: + self.SetTitle(title+" (%s)" % server) #Fonts self.normal_font = wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.NORMAL) self.bold_font = wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD) self.italic_font = wx.Font(8, wx.DEFAULT, wx.FONTSTYLE_ITALIC, wx.NORMAL) + self.button_font = wx.Font(6, wx.DEFAULT, wx.NORMAL, wx.BOLD) self.modified = {} # dict of modified data (i.e. what we have to save) @@ -77,14 +80,40 @@ for gateway in gateways: self.addGateway(gateway, gateways[gateway]) + self.ext_server_panel = wx.Panel(self) + self.ext_server_panel.sizer = wx.BoxSizer(wx.HORIZONTAL) + self.ext_server_panel.SetSizer(self.ext_server_panel.sizer) + self.ext_server_panel.SetAutoLayout(True) + self.sizer.Add(self.ext_server_panel, 0, flag=wx.EXPAND) + + ext_server_label = wx.StaticText(self.ext_server_panel, -1, "Use external XMPP server: ") + ext_server_label.SetFont(wx.ITALIC_FONT) + self.ext_server_text = wx.TextCtrl(self.ext_server_panel, -1) + ext_server_button = wx.Button(self.ext_server_panel, -1, "GO !") + self.ext_server_panel.Bind(wx.EVT_BUTTON, self.browseExternalServer, ext_server_button) + + self.ext_server_panel.sizer.Add(ext_server_label) + self.ext_server_panel.sizer.Add(self.ext_server_text, 1, flag=wx.EXPAND) + self.ext_server_panel.sizer.Add(ext_server_button) #self.panel.sizer.Fit(self) self.sizer.Fit(self) self.Show() + def browseExternalServer(self, event): + """Open the gateway manager on given server""" + server = self.ext_server_text.GetValue() + debug("Opening gateways manager on [%s]" % server) + id = self.host.bridge.findGateways(server) + self.host.current_action_ids.add(id) + self.host.current_action_ids_cb[id] = self.host.onGatewaysFound + self.MakeModal(False) + self.Destroy() + + def addGateway(self, gateway, param): - + #First The icon @@ -133,7 +162,6 @@ print "register id:",id self.MakeModal(False) self.Destroy() - event.Skip() def unregister_cb(event): """Called when unregister button is clicked""" @@ -143,15 +171,13 @@ print "unregister id:",id self.MakeModal(False) self.Destroy() - event.Skip() - button_font = wx.Font(6, wx.DEFAULT, wx.NORMAL, wx.BOLD) reg_button = wx.Button(self.panel, -1, "Register", size=wx.Size(-1, 8)) - reg_button.SetFont(button_font) + reg_button.SetFont(self.button_font) reg_button.gateway_jid = JID(gateway) self.panel.Bind(wx.EVT_BUTTON, register_cb, reg_button) unreg_button = wx.Button(self.panel, -1, "Unregister", size=wx.Size(-1, 8)) - unreg_button.SetFont(button_font) + unreg_button.SetFont(self.button_font) unreg_button.gateway_jid = JID(gateway) self.panel.Bind(wx.EVT_BUTTON, unregister_cb, unreg_button)
--- 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})
--- a/plugins/plugin_xep_0096.py Thu Dec 17 13:13:13 2009 +1100 +++ b/plugins/plugin_xep_0096.py Thu Dec 17 17:29:02 2009 +1100 @@ -22,7 +22,8 @@ from logging import debug, info, error from twisted.words.xish import domish from twisted.internet import protocol -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 import os.path from twisted.internet import reactor #FIXME best way ??? import pdb
--- a/plugins/plugin_xep_0100.py Thu Dec 17 13:13:13 2009 +1100 +++ b/plugins/plugin_xep_0100.py Thu Dec 17 17:29:02 2009 +1100 @@ -21,7 +21,8 @@ from logging import debug, info, error from twisted.internet import protocol -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 import pdb from wokkel import disco, iwokkel @@ -43,7 +44,17 @@ self.__gateways = {} #dict used to construct the answer to findGateways. Key = target jid host.bridge.addMethod("findGateways", ".communication", in_sign='s', out_sign='s', method=self.findGateways) host.bridge.addMethod("gatewayRegister", ".request", in_sign='ssa(ss)', out_sign='s', method=self.gatewayRegister) - + + def __inc_handled_items(self, request_id): + self.__gateways[request_id]['__handled_items']+=1 + + if self.__gateways[request_id]['__total_items'] == self.__gateways[request_id]['__handled_items']: + debug ("All items checked for id [%s]" % str(request_id)) + + del self.__gateways[request_id]['__total_items'] + del self.__gateways[request_id]['__handled_items'] + self.host.actionResultExt(request_id,"DICT_DICT",self.__gateways[request_id]) + def discoInfo(self, disco, entity, request_id): """Find disco infos about entity, to check if it is a gateway""" @@ -55,14 +66,14 @@ 'type':identity[1] } - self.__gateways[request_id]['__handled_items']+=1 - - if self.__gateways[request_id]['__total_items'] == self.__gateways[request_id]['__handled_items']: - debug ("All items checked for id [%s]" % str(request_id)) - - del self.__gateways[request_id]['__total_items'] - del self.__gateways[request_id]['__handled_items'] - self.host.actionResultExt(request_id,"DICT_DICT",self.__gateways[request_id]) + self.__inc_handled_items(request_id) + + def discoInfoErr(self, failure, entity, request_id): + """Something is going wrong with disco""" + failure.trap(jab_error.StanzaError) + error("Error when discovering [%s]: %s" % (entity.full(), failure.value.condition)) + self.__inc_handled_items(request_id) + def discoItems(self, disco, request_id): """Look for items with disco protocol, and ask infos for each one""" @@ -76,6 +87,7 @@ for item in disco._items: debug ("item found: %s", item.name) self.host.disco.requestInfo(item.entity).addCallback(self.discoInfo, entity=item.entity, request_id=request_id) + self.host.disco.requestInfo(item.entity).addErrback(self.discoInfoErr, entity=item.entity, request_id=request_id) def registrationSuccessful(self, target): """Called when in_band registration is ok, we must now follow the rest of procedure"""
--- a/sat.tac Thu Dec 17 13:13:13 2009 +1100 +++ b/sat.tac Thu Dec 17 17:29:02 2009 +1100 @@ -26,7 +26,8 @@ from twisted.internet import glib2reactor, protocol, task glib2reactor.install() -from twisted.words.protocols.jabber import jid, xmlstream, error +from twisted.words.protocols.jabber import jid, xmlstream +from twisted.words.protocols.jabber import error as jab_error from twisted.words.xish import domish from twisted.internet import reactor
--- a/tools/xml_tools.py Thu Dec 17 13:13:13 2009 +1100 +++ b/tools/xml_tools.py Thu Dec 17 17:29:02 2009 +1100 @@ -52,17 +52,16 @@ __field_type = "password" else: error (u"FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType) - __field_type = "string_field" + __field_type = "string" elem = doc.createElement('elem') elem.setAttribute('name', field.var) elem.setAttribute('type', __field_type) - elem.setAttribute('label', field.label) + elem.setAttribute('label', field.label or "") if field.value: text = doc.createTextNode(field.value) elem.appendChild(text) top_element.appendChild(elem) - result = doc.toxml() doc.unlink() return result