Ignore:
Timestamp:
Apr 19, 2013 6:05:06 AM (11 years ago)
Author:
riza
Message:

Re #1643: Code restructure + modification to handle non blocking mode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib-util/src/pjlib-util/cli_telnet.c

    r4461 r4476  
    146146{ 
    147147    TRANSMIT_BINARY     = 0,    /* Transmit Binary. */ 
    148     ECHO                = 1,    /* Echo. */ 
     148    TERM_ECHO           = 1,    /* Echo. */ 
    149149    RECONNECT           = 2,    /* Reconnection. */ 
    150150    SUPPRESS_GA         = 3,    /* Suppress Go Aheah. */ 
     
    896896static pj_bool_t handle_alfa_num(cli_telnet_sess *sess, unsigned char *data) 
    897897{         
    898     if (is_local_option_state_ena(sess, ECHO)) { 
     898    if (is_local_option_state_ena(sess, TERM_ECHO)) { 
    899899        if (recv_buf_right_len(sess->rcmd) > 0) { 
    900900            /* Cursor is not at EOL, insert character */             
     
    10621062     
    10631063    status = pj_cli_sess_exec(&sess->base, (char *)&sess->rcmd->rbuf,  
    1064                               pool, &info);     
     1064                              pool, &info); 
    10651065 
    10661066    switch (status) { 
     
    16461646    set_peer_option(sess, STATUS, PJ_TRUE); 
    16471647    set_peer_option(sess, TIMING_MARK, PJ_TRUE); 
    1648     set_peer_option(sess, ECHO, PJ_TRUE);     
     1648    set_peer_option(sess, TERM_ECHO, PJ_TRUE); 
    16491649 
    16501650    send_cmd_do(sess, SUPPRESS_GA); 
    1651     send_cmd_will(sess, ECHO); 
     1651    send_cmd_will(sess, TERM_ECHO); 
    16521652    send_cmd_will(sess, STATUS);    
    16531653    send_cmd_will(sess, SUPPRESS_GA); 
     
    17281728 
    17291729    /* Start telnet daemon */ 
    1730     telnet_start(fe); 
     1730    status = telnet_start(fe); 
     1731    if (status != PJ_SUCCESS) 
     1732        goto on_exit; 
    17311733 
    17321734    pj_cli_register_front_end(cli, &fe->base); 
     
    17701772                                &val, sizeof(val)); 
    17711773 
    1772     if (status != PJ_SUCCESS) 
    1773         goto on_exit; 
     1774    if (status != PJ_SUCCESS) { 
     1775        PJ_LOG(3, (THIS_FILE, "Failed setting socket options")); 
     1776    } 
    17741777 
    17751778    /* The loop is silly, but what else can we do? */ 
     
    18341837    } 
    18351838 
    1836     /** Fill telnet information and call pj_cli_telnet_on_started callback */ 
     1839    return PJ_SUCCESS; 
     1840 
     1841on_exit: 
    18371842    if (fe->cfg.on_started) { 
    1838         char ip_addr[32]; 
    1839         pj_cli_telnet_info telnet_info; 
    1840         pj_sockaddr hostip; 
    1841  
    1842         telnet_info.ip_address.ptr = ip_addr; 
    1843         telnet_info.ip_address.slen = 0; 
    1844          
    1845         status = pj_gethostip(pj_AF_INET(), &hostip); 
    1846         if (status != PJ_SUCCESS) 
    1847             goto on_exit; 
    1848  
    1849         pj_strcpy2(&telnet_info.ip_address,  
    1850                    pj_inet_ntoa(hostip.ipv4.sin_addr)); 
    1851  
    1852         telnet_info.port = fe->cfg.port; 
    1853  
    1854         (*fe->cfg.on_started)(&telnet_info); 
    1855     } 
    1856  
    1857     return PJ_SUCCESS; 
    1858  
    1859 on_exit: 
     1843        (*fe->cfg.on_started)(status); 
     1844    } 
     1845 
    18601846    if (fe->asock) 
    18611847        pj_activesock_close(fe->asock); 
     
    19081894    /** Start Telnet **/ 
    19091895    status = telnet_start(fe); 
    1910     if (status == PJ_SUCCESS) 
     1896    if (status == PJ_SUCCESS) { 
     1897        if (fe->cfg.on_started) { 
     1898            (*fe->cfg.on_started)(status); 
     1899        } 
    19111900        TRACE_((THIS_FILE, "Telnet Restarted")); 
    1912      
     1901    } 
    19131902on_exit: 
    19141903    return status; 
    19151904} 
     1905 
     1906PJ_DEF(pj_status_t) pj_cli_telnet_get_info(pj_cli_front_end *fe,  
     1907                                           pj_cli_telnet_info *info) 
     1908{ 
     1909    pj_sockaddr hostip; 
     1910    pj_status_t status; 
     1911    cli_telnet_fe *tfe = (cli_telnet_fe*) fe;  
     1912 
     1913    PJ_ASSERT_RETURN(fe && (fe->type == PJ_CLI_TELNET_FRONT_END) && info,  
     1914                     PJ_EINVAL); 
     1915 
     1916    pj_strset(&info->ip_address, info->buf_, 0); 
     1917 
     1918    status = pj_gethostip(pj_AF_INET(), &hostip); 
     1919    if (status != PJ_SUCCESS) 
     1920        return status; 
     1921 
     1922    pj_strcpy2(&info->ip_address, pj_inet_ntoa(hostip.ipv4.sin_addr)); 
     1923 
     1924    info->port = tfe->cfg.port; 
     1925 
     1926    return PJ_SUCCESS; 
     1927} 
Note: See TracChangeset for help on using the changeset viewer.