Spamworldpro Mini Shell
Spamworldpro


Server : Apache/2.4.52 (Ubuntu)
System : Linux webserver 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2 x86_64
User : www-data ( 33)
PHP Version : 8.1.2-1ubuntu2.21
Disable Function : NONE
Directory :  /lib/python3/dist-packages/twisted/words/protocols/jabber/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/twisted/words/protocols/jabber/__pycache__/component.cpython-310.pyc
o

�bj;�@s�dZddlmZddlmZddlmZddlmZddl	m
Z
mZmZm
Z
ddlmZddlmZd	Zd
d�ZGdd
�d
�ZGdd�de
j�ZGdd�de
j�Zeej�Gdd�dej��ZGdd�dej�Zdd�ZGdd�d�ZGdd�de
j �Z!dS)a�
External server-side components.

Most Jabber server implementations allow for add-on components that act as a
separate entity on the Jabber network, but use the server-to-server
functionality of a regular Jabber IM server. These so-called 'external
components' are connected to the Jabber server using the Jabber Component
Protocol as defined in U{JEP-0114<http://www.jabber.org/jeps/jep-0114.html>}.

This module allows for writing external server-side component by assigning one
or more services implementing L{ijabber.IService} up to L{ServiceManager}. The
ServiceManager connects to the Jabber server and is responsible for the
corresponding XML stream.
�)�implementer)�service)�defer)�log)�error�ijabber�	jstrports�	xmlstream)�	internJID)�domishzjabber:component:acceptcCst||�}t�|�S)z�
    XML stream factory for external server-side components.

    @param componentid: JID of the component.
    @type componentid: L{unicode}
    @param password: password used to authenticate to the server.
    @type password: C{str}
    )�ConnectComponentAuthenticatorr	�XmlStreamFactory)�componentid�password�a�r�J/usr/lib/python3/dist-packages/twisted/words/protocols/jabber/component.py�componentFactory!s
	
rc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�ComponentInitiatingInitializerz�
    External server-side component authentication initializer for the
    initiating entity.

    @ivar xmlstream: XML stream between server and component.
    @type xmlstream: L{xmlstream.XmlStream}
    cCs||_d|_dS�N)r	�	_deferred��self�xsrrr�__init__7s
z'ComponentInitiatingInitializer.__init__cCs`|j}t�|jjdf�}t�|j|jj�}|�t	|��|�
d|j�|�|�t
��|_|jS)N�	handshakez
/handshake)r	r�Element�	namespace�hashPassword�sid�
authenticatorr�
addContent�str�addOnetimeObserver�_cbHandshake�sendr�Deferredr)rr�hs�digestrrr�
initialize;s

z)ComponentInitiatingInitializer.initializecCs|jj|j_|j�d�dSr)r	�otherEntity�
thisEntityr�callback)r�_rrrr$Gsz+ComponentInitiatingInitializer._cbHandshakeN)�__name__�
__module__�__qualname__�__doc__rr)r$rrrrr.s
rc@s$eZdZdZeZdd�Zdd�ZdS)rz�
    Authenticator to permit an XmlStream to authenticate against a Jabber
    server as an external component (where the Authenticator is initiating the
    stream).
    cCstj�||�||_dS)z�
        @type componentjid: C{str}
        @param componentjid: Jabber ID that this component wishes to bind to.

        @type password: C{str}
        @param password: Password/secret this component uses to authenticate.
        N)r	�ConnectAuthenticatorrr)r�componentjidrrrrrWs	
z&ConnectComponentAuthenticator.__init__cCs$d|_tj�||�t|�g|_dS)N�rr)�versionr	r2�associateWithStreamr�initializersrrrrr6csz1ConnectComponentAuthenticator.associateWithStreamN)r.r/r0r1�NS_COMPONENT_ACCEPTrrr6rrrrrNs
rc@s<eZdZdZeZdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dS)
�ListenComponentAuthenticatorz�
    Authenticator for accepting components.

    @since: 8.2
    @ivar secret: The shared secret used to authorized incoming component
                  connections.
    @type secret: C{unicode}.
    cCs||_tj�|�dSr)�secretr	�ListenAuthenticatorr)rr:rrrrvsz%ListenComponentAuthenticator.__init__cCsd|_tj�||�dS)z�
        Associate the authenticator with a stream.

        This sets the stream's version to 0.0, because the XEP-0114 component
        protocol was not designed for XMPP 1.0.
        r4N)r5r	r;r6rrrrr6zsz0ListenComponentAuthenticator.associateWithStreamcCsttj�||�|j|jkrt�d�}|j�|�dS|jjs+t�d�}|j�|�dS|j�	�|j�
d|j�dS)aa
        Called by the stream when it has started.

        This examines the default namespace of the incoming stream and whether
        there is a requested hostname for the component. Then it generates a
        stream identifier, sends a response header and adds an observer for
        the first incoming element, triggering L{onElement}.
        zinvalid-namespaceNzimproper-addressing�/*)r	r;�
streamStarted�
defaultUrirr�StreamError�sendStreamErrorr+�
sendHeaderr#�	onElement)r�rootElement�excrrrr=�s



z*ListenComponentAuthenticator.streamStartedcCsB|j|jf|jdfkr|�t|��dSt�d�}|j�|�dS)a.
        Called on incoming XML Stanzas.

        The very first element received should be a request for handshake.
        Otherwise, the stream is dropped with a 'not-authorized' error. If a
        handshake request was received, the hash is extracted and passed to
        L{onHandshake}.
        r�not-authorizedN)	�uri�namer�onHandshaker"rr?r	r@)r�elementrDrrrrB�s	
z&ListenComponentAuthenticator.onElementcCs^t�|jjt|j��}||krtjddd�}|j�|�dS|j�d�|j�	|jtj
�dS)a9
        Called upon receiving the handshake request.

        This checks that the given hash in C{handshake} is equal to a
        calculated hash, responding with a handshake reply or a stream error.
        If the handshake was ok, the stream is authorized, and  XML Stanzas may
        be exchanged.
        rEzInvalid hash)�textz<handshake/>N)r	rrr"r:rr?r@r%�dispatch�STREAM_AUTHD_EVENT)rr�calculatedHashrDrrrrH�s	z(ListenComponentAuthenticator.onHandshakeN)r.r/r0r1r8rrr6r=rBrHrrrrr9js	
r9c@�0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�Servicez1
    External server-side component service.
    cC�dSrrrrrr�componentConnected��zService.componentConnectedcCrPrr�rrrr�componentDisconnected�rRzService.componentDisconnectedcCrPrrrrrr�transportConnected�rRzService.transportConnectedcCs|j�|�dS)a�
        Send data over service parent's XML stream.

        @note: L{ServiceManager} maintains a queue for data sent using this
        method when there is no current established XML stream. This data is
        then sent as soon as a new stream has been established and initialized.
        Subsequently, L{componentConnected} will be called again. If this
        queueing is not desired, use C{send} on the XmlStream object (passed to
        L{componentConnected}) directly.

        @param obj: data to be sent over the XML stream. This is usually an
        object providing L{domish.IElement}, or serialized XML. See
        L{xmlstream.XmlStream} for details.
        N)�parentr%�r�objrrrr%�szService.sendN)r.r/r0r1rQrTrUr%rrrrrO�srOc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�ServiceManagera[
    Business logic for a managed component connection to a Jabber router.

    This service maintains a single connection to a Jabber router and provides
    facilities for packet routing and transmission. Business logic modules are
    services implementing L{ijabber.IService} (like subclasses of L{Service}),
    and added as sub-service.
    cCsztj�|�||_d|_g|_t|j|�|_|j�tj	|j
�|j�tj|j�|j�tj
|j�|jj|_|jj|_dSr)r�MultiServicer�jabberIdr	�_packetQueuer�
_xsFactory�addBootstrap�STREAM_CONNECTED_EVENT�
_connectedrL�_authd�STREAM_END_EVENT�
_disconnected�removeBootstrap)r�jidrrrrr�s
zServiceManager.__init__cCs|jSr)r]rSrrr�
getFactoryszServiceManager.getFactorycCs*||_|D]
}tj�|�r|�|�qdSr)r	r�IService�
providedByrU)rr�crrrr`s
��zServiceManager._connectedcCsB|jD]}|j�|�qg|_|D]
}tj�|�r|�|�qdSr)r\r	r%rrgrhrQ)rr�prirrrras

��zServiceManager._authdcCs(d|_|D]}tj�|�r|��qdSr)r	rrgrhrT)rr-rirrrrcs��zServiceManager._disconnectedcCs*|jdkr
|j�|�dS|j�|�dS)a�
        Send data over the XML stream.

        When there is no established XML stream, the data is queued and sent
        out when a new XML stream has been established and initialized.

        @param obj: data to be sent over the XML stream. This is usually an
        object providing L{domish.IElement}, or serialized XML. See
        L{xmlstream.XmlStream} for details.
        N)r	r%r\�appendrWrrrr%"s
zServiceManager.sendN)
r.r/r0r1rrfr`rarcr%rrrrrY�s		rYcCs(t||�}t�||���}|�|�|S)z[
    Constructs a pre-built L{ServiceManager}, using the specified strport
    string.
    )rYr�clientrf�setServiceParent)rer�strport�svc�
client_svcrrr�buildServiceManager4s

rqc@rN)�Routera�
    XMPP Server's Router.

    A router connects the different components of the XMPP service and routes
    messages between them based on the given routing table.

    Connected components are trusted to have correct addressing in the
    stanzas they offer for routing.

    A route destination of L{None} adds a default route. Traffic for which no
    specific route exists, will be routed to this default route.

    @since: 8.2
    @ivar routes: Routes based on the host part of JIDs. Maps host names to the
                  L{EventDispatcher<utility.EventDispatcher>}s that should
                  receive the traffic. A key of L{None} means the default
                  route.
    @type routes: C{dict}
    cCs
i|_dSr)�routesrSrrrrU�
zRouter.__init__cCs||j|<|�d|j�dS)a
        Add a new route.

        The passed XML Stream C{xs} will have an observer for all stanzas
        added to route its outgoing traffic. In turn, traffic for
        C{destination} will be passed to this stream.

        @param destination: Destination of the route to be added as a host name
                            or L{None} for the default route.
        @type destination: C{str} or L{None}.
        @param xs: XML Stream to register the route for.
        @type xs: L{EventDispatcher<utility.EventDispatcher>}.
        r<N)rs�addObserver�route�r�destinationrrrr�addRouteXs
zRouter.addRoutecCs,|�d|j�||j|kr|j|=dSdS)a
        Remove a route.

        @param destination: Destination of the route that should be removed.
        @type destination: C{str}.
        @param xs: XML Stream to remove the route for.
        @type xs: L{EventDispatcher<utility.EventDispatcher>}.
        r<N)�removeObserverrvrsrwrrr�removeRouteis	�zRouter.removeRoutecCs`t|d�}t�d|���d|�����|j|jvr&|j|j�|�dS|jd�|�dS)z{
        Route a stanza.

        @param stanza: The stanza to be routed.
        @type stanza: L{domish.Element}.
        �tozRouting to z: N)�JIDr�msg�full�toXml�hostrsr%)r�stanzarxrrrrvvs
zRouter.routeN)r.r/r0r1rryr{rvrrrrrr@s
rrc@s>eZdZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�XMPPComponentServerFactoryz�
    XMPP Component Server factory.

    This factory accepts XMPP external component connections and makes
    the router service route traffic for a component's bound domain
    to that component.

    @since: 8.2
    Fr:csP|�_|�_�fdd�}tj��|���tj�j���tj�j	�d�_
dS)Ncs
t�j�Sr)r9r:rrSrr�authenticatorFactory�rtzAXMPPComponentServerFactory.__init__.<locals>.authenticatorFactoryr)�routerr:r	�XmlStreamServerFactoryrr^r_�onConnectionMaderL�onAuthenticated�serial)rr�r:r�rrSrr�s
z#XMPPComponentServerFactory.__init__csT|j�_|jd7_�fdd�}�fdd�}|jr |�_|�_��tj|j�dS)z{
        Called when a component connection was made.

        This enables traffic debugging on incoming streams.
        �c�t�d�j|f�dS)Nz
RECV (%d): %r�rr~r���buf�rrr�	logDataIn��z>XMPPComponentServerFactory.onConnectionMade.<locals>.logDataIncr�)Nz
SEND (%d): %rr�r�r�rr�
logDataOut�r�z?XMPPComponentServerFactory.onConnectionMade.<locals>.logDataOutN)r��
logTraffic�rawDataInFn�rawDataOutFnrur	�STREAM_ERROR_EVENT�onError)rrr�r�rr�rr��sz+XMPPComponentServerFactory.onConnectionMadecCs0|jj}|j�||�|�tj|jd||�dS)z�
        Called when a component has successfully authenticated.

        Add the component to the routing table and establish a handler
        for a closed connection.
        rN)r+r�r�ryrur	rb�onConnectionLost)rrrxrrrr��s
�z*XMPPComponentServerFactory.onAuthenticatedcCst�|d�dS)NzStream Error)r�err)r�reasonrrrr��sz"XMPPComponentServerFactory.onErrorcCs|j�||�dSr)r�r{)rrxrr�rrrr��sz+XMPPComponentServerFactory.onConnectionLostN)r:)
r.r/r0r1r�rr�r�r�r�rrrrr��s


r�N)"r1�zope.interfacer�twisted.applicationr�twisted.internetr�twisted.pythonr�twisted.words.protocols.jabberrrrr	�"twisted.words.protocols.jabber.jidr
r}�twisted.words.xishrr8rrr2rr;r9rgrOrZrYrqrrr�r�rrrr�<module>s&
 V!RG

Spamworldpro Mini