comparison src/sat.tac @ 305:15a12bf2bb62

core: server identities are now save in memory
author Goffi <goffi@goffi.org>
date Thu, 07 Apr 2011 22:21:16 +0200
parents f7bd973bba5a
children cc8ffbfe938c
comparison
equal deleted inserted replaced
304:e04ccf122bb6 305:15a12bf2bb62
27 27
28 import gettext 28 import gettext
29 gettext.install('sat', "i18n", unicode=True) 29 gettext.install('sat', "i18n", unicode=True)
30 30
31 from twisted.application import internet, service 31 from twisted.application import internet, service
32 from twisted.internet import glib2reactor, protocol, task 32 from twisted.internet import glib2reactor, protocol, task, defer
33 glib2reactor.install() 33 glib2reactor.install()
34 34
35 from twisted.words.protocols.jabber import jid, xmlstream 35 from twisted.words.protocols.jabber import jid, xmlstream
36 from twisted.words.protocols.jabber import error as jab_error 36 from twisted.words.protocols.jabber import error as jab_error
37 from twisted.words.xish import domish 37 from twisted.words.xish import domish
78 client.XMPPClient.__init__(self, user_jid, password, host, port) 78 client.XMPPClient.__init__(self, user_jid, password, host, port)
79 self.factory.clientConnectionLost = self.connectionLost 79 self.factory.clientConnectionLost = self.connectionLost
80 self.__connected=False 80 self.__connected=False
81 self.profile = profile 81 self.profile = profile
82 self.host_app = host_app 82 self.host_app = host_app
83 self.client_initialized = defer.Deferred()
83 84
84 def _authd(self, xmlstream): 85 def _authd(self, xmlstream):
85 if not self.host_app.trigger.point("XML Initialized", xmlstream, self.profile): 86 if not self.host_app.trigger.point("XML Initialized", xmlstream, self.profile):
86 return 87 return
87 client.XMPPClient._authd(self, xmlstream) 88 client.XMPPClient._authd(self, xmlstream)
108 self.roster.requestRoster() 109 self.roster.requestRoster()
109 110
110 self.presence.available() 111 self.presence.available()
111 112
112 self.disco.requestInfo(jid.JID(self.host_app.memory.getParamA("Server", "Connection", profile_key=self.profile))).addCallback(self.host_app.serverDisco, self.profile) #FIXME: use these informations 113 self.disco.requestInfo(jid.JID(self.host_app.memory.getParamA("Server", "Connection", profile_key=self.profile))).addCallback(self.host_app.serverDisco, self.profile) #FIXME: use these informations
114 self.disco.requestItems(jid.JID(self.host_app.memory.getParamA("Server", "Connection", profile_key=self.profile))).addCallback(self.host_app.serverDiscoItems, self.disco, self.profile, self.client_initialized)
113 115
114 def initializationFailed(self, reason): 116 def initializationFailed(self, reason):
115 print ("initializationFailed: %s" % reason) 117 print ("initializationFailed: %s" % reason)
116 self.host_app.bridge.connectionError("AUTH_ERROR", self.profile) 118 self.host_app.bridge.connectionError("AUTH_ERROR", self.profile)
117 try: 119 try:
153 class SatRosterProtocol(xmppim.RosterClientProtocol): 155 class SatRosterProtocol(xmppim.RosterClientProtocol):
154 156
155 def __init__(self, host): 157 def __init__(self, host):
156 xmppim.RosterClientProtocol.__init__(self) 158 xmppim.RosterClientProtocol.__init__(self)
157 self.host = host 159 self.host = host
160 self._groups=set()
158 161
159 def rosterCb(self, roster): 162 def rosterCb(self, roster):
160 for raw_jid, item in roster.iteritems(): 163 for raw_jid, item in roster.iteritems():
161 self.onRosterSet(item) 164 self.onRosterSet(item)
162 165
186 if item.name: 189 if item.name:
187 item_attr['name'] = item.name 190 item_attr['name'] = item.name
188 info (_("new contact in roster list: %s"), item.jid.full()) 191 info (_("new contact in roster list: %s"), item.jid.full())
189 self.host.memory.addContact(item.jid, item_attr, item.groups, self.parent.profile) 192 self.host.memory.addContact(item.jid, item_attr, item.groups, self.parent.profile)
190 self.host.bridge.newContact(item.jid.full(), item_attr, item.groups, self.parent.profile) 193 self.host.bridge.newContact(item.jid.full(), item_attr, item.groups, self.parent.profile)
194 self._groups.update(item.groups)
191 195
192 def onRosterRemove(self, entity): 196 def onRosterRemove(self, entity):
193 """Called when a roster removal event is received""" 197 """Called when a roster removal event is received"""
194 #TODO: send a signal to frontends 198 #TODO: send a signal to frontends
195 print _("removing %s from roster list") % entity.full() 199 print _("removing %s from roster list") % entity.full()
196 self.host.memory.delContact(entity, self.parent.profile) 200 self.host.memory.delContact(entity, self.parent.profile)
201
202 def getGroups(self):
203 """Return a set of groups"""
204 return self._groups
197 205
198 class SatPresenceProtocol(xmppim.PresenceClientProtocol): 206 class SatPresenceProtocol(xmppim.PresenceClientProtocol):
199 207
200 def __init__(self, host): 208 def __init__(self, host):
201 xmppim.PresenceClientProtocol.__init__(self) 209 xmppim.PresenceClientProtocol.__init__(self)
712 debug (_("Feature found: %s"),feature) 720 debug (_("Feature found: %s"),feature)
713 self.memory.addServerFeature(feature, profile) 721 self.memory.addServerFeature(feature, profile)
714 for cat, type in disco.identities: 722 for cat, type in disco.identities:
715 debug (_("Identity found: [%(category)s/%(type)s] %(identity)s") % {'category':cat, 'type':type, 'identity':disco.identities[(cat,type)]}) 723 debug (_("Identity found: [%(category)s/%(type)s] %(identity)s") % {'category':cat, 'type':type, 'identity':disco.identities[(cat,type)]})
716 724
725 def serverDiscoItems(self, disco_result, disco_client, profile, initialized):
726 """xep-0030 Discovery Protocol.
727 @param disco_result: result of the disco item querry
728 @param disco_client: SatDiscoProtocol instance
729 @param profile: profile of the user
730 @param initialized: deferred which must be chained when everything is done"""
731 def _check_entity_cb(result, entity, profile):
732 for category, type in result.identities:
733 debug (_('Identity added: (%(category)s,%(type)s) ==> %(entity)s [%(profile)s]') % {
734 'category':category, 'type':type, 'entity':entity, 'profile':profile})
735 self.memory.addServerIdentity(category, type, entity, profile)
736
737 defer_list = []
738 for item in disco_result._items:
739 defer_list.append(disco_client.requestInfo(item.entity).addCallback(_check_entity_cb, item.entity, profile))
740 defer.DeferredList(defer_list).chainDeferred(initialized)
741
717 742
718 ## Generic HMI ## 743 ## Generic HMI ##
719 744
720 def actionResult(self, id, type, data): 745 def actionResult(self, id, type, data):
721 """Send the result of an action 746 """Send the result of an action