annotate src/core/xmpp.py @ 2132:c0577837680a

core: replaced SkipHistory exception by a key in mess_data: SkipHistory was skipping all remaining triggers just to skip history, which is not the intented behaviour. Now history can be skipped by setting mess_data[u'history'] = C.HISTORY_SKIP, this way we won't skip importants triggers. When history is skipped, mess_data[u'extra'][u'history'] will be set to C.HISTORY_SKIP for frontends, so they can inform user that the message is not stored locally.
author Goffi <goffi@goffi.org>
date Sun, 05 Feb 2017 14:55:21 +0100
parents f0bc29dc8157
children cc3a6aea9508
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
goffi@necton2
parents:
diff changeset
2 # -*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
4 # SAT: a jabber client
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1743
diff changeset
5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org)
0
goffi@necton2
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
10 # (at your option) any later version.
0
goffi@necton2
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
15 # GNU Affero General Public License for more details.
0
goffi@necton2
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
0
goffi@necton2
parents:
diff changeset
19
1053
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
20 from sat.core.i18n import _
923
e77948faaef3 core: removed default_config:
Goffi <goffi@goffi.org>
parents: 875
diff changeset
21 from sat.core.constants import Const as C
2109
85f3e12e984d core (memory/cache): file caching handling, first draft:
Goffi <goffi@goffi.org>
parents: 2099
diff changeset
22 from sat.memory import cache
330
608a4a2ba94e Core: created a new core module where xmpp classes are put
Goffi <goffi@goffi.org>
parents: 324
diff changeset
23 from twisted.internet import task, defer
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
24 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
25 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
26 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
27 from twisted.words.protocols.jabber import jid
2130
f0bc29dc8157 added "send" trigger point as the last one before sending, can be used for e2e encryption
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
28 from twisted.words.xish import domish
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
29 from twisted.python import failure
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
30 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
31 from wokkel import delay
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
32 from sat.core.log import getLogger
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
33 log = getLogger(__name__)
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
34 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
35 from zope.interface import implements
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
36 import time
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
37 import calendar
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
38 import uuid
2089
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
39 import sys
0
goffi@necton2
parents:
diff changeset
40
333
4c835d614bdb core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents: 330
diff changeset
41
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
42 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
43 implements(iwokkel.IDisco)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
44
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
45 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
46 # 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
47 # If no SRV record is found, the host is directly extracted from the JID.
2113
9c861d07b5b6 core: added sessionGetInfos bridge method to retrieve various data on current profile session + client.started keep start time
Goffi <goffi@goffi.org>
parents: 2110
diff changeset
48 self.started = time.time()
2089
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
49 if sys.platform == "android":
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
50 # 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
51 # TODO: remove this hack and fix SRV
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
52 log.info(u"FIXME: Android hack, ignoring SRV")
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
53 host = user_jid.host
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
54 hosts_map = host_app.memory.getConfig("android", "hosts_dict", {})
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
55 if host in hosts_map:
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
56 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
57 host_ori = host,
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
58 host_to_use = hosts_map[host]))
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
59 host = hosts_map[host]
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
60 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
61 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
62 self.factory.maxRetries = max_retries
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
63 self.__connected = False
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
64 self.profile = profile
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
65 self.host_app = host_app
2109
85f3e12e984d core (memory/cache): file caching handling, first draft:
Goffi <goffi@goffi.org>
parents: 2099
diff changeset
66 self.cache = cache.Cache(host_app, profile)
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
67 self._mess_id_uid = {} # map from message id to uid use in history. Key: (full_jid,message_id) Value: uid
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
68 self.conn_deferred = defer.Deferred()
1522
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1480
diff changeset
69 self._progress_cb = {} # callback called when a progress is requested (key = progress id)
1622
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1573
diff changeset
70 self.actions = {} # used to keep track of actions for retrieval (key = action_id)
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
71
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
72 def getConnectionDeferred(self):
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
73 """Return a deferred which fire when the client is connected"""
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
74 return self.conn_deferred
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
75
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
76 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
77 """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
78
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 @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
80 @param timeout(None, int): timeout in seconds
2110
2d633b3c923d plugin XEP-0231: Bits of Binary first draft:
Goffi <goffi@goffi.org>
parents: 2109
diff changeset
81 @return((D)domish.Element: result stanza
2d633b3c923d plugin XEP-0231: Bits of Binary first draft:
Goffi <goffi@goffi.org>
parents: 2109
diff changeset
82 errback is called if and error stanza is returned
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
83 """
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
84 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
85 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
86 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
87
1573
6338677f3a89 core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents: 1564
diff changeset
88 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
89 """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
90
6338677f3a89 core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents: 1564
diff changeset
91 @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
92 @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
93 """
6338677f3a89 core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents: 1564
diff changeset
94 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
95 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
96
2130
f0bc29dc8157 added "send" trigger point as the last one before sending, can be used for e2e encryption
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
97 def send(self, obj):
f0bc29dc8157 added "send" trigger point as the last one before sending, can be used for e2e encryption
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
98 # original send method accept string
f0bc29dc8157 added "send" trigger point as the last one before sending, can be used for e2e encryption
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
99 # but we restrict to domish.Element to make trigger treatments easier
f0bc29dc8157 added "send" trigger point as the last one before sending, can be used for e2e encryption
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
100 assert isinstance(obj, domish.Element)
f0bc29dc8157 added "send" trigger point as the last one before sending, can be used for e2e encryption
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
101 # XXX: this trigger is the last one before sending stanza on wire
f0bc29dc8157 added "send" trigger point as the last one before sending, can be used for e2e encryption
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
102 # is it is intended for things like end 2 end encryption.
f0bc29dc8157 added "send" trigger point as the last one before sending, can be used for e2e encryption
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
103 # *DO NOT* cancel (i.e. return False) without very good reason
f0bc29dc8157 added "send" trigger point as the last one before sending, can be used for e2e encryption
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
104 # (out of band transmission for instance).
f0bc29dc8157 added "send" trigger point as the last one before sending, can be used for e2e encryption
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
105 # e2e should have a priority of 0 here, and out of band transmission
f0bc29dc8157 added "send" trigger point as the last one before sending, can be used for e2e encryption
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
106 # a lower priority
f0bc29dc8157 added "send" trigger point as the last one before sending, can be used for e2e encryption
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
107 if not self.host_app.trigger.point("send", self, obj):
f0bc29dc8157 added "send" trigger point as the last one before sending, can be used for e2e encryption
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
108 return
f0bc29dc8157 added "send" trigger point as the last one before sending, can be used for e2e encryption
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
109 return super(SatXMPPClient, self).send(obj)
f0bc29dc8157 added "send" trigger point as the last one before sending, can be used for e2e encryption
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
110
f0bc29dc8157 added "send" trigger point as the last one before sending, can be used for e2e encryption
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
111
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
112 def _authd(self, xmlstream):
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 277
diff changeset
113 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
114 return
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
115 wokkel_client.XMPPClient._authd(self, xmlstream)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
116 self.__connected = True
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
117 log.info(_("********** [%s] CONNECTED **********") % self.profile)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
118 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
119 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
120
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
121 def streamInitialized(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
122 """Called after _authd"""
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
123 log.debug(_("XML stream is initialized"))
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
124 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
125 self.keep_alife.start(C.XMPP_KEEP_ALIFE)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
126
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
127 self.disco = SatDiscoProtocol(self)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
128 self.disco.setHandlerParent(self)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
129 self.discoHandler = disco.DiscoHandler()
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
130 self.discoHandler.setHandlerParent(self)
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
131 disco_d = defer.succeed(None)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
132
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
133 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
134 return
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
135
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
136 def finish_connection(dummy):
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
137 self.roster.requestRoster()
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
138 self.presence.available()
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
139 self.conn_deferred.callback(None)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
140
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
141 disco_d.addCallback(finish_connection)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
142
262
af3d4f11fe43 Added management of connection error
Goffi <goffi@goffi.org>
parents: 260
diff changeset
143 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
144 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
145 self.conn_deferred.errback(reason.value)
262
af3d4f11fe43 Added management of connection error
Goffi <goffi@goffi.org>
parents: 260
diff changeset
146 try:
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
147 wokkel_client.XMPPClient.initializationFailed(self, reason)
262
af3d4f11fe43 Added management of connection error
Goffi <goffi@goffi.org>
parents: 260
diff changeset
148 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
149 # 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
150 pass
af3d4f11fe43 Added management of connection error
Goffi <goffi@goffi.org>
parents: 260
diff changeset
151
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
152 def isConnected(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
153 return self.__connected
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
154
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
155 def connectionLost(self, connector, unused_reason):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
156 try:
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
157 self.keep_alife.stop()
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
158 except AttributeError:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
159 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
160 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
161 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
162 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
163 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
164 self.__connected = False
0
goffi@necton2
parents:
diff changeset
165
goffi@necton2
parents:
diff changeset
166
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
167 class SatMessageProtocol(xmppim.MessageProtocol):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
168
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
169 def __init__(self, host):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
170 xmppim.MessageProtocol.__init__(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
171 self.host = host
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
172
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
173 @staticmethod
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
174 def parseMessage(message_elt, client=None):
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
175 """parse a message XML and return message_data
663
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
176
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
177 @param message_elt(domish.Element): raw <message> xml
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
178 @param client(SatXMPPClient, None): client to map message id to uid
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
179 if None, mapping will not be done
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
180 @return(dict): message data
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
181 """
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
182 message = {}
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
183 subject = {}
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
184 extra = {}
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
185 data = {"from": jid.JID(message_elt['from']),
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
186 "to": jid.JID(message_elt['to']),
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
187 "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
188 "message": message,
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
189 "subject": subject,
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
190 "type": message_elt.getAttribute('type', 'normal'),
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
191 "extra": extra}
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
192
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
193 if client is not None:
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
194 try:
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
195 data['stanza_id'] = message_elt['id']
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
196 except KeyError:
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
197 pass
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
198 else:
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
199 client._mess_id_uid[(data['from'], data['stanza_id'])] = data['uid']
663
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
200
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
201 # message
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
202 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
203 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
204
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
205 # subject
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
206 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
207 subject[e.getAttribute((C.NS_XML, 'lang'),'')] = unicode(e)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
208
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
209 # delay and timestamp
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
210 try:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
211 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
212 except StopIteration:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
213 data['timestamp'] = time.time()
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
214 else:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
215 parsed_delay = delay.Delay.fromElement(delay_elt)
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
216 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
217 data['received_timestamp'] = unicode(time.time())
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
218 if parsed_delay.sender:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
219 data['delay_sender'] = parsed_delay.sender.full()
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
220 return data
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
221
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
222 def onMessage(self, message_elt):
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
223 # TODO: handle threads
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
224 client = self.parent
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
225 if not 'from' in message_elt.attributes:
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
226 message_elt['from'] = client.jid.host
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
227 log.debug(_(u"got message from: {from_}").format(from_=message_elt['from']))
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
228 post_treat = defer.Deferred() # XXX: plugin can add their treatments to this deferred
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
229
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
230 if not self.host.trigger.point("MessageReceived", client, message_elt, post_treat):
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
231 return
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
232
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
233 data = self.parseMessage(message_elt, client)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
234
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
235 post_treat.addCallback(self.skipEmptyMessage)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
236 post_treat.addCallback(self.addToHistory, client)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
237 post_treat.addCallback(self.bridgeSignal, client, data)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
238 post_treat.addErrback(self.cancelErrorTrap)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
239 post_treat.callback(data)
663
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
240
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
241 def skipEmptyMessage(self, data):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
242 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
243 raise failure.Failure(exceptions.CancelError("Cancelled empty message"))
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
244 return data
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
245
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
246 def addToHistory(self, data, client):
2132
c0577837680a core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents: 2130
diff changeset
247 if data.pop(u'history', None) == C.HISTORY_SKIP:
c0577837680a core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents: 2130
diff changeset
248 log.info(u'history is skipped as requested')
c0577837680a core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents: 2130
diff changeset
249 data[u'extra'][u'history'] = C.HISTORY_SKIP
c0577837680a core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents: 2130
diff changeset
250 else:
c0577837680a core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents: 2130
diff changeset
251 return self.host.memory.addToHistory(client, data)
663
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
252
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
253 def bridgeSignal(self, dummy, client, data):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
254 try:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
255 data['extra']['received_timestamp'] = data['received_timestamp']
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
256 data['extra']['delay_sender'] = data['delay_sender']
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
257 except KeyError:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
258 pass
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
259 if data is not None:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
260 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
261 return data
1053
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
262
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
263 def cancelErrorTrap(self, failure_):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
264 """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
265 failure_.trap(exceptions.CancelError)
636
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents: 611
diff changeset
266
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
267
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
268 class SatRosterProtocol(xmppim.RosterClientProtocol):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
269
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
270 def __init__(self, host):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
271 xmppim.RosterClientProtocol.__init__(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
272 self.host = host
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
273 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
274 #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
275 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
276 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
277
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
278 def rosterCb(self, roster):
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
279 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
280 self._groups.clear()
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
281 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
282 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
283 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
284 #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
285 # 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
286 # 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
287 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
288 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
289 else:
f8ecce11a0bc core (xmmp): keep the roster groups cache synchronised + fixes a log.warning
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
290 self._registerItem(item)
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
291
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
292 def _registerItem(self, item):
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
293 """Register item in local cache
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
294
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
295 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
296 @param item (RosterIem): item added
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
297 """
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
298 log.debug(u"registering item: {}".format(item.entity.full()))
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
299 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
300 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
301 if not item.subscriptionTo:
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
302 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
303 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
304 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
305 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
306 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
307 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
308
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
309 for group in item.groups:
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
310 self._groups.setdefault(group, set()).add(item.entity)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
311
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
312 def requestRoster(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
313 """ ask the server for Roster list """
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
314 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
315 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
316 d.chainDeferred(self.got_roster)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
317
875
19d7d077478a core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents: 819
diff changeset
318 def removeItem(self, to_jid):
19d7d077478a core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents: 819
diff changeset
319 """Remove a contact from roster list
19d7d077478a core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents: 819
diff changeset
320 @param to_jid: a JID instance
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
321 @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
322 """
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
323 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
324
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
325 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
326 """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
327
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
328 @param item: RosterItem
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
329 @return: dictionary of attributes
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
330 """
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
331 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
332 'from': unicode(item.subscriptionFrom),
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
333 '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
334 }
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
335 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
336 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
337 return item_attr
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
338
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
339 def setReceived(self, request):
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
340 #TODO: implement roster versioning (cf RFC 6121 §2.6)
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
341 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
342 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
343 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
344 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
345 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
346 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
347 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
348 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
349 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
350 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
351 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
352 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
353 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
354
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
355 def removeReceived(self, request):
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
356 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
357 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
358
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
359 # 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
360 try:
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
361 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
362 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
363 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
364 return
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
365 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
366 try:
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
367 jids_set = self._groups[group]
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
368 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
369 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
370 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
371 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
372 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
373 {"group": group, "jid": entity})
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
374
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
375 # then we send the bridge signal
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
376 self.host.bridge.contactDeleted(entity.full(), self.parent.profile)
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
377
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
378 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
379 """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
380 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
381
1300
ba73798317a7 core: fixed items registration in roster management
Goffi <goffi@goffi.org>
parents: 1299
diff changeset
382 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
383 """Return RosterItem for a given jid
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
384
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
385 @param entity_jid(jid.JID): jid of the contact
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
386 @return(RosterItem, None): RosterItem instance
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
387 None if contact is not in cache
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
388 """
1300
ba73798317a7 core: fixed items registration in roster management
Goffi <goffi@goffi.org>
parents: 1299
diff changeset
389 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
390
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
391 def getJids(self):
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
392 """Return all jids of the roster"""
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 466
diff changeset
393 return self._jids.keys()
487
e789917fb59d core: added isJidInRoster method
Goffi <goffi@goffi.org>
parents: 484
diff changeset
394
e789917fb59d core: added isJidInRoster method
Goffi <goffi@goffi.org>
parents: 484
diff changeset
395 def isJidInRoster(self, entity_jid):
e789917fb59d core: added isJidInRoster method
Goffi <goffi@goffi.org>
parents: 484
diff changeset
396 """Return True if jid is in roster"""
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
397 return entity_jid in self._jids
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
398
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
399 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
400 """Return all items of the roster"""
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 466
diff changeset
401 return self._jids.values()
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
402
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
403 def getJidsFromGroup(self, group):
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
404 try:
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
405 return self._groups[group]
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
406 except KeyError:
1300
ba73798317a7 core: fixed items registration in roster management
Goffi <goffi@goffi.org>
parents: 1299
diff changeset
407 raise exceptions.UnknownGroupError(group)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
408
1450
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1435
diff changeset
409 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
410 """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
411
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1435
diff changeset
412 @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
413 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
414 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
415 @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
416 @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
417 """
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1435
diff changeset
418 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
419 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
420
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1435
diff changeset
421 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
422 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
423 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
424 jids = set()
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1435
diff changeset
425 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
426 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
427 return jids
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1435
diff changeset
428 else:
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1435
diff changeset
429 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
430
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
431 def getNick(self, entity_jid):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
432 """Return a nick name for an entity
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
433
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
434 return nick choosed by user if available
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
435 else return user part of entity_jid
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
436 """
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
437 item = self.getItem(entity_jid)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
438 if item is None:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
439 return entity_jid.user
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
440 else:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
441 return item.name or entity_jid.user
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
442
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
443
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
444 class SatPresenceProtocol(xmppim.PresenceClientProtocol):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
445
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
446 def __init__(self, host):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
447 xmppim.PresenceClientProtocol.__init__(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
448 self.host = host
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
449
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
450 def send(self, obj):
953
4a577b170809 plugin xep-0115: caps optimisation
Goffi <goffi@goffi.org>
parents: 947
diff changeset
451 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
452 return
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
453 super(SatPresenceProtocol, self).send(obj)
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
454
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
455 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
456 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
457
334
698cbc6ebec8 core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents: 333
diff changeset
458 if not statuses:
698cbc6ebec8 core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents: 333
diff changeset
459 statuses = {}
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
460
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
461 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
462 statuses[C.PRESENCE_STATUSES_DEFAULT] = statuses.pop(None)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
463
1480
8d61160ee4b8 core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents: 1450
diff changeset
464 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
465 return
8d61160ee4b8 core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents: 1450
diff changeset
466
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
467 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
468 int(priority), statuses,
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
469 self.parent.profile)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
470
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
471 # now it's time to notify frontends
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
472 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
473 int(priority), statuses,
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
474 self.parent.profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
475
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
476 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
477 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
478
333
4c835d614bdb core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents: 330
diff changeset
479 if not statuses:
4c835d614bdb core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents: 330
diff changeset
480 statuses = {}
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
481
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
482 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
483 statuses[C.PRESENCE_STATUSES_DEFAULT] = statuses.pop(None)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
484
1170
2df6427a5299 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 1167
diff changeset
485 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
486 return
2df6427a5299 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 1167
diff changeset
487
1685
43a127b6a4f2 core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
488 # 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
489 # 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
490 try:
43a127b6a4f2 core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
491 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
492 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
493 # 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
494 pass
43a127b6a4f2 core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
495 else:
43a127b6a4f2 core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
496 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
497 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
498
1685
43a127b6a4f2 core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
499 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
500
611
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
501 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
502 """Set a presence and statuses.
b06047e1c1fb primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents: 1431
diff changeset
503
b06047e1c1fb primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents: 1431
diff changeset
504 @param entity (jid.JID): entity
b06047e1c1fb primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents: 1431
diff changeset
505 @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
506 @param statuses (dict{unicode: unicode}): multilingual statuses with
b06047e1c1fb primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents: 1431
diff changeset
507 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
508 """
611
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
509 if priority is None:
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
510 try:
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
511 priority = int(self.host.memory.getParamA("Priority", "Connection", profile_key=self.parent.profile))
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
512 except ValueError:
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
513 priority = 0
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
514
734
b26dfac8e46c core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents: 726
diff changeset
515 if statuses is None:
562
0bb2e0d1c878 core, plugin XEP-0054: avatar upload:
Goffi <goffi@goffi.org>
parents: 549
diff changeset
516 statuses = {}
734
b26dfac8e46c core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents: 726
diff changeset
517
b26dfac8e46c core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents: 726
diff changeset
518 # default for us is None for wokkel
b26dfac8e46c core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents: 726
diff changeset
519 # 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
520 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
521 statuses[None] = statuses.pop(C.PRESENCE_STATUSES_DEFAULT)
379
adcc41e4d6ea core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents: 347
diff changeset
522
734
b26dfac8e46c core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents: 726
diff changeset
523 presence_elt = xmppim.AvailablePresence(entity, show, statuses, priority)
379
adcc41e4d6ea core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents: 347
diff changeset
524
562
0bb2e0d1c878 core, plugin XEP-0054: avatar upload:
Goffi <goffi@goffi.org>
parents: 549
diff changeset
525 # ... before switching back
0bb2e0d1c878 core, plugin XEP-0054: avatar upload:
Goffi <goffi@goffi.org>
parents: 549
diff changeset
526 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
527 statuses['default'] = statuses.pop(None)
379
adcc41e4d6ea core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents: 347
diff changeset
528
1167
fe102b4cf275 core (xmpp): fixes SatPresenceProtocol.available to prevent an eventual code skipping
souliane <souliane@mailoo.org>
parents: 1089
diff changeset
529 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
530 return
fe102b4cf275 core (xmpp): fixes SatPresenceProtocol.available to prevent an eventual code skipping
souliane <souliane@mailoo.org>
parents: 1089
diff changeset
531 self.send(presence_elt)
fe102b4cf275 core (xmpp): fixes SatPresenceProtocol.available to prevent an eventual code skipping
souliane <souliane@mailoo.org>
parents: 1089
diff changeset
532
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
533 @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
534 def subscribed(self, entity):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
535 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
536 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
537 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
538 item = self.parent.roster.getItem(entity)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
539 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
540 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
541 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
542
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
543 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
544 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
545 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
546
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
547 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
548 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
549 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
550
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
551 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
552 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
553 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
554
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
555 @defer.inlineCallbacks
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
556 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
557 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
558 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
559 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
560 if item and item.subscriptionTo:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
561 # 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
562 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
563 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
564 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
565 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
566 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
567
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
568 @defer.inlineCallbacks
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
569 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
570 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
571 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
572 item = self.parent.roster.getItem(entity)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
573 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
574 log.debug(_('automatic contact deletion'))
875
19d7d077478a core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents: 819
diff changeset
575 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
576 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
577
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
578
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
579 class SatDiscoProtocol(disco.DiscoClientProtocol):
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
580 def __init__(self, host):
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
581 disco.DiscoClientProtocol.__init__(self)
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
582
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
583
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
584 class SatFallbackHandler(generic.FallbackHandler):
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
585 def __init__(self, host):
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
586 generic.FallbackHandler.__init__(self)
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
587
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
588 def iqFallback(self, iq):
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
589 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
590 return
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
591 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
592 generic.FallbackHandler.iqFallback(self, iq)
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
593
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
594
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
595 class RegisteringAuthenticator(xmlstream.ConnectAuthenticator):
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
596
1037
6e975c6b0faf core, memory, bridge, plugin misc_register_account: move registerNewAccount to a new plugin:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
597 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
598 xmlstream.ConnectAuthenticator.__init__(self, jabber_host)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
599 self.host = host
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
600 self.jabber_host = jabber_host
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
601 self.user_login = user_login
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
602 self.user_pass = user_pass
336
953536246d9d core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents: 334
diff changeset
603 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
604 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
605 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
606 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
607
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
608 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
609 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
610 self.xmlstream.namespace = C.NS_CLIENT
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
611 self.xmlstream.sendHeader()
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
612
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
613 iq = xmlstream.IQ(self.xmlstream, 'set')
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
614 iq["to"] = self.jabber_host
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
615 query = iq.addElement(('jabber:iq:register', 'query'))
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
616 _user = query.addElement('username')
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
617 _user.addContent(self.user_login)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
618 _pass = query.addElement('password')
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
619 _pass.addContent(self.user_pass)
336
953536246d9d core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents: 334
diff changeset
620 if self.user_email:
953536246d9d core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents: 334
diff changeset
621 _email = query.addElement('email')
953536246d9d core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents: 334
diff changeset
622 _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
623 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
624 d.chainDeferred(self.deferred)
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
625
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
626 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
627 log.debug(_(u"Registration answer: %s") % answer.toXml())
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
628 self.xmlstream.sendFooter()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
629
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
630 def registrationFailure(self, failure_):
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
631 log.info(_("Registration failure: %s") % unicode(failure_.value))
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
632 self.xmlstream.sendFooter()
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
633 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
634
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
635
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
636 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
637
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
638 def getDiscoInfo(self, requestor, target, node):
461
4e361d295bca core: typo
Goffi <goffi@goffi.org>
parents: 459
diff changeset
639 #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
640 # 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
641 # 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
642 # 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
643 # 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
644 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
645
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
646 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
647 """ 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
648 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
649 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
650 #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
651 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
652
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
653 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
923
e77948faaef3 core: removed default_config:
Goffi <goffi@goffi.org>
parents: 875
diff changeset
654 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
655
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
656 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
657 return []