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
This commit is contained in:
parent
127d383eb5
commit
b5ea5bfdc8
1 changed files with 29 additions and 14 deletions
|
|
@ -16,39 +16,42 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import calendar
|
||||||
|
import copy
|
||||||
|
from functools import partial
|
||||||
|
import mimetypes
|
||||||
|
from pathlib import Path
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import calendar
|
|
||||||
import uuid
|
|
||||||
import mimetypes
|
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
from urllib.parse import urlparse, unquote
|
from urllib.parse import unquote, urlparse
|
||||||
from functools import partial
|
import uuid
|
||||||
from pathlib import Path
|
|
||||||
import shortuuid
|
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 defer, error as internet_error
|
||||||
from twisted.internet import ssl
|
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 xmlstream
|
||||||
from twisted.words.protocols.jabber import error
|
from twisted.words.protocols.jabber import error
|
||||||
from twisted.words.protocols.jabber import jid
|
from twisted.words.protocols.jabber import jid
|
||||||
|
from twisted.words.protocols.jabber.xmlstream import XMPPHandler
|
||||||
from twisted.words.xish import domish
|
from twisted.words.xish import domish
|
||||||
from twisted.python import failure
|
from wokkel import client as wokkel_client, disco, generic, iwokkel, xmppim
|
||||||
from wokkel import client as wokkel_client, disco, xmppim, generic, iwokkel
|
|
||||||
from wokkel import component
|
from wokkel import component
|
||||||
from wokkel import delay
|
from wokkel import delay
|
||||||
from sat.core.log import getLogger
|
from zope.interface import implementer
|
||||||
|
|
||||||
from sat.core import exceptions
|
from sat.core import exceptions
|
||||||
from sat.core import core_types
|
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 encryption
|
||||||
from sat.memory import persistent
|
from sat.memory import persistent
|
||||||
from sat.tools import xml_tools
|
from sat.tools import xml_tools
|
||||||
from sat.tools import utils
|
from sat.tools import utils
|
||||||
from sat.tools.common import data_format
|
from sat.tools.common import data_format
|
||||||
from zope.interface import implementer
|
|
||||||
|
|
||||||
log = getLogger(__name__)
|
log = getLogger(__name__)
|
||||||
|
|
||||||
|
|
@ -1109,6 +1112,18 @@ class SatXMPPComponent(SatXMPPEntity, component.Component):
|
||||||
peer_jid = jid.JID(iq_elt["from"])
|
peer_jid = jid.JID(iq_elt["from"])
|
||||||
return peer_jid, owner
|
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):
|
class SatMessageProtocol(xmppim.MessageProtocol):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue