Ignore:
Timestamp:
Feb 4, 2014 10:13:56 AM (10 years ago)
Author:
bennylp
Message:

Misc (re #1630): Fixing warnings about variable set but not used with recent gcc

File:
1 edited

Legend:

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

    r4537 r4728  
    3737    (defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE!=0) 
    3838 
    39 #define EADDRINUSE WSAEADDRINUSE  
     39#define EADDRINUSE WSAEADDRINUSE 
    4040 
    4141#endif 
     
    6767 * This specify the state for the telnet option negotiation. 
    6868 */ 
    69 enum cli_telnet_option_states  
    70 {     
     69enum cli_telnet_option_states 
     70{ 
    7171    OPT_DISABLE,                /* Option disable */ 
    7272    OPT_ENABLE,                 /* Option enable */ 
    7373    OPT_EXPECT_DISABLE,         /* Already send disable req, expecting resp */ 
    7474    OPT_EXPECT_ENABLE,          /* Already send enable req, expecting resp */ 
    75     OPT_EXPECT_DISABLE_REV,     /* Already send disable req, expecting resp,  
     75    OPT_EXPECT_DISABLE_REV,     /* Already send disable req, expecting resp, 
    7676                                 * need to send enable req */ 
    7777    OPT_EXPECT_ENABLE_REV       /* Already send enable req, expecting resp, 
     
    199199}; 
    200200 
    201 enum terminal_cmd  
     201enum terminal_cmd 
    202202{ 
    203203    TC_ESC              = 27, 
     
    207207    TC_LEFT             = 68, 
    208208    TC_END              = 70, 
    209     TC_HOME             = 72,     
     209    TC_HOME             = 72, 
    210210    TC_CTRL_C           = 3, 
    211211    TC_CR               = 13, 
     
    229229 
    230230/** 
    231  * This structure contains the command line shown to the user.  
    232  * The telnet also needs to maintain and manage command cursor position.  
     231 * This structure contains the command line shown to the user. 
     232 * The telnet also needs to maintain and manage command cursor position. 
    233233 * Due to that reason, the insert/delete character process from buffer will 
    234234 * consider its current cursor position. 
     
    252252 
    253253/** 
    254  * This structure contains the command history executed by user.  
     254 * This structure contains the command history executed by user. 
    255255 * Besides storing the command history, it is necessary to be able 
    256256 * to browse it. 
     
    291291    pj_thread_t            *worker_thread; 
    292292    pj_bool_t               is_quitting; 
    293     pj_mutex_t             *mutex;     
     293    pj_mutex_t             *mutex; 
    294294} cli_telnet_fe; 
    295295 
     
    305305 
    306306/** 
    307  * Return the number of characters between the current cursor position  
     307 * Return the number of characters between the current cursor position 
    308308 * to the end of line. 
    309309 */ 
     
    314314 
    315315/** 
    316  * Insert character to the receive buffer.  
    317  */ 
    318 static pj_bool_t recv_buf_insert(telnet_recv_buf *recv_buf,  
    319                                  unsigned char *data)  
    320 {     
     316 * Insert character to the receive buffer. 
     317 */ 
     318static pj_bool_t recv_buf_insert(telnet_recv_buf *recv_buf, 
     319                                 unsigned char *data) 
     320{ 
    321321    if (recv_buf->len+1 >= PJ_CLI_MAX_CMDBUF) { 
    322322        return PJ_FALSE; 
    323     } else {     
     323    } else { 
    324324        if (*data == '\t' || *data == '?' || *data == '\r') { 
    325325            /* Always insert to the end of line */ 
     
    328328            /* Insert based on the current cursor pos */ 
    329329            unsigned cur_pos = recv_buf->cur_pos; 
    330             unsigned rlen = recv_buf_right_len(recv_buf);            
    331             if (rlen > 0) {                  
     330            unsigned rlen = recv_buf_right_len(recv_buf); 
     331            if (rlen > 0) { 
    332332                /* Shift right characters */ 
    333                 pj_memmove(&recv_buf->rbuf[cur_pos+1],  
    334                            &recv_buf->rbuf[cur_pos],  
     333                pj_memmove(&recv_buf->rbuf[cur_pos+1], 
     334                           &recv_buf->rbuf[cur_pos], 
    335335                           rlen+1); 
    336             }  
     336            } 
    337337            recv_buf->rbuf[cur_pos] = *data; 
    338338        } 
     
    356356            unsigned cur_pos = recv_buf->cur_pos; 
    357357            /* Shift left characters */ 
    358             pj_memmove(&recv_buf->rbuf[cur_pos-1], &recv_buf->rbuf[cur_pos],  
     358            pj_memmove(&recv_buf->rbuf[cur_pos-1], &recv_buf->rbuf[cur_pos], 
    359359                       rlen); 
    360360        } 
     
    362362        --recv_buf->len; 
    363363        recv_buf->rbuf[recv_buf->len] = 0; 
    364     }     
     364    } 
    365365    return PJ_TRUE; 
    366366} 
     
    373373 
    374374/** 
    375  * Insert the command to history. If the entered command is not on the list,  
    376  * a new entry will be created. All entered command will be moved to  
    377  * the first entry of the history.  
    378  */ 
    379 static pj_status_t insert_history(cli_telnet_sess *sess,                                  
     375 * Insert the command to history. If the entered command is not on the list, 
     376 * a new entry will be created. All entered command will be moved to 
     377 * the first entry of the history. 
     378 */ 
     379static pj_status_t insert_history(cli_telnet_sess *sess, 
    380380                                  char *cmd_val) 
    381381{ 
     
    393393    in_history = pj_list_search(sess->history, (void*)&cmd, compare_str); 
    394394    if (!in_history) { 
    395         if (pj_list_size(sess->history) < PJ_CLI_MAX_CMD_HISTORY) {          
     395        if (pj_list_size(sess->history) < PJ_CLI_MAX_CMD_HISTORY) { 
    396396            char *data_history; 
    397397            in_history = PJ_POOL_ZALLOC_T(sess->pool, cmd_history); 
    398398            pj_list_init(in_history); 
    399             data_history = (char *)pj_pool_calloc(sess->pool,  
     399            data_history = (char *)pj_pool_calloc(sess->pool, 
    400400                           sizeof(char), PJ_CLI_MAX_CMDBUF); 
    401401            in_history->command.ptr = data_history; 
     
    404404            /* Get the oldest history */ 
    405405            in_history = sess->history->prev; 
    406         }            
     406        } 
    407407    } else { 
    408408        pj_list_insert_nodes_after(in_history->prev, in_history->next); 
     
    416416 
    417417/** 
    418  * Get the next or previous history of the shown/active history.  
     418 * Get the next or previous history of the shown/active history. 
    419419 */ 
    420420static pj_str_t* get_prev_history(cli_telnet_sess *sess, pj_bool_t is_forward) 
     
    434434        return NULL; 
    435435    } else { 
    436         if (is_forward) {            
    437             node = (node->next==root)?node->next->next:node->next;           
     436        if (is_forward) { 
     437            node = (node->next==root)?node->next->next:node->next; 
    438438        } else { 
    439             node = (node->prev==root)?node->prev->prev:node->prev;           
     439            node = (node->prev==root)?node->prev->prev:node->prev; 
    440440        } 
    441441        retval = &node->command; 
     
    451451 * referenced - (RFC-854). 
    452452 */ 
    453 static pj_bool_t send_telnet_cmd(cli_telnet_sess *sess,  
    454                                  cli_telnet_command cmd,  
     453static pj_bool_t send_telnet_cmd(cli_telnet_sess *sess, 
     454                                 cli_telnet_command cmd, 
    455455                                 unsigned char option) 
    456 {        
     456{ 
    457457    unsigned char buf[3]; 
    458458    PJ_ASSERT_RETURN(sess, PJ_FALSE); 
     
    470470 * For local option: send WILL. 
    471471 * For remote option: send DO. 
    472  * This method also handle the state transition of the ENABLE  
     472 * This method also handle the state transition of the ENABLE 
    473473 * negotiation process. 
    474474 */ 
    475 static pj_bool_t send_enable_option(cli_telnet_sess *sess,  
    476                                     pj_bool_t is_local,  
     475static pj_bool_t send_enable_option(cli_telnet_sess *sess, 
     476                                    pj_bool_t is_local, 
    477477                                    unsigned char option) 
    478478{ 
     
    500500            *state = OPT_EXPECT_ENABLE; 
    501501            break; 
    502         case OPT_EXPECT_DISABLE_REV:         
     502        case OPT_EXPECT_DISABLE_REV: 
    503503            *state = OPT_DISABLE; 
    504504            break; 
     
    509509} 
    510510 
    511 static pj_bool_t send_cmd_do(cli_telnet_sess *sess,  
     511static pj_bool_t send_cmd_do(cli_telnet_sess *sess, 
    512512                             unsigned char option) 
    513513{ 
     
    515515} 
    516516 
    517 static pj_bool_t send_cmd_will(cli_telnet_sess *sess,  
     517static pj_bool_t send_cmd_will(cli_telnet_sess *sess, 
    518518                               unsigned char option) 
    519519{ 
     
    523523/** 
    524524 * This method will handle receiving telnet's ENABLE option negotiation. 
    525  * This method also handle the state transition of the ENABLE  
    526  * negotiation process.  
    527  */ 
    528 static pj_bool_t receive_enable_option(cli_telnet_sess *sess,  
    529                                        pj_bool_t is_local,  
     525 * This method also handle the state transition of the ENABLE 
     526 * negotiation process. 
     527 */ 
     528static pj_bool_t receive_enable_option(cli_telnet_sess *sess, 
     529                                       pj_bool_t is_local, 
    530530                                       unsigned char option) 
    531531{ 
     
    550550            } 
    551551            break; 
    552         case OPT_EXPECT_ENABLE:      
     552        case OPT_EXPECT_ENABLE: 
    553553            *state = OPT_ENABLE; 
    554554            break; 
    555         case OPT_EXPECT_DISABLE:             
     555        case OPT_EXPECT_DISABLE: 
    556556            *state = OPT_DISABLE; 
    557557            break; 
    558558        case OPT_EXPECT_ENABLE_REV: 
    559559            *state = OPT_EXPECT_DISABLE; 
    560             send_telnet_cmd(sess, is_local?WONT:DONT, option);       
     560            send_telnet_cmd(sess, is_local?WONT:DONT, option); 
    561561            break; 
    562562        case OPT_EXPECT_DISABLE_REV: 
     
    566566            return PJ_FALSE; 
    567567    } 
    568     return PJ_TRUE;         
     568    return PJ_TRUE; 
    569569} 
    570570 
    571571/** 
    572572 * This method will handle receiving telnet's DISABLE option negotiation. 
    573  * This method also handle the state transition of the DISABLE  
    574  * negotiation process.  
    575  */ 
    576 static pj_bool_t receive_disable_option(cli_telnet_sess *sess,  
    577                                         pj_bool_t is_local,  
     573 * This method also handle the state transition of the DISABLE 
     574 * negotiation process. 
     575 */ 
     576static pj_bool_t receive_disable_option(cli_telnet_sess *sess, 
     577                                        pj_bool_t is_local, 
    578578                                        unsigned char option) 
    579579{ 
     
    585585    sess_opt = &sess->telnet_option[option]; 
    586586    state = is_local?(&sess_opt->local_state):(&sess_opt->peer_state); 
    587      
     587 
    588588    switch (*state) { 
    589589        case OPT_ENABLE: 
     
    595595            /* Ignore if already enabled */ 
    596596            break; 
    597         case OPT_EXPECT_ENABLE:      
     597        case OPT_EXPECT_ENABLE: 
    598598        case OPT_EXPECT_DISABLE: 
    599599            *state = OPT_DISABLE; 
     
    601601        case OPT_EXPECT_ENABLE_REV: 
    602602            *state = OPT_DISABLE; 
    603             send_telnet_cmd(sess, is_local?WONT:DONT, option);       
     603            send_telnet_cmd(sess, is_local?WONT:DONT, option); 
    604604            break; 
    605605        case OPT_EXPECT_DISABLE_REV: 
     
    610610            return PJ_FALSE; 
    611611    } 
    612     return PJ_TRUE;        
     612    return PJ_TRUE; 
    613613} 
    614614 
     
    633633} 
    634634 
    635 static void set_local_option(cli_telnet_sess *sess,  
    636                              unsigned char option,  
    637                              pj_bool_t enable)  
     635static void set_local_option(cli_telnet_sess *sess, 
     636                             unsigned char option, 
     637                             pj_bool_t enable) 
    638638{ 
    639639    sess->telnet_option[option].local_is_enable = enable; 
    640640} 
    641641 
    642 static void set_peer_option(cli_telnet_sess *sess,  
    643                             unsigned char option,  
    644                             pj_bool_t enable)  
     642static void set_peer_option(cli_telnet_sess *sess, 
     643                            unsigned char option, 
     644                            pj_bool_t enable) 
    645645{ 
    646646    sess->telnet_option[option].peer_is_enable = enable; 
    647647} 
    648648 
    649 static pj_bool_t is_local_option_state_ena(cli_telnet_sess *sess,  
     649static pj_bool_t is_local_option_state_ena(cli_telnet_sess *sess, 
    650650                                           unsigned char option) 
    651 {     
     651{ 
    652652    return (sess->telnet_option[option].local_state == OPT_ENABLE); 
    653653} 
    654654 
    655 static void send_return_key(cli_telnet_sess *sess)  
    656 {     
     655static void send_return_key(cli_telnet_sess *sess) 
     656{ 
    657657    telnet_sess_send2(sess, (unsigned char*)"\r\n", 2); 
    658658} 
     
    671671    send_data.ptr = data_str; 
    672672    send_data.slen = 0; 
    673      
     673 
    674674    pj_strcat(&send_data, &fe->cfg.prompt_str); 
    675675 
     
    681681 * the error position of the source command. 
    682682 */ 
    683 static void send_err_arg(cli_telnet_sess *sess,  
    684                          const pj_cli_exec_info *info,  
     683static void send_err_arg(cli_telnet_sess *sess, 
     684                         const pj_cli_exec_info *info, 
    685685                         const pj_str_t *msg, 
    686686                         pj_bool_t with_return, 
     
    715715} 
    716716 
    717 static void send_inv_arg(cli_telnet_sess *sess,  
     717static void send_inv_arg(cli_telnet_sess *sess, 
    718718                         const pj_cli_exec_info *info, 
    719719                         pj_bool_t with_return, 
     
    724724} 
    725725 
    726 static void send_too_many_arg(cli_telnet_sess *sess,  
     726static void send_too_many_arg(cli_telnet_sess *sess, 
    727727                              const pj_cli_exec_info *info, 
    728728                              pj_bool_t with_return, 
     
    733733} 
    734734 
    735 static void send_hint_arg(cli_telnet_sess *sess,  
    736                           pj_str_t *send_data,  
     735static void send_hint_arg(cli_telnet_sess *sess, 
     736                          pj_str_t *send_data, 
    737737                          const pj_str_t *desc, 
    738738                          pj_ssize_t cmd_len, 
     
    756756 * is ambiguous. It will show the matching command as the hint information. 
    757757 */ 
    758 static void send_ambi_arg(cli_telnet_sess *sess,  
     758static void send_ambi_arg(cli_telnet_sess *sess, 
    759759                          const pj_cli_exec_info *info, 
    760760                          pj_bool_t with_return, 
     
    770770    pj_ssize_t max_length = 0; 
    771771    pj_ssize_t cmd_length = 0; 
    772     const pj_str_t *cmd_desc = 0; 
    773772    static const pj_str_t sc_type = {"sc", 2}; 
    774773    static const pj_str_t choice_type = {"choice", 6}; 
    775774    send_data.ptr = data; 
    776775    send_data.slen = 0; 
    777      
     776 
    778777    if (with_return) 
    779778        pj_strcat2(&send_data, "\r\n"); 
     
    787786    /* Get the max length of the command name */ 
    788787    for (i=0;i<info->hint_cnt;++i) { 
    789         if ((&hint[i].type) && (hint[i].type.slen > 0)) {            
    790             if (pj_stricmp(&hint[i].type, &sc_type) == 0) {              
     788        if ((&hint[i].type) && (hint[i].type.slen > 0)) { 
     789            if (pj_stricmp(&hint[i].type, &sc_type) == 0) { 
    791790                if ((i > 0) && (!pj_stricmp(&hint[i-1].desc, &hint[i].desc))) { 
    792791                    cmd_length += (hint[i].name.slen + 3); 
    793792                } else { 
    794793                    cmd_length = hint[i].name.slen; 
    795                 }                
     794                } 
    796795            } else { 
    797796                cmd_length = hint[i].name.slen; 
    798797            } 
    799         } else {                     
     798        } else { 
    800799            cmd_length = hint[i].name.slen; 
    801800        } 
     
    805804        } 
    806805    } 
    807      
     806 
    808807    cmd_length = 0; 
    809808    /* Build hint information */ 
    810     for (i=0;i<info->hint_cnt;++i) {                     
    811         if ((&hint[i].type) && (hint[i].type.slen > 0)) {            
     809    for (i=0;i<info->hint_cnt;++i) { 
     810        if ((&hint[i].type) && (hint[i].type.slen > 0)) { 
    812811            if (pj_stricmp(&hint[i].type, &sc_type) == 0) { 
    813812                parse_state = OP_SHORTCUT; 
     
    817816                parse_state = OP_TYPE; 
    818817            } 
    819         } else {                     
     818        } else { 
    820819            parse_state = OP_NORMAL; 
    821820        } 
    822          
     821 
    823822        if (parse_state != OP_SHORTCUT) { 
    824823            pj_strcat2(&send_data, "\r\n  "); 
    825824            cmd_length = hint[i].name.slen; 
    826         }            
    827          
     825        } 
     826 
    828827        switch (parse_state) { 
    829828        case OP_CHOICE: 
    830             /* Format : "[Choice Value]  description" */             
     829            /* Format : "[Choice Value]  description" */ 
    831830            pj_strcat2(&send_data, "["); 
    832831            pj_strcat(&send_data, &hint[i].name); 
    833             pj_strcat2(&send_data, "]");         
     832            pj_strcat2(&send_data, "]"); 
    834833            break; 
    835834        case OP_TYPE: 
     
    837836            pj_strcat2(&send_data, "<"); 
    838837            pj_strcat(&send_data, &hint[i].name); 
    839             pj_strcat2(&send_data, ">");         
     838            pj_strcat2(&send_data, ">"); 
    840839            break; 
    841840        case OP_SHORTCUT: 
    842841            /* Format : "Command | sc |  description" */ 
    843             {            
     842            { 
    844843                cmd_length += hint[i].name.slen; 
    845844                if ((i > 0) && (!pj_stricmp(&hint[i-1].desc, &hint[i].desc))) { 
    846845                    pj_strcat2(&send_data, " | "); 
    847                     cmd_length += 3;                 
     846                    cmd_length += 3; 
    848847                } else { 
    849848                    pj_strcat2(&send_data, "\r\n  "); 
    850849                } 
    851                 pj_strcat(&send_data, &hint[i].name);    
     850                pj_strcat(&send_data, &hint[i].name); 
    852851            } 
    853852            break; 
     
    855854            /* Command */ 
    856855            pj_strcat(&send_data, &hint[i].name); 
    857             cmd_desc = &hint[i].desc;        
    858             break; 
    859         } 
    860          
    861         if ((parse_state == OP_TYPE) || (parse_state == OP_CHOICE) ||  
     856            break; 
     857        } 
     858 
     859        if ((parse_state == OP_TYPE) || (parse_state == OP_CHOICE) || 
    862860            ((i+1) >= info->hint_cnt) || 
    863             (pj_strncmp(&hint[i].desc, &hint[i+1].desc, hint[i].desc.slen)))  
     861            (pj_strncmp(&hint[i].desc, &hint[i+1].desc, hint[i].desc.slen))) 
    864862        { 
    865863            /* Add description info */ 
    866             send_hint_arg(sess, &send_data,  
    867                           &hint[i].desc, cmd_length,  
     864            send_hint_arg(sess, &send_data, 
     865                          &hint[i].desc, cmd_length, 
    868866                          max_length); 
    869867 
    870868            cmd_length = 0; 
    871         }        
    872     }   
    873     pj_strcat2(&send_data, "\r\n");        
     869        } 
     870    } 
     871    pj_strcat2(&send_data, "\r\n"); 
    874872    pj_strcat(&send_data, &fe->cfg.prompt_str); 
    875873    if (with_last_cmd) 
    876874        pj_strcat2(&send_data, (char *)sess->rcmd->rbuf); 
    877875 
    878     telnet_sess_send(sess, &send_data);     
     876    telnet_sess_send(sess, &send_data); 
    879877} 
    880878 
     
    882880 * This method is to send command completion of the entered command. 
    883881 */ 
    884 static void send_comp_arg(cli_telnet_sess *sess,  
     882static void send_comp_arg(cli_telnet_sess *sess, 
    885883                          pj_cli_exec_info *info) 
    886884{ 
     
    893891    send_data.slen = 0; 
    894892 
    895     pj_strcat(&send_data, &info->hint[0].name);         
     893    pj_strcat(&send_data, &info->hint[0].name); 
    896894 
    897895    telnet_sess_send(sess, &send_data); 
     
    902900 */ 
    903901static pj_bool_t handle_alfa_num(cli_telnet_sess *sess, unsigned char *data) 
    904 {         
     902{ 
    905903    if (is_local_option_state_ena(sess, TERM_ECHO)) { 
    906904        if (recv_buf_right_len(sess->rcmd) > 0) { 
    907             /* Cursor is not at EOL, insert character */             
     905            /* Cursor is not at EOL, insert character */ 
    908906            unsigned char echo[5] = {0x1b, 0x5b, 0x31, 0x40, 0x00}; 
    909907            echo[4] = *data; 
     
    914912        } 
    915913        return PJ_TRUE; 
    916     }  
     914    } 
    917915    return PJ_FALSE; 
    918916} 
     
    926924    if (recv_buf_backspace(sess->rcmd)) { 
    927925        if (rlen) { 
    928             /*  
    929              * Cursor is not at the end of line, move the characters  
     926            /* 
     927             * Cursor is not at the end of line, move the characters 
    930928             * after the cursor to left 
    931929             */ 
     
    934932            telnet_sess_send2(sess, echo, 5); 
    935933        } else { 
    936             const static unsigned char echo[3] = {0x08, 0x20, 0x08};         
     934            const static unsigned char echo[3] = {0x08, 0x20, 0x08}; 
    937935            telnet_sess_send2(sess, echo, 3); 
    938936        } 
     
    942940} 
    943941 
    944 /*  
    945  * Syntax error handler for parser.  
     942/* 
     943 * Syntax error handler for parser. 
    946944 */ 
    947945static void on_syntax_error(pj_scanner *scanner) 
     
    958956    pj_scanner scanner; 
    959957    PJ_USE_EXCEPTION; 
    960     pj_scan_init(&scanner, cmd->ptr, cmd->slen, PJ_SCAN_AUTOSKIP_WS,  
     958    pj_scan_init(&scanner, cmd->ptr, cmd->slen, PJ_SCAN_AUTOSKIP_WS, 
    961959                 &on_syntax_error); 
    962960    PJ_TRY { 
     
    966964    } 
    967965    PJ_CATCH_ANY { 
    968         pj_scan_fini(&scanner);  
     966        pj_scan_fini(&scanner); 
    969967        return PJ_GET_EXCEPTION(); 
    970968    } 
     
    981979    pj_bool_t retval = PJ_TRUE; 
    982980    unsigned len; 
    983      
     981 
    984982    pj_pool_t *pool; 
    985983    pj_cli_cmd_val *cmd_val; 
     
    990988 
    991989    cmd_val = PJ_POOL_ZALLOC_T(pool, pj_cli_cmd_val); 
    992      
    993     status = pj_cli_sess_parse(&sess->base, (char *)&sess->rcmd->rbuf, cmd_val,  
    994                                pool, &info);     
     990 
     991    status = pj_cli_sess_parse(&sess->base, (char *)&sess->rcmd->rbuf, cmd_val, 
     992                               pool, &info); 
    995993 
    996994    len = (unsigned)pj_ansi_strlen((char *)sess->rcmd->rbuf); 
     
    998996    switch (status) { 
    999997    case PJ_CLI_EINVARG: 
    1000         send_inv_arg(sess, &info, PJ_TRUE, PJ_TRUE);             
     998        send_inv_arg(sess, &info, PJ_TRUE, PJ_TRUE); 
    1001999        break; 
    10021000    case PJ_CLI_ETOOMANYARGS: 
     
    10151013            telnet_sess_send2(sess, data_sent, rlen); 
    10161014        } 
    1017         if (info.hint_cnt > 0) {         
     1015        if (info.hint_cnt > 0) { 
    10181016            /* Complete command */ 
    10191017            pj_str_t cmd = pj_str((char *)sess->rcmd->rbuf); 
     
    10261024                if (hint_info->slen >= last_token.slen) { 
    10271025                    hint_info->slen -= last_token.slen; 
    1028                     pj_memmove(hint_info->ptr,  
    1029                                &hint_info->ptr[last_token.slen],  
    1030                                hint_info->slen);                     
    1031                 }  
     1026                    pj_memmove(hint_info->ptr, 
     1027                               &hint_info->ptr[last_token.slen], 
     1028                               hint_info->slen); 
     1029                } 
    10321030                send_comp_arg(sess, &info); 
    10331031 
    1034                 pj_memcpy(&sess->rcmd->rbuf[len], info.hint[0].name.ptr,  
     1032                pj_memcpy(&sess->rcmd->rbuf[len], info.hint[0].name.ptr, 
    10351033                          info.hint[0].name.slen); 
    10361034 
    10371035                len += (unsigned)info.hint[0].name.slen; 
    1038                 sess->rcmd->rbuf[len] = 0;                   
     1036                sess->rcmd->rbuf[len] = 0; 
    10391037            } 
    10401038        } else { 
     
    10461044    sess->rcmd->cur_pos = sess->rcmd->len; 
    10471045 
    1048     pj_pool_release(pool);       
    1049     return retval;  
     1046    pj_pool_release(pool); 
     1047    return retval; 
    10501048} 
    10511049 
     
    10571055    pj_status_t status; 
    10581056    pj_bool_t retval = PJ_TRUE; 
    1059      
    1060     pj_pool_t *pool;     
    1061     pj_cli_exec_info info;     
    1062      
     1057 
     1058    pj_pool_t *pool; 
     1059    pj_cli_exec_info info; 
     1060 
    10631061    send_return_key(sess); 
    10641062    insert_history(sess, (char *)&sess->rcmd->rbuf); 
     
    10661064    pool = pj_pool_create(sess->pool->factory, "handle_return", 
    10671065                          PJ_CLI_TELNET_POOL_SIZE, PJ_CLI_TELNET_POOL_INC, 
    1068                           NULL);     
    1069      
    1070     status = pj_cli_sess_exec(&sess->base, (char *)&sess->rcmd->rbuf,  
     1066                          NULL); 
     1067 
     1068    status = pj_cli_sess_exec(&sess->base, (char *)&sess->rcmd->rbuf, 
    10711069                              pool, &info); 
    10721070 
    10731071    switch (status) { 
    10741072    case PJ_CLI_EINVARG: 
    1075         send_inv_arg(sess, &info, PJ_FALSE, PJ_FALSE);   
     1073        send_inv_arg(sess, &info, PJ_FALSE, PJ_FALSE); 
    10761074        break; 
    10771075    case PJ_CLI_ETOOMANYARGS: 
     
    10881086        send_prompt_str(sess); 
    10891087        break; 
    1090     }     
     1088    } 
    10911089    if (retval) { 
    10921090        sess->rcmd->rbuf[0] = 0; 
     
    10951093    } 
    10961094 
    1097     pj_pool_release(pool);       
    1098     return retval;  
     1095    pj_pool_release(pool); 
     1096    return retval; 
    10991097} 
    11001098 
     
    11061104    if (recv_buf_right_len(sess->rcmd)) { 
    11071105        unsigned char *data = &sess->rcmd->rbuf[sess->rcmd->cur_pos++]; 
    1108         telnet_sess_send2(sess, data, 1);                
     1106        telnet_sess_send2(sess, data, 1); 
    11091107        return PJ_TRUE; 
    11101108    } 
     
    11161114 */ 
    11171115static pj_bool_t handle_left_key(cli_telnet_sess *sess) 
    1118 {     
     1116{ 
    11191117    static const unsigned char move_cursor_left = 0x08; 
    11201118    if (sess->rcmd->cur_pos) { 
     
    11511149            send_data.slen = sess->rcmd->cur_pos; 
    11521150        } 
    1153          
     1151 
    11541152        if (sess->rcmd->len > (unsigned)history->slen) { 
    11551153            /* Clear the command currently shown*/ 
     
    11591157 
    11601158            /* Move cursor position to the beginning of line */ 
    1161             pj_memset(&send_data.ptr[send_data.slen], MOVE_CURSOR_LEFT,  
     1159            pj_memset(&send_data.ptr[send_data.slen], MOVE_CURSOR_LEFT, 
    11621160                      buf_len); 
    11631161            send_data.slen += buf_len; 
    1164         }  
     1162        } 
    11651163        /* Send data */ 
    11661164        pj_strcat(&send_data, history); 
     
    11751173} 
    11761174 
    1177 static pj_status_t process_vt100_cmd(cli_telnet_sess *sess,  
     1175static pj_status_t process_vt100_cmd(cli_telnet_sess *sess, 
    11781176                                     unsigned char *cmd) 
    1179 {     
     1177{ 
    11801178    pj_status_t status = PJ_TRUE; 
    11811179    switch (*cmd) { 
     
    12251223} 
    12261224 
    1227 /*  
    1228  * Send a message to a telnet session  
     1225/* 
     1226 * Send a message to a telnet session 
    12291227 */ 
    12301228static pj_status_t telnet_sess_send(cli_telnet_sess *sess, 
     
    12411239 
    12421240    if (sess->buf_len == 0) 
    1243         status = pj_activesock_send(sess->asock, &sess->op_key,  
     1241        status = pj_activesock_send(sess->asock, &sess->op_key, 
    12441242                                    str->ptr, &sz, 0); 
    1245     /* If we cannot send now, append it at the end of the buffer  
     1243    /* If we cannot send now, append it at the end of the buffer 
    12461244     * to be sent later. 
    12471245     */ 
    1248     if (sess->buf_len > 0 ||  
     1246    if (sess->buf_len > 0 || 
    12491247        (status != PJ_SUCCESS && status != PJ_EPENDING)) 
    12501248    { 
     
    12731271} 
    12741272 
    1275 /*  
    1276  * Send a message to a telnet session with formatted text  
     1273/* 
     1274 * Send a message to a telnet session with formatted text 
    12771275 * (add single linefeed character with carriage return) 
    12781276 */ 
     
    12881286    PJ_USE_EXCEPTION; 
    12891287 
    1290     pj_scan_init(&scanner, str->ptr, str->slen,  
     1288    pj_scan_init(&scanner, str->ptr, str->slen, 
    12911289                 PJ_SCAN_AUTOSKIP_WS, &on_syntax_error); 
    1292      
     1290 
    12931291    str_begin = scanner.begin; 
    12941292 
    12951293    PJ_TRY { 
    1296         while (!pj_scan_is_eof(&scanner)) {                  
    1297             pj_scan_get_until_ch(&scanner, '\n', &out_str);          
     1294        while (!pj_scan_is_eof(&scanner)) { 
     1295            pj_scan_get_until_ch(&scanner, '\n', &out_str); 
    12981296            str_len = (int)(scanner.curptr - str_begin); 
    1299             if (*scanner.curptr == '\n') {               
    1300                 if ((str_len > 1) && (out_str.ptr[str_len-2] == '\r'))  
    1301                 {                            
     1297            if (*scanner.curptr == '\n') { 
     1298                if ((str_len > 1) && (out_str.ptr[str_len-2] == '\r')) 
     1299                { 
    13021300                    continue; 
    1303                 } else {                     
     1301                } else { 
    13041302                    int str_pos = (int)(str_begin - scanner.begin); 
    13051303 
     
    13141312                        pj_scan_advance_n(&scanner, 1, PJ_TRUE); 
    13151313                        str_begin = scanner.curptr; 
    1316                     }                
     1314                    } 
    13171315                } 
    13181316            } else { 
     
    13551353    pj_mutex_unlock(tsess->smutex); 
    13561354    pj_activesock_close(tsess->asock); 
    1357     pj_mutex_destroy(tsess->smutex);     
     1355    pj_mutex_destroy(tsess->smutex); 
    13581356    pj_pool_release(tsess->pool); 
    13591357} 
     
    13631361{ 
    13641362    cli_telnet_fe *tfe = (cli_telnet_fe *)fe; 
    1365     pj_cli_sess *sess;     
     1363    pj_cli_sess *sess; 
    13661364 
    13671365    pj_mutex_lock(tfe->mutex); 
     
    13711369        cli_telnet_sess *tsess = (cli_telnet_sess *)sess; 
    13721370 
    1373         sess = sess->next;         
     1371        sess = sess->next; 
    13741372        if (tsess->base.log_level > level) { 
    13751373            pj_str_t s; 
     
    13791377        } 
    13801378    } 
    1381      
     1379 
    13821380    pj_mutex_unlock(tfe->mutex); 
    13831381} 
     
    14361434                            pj_activesock_get_user_data(asock); 
    14371435 
    1438     PJ_UNUSED_ARG(op_key);     
     1436    PJ_UNUSED_ARG(op_key); 
    14391437 
    14401438    if (sent <= 0) { 
     
    14711469                            pj_activesock_get_user_data(asock); 
    14721470    cli_telnet_fe *tfe = (cli_telnet_fe *)sess->base.fe; 
    1473     unsigned char *cdata = (unsigned char*)data;     
     1471    unsigned char *cdata = (unsigned char*)data; 
    14741472    pj_status_t is_valid = PJ_TRUE; 
    14751473 
     
    14831481        TRACE_((THIS_FILE, "Error on data read %d", status)); 
    14841482        return PJ_FALSE; 
    1485     }     
     1483    } 
    14861484 
    14871485    pj_mutex_lock(sess->smutex); 
     
    14901488        case ST_CR: 
    14911489            sess->parse_state = ST_NORMAL; 
    1492             if (*cdata == 0 || *cdata == '\n')                           
     1490            if (*cdata == 0 || *cdata == '\n') 
    14931491                pj_mutex_unlock(sess->smutex); 
    14941492                is_valid = handle_return(sess); 
    1495                 if (!is_valid)               
     1493                if (!is_valid) 
    14961494                    return PJ_FALSE; 
    1497                 pj_mutex_lock(sess->smutex);     
     1495                pj_mutex_lock(sess->smutex); 
    14981496                break; 
    14991497        case ST_NORMAL: 
     
    15021500            } else if (*cdata == 127) { 
    15031501                is_valid = handle_backspace(sess, cdata); 
    1504             } else if (*cdata == 27) {               
     1502            } else if (*cdata == 27) { 
    15051503                sess->parse_state = ST_ESC; 
    1506             } else {  
     1504            } else { 
    15071505                if (recv_buf_insert(sess->rcmd, cdata)) { 
    15081506                    if (*cdata == '\r') { 
     
    15191517            break; 
    15201518        case ST_ESC: 
    1521             if (*cdata == 91) {          
     1519            if (*cdata == 91) { 
    15221520                sess->parse_state = ST_VT100; 
    15231521            } else { 
     
    15981596    if (status != PJ_SUCCESS && status != PJ_EPENDING) { 
    15991597        TRACE_((THIS_FILE, "Error on data accept %d", status)); 
    1600         if (status == PJ_ESOCKETSTOP)  
    1601             telnet_restart(fe);      
    1602          
     1598        if (status == PJ_ESOCKETSTOP) 
     1599            telnet_restart(fe); 
     1600 
    16031601        return PJ_FALSE; 
    1604     }     
     1602    } 
    16051603 
    16061604    /* An incoming connection is accepted, create a new session */ 
     
    16091607                          NULL); 
    16101608    if (!pool) { 
    1611         TRACE_((THIS_FILE,  
     1609        TRACE_((THIS_FILE, 
    16121610                "Not enough memory to create a new telnet session")); 
    16131611        return PJ_TRUE; 
     
    16321630    if (sstatus != PJ_SUCCESS) 
    16331631        goto on_exit; 
    1634      
     1632 
    16351633    sstatus = pj_activesock_create(pool, newsock, pj_SOCK_STREAM(), 
    16361634                                   NULL, fe->cfg.ioqueue, 
     
    16571655    send_cmd_do(sess, SUPPRESS_GA); 
    16581656    send_cmd_will(sess, TERM_ECHO); 
    1659     send_cmd_will(sess, STATUS);    
     1657    send_cmd_will(sess, STATUS); 
    16601658    send_cmd_will(sess, SUPPRESS_GA); 
    16611659 
     
    16821680    else 
    16831681        pj_sock_close(newsock); 
    1684      
     1682 
    16851683    if (sess->smutex) 
    16861684        pj_mutex_destroy(sess->smutex); 
     
    16971695    cli_telnet_fe *fe; 
    16981696    pj_pool_t *pool; 
    1699     pj_status_t status;    
     1697    pj_status_t status; 
    17001698 
    17011699    PJ_ASSERT_RETURN(cli, PJ_EINVAL); 
     
    17071705    if (!fe) 
    17081706        return PJ_ENOMEM; 
    1709          
     1707 
    17101708    fe->base.op = PJ_POOL_ZALLOC_T(pool, struct pj_cli_front_end_op); 
    17111709 
     
    17141712    else 
    17151713        pj_memcpy(&fe->cfg, param, sizeof(*param)); 
    1716          
     1714 
    17171715    pj_list_init(&fe->sess_head); 
    17181716    fe->base.cli = cli; 
     
    17221720    fe->pool = pool; 
    17231721 
    1724     if (!fe->cfg.ioqueue) {      
     1722    if (!fe->cfg.ioqueue) { 
    17251723        /* Create own ioqueue if application doesn't supply one */ 
    17261724        status = pj_ioqueue_create(pool, 8, &fe->cfg.ioqueue); 
     
    17621760    pj_activesock_cb asock_cb; 
    17631761    pj_sockaddr_in addr; 
    1764     pj_status_t status;    
     1762    pj_status_t status; 
    17651763    int val; 
    17661764    int restart_retry; 
     
    17941792        PJ_LOG(4,(THIS_FILE, "Address is still in use, retrying..")); 
    17951793        pj_thread_sleep(msec); 
    1796     }     
    1797      
    1798     if (status == PJ_SUCCESS) {  
    1799         int addr_len = sizeof(addr);     
     1794    } 
     1795 
     1796    if (status == PJ_SUCCESS) { 
     1797        int addr_len = sizeof(addr); 
    18001798 
    18011799        status = pj_sock_getsockname(sock, &addr, &addr_len); 
    18021800        if (status != PJ_SUCCESS) 
    18031801            goto on_exit; 
    1804              
    1805         fe->cfg.port = pj_sockaddr_in_get_port(&addr);   
     1802 
     1803        fe->cfg.port = pj_sockaddr_in_get_port(&addr); 
    18061804 
    18071805        if (fe->cfg.prompt_str.slen == 0) { 
    18081806            pj_str_t prompt_sign = {"> ", 2}; 
    1809             char *prompt_data = pj_pool_alloc(fe->pool,  
     1807            char *prompt_data = pj_pool_alloc(fe->pool, 
    18101808                                              pj_gethostname()->slen+2); 
    18111809            fe->cfg.prompt_str.ptr = prompt_data; 
     
    18131811            pj_strcpy(&fe->cfg.prompt_str, pj_gethostname()); 
    18141812            pj_strcat(&fe->cfg.prompt_str, &prompt_sign); 
    1815         }        
     1813        } 
    18161814    } else { 
    18171815        PJ_LOG(3, (THIS_FILE, "Failed binding the socket")); 
     
    18691867{ 
    18701868    pj_status_t status; 
    1871     pj_cli_sess *sess;       
     1869    pj_cli_sess *sess; 
    18721870 
    18731871    fe->is_quitting = PJ_TRUE; 
    1874     if (fe->worker_thread) {     
     1872    if (fe->worker_thread) { 
    18751873        pj_thread_join(fe->worker_thread); 
    18761874    } 
     
    19111909} 
    19121910 
    1913 PJ_DEF(pj_status_t) pj_cli_telnet_get_info(pj_cli_front_end *fe,  
     1911PJ_DEF(pj_status_t) pj_cli_telnet_get_info(pj_cli_front_end *fe, 
    19141912                                           pj_cli_telnet_info *info) 
    19151913{ 
    19161914    pj_sockaddr hostip; 
    19171915    pj_status_t status; 
    1918     cli_telnet_fe *tfe = (cli_telnet_fe*) fe;  
    1919  
    1920     PJ_ASSERT_RETURN(fe && (fe->type == PJ_CLI_TELNET_FRONT_END) && info,  
     1916    cli_telnet_fe *tfe = (cli_telnet_fe*) fe; 
     1917 
     1918    PJ_ASSERT_RETURN(fe && (fe->type == PJ_CLI_TELNET_FRONT_END) && info, 
    19211919                     PJ_EINVAL); 
    19221920 
Note: See TracChangeset for help on using the changeset viewer.