annotate sat/core/xmpp.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 93d64ce7a429
children 189e38fb11ff
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
2483
0046283a285d dates update
Goffi <goffi@goffi.org>
parents: 2460
diff changeset
5 # Copyright (C) 2009-2018 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
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
31 from wokkel import component
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
32 from wokkel import delay
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
33 from sat.core.log import getLogger
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
34
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
35 log = getLogger(__name__)
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
36 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
37 from zope.interface import implements
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
38 import time
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
39 import calendar
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
40 import uuid
2089
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
41 import sys
0
goffi@necton2
parents:
diff changeset
42
333
4c835d614bdb core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents: 330
diff changeset
43
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
44 class SatXMPPEntity(object):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
45 """Common code for Client and Component"""
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
46
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
47 def __init__(self, host_app, profile, max_retries):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
48
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
49 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
50 self.factory.maxRetries = max_retries
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
51 # when self._connected is None, we are not connected
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
52 # else, it's a deferred which fire on disconnection
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
53 self._connected = None
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
54 self.profile = profile
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
55 self.host_app = host_app
2109
85f3e12e984d core (memory/cache): file caching handling, first draft:
Goffi <goffi@goffi.org>
parents: 2099
diff changeset
56 self.cache = cache.Cache(host_app, profile)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
57 self._mess_id_uid = {} # map from message id to uid used in history. Key: (full_jid,message_id) Value: uid
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
58 self.conn_deferred = defer.Deferred()
2498
d6de69da3dd4 core (client): component improvments:
Goffi <goffi@goffi.org>
parents: 2497
diff changeset
59 self._progress_cb = {} # callback called when a progress is requested (key = progress id)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
60 self.actions = {} # used to keep track of actions for retrieval (key = action_id)
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
61
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
62 ## initialisation ##
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
63
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
64 @defer.inlineCallbacks
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
65 def _callConnectionTriggers(self):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
66 """Call conneting trigger prepare connected trigger
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
67
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
68 @param plugins(iterable): plugins to use
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
69 @return (list[object, callable]): plugin to trigger tuples with:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
70 - plugin instance
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
71 - profileConnected* triggers (to call after connection)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
72 """
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
73 plugin_conn_cb = []
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
74 for plugin in self._getPluginsList():
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
75 # we check if plugin handle client mode
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
76 if plugin.is_handler:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
77 plugin.getHandler(self).setHandlerParent(self)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
78
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
79 # profileConnecting/profileConnected methods handling
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
80
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
81 # profile connecting is called right now (before actually starting client)
2498
d6de69da3dd4 core (client): component improvments:
Goffi <goffi@goffi.org>
parents: 2497
diff changeset
82 connecting_cb = getattr(plugin, "profileConnecting", None)
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
83 if connecting_cb is not None:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
84 yield connecting_cb(self)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
85
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
86 # profile connected is called after client is ready and roster is got
2498
d6de69da3dd4 core (client): component improvments:
Goffi <goffi@goffi.org>
parents: 2497
diff changeset
87 connected_cb = getattr(plugin, "profileConnected", None)
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
88 if connected_cb is not None:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
89 plugin_conn_cb.append((plugin, connected_cb))
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
90
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
91 defer.returnValue(plugin_conn_cb)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
92
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
93 def _getPluginsList(self):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
94 """Return list of plugin to use
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
95
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
96 need to be implemented by subclasses
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
97 this list is used to call profileConnect* triggers
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
98 @return(iterable[object]): plugins to use
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
99 """
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
100 raise NotImplementedError
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
101
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
102 def _createSubProtocols(self):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
103 return
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
104
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
105 def entityConnected(self):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
106 """Called once connection is done
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
107
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
108 may return a Deferred, to perform initialisation tasks
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
109 """
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
110 return
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
111
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
112 @classmethod
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
113 @defer.inlineCallbacks
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
114 def startConnection(cls, host, profile, max_retries):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
115 """instantiate the entity and start the connection"""
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
116 # FIXME: reconnection doesn't seems to be handled correclty (client is deleted then recreated from scrash
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
117 # most of methods called here should be called once on first connection (e.g. adding subprotocols)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
118 # but client should not be deleted except if session is finished (independently of connection/deconnection
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
119 #
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
120 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
121 port = int(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
122 host.memory.getParamA(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
123 C.FORCE_PORT_PARAM, "Connection", profile_key=profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
124 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
125 )
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
126 except ValueError:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
127 log.debug(_("Can't parse port value, using default value"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
128 port = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
129 None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
130 ) # will use default value 5222 or be retrieved from a DNS SRV record
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
131
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
132 password = yield host.memory.asyncGetParamA(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
133 "Password", "Connection", profile_key=profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
134 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
135 entity = host.profiles[profile] = cls(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
136 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
137 profile,
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
138 jid.JID(host.memory.getParamA("JabberID", "Connection", profile_key=profile)),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
139 password,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
140 host.memory.getParamA(C.FORCE_SERVER_PARAM, "Connection", profile_key=profile)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
141 or None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
142 port,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
143 max_retries,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
144 )
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
145
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
146 entity._createSubProtocols()
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
147
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
148 entity.fallBack = SatFallbackHandler(host)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
149 entity.fallBack.setHandlerParent(entity)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
150
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
151 entity.versionHandler = SatVersionHandler(C.APP_NAME_FULL, host.full_version)
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
152 entity.versionHandler.setHandlerParent(entity)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
153
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
154 entity.identityHandler = SatIdentityHandler()
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
155 entity.identityHandler.setHandlerParent(entity)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
156
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
157 log.debug(_("setting plugins parents"))
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
158
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
159 plugin_conn_cb = yield entity._callConnectionTriggers()
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
160
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
161 entity.startService()
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
162
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
163 yield entity.getConnectionDeferred()
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
164
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
165 yield defer.maybeDeferred(entity.entityConnected)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
166
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
167 # Call profileConnected callback for all plugins, and print error message if any of them fails
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
168 conn_cb_list = []
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
169 for dummy, callback in plugin_conn_cb:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
170 conn_cb_list.append(defer.maybeDeferred(callback, entity))
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
171 list_d = defer.DeferredList(conn_cb_list)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
172
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
173 def logPluginResults(results):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
174 all_succeed = all([success for success, result in results])
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
175 if not all_succeed:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
176 log.error(_(u"Plugins initialisation error"))
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
177 for idx, (success, result) in enumerate(results):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
178 if not success:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
179 log.error(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
180 u"error (plugin %(name)s): %(failure)s"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
181 % {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
182 "name": plugin_conn_cb[idx][0]._info["import_name"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
183 "failure": result,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
184 }
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
185 )
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
186
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
187 yield list_d.addCallback(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
188 logPluginResults
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
189 ) # FIXME: we should have a timeout here, and a way to know if a plugin freeze
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
190 # TODO: mesure launch time of each plugin
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
191
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
192 def getConnectionDeferred(self):
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
193 """Return a deferred which fire when the client is connected"""
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
194 return self.conn_deferred
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
195
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
196 def _disconnectionCb(self, dummy):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
197 self._connected = None
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
198
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
199 def _disconnectionEb(self, failure_):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
200 log.error(_(u"Error while disconnecting: {}".format(failure_)))
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
201
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
202 def _authd(self, xmlstream):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
203 if not self.host_app.trigger.point("XML Initialized", xmlstream, self.profile):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
204 return
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
205 super(SatXMPPEntity, self)._authd(xmlstream)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
206
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
207 # the following Deferred is used to know when we are connected
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
208 # so we need to be set it to None when connection is lost
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
209 self._connected = defer.Deferred()
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
210 self._connected.addCallback(self._cleanConnection)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
211 self._connected.addCallback(self._disconnectionCb)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
212 self._connected.addErrback(self._disconnectionEb)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
213
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
214 log.info(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
215 _(u"********** [{profile}] CONNECTED **********").format(profile=self.profile)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
216 )
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
217 self.streamInitialized()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
218 self.host_app.bridge.connected(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
219 self.profile, unicode(self.jid)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
220 ) # we send the signal to the clients
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
221
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
222 def _finish_connection(self, dummy):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
223 self.conn_deferred.callback(None)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
224
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
225 def streamInitialized(self):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
226 """Called after _authd"""
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
227 log.debug(_(u"XML stream is initialized"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
228 self.keep_alife = task.LoopingCall(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
229 self.xmlstream.send, " "
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
230 ) # Needed to avoid disconnection (specially with openfire)
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
231 self.keep_alife.start(C.XMPP_KEEP_ALIFE)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
232
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
233 self.disco = SatDiscoProtocol(self)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
234 self.disco.setHandlerParent(self)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
235 self.discoHandler = disco.DiscoHandler()
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
236 self.discoHandler.setHandlerParent(self)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
237 disco_d = defer.succeed(None)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
238
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
239 if not self.host_app.trigger.point("Disco handled", disco_d, self.profile):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
240 return
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
241
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
242 disco_d.addCallback(self._finish_connection)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
243
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
244 def initializationFailed(self, reason):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
245 log.error(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
246 _(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
247 u"ERROR: XMPP connection failed for profile '%(profile)s': %(reason)s"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
248 % {"profile": self.profile, "reason": reason}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
249 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
250 )
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
251 self.conn_deferred.errback(reason.value)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
252 try:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
253 super(SatXMPPEntity, self).initializationFailed(reason)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
254 except:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
255 # we already chained an errback, no need to raise an exception
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
256 pass
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
257
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
258 ## connection ##
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
259
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
260 def connectionLost(self, connector, reason):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
261 try:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
262 self.keep_alife.stop()
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
263 except AttributeError:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
264 log.debug(_("No keep_alife"))
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
265 if self._connected is not None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
266 self.host_app.bridge.disconnected(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
267 self.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
268 ) # we send the signal to the clients
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
269 self._connected.callback(None)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
270 self.host_app.purgeEntity(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
271 self.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
272 ) # and we remove references to this client
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
273 log.info(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
274 _(u"********** [{profile}] DISCONNECTED **********").format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
275 profile=self.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
276 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
277 )
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
278 if not self.conn_deferred.called:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
279 # FIXME: real error is not gotten here (e.g. if jid is not know by Prosody,
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
280 # we should have the real error)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
281 self.conn_deferred.errback(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
282 error.StreamError(u"Server unexpectedly closed the connection")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
283 )
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
284
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
285 @defer.inlineCallbacks
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
286 def _cleanConnection(self, dummy):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
287 """method called on disconnection
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
288
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
289 used to call profileDisconnected* triggers
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
290 """
2498
d6de69da3dd4 core (client): component improvments:
Goffi <goffi@goffi.org>
parents: 2497
diff changeset
291 trigger_name = "profileDisconnected"
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
292 for plugin in self._getPluginsList():
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
293 disconnected_cb = getattr(plugin, trigger_name, None)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
294 if disconnected_cb is not None:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
295 yield disconnected_cb(self)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
296
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
297 def isConnected(self):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
298 return self._connected is not None
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
299
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
300 def entityDisconnect(self):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
301 log.info(_(u"Disconnecting..."))
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
302 self.stopService()
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
303 if self._connected is not None:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
304 return self._connected
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
305 else:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
306 return defer.succeed(None)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
307
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
308 ## sending ##
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
309
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
310 def IQ(self, type_=u"set", timeout=60):
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
311 """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
312
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
313 @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
314 @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
315 @return((D)domish.Element: result stanza
2d633b3c923d plugin XEP-0231: Bits of Binary first draft:
Goffi <goffi@goffi.org>
parents: 2109
diff changeset
316 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
317 """
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
318 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
319 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
320 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
321
1573
6338677f3a89 core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents: 1564
diff changeset
322 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
323 """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
324
6338677f3a89 core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents: 1564
diff changeset
325 @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
326 @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
327 """
6338677f3a89 core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents: 1564
diff changeset
328 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
329 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
330
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
331 def generateMessageXML(self, data):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
332 """Generate <message/> stanza from message data
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
333
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
334 @param data(dict): message data
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
335 domish element will be put in data['xml']
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
336 following keys are needed:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
337 - from
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
338 - to
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
339 - uid: can be set to '' if uid attribute is not wanted
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
340 - message
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
341 - type
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
342 - subject
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
343 - extra
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
344 @return (dict) message data
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
345 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
346 data["xml"] = message_elt = domish.Element((None, "message"))
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
347 message_elt["to"] = data["to"].full()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
348 message_elt["from"] = data["from"].full()
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
349 message_elt["type"] = data["type"]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
350 if data["uid"]: # key must be present but can be set to ''
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
351 # by a plugin to avoid id on purpose
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
352 message_elt["id"] = data["uid"]
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
353 for lang, subject in data["subject"].iteritems():
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
354 subject_elt = message_elt.addElement("subject", content=subject)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
355 if lang:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
356 subject_elt[(C.NS_XML, "lang")] = lang
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
357 for lang, message in data["message"].iteritems():
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
358 body_elt = message_elt.addElement("body", content=message)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
359 if lang:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
360 body_elt[(C.NS_XML, "lang")] = lang
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
361 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
362 thread = data["extra"]["thread"]
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
363 except KeyError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
364 if "thread_parent" in data["extra"]:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
365 raise exceptions.InternalError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
366 u"thread_parent found while there is not associated thread"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
367 )
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
368 else:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
369 thread_elt = message_elt.addElement("thread", content=thread)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
370 try:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
371 thread_elt["parent"] = data["extra"]["thread_parent"]
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
372 except KeyError:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
373 pass
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
374 return data
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
375
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
376 def addPostXmlCallbacks(self, post_xml_treatments):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
377 """Used to add class level callbacks at the end of the workflow
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
378
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
379 @param post_xml_treatments(D): the same Deferred as in sendMessage trigger
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
380 """
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
381 raise NotImplementedError
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
382
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
383 def sendMessage(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
384 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
385 to_jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
386 message,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
387 subject=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
388 mess_type="auto",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
389 extra=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
390 uid=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
391 no_trigger=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
392 ):
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
393 """Send a message to an entity
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
394
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
395 @param to_jid(jid.JID): destinee of the message
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
396 @param message(dict): message body, key is the language (use '' when unknown)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
397 @param subject(dict): message subject, key is the language (use '' when unknown)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
398 @param mess_type(str): one of standard message type (cf RFC 6121 §5.2.2) or:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
399 - auto: for automatic type detection
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
400 - info: for information ("info_type" can be specified in extra)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
401 @param extra(dict, None): extra data. Key can be:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
402 - info_type: information type, can be
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
403 TODO
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
404 @param uid(unicode, None): unique id:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
405 should be unique at least in this XMPP session
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
406 if None, an uuid will be generated
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
407 @param no_trigger (bool): if True, sendMessage[suffix] trigger will no be used
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
408 useful when a message need to be sent without any modification
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
409 """
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
410 if subject is None:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
411 subject = {}
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
412 if extra is None:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
413 extra = {}
2460
feaacc462fef core: moved CHAT_* constants from frontends to core constants + uses constants for MESS_TYPE_* in sendMessage
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
414
feaacc462fef core: moved CHAT_* constants from frontends to core constants + uses constants for MESS_TYPE_* in sendMessage
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
415 assert mess_type in C.MESS_TYPE_ALL
feaacc462fef core: moved CHAT_* constants from frontends to core constants + uses constants for MESS_TYPE_* in sendMessage
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
416
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
417 data = { # dict is similar to the one used in client.onMessage
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
418 "from": self.jid,
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
419 "to": to_jid,
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
420 "uid": uid or unicode(uuid.uuid4()),
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
421 "message": message,
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
422 "subject": subject,
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
423 "type": mess_type,
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
424 "extra": extra,
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
425 "timestamp": time.time(),
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
426 }
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
427 pre_xml_treatments = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
428 defer.Deferred()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
429 ) # XXX: plugin can add their pre XML treatments to this deferred
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
430 post_xml_treatments = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
431 defer.Deferred()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
432 ) # XXX: plugin can add their post XML treatments to this deferred
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
433
2460
feaacc462fef core: moved CHAT_* constants from frontends to core constants + uses constants for MESS_TYPE_* in sendMessage
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
434 if data["type"] == C.MESS_TYPE_AUTO:
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
435 # we try to guess the type
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
436 if data["subject"]:
2460
feaacc462fef core: moved CHAT_* constants from frontends to core constants + uses constants for MESS_TYPE_* in sendMessage
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
437 data["type"] = C.MESS_TYPE_NORMAL
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
438 elif not data[
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
439 "to"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
440 ].resource: # if to JID has a resource, the type is not 'groupchat'
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
441 # we may have a groupchat message, we check if the we know this jid
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
442 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
443 entity_type = self.host_app.memory.getEntityData(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
444 data["to"], ["type"], self.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
445 )["type"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
446 # FIXME: should entity_type manage resources ?
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
447 except (exceptions.UnknownEntityError, KeyError):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
448 entity_type = "contact"
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
449
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
450 if entity_type == "chatroom":
2460
feaacc462fef core: moved CHAT_* constants from frontends to core constants + uses constants for MESS_TYPE_* in sendMessage
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
451 data["type"] = C.MESS_TYPE_GROUPCHAT
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
452 else:
2460
feaacc462fef core: moved CHAT_* constants from frontends to core constants + uses constants for MESS_TYPE_* in sendMessage
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
453 data["type"] = C.MESS_TYPE_CHAT
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
454 else:
2460
feaacc462fef core: moved CHAT_* constants from frontends to core constants + uses constants for MESS_TYPE_* in sendMessage
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
455 data["type"] == C.MESS_TYPE_CHAT
feaacc462fef core: moved CHAT_* constants from frontends to core constants + uses constants for MESS_TYPE_* in sendMessage
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
456 data["type"] == C.MESS_TYPE_CHAT if data["subject"] else C.MESS_TYPE_NORMAL
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
457
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
458 # FIXME: send_only is used by libervia's OTR plugin to avoid
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
459 # the triggers from frontend, and no_trigger do the same
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
460 # thing internally, this could be unified
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
461 send_only = data["extra"].get("send_only", False)
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
462
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
463 if not no_trigger and not send_only:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
464 if not self.host_app.trigger.point(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
465 "sendMessage" + self.trigger_suffix,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
466 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
467 data,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
468 pre_xml_treatments,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
469 post_xml_treatments,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
470 ):
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
471 return defer.succeed(None)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
472
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
473 log.debug(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
474 _(u"Sending message (type {type}, to {to})").format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
475 type=data["type"], to=to_jid.full()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
476 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
477 )
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
478
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
479 pre_xml_treatments.addCallback(lambda dummy: self.generateMessageXML(data))
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
480 pre_xml_treatments.chainDeferred(post_xml_treatments)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
481 post_xml_treatments.addCallback(self.sendMessageData)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
482 if send_only:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
483 log.debug(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
484 _(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
485 "Triggers, storage and echo have been inhibited by the 'send_only' parameter"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
486 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
487 )
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
488 else:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
489 self.addPostXmlCallbacks(post_xml_treatments)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
490 post_xml_treatments.addErrback(self._cancelErrorTrap)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
491 post_xml_treatments.addErrback(self.host_app.logErrback)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
492 pre_xml_treatments.callback(data)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
493 return pre_xml_treatments
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
494
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
495 def _cancelErrorTrap(self, failure):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
496 """A message sending can be cancelled by a plugin treatment"""
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
497 failure.trap(exceptions.CancelError)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
498
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
499 def messageAddToHistory(self, data):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
500 """Store message into database (for local history)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
501
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
502 @param data: message data dictionnary
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
503 @param client: profile's client
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
504 """
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
505 if data[u"type"] != C.MESS_TYPE_GROUPCHAT:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
506 # we don't add groupchat message to history, as we get them back
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
507 # and they will be added then
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
508 if data[u"message"] or data[u"subject"]: # we need a message to store
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
509 self.host_app.memory.addToHistory(self, data)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
510 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
511 log.warning(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
512 u"No message found"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
513 ) # empty body should be managed by plugins before this point
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
514 return data
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
515
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
516 def messageSendToBridge(self, data):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
517 """Send message to bridge, so frontends can display it
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
518
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
519 @param data: message data dictionnary
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
520 @param client: profile's client
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
521 """
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
522 if data[u"type"] != C.MESS_TYPE_GROUPCHAT:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
523 # we don't send groupchat message to bridge, as we get them back
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
524 # and they will be added the
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
525 if (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
526 data[u"message"] or data[u"subject"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
527 ): # we need a message to send something
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
528 # We send back the message, so all frontends are aware of it
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
529 self.host_app.bridge.messageNew(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
530 data[u"uid"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
531 data[u"timestamp"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
532 data[u"from"].full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
533 data[u"to"].full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
534 data[u"message"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
535 data[u"subject"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
536 data[u"type"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
537 data[u"extra"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
538 profile=self.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
539 )
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
540 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
541 log.warning(_(u"No message found"))
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
542 return data
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
543
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
544
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
545 class SatXMPPClient(SatXMPPEntity, wokkel_client.XMPPClient):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
546 implements(iwokkel.IDisco)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
547 trigger_suffix = ""
2498
d6de69da3dd4 core (client): component improvments:
Goffi <goffi@goffi.org>
parents: 2497
diff changeset
548 is_component = False
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
549
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
550 def __init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
551 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
552 host_app,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
553 profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
554 user_jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
555 password,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
556 host=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
557 port=C.XMPP_C2S_PORT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
558 max_retries=C.XMPP_MAX_RETRIES,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
559 ):
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
560 # XXX: DNS SRV records are checked when the host is not specified.
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
561 # If no SRV record is found, the host is directly extracted from the JID.
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
562 self.started = time.time()
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
563
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
564 # Currently, we use "client/pc/Salut à Toi", but as
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
565 # SàT is multi-frontends and can be used on mobile devices, as a bot, with a web frontend,
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
566 # etc., we should implement a way to dynamically update identities through the bridge
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
567 self.identities = [disco.DiscoIdentity(u"client", u"pc", C.APP_NAME)]
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
568 if sys.platform == "android":
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
569 # FIXME: temporary hack as SRV is not working on android
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
570 # TODO: remove this hack and fix SRV
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
571 log.info(u"FIXME: Android hack, ignoring SRV")
2596
93d64ce7a429 core (xmpp): fixed "Force server" param on Android
Goffi <goffi@goffi.org>
parents: 2594
diff changeset
572 if host is None:
93d64ce7a429 core (xmpp): fixed "Force server" param on Android
Goffi <goffi@goffi.org>
parents: 2594
diff changeset
573 host = user_jid.host
2594
59ba387c17ea core (xmpp): use "phone" type in identities when backend is started from Android
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
574 # for now we consider Android devices to be always phones
59ba387c17ea core (xmpp): use "phone" type in identities when backend is started from Android
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
575 self.identities = [disco.DiscoIdentity(u"client", u"phone", C.APP_NAME)]
2259
f51315500eb1 core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
576
f51315500eb1 core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
577 hosts_map = host_app.memory.getConfig(None, "hosts_dict", {})
f51315500eb1 core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
578 if host is None and user_jid.host in hosts_map:
f51315500eb1 core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
579 host_data = hosts_map[user_jid.host]
f51315500eb1 core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
580 if isinstance(host_data, basestring):
f51315500eb1 core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
581 host = host_data
f51315500eb1 core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
582 elif isinstance(host_data, dict):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
583 if u"host" in host_data:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
584 host = host_data[u"host"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
585 if u"port" in host_data:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
586 port = host_data[u"port"]
2259
f51315500eb1 core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
587 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
588 log.warning(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
589 _(u"invalid data used for host: {data}").format(data=host_data)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
590 )
2259
f51315500eb1 core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
591 host_data = None
f51315500eb1 core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
592 if host_data is not None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
593 log.info(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
594 u"using {host}:{port} for host {host_ori} as requested in config".format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
595 host_ori=user_jid.host, host=host, port=port
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
596 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
597 )
2259
f51315500eb1 core: added hosts_dict handling in general config:
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
598
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
599 wokkel_client.XMPPClient.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
600 self, user_jid, password, host or None, port or C.XMPP_C2S_PORT
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
601 )
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
602 SatXMPPEntity.__init__(self, host_app, profile, max_retries)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
603
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
604 def _getPluginsList(self):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
605 for p in self.host_app.plugins.itervalues():
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
606 if C.PLUG_MODE_CLIENT in p._info[u"modes"]:
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
607 yield p
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
608
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
609 def _createSubProtocols(self):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
610 self.messageProt = SatMessageProtocol(self.host_app)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
611 self.messageProt.setHandlerParent(self)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
612
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
613 self.roster = SatRosterProtocol(self.host_app)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
614 self.roster.setHandlerParent(self)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
615
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
616 self.presence = SatPresenceProtocol(self.host_app)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
617 self.presence.setHandlerParent(self)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
618
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
619 def entityConnected(self):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
620 # we want to be sure that we got the roster
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
621 return self.roster.got_roster
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
622
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
623 def addPostXmlCallbacks(self, post_xml_treatments):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
624 post_xml_treatments.addCallback(self.messageAddToHistory)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
625 post_xml_treatments.addCallback(self.messageSendToBridge)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
626
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
627 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
628 # 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
629 # 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
630 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
631 # XXX: this trigger is the last one before sending stanza on wire
2509
d485e9416493 core (memory/cache): common cache:
Goffi <goffi@goffi.org>
parents: 2498
diff changeset
632 # it is intended for things like end 2 end encryption.
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
633 # *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
634 # (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
635 # 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
636 # a lower priority
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
637 #  FIXME: trigger not used yet, can be uncommented when e2e full stanza encryption is implemented
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
638 #  if not self.host_app.trigger.point("send", self, obj):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
639 #   return
2136
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
640 super(SatXMPPClient, self).send(obj)
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
641
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
642 def sendMessageData(self, mess_data):
2136
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
643 """Convenient method to send message data to stream
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
644
2136
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
645 This method will send mess_data[u'xml'] to stream, but a trigger is there
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
646 The trigger can't be cancelled, it's a good place for e2e encryption which
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
647 don't handle full stanza encryption
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
648 @param mess_data(dict): message data as constructed by onMessage workflow
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
649 @return (dict): mess_data (so it can be used in a deferred chain)
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
650 """
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
651 # XXX: This is the last trigger before u"send" (last but one globally) for sending message.
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
652 # This is intented for e2e encryption which doesn't do full stanza encryption (e.g. OTR)
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
653 # This trigger point can't cancel the method
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
654 self.host_app.trigger.point("sendMessageData", self, mess_data)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
655 self.send(mess_data[u"xml"])
2136
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
656 return mess_data
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
657
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
658 def feedback(self, to_jid, message):
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
659 """Send message to frontends
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
660
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
661 This message will be an info message, not recorded in history.
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
662 It can be used to give feedback of a command
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
663 @param to_jid(jid.JID): destinee jid
2136
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
664 @param message(unicode): message to send to frontends
cc3a6aea9508 core (client): added feedback and sendMessage methods:
Goffi <goffi@goffi.org>
parents: 2132
diff changeset
665 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
666 self.host_app.bridge.messageNew(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
667 uid=unicode(uuid.uuid4()),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
668 timestamp=time.time(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
669 from_jid=self.jid.full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
670 to_jid=to_jid.full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
671 message={u"": message},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
672 subject={},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
673 mess_type=C.MESS_TYPE_INFO,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
674 extra={},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
675 profile=self.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
676 )
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
677
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
678 def _finish_connection(self, dummy):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
679 self.roster.requestRoster()
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
680 self.presence.available()
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
681 super(SatXMPPClient, self)._finish_connection(dummy)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
682
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
683
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
684 class SatXMPPComponent(SatXMPPEntity, component.Component):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
685 """XMPP component
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
686
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
687 This component are similar but not identical to clients.
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
688 An entry point plugin is launched after component is connected.
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
689 Component need to instantiate MessageProtocol itself
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
690 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
691
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
692 implements(iwokkel.IDisco)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
693 trigger_suffix = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
694 "Component"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
695 ) # used for to distinguish some trigger points set in SatXMPPEntity
2498
d6de69da3dd4 core (client): component improvments:
Goffi <goffi@goffi.org>
parents: 2497
diff changeset
696 is_component = True
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
697 sendHistory = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
698 False
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
699 ) # XXX: set to True from entry plugin to keep messages in history for received messages
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
700
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
701 def __init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
702 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
703 host_app,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
704 profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
705 component_jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
706 password,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
707 host=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
708 port=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
709 max_retries=C.XMPP_MAX_RETRIES,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
710 ):
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
711 self.started = time.time()
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
712 if port is None:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
713 port = C.XMPP_COMPONENT_PORT
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
714
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
715 ## entry point ##
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
716 entry_point = host_app.memory.getEntryPoint(profile)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
717 try:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
718 self.entry_plugin = host_app.plugins[entry_point]
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
719 except KeyError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
720 raise exceptions.NotFound(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
721 _(u"The requested entry point ({entry_point}) is not available").format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
722 entry_point=entry_point
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
723 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
724 )
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
725
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
726 self.identities = [disco.DiscoIdentity(u"component", u"generic", C.APP_NAME)]
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
727 # jid is set automatically on bind by Twisted for Client, but not for Component
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
728 self.jid = component_jid
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
729 if host is None:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
730 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
731 host = component_jid.host.split(u".", 1)[1]
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
732 except IndexError:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
733 raise ValueError(u"Can't guess host from jid, please specify a host")
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
734 # XXX: component.Component expect unicode jid, while Client expect jid.JID.
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
735 # this is not consistent, so we use jid.JID for SatXMPP*
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
736 component.Component.__init__(self, host, port, component_jid.full(), password)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
737 SatXMPPEntity.__init__(self, host_app, profile, max_retries)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
738
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
739 def _buildDependencies(self, current, plugins, required=True):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
740 """build recursively dependencies needed for a plugin
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
741
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
742 this method build list of plugin needed for a component and raises
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
743 errors if they are not available or not allowed for components
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
744 @param current(object): parent plugin to check
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
745 use entry_point for first call
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
746 @param plugins(list): list of validated plugins, will be filled by the method
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
747 give an empty list for first call
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
748 @param required(bool): True if plugin is mandatory
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
749 for recursive calls only, should not be modified by inital caller
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
750 @raise InternalError: one of the plugin is not handling components
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
751 @raise KeyError: one plugin should be present in self.host_app.plugins but it is not
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
752 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
753 if C.PLUG_MODE_COMPONENT not in current._info[u"modes"]:
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
754 if not required:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
755 return
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
756 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
757 log.error(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
758 _(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
759 u"Plugin {current_name} is needed for {entry_name}, but it doesn't handle component mode"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
760 ).format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
761 current_name=current._info[u"import_name"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
762 entry_name=self.entry_plugin._info[u"import_name"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
763 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
764 )
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
765 raise exceptions.InternalError(_(u"invalid plugin mode"))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
766
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
767 for import_name in current._info.get(C.PI_DEPENDENCIES, []):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
768 # plugins are already loaded as dependencies
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
769 # so we know they are in self.host_app.plugins
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
770 dep = self.host_app.plugins[import_name]
2498
d6de69da3dd4 core (client): component improvments:
Goffi <goffi@goffi.org>
parents: 2497
diff changeset
771 self._buildDependencies(dep, plugins)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
772
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
773 for import_name in current._info.get(C.PI_RECOMMENDATIONS, []):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
774 # here plugins are only recommendations,
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
775 # so they may not exist in self.host_app.plugins
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
776 try:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
777 dep = self.host_app.plugins[import_name]
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
778 except KeyError:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
779 continue
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
780 self._buildDependencies(dep, plugins, required=False)
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
781
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
782 if current not in plugins:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
783 # current can be required for several plugins and so
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
784 # it can already be present in the list
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
785 plugins.append(current)
262
af3d4f11fe43 Added management of connection error
Goffi <goffi@goffi.org>
parents: 260
diff changeset
786
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
787 def _getPluginsList(self):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
788 # XXX: for component we don't launch all plugins triggers
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
789 # but only the ones from which there is a dependency
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
790 plugins = []
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
791 self._buildDependencies(self.entry_plugin, plugins)
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
792 return plugins
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
793
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
794 def entityConnected(self):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
795 # we can now launch entry point
2498
d6de69da3dd4 core (client): component improvments:
Goffi <goffi@goffi.org>
parents: 2497
diff changeset
796 try:
d6de69da3dd4 core (client): component improvments:
Goffi <goffi@goffi.org>
parents: 2497
diff changeset
797 start_cb = self.entry_plugin.componentStart
d6de69da3dd4 core (client): component improvments:
Goffi <goffi@goffi.org>
parents: 2497
diff changeset
798 except AttributeError:
d6de69da3dd4 core (client): component improvments:
Goffi <goffi@goffi.org>
parents: 2497
diff changeset
799 return
d6de69da3dd4 core (client): component improvments:
Goffi <goffi@goffi.org>
parents: 2497
diff changeset
800 else:
d6de69da3dd4 core (client): component improvments:
Goffi <goffi@goffi.org>
parents: 2497
diff changeset
801 return start_cb(self)
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
802
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
803 def addPostXmlCallbacks(self, post_xml_treatments):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
804 if self.sendHistory:
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
805 post_xml_treatments.addCallback(self.messageAddToHistory)
0
goffi@necton2
parents:
diff changeset
806
goffi@necton2
parents:
diff changeset
807
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
808 class SatMessageProtocol(xmppim.MessageProtocol):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
809 def __init__(self, host):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
810 xmppim.MessageProtocol.__init__(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
811 self.host = host
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
812
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
813 @staticmethod
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
814 def parseMessage(message_elt, client=None):
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
815 """parse a message XML and return message_data
663
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
816
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
817 @param message_elt(domish.Element): raw <message> xml
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
818 @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
819 if None, mapping will not be done
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
820 @return(dict): message data
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
821 """
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
822 message = {}
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
823 subject = {}
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
824 extra = {}
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
825 data = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
826 "from": jid.JID(message_elt["from"]),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
827 "to": jid.JID(message_elt["to"]),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
828 "uid": message_elt.getAttribute(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
829 "uid", unicode(uuid.uuid4())
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
830 ), # XXX: uid is not a standard attribute but may be added by plugins
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
831 "message": message,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
832 "subject": subject,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
833 "type": message_elt.getAttribute("type", "normal"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
834 "extra": extra,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
835 }
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
836
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
837 if client is not None:
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
838 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
839 data["stanza_id"] = message_elt["id"]
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
840 except KeyError:
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
841 pass
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
842 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
843 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
844
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
845 # message
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
846 for e in message_elt.elements(C.NS_CLIENT, "body"):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
847 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
848
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
849 # subject
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
850 for e in message_elt.elements(C.NS_CLIENT, "subject"):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
851 subject[e.getAttribute((C.NS_XML, "lang"), "")] = unicode(e)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
852
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
853 # delay and timestamp
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
854 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
855 delay_elt = message_elt.elements(delay.NS_DELAY, "delay").next()
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
856 except StopIteration:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
857 data["timestamp"] = time.time()
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
858 else:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
859 parsed_delay = delay.Delay.fromElement(delay_elt)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
860 data["timestamp"] = calendar.timegm(parsed_delay.stamp.utctimetuple())
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
861 data["received_timestamp"] = unicode(time.time())
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
862 if parsed_delay.sender:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
863 data["delay_sender"] = parsed_delay.sender.full()
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
864 return data
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
865
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
866 def onMessage(self, message_elt):
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
867 # TODO: handle threads
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
868 client = self.parent
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
869 if not "from" in message_elt.attributes:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
870 message_elt["from"] = client.jid.host
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
871 log.debug(_(u"got message from: {from_}").format(from_=message_elt["from"]))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
872 post_treat = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
873 defer.Deferred()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
874 ) # XXX: plugin can add their treatments to this deferred
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
875
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
876 if not self.host.trigger.point(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
877 "MessageReceived", client, message_elt, post_treat
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
878 ):
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
879 return
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
880
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
881 data = self.parseMessage(message_elt, client)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
882
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
883 post_treat.addCallback(self.skipEmptyMessage)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
884 post_treat.addCallback(self.addToHistory, client)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
885 post_treat.addCallback(self.bridgeSignal, client, data)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
886 post_treat.addErrback(self.cancelErrorTrap)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
887 post_treat.callback(data)
663
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
888
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
889 def skipEmptyMessage(self, data):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
890 if not data["message"] and not data["extra"] and not data["subject"]:
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
891 raise failure.Failure(exceptions.CancelError("Cancelled empty message"))
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
892 return data
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
893
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
894 def addToHistory(self, data, client):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
895 if data.pop(u"history", None) == C.HISTORY_SKIP:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
896 log.info(u"history is skipped as requested")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
897 data[u"extra"][u"history"] = C.HISTORY_SKIP
2132
c0577837680a core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents: 2130
diff changeset
898 else:
c0577837680a core: replaced SkipHistory exception by a key in mess_data:
Goffi <goffi@goffi.org>
parents: 2130
diff changeset
899 return self.host.memory.addToHistory(client, data)
663
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 636
diff changeset
900
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
901 def bridgeSignal(self, dummy, client, data):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
902 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
903 data["extra"]["received_timestamp"] = data["received_timestamp"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
904 data["extra"]["delay_sender"] = data["delay_sender"]
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
905 except KeyError:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
906 pass
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
907 if data is not None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
908 self.host.bridge.messageNew(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
909 data["uid"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
910 data["timestamp"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
911 data["from"].full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
912 data["to"].full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
913 data["message"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
914 data["subject"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
915 data["type"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
916 data["extra"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
917 profile=client.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
918 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
919 return data
1053
71d63750963e core (XMPP): message received (onMessage) refactoring:
Goffi <goffi@goffi.org>
parents: 1037
diff changeset
920
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
921 def cancelErrorTrap(self, failure_):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
922 """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
923 failure_.trap(exceptions.CancelError)
636
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents: 611
diff changeset
924
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
925
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
926 class SatRosterProtocol(xmppim.RosterClientProtocol):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
927 def __init__(self, host):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
928 xmppim.RosterClientProtocol.__init__(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
929 self.host = host
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
930 self.got_roster = defer.Deferred() # called when roster is received and ready
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
931 # 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
932 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
933 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
934
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
935 def rosterCb(self, roster):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
936 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
937 self._groups.clear()
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
938 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
939 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
940 if not item.subscriptionTo and not item.subscriptionFrom and not item.ask:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
941 # XXX: current behaviour: we don't want contact in our roster list
1398
f8ecce11a0bc core (xmmp): keep the roster groups cache synchronised + fixes a log.warning
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
942 # 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
943 # may change in the future
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
944 log.info(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
945 u"Removing contact {} from roster because there is no presence subscription".format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
946 item.jid
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
947 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
948 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
949 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
950 else:
f8ecce11a0bc core (xmmp): keep the roster groups cache synchronised + fixes a log.warning
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
951 self._registerItem(item)
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
952
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
953 def _registerItem(self, item):
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
954 """Register item in local cache
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
955
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
956 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
957 @param item (RosterIem): item added
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
958 """
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
959 log.debug(u"registering item: {}".format(item.entity.full()))
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
960 if item.entity.resource:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
961 log.warning(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
962 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."
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
963 )
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
964 if not item.subscriptionTo:
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
965 if not item.subscriptionFrom:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
966 log.info(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
967 _(u"There's no subscription between you and [{}]!").format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
968 item.entity.full()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
969 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
970 )
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
971 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
972 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
973 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
974 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
975
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
976 for group in item.groups:
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
977 self._groups.setdefault(group, set()).add(item.entity)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
978
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
979 def requestRoster(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
980 """ ask the server for Roster list """
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
981 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
982 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
983 d.chainDeferred(self.got_roster)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
984
875
19d7d077478a core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents: 819
diff changeset
985 def removeItem(self, to_jid):
19d7d077478a core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents: 819
diff changeset
986 """Remove a contact from roster list
19d7d077478a core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents: 819
diff changeset
987 @param to_jid: a JID instance
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
988 @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
989 """
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
990 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
991
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
992 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
993 """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
994
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
995 @param item: RosterItem
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
996 @return: dictionary of attributes
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
997 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
998 item_attr = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
999 "to": unicode(item.subscriptionTo),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1000 "from": unicode(item.subscriptionFrom),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1001 "ask": unicode(item.ask),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1002 }
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1003 if item.name:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1004 item_attr["name"] = item.name
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1005 return item_attr
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1006
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
1007 def setReceived(self, request):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1008 # TODO: implement roster versioning (cf RFC 6121 §2.6)
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
1009 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
1010 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
1011 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
1012 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
1013 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
1014 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
1015 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
1016 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
1017 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
1018 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
1019 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
1020 self._registerItem(item)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1021 self.host.bridge.newContact(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1022 item.entity.full(), self.getAttributes(item), item.groups, self.parent.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1023 )
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1024
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
1025 def removeReceived(self, request):
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
1026 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
1027 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
1028
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
1029 # 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
1030 try:
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
1031 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
1032 except KeyError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1033 log.error(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1034 u"Received a roster remove event for an item not in cache ({})".format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1035 entity
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1036 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1037 )
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1038 return
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1039 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
1040 try:
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1041 jids_set = self._groups[group]
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
1042 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
1043 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
1044 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
1045 except KeyError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1046 log.warning(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1047 u"there is no cache for the group [%(group)s] of the removed roster item [%(jid)s]"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1048 % {"group": group, "jid": entity}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1049 )
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1050
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
1051 # then we send the bridge signal
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
1052 self.host.bridge.contactDeleted(entity.full(), self.parent.profile)
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
1053
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
1054 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
1055 """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
1056 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
1057
1300
ba73798317a7 core: fixed items registration in roster management
Goffi <goffi@goffi.org>
parents: 1299
diff changeset
1058 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
1059 """Return RosterItem for a given jid
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
1060
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
1061 @param entity_jid(jid.JID): jid of the contact
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
1062 @return(RosterItem, None): RosterItem instance
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
1063 None if contact is not in cache
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
1064 """
1300
ba73798317a7 core: fixed items registration in roster management
Goffi <goffi@goffi.org>
parents: 1299
diff changeset
1065 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
1066
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
1067 def getJids(self):
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
1068 """Return all jids of the roster"""
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 466
diff changeset
1069 return self._jids.keys()
487
e789917fb59d core: added isJidInRoster method
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1070
e789917fb59d core: added isJidInRoster method
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1071 def isJidInRoster(self, entity_jid):
e789917fb59d core: added isJidInRoster method
Goffi <goffi@goffi.org>
parents: 484
diff changeset
1072 """Return True if jid is in roster"""
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
1073 return entity_jid in self._jids
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1074
2139
f8401024ab28 core (roster): added isPresenceAuthorised to check if an entity is authorised to see our presence
Goffi <goffi@goffi.org>
parents: 2136
diff changeset
1075 def isPresenceAuthorised(self, entity_jid):
f8401024ab28 core (roster): added isPresenceAuthorised to check if an entity is authorised to see our presence
Goffi <goffi@goffi.org>
parents: 2136
diff changeset
1076 """Return True if entity is authorised to see our presence"""
f8401024ab28 core (roster): added isPresenceAuthorised to check if an entity is authorised to see our presence
Goffi <goffi@goffi.org>
parents: 2136
diff changeset
1077 try:
f8401024ab28 core (roster): added isPresenceAuthorised to check if an entity is authorised to see our presence
Goffi <goffi@goffi.org>
parents: 2136
diff changeset
1078 item = self._jids[entity_jid.userhostJID()]
f8401024ab28 core (roster): added isPresenceAuthorised to check if an entity is authorised to see our presence
Goffi <goffi@goffi.org>
parents: 2136
diff changeset
1079 except KeyError:
f8401024ab28 core (roster): added isPresenceAuthorised to check if an entity is authorised to see our presence
Goffi <goffi@goffi.org>
parents: 2136
diff changeset
1080 return False
f8401024ab28 core (roster): added isPresenceAuthorised to check if an entity is authorised to see our presence
Goffi <goffi@goffi.org>
parents: 2136
diff changeset
1081 return item.subscriptionFrom
f8401024ab28 core (roster): added isPresenceAuthorised to check if an entity is authorised to see our presence
Goffi <goffi@goffi.org>
parents: 2136
diff changeset
1082
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 461
diff changeset
1083 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
1084 """Return all items of the roster"""
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 466
diff changeset
1085 return self._jids.values()
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1086
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1087 def getJidsFromGroup(self, group):
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1088 try:
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1089 return self._groups[group]
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1090 except KeyError:
1300
ba73798317a7 core: fixed items registration in roster management
Goffi <goffi@goffi.org>
parents: 1299
diff changeset
1091 raise exceptions.UnknownGroupError(group)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1092
1450
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1435
diff changeset
1093 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
1094 """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
1095
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1435
diff changeset
1096 @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
1097 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
1098 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
1099 @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
1100 @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
1101 """
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1435
diff changeset
1102 if type_ == C.ALL and groups is not None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1103 raise ValueError("groups must not be set for {} type".format(C.ALL))
1450
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1435
diff changeset
1104
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1435
diff changeset
1105 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
1106 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
1107 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
1108 jids = set()
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1435
diff changeset
1109 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
1110 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
1111 return jids
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1435
diff changeset
1112 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1113 raise ValueError(u"Unexpected type_ {}".format(type_))
1450
7797dda847ae plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents: 1435
diff changeset
1114
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
1115 def getNick(self, entity_jid):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
1116 """Return a nick name for an entity
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
1117
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
1118 return nick choosed by user if available
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
1119 else return user part of entity_jid
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
1120 """
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
1121 item = self.getItem(entity_jid)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
1122 if item is None:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
1123 return entity_jid.user
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
1124 else:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
1125 return item.name or entity_jid.user
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
1126
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
1127
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
1128 class SatPresenceProtocol(xmppim.PresenceClientProtocol):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
1129 def __init__(self, host):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
1130 xmppim.PresenceClientProtocol.__init__(self)
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
1131 self.host = host
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1132
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
1133 def send(self, obj):
2543
60758de1c227 plugin XEP-0115: fixed caps initial check
Goffi <goffi@goffi.org>
parents: 2527
diff changeset
1134 presence_d = defer.succeed(None)
60758de1c227 plugin XEP-0115: fixed caps initial check
Goffi <goffi@goffi.org>
parents: 2527
diff changeset
1135 if not self.host.trigger.point("Presence send", self.parent, obj, presence_d):
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
1136 return
2543
60758de1c227 plugin XEP-0115: fixed caps initial check
Goffi <goffi@goffi.org>
parents: 2527
diff changeset
1137 presence_d.addCallback(lambda __: super(SatPresenceProtocol, self).send(obj))
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 934
diff changeset
1138
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
1139 def availableReceived(self, entity, show=None, statuses=None, priority=0):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1140 log.debug(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1141 _(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1142 u"presence update for [%(entity)s] (available, show=%(show)s statuses=%(statuses)s priority=%(priority)d)"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1143 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1144 % {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1145 "entity": entity,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1146 C.PRESENCE_SHOW: show,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1147 C.PRESENCE_STATUSES: statuses,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1148 C.PRESENCE_PRIORITY: priority,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1149 }
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1150 )
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1151
334
698cbc6ebec8 core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents: 333
diff changeset
1152 if not statuses:
698cbc6ebec8 core: fixed None instead of empty dict in availableReceived
Goffi <goffi@goffi.org>
parents: 333
diff changeset
1153 statuses = {}
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1154
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
1155 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
1156 statuses[C.PRESENCE_STATUSES_DEFAULT] = statuses.pop(None)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
1157
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1158 if not self.host.trigger.point(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1159 "presenceReceived", entity, show, priority, statuses, self.parent.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1160 ):
1480
8d61160ee4b8 core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents: 1450
diff changeset
1161 return
8d61160ee4b8 core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents: 1450
diff changeset
1162
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1163 self.host.memory.setPresenceStatus(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1164 entity, show or "", int(priority), statuses, self.parent.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1165 )
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
1166
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
1167 # now it's time to notify frontends
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1168 self.host.bridge.presenceUpdate(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1169 entity.full(), show or "", int(priority), statuses, self.parent.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1170 )
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1171
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
1172 def unavailableReceived(self, entity, statuses=None):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1173 log.debug(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1174 _(u"presence update for [%(entity)s] (unavailable, statuses=%(statuses)s)")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1175 % {"entity": entity, C.PRESENCE_STATUSES: statuses}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1176 )
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1177
333
4c835d614bdb core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents: 330
diff changeset
1178 if not statuses:
4c835d614bdb core: fixed a None sent instead of empty dict in unavailableReceived
Goffi <goffi@goffi.org>
parents: 330
diff changeset
1179 statuses = {}
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1180
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
1181 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
1182 statuses[C.PRESENCE_STATUSES_DEFAULT] = statuses.pop(None)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
1183
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1184 if not self.host.trigger.point(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1185 "presenceReceived", entity, "unavailable", 0, statuses, self.parent.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1186 ):
1170
2df6427a5299 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 1167
diff changeset
1187 return
2df6427a5299 plugin OTR: forces FINISHED state if we are in ENCRYPTED state on contact disconnection
souliane <souliane@mailoo.org>
parents: 1167
diff changeset
1188
1685
43a127b6a4f2 core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
1189 # 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
1190 # 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
1191 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1192 presence = self.host.memory.getEntityDatum(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1193 entity, "presence", self.parent.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1194 )
1690
772c8edd1057 core: fixed cache check on presence unavailable
Goffi <goffi@goffi.org>
parents: 1685
diff changeset
1195 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
1196 # 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
1197 pass
43a127b6a4f2 core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
1198 else:
43a127b6a4f2 core: avoid to send presence unavailable signal when it's not necessary
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
1199 if presence.show != C.PRESENCE_UNAVAILABLE:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1200 self.host.bridge.presenceUpdate(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1201 entity.full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1202 C.PRESENCE_UNAVAILABLE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1203 0,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1204 statuses,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1205 self.parent.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1206 )
1480
8d61160ee4b8 core, plugin watched: new plugin, show an alert when a watched entity goes online
Goffi <goffi@goffi.org>
parents: 1450
diff changeset
1207
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1208 self.host.memory.setPresenceStatus(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1209 entity, C.PRESENCE_UNAVAILABLE, 0, statuses, self.parent.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1210 )
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1211
611
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
1212 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
1213 """Set a presence and statuses.
b06047e1c1fb primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents: 1431
diff changeset
1214
b06047e1c1fb primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents: 1431
diff changeset
1215 @param entity (jid.JID): entity
b06047e1c1fb primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents: 1431
diff changeset
1216 @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
1217 @param statuses (dict{unicode: unicode}): multilingual statuses with
b06047e1c1fb primitivus: fix setting the presence and status
souliane <souliane@mailoo.org>
parents: 1431
diff changeset
1218 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
1219 """
611
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
1220 if priority is None:
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
1221 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1222 priority = int(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1223 self.host.memory.getParamA(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1224 "Priority", "Connection", profile_key=self.parent.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1225 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1226 )
611
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
1227 except ValueError:
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
1228 priority = 0
d722778b152c core: added Priority management
Goffi <goffi@goffi.org>
parents: 609
diff changeset
1229
734
b26dfac8e46c core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents: 726
diff changeset
1230 if statuses is None:
562
0bb2e0d1c878 core, plugin XEP-0054: avatar upload:
Goffi <goffi@goffi.org>
parents: 549
diff changeset
1231 statuses = {}
734
b26dfac8e46c core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents: 726
diff changeset
1232
b26dfac8e46c core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents: 726
diff changeset
1233 # default for us is None for wokkel
b26dfac8e46c core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents: 726
diff changeset
1234 # 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
1235 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
1236 statuses[None] = statuses.pop(C.PRESENCE_STATUSES_DEFAULT)
379
adcc41e4d6ea core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents: 347
diff changeset
1237
734
b26dfac8e46c core: bad indentation in SatPresenceProtocol.available
souliane <souliane@mailoo.org>
parents: 726
diff changeset
1238 presence_elt = xmppim.AvailablePresence(entity, show, statuses, priority)
379
adcc41e4d6ea core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents: 347
diff changeset
1239
562
0bb2e0d1c878 core, plugin XEP-0054: avatar upload:
Goffi <goffi@goffi.org>
parents: 549
diff changeset
1240 # ... before switching back
0bb2e0d1c878 core, plugin XEP-0054: avatar upload:
Goffi <goffi@goffi.org>
parents: 549
diff changeset
1241 if None in statuses:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1242 statuses["default"] = statuses.pop(None)
379
adcc41e4d6ea core: Fix status update crash
Xavier Maillard <xavier@maillard.im>
parents: 347
diff changeset
1243
1167
fe102b4cf275 core (xmpp): fixes SatPresenceProtocol.available to prevent an eventual code skipping
souliane <souliane@mailoo.org>
parents: 1089
diff changeset
1244 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
1245 return
fe102b4cf275 core (xmpp): fixes SatPresenceProtocol.available to prevent an eventual code skipping
souliane <souliane@mailoo.org>
parents: 1089
diff changeset
1246 self.send(presence_elt)
fe102b4cf275 core (xmpp): fixes SatPresenceProtocol.available to prevent an eventual code skipping
souliane <souliane@mailoo.org>
parents: 1089
diff changeset
1247
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
1248 @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
1249 def subscribed(self, entity):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
1250 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
1251 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
1252 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
1253 item = self.parent.roster.getItem(entity)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1254 if (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1255 not item or not item.subscriptionTo
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1256 ): # we automatically subscribe to 'to' presence
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
1257 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
1258 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
1259
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
1260 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
1261 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
1262 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
1263
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
1264 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
1265 log.debug(_(u"subscription approved for [%s]") % entity.userhost())
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1266 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
1267
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
1268 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
1269 log.debug(_(u"unsubscription confirmed for [%s]") % entity.userhost())
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1270 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
1271
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
1272 @defer.inlineCallbacks
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
1273 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
1274 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
1275 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
1276 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
1277 if item and item.subscriptionTo:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
1278 # We automatically accept subscription if we are already subscribed to contact presence
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1279 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
1280 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
1281 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1282 self.host.memory.addWaitingSub(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1283 "subscribe", entity.userhost(), self.parent.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1284 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1285 self.host.bridge.subscribe(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1286 "subscribe", entity.userhost(), self.parent.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1287 )
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
1288
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
1289 @defer.inlineCallbacks
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
1290 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
1291 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
1292 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
1293 item = self.parent.roster.getItem(entity)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
1294 if item and item.subscriptionFrom: # we automatically remove contact
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1295 log.debug(_("automatic contact deletion"))
875
19d7d077478a core (xmpp): fix automatic contact deletion
souliane <souliane@mailoo.org>
parents: 819
diff changeset
1296 self.host.delContact(entity, self.parent.profile)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1297 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
1298
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
1299
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
1300 class SatDiscoProtocol(disco.DiscoClientProtocol):
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
1301 def __init__(self, host):
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
1302 disco.DiscoClientProtocol.__init__(self)
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
1303
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
1304
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
1305 class SatFallbackHandler(generic.FallbackHandler):
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
1306 def __init__(self, host):
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
1307 generic.FallbackHandler.__init__(self)
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
1308
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
1309 def iqFallback(self, iq):
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
1310 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
1311 return
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 960
diff changeset
1312 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
1313 generic.FallbackHandler.iqFallback(self, iq)
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
1314
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
1315
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
1316 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
1317 def getDiscoInfo(self, requestor, target, node):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1318 # 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
1319 # 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
1320 # 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
1321 # 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
1322 # 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
1323 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
1324
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
1325
666
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
1326 class SatIdentityHandler(XMPPHandler):
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
1327 """ Manage disco Identity of SàT.
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
1328
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
1329 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1330
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1331 # TODO: dynamic identity update (see docstring). Note that a XMPP entity can have several identities
666
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
1332 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
1333
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1334 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2139
diff changeset
1335 return self.parent.identities
666
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
1336
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2596
diff changeset
1337 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
666
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 663
diff changeset
1338 return []