Mercurial > libervia-backend
annotate src/core/xmpp.py @ 2089:0931b5a6213c
core, quick_frontends: android compatibility hacks:
a couple of hacks have been used so backend can be launched on android using kivy
- config file (sat.conf) is been read on a specific dir, using a detection of Cagou domains in constants.py
- fixed crash when using sys.stdout.isatty in log_config.py
- Q&D fix for logging encoding issue on android
- when android is detected, the path/pattern to load plugins is modified
- SRV is not working at the moment on android. If the platform is detected, the host is used directly with default port. A hosts_dir configuration can be used in [android] section to map a specific ip to a host
- getRepositoryData in tools/utils return constant string on android. Proper repository data need to be copied during package building.
- [quick app] more robust failure handling on asyncConnect error
- [quick chat] default to utf-8 when getlocale doesn't return the actual locale.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 04 Dec 2016 18:16:48 +0100 |
parents | 046449cc2bff |
children | ad88808591ef |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
1 #!/usr/bin/env python2 |
0 | 2 # -*- coding: utf-8 -*- |
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 |
1766 | 5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org) |
0 | 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 | 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 | 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 | 19 |
1053
71d63750963e
core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents:
1037
diff
changeset
|
20 from sat.core.i18n import _ |
923 | 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 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
23 from twisted.words.protocols.jabber.xmlstream import XMPPHandler |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
24 from twisted.words.protocols.jabber import xmlstream |
1573
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
25 from twisted.words.protocols.jabber import error |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
26 from twisted.words.protocols.jabber import jid |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
27 from twisted.python import failure |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
28 from wokkel import client as wokkel_client, disco, xmppim, generic, iwokkel |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
29 from wokkel import delay |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
960
diff
changeset
|
30 from sat.core.log import getLogger |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
960
diff
changeset
|
31 log = getLogger(__name__) |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
487
diff
changeset
|
32 from sat.core import exceptions |
666
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 zope.interface import implements |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
34 import time |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
35 import calendar |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
36 import uuid |
2089
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
37 import sys |
0 | 38 |
333
4c835d614bdb
core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
39 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
40 class SatXMPPClient(wokkel_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
|
41 implements(iwokkel.IDisco) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
42 |
1725
c1be6363bfab
core, plugin misc_account: set XMPP connection max retries to 0 when checking if an external account exists
souliane <souliane@mailoo.org>
parents:
1722
diff
changeset
|
43 def __init__(self, host_app, profile, user_jid, password, host=None, port=C.XMPP_C2S_PORT, max_retries=C.XMPP_MAX_RETRIES): |
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
|
44 # 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
|
45 # If no SRV record is found, the host is directly extracted from the JID. |
2089
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
46 if sys.platform == "android": |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
47 # FIXME: temporary hack as SRV is not working on android |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
48 # TODO: remove this hack and fix SRV |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
49 log.info(u"FIXME: Android hack, ignoring SRV") |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
50 host = user_jid.host |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
51 hosts_map = host_app.memory.getConfig("android", "hosts_dict", {}) |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
52 if host in hosts_map: |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
53 log.info(u"using {host_to_use} for host {host_ori} as requested in config".format( |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
54 host_ori = host, |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
55 host_to_use = hosts_map[host])) |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
56 host = hosts_map[host] |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
57 wokkel_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
|
58 self.factory.clientConnectionLost = self.connectionLost |
1725
c1be6363bfab
core, plugin misc_account: set XMPP connection max retries to 0 when checking if an external account exists
souliane <souliane@mailoo.org>
parents:
1722
diff
changeset
|
59 self.factory.maxRetries = max_retries |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
60 self.__connected = False |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
61 self.profile = profile |
64 | 62 self.host_app = host_app |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
63 self._mess_id_uid = {} # map from message id to uid use in history. Key: (full_jid,message_id) Value: uid |
341 | 64 self.conn_deferred = defer.Deferred() |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1480
diff
changeset
|
65 self._progress_cb = {} # callback called when a progress is requested (key = progress id) |
1622 | 66 self.actions = {} # used to keep track of actions for retrieval (key = action_id) |
341 | 67 |
68 def getConnectionDeferred(self): | |
69 """Return a deferred which fire when the client is connected""" | |
70 return self.conn_deferred | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
71 |
1551
591c32dbfb0b
core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
Goffi <goffi@goffi.org>
parents:
1522
diff
changeset
|
72 def IQ(self, type_=u'set', timeout=None): |
591c32dbfb0b
core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
Goffi <goffi@goffi.org>
parents:
1522
diff
changeset
|
73 """shortcut to create an IQ element managing deferred |
591c32dbfb0b
core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
Goffi <goffi@goffi.org>
parents:
1522
diff
changeset
|
74 |
591c32dbfb0b
core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
Goffi <goffi@goffi.org>
parents:
1522
diff
changeset
|
75 @param type_(unicode): IQ type ('set' or 'get') |
591c32dbfb0b
core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
Goffi <goffi@goffi.org>
parents:
1522
diff
changeset
|
76 @param timeout(None, int): timeout in seconds |
591c32dbfb0b
core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
Goffi <goffi@goffi.org>
parents:
1522
diff
changeset
|
77 """ |
591c32dbfb0b
core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
Goffi <goffi@goffi.org>
parents:
1522
diff
changeset
|
78 iq_elt = xmlstream.IQ(self.xmlstream, type_) |
591c32dbfb0b
core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
Goffi <goffi@goffi.org>
parents:
1522
diff
changeset
|
79 iq_elt.timeout = timeout |
591c32dbfb0b
core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
Goffi <goffi@goffi.org>
parents:
1522
diff
changeset
|
80 return iq_elt |
591c32dbfb0b
core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
Goffi <goffi@goffi.org>
parents:
1522
diff
changeset
|
81 |
1573
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
82 def sendError(self, iq_elt, condition): |
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
83 """Send error stanza build from iq_elt |
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
84 |
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
85 @param iq_elt(domish.Element): initial IQ element |
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
86 @param condition(unicode): error condition |
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
87 """ |
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
88 iq_error_elt = error.StanzaError(condition).toResponse(iq_elt) |
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
89 self.xmlstream.send(iq_error_elt) |
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1564
diff
changeset
|
90 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
91 def _authd(self, xmlstream): |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
92 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
|
93 return |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
94 wokkel_client.XMPPClient._authd(self, xmlstream) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
95 self.__connected = True |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
960
diff
changeset
|
96 log.info(_("********** [%s] CONNECTED **********") % self.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
97 self.streamInitialized() |
1435
7590bbf44eed
bridge, quick_frontend: the JID that is assigned by the server can differ from the one we asked for (resource)
souliane <souliane@mailoo.org>
parents:
1434
diff
changeset
|
98 self.host_app.bridge.connected(self.profile, unicode(self.jid)) # we send the signal to the clients |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
99 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
100 def streamInitialized(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
101 """Called after _authd""" |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
960
diff
changeset
|
102 log.debug(_("XML stream is initialized")) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
103 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
|
104 self.keep_alife.start(C.XMPP_KEEP_ALIFE) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
105 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
106 self.disco = SatDiscoProtocol(self) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
107 self.disco.setHandlerParent(self) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
108 self.discoHandler = disco.DiscoHandler() |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
109 self.discoHandler.setHandlerParent(self) |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
934
diff
changeset
|
110 disco_d = defer.succeed(None) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
111 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
934
diff
changeset
|
112 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
|
113 return |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
114 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
934
diff
changeset
|
115 def finish_connection(dummy): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
934
diff
changeset
|
116 self.roster.requestRoster() |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
934
diff
changeset
|
117 self.presence.available() |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
934
diff
changeset
|
118 self.conn_deferred.callback(None) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
119 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
934
diff
changeset
|
120 disco_d.addCallback(finish_connection) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
121 |
262
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
122 def initializationFailed(self, reason): |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1398
diff
changeset
|
123 log.error(_(u"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
|
124 self.conn_deferred.errback(reason.value) |
262
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
125 try: |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
126 wokkel_client.XMPPClient.initializationFailed(self, reason) |
262
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
127 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
|
128 # 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
|
129 pass |
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
130 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
131 def isConnected(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
132 return self.__connected |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
133 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
134 def connectionLost(self, connector, unused_reason): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
135 try: |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
136 self.keep_alife.stop() |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
137 except AttributeError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
960
diff
changeset
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 self.__connected = False |
0 | 144 |
145 | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
146 class SatMessageProtocol(xmppim.MessageProtocol): |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
147 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
148 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
149 xmppim.MessageProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
150 self.host = host |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
151 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
152 def onMessage(self, message_elt): |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
153 # TODO: handle threads |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
154 client = self.parent |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
155 if not 'from' in message_elt.attributes: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
156 message_elt['from'] = client.jid.host |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
157 log.debug(_(u"got message from: {from_}").format(from_=message_elt['from'])) |
697
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
158 post_treat = defer.Deferred() # XXX: plugin can add their treatments to this deferred |
663 | 159 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
160 if not self.host.trigger.point("MessageReceived", client, message_elt, post_treat): |
513
8ee9113d307b
core, quick_frontend, primitivus, wixi, bridge: fixed delayed message timestamp:
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
161 return |
663 | 162 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
163 message = {} |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
164 subject = {} |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
165 extra = {} |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
166 data = {"from": jid.JID(message_elt['from']), |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
167 "to": jid.JID(message_elt['to']), |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
168 "uid": message_elt.getAttribute('uid', unicode(uuid.uuid4())), # XXX: uid is not a standard attribute but may be added by plugins |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
169 "message": message, |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
170 "subject": subject, |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
171 "type": message_elt.getAttribute('type', 'normal'), |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
172 "extra": extra} |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
173 |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
174 try: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
175 data['stanza_id'] = message_elt['id'] |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
176 except KeyError: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
177 pass |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
178 else: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
179 client._mess_id_uid[(data['from'], data['stanza_id'])] = data['uid'] |
663 | 180 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
181 # message |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
182 for e in message_elt.elements(C.NS_CLIENT, 'body'): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
183 message[e.getAttribute((C.NS_XML,'lang'),'')] = unicode(e) |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
184 |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
185 # subject |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
186 for e in message_elt.elements(C.NS_CLIENT, 'subject'): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
187 subject[e.getAttribute((C.NS_XML, 'lang'),'')] = unicode(e) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
188 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
189 # delay and timestamp |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
190 try: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
191 delay_elt = message_elt.elements(delay.NS_DELAY, 'delay').next() |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
192 except StopIteration: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
193 data['timestamp'] = time.time() |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
194 else: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
195 parsed_delay = delay.Delay.fromElement(delay_elt) |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
196 data['timestamp'] = calendar.timegm(parsed_delay.stamp.utctimetuple()) |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
197 data['received_timestamp'] = unicode(time.time()) |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
198 if parsed_delay.sender: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
199 data['delay_sender'] = parsed_delay.sender.full() |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
200 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
201 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
202 post_treat.addCallback(self.skipEmptyMessage) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
203 post_treat.addCallback(self.addToHistory, client) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
204 post_treat.addErrback(self.treatmentsEb) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
205 post_treat.addCallback(self.bridgeSignal, client, data) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
206 post_treat.addErrback(self.cancelErrorTrap) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
207 post_treat.callback(data) |
663 | 208 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
209 def skipEmptyMessage(self, data): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
210 if not data['message'] and not data['extra'] and not data['subject']: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
211 raise failure.Failure(exceptions.CancelError("Cancelled empty message")) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
212 return data |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
213 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
214 def addToHistory(self, data, client): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
215 return self.host.memory.addToHistory(client, data) |
1053
71d63750963e
core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents:
1037
diff
changeset
|
216 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
217 def treatmentsEb(self, failure_): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
218 failure_.trap(exceptions.SkipHistory) |
663 | 219 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
220 def bridgeSignal(self, dummy, client, data): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
221 try: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
222 data['extra']['received_timestamp'] = data['received_timestamp'] |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
223 data['extra']['delay_sender'] = data['delay_sender'] |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
224 except KeyError: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
225 pass |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
226 if data is not None: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
227 self.host.bridge.messageNew(data['uid'], data['timestamp'], data['from'].full(), data['to'].full(), data['message'], data['subject'], data['type'], data['extra'], profile=client.profile) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
228 return data |
1053
71d63750963e
core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents:
1037
diff
changeset
|
229 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
230 def cancelErrorTrap(self, failure_): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
231 """A message sending can be cancelled by a plugin treatment""" |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
232 failure_.trap(exceptions.CancelError) |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
611
diff
changeset
|
233 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
234 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
235 class SatRosterProtocol(xmppim.RosterClientProtocol): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
236 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
237 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
238 xmppim.RosterClientProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
239 self.host = host |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
240 self.got_roster = defer.Deferred() # called when roster is received and ready |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
241 #XXX: the two following dicts keep a local copy of the roster |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
242 self._groups = {} # map from groups to jids: key=group value=set of jids |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
243 self._jids = None # map from jids to RosterItem: key=jid value=RosterItem |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
244 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
245 def rosterCb(self, roster): |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
246 assert roster is not None # FIXME: must be managed with roster versioning |
1427
1e833970b7f0
core (xmpp): update the cache for a contact group when a contact is removed from it
souliane <souliane@mailoo.org>
parents:
1426
diff
changeset
|
247 self._groups.clear() |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
248 self._jids = roster |
1398
f8ecce11a0bc
core (xmmp): keep the roster groups cache synchronised + fixes a log.warning
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
249 for item in roster.itervalues(): |
f8ecce11a0bc
core (xmmp): keep the roster groups cache synchronised + fixes a log.warning
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
250 if not item.subscriptionTo and not item.subscriptionFrom and not item.ask: |
f8ecce11a0bc
core (xmmp): keep the roster groups cache synchronised + fixes a log.warning
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
251 #XXX: current behaviour: we don't want contact in our roster list |
f8ecce11a0bc
core (xmmp): keep the roster groups cache synchronised + fixes a log.warning
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
252 # if there is no presence subscription |
f8ecce11a0bc
core (xmmp): keep the roster groups cache synchronised + fixes a log.warning
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
253 # may change in the future |
1431
70abe871eac3
core (xmpp): added log message when a an entity without presence subscription is removed from roster
Goffi <goffi@goffi.org>
parents:
1427
diff
changeset
|
254 log.info(u"Removing contact {} from roster because there is no presence subscription".format(item.jid)) |
1426
614145ef6e60
core (xmpp): RosterItem.jid is deprecated in Wokkel 0.7.1, use RosterItem.entity instead
souliane <souliane@mailoo.org>
parents:
1417
diff
changeset
|
255 self.removeItem(item.entity) # FIXME: to be checked |
1398
f8ecce11a0bc
core (xmmp): keep the roster groups cache synchronised + fixes a log.warning
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
256 else: |
f8ecce11a0bc
core (xmmp): keep the roster groups cache synchronised + fixes a log.warning
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
257 self._registerItem(item) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
258 |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
259 def _registerItem(self, item): |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
260 """Register item in local cache |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
261 |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
262 item must be already registered in self._jids before this method is called |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
263 @param item (RosterIem): item added |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
264 """ |
1426
614145ef6e60
core (xmpp): RosterItem.jid is deprecated in Wokkel 0.7.1, use RosterItem.entity instead
souliane <souliane@mailoo.org>
parents:
1417
diff
changeset
|
265 log.debug(u"registering item: {}".format(item.entity.full())) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
266 if item.entity.resource: |
1299
3360074a2f00
core: fixed some logging calls without unicode strings, and use of print
Goffi <goffi@goffi.org>
parents:
1262
diff
changeset
|
267 log.warning(u"Received a roster item with a resource, this is not common but not restricted by RFC 6121, this case may be not well tested.") |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
268 if not item.subscriptionTo: |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
269 if not item.subscriptionFrom: |
1426
614145ef6e60
core (xmpp): RosterItem.jid is deprecated in Wokkel 0.7.1, use RosterItem.entity instead
souliane <souliane@mailoo.org>
parents:
1417
diff
changeset
|
270 log.info(_(u"There's no subscription between you and [{}]!").format(item.entity.full())) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
271 else: |
1426
614145ef6e60
core (xmpp): RosterItem.jid is deprecated in Wokkel 0.7.1, use RosterItem.entity instead
souliane <souliane@mailoo.org>
parents:
1417
diff
changeset
|
272 log.info(_(u"You are not subscribed to [{}]!").format(item.entity.full())) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
273 if not item.subscriptionFrom: |
1426
614145ef6e60
core (xmpp): RosterItem.jid is deprecated in Wokkel 0.7.1, use RosterItem.entity instead
souliane <souliane@mailoo.org>
parents:
1417
diff
changeset
|
274 log.info(_(u"[{}] is not subscribed to you!").format(item.entity.full())) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
275 |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
276 for group in item.groups: |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
277 self._groups.setdefault(group, set()).add(item.entity) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
278 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
279 def requestRoster(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
280 """ ask the server for Roster list """ |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
960
diff
changeset
|
281 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
|
282 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
|
283 d.chainDeferred(self.got_roster) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
284 |
875
19d7d077478a
core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents:
819
diff
changeset
|
285 def removeItem(self, to_jid): |
19d7d077478a
core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents:
819
diff
changeset
|
286 """Remove a contact from roster list |
19d7d077478a
core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents:
819
diff
changeset
|
287 @param to_jid: a JID instance |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
288 @return: Deferred |
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
|
289 """ |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
290 return xmppim.RosterClientProtocol.removeItem(self, to_jid) |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
291 |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
292 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
|
293 """Return dictionary of attributes as used in bridge from a RosterItem |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
294 |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
295 @param item: RosterItem |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
296 @return: dictionary of attributes |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
297 """ |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
487
diff
changeset
|
298 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
|
299 'from': unicode(item.subscriptionFrom), |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
487
diff
changeset
|
300 '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
|
301 } |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
302 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
|
303 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
|
304 return item_attr |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
305 |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
306 def setReceived(self, request): |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
307 #TODO: implement roster versioning (cf RFC 6121 §2.6) |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
308 item = request.item |
1427
1e833970b7f0
core (xmpp): update the cache for a contact group when a contact is removed from it
souliane <souliane@mailoo.org>
parents:
1426
diff
changeset
|
309 try: # update the cache for the groups the contact has been removed from |
1e833970b7f0
core (xmpp): update the cache for a contact group when a contact is removed from it
souliane <souliane@mailoo.org>
parents:
1426
diff
changeset
|
310 left_groups = set(self._jids[item.entity].groups).difference(item.groups) |
1e833970b7f0
core (xmpp): update the cache for a contact group when a contact is removed from it
souliane <souliane@mailoo.org>
parents:
1426
diff
changeset
|
311 for group in left_groups: |
1e833970b7f0
core (xmpp): update the cache for a contact group when a contact is removed from it
souliane <souliane@mailoo.org>
parents:
1426
diff
changeset
|
312 jids_set = self._groups[group] |
1e833970b7f0
core (xmpp): update the cache for a contact group when a contact is removed from it
souliane <souliane@mailoo.org>
parents:
1426
diff
changeset
|
313 jids_set.remove(item.entity) |
1e833970b7f0
core (xmpp): update the cache for a contact group when a contact is removed from it
souliane <souliane@mailoo.org>
parents:
1426
diff
changeset
|
314 if not jids_set: |
1e833970b7f0
core (xmpp): update the cache for a contact group when a contact is removed from it
souliane <souliane@mailoo.org>
parents:
1426
diff
changeset
|
315 del self._groups[group] |
1e833970b7f0
core (xmpp): update the cache for a contact group when a contact is removed from it
souliane <souliane@mailoo.org>
parents:
1426
diff
changeset
|
316 except KeyError: |
1e833970b7f0
core (xmpp): update the cache for a contact group when a contact is removed from it
souliane <souliane@mailoo.org>
parents:
1426
diff
changeset
|
317 pass # no previous item registration (or it's been cleared) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
318 self._jids[item.entity] = item |
1398
f8ecce11a0bc
core (xmmp): keep the roster groups cache synchronised + fixes a log.warning
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
319 self._registerItem(item) |
1426
614145ef6e60
core (xmpp): RosterItem.jid is deprecated in Wokkel 0.7.1, use RosterItem.entity instead
souliane <souliane@mailoo.org>
parents:
1417
diff
changeset
|
320 self.host.bridge.newContact(item.entity.full(), self.getAttributes(item), item.groups, self.parent.profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
321 |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
322 def removeReceived(self, request): |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
323 entity = request.item.entity |
1299
3360074a2f00
core: fixed some logging calls without unicode strings, and use of print
Goffi <goffi@goffi.org>
parents:
1262
diff
changeset
|
324 log.info(u"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
|
325 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
326 # 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
|
327 try: |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
328 item = self._jids.pop(entity) |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
329 except KeyError: |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1398
diff
changeset
|
330 log.error(u"Received a roster remove event for an item not in cache ({})".format(entity)) |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
331 return |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
332 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
|
333 try: |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
334 jids_set = self._groups[group] |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
335 jids_set.remove(entity) |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
336 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
|
337 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
|
338 except KeyError: |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1398
diff
changeset
|
339 log.warning(u"there is no cache for the group [%(group)s] of the removed roster item [%(jid)s]" % |
1398
f8ecce11a0bc
core (xmmp): keep the roster groups cache synchronised + fixes a log.warning
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
340 {"group": group, "jid": entity}) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
341 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
342 # then we send the bridge signal |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
343 self.host.bridge.contactDeleted(entity.full(), self.parent.profile) |
50 | 344 |
305
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
345 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
|
346 """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
|
347 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
|
348 |
1300
ba73798317a7
core: fixed items registration in roster management
Goffi <goffi@goffi.org>
parents:
1299
diff
changeset
|
349 def getItem(self, entity_jid): |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
350 """Return RosterItem for a given jid |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
351 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
352 @param entity_jid(jid.JID): jid of the contact |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
353 @return(RosterItem, None): RosterItem instance |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
354 None if contact is not in cache |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
355 """ |
1300
ba73798317a7
core: fixed items registration in roster management
Goffi <goffi@goffi.org>
parents:
1299
diff
changeset
|
356 return self._jids.get(entity_jid, None) |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
357 |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
358 def getJids(self): |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
359 """Return all jids of the roster""" |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
466
diff
changeset
|
360 return self._jids.keys() |
487 | 361 |
362 def isJidInRoster(self, entity_jid): | |
363 """Return True if jid is in roster""" | |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
364 return entity_jid in self._jids |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
365 |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
366 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
|
367 """Return all items of the roster""" |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
466
diff
changeset
|
368 return self._jids.values() |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
487
diff
changeset
|
369 |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
487
diff
changeset
|
370 def getJidsFromGroup(self, group): |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
487
diff
changeset
|
371 try: |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
487
diff
changeset
|
372 return self._groups[group] |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
487
diff
changeset
|
373 except KeyError: |
1300
ba73798317a7
core: fixed items registration in roster management
Goffi <goffi@goffi.org>
parents:
1299
diff
changeset
|
374 raise exceptions.UnknownGroupError(group) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
375 |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
376 def getJidsSet(self, type_, groups=None): |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
377 """Helper method to get a set of jids |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
378 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
379 @param type_(unicode): one of: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
380 C.ALL: get all jids from roster |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
381 C.GROUP: get jids from groups (listed in "groups") |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
382 @groups(list[unicode]): list of groups used if type_==C.GROUP |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
383 @return (set(jid.JID)): set of selected jids |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
384 """ |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
385 if type_ == C.ALL and groups is not None: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
386 raise ValueError('groups must not be set for {} type'.format(C.ALL)) |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
387 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
388 if type_ == C.ALL: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
389 return set(self.getJids()) |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
390 elif type_ == C.GROUP: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
391 jids = set() |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
392 for group in groups: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
393 jids.update(self.getJidsFromGroup(group)) |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
394 return jids |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
395 else: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
396 raise ValueError(u'Unexpected type_ {}'.format(type_)) |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1435
diff
changeset
|
397 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
398 def getNick(self, entity_jid): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
399 """Return a nick name for an entity |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
400 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
401 return nick choosed by user if available |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
402 else return user part of entity_jid |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
403 """ |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
404 item = self.getItem(entity_jid) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
405 if item is None: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
406 return entity_jid.user |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
407 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
408 return item.name or entity_jid.user |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
409 |
305
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
410 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
411 class SatPresenceProtocol(xmppim.PresenceClientProtocol): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
412 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
413 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
414 xmppim.PresenceClientProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
415 self.host = host |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
416 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
934
diff
changeset
|
417 def send(self, obj): |
953 | 418 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
|
419 return |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
934
diff
changeset
|
420 super(SatPresenceProtocol, self).send(obj) |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
934
diff
changeset
|
421 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
422 def availableReceived(self, entity, show=None, statuses=None, priority=0): |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1398
diff
changeset
|
423 log.debug(_(u"presence update for [%(entity)s] (available, show=%(show)s statuses=%(statuses)s priority=%(priority)d)") % {'entity': entity, C.PRESENCE_SHOW: show, C.PRESENCE_STATUSES: statuses, C.PRESENCE_PRIORITY: priority}) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
424 |
334
698cbc6ebec8
core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents:
333
diff
changeset
|
425 if not statuses: |
698cbc6ebec8
core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents:
333
diff
changeset
|
426 statuses = {} |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
427 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
428 if None in statuses: # we only want string keys |
1417
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
429 statuses[C.PRESENCE_STATUSES_DEFAULT] = statuses.pop(None) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
430 |
1480
8d61160ee4b8
core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents:
1450
diff
changeset
|
431 if not self.host.trigger.point("presenceReceived", entity, show, priority, statuses, self.parent.profile): |
8d61160ee4b8
core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents:
1450
diff
changeset
|
432 return |
8d61160ee4b8
core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents:
1450
diff
changeset
|
433 |
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
|
434 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
|
435 int(priority), statuses, |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
436 self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
437 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
438 # now it's time to notify frontends |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
439 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
|
440 int(priority), statuses, |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
441 self.parent.profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
442 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
443 def unavailableReceived(self, entity, statuses=None): |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1398
diff
changeset
|
444 log.debug(_(u"presence update for [%(entity)s] (unavailable, statuses=%(statuses)s)") % {'entity': entity, C.PRESENCE_STATUSES: statuses}) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
445 |
333
4c835d614bdb
core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
446 if not statuses: |
4c835d614bdb
core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
447 statuses = {} |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
448 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
449 if None in statuses: # we only want string keys |
1417
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
450 statuses[C.PRESENCE_STATUSES_DEFAULT] = statuses.pop(None) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
451 |
1170
2df6427a5299
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
1167
diff
changeset
|
452 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
|
453 return |
2df6427a5299
plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents:
1167
diff
changeset
|
454 |
1685
43a127b6a4f2
core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents:
1622
diff
changeset
|
455 # now it's time to notify frontends |
43a127b6a4f2
core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents:
1622
diff
changeset
|
456 # if the entity is not known yet in this session or is already unavailable, there is no need to send an unavailable signal |
43a127b6a4f2
core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents:
1622
diff
changeset
|
457 try: |
43a127b6a4f2
core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents:
1622
diff
changeset
|
458 presence = self.host.memory.getEntityDatum(entity, "presence", self.parent.profile) |
1690
772c8edd1057
core: fixed cache check on presence unavailable
Goffi <goffi@goffi.org>
parents:
1685
diff
changeset
|
459 except (KeyError, exceptions.UnknownEntityError): |
1685
43a127b6a4f2
core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents:
1622
diff
changeset
|
460 # the entity has not been seen yet in this session |
43a127b6a4f2
core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents:
1622
diff
changeset
|
461 pass |
43a127b6a4f2
core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents:
1622
diff
changeset
|
462 else: |
43a127b6a4f2
core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents:
1622
diff
changeset
|
463 if presence.show != C.PRESENCE_UNAVAILABLE: |
43a127b6a4f2
core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents:
1622
diff
changeset
|
464 self.host.bridge.presenceUpdate(entity.full(), C.PRESENCE_UNAVAILABLE, 0, statuses, self.parent.profile) |
1480
8d61160ee4b8
core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents:
1450
diff
changeset
|
465 |
1685
43a127b6a4f2
core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents:
1622
diff
changeset
|
466 self.host.memory.setPresenceStatus(entity, C.PRESENCE_UNAVAILABLE, 0, statuses, self.parent.profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
467 |
611 | 468 def available(self, entity=None, show=None, statuses=None, priority=None): |
1434
b06047e1c1fb
primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents:
1431
diff
changeset
|
469 """Set a presence and statuses. |
b06047e1c1fb
primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents:
1431
diff
changeset
|
470 |
b06047e1c1fb
primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents:
1431
diff
changeset
|
471 @param entity (jid.JID): entity |
b06047e1c1fb
primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents:
1431
diff
changeset
|
472 @param show (unicode): value in ('unavailable', '', 'away', 'xa', 'chat', 'dnd') |
b06047e1c1fb
primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents:
1431
diff
changeset
|
473 @param statuses (dict{unicode: unicode}): multilingual statuses with |
b06047e1c1fb
primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents:
1431
diff
changeset
|
474 the entry key beeing a language code on 2 characters or "default". |
b06047e1c1fb
primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents:
1431
diff
changeset
|
475 """ |
611 | 476 if priority is None: |
477 try: | |
478 priority = int(self.host.memory.getParamA("Priority", "Connection", profile_key=self.parent.profile)) | |
479 except ValueError: | |
480 priority = 0 | |
481 | |
734
b26dfac8e46c
core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
482 if statuses is None: |
562
0bb2e0d1c878
core, plugin XEP-0054: avatar upload:
Goffi <goffi@goffi.org>
parents:
549
diff
changeset
|
483 statuses = {} |
734
b26dfac8e46c
core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
484 |
b26dfac8e46c
core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
485 # default for us is None for wokkel |
b26dfac8e46c
core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
486 # so we must temporarily switch to wokkel's convention... |
1417
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
487 if C.PRESENCE_STATUSES_DEFAULT in statuses: |
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
488 statuses[None] = statuses.pop(C.PRESENCE_STATUSES_DEFAULT) |
379
adcc41e4d6ea
core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents:
347
diff
changeset
|
489 |
734
b26dfac8e46c
core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
490 presence_elt = xmppim.AvailablePresence(entity, show, statuses, priority) |
379
adcc41e4d6ea
core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents:
347
diff
changeset
|
491 |
562
0bb2e0d1c878
core, plugin XEP-0054: avatar upload:
Goffi <goffi@goffi.org>
parents:
549
diff
changeset
|
492 # ... before switching back |
0bb2e0d1c878
core, plugin XEP-0054: avatar upload:
Goffi <goffi@goffi.org>
parents:
549
diff
changeset
|
493 if None in statuses: |
1417
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
494 statuses['default'] = statuses.pop(None) |
379
adcc41e4d6ea
core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents:
347
diff
changeset
|
495 |
1167
fe102b4cf275
core (xmpp): fixes SatPresenceProtocol.available to prevent an eventual code skipping
souliane <souliane@mailoo.org>
parents:
1089
diff
changeset
|
496 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
|
497 return |
fe102b4cf275
core (xmpp): fixes SatPresenceProtocol.available to prevent an eventual code skipping
souliane <souliane@mailoo.org>
parents:
1089
diff
changeset
|
498 self.send(presence_elt) |
fe102b4cf275
core (xmpp): fixes SatPresenceProtocol.available to prevent an eventual code skipping
souliane <souliane@mailoo.org>
parents:
1089
diff
changeset
|
499 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
500 @defer.inlineCallbacks |
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
|
501 def subscribed(self, entity): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
502 yield self.parent.roster.got_roster |
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
|
503 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
|
504 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
|
505 item = self.parent.roster.getItem(entity) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
506 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
|
507 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
|
508 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
|
509 |
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
|
510 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
|
511 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
|
512 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
|
513 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
514 def subscribedReceived(self, entity): |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1398
diff
changeset
|
515 log.debug(_(u"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
|
516 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
|
517 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
518 def unsubscribedReceived(self, entity): |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1398
diff
changeset
|
519 log.debug(_(u"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
|
520 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
|
521 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
522 @defer.inlineCallbacks |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
523 def subscribeReceived(self, entity): |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1398
diff
changeset
|
524 log.debug(_(u"subscription request from [%s]") % entity.userhost()) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
525 yield self.parent.roster.got_roster |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
526 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
|
527 if item and item.subscriptionTo: |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
528 # 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
|
529 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
|
530 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
|
531 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
|
532 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
|
533 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
|
534 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
535 @defer.inlineCallbacks |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
536 def unsubscribeReceived(self, entity): |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1398
diff
changeset
|
537 log.debug(_(u"unsubscription asked for [%s]") % entity.userhost()) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
538 yield self.parent.roster.got_roster |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
539 item = self.parent.roster.getItem(entity) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
540 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
|
541 log.debug(_('automatic contact deletion')) |
875
19d7d077478a
core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents:
819
diff
changeset
|
542 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
|
543 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
|
544 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
545 |
14 | 546 class SatDiscoProtocol(disco.DiscoClientProtocol): |
547 def __init__(self, host): | |
548 disco.DiscoClientProtocol.__init__(self) | |
549 | |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
550 |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
551 class SatFallbackHandler(generic.FallbackHandler): |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
552 def __init__(self, host): |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
553 generic.FallbackHandler.__init__(self) |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
554 |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
555 def iqFallback(self, iq): |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
556 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
|
557 return |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
960
diff
changeset
|
558 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
|
559 generic.FallbackHandler.iqFallback(self, iq) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
560 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
561 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
562 class RegisteringAuthenticator(xmlstream.ConnectAuthenticator): |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
563 |
1037
6e975c6b0faf
core, memory, bridge, plugin misc_register_account: move registerNewAccount to a new plugin:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
564 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
|
565 xmlstream.ConnectAuthenticator.__init__(self, jabber_host) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
566 self.host = host |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
567 self.jabber_host = jabber_host |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
568 self.user_login = user_login |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
569 self.user_pass = user_pass |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
570 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
|
571 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
|
572 self.profile = profile |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1398
diff
changeset
|
573 log.debug(_(u"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
|
574 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
575 def connectionMade(self): |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1398
diff
changeset
|
576 log.debug(_(u"Connection made with %s" % self.jabber_host)) |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
577 self.xmlstream.namespace = C.NS_CLIENT |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
578 self.xmlstream.sendHeader() |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
579 |
1551
591c32dbfb0b
core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
Goffi <goffi@goffi.org>
parents:
1522
diff
changeset
|
580 iq = xmlstream.IQ(self.xmlstream, 'set') |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
581 iq["to"] = self.jabber_host |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
582 query = iq.addElement(('jabber:iq:register', 'query')) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
583 _user = query.addElement('username') |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
584 _user.addContent(self.user_login) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
585 _pass = query.addElement('password') |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
586 _pass.addContent(self.user_pass) |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
587 if self.user_email: |
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
588 _email = query.addElement('email') |
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
589 _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
|
590 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
|
591 d.chainDeferred(self.deferred) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
592 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
593 def registrationAnswer(self, answer): |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1398
diff
changeset
|
594 log.debug(_(u"Registration answer: %s") % answer.toXml()) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
595 self.xmlstream.sendFooter() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
596 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
597 def registrationFailure(self, failure_): |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
598 log.info(_("Registration failure: %s") % unicode(failure_.value)) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
599 self.xmlstream.sendFooter() |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
600 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
|
601 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
602 |
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
|
603 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
|
604 |
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
|
605 def getDiscoInfo(self, requestor, target, node): |
461 | 606 #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
|
607 # 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
|
608 # 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
|
609 # 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
|
610 # 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
|
611 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
|
612 |
2a7185b8452c
core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents:
663
diff
changeset
|
613 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
|
614 """ 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
|
615 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
|
616 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
|
617 #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
|
618 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
|
619 |
2a7185b8452c
core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents:
663
diff
changeset
|
620 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
923 | 621 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
|
622 |
2a7185b8452c
core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents:
663
diff
changeset
|
623 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
|
624 return [] |