%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/protocols/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/protocols/__pycache__/sip.cpython-312.pyc

�

Ϫ�fH��
��dZddlZddlZddlZddlmZddlmZmZddl	m
Z
mZddlm
Z
ddlmZmZmZddlmZdd	lmZd
Zddd
ddddddd�	ZiZej3�D]
\ZZeee<�[[idd�dd�dd�dd�dd�dd �d!d"�d#d$�d%d&�d'd(�d)d*�d+d,�d-d.�d/d0�d1d2�d3d4�d5d6�id7d8�d9d:�d;d<�d=d>�d?d@�dAdB�dCdD�dEdF�dGdH�dIdJ�dKdL�dMdN�dOdP�dQdR�dSdT�dUdV�dWdX��idYdZ�d[d\�d]d^�d_d`�dadb�dcdd�dedf�dgdh�didj�dkdl�dmdn�dodp�dqdr�dsdt�dudv�dwdx�dydz��d{d:d|��Zd}d~dd��Zd��Zd��Ze �Z!Gd��d��Z"d��Z#Gd��d��Z$d�d��Z%d��Z&d�d��Z'Gd��d�e(�Z)Gd��d�e)�Z*Gd��d��Z+Gd��d�e+�Z,Gd��d�e+�Z-Gd��d�ej\�Z/Gd��d�ej`�Z1Gd��d�e
�Z2Gd��d��Z3Gd��d�e
�Z4Gd��d�e
�Z5Gd��d�e1�Z6Gd��d�e
�Z7Gd��d�e6�Z8ee4e5�Gd��d���Z9y)�zP
Session Initialization Protocol.

Documented in RFC 2543.
[Superseded by 3261]
�N)�OrderedDict)�Dict�List)�	Interface�implementer)�cred)�defer�protocol�reactor)�basic)�logi��i�m�e�l�c�f�s�t�v)	�call-id�contactzcontent-encoding�content-lengthzcontent-type�from�subject�to�via�d�Trying��Ringing�zCall Is Being Forwarded��Queued�zSession Progress���OKi,zMultiple Choicesi-zMoved Permanentlyi.zMoved Temporarilyi/z	See Otheri1z	Use Proxyi|zAlternative Service�zBad Request��Unauthorizedi�zPayment Requiredi��	Forbidden�z	Not Foundi�zMethod Not Allowedi�zNot Acceptablei�zProxy Authentication Requiredi�zRequest Timeouti��Conflicti��Gonei�zLength Requiredi�zRequest Entity Too Largei�zRequest-URI Too Largei�zUnsupported Media Typei�zUnsupported URI Schemei�z
Bad Extensioni�zExtension Requiredi�zInterval Too Briefi�zTemporarily Unavailablei�zCall/Transaction Does Not Existi�z
Loop Detectedi�z
Too Many Hopsi�zAddress Incompletei��	Ambiguousi�z	Busy Herei�zRequest Terminatedi�zNot Acceptable Herei�zRequest Pendingi��Undecipherable��zInternal Server Error�zNot Implementedi�zBad Gatewayi�zService Unavailablei�zServer Time-outi�zSIP Version not supportedizMessage Too LargeiXzBusy Everywherei[�DeclinezDoes not exist anywhere)i\i^�CSeqzCall-IDzWWW-Authenticate)�cseqr�www-authenticatec��dj|jd�D�cgc]}|j���c}�Scc}w)zK
    Capitalize a string, making sure to treat '-' as a word separator
    �-)�join�split�
capitalize)r�xs  �7/usr/lib/python3/dist-packages/twisted/protocols/sip.py�dashCapitalizer>ls/���8�8�Q�W�W�S�\�:��Q�\�\�^�:�;�;��:s�=c�:�|d|dcxk(rdk(r	n|S|ddS|S)Nr����"��)rs r=�unqrDss.����t�q��u�����H���2�w���H�c�b�eZdZdZeddddeddfd�Zed��Zejd��Zd�Z
y)	�Viaa�
    A L{Via} is a SIP Via header, representing a segment of the path taken by
    the request.

    See RFC 3261, sections 8.1.1.7, 18.2.2, and 20.42.

    @ivar transport: Network protocol used for this leg. (Probably either "TCP"
    or "UDP".)
    @type transport: C{str}
    @ivar branch: Unique identifier for this request.
    @type branch: C{str}
    @ivar host: Hostname or IP for this leg.
    @type host: C{str}
    @ivar port: Port used for this leg.
    @type port C{int}, or None.
    @ivar rportRequested: Whether to request RFC 3581 client processing or not.
    @type rportRequested: C{bool}
    @ivar rportValue: Servers wishing to honor requests for RFC 3581 processing
    should set this parameter to the source port the request was received
    from.
    @type rportValue: C{int}, or None.

    @ivar ttl: Time-to-live for requests on multicast paths.
    @type ttl: C{int}, or None.
    @ivar maddr: The destination multicast address, if any.
    @type maddr: C{str}, or None.
    @ivar hidden: Obsolete in SIP 2.0.
    @type hidden: C{bool}
    @ivar otherParams: Any other parameters in the header.
    @type otherParams: C{dict}
    �UDPNFc
�L�||_||_||_||_||_||_|dur+t
jdtd��d|_	d|_
n6|�d|_	d|_
n%|turd|_	d|_
n||_	d|_
||_|	|_
|
|_y)a(
        Set parameters of this Via header. All arguments correspond to
        attributes of the same name.

        To maintain compatibility with old SIP
        code, the 'rport' argument is used to determine the values of
        C{rportRequested} and C{rportValue}. If None, C{rportRequested} is set
        to True. (The deprecated method for doing this is to pass True.) If an
        integer, C{rportValue} is set to the given value.

        Any arguments not explicitly named here are collected into the
        C{otherParams} dict.
        Tz+rport=True is deprecated since Twisted 9.0.�)�
stacklevelNF)�	transport�host�port�ttl�hidden�received�warnings�warn�DeprecationWarning�
rportValue�rportRequested�_absent�branch�maddr�otherParams)�selfrMrNrLrOrPrQ�rportrXrY�kws           r=�__init__zVia.__init__�s���4#�����	���	������� ��
��D�=��M�M�=�"��
�
#�D�O�"&�D��
�]�"�D�O�"&�D��
�g�
�"�D�O�"'�D��#�D�O�"'�D�������
���rEc�T�|jdk(ry|j�|jSy)zG
        Returns the rport value expected by the old SIP code.
        TN)rVrU�r[s r=r\z	Via.rport�s,��
���$�&��
�_�_�
(��?�?�"�rEc� �||_d|_y)z�
        L{Base._fixupNAT} sets C{rport} directly, so this method sets
        C{rportValue} based on that.

        @param newRPort: The new rport value.
        @type newRPort: C{int}
        FN)rUrV)r[�newRPorts  r=r\z	Via.rport�s��#���#��rEc��d|j�d|j�d|j��}|jr|dz
}dD]}t	||�}|��|d|�d|��z
}�|j
r|dz
}n|j�|d	|j��z
}t|jj��}|D]\}}|�	|d|zz
}�|d|�d|��z
}�|S)
zI
        Serialize this header for use in a request or response.
        zSIP/2.0/� �:z;hidden)rOrXrYrQ�;�=z;rportz;rport=)rLrMrNrP�getattrrVrUr\�sortedrZ�items)r[r�n�value�etc�krs       r=�toStringzVia.toString�s����t�~�~�&�a��	�	�{�!�D�I�I�;�?���;�;�
��N�A�5�	%�A��D�!�$�E�� ��q���1�U�G�_�$��	%����
��M�A�
�_�_�
(�
�7�4�:�:�,�'�'�A��T�%�%�+�+�-�.���	!�D�A�q��y��S�1�W����q���1�Q�C�[� ��		!�
�rE)�__name__�
__module__�__qualname__�__doc__�PORTrWr^�propertyr\�setterrorCrEr=rGrG|sY���F��������4�l�	��	��\�\�	$��	$�rErGc�~�|jd�}|d|dd}}|jdd�\}}|j�}i}|jd�\}}}	|dk7s|dk7rtd	|����|	|d
<d|vr(|jd�\}
}t|�|d<|
|d
<n||d
<|D]�}|j�jdd�}t	|�dk(r|dd}
}n|\}}
|dk(rd|d<�I|jdd�}t	|�dk(r|dd}}n|\}}|dvrt|�}|||<��tdi|��S)za
    Parse a Via header.

    @return: The parsed version of this header.
    @rtype: L{Via}
    rfrrBNrd�/�SIPz2.0zwrong protocol or version: rLrerNrM�rPTrg)r\rOrC)r:�strip�
ValueError�int�lenrG)rl�parts�sent�params�protocolinfo�by�result�pname�pversionrLrMrN�p�comment�names               r=�parseViaHeaderr�sv��
�K�K���E���8�U�1�2�Y�&�D��z�z�#�q�)��L�"�	����B�
�F�!-�!3�!3�C�!8��E�8�Y���~��U�*��6�u�i�@�A�A�#�F�;��
�b�y��X�X�c�]�
��d��T���v����v����v��
���
�G�G�I�O�O�C��#���q�6�Q�;��1��r�w�A��J�A�w���=�#�F�8�������Q����u�:��?���(�D�%�D��K�D�%��'�'��E�
����t��#�$�=��=�rEc�R�eZdZdZ											dd�Zdefd�Zdefd�Zdefd�Zy)	�URLz
    A SIP URL.
    Nc
���||_||_||_||_||_||_||_|
|_||_|	|_	|dk(rg|_
n||_
|dk(ri|_y||_y�N)�usernamerM�passwordrNrL�usertype�method�tagrOrY�other�headers)
r[rMr�r�rNrLr�r�rOrYr�r�r�s
             r=r^zURL.__init__4st��!��
���	� ��
���	�"��� ��
������������
��D�=��D�J��D�J��d�?��D�L�"�D�LrE�returnc�&�g}|j}|d�|jdk7r>||j�|jdk7r|d|jz�|d�||j�|jdk7r|d|jz�|j
dk7r|d|j
z�dD]"}t
||�}|dk7s�|d|�d|����$|jD]
}|d	|z��|jro|d
�|dj|jj�D��cgc],\}}tj|�xst|��d|����.c}}��dj|�Scc}}w)
N�sip:z:%s�@z:%dz;user=%s�rLrOrYr�r�rfrgz;%s�?�&rz)�appendr�r�rMrNr�rhr�r�r9rj�specialCases�getr>)r[r�wrkr�hs      r=rozURL.toStringVsn����
�H�H��	�&�	��=�=�D� �
�d�m�m���}�}��$��%�$�-�-�'�(�
�c�F�	�$�)�)���9�9���
�e�d�i�i�� ��=�=�D� �
�j�4�=�=�(�)�?�	�A���a� �A��D�y��A�a�S��!��+��	����	�A�
�e�a�i�L�	��<�<�
�c�F�
����'+�l�l�&8�&8�&:��"�Q��)�,�,�Q�/�D�>�!�3D�E�Q�q�c�J���
��w�w�q�z���
s�?1F
c�"�|j�Sr�)ror`s r=�__str__zURL.__str__vs���}�}��rEc��dj|j|j|j|j|j
�S)Nz<URL {}:{}@{}:{!r}/{}>)�formatr�r�rMrNrLr`s r=�__repr__zURL.__repr__ys8��'�.�.��M�M��M�M��I�I��I�I��N�N�
�	
rE)NNNNNNNNNNN)	rprqrrrsr^�strror�r�rCrEr=r�r�/sU�����
��������� #�D�#��@���
�#�
rEr�c���i}|jd�std|ddz��|ddjd�}|d|dd}}|jdd�}t|�d	k(r?|\}}	|jd
d�}
t|
�dk(r	|
d|d<n|
d|d<|
d|d<n|d}	|	jd
d�}t|�dk(r	|d|d
<n|d|d
<t	|d�|d<|dk7r||d
<|dk7r||d<|D]�}||dk(rOd|vrKix|d<}
|jdd�\}}|jd�D]}|jd�\}}||
|<�|jdd�}t|�dk(r"|jdg�j
|���|\}}|dk(r||d<��|dvr|dk(rt	|�}|||<��|jdg�j
|���tdi|��S)zV
    Return string into URL object.

    URIs are of form 'sip:user@example.com'.
    r�zunsupported scheme: N�rfrrBr�rJrer�r�rMrNr@r�r�r�rgr��userr�r�rOrC)�
startswithr|r:r~r}�
setdefaultr�r�)�urlrMrN�dr�
userdomainr��udparts�userpass�hostport�upparts�hppartsr�r�r��headerrnr�nvr�rls                     r=�parseURLr��s;��	�A��>�>�&�!��/�#�b�q�'�9�:�:����G�M�M�#��E��q��5���9��J����s�A�&�G�
�7�|�q��$���(��.�.��a�(���w�<�1��#�A�J�A�j�M�#�A�J�A�j�M�#�A�J�A�j�M��1�:���n�n�S�!�$�G�
�7�|�q���A�J��&�	��A�J��&�	����
�O��&�	��t�|���&�	��t�|���&�	�
�0����r�
�?�s�a�x�!�!�A�i�L�1�����a��J�A�w�!�-�-��,�
���|�|�C�(���1���!��
��W�W�S�!�_���r�7�a�<�
�L�L��"�%�,�,�Q�/�����e��6�>�!�A�j�M�
�C�
C��u�}��E�
���A�d�G�
�L�L��"�%�,�,�Q�/�'0�(�8��8�OrEc�<�d|_d|_d|_i|_y)z*
    Clean a URL from a Request line.
    N)rLrYrOr�)r�s r=�cleanRequestURLr��s ���C�M��C�I��C�G��C�KrEc� �|j�}|jd�rdt|||��ifSi}|jdd�\}}|j�}|jd�r|dd}|j	d�r|dd}|jd	d�\}}t|||��}|j�}|r2|jd
�D]}|s�|jd�\}	}
|
||	<� |rd|_i|_d|_d|_|||fS)z�
    Return (name, uri, params) for From/To/Contact header.

    @param clean: remove unnecessary info, usually for From and To headers.
    r�rz�rMrN�<rBrANr@�>rfrg)	r{r�r�r:�endswithrOr�rLrY)�addressrMrN�cleanr�r�r��paramstringrrnrs           r=�parseAddressr��s!���m�m�o�G����&�!��8�G�$�T�:�B�>�>�
�F��
�
�c�1�%�I�D�#��:�:�<�D����s���A�B�x���}�}�S���C�R�y���y�y��a�(��C��
�3�T��
-�C��#�#�%�K���"�"�3�'�	�A����7�7�3�<�D�A�q��F�1�I�		�

���������
���	���f��rEc��eZdZdd�Zy)�SIPErrorNc�l�|�	t|}tj|d||fz�||_||_y)NzSIP error (%d): %s)�statusCodes�	Exceptionr^�code�phrase)r[r�r�s   r=r^zSIPError.__init__�s9���>� ��&�F����4�!5��v��!F�G���	���rEr��rprqrrr^rCrEr=r�r��s��rEr�c��eZdZdZy)�RegistrationErrorz(
    Registration was not possible.
    N�rprqrrrsrCrEr=r�r�����rEr�c�8�eZdZdZdZd�Zd�Zd�Zd�Zd�Z	d�Z
y)	�Messagez
    A SIP message.
    Nc�>�t�|_d|_d|_y)Nrzr)rr��body�finishedr`s r=r^zMessage.__init__�s��"�}�����	���
rEc���|j�}tj||�}|dk(rt|�|_|j
j
|g�j|�y)Nr)�lower�longHeadersr�r}�lengthr�r�r�)r[r�rls   r=�	addHeaderzMessage.addHeadersP���z�z�|�����t�T�*���#�#��e�*�D�K�������b�)�0�0��7rEc�.�|xj|z
c_yr�)r��r[�datas  r=�bodyDataReceivedzMessage.bodyDataReceived	s���	�	�T��	rEc��|jdk7r-|jt|j�k7rtd��d|_y)Nzwrong body lengthrB)r�r~r�r|r�r`s r=�creationFinishedzMessage.creationFinisheds4���K�K�4��d�k�k�S����^�&C��0�1�1���
rEc��d|j�z}|jj�D]7\}}|D]-}|tj	|�xst|��d|�d�z
}�/�9|dz
}||jz
}|S)Nz%s
z: z
)�_getHeaderLiner�rjr�r�r>r�)r[rrk�vsrs     r=rozMessage.toStrings����t�*�*�,�,���\�\�'�'�)�	L�E�A�r��
L����(�(��+�@�~�a�/@�A��A�3�d�K�K��
L�	L�	
�V���	�T�Y�Y����rEc��t�r���NotImplementedErrorr`s r=r�zMessage._getHeaderLines��!�!rE)rprqrrrsr�r^r�r�r�ror�rCrEr=r�r��s,����F��
8���
�"rEr�c�*�eZdZdZdd�Zdefd�Zd�Zy)�Requestz
    A Request for a URI
    c��tj|�||_t|t�r||_yt
|�|_t|j
�yr�)r�r^r��
isinstancer��urir�r�)r[r�r��versions    r=r^zRequest.__init__#s?�����������c�3���D�H���}�D�H��D�H�H�%rEr�c�h�dt|�|j|jj�fzS)Nz<SIP Request %d:%s %s>)�idr�r�ror`s r=r�zRequest.__repr__,s)��'�2�d�8�T�[�[�$�(�(�BS�BS�BU�*V�V�VrEc�V�|j�d|jj��d�S)Nrdz SIP/2.0)r�r�ror`s r=r�zRequest._getHeaderLine/s'���+�+��a���� 1� 1� 3�4�H�=�=rEN)�SIP/2.0�rprqrrrsr^r�r�r�rCrEr=r�r�s���&�W�#�W�>rEr�c�*�eZdZdZdd�Zdefd�Zd�Zy)�Responsez%
    A Response to a URI Request
    Nc�f�tj|�||_|dk(r	t|}||_yr�)r�r^r�r�r�)r[r�r�r�s    r=r^zResponse.__init__8s/���������	��T�>� ��&�F���rEr�c�6�dt|�|jfzS)Nz<SIP Response %d:%s>)r�r�r`s r=r�zResponse.__repr__?s��%��D��4�9�9�(=�=�=rEc�:�d|j�d|j��S)NzSIP/2.0 rd)r�r�r`s r=r�zResponse._getHeaderLineBs���$�)�)��A�d�k�k�]�3�3rE)Nr�r�rCrEr=r�r�3s����>�#�>�4rEr�c�d�eZdZdZdZdZdZdZdZd�Z	dd�Z
d�Zd	�Zd
�Z
d�Zd�Zd
�Zdd�Zd�Zy)�MessagesParserz�
    A SIP messages parser.

    Expects dataReceived, dataDone repeatedly,
    in that order. Shouldn't be connected to actual transport.
    r�rB�	firstlinerc�2�||_|j�yr�)�messageReceived�reset)r[�messageReceivedCallbacks  r=r^zMessagesParser.__init__Us��6����
�
�rEc�l�d|_d|_d|_d|_d|_|j|�y)Nr�r)�stater��bodyReceived�messager��setLineMode�r[�
remainingDatas  r=r�zMessagesParser.resetYs4�� ��
�����������������'rEc�2�d|_|j�y)N�invalid)r��
setRawModer`s r=�invalidMessagezMessagesParser.invalidMessageas����
����rEc�,�|j�|jdk(ry|jdk7r|j�y|jdk(r|j	�y|j|j
kr|j�yt
d��)zI
        Clear out any buffered data that may be hanging around.
        r�Nr�zthis should never happen)�clearLineBufferr�r�r��messageDoner��RuntimeErrorr`s r=�dataDonezMessagesParser.dataDoneesx��	
�����:�:��$���:�:����J�J�L���;�;�$������
�[�[�4�,�,�
,��J�J�L��9�:�:rEc���	t|t�r|jd�}tjj||�y#t$r'tj�|j�YywxYw)N�utf-8)
r�r��encoder�LineReceiver�dataReceivedr�r
�errrr�s  r=rzMessagesParser.dataReceivedysY��	"��$��$��{�{�7�+�����+�+�D�$�7���	"��G�G�I����!�	"�s�AA�-A4�3A4c��t�)z2
        Expected to create self.message.
        r��r[�lines  r=�handleFirstLinezMessagesParser.handleFirstLine�s
��"�!rEc�$�|j�yr�)rrs  r=�lineLengthExceededz!MessagesParser.lineLengthExceeded�s�����rEc���t|t�r|jd�}|jdk(r�|j	d�s|j	d�r)|dd}|j	d�r�|j	d�r�)|sy	|jdd�\}}}|dk(r1|jr%	t|�}t||�|_d	|_y|dk(r%|jrt||�|_d	|_y|j�y|jd	k(sJ�|r�|j	d�s|j	d
�r*|j\}}|||j�zf|_y|jr*|jj |j�d|_	|jdd�\}}||j�f|_|j#�dk(r 	t|j��|_yyd
|_|jr*|jj |j�d|_|j$dk(r|j'�y|j)�y#t$r|j�YywxYw#t$r|j�YywxYw#t$r|j�YywxYw#t$r|j�YywxYw)Nr
r��
�
rBrdrJr�r��	rerr�r)r��bytes�decoder�r�r:r|r�acceptResponsesr}r�r��acceptRequestsr�r��lstripr�r�r�r	r)r[r�a�brr�r�rls        r=�lineReceivedzMessagesParser.lineReceived�s����d�E�"��;�;�w�'�D��:�:��$��/�/�$�'�4�?�?�4�+@��A�B�x���/�/�$�'�4�?�?�4�+@���
��*�*�S�!�,���1�a��I�~�$�"6�"6���q�6�D� (��a�0���#�D�J��
�i��D�$7�$7�&�q�!�}���#�D�J���#�#�%���:�:��*�*�*�����s�#�t���t�'<�"�k�k���e�"�U�T�[�[�]�%:�;����;�;�*�D�L�L�*�*�D�K�K�8�"&�D�K��"&�*�*�S�!�"4�K�D�%�#�E�L�L�N�2����:�:�<�#3�3��&)�%�,�,�.�&9���4� �D�J��{�{�&����&�&����4�"����{�{�a��� � �"���O�O���m�
��#�#�%��
��"���'�'�)����2"���'�'�)����&���+�+�-���sH�I+�(J
�J)�K�+J�J�
J&�%J&�)K�K�K$�#K$c��|jdk(sJ�|jj�|j|j�|j	|�y)Nr�)r�r�r�r�r�rs  r=r	zMessagesParser.messageDone�sB���z�z�V�#�#�#����%�%�'����T�\�\�*��
�
�=�!rEc�H�|jdvsJ�t|t�r|jd�}|jdk(ry|jdk(r|j
j
|�yt|�}|j|jz
}||kDr3|j
j
|d|�|j||d�y|xj|z
c_|j
j
|�|j|jk(r|j�yy)N)r�rr
r)
r�r�rrr�r�r�r~r�r	)r[r��dataLen�expectedLens    r=�rawDataReceivedzMessagesParser.rawDataReceived�s����z�z�0�0�0�0��d�E�"��;�;�w�'�D��:�:��"���;�;�$���L�L�)�)�$�/��$�i�G��+�+��(9�(9�9�K���$����-�-�d�<�K�.@�A�� � ��k�l�!3�4���!�!�W�,�!����-�-�d�3��$�$����3��$�$�&�4rEN)rz)rprqrrrsr�rrr��debugr^r�rrrrrr#r	r(rCrEr=r�r�FsV����G��O��N��E�
�E��(��;�("�"��A�F"�'rEr�c�N�eZdZdZeZdZd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zy)
�Basez1
    Base class for SIP clients and servers.
    Fc�F�g|_t|j�|_yr�)�messagesr��
addMessage�parserr`s r=r^z
Base.__init__�s����
�$�T�_�_�5��rEc�:�|jj|�yr�)r-r�)r[�msgs  r=r.zBase.addMessage�s���
�
���S�!rEc��|jj|�|jj�|jD]~}|j	||�|j
r)t
jd|j��d|���t|t�r|j||��m|j||���g|jddy)Nz	Received z from )
r/rrr-�	_fixupNATr)r
r1ror�r��handle_request�handle_response)r[r��addrrs    r=�datagramReceivedzBase.datagramReceived�s������ � ��&����������	.�A��N�N�1�d�#��z�z����)�A�J�J�L�#3�6�$��B�C��!�W�%��#�#�A�t�,��$�$�Q��-�	.���
�
�a�rEc�Z�|\}}t|jdd�}|j|k7r>||_|j|k7r||_|j
�|jdd<y|j
dk(r/||_||_|j
�|jdd<yy)NrrT)r�r�rMrQrNr\ro)r[r��
sourcePeer�srcHost�srcPort�	senderVias      r=r3zBase._fixupNATs���'���'�"�7�?�?�5�#9�!�#<�=�	��>�>�W�$�!(�I���~�~��(�")�	��(1�(:�(:�(<�G�O�O�E�"�1�%�
�_�_��
$�!(�I��%�I�O�(1�(:�(:�(<�G�O�O�E�"�1�%�%rEc��t|jdd�}|jxs|j}|jxs|j
xs|j}t||��}|j||�y�zX
        Deliver response.

        Destination is based on topmost Via header.
        rrr�N�	r�r�rQrMr\rNrtr��sendMessage�r[�responseMessage�destViarMrN�destAddrs      r=�deliverResponsezBase.deliverResponsesi��!��!8�!8��!?��!B�C�����/�7�<�<���}�}�9����9��	�	���D�t�,������?�3rEc��t|�}dD].}|jj|g�dd|j|<�0|S�z9
        Create a response to a request message.
        )rrrrr5N�r�r�r��r[r��request�responser�s     r=�responseFromRequestzBase.responseFromRequest!sK���D�>��<�	F�D�%,�_�_�%8�%8��r�%B�1�%E�H���T�"�	F��rEc��|jdvrtd��|jr)tjd|j��d|���|j�}t
|t�r|jd�}|jj||j|jxs|jf�y)z�
        Send a message.

        @param destURL: C{URL}. This should be a *physical* URL, not a logical one.
        @param message: The message to send.
        )�udpNzonly UDP currently supportedzSending z to r
N)
rLr
r)r
r1ror�r�r�writerMrNrt)r[�destURLr�r�s    r=r@zBase.sendMessage+s������M�1��=�>�>��:�:��G�G�h�w�/�/�1�4�D���D�E����!���d�C� ��;�;�w�'�D������T�G�L�L�'�,�,�2K�$�)�)�#L�MrEc��t�)z�
        Override to define behavior for requests received

        @type message: C{Message}
        @type addr: C{tuple}
        r��r[r�r6s   r=r4zBase.handle_request;�
��"�!rEc��t�)z�
        Override to define behavior for responses received.

        @type message: C{Message}
        @type addr: C{tuple}
        r�rRs   r=r5zBase.handle_responseDrSrEN)rprqrrrsrtr)r^r.r7r3rErLr@r4r5rCrEr=r+r+�sA����D��E�6�"��=�4��N� "�"rEr+c��eZdZdZy)�IContactz(
    A user of a registrar or proxy
    Nr�rCrEr=rVrVNr�rErVc��eZdZd�Zy)�Registrationc� �||_||_yr�)�secondsToExpiry�
contactURL)r[rZr[s   r=r^zRegistration.__init__Us��.���$��rENr�rCrEr=rXrXTs��%rErXc�"�eZdZdZd�Zd�Zd�Zy)�	IRegistryz?
    Allows registration of logical->physical URL mapping.
    c��y)z�
        Register the physical address of a logical URL.

        @return: Deferred of C{Registration} or failure with RegistrationError.
        NrC��	domainURL�
logicalURL�physicalURLs   r=�registerAddresszIRegistry.registerAddress_��rEc��y)z�
        Unregister the physical address of a logical URL.

        @return: Deferred of C{Registration} or failure with RegistrationError.
        NrCr_s   r=�unregisterAddresszIRegistry.unregisterAddressfrdrEc��y)z�
        Get registration info for logical URL.

        @return: Deferred of C{Registration} object or failure of LookupError.
        NrC�ras r=�getRegistrationInfozIRegistry.getRegistrationInfomrdrEN)rprqrrrsrcrfrirCrEr=r]r]Zs�����rEr]c��eZdZdZd�Zy)�ILocatorz<
    Allow looking up physical address for logical URL.
    c��y)z�
        Return physical URL of server for logical URL of user.

        @param logicalURL: a logical C{URL}.
        @return: Deferred which becomes URL or fails with LookupError.
        NrCrhs r=�
getAddresszILocator.getAddresszrdrEN)rprqrrrsrmrCrEr=rkrkus���rErkc�T�eZdZdZeZdZdefd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zy)�Proxyz
    SIP proxy.
    Nc�v�|xstj�|_||_tj|�y)z�
        Create new instance.

        @param host: our hostname/IP as set in Via headers.
        @param port: our port as set in Via headers.
        N)�socket�getfqdnrMrNr+r^)r[rMrNs   r=r^zProxy.__init__�s*���,�F�N�N�,��	���	��
�
�d�rEc�D�t|j|j��S)z<
        Return value of Via header for this proxy.
        r�)rGrMrNr`s r=�getViazProxy.getVia�s����	�	��	�	�2�2rEc����t�d�jzd�}|��j}	|�|�}|�|j��fd��yy#t$r5}�j�j
