Mercurial > libervia-backend
comparison sat/core/xmpp.py @ 3736:e52de21873d3
core (xmpp): new `getVirtualClient` for components:
this method is used to make a client with a given JID instead of component's JID. This is
needed when a JID managed by the component (e.g. associated to a legacy service account)
must be used.
rel 364
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 22 Mar 2022 17:00:42 +0100 |
parents | b9718216a1c0 |
children | 9581098b64f0 |
comparison
equal
deleted
inserted
replaced
3735:04ecc8eeb81a | 3736:e52de21873d3 |
---|---|
14 # GNU Affero General Public License for more details. | 14 # GNU Affero General Public License for more details. |
15 | 15 |
16 # You should have received a copy of the GNU Affero General Public License | 16 # You should have received a copy of the GNU Affero General Public License |
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 |
19 import calendar | |
20 import copy | |
21 from functools import partial | |
22 import mimetypes | |
23 from pathlib import Path | |
19 import sys | 24 import sys |
20 import time | 25 import time |
21 import calendar | 26 from typing import Tuple |
27 from urllib.parse import unquote, urlparse | |
22 import uuid | 28 import uuid |
23 import mimetypes | 29 |
24 from typing import Tuple | |
25 from urllib.parse import urlparse, unquote | |
26 from functools import partial | |
27 from pathlib import Path | |
28 import shortuuid | 30 import shortuuid |
29 from sat.core.i18n import _ | |
30 from sat.core.constants import Const as C | |
31 from sat.memory import cache | |
32 from twisted.internet import defer, error as internet_error | 31 from twisted.internet import defer, error as internet_error |
33 from twisted.internet import ssl | 32 from twisted.internet import ssl |
34 from twisted.words.protocols.jabber.xmlstream import XMPPHandler | 33 from twisted.python import failure |
35 from twisted.words.protocols.jabber import xmlstream | 34 from twisted.words.protocols.jabber import xmlstream |
36 from twisted.words.protocols.jabber import error | 35 from twisted.words.protocols.jabber import error |
37 from twisted.words.protocols.jabber import jid | 36 from twisted.words.protocols.jabber import jid |
37 from twisted.words.protocols.jabber.xmlstream import XMPPHandler | |
38 from twisted.words.xish import domish | 38 from twisted.words.xish import domish |
39 from twisted.python import failure | 39 from wokkel import client as wokkel_client, disco, generic, iwokkel, xmppim |
40 from wokkel import client as wokkel_client, disco, xmppim, generic, iwokkel | |
41 from wokkel import component | 40 from wokkel import component |
42 from wokkel import delay | 41 from wokkel import delay |
43 from sat.core.log import getLogger | 42 from zope.interface import implementer |
43 | |
44 from sat.core import exceptions | 44 from sat.core import exceptions |
45 from sat.core import core_types | 45 from sat.core import core_types |
46 from sat.core.constants import Const as C | |
47 from sat.core.i18n import _ | |
48 from sat.core.log import getLogger | |
49 from sat.memory import cache | |
46 from sat.memory import encryption | 50 from sat.memory import encryption |
47 from sat.memory import persistent | 51 from sat.memory import persistent |
48 from sat.tools import xml_tools | 52 from sat.tools import xml_tools |
49 from sat.tools import utils | 53 from sat.tools import utils |
50 from sat.tools.common import data_format | 54 from sat.tools.common import data_format |
51 from zope.interface import implementer | |
52 | 55 |
53 log = getLogger(__name__) | 56 log = getLogger(__name__) |
54 | 57 |
55 | 58 |
56 NS_X_DATA = "jabber:x:data" | 59 NS_X_DATA = "jabber:x:data" |
1107 owner = jid.JID(iq_elt["from"]).userhostJID() | 1110 owner = jid.JID(iq_elt["from"]).userhostJID() |
1108 | 1111 |
1109 peer_jid = jid.JID(iq_elt["from"]) | 1112 peer_jid = jid.JID(iq_elt["from"]) |
1110 return peer_jid, owner | 1113 return peer_jid, owner |
1111 | 1114 |
1115 def getVirtualClient(self, jid_: jid.JID) -> SatXMPPEntity: | |
1116 """Get client for this component with a specified jid | |
1117 | |
1118 This is needed to perform operations with a virtual JID corresponding to a virtual | |
1119 entity (e.g. identified of a legacy network account) instead of the JID of the | |
1120 gateway itself. | |
1121 @param jid_: virtual JID to use | |
1122 @return: virtual client | |
1123 """ | |
1124 client = copy.copy(self) | |
1125 client.jid = jid_ | |
1126 return client | |
1112 | 1127 |
1113 | 1128 |
1114 class SatMessageProtocol(xmppim.MessageProtocol): | 1129 class SatMessageProtocol(xmppim.MessageProtocol): |
1115 | 1130 |
1116 def __init__(self, host): | 1131 def __init__(self, host): |