Mercurial > libervia-backend
changeset 30:d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
- wix: register in gateways manager now call the in-band registration process
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 08 Dec 2009 04:19:41 +0100 |
parents | df3b0b5ac49e |
children | 7b34ffa2ff45 |
files | frontends/sat_bridge_frontend/DBus.py frontends/wix/gateways.py plugins/plugin_xep_0077.py plugins/plugin_xep_0100.py sat.tac |
diffstat | 5 files changed, 85 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/sat_bridge_frontend/DBus.py Tue Dec 08 02:31:35 2009 +0100 +++ b/frontends/sat_bridge_frontend/DBus.py Tue Dec 08 04:19:41 2009 +0100 @@ -61,6 +61,9 @@ def findGateways(self, target): return self.db_comm_iface.findGateways(target) + def in_band_register(self, target): + return self.db_comm_iface.in_band_register(target) + def setPresence(self, to="", type="", show="", status="", priority=0): return self.db_comm_iface.setPresence(to, type, show, status, priority)
--- a/frontends/wix/gateways.py Tue Dec 08 02:31:35 2009 +0100 +++ b/frontends/wix/gateways.py Tue Dec 08 04:19:41 2009 +0100 @@ -116,9 +116,19 @@ type_label.SetFont(self.italic_font) #The buttons + def register_cb(event): + """Called when register button is clicked""" + gateway_jid = event.GetEventObject().gateway_jid + id = self.host.bridge.in_band_register(gateway_jid) + self.host.current_action_ids.add(id) + print "register id:",id + 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.gateway_jid = JID(gateway) + self.panel.Bind(wx.EVT_BUTTON, register_cb, reg_button) self.panel.sizer.Add(im_icon) self.panel.sizer.Add(label)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/plugin_xep_0077.py Tue Dec 08 04:19:41 2009 +0100 @@ -0,0 +1,68 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +""" +SAT plugin for managing xep-0077 +Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +""" + +from logging import debug, info, error +from twisted.words.protocols.jabber import client, jid, xmlstream, error +from twisted.words.protocols.jabber.xmlstream import IQ +from twisted.internet import reactor +import pdb + +NS_REG = 'jabber:iq:register' + +PLUGIN_INFO = { +"name": "XEP 0077 Plugin", +"import_name": "XEP_0077", +"type": "XEP", +"dependencies": [], +"main": "XEP_0077", +"description": """Implementation of SI File Transfert""" +} + +class XEP_0077(): + + def __init__(self, host): + info("Plugin XEP_0077 initialization") + self.host = host + host.bridge.addMethod("in_band_register", ".communication", in_sign='s', out_sign='s', method=self.in_band_register) + + def reg_ok(self, answer): + """Called after the first get IQ""" + print "answer:",answer + + def reg_err(self, failure): + """Called when something is wrong with registration""" + info ("Registration failure: %s" % str(failure.value)) + answer_data = {} + answer_data['reason'] = 'unknown' + answer_data={"message":"%s [code: %s]" % (failure.value.condition, failure.value.code)} + answer_type = "ERROR" + self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data) + + def in_band_register(self, target): + """register to a target JID""" + to_jid = jid.JID(target) + debug("Asking registration for [%s]" % target) + reg_request=IQ(self.host.xmlstream,'get') + reg_request["from"]=self.host.me.full() + reg_request["to"] = to_jid.full() + query=reg_request.addElement('query', NS_REG) + reg_request.send(to_jid.full()).addCallbacks(self.reg_ok, self.reg_err) + return reg_request["id"]
--- a/plugins/plugin_xep_0100.py Tue Dec 08 02:31:35 2009 +0100 +++ b/plugins/plugin_xep_0100.py Tue Dec 08 04:19:41 2009 +0100 @@ -48,7 +48,7 @@ for identity in disco.identities: if identity[0] == 'gateway': - print ("Found gateway (%s): %s" % (entity, disco.identities[identity])) + print ("Found gateway (%s): %s" % (entity.full(), disco.identities[identity])) self.__gateways[request_id][entity.full()] = { 'name':disco.identities[identity], 'type':identity[1]
--- a/sat.tac Tue Dec 08 02:31:35 2009 +0100 +++ b/sat.tac Tue Dec 08 04:19:41 2009 +0100 @@ -229,11 +229,11 @@ self.host.bridge.actionResult(answer_type, self.answer_id, answer_data) self.xmlstream.sendFooter() - def registrationFailure(self, error): - info ("Registration failure: %s" % str(error.value)) + def registrationFailure(self, failure): + info ("Registration failure: %s" % str(failure.value)) answer_type = "ERROR" answer_data = {} - if error.value.condition == 'conflict': + if failure.value.condition == 'conflict': answer_data['reason'] = 'conflict' answer_data={"message":"Username already exists, please choose an other one"} else: