annotate src/core/xmpp.py @ 484:23cbdf0a0777

core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
author Goffi <goffi@goffi.org>
date Wed, 15 Aug 2012 15:50:46 +0200
parents 2a072735e459
children e789917fb59d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 # -*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
goffi@necton2
parents:
diff changeset
4 """
goffi@necton2
parents:
diff changeset
5 SAT: a jabber client
459
cf005701624b copyleft date update
Goffi <goffi@goffi.org>
parents: 438
diff changeset
6 Copyright (C) 2009, 2010, 2011, 2012 Jérôme Poisson (goffi@goffi.org)
0
goffi@necton2
parents:
diff changeset
7
goffi@necton2
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
480
2a072735e459 Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents: 471
diff changeset
9 it under the terms of the GNU Affero General Public License as published by
0
goffi@necton2
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
goffi@necton2
parents:
diff changeset
11 (at your option) any later version.
goffi@necton2
parents:
diff changeset
12
goffi@necton2
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
goffi@necton2
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
goffi@necton2
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
480
2a072735e459 Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents: 471
diff changeset
16 GNU Affero General Public License for more details.
0
goffi@necton2
parents:
diff changeset
17
480
2a072735e459 Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents: 471
diff changeset
18 You should have received a copy of the GNU Affero General Public License
0
goffi@necton2
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
goffi@necton2
parents:
diff changeset
20 """
goffi@necton2
parents:
diff changeset
21
330
608a4a2ba94e Core: created a new core module where xmpp classes are put
Goffi <goffi@goffi.org>
parents: 324
diff changeset
22 from twisted.internet import task, defer
39
2e3411a6baad Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents: 37
diff changeset
23 from twisted.words.protocols.jabber import jid, xmlstream
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
24 from wokkel import client, disco, xmppim, generic, compat
0
goffi@necton2
parents:
diff changeset
25 from logging import debug, info, error
goffi@necton2
parents:
diff changeset
26
333
4c835d614bdb core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents: 330
diff changeset
27
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
28 class SatXMPPClient(client.XMPPClient):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
29
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
30 def __init__(self, host_app, profile, user_jid, password, host=None, port=5222):
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
31 client.XMPPClient.__init__(self, user_jid, password, host, port)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
32 self.factory.clientConnectionLost = self.connectionLost
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
33 self.__connected=False
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
34 self.profile = profile
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
35 self.host_app = host_app
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
36 self.client_initialized = defer.Deferred()
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
37 self.conn_deferred = defer.Deferred()
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
38
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
39 def getConnectionDeferred(self):
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
40 """Return a deferred which fire when the client is connected"""
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
41 return self.conn_deferred
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
42
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
43 def _authd(self, xmlstream):
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 277
diff changeset
44 if not self.host_app.trigger.point("XML Initialized", xmlstream, self.profile):
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 277
diff changeset
45 return
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
46 client.XMPPClient._authd(self, xmlstream)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
47 self.__connected=True
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
48 info (_("********** [%s] CONNECTED **********") % self.profile)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
49 self.streamInitialized()
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 65
diff changeset
50 self.host_app.bridge.connected(self.profile) #we send the signal to the clients
277
05caa87196e6 new xml log plugin
Goffi <goffi@goffi.org>
parents: 276
diff changeset
51
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
52
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
53 def streamInitialized(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
54 """Called after _authd"""
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
55 debug (_("XML stream is initialized"))
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
56 self.keep_alife = task.LoopingCall(self.xmlstream.send, " ") #Needed to avoid disconnection (specially with openfire)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
57 self.keep_alife.start(180)
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
58
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
59 self.disco = SatDiscoProtocol(self)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
60 self.disco.setHandlerParent(self)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
61 self.discoHandler = disco.DiscoHandler()
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
62 self.discoHandler.setHandlerParent(self)
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 277
diff changeset
63
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 277
diff changeset
64 if not self.host_app.trigger.point("Disco Handled", self.profile):
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 277
diff changeset
65 return
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
66
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
67 self.roster.requestRoster()
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
68
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
69 self.presence.available()
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
70
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 277
diff changeset
71 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
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
72 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)
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
73 self.conn_deferred.callback(None)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
74
262
af3d4f11fe43 Added management of connection error
Goffi <goffi@goffi.org>
parents: 260
diff changeset
75 def initializationFailed(self, reason):
af3d4f11fe43 Added management of connection error
Goffi <goffi@goffi.org>
parents: 260
diff changeset
76 print ("initializationFailed: %s" % reason)
274
c1ad04586edf Bridge: rename connection_error to connectionError for function name consistency
Goffi <goffi@goffi.org>
parents: 266
diff changeset
77 self.host_app.bridge.connectionError("AUTH_ERROR", self.profile)
262
af3d4f11fe43 Added management of connection error
Goffi <goffi@goffi.org>
parents: 260
diff changeset
78 try:
af3d4f11fe43 Added management of connection error
Goffi <goffi@goffi.org>
parents: 260
diff changeset
79 client.XMPPClient.initializationFailed(self, reason)
af3d4f11fe43 Added management of connection error
Goffi <goffi@goffi.org>
parents: 260
diff changeset
80 except:
af3d4f11fe43 Added management of connection error
Goffi <goffi@goffi.org>
parents: 260
diff changeset
81 #we already send an error signal, no need to raise an exception
af3d4f11fe43 Added management of connection error
Goffi <goffi@goffi.org>
parents: 260
diff changeset
82 pass
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
83 self.conn_deferred.errback()
262
af3d4f11fe43 Added management of connection error
Goffi <goffi@goffi.org>
parents: 260
diff changeset
84
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
85 def isConnected(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
86 return self.__connected
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
87
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
88 def connectionLost(self, connector, unused_reason):
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
89 self.__connected=False
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
90 info (_("********** [%s] DISCONNECTED **********") % self.profile)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
91 try:
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
92 self.keep_alife.stop()
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
93 except AttributeError:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
94 debug (_("No keep_alife"))
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 65
diff changeset
95 self.host_app.bridge.disconnected(self.profile) #we send the signal to the clients
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 379
diff changeset
96 self.host_app.purgeClient(self.profile) #and we remove references to this client
0
goffi@necton2
parents:
diff changeset
97
goffi@necton2
parents:
diff changeset
98
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
99 class SatMessageProtocol(xmppim.MessageProtocol):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
100
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
101 def __init__(self, host):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
102 xmppim.MessageProtocol.__init__(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
103 self.host = host
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
104
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
105 def onMessage(self, message):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
106 debug (_(u"got message from: %s"), message["from"])
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 252
diff changeset
107 if not self.host.trigger.point("MessageReceived",message, profile=self.parent.profile):
426
ae446194c20c core: don't save anymore delayed message in history
Goffi <goffi@goffi.org>
parents: 425
diff changeset
108 return
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
109 for e in message.elements():
426
ae446194c20c core: don't save anymore delayed message in history
Goffi <goffi@goffi.org>
parents: 425
diff changeset
110 if e.name == "body":
ae446194c20c core: don't save anymore delayed message in history
Goffi <goffi@goffi.org>
parents: 425
diff changeset
111 mess_type = message['type'] if message.hasAttribute('type') else 'normal'
429
37285f2d37c8 core: fixed empty body error on new message
Goffi <goffi@goffi.org>
parents: 426
diff changeset
112 mess_body = e.children[0] if e.children else ""
37285f2d37c8 core: fixed empty body error on new message
Goffi <goffi@goffi.org>
parents: 426
diff changeset
113 self.host.bridge.newMessage(message["from"], mess_body, mess_type, message['to'], profile=self.parent.profile)
426
ae446194c20c core: don't save anymore delayed message in history
Goffi <goffi@goffi.org>
parents: 425
diff changeset
114 if not u"delay" in [elem.name for elem in message.elements()]: #we don't save delayed messages in history
429
37285f2d37c8 core: fixed empty body error on new message
Goffi <goffi@goffi.org>
parents: 426
diff changeset
115 self.host.memory.addToHistory(jid.JID(message["from"]), jid.JID(message["to"]), mess_body, profile=self.parent.profile)
426
ae446194c20c core: don't save anymore delayed message in history
Goffi <goffi@goffi.org>
parents: 425
diff changeset
116 break
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
117
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
118 class SatRosterProtocol(xmppim.RosterClientProtocol):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
119
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
120 def __init__(self, host):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
121 xmppim.RosterClientProtocol.__init__(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
122 self.host = host
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
123 #XXX: the two following dicts keep a local copy of the roster
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
124 self._groups = {} #map from groups to bare jids: key=group value=set of bare jids
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
125 self._jids = {} #map from bare jids to RosterItem: key=jid value=RosterItem
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
126
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
127 def rosterCb(self, roster):
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
128 for raw_jid, item in roster.iteritems():
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
129 self.onRosterSet(item)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
130
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
131 def requestRoster(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
132 """ ask the server for Roster list """
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
133 debug("requestRoster")
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
134 self.getRoster().addCallback(self.rosterCb)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
135
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
136 def removeItem(self, to):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
137 """Remove a contact from roster list"""
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
138 xmppim.RosterClientProtocol.removeItem(self, to)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
139 #TODO: check IQ result
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
140
187
12544ea2951f Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents: 155
diff changeset
141 #XXX: disabled (cf http://wokkel.ik.nu/ticket/56))
12544ea2951f Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents: 155
diff changeset
142 #def addItem(self, to):
12544ea2951f Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents: 155
diff changeset
143 #"""Add a contact to roster list"""
12544ea2951f Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents: 155
diff changeset
144 #xmppim.RosterClientProtocol.addItem(self, to)
12544ea2951f Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents: 155
diff changeset
145 #TODO: check IQ result"""
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
146
346
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
147 def updateItem(self, roster_item):
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
148 """
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
149 Update an item of the contact list.
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
150
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
151 @param roster_item: item to update
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
152 """
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
153 iq = compat.IQ(self.xmlstream, 'set')
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
154 iq.addElement((xmppim.NS_ROSTER, 'query'))
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
155 item = iq.query.addElement('item')
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
156 item['jid'] = roster_item.jid.userhost()
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
157 if roster_item.name:
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
158 item['name'] = roster_item.name
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
159 for group in roster_item.groups:
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
160 item.addElement('group', content=group)
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
161 return iq.send()
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
162
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
163 def getAttributes(self, item):
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
164 """Return dictionary of attributes as used in bridge from a RosterItem
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
165 @param item: RosterItem
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
166 @return: dictionary of attributes"""
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
167 item_attr = {'to': str(item.subscriptionTo),
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
168 'from': str(item.subscriptionFrom),
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
169 'ask': str(item.ask)
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
170 }
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
171 if item.name:
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
172 item_attr['name'] = item.name
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
173 return item_attr
346
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
174
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
175 def onRosterSet(self, item):
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
176 """Called when a new/update roster item is received"""
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
177 #TODO: send a signal to frontends
347
ea3e1b82dd79 core: contact deletion from roster if we have no subscription to it (behaviour may change in futur)
Goffi <goffi@goffi.org>
parents: 346
diff changeset
178 if not item.subscriptionTo and not item.subscriptionFrom and not item.ask:
ea3e1b82dd79 core: contact deletion from roster if we have no subscription to it (behaviour may change in futur)
Goffi <goffi@goffi.org>
parents: 346
diff changeset
179 #XXX: current behaviour: we don't want contact in our roster list
ea3e1b82dd79 core: contact deletion from roster if we have no subscription to it (behaviour may change in futur)
Goffi <goffi@goffi.org>
parents: 346
diff changeset
180 #if there is no presence subscription
ea3e1b82dd79 core: contact deletion from roster if we have no subscription to it (behaviour may change in futur)
Goffi <goffi@goffi.org>
parents: 346
diff changeset
181 #may change in the future
ea3e1b82dd79 core: contact deletion from roster if we have no subscription to it (behaviour may change in futur)
Goffi <goffi@goffi.org>
parents: 346
diff changeset
182 self.removeItem(item.jid)
ea3e1b82dd79 core: contact deletion from roster if we have no subscription to it (behaviour may change in futur)
Goffi <goffi@goffi.org>
parents: 346
diff changeset
183 return
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
184 info (_("new contact in roster list: %s"), item.jid.full())
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
185 #self.host.memory.addContact(item.jid, item_attr, item.groups, self.parent.profile)
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
186
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
187 bare_jid = item.jid.userhost()
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
188 self._jids[bare_jid] = item
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
189 for group in item.groups:
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 467
diff changeset
190 self._groups.setdefault(group,set()).add(bare_jid)
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
191 self.host.bridge.newContact(item.jid.full(), self.getAttributes(item), item.groups, self.parent.profile)
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
192
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
193 def onRosterRemove(self, entity):
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
194 """Called when a roster removal event is received"""
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
195 print _("removing %s from roster list") % entity.full()
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
196 bare_jid = entity.userhost()
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
197
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
198 #we first remove item from local cache (self._groups and self._jids)
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
199 try:
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
200 item = self._jids.pop(bare_jid)
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
201 except KeyError:
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
202 log.warning("Received a roster remove event for an item not in cache")
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
203 return
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
204 for group in item.groups:
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
205 try:
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
206 jids_set = self._groups[group]
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
207 jids_set.remove(bare_jid)
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
208 if not jids_set:
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
209 del self._groups[group]
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
210 except KeyError:
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
211 log.warning("there is not cache for the group [%(groups)s] of the removed roster item [%(jid)s]" %
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
212 {"group": group, "jid": bare_jid})
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
213
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
214 #then we send the bridge signal
347
ea3e1b82dd79 core: contact deletion from roster if we have no subscription to it (behaviour may change in futur)
Goffi <goffi@goffi.org>
parents: 346
diff changeset
215 self.host.bridge.contactDeleted(entity.userhost(), self.parent.profile)
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
216
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
217 def getGroups(self):
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
218 """Return a list of groups"""
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
219 return self._groups.keys()
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
220
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
221 def getItem(self, jid):
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
222 """Return RosterItem for a given jid
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
223 @param jid: jid of the contact
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
224 @return: RosterItem or None if contact is not in cache"""
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
225 return self._jids.get(jid.userhost(), None)
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
226
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 466
diff changeset
227 def getBareJids(self):
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 466
diff changeset
228 """Return all bare jids (as unicode) of the roster"""
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 466
diff changeset
229 return self._jids.keys()
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 466
diff changeset
230
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
231 def getItems(self):
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
232 """Return all items of the roster"""
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 466
diff changeset
233 return self._jids.values()
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
234
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
235
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
236 class SatPresenceProtocol(xmppim.PresenceClientProtocol):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
237
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
238 def __init__(self, host):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
239 xmppim.PresenceClientProtocol.__init__(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
240 self.host = host
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
241
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
242 def availableReceived(self, entity, show=None, statuses=None, priority=0):
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 69
diff changeset
243 debug (_("presence update for [%(entity)s] (available, show=%(show)s statuses=%(statuses)s priority=%(priority)d)") % {'entity':entity, 'show':show, 'statuses':statuses, 'priority':priority})
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
244
334
698cbc6ebec8 core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents: 333
diff changeset
245 if not statuses:
698cbc6ebec8 core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents: 333
diff changeset
246 statuses = {}
698cbc6ebec8 core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents: 333
diff changeset
247
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
248 if statuses.has_key(None): #we only want string keys
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
249 statuses["default"] = statuses[None]
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
250 del statuses[None]
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
251
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
252 self.host.memory.setPresenceStatus(entity, show or "",
65
d35c5edab53f SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents: 64
diff changeset
253 int(priority), statuses, self.parent.profile)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
254
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
255 #now it's time to notify frontends
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
256 self.host.bridge.presenceUpdate(entity.full(), show or "",
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 65
diff changeset
257 int(priority), statuses, self.parent.profile)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
258
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
259 def unavailableReceived(self, entity, statuses=None):
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 69
diff changeset
260 debug (_("presence update for [%(entity)s] (unavailable, statuses=%(statuses)s)") % {'entity':entity, 'statuses':statuses})
334
698cbc6ebec8 core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents: 333
diff changeset
261
333
4c835d614bdb core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents: 330
diff changeset
262 if not statuses:
4c835d614bdb core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents: 330
diff changeset
263 statuses = {}
334
698cbc6ebec8 core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents: 333
diff changeset
264
333
4c835d614bdb core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents: 330
diff changeset
265 if statuses.has_key(None): #we only want string keys
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
266 statuses["default"] = statuses[None]
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
267 del statuses[None]
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
268 self.host.memory.setPresenceStatus(entity, "unavailable", 0, statuses, self.parent.profile)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
269
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
270 #now it's time to notify frontends
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 65
diff changeset
271 self.host.bridge.presenceUpdate(entity.full(), "unavailable", 0, statuses, self.parent.profile)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
272
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
273
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
274 def available(self, entity=None, show=None, statuses=None, priority=0):
379
adcc41e4d6ea core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents: 347
diff changeset
275 if not statuses:
adcc41e4d6ea core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents: 347
diff changeset
276 statuses = {}
438
62145e50eae5 core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents: 429
diff changeset
277 # default for us is None for wokkel
62145e50eae5 core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents: 429
diff changeset
278 # so we must temporarily switch to wokkel's convention...
379
adcc41e4d6ea core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents: 347
diff changeset
279 if 'default' in statuses:
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
280 statuses[None] = statuses['default']
379
adcc41e4d6ea core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents: 347
diff changeset
281
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
282 xmppim.PresenceClientProtocol.available(self, entity, show, statuses, priority)
379
adcc41e4d6ea core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents: 347
diff changeset
283
adcc41e4d6ea core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents: 347
diff changeset
284 # ... before switching back
adcc41e4d6ea core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents: 347
diff changeset
285 if None in statuses:
adcc41e4d6ea core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents: 347
diff changeset
286 del statuses[None]
adcc41e4d6ea core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents: 347
diff changeset
287
346
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
288 def subscribed(self, entity):
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
289 xmppim.PresenceClientProtocol.subscribed(self, entity)
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
290 self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile)
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
291 item = self.parent.roster.getItem(entity)
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
292 if not item or not item.subscriptionTo: #we automatically subscribe to 'to' presence
346
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
293 debug(_('sending automatic "from" subscription request'))
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
294 self.subscribe(entity)
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
295
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
296 def unsubscribed(self, entity):
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
297 xmppim.PresenceClientProtocol.unsubscribed(self, entity)
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
298 self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile)
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
299
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
300 def subscribedReceived(self, entity):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
301 debug (_("subscription approved for [%s]") % entity.userhost())
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 65
diff changeset
302 self.host.bridge.subscribe('subscribed', entity.userhost(), self.parent.profile)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
303
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
304 def unsubscribedReceived(self, entity):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
305 debug (_("unsubscription confirmed for [%s]") % entity.userhost())
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 65
diff changeset
306 self.host.bridge.subscribe('unsubscribed', entity.userhost(), self.parent.profile)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
307
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
308 def subscribeReceived(self, entity):
346
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
309 debug (_("subscription request from [%s]") % entity.userhost())
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
310 item = self.parent.roster.getItem(entity)
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
311 if item and item.subscriptionTo:
346
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
312 #We automatically accept subscription if we are already subscribed to contact presence
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
313 debug(_('sending automatic subscription acceptance'))
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
314 self.subscribed(entity)
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
315 else:
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
316 self.host.memory.addWaitingSub('subscribe', entity.userhost(), self.parent.profile)
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
317 self.host.bridge.subscribe('subscribe', entity.userhost(), self.parent.profile)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
318
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
319 def unsubscribeReceived(self, entity):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
320 debug (_("unsubscription asked for [%s]") % entity.userhost())
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
321 item = self.parent.roster.getItem(entity)
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
322 if item and item.subscriptionFrom: #we automatically remove contact
346
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
323 debug(_('automatic contact deletion'))
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
324 self.host.delContact(entity.userhost(), self.parent.profile)
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 65
diff changeset
325 self.host.bridge.subscribe('unsubscribe', entity.userhost(), self.parent.profile)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
326
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
327 class SatDiscoProtocol(disco.DiscoClientProtocol):
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
328 def __init__(self, host):
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
329 disco.DiscoClientProtocol.__init__(self)
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
330
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
331 class SatFallbackHandler(generic.FallbackHandler):
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
332 def __init__(self, host):
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
333 generic.FallbackHandler.__init__(self)
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
334
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
335 def iqFallback(self, iq):
292
f7bd973bba5a core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents: 288
diff changeset
336 if iq.handled == True:
f7bd973bba5a core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents: 288
diff changeset
337 return
f7bd973bba5a core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents: 288
diff changeset
338 debug (u"iqFallback: xml = [%s]" % (iq.toXml()))
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
339 generic.FallbackHandler.iqFallback(self, iq)
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
340
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
341 class RegisteringAuthenticator(xmlstream.ConnectAuthenticator):
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
342
336
953536246d9d core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents: 334
diff changeset
343 def __init__(self, host, jabber_host, user_login, user_pass, email, answer_id):
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
344 xmlstream.ConnectAuthenticator.__init__(self, jabber_host)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
345 self.host = host
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
346 self.jabber_host = jabber_host
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
347 self.user_login = user_login
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
348 self.user_pass = user_pass
336
953536246d9d core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents: 334
diff changeset
349 self.user_email = email
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
350 self.answer_id = answer_id
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
351 print _("Registration asked for"),user_login, user_pass, jabber_host
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
352
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
353 def connectionMade(self):
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
354 print "connectionMade"
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
355
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
356 self.xmlstream.namespace = "jabber:client"
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
357 self.xmlstream.sendHeader()
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
358
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
359 iq = compat.IQ(self.xmlstream, 'set')
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
360 iq["to"] = self.jabber_host
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
361 query = iq.addElement(('jabber:iq:register', 'query'))
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
362 _user = query.addElement('username')
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
363 _user.addContent(self.user_login)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
364 _pass = query.addElement('password')
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
365 _pass.addContent(self.user_pass)
336
953536246d9d core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents: 334
diff changeset
366 if self.user_email:
953536246d9d core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents: 334
diff changeset
367 _email = query.addElement('email')
953536246d9d core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents: 334
diff changeset
368 _email.addContent(self.user_email)
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
369 reg = iq.send(self.jabber_host).addCallbacks(self.registrationAnswer, self.registrationFailure)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
370
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
371 def registrationAnswer(self, answer):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
372 debug (_("registration answer: %s") % answer.toXml())
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
373 answer_type = "SUCCESS"
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
374 answer_data={"message":_("Registration successfull")}
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
375 self.host.bridge.actionResult(answer_type, self.answer_id, answer_data)
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
376 self.xmlstream.sendFooter()
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
377
30
d6b613764dd7 new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents: 25
diff changeset
378 def registrationFailure(self, failure):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
379 info (_("Registration failure: %s") % str(failure.value))
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
380 answer_type = "ERROR"
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
381 answer_data = {}
30
d6b613764dd7 new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents: 25
diff changeset
382 if failure.value.condition == 'conflict':
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
383 answer_data['reason'] = 'conflict'
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
384 answer_data={"message":_("Username already exists, please choose an other one")}
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
385 else:
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
386 answer_data['reason'] = 'unknown'
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
387 answer_data={"message":_("Registration failed (%s)") % str(failure.value.condition)}
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
388 self.host.bridge.actionResult(answer_type, self.answer_id, answer_data)
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
389 self.xmlstream.sendFooter()
292
f7bd973bba5a core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents: 288
diff changeset
390
f7bd973bba5a core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents: 288
diff changeset
391 class SatVersionHandler(generic.VersionHandler):
f7bd973bba5a core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents: 288
diff changeset
392
f7bd973bba5a core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents: 288
diff changeset
393 def getDiscoInfo(self, requestor, target, node):
461
4e361d295bca core: typo
Goffi <goffi@goffi.org>
parents: 459
diff changeset
394 #XXX: We need to work around wokkel's behaviour (namespace not added if there is a
292
f7bd973bba5a core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents: 288
diff changeset
395 # node) as it cause issues with XEP-0115 & PEP (XEP-0163): there is a node when server
f7bd973bba5a core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents: 288
diff changeset
396 # ask for disco info, and not when we generate the key, so the hash is used with different
f7bd973bba5a core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents: 288
diff changeset
397 # disco features, and when the server (seen on ejabberd) generate its own hash for security check
f7bd973bba5a core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents: 288
diff changeset
398 # it reject our features (resulting in e.g. no notification on PEP)
f7bd973bba5a core: wokkel behavious work around on VersionHandler to avoid XEP-0115 issue with ejabberd (see comments for details)
Goffi <goffi@goffi.org>
parents: 288
diff changeset
399 return generic.VersionHandler.getDiscoInfo(self, requestor, target, None)
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
400