File: //lib/python3/dist-packages/twisted/words/protocols/jabber/__pycache__/component.cpython-310.pyc
o
�bj; � @ s� d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl m
Z
mZmZm
Z
ddlmZ ddlmZ d Zd
d� ZG dd
� d
�ZG dd� de
j�ZG dd� de
j�Zeej�G dd� dej��ZG dd� dej�Zdd� ZG dd� d�ZG dd� 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:acceptc C s t | |�}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
r c @ s( e Zd ZdZdd� 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}
c C s || _ d | _d S �N)r � _deferred��self�xsr r r �__init__7 s
z'ComponentInitiatingInitializer.__init__c C s` | j }t�| j jdf�}t �|j|jj�}|�t |�� |�
d| j� |�|� t
�� | _| jS )N� handshakez
/handshake)r r �Element� namespace�hashPassword�sid�
authenticatorr �
addContent�str�addOnetimeObserver�_cbHandshake�sendr �Deferredr )r r �hs�digestr r r �
initialize; s
z)ComponentInitiatingInitializer.initializec C s | j j| j _| j�d � d S r )r �otherEntity�
thisEntityr �callback)r �_r r r r$ G s z+ComponentInitiatingInitializer._cbHandshakeN)�__name__�
__module__�__qualname__�__doc__r r) r$ r r r r r . s
r c @ s$ e Zd ZdZeZdd� 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).
c C s t j�| |� || _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 �ConnectAuthenticatorr r )r �componentjidr r r r r W s
z&ConnectComponentAuthenticator.__init__c C s$ d|_ tj�| |� t|�g|_d S )N�r r )�versionr r2 �associateWithStreamr �initializersr r r r r6 c s z1ConnectComponentAuthenticator.associateWithStreamN)r. r/ r0 r1 �NS_COMPONENT_ACCEPTr r r6 r r r r r N s
r c @ s<