new plugin: gateways plugin, and first implementation of findGateways
- test menu in Wix - new actionResultExt method, for sending dictionary of dictionaries - new getNextId method, for accessing sat ids from plugins.
This commit is contained in:
parent
1af4c213d8
commit
77cd653fa6
6 changed files with 128 additions and 3 deletions
|
|
@ -41,6 +41,7 @@ class QuickApp():
|
||||||
self.bridge.register("contactDeleted", self.contactDeleted)
|
self.bridge.register("contactDeleted", self.contactDeleted)
|
||||||
self.bridge.register("askConfirmation", self.askConfirmation, "request")
|
self.bridge.register("askConfirmation", self.askConfirmation, "request")
|
||||||
self.bridge.register("actionResult", self.actionResult, "request")
|
self.bridge.register("actionResult", self.actionResult, "request")
|
||||||
|
self.bridge.register("actionResultExt", self.actionResult, "request")
|
||||||
|
|
||||||
###now we get the essential params###
|
###now we get the essential params###
|
||||||
self.whoami=JID(self.bridge.getParamA("JabberID","Connection"))
|
self.whoami=JID(self.bridge.getParamA("JabberID","Connection"))
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,9 @@ class DBusBridgeFrontend(BridgeFrontend):
|
||||||
def sendFile(self, to, path):
|
def sendFile(self, to, path):
|
||||||
return self.db_comm_iface.sendFile(to, path)
|
return self.db_comm_iface.sendFile(to, path)
|
||||||
|
|
||||||
|
def findGateways(self, target):
|
||||||
|
return self.db_comm_iface.findGateways(target)
|
||||||
|
|
||||||
def setPresence(self, to="", type="", show="", status="", priority=0):
|
def setPresence(self, to="", type="", show="", status="", priority=0):
|
||||||
return self.db_comm_iface.setPresence(to, type, show, status, priority)
|
return self.db_comm_iface.setPresence(to, type, show, status, priority)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ idEXIT = 3
|
||||||
idPARAM = 4
|
idPARAM = 4
|
||||||
idADD_CONTACT = 5
|
idADD_CONTACT = 5
|
||||||
idREMOVE_CONTACT = 6
|
idREMOVE_CONTACT = 6
|
||||||
|
idFIND_GATEWAYS = 7
|
||||||
const_DEFAULT_GROUP = "Unclassed"
|
const_DEFAULT_GROUP = "Unclassed"
|
||||||
const_STATUS = {"Online":"",
|
const_STATUS = {"Online":"",
|
||||||
"Want to discuss":"chat",
|
"Want to discuss":"chat",
|
||||||
|
|
@ -205,9 +206,12 @@ class MainWindow(wx.Frame, QuickApp):
|
||||||
contactMenu = wx.Menu()
|
contactMenu = wx.Menu()
|
||||||
contactMenu.Append(idADD_CONTACT, "&Add contact"," Add a contact to your list")
|
contactMenu.Append(idADD_CONTACT, "&Add contact"," Add a contact to your list")
|
||||||
contactMenu.Append(idREMOVE_CONTACT, "&Remove contact"," Remove the selected contact from your list")
|
contactMenu.Append(idREMOVE_CONTACT, "&Remove contact"," Remove the selected contact from your list")
|
||||||
|
communicationMenu = wx.Menu()
|
||||||
|
communicationMenu.Append(idFIND_GATEWAYS, "&Find Gateways"," Find gateways to legacy IM")
|
||||||
menuBar = wx.MenuBar()
|
menuBar = wx.MenuBar()
|
||||||
menuBar.Append(connectMenu,"&General")
|
menuBar.Append(connectMenu,"&General")
|
||||||
menuBar.Append(contactMenu,"&Contacts")
|
menuBar.Append(contactMenu,"&Contacts")
|
||||||
|
menuBar.Append(communicationMenu,"&Communication")
|
||||||
self.SetMenuBar(menuBar)
|
self.SetMenuBar(menuBar)
|
||||||
|
|
||||||
#events
|
#events
|
||||||
|
|
@ -217,6 +221,7 @@ class MainWindow(wx.Frame, QuickApp):
|
||||||
wx.EVT_MENU(self, idEXIT, self.onExit)
|
wx.EVT_MENU(self, idEXIT, self.onExit)
|
||||||
wx.EVT_MENU(self, idADD_CONTACT, self.onAddContact)
|
wx.EVT_MENU(self, idADD_CONTACT, self.onAddContact)
|
||||||
wx.EVT_MENU(self, idREMOVE_CONTACT, self.onRemoveContact)
|
wx.EVT_MENU(self, idREMOVE_CONTACT, self.onRemoveContact)
|
||||||
|
wx.EVT_MENU(self, idFIND_GATEWAYS, self.onFindGateways)
|
||||||
|
|
||||||
|
|
||||||
def newMessage(self, from_jid, msg, type, to_jid):
|
def newMessage(self, from_jid, msg, type, to_jid):
|
||||||
|
|
@ -302,7 +307,7 @@ class MainWindow(wx.Frame, QuickApp):
|
||||||
dlg.Destroy()
|
dlg.Destroy()
|
||||||
|
|
||||||
def actionResult(self, type, id, data):
|
def actionResult(self, type, id, data):
|
||||||
debug ("actionResult: type = [%s] id = [%s] data =[%s]" % (type, id, data))
|
debug ("actionResult: type = [%s] id = [%s] data = [%s]" % (type, id, data))
|
||||||
if type == "SUPPRESS":
|
if type == "SUPPRESS":
|
||||||
self.current_action_ids.remove(id)
|
self.current_action_ids.remove(id)
|
||||||
elif type == "SUCCESS":
|
elif type == "SUCCESS":
|
||||||
|
|
@ -321,6 +326,8 @@ class MainWindow(wx.Frame, QuickApp):
|
||||||
)
|
)
|
||||||
dlg.ShowModal()
|
dlg.ShowModal()
|
||||||
dlg.Destroy()
|
dlg.Destroy()
|
||||||
|
elif type == "DICT_DICT":
|
||||||
|
print ("Dict of dict found as result")
|
||||||
else:
|
else:
|
||||||
error ("FIXME FIXME FIXME: type [%s] not implemented" % type)
|
error ("FIXME FIXME FIXME: type [%s] not implemented" % type)
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
@ -421,6 +428,11 @@ class MainWindow(wx.Frame, QuickApp):
|
||||||
|
|
||||||
dlg.Destroy()
|
dlg.Destroy()
|
||||||
|
|
||||||
|
def onFindGateways(self, e):
|
||||||
|
debug("Find Gateways request")
|
||||||
|
id = self.bridge.findGateways(self.whoami.domain)
|
||||||
|
print "Find Gateways id=", id
|
||||||
|
|
||||||
def onClose(self, e):
|
def onClose(self, e):
|
||||||
info("Exiting...")
|
info("Exiting...")
|
||||||
e.Skip()
|
e.Skip()
|
||||||
|
|
|
||||||
86
plugins/plugin_xep_0100.py
Executable file
86
plugins/plugin_xep_0100.py
Executable file
|
|
@ -0,0 +1,86 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
SAT plugin for managing gateways (xep-0100)
|
||||||
|
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.internet import protocol
|
||||||
|
from twisted.words.protocols.jabber import client, jid, xmlstream, error
|
||||||
|
import pdb
|
||||||
|
|
||||||
|
from wokkel import disco, iwokkel
|
||||||
|
|
||||||
|
PLUGIN_INFO = {
|
||||||
|
"name": "Gateways Plugin",
|
||||||
|
"import_name": "XEP_0100",
|
||||||
|
"type": "XEP",
|
||||||
|
"dependencies": [],
|
||||||
|
"main": "XEP_0100",
|
||||||
|
"description": """Implementation of Gateways protocol"""
|
||||||
|
}
|
||||||
|
|
||||||
|
class XEP_0100():
|
||||||
|
|
||||||
|
def __init__(self, host):
|
||||||
|
info("Gateways plugin initialization")
|
||||||
|
self.host = host
|
||||||
|
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)
|
||||||
|
|
||||||
|
def discoInfo(self, disco, entity, request_id):
|
||||||
|
"""Find disco infos about entity, to check if it is a gateway"""
|
||||||
|
|
||||||
|
for identity in disco.identities:
|
||||||
|
if identity[0] == 'gateway':
|
||||||
|
print ("Found gateway (%s): %s" % (entity, disco.identities[identity]))
|
||||||
|
self.__gateways[request_id][entity.full()] = {
|
||||||
|
'name':disco.identities[identity],
|
||||||
|
'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])
|
||||||
|
|
||||||
|
def discoItems(self, disco, request_id):
|
||||||
|
"""Look for items with disco protocol, and ask infos for each one"""
|
||||||
|
|
||||||
|
if len(disco._items) == 0:
|
||||||
|
debug ("No gateway found")
|
||||||
|
self.host.actionResultExt(request_id,"DICT_DICT",{})
|
||||||
|
return
|
||||||
|
|
||||||
|
self.__gateways[request_id] = {'__total_items':len(disco._items), '__handled_items':0}
|
||||||
|
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)
|
||||||
|
|
||||||
|
def findGateways(self, target):
|
||||||
|
"""Find gateways in the target JID, using discovery protocol
|
||||||
|
Return an id used for retrieving the list of gateways
|
||||||
|
"""
|
||||||
|
debug ("find gateways (target = %s)" % target)
|
||||||
|
request_id = self.host.get_next_id()
|
||||||
|
self.host.disco.requestItems(jid.JID(target)).addCallback(self.discoItems, request_id=request_id)
|
||||||
|
return request_id
|
||||||
17
sat.tac
17
sat.tac
|
|
@ -245,6 +245,9 @@ class RegisteringAuthenticator(xmlstream.ConnectAuthenticator):
|
||||||
|
|
||||||
class SAT(service.Service):
|
class SAT(service.Service):
|
||||||
|
|
||||||
|
def get_next_id(self):
|
||||||
|
return sat_next_id()
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
#TODO: standardize callback system
|
#TODO: standardize callback system
|
||||||
self.__waiting_conf = {} #callback called when a confirmation is received
|
self.__waiting_conf = {} #callback called when a confirmation is received
|
||||||
|
|
@ -515,16 +518,28 @@ class SAT(service.Service):
|
||||||
for cat, type in disco.identities:
|
for cat, type in disco.identities:
|
||||||
debug ("Identity found: [%s/%s] %s" % (cat, type, disco.identities[(cat,type)]))
|
debug ("Identity found: [%s/%s] %s" % (cat, type, disco.identities[(cat,type)]))
|
||||||
|
|
||||||
|
|
||||||
## Generic HMI ##
|
## Generic HMI ##
|
||||||
|
|
||||||
def actionResult(self, id, type, data):
|
def actionResult(self, id, type, data):
|
||||||
"""Send the result of an action
|
"""Send the result of an action
|
||||||
@param id: same id used with action
|
@param id: same id used with action
|
||||||
@type: result type ("PARAM", "SUCCESS", "ERROR")
|
@type: result type ("PARAM", "SUCCESS", "ERROR")
|
||||||
@data: data (depend of result type)
|
@data: dictionary
|
||||||
"""
|
"""
|
||||||
self.bridge.actionResult(type, id, data)
|
self.bridge.actionResult(type, id, data)
|
||||||
|
|
||||||
|
def actionResultExt(self, id, type, data):
|
||||||
|
"""Send the result of an action, extended version
|
||||||
|
@param id: same id used with action
|
||||||
|
@type: result type ("PARAM", "SUCCESS", "ERROR")
|
||||||
|
@data: dictionary of dictionaries
|
||||||
|
"""
|
||||||
|
if type != "DICT_DICT":
|
||||||
|
error("type for actionResultExt must be DICT_DICT, fixing it")
|
||||||
|
type = "DICT_DICT"
|
||||||
|
self.bridge.actionResultExt(type, id, data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def askConfirmation(self, id, type, data, cb):
|
def askConfirmation(self, id, type, data, cb):
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,11 @@ class DbusObject(dbus.service.Object):
|
||||||
def actionResult(self, type, id, data):
|
def actionResult(self, type, id, data):
|
||||||
debug("result of action: id = [%s] type = %s data = %s", id, type, data)
|
debug("result of action: id = [%s] type = %s data = %s", id, type, data)
|
||||||
|
|
||||||
|
@dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX,
|
||||||
|
signature='ssa{sa{ss}}')
|
||||||
|
def actionResultExt(self, type, id, data):
|
||||||
|
debug("extended result of action: id = [%s] type = %s data = %s", id, type, data)
|
||||||
|
|
||||||
### methods ###
|
### methods ###
|
||||||
|
|
||||||
@dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
|
@dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
|
||||||
|
|
@ -255,6 +260,9 @@ class DBusBridge(Bridge):
|
||||||
def actionResult(self, type, id, data):
|
def actionResult(self, type, id, data):
|
||||||
self.dbus_bridge.actionResult(type, id, data)
|
self.dbus_bridge.actionResult(type, id, data)
|
||||||
|
|
||||||
|
def actionResultExt(self, type, id, data):
|
||||||
|
self.dbus_bridge.actionResultExt(type, id, data)
|
||||||
|
|
||||||
def register(self, name, callback):
|
def register(self, name, callback):
|
||||||
debug("registering DBus bridge method [%s]",name)
|
debug("registering DBus bridge method [%s]",name)
|
||||||
self.dbus_bridge.register(name, callback)
|
self.dbus_bridge.register(name, callback)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue