
    Yf&                         d Z ddlmZ ddlmZ ddlmZ ddlmZ  eej	                   G d dej                              Z
dS )	z
The parent class for all the SSH Channels.  Currently implemented channels
are session, direct-tcp, and forwarded-tcp.

Maintainer: Paul Swartz
    )implementer)
interfaces)Logger)logc                       e Zd ZU dZ e            ZdZeed<   	 	 	 	 	 	 	 ddZ	de
fdZdefdZd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )
SSHChannela  
    A class that represents a multiplexed channel over an SSH connection.
    The channel has a local window which is the maximum amount of data it will
    receive, and a remote which is the maximum amount of data the remote side
    will accept.  There is also a maximum packet size for any individual data
    packet going each way.

    @ivar name: the name of the channel.
    @type name: L{bytes}
    @ivar localWindowSize: the maximum size of the local window in bytes.
    @type localWindowSize: L{int}
    @ivar localWindowLeft: how many bytes are left in the local window.
    @type localWindowLeft: L{int}
    @ivar localMaxPacket: the maximum size of packet we will accept in bytes.
    @type localMaxPacket: L{int}
    @ivar remoteWindowLeft: how many bytes are left in the remote window.
    @type remoteWindowLeft: L{int}
    @ivar remoteMaxPacket: the maximum size of a packet the remote side will
        accept in bytes.
    @type remoteMaxPacket: L{int}
    @ivar conn: the connection this channel is multiplexed through.
    @type conn: L{SSHConnection}
    @ivar data: any data to send to the other side when the channel is
        requested.
    @type data: L{bytes}
    @ivar avatar: an avatar for the logged-in user (if a server channel)
    @ivar localClosed: True if we aren't accepting more data.
    @type localClosed: L{bool}
    @ivar remoteClosed: True if the other side isn't accepting more data.
    @type remoteClosed: L{bool}
    Nnamer   c                     |pd| _         | j         | _        |pd| _        || _        || _        d| _        || _        || _        || _        d| _	        d| _
        g | _        d| _        d| _        d| _        d | _        d S )Ni   i          r   )localWindowSizelocalWindowLeftlocalMaxPacketremoteWindowLeftremoteMaxPacket
areWritingconndataavatarspecificDatabufextBufclosinglocalClosedremoteClosedid)selflocalWindowr   remoteWindowr   r   r   r   s           K/var/www/html/env/lib/python3.11/site-packages/twisted/conch/ssh/channel.py__init__zSSHChannel.__init__9   s      +4f#3,5 ,.		r   returnc                 P    |                                                      d          S )Nascii)	__bytes__decoder   s    r    __str__zSSHChannel.__str__T   s     ~~&&w///r   c                 <    | j         }|sd}d|| j        | j        fz  S )zD
        Return a byte string representation of the channel
        s   Nones   <SSHChannel %b (lw %d rw %d)>)r	   r   r   )r   r	   s     r    r%   zSSHChannel.__bytes__W   s9     y 	D/ !3
 
 	
r   c                     | j         d urt          | j                   pd}| j        r| j                            d          }nd}d| d| d| j                                         S )Nunknownr$   NonezSSHChannel z (z) on )r   strr	   r&   r   	logPrefix)r   r   r	   s      r    r.   zSSHChannel.logPrefixe   sr    gT!2c$'ll@y9 	9##G,,DDDETEEREEdi.A.A.C.CEEEr   c                 :    | j                             d           dS )z
        Called when the channel is opened.  specificData is any data that the
        other side sent us when opening the channel.

        @type specificData: L{bytes}
        zchannel openN_loginfo)r   r   s     r    channelOpenzSSHChannel.channelOpenm   s     		~&&&&&r   c                 >    | j                             d|           dS )z
        Called when the open failed for some reason.
        reason.desc is a string descrption, reason.code the SSH error code.

        @type reason: L{error.ConchError}
        z(other side refused open
reason: {reason})reasonN)r1   error)r   r5   s     r    
openFailedzSSHChannel.openFailedv   s#     		CFSSSSSr   c                 4   | j         |z   | _         | j        s"| j        sd| _        |                                  | j        r#| j        }d| _        |                     |           | j        r,| j        }g | _        |D ]\  }}|                     ||           dS dS )z
        Called when bytes are added to the remote window.  By default it clears
        the data buffers.

        @type data:    L{bytes}
        Tr   N)r   r   r   startWritingr   writer   writeExtended)r   r   btypes       r    addWindowByteszSSHChannel.addWindowBytes   s     !% 5 < 	 t| 	 "DO8 	ADHJJqMMM; 	/ADK / /
d""4....		/ 	// /r   c                     |                     dd                              d          }t          | d|z   d          }|r ||          S | j                            d|           dS )	aJ  
        Called when a request is sent to this channel.  By default it delegates
        to self.request_<requestType>.
        If this function returns true, the request succeeded, otherwise it
        failed.

        @type requestType:  L{bytes}
        @type data:         L{bytes}
        @rtype:             L{bool}
           -   _r$   request_Nz#unhandled request for {requestType})requestTyper   )replacer&   getattrr1   r2   )r   rC   r   foofs        r    requestReceivedzSSHChannel.requestReceived   sp     !!$--44W==D*s*D11 	1T77N	<+VVVqr   c                 >    | j                             d|           dS )zL
        Called when we receive data.

        @type data: L{bytes}
        zgot data {data})r   Nr1   debugr   r   s     r    dataReceivedzSSHChannel.dataReceived   s#     		)55555r   c                 @    | j                             d||           dS )z
        Called when we receive extended data (usually standard error).

        @type dataType: L{int}
        @type data:     L{str}
        z%got extended data {dataType} {data!r})dataTyper   NrJ   r   rO   r   s      r    extReceivedzSSHChannel.extReceived   s2     		3hT 	 	
 	
 	
 	
 	
