annotate src/core/xmpp.py @ 1276:56adf73bedeb

core (xmpp): set missing "from" attribute of received messages to the server domain
author souliane <souliane@mailoo.org>
date Fri, 19 Dec 2014 11:42:45 +0100
parents 8b891f9be183
children f71a0fc26886
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
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
4 # SAT: a jabber client
811
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 771
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
0
goffi@necton2
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
10 # (at your option) any later version.
0
goffi@necton2
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
15 # GNU Affero General Public License for more details.
0
goffi@necton2
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
0
goffi@necton2
parents:
diff changeset
19
1053
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
20 from sat.core.i18n import _
923
e77948faaef3 core: removed default_config:
Goffi <goffi@goffi.org>
parents: 875
diff changeset
21 from sat.core.constants import Const as C
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
666
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
24 from wokkel import client, disco, xmppim, generic, compat, delay, iwokkel
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
25 from sat.core.log import getLogger
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
26 log = getLogger(__name__)
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
27 from sat.core import exceptions
513
8ee9113d307b core, quick_frontend, primitivus, wixi, bridge: fixed delayed message timestamp:
Goffi <goffi@goffi.org>
parents: 512
diff changeset
28 from calendar import timegm
666
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
29 from zope.interface import implements
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
30 try:
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
31 from twisted.words.protocols.xmlstream import XMPPHandler
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
32 except ImportError:
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
33 from wokkel.subprotocols import XMPPHandler
0
goffi@necton2
parents:
diff changeset
34
333
4c835d614bdb core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents: 330
diff changeset
35
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
36 class SatXMPPClient(client.XMPPClient):
666
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
37 implements(iwokkel.IDisco)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
38
1089
8e0072754413 core, plugins, stdui, frontends: fixes handling of "Force server" and "Force port" parameters:
souliane <souliane@mailoo.org>
parents: 1088
diff changeset
39 def __init__(self, host_app, profile, user_jid, password, host=None, port=C.XMPP_C2S_PORT):
1088
b29452cab50b core, memory, plugins, stdui, frontends: look for DNS SRV records when server is not specified:
souliane <souliane@mailoo.org>
parents: 1061
diff changeset
40 # XXX: DNS SRV records are checked when the host is not specified.
b29452cab50b core, memory, plugins, stdui, frontends: look for DNS SRV records when server is not specified:
souliane <souliane@mailoo.org>
parents: 1061
diff changeset
41 # If no SRV record is found, the host is directly extracted from the JID.
1089
8e0072754413 core, plugins, stdui, frontends: fixes handling of "Force server" and "Force port" parameters:
souliane <souliane@mailoo.org>
parents: 1088
diff changeset
42 client.XMPPClient.__init__(self, user_jid, password, host or None, port or C.XMPP_C2S_PORT)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
43 self.factory.clientConnectionLost = self.connectionLost
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
44 self.__connected = False
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
45 self.profile = profile
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
46 self.host_app = host_app
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
47 self.conn_deferred = defer.Deferred()
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
48 self._waiting_conf = {} # callback called when a confirmation is received
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
49 self._progress_cb_map = {} # callback called when a progress is requested (key = progress id)
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
50
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
51 def getConnectionDeferred(self):
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
52 """Return a deferred which fire when the client is connected"""
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
53 return self.conn_deferred
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
54
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
55 def _authd(self, xmlstream):
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 277
diff changeset
56 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
57 return
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
58 client.XMPPClient._authd(self, xmlstream)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
59 self.__connected = True
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
60 log.info(_("********** [%s] CONNECTED **********") % self.profile)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
61 self.streamInitialized()
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
62 self.host_app.bridge.connected(self.profile) # we send the signal to the clients
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
63
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
64 def streamInitialized(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
65 """Called after _authd"""
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
66 log.debug(_("XML stream is initialized"))
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
67 self.keep_alife = task.LoopingCall(self.xmlstream.send, " ") # Needed to avoid disconnection (specially with openfire)
1211
9355f48f979e core: move XMPP keep-alife value to the constants
souliane <souliane@mailoo.org>
parents: 1170
diff changeset
68 self.keep_alife.start(C.XMPP_KEEP_ALIFE)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
69
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
70 self.disco = SatDiscoProtocol(self)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
71 self.disco.setHandlerParent(self)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
72 self.discoHandler = disco.DiscoHandler()
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
73 self.discoHandler.setHandlerParent(self)
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
74 disco_d = defer.succeed(None)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
75
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
76 if not self.host_app.trigger.point("Disco handled", disco_d, self.profile):
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 277
diff changeset
77 return
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
78
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
79 def finish_connection(dummy):
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
80 self.roster.requestRoster()
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
81 self.presence.available()
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
82 self.conn_deferred.callback(None)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
83
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
84 disco_d.addCallback(finish_connection)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
85
262
af3d4f11fe43 Added management of connection error
Goffi <goffi@goffi.org>
parents: 260
diff changeset
86 def initializationFailed(self, reason):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
87 log.error(_("ERROR: XMPP connection failed for profile '%(profile)s': %(reason)s" % {'profile': self.profile, 'reason': reason}))
1060
aa15453ec54d core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
souliane <souliane@mailoo.org>
parents: 1053
diff changeset
88 self.conn_deferred.errback(reason.value)
262
af3d4f11fe43 Added management of connection error
Goffi <goffi@goffi.org>
parents: 260
diff changeset
89 try:
af3d4f11fe43 Added management of connection error
Goffi <goffi@goffi.org>
parents: 260
diff changeset
90 client.XMPPClient.initializationFailed(self, reason)
af3d4f11fe43 Added management of connection error
Goffi <goffi@goffi.org>
parents: 260
diff changeset
91 except:
1060
aa15453ec54d core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
souliane <souliane@mailoo.org>
parents: 1053
diff changeset
92 # we already chained an errback, no need to raise an exception
262
af3d4f11fe43 Added management of connection error
Goffi <goffi@goffi.org>
parents: 260
diff changeset
93 pass
af3d4f11fe43 Added management of connection error
Goffi <goffi@goffi.org>
parents: 260
diff changeset
94
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
95 def isConnected(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
96 return self.__connected
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
97
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
98 def connectionLost(self, connector, unused_reason):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
99 try:
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
100 self.keep_alife.stop()
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
101 except AttributeError:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
102 log.debug(_("No keep_alife"))
1060
aa15453ec54d core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
souliane <souliane@mailoo.org>
parents: 1053
diff changeset
103 if self.__connected:
aa15453ec54d core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
souliane <souliane@mailoo.org>
parents: 1053
diff changeset
104 log.info(_("********** [%s] DISCONNECTED **********") % self.profile)
aa15453ec54d core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
souliane <souliane@mailoo.org>
parents: 1053
diff changeset
105 self.host_app.bridge.disconnected(self.profile) # we send the signal to the clients
aa15453ec54d core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
souliane <souliane@mailoo.org>
parents: 1053
diff changeset
106 self.host_app.purgeClient(self.profile) # and we remove references to this client
aa15453ec54d core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
souliane <souliane@mailoo.org>
parents: 1053
diff changeset
107 self.__connected = False
0
goffi@necton2
parents:
diff changeset
108
goffi@necton2
parents:
diff changeset
109
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
110 class SatMessageProtocol(xmppim.MessageProtocol):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
111
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
112 def __init__(self, host):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
113 xmppim.MessageProtocol.__init__(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
114 self.host = host
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
115
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
116 def onMessage(self, message):
1276
56adf73bedeb core (xmpp): set missing "from" attribute of received messages to the server domain
souliane <souliane@mailoo.org>
parents: 1246
diff changeset
117 if not message.hasAttribute('from'):
56adf73bedeb core (xmpp): set missing "from" attribute of received messages to the server domain
souliane <souliane@mailoo.org>
parents: 1246
diff changeset
118 message['from'] = self.parent.jid.host
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
119 log.debug(_(u"got message from: %s") % message["from"])
697
0c84fb112d70 core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents: 669
diff changeset
120 post_treat = defer.Deferred() # XXX: plugin can add their treatments to this deferred
663
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
121
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
122 if not self.host.trigger.point("MessageReceived", message, post_treat, profile=self.parent.profile):
513
8ee9113d307b core, quick_frontend, primitivus, wixi, bridge: fixed delayed message timestamp:
Goffi <goffi@goffi.org>
parents: 512
diff changeset
123 return
663
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
124
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
125 data = {"from": message['from'],
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
126 "to": message['to'],
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
127 "body": "",
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
128 "extra": {}}
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
129
513
8ee9113d307b core, quick_frontend, primitivus, wixi, bridge: fixed delayed message timestamp:
Goffi <goffi@goffi.org>
parents: 512
diff changeset
130 for e in message.elements():
8ee9113d307b core, quick_frontend, primitivus, wixi, bridge: fixed delayed message timestamp:
Goffi <goffi@goffi.org>
parents: 512
diff changeset
131 if e.name == "body":
663
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
132 data['body'] = e.children[0] if e.children else ""
1061
3700165d68dc core (xmpp): onMessage handles an eventual subject (used for announcement / headline message)
souliane <souliane@mailoo.org>
parents: 1060
diff changeset
133 elif e.name == "subject" and e.children:
3700165d68dc core (xmpp): onMessage handles an eventual subject (used for announcement / headline message)
souliane <souliane@mailoo.org>
parents: 1060
diff changeset
134 data['extra']['subject'] = e.children[0]
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
135
663
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
136 data['type'] = message['type'] if message.hasAttribute('type') else 'normal'
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
137
1053
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
138 def bridgeSignal(data):
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
139 if data is not None:
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
140 self.host.bridge.newMessage(data['from'], data['body'], data['type'], data['to'], data['extra'], profile=self.parent.profile)
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
141 return data
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
142
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
143 def addToHistory(data):
663
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
144 # set message body to empty string by default, and later
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
145 # also forward message without body (chat state notification...)
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
146 try:
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
147 _delay = delay.Delay.fromElement(filter(lambda elm: elm.name == 'delay', message.elements())[0])
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
148 timestamp = timegm(_delay.stamp.utctimetuple())
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
149 data['extra']['archive'] = str(timestamp)
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
150 if data['type'] != 'groupchat': # XXX: we don't save delayed messages in history for groupchats
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
151 #TODO: add delayed messages to history if they aren't already in it
669
ffb716804580 core, bridge: extra parameter is saved in history:
Goffi <goffi@goffi.org>
parents: 666
diff changeset
152 self.host.memory.addToHistory(jid.JID(data['from']), jid.JID(data['to']), data['body'], data['type'], data['extra'], timestamp, profile=self.parent.profile)
663
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
153 except IndexError:
669
ffb716804580 core, bridge: extra parameter is saved in history:
Goffi <goffi@goffi.org>
parents: 666
diff changeset
154 self.host.memory.addToHistory(jid.JID(data['from']), jid.JID(data['to']), data['body'], data['type'], data['extra'], profile=self.parent.profile)
1053
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
155 return data
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
156
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
157 def treatmentsEb(failure):
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
158 failure.trap(exceptions.SkipHistory)
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
159 return data
663
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
160
1053
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
161 def cancelErrorTrap(failure):
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
162 """A message sending can be cancelled by a plugin treatment"""
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
163 failure.trap(exceptions.CancelError)
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
164
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
165 post_treat.addCallback(addToHistory)
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
166 post_treat.addErrback(treatmentsEb)
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
167 post_treat.addCallback(bridgeSignal)
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
168 post_treat.addErrback(cancelErrorTrap)
663
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
169 post_treat.callback(data)
636
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents: 611
diff changeset
170
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
171
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
172 class SatRosterProtocol(xmppim.RosterClientProtocol):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
173
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
174 def __init__(self, host):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
175 xmppim.RosterClientProtocol.__init__(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
176 self.host = host
549
2c5ef983f2ef core: client.roster has now a got_roster deferred which is fired when roster is available
Goffi <goffi@goffi.org>
parents: 538
diff changeset
177 self.got_roster = defer.Deferred()
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
178 #XXX: the two following dicts keep a local copy of the roster
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
179 self._groups = {} # map from groups to bare jids: key=group value=set of bare jids
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
180 self._jids = {} # map from bare jids to RosterItem: key=jid value=RosterItem
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
181
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
182 def rosterCb(self, roster):
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
183 for raw_jid, item in roster.iteritems():
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
184 self.onRosterSet(item)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
185
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
186 def requestRoster(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
187 """ ask the server for Roster list """
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
188 log.debug("requestRoster")
549
2c5ef983f2ef core: client.roster has now a got_roster deferred which is fired when roster is available
Goffi <goffi@goffi.org>
parents: 538
diff changeset
189 d = self.getRoster().addCallback(self.rosterCb)
2c5ef983f2ef core: client.roster has now a got_roster deferred which is fired when roster is available
Goffi <goffi@goffi.org>
parents: 538
diff changeset
190 d.chainDeferred(self.got_roster)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
191
875
19d7d077478a core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents: 819
diff changeset
192 def removeItem(self, to_jid):
19d7d077478a core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents: 819
diff changeset
193 """Remove a contact from roster list
19d7d077478a core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents: 819
diff changeset
194 @param to_jid: a JID instance
19d7d077478a core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents: 819
diff changeset
195 """
19d7d077478a core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents: 819
diff changeset
196 xmppim.RosterClientProtocol.removeItem(self, to_jid)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
197 #TODO: check IQ result
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
198
187
12544ea2951f Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents: 155
diff changeset
199 #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
200 #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
201 #"""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
202 #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
203 #TODO: check IQ result"""
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
204
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
205 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
206 """
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
207 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
208
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
209 @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
210 """
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
211 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
212 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
213 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
214 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
215 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
216 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
217 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
218 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
219 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
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 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
222 """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
223 @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
224 @return: dictionary of attributes"""
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
225 item_attr = {'to': unicode(item.subscriptionTo),
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
226 'from': unicode(item.subscriptionFrom),
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
227 'ask': unicode(item.ask)
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
228 }
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
229 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
230 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
231 return item_attr
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
232
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
233 def onRosterSet(self, item):
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
234 """Called when a new/update roster item is received"""
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
235 #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
236 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
237 #XXX: current behaviour: we don't want contact in our roster list
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
238 # if there is no presence subscription
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
239 # may change in the future
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
240 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
241 return
1246
8b891f9be183 core, plugins: improve a bit some log messages
souliane <souliane@mailoo.org>
parents: 1211
diff changeset
242 log.debug(_("New contact in roster list: %s") % item.jid.full())
958
9393dc29aaf3 core (XMPP): added warning when a contact ins roster is not subscribed from or to
Goffi <goffi@goffi.org>
parents: 953
diff changeset
243 if not item.subscriptionTo:
1246
8b891f9be183 core, plugins: improve a bit some log messages
souliane <souliane@mailoo.org>
parents: 1211
diff changeset
244 if not item.subscriptionFrom:
8b891f9be183 core, plugins: improve a bit some log messages
souliane <souliane@mailoo.org>
parents: 1211
diff changeset
245 log.info(_("There's no subscription between you and [%s]!") % item.jid.full())
8b891f9be183 core, plugins: improve a bit some log messages
souliane <souliane@mailoo.org>
parents: 1211
diff changeset
246 else:
8b891f9be183 core, plugins: improve a bit some log messages
souliane <souliane@mailoo.org>
parents: 1211
diff changeset
247 log.info(_("You are not subscribed to [%s]!") % item.jid.full())
958
9393dc29aaf3 core (XMPP): added warning when a contact ins roster is not subscribed from or to
Goffi <goffi@goffi.org>
parents: 953
diff changeset
248 if not item.subscriptionFrom:
1246
8b891f9be183 core, plugins: improve a bit some log messages
souliane <souliane@mailoo.org>
parents: 1211
diff changeset
249 log.info(_("[%s] is not subscribed to you!") % 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
250 #self.host.memory.addContact(item.jid, item_attr, item.groups, self.parent.profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
251
726
ade9997fabfa core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents: 697
diff changeset
252 bare_jid = item.jid.userhostJID()
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
253 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
254 for group in item.groups:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
255 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
256 self.host.bridge.newContact(item.jid.full(), self.getAttributes(item), item.groups, self.parent.profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
257
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
258 def onRosterRemove(self, entity):
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
259 """Called when a roster removal event is received"""
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
260 print _("removing %s from roster list") % entity.full()
726
ade9997fabfa core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents: 697
diff changeset
261 bare_jid = entity.userhostJID()
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
262
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
263 # we first remove item from local cache (self._groups and self._jids)
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
264 try:
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
265 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
266 except KeyError:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
267 log.warning("Received a roster remove event for an item not in cache")
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
268 return
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
269 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
270 try:
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
271 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
272 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
273 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
274 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
275 except KeyError:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
276 log.warning("there is not cache for the group [%(groups)s] of the removed roster item [%(jid)s]" %
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
277 {"group": group, "jid": bare_jid})
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
278
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
279 # 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
280 self.host.bridge.contactDeleted(entity.userhost(), self.parent.profile)
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
281
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
282 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
283 """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
284 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
285
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
286 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
287 """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
288 @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
289 @return: RosterItem or None if contact is not in cache"""
726
ade9997fabfa core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents: 697
diff changeset
290 return self._jids.get(jid.userhostJID(), None)
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
291
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 466
diff changeset
292 def getBareJids(self):
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 466
diff changeset
293 """Return all bare jids (as unicode) of the roster"""
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 466
diff changeset
294 return self._jids.keys()
487
e789917fb59d core: added isJidInRoster method
Goffi <goffi@goffi.org>
parents: 484
diff changeset
295
e789917fb59d core: added isJidInRoster method
Goffi <goffi@goffi.org>
parents: 484
diff changeset
296 def isJidInRoster(self, entity_jid):
e789917fb59d core: added isJidInRoster method
Goffi <goffi@goffi.org>
parents: 484
diff changeset
297 """Return True if jid is in roster"""
726
ade9997fabfa core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents: 697
diff changeset
298 return entity_jid.userhostJID() in self._jids
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
299
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
300 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
301 """Return all items of the roster"""
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 466
diff changeset
302 return self._jids.values()
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
303
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
304 def getJidsFromGroup(self, group):
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
305 try:
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
306 return self._groups[group]
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
307 except KeyError:
819
9e3641ea648f core: fixed UnknownGroupError exception in getJidsFromGroup
Goffi <goffi@goffi.org>
parents: 811
diff changeset
308 raise exceptions.UnknownGroupError
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
309
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
310
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
311 class SatPresenceProtocol(xmppim.PresenceClientProtocol):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
312
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
313 def __init__(self, host):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
314 xmppim.PresenceClientProtocol.__init__(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
315 self.host = host
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
316
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
317 def send(self, obj):
953
4a577b170809 plugin xep-0115: caps optimisation
Goffi <goffi@goffi.org>
parents: 947
diff changeset
318 if not self.host.trigger.point("Presence send", self.parent, obj):
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
319 return
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
320 super(SatPresenceProtocol, self).send(obj)
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
321
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
322 def availableReceived(self, entity, show=None, statuses=None, priority=0):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
323 log.debug(_("presence update for [%(entity)s] (available, show=%(show)s statuses=%(statuses)s priority=%(priority)d)") % {'entity': entity, 'show': show, 'statuses': statuses, 'priority': priority})
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
324
334
698cbc6ebec8 core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents: 333
diff changeset
325 if not statuses:
698cbc6ebec8 core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents: 333
diff changeset
326 statuses = {}
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
327
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
328 if None in statuses: # we only want string keys
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
329 statuses["default"] = statuses[None]
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
330 del statuses[None]
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
331
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
332 self.host.memory.setPresenceStatus(entity, show or "",
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
333 int(priority), statuses,
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
334 self.parent.profile)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
335
1170
2df6427a5299 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 1167
diff changeset
336 # uncomment these two lines if you need the trigger
2df6427a5299 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 1167
diff changeset
337 #if not self.host.trigger.point("presenceReceived", entity, "unavailable", 0, statuses, self.parent.profile):
2df6427a5299 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 1167
diff changeset
338 # return
2df6427a5299 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 1167
diff changeset
339
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
340 # now it's time to notify frontends
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
341 self.host.bridge.presenceUpdate(entity.full(), show or "",
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
342 int(priority), statuses,
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
343 self.parent.profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
344
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
345 def unavailableReceived(self, entity, statuses=None):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
346 log.debug(_("presence update for [%(entity)s] (unavailable, statuses=%(statuses)s)") % {'entity': entity, 'statuses': statuses})
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
347
333
4c835d614bdb core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents: 330
diff changeset
348 if not statuses:
4c835d614bdb core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents: 330
diff changeset
349 statuses = {}
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
350
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
351 if None in statuses: # we only want string keys
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
352 statuses["default"] = statuses[None]
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
353 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
354 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
355
1170
2df6427a5299 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 1167
diff changeset
356 if not self.host.trigger.point("presenceReceived", entity, "unavailable", 0, statuses, self.parent.profile):
2df6427a5299 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 1167
diff changeset
357 return
2df6427a5299 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 1167
diff changeset
358
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
359 # 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
360 self.host.bridge.presenceUpdate(entity.full(), "unavailable", 0, statuses, self.parent.profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
361
611
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
362 def available(self, entity=None, show=None, statuses=None, priority=None):
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
363 if priority is None:
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
364 try:
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
365 priority = int(self.host.memory.getParamA("Priority", "Connection", profile_key=self.parent.profile))
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
366 except ValueError:
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
367 priority = 0
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
368
734
b26dfac8e46c core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents: 726
diff changeset
369 if statuses is None:
562
0bb2e0d1c878 core, plugin XEP-0054: avatar upload:
Goffi <goffi@goffi.org>
parents: 549
diff changeset
370 statuses = {}
734
b26dfac8e46c core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents: 726
diff changeset
371
b26dfac8e46c core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents: 726
diff changeset
372 # default for us is None for wokkel
b26dfac8e46c core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents: 726
diff changeset
373 # so we must temporarily switch to wokkel's convention...
b26dfac8e46c core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents: 726
diff changeset
374 if 'default' in statuses:
b26dfac8e46c core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents: 726
diff changeset
375 statuses[None] = statuses['default']
947
61c4755f0394 core (XMPP): fix status in presence
Goffi <goffi@goffi.org>
parents: 944
diff changeset
376 del statuses['default']
379
adcc41e4d6ea core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents: 347
diff changeset
377
734
b26dfac8e46c core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents: 726
diff changeset
378 presence_elt = xmppim.AvailablePresence(entity, show, statuses, priority)
379
adcc41e4d6ea core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents: 347
diff changeset
379
562
0bb2e0d1c878 core, plugin XEP-0054: avatar upload:
Goffi <goffi@goffi.org>
parents: 549
diff changeset
380 # ... before switching back
0bb2e0d1c878 core, plugin XEP-0054: avatar upload:
Goffi <goffi@goffi.org>
parents: 549
diff changeset
381 if None in statuses:
947
61c4755f0394 core (XMPP): fix status in presence
Goffi <goffi@goffi.org>
parents: 944
diff changeset
382 statuses['default'] = statuses[None]
562
0bb2e0d1c878 core, plugin XEP-0054: avatar upload:
Goffi <goffi@goffi.org>
parents: 549
diff changeset
383 del statuses[None]
379
adcc41e4d6ea core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents: 347
diff changeset
384
1167
fe102b4cf275 core (xmpp): fixes SatPresenceProtocol.available to prevent an eventual code skipping
souliane <souliane@mailoo.org>
parents: 1089
diff changeset
385 if not self.host.trigger.point("presence_available", presence_elt, self.parent):
fe102b4cf275 core (xmpp): fixes SatPresenceProtocol.available to prevent an eventual code skipping
souliane <souliane@mailoo.org>
parents: 1089
diff changeset
386 return
fe102b4cf275 core (xmpp): fixes SatPresenceProtocol.available to prevent an eventual code skipping
souliane <souliane@mailoo.org>
parents: 1089
diff changeset
387 self.send(presence_elt)
fe102b4cf275 core (xmpp): fixes SatPresenceProtocol.available to prevent an eventual code skipping
souliane <souliane@mailoo.org>
parents: 1089
diff changeset
388
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
389 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
390 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
391 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
392 item = self.parent.roster.getItem(entity)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
393 if not item or not item.subscriptionTo: # we automatically subscribe to 'to' presence
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
394 log.debug(_('sending automatic "from" subscription request'))
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
395 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
396
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
397 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
398 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
399 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
400
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
401 def subscribedReceived(self, entity):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
402 log.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
403 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
404
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
405 def unsubscribedReceived(self, entity):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
406 log.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
407 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
408
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
409 def subscribeReceived(self, entity):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
410 log.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
411 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
412 if item and item.subscriptionTo:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
413 # We automatically accept subscription if we are already subscribed to contact presence
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
414 log.debug(_('sending automatic subscription acceptance'))
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
415 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
416 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
417 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
418 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
419
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
420 def unsubscribeReceived(self, entity):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
421 log.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
422 item = self.parent.roster.getItem(entity)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
423 if item and item.subscriptionFrom: # we automatically remove contact
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
424 log.debug(_('automatic contact deletion'))
875
19d7d077478a core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents: 819
diff changeset
425 self.host.delContact(entity, self.parent.profile)
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 65
diff changeset
426 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
427
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
428
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
429 class SatDiscoProtocol(disco.DiscoClientProtocol):
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
430 def __init__(self, host):
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
431 disco.DiscoClientProtocol.__init__(self)
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
432
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
433
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
434 class SatFallbackHandler(generic.FallbackHandler):
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
435 def __init__(self, host):
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
436 generic.FallbackHandler.__init__(self)
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
437
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
438 def iqFallback(self, iq):
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
439 if iq.handled is True:
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
440 return
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
441 log.debug(u"iqFallback: xml = [%s]" % (iq.toXml()))
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
442 generic.FallbackHandler.iqFallback(self, iq)
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
443
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
444
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
445 class RegisteringAuthenticator(xmlstream.ConnectAuthenticator):
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
446
1037
6e975c6b0faf core, memory, bridge, plugin misc_register_account: move registerNewAccount to a new plugin:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
447 def __init__(self, host, jabber_host, user_login, user_pass, email, deferred, profile):
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
448 xmlstream.ConnectAuthenticator.__init__(self, jabber_host)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
449 self.host = host
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
450 self.jabber_host = jabber_host
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
451 self.user_login = user_login
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
452 self.user_pass = user_pass
336
953536246d9d core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents: 334
diff changeset
453 self.user_email = email
1037
6e975c6b0faf core, memory, bridge, plugin misc_register_account: move registerNewAccount to a new plugin:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
454 self.deferred = deferred
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 527
diff changeset
455 self.profile = profile
1037
6e975c6b0faf core, memory, bridge, plugin misc_register_account: move registerNewAccount to a new plugin:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
456 log.debug(_("Registration asked for %(user)s@%(host)s") % {'user': user_login, 'host': jabber_host})
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
457
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
458 def connectionMade(self):
1037
6e975c6b0faf core, memory, bridge, plugin misc_register_account: move registerNewAccount to a new plugin:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
459 log.debug(_("Connection made with %s" % self.jabber_host))
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
460 self.xmlstream.namespace = "jabber:client"
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
461 self.xmlstream.sendHeader()
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
462
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
463 iq = compat.IQ(self.xmlstream, 'set')
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
464 iq["to"] = self.jabber_host
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
465 query = iq.addElement(('jabber:iq:register', 'query'))
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
466 _user = query.addElement('username')
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
467 _user.addContent(self.user_login)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
468 _pass = query.addElement('password')
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
469 _pass.addContent(self.user_pass)
336
953536246d9d core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents: 334
diff changeset
470 if self.user_email:
953536246d9d core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents: 334
diff changeset
471 _email = query.addElement('email')
953536246d9d core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents: 334
diff changeset
472 _email.addContent(self.user_email)
1037
6e975c6b0faf core, memory, bridge, plugin misc_register_account: move registerNewAccount to a new plugin:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
473 d = iq.send(self.jabber_host).addCallbacks(self.registrationAnswer, self.registrationFailure)
6e975c6b0faf core, memory, bridge, plugin misc_register_account: move registerNewAccount to a new plugin:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
474 d.chainDeferred(self.deferred)
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
475
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
476 def registrationAnswer(self, answer):
1037
6e975c6b0faf core, memory, bridge, plugin misc_register_account: move registerNewAccount to a new plugin:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
477 log.debug(_("Registration answer: %s") % answer.toXml())
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
478 self.xmlstream.sendFooter()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
479
30
d6b613764dd7 new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents: 25
diff changeset
480 def registrationFailure(self, failure):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
481 log.info(_("Registration failure: %s") % str(failure.value))
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
482 self.xmlstream.sendFooter()
1037
6e975c6b0faf core, memory, bridge, plugin misc_register_account: move registerNewAccount to a new plugin:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
483 raise failure.value
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
484
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
485
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
486 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
487
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
488 def getDiscoInfo(self, requestor, target, node):
461
4e361d295bca core: typo
Goffi <goffi@goffi.org>
parents: 459
diff changeset
489 #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
490 # 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
491 # 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
492 # 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
493 # 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
494 return generic.VersionHandler.getDiscoInfo(self, requestor, target, None)
666
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
495
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
496 class SatIdentityHandler(XMPPHandler):
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
497 """ Manage disco Identity of SàT. Currently, we use "client/pc/Salut à Toi", but as
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
498 SàT is multi-frontends and can be used on mobile devices, as a bot, with a web frontend,
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
499 etc, we should implement a way to dynamically update identities through the bridge """
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
500 #TODO: dynamic identity update (see docstring). Note that a XMPP entity can have several identities
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
501 implements(iwokkel.IDisco)
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
502
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
503 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
923
e77948faaef3 core: removed default_config:
Goffi <goffi@goffi.org>
parents: 875
diff changeset
504 return [disco.DiscoIdentity(u"client", u"pc", C.APP_NAME)]
666
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
505
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
506 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
507 return []