Mercurial > libervia-backend
changeset 65:d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
/!\ profiles not managed yet for dbus signals
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 31 Jan 2010 15:57:03 +1100 |
parents | d46f849664aa |
children | 8147b4f40809 |
files | frontends/sat_bridge_frontend/DBus.py plugins/plugin_xep_0100.py sat.tac sat_bridge/DBus.py tools/memory.py |
diffstat | 5 files changed, 192 insertions(+), 144 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/sat_bridge_frontend/DBus.py Sat Jan 30 16:17:33 2010 +1100 +++ b/frontends/sat_bridge_frontend/DBus.py Sun Jan 31 15:57:03 2010 +1100 @@ -40,29 +40,69 @@ elif iface == "request": self.db_req_iface.connect_to_signal(functionName, handler) - def connect(self): - return self.db_comm_iface.connect() + def connect(self, profile_key='@DEFAULT@'): + return self.db_comm_iface.connect(profile_key) + + def disconnect(self, profile_key='@DEFAULT@'): + return self.db_comm_iface.disconnect(profile_key) + + def isConnected(self, profile_key='@DEFAULT@'): + return self.db_comm_iface.isConnected(profile_key) - def disconnect(self): - return self.db_comm_iface.disconnect() + def getContacts(self, profile_key='@DEFAULT@'): + return self.db_comm_iface.getContacts(profile_key) + + def getPresenceStatus(self, profile_key='@DEFAULT@'): + return self.db_comm_iface.getPresenceStatus(profile_key) - def getContacts(self): - return self.db_comm_iface.getContacts() + def getWaitingSub(self, profile_key='@DEFAULT@'): + return self.db_comm_iface.getWaitingSub(profile_key) + + def sendMessage(self, to, message, profile_key='@DEFAULT@'): + return self.db_comm_iface.sendMessage(to, message, profile_key) + + def setPresence(self, to="", show="", priority=0, statuses={}, profile_key='@DEFAULT@'): + return self.db_comm_iface.setPresence(to, show, priority, statuses, profile_key) - def getPresenceStatus(self): - return self.db_comm_iface.getPresenceStatus() + def subscription(self, type, entity, profile_key='@DEFAULT@'): + return self.db_comm_iface.subscription(type, entity, profile_key) + + def setParam(self, name, value, category, profile_key='@DEFAULT@'): + return self.db_comm_iface.setParam(name, value, category, profile_key) + + def getParamA(self, name, category, profile_key='@DEFAULT@'): + return self.db_comm_iface.getParamA(name, category, profile_key) + + def getParams(self, profile_key='@DEFAULT@'): + return self.db_comm_iface.getParams(profile_key) + + def getParamsForCategory(self, category, profile_key='@DEFAULT@'): + return self.db_comm_iface.getParamsForCategory(category, profile_key) - def getWaitingSub(self): - return self.db_comm_iface.getWaitingSub() + def getParamsCategories(self): + return self.db_comm_iface.getParamsCategories(profile_key) - def sendMessage(self, to, message): - return self.db_comm_iface.sendMessage(to, message) + def getHistory(self, from_jid, to_jid, size): + return self.db_comm_iface.getHistory(from_jid, to_jid, size) + + def addContact(self, jid, profile_key='@DEFAULT@'): + return self.db_comm_iface.addContact(jid, profile_key) + def delContact(self, jid, profile_key='@DEFAULT@'): + return self.db_comm_iface.delContact(jid, profile_key) + + def launchAction(self, type, data): + return self.db_req_iface.launchAction(type, data) + + def confirmationAnswer(self, id, accepted, data): + return self.db_req_iface.confirmationAnswer(id, accepted, data) + +#methods from plugins def sendFile(self, to, path, profile_key='@DEFAULT@'): return self.db_comm_iface.sendFile(to, path, profile_key) - def findGateways(self, target): - return self.db_comm_iface.findGateways(target) + def findGateways(self, target, profile_key='@DEFAULT@'): + return self.db_comm_iface.findGateways(target, profile_key) def getCard(self, target, profile_key='@DEFAULT@'): return self.db_comm_iface.getCard(target, profile_key) @@ -75,45 +115,6 @@ def in_band_register(self, target, profile_key='@DEFAULT@'): return self.db_comm_iface.in_band_register(target, profile_key) - - def setPresence(self, to="", show="", priority=0, statuses={}): - return self.db_comm_iface.setPresence(to, show, priority, statuses) - - def subscription(self, type, entity): - return self.db_comm_iface.subscription(type, entity) - - def setParam(self, name, value, category): - return self.db_comm_iface.setParam(name, value, category) - - def getParamA(self, name, category): - return self.db_comm_iface.getParamA(name, category) - - def getParams(self): - return self.db_comm_iface.getParams() - - def getParamsForCategory(self, category): - return self.db_comm_iface.getParamsForCategory(category) - - def getParamsCategories(self): - return self.db_comm_iface.getParamsCategories() - - def getHistory(self, from_jid, to_jid, size): - return self.db_comm_iface.getHistory(from_jid, to_jid, size) - - def addContact(self, jid): - return self.db_comm_iface.addContact(jid) - - def delContact(self, jid): - return self.db_comm_iface.delContact(jid) - - def isConnected(self): - return self.db_comm_iface.isConnected() - - def launchAction(self, type, data): - return self.db_req_iface.launchAction(type, data) - - def confirmationAnswer(self, id, accepted, data): - return self.db_req_iface.confirmationAnswer(id, accepted, data) def gatewayRegister(self, action, target, data): if data == None:
--- a/plugins/plugin_xep_0100.py Sat Jan 30 16:17:33 2010 +1100 +++ b/plugins/plugin_xep_0100.py Sun Jan 31 15:57:03 2010 +1100 @@ -43,7 +43,7 @@ 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) + host.bridge.addMethod("findGateways", ".communication", in_sign='ss', 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): @@ -109,6 +109,7 @@ """ client = self.host.getClient(profile_key) assert(client) + print "target ===>", target to_jid = jid.JID(target) debug ("find gateways (target = %s)" % to_jid.full()) request_id = self.host.get_next_id()
--- a/sat.tac Sat Jan 30 16:17:33 2010 +1100 +++ b/sat.tac Sun Jan 31 15:57:03 2010 +1100 @@ -81,7 +81,7 @@ print "SatXMPPClient" client.XMPPClient._authd(self, xmlstream) self.__connected=True - print "********** CONNECTED **********" + print "********** [%s] CONNECTED **********" % self.profile self.streamInitialized() self.host_app.bridge.connected() #we send the signal to the clients @@ -107,7 +107,7 @@ def connectionLost(self, connector, unused_reason): self.__connected=False - print "********** DISCONNECTED **********" + print "********** [%s] DISCONNECTED **********" % self.profile try: self.keep_alife.stop() except AttributeError: @@ -164,14 +164,14 @@ if item.name: item_attr['name'] = item.name info ("new contact in roster list: %s", item.jid.full()) - self.host.memory.addContact(item.jid, item_attr, item.groups) + self.host.memory.addContact(item.jid, item_attr, item.groups, self.parent.profile) self.host.bridge.newContact(item.jid.full(), item_attr, item.groups) def onRosterRemove(self, entity): """Called when a roster removal event is received""" #TODO: send a signal to frontends print "removing %s from roster list" % entity.full() - self.host.memory.delContact(entity) + self.host.memory.delContact(entity, self.parent.profile) class SatPresenceProtocol(xmppim.PresenceClientProtocol): @@ -187,7 +187,7 @@ del statuses[None] self.host.memory.addPresenceStatus(entity, show or "", - int(priority), statuses) + int(priority), statuses, self.parent.profile) #now it's time to notify frontends self.host.bridge.presenceUpdate(entity.full(), show or "", @@ -197,7 +197,7 @@ if statuses and statuses.has_key(None): #we only want string keys statuses["default"] = statuses[None] del statuses[None] - self.host.memory.addPresenceStatus(entity, "unavailable", 0, statuses) + self.host.memory.addPresenceStatus(entity, "unavailable", 0, statuses, self.parent.profile) #now it's time to notify frontends self.host.bridge.presenceUpdate(entity.full(), "unavailable", 0, statuses) @@ -211,22 +211,22 @@ def subscribedReceived(self, entity): debug ("subscription approved for [%s]" % entity.userhost()) - self.host.memory.delWaitingSub(entity.userhost()) + self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile) self.host.bridge.subscribe('subscribed', entity.userhost()) def unsubscribedReceived(self, entity): debug ("unsubscription confirmed for [%s]" % entity.userhost()) - self.host.memory.delWaitingSub(entity.userhost()) + self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile) self.host.bridge.subscribe('unsubscribed', entity.userhost()) def subscribeReceived(self, entity): debug ("subscription request for [%s]" % entity.userhost()) - self.host.memory.addWaitingSub('subscribe', entity.userhost()) + self.host.memory.addWaitingSub('subscribe', entity.userhost(), self.parent.profile) self.host.bridge.subscribe('subscribe', entity.userhost()) def unsubscribeReceived(self, entity): debug ("unsubscription asked for [%s]" % entity.userhost()) - self.host.memory.addWaitingSub('unsubscribe', entity.userhost()) + self.host.memory.addWaitingSub('unsubscribe', entity.userhost(), self.parent.profile) self.host.bridge.subscribe('unsubscribe', entity.userhost()) class SatDiscoProtocol(disco.DiscoClientProtocol):
--- a/sat_bridge/DBus.py Sat Jan 30 16:17:33 2010 +1100 +++ b/sat_bridge/DBus.py Sun Jan 31 15:57:03 2010 +1100 @@ -124,76 +124,76 @@ return self.cb["registerNewAccount"](login, password, host, port) @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='', out_signature='') - def connect(self): + in_signature='s', out_signature='') + def connect(self, profile_key='@DEFAULT@'): info ("Connection asked") return self.cb["connect"]() @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='', out_signature='') - def disconnect(self): + in_signature='s', out_signature='') + def disconnect(self, profile_key='@DEFAULT@'): info ("Disconnection asked") - return self.cb["disconnect"]() + return self.cb["disconnect"](profile_key) @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, in_signature='', out_signature='b') - def isConnected(self): + def isConnected(self, profile_key='@DEFAULT@'): info ("Connection status asked") - return self.cb["isConnected"]() + return self.cb["isConnected"](profile_key) @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='', out_signature='a(sa{ss}as)') - def getContacts(self): + in_signature='s', out_signature='a(sa{ss}as)') + def getContacts(self, profile_key='@DEFAULT@'): debug("getContacts...") - return self.cb["getContacts"]() - - @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='', out_signature='a{sa{s(sia{ss})}}') - def getPresenceStatus(self): - debug("getPresenceStatus...") - return self.cb["getPresenceStatus"]() + return self.cb["getContacts"](profile_key) @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='', out_signature='a{ss}') - def getWaitingSub(self): - debug("getWaitingSub...") - return self.cb["getWaitingSub"]() + in_signature='s', out_signature='a{sa{s(sia{ss})}}') + def getPresenceStatus(self, profile_key='@DEFAULT@'): + debug("getPresenceStatus...") + return self.cb["getPresenceStatus"](profile_key) @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='ss', out_signature='') - def sendMessage(self, to, message): - debug("sendMessage...") - self.cb["sendMessage"](to, message) - - @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='ssia{ss}', out_signature='') - def setPresence(self, to="", show="", priority=0, statuses={}): - self.cb["setPresence"](to, show, priority, statuses) - - @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='ss', out_signature='') - def subscription(self, type, entity): - self.cb["subscription"](type, entity) + in_signature='s', out_signature='a{ss}') + def getWaitingSub(self, profile_key='@DEFAULT@'): + debug("getWaitingSub...") + return self.cb["getWaitingSub"](profile_key) @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, in_signature='sss', out_signature='') - def setParam(self, name, value, category): - self.cb["setParam"](str(name), str(value), str(category)) + def sendMessage(self, to, message, profile_key='@DEFAULT@'): + debug("sendMessage...") + self.cb["sendMessage"](to, message, profile_key) + + @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, + in_signature='ssia{ss}s', out_signature='') + def setPresence(self, to="", show="", priority=0, statuses={}, profile_key='@DEFAULT@'): + self.cb["setPresence"](to, show, priority, statuses, profile_key) + + @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, + in_signature='sss', out_signature='') + def subscription(self, type, entity, profile_key='@DEFAULT@'): + self.cb["subscription"](type, entity, profile_key) + + @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, + in_signature='ssss', out_signature='') + def setParam(self, name, value, category, profile_key='@DEFAULT@'): + self.cb["setParam"](str(name), str(value), str(category), profile_key) @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='ss', out_signature='s') - def getParamA(self, name, category="default"): - return self.cb["getParamA"](name, category) - - @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='', out_signature='s') - def getParams(self): - return self.cb["getParams"]() + in_signature='sss', out_signature='s') + def getParamA(self, name, category="default", profile_key='@DEFAULT@'): + return self.cb["getParamA"](name, category, profile_key = profile_key) @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, in_signature='s', out_signature='s') - def getParamsForCategory(self, category): - return self.cb["getParamsForCategory"](category) + def getParams(self, profile_key='@DEFAULT@'): + return self.cb["getParams"](profile_key) + + @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, + in_signature='ss', out_signature='s') + def getParamsForCategory(self, category, profile_key='@DEFAULT@'): + return self.cb["getParamsForCategory"](category, profile_key) @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, in_signature='', out_signature='as') @@ -207,16 +207,16 @@ return self.cb["getHistory"](from_jid, to_jid, size) @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='s', out_signature='') - def addContact(self, entity): - debug("Subscription asked for %s", entity) - return self.cb["addContact"](entity) + in_signature='ss', out_signature='') + def addContact(self, entity, profile_key='@DEFAULT@'): + debug("Subscription asked for %s (profile %s)", entity, profile_key) + return self.cb["addContact"](entity, profile_key) @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='s', out_signature='') - def delContact(self, entity): - debug("Unsubscription asked for %s", entity) - return self.cb["delContact"](entity) + in_signature='ss', out_signature='') + def delContact(self, entity, profile_key='@DEFAULT@'): + debug("Unsubscription asked for %s (profile %s)", entity, profile_key) + return self.cb["delContact"](entity, profile_key) @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, in_signature='sa{ss}', out_signature='s')
--- a/tools/memory.py Sat Jan 30 16:17:33 2010 +1100 +++ b/tools/memory.py Sun Jan 31 15:57:03 2010 +1100 @@ -36,7 +36,7 @@ SAVEFILE_PRIVATE="/private" #file used to store misc values (mainly for plugins) class Param(): - """This class manage parameter with xml""" + """This class manage parameters with xml""" ### TODO: add desciption in params #TODO: mettre Watched dans un plugin @@ -505,53 +505,99 @@ return None - def addContact(self, contact_jid, attributes, groups): + def addContact(self, contact_jid, attributes, groups, profile_key='@DEFAULT@'): debug("Memory addContact: %s",contact_jid.userhost()) + profile = self.getProfileName(profile_key) + if not profile: + error ('Trying to add a contact to a non-existant profile') + return assert(isinstance(attributes,dict)) assert(isinstance(groups,set)) - self.contacts[contact_jid.userhost()]=[attributes, groups] + if not self.contacts.has_key(profile): + self.contacts[profile] = {} + self.contacts[profile][contact_jid.userhost()]=[attributes, groups] - def delContact(self, contact_jid): + def delContact(self, contact_jid, profile_key='@DEFAULT@'): debug("Memory delContact: %s",contact_jid.userhost()) - if self.contacts.has_key(contact_jid.userhost()): - del self.contacts[contact_jid.userhost()] + profile = self.getProfileName(profile_key) + if not profile: + error ('Trying to delete a contact for a non-existant profile') + return + if self.contacts.has_key(profile) and self.contacts[profile].has_key(contact_jid.userhost()): + del self.contacts[profile][contact_jid.userhost()] - def getContact(self, contact_jid): - if self.contacts.has_key(contact_jid.userhost()): - self.contacts[contact_jid.userhost()] + def getContact(self, contact_jid, profile_key='@DEFAULT@'): + profile = self.getProfileName(profile_key) + if not profile: + error('Asking a contact for a non-existant profile') + return None + if self.contacts.has_key(profile) and self.contacts[profile].has_key(contact_jid.userhost()): + self.contacts[profile][contact_jid.userhost()] else: return None - def getContacts(self): + def getContacts(self, profile_key='@DEFAULT@'): + """Return list of contacts for given profile + @param profile_key: profile key + @return list of [contact, attr, groups]""" debug ("Memory getContact OK (%s)", self.contacts) + profile = self.getProfileName(profile_key) + if not profile: + error('Asking contacts for a non-existant profile') + return [] ret=[] - for contact in self.contacts: - attr, groups = self.contacts[contact] + for contact in self.contacts[profile]: + attr, groups = self.contacts[profile][contact] ret.append([contact, attr, groups ]) return ret - def addPresenceStatus(self, contact_jid, show, priority, statuses): - if not self.presenceStatus.has_key(contact_jid.userhost()): - self.presenceStatus[contact_jid.userhost()] = {} + def addPresenceStatus(self, contact_jid, show, priority, statuses, profile_key='@DEFAULT@'): + profile = self.getProfileName(profile_key) + if not profile: + error('Trying to add presence status to a non-existant profile') + return + if not self.presenceStatus.has_key(profile): + self.presenceStatus[profile] = {} + if not self.presenceStatus[profile].has_key(contact_jid.userhost()): + self.presenceStatus[profile][contact_jid.userhost()] = {} resource = jid.parse(contact_jid.full())[2] or '' - self.presenceStatus[contact_jid.userhost()][resource] = (show, priority, statuses) + self.presenceStatus[profile][contact_jid.userhost()][resource] = (show, priority, statuses) - def addWaitingSub(self, type, contact_jid): + def addWaitingSub(self, type, contact_jid, profile_key): """Called when a subcription request is received""" - self.subscriptions[contact_jid] = type + profile = self.getProfileName(profile_key) + assert(profile) + if not self.subscriptions.has_key(profile): + self.subscriptions[profile] = {} + self.subscriptions[profile][contact_jid] = type - def delWaitingSub(self, contact_jid): + def delWaitingSub(self, contact_jid, profile_key): """Called when a subcription request is finished""" - if self.subscriptions.has_key(contact_jid): - del self.subscriptions[contact_jid] + profile = self.getProfileName(profile_key) + assert(profile) + if self.subscriptions.has_key(profile) and self.subscriptions[profile].has_key(contact_jid): + del self.subscriptions[profile][contact_jid] - def getWaitingSub(self): + def getWaitingSub(self, profile_key='@DEFAULT@'): """Called to get a list of currently waiting subscription requests""" - return self.subscriptions + profile = self.getProfileName(profile_key) + if not profile: + error('Asking waiting subscriptions for a non-existant profile') + return {} + if not self.subscriptions.has_key(profile): + return {} + + return self.subscriptions[profile] - def getPresenceStatus(self): - debug ("Memory getPresenceStatus (%s)", self.presenceStatus) - return self.presenceStatus + def getPresenceStatus(self, profile_key='@DEFAULT@'): + profile = self.getProfileName(profile_key) + if not profile: + error('Asking contacts for a non-existant profile') + return {} + if not self.presenceStatus.has_key(profile): + self.presenceStatus[profile] = {} + debug ("Memory getPresenceStatus (%s)", self.presenceStatus[profile]) + return self.presenceStatus[profile] def getParamA(self, name, category, attr="value", profile_key="@DEFAULT@"): return self.params.getParamA(name, category, attr, profile_key)