r   c                 :    | j                             d           dS )zD
        Called when the other side will send no more data.
        z
remote eofNr0   r'   s    r    eofReceivedzSSHChannel.eofReceived   s     		|$$$$$r   c                 b    | j                             d           |                                  dS )zD
        Called when the other side has closed the channel.
        zremote closeN)r1   r2   loseConnectionr'   s    r    closeReceivedzSSHChannel.closeReceived   s0     		~&&&r   c                 :    | j                             d           dS )z
        Called when the channel is closed.  This means that both our side and
        the remote side have closed the channel.
        closedNr0   r'   s    r    rX   zSSHChannel.closed   s    
 		x     r   c                    | j         r| xj         |z  c_         dS t          |          }|| j        k    rF|d| j                 || j        d         c}| _         d| _        |                                  | j        }| j        }| j        j        }t          d||          }|D ]} || ||||z                       | xj        |z  c_        | j	        r| j         s| 
                                 dS dS dS )z
        Write some data to the channel.  If there is not enough remote window
        available, buffer until it is.  Otherwise, split the data into
        packets of length remoteMaxPacket and send them.

        @type data: L{bytes}
        Nr   )r   lenr   r   stopWritingr   r   sendDataranger   rU   )r   r   toprmpr:   roffsets          r    r:   zSSHChannel.write   s4    8 	HHHHF$ii&&&,t,,-T*,,- D$(  DO'C"	"!S# 	5 	5FE$Vfsl234444$< 	" 	"!!!!!	" 	" 	" 	"r   c                    | j         rQ| j         d         d         |k    r| j         d         dxx         |z  cc<   n| j                             ||g           dS t          |          | j        k    rB|d| j                 ||| j        d         ggc}| _         d| _        |                                  t          |          | j        k    re| j                            | ||d| j                            || j        d         }| xj        | j        z  c_        t          |          | j        k    e|r9| j                            | ||           | xj        t          |          z  c_        | j	        r| 
                                 dS dS )a  
        Send extended data to this channel.  If there is not enough remote
        window available, buffer until there is.  Otherwise, split the data
        into packets of length remoteMaxPacket and send them.

        @type dataType: L{int}
        @type data:     L{bytes}
        r   r   N)r   appendrZ   r   r   r[   r   r   sendExtendedDatar   rU   rP   s      r    r;   zSSHChannel.writeExtended   s    ; 	{2q!X--B"""d*""""""Hd#3444Ft99t,,,,t,,-D!6!8!89:; D$+  DO$ii$...I&&tXt<Rd>R<R7STTT,../D!!T%99!! $ii$...  	/I&&tXt<<<!!SYY.!!< 	"!!!!!	" 	"r   c                 V    |                      d                    |                     dS )z
        Part of the Transport interface.  Write a list of strings to the
        channel.

        @type data: C{list} of L{str}
        r   N)r:   joinrL   s     r    writeSequencezSSHChannel.writeSequence
  s&     	

388D>>"""""r   c                 l    d| _         | j        s#| j        s| j                            |            dS dS dS )zr
        Close the channel if there is no buferred data.  Otherwise, note the
        request and return.
        r   N)r   r   r   r   	sendCloser'   s    r    rU   zSSHChannel.loseConnection  sN    
 x 	& 	&I%%%%%	& 	& 	& 	&r   c                 >    | j         j                                        S )z
        See: L{ITransport.getPeer}

        @return: The remote address of this connection.
        @rtype: L{SSHTransportAddress}.
        )r   	transportgetPeerr'   s    r    rm   zSSHChannel.getPeer       y"**,,,r   c                 >    | j         j                                        S )z
        See: L{ITransport.getHost}

        @return: An address describing this side of the connection.
        @rtype: L{SSHTransportAddress}.
        )r   rl   getHostr'   s    r    rp   zSSHChannel.getHost%  rn   r   c                     dS )z
        Called when the remote buffer is full, as a hint to stop writing.
        This can be ignored, but it can be helpful.
        N r'   s    r    r[   zSSHChannel.stopWriting.        r   c                     dS )ze
        Called when the remote buffer has more room, as a hint to continue
        writing.
        Nrr   r'   s    r    r9   zSSHChannel.startWriting4  rs   r   )r   r   r   r   NNN)__name__
__module____qualname____doc__r   r1   r	   bytes__annotations__r!   r-   r(   r%   r.   r3   r7   r>   rH   rM   rQ   rS   rV   rX   r:   r;   rh   rU   rm   rp   r[   r9   rr   r   r    r   r      s         @ 688DD%    60 0 0 0 0
5 
 
 
 
F F F' ' 'T T T/ / /*  $6 6 6	
 	
 	
% % %  ! ! !" " ":" " "@# # #& & &- - -- - -      r   r   N)rx   zope.interfacer   twisted.internetr   twisted.loggerr   twisted.pythonr   
ITransportr   rr   r   r    <module>r      s   
  ' & & & & & ' ' ' ' ' ' ! ! ! ! ! !       Z"##c c c c c c c $#c c cr   