|j���Yd}~yd}~wt$r8tj��j�j
d���YywxYw)Nzhandle_%s_requestc�Z���j�j|j���Sr�)rErLr�)rr�r[s ��r=�<lambda>z&Proxy.handle_request.<locals>.<lambda>�s&���d�2�2��0�0�����A��rEr1)rhr��handle_request_default�
addErrbackr�rErLr��
BaseExceptionr
r)r[r�r6rr�rs``    r=r4zProxy.handle_request�s����
�D�-����>��E���9��+�+�A�
	��'�4� �A��}��������
�	L�� � ��!9�!9�!�&�&�'�!J�K�K���	I��G�G�I�� � ��!9�!9�#�w�!G�H�	I�s�	A�	C�+B�AC�
Cc����|\}}�fd�}�j�}|j�|jdvrtjd�y|jdjd|j��t
|jddd��\}}}	�jj|�}
|
j�j|�|
j�j|�y)	z�
        Default request handler.

        Default behaviour for OPTIONS and unknown methods for proxies
        is to forward message on to the client.

        Since at the moment we are stateless proxy, that's basically
        everything.
        c�h��|j�|jdd<�j||�S)Nrr)ror�r@)r�r�r[s  �r=�_mungContactHeaderz8Proxy.handle_request_default.<locals>._mungContactHeader�s/���,/�L�L�N�G�O�O�I�&�q�)��#�#�C��1�1rErzDropping looped message.NrrrB�r�)
rtror�r
r1�insertr��locatorrm�addCallbackr@ry�_cantForwardRequest)r[r�r9r:r;r}�	viaHeaderr�r��tagsr�s`          r=rxzProxy.handle_request_default�s����(���'�	2��K�K�M�	�����7�?�?�5�#9�9��G�G�.�/�������%�%�a��);�);�)=�>�&�w���t�'<�Q�'?�q�I���c�4�
�L�L�#�#�C�(��	�
�
�d�&�&��0�	���T�-�-�w�7rEc��|jt�|jdd=|j|j	d|��y)Nrrr,)�trap�LookupErrorr�rErL�r[�errorr�s   r=r�zProxy._cantForwardRequest�s:��
�
�
�;���O�O�E�"�1�%����T�5�5�c�7�C�DrEc��t|jdd�}|jxs|j}|jxs|j
xs|j}t||��}|j||�yr>r?rAs      r=rEzProxy.deliverResponse�si��!��!8�!8��!?��!B�C�����/�7�<�<���}�}�9����9��	�	���D�t�,������?�3rEc��t|�}dD].}|jj|g�dd|j|<�0|SrGrHrIs     r=rLzProxy.responseFromRequest�sI���D�>��<�	F�D�%,�_�_�%8�%8��r�%B�1�%E�H���T�"�	F��rEc�N�t|jdd�}|j|jf|j|jfk7rt	j
d�y|jdd=|jds|j
||�y|j|�y)z+
        Default response handler.
        rrz&Dropping incorrectly addressed messageN)r�r�rMrNr
r1�gotResponserE)r[r�r6rs    r=r5zProxy.handle_response�s���
�7�?�?�5�1�!�4�5��
�F�F�A�F�F���	�	�4�9�9�5�5�
�G�G�<�=���O�O�E�"�1�%����u�%����W�d�+�����W�%rEc��y)zJ
        Called with responses that are addressed at this server.
        NrCrRs   r=r�zProxy.gotResponse�s��	
rE)rprqrrrsrtr�r^rtr4rxr�rErLr5r�rCrEr=roro�sF����D��G� �t�	�3��*8�<E�
4��&�$
rEroc��eZdZd�Zd�Zy)�IAuthorizerc��y)z�
        Generate a challenge the client may respond to.

        @type peer: C{tuple}
        @param peer: The client's address

        @rtype: C{str}
        @return: The challenge string
        NrC)�peers r=�getChallengezIAuthorizer.getChallengerdrEc��y)zf
        Create a credentials object from the given response.

        @type response: C{str}
        NrC)rKs r=rzIAuthorizer.decoderdrEN)rprqrrr�rrCrEr=r�r�s��	�rEr�c��eZdZUdZdZdZiZeee	fe
d<d�Zd�Zd�Z
d�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zy)�
RegisterProxyzk
    A proxy that allows registration for a specific domain.

    Unregistered users won't be handled.
    N�authorizersc�D�tj|g|��i|��i|_yr�)ror^�liveChallenges)r[�argsr]s   r=r^zRegisterProxy.__init__&s ��
���t�)�d�)�b�)� ��rEc��|\}}yr�rC�r[r��	host_portrMrNs     r=�handle_ACK_requestz RegisterProxy.handle_ACK_request*s��!���t�rEc��|\}}|j�|j|||�yd|jvr|j|||�S|j	|||�S)z`
        Handle a registration request.

        Currently registration is not proxied.
        N�
authorization)�portal�registerr��unauthorized�loginr�s     r=�handle_REGISTER_requestz%RegisterProxy.handle_REGISTER_request3s]��!���t��;�;���M�M�'�4��.��g�o�o�5��(�(��$��=�=��z�z�'�4��6�6rEc��|jd|�}|jj�D]�\}}|j||f�}|�!|j	��d|j
�d�}n#|j	��d|�d|j
�d�}|jjdg�j|���|j|�y)Nr)z realm="rArdz,realm="r6)
rLr�rjr��titlerMr�r�r�rE)	r[r�rMrNr�scheme�auth�chalrls	         r=r�zRegisterProxy.unauthorizedDs����$�$�S�'�2�� �,�,�2�2�4�	G�L�F�D��$�$�d�D�\�2�D��|�!�<�<�>�*�(�4�9�9�+�Q�?��!�<�<�>�*�!�D�6��$�)�)��A�F��
�I�I� � �!3�R�8�?�?��F�
	G�	
���Q�rEc���|jddjdd�}|jj|dj	��}|r�	|j|d�}|xjd|jzz
c_|jj|dt�j|j|||�j|j|||�jtj �y|j'|j)d|��y#t"$r�t$$r8tj �|j'|j)d|��YywxYw)Nr�rrBr�r1r2)r�r:r�r�r�rr�rMr�r�rVr��_cbLoginry�_ebLoginr
rr�rzrErL)r[r�rMrNrr!rs       r=r�zRegisterProxy.loginOs"������0��3�9�9�$��B����� � ��q����!1�2���
U��H�H�U�1�X�&���
�
�c�D�I�I�o�-�
����!�!�!�T�8�4�@�@��M�M�7�D�$���*�T�]�]�G�T�4�@���C�G�G�AT�� � ��!9�!9�#�w�!G�H���
�� �
M����	��$�$�T�%=�%=�c�7�%K�L�
M�s�D!�!AE+�*E+c�6�|\}}}|j|||�yr�)r�)r[�i_a_lr�rMrNrr!rs        r=r�zRegisterProxy._cbLoginbs���	��A�q��
�
�g�t�T�*rEc�|�|jtjj�|j	|||�yr�)r�rr��UnauthorizedLoginr�)r[�failurer�rMrNs     r=r�zRegisterProxy._ebLogings*�����T�Z�Z�1�1�2����'�4��.rEc��t|jddd��\}}}d}d|jvr|jdd}|jjddg�ddk(r|j|||�y|�:t|||�	�\}}}|jj|j||�}	n|jj|�}	|	j|j|j|f|f�
�y)z-
        Allow all users to register
        rrrBr~Nr�expires�0r�)�callbackArgs�errbackArgs)r�r�r��
unregister�registryrcr�ri�addCallbacks�_cbRegister�_ebRegister)
r[r�rMrNr��toURLr�rr[r�s
          r=r�zRegisterProxy.registerks���+�7�?�?�4�+@��+C�1�M���e�V�������'��o�o�i�0��3�G��?�?���y�4�&�1�!�4��;��O�O�G�U�G�4��"�+7��d�QU�+V�(��j�&��M�M�1�1�'�+�+�u�j�Q���M�M�5�5�e�<��
�N�N�� � �� � �%�Z�$�J�	
�
rEc��|jd|�}|jdk7rI|jd|jj��|jdd|jz�|jdd�|j|�y)Nr&rr�z%drr�)rLr[r�rorZrE)r[�registrationr�rKs    r=r�zRegisterProxy._cbRegister�s{���+�+�C��9���"�"�d�*����y�,�*A�*A�*J�*J�*L�M����y�$��1M�1M�*M�N����+�S�1����X�&rEc�8�|jtt�yr�)r�r�r�r�s   r=r�zRegisterProxy._ebRegister�s��
�
�
�$�k�2rEc��	t|jdd�}|dk(ru|dk(rd}nt|�\}}}|jj	|j
||�}|j
|j|�j|j|�yy#t$r$|j|jd|��YywxYw)Nr�r�*r()
r}r�r�r�rfr�r��
_cbUnregisterry�
_ebUnregisterr|rErL)	r[r�r�rr�r[r�r�r�s	         r=r�zRegisterProxy.unregister�s���
	��'�/�/�)�4�Q�7�8�G��!�|��c�>�!$�J�/;�G�/D�,�D�*�f��M�M�3�3�G�K�K��
�S���
�
�d�0�0�'�:�E�E��&�&���
���	I�� � ��!9�!9�#�w�!G�H�	I�s�B�*C�Cc���|jd|�}|jjdg�j|jj��|j
dd�|j|�y)Nr&rr�r�)rLr�r�r�r[ror�rE)r[r�r�r1s    r=r�zRegisterProxy._cbUnregister�s^���&�&�s�G�4�������y�"�-�4�4�\�5L�5L�5U�5U�5W�X��
�
�i��%����S�!rEc��yr�rC)r[r�r�s   r=r�zRegisterProxy._ebUnregister�s��rE)rprqrrrsr�r�r�rr�r��__annotations__r^r�r�r�r�r�r�r�r�r�r�r�r�rCrEr=r�r�si����F��H�*,�K��c�;�&�'�,�!�
�7�"	 �I�&+�
/��4'�3�
� "�
rEr�c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�InMemoryRegistryz6
    A simplistic registry for a specific domain.
    c� �||_i|_yr�)�domain�users)r[r�s  r=r^zInMemoryRegistry.__init__�s�������
rEc�>�|j|jk7rtjt	d��S|j
|jvr1|j|j
\}}tj|�Stjt	d��S�Nzunknown domain�no such user)rMr�r	�failr�r�r��succeed�r[�userURI�dcr�s    r=rmzInMemoryRegistry.getAddress�st���<�<�4�;�;�&��:�:�k�*:�;�<�<����t�z�z�)��j�j��!1�!1�2�G�B���=�=��%�%��:�:�k�.�9�:�:rEc	��|j|jk7rtjt	d��S|j
|jvrg|j|j
\}}tjtt|j�tj�z
�|��Stjt	d��Sr�)rMr�r	r�r�r�r�r�rXr}�getTime�timer�s    r=riz$InMemoryRegistry.getRegistrationInfo�s����<�<�4�;�;�&��:�:�k�*:�;�<�<����t�z�z�)��j�j��!1�!1�2�G�B���=�=��c�"�*�*�,�����2L�.M�s�!S�T�T��:�:�k�.�9�:�:rEc��	|j|\}}|j�|j|=tjtd|��S#t$r!tjtd��cYSwxYw)Nr�r)r��cancel�KeyErrorr	r�r�r�rX)r[r�r�r�s    r=�_expireRegistrationz$InMemoryRegistry._expireRegistration�sk��	%��j�j��*�G�B��
�I�I�K��
�
�8�$��}�}�\�!�S�1�2�2���	;��:�:�k�.�9�:�:�	;�s�A�'A:�9A:c	�N�|j|jk7r3tjd�t	j
t
d��S|j|jk7r3tjd�t	j
t
d��S|j|jvr.|j|j\}}|jd�n+tjd|j|j�}tjd|j��d|j����||f|j|j<t	jtt!|j#�t%j$�z
�|��S)Nz(Registration for domain we don't handle.r,izRegistered z at )rMr�r
r1r	r�r�r�r�r�r�	callLaterr�ror�rXr}r�r�)r[r`rarbr��olds      r=rcz InMemoryRegistry.registerAddress�s-���>�>�T�[�[�(��G�G�>�?��:�:�/��4�5�5��?�?�d�k�k�)��G�G�>�?��:�:�/��4�5�5����$�*�*�,��j�j��!4�!4�5�G�B���H�H�T�N��"�"�4��)A�)A�:�CV�CV�W�B����+�j�1�1�3�4�D��9M�9M�9O�8P�Q�R�+-�{�*;��
�
�:�&�&�'��}�}�\�#�b�j�j�l�T�Y�Y�[�.H�*I�;�W�X�XrEc�8�|j|j�Sr�)r�r�)r[r`rarbs    r=rfz"InMemoryRegistry.unregisterAddress�s���'�'�
�(;�(;�<�<rEN)
rprqrrrsr^rmrir�rcrfrCrEr=r�r��s&����;�;�3�Y� =rEr�)NN)NNr):rsrqr�rR�collectionsr�typingrr�zope.interfacerr�twistedr�twisted.internetr	r
r�twisted.protocolsr�twisted.pythonr
rt�shortHeadersr�rjrnrr�r�r>rD�objectrWrGr�r�r�r�r�r�r�r�r�r�r�rr��DatagramProtocolr+rVrXr]rkror�r�r�rCrEr=�<module>r�sy��
����#��1��5�5�#�����������

��
������� ��D�A�q��K��N���q�6���6���6��	"�6���	6�
�	�6���
6��	�6��	�6��	�6���6���6��	�6���6���6��	�6� ��!6�"��#6�$�	�%6�&�	�'6�(�	(�)6�*�	�+6�,��-6�.��/6�0�	�16�2�	#�36�4�	 �56�6�	!�76�8�	!�96�:��;6�<�	�=6�>�	�?6�@�	"�A6�B�	*�C6�D��E6�F��G6�H�	�I6�J��K6�L��M6�N�	�O6�P�	�Q6�R�	�S6�T�	�U6�V�	 �W6�X�	�Y6�Z��[6�\�	�]6�^�	�_6�`�	$�a6�b�	�c6�d�	�e6�f��g6�h
#�	�k6��r
��*���<�
��(��E�E�P(�VQ
�Q
�h4�n� �F�y�����%"�%"�P>�g�>�*4�w�4�&a'�U�'�'�a'�Ha"�8�$�$�a"�H�y��%�%��	��6�y��
�D�
�D�)��(P
�E�P
�f
�Y��!�6=�6=�"�6=rE

Zerion Mini Shell 1.0