Changeset 7485 for lang/c

Show
Ignore:
Timestamp:
03/05/08 13:57:16 (5 years ago)
Author:
frsyuki
Message:

lang/c/partty: send SB OPT_NAWS only when the tenlnet client supports it

Location:
lang/c/partty/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • lang/c/partty/trunk/emtelnet.cc

    r7417 r7485  
    124124{ 
    125125        owrite3(IAC, SB, cmd); 
    126         owrite((const byte*)msg, len); 
     126        // don't send IAC alone 
     127#ifdef EMTELNET_CONVERT_CRLF_LF 
     128        // don't convert CRLF to LF 
     129        const byte* p = (const byte*)msg; 
     130        const byte* endp = p + len; 
     131        for(; p != endp; ++p) { 
     132                if( *p == IAC ) { 
     133                        owrite2(IAC, IAC); 
     134                } else { 
     135                        owrite1(*p); 
     136                } 
     137        } 
     138#else 
     139        send(msg, len); 
     140#endif 
    127141        owrite2(IAC, SE); 
    128142} 
  • lang/c/partty/trunk/host.cc

    r7473 r7485  
    219219        } else if( len == 0 ) { throw io_end_error("server connection closed"); } 
    220220        // ロック中ならServerからの入力は捨てる 
    221         if( m_locking ) { return 0; } 
     221        if( m_locking ) { return 0; }  // XXX Telnetの返答も無視している 
    222222        // Telnetフィルタ 
    223223        m_telnet.recv(shared_buffer, len); 
  • lang/c/partty/trunk/multiplexer.cc

    r7472 r7485  
    1919// FIXME perror -> ログ 
    2020 
    21 filt_telnetd::filt_telnetd() : 
     21filt_telnetd::filt_telnetd(sender_telnetd& host_telnet) : 
    2222                emtelnet((void*)this), 
    23                 m_enable_ws(true)  // XXX デフォルトtrue 
     23                m_host_telnet(host_telnet), 
     24                m_enable_ws(false) 
    2425{ 
    2526        // use these options 
     
    6061void filt_telnetd::enable_ws_handler(char cmd, bool sw, emtelnet& base) 
    6162{ 
    62         static_cast<filt_telnetd&>(base).m_enable_ws = sw; 
     63        filt_telnetd& self( static_cast<filt_telnetd&>(base) ); 
     64        self.m_enable_ws = sw; 
     65        if(sw) { 
     66                sender_telnetd& host( self.m_host_telnet ); 
     67                if( host.ws_initialized() ) { 
     68                        // 初期ウィンドウサイズを設定 
     69                        if( host.ws_initialized() ) { 
     70                                char sbbuf[4]; 
     71                                *((short*)sbbuf) = htons(host.get_rows()); 
     72                                *((short*)(sbbuf+2)) = htons(host.get_cols()); 
     73                                self.send_ws(sbbuf, sizeof(sbbuf)); 
     74                        } 
     75                } 
     76        } 
    6377} 
    6478 
     
    250264                return 0; 
    251265        } 
    252         guest_set.set(guest); 
     266        guest_set.set<sender_telnetd&>(guest, m_host_telnet); 
    253267        // 書き込み待ちバッファにSERVER_WELCOME_MESSAGEを加える 
    254268        guest_set.data(guest).send(SERVER_WELCOME_MESSAGE, strlen(SERVER_WELCOME_MESSAGE), NULL); 
    255269        num_guest++; 
    256         // 初期ウィンドウサイズを設定 
    257         if( m_host_telnet.ws_initialized() ) { 
    258                 char sbbuf[4]; 
    259                 *((short*)sbbuf) = htons(m_host_telnet.get_rows()); 
    260                 *((short*)(sbbuf+2)) = htons(m_host_telnet.get_cols()); 
    261                 guest_set.data(guest).send_ws(sbbuf, sizeof(sbbuf)); 
    262         } 
    263270        return 0; 
    264271} 
  • lang/c/partty/trunk/multiplexer.h

    r7417 r7485  
    88namespace Partty { 
    99 
     10class sender_telnetd : public emtelnet { 
     11public: 
     12        sender_telnetd(); 
     13private: 
     14        static void pass_through_handler(char cmd, bool sw, emtelnet& base) {} 
     15        static void window_size_handler(char cmd, const char* msg, size_t len, emtelnet& self); 
     16public: 
     17        void ws_change(short cols, short rows) { 
     18                m_cols = cols; 
     19                m_rows = rows; 
     20                m_ws_changed = true; 
     21        } 
     22        bool ws_changed(void) const { return m_ws_changed; } 
     23        short get_cols(void) const { return m_cols; } 
     24        short get_rows(void) const { return m_rows; } 
     25        void ws_flush(void) { m_ws_changed = false; } 
     26        bool ws_initialized(void) const { return (m_cols != 0 && m_rows != 0); } 
     27private: 
     28        short m_cols; 
     29        short m_rows; 
     30        bool m_ws_changed; 
     31}; 
     32 
     33 
    1034class filt_telnetd : public emtelnet { 
    1135public: 
     
    1539        }; 
    1640public: 
    17         filt_telnetd(); 
     41        explicit filt_telnetd(sender_telnetd& host_telnet); 
    1842        inline void send(const void* buf, size_t len, buffer_t* out); 
    1943        inline void recv(const void* buf, size_t len, buffer_t* in, buffer_t* out); 
     
    3155        static void pass_through_handler(char cmd, bool sw, emtelnet& base) {} 
    3256        static void enable_ws_handler(char cmd, bool sw, emtelnet& base); 
     57        sender_telnetd& m_host_telnet; 
    3358        bool m_enable_ws; 
    3459}; 
     
    6994        out->len = olength; 
    7095} 
    71  
    72  
    73 class sender_telnetd : public emtelnet { 
    74 public: 
    75         sender_telnetd(); 
    76 private: 
    77         static void pass_through_handler(char cmd, bool sw, emtelnet& base) {} 
    78         static void window_size_handler(char cmd, const char* msg, size_t len, emtelnet& self); 
    79 public: 
    80         void ws_change(short cols, short rows) { 
    81                 m_cols = cols; 
    82                 m_rows = rows; 
    83                 m_ws_changed = true; 
    84         } 
    85         bool ws_changed(void) const { return m_ws_changed; } 
    86         short get_cols(void) const { return m_cols; } 
    87         short get_rows(void) const { return m_rows; } 
    88         void ws_flush(void) { m_ws_changed = false; } 
    89         bool ws_initialized(void) const { return (m_cols != 0 && m_rows != 0); } 
    90 private: 
    91         short m_cols; 
    92         short m_rows; 
    93         bool m_ws_changed; 
    94 }; 
    9596 
    9697