changeset 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 <>
date Tue, 22 Mar 2022 17:00:42 +0100
parents 04ecc8eeb81a
children 783d6dc87b80
files sat/core/
diffstat 1 files changed, 29 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/sat/core/	Mon Mar 21 16:37:19 2022 +0100
+++ b/sat/core/	Tue Mar 22 17:00:42 2022 +0100
@@ -16,39 +16,42 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <>.
+import calendar
+import copy
+from functools import partial
+import mimetypes
+from pathlib import Path
 import sys
 import time
-import calendar
+from typing import Tuple
+from urllib.parse import unquote, urlparse
 import uuid
-import mimetypes
-from typing import Tuple
-from urllib.parse import urlparse, unquote
-from functools import partial
-from pathlib import Path
 import shortuuid
-from sat.core.i18n import _
-from sat.core.constants import Const as C
-from sat.memory import cache
 from twisted.internet import defer, error as internet_error
 from twisted.internet import ssl
-from twisted.words.protocols.jabber.xmlstream import XMPPHandler
+from twisted.python import failure
 from twisted.words.protocols.jabber import xmlstream
 from twisted.words.protocols.jabber import error
 from twisted.words.protocols.jabber import jid
+from twisted.words.protocols.jabber.xmlstream import XMPPHandler
 from twisted.words.xish import domish
-from twisted.python import failure
-from wokkel import client as wokkel_client, disco, xmppim, generic, iwokkel
+from wokkel import client as wokkel_client, disco, generic, iwokkel, xmppim
 from wokkel import component
 from wokkel import delay
-from sat.core.log import getLogger
+from zope.interface import implementer
 from sat.core import exceptions
 from sat.core import core_types
+from sat.core.constants import Const as C
+from sat.core.i18n import _
+from sat.core.log import getLogger
+from sat.memory import cache
 from sat.memory import encryption
 from sat.memory import persistent
 from import xml_tools
 from import utils
 from import data_format
-from zope.interface import implementer
 log = getLogger(__name__)
@@ -1109,6 +1112,18 @@
         peer_jid = jid.JID(iq_elt["from"])
         return peer_jid, owner
+    def getVirtualClient(self, jid_: jid.JID) -> SatXMPPEntity:
+        """Get client for this component with a specified jid
+        This is needed to perform operations with a virtual JID corresponding to a virtual
+        entity (e.g. identified of a legacy network account) instead of the JID of the
+        gateway itself.
+        @param jid_: virtual JID to use
+        @return: virtual client
+        """
+        client = copy.copy(self)
+        client.jid = jid_
+        return client
 class SatMessageProtocol(xmppim.MessageProtocol):