Changeset 4728 for pjproject


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

Location:
pjproject/trunk
Files:
26 edited

Legend:

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

    r4537 r4728  
    4646    pj_thread_t        *input_thread; 
    4747    pj_bool_t           thread_quit; 
    48     pj_sem_t           *thread_sem;    
    49     pj_cli_console_cfg  cfg;     
     48    pj_sem_t           *thread_sem; 
     49    pj_cli_console_cfg  cfg; 
    5050 
    5151    struct async_input_t 
    52     {         
     52    { 
    5353        char       *buf; 
    54         unsigned    maxlen;      
     54        unsigned    maxlen; 
    5555        pj_sem_t   *sem; 
    5656    } input; 
     
    127127    if (!pool) 
    128128        return PJ_ENOMEM; 
    129          
     129 
    130130    sess = PJ_POOL_ZALLOC_T(pool, pj_cli_sess); 
    131131    fe = PJ_POOL_ZALLOC_T(pool, struct cli_console_fe); 
     
    136136    } 
    137137    sess->fe = &fe->base; 
    138     sess->log_level = param->log_level;     
     138    sess->log_level = param->log_level; 
    139139    sess->op = PJ_POOL_ZALLOC_T(pool, struct pj_cli_sess_op); 
    140140    fe->base.op = PJ_POOL_ZALLOC_T(pool, struct pj_cli_front_end_op); 
     
    155155 
    156156    pj_cli_register_front_end(cli, &fe->base); 
    157     if (param->prompt_str.slen == 0) {   
     157    if (param->prompt_str.slen == 0) { 
    158158        pj_str_t prompt_sign = pj_str(">>> "); 
    159159        fe->cfg.prompt_str.ptr = pj_pool_alloc(fe->pool, prompt_sign.slen+1); 
    160         pj_strcpy(&fe->cfg.prompt_str, &prompt_sign);    
     160        pj_strcpy(&fe->cfg.prompt_str, &prompt_sign); 
    161161    } else { 
    162         fe->cfg.prompt_str.ptr = pj_pool_alloc(fe->pool,  
     162        fe->cfg.prompt_str.ptr = pj_pool_alloc(fe->pool, 
    163163                                               param->prompt_str.slen+1); 
    164164        pj_strcpy(&fe->cfg.prompt_str, &param->prompt_str); 
    165     }     
    166     fe->cfg.prompt_str.ptr[fe->cfg.prompt_str.slen] = 0;  
     165    } 
     166    fe->cfg.prompt_str.ptr[fe->cfg.prompt_str.slen] = 0; 
    167167 
    168168    if (param->quit_command.slen) 
     
    184184    send_data.ptr = data_str; 
    185185    send_data.slen = 0; 
    186      
     186 
    187187    pj_strcat(&send_data, &fe->cfg.prompt_str); 
    188188    send_data.ptr[send_data.slen] = 0; 
     
    191191} 
    192192 
    193 static void send_err_arg(pj_cli_sess *sess,  
    194                          const pj_cli_exec_info *info,  
     193static void send_err_arg(pj_cli_sess *sess, 
     194                         const pj_cli_exec_info *info, 
    195195                         const pj_str_t *msg, 
    196196                         pj_bool_t with_return) 
     
    219219 
    220220    send_data.ptr[send_data.slen] = 0; 
    221     printf("%s", send_data.ptr);     
    222 } 
    223  
    224 static void send_inv_arg(pj_cli_sess *sess,  
     221    printf("%s", send_data.ptr); 
     222} 
     223 
     224static void send_inv_arg(pj_cli_sess *sess, 
    225225                         const pj_cli_exec_info *info, 
    226226                         pj_bool_t with_return) 
     
    230230} 
    231231 
    232 static void send_too_many_arg(pj_cli_sess *sess,  
     232static void send_too_many_arg(pj_cli_sess *sess, 
    233233                              const pj_cli_exec_info *info, 
    234234                              pj_bool_t with_return) 
     
    238238} 
    239239 
    240 static void send_hint_arg(pj_str_t *send_data,  
     240static void send_hint_arg(pj_str_t *send_data, 
    241241                          const pj_str_t *desc, 
    242242                          pj_ssize_t cmd_len, 
     
    257257} 
    258258 
    259 static void send_ambi_arg(pj_cli_sess *sess,  
     259static void send_ambi_arg(pj_cli_sess *sess, 
    260260                          const pj_cli_exec_info *info, 
    261261                          pj_bool_t with_return) 
     
    270270    pj_ssize_t max_length = 0; 
    271271    pj_ssize_t cmd_length = 0; 
    272     const pj_str_t *cmd_desc = 0; 
    273272    static const pj_str_t sc_type = {"sc", 2}; 
    274273    static const pj_str_t choice_type = {"choice", 6}; 
    275274    send_data.ptr = data; 
    276275    send_data.slen = 0; 
    277      
     276 
    278277    if (with_return) 
    279278        pj_strcat2(&send_data, "\r\n"); 
     
    284283        pj_strcat2(&send_data, " "); 
    285284    } 
    286     pj_strcat2(&send_data, "^");         
     285    pj_strcat2(&send_data, "^"); 
    287286    /* Get the max length of the command name */ 
    288287    for (i=0;i<info->hint_cnt;++i) { 
    289         if ((&hint[i].type) && (hint[i].type.slen > 0)) {            
    290             if (pj_stricmp(&hint[i].type, &sc_type) == 0) {              
     288        if ((&hint[i].type) && (hint[i].type.slen > 0)) { 
     289            if (pj_stricmp(&hint[i].type, &sc_type) == 0) { 
    291290                if ((i > 0) && (!pj_stricmp(&hint[i-1].desc, &hint[i].desc))) { 
    292291                    cmd_length += (hint[i].name.slen + 3); 
    293292                } else { 
    294293                    cmd_length = hint[i].name.slen; 
    295                 }                
     294                } 
    296295            } else { 
    297296                cmd_length = hint[i].name.slen; 
    298297            } 
    299         } else {                     
     298        } else { 
    300299            cmd_length = hint[i].name.slen; 
    301300        } 
     
    308307    cmd_length = 0; 
    309308    for (i=0;i<info->hint_cnt;++i) { 
    310         if ((&hint[i].type) && (hint[i].type.slen > 0)) {            
     309        if ((&hint[i].type) && (hint[i].type.slen > 0)) { 
    311310            if (pj_stricmp(&hint[i].type, &sc_type) == 0) { 
    312311                parse_state = OP_SHORTCUT; 
     
    316315                parse_state = OP_TYPE; 
    317316            } 
    318         } else {                     
     317        } else { 
    319318            parse_state = OP_NORMAL; 
    320319        } 
     
    324323            cmd_length = hint[i].name.slen; 
    325324        } 
    326      
     325 
    327326        switch (parse_state) { 
    328327        case OP_CHOICE: 
    329328            pj_strcat2(&send_data, "["); 
    330329            pj_strcat(&send_data, &hint[i].name); 
    331             pj_strcat2(&send_data, "]");         
     330            pj_strcat2(&send_data, "]"); 
    332331            break; 
    333332        case OP_TYPE: 
    334333            pj_strcat2(&send_data, "<"); 
    335334            pj_strcat(&send_data, &hint[i].type); 
    336             pj_strcat2(&send_data, ">");         
     335            pj_strcat2(&send_data, ">"); 
    337336            break; 
    338337        case OP_SHORTCUT: 
    339338            /* Format : "Command | sc |  description" */ 
    340             {            
     339            { 
    341340                cmd_length += hint[i].name.slen; 
    342341                if ((i > 0) && (!pj_stricmp(&hint[i-1].desc, &hint[i].desc))) { 
    343342                    pj_strcat2(&send_data, " | "); 
    344                     cmd_length += 3;                 
     343                    cmd_length += 3; 
    345344                } else { 
    346345                    pj_strcat2(&send_data, "\r\n  "); 
    347346                } 
    348                 pj_strcat(&send_data, &hint[i].name);    
     347                pj_strcat(&send_data, &hint[i].name); 
    349348            } 
    350349            break; 
    351350        default: 
    352351            pj_strcat(&send_data, &hint[i].name); 
    353             cmd_desc = &hint[i].desc; 
    354352            break; 
    355353        } 
    356          
    357         if ((parse_state == OP_TYPE) || (parse_state == OP_CHOICE) ||  
     354 
     355        if ((parse_state == OP_TYPE) || (parse_state == OP_CHOICE) || 
    358356            ((i+1) >= info->hint_cnt) || 
    359             (pj_strncmp(&hint[i].desc, &hint[i+1].desc, hint[i].desc.slen)))  
     357            (pj_strncmp(&hint[i].desc, &hint[i+1].desc, hint[i].desc.slen))) 
    360358        { 
    361359            /* Add description info */ 
     
    364362            cmd_length = 0; 
    365363        } 
    366     }   
     364    } 
    367365    pj_strcat2(&send_data, "\r\n"); 
    368366    pj_strcat(&send_data, &fe->cfg.prompt_str); 
    369367    send_data.ptr[send_data.slen] = 0; 
    370     printf("%s", send_data.ptr);     
     368    printf("%s", send_data.ptr); 
    371369} 
    372370 
     
    375373    pj_status_t status; 
    376374    pj_bool_t retval = PJ_TRUE; 
    377      
     375 
    378376    pj_pool_t *pool; 
    379377    pj_cli_cmd_val *cmd_val; 
     
    388386 
    389387    cmd_val = PJ_POOL_ZALLOC_T(pool, pj_cli_cmd_val); 
    390      
    391     status = pj_cli_sess_parse(sess, recv_buf, cmd_val,  
     388 
     389    status = pj_cli_sess_parse(sess, recv_buf, cmd_val, 
    392390                               pool, &info); 
    393391 
    394392    switch (status) { 
    395393    case PJ_CLI_EINVARG: 
    396         send_inv_arg(sess, &info, PJ_TRUE);              
     394        send_inv_arg(sess, &info, PJ_TRUE); 
    397395        break; 
    398396    case PJ_CLI_ETOOMANYARGS: 
     
    403401        send_ambi_arg(sess, &info, PJ_TRUE); 
    404402        break; 
    405     case PJ_SUCCESS:     
    406         if (info.hint_cnt > 0) {         
    407             /* Compelete command */          
    408             send_ambi_arg(sess, &info, PJ_TRUE);                         
     403    case PJ_SUCCESS: 
     404        if (info.hint_cnt > 0) { 
     405            /* Compelete command */ 
     406            send_ambi_arg(sess, &info, PJ_TRUE); 
    409407        } else { 
    410408            retval = PJ_FALSE; 
    411         }        
    412         break; 
    413     } 
    414  
    415     pj_pool_release(pool);       
    416     return retval;  
     409        } 
     410        break; 
     411    } 
     412 
     413    pj_pool_release(pool); 
     414    return retval; 
    417415} 
    418416 
     
    421419    pj_status_t status; 
    422420    pj_bool_t retval = PJ_TRUE; 
    423      
    424     pj_pool_t *pool;     
     421 
     422    pj_pool_t *pool; 
    425423    pj_cli_exec_info info; 
    426424    pj_cli_t *cli = sess->fe->cli; 
    427425    struct cli_console_fe *fe = (struct cli_console_fe *)sess->fe; 
    428426    char *recv_buf = fe->input.buf; 
    429          
     427 
    430428    printf("\r\n"); 
    431429 
    432430    pool = pj_pool_create(pj_cli_get_param(cli)->pf, "handle_exec", 
    433431                          PJ_CLI_CONSOLE_POOL_SIZE, PJ_CLI_CONSOLE_POOL_INC, 
    434                           NULL);     
    435      
    436     status = pj_cli_sess_exec(sess, recv_buf,  
     432                          NULL); 
     433 
     434    status = pj_cli_sess_exec(sess, recv_buf, 
    437435                              pool, &info); 
    438436 
    439437    switch (status) { 
    440438    case PJ_CLI_EINVARG: 
    441         send_inv_arg(sess, &info, PJ_FALSE);     
     439        send_inv_arg(sess, &info, PJ_FALSE); 
    442440        break; 
    443441    case PJ_CLI_ETOOMANYARGS: 
     
    452450        break; 
    453451    case PJ_SUCCESS: 
    454         send_prompt_str(sess);   
    455         break; 
    456     }     
    457  
    458     pj_pool_release(pool);       
    459     return retval;  
     452        send_prompt_str(sess); 
     453        break; 
     454    } 
     455 
     456    pj_pool_release(pool); 
     457    return retval; 
    460458} 
    461459 
    462460static int readline_thread(void * p) 
    463 {     
     461{ 
    464462    struct cli_console_fe * fe = (struct cli_console_fe *)p; 
    465463 
     
    473471 
    474472        if (fgets(recv_buf, fe->input.maxlen, stdin) == NULL) { 
    475             /*  
     473            /* 
    476474             * Be friendly to users who redirect commands into 
    477475             * program, when file ends, resume with kbd. 
     
    488486                puts("Cannot switch back to console from file redirection"); 
    489487                if (fe->cfg.quit_command.slen) { 
    490                     pj_memcpy(recv_buf, fe->cfg.quit_command.ptr,  
     488                    pj_memcpy(recv_buf, fe->cfg.quit_command.ptr, 
    491489                              fe->input.maxlen); 
    492490                } 
    493                 recv_buf[fe->cfg.quit_command.slen] = '\0';              
     491                recv_buf[fe->cfg.quit_command.slen] = '\0'; 
    494492            } else { 
    495493                puts("Switched back to console from file redirection"); 
     
    506504            break; 
    507505        } 
    508         input_len = pj_ansi_strlen(fe->input.buf);       
     506        input_len = pj_ansi_strlen(fe->input.buf); 
    509507        if ((input_len > 1) && (fe->input.buf[input_len-2] == '?')) { 
    510508            fe->input.buf[input_len-1] = 0; 
     
    516514        } 
    517515 
    518         pj_sem_post(fe->input.sem);         
     516        pj_sem_post(fe->input.sem); 
    519517        pj_sem_wait(fe->thread_sem); 
    520     }     
     518    } 
    521519 
    522520    return 0; 
    523521} 
    524522 
    525 PJ_DEF(pj_status_t) pj_cli_console_process(pj_cli_sess *sess,  
     523PJ_DEF(pj_status_t) pj_cli_console_process(pj_cli_sess *sess, 
    526524                                           char *buf, 
    527525                                           unsigned maxlen) 
  • 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 
  • pjproject/trunk/pjlib/src/pj/os_core_unix.c

    r4359 r4728  
    11/* $Id$ */ 
    2 /*  
     2/* 
    33 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 
    44 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 
     
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1919 */ 
    2020/* 
     
    165165    pj_log_init(); 
    166166 
    167     /* Initialize exception ID for the pool.  
     167    /* Initialize exception ID for the pool. 
    168168     * Must do so after critical section is configured. 
    169169     */ 
     
    171171    if (rc != PJ_SUCCESS) 
    172172        return rc; 
    173      
     173 
    174174    /* Init random seed. */ 
    175175    /* Or probably not. Let application in charge of this */ 
     
    188188        } 
    189189    } 
    190 #endif    
     190#endif 
    191191 
    192192    /* Flag PJLIB as initialized */ 
     
    383383 * Get native thread handle 
    384384 */ 
    385 PJ_DEF(void*) pj_thread_get_os_handle(pj_thread_t *thread)  
     385PJ_DEF(void*) pj_thread_get_os_handle(pj_thread_t *thread) 
    386386{ 
    387387    PJ_ASSERT_RETURN(thread, NULL); 
     
    441441 
    442442    if(cstr_thread_name && pj_strlen(&thread_name) < sizeof(thread->obj_name)-1) 
    443         pj_ansi_snprintf(thread->obj_name, sizeof(thread->obj_name),  
     443        pj_ansi_snprintf(thread->obj_name, sizeof(thread->obj_name), 
    444444                         cstr_thread_name, thread->thread); 
    445445    else 
    446         pj_ansi_snprintf(thread->obj_name, sizeof(thread->obj_name),  
     446        pj_ansi_snprintf(thread->obj_name, sizeof(thread->obj_name), 
    447447                         "thr%p", (void*)thread->thread); 
    448      
     448 
    449449    rc = pj_thread_local_set(thread_tls_id, thread); 
    450450    if (rc != PJ_SUCCESS) { 
     
    458458    thread->stk_max_usage = 0; 
    459459#else 
    460     stack_ptr = '\0'; 
     460    PJ_UNUSED_ARG(stack_ptr); 
    461461#endif 
    462462 
     
    533533 * pj_thread_create(...) 
    534534 */ 
    535 PJ_DEF(pj_status_t) pj_thread_create( pj_pool_t *pool,  
     535PJ_DEF(pj_status_t) pj_thread_create( pj_pool_t *pool, 
    536536                                      const char *thread_name, 
    537                                       pj_thread_proc *proc,  
     537                                      pj_thread_proc *proc, 
    538538                                      void *arg, 
    539                                       pj_size_t stack_size,  
     539                                      pj_size_t stack_size, 
    540540                                      unsigned flags, 
    541541                                      pj_thread_t **ptr_thread) 
     
    555555    rec = (struct pj_thread_t*) pj_pool_zalloc(pool, sizeof(pj_thread_t)); 
    556556    PJ_ASSERT_RETURN(rec, PJ_ENOMEM); 
    557      
     557 
    558558    /* Set name. */ 
    559     if (!thread_name)  
     559    if (!thread_name) 
    560560        thread_name = "thr%p"; 
    561      
     561 
    562562    if (strchr(thread_name, '%')) { 
    563563        pj_ansi_snprintf(rec->obj_name, PJ_MAX_OBJ_NAME, thread_name, rec); 
     
    587587        pj_assert(rec->suspended_mutex == NULL); 
    588588    } 
    589      
     589 
    590590 
    591591    /* Init thread attributes */ 
     
    668668#if PJ_HAS_THREADS 
    669669    pj_thread_t *rec = (pj_thread_t*)pj_thread_local_get(thread_tls_id); 
    670      
     670 
    671671    if (rec == NULL) { 
    672672        pj_assert(!"Calling pjlib from unknown/external thread. You must " 
     
    706706        return PJ_SUCCESS; 
    707707    else { 
    708         /* Calling pthread_join() on a thread that no longer exists and  
    709          * getting back ESRCH isn't an error (in this context).  
     708        /* Calling pthread_join() on a thread that no longer exists and 
     709         * getting back ESRCH isn't an error (in this context). 
    710710         * Thanks Phil Torre <ptorre@zetron.com>. 
    711711         */ 
     
    762762    /* MacOS X (reported on 10.5) seems to always set errno to ETIMEDOUT. 
    763763     * It does so because usleep() is declared to return int, and we're 
    764      * supposed to check for errno only when usleep() returns non-zero.  
     764     * supposed to check for errno only when usleep() returns non-zero. 
    765765     * Unfortunately, usleep() is declared to return void in other platforms 
    766      * so it's not possible to always check for the return value (unless  
     766     * so it's not possible to always check for the return value (unless 
    767767     * we add a detection routine in autoconf). 
    768768     * 
     
    832832 * pj_atomic_create() 
    833833 */ 
    834 PJ_DEF(pj_status_t) pj_atomic_create( pj_pool_t *pool,  
     834PJ_DEF(pj_status_t) pj_atomic_create( pj_pool_t *pool, 
    835835                                      pj_atomic_value_t initial, 
    836836                                      pj_atomic_t **ptr_atomic) 
     
    842842 
    843843    PJ_ASSERT_RETURN(atomic_var, PJ_ENOMEM); 
    844      
     844 
    845845#if PJ_HAS_THREADS 
    846846    rc = pj_mutex_create(pool, "atm%p", PJ_MUTEX_SIMPLE, &atomic_var->mutex); 
     
    880880#if PJ_HAS_THREADS 
    881881    pj_mutex_unlock( atomic_var->mutex); 
    882 #endif  
     882#endif 
    883883} 
    884884 
     
    889889{ 
    890890    pj_atomic_value_t oldval; 
    891      
     891 
    892892    PJ_CHECK_STACK(); 
    893893 
     
    959959/* 
    960960 * pj_atomic_add_and_get() 
    961  */  
    962 PJ_DEF(pj_atomic_value_t) pj_atomic_add_and_get( pj_atomic_t *atomic_var,  
     961 */ 
     962PJ_DEF(pj_atomic_value_t) pj_atomic_add_and_get( pj_atomic_t *atomic_var, 
    963963                                                 pj_atomic_value_t value ) 
    964964{ 
     
    968968    pj_mutex_lock(atomic_var->mutex); 
    969969#endif 
    970      
     970 
    971971    atomic_var->value += value; 
    972972    new_value = atomic_var->value; 
     
    981981/* 
    982982 * pj_atomic_add() 
    983  */  
    984 PJ_DEF(void) pj_atomic_add( pj_atomic_t *atomic_var,  
     983 */ 
     984PJ_DEF(void) pj_atomic_add( pj_atomic_t *atomic_var, 
    985985                            pj_atomic_value_t value ) 
    986986{ 
     
    10121012            break; 
    10131013    } 
    1014     if (i == MAX_THREADS)  
     1014    if (i == MAX_THREADS) 
    10151015        return PJ_ETOOMANY; 
    1016      
     1016 
    10171017    tls_flag[i] = 1; 
    10181018    tls[i] = NULL; 
     
    11191119       defined(PJ_PTHREAD_MUTEXATTR_T_HAS_RECURSIVE) 
    11201120        // Phil Torre <ptorre@zetron.com>: 
    1121         // The RTEMS implementation of POSIX mutexes doesn't include  
     1121        // The RTEMS implementation of POSIX mutexes doesn't include 
    11221122        // pthread_mutexattr_settype(), so what follows is a hack 
    11231123        // until I get RTEMS patched to support the set/get functions. 
     
    11321132#endif 
    11331133    } 
    1134      
     1134 
    11351135    if (rc != 0) { 
    11361136        return PJ_RETURN_OS_ERROR(rc); 
     
    11411141        return PJ_RETURN_OS_ERROR(rc); 
    11421142    } 
    1143      
     1143 
    11441144    rc = pthread_mutexattr_destroy(&attr); 
    11451145    if (rc != 0) { 
     
    11761176 * pj_mutex_create() 
    11771177 */ 
    1178 PJ_DEF(pj_status_t) pj_mutex_create(pj_pool_t *pool,  
    1179                                     const char *name,  
     1178PJ_DEF(pj_status_t) pj_mutex_create(pj_pool_t *pool, 
     1179                                    const char *name, 
    11801180                                    int type, 
    11811181                                    pj_mutex_t **ptr_mutex) 
     
    11921192    if ((rc=init_mutex(mutex, name, type)) != PJ_SUCCESS) 
    11931193        return rc; 
    1194      
     1194 
    11951195    *ptr_mutex = mutex; 
    11961196    return PJ_SUCCESS; 
     
    12041204 * pj_mutex_create_simple() 
    12051205 */ 
    1206 PJ_DEF(pj_status_t) pj_mutex_create_simple( pj_pool_t *pool,  
     1206PJ_DEF(pj_status_t) pj_mutex_create_simple( pj_pool_t *pool, 
    12071207                                            const char *name, 
    12081208                                            pj_mutex_t **mutex ) 
     
    12331233 
    12341234#if PJ_DEBUG 
    1235     PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s is waiting (mutex owner=%s)",  
     1235    PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s is waiting (mutex owner=%s)", 
    12361236                                pj_thread_this()->obj_name, 
    12371237                                mutex->owner_name)); 
    12381238#else 
    1239     PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s is waiting",  
     1239    PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s is waiting", 
    12401240                                pj_thread_this()->obj_name)); 
    12411241#endif 
     
    12511251    } 
    12521252 
    1253     PJ_LOG(6,(mutex->obj_name,  
    1254               (status==0 ?  
    1255                 "Mutex acquired by thread %s (level=%d)" :  
     1253    PJ_LOG(6,(mutex->obj_name, 
     1254              (status==0 ? 
     1255                "Mutex acquired by thread %s (level=%d)" : 
    12561256                "Mutex acquisition FAILED by %s (level=%d)"), 
    12571257              pj_thread_this()->obj_name, 
    12581258              mutex->nesting_level)); 
    12591259#else 
    1260     PJ_LOG(6,(mutex->obj_name,  
     1260    PJ_LOG(6,(mutex->obj_name, 
    12611261              (status==0 ? "Mutex acquired by thread %s" : "FAILED by %s"), 
    12621262              pj_thread_this()->obj_name)); 
     
    12911291    } 
    12921292 
    1293     PJ_LOG(6,(mutex->obj_name, "Mutex released by thread %s (level=%d)",  
    1294                                 pj_thread_this()->obj_name,  
     1293    PJ_LOG(6,(mutex->obj_name, "Mutex released by thread %s (level=%d)", 
     1294                                pj_thread_this()->obj_name, 
    12951295                                mutex->nesting_level)); 
    12961296#else 
    1297     PJ_LOG(6,(mutex->obj_name, "Mutex released by thread %s",  
     1297    PJ_LOG(6,(mutex->obj_name, "Mutex released by thread %s", 
    12981298                                pj_thread_this()->obj_name)); 
    12991299#endif 
     
    13221322    PJ_ASSERT_RETURN(mutex, PJ_EINVAL); 
    13231323 
    1324     PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s is trying",  
     1324    PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s is trying", 
    13251325                                pj_thread_this()->obj_name)); 
    13261326 
     
    13331333        ++mutex->nesting_level; 
    13341334 
    1335         PJ_LOG(6,(mutex->obj_name, "Mutex acquired by thread %s (level=%d)",  
     1335        PJ_LOG(6,(mutex->obj_name, "Mutex acquired by thread %s (level=%d)", 
    13361336                                   pj_thread_this()->obj_name, 
    13371337                                   mutex->nesting_level)); 
    13381338#else 
    1339         PJ_LOG(6,(mutex->obj_name, "Mutex acquired by thread %s",  
     1339        PJ_LOG(6,(mutex->obj_name, "Mutex acquired by thread %s", 
    13401340                                  pj_thread_this()->obj_name)); 
    13411341#endif 
    13421342    } else { 
    1343         PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s's trylock() failed",  
     1343        PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s's trylock() failed", 
    13441344                                    pj_thread_this()->obj_name)); 
    13451345    } 
    1346      
     1346 
    13471347    if (status==0) 
    13481348        return PJ_SUCCESS; 
     
    14261426 
    14271427    PJ_UNUSED_ARG(name); 
    1428      
     1428 
    14291429    rwm = PJ_POOL_ALLOC_T(pool, pj_rwmutex_t); 
    14301430    PJ_ASSERT_RETURN(rwm, PJ_ENOMEM); 
     
    15161516 * pj_sem_create() 
    15171517 */ 
    1518 PJ_DEF(pj_status_t) pj_sem_create( pj_pool_t *pool,  
     1518PJ_DEF(pj_status_t) pj_sem_create( pj_pool_t *pool, 
    15191519                                   const char *name, 
    1520                                    unsigned initial,  
     1520                                   unsigned initial, 
    15211521                                   unsigned max, 
    15221522                                   pj_sem_t **ptr_sem) 
     
    15371537        pj_str_t nam; 
    15381538 
    1539         /* We should use SEM_NAME_LEN, but this doesn't seem to be  
     1539        /* We should use SEM_NAME_LEN, but this doesn't seem to be 
    15401540         * declared anywhere? The value here is just from trial and error 
    15411541         * to get the longest name supported. 
     
    15541554 
    15551555        /* Create semaphore */ 
    1556         sem->sem = sem_open(sem_name, O_CREAT|O_EXCL, S_IRUSR|S_IWUSR,  
     1556        sem->sem = sem_open(sem_name, O_CREAT|O_EXCL, S_IRUSR|S_IWUSR, 
    15571557                            initial); 
    15581558        if (sem->sem == SEM_FAILED) 
     
    15641564#else 
    15651565    sem->sem = PJ_POOL_ALLOC_T(pool, sem_t); 
    1566     if (sem_init( sem->sem, 0, initial) != 0)  
     1566    if (sem_init( sem->sem, 0, initial) != 0) 
    15671567        return PJ_RETURN_OS_ERROR(pj_get_native_os_error()); 
    15681568#endif 
    1569      
     1569 
    15701570    /* Set name. */ 
    15711571    if (!name) { 
     
    16001600    PJ_ASSERT_RETURN(sem, PJ_EINVAL); 
    16011601 
    1602     PJ_LOG(6, (sem->obj_name, "Semaphore: thread %s is waiting",  
     1602    PJ_LOG(6, (sem->obj_name, "Semaphore: thread %s is waiting", 
    16031603                              pj_thread_this()->obj_name)); 
    16041604 
    16051605    result = sem_wait( sem->sem ); 
    1606      
     1606 
    16071607    if (result == 0) { 
    1608         PJ_LOG(6, (sem->obj_name, "Semaphore acquired by thread %s",  
     1608        PJ_LOG(6, (sem->obj_name, "Semaphore acquired by thread %s", 
    16091609                                  pj_thread_this()->obj_name)); 
    16101610    } else { 
    1611         PJ_LOG(6, (sem->obj_name, "Semaphore: thread %s FAILED to acquire",  
     1611        PJ_LOG(6, (sem->obj_name, "Semaphore: thread %s FAILED to acquire", 
    16121612                                  pj_thread_this()->obj_name)); 
    16131613    } 
     
    16351635 
    16361636    result = sem_trywait( sem->sem ); 
    1637      
     1637 
    16381638    if (result == 0) { 
    1639         PJ_LOG(6, (sem->obj_name, "Semaphore acquired by thread %s",  
     1639        PJ_LOG(6, (sem->obj_name, "Semaphore acquired by thread %s", 
    16401640                                  pj_thread_this()->obj_name)); 
    1641     }  
     1641    } 
    16421642    if (result == 0) 
    16431643        return PJ_SUCCESS; 
  • pjproject/trunk/pjlib/src/pjlib-test/test.c

    r4712 r4728  
    11/* $Id$ */ 
    2 /*  
     2/* 
    33 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 
    44 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 
     
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1919 */ 
    2020#include "test.h" 
     
    3939const char *param_echo_server = ECHO_SERVER_ADDRESS; 
    4040int param_echo_port = ECHO_SERVER_START_PORT; 
    41 int param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |  
     41int param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME | 
    4242                      PJ_LOG_HAS_MICRO_SEC; 
    4343 
     
    6464        return rc; 
    6565    } 
    66      
     66 
    6767    //pj_dump_config(); 
    6868    pj_caching_pool_init( &caching_pool, NULL, 0 ); 
     
    9999    DO_TEST( string_test() ); 
    100100#endif 
    101      
     101 
    102102#if INCLUDE_FIFOBUF_TEST 
    103103    DO_TEST( fifobuf_test() ); 
     
    185185        param_echo_sock_type = pj_SOCK_DGRAM(); 
    186186 
    187     echo_client( param_echo_sock_type,  
    188                  param_echo_server,  
     187    echo_client( param_echo_sock_type, 
     188                 param_echo_server, 
    189189                 param_echo_port); 
    190190#endif 
     
    197197 
    198198    PJ_LOG(3,("test", "")); 
    199   
     199 
    200200    pj_thread_get_stack_info(pj_thread_this(), &filename, &line); 
    201     PJ_LOG(3,("test", "Stack max usage: %u, deepest: %s:%u",  
     201    PJ_LOG(3,("test", "Stack max usage: %u, deepest: %s:%u", 
    202202                      pj_thread_get_stack_max_usage(pj_thread_this()), 
    203203                      filename, line)); 
     
    206206    else 
    207207        PJ_LOG(3,("test", "Test completed with error(s)")); 
    208      
     208 
    209209    pj_shutdown(); 
    210      
     210 
    211211    return 0; 
    212212} 
     
    217217{ 
    218218    PJ_USE_EXCEPTION; 
    219  
    220     pj_AF_INET(); 
    221219 
    222220    PJ_TRY { 
     
    225223    PJ_CATCH_ANY { 
    226224        int id = PJ_GET_EXCEPTION(); 
    227         PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)",  
     225        PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)", 
    228226                  id, pj_exception_id_name(id))); 
    229227    } 
  • pjproject/trunk/pjlib/src/pjlib-test/thread.c

    r3553 r4728  
    11/* $Id$ */ 
    2 /*  
     2/* 
    33 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 
    44 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 
     
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1919 */ 
    2020#include "test.h" 
     
    3131 *  - whether thread timeslicing works, and threads have equal 
    3232 *    time-slice proportion. 
    33  *  
     33 * 
    3434 * APIs tested: 
    3535 *  - pj_thread_create() 
     
    7878 
    7979    id = *pcounter; 
     80    PJ_UNUSED_ARG(id); /* Warning about unused var if TRACE__ is disabled */ 
    8081    TRACE__((THIS_FILE, "     thread %d running..", id)); 
    8182 
     
    121122    pj_status_t rc; 
    122123    pj_uint32_t counter = 0; 
    123   
     124 
    124125    PJ_LOG(3,(THIS_FILE, "..%s", title)); 
    125      
     126 
    126127    pool = pj_pool_create(mem, NULL, 4000, 4000, NULL); 
    127128    if (!pool) 
     
    153154            return -1015; 
    154155        } 
    155          
     156 
    156157        rc = pj_thread_resume(thread); 
    157158        if (rc != PJ_SUCCESS) { 
     
    160161        } 
    161162    } 
    162      
     163 
    163164    PJ_LOG(3,(THIS_FILE, "..waiting for thread to quit..")); 
    164165 
     
    174175        return -1025; 
    175176    } 
    176      
     177 
    177178    PJ_LOG(3,(THIS_FILE, "...%s success", title)); 
    178179    return PJ_SUCCESS; 
     
    203204    for (i=0; i<NUM_THREADS; ++i) { 
    204205        counter[i] = i; 
    205         rc = pj_thread_create(pool, "thread", (pj_thread_proc*)&thread_proc,  
    206                               &counter[i],  
    207                               PJ_THREAD_DEFAULT_STACK_SIZE,  
    208                               PJ_THREAD_SUSPENDED,  
     206        rc = pj_thread_create(pool, "thread", (pj_thread_proc*)&thread_proc, 
     207                              &counter[i], 
     208                              PJ_THREAD_DEFAULT_STACK_SIZE, 
     209                              PJ_THREAD_SUSPENDED, 
    209210                              &thread[i]); 
    210211        if (rc!=PJ_SUCCESS) { 
     
    224225    for (i=0; i<NUM_THREADS; ++i) { 
    225226        if (counter[i] > i) { 
    226             PJ_LOG(3,(THIS_FILE, "....ERROR! Thread %d-th is not suspended!",  
     227            PJ_LOG(3,(THIS_FILE, "....ERROR! Thread %d-th is not suspended!", 
    227228                      i)); 
    228229            return -30; 
     
    240241    } 
    241242 
    242     /* Main thread sleeps for some time to allow threads to run.  
     243    /* Main thread sleeps for some time to allow threads to run. 
    243244     * The longer we sleep, the more accurate the calculation will be, 
    244245     * but it'll make user waits for longer for the test to finish. 
     
    253254    /* Wait until all threads quit, then destroy. */ 
    254255    for (i=0; i<NUM_THREADS; ++i) { 
    255         TRACE__((THIS_FILE, "    Main thread joining thread %d [%p]..",  
     256        TRACE__((THIS_FILE, "    Main thread joining thread %d [%p]..", 
    256257                            i, thread[i])); 
    257258        rc = pj_thread_join(thread[i]); 
     
    292293    diff = (highest-lowest)*100 / ((highest+lowest)/2); 
    293294    if ( diff >= 50) { 
    294         PJ_LOG(3,(THIS_FILE,  
     295        PJ_LOG(3,(THIS_FILE, 
    295296                  "...ERROR: thread didn't have equal timeslice!")); 
    296         PJ_LOG(3,(THIS_FILE,  
     297        PJ_LOG(3,(THIS_FILE, 
    297298                  ".....lowest counter=%u, highest counter=%u, diff=%u%%", 
    298299                  lowest, highest, diff)); 
    299300        return -80; 
    300301    } else { 
    301         PJ_LOG(3,(THIS_FILE,  
     302        PJ_LOG(3,(THIS_FILE, 
    302303                  "...info: timeslice diff between lowest & highest=%u%%", 
    303304                  diff)); 
     
    315316    if (rc != PJ_SUCCESS) 
    316317        return rc; 
    317      
     318 
    318319    rc = simple_thread("suspended thread test", PJ_THREAD_SUSPENDED); 
    319320    if (rc != PJ_SUCCESS) 
    320321        return rc; 
    321      
     322 
    322323    rc = timeslice_test(); 
    323324    if (rc != PJ_SUCCESS) 
     
    329330#else 
    330331/* To prevent warning about "translation unit is empty" 
    331  * when this test is disabled.  
     332 * when this test is disabled. 
    332333 */ 
    333334int dummy_thread_test; 
  • pjproject/trunk/pjmedia/src/pjmedia-audiodev/bb10_dev.c

    r4707 r4728  
    501501                if (status.status == SND_PCM_STATUS_READY || 
    502502                    status.status == SND_PCM_STATUS_UNDERRUN || 
    503                     status.status == SND_PCM_STATUS_ERROR )  
     503                    status.status == SND_PCM_STATUS_ERROR ) 
    504504                { 
    505505                    if (snd_pcm_plugin_prepare (stream->pb_pcm, 
     
    778778    TRACE_((THIS_FILE, "bb10_open_playback: pb_frames = %d clock = %d", 
    779779                       stream->pb_frames, param->clock_rate)); 
    780      
     780 
    781781    return PJ_SUCCESS; 
    782782} 
     
    864864 
    865865    frame_size = setup.buf.block.frag_size; 
     866    PJ_UNUSED_ARG(frame_size); /* Warning about unused var */ 
    866867 
    867868    /* Set clock rate */ 
     
    962963 
    963964 
    964 /*  
     965/* 
    965966 * API: get running parameter 
    966967 * based on ALSA template 
     
    981982/* 
    982983 * API: get capability 
    983  * based on ALSA template  
     984 * based on ALSA template 
    984985*/ 
    985986static pj_status_t bb10_stream_get_cap(pjmedia_aud_stream *s, 
     
    10431044            ret = bb10_initialize_playback_ctrl(stream,true); 
    10441045        } else { 
    1045             ret = bb10_initialize_playback_ctrl(stream,false);           
     1046            ret = bb10_initialize_playback_ctrl(stream,false); 
    10461047        } 
    10471048        return ret; 
  • pjproject/trunk/pjmedia/src/pjmedia/echo_suppress.c

    r4713 r4728  
    11/* $Id$ */ 
    2 /*  
     2/* 
    33 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 
    44 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 
     
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1919 */ 
    2020#include <pjmedia/types.h> 
     
    7878#if 0 
    7979#   define TRACE_(expr) PJ_LOG(5,expr) 
     80 
     81static const char *state_names[] = 
     82{ 
     83    "Null", 
     84    "local talking", 
     85    "remote silent", 
     86    "doubletalk", 
     87    "remote talking" 
     88}; 
     89 
    8090#else 
    8191#   define TRACE_(expr) 
     
    126136} talk_state_t; 
    127137 
    128 static const char *state_names[] =  
    129 { 
    130     "Null", 
    131     "local talking", 
    132     "remote silent", 
    133     "doubletalk", 
    134     "remote talking" 
    135 }; 
    136  
    137138 
    138139/* Description: 
    139140 
    140141   The echo suppressor tries to find the position of echoed signal by looking 
    141    at the correlation between signal played to the speaker (played signal)  
     142   at the correlation between signal played to the speaker (played signal) 
    142143   and the signal captured from the microphone (recorded signal). 
    143144 
    144    To do this, it first divides the frames (from mic and speaker) into  
     145   To do this, it first divides the frames (from mic and speaker) into 
    145146   segments, calculate the audio level of the segment, and save the level 
    146147   information in the playback and record history (play_hist and rec_hist 
     
    151152 
    152153   The record history size is as large as the template size (tmpl_cnt), since 
    153    we will use the record history as the template to find the best matching  
     154   we will use the record history as the template to find the best matching 
    154155   position in the playback history. 
    155156 
     
    188189      similar) the signal is. The correlation value is done over the template 
    189190      duration. 
    190     - the gain scaling factor, that is the ratio between mic signal and  
     191    - the gain scaling factor, that is the ratio between mic signal and 
    191192      speaker signal. The ES calculates both the minimum and average ratios. 
    192193 
     
    210211   Processing: 
    211212 
    212    Once learning is done, the ES will change the level of the mic signal  
     213   Once learning is done, the ES will change the level of the mic signal 
    213214   depending on the state of the conversation and according to the ratio that 
    214215   has been found in the learning phase above. 
     
    264265 
    265266/* 
    266  * Create.  
     267 * Create. 
    267268 */ 
    268269PJ_DEF(pj_status_t) echo_supp_create( pj_pool_t *pool, 
     
    293294    ec->play_hist_cnt = (pj_uint16_t)(ec->tail_cnt+ec->templ_cnt); 
    294295 
    295     ec->max_calc = (pj_uint16_t)(MAX_CALC_DURATION_SEC * clock_rate /  
     296    ec->max_calc = (pj_uint16_t)(MAX_CALC_DURATION_SEC * clock_rate / 
    296297                                 ec->samples_per_segment); 
    297298 
    298     ec->rec_hist = (pj_uint16_t*)  
     299    ec->rec_hist = (pj_uint16_t*) 
    299300                    pj_pool_alloc(pool, ec->templ_cnt * 
    300301                                        sizeof(ec->rec_hist[0])); 
    301302 
    302303    /* Note: play history has twice number of elements */ 
    303     ec->play_hist = (pj_uint16_t*)  
     304    ec->play_hist = (pj_uint16_t*) 
    304305                     pj_pool_alloc(pool, ec->play_hist_cnt * 
    305306                                         sizeof(ec->play_hist[0])); 
    306307 
    307308    ec->corr_sum = (float*) 
    308                    pj_pool_alloc(pool, ec->tail_cnt *  
     309                   pj_pool_alloc(pool, ec->tail_cnt * 
    309310                                       sizeof(ec->corr_sum[0])); 
    310311    ec->tmp_corr = (float*) 
    311                    pj_pool_alloc(pool, ec->tail_cnt *  
     312                   pj_pool_alloc(pool, ec->tail_cnt * 
    312313                                       sizeof(ec->tmp_corr[0])); 
    313314    ec->min_factor = (float*) 
    314                      pj_pool_alloc(pool, ec->tail_cnt *  
     315                     pj_pool_alloc(pool, ec->tail_cnt * 
    315316                                         sizeof(ec->min_factor[0])); 
    316317    ec->avg_factor = (float*) 
    317                      pj_pool_alloc(pool, ec->tail_cnt *  
     318                     pj_pool_alloc(pool, ec->tail_cnt * 
    318319                                         sizeof(ec->avg_factor[0])); 
    319320    ec->tmp_factor = (float*) 
    320                      pj_pool_alloc(pool, ec->tail_cnt *  
     321                     pj_pool_alloc(pool, ec->tail_cnt * 
    321322                                         sizeof(ec->tmp_factor[0])); 
    322323    echo_supp_reset(ec); 
     
    328329 
    329330/* 
    330  * Destroy.  
     331 * Destroy. 
    331332 */ 
    332333PJ_DEF(pj_status_t) echo_supp_destroy(void *state) 
     
    394395 
    395396/* Set state */ 
    396 static void echo_supp_set_state(echo_supp *ec, talk_state_t state,  
     397static void echo_supp_set_state(echo_supp *ec, talk_state_t state, 
    397398                                unsigned level) 
    398399{ 
     
    400401 
    401402    if (state != ec->talk_state) { 
    402         TRACE_((THIS_FILE, "[%03d.%03d] %s --> %s, level=%u",  
    403                            (ec->update_cnt * SEGMENT_PTIME / 1000),  
     403        TRACE_((THIS_FILE, "[%03d.%03d] %s --> %s, level=%u", 
     404                           (ec->update_cnt * SEGMENT_PTIME / 1000), 
    404405                           ((ec->update_cnt * SEGMENT_PTIME) % 1000), 
    405406                           state_names[ec->talk_state], 
     
    470471    } else { 
    471472        /* Update from previous calculation */ 
    472         ec->sum_rec_level = ec->sum_rec_level - old_rec_frm_level +  
     473        ec->sum_rec_level = ec->sum_rec_level - old_rec_frm_level + 
    473474                            ec->rec_hist[ec->templ_cnt-1]; 
    474         ec->rec_corr = ec->rec_corr - ((float)ec->rec_hist[0] /  
     475        ec->rec_corr = ec->rec_corr - ((float)ec->rec_hist[0] / 
    475476                                              old_rec_frm_level) + 
    476477                       ((float)ec->rec_hist[ec->templ_cnt-1] / 
     
    483484     * to detect echo. 
    484485     */ 
    485     /*  
    486      * First phase: do full calculation for the first position  
     486    /* 
     487     * First phase: do full calculation for the first position 
    487488     */ 
    488489    if (ec->sum_play_level0 == 0) { 
     
    501502    } else { 
    502503        /* Update from previous calculation */ 
    503         ec->sum_play_level0 = ec->sum_play_level0 - old_play_frm_level +  
     504        ec->sum_play_level0 = ec->sum_play_level0 - old_play_frm_level + 
    504505                              ec->play_hist[ec->templ_cnt-1]; 
    505         ec->play_corr0 = ec->play_corr0 - ((float)ec->play_hist[0] /  
     506        ec->play_corr0 = ec->play_corr0 - ((float)ec->play_hist[0] / 
    506507                                                  old_play_frm_level) + 
    507508                         ((float)ec->play_hist[ec->templ_cnt-1] / 
     
    585586        if (ec->tmp_factor[i] < ec->min_factor[i]) 
    586587            ec->min_factor[i] = ec->tmp_factor[i]; 
    587         ec->avg_factor[i] = ((ec->avg_factor[i] * ec->tail_cnt) +  
     588        ec->avg_factor[i] = ((ec->avg_factor[i] * ec->tail_cnt) + 
    588589                                    ec->tmp_factor[i]) / 
    589590                            (ec->tail_cnt + 1); 
     
    610611        iavg = (int)(ec->avg_factor[ec->tail_index] * 1000); 
    611612 
    612         PJ_LOG(4,(THIS_FILE,  
     613        PJ_LOG(4,(THIS_FILE, 
    613614                  "Echo suppressor updated at t=%03d.%03ds, echo tail=%d msec" 
    614615                  ", factor min/avg=%d.%03d/%d.%03d", 
     
    634635        iavg = (int)(ec->avg_factor[ec->tail_index] * 1000); 
    635636 
    636         PJ_LOG(4,(THIS_FILE,  
     637        PJ_LOG(4,(THIS_FILE, 
    637638                  "Echo suppressor learning done at t=%03d.%03ds, tail=%d ms" 
    638639                  ", factor min/avg=%d.%03d/%d.%03d", 
     
    647648 
    648649/* Amplify frame */ 
    649 static void amplify_frame(pj_int16_t *frm, unsigned length,  
     650static void amplify_frame(pj_int16_t *frm, unsigned length, 
    650651                          pj_ufloat_t factor) 
    651652{ 
     
    657658} 
    658659 
    659 /*  
     660/* 
    660661 * Perform echo cancellation. 
    661662 */ 
     
    710711         * if remote user is currently talking 
    711712         */ 
    712         for (i=ec->play_hist_cnt -lookup_cnt -tail_cnt;  
    713              i<ec->play_hist_cnt-tail_cnt; ++i)  
     713        for (i=ec->play_hist_cnt -lookup_cnt -tail_cnt; 
     714             i<ec->play_hist_cnt-tail_cnt; ++i) 
    714715        { 
    715716            if (ec->play_hist[i] > play_level) 
     
    733734            } else { 
    734735                /* Speaker is active, but we've picked up large signal in 
    735                  * the microphone. Assume that this is an echo, so bring  
     736                 * the microphone. Assume that this is an echo, so bring 
    736737                 * the level down to minimum too. 
    737738                 */ 
     
    763764 
    764765        /* Amplify frame */ 
    765         amplify_frame(rec_frm, ec->samples_per_frame,  
     766        amplify_frame(rec_frm, ec->samples_per_frame, 
    766767                      pj_ufloat_from_float(factor)); 
    767768        ec->last_factor = factor; 
     
    775776 
    776777            /* Accumulate average echo residue to see the ES effectiveness */ 
    777             ec->residue = ((ec->residue * ec->running_cnt) + level) /  
     778            ec->residue = ((ec->residue * ec->running_cnt) + level) / 
    778779                          (ec->running_cnt + 1); 
    779780 
  • pjproject/trunk/pjmedia/src/pjmedia/jbuf.c

    r4537 r4728  
    11/* $Id$ */ 
    2 /*  
     2/* 
    33 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 
    44 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 
     
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1919 */ 
    2020/* 
     
    3636#define INVALID_OFFSET          -9999 
    3737 
    38 /* Maximum burst length, whenever an operation is bursting longer than  
     38/* Maximum burst length, whenever an operation is bursting longer than 
    3939 * this value, JB will assume that the opposite operation was idle. 
    4040 */ 
     
    4747 
    4848 
    49 /* Minimal difference between JB size and 2*burst-level to perform  
    50  * JB shrinking in static discard algorithm.  
     49/* Minimal difference between JB size and 2*burst-level to perform 
     50 * JB shrinking in static discard algorithm. 
    5151 */ 
    5252#define STA_DISC_SAFE_SHRINKING_DIFF    1 
     
    6868    pj_uint32_t     *bit_info;          /**< frame bit info array           */ 
    6969    pj_uint32_t     *ts;                /**< timestamp array                */ 
    70      
     70 
    7171    /* States */ 
    7272    unsigned         head;              /**< index of head, pointed frame 
    7373                                             will be returned by next GET   */ 
    74     unsigned         size;              /**< current size of framelist,  
     74    unsigned         size;              /**< current size of framelist, 
    7575                                             including discarded frames.    */ 
    76     unsigned         discarded_num;     /**< current number of discarded  
     76    unsigned         discarded_num;     /**< current number of discarded 
    7777                                             frames.                        */ 
    7878    int              origin;            /**< original index of flist_head   */ 
     
    9292    pj_size_t       jb_frame_size;      /**< frame size                     */ 
    9393    unsigned        jb_frame_ptime;     /**< frame duration.                */ 
    94     pj_size_t       jb_max_count;       /**< capacity of jitter buffer,  
     94    pj_size_t       jb_max_count;       /**< capacity of jitter buffer, 
    9595                                             in frames                      */ 
    9696    int             jb_init_prefetch;   /**< Initial prefetch               */ 
     
    9898    int             jb_max_prefetch;    /**< Maximum allowable prefetch     */ 
    9999    int             jb_max_burst;       /**< maximum possible burst, whenever 
    100                                              burst exceeds this value, it  
    101                                              won't be included in level  
     100                                             burst exceeds this value, it 
     101                                             won't be included in level 
    102102                                             calculation                    */ 
    103103    int             jb_min_shrink_gap;  /**< How often can we shrink        */ 
     
    108108 
    109109    /* States */ 
    110     int             jb_level;           /**< delay between source &  
    111                                              destination (calculated according  
    112                                              of the number of burst get/put  
     110    int             jb_level;           /**< delay between source & 
     111                                             destination (calculated according 
     112                                             of the number of burst get/put 
    113113                                             operations)                    */ 
    114     int             jb_max_hist_level;  /**< max level during the last level  
     114    int             jb_max_hist_level;  /**< max level during the last level 
    115115                                             calculations                   */ 
    116     int             jb_stable_hist;     /**< num of times the delay has been  
     116    int             jb_stable_hist;     /**< num of times the delay has been 
    117117                                             lower then the prefetch num    */ 
    118     int             jb_last_op;         /**< last operation executed  
     118    int             jb_last_op;         /**< last operation executed 
    119119                                             (put/get)                      */ 
    120120    int             jb_eff_level;       /**< effective burst level          */ 
    121     int             jb_prefetch;        /**< no. of frame to insert before  
    122                                              removing some (at the beginning  
    123                                              of the framelist->content  
     121    int             jb_prefetch;        /**< no. of frame to insert before 
     122                                             removing some (at the beginning 
     123                                             of the framelist->content 
    124124                                             operation), the value may be 
    125125                                             continuously updated based on 
    126126                                             current frame burst level.     */ 
    127127    pj_bool_t       jb_prefetching;     /**< flag if jbuf is prefetching.   */ 
    128     int             jb_status;          /**< status is 'init' until the first  
     128    int             jb_status;          /**< status is 'init' until the first 
    129129                                             'put' operation                */ 
    130     int             jb_init_cycle_cnt;  /**< status is 'init' until the first  
     130    int             jb_init_cycle_cnt;  /**< status is 'init' until the first 
    131131                                             'put' operation                */ 
    132132 
     
    137137 
    138138    /* Statistics */ 
    139     pj_math_stat    jb_delay;           /**< Delay statistics of jitter buffer  
     139    pj_math_stat    jb_delay;           /**< Delay statistics of jitter buffer 
    140140                                             (in ms)                        */ 
    141141    pj_math_stat    jb_burst;           /**< Burst statistics (in frames)   */ 
     
    165165 
    166166 
    167 /* Enabling this would log the jitter buffer state about once per  
     167/* Enabling this would log the jitter buffer state about once per 
    168168 * second. 
    169169 */ 
     
    181181                                      jb_framelist_t *framelist, 
    182182                                      unsigned frame_size, 
    183                                       unsigned max_count)  
     183                                      unsigned max_count) 
    184184{ 
    185185    PJ_ASSERT_RETURN(pool && framelist, PJ_EINVAL); 
     
    189189    framelist->frame_size   = frame_size; 
    190190    framelist->max_count    = max_count; 
    191     framelist->content      = (char*)  
     191    framelist->content      = (char*) 
    192192                              pj_pool_alloc(pool, 
    193                                             framelist->frame_size*  
     193                                            framelist->frame_size* 
    194194                                            framelist->max_count); 
    195195    framelist->frame_type   = (int*) 
    196                               pj_pool_alloc(pool,  
     196                              pj_pool_alloc(pool, 
    197197                                            sizeof(framelist->frame_type[0])* 
    198198                                            framelist->max_count); 
    199199    framelist->content_len  = (pj_size_t*) 
    200                               pj_pool_alloc(pool,  
     200                              pj_pool_alloc(pool, 
    201201                                            sizeof(framelist->content_len[0])* 
    202202                                            framelist->max_count); 
    203203    framelist->bit_info     = (pj_uint32_t*) 
    204                               pj_pool_alloc(pool,  
     204                              pj_pool_alloc(pool, 
    205205                                            sizeof(framelist->bit_info[0])* 
    206206                                            framelist->max_count); 
    207207    framelist->ts           = (pj_uint32_t*) 
    208                               pj_pool_alloc(pool,  
     208                              pj_pool_alloc(pool, 
    209209                                            sizeof(framelist->ts[0])* 
    210210                                            framelist->max_count); 
     
    214214} 
    215215 
    216 static pj_status_t jb_framelist_destroy(jb_framelist_t *framelist)  
     216static pj_status_t jb_framelist_destroy(jb_framelist_t *framelist) 
    217217{ 
    218218    PJ_UNUSED_ARG(framelist); 
     
    220220} 
    221221 
    222 static pj_status_t jb_framelist_reset(jb_framelist_t *framelist)  
     222static pj_status_t jb_framelist_reset(jb_framelist_t *framelist) 
    223223{ 
    224224    framelist->head = 0; 
     
    228228 
    229229 
    230     //pj_bzero(framelist->content,  
    231     //       framelist->frame_size *  
     230    //pj_bzero(framelist->content, 
     231    //       framelist->frame_size * 
    232232    //       framelist->max_count); 
    233233 
    234234    pj_memset(framelist->frame_type, 
    235235              PJMEDIA_JB_MISSING_FRAME, 
    236               sizeof(framelist->frame_type[0]) *  
     236              sizeof(framelist->frame_type[0]) * 
    237237              framelist->max_count); 
    238238 
    239     pj_bzero(framelist->content_len,  
    240              sizeof(framelist->content_len[0]) *  
     239    pj_bzero(framelist->content_len, 
     240             sizeof(framelist->content_len[0]) * 
    241241             framelist->max_count); 
    242242 
    243243    //pj_bzero(framelist->bit_info, 
    244     //       sizeof(framelist->bit_info[0]) *  
     244    //       sizeof(framelist->bit_info[0]) * 
    245245    //       framelist->max_count); 
    246246 
     
    249249 
    250250 
    251 static unsigned jb_framelist_size(const jb_framelist_t *framelist)  
     251static unsigned jb_framelist_size(const jb_framelist_t *framelist) 
    252252{ 
    253253    return framelist->size; 
     
    255255 
    256256 
    257 static unsigned jb_framelist_eff_size(const jb_framelist_t *framelist)  
     257static unsigned jb_framelist_eff_size(const jb_framelist_t *framelist) 
    258258{ 
    259259    return (framelist->size - framelist->discarded_num); 
    260260} 
    261261 
    262 static int jb_framelist_origin(const jb_framelist_t *framelist)  
     262static int jb_framelist_origin(const jb_framelist_t *framelist) 
    263263{ 
    264264    return framelist->origin; 
     
    271271                                  pj_uint32_t *bit_info, 
    272272                                  pj_uint32_t *ts, 
    273                                   int *seq)  
     273                                  int *seq) 
    274274{ 
    275275    if (framelist->size) { 
     
    296296                    *bit_info = 0; 
    297297            } else { 
    298                 pj_memcpy(frame,  
    299                           framelist->content +  
     298                pj_memcpy(frame, 
     299                          framelist->content + 
    300300                          framelist->head * framelist->frame_size, 
    301301                          framelist->frame_size); 
    302                 *p_type = (pjmedia_jb_frame_type)  
     302                *p_type = (pjmedia_jb_frame_type) 
    303303                          framelist->frame_type[framelist->head]; 
    304304                if (size) 
     
    312312                *seq = framelist->origin; 
    313313 
    314             //pj_bzero(framelist->content +  
     314            //pj_bzero(framelist->content + 
    315315            //   framelist->head * framelist->frame_size, 
    316316            //   framelist->frame_size); 
     
    323323            framelist->head = (framelist->head + 1) % framelist->max_count; 
    324324            framelist->size--; 
    325          
     325 
    326326            return PJ_TRUE; 
    327327        } 
     
    342342                                   pj_uint32_t *bit_info, 
    343343                                   pj_uint32_t *ts, 
    344                                    int *seq)  
     344                                   int *seq) 
    345345{ 
    346346    unsigned pos, idx; 
     
    367367        *frame = framelist->content + pos*framelist->frame_size; 
    368368    if (type) 
    369         *type = (pjmedia_jb_frame_type)  
     369        *type = (pjmedia_jb_frame_type) 
    370370                framelist->frame_type[pos]; 
    371371    if (size) 
     
    384384/* Remove oldest frames as many as param 'count' */ 
    385385static unsigned jb_framelist_remove_head(jb_framelist_t *framelist, 
    386                                          unsigned count)  
    387 { 
    388     if (count > framelist->size)  
     386                                         unsigned count) 
     387{ 
     388    if (count > framelist->size) 
    389389        count = framelist->size; 
    390390 
     
    410410        } 
    411411 
    412         //pj_bzero(framelist->content +  
     412        //pj_bzero(framelist->content + 
    413413        //          framelist->head * framelist->frame_size, 
    414414        //          step1*framelist->frame_size); 
     
    440440        framelist->size -= count; 
    441441    } 
    442      
     442 
    443443    return count; 
    444444} 
     
    549549 
    550550 
    551 PJ_DEF(pj_status_t) pjmedia_jbuf_create(pj_pool_t *pool,  
     551PJ_DEF(pj_status_t) pjmedia_jbuf_create(pj_pool_t *pool, 
    552552                                        const pj_str_t *name, 
    553                                         unsigned frame_size,  
     553                                        unsigned frame_size, 
    554554                                        unsigned ptime, 
    555555                                        unsigned max_count, 
     
    597597    PJ_ASSERT_RETURN(prefetch <= jb->jb_max_count, PJ_EINVAL); 
    598598 
    599     jb->jb_min_prefetch = jb->jb_max_prefetch =  
     599    jb->jb_min_prefetch = jb->jb_max_prefetch = 
    600600        jb->jb_prefetch = jb->jb_init_prefetch = prefetch; 
    601601 
     
    676676               "  burst (min/max/avg/dev)=%d/%d/%d/%d frames\n" 
    677677               "  lost=%d discard=%d empty=%d", 
    678                jb_framelist_size(&jb->jb_framelist),  
    679                jb_framelist_eff_size(&jb->jb_framelist),  
     678               jb_framelist_size(&jb->jb_framelist), 
     679               jb_framelist_eff_size(&jb->jb_framelist), 
    680680               jb->jb_prefetch, jb->jb_eff_level, 
    681                jb->jb_delay.min, jb->jb_delay.max, jb->jb_delay.mean,  
     681               jb->jb_delay.min, jb->jb_delay.max, jb->jb_delay.mean, 
    682682               pj_math_stat_get_stddev(&jb->jb_delay), 
    683                jb->jb_burst.min, jb->jb_burst.max, jb->jb_burst.mean,  
     683               jb->jb_burst.min, jb->jb_burst.max, jb->jb_burst.mean, 
    684684               pj_math_stat_get_stddev(&jb->jb_burst), 
    685685               jb->jb_lost, jb->jb_discard, jb->jb_empty)); 
     
    705705 
    706706        enum { STABLE_HISTORY_LIMIT = 20 }; 
    707          
     707 
    708708        jb->jb_stable_hist++; 
    709          
    710         /* Only update the effective level (and prefetch) if 'stable'  
     709 
     710        /* Only update the effective level (and prefetch) if 'stable' 
    711711         * condition is reached (not just short time impulse) 
    712712         */ 
    713713        if (jb->jb_stable_hist > STABLE_HISTORY_LIMIT) { 
    714          
     714 
    715715            diff = (jb->jb_eff_level - jb->jb_max_hist_level) / 3; 
    716716 
     
    724724            if (jb->jb_init_prefetch) { 
    725725                jb->jb_prefetch = jb->jb_eff_level; 
    726                 if (jb->jb_prefetch < jb->jb_min_prefetch)  
     726                if (jb->jb_prefetch < jb->jb_min_prefetch) 
    727727                    jb->jb_prefetch = jb->jb_min_prefetch; 
    728728                if (jb->jb_prefetch > jb->jb_max_prefetch) 
     
    736736            TRACE__((jb->jb_name.ptr,"jb updated(1), lvl=%d pre=%d, size=%d", 
    737737                     jb->jb_eff_level, jb->jb_prefetch, cur_size)); 
     738            PJ_UNUSED_ARG(cur_size); /* Warning about unused var */ 
    738739        } 
    739740    } 
     
    759760        //jb->jb_max_hist_level = 0; 
    760761 
    761         TRACE__((jb->jb_name.ptr,"jb updated(2), lvl=%d pre=%d, size=%d",  
     762        TRACE__((jb->jb_name.ptr,"jb updated(2), lvl=%d pre=%d, size=%d", 
    762763                 jb->jb_eff_level, jb->jb_prefetch, cur_size)); 
    763764    } 
     
    778779     * 
    779780     * Moreover, normally drift level is quite low, so JB shouldn't need 
    780      * to shrink aggresively, it will shrink maximum one frame per  
    781      * PJMEDIA_JBUF_DISC_MIN_GAP ms. Theoritically, JB may handle drift level  
     781     * to shrink aggresively, it will shrink maximum one frame per 
     782     * PJMEDIA_JBUF_DISC_MIN_GAP ms. Theoritically, JB may handle drift level 
    782783     * as much as = FRAME_PTIME/PJMEDIA_JBUF_DISC_MIN_GAP * 100% 
    783784     * 
    784      * Whenever there is drift, where PUT > GET, this method will keep  
     785     * Whenever there is drift, where PUT > GET, this method will keep 
    785786     * the latency (JB size) as much as twice of burst level. 
    786787     */ 
     
    797798        int seq_origin; 
    798799 
    799         /* Check and adjust jb_discard_ref, in case there was  
    800          * seq restart  
     800        /* Check and adjust jb_discard_ref, in case there was 
     801         * seq restart 
    801802         */ 
    802803        seq_origin = jb_framelist_origin(&jb->jb_framelist); 
     
    814815            jb->jb_discard += diff; 
    815816 
    816             TRACE__((jb->jb_name.ptr,  
     817            TRACE__((jb->jb_name.ptr, 
    817818                     "JB shrinking %d frame(s), cur size=%d", diff, 
    818819                     jb_framelist_eff_size(&jb->jb_framelist))); 
     
    846847        T = PJMEDIA_JBUF_PRO_DISC_T2; 
    847848    else 
    848         T = PJMEDIA_JBUF_PRO_DISC_T1 +  
     849        T = PJMEDIA_JBUF_PRO_DISC_T1 + 
    849850            (PJMEDIA_JBUF_PRO_DISC_T2 - PJMEDIA_JBUF_PRO_DISC_T1) * 
    850851            (burst_level - PJMEDIA_JBUF_PRO_DISC_MIN_BURST) / 
     
    874875    if (last_seq >= (jb->jb_discard_ref + (int)jb->jb_discard_dist)) { 
    875876        int discard_seq; 
    876          
     877 
    877878        discard_seq = jb->jb_discard_ref + jb->jb_discard_dist; 
    878879        if (discard_seq < jb_framelist_origin(&jb->jb_framelist)) 
     
    881882        jb_framelist_discard(&jb->jb_framelist, discard_seq); 
    882883 
    883         TRACE__((jb->jb_name.ptr,  
     884        TRACE__((jb->jb_name.ptr, 
    884885                "Discard #%d: ref=#%d dist=%d orig=%d size=%d/%d " 
    885886                "burst=%d/%d", 
     
    897898    } 
    898899} 
    899      
     900 
    900901 
    901902PJ_INLINE(void) jbuf_update(pjmedia_jbuf *jb, int oper) 
     
    905906 
    906907        if (jb->jb_status == JB_STATUS_INITIALIZING) { 
    907             /* Switch status 'initializing' -> 'processing' after some OP  
    908              * switch cycles and current OP is GET (burst level is calculated  
     908            /* Switch status 'initializing' -> 'processing' after some OP 
     909             * switch cycles and current OP is GET (burst level is calculated 
    909910             * based on PUT burst), so burst calculation is guaranted to be 
    910911             * performed right after the status switching. 
     
    922923        } 
    923924 
    924         /* Perform jitter calculation based on PUT burst-level only, since  
     925        /* Perform jitter calculation based on PUT burst-level only, since 
    925926         * GET burst-level may not be accurate, e.g: when VAD is active. 
    926927         * Note that when burst-level is too big, i.e: exceeds jb_max_burst, 
    927          * the GET op may be idle, in this case, we better skip the jitter  
     928         * the GET op may be idle, in this case, we better skip the jitter 
    928929         * calculation. 
    929930         */ 
     
    940941} 
    941942 
    942 PJ_DEF(void) pjmedia_jbuf_put_frame( pjmedia_jbuf *jb,  
    943                                      const void *frame,  
    944                                      pj_size_t frame_size,  
     943PJ_DEF(void) pjmedia_jbuf_put_frame( pjmedia_jbuf *jb, 
     944                                     const void *frame, 
     945                                     pj_size_t frame_size, 
    945946                                     int frame_seq) 
    946947{ 
     
    948949} 
    949950 
    950 PJ_DEF(void) pjmedia_jbuf_put_frame2(pjmedia_jbuf *jb,  
    951                                      const void *frame,  
    952                                      pj_size_t frame_size,  
     951PJ_DEF(void) pjmedia_jbuf_put_frame2(pjmedia_jbuf *jb, 
     952                                     const void *frame, 
     953                                     pj_size_t frame_size, 
    953954                                     pj_uint32_t bit_info, 
    954955                                     int frame_seq, 
    955956                                     pj_bool_t *discarded) 
    956957{ 
    957     pjmedia_jbuf_put_frame3(jb, frame, frame_size, bit_info, frame_seq, 0,  
     958    pjmedia_jbuf_put_frame3(jb, frame, frame_size, bit_info, frame_seq, 0, 
    958959                            discarded); 
    959960} 
    960961 
    961 PJ_DEF(void) pjmedia_jbuf_put_frame3(pjmedia_jbuf *jb,  
    962                                      const void *frame,  
    963                                      pj_size_t frame_size,  
     962PJ_DEF(void) pjmedia_jbuf_put_frame3(pjmedia_jbuf *jb, 
     963                                     const void *frame, 
     964                                     pj_size_t frame_size, 
    964965                                     pj_uint32_t bit_info, 
    965966                                     int frame_seq, 
     
    978979                                 (unsigned)min_frame_size, bit_info, ts, 
    979980                                 PJMEDIA_JB_NORMAL_FRAME); 
    980      
     981 
    981982    /* Jitter buffer is full, remove some older frames */ 
    982983    while (status == PJ_ETOOMANY) { 
     
    10101011    if (status == PJ_SUCCESS) { 
    10111012        if (jb->jb_prefetching) { 
    1012             TRACE__((jb->jb_name.ptr, "PUT prefetch_cnt=%d/%d",  
     1013            TRACE__((jb->jb_name.ptr, "PUT prefetch_cnt=%d/%d", 
    10131014                     new_size, jb->jb_prefetch)); 
    10141015            if (new_size >= jb->jb_prefetch) 
     
    10241025 * Get frame from jitter buffer. 
    10251026 */ 
    1026 PJ_DEF(void) pjmedia_jbuf_get_frame( pjmedia_jbuf *jb,  
    1027                                      void *frame,  
     1027PJ_DEF(void) pjmedia_jbuf_get_frame( pjmedia_jbuf *jb, 
     1028                                     void *frame, 
    10281029                                     char *p_frame_type) 
    10291030{ 
     
    10351036 * Get frame from jitter buffer. 
    10361037 */ 
    1037 PJ_DEF(void) pjmedia_jbuf_get_frame2(pjmedia_jbuf *jb,  
    1038                                      void *frame,  
     1038PJ_DEF(void) pjmedia_jbuf_get_frame2(pjmedia_jbuf *jb, 
     1039                                     void *frame, 
    10391040                                     pj_size_t *size, 
    10401041                                     char *p_frame_type, 
     
    10481049 * Get frame from jitter buffer. 
    10491050 */ 
    1050 PJ_DEF(void) pjmedia_jbuf_get_frame3(pjmedia_jbuf *jb,  
    1051                                      void *frame,  
     1051PJ_DEF(void) pjmedia_jbuf_get_frame3(pjmedia_jbuf *jb, 
     1052                                     void *frame, 
    10521053                                     pj_size_t *size, 
    10531054                                     char *p_frame_type, 
     
    10781079 
    10791080        /* Try to retrieve a frame from frame list */ 
    1080         res = jb_framelist_get(&jb->jb_framelist, frame, size, &ftype,  
     1081        res = jb_framelist_get(&jb->jb_framelist, frame, size, &ftype, 
    10811082                               bit_info, ts, seq); 
    10821083        if (res) { 
     
    10971098                /* We've just retrieved one frame, so add one to cur_size */ 
    10981099                cur_size = jb_framelist_eff_size(&jb->jb_framelist) + 1; 
    1099                 pj_math_stat_update(&jb->jb_delay,  
     1100                pj_math_stat_update(&jb->jb_delay, 
    11001101                                    cur_size*jb->jb_frame_ptime); 
    11011102            } 
     
    11291130    state->min_prefetch = jb->jb_min_prefetch; 
    11301131    state->max_prefetch = jb->jb_max_prefetch; 
    1131      
     1132 
    11321133    state->burst = jb->jb_eff_level; 
    11331134    state->prefetch = jb->jb_prefetch; 
    11341135    state->size = jb_framelist_eff_size(&jb->jb_framelist); 
    1135      
     1136 
    11361137    state->avg_delay = jb->jb_delay.mean; 
    11371138    state->min_delay = jb->jb_delay.min; 
    11381139    state->max_delay = jb->jb_delay.max; 
    11391140    state->dev_delay = pj_math_stat_get_stddev(&jb->jb_delay); 
    1140      
     1141 
    11411142    state->avg_burst = jb->jb_burst.mean; 
    11421143    state->empty = jb->jb_empty; 
     
    11501151PJ_DEF(void) pjmedia_jbuf_peek_frame( pjmedia_jbuf *jb, 
    11511152                                      unsigned offset, 
    1152                                       const void **frame,  
    1153                                       pj_size_t *size,  
     1153                                      const void **frame, 
     1154                                      pj_size_t *size, 
    11541155                                      char *p_frm_type, 
    11551156                                      pj_uint32_t *bit_info, 
     
    11711172 
    11721173 
    1173 PJ_DEF(unsigned) pjmedia_jbuf_remove_frame(pjmedia_jbuf *jb,  
     1174PJ_DEF(unsigned) pjmedia_jbuf_remove_frame(pjmedia_jbuf *jb, 
    11741175                                           unsigned frame_cnt) 
    11751176{ 
  • pjproject/trunk/pjmedia/src/pjmedia/stream.c

    r4613 r4728  
    11/* $Id$ */ 
    2 /*  
     2/* 
    33 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 
    44 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 
     
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1919 */ 
    2020#include <pjmedia/stream.h> 
     
    185185     */ 
    186186    pj_bool_t                has_g722_mpeg_bug; 
    187                                             /**< Flag to specify whether  
    188                                                  normalization process  
     187                                            /**< Flag to specify whether 
     188                                                 normalization process 
    189189                                                 is needed                  */ 
    190190    unsigned                 rtp_tx_ts_len_per_pkt; 
    191191                                            /**< Normalized ts length per packet 
    192                                                  transmitted according to  
     192                                                 transmitted according to 
    193193                                                 'erroneous' definition     */ 
    194194    unsigned                 rtp_rx_ts_len_per_frame; 
    195195                                            /**< Normalized ts length per frame 
    196                                                  received according to  
     196                                                 received according to 
    197197                                                 'erroneous' definition     */ 
    198198    unsigned                 rtp_rx_last_cnt;/**< Nb of frames in last pkt  */ 
     
    203203 
    204204#if defined(PJMEDIA_HAS_RTCP_XR) && (PJMEDIA_HAS_RTCP_XR != 0) 
    205     pj_uint32_t              rtcp_xr_last_tx;  /**< RTCP XR tx time  
     205    pj_uint32_t              rtcp_xr_last_tx;  /**< RTCP XR tx time 
    206206                                                    in timestamp.           */ 
    207207    pj_uint32_t              rtcp_xr_interval; /**< Interval, in timestamp. */ 
    208     pj_sockaddr              rtcp_xr_dest;     /**< Additional remote RTCP XR  
    209                                                     dest. If sin_family is  
     208    pj_sockaddr              rtcp_xr_dest;     /**< Additional remote RTCP XR 
     209                                                    dest. If sin_family is 
    210210                                                    zero, it will be ignored*/ 
    211211    unsigned                 rtcp_xr_dest_len; /**< Length of RTCP XR dest 
     
    231231 
    232232/* RFC 2833 digit */ 
    233 static const char digitmap[16] = { '0', '1', '2', '3',  
    234                                    '4', '5', '6', '7',  
     233static const char digitmap[16] = { '0', '1', '2', '3', 
     234                                   '4', '5', '6', '7', 
    235235                                   '8', '9', '*', '#', 
    236236                                   'A', 'B', 'C', 'D'}; 
     
    285285} 
    286286 
    287 PJ_INLINE(int) trace_jb_print_state(pjmedia_stream *stream,  
     287PJ_INLINE(int) trace_jb_print_state(pjmedia_stream *stream, 
    288288                                    char **buf, pj_ssize_t len) 
    289289{ 
     
    460460 
    461461#else 
    462      
     462 
    463463    PJ_UNUSED_ARG(stream); 
    464464 
     
    498498    samples_per_frame = stream->codec_param.info.frm_ptime * 
    499499                        stream->codec_param.info.clock_rate * 
    500                         stream->codec_param.info.channel_cnt /  
     500                        stream->codec_param.info.channel_cnt / 
    501501                        1000; 
    502502    p_out_samp = (pj_int16_t*) frame->buf; 
    503503 
    504     for (samples_count=0; samples_count < samples_required;  
    505          samples_count += samples_per_frame)  
     504    for (samples_count=0; samples_count < samples_required; 
     505         samples_count += samples_per_frame) 
    506506    { 
    507507        char frame_type; 
     
    518518 
    519519        if (frame_type == PJMEDIA_JB_MISSING_FRAME) { 
    520              
     520 
    521521            /* Activate PLC */ 
    522             if (stream->codec->op->recover &&  
     522            if (stream->codec->op->recover && 
    523523                stream->codec_param.setting.plc && 
    524                 stream->plc_cnt < stream->max_plc_cnt)  
     524                stream->plc_cnt < stream->max_plc_cnt) 
    525525            { 
    526526                pjmedia_frame frame_out; 
     
    561561            /* Jitter buffer is empty. If this is the first "empty" state, 
    562562             * activate PLC to smoothen the fade-out, otherwise zero 
    563              * the frame.  
     563             * the frame. 
    564564             */ 
    565565            //Using this "if" will only invoke PLC for the first packet 
     
    568568            if (1) { 
    569569                /* Activate PLC to smoothen the missing frame */ 
    570                 if (stream->codec->op->recover &&  
     570                if (stream->codec->op->recover && 
    571571                    stream->codec_param.setting.plc && 
    572                     stream->plc_cnt < stream->max_plc_cnt)  
     572                    stream->plc_cnt < stream->max_plc_cnt) 
    573573                { 
    574574                    pjmedia_frame frame_out; 
     
    590590 
    591591                    with_plc = ", plc invoked"; 
    592                 }  
     592                } 
    593593            } 
    594594 
     
    604604                /* Report changing frame type event */ 
    605605                pjmedia_jbuf_get_state(stream->jb, &jb_state); 
    606                 PJ_LOG(5,(stream->port.info.name.ptr,  
    607                           "Jitter buffer empty (prefetch=%d)%s",  
     606                PJ_LOG(5,(stream->port.info.name.ptr, 
     607                          "Jitter buffer empty (prefetch=%d)%s", 
    608608                          jb_state.prefetch, with_plc)); 
    609609 
     
    623623 
    624624            /* Always activate PLC when it's available.. */ 
    625             if (stream->codec->op->recover &&  
     625            if (stream->codec->op->recover && 
    626626                stream->codec_param.setting.plc && 
    627                 stream->plc_cnt < stream->max_plc_cnt)  
     627                stream->plc_cnt < stream->max_plc_cnt) 
    628628            { 
    629629                pjmedia_frame frame_out; 
     
    645645 
    646646                with_plc = ", plc invoked"; 
    647             }  
     647            } 
    648648 
    649649            if (samples_count < samples_required) { 
     
    658658                /* Report changing frame type event */ 
    659659                pjmedia_jbuf_get_state(stream->jb, &jb_state); 
    660                 PJ_LOG(5,(stream->port.info.name.ptr,  
    661                           "Jitter buffer is bufferring (prefetch=%d)%s",  
     660                PJ_LOG(5,(stream->port.info.name.ptr, 
     661                          "Jitter buffer is bufferring (prefetch=%d)%s", 
    662662                          jb_state.prefetch, with_plc)); 
    663663 
     
    684684            frame_out.size = frame->size - samples_count*BYTES_PER_SAMPLE; 
    685685            status = pjmedia_codec_decode( stream->codec, &frame_in, 
    686                                            (unsigned)frame_out.size,  
     686                                           (unsigned)frame_out.size, 
    687687                                           &frame_out); 
    688688            if (status != 0) { 
    689                 LOGERR_((port->info.name.ptr, "codec decode() error",  
     689                LOGERR_((port->info.name.ptr, "codec decode() error", 
    690690                         status)); 
    691691 
    692                 pjmedia_zero_samples(p_out_samp + samples_count,  
     692                pjmedia_zero_samples(p_out_samp + samples_count, 
    693693                                     samples_per_frame); 
    694694            } 
     
    696696            if (stream->jb_last_frm != frame_type) { 
    697697                /* Report changing frame type event */ 
    698                 PJ_LOG(5,(stream->port.info.name.ptr,  
     698                PJ_LOG(5,(stream->port.info.name.ptr, 
    699699                          "Jitter buffer starts returning normal frames " 
    700700                          "(after %d empty/lost)", 
     
    753753    samples_per_frame = stream->codec_param.info.frm_ptime * 
    754754                        stream->codec_param.info.clock_rate * 
    755                         stream->codec_param.info.channel_cnt /  
     755                        stream->codec_param.info.channel_cnt / 
    756756                        1000; 
    757757 
     
    774774        trace_jb_get(stream, frame_type, frame_size); 
    775775#endif 
    776          
     776 
    777777        /* Unlock jitter buffer mutex. */ 
    778778        pj_mutex_unlock( stream->jb_mutex ); 
     
    791791                                           0, frame); 
    792792            if (status != PJ_SUCCESS) { 
    793                 LOGERR_((port->info.name.ptr, "codec decode() error",  
     793                LOGERR_((port->info.name.ptr, "codec decode() error", 
    794794                         status)); 
    795795                pjmedia_frame_ext_append_subframe(f, NULL, 0, 
     
    799799            if (stream->jb_last_frm != frame_type) { 
    800800                /* Report changing frame type event */ 
    801                 PJ_LOG(5,(stream->port.info.name.ptr,  
     801                PJ_LOG(5,(stream->port.info.name.ptr, 
    802802                          "Jitter buffer starts returning normal frames " 
    803803                          "(after %d empty/lost)", 
     
    817817                status = pjmedia_codec_recover(stream->codec, 0, frame); 
    818818            } 
    819              
     819 
    820820            /* No PLC or PLC failed */ 
    821821            if (!stream->codec->op->recover || status != PJ_SUCCESS) { 
     
    840840                    /* Report changing frame type event */ 
    841841                    pjmedia_jbuf_get_state(stream->jb, &jb_state); 
    842                     PJ_LOG(5,(stream->port.info.name.ptr,  
    843                               "Jitter buffer empty (prefetch=%d)",  
     842                    PJ_LOG(5,(stream->port.info.name.ptr, 
     843                              "Jitter buffer empty (prefetch=%d)", 
    844844                              jb_state.prefetch)); 
    845845 
     
    859859                    /* Report changing frame type event */ 
    860860                    pjmedia_jbuf_get_state(stream->jb, &jb_state); 
    861                     PJ_LOG(5,(stream->port.info.name.ptr,  
     861                    PJ_LOG(5,(stream->port.info.name.ptr, 
    862862                              "Jitter buffer is bufferring (prefetch=%d)", 
    863863                              jb_state.prefetch)); 
     
    879879 * Transmit DTMF 
    880880 */ 
    881 static void create_dtmf_payload(pjmedia_stream *stream,  
     881static void create_dtmf_payload(pjmedia_stream *stream, 
    882882                                struct pjmedia_frame *frame_out, 
    883883                                int forced_last, int *first, int *last) 
     
    885885    pjmedia_rtp_dtmf_event *event; 
    886886    struct dtmf *digit = &stream->tx_dtmf_buf[0]; 
    887     pj_uint32_t cur_ts; 
    888887 
    889888    pj_assert(sizeof(pjmedia_rtp_dtmf_event) == 4); 
     
    892891 
    893892    event = (pjmedia_rtp_dtmf_event*) frame_out->buf; 
    894     cur_ts = pj_ntohl(stream->enc->rtp.out_hdr.ts); 
    895893 
    896894    if (digit->duration == 0) { 
    897         PJ_LOG(5,(stream->port.info.name.ptr, "Sending DTMF digit id %c",  
     895        PJ_LOG(5,(stream->port.info.name.ptr, "Sending DTMF digit id %c", 
    898896                  digitmap[digit->event])); 
    899897        *first = 1; 
     
    988986        /* Update RTCP XR with current JB states */ 
    989987        pjmedia_jbuf_get_state(stream->jb, &jb_state); 
    990              
     988 
    991989        i = jb_state.avg_delay; 
    992         status = pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session,  
     990        status = pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 
    993991                                             PJMEDIA_RTCP_XR_INFO_JB_NOM, i); 
    994992        pj_assert(status == PJ_SUCCESS); 
    995993 
    996994        i = jb_state.max_delay; 
    997         status = pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session,  
     995        status = pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 
    998996                                             PJMEDIA_RTCP_XR_INFO_JB_MAX, i); 
    999997        pj_assert(status == PJ_SUCCESS); 
     
    10081006            /* Send the RTCP XR to third-party destination if specified */ 
    10091007            if (stream->rtcp_xr_dest_len) { 
    1010                 pjmedia_transport_send_rtcp2(stream->transport,  
     1008                pjmedia_transport_send_rtcp2(stream->transport, 
    10111009                                             &stream->rtcp_xr_dest, 
    1012                                              stream->rtcp_xr_dest_len,  
     1010                                             stream->rtcp_xr_dest_len, 
    10131011                                             xr_pkt, xr_len); 
    10141012            } 
     
    10501048static void check_tx_rtcp(pjmedia_stream *stream, pj_uint32_t timestamp) 
    10511049{ 
    1052     /* Note that timestamp may represent local or remote timestamp,  
     1050    /* Note that timestamp may represent local or remote timestamp, 
    10531051     * depending on whether this function is called from put_frame() 
    10541052     * or get_frame(). 
     
    10561054 
    10571055    if (stream->rtcp_last_tx == 0) { 
    1058          
     1056 
    10591057        stream->rtcp_last_tx = timestamp; 
    10601058 
     
    10671065            if (stream->rtcp_xr_last_tx == 0) { 
    10681066                stream->rtcp_xr_last_tx = timestamp; 
    1069             } else if (timestamp - stream->rtcp_xr_last_tx >=  
     1067            } else if (timestamp - stream->rtcp_xr_last_tx >= 
    10701068                       stream->rtcp_xr_interval) 
    10711069            { 
     
    11311129 
    11321130    /* How many samples are needed */ 
    1133     count = stream->codec_param.info.enc_ptime *  
     1131    count = stream->codec_param.info.enc_ptime * 
    11341132            PJMEDIA_PIA_SRATE(&stream->port.info) / 1000; 
    11351133 
     
    11541152 * put_frame_imp() 
    11551153 */ 
    1156 static pj_status_t put_frame_imp( pjmedia_port *port,  
     1154static pj_status_t put_frame_imp( pjmedia_port *port, 
    11571155                                  pjmedia_frame *frame ) 
    11581156{ 
     
    11751173        pj_uint32_t dtx_duration; 
    11761174 
    1177         dtx_duration = pj_timestamp_diff32(&stream->last_frm_ts_sent,  
     1175        dtx_duration = pj_timestamp_diff32(&stream->last_frm_ts_sent, 
    11781176                                           &frame->timestamp); 
    11791177        if (dtx_duration > 
     
    11941192    /* Number of samples in the frame */ 
    11951193    if (frame->type == PJMEDIA_FRAME_TYPE_AUDIO) 
    1196         ts_len = ((unsigned)frame->size >> 1) /  
     1194        ts_len = ((unsigned)frame->size >> 1) / 
    11971195                 stream->codec_param.info.channel_cnt; 
    11981196    else if (frame->type == PJMEDIA_FRAME_TYPE_EXTENDED) 
     
    12061204 
    12071205#if defined(PJMEDIA_HANDLE_G722_MPEG_BUG) && (PJMEDIA_HANDLE_G722_MPEG_BUG!=0) 
    1208     /* Handle special case for audio codec with RTP timestamp inconsistence  
     1206    /* Handle special case for audio codec with RTP timestamp inconsistence 
    12091207     * e.g: G722, MPEG audio. 
    12101208     */ 
     
    12251223 
    12261224 
    1227     /* If we have DTMF digits in the queue, transmit the digits.  
     1225    /* If we have DTMF digits in the queue, transmit the digits. 
    12281226     * Otherwise encode the PCM buffer. 
    12291227     */ 
     
    12351233        /* Encapsulate into RTP packet. Note that: 
    12361234         *  - RTP marker should be set on the beginning of a new event 
    1237          *  - RTP timestamp is constant for the same packet.  
     1235         *  - RTP timestamp is constant for the same packet. 
    12381236         */ 
    1239         status = pjmedia_rtp_encode_rtp( &channel->rtp,  
    1240                                          stream->tx_event_pt, first,  
     1237        status = pjmedia_rtp_encode_rtp( &channel->rtp, 
     1238                                         stream->tx_event_pt, first, 
    12411239                                         (int)frame_out.size, 
    1242                                          (first ? rtp_ts_len : 0),  
    1243                                          (const void**)&rtphdr,  
     1240                                         (first ? rtp_ts_len : 0), 
     1241                                         (const void**)&rtphdr, 
    12441242                                         &rtphdrlen); 
    12451243 
    12461244        if (last) { 
    1247             /* This is the last packet for the event.  
     1245            /* This is the last packet for the event. 
    12481246             * Increment the RTP timestamp of the RTP session, for next 
    12491247             * RTP packets. 
     
    12721270               stream->codec_param.info.channel_cnt * 
    12731271               stream->codec_param.info.clock_rate/1000 < 
    1274                   PJ_ARRAY_SIZE(zero_frame))  
     1272                  PJ_ARRAY_SIZE(zero_frame)) 
    12751273    { 
    12761274        pjmedia_frame silence_frame; 
     
    12831281        silence_frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 
    12841282        silence_frame.timestamp.u32.lo = pj_ntohl(stream->enc->rtp.out_hdr.ts); 
    1285          
     1283 
    12861284        /* Encode! */ 
    12871285        status = pjmedia_codec_encode( stream->codec, &silence_frame, 
    1288                                        channel->out_pkt_size -  
     1286                                       channel->out_pkt_size - 
    12891287                                       sizeof(pjmedia_rtp_hdr), 
    12901288                                       &frame_out); 
    12911289        if (status != PJ_SUCCESS) { 
    1292             LOGERR_((stream->port.info.name.ptr,  
     1290            LOGERR_((stream->port.info.name.ptr, 
    12931291                    "Codec encode() error", status)); 
    12941292            return status; 
     
    12961294 
    12971295        /* Encapsulate. */ 
    1298         status = pjmedia_rtp_encode_rtp( &channel->rtp,  
    1299                                          channel->pt, 0,  
    1300                                          (int)frame_out.size, rtp_ts_len,  
    1301                                          (const void**)&rtphdr,  
     1296        status = pjmedia_rtp_encode_rtp( &channel->rtp, 
     1297                                         channel->pt, 0, 
     1298                                         (int)frame_out.size, rtp_ts_len, 
     1299                                         (const void**)&rtphdr, 
    13021300                                         &rtphdrlen); 
    13031301 
     
    13091307    { 
    13101308        /* Encode! */ 
    1311         status = pjmedia_codec_encode( stream->codec, frame,  
    1312                                        channel->out_pkt_size -  
     1309        status = pjmedia_codec_encode( stream->codec, frame, 
     1310                                       channel->out_pkt_size - 
    13131311                                       sizeof(pjmedia_rtp_hdr), 
    13141312                                       &frame_out); 
    13151313        if (status != PJ_SUCCESS) { 
    1316             LOGERR_((stream->port.info.name.ptr,  
     1314            LOGERR_((stream->port.info.name.ptr, 
    13171315                    "Codec encode() error", status)); 
    13181316            return status; 
     
    13201318 
    13211319        /* Encapsulate. */ 
    1322         status = pjmedia_rtp_encode_rtp( &channel->rtp,  
    1323                                          channel->pt, 0,  
    1324                                          (int)frame_out.size, rtp_ts_len,  
    1325                                          (const void**)&rtphdr,  
     1320        status = pjmedia_rtp_encode_rtp( &channel->rtp, 
     1321                                         channel->pt, 0, 
     1322                                         (int)frame_out.size, rtp_ts_len, 
     1323                                         (const void**)&rtphdr, 
    13261324                                         &rtphdrlen); 
    13271325 
     
    13291327 
    13301328        /* Just update RTP session's timestamp. */ 
    1331         status = pjmedia_rtp_encode_rtp( &channel->rtp,  
    1332                                          0, 0,  
    1333                                          0, rtp_ts_len,  
    1334                                          (const void**)&rtphdr,  
     1329        status = pjmedia_rtp_encode_rtp( &channel->rtp, 
     1330                                         0, 0, 
     1331                                         0, rtp_ts_len, 
     1332                                         (const void**)&rtphdr, 
    13351333                                         &rtphdrlen); 
    13361334 
     
    13381336 
    13391337    if (status != PJ_SUCCESS) { 
    1340         LOGERR_((stream->port.info.name.ptr,  
     1338        LOGERR_((stream->port.info.name.ptr, 
    13411339                "RTP encode_rtp() error", status)); 
    13421340        return status; 
    13431341    } 
    13441342 
    1345     /* Check if now is the time to transmit RTCP SR/RR report.  
     1343    /* Check if now is the time to transmit RTCP SR/RR report. 
    13461344     * We only do this when stream direction is not "decoding only", because 
    13471345     * when it is, check_tx_rtcp() will be handled by get_frame(). 
     
    14141412 * RTP packet, and transmit to peer. 
    14151413 */ 
    1416 static pj_status_t put_frame( pjmedia_port *port,  
     1414static pj_status_t put_frame( pjmedia_port *port, 
    14171415                              pjmedia_frame *frame ) 
    14181416{ 
     
    14621460     */ 
    14631461    if (stream->vad_enabled != stream->codec_param.setting.vad && 
    1464         (stream->tx_duration - stream->ts_vad_disabled) >  
     1462        (stream->tx_duration - stream->ts_vad_disabled) > 
    14651463           PJMEDIA_PIA_SRATE(&stream->port.info) * 
    14661464          PJMEDIA_STREAM_VAD_SUSPEND_MSEC / 1000) 
     
    14791477        pj_status_t status = PJ_SUCCESS; 
    14801478 
    1481         /* Copy original frame to temporary frame since we need  
     1479        /* Copy original frame to temporary frame since we need 
    14821480         * to modify it. 
    14831481         */ 
     
    15461544 * Handle incoming DTMF digits. 
    15471545 */ 
    1548 static void handle_incoming_dtmf( pjmedia_stream *stream,  
     1546static void handle_incoming_dtmf( pjmedia_stream *stream, 
    15491547                                  const void *payload, unsigned payloadlen) 
    15501548{ 
     
    15721570    /* Ignore unknown event. */ 
    15731571    if (event->event > 15) { 
    1574         PJ_LOG(5,(stream->port.info.name.ptr,  
     1572        PJ_LOG(5,(stream->port.info.name.ptr, 
    15751573                  "Ignored RTP pkt with bad DTMF event %d", 
    15761574                  event->event)); 
     
    15911589    if (stream->dtmf_cb) { 
    15921590 
    1593         stream->dtmf_cb(stream, stream->dtmf_cb_user_data,  
     1591        stream->dtmf_cb(stream, stream->dtmf_cb_user_data, 
    15941592                        digitmap[event->event]); 
    15951593 
     
    16011599        if (stream->rx_dtmf_count >= PJ_ARRAY_SIZE(stream->rx_dtmf_buf)) { 
    16021600            /* DTMF digits overflow.  Discard the oldest digit. */ 
    1603             pj_array_erase(stream->rx_dtmf_buf,  
     1601            pj_array_erase(stream->rx_dtmf_buf, 
    16041602                           sizeof(stream->rx_dtmf_buf[0]), 
    16051603                           stream->rx_dtmf_count, 0); 
     
    16141612/* 
    16151613 * This callback is called by stream transport on receipt of packets 
    1616  * in the RTP socket.  
    1617  */ 
    1618 static void on_rx_rtp( void *data,  
     1614 * in the RTP socket. 
     1615 */ 
     1616static void on_rx_rtp( void *data, 
    16191617                       void *pkt, 
    16201618                       pj_ssize_t bytes_read) 
     
    16321630    /* Check for errors */ 
    16331631    if (bytes_read < 0) { 
    1634         LOGERR_((stream->port.info.name.ptr, "RTP recv() error",  
     1632        LOGERR_((stream->port.info.name.ptr, "RTP recv() error", 
    16351633                (pj_status_t)-bytes_read)); 
    16361634        return; 
     
    16601658                                hdr->pt != stream->rx_event_pt); 
    16611659    if (seq_st.status.value) { 
    1662         TRC_  ((stream->port.info.name.ptr,  
     1660        TRC_  ((stream->port.info.name.ptr, 
    16631661                "RTP status: badpt=%d, badssrc=%d, dup=%d, " 
    1664                 "outorder=%d, probation=%d, restart=%d",  
     1662                "outorder=%d, probation=%d, restart=%d", 
    16651663                seq_st.status.flag.badpt, 
    16661664                seq_st.status.flag.badssrc, 
     
    17371735                                     payloadlen, &ts, &count, frames); 
    17381736        if (status != PJ_SUCCESS) { 
    1739             LOGERR_((stream->port.info.name.ptr,  
    1740                      "Codec parse() error",  
     1737            LOGERR_((stream->port.info.name.ptr, 
     1738                     "Codec parse() error", 
    17411739                     status)); 
    17421740            count = 0; 
     
    17461744        /* This code is used to learn the samples per frame value that is put 
    17471745         * by remote endpoint, for codecs with inconsistent clock rate such 
    1748          * as G.722 or MPEG audio. We need to learn the samples per frame  
     1746         * as G.722 or MPEG audio. We need to learn the samples per frame 
    17491747         * value as it is used as divider when inserting frames into the 
    17501748         * jitter buffer. 
     
    17521750        if (stream->has_g722_mpeg_bug) { 
    17531751            if (stream->rtp_rx_check_cnt) { 
    1754                 /* Make sure the detection performed only on two consecutive  
     1752                /* Make sure the detection performed only on two consecutive 
    17551753                 * packets with valid RTP sequence and no wrapped timestamp. 
    17561754                 */ 
    1757                 if (seq_st.diff == 1 && stream->rtp_rx_last_ts &&  
    1758                     ts.u64 > stream->rtp_rx_last_ts &&  
     1755                if (seq_st.diff == 1 && stream->rtp_rx_last_ts && 
     1756                    ts.u64 > stream->rtp_rx_last_ts && 
    17591757                    stream->rtp_rx_last_cnt > 0) 
    17601758                { 
     
    17681766 
    17691767                    /* Get remote frame timestamp span */ 
    1770                     peer_frm_ts_diff =  
    1771                         ((pj_uint32_t)ts.u64-stream->rtp_rx_last_ts) /  
     1768                    peer_frm_ts_diff = 
     1769                        ((pj_uint32_t)ts.u64-stream->rtp_rx_last_ts) / 
    17721770                        stream->rtp_rx_last_cnt; 
    17731771 
     
    17781776                     */ 
    17791777                    if (stream->codec_param.info.pt == PJMEDIA_RTP_PT_G722 && 
    1780                         (peer_frm_ts_diff == frm_ts_span ||  
     1778                        (peer_frm_ts_diff == frm_ts_span || 
    17811779                         peer_frm_ts_diff == (frm_ts_span>>1))) 
    17821780                    { 
     
    17901788                        if (--stream->rtp_rx_check_cnt == 0) { 
    17911789                            PJ_LOG(4, (THIS_FILE, "G722 codec used, remote" 
    1792                                        " samples per frame detected = %d",  
     1790                                       " samples per frame detected = %d", 
    17931791                                       stream->rtp_rx_ts_len_per_frame)); 
    1794                              
     1792 
    17951793                            /* Reset jitter buffer once detection done */ 
    17961794                            pjmedia_jbuf_reset(stream->jb); 
     
    18111809 
    18121810        } else { 
    1813             ts_span = stream->codec_param.info.frm_ptime *  
     1811            ts_span = stream->codec_param.info.frm_ptime * 
    18141812                      stream->codec_param.info.clock_rate / 
    18151813                      1000; 
    18161814        } 
    18171815#else 
    1818         ts_span = stream->codec_param.info.frm_ptime *  
     1816        ts_span = stream->codec_param.info.frm_ptime * 
    18191817                  stream->codec_param.info.clock_rate / 
    18201818                  1000; 
     
    18421840 
    18431841    /* Check if now is the time to transmit RTCP SR/RR report. 
    1844      * We only do this when stream direction is "decoding only",  
     1842     * We only do this when stream direction is "decoding only", 
    18451843     * because otherwise check_tx_rtcp() will be handled by put_frame() 
    18461844     */ 
     
    18501848 
    18511849    if (status != 0) { 
    1852         LOGERR_((stream->port.info.name.ptr, "Jitter buffer put() error",  
     1850        LOGERR_((stream->port.info.name.ptr, "Jitter buffer put() error", 
    18531851                status)); 
    18541852        pkt_discarded = PJ_TRUE; 
     
    18801878/* 
    18811879 * This callback is called by stream transport on receipt of packets 
    1882  * in the RTCP socket.  
     1880 * in the RTCP socket. 
    18831881 */ 
    18841882static void on_rx_rtcp( void *data, 
    1885                         void *pkt,  
     1883                        void *pkt, 
    18861884                        pj_ssize_t bytes_read) 
    18871885{ 
     
    18901888    /* Check for errors */ 
    18911889    if (bytes_read < 0) { 
    1892         LOGERR_((stream->port.info.name.ptr, "RTCP recv() error",  
     1890        LOGERR_((stream->port.info.name.ptr, "RTCP recv() error", 
    18931891                (pj_status_t)-bytes_read)); 
    18941892        return; 
     
    19111909    pjmedia_channel *channel; 
    19121910    pj_status_t status; 
    1913      
     1911 
    19141912    /* Allocate memory for channel descriptor */ 
    19151913 
     
    19241922    channel->pt = pt; 
    19251923 
    1926      
     1924 
    19271925    /* Allocate buffer for outgoing packet. */ 
    19281926 
    19291927    if (param->type == PJMEDIA_TYPE_AUDIO) { 
    1930         channel->out_pkt_size = sizeof(pjmedia_rtp_hdr) +  
    1931                                 stream->codec_param.info.max_bps *  
    1932                                 PJMEDIA_MAX_FRAME_DURATION_MS /  
     1928        channel->out_pkt_size = sizeof(pjmedia_rtp_hdr) + 
     1929                                stream->codec_param.info.max_bps * 
     1930                                PJMEDIA_MAX_FRAME_DURATION_MS / 
    19331931                                8 / 1000; 
    19341932        if (channel->out_pkt_size > PJMEDIA_MAX_MTU - 
     
    20782076        stream->codec_param = *info->param; 
    20792077    else { 
    2080         status = pjmedia_codec_mgr_get_default_param(stream->codec_mgr,  
    2081                                                      &info->fmt,  
     2078        status = pjmedia_codec_mgr_get_default_param(stream->codec_mgr, 
     2079                                                     &info->fmt, 
    20822080                                                     &stream->codec_param); 
    20832081        if (status != PJ_SUCCESS) 
     
    21372135    /* If encoder and decoder's ptime are asymmetric, then we need to 
    21382136     * create buffer on the encoder side. This could happen for example 
    2139      * with iLBC  
     2137     * with iLBC 
    21402138     */ 
    21412139    if (stream->codec_param.info.enc_ptime!=0 && 
     
    21852183        stream->frame_size = stream->codec_param.info.max_rx_frame_size; 
    21862184    } else { 
    2187         stream->frame_size = stream->codec_param.info.max_bps *  
     2185        stream->frame_size = stream->codec_param.info.max_bps * 
    21882186                             stream->codec_param.info.frm_ptime / 8 / 1000; 
    21892187        if ((stream->codec_param.info.max_bps * 
     
    22182216    /* Init jitter buffer parameters: */ 
    22192217    if (info->jb_max >= stream->codec_param.info.frm_ptime) 
    2220         jb_max = (info->jb_max + stream->codec_param.info.frm_ptime - 1) /  
     2218        jb_max = (info->jb_max + stream->codec_param.info.frm_ptime - 1) / 
    22212219                 stream->codec_param.info.frm_ptime; 
    22222220    else 
     
    22432241    /* Create jitter buffer */ 
    22442242    status = pjmedia_jbuf_create(pool, &stream->port.info.name, 
    2245                                  stream->frame_size,  
     2243                                 stream->frame_size, 
    22462244                                 stream->codec_param.info.frm_ptime, 
    22472245                                 jb_max, &stream->jb); 
     
    22552253    /* Create decoder channel: */ 
    22562254 
    2257     status = create_channel( pool, stream, PJMEDIA_DIR_DECODING,  
     2255    status = create_channel( pool, stream, PJMEDIA_DIR_DECODING, 
    22582256                             info->rx_pt, info, &stream->dec); 
    22592257    if (status != PJ_SUCCESS) 
     
    22632261    /* Create encoder channel: */ 
    22642262 
    2265     status = create_channel( pool, stream, PJMEDIA_DIR_ENCODING,  
     2263    status = create_channel( pool, stream, PJMEDIA_DIR_ENCODING, 
    22662264                             info->tx_pt, info, &stream->enc); 
    22672265    if (status != PJ_SUCCESS) 
     
    23162314 
    23172315    /* Only attach transport when stream is ready. */ 
    2318     status = pjmedia_transport_attach(tp, stream, &info->rem_addr,  
    2319                                       &info->rem_rtcp,  
    2320                                       pj_sockaddr_get_len(&info->rem_addr),  
     2316    status = pjmedia_transport_attach(tp, stream, &info->rem_addr, 
     2317                                      &info->rem_rtcp, 
     2318                                      pj_sockaddr_get_len(&info->rem_addr), 
    23212319                                      &on_rx_rtp, &on_rx_rtcp); 
    23222320    if (status != PJ_SUCCESS) 
     
    23362334            stream->rtcp_xr_interval = info->rtcp_xr_interval; 
    23372335        else 
    2338             stream->rtcp_xr_interval = (PJMEDIA_RTCP_INTERVAL +  
    2339                                        (pj_rand() % 8000)) *  
     2336            stream->rtcp_xr_interval = (PJMEDIA_RTCP_INTERVAL + 
     2337                                       (pj_rand() % 8000)) * 
    23402338                                       info->fmt.clock_rate / 1000; 
    23412339 
     
    23492347        /* jitter buffer adaptive info */ 
    23502348        i = PJMEDIA_RTCP_XR_JB_ADAPTIVE; 
    2351         pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session,  
     2349        pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 
    23522350                                    PJMEDIA_RTCP_XR_INFO_CONF_JBA, 
    23532351                                    i); 
     
    23552353        /* Jitter buffer aggressiveness info (estimated) */ 
    23562354        i = 7; 
    2357         pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session,  
     2355        pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 
    23582356                                    PJMEDIA_RTCP_XR_INFO_CONF_JBR, 
    23592357                                    i); 
     
    23612359        /* Jitter buffer absolute maximum delay */ 
    23622360        i = jb_max * stream->codec_param.info.frm_ptime; 
    2363         pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session,  
     2361        pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 
    23642362                                    PJMEDIA_RTCP_XR_INFO_JB_ABS_MAX, 
    23652363                                    i); 
     
    23742372            i = PJMEDIA_RTCP_XR_PLC_DIS; 
    23752373#endif 
    2376         pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session,  
     2374        pjmedia_rtcp_xr_update_info(&stream->rtcp.xr_session, 
    23772375                                    PJMEDIA_RTCP_XR_INFO_CONF_PLC, 
    23782376                                    i); 
     
    23962394        pj_ssize_t len; 
    23972395 
    2398         pj_ansi_snprintf(trace_name, sizeof(trace_name),  
     2396        pj_ansi_snprintf(trace_name, sizeof(trace_name), 
    23992397                         TRACE_JB_PATH_PREFIX "%s.csv", 
    24002398                         stream->port.info.name.ptr); 
     
    24022400        if (status != PJ_SUCCESS) { 
    24032401            stream->trace_jb_fd = TRACE_JB_INVALID_FD; 
    2404             PJ_LOG(3,(THIS_FILE, "Failed creating RTP trace file '%s'",  
     2402            PJ_LOG(3,(THIS_FILE, "Failed creating RTP trace file '%s'", 
    24052403                      trace_name)); 
    24062404        } else { 
     
    24902488    } 
    24912489 
    2492     /* Detach from transport  
     2490    /* Detach from transport 
    24932491     * MUST NOT hold stream mutex while detaching from transport, as 
    24942492     * it may cause deadlock. See ticket #460 for the details. 
     
    25132511 
    25142512    /* Free mutex */ 
    2515      
     2513 
    25162514    if (stream->jb_mutex) { 
    25172515        pj_mutex_destroy(stream->jb_mutex); 
     
    27242722        return PJMEDIA_RTP_EREMNORFC2833; 
    27252723    } 
    2726      
     2724 
    27272725    pj_mutex_lock(stream->jb_mutex); 
    2728      
     2726 
    27292727    if (stream->tx_dtmf_count+digit_char->slen >= 
    27302728        (long)PJ_ARRAY_SIZE(stream->tx_dtmf_buf)) 
     
    27352733 
    27362734        /* convert ASCII digits into payload type first, to make sure 
    2737          * that all digits are valid.  
     2735         * that all digits are valid. 
    27382736         */ 
    27392737        for (i=0; i<digit_char->slen; ++i) { 
     
    27442742            { 
    27452743                pt = dig - '0'; 
    2746             }  
     2744            } 
    27472745            else if (dig >= 'a' && dig <= 'd') 
    27482746            { 
     
    28302828 */ 
    28312829PJ_DEF(pj_status_t) pjmedia_stream_set_dtmf_callback(pjmedia_stream *stream, 
    2832                                  void (*cb)(pjmedia_stream*,  
    2833                                             void *user_data,  
    2834                                             int digit),  
     2830                                 void (*cb)(pjmedia_stream*, 
     2831                                            void *user_data, 
     2832                                            int digit), 
    28352833                                 void *user_data) 
    28362834{ 
  • pjproject/trunk/pjmedia/src/pjmedia/transport_srtp.c

    r4723 r4728  
    11/* $Id$ */ 
    2 /*  
     2/* 
    33 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 
    44 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 
     
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
    1919 */ 
    2020 
     
    4646#define MAX_KEY_LEN                 128 
    4747 
    48 /* Initial value of probation counter. When probation counter > 0,  
     48/* Initial value of probation counter. When probation counter > 0, 
    4949 * it means SRTP is in probation state, and it may restart when 
    5050 * srtp_unprotect() returns err_status_replay_* 
     
    7777 
    7878    /* cipher AES_CM, auth HMAC_SHA1, auth tag len = 10 octets */ 
    79     {"AES_CM_128_HMAC_SHA1_80", AES_128_ICM, 30, HMAC_SHA1, 20, 10, 10,  
     79    {"AES_CM_128_HMAC_SHA1_80", AES_128_ICM, 30, HMAC_SHA1, 20, 10, 10, 
    8080        sec_serv_conf_and_auth}, 
    8181 
     
    8484        sec_serv_conf_and_auth}, 
    8585 
    86     /*  
     86    /* 
    8787     * F8_128_HMAC_SHA1_8 not supported by libsrtp? 
    8888     * {"F8_128_HMAC_SHA1_8", NULL_CIPHER, 0, NULL_AUTH, 0, 0, 0, sec_serv_none} 
     
    125125                                   void *pkt, 
    126126                                   pj_ssize_t size); 
    127          
     127 
    128128    /* Transport information */ 
    129129    pjmedia_transport   *member_tp; /**< Underlying transport.       */ 
     
    131131    /* SRTP usage policy of peer. This field is updated when media is starting. 
    132132     * This is useful when SRTP is in optional mode and peer is using mandatory 
    133      * mode, so when local is about to reinvite/update, it should offer  
     133     * mode, so when local is about to reinvite/update, it should offer 
    134134     * RTP/SAVP instead of offering RTP/AVP. 
    135135     */ 
    136136    pjmedia_srtp_use     peer_use; 
    137137 
    138     /* When probation counter > 0, it means SRTP is in probation state,  
     138    /* When probation counter > 0, it means SRTP is in probation state, 
    139139     * and it may restart when srtp_unprotect() returns err_status_replay_* 
    140140     */ 
     
    206206 
    207207 
    208 static pjmedia_transport_op transport_srtp_op =  
     208static pjmedia_transport_op transport_srtp_op = 
    209209{ 
    210210    &transport_get_info, 
     
    239239        "couldn't deallocate properly",     /* err_status_dealloc_fail  = 4  */ 
    240240        "couldn't initialize",              /* err_status_init_fail     = 5  */ 
    241         "can't process as much data as requested",  
     241        "can't process as much data as requested", 
    242242                                            /* err_status_terminus      = 6  */ 
    243243        "authentication failure",           /* err_status_auth_fail     = 7  */ 
    244244        "cipher failure",                   /* err_status_cipher_fail   = 8  */ 
    245245        "replay check failed (bad index)",  /* err_status_replay_fail   = 9  */ 
    246         "replay check failed (index too old)",  
     246        "replay check failed (index too old)", 
    247247                                            /* err_status_replay_old    = 10 */ 
    248248        "algorithm failed test routine",    /* err_status_algo_fail     = 11 */ 
    249249        "unsupported operation",            /* err_status_no_such_op    = 12 */ 
    250250        "no appropriate context found",     /* err_status_no_ctx        = 13 */ 
    251         "unable to perform desired validation",  
     251        "unable to perform desired validation", 
    252252                                            /* err_status_cant_check    = 14 */ 
    253253        "can't use key any more",           /* err_status_key_expired   = 15 */ 
     
    286286 
    287287        err = srtp_init(); 
    288         if (err != err_status_ok) {  
    289             PJ_LOG(4, (THIS_FILE, "Failed to initialize libsrtp: %s",  
     288        if (err != err_status_ok) { 
     289            PJ_LOG(4, (THIS_FILE, "Failed to initialize libsrtp: %s", 
    290290                       get_libsrtp_errstr(err))); 
    291291            return PJMEDIA_ERRNO_FROM_LIBSRTP(err); 
     
    294294        if (pjmedia_endpt_atexit(endpt, pjmedia_srtp_deinit_lib) != PJ_SUCCESS) 
    295295        { 
    296             /* There will be memory leak when it fails to schedule libsrtp  
     296            /* There will be memory leak when it fails to schedule libsrtp 
    297297             * deinitialization, however the memory leak could be harmless, 
    298              * since in modern OS's memory used by an application is released  
     298             * since in modern OS's memory used by an application is released 
    299299             * when the application terminates. 
    300300             */ 
     
    307307    PJ_UNUSED_ARG(endpt); 
    308308#endif 
    309      
     309 
    310310    return PJ_SUCCESS; 
    311311} 
     
    338338#endif 
    339339    if (err != err_status_ok) { 
    340         PJ_LOG(4, (THIS_FILE, "Failed to deinitialize libsrtp: %s",  
     340        PJ_LOG(4, (THIS_FILE, "Failed to deinitialize libsrtp: %s", 
    341341                   get_libsrtp_errstr(err))); 
    342342    } 
     
    350350    int i; 
    351351    int cs_cnt = sizeof(crypto_suites)/sizeof(crypto_suites[0]); 
    352      
     352 
    353353    /* treat unspecified crypto_name as crypto 'NULL' */ 
    354354    if (crypto_name->slen == 0) 
     
    421421 
    422422    /* Check crypto availability */ 
    423     if (opt && opt->crypto_count == 0 &&  
     423    if (opt && opt->crypto_count == 0 && 
    424424        opt->use == PJMEDIA_SRTP_MANDATORY) 
    425425        return PJMEDIA_SRTP_ESDPREQCRYPTO; 
     
    435435 
    436436            /* check key length */ 
    437             if (opt->crypto[i].key.slen &&  
    438                 opt->crypto[i].key.slen <  
     437            if (opt->crypto[i].key.slen && 
     438                opt->crypto[i].key.slen < 
    439439                (pj_ssize_t)crypto_suites[cs_idx].cipher_key_len) 
    440440                return PJMEDIA_SRTP_EINKEYLEN; 
     
    506506 */ 
    507507PJ_DEF(pj_status_t) pjmedia_transport_srtp_start( 
    508                            pjmedia_transport *tp,  
     508                           pjmedia_transport *tp, 
    509509                           const pjmedia_srtp_crypto *tx, 
    510510                           const pjmedia_srtp_crypto *rx) 
     
    518518    int              cr_rx_idx = 0; 
    519519    int              au_rx_idx = 0; 
    520     int              crypto_suites_cnt; 
    521520    pj_status_t      status = PJ_SUCCESS; 
    522521 
     
    528527        pjmedia_transport_srtp_stop(tp); 
    529528    } 
    530  
    531     crypto_suites_cnt = sizeof(crypto_suites)/sizeof(crypto_suites[0]); 
    532529 
    533530    /* Get encryption and authentication method */ 
     
    545542 
    546543    /* Check whether the crypto-suite requested is supported */ 
    547     if (cr_tx_idx == -1 || cr_rx_idx == -1 || au_tx_idx == -1 ||  
     544    if (cr_tx_idx == -1 || cr_rx_idx == -1 || au_tx_idx == -1 || 
    548545        au_rx_idx == -1) 
    549546    { 
     
    648645        else 
    649646            b64[b64_len] = '\0'; 
    650          
     647 
    651648        PJ_LOG(5, (srtp->pool->obj_name, "TX: %s key=%s", 
    652649                   srtp->tx_policy.name.ptr, b64)); 
     
    700697    err = srtp_dealloc(p_srtp->srtp_rx_ctx); 
    701698    if (err != err_status_ok) { 
    702         PJ_LOG(4, (p_srtp->pool->obj_name,  
     699        PJ_LOG(4, (p_srtp->pool->obj_name, 
    703700                   "Failed to dealloc RX SRTP context: %s", 
    704701                   get_libsrtp_errstr(err))); 
     
    706703    err = srtp_dealloc(p_srtp->srtp_tx_ctx); 
    707704    if (err != err_status_ok) { 
    708         PJ_LOG(4, (p_srtp->pool->obj_name,  
     705        PJ_LOG(4, (p_srtp->pool->obj_name, 
    709706                   "Failed to dealloc TX SRTP context: %s", 
    710707                   get_libsrtp_errstr(err))); 
     
    753750    info->spc_info[spc_info_idx].type = PJMEDIA_TRANSPORT_TYPE_SRTP; 
    754751    info->spc_info[spc_info_idx].cbsize = sizeof(srtp_info); 
    755     pj_memcpy(&info->spc_info[spc_info_idx].buffer, &srtp_info,  
     752    pj_memcpy(&info->spc_info[spc_info_idx].buffer, &srtp_info, 
    756753              sizeof(srtp_info)); 
    757754 
     
    782779 
    783780    /* Attach itself to transport */ 
    784     status = pjmedia_transport_attach(srtp->member_tp, srtp, rem_addr,  
     781    status = pjmedia_transport_attach(srtp->member_tp, srtp, rem_addr, 
    785782                                      rem_rtcp, addr_len, &srtp_rtp_cb, 
    786783                                      &srtp_rtcp_cb); 
     
    842839 
    843840    if (err == err_status_ok) { 
    844         status = pjmedia_transport_send_rtp(srtp->member_tp,  
     841        status = pjmedia_transport_send_rtp(srtp->member_tp, 
    845842                                            srtp->rtp_tx_buffer, len); 
    846843    } else { 
    847844        status = PJMEDIA_ERRNO_FROM_LIBSRTP(err); 
    848845    } 
    849      
     846 
    850847    return status; 
    851848} 
     
    870867 
    871868    if (srtp->bypass_srtp) { 
    872         return pjmedia_transport_send_rtcp2(srtp->member_tp, addr, addr_len,  
     869        return pjmedia_transport_send_rtcp2(srtp->member_tp, addr, addr_len, 
    873870                                            pkt, size); 
    874871    } 
     
    903900{ 
    904901    transport_srtp *srtp = (transport_srtp *) tp; 
    905      
     902 
    906903    PJ_ASSERT_RETURN(tp, PJ_EINVAL); 
    907904 
     
    965962    } 
    966963    err = srtp_unprotect(srtp->srtp_rx_ctx, (pj_uint8_t*)pkt, &len); 
    967     if (srtp->probation_cnt > 0 &&  
    968         (err == err_status_replay_old || err == err_status_replay_fail))  
     964    if (srtp->probation_cnt > 0 && 
     965        (err == err_status_replay_old || err == err_status_replay_fail)) 
    969966    { 
    970967        /* Handle such condition that stream is updated (RTP seq is reinited 
    971          * & SRTP is restarted), but some old packets are still coming  
     968         * & SRTP is restarted), but some old packets are still coming 
    972969         * so SRTP is learning wrong RTP seq. While the newly inited RTP seq 
    973          * comes, SRTP thinks the RTP seq is replayed, so srtp_unprotect()  
     970         * comes, SRTP thinks the RTP seq is replayed, so srtp_unprotect() 
    974971         * will return err_status_replay_*. Restarting SRTP can resolve this. 
    975972         */ 
     
    982979                                              &tx, &rx); 
    983980        if (status != PJ_SUCCESS) { 
    984             PJ_LOG(5,(srtp->pool->obj_name, "Failed to restart SRTP, err=%s",  
     981            PJ_LOG(5,(srtp->pool->obj_name, "Failed to restart SRTP, err=%s", 
    985982                      get_libsrtp_errstr(err))); 
    986983        } else if (!srtp->bypass_srtp) { 
     
    990987 
    991988    if (err != err_status_ok) { 
    992         PJ_LOG(5,(srtp->pool->obj_name,  
    993                   "Failed to unprotect SRTP, pkt size=%d, err=%s",  
     989        PJ_LOG(5,(srtp->pool->obj_name, 
     990                  "Failed to unprotect SRTP, pkt size=%d, err=%s", 
    994991                  size, get_libsrtp_errstr(err))); 
    995992    } else { 
     
    10361033    err = srtp_unprotect_rtcp(srtp->srtp_rx_ctx, (pj_uint8_t*)pkt, &len); 
    10371034    if (err != err_status_ok) { 
    1038         PJ_LOG(5,(srtp->pool->obj_name,  
     1035        PJ_LOG(5,(srtp->pool->obj_name, 
    10391036                  "Failed to unprotect SRTCP, pkt size=%d, err=%s", 
    10401037                  size, get_libsrtp_errstr(err))); 
     
    10561053 */ 
    10571054static pj_status_t generate_crypto_attr_value(pj_pool_t *pool, 
    1058                                               char *buffer, int *buffer_len,  
     1055                                              char *buffer, int *buffer_len, 
    10591056                                              pjmedia_srtp_crypto *crypto, 
    10601057                                              int tag) 
     
    10881085            key_ok = PJ_TRUE; 
    10891086 
    1090             err = crypto_get_random((unsigned char*)key,  
     1087            err = crypto_get_random((unsigned char*)key, 
    10911088                                     crypto_suites[cs_idx].cipher_key_len); 
    10921089            if (err != err_status_ok) { 
     
    11001097        } while (!key_ok); 
    11011098        crypto->key.ptr = (char*) 
    1102                           pj_pool_zalloc(pool,  
     1099                          pj_pool_zalloc(pool, 
    11031100                                         crypto_suites[cs_idx].cipher_key_len); 
    11041101        pj_memcpy(crypto->key.ptr, key, crypto_suites[cs_idx].cipher_key_len); 
     
    11181115 
    11191116    b64_key[b64_key_len] = '\0'; 
    1120      
     1117 
    11211118    PJ_ASSERT_RETURN(*buffer_len >= (crypto->name.slen + \ 
    11221119                     b64_key_len + 16), PJ_ETOOSMALL); 
     
    11241121    /* Print the crypto attribute value. */ 
    11251122    print_len = pj_ansi_snprintf(buffer, *buffer_len, "%d %s inline:%s", 
    1126                                    tag,  
     1123                                   tag, 
    11271124                                   crypto_suites[cs_idx].name, 
    11281125                                   b64_key); 
     
    12061203    crypto->key.ptr = (char*) pj_pool_zalloc(pool, MAX_KEY_LEN); 
    12071204    itmp = MAX_KEY_LEN; 
    1208     status = pj_base64_decode(&tmp, (pj_uint8_t*)crypto->key.ptr,  
     1205    status = pj_base64_decode(&tmp, (pj_uint8_t*)crypto->key.ptr, 
    12091206                              &itmp); 
    12101207    if (status != PJ_SUCCESS) { 
     
    12271224 
    12281225    PJ_ASSERT_RETURN(tp, PJ_EINVAL); 
    1229      
     1226 
    12301227    pj_bzero(&srtp->rx_policy_neg, sizeof(srtp->rx_policy_neg)); 
    12311228    pj_bzero(&srtp->tx_policy_neg, sizeof(srtp->tx_policy_neg)); 
     
    12751272 
    12761273PROPAGATE_MEDIA_CREATE: 
    1277     return pjmedia_transport_media_create(srtp->member_tp, sdp_pool,  
     1274    return pjmedia_transport_media_create(srtp->member_tp, sdp_pool, 
    12781275                                          member_tp_option, sdp_remote, 
    12791276                                          media_index); 
     
    12971294 
    12981295    PJ_ASSERT_RETURN(tp && sdp_pool && sdp_local, PJ_EINVAL); 
    1299      
     1296 
    13001297    pj_bzero(&srtp->rx_policy_neg, sizeof(srtp->rx_policy_neg)); 
    13011298    pj_bzero(&srtp->tx_policy_neg, sizeof(srtp->tx_policy_neg)); 
     
    13071304 
    13081305    /* Bypass if media transport is not RTP/AVP or RTP/SAVP */ 
    1309     if (pj_stricmp(&m_loc->desc.transport, &ID_RTP_AVP)  != 0 &&  
     1306    if (pj_stricmp(&m_loc->desc.transport, &ID_RTP_AVP)  != 0 && 
    13101307        pj_stricmp(&m_loc->desc.transport, &ID_RTP_SAVP) != 0) 
    13111308        goto BYPASS_SRTP; 
     
    13181315     */ 
    13191316    /* 
    1320     if (pjmedia_sdp_media_find_attr(m_loc, &ID_INACTIVE, NULL) ||  
     1317    if (pjmedia_sdp_media_find_attr(m_loc, &ID_INACTIVE, NULL) || 
    13211318        (m_rem && pjmedia_sdp_media_find_attr(m_rem, &ID_INACTIVE, NULL))) 
    13221319        goto BYPASS_SRTP; 
    13231320    */ 
    13241321 
    1325     /* Check remote media transport & set local media transport  
     1322    /* Check remote media transport & set local media transport 
    13261323     * based on SRTP usage option. 
    13271324     */ 
     
    13331330                goto BYPASS_SRTP; 
    13341331            case PJMEDIA_SRTP_OPTIONAL: 
    1335                 m_loc->desc.transport =  
     1332                m_loc->desc.transport = 
    13361333                                (srtp->peer_use == PJMEDIA_SRTP_MANDATORY)? 
    13371334                                ID_RTP_SAVP : ID_RTP_AVP; 
     
    13561353                if (buffer_len) { 
    13571354                    pj_strset(&attr_value, buffer, buffer_len); 
    1358                     attr = pjmedia_sdp_attr_create(srtp->pool, ID_CRYPTO.ptr,  
     1355                    attr = pjmedia_sdp_attr_create(srtp->pool, ID_CRYPTO.ptr, 
    13591356                                                   &attr_value); 
    13601357                    m_loc->attr[m_loc->attr_count++] = attr; 
     
    14011398                has_crypto_attr = PJ_TRUE; 
    14021399 
    1403                 status = parse_attr_crypto(srtp->pool, m_rem->attr[i],  
     1400                status = parse_attr_crypto(srtp->pool, m_rem->attr[i], 
    14041401                                           &tmp_rx_crypto, &tags[cr_attr_count]); 
    14051402                if (status != PJ_SUCCESS) 
    14061403                    return status; 
    1407           
     1404 
    14081405                /* Check duplicated tag */ 
    14091406                for (j=0; j<cr_attr_count; ++j) { 
     
    14171414                    /* lets see if the crypto-suite offered is supported */ 
    14181415                    for (j=0; j<srtp->setting.crypto_count; ++j) 
    1419                         if (pj_stricmp(&tmp_rx_crypto.name,  
     1416                        if (pj_stricmp(&tmp_rx_crypto.name, 
    14201417                                       &srtp->setting.crypto[j].name) == 0) 
    14211418                        { 
     
    14341431                            //          hex_test_key, 
    14351432                            //          strlen(hex_test_key)); 
    1436                             //pj_strset(test_key, raw_test_key,  
     1433                            //pj_strset(test_key, raw_test_key, 
    14371434                            //    crypto_suites[cs_idx].cipher_key_len); 
    14381435                            /* EO Force to use test key */ 
    14391436 
    1440                             if (tmp_rx_crypto.key.slen !=  
     1437                            if (tmp_rx_crypto.key.slen != 
    14411438                                (int)crypto_suites[cs_idx].cipher_key_len) 
    14421439                                return PJMEDIA_SRTP_EINKEYLEN; 
     
    14591456                case PJMEDIA_SRTP_OPTIONAL: 
    14601457                    /* bypass SRTP when no crypto-attr and remote uses RTP/AVP */ 
    1461                     if (!has_crypto_attr &&  
     1458                    if (!has_crypto_attr && 
    14621459                        pj_stricmp(&m_rem->desc.transport, &ID_RTP_AVP) == 0) 
    14631460                        goto BYPASS_SRTP; 
    14641461                    /* bypass SRTP when nothing match and remote uses RTP/AVP */ 
    1465                     else if (matched_idx == -1 &&  
     1462                    else if (matched_idx == -1 && 
    14661463                        pj_stricmp(&m_rem->desc.transport, &ID_RTP_AVP) == 0) 
    14671464                        goto BYPASS_SRTP; 
     
    14851482            } 
    14861483 
    1487             /* we have to generate crypto answer,  
     1484            /* we have to generate crypto answer, 
    14881485             * with srtp->tx_policy_neg matched the offer 
    14891486             * and rem_tag contains matched offer tag. 
     
    14971494 
    14981495            srtp->tx_policy_neg = srtp->setting.crypto[matched_idx]; 
    1499              
     1496 
    15001497            /* If buffer_len==0, just skip the crypto attribute. */ 
    15011498            if (buffer_len) { 
    15021499                pj_strset(&attr_value, buffer, buffer_len); 
    1503                 attr = pjmedia_sdp_attr_create(sdp_pool, ID_CRYPTO.ptr,  
     1500                attr = pjmedia_sdp_attr_create(sdp_pool, ID_CRYPTO.ptr, 
    15041501                                               &attr_value); 
    15051502                m_loc->attr[m_loc->attr_count++] = attr; 
     
    15081505            /* At this point, we get valid rx_policy_neg & tx_policy_neg. */ 
    15091506        } 
    1510              
     1507 
    15111508    } 
    15121509    goto PROPAGATE_MEDIA_CREATE; 
     
    15191516 
    15201517PROPAGATE_MEDIA_CREATE: 
    1521     return pjmedia_transport_encode_sdp(srtp->member_tp, sdp_pool,  
     1518    return pjmedia_transport_encode_sdp(srtp->member_tp, sdp_pool, 
    15221519                                        sdp_local, sdp_remote, media_index); 
    15231520} 
     
    15481545    /* For answerer side, this function will just have to start SRTP */ 
    15491546 
    1550     /* Check remote media transport & set local media transport  
     1547    /* Check remote media transport & set local media transport 
    15511548     * based on SRTP usage option. 
    15521549     */ 
     
    15611558            // Regardless the answer's transport type (RTP/AVP or RTP/SAVP), 
    15621559            // the answer must be processed through in optional mode. 
    1563             // Please note that at this point transport type is ensured to be  
     1560            // Please note that at this point transport type is ensured to be 
    15641561            // RTP/AVP or RTP/SAVP, see transport_media_create() 
    15651562            //if (pj_stricmp(&m_rem->desc.transport, &m_loc->desc.transport)) { 
     
    15741571        } 
    15751572    } 
    1576      
     1573 
    15771574    if (srtp->offerer_side) { 
    15781575        /* find supported crypto-suite, get the tag, and assign policy_local */ 
     
    15931590            has_crypto_attr = PJ_TRUE; 
    15941591 
    1595             status = parse_attr_crypto(srtp->pool, m_rem->attr[i],  
     1592            status = parse_attr_crypto(srtp->pool, m_rem->attr[i], 
    15961593                                       &tmp_tx_crypto, &rem_tag); 
    15971594            if (status != PJ_SUCCESS) 
     
    16061603 
    16071604            /* match the crypto name */ 
    1608             if (pj_stricmp(&tmp_tx_crypto.name,  
     1605            if (pj_stricmp(&tmp_tx_crypto.name, 
    16091606                &srtp->setting.crypto[rem_tag-1].name) != 0) 
    16101607            { 
     
    16341631 
    16351632    /* Make sure we have the SRTP policies */ 
    1636     if (srtp_crypto_empty(&srtp->tx_policy_neg) ||  
     1633    if (srtp_crypto_empty(&srtp->tx_policy_neg) || 
    16371634        srtp_crypto_empty(&srtp->rx_policy_neg)) 
    16381635    { 
     
    16711668 
    16721669PROPAGATE_MEDIA_START: 
    1673     return pjmedia_transport_media_start(srtp->member_tp, pool,  
     1670    return pjmedia_transport_media_start(srtp->member_tp, pool, 
    16741671                                         sdp_local, sdp_remote, 
    16751672                                         media_index); 
     
    16851682    status = pjmedia_transport_media_stop(srtp->member_tp); 
    16861683    if (status != PJ_SUCCESS) 
    1687         PJ_LOG(4, (srtp->pool->obj_name,  
     1684        PJ_LOG(4, (srtp->pool->obj_name, 
    16881685                   "SRTP failed stop underlying media transport.")); 
    16891686 
     
    17201717    else 
    17211718        err = srtp_unprotect_rtcp(srtp->srtp_rx_ctx, pkt, pkt_len); 
    1722      
     1719 
    17231720    if (err != err_status_ok) { 
    1724         PJ_LOG(5,(srtp->pool->obj_name,  
    1725                   "Failed to unprotect SRTP, pkt size=%d, err=%s",  
     1721        PJ_LOG(5,(srtp->pool->obj_name, 
     1722                  "Failed to unprotect SRTP, pkt size=%d, err=%s", 
    17261723                  *pkt_len, get_libsrtp_errstr(err))); 
    17271724    } 
  • pjproject/trunk/pjmedia/src/test/jbuf_test.c

    r3841 r4728  
    11/* $Id$ */ 
    2 /*  
     2/* 
    33 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 
    44 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 
     
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1919 */ 
    2020#include <stdio.h> 
     
    4848} test_cond_t; 
    4949 
    50 static pj_bool_t parse_test_headers(char *line, test_param_t *param,  
     50static pj_bool_t parse_test_headers(char *line, test_param_t *param, 
    5151                               test_cond_t *cond) 
    5252{ 
     
    5757        char mode_st[16]; 
    5858 
    59         sscanf(p+1, "%s %u %u %u", mode_st, &param->init_prefetch,  
     59        sscanf(p+1, "%s %u %u %u", mode_st, &param->init_prefetch, 
    6060               &param->min_prefetch, &param->max_prefetch); 
    6161        param->adaptive = (pj_ansi_stricmp(mode_st, "adaptive") == 0); 
     
    103103} 
    104104 
    105 static pj_bool_t process_test_data(char data, pjmedia_jbuf *jb,  
     105static pj_bool_t process_test_data(char data, pjmedia_jbuf *jb, 
    106106                                   pj_uint16_t *seq, pj_uint16_t *last_seq) 
    107107{ 
     
    156156 
    157157        pjmedia_jbuf_get_state(jb, &state); 
    158         printf("seq=%d\t%c\tsize=%d\tprefetch=%d\n",  
     158        printf("seq=%d\t%c\tsize=%d\tprefetch=%d\n", 
    159159               *last_seq, toupper(data), state.size, state.prefetch); 
    160160    } 
     161#else 
     162    PJ_UNUSED_ARG(print_state); /* Warning about variable set but unused */ 
    161163#endif 
    162164 
     
    171173    int rc = 0; 
    172174    const char* input_filename = "Jbtest.dat"; 
    173     const char* input_search_path[] = {  
     175    const char* input_search_path[] = { 
    174176        "../build", 
    175177        "pjmedia/build", 
     
    192194        } 
    193195    } 
    194      
     196 
    195197    /* Failed to open test data file. */ 
    196198    if (input == NULL) { 
     
    245247 
    246248        if (param.adaptive) { 
    247             pjmedia_jbuf_set_adaptive(jb,  
    248                                       param.init_prefetch,  
     249            pjmedia_jbuf_set_adaptive(jb, 
     250                                      param.init_prefetch, 
    249251                                      param.min_prefetch, 
    250252                                      param.max_prefetch); 
     
    255257#ifdef REPORT 
    256258        pjmedia_jbuf_get_state(jb, &state); 
    257         printf("Initial\tsize=%d\tprefetch=%d\tmin.pftch=%d\tmax.pftch=%d\n",  
    258                state.size, state.prefetch, state.min_prefetch,  
     259        printf("Initial\tsize=%d\tprefetch=%d\tmin.pftch=%d\tmax.pftch=%d\n", 
     260               state.size, state.prefetch, state.min_prefetch, 
    259261               state.max_prefetch); 
    260262#endif 
     
    264266        while (1) { 
    265267            char c; 
    266              
     268 
    267269            /* Get next line of test data */ 
    268270            if (!p || *p == 0) { 
     
    302304        printf("  size=%d prefetch=%d\n", state.size, state.prefetch); 
    303305        printf("  delay (min/max/avg/dev)=%d/%d/%d/%d ms\n", 
    304                state.min_delay, state.max_delay, state.avg_delay,  
     306               state.min_delay, state.max_delay, state.avg_delay, 
    305307               state.dev_delay); 
    306         printf("  lost=%d discard=%d empty=%d burst(avg)=%d\n",  
     308        printf("  lost=%d discard=%d empty=%d burst(avg)=%d\n", 
    307309               state.lost, state.discard, state.empty, state.avg_burst); 
    308310 
    309311        /* Evaluate test session */ 
    310312        if (cond.burst >= 0 && (int)state.avg_burst > cond.burst) { 
    311             printf("! 'Burst' should be %d, it is %d\n",  
     313            printf("! 'Burst' should be %d, it is %d\n", 
    312314                   cond.burst, state.avg_burst); 
    313315            rc |= 1; 
    314316        } 
    315317        if (cond.delay >= 0 && (int)state.avg_delay/JB_PTIME > cond.delay) { 
    316             printf("! 'Delay' should be %d, it is %d\n",  
     318            printf("! 'Delay' should be %d, it is %d\n", 
    317319                   cond.delay, state.avg_delay/JB_PTIME); 
    318320            rc |= 2; 
    319321        } 
    320322        if (cond.delay_min >= 0 && (int)state.min_delay/JB_PTIME > cond.delay_min) { 
    321             printf("! 'Minimum delay' should be %d, it is %d\n",  
     323            printf("! 'Minimum delay' should be %d, it is %d\n", 
    322324                   cond.delay_min, state.min_delay/JB_PTIME); 
    323325            rc |= 32; 
     
    329331        } 
    330332        if (cond.empty >= 0 && (int)state.empty > cond.empty) { 
    331             printf("! 'Empty' should be %d, it is %d\n",  
     333            printf("! 'Empty' should be %d, it is %d\n", 
    332334                   cond.empty, state.empty); 
    333335            rc |= 8; 
    334336        } 
    335337        if (cond.lost >= 0 && (int)state.lost > cond.lost) { 
    336             printf("! 'Lost' should be %d, it is %d\n",  
     338            printf("! 'Lost' should be %d, it is %d\n", 
    337339                   cond.lost, state.lost); 
    338340            rc |= 16; 
  • pjproject/trunk/pjnath/src/pjnath-test/ice_test.c

    r4412 r4728  
    11/* $Id$ */ 
    2 /*  
     2/* 
    33 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 
    44 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 
     
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1919 */ 
    2020#include "test.h" 
     
    113113 
    114114static void ice_on_rx_data(pj_ice_strans *ice_st, 
    115                            unsigned comp_id,  
     115                           unsigned comp_id, 
    116116                           void *pkt, pj_size_t size, 
    117117                           const pj_sockaddr_t *src_addr, 
    118118                           unsigned src_addr_len); 
    119 static void ice_on_ice_complete(pj_ice_strans *ice_st,  
     119static void ice_on_ice_complete(pj_ice_strans *ice_st, 
    120120                                pj_ice_strans_op op, 
    121121                                pj_status_t status); 
     
    202202    return PJ_SUCCESS; 
    203203} 
    204                               
     204 
    205205/* Create test session */ 
    206206static int create_sess(pj_stun_config *stun_cfg, 
     
    239239        return -10; 
    240240    } 
    241     sess->server->turn_respond_allocate =  
     241    sess->server->turn_respond_allocate = 
    242242        sess->server->turn_respond_refresh = PJ_TRUE; 
    243243 
     
    319319 
    320320static void ice_on_rx_data(pj_ice_strans *ice_st, 
    321                            unsigned comp_id,  
     321                           unsigned comp_id, 
    322322                           void *pkt, pj_size_t size, 
    323323                           const pj_sockaddr_t *src_addr, 
     
    336336 
    337337 
    338 static void ice_on_ice_complete(pj_ice_strans *ice_st,  
     338static void ice_on_ice_complete(pj_ice_strans *ice_st, 
    339339                                pj_ice_strans_op op, 
    340340                                pj_status_t status) 
     
    437437    for (; i<max_cnt; ++i) { 
    438438        if (ept1->cfg.comp_cnt>i && 
    439             pj_ice_strans_get_valid_pair(ept1->ice, i+1) != NULL)  
     439            pj_ice_strans_get_valid_pair(ept1->ice, i+1) != NULL) 
    440440        { 
    441441            PJ_LOG(3,(THIS_FILE, INDENT "err: ice1 shouldn't have valid pair " 
     
    444444        } 
    445445        if (ept2->cfg.comp_cnt>i && 
    446             pj_ice_strans_get_valid_pair(ept2->ice, i+1) != NULL)  
     446            pj_ice_strans_get_valid_pair(ept2->ice, i+1) != NULL) 
    447447        { 
    448448            PJ_LOG(3,(THIS_FILE, INDENT "err: ice2 shouldn't have valid pair " 
     
    464464                                    pj_gettimeofday(&t); \ 
    465465                                    if (expr) { \ 
    466                                         rc = PJ_SUCCESS; \ 
     466                                        RC = PJ_SUCCESS; \ 
    467467                                        break; \ 
    468468                                    } \ 
     
    478478    struct test_sess *sess = (struct test_sess *) data; 
    479479    pj_stun_config *stun_cfg = sess->stun_cfg; 
    480      
     480 
    481481    /* Wait until negotiation is complete on both endpoints */ 
    482482#define ALL_DONE    (sess->param->worker_quit || \ 
     
    484484                         sess->callee.result.nego_status!=PJ_EPENDING)) 
    485485    WAIT_UNTIL(sess->param->worker_timeout, ALL_DONE, rc); 
    486      
     486    PJ_UNUSED_ARG(rc); 
    487487    return 0; 
    488488} 
     
    539539    } 
    540540    /* Init ICE on caller */ 
    541     rc = pj_ice_strans_init_ice(sess->caller.ice, sess->caller.cfg.role,  
     541    rc = pj_ice_strans_init_ice(sess->caller.ice, sess->caller.cfg.role, 
    542542                                &sess->caller.ufrag, &sess->caller.pass); 
    543543    if (rc != PJ_SUCCESS) { 
     
    548548 
    549549    /* Init ICE on callee */ 
    550     rc = pj_ice_strans_init_ice(sess->callee.ice, sess->callee.cfg.role,  
     550    rc = pj_ice_strans_init_ice(sess->callee.ice, sess->callee.cfg.role, 
    551551                                &sess->callee.ufrag, &sess->callee.pass); 
    552552    if (rc != PJ_SUCCESS) { 
     
    597597        goto on_destroy; 
    598598    } 
    599      
     599 
    600600    WAIT_UNTIL(30000, ALL_DONE, rc); 
    601601    if (!ALL_DONE) { 
     
    691691        struct test_cfg  ua1; 
    692692        struct test_cfg  ua2; 
    693     } sess_cfg[] =  
     693    } sess_cfg[] = 
    694694    { 
    695695        /*  Role    comp#   host?   stun?   turn?   flag?  ans_del snd_del des_del */ 
     
    741741    /* Simple test first with host candidate */ 
    742742    if (1) { 
    743         struct sess_cfg_t cfg =  
     743        struct sess_cfg_t cfg = 
    744744        { 
    745745            "Basic with host candidates", 
     
    750750        }; 
    751751 
    752         rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag,  
     752        rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag, 
    753753                          &cfg.ua1, &cfg.ua2); 
    754754        if (rc != 0) 
     
    757757        cfg.ua1.comp_cnt = 2; 
    758758        cfg.ua2.comp_cnt = 2; 
    759         rc = perform_test("Basic with host candidates, 2 components",  
    760                           &stun_cfg, cfg.server_flag,  
    761                           &cfg.ua1, &cfg.ua2); 
    762         if (rc != 0) 
    763             goto on_return; 
    764     } 
    765      
     759        rc = perform_test("Basic with host candidates, 2 components", 
     760                          &stun_cfg, cfg.server_flag, 
     761                          &cfg.ua1, &cfg.ua2); 
     762        if (rc != 0) 
     763            goto on_return; 
     764    } 
     765 
    766766    /* Simple test first with srflx candidate */ 
    767767    if (1) { 
    768         struct sess_cfg_t cfg =  
     768        struct sess_cfg_t cfg = 
    769769        { 
    770770            "Basic with srflx candidates", 
     
    775775        }; 
    776776 
    777         rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag,  
     777        rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag, 
    778778                          &cfg.ua1, &cfg.ua2); 
    779779        if (rc != 0) 
     
    783783        cfg.ua2.comp_cnt = 2; 
    784784 
    785         rc = perform_test("Basic with srflx candidates, 2 components",  
    786                           &stun_cfg, cfg.server_flag,  
     785        rc = perform_test("Basic with srflx candidates, 2 components", 
     786                          &stun_cfg, cfg.server_flag, 
    787787                          &cfg.ua1, &cfg.ua2); 
    788788        if (rc != 0) 
     
    792792    /* Simple test with relay candidate */ 
    793793    if (1) { 
    794         struct sess_cfg_t cfg =  
     794        struct sess_cfg_t cfg = 
    795795        { 
    796796            "Basic with relay candidates", 
     
    801801        }; 
    802802 
    803         rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag,  
     803        rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag, 
    804804                          &cfg.ua1, &cfg.ua2); 
    805805        if (rc != 0) 
     
    809809        cfg.ua2.comp_cnt = 2; 
    810810 
    811         rc = perform_test("Basic with relay candidates, 2 components",  
    812                           &stun_cfg, cfg.server_flag,  
     811        rc = perform_test("Basic with relay candidates, 2 components", 
     812                          &stun_cfg, cfg.server_flag, 
    813813                          &cfg.ua1, &cfg.ua2); 
    814814        if (rc != 0) 
     
    818818    /* Failure test with STUN resolution */ 
    819819    if (1) { 
    820         struct sess_cfg_t cfg =  
     820        struct sess_cfg_t cfg = 
    821821        { 
    822822            "STUN resolution failure", 
     
    835835        cfg.ua2.client_flag |= DEL_ON_ERR; 
    836836 
    837         rc = perform_test("STUN resolution failure with destroy on callback",  
    838                           &stun_cfg, cfg.server_flag,  
     837        rc = perform_test("STUN resolution failure with destroy on callback", 
     838                          &stun_cfg, cfg.server_flag, 
    839839                          &cfg.ua1, &cfg.ua2); 
    840840        if (rc != 0) 
     
    844844    /* Failure test with TURN resolution */ 
    845845    if (1) { 
    846         struct sess_cfg_t cfg =  
     846        struct sess_cfg_t cfg = 
    847847        { 
    848848            "TURN allocation failure", 
     
    853853        }; 
    854854 
    855         rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag,  
     855        rc = perform_test(cfg.title, &stun_cfg, cfg.server_flag, 
    856856                          &cfg.ua1, &cfg.ua2); 
    857857        if (rc != 0) 
     
    861861        cfg.ua2.client_flag |= DEL_ON_ERR; 
    862862 
    863         rc = perform_test("TURN allocation failure with destroy on callback",  
    864                           &stun_cfg, cfg.server_flag,  
     863        rc = perform_test("TURN allocation failure with destroy on callback", 
     864                          &stun_cfg, cfg.server_flag, 
    865865                          &cfg.ua1, &cfg.ua2); 
    866866        if (rc != 0) 
     
    871871    /* STUN failure, testing TURN deallocation */ 
    872872    if (1) { 
    873         struct sess_cfg_t cfg =  
     873        struct sess_cfg_t cfg = 
    874874        { 
    875875            "STUN failure, testing TURN deallocation", 
     
    888888        cfg.ua2.client_flag |= DEL_ON_ERR; 
    889889 
    890         rc = perform_test("STUN failure, testing TURN deallocation (cb)",  
    891                           &stun_cfg, cfg.server_flag,  
     890        rc = perform_test("STUN failure, testing TURN deallocation (cb)", 
     891                          &stun_cfg, cfg.server_flag, 
    892892                          &cfg.ua1, &cfg.ua2); 
    893893        if (rc != 0) 
     
    909909                pj_ice_sess_role        ua1; 
    910910                pj_ice_sess_role        ua2; 
    911             } role[] =  
     911            } role[] = 
    912912            { 
    913913                { ROLE1, ROLE2}, 
     
    937937                        char title[120]; 
    938938 
    939                         sprintf(title,  
    940                                 "%s/%s, %dms answer delay, %d vs %d components",  
     939                        sprintf(title, 
     940                                "%s/%s, %dms answer delay, %d vs %d components", 
    941941                                pj_ice_sess_role_name(role[j].ua1), 
    942942                                pj_ice_sess_role_name(role[j].ua2), 
     
    944944 
    945945                        cfg->ua2.comp_cnt = k2; 
    946                         rc = perform_test(title, &stun_cfg, cfg->server_flag,  
     946                        rc = perform_test(title, &stun_cfg, cfg->server_flag, 
    947947                                          &cfg->ua1, &cfg->ua2); 
    948948                        if (rc != 0) 
     
    10221022    unsigned i; 
    10231023    int rc; 
    1024      
     1024 
    10251025    pool = pj_pool_create(mem, NULL, 512, 512, NULL); 
    10261026    rc = create_stun_config(pool, &stun_cfg); 
     
    10291029        return -7; 
    10301030    } 
    1031      
     1031 
    10321032    for (i = 0; i < LOOP; i++) { 
    10331033        PJ_LOG(3,(THIS_FILE, INDENT "Test %d of %d", i+1, LOOP)); 
     
    10391039    /* Avoid compiler warning */ 
    10401040    goto on_return; 
    1041      
     1041 
    10421042on_return: 
    10431043    destroy_stun_config(&stun_cfg); 
  • pjproject/trunk/pjnath/src/pjnath-test/test.c

    r4537 r4728  
    11/* $Id$ */ 
    2 /*  
     2/* 
    33 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 
    44 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 
     
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1919 */ 
    2020#include "test.h" 
     
    109109 
    110110    st->timer_cnt = (unsigned)pj_timer_heap_count(cfg->timer_heap); 
    111      
     111 
    112112    cp = (pj_caching_pool*)cfg->pf; 
    113113    st->pool_used_cnt = (unsigned)cp->used_count; 
    114114} 
    115115 
    116 int check_pjlib_state(pj_stun_config *cfg,  
     116int check_pjlib_state(pj_stun_config *cfg, 
    117117                      const struct pjlib_state *initial_st) 
    118118{ 
     
    154154pj_pool_factory *mem; 
    155155 
    156 int param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |  
     156int param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME | 
    157157                      PJ_LOG_HAS_MICRO_SEC; 
    158158 
     
    179179    pj_log_set_level(3); 
    180180    pj_log_set_decor(param_log_decor); 
     181    PJ_UNUSED_ARG(test_log_func); 
    181182#elif 1 
    182183    log_file = fopen("pjnath-test.log", "wt"); 
     
    191192        return rc; 
    192193    } 
    193      
     194 
    194195    pj_dump_config(); 
    195196    pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 ); 
     
    234235    PJ_CATCH_ANY { 
    235236        int id = PJ_GET_EXCEPTION(); 
    236         PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)",  
     237        PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)", 
    237238                  id, pj_exception_id_name(id))); 
    238239    } 
  • pjproject/trunk/pjnath/src/pjnath/ice_strans.c

    r4606 r4728  
    11/* $Id$ */ 
    2 /*  
     2/* 
    33 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 
    44 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 
     
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1919 */ 
    2020#include <pjnath/ice_strans.h> 
     
    6666 
    6767/* The candidate type preference when STUN candidate is used */ 
    68 static pj_uint8_t srflx_pref_table[PJ_ICE_CAND_TYPE_MAX] =  
     68static pj_uint8_t srflx_pref_table[PJ_ICE_CAND_TYPE_MAX] = 
    6969{ 
    7070#if PJNATH_ICE_PRIO_STD 
     
    8585/* ICE callbacks */ 
    8686static void        on_ice_complete(pj_ice_sess *ice, pj_status_t status); 
    87 static pj_status_t ice_tx_pkt(pj_ice_sess *ice,  
     87static pj_status_t ice_tx_pkt(pj_ice_sess *ice, 
    8888                              unsigned comp_id, 
    8989                              unsigned transport_id, 
     
    9191                              const pj_sockaddr_t *dst_addr, 
    9292                              unsigned dst_addr_len); 
    93 static void        ice_rx_data(pj_ice_sess *ice,  
    94                                unsigned comp_id,  
     93static void        ice_rx_data(pj_ice_sess *ice, 
     94                               unsigned comp_id, 
    9595                               unsigned transport_id, 
    9696                               void *pkt, pj_size_t size, 
     
    111111                                   pj_ssize_t sent); 
    112112/* Notification when the status of the STUN transport has changed. */ 
    113 static pj_bool_t stun_on_status(pj_stun_sock *stun_sock,  
     113static pj_bool_t stun_on_status(pj_stun_sock *stun_sock, 
    114114                                pj_stun_sock_op op, 
    115115                                pj_status_t status); 
     
    137137 * in ICE stream transport typically corresponds to a single socket created 
    138138 * for this component, and bound to a specific transport address. This 
    139  * component may have multiple alias addresses, for example one alias  
     139 * component may have multiple alias addresses, for example one alias 
    140140 * address for each interfaces in multi-homed host, another for server 
    141141 * reflexive alias, and another for relayed alias. For each transport 
     
    299299    /* Override with component specific socket buffer size settings, if any */ 
    300300    if (ice_st->cfg.comp[comp->comp_id-1].so_rcvbuf_size > 0) { 
    301         ice_st->cfg.turn.cfg.so_rcvbuf_size =  
     301        ice_st->cfg.turn.cfg.so_rcvbuf_size = 
    302302            ice_st->cfg.comp[comp->comp_id-1].so_rcvbuf_size; 
    303303    } 
    304304    if (ice_st->cfg.comp[comp->comp_id-1].so_sndbuf_size > 0) { 
    305         ice_st->cfg.turn.cfg.so_sndbuf_size =  
     305        ice_st->cfg.turn.cfg.so_sndbuf_size = 
    306306            ice_st->cfg.comp[comp->comp_id-1].so_sndbuf_size; 
    307307    } 
     
    382382        stun_sock_cb.on_status = &stun_on_status; 
    383383        stun_sock_cb.on_data_sent = &stun_on_data_sent; 
    384          
     384 
    385385        /* Override component specific QoS settings, if any */ 
    386386        if (ice_st->cfg.comp[comp_id-1].qos_type) { 
    387             ice_st->cfg.stun.cfg.qos_type =  
     387            ice_st->cfg.stun.cfg.qos_type = 
    388388                ice_st->cfg.comp[comp_id-1].qos_type; 
    389389        } 
     
    396396        /* Override component specific socket buffer size settings, if any */ 
    397397        if (ice_st->cfg.comp[comp_id-1].so_rcvbuf_size > 0) { 
    398             ice_st->cfg.stun.cfg.so_rcvbuf_size =  
     398            ice_st->cfg.stun.cfg.so_rcvbuf_size = 
    399399                ice_st->cfg.comp[comp_id-1].so_rcvbuf_size; 
    400400        } 
    401401        if (ice_st->cfg.comp[comp_id-1].so_sndbuf_size > 0) { 
    402             ice_st->cfg.stun.cfg.so_sndbuf_size =  
     402            ice_st->cfg.stun.cfg.so_sndbuf_size = 
    403403                ice_st->cfg.comp[comp_id-1].so_sndbuf_size; 
    404404        } 
     
    412412            return status; 
    413413 
    414         /* Start STUN Binding resolution and add srflx candidate  
    415          * only if server is set  
     414        /* Start STUN Binding resolution and add srflx candidate 
     415         * only if server is set 
    416416         */ 
    417417        if (ice_st->cfg.stun.server.slen) { 
     
    421421            ///sess_add_ref(ice_st); 
    422422 
    423             PJ_LOG(4,(ice_st->obj_name,  
     423            PJ_LOG(4,(ice_st->obj_name, 
    424424                      "Comp %d: srflx candidate starts Binding discovery", 
    425425                      comp_id)); 
     
    428428 
    429429            /* Start Binding resolution */ 
    430             status = pj_stun_sock_start(comp->stun_sock,  
     430            status = pj_stun_sock_start(comp->stun_sock, 
    431431                                        &ice_st->cfg.stun.server, 
    432                                         ice_st->cfg.stun.port,  
     432                                        ice_st->cfg.stun.port, 
    433433                                        ice_st->cfg.resolver); 
    434434            if (status != PJ_SUCCESS) { 
     
    476476                return status; 
    477477 
    478             for (i=0; i<stun_sock_info.alias_cnt &&  
    479                       i<ice_st->cfg.stun.max_host_cands; ++i)  
     478            for (i=0; i<stun_sock_info.alias_cnt && 
     479                      i<ice_st->cfg.stun.max_host_cands; ++i) 
    480480            { 
    481481                char addrinfo[PJ_INET6_ADDRSTRLEN+10]; 
     
    488488                } 
    489489 
    490                 /* Ignore loopback addresses unless cfg->stun.loop_addr  
    491                  * is set  
     490                /* Ignore loopback addresses unless cfg->stun.loop_addr 
     491                 * is set 
    492492                 */ 
    493493                if ((pj_ntohl(addr->ipv4.sin_addr.s_addr)>>24)==127) { 
     
    509509                                       cand->type, &cand->base_addr); 
    510510 
    511                 PJ_LOG(4,(ice_st->obj_name,  
     511                PJ_LOG(4,(ice_st->obj_name, 
    512512                          "Comp %d: host candidate %s added", 
    513513                          comp_id, pj_sockaddr_print(&cand->addr, addrinfo, 
     
    533533 
    534534 
    535 /*  
    536  * Create ICE stream transport  
     535/* 
     536 * Create ICE stream transport 
    537537 */ 
    538538PJ_DEF(pj_status_t) pj_ice_strans_create( const char *name, 
     
    565565    ice_st->user_data = user_data; 
    566566 
    567     PJ_LOG(4,(ice_st->obj_name,  
     567    PJ_LOG(4,(ice_st->obj_name, 
    568568              "Creating ICE stream transport with %d component(s)", 
    569569              comp_cnt)); 
     
    587587 
    588588    ice_st->comp_cnt = comp_cnt; 
    589     ice_st->comp = (pj_ice_strans_comp**)  
     589    ice_st->comp = (pj_ice_strans_comp**) 
    590590                   pj_pool_calloc(pool, comp_cnt, sizeof(pj_ice_strans_comp*)); 
    591591 
     
    593593    ice_st->state = PJ_ICE_STRANS_STATE_INIT; 
    594594 
    595     /* Acquire initialization mutex to prevent callback to be  
     595    /* Acquire initialization mutex to prevent callback to be 
    596596     * called before we finish initialization. 
    597597     */ 
     
    750750    ice_st->state = PJ_ICE_STRANS_STATE_READY; 
    751751    if (ice_st->cb.on_ice_complete) 
    752         (*ice_st->cb.on_ice_complete)(ice_st, PJ_ICE_STRANS_OP_INIT,  
     752        (*ice_st->cb.on_ice_complete)(ice_st, PJ_ICE_STRANS_OP_INIT, 
    753753                                      PJ_SUCCESS); 
    754754} 
     
    786786 
    787787/* 
    788  * Specify various options for this ICE stream transport.  
     788 * Specify various options for this ICE stream transport. 
    789789 */ 
    790790PJ_DEF(pj_status_t) pj_ice_strans_set_options(pj_ice_strans *ice_st, 
     
    835835    /* Create! */ 
    836836    status = pj_ice_sess_create(&ice_st->cfg.stun_cfg, ice_st->obj_name, role, 
    837                                 ice_st->comp_cnt, &ice_cb,  
     837                                ice_st->comp_cnt, &ice_cb, 
    838838                                local_ufrag, local_passwd, 
    839839                                ice_st->grp_lock, 
     
    853853     */ 
    854854    if (ice_st->comp[0]->default_cand >= 0 && 
    855         ice_st->comp[0]->cand_list[ice_st->comp[0]->default_cand].type  
     855        ice_st->comp[0]->cand_list[ice_st->comp[0]->default_cand].type 
    856856            == PJ_ICE_CAND_TYPE_SRFLX) 
    857857    { 
     
    866866        /* Re-enable logging for Send/Data indications */ 
    867867        if (comp->turn_sock) { 
    868             PJ_LOG(5,(ice_st->obj_name,  
     868            PJ_LOG(5,(ice_st->obj_name, 
    869869                      "Disabling STUN Indication logging for " 
    870870                      "component %d", i+1)); 
     
    879879            /* Skip if candidate is not ready */ 
    880880            if (cand->status != PJ_SUCCESS) { 
    881                 PJ_LOG(5,(ice_st->obj_name,  
     881                PJ_LOG(5,(ice_st->obj_name, 
    882882                          "Candidate %d of comp %d is not added (pending)", 
    883883                          j, i)); 
     
    889889 
    890890            /* Add the candidate */ 
    891             status = pj_ice_sess_add_cand(ice_st->ice, comp->comp_id,  
    892                                           cand->transport_id, cand->type,  
    893                                           cand->local_pref,  
    894                                           &cand->foundation, &cand->addr,  
     891            status = pj_ice_sess_add_cand(ice_st->ice, comp->comp_id, 
     892                                          cand->transport_id, cand->type, 
     893                                          cand->local_pref, 
     894                                          &cand->foundation, &cand->addr, 
    895895                                          &cand->base_addr,  &cand->rel_addr, 
    896896                                          pj_sockaddr_get_len(&cand->addr), 
     
    912912 
    913913/* 
    914  * Check if the ICE stream transport has the ICE session created.  
     914 * Check if the ICE stream transport has the ICE session created. 
    915915 */ 
    916916PJ_DEF(pj_bool_t) pj_ice_strans_has_sess(pj_ice_strans *ice_st) 
     
    985985    unsigned i, cnt; 
    986986 
    987     PJ_ASSERT_RETURN(ice_st && ice_st->ice && comp_id &&  
     987    PJ_ASSERT_RETURN(ice_st && ice_st->ice && comp_id && 
    988988                     comp_id <= ice_st->comp_cnt, 0); 
    989989 
     
    10081008    unsigned i, cnt; 
    10091009 
    1010     PJ_ASSERT_RETURN(ice_st && ice_st->ice && comp_id &&  
     1010    PJ_ASSERT_RETURN(ice_st && ice_st->ice && comp_id && 
    10111011                     comp_id <= ice_st->comp_cnt && count && cand, PJ_EINVAL); 
    10121012 
     
    10421042        pj_ice_strans_comp *comp = ice_st->comp[comp_id - 1]; 
    10431043        pj_assert(comp->default_cand>=0 && comp->default_cand<comp->cand_cnt); 
    1044         pj_memcpy(cand, &comp->cand_list[comp->default_cand],  
     1044        pj_memcpy(cand, &comp->cand_list[comp->default_cand], 
    10451045                  sizeof(pj_ice_sess_cand)); 
    10461046    } 
     
    11081108 
    11091109            if (count) { 
    1110                 status = pj_turn_sock_set_perm(comp->turn_sock, count,  
     1110                status = pj_turn_sock_set_perm(comp->turn_sock, count, 
    11111111                                               addrs, 0); 
    11121112                if (status != PJ_SUCCESS) { 
     
    11321132 * Get valid pair. 
    11331133 */ 
    1134 PJ_DEF(const pj_ice_sess_check*)  
     1134PJ_DEF(const pj_ice_sess_check*) 
    11351135pj_ice_strans_get_valid_pair(const pj_ice_strans *ice_st, 
    11361136                             unsigned comp_id) 
     
    11381138    PJ_ASSERT_RETURN(ice_st && comp_id && comp_id <= ice_st->comp_cnt, 
    11391139                     NULL); 
    1140      
     1140 
    11411141    if (ice_st->ice == NULL) 
    11421142        return NULL; 
    1143      
     1143 
    11441144    return ice_st->ice->comp[comp_id-1].valid_check; 
    11451145} 
     
    11711171                                          int dst_addr_len) 
    11721172{ 
    1173     pj_ssize_t pkt_size; 
    11741173    pj_ice_strans_comp *comp; 
    11751174    unsigned def_cand; 
     
    12201219            if (!comp->turn_log_off) { 
    12211220                /* Disable logging for Send/Data indications */ 
    1222                 PJ_LOG(5,(ice_st->obj_name,  
     1221                PJ_LOG(5,(ice_st->obj_name, 
    12231222                          "Disabling STUN Indication logging for " 
    12241223                          "component %d", comp->comp_id)); 
     
    12271226            } 
    12281227 
    1229             status = pj_turn_sock_sendto(comp->turn_sock,  
    1230                                          (const pj_uint8_t*)data,  
     1228            status = pj_turn_sock_sendto(comp->turn_sock, 
     1229                                         (const pj_uint8_t*)data, 
    12311230                                         (unsigned)data_len, 
    12321231                                         dst_addr, dst_addr_len); 
    1233             return (status==PJ_SUCCESS||status==PJ_EPENDING) ?  
     1232            return (status==PJ_SUCCESS||status==PJ_EPENDING) ? 
    12341233                    PJ_SUCCESS : status; 
    12351234        } else { 
    1236             pkt_size = data_len; 
    1237             status = pj_stun_sock_sendto(comp->stun_sock, NULL, data,  
    1238                                          (unsigned)data_len, 0, dst_addr,  
     1235            status = pj_stun_sock_sendto(comp->stun_sock, NULL, data, 
     1236                                         (unsigned)data_len, 0, dst_addr, 
    12391237                                         dst_addr_len); 
    1240             return (status==PJ_SUCCESS||status==PJ_EPENDING) ?  
     1238            return (status==PJ_SUCCESS||status==PJ_EPENDING) ? 
    12411239                    PJ_SUCCESS : status; 
    12421240        } 
     
    12661264            char errmsg[PJ_ERR_MSG_SIZE]; 
    12671265            pj_strerror(status, errmsg, sizeof(errmsg)); 
    1268             PJ_LOG(4,(ice_st->obj_name,  
    1269                       "ICE negotiation failed after %ds:%03d: %s",  
     1266            PJ_LOG(4,(ice_st->obj_name, 
     1267                      "ICE negotiation failed after %ds:%03d: %s", 
    12701268                      msec/1000, msec%1000, errmsg)); 
    12711269        } else { 
     
    12771275            }; 
    12781276 
    1279             PJ_LOG(4,(ice_st->obj_name,  
     1277            PJ_LOG(4,(ice_st->obj_name, 
    12801278                      "ICE negotiation success after %ds:%03d", 
    12811279                      msec/1000, msec%1000)); 
     
    12891287                    char rip[PJ_INET6_ADDRSTRLEN+10]; 
    12901288 
    1291                     pj_sockaddr_print(&check->lcand->addr, lip,  
     1289                    pj_sockaddr_print(&check->lcand->addr, lip, 
    12921290                                      sizeof(lip), 3); 
    1293                     pj_sockaddr_print(&check->rcand->addr, rip,  
     1291                    pj_sockaddr_print(&check->rcand->addr, rip, 
    12941292                                      sizeof(rip), 3); 
    12951293 
     
    13041302 
    13051303                        /* Disable logging for Send/Data indications */ 
    1306                         PJ_LOG(5,(ice_st->obj_name,  
     1304                        PJ_LOG(5,(ice_st->obj_name, 
    13071305                                  "Disabling STUN Indication logging for " 
    13081306                                  "component %d", i+1)); 
     
    13151313                              "sending from %s candidate %s to " 
    13161314                              "%s candidate %s", 
    1317                               i+1,  
     1315                              i+1, 
    13181316                              pj_ice_get_cand_type_name(check->lcand->type), 
    13191317                              lip, 
    13201318                              pj_ice_get_cand_type_name(check->rcand->type), 
    13211319                              rip)); 
    1322                                
     1320 
    13231321                } else { 
    1324                     PJ_LOG(4,(ice_st->obj_name,  
     1322                    PJ_LOG(4,(ice_st->obj_name, 
    13251323                              "Comp %d: disabled", i+1)); 
    13261324                } 
     
    13321330 
    13331331        pj_log_push_indent(); 
    1334         (*ice_st->cb.on_ice_complete)(ice_st, PJ_ICE_STRANS_OP_NEGOTIATION,  
     1332        (*ice_st->cb.on_ice_complete)(ice_st, PJ_ICE_STRANS_OP_NEGOTIATION, 
    13351333                                      status); 
    13361334        pj_log_pop_indent(); 
    1337          
     1335 
    13381336    } 
    13391337 
     
    13441342 * Callback called by ICE session when it wants to send outgoing packet. 
    13451343 */ 
    1346 static pj_status_t ice_tx_pkt(pj_ice_sess *ice,  
    1347                               unsigned comp_id,  
     1344static pj_status_t ice_tx_pkt(pj_ice_sess *ice, 
     1345                              unsigned comp_id, 
    13481346                              unsigned transport_id, 
    13491347                              const void *pkt, pj_size_t size, 
     
    13621360    comp = ice_st->comp[comp_id-1]; 
    13631361 
    1364     TRACE_PKT((comp->ice_st->obj_name,  
     1362    TRACE_PKT((comp->ice_st->obj_name, 
    13651363               "Component %d TX packet to %s:%d with transport %d", 
    1366                comp_id,  
     1364               comp_id, 
    13671365               pj_sockaddr_print(dst_addr, daddr, sizeof(addr), 0), 
    13681366               pj_sockaddr_get_port(dst_addr), 
     
    13711369    if (transport_id == TP_TURN) { 
    13721370        if (comp->turn_sock) { 
    1373             status = pj_turn_sock_sendto(comp->turn_sock,  
    1374                                          (const pj_uint8_t*)pkt,  
     1371            status = pj_turn_sock_sendto(comp->turn_sock, 
     1372                                         (const pj_uint8_t*)pkt, 
    13751373                                         (unsigned)size, 
    13761374                                         dst_addr, dst_addr_len); 
     
    13791377        } 
    13801378    } else if (transport_id == TP_STUN) { 
    1381         status = pj_stun_sock_sendto(comp->stun_sock, NULL,  
     1379        status = pj_stun_sock_sendto(comp->stun_sock, NULL, 
    13821380                                     pkt, (unsigned)size, 0, 
    13831381                                     dst_addr, dst_addr_len); 
     
    13861384        status = PJ_EINVALIDOP; 
    13871385    } 
    1388      
     1386 
    13891387    return (status==PJ_SUCCESS||status==PJ_EPENDING) ? PJ_SUCCESS : status; 
    13901388} 
     
    13931391 * Callback called by ICE session when it receives application data. 
    13941392 */ 
    1395 static void ice_rx_data(pj_ice_sess *ice,  
    1396                         unsigned comp_id,  
     1393static void ice_rx_data(pj_ice_sess *ice, 
     1394                        unsigned comp_id, 
    13971395                        unsigned transport_id, 
    13981396                        void *pkt, pj_size_t size, 
     
    14051403 
    14061404    if (ice_st->cb.on_rx_data) { 
    1407         (*ice_st->cb.on_rx_data)(ice_st, comp_id, pkt, size,  
     1405        (*ice_st->cb.on_rx_data)(ice_st, comp_id, pkt, size, 
    14081406                                 src_addr, src_addr_len); 
    14091407    } 
     
    14111409 
    14121410/* Notification when incoming packet has been received from 
    1413  * the STUN socket.  
     1411 * the STUN socket. 
    14141412 */ 
    14151413static pj_bool_t stun_on_rx_data(pj_stun_sock *stun_sock, 
     
    14391437         */ 
    14401438        if (ice_st->cb.on_rx_data) { 
    1441             (*ice_st->cb.on_rx_data)(ice_st, comp->comp_id, pkt, pkt_len,  
     1439            (*ice_st->cb.on_rx_data)(ice_st, comp->comp_id, pkt, pkt_len, 
    14421440                                     src_addr, addr_len); 
    14431441        } 
     
    14461444 
    14471445        /* Hand over the packet to ICE session */ 
    1448         status = pj_ice_sess_on_rx_pkt(comp->ice_st->ice, comp->comp_id,  
     1446        status = pj_ice_sess_on_rx_pkt(comp->ice_st->ice, comp->comp_id, 
    14491447                                       TP_STUN, pkt, pkt_len, 
    14501448                                       src_addr, addr_len); 
    14511449 
    14521450        if (status != PJ_SUCCESS) { 
    1453             ice_st_perror(comp->ice_st, "Error processing packet",  
     1451            ice_st_perror(comp->ice_st, "Error processing packet", 
    14541452                          status); 
    14551453        } 
     
    14601458 
    14611459/* Notifification when asynchronous send operation to the STUN socket 
    1462  * has completed.  
     1460 * has completed. 
    14631461 */ 
    14641462static pj_bool_t stun_on_data_sent(pj_stun_sock *stun_sock, 
     
    14731471 
    14741472/* Notification when the status of the STUN transport has changed. */ 
    1475 static pj_bool_t stun_on_status(pj_stun_sock *stun_sock,  
     1473static pj_bool_t stun_on_status(pj_stun_sock *stun_sock, 
    14761474                                pj_stun_sock_op op, 
    14771475                                pj_status_t status) 
     
    15731571                } 
    15741572 
    1575                 PJ_LOG(4,(comp->ice_st->obj_name,  
     1573                PJ_LOG(4,(comp->ice_st->obj_name, 
    15761574                          "Comp %d: %s, " 
    15771575                          "srflx address is %s", 
    1578                           comp->comp_id, op_name,  
    1579                           pj_sockaddr_print(&info.mapped_addr, ipaddr,  
     1576                          comp->comp_id, op_name, 
     1577                          pj_sockaddr_print(&info.mapped_addr, ipaddr, 
    15801578                                             sizeof(ipaddr), 3))); 
    15811579 
     
    16631661 
    16641662        if (status != PJ_SUCCESS) { 
    1665             ice_st_perror(comp->ice_st,  
    1666                           "Error processing packet from TURN relay",  
     1663            ice_st_perror(comp->ice_st, 
     1664                          "Error processing packet from TURN relay", 
    16671665                          status); 
    16681666        } 
     
    17221720        pj_sockaddr_cp(&cand->base_addr, &rel_info.relay_addr); 
    17231721        pj_sockaddr_cp(&cand->rel_addr, &rel_info.mapped_addr); 
    1724         pj_ice_calc_foundation(comp->ice_st->pool, &cand->foundation,  
    1725                                PJ_ICE_CAND_TYPE_RELAYED,  
     1722        pj_ice_calc_foundation(comp->ice_st->pool, &cand->foundation, 
     1723                               PJ_ICE_CAND_TYPE_RELAYED, 
    17261724                               &rel_info.relay_addr); 
    17271725        cand->status = PJ_SUCCESS; 
     
    17301728        comp->default_cand = (unsigned)(cand - comp->cand_list); 
    17311729 
    1732         PJ_LOG(4,(comp->ice_st->obj_name,  
     1730        PJ_LOG(4,(comp->ice_st->obj_name, 
    17331731                  "Comp %d: TURN allocation complete, relay address is %s", 
    1734                   comp->comp_id,  
    1735                   pj_sockaddr_print(&rel_info.relay_addr, ipaddr,  
     1732                  comp->comp_id, 
     1733                  pj_sockaddr_print(&rel_info.relay_addr, ipaddr, 
    17361734                                     sizeof(ipaddr), 3))); 
    17371735 
  • pjproject/trunk/pjnath/src/pjturn-srv/allocation.c

    r4360 r4728  
    11/* $Id$ */ 
    2 /*  
     2/* 
    33 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 
    44 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 
     
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1919 */ 
    2020#include "turn.h" 
     
    6363                                pj_turn_relay_res *relay); 
    6464static void destroy_relay(pj_turn_relay_res *relay); 
    65 static void on_rx_from_peer(pj_ioqueue_key_t *key,  
    66                             pj_ioqueue_op_key_t *op_key,  
     65static void on_rx_from_peer(pj_ioqueue_key_t *key, 
     66                            pj_ioqueue_op_key_t *op_key, 
    6767                            pj_ssize_t bytes_read); 
    6868static pj_status_t stun_on_send_msg(pj_stun_session *sess, 
     
    125125    /* Check if we can satisfy the bandwidth */ 
    126126    if (cfg->bandwidth > MAX_CLIENT_BANDWIDTH) { 
    127         pj_stun_session_respond(sess, rdata,  
     127        pj_stun_session_respond(sess, rdata, 
    128128                                PJ_STUN_SC_ALLOCATION_QUOTA_REACHED, 
    129129                                "Invalid bandwidth", NULL, PJ_TRUE, 
     
    137137    if (attr_req_tp == NULL) { 
    138138        pj_stun_session_respond(sess, rdata, PJ_STUN_SC_BAD_REQUEST, 
    139                                 "Missing REQUESTED-TRANSPORT attribute",  
     139                                "Missing REQUESTED-TRANSPORT attribute", 
    140140                                NULL, PJ_TRUE, src_addr, src_addr_len); 
    141141        return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_BAD_REQUEST); 
     
    157157    if (attr_res_token) { 
    158158        /* We don't support RESERVATION-TOKEN for now */ 
    159         pj_stun_session_respond(sess, rdata,  
     159        pj_stun_session_respond(sess, rdata, 
    160160                                PJ_STUN_SC_BAD_REQUEST, 
    161                                 "RESERVATION-TOKEN is not supported", NULL,  
     161                                "RESERVATION-TOKEN is not supported", NULL, 
    162162                                PJ_TRUE, src_addr, src_addr_len); 
    163163        return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_BAD_REQUEST); 
     
    171171        if (cfg->lifetime < MIN_LIFETIME) { 
    172172            pj_stun_session_respond(sess, rdata, PJ_STUN_SC_BAD_REQUEST, 
    173                                     "LIFETIME too short", NULL,  
     173                                    "LIFETIME too short", NULL, 
    174174                                    PJ_TRUE, src_addr, src_addr_len); 
    175175            return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_BAD_REQUEST); 
     
    207207    /* Add LIFETIME. */ 
    208208    pj_stun_msg_add_uint_attr(tdata->pool, tdata->msg, 
    209                               PJ_STUN_ATTR_LIFETIME,  
     209                              PJ_STUN_ATTR_LIFETIME, 
    210210                              (unsigned)alloc->relay.lifetime); 
    211211 
     
    223223                                  &alloc->hkey.clt_addr, 
    224224                                  pj_sockaddr_get_len(&alloc->hkey.clt_addr)); 
    225      
     225 
    226226    /* Send the response */ 
    227227    return pj_stun_session_send_msg(srv_sess, transport, PJ_TRUE, 
    228                                     PJ_FALSE, &alloc->hkey.clt_addr,  
     228                                    PJ_FALSE, &alloc->hkey.clt_addr, 
    229229                                    pj_sockaddr_get_len(&alloc->hkey.clt_addr), 
    230230                                    tdata); 
     
    256256 
    257257    /* Lookup the password */ 
    258     status = pj_turn_get_password(NULL, NULL, &realm->value,  
    259                                   &user->value, alloc->pool,  
    260                                   &alloc->cred.data.static_cred.data_type,  
     258    status = pj_turn_get_password(NULL, NULL, &realm->value, 
     259                                  &user->value, alloc->pool, 
     260                                  &alloc->cred.data.static_cred.data_type, 
    261261                                  &alloc->cred.data.static_cred.data); 
    262262    if (status != PJ_SUCCESS) 
     
    315315    pj_memcpy(&alloc->hkey.clt_addr, src_addr, src_addr_len); 
    316316 
    317     status = pj_lock_create_recursive_mutex(pool, alloc->obj_name,  
     317    status = pj_lock_create_recursive_mutex(pool, alloc->obj_name, 
    318318                                            &alloc->lock); 
    319319    if (status != PJ_SUCCESS) { 
     
    328328 
    329329    /* Print info */ 
    330     pj_ansi_strcpy(alloc->info,  
     330    pj_ansi_strcpy(alloc->info, 
    331331                   pj_turn_tp_type_name(transport->listener->tp_type)); 
    332332    alloc->info[3] = ':'; 
     
    372372 
    373373    /* Done */ 
    374     pj_sockaddr_print(&alloc->relay.hkey.addr, str_tmp,  
     374    pj_sockaddr_print(&alloc->relay.hkey.addr, str_tmp, 
    375375                      sizeof(str_tmp), 3); 
    376     PJ_LOG(4,(alloc->obj_name, "Client %s created, relay addr=%s:%s",  
     376    PJ_LOG(4,(alloc->obj_name, "Client %s created, relay addr=%s:%s", 
    377377              alloc->info, pj_turn_tp_type_name(req.tp_type), str_tmp)); 
    378378 
     
    384384    /* Send reply to the ALLOCATE request */ 
    385385    pj_strerror(status, str_tmp, sizeof(str_tmp)); 
    386     pj_stun_session_respond(srv_sess, rdata, PJ_STUN_SC_BAD_REQUEST, str_tmp,  
     386    pj_stun_session_respond(srv_sess, rdata, PJ_STUN_SC_BAD_REQUEST, str_tmp, 
    387387                            transport, PJ_TRUE, src_addr, src_addr_len); 
    388388 
     
    397397{ 
    398398    if (relay->timer.id) { 
    399         pj_timer_heap_cancel(relay->allocation->server->core.timer_heap,  
     399        pj_timer_heap_cancel(relay->allocation->server->core.timer_heap, 
    400400                             &relay->timer); 
    401401        relay->timer.id = PJ_FALSE; 
     
    483483 
    484484/* Initiate shutdown sequence for this allocation and start destroy timer. 
    485  * Once allocation is marked as shutting down, any packets will be  
    486  * rejected/discarded  
     485 * Once allocation is marked as shutting down, any packets will be 
     486 * rejected/discarded 
    487487 */ 
    488488static void alloc_shutdown(pj_turn_allocation *alloc) 
     
    502502         */ 
    503503        return; 
    504     }  
     504    } 
    505505 
    506506    pj_assert(alloc->relay.timer.id == TIMER_ID_NONE); 
     
    531531    pj_assert(alloc->relay.timer.id != TIMER_ID_DESTROY); 
    532532    if (alloc->relay.timer.id != 0) { 
    533         pj_timer_heap_cancel(alloc->server->core.timer_heap,  
     533        pj_timer_heap_cancel(alloc->server->core.timer_heap, 
    534534                             &alloc->relay.timer); 
    535535        alloc->relay.timer.id = TIMER_ID_NONE; 
     
    540540 
    541541    alloc->relay.timer.id = TIMER_ID_TIMEOUT; 
    542     status = pj_timer_heap_schedule(alloc->server->core.timer_heap,  
     542    status = pj_timer_heap_schedule(alloc->server->core.timer_heap, 
    543543                                    &alloc->relay.timer, &delay); 
    544544    if (status != PJ_SUCCESS) { 
     
    566566        e->id = TIMER_ID_NONE; 
    567567 
    568         PJ_LOG(4,(alloc->obj_name,  
    569                   "Client %s refresh timed-out, shutting down..",  
     568        PJ_LOG(4,(alloc->obj_name, 
     569                  "Client %s refresh timed-out, shutting down..", 
    570570                  alloc->info)); 
    571571 
     
    575575        e->id = TIMER_ID_NONE; 
    576576 
    577         PJ_LOG(4,(alloc->obj_name, "Client %s destroying..",  
     577        PJ_LOG(4,(alloc->obj_name, "Client %s destroying..", 
    578578                  alloc->info)); 
    579579 
     
    601601 
    602602    pj_bzero(relay, sizeof(*relay)); 
    603      
     603 
    604604    relay->allocation = alloc; 
    605605    relay->tp.sock = PJ_INVALID_SOCKET; 
    606      
     606 
    607607    /* TODO: get the requested address family from somewhere */ 
    608608    af = alloc->transport->listener->addr.addr.sa_family; 
     
    622622    /* Lifetime and timeout */ 
    623623    relay->lifetime = req->lifetime; 
    624     pj_timer_entry_init(&relay->timer, TIMER_ID_NONE, relay,  
     624    pj_timer_entry_init(&relay->timer, TIMER_ID_NONE, relay, 
    625625                        &relay_timeout_cb); 
    626626    resched_timeout(alloc); 
    627      
     627 
    628628    /* Transport type */ 
    629629    relay->hkey.tp_type = req->tp_type; 
     
    677677        pj_sockaddr_init(af, &bound_addr, NULL, port); 
    678678 
    679         status = pj_sock_bind(relay->tp.sock, &bound_addr,  
     679        status = pj_sock_bind(relay->tp.sock, &bound_addr, 
    680680                              pj_sockaddr_get_len(&bound_addr)); 
    681681        if (status == PJ_SUCCESS) 
     
    685685    if (status != PJ_SUCCESS) { 
    686686        /* Unable to allocate port */ 
    687         PJ_LOG(4,(THIS_FILE, "Unable to allocate relay, giving up: err %d",  
     687        PJ_LOG(4,(THIS_FILE, "Unable to allocate relay, giving up: err %d", 
    688688                  status)); 
    689689        pj_sock_close(relay->tp.sock); 
     
    696696    status = pj_sock_getsockname(relay->tp.sock, &relay->hkey.addr, &namelen); 
    697697    if (status != PJ_SUCCESS) { 
    698         PJ_LOG(4,(THIS_FILE, "pj_sock_getsockname() failed: err %d",  
     698        PJ_LOG(4,(THIS_FILE, "pj_sock_getsockname() failed: err %d", 
    699699                  status)); 
    700700        pj_sock_close(relay->tp.sock); 
     
    703703    } 
    704704    if (!pj_sockaddr_has_addr(&relay->hkey.addr)) { 
    705         pj_sockaddr_copy_addr(&relay->hkey.addr,  
     705        pj_sockaddr_copy_addr(&relay->hkey.addr, 
    706706                              &alloc->transport->listener->addr); 
    707707    } 
     
    719719                                      relay, &icb, &relay->tp.key); 
    720720    if (status != PJ_SUCCESS) { 
    721         PJ_LOG(4,(THIS_FILE, "pj_ioqueue_register_sock() failed: err %d",  
     721        PJ_LOG(4,(THIS_FILE, "pj_ioqueue_register_sock() failed: err %d", 
    722722                  status)); 
    723723        pj_sock_close(relay->tp.sock); 
     
    737737static void send_reply_err(pj_turn_allocation *alloc, 
    738738                           const pj_stun_rx_data *rdata, 
    739                            pj_bool_t cache,  
     739                           pj_bool_t cache, 
    740740                           int code, const char *errmsg) 
    741741{ 
    742742    pj_status_t status; 
    743743 
    744     status = pj_stun_session_respond(alloc->sess, rdata, code, errmsg, NULL,  
     744    status = pj_stun_session_respond(alloc->sess, rdata, code, errmsg, NULL, 
    745745                                     cache, &alloc->hkey.clt_addr, 
    746746                                     pj_sockaddr_get_len(&alloc->hkey.clt_addr.addr)); 
     
    787787    } 
    788788 
    789     status = pj_stun_session_send_msg(alloc->sess, NULL, PJ_TRUE,  
    790                                       PJ_FALSE, &alloc->hkey.clt_addr,   
    791                                       pj_sockaddr_get_len(&alloc->hkey.clt_addr),  
     789    status = pj_stun_session_send_msg(alloc->sess, NULL, PJ_TRUE, 
     790                                      PJ_FALSE, &alloc->hkey.clt_addr, 
     791                                      pj_sockaddr_get_len(&alloc->hkey.clt_addr), 
    792792                                      tdata); 
    793793    if (status != PJ_SUCCESS) { 
     
    807807    perm = PJ_POOL_ZALLOC_T(alloc->pool, pj_turn_permission); 
    808808    pj_memcpy(&perm->hkey.peer_addr, peer_addr, addr_len); 
    809      
     809 
    810810    perm->allocation = alloc; 
    811811    perm->channel = PJ_TURN_INVALID_CHANNEL; 
     
    815815 
    816816    /* Register to hash table (only the address part!) */ 
    817     pj_hash_set(alloc->pool, alloc->peer_table,  
    818                 pj_sockaddr_get_addr(&perm->hkey.peer_addr),  
     817    pj_hash_set(alloc->pool, alloc->peer_table, 
     818                pj_sockaddr_get_addr(&perm->hkey.peer_addr), 
    819819                pj_sockaddr_get_addr_len(&perm->hkey.peer_addr), 0, perm); 
    820820 
     
    835835 
    836836    /* Remove from permission hash table */ 
    837     pj_hash_set(NULL, alloc->peer_table,  
    838                 pj_sockaddr_get_addr(&perm->hkey.peer_addr),  
     837    pj_hash_set(NULL, alloc->peer_table, 
     838                pj_sockaddr_get_addr(&perm->hkey.peer_addr), 
    839839                pj_sockaddr_get_addr_len(&perm->hkey.peer_addr), 0, NULL); 
    840840 
    841841    /* Remove from channel hash table, if assigned a channel number */ 
    842842    if (perm->channel != PJ_TURN_INVALID_CHANNEL) { 
    843         pj_hash_set(NULL, alloc->ch_table, &perm->channel,  
     843        pj_hash_set(NULL, alloc->ch_table, &perm->channel, 
    844844                    sizeof(perm->channel), 0, NULL); 
    845845    } 
     
    859859 
    860860    /* Lookup in peer hash table */ 
    861     perm = (pj_turn_permission*)  
    862            pj_hash_get(alloc->peer_table,  
     861    perm = (pj_turn_permission*) 
     862           pj_hash_get(alloc->peer_table, 
    863863                       pj_sockaddr_get_addr(peer_addr), 
    864                        pj_sockaddr_get_addr_len(peer_addr),  
     864                       pj_sockaddr_get_addr_len(peer_addr), 
    865865                       NULL); 
    866866    return perm ? check_permission_expiry(perm) : NULL; 
     
    881881} 
    882882 
    883 /* Update permission because of data from client to peer.  
     883/* Update permission because of data from client to peer. 
    884884 * Return PJ_TRUE is permission is found. 
    885885 */ 
     
    917917         * callbacks. 
    918918         * 
    919          * Note: currently it is necessary to specify the  
     919         * Note: currently it is necessary to specify the 
    920920         * PJ_STUN_NO_FINGERPRINT_CHECK otherwise the FINGERPRINT 
    921921         * attribute inside STUN Send Indication message will mess up 
     
    930930        status = pj_stun_session_on_rx_pkt(alloc->sess, pkt->pkt, pkt->len, 
    931931                                           options, NULL, &parsed_len, 
    932                                            &pkt->src.clt_addr,  
     932                                           &pkt->src.clt_addr, 
    933933                                           pkt->src_addr_len); 
    934934 
     
    963963        if (alloc->transport->listener->tp_type == PJ_TURN_TP_UDP) { 
    964964            if (pkt->len < pj_ntohs(cd->length)+sizeof(*cd)) { 
    965                 PJ_LOG(4,(alloc->obj_name,  
     965                PJ_LOG(4,(alloc->obj_name, 
    966966                          "ChannelData from %s discarded: UDP size error", 
    967967                          alloc->info)); 
     
    976976        if (!perm) { 
    977977            /* Discard */ 
    978             PJ_LOG(4,(alloc->obj_name,  
     978            PJ_LOG(4,(alloc->obj_name, 
    979979                      "ChannelData from %s discarded: ch#0x%x not found", 
    980980                      alloc->info, pj_ntohs(cd->ch_number))); 
     
    999999 
    10001000/* 
    1001  * Handle incoming packet from peer. This function is called by  
     1001 * Handle incoming packet from peer. This function is called by 
    10021002 * on_rx_from_peer(). 
    10031003 */ 
     
    10101010 
    10111011    /* Lookup permission */ 
    1012     perm = lookup_permission_by_addr(alloc, src_addr,  
     1012    perm = lookup_permission_by_addr(alloc, src_addr, 
    10131013                                     pj_sockaddr_get_len(src_addr)); 
    10141014    if (perm == NULL) { 
     
    10501050        pj_status_t status; 
    10511051 
    1052         status = pj_stun_session_create_ind(alloc->sess,  
     1052        status = pj_stun_session_create_ind(alloc->sess, 
    10531053                                            PJ_STUN_DATA_INDICATION, &tdata); 
    10541054        if (status != PJ_SUCCESS) { 
     
    10571057        } 
    10581058 
    1059         pj_stun_msg_add_sockaddr_attr(tdata->pool, tdata->msg,  
     1059        pj_stun_msg_add_sockaddr_attr(tdata->pool, tdata->msg, 
    10601060                                      PJ_STUN_ATTR_XOR_PEER_ADDR, PJ_TRUE, 
    10611061                                      src_addr, pj_sockaddr_get_len(src_addr)); 
    10621062        pj_stun_msg_add_binary_attr(tdata->pool, tdata->msg, 
    1063                                     PJ_STUN_ATTR_DATA,  
     1063                                    PJ_STUN_ATTR_DATA, 
    10641064                                    (const pj_uint8_t*)pkt, len); 
    10651065 
    1066         pj_stun_session_send_msg(alloc->sess, NULL, PJ_FALSE,  
    1067                                  PJ_FALSE, &alloc->hkey.clt_addr,  
    1068                                  pj_sockaddr_get_len(&alloc->hkey.clt_addr),  
     1066        pj_stun_session_send_msg(alloc->sess, NULL, PJ_FALSE, 
     1067                                 PJ_FALSE, &alloc->hkey.clt_addr, 
     1068                                 pj_sockaddr_get_len(&alloc->hkey.clt_addr), 
    10691069                                 tdata); 
    10701070    } 
     
    10741074 * ioqueue notification on RX packets from the relay socket. 
    10751075 */ 
    1076 static void on_rx_from_peer(pj_ioqueue_key_t *key,  
    1077                             pj_ioqueue_op_key_t *op_key,  
     1076static void on_rx_from_peer(pj_ioqueue_key_t *key, 
     1077                            pj_ioqueue_op_key_t *op_key, 
    10781078                            pj_ssize_t bytes_read) 
    10791079{ 
     
    10971097        status = pj_ioqueue_recvfrom(key, op_key, 
    10981098                                     rel->tp.rx_pkt, &bytes_read, 0, 
    1099                                      &rel->tp.src_addr,  
     1099                                     &rel->tp.src_addr, 
    11001100                                     &rel->tp.src_addr_len); 
    11011101 
     
    11571157    if (alloc->relay.lifetime == 0) { 
    11581158        /* Reject with 437 if we're shutting down */ 
    1159         send_reply_err(alloc, rdata, PJ_TRUE,  
     1159        send_reply_err(alloc, rdata, PJ_TRUE, 
    11601160                       PJ_STUN_SC_ALLOCATION_MISMATCH, NULL); 
    11611161        return PJ_SUCCESS; 
     
    11631163 
    11641164    if (msg->hdr.type == PJ_STUN_REFRESH_REQUEST) { 
    1165         /*  
    1166          * Handle REFRESH request  
     1165        /* 
     1166         * Handle REFRESH request 
    11671167         */ 
    11681168        pj_stun_lifetime_attr *lifetime; 
     
    11761176        bandwidth = (pj_stun_bandwidth_attr*) 
    11771177                    pj_stun_msg_find_attr(msg, PJ_STUN_ATTR_BANDWIDTH, 0); 
     1178 
     1179        /* TODO: process bandwidth */ 
     1180        PJ_UNUSED_ARG(bandwidth); 
    11781181 
    11791182        if (lifetime && lifetime->value==0) { 
     
    11871190 
    11881191            /* Shutdown allocation */ 
    1189             PJ_LOG(4,(alloc->obj_name,  
     1192            PJ_LOG(4,(alloc->obj_name, 
    11901193                      "Client %s request to dealloc, shutting down", 
    11911194                      alloc->info)); 
     
    11971200             * This is a refresh request. 
    11981201             */ 
    1199              
     1202 
    12001203            /* Update lifetime */ 
    12011204            if (lifetime) { 
     
    12271230 
    12281231        if (!ch_attr || !peer_attr) { 
    1229             send_reply_err(alloc, rdata, PJ_TRUE,  
     1232            send_reply_err(alloc, rdata, PJ_TRUE, 
    12301233                           PJ_STUN_SC_BAD_REQUEST, NULL); 
    12311234            return PJ_SUCCESS; 
     
    12351238        p1 = lookup_permission_by_chnum(alloc, PJ_STUN_GET_CH_NB(ch_attr->value)); 
    12361239 
    1237         /* If permission is found, this is supposed to be a channel bind  
     1240        /* If permission is found, this is supposed to be a channel bind 
    12381241         * refresh. Make sure it's for the same peer. 
    12391242         */ 
     
    12411244            if (pj_sockaddr_cmp(&p1->hkey.peer_addr, &peer_attr->sockaddr)) { 
    12421245                /* Address mismatch. Send 400 */ 
    1243                 send_reply_err(alloc, rdata, PJ_TRUE,  
    1244                                PJ_STUN_SC_BAD_REQUEST,  
     1246                send_reply_err(alloc, rdata, PJ_TRUE, 
     1247                               PJ_STUN_SC_BAD_REQUEST, 
    12451248                               "Peer address mismatch"); 
    12461249                return PJ_SUCCESS; 
     
    12631266                                       pj_sockaddr_get_len(&peer_attr->sockaddr)); 
    12641267        if (p2 && p2->channel != PJ_TURN_INVALID_CHANNEL) { 
    1265             send_reply_err(alloc, rdata, PJ_TRUE, PJ_STUN_SC_BAD_REQUEST,  
     1268            send_reply_err(alloc, rdata, PJ_TRUE, PJ_STUN_SC_BAD_REQUEST, 
    12661269                           "Peer address already assigned a channel number"); 
    12671270            return PJ_SUCCESS; 
     
    12811284        /* Register to hash table */ 
    12821285        pj_assert(sizeof(p2->channel==2)); 
    1283         pj_hash_set(alloc->pool, alloc->ch_table, &p2->channel,  
     1286        pj_hash_set(alloc->pool, alloc->ch_table, &p2->channel, 
    12841287                    sizeof(p2->channel), 0, p2); 
    12851288 
     
    13681371    /* Relay the data to peer */ 
    13691372    len = data_attr->length; 
    1370     pj_sock_sendto(alloc->relay.tp.sock, data_attr->data,  
     1373    pj_sock_sendto(alloc->relay.tp.sock, data_attr->data, 
    13711374                   &len, 0, &peer_attr->sockaddr, 
    13721375                   pj_sockaddr_get_len(&peer_attr->sockaddr)); 
  • pjproject/trunk/pjnath/src/pjturn-srv/server.c

    r4360 r4728  
    11/* $Id$ */ 
    2 /*  
     2/* 
    33 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 
    44 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 
     
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1919 */ 
    2020#include "turn.h" 
     
    7777 * Create server. 
    7878 */ 
    79 PJ_DEF(pj_status_t) pj_turn_srv_create(pj_pool_factory *pf,  
     79PJ_DEF(pj_status_t) pj_turn_srv_create(pj_pool_factory *pf, 
    8080                                       pj_turn_srv **p_srv) 
    8181{ 
     
    9595    srv->core.pool = pool; 
    9696    srv->core.tls_key = srv->core.tls_data = -1; 
    97      
     97 
    9898    /* Create ioqueue */ 
    9999    status = pj_ioqueue_create(pool, MAX_HANDLES, &srv->core.ioqueue); 
     
    102102 
    103103    /* Server mutex */ 
    104     status = pj_lock_create_recursive_mutex(pool, srv->obj_name,  
     104    status = pj_lock_create_recursive_mutex(pool, srv->obj_name, 
    105105                                            &srv->core.lock); 
    106106    if (status != PJ_SUCCESS) 
     
    115115    if (status != PJ_SUCCESS) 
    116116        goto on_error; 
    117      
     117 
    118118    /* Create timer heap */ 
    119119    status = pj_timer_heap_create(pool, MAX_TIMER, &srv->core.timer_heap); 
     
    126126    /* Array of listeners */ 
    127127    srv->core.listener = (pj_turn_listener**) 
    128                          pj_pool_calloc(pool, MAX_LISTENERS,  
     128                         pj_pool_calloc(pool, MAX_LISTENERS, 
    129129                                        sizeof(srv->core.listener[0])); 
    130130 
     
    170170    srv->core.thread_cnt = MAX_THREADS; 
    171171    srv->core.thread = (pj_thread_t**) 
    172                        pj_pool_calloc(pool, srv->core.thread_cnt,  
     172                       pj_pool_calloc(pool, srv->core.thread_cnt, 
    173173                                      sizeof(pj_thread_t*)); 
    174174 
    175175    /* Start the worker threads */ 
    176176    for (i=0; i<srv->core.thread_cnt; ++i) { 
    177         status = pj_thread_create(pool, srv->obj_name, &server_thread_proc,  
     177        status = pj_thread_create(pool, srv->obj_name, &server_thread_proc, 
    178178                                  srv, 0, 0, &srv->core.thread[i]); 
    179179        if (status != PJ_SUCCESS) 
     
    182182 
    183183    /* We're done. Application should add listeners now */ 
    184     PJ_LOG(4,(srv->obj_name, "TURN server v%s is running",  
     184    PJ_LOG(4,(srv->obj_name, "TURN server v%s is running", 
    185185              pj_get_version())); 
    186186 
     
    194194 
    195195 
    196 /*  
    197  * Handle timer and network events  
     196/* 
     197 * Handle timer and network events 
    198198 */ 
    199199static void srv_handle_events(pj_turn_srv *srv, const pj_time_val *max_timeout) 
     
    204204    int c; 
    205205 
    206     /* Poll the timer. The timer heap has its own mutex for better  
    207      * granularity, so we don't need to lock the server.  
     206    /* Poll the timer. The timer heap has its own mutex for better 
     207     * granularity, so we don't need to lock the server. 
    208208     */ 
    209209    timeout.sec = timeout.msec = 0; 
     
    223223    } 
    224224 
    225     /* Poll ioqueue.  
     225    /* Poll ioqueue. 
    226226     * Repeat polling the ioqueue while we have immediate events, because 
    227227     * timer heap may process more than one events, so if we only process 
     
    293293        } 
    294294    } 
    295      
     295 
    296296    /* Destroy all listeners. */ 
    297297    for (i=0; i<srv->core.lis_cnt; ++i) { 
     
    313313        srv->tables.res = NULL; 
    314314    } 
    315      
     315 
    316316    /* Destroy timer heap */ 
    317317    if (srv->core.timer_heap) { 
     
    461461 
    462462 
    463 /* Callback from our own STUN session whenever it needs to send  
     463/* Callback from our own STUN session whenever it needs to send 
    464464 * outgoing STUN packet. 
    465465 */ 
     
    472472{ 
    473473    pj_turn_transport *transport = (pj_turn_transport*) token; 
    474      
     474 
    475475    PJ_ASSERT_RETURN(transport!=NULL, PJ_EINVALIDOP); 
    476476 
    477477    PJ_UNUSED_ARG(sess); 
    478478 
    479     return transport->sendto(transport, pdu, pdu_size, 0,  
     479    return transport->sendto(transport, pdu, pdu_size, 0, 
    480480                             dst_addr, addr_len); 
    481481} 
     
    483483 
    484484/* Respond to STUN request */ 
    485 static pj_status_t stun_respond(pj_stun_session *sess,  
     485static pj_status_t stun_respond(pj_stun_session *sess, 
    486486                                pj_turn_transport *transport, 
    487487                                const pj_stun_rx_data *rdata, 
    488                                 unsigned code,  
     488                                unsigned code, 
    489489                                const char *errmsg, 
    490                                 pj_bool_t cache,  
    491                                 const pj_sockaddr_t *dst_addr,  
     490                                pj_bool_t cache, 
     491                                const pj_sockaddr_t *dst_addr, 
    492492                                unsigned addr_len) 
    493493{ 
     
    497497 
    498498    /* Create response */ 
    499     status = pj_stun_session_create_res(sess, rdata, code,  
     499    status = pj_stun_session_create_res(sess, rdata, code, 
    500500                                        (errmsg?pj_cstr(&reason,errmsg):NULL), 
    501501                                        &tdata); 
     
    504504 
    505505    /* Send the response */ 
    506     return pj_stun_session_send_msg(sess, transport, cache, PJ_FALSE,  
     506    return pj_stun_session_send_msg(sess, transport, cache, PJ_FALSE, 
    507507                                    dst_addr,  addr_len, tdata); 
    508508} 
     
    523523    pj_turn_transport *transport; 
    524524    const pj_stun_msg *msg = rdata->msg; 
    525     pj_turn_srv *srv; 
    526525    pj_turn_allocation *alloc; 
    527526    pj_status_t status; 
     
    531530 
    532531    transport = (pj_turn_transport*) token; 
    533     srv = transport->listener->server; 
    534532 
    535533    /* Respond any requests other than ALLOCATE with 437 response */ 
     
    570568 
    571569    /* Create response */ 
    572     status = pj_stun_msg_create_response(pkt->pool, request, 0, NULL,  
     570    status = pj_stun_msg_create_response(pkt->pool, request, 0, NULL, 
    573571                                         &response); 
    574572    if (status != PJ_SUCCESS) 
     
    576574 
    577575    /* Add XOR-MAPPED-ADDRESS */ 
    578     pj_stun_msg_add_sockaddr_attr(pkt->pool, response,  
     576    pj_stun_msg_add_sockaddr_attr(pkt->pool, response, 
    579577                                  PJ_STUN_ATTR_XOR_MAPPED_ADDR, 
    580578                                  PJ_TRUE, 
     
    588586 
    589587    /* Send response */ 
    590     pkt->transport->sendto(pkt->transport, pdu, len, 0,  
     588    pkt->transport->sendto(pkt->transport, pdu, len, 0, 
    591589                           &pkt->src.clt_addr, pkt->src_addr_len); 
    592590} 
     
    599597 * if an allocation is not found. 
    600598 */ 
    601 PJ_DEF(void) pj_turn_srv_on_rx_pkt(pj_turn_srv *srv,  
     599PJ_DEF(void) pj_turn_srv_on_rx_pkt(pj_turn_srv *srv, 
    602600                                   pj_turn_pkt *pkt) 
    603601{ 
     
    639637            if ((*pkt->pkt != 0x00 && *pkt->pkt != 0x01) || 
    640638                pkt->len > 1600 || 
    641                 (options & PJ_STUN_IS_DATAGRAM))  
     639                (options & PJ_STUN_IS_DATAGRAM)) 
    642640            { 
    643641                char errmsg[PJ_ERR_MSG_SIZE]; 
     
    647645 
    648646                pj_strerror(status, errmsg, sizeof(errmsg)); 
    649                 PJ_LOG(5,(srv->obj_name,  
     647                PJ_LOG(5,(srv->obj_name, 
    650648                          "Non-STUN packet from %s is dropped: %s", 
    651649                          pj_sockaddr_print(&pkt->src.clt_addr, ip, sizeof(ip), 3), 
     
    655653        } 
    656654 
    657         /* Special handling for Binding Request. We won't give it to the  
     655        /* Special handling for Binding Request. We won't give it to the 
    658656         * STUN session since this request is not authenticated. 
    659657         */ 
     
    669667        options &= ~PJ_STUN_CHECK_PACKET; 
    670668        parsed_len = 0; 
    671         status = pj_stun_session_on_rx_pkt(srv->core.stun_sess, pkt->pkt,  
     669        status = pj_stun_session_on_rx_pkt(srv->core.stun_sess, pkt->pkt, 
    672670                                           pkt->len, options, pkt->transport, 
    673                                            &parsed_len, &pkt->src.clt_addr,  
     671                                           &parsed_len, &pkt->src.clt_addr, 
    674672                                           pkt->src_addr_len); 
    675673        if (status != PJ_SUCCESS) { 
     
    678676 
    679677            pj_strerror(status, errmsg, sizeof(errmsg)); 
    680             PJ_LOG(5,(srv->obj_name,  
     678            PJ_LOG(5,(srv->obj_name, 
    681679                      "Error processing STUN packet from %s: %s", 
    682680                      pj_sockaddr_print(&pkt->src.clt_addr, ip, sizeof(ip), 3), 
  • pjproject/trunk/pjsip-apps/src/pjsystest/systest.c

    r4537 r4728  
    11/* $Id$ */ 
    2 /*  
     2/* 
    33 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 
    44 * 
     
    1515 * You should have received a copy of the GNU General Public License 
    1616 * along with this program; if not, write to the Free Software 
    17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1818 */ 
    1919#include "systest.h" 
     
    5757static gui_menu menu_getsets = { "View Settings", &systest_display_settings }; 
    5858 
    59 static gui_menu menu_tests = {  
    60     "Tests", NULL,  
    61     10,  
     59static gui_menu menu_tests = { 
     60    "Tests", NULL, 
     61    10, 
    6262    { 
    6363        &menu_wizard, 
    64         &menu_audtest,  
     64        &menu_audtest, 
    6565        &menu_playtn, 
    6666        &menu_playwv1, 
     
    6969        &menu_calclat, 
    7070        &menu_sndaec, 
    71         NULL,  
     71        NULL, 
    7272        &menu_exit 
    7373    } 
    7474}; 
    7575 
    76 static gui_menu menu_options = {  
    77     "Options", NULL,  
    78     2,  
     76static gui_menu menu_options = { 
     77    "Options", NULL, 
     78    2, 
    7979    { 
    8080        &menu_listdev, 
     
    8383}; 
    8484 
    85 static gui_menu root_menu = {  
    86     "Root", NULL, 2, {&menu_tests, &menu_options}  
     85static gui_menu root_menu = { 
     86    "Root", NULL, 2, {&menu_tests, &menu_options} 
    8787}; 
    8888 
     
    134134    else 
    135135        errmsg[0] = '\0'; 
    136      
     136 
    137137    strcpy(themsg, title); 
    138138    strncat(themsg, errmsg, sizeof(themsg)-1); 
     
    159159 
    160160/***************************************************************************** 
    161  * test: play simple ringback tone and hear it  
     161 * test: play simple ringback tone and hear it 
    162162 */ 
    163163static void systest_play_tone(void) 
     
    202202 
    203203    pool = pjsua_pool_create("ringback", 512, 512); 
    204     samples_per_frame = systest.media_cfg.audio_frame_ptime *  
     204    samples_per_frame = systest.media_cfg.audio_frame_ptime * 
    205205                        systest.media_cfg.clock_rate * 
    206206                        systest.media_cfg.channel_count / 1000; 
     
    208208    /* Ringback tone (call is ringing) */ 
    209209    name = pj_str("ringback"); 
    210     status = pjmedia_tonegen_create2(pool, &name,  
     210    status = pjmedia_tonegen_create2(pool, &name, 
    211211                                     systest.media_cfg.clock_rate, 
    212                                      systest.media_cfg.channel_count,  
     212                                     systest.media_cfg.channel_count, 
    213213                                     samples_per_frame, 
    214                                      16, PJMEDIA_TONEGEN_LOOP,  
     214                                     16, PJMEDIA_TONEGEN_LOOP, 
    215215                                     &ringback_port); 
    216216    if (status != PJ_SUCCESS) 
     
    270270 * the file. 
    271271 */ 
    272 static pj_status_t create_player(unsigned path_cnt, const char *paths[],  
     272static pj_status_t create_player(unsigned path_cnt, const char *paths[], 
    273273                                 pjsua_player_id *p_id) 
    274274{ 
     
    365365 
    366366/***************************************************************************** 
    367  * test: record audio  
     367 * test: record audio 
    368368 */ 
    369369static void systest_rec_audio(void) 
     
    388388                     "from the microphone, and playback the " 
    389389                     "audio to the speaker. Press OK to start recording, " 
    390                      "CANCEL to skip.",  
     390                     "CANCEL to skip.", 
    391391                     WITH_OKCANCEL); 
    392392    if (key != KEY_OK) { 
     
    433433                     "The recorded audio is being played now to " 
    434434                     "the speaker device, in a loop. Listen for " 
    435                      "any audio impairments. Press OK to stop.",  
     435                     "any audio impairments. Press OK to stop.", 
    436436                     WITH_OK); 
    437437 
     
    526526    param.clock_rate = systest.media_cfg.snd_clock_rate; 
    527527    param.channel_count = systest.media_cfg.channel_count; 
    528     param.samples_per_frame = param.clock_rate * param.channel_count *  
     528    param.samples_per_frame = param.clock_rate * param.channel_count * 
    529529                              systest.media_cfg.audio_frame_ptime / 1000; 
    530530 
    531531    /* Latency settings */ 
    532     param.flags |= (PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY |  
     532    param.flags |= (PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY | 
    533533                    PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY); 
    534534    param.input_latency_ms = systest.media_cfg.snd_rec_latency; 
     
    554554 
    555555    if (result.rec.frame_cnt==0) { 
    556         problems[problem_count++] =  
     556        problems[problem_count++] = 
    557557            "No audio frames were captured from the microphone. " 
    558558            "This means the audio device is not working properly."; 
    559559    } else { 
    560         pj_ansi_snprintf(textbuf+textbufpos,  
     560        pj_ansi_snprintf(textbuf+textbufpos, 
    561561                         sizeof(textbuf)-textbufpos, 
    562562                         "Rec : interval (min/max/avg/dev)=\r\n" 
     
    571571 
    572572        if (result.rec.max_burst > GOOD_MAX_INTERVAL) { 
    573             problems[problem_count++] =  
     573            problems[problem_count++] = 
    574574                "Recording max burst is quite high"; 
    575575        } 
     
    577577 
    578578    if (result.play.frame_cnt==0) { 
    579         problems[problem_count++] =  
     579        problems[problem_count++] = 
    580580            "No audio frames were played to the speaker. " 
    581581            "This means the audio device is not working properly."; 
    582582    } else { 
    583         pj_ansi_snprintf(textbuf+textbufpos,  
     583        pj_ansi_snprintf(textbuf+textbufpos, 
    584584                         sizeof(textbuf)-textbufpos, 
    585585                         "Play: interval (min/max/avg/dev)=\r\n" 
     
    594594 
    595595        if (result.play.max_burst > GOOD_MAX_INTERVAL) { 
    596             problems[problem_count++] =  
     596            problems[problem_count++] = 
    597597                "Playback max burst is quite high"; 
    598598        } 
     
    601601    if (result.rec_drift_per_sec) { 
    602602        const char *which = result.rec_drift_per_sec>=0 ? "faster" : "slower"; 
    603         unsigned drift = result.rec_drift_per_sec>=0 ?  
     603        unsigned drift = result.rec_drift_per_sec>=0 ? 
    604604                            result.rec_drift_per_sec : 
    605605                            -result.rec_drift_per_sec; 
     
    614614 
    615615    if (problem_count == 0) { 
    616         pj_ansi_snprintf(textbuf+textbufpos,  
     616        pj_ansi_snprintf(textbuf+textbufpos, 
    617617                         sizeof(textbuf)-textbufpos, 
    618618                         "\r\nThe sound device seems to be okay!"); 
     
    624624 
    625625        pj_ansi_snprintf(textbuf+textbufpos, 
    626                          sizeof(textbuf)-textbufpos,  
     626                         sizeof(textbuf)-textbufpos, 
    627627                         "There could be %d problem(s) with the " 
    628628                         "sound device:\r\n", 
     
    632632        for (i=0; i<problem_count; ++i) { 
    633633            pj_ansi_snprintf(textbuf+textbufpos, 
    634                              sizeof(textbuf)-textbufpos,  
     634                             sizeof(textbuf)-textbufpos, 
    635635                             " %d: %s\r\n", i+1, problems[i]); 
    636636            textbufpos = strlen(textbuf); 
     
    650650 */ 
    651651static int calculate_latency(pj_pool_t *pool, pjmedia_port *wav, 
    652                              unsigned *lat_sum, unsigned *lat_cnt,  
     652                             unsigned *lat_sum, unsigned *lat_cnt, 
    653653                             unsigned *lat_min, unsigned *lat_max) 
    654654{ 
     
    689689    } 
    690690 
    691     /* Zero the first 500ms to remove loud click noises  
     691    /* Zero the first 500ms to remove loud click noises 
    692692     * (keypad press, etc.) 
    693693     */ 
     
    784784        return; 
    785785    } 
    786     key = gui_msgbox(title,  
     786    key = gui_msgbox(title, 
    787787                     "For this test to work, we must be able to capture " 
    788788                     "the audio played in the speaker (the echo), and only" 
     
    798798    PJ_LOG(3,(THIS_FILE, "Running %s", title)); 
    799799 
    800     status = create_player(PJ_ARRAY_SIZE(ref_wav_paths), ref_wav_paths,  
     800    status = create_player(PJ_ARRAY_SIZE(ref_wav_paths), ref_wav_paths, 
    801801                           &play_id); 
    802802    if (status != PJ_SUCCESS) 
     
    817817    status = pjsua_conf_connect(0, rec_slot); 
    818818    status = pjsua_conf_connect(play_slot, rec_slot); 
    819      
     819 
    820820 
    821821    /* We're running */ 
     
    870870        goto on_return; 
    871871 
    872     status = calculate_latency(pool, wav_port, &lat_sum, &lat_cnt,  
     872    status = calculate_latency(pool, wav_port, &lat_sum, &lat_cnt, 
    873873                               &lat_min, &lat_max); 
    874874    if (status != PJ_SUCCESS) 
     
    913913            msglen = strlen(msg); 
    914914        } 
    915          
     915 
    916916        key = gui_msgbox(title, msg, WITH_OK); 
    917917 
     
    965965     * Create player and recorder 
    966966     */ 
    967     status = create_player(PJ_ARRAY_SIZE(ref_wav_paths), ref_wav_paths,  
     967    status = create_player(PJ_ARRAY_SIZE(ref_wav_paths), ref_wav_paths, 
    968968                           &player_id); 
    969969    if (status != PJ_SUCCESS) { 
     
    10181018    gui_msgbox(title, "We are now playing the captured audio from the mic. " 
    10191019                      "Check if echo (of the audio played back previously) is " 
    1020                       "present in the audio. The recording is stored in "  
     1020                      "present in the audio. The recording is stored in " 
    10211021                      AEC_REC_PATH " for offline analysis. " 
    10221022                      "Press OK to stop.", 
     
    10741074    enum gui_key key; 
    10751075    const char *title = "Audio Device List"; 
    1076      
     1076 
    10771077    ti = systest_alloc_test_item(title); 
    10781078    if (!ti) 
     
    10831083    dev_count = pjmedia_aud_dev_count(); 
    10841084    if (dev_count == 0) { 
    1085         key = gui_msgbox(title,  
     1085        key = gui_msgbox(title, 
    10861086                         "No audio devices are found", WITH_OK); 
    10871087        ti->success = PJ_FALSE; 
     
    11071107        pj_ansi_snprintf(ti->reason+len, sizeof(ti->reason)-len, 
    11081108                         " %2d: %s [%s] (%d/%d)\r\n", 
    1109                           i, info.driver, info.name,  
     1109                          i, info.driver, info.name, 
    11101110                          info.input_count, info.output_count); 
    11111111        len = strlen(ti->reason); 
     
    11141114    ti->reason[len] = '\0'; 
    11151115    key = gui_msgbox(title, ti->reason, WITH_OK); 
     1116    PJ_UNUSED_ARG(key); 
    11161117 
    11171118    ti->success = PJ_TRUE; 
     
    12051206    ti->reason[sizeof(ti->reason)-1] = '\0'; 
    12061207    key = gui_msgbox(title, textbuf, WITH_OK); 
    1207  
     1208    PJ_UNUSED_ARG(key); /* Warning about unused var */ 
    12081209} 
    12091210 
     
    12431244    systest.media_cfg.snd_rec_latency = OVERRIDE_AUDDEV_REC_LAT; 
    12441245#endif 
    1245          
     1246 
    12461247    status = pjsua_init(&systest.ua_cfg, &log_cfg, &systest.media_cfg); 
    12471248    if (status != PJ_SUCCESS) { 
  • pjproject/trunk/pjsip/src/pjsip/sip_auth_client.c

    r4537 r4728  
    11/* $Id$ */ 
    2 /*  
     2/* 
    33 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 
    44 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 
     
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1919 */ 
    2020 
     
    138138/* 
    139139 * Create response digest based on the parameters and store the 
    140  * digest ASCII in 'result'.  
     140 * digest ASCII in 'result'. 
    141141 */ 
    142142PJ_DEF(void) pjsip_auth_create_digest( pj_str_t *result, 
     
    160160 
    161161    if ((cred_info->data_type & PASSWD_MASK) == PJSIP_CRED_DATA_PLAIN_PASSWD) { 
    162         /***  
    163          *** ha1 = MD5(username ":" realm ":" password)  
     162        /*** 
     163         *** ha1 = MD5(username ":" realm ":" password) 
    164164         ***/ 
    165165        pj_md5_init(&pms); 
     
    183183 
    184184    /*** 
    185      *** ha2 = MD5(method ":" req_uri)  
     185     *** ha2 = MD5(method ":" req_uri) 
    186186     ***/ 
    187187    pj_md5_init(&pms); 
     
    196196    /*** 
    197197     *** When qop is not used: 
    198      ***    response = MD5(ha1 ":" nonce ":" ha2)  
     198     ***    response = MD5(ha1 ":" nonce ":" ha2) 
    199199     *** 
    200200     *** When qop=auth is used: 
     
    218218    /* This is the final response digest. */ 
    219219    pj_md5_final(&pms, digest); 
    220      
     220 
    221221    /* Convert digest to string and store in chal->response. */ 
    222222    result->slen = PJSIP_MD5STRLEN; 
     
    259259 
    260260/* 
    261  * Generate response digest.  
     261 * Generate response digest. 
    262262 * Most of the parameters to generate the digest (i.e. username, realm, uri, 
    263263 * and nonce) are expected to be in the credential. Additional parameters (i.e. 
     
    308308        if ((cred_info->data_type & EXT_MASK) == PJSIP_CRED_DATA_EXT_AKA) { 
    309309            /* Call application callback to create the response digest */ 
    310             return (*cred_info->ext.aka.cb)(pool, chal, cred_info,  
     310            return (*cred_info->ext.aka.cb)(pool, chal, cred_info, 
    311311                                            method, cred); 
    312         }  
     312        } 
    313313        else { 
    314314            /* Convert digest to string and store in chal->response. */ 
    315             pjsip_auth_create_digest( &cred->response, &cred->nonce, NULL,  
    316                                       NULL,  NULL, uri, &chal->realm,  
     315            pjsip_auth_create_digest( &cred->response, &cred->nonce, NULL, 
     316                                      NULL,  NULL, uri, &chal->realm, 
    317317                                      cred_info, method); 
    318318        } 
    319319 
    320320    } else if (has_auth_qop(pool, &chal->qop)) { 
    321         /* Server requires quality of protection.  
     321        /* Server requires quality of protection. 
    322322         * We respond with selecting "qop=auth" protection. 
    323323         */ 
     
    335335        if ((cred_info->data_type & EXT_MASK) == PJSIP_CRED_DATA_EXT_AKA) { 
    336336            /* Call application callback to create the response digest */ 
    337             return (*cred_info->ext.aka.cb)(pool, chal, cred_info,  
     337            return (*cred_info->ext.aka.cb)(pool, chal, cred_info, 
    338338                                            method, cred); 
    339339        } 
    340340        else { 
    341             pjsip_auth_create_digest( &cred->response, &cred->nonce,  
    342                                       &cred->nc, cnonce, &pjsip_AUTH_STR,  
     341            pjsip_auth_create_digest( &cred->response, &cred->nonce, 
     342                                      &cred->nc, cnonce, &pjsip_AUTH_STR, 
    343343                                      uri, &chal->realm, cred_info, method ); 
    344344        } 
     
    346346    } else { 
    347347        /* Server requires quality protection that we don't support. */ 
    348         PJ_LOG(4,(THIS_FILE, "Unsupported qop offer %.*s",  
     348        PJ_LOG(4,(THIS_FILE, "Unsupported qop offer %.*s", 
    349349                  chal->qop.slen, chal->qop.ptr)); 
    350350        return PJSIP_EINVALIDQOP; 
     
    358358 * Update authentication session with a challenge. 
    359359 */ 
    360 static void update_digest_session( pj_pool_t *ses_pool,  
     360static void update_digest_session( pj_pool_t *ses_pool, 
    361361                                   pjsip_cached_auth *cached_auth, 
    362362                                   const pjsip_www_authenticate_hdr *hdr ) 
     
    371371             * than the one in the cache, to reduce memory usage. 
    372372             */ 
    373             const pjsip_digest_challenge *d1 =  
     373            const pjsip_digest_challenge *d1 = 
    374374                        &cached_auth->last_chal->challenge.digest; 
    375375            const pjsip_digest_challenge *d2 = &hdr->challenge.digest; 
     
    407407        */ 
    408408        if (cached_auth->realm.slen == 0) { 
    409             pj_strdup(ses_pool, &cached_auth->realm,  
     409            pj_strdup(ses_pool, &cached_auth->realm, 
    410410                      &hdr->challenge.digest.realm); 
    411411        } 
     
    413413    } else { 
    414414        /* Update last_nonce and nonce-count */ 
    415         if (!pj_strcmp(&hdr->challenge.digest.nonce,  
    416                        &cached_auth->last_chal->challenge.digest.nonce))  
     415        if (!pj_strcmp(&hdr->challenge.digest.nonce, 
     416                       &cached_auth->last_chal->challenge.digest.nonce)) 
    417417        { 
    418418            /* Same nonce, increment nonce-count */ 
     
    424424            /* Has the opaque changed? */ 
    425425            if (pj_strcmp(&cached_auth->last_chal->challenge.digest.opaque, 
    426                           &hdr->challenge.digest.opaque))  
     426                          &hdr->challenge.digest.opaque)) 
    427427            { 
    428                 pj_strdup(ses_pool,  
     428                pj_strdup(ses_pool, 
    429429                          &cached_auth->last_chal->challenge.digest.opaque, 
    430430                          &hdr->challenge.digest.opaque); 
     
    485485PJ_DEF(pj_status_t) pjsip_auth_clt_init(  pjsip_auth_clt_sess *sess, 
    486486                                          pjsip_endpoint *endpt, 
    487                                           pj_pool_t *pool,  
     487                                          pj_pool_t *pool, 
    488488                                          unsigned options) 
    489489{ 
     
    510510 
    511511    pjsip_auth_clt_init(sess, (pjsip_endpoint*)rhs->endpt, pool, 0); 
    512      
     512 
    513513    sess->cred_cnt = rhs->cred_cnt; 
    514514    sess->cred_info = (pjsip_cred_info*) 
    515                       pj_pool_alloc(pool,  
     515                      pj_pool_alloc(pool, 
    516516                                    sess->cred_cnt*sizeof(pjsip_cred_info)); 
    517517    for (i=0; i<rhs->cred_cnt; ++i) { 
    518518        pj_strdup(pool, &sess->cred_info[i].realm, &rhs->cred_info[i].realm); 
    519519        pj_strdup(pool, &sess->cred_info[i].scheme, &rhs->cred_info[i].scheme); 
    520         pj_strdup(pool, &sess->cred_info[i].username,  
     520        pj_strdup(pool, &sess->cred_info[i].username, 
    521521                  &rhs->cred_info[i].username); 
    522522        sess->cred_info[i].data_type = rhs->cred_info[i].data_type; 
     
    553553            sess->cred_info[i].data_type = c[i].data_type; 
    554554 
    555             /* When data_type is PJSIP_CRED_DATA_EXT_AKA,  
     555            /* When data_type is PJSIP_CRED_DATA_EXT_AKA, 
    556556             * callback must be specified. 
    557557             */ 
     
    569569 
    570570                /* Verify K len */ 
    571                 PJ_ASSERT_RETURN(c[i].ext.aka.k.slen <= PJSIP_AKA_KLEN,  
     571                PJ_ASSERT_RETURN(c[i].ext.aka.k.slen <= PJSIP_AKA_KLEN, 
    572572                                 PJSIP_EAUTHINAKACRED); 
    573573 
    574574                /* Verify OP len */ 
    575                 PJ_ASSERT_RETURN(c[i].ext.aka.op.slen <= PJSIP_AKA_OPLEN,  
     575                PJ_ASSERT_RETURN(c[i].ext.aka.op.slen <= PJSIP_AKA_OPLEN, 
    576576                                 PJSIP_EAUTHINAKACRED); 
    577577 
     
    631631 
    632632 
    633 /*  
     633/* 
    634634 * Create Authorization/Proxy-Authorization response header based on the challege 
    635635 * in WWW-Authenticate/Proxy-Authenticate header. 
     
    786786    if (status != PJ_SUCCESS) 
    787787        return status; 
    788      
     788 
    789789    pjsip_msg_add_hdr( tdata->msg, (pjsip_hdr*)hauth); 
    790790 
     
    832832    /* Get the method. */ 
    833833    method = &tdata->msg->line.req.method; 
     834    PJ_UNUSED_ARG(method); /* Warning about unused var caused by #if below */ 
    834835 
    835836    auth = sess->cached_auth.next; 
     
    870871#           endif 
    871872 
    872         }  
     873        } 
    873874#       if defined(PJSIP_AUTH_QOP_SUPPORT) && \ 
    874875           defined(PJSIP_AUTH_AUTO_SEND_NEXT) && \ 
    875876           (PJSIP_AUTH_QOP_SUPPORT && PJSIP_AUTH_AUTO_SEND_NEXT) 
    876877        else if (auth->qop_value == PJSIP_AUTH_QOP_AUTH) { 
    877             /* For qop="auth", we have to re-create the authorization header.  
     878            /* For qop="auth", we have to re-create the authorization header. 
    878879             */ 
    879880            const pjsip_cred_info *cred; 
     
    881882            pj_status_t status; 
    882883 
    883             cred = auth_find_cred(sess, &auth->realm,  
     884            cred = auth_find_cred(sess, &auth->realm, 
    884885                                  &auth->last_chal->scheme); 
    885886            if (!cred) { 
     
    888889            } 
    889890 
    890             status = auth_respond( tdata->pool, auth->last_chal,  
    891                                    tdata->msg->line.req.uri,  
     891            status = auth_respond( tdata->pool, auth->last_chal, 
     892                                   tdata->msg->line.req.uri, 
    892893                                   cred, 
    893894                                   &tdata->msg->line.req.method, 
     
    895896            if (status != PJ_SUCCESS) 
    896897                return status; 
    897              
     898 
    898899            //pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)hauth); 
    899900            pj_list_push_back(&added, hauth); 
     
    984985        { 
    985986            sent_auth = (pjsip_authorization_hdr*) hdr; 
    986             if (pj_stricmp(&hchal->challenge.common.realm,  
     987            if (pj_stricmp(&hchal->challenge.common.realm, 
    987988                           &sent_auth->credential.common.realm )==0) 
    988989            { 
     
    10551056 
    10561057    /* Find credential to be used for the challenge. */ 
    1057     cred = auth_find_cred( sess, &hchal->challenge.common.realm,  
     1058    cred = auth_find_cred( sess, &hchal->challenge.common.realm, 
    10581059                           &hchal->scheme); 
    10591060    if (!cred) { 
    10601061        const pj_str_t *realm = &hchal->challenge.common.realm; 
    1061         PJ_LOG(4,(THIS_FILE,  
     1062        PJ_LOG(4,(THIS_FILE, 
    10621063                  "Unable to set auth for %s: can not find credential for %.*s/%.*s", 
    1063                   tdata->obj_name,  
     1064                  tdata->obj_name, 
    10641065                  realm->slen, realm->ptr, 
    10651066                  hchal->scheme.slen, hchal->scheme.ptr)); 
     
    10681069 
    10691070    /* Respond to authorization challenge. */ 
    1070     status = auth_respond( req_pool, hchal, uri, cred,  
    1071                            &tdata->msg->line.req.method,  
     1071    status = auth_respond( req_pool, hchal, uri, cred, 
     1072                           &tdata->msg->line.req.method, 
    10721073                           sess->pool, cached_auth, h_auth); 
    10731074    return status; 
     
    11481149         * authorization session. 
    11491150         */ 
    1150         status = process_auth( tdata->pool, hchal, tdata->msg->line.req.uri,  
     1151        status = process_auth( tdata->pool, hchal, tdata->msg->line.req.uri, 
    11511152                               tdata, sess, cached_auth, &hauth); 
    11521153        if (status != PJ_SUCCESS) 
  • pjproject/trunk/pjsip/src/pjsip/sip_dialog.c

    r4208 r4728  
    11/* $Id$ */ 
    2 /*  
     2/* 
    33 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 
    44 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 
     
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1919 */ 
    2020#include <pjsip/sip_dialog.h> 
     
    7474        return PJ_EINVALIDOP; 
    7575 
    76     pool = pjsip_endpt_create_pool(endpt, "dlg%p",  
    77                                    PJSIP_POOL_LEN_DIALOG,  
     76    pool = pjsip_endpt_create_pool(endpt, "dlg%p", 
     77                                   PJSIP_POOL_LEN_DIALOG, 
    7878                                   PJSIP_POOL_INC_DIALOG); 
    7979    if (!pool) 
     
    195195    dlg->local.info = pjsip_from_hdr_create(dlg->pool); 
    196196    pj_strdup_with_null(dlg->pool, &dlg->local.info_str, local_uri); 
    197     dlg->local.info->uri = pjsip_parse_uri(dlg->pool,  
    198                                            dlg->local.info_str.ptr,  
     197    dlg->local.info->uri = pjsip_parse_uri(dlg->pool, 
     198                                           dlg->local.info_str.ptr, 
    199199                                           dlg->local.info_str.slen, 0); 
    200200    if (!dlg->local.info->uri) { 
     
    215215 
    216216    /* Init local contact. */ 
    217     pj_strdup_with_null(dlg->pool, &tmp,  
     217    pj_strdup_with_null(dlg->pool, &tmp, 
    218218                        local_contact ? local_contact : local_uri); 
    219219    dlg->local.contact = (pjsip_contact_hdr*) 
    220                          pjsip_parse_hdr(dlg->pool, &HCONTACT, tmp.ptr,  
     220                         pjsip_parse_hdr(dlg->pool, &HCONTACT, tmp.ptr, 
    221221                                         tmp.slen, NULL); 
    222222    if (!dlg->local.contact) { 
     
    228228    dlg->remote.info = pjsip_to_hdr_create(dlg->pool); 
    229229    pj_strdup_with_null(dlg->pool, &dlg->remote.info_str, remote_uri); 
    230     dlg->remote.info->uri = pjsip_parse_uri(dlg->pool,  
    231                                             dlg->remote.info_str.ptr,  
     230    dlg->remote.info->uri = pjsip_parse_uri(dlg->pool, 
     231                                            dlg->remote.info_str.ptr, 
    232232                                            dlg->remote.info_str.slen, 0); 
    233233    if (!dlg->remote.info->uri) { 
     
    240240        PJSIP_URI_SCHEME_IS_SIPS(dlg->remote.info->uri)) 
    241241    { 
    242         pjsip_sip_uri *sip_uri = (pjsip_sip_uri *)  
     242        pjsip_sip_uri *sip_uri = (pjsip_sip_uri *) 
    243243                                 pjsip_uri_get_uri(dlg->remote.info->uri); 
    244244        if (!pj_list_empty(&sip_uri->header_param)) { 
     
    249249 
    250250            /* Print URI */ 
    251             tmp.ptr = (char*) pj_pool_alloc(dlg->pool,  
     251            tmp.ptr = (char*) pj_pool_alloc(dlg->pool, 
    252252                                            dlg->remote.info_str.slen); 
    253253            tmp.slen = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, 
    254                                        sip_uri, tmp.ptr,  
     254                                       sip_uri, tmp.ptr, 
    255255                                       dlg->remote.info_str.slen); 
    256256 
     
    283283 
    284284    /* Init client authentication session. */ 
    285     status = pjsip_auth_clt_init(&dlg->auth_sess, dlg->endpt,  
     285    status = pjsip_auth_clt_init(&dlg->auth_sess, dlg->endpt, 
    286286                                 dlg->pool, 0); 
    287287    if (status != PJ_SUCCESS) 
     
    333333                     PJSIP_ENOTREQUESTMSG); 
    334334 
    335     /* Request must not have To tag.  
     335    /* Request must not have To tag. 
    336336     * This should have been checked in the user agent (or application?). 
    337337     */ 
    338338    PJ_ASSERT_RETURN(rdata->msg_info.to->tag.slen == 0, PJ_EINVALIDOP); 
    339                       
     339 
    340340    /* The request must be a dialog establishing request. */ 
    341341    PJ_ASSERT_RETURN( 
     
    385385    /* TODO: 
    386386     *  Section 12.1.1, paragraph about using SIPS URI in Contact. 
    387      *  If the request that initiated the dialog contained a SIPS URI  
    388      *  in the Request-URI or in the top Record-Route header field value,  
    389      *  if there was any, or the Contact header field if there was no  
     387     *  If the request that initiated the dialog contained a SIPS URI 
     388     *  in the Request-URI or in the top Record-Route header field value, 
     389     *  if there was any, or the Contact header field if there was no 
    390390     *  Record-Route header field, the Contact header field in the response 
    391391     *  MUST be a SIPS URI. 
     
    396396        pj_strdup_with_null(dlg->pool, &tmp, contact); 
    397397        dlg->local.contact = (pjsip_contact_hdr*) 
    398                              pjsip_parse_hdr(dlg->pool, &HCONTACT, tmp.ptr,  
     398                             pjsip_parse_hdr(dlg->pool, &HCONTACT, tmp.ptr, 
    399399                                             tmp.slen, NULL); 
    400400        if (!dlg->local.contact) { 
     
    409409 
    410410    /* Init remote info from the From header. */ 
    411     dlg->remote.info = (pjsip_fromto_hdr*)  
     411    dlg->remote.info = (pjsip_fromto_hdr*) 
    412412                       pjsip_hdr_clone(dlg->pool, rdata->msg_info.from); 
    413413    pjsip_fromto_hdr_set_to(dlg->remote.info); 
     
    426426 
    427427 
    428     /* Init remote's contact from Contact header.  
     428    /* Init remote's contact from Contact header. 
    429429     * Iterate the Contact URI until we find sip: or sips: scheme. 
    430430     */ 
     
    452452    } 
    453453 
    454     dlg->remote.contact = (pjsip_contact_hdr*)  
     454    dlg->remote.contact = (pjsip_contact_hdr*) 
    455455                          pjsip_hdr_clone(dlg->pool, (pjsip_hdr*)contact_hdr); 
    456456 
     
    464464    dlg->role = PJSIP_ROLE_UAS; 
    465465 
    466     /* Secure?  
     466    /* Secure? 
    467467     *  RFC 3261 Section 12.1.1: 
    468      *  If the request arrived over TLS, and the Request-URI contained a  
     468     *  If the request arrived over TLS, and the Request-URI contained a 
    469469     *  SIPS URI, the 'secure' flag is set to TRUE. 
    470470     */ 
     
    473473 
    474474    /* Call-ID */ 
    475     dlg->call_id = (pjsip_cid_hdr*)  
     475    dlg->call_id = (pjsip_cid_hdr*) 
    476476                   pjsip_hdr_clone(dlg->pool, rdata->msg_info.cid); 
    477477 
    478     /* Route set.  
     478    /* Route set. 
    479479     *  RFC 3261 Section 12.1.1: 
    480      *  The route set MUST be set to the list of URIs in the Record-Route  
    481      *  header field from the request, taken in order and preserving all URI  
     480     *  The route set MUST be set to the list of URIs in the Record-Route 
     481     *  header field from the request, taken in order and preserving all URI 
    482482     *  parameters. If no Record-Route header field is present in the request, 
    483483     * the route set MUST be set to the empty set. 
     
    499499        if (rr == (void*)&rdata->msg_info.msg->hdr) 
    500500            break; 
    501         rr = (pjsip_route_hdr*) pjsip_msg_find_hdr(rdata->msg_info.msg,  
     501        rr = (pjsip_route_hdr*) pjsip_msg_find_hdr(rdata->msg_info.msg, 
    502502                                                   PJSIP_H_RECORD_ROUTE, rr); 
    503503    } 
     
    621621    /* Check arguments. */ 
    622622    PJ_ASSERT_RETURN(first_dlg && rdata && new_dlg, PJ_EINVAL); 
    623      
     623 
    624624    /* rdata must be response message. */ 
    625625    PJ_ASSERT_RETURN(msg->type == PJSIP_RESPONSE_MSG, 
     
    649649 
    650650    /* Clone local info. */ 
    651     dlg->local.info = (pjsip_fromto_hdr*)  
     651    dlg->local.info = (pjsip_fromto_hdr*) 
    652652                      pjsip_hdr_clone(dlg->pool, first_dlg->local.info); 
    653653 
     
    661661 
    662662    /* Clone local Contact. */ 
    663     dlg->local.contact = (pjsip_contact_hdr*)  
     663    dlg->local.contact = (pjsip_contact_hdr*) 
    664664                         pjsip_hdr_clone(dlg->pool, first_dlg->local.contact); 
    665665 
    666666    /* Clone remote info. */ 
    667     dlg->remote.info = (pjsip_fromto_hdr*)  
     667    dlg->remote.info = (pjsip_fromto_hdr*) 
    668668                       pjsip_hdr_clone(dlg->pool, first_dlg->remote.info); 
    669669 
     
    690690 
    691691    /* Clone Call-ID header. */ 
    692     dlg->call_id = (pjsip_cid_hdr*)  
     692    dlg->call_id = (pjsip_cid_hdr*) 
    693693                   pjsip_hdr_clone(dlg->pool, first_dlg->call_id); 
    694694 
     
    708708 
    709709    /* Clone client authentication session. */ 
    710     status = pjsip_auth_clt_clone(dlg->pool, &dlg->auth_sess,  
     710    status = pjsip_auth_clt_clone(dlg->pool, &dlg->auth_sess, 
    711711                                  &first_dlg->auth_sess); 
    712712    if (status != PJ_SUCCESS) 
     
    842842PJ_DEF(void) pjsip_dlg_inc_lock(pjsip_dialog *dlg) 
    843843{ 
    844     PJ_LOG(6,(dlg->obj_name, "Entering pjsip_dlg_inc_lock(), sess_count=%d",  
     844    PJ_LOG(6,(dlg->obj_name, "Entering pjsip_dlg_inc_lock(), sess_count=%d", 
    845845              dlg->sess_count)); 
    846846 
     
    848848    dlg->sess_count++; 
    849849 
    850     PJ_LOG(6,(dlg->obj_name, "Leaving pjsip_dlg_inc_lock(), sess_count=%d",  
     850    PJ_LOG(6,(dlg->obj_name, "Leaving pjsip_dlg_inc_lock(), sess_count=%d", 
    851851              dlg->sess_count)); 
    852852} 
     
    859859    pj_status_t status; 
    860860 
    861     PJ_LOG(6,(dlg->obj_name,"Entering pjsip_dlg_try_inc_lock(), sess_count=%d",  
     861    PJ_LOG(6,(dlg->obj_name,"Entering pjsip_dlg_try_inc_lock(), sess_count=%d", 
    862862              dlg->sess_count)); 
    863863 
     
    870870    dlg->sess_count++; 
    871871 
    872     PJ_LOG(6,(dlg->obj_name, "Leaving pjsip_dlg_try_inc_lock(), sess_count=%d",  
     872    PJ_LOG(6,(dlg->obj_name, "Leaving pjsip_dlg_try_inc_lock(), sess_count=%d", 
    873873              dlg->sess_count)); 
    874874 
     
    885885    PJ_ASSERT_ON_FAIL(dlg!=NULL, return); 
    886886 
    887     PJ_LOG(6,(dlg->obj_name, "Entering pjsip_dlg_dec_lock(), sess_count=%d",  
     887    PJ_LOG(6,(dlg->obj_name, "Entering pjsip_dlg_dec_lock(), sess_count=%d", 
    888888              dlg->sess_count)); 
    889889 
     
    960960    PJ_ASSERT_RETURN(dlg->usage_cnt < PJSIP_MAX_MODULE, PJ_EBUG); 
    961961 
    962     PJ_LOG(5,(dlg->obj_name,  
     962    PJ_LOG(5,(dlg->obj_name, 
    963963              "Module %.*s added as dialog usage, data=%p", 
    964964              (int)mod->name.slen, mod->name.ptr, mod_data)); 
     
    977977             * So return PJ_SUCCESS here. 
    978978             */ 
    979             PJ_LOG(4,(dlg->obj_name,  
     979            PJ_LOG(4,(dlg->obj_name, 
    980980                      "Module %.*s already registered as dialog usage, " 
    981981                      "updating the data %p", 
     
    10001000    pj_array_insert(dlg->usage, sizeof(dlg->usage[0]), dlg->usage_cnt, 
    10011001                    index, &mod); 
    1002      
     1002 
    10031003    /* Set module data. */ 
    10041004    dlg->mod_data[mod->id] = mod_data; 
     
    10141014 
    10151015/* 
    1016  * Attach module specific data to the dialog. Application can also set  
     1016 * Attach module specific data to the dialog. Application can also set 
    10171017 * the value directly by accessing dlg->mod_data[module_id]. 
    10181018 */ 
     
    10441044/* 
    10451045 * Create a new request within dialog (i.e. after the dialog session has been 
    1046  * established). The construction of such requests follows the rule in  
     1046 * established). The construction of such requests follows the rule in 
    10471047 * RFC3261 section 12.2.1. 
    10481048 */ 
     
    10581058 
    10591059    /* Contact Header field. 
    1060      * Contact can only be present in requests that establish dialog (in the  
     1060     * Contact can only be present in requests that establish dialog (in the 
    10611061     * core SIP spec, only INVITE). 
    10621062     */ 
     
    10831083        return status; 
    10841084 
    1085     /* Just copy dialog route-set to Route header.  
     1085    /* Just copy dialog route-set to Route header. 
    10861086     * The transaction will do the processing as specified in Section 12.2.1 
    10871087     * of RFC 3261 in function tsx_process_route() in sip_transaction.c. 
     
    11931193     */ 
    11941194    if (msg->line.req.method.id != PJSIP_CANCEL_METHOD && 
    1195         msg->line.req.method.id != PJSIP_ACK_METHOD)  
     1195        msg->line.req.method.id != PJSIP_ACK_METHOD) 
    11961196    { 
    11971197        pjsip_cseq_hdr *ch; 
    1198          
     1198 
    11991199        ch = PJSIP_MSG_CSEQ_HDR(msg); 
    12001200        PJ_ASSERT_RETURN(ch!=NULL, PJ_EBUG); 
     
    12451245 
    12461246        /* Send request */ 
    1247         status = pjsip_endpt_send_request_stateless(dlg->endpt, tdata,  
     1247        status = pjsip_endpt_send_request_stateless(dlg->endpt, tdata, 
    12481248                                                    NULL, NULL); 
    12491249        if (status != PJ_SUCCESS) 
     
    12601260    /* Unlock dialog, may destroy dialog. */ 
    12611261    pjsip_dlg_dec_lock(dlg); 
    1262     
     1262 
    12631263    /* Whatever happen delete the message. */ 
    12641264    pjsip_tx_data_dec_ref( tdata ); 
     
    12871287        /* Add Contact header for 1xx, 2xx, 3xx and 485 response. */ 
    12881288        if (st_class==2 || st_class==3 || (st_class==1 && st_code != 100) || 
    1289             st_code==485)  
     1289            st_code==485) 
    12901290        { 
    12911291            /* Add contact header only if one is not present. */ 
    12921292            if (pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL) == 0 && 
    1293                 pjsip_msg_find_hdr_by_name(tdata->msg, &HCONTACT, NULL) == 0)  
     1293                pjsip_msg_find_hdr_by_name(tdata->msg, &HCONTACT, NULL) == 0) 
    12941294            { 
    1295                 hdr = (pjsip_hdr*) pjsip_hdr_clone(tdata->pool,  
     1295                hdr = (pjsip_hdr*) pjsip_hdr_clone(tdata->pool, 
    12961296                                                   dlg->local.contact); 
    12971297                pjsip_msg_add_hdr(tdata->msg, hdr); 
     
    13021302        if ((((st_code/10==18 || st_class==2) && dlg->add_allow) 
    13031303             || st_code==405) && 
    1304             pjsip_msg_find_hdr(tdata->msg, PJSIP_H_ALLOW, NULL)==NULL)  
     1304            pjsip_msg_find_hdr(tdata->msg, PJSIP_H_ALLOW, NULL)==NULL) 
    13051305        { 
    13061306            c_hdr = pjsip_endpt_get_capability(dlg->endpt, 
     
    13131313 
    13141314        /* Add Supported header in 2xx response. */ 
    1315         if (st_class==2 &&  
    1316             pjsip_msg_find_hdr(tdata->msg, PJSIP_H_SUPPORTED, NULL)==NULL)  
     1315        if (st_class==2 && 
     1316            pjsip_msg_find_hdr(tdata->msg, PJSIP_H_SUPPORTED, NULL)==NULL) 
    13171317        { 
    13181318            c_hdr = pjsip_endpt_get_capability(dlg->endpt, 
     
    14011401    } 
    14021402 
    1403     /* Remove existing Contact header (without this, when dialog sent  
     1403    /* Remove existing Contact header (without this, when dialog sent 
    14041404     * 180 and then 302, the Contact in 302 will not get updated). 
    14051405     */ 
     
    14461446              pjsip_tx_data_get_info(tdata))); 
    14471447 
    1448     /* Check that transaction method and cseq match the response.  
     1448    /* Check that transaction method and cseq match the response. 
    14491449     * This operation is sloooww (search CSeq header twice), that's why 
    14501450     * we only do it in debug mode. 
     
    14521452#if defined(PJ_DEBUG) && PJ_DEBUG!=0 
    14531453    PJ_ASSERT_RETURN( PJSIP_MSG_CSEQ_HDR(tdata->msg)->cseq == tsx->cseq && 
    1454                       pjsip_method_cmp(&PJSIP_MSG_CSEQ_HDR(tdata->msg)->method,  
     1454                      pjsip_method_cmp(&PJSIP_MSG_CSEQ_HDR(tdata->msg)->method, 
    14551455                                       &tsx->method)==0, 
    14561456                      PJ_EINVALIDOP); 
     
    14781478    status = pjsip_tsx_send_msg(tsx, tdata); 
    14791479 
    1480     /* This function must decrement transmit data request counter  
     1480    /* This function must decrement transmit data request counter 
    14811481     * regardless of the operation status. The transaction only 
    14821482     * decrements the counter if the operation is successful. 
     
    15631563    if (rdata->msg_info.cseq->cseq <= dlg->remote.cseq && 
    15641564        rdata->msg_info.msg->line.req.method.id != PJSIP_ACK_METHOD && 
    1565         rdata->msg_info.msg->line.req.method.id != PJSIP_CANCEL_METHOD)  
     1565        rdata->msg_info.msg->line.req.method.id != PJSIP_CANCEL_METHOD) 
    15661566    { 
    15671567        /* Invalid CSeq. 
     
    15951595 
    15961596    /* Create UAS transaction for this request. */ 
    1597     if (pjsip_rdata_get_tsx(rdata) == NULL &&  
    1598         rdata->msg_info.msg->line.req.method.id != PJSIP_ACK_METHOD)  
     1597    if (pjsip_rdata_get_tsx(rdata) == NULL && 
     1598        rdata->msg_info.msg->line.req.method.id != PJSIP_ACK_METHOD) 
    15991599    { 
    16001600        status = pjsip_tsx_create_uas(dlg->ua, rdata, &tsx); 
     
    16301630 
    16311631        contact = (pjsip_contact_hdr*) 
    1632                   pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT,  
     1632                  pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, 
    16331633                                     NULL); 
    16341634        if (contact && contact->uri && 
     
    16381638                           contact->uri))) 
    16391639        { 
    1640             dlg->remote.contact = (pjsip_contact_hdr*)  
     1640            dlg->remote.contact = (pjsip_contact_hdr*) 
    16411641                                  pjsip_hdr_clone(dlg->pool, contact); 
    16421642            dlg->target = dlg->remote.contact->uri; 
     
    16881688{ 
    16891689    const pjsip_hdr *hdr, *end_hdr; 
    1690     pj_int32_t msg_cseq; 
     1690    //pj_int32_t msg_cseq; 
    16911691    const pjsip_msg *msg; 
    16921692 
    16931693    msg = rdata->msg_info.msg; 
    1694     msg_cseq = rdata->msg_info.cseq->cseq; 
     1694    //msg_cseq = rdata->msg_info.cseq->cseq; 
    16951695 
    16961696    /* Ignore if route set has been frozen */ 
     
    17081708 
    17091709        /* Ignore subsequent responses with higher CSeq than initial CSeq. 
    1710          * Unfortunately this would be broken when the first request is  
     1710         * Unfortunately this would be broken when the first request is 
    17111711         * challenged! 
    17121712         */ 
     
    17471747    PJ_LOG(5,(dlg->obj_name, "Route-set updated")); 
    17481748 
    1749     /* Freeze the route set only when the route set comes in 2xx response.  
    1750      * If it is in 1xx response, prepare to recompute the route set when  
     1749    /* Freeze the route set only when the route set comes in 2xx response. 
     1750     * If it is in 1xx response, prepare to recompute the route set when 
    17511751     * the 2xx response comes in. 
    17521752     * 
     
    17561756     * upon receiving 2xx response). Also RFC 3261 says so in 13.2.2.4. 
    17571757     * 
    1758      * The pjsip_method_creates_dialog() check protects from wrongly  
     1758     * The pjsip_method_creates_dialog() check protects from wrongly 
    17591759     * freezing the route set upon receiving 200/OK response for PRACK. 
    17601760     */ 
    17611761    if (pjsip_method_creates_dialog(&rdata->msg_info.cseq->method) && 
    1762         PJSIP_IS_STATUS_IN_CLASS(msg->line.status.code, 200))  
     1762        PJSIP_IS_STATUS_IN_CLASS(msg->line.status.code, 200)) 
    17631763    { 
    17641764        dlg->route_set_frozen = PJ_TRUE; 
     
    17891789    res_code = rdata->msg_info.msg->line.status.code; 
    17901790 
    1791     /* When we receive response that establishes dialog, update To tag,  
     1791    /* When we receive response that establishes dialog, update To tag, 
    17921792     * route set and dialog target. 
    17931793     * 
     
    18031803     * New update: 
    18041804     * We also need to update the dialog for 1xx responses, to handle the 
    1805      * case when 100rel is used, otherwise PRACK will be sent to the  
     1805     * case when 100rel is used, otherwise PRACK will be sent to the 
    18061806     * wrong target. 
    18071807     */ 
    1808     if ((dlg->state == PJSIP_DIALOG_STATE_NULL &&  
     1808    if ((dlg->state == PJSIP_DIALOG_STATE_NULL && 
    18091809         pjsip_method_creates_dialog(&rdata->msg_info.cseq->method) && 
    18101810         (res_code > 100 && res_code < 300) && 
    1811          rdata->msg_info.to->tag.slen)  
     1811         rdata->msg_info.to->tag.slen) 
    18121812         || 
    18131813        (dlg->role==PJSIP_ROLE_UAC && 
     
    18201820        pjsip_contact_hdr *contact; 
    18211821 
    1822         /* Update remote capability info, when To tags in the dialog remote  
     1822        /* Update remote capability info, when To tags in the dialog remote 
    18231823         * info and the incoming response are different, e.g: first response 
    18241824         * with To-tag or forking, apply strict update. 
     
    18341834        /* RFC 3271 Section 12.1.2: 
    18351835         * The route set MUST be set to the list of URIs in the Record-Route 
    1836          * header field from the response, taken in reverse order and  
    1837          * preserving all URI parameters. If no Record-Route header field  
    1838          * is present in the response, the route set MUST be set to the  
     1836         * header field from the response, taken in reverse order and 
     1837         * preserving all URI parameters. If no Record-Route header field 
     1838         * is present in the response, the route set MUST be set to the 
    18391839         * empty set. This route set, even if empty, overrides any pre-existing 
    18401840         * route set for future requests in this dialog. 
     
    18421842        dlg_update_routeset(dlg, rdata); 
    18431843 
    1844         /* The remote target MUST be set to the URI from the Contact header  
     1844        /* The remote target MUST be set to the URI from the Contact header 
    18451845         * field of the response. 
    18461846         */ 
    18471847        contact = (pjsip_contact_hdr*) 
    1848                   pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT,  
     1848                  pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, 
    18491849                                     NULL); 
    18501850        if (contact && contact->uri && 
     
    18541854                           contact->uri))) 
    18551855        { 
    1856             dlg->remote.contact = (pjsip_contact_hdr*)  
     1856            dlg->remote.contact = (pjsip_contact_hdr*) 
    18571857                                  pjsip_hdr_clone(dlg->pool, contact); 
    18581858            dlg->target = dlg->remote.contact->uri; 
     
    18641864         * gets through this dialog (it shouldn't happen). 
    18651865         */ 
    1866         if (dlg->role==PJSIP_ROLE_UAC && !dlg->uac_has_2xx &&  
    1867             res_code/100==2)  
     1866        if (dlg->role==PJSIP_ROLE_UAC && !dlg->uac_has_2xx && 
     1867            res_code/100==2) 
    18681868        { 
    18691869            dlg->uac_has_2xx = PJ_TRUE; 
     
    18721872 
    18731873    /* Update remote target (again) when receiving 2xx response messages 
    1874      * that's defined as target refresh.  
     1874     * that's defined as target refresh. 
    18751875     * 
    18761876     * Also upon receiving 2xx response, recheck again the route set. 
     
    18821882        the "confirmed" state, and the route set for the dialog MUST be 
    18831883        recomputed based on the 2xx response using the procedures of Section 
    1884         12.2.1.2.  
     1884        12.2.1.2. 
    18851885 
    18861886        Note that the only piece of state that is recomputed is the route 
     
    18971897 
    18981898        contact = (pjsip_contact_hdr*) pjsip_msg_find_hdr(rdata->msg_info.msg, 
    1899                                                           PJSIP_H_CONTACT,  
     1899                                                          PJSIP_H_CONTACT, 
    19001900                                                          NULL); 
    19011901        if (contact && contact->uri && 
     
    19051905                           contact->uri))) 
    19061906        { 
    1907             dlg->remote.contact = (pjsip_contact_hdr*)  
     1907            dlg->remote.contact = (pjsip_contact_hdr*) 
    19081908                                  pjsip_hdr_clone(dlg->pool, contact); 
    19091909            dlg->target = dlg->remote.contact->uri; 
     
    19431943        pj_status_t status; 
    19441944 
    1945         if (rdata->msg_info.cseq->method.id==PJSIP_INVITE_METHOD &&  
    1946             rdata->msg_info.msg->line.status.code/100 == 2)  
     1945        if (rdata->msg_info.cseq->method.id==PJSIP_INVITE_METHOD && 
     1946            rdata->msg_info.msg->line.status.code/100 == 2) 
    19471947        { 
    19481948            pjsip_tx_data *ack; 
     
    19581958            pjsip_transaction *tsx = pjsip_rdata_get_tsx(rdata); 
    19591959            pjsip_tx_data *tdata; 
    1960              
    1961             status = pjsip_auth_clt_reinit_req( &dlg->auth_sess,  
     1960 
     1961            status = pjsip_auth_clt_reinit_req( &dlg->auth_sess, 
    19621962                                                rdata, tsx->last_tx, 
    19631963                                                &tdata); 
    1964              
     1964 
    19651965            if (status == PJ_SUCCESS) { 
    19661966                /* Re-send request. */ 
     
    20152015     */ 
    20162016    if (tsx->state == PJSIP_TSX_STATE_TERMINATED && 
    2017         tsx->mod_data[dlg->ua->id] == dlg)  
     2017        tsx->mod_data[dlg->ua->id] == dlg) 
    20182018    { 
    20192019        pj_assert(dlg->tsx_count>0); 
     
    20452045    pjsip_dlg_inc_lock(dlg); 
    20462046 
    2047     hdr = (const pjsip_generic_array_hdr*)  
     2047    hdr = (const pjsip_generic_array_hdr*) 
    20482048           pjsip_dlg_get_remote_cap_hdr(dlg, htype, hname); 
    20492049    if (!hdr) { 
     
    20722072                                                pj_bool_t strict) 
    20732073{ 
    2074     pjsip_hdr_e htypes[] =  
     2074    pjsip_hdr_e htypes[] = 
    20752075        { PJSIP_H_ACCEPT, PJSIP_H_ALLOW, PJSIP_H_SUPPORTED }; 
    20762076    unsigned i; 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c

    r4724 r4728  
    11/* $Id$ */ 
    2 /*  
     2/* 
    33 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 
    44 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 
     
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1919 */ 
    2020#include <pjsua-lib/pjsua.h> 
     
    3939 * The INFO method. 
    4040 */ 
    41 const pjsip_method pjsip_info_method =  
     41const pjsip_method pjsip_info_method = 
    4242{ 
    4343    PJSIP_OTHER_METHOD, 
     
    4949 * session state has changed. 
    5050 */ 
    51 static void pjsua_call_on_state_changed(pjsip_inv_session *inv,  
     51static void pjsua_call_on_state_changed(pjsip_inv_session *inv, 
    5252                                        pjsip_event *e); 
    5353 
     
    5555 * has forked. 
    5656 */ 
    57 static void pjsua_call_on_forked( pjsip_inv_session *inv,  
     57static void pjsua_call_on_forked( pjsip_inv_session *inv, 
    5858                                  pjsip_event *e); 
    5959 
     
    164164    /* Check the route URI's and force loose route if required */ 
    165165    for (i=0; i<pjsua_var.ua_cfg.outbound_proxy_cnt; ++i) { 
    166         status = normalize_route_uri(pjsua_var.pool,  
     166        status = normalize_route_uri(pjsua_var.pool, 
    167167                                     &pjsua_var.ua_cfg.outbound_proxy[i]); 
    168168        if (status != PJ_SUCCESS) 
     
    258258#if 1 
    259259    /* New algorithm: round-robin */ 
    260     if (pjsua_var.next_call_id >= (int)pjsua_var.ua_cfg.max_calls ||  
     260    if (pjsua_var.next_call_id >= (int)pjsua_var.ua_cfg.max_calls || 
    261261        pjsua_var.next_call_id < 0) 
    262262    { 
     
    264264    } 
    265265 
    266     for (cid=pjsua_var.next_call_id;  
    267          cid<(int)pjsua_var.ua_cfg.max_calls;  
    268          ++cid)  
     266    for (cid=pjsua_var.next_call_id; 
     267         cid<(int)pjsua_var.ua_cfg.max_calls; 
     268         ++cid) 
    269269    { 
    270270        if (pjsua_var.calls[cid].inv == NULL && 
     
    310310    if (pj_stristr(dst_uri, &sips)) 
    311311        return 2; 
    312      
     312 
    313313    if (!pj_list_empty(&acc->route_set)) { 
    314314        pjsip_route_hdr *r = acc->route_set.next; 
    315315        pjsip_uri *uri = r->name_addr.uri; 
    316316        pjsip_sip_uri *sip_uri; 
    317          
     317 
    318318        sip_uri = (pjsip_sip_uri*)pjsip_uri_get_uri(uri); 
    319319        if (pj_stricmp2(&sip_uri->transport_param, "tls")==0) 
     
    338338        pjsip_uri *uri = r->name_addr.uri; 
    339339        pjsip_sip_uri *sip_uri; 
    340          
     340 
    341341        sip_uri = (pjsip_sip_uri*)pjsip_uri_get_uri(uri); 
    342342        if (pj_stricmp2(&sip_uri->transport_param, "tls")==0) 
     
    468468    /* Set credentials: */ 
    469469    if (acc->cred_cnt) { 
    470         pjsip_auth_clt_set_credentials( &dlg->auth_sess,  
     470        pjsip_auth_clt_set_credentials( &dlg->auth_sess, 
    471471                                        acc->cred_cnt, acc->cred); 
    472472    } 
     
    479479    status = pjsip_inv_invite(inv, &tdata); 
    480480    if (status != PJ_SUCCESS) { 
    481         pjsua_perror(THIS_FILE, "Unable to create initial INVITE request",  
     481        pjsua_perror(THIS_FILE, "Unable to create initial INVITE request", 
    482482                     status); 
    483483        goto on_error; 
     
    499499        cb_called = PJ_TRUE; 
    500500 
    501         /* Upon failure to send first request, the invite  
     501        /* Upon failure to send first request, the invite 
    502502         * session would have been cleared. 
    503503         */ 
     
    617617 
    618618    /* Check that account is valid */ 
    619     PJ_ASSERT_RETURN(acc_id>=0 || acc_id<(int)PJ_ARRAY_SIZE(pjsua_var.acc),  
     619    PJ_ASSERT_RETURN(acc_id>=0 || acc_id<(int)PJ_ARRAY_SIZE(pjsua_var.acc), 
    620620                     PJ_EINVAL); 
    621621 
     
    631631 
    632632    /* Create sound port if none is instantiated, to check if sound device 
    633      * can be used. But only do this with the conference bridge, as with  
    634      * audio switchboard (i.e. APS-Direct), we can only open the sound  
     633     * can be used. But only do this with the conference bridge, as with 
     634     * audio switchboard (i.e. APS-Direct), we can only open the sound 
    635635     * device once the correct format has been known 
    636636     */ 
    637     if (!pjsua_var.is_mswitch && pjsua_var.snd_port==NULL &&  
    638         pjsua_var.null_snd==NULL && !pjsua_var.no_snd)  
     637    if (!pjsua_var.is_mswitch && pjsua_var.snd_port==NULL && 
     638        pjsua_var.null_snd==NULL && !pjsua_var.no_snd) 
    639639    { 
    640640        status = pjsua_set_snd_dev(pjsua_var.cap_dev, pjsua_var.play_dev); 
     
    679679    tmp_pool = pjsua_pool_create("tmpcall10", 512, 256); 
    680680 
    681     /* Verify that destination URI is valid before calling  
    682      * pjsua_acc_create_uac_contact, or otherwise there   
     681    /* Verify that destination URI is valid before calling 
     682     * pjsua_acc_create_uac_contact, or otherwise there 
    683683     * a misleading "Invalid Contact URI" error will be printed 
    684684     * when pjsua_acc_create_uac_contact() fails. 
     
    692692 
    693693        if (uri == NULL) { 
    694             pjsua_perror(THIS_FILE, "Unable to make call",  
     694            pjsua_perror(THIS_FILE, "Unable to make call", 
    695695                         PJSIP_EINVALIDREQURI); 
    696696            status = PJSIP_EINVALIDREQURI; 
     
    714714                                              acc_id, dest_uri); 
    715715        if (status != PJ_SUCCESS) { 
    716             pjsua_perror(THIS_FILE, "Unable to generate Contact header",  
     716            pjsua_perror(THIS_FILE, "Unable to generate Contact header", 
    717717                         status); 
    718718            goto on_error; 
     
    721721 
    722722    /* Create outgoing dialog: */ 
    723     status = pjsip_dlg_create_uac( pjsip_ua_instance(),  
     723    status = pjsip_dlg_create_uac( pjsip_ua_instance(), 
    724724                                   &acc->cfg.id, &contact, 
    725725                                   dest_uri, 
     
    745745    /* Attach user data */ 
    746746    call->user_data = user_data; 
    747      
     747 
    748748    /* Store variables required for the callback after the async 
    749749     * media transport creation is completed. 
     
    762762 
    763763    /* Init media channel */ 
    764     status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC,  
     764    status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC, 
    765765                                      call->secure_level, dlg->pool, 
    766766                                      NULL, NULL, PJ_TRUE, 
     
    813813 
    814814/* Get the NAT type information in remote's SDP */ 
    815 static void update_remote_nat_type(pjsua_call *call,  
     815static void update_remote_nat_type(pjsua_call *call, 
    816816                                   const pjmedia_sdp_session *sdp) 
    817817{ 
     
    900900{ 
    901901    struct call_answer *answer, *next; 
    902      
     902 
    903903    answer = call->async_call.call_var.inc_call.answers.next; 
    904904    while (answer != &call->async_call.call_var.inc_call.answers) { 
     
    906906        pjsua_call_answer2(call->index, answer->opt, answer->code, 
    907907                           answer->reason, answer->msg_data); 
    908          
     908 
    909909        /* Call might have been disconnected if application is answering 
    910910         * with 200/OK and the media failed to start. 
     
    953953 
    954954    status = pjsua_media_channel_create_sdp(call_id, 
    955                                             call->async_call.dlg->pool,  
     955                                            call->async_call.dlg->pool, 
    956956                                            offer, &answer, &sip_err_code); 
    957957    if (status != PJ_SUCCESS) { 
     
    977977        sip_err_code = PJSIP_ERRNO_TO_SIP_STATUS(status); 
    978978        goto on_return; 
    979     }  
     979    } 
    980980 
    981981on_return: 
     
    10071007        if (call->async_call.call_var.inc_call.replaced_dlg) { 
    10081008            /* Process pending call replace */ 
    1009             pjsip_dialog *replaced_dlg =  
     1009            pjsip_dialog *replaced_dlg = 
    10101010                        call->async_call.call_var.inc_call.replaced_dlg; 
    10111011            process_incoming_call_replace(call, replaced_dlg); 
     
    10541054    /* Don't want to accept the call if shutdown is in progress */ 
    10551055    if (pjsua_var.thread_quit_flag) { 
    1056         pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata,  
     1056        pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 
    10571057                                      PJSIP_SC_TEMPORARILY_UNAVAILABLE, NULL, 
    10581058                                      NULL, NULL); 
     
    10691069 
    10701070    if (call_id == PJSUA_INVALID_ID) { 
    1071         pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata,  
     1071        pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 
    10721072                                      PJSIP_SC_BUSY_HERE, NULL, 
    10731073                                      NULL, NULL); 
    1074         PJ_LOG(2,(THIS_FILE,  
     1074        PJ_LOG(2,(THIS_FILE, 
    10751075                  "Unable to accept incoming call (too many calls)")); 
    10761076        goto on_return; 
     
    10981098 
    10991099            pjsip_get_response_addr(response->pool, rdata, &res_addr); 
    1100             pjsip_endpt_send_response(pjsua_var.endpt, &res_addr, response,  
     1100            pjsip_endpt_send_response(pjsua_var.endpt, &res_addr, response, 
    11011101                                      NULL, NULL); 
    11021102 
     
    11521152                st_text = *pjsip_get_status_text(st_code); 
    11531153 
    1154             pjsip_endpt_respond(pjsua_var.endpt, NULL, rdata,  
     1154            pjsip_endpt_respond(pjsua_var.endpt, NULL, rdata, 
    11551155                                st_code, &st_text, NULL, NULL, NULL); 
    11561156            goto on_return; 
     
    11581158    } 
    11591159 
    1160     /*  
     1160    /* 
    11611161     * Get which account is most likely to be associated with this incoming 
    11621162     * call. We need the account to find which contact URI to put for 
     
    11901190            pjsip_warning_hdr *w; 
    11911191 
    1192             pjsua_perror(THIS_FILE, "Bad SDP in incoming INVITE",  
     1192            pjsua_perror(THIS_FILE, "Bad SDP in incoming INVITE", 
    11931193                         status); 
    11941194 
    1195             w = pjsip_warning_hdr_create_from_status(rdata->tp_info.pool,  
     1195            w = pjsip_warning_hdr_create_from_status(rdata->tp_info.pool, 
    11961196                                             pjsip_endpt_name(pjsua_var.endpt), 
    11971197                                             status); 
     
    11991199            pj_list_push_back(&hdr_list, w); 
    12001200 
    1201             pjsip_endpt_respond(pjsua_var.endpt, NULL, rdata, 400,  
     1201            pjsip_endpt_respond(pjsua_var.endpt, NULL, rdata, 400, 
    12021202                                &reason, &hdr_list, NULL, NULL); 
    12031203            goto on_return; 
    12041204        } 
    12051205 
    1206         /* Do quick checks on SDP before passing it to transports. More elabore  
     1206        /* Do quick checks on SDP before passing it to transports. More elabore 
    12071207         * checks will be done in pjsip_inv_verify_request2() below. 
    12081208         */ 
    12091209        if (offer->media_count==0) { 
    12101210            const pj_str_t reason = pj_str("Missing media in SDP"); 
    1211             pjsip_endpt_respond(pjsua_var.endpt, NULL, rdata, 400, &reason,  
     1211            pjsip_endpt_respond(pjsua_var.endpt, NULL, rdata, 400, &reason, 
    12121212                                NULL, NULL, NULL); 
    12131213            goto on_return; 
     
    12411241 
    12421242            pjsip_get_response_addr(response->pool, rdata, &res_addr); 
    1243             pjsip_endpt_send_response(pjsua_var.endpt, &res_addr, response,  
     1243            pjsip_endpt_send_response(pjsua_var.endpt, &res_addr, response, 
    12441244                                      NULL, NULL); 
    12451245 
     
    12511251 
    12521252        goto on_return; 
    1253     }  
     1253    } 
    12541254 
    12551255    /* Get suitable Contact header */ 
     
    12601260                                              acc_id, rdata); 
    12611261        if (status != PJ_SUCCESS) { 
    1262             pjsua_perror(THIS_FILE, "Unable to generate Contact header",  
     1262            pjsua_perror(THIS_FILE, "Unable to generate Contact header", 
    12631263                         status); 
    12641264            pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 500, NULL, 
     
    12861286    /* Set credentials */ 
    12871287    if (pjsua_var.acc[acc_id].cred_cnt) { 
    1288         pjsip_auth_clt_set_credentials(&dlg->auth_sess,  
     1288        pjsip_auth_clt_set_credentials(&dlg->auth_sess, 
    12891289                                       pjsua_var.acc[acc_id].cred_cnt, 
    12901290                                       pjsua_var.acc[acc_id].cred); 
     
    12921292 
    12931293    /* Set preference */ 
    1294     pjsip_auth_clt_set_prefs(&dlg->auth_sess,  
     1294    pjsip_auth_clt_set_prefs(&dlg->auth_sess, 
    12951295                             &pjsua_var.acc[acc_id].cfg.auth_pref); 
    12961296 
     
    12981298     * did not require it. 
    12991299     */ 
    1300     if (pjsua_var.acc[acc_id].cfg.use_timer == PJSUA_SIP_TIMER_INACTIVE &&  
     1300    if (pjsua_var.acc[acc_id].cfg.use_timer == PJSUA_SIP_TIMER_INACTIVE && 
    13011301        (options & PJSIP_INV_REQUIRE_TIMER) == 0) 
    13021302    { 
     
    13231323        pjsip_warning_hdr *w; 
    13241324 
    1325         w = pjsip_warning_hdr_create_from_status(dlg->pool,  
     1325        w = pjsip_warning_hdr_create_from_status(dlg->pool, 
    13261326                                                 pjsip_endpt_name(pjsua_var.endpt), 
    13271327                                                 status); 
     
    13611361     */ 
    13621362    if (offer || replaced_dlg) { 
    1363         status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAS,  
    1364                                           call->secure_level,  
     1363        status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAS, 
     1364                                          call->secure_level, 
    13651365                                          rdata->tp_info.pool, 
    13661366                                          offer, 
     
    13771377                 */ 
    13781378                pjsip_dlg_respond(dlg, rdata, sip_err_code, NULL, NULL, NULL); 
    1379                 pjsip_inv_terminate(call->inv, sip_err_code, PJ_FALSE);  
     1379                pjsip_inv_terminate(call->inv, sip_err_code, PJ_FALSE); 
    13801380                call->inv = NULL; 
    13811381                call->async_call.dlg = NULL; 
     
    13851385            pjsua_perror(THIS_FILE, "Error initializing media channel", status); 
    13861386            pjsip_dlg_respond(dlg, rdata, sip_err_code, NULL, NULL, NULL); 
    1387             pjsip_inv_terminate(call->inv, sip_err_code, PJ_FALSE);  
    1388             call->inv = NULL;  
     1387            pjsip_inv_terminate(call->inv, sip_err_code, PJ_FALSE); 
     1388            call->inv = NULL; 
    13891389            call->async_call.dlg = NULL; 
    13901390            goto on_return; 
     
    13931393 
    13941394    /* Create answer */ 
    1395 /*   
    1396     status = pjsua_media_channel_create_sdp(call->index, rdata->tp_info.pool,  
     1395/* 
     1396    status = pjsua_media_channel_create_sdp(call->index, rdata->tp_info.pool, 
    13971397                                            offer, &answer, &sip_err_code); 
    13981398    if (status != PJ_SUCCESS) { 
     
    14051405 
    14061406    /* Init Session Timers */ 
    1407     status = pjsip_timer_init_session(inv,  
     1407    status = pjsip_timer_init_session(inv, 
    14081408                                    &pjsua_var.acc[acc_id].cfg.timer_setting); 
    14091409    if (status != PJ_SUCCESS) { 
     
    14201420 
    14211421    /* Update NAT type of remote endpoint, only when there is SDP in 
    1422      * incoming INVITE!  
     1422     * incoming INVITE! 
    14231423     */ 
    14241424    if (pjsua_var.ua_cfg.nat_type_in_sdp && inv->neg && 
    1425         pjmedia_sdp_neg_get_state(inv->neg) > PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER)  
     1425        pjmedia_sdp_neg_get_state(inv->neg) > PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER) 
    14261426    { 
    14271427        const pjmedia_sdp_session *remote_sdp; 
     
    14891489        } 
    14901490    } else { 
    1491         /* Notify application if on_incoming_call() is overriden,  
     1491        /* Notify application if on_incoming_call() is overriden, 
    14921492         * otherwise hangup the call with 480 
    14931493         */ 
     
    14951495            pjsua_var.ua_cfg.cb.on_incoming_call(acc_id, call_id, rdata); 
    14961496        } else { 
    1497             pjsua_call_hangup(call_id, PJSIP_SC_TEMPORARILY_UNAVAILABLE,  
     1497            pjsua_call_hangup(call_id, PJSIP_SC_TEMPORARILY_UNAVAILABLE, 
    14981498                              NULL, NULL); 
    14991499        } 
     
    15511551                break; 
    15521552        } 
    1553          
     1553 
    15541554        has_pjsua_lock = PJ_FALSE; 
    15551555 
     
    15961596        return PJ_ETIMEDOUT; 
    15971597    } 
    1598      
     1598 
    15991599    *p_call = call; 
    16001600    *p_dlg = dlg; 
     
    17011701                   sizeof(info->buf_.last_status_text)); 
    17021702    } 
    1703      
     1703 
    17041704    /* Audio & video count offered by remote */ 
    17051705    info->rem_offerer   = call->rem_offerer; 
     
    17271727            pjmedia_vid_dev_index cap_dev = PJMEDIA_VID_INVALID_DEV; 
    17281728 
    1729             info->media[info->media_cnt].stream.vid.win_in =  
     1729            info->media[info->media_cnt].stream.vid.win_in = 
    17301730                                                call_med->strm.v.rdr_win_id; 
    17311731 
     
    17631763            pjmedia_vid_dev_index cap_dev = PJMEDIA_VID_INVALID_DEV; 
    17641764 
    1765             info->prov_media[info->prov_media_cnt].stream.vid.win_in =  
     1765            info->prov_media[info->prov_media_cnt].stream.vid.win_in = 
    17661766                                                call_med->strm.v.rdr_win_id; 
    17671767 
     
    18741874 * Get media transport info for the specified media index. 
    18751875 */ 
    1876 PJ_DEF(pj_status_t)  
     1876PJ_DEF(pj_status_t) 
    18771877pjsua_call_get_med_transport_info(pjsua_call_id call_id, 
    18781878                                  unsigned med_idx, 
     
    18901890 
    18911891    call = &pjsua_var.calls[call_id]; 
    1892      
     1892 
    18931893    if (med_idx >= call->med_cnt) { 
    18941894        PJSUA_UNLOCK(); 
     
    19001900    pjmedia_transport_info_init(t); 
    19011901    status = pjmedia_transport_get_info(call_med->tp, t); 
    1902      
     1902 
    19031903    PJSUA_UNLOCK(); 
    19041904    return status; 
     
    19321932 
    19331933    status = pjsua_media_channel_create_sdp(call_id, 
    1934                                             call->async_call.dlg->pool,  
     1934                                            call->async_call.dlg->pool, 
    19351935                                            NULL, &sdp, &sip_err_code); 
    19361936    if (status != PJ_SUCCESS) { 
     
    19841984 * Send response to incoming INVITE request. 
    19851985 */ 
    1986 PJ_DEF(pj_status_t) pjsua_call_answer( pjsua_call_id call_id,  
     1986PJ_DEF(pj_status_t) pjsua_call_answer( pjsua_call_id call_id, 
    19871987                                       unsigned code, 
    19881988                                       const pj_str_t *reason, 
     
    20422042     *   answer code 183 or 2xx is issued 
    20432043     */ 
    2044     if (!call->med_ch_cb &&  
     2044    if (!call->med_ch_cb && 
    20452045        (call->opt_inited || (code==183 || code/100==2)) && 
    20462046        (!call->inv->neg || 
    2047          pjmedia_sdp_neg_get_state(call->inv->neg) ==  
     2047         pjmedia_sdp_neg_get_state(call->inv->neg) == 
    20482048                PJMEDIA_SDP_NEG_STATE_NULL)) 
    20492049    { 
     
    20762076    if (call->med_ch_cb) { 
    20772077        struct call_answer *answer; 
    2078          
     2078 
    20792079        PJ_LOG(4,(THIS_FILE, "Pending answering call %d upon completion " 
    20802080                             "of media transport", call_id)); 
     
    21142114    status = pjsip_inv_answer(call->inv, code, reason, NULL, &tdata); 
    21152115    if (status != PJ_SUCCESS) { 
    2116         pjsua_perror(THIS_FILE, "Error creating response",  
     2116        pjsua_perror(THIS_FILE, "Error creating response", 
    21172117                     status); 
    21182118        goto on_return; 
     
    21312131    status = pjsip_inv_send_msg(call->inv, tdata); 
    21322132    if (status != PJ_SUCCESS) 
    2133         pjsua_perror(THIS_FILE, "Error sending response",  
     2133        pjsua_perror(THIS_FILE, "Error sending response", 
    21342134                     status); 
    21352135 
     
    21602160                             call_id)); 
    21612161    } 
    2162      
     2162 
    21632163    PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls, 
    21642164                     PJ_EINVAL); 
     
    21862186                       sizeof(call->last_text_buf_)); 
    21872187        } 
    2188          
     2188 
    21892189        goto on_return; 
    21902190    } 
     
    22012201    status = pjsip_inv_end_session(call->inv, code, reason, &tdata); 
    22022202    if (status != PJ_SUCCESS) { 
    2203         pjsua_perror(THIS_FILE,  
    2204                      "Failed to create end session message",  
     2203        pjsua_perror(THIS_FILE, 
     2204                     "Failed to create end session message", 
    22052205                     status); 
    22062206        goto on_return; 
    22072207    } 
    22082208 
    2209     /* pjsip_inv_end_session may return PJ_SUCCESS with NULL  
     2209    /* pjsip_inv_end_session may return PJ_SUCCESS with NULL 
    22102210     * as p_tdata when INVITE transaction has not been answered 
    22112211     * with any provisional responses. 
     
    22202220    status = pjsip_inv_send_msg(call->inv, tdata); 
    22212221    if (status != PJ_SUCCESS) { 
    2222         pjsua_perror(THIS_FILE,  
    2223                      "Failed to send end session message",  
     2222        pjsua_perror(THIS_FILE, 
     2223                     "Failed to send end session message", 
    22242224                     status); 
    22252225        goto on_return; 
     
    22522252                     PJ_EINVAL); 
    22532253 
    2254     status = acquire_call("pjsua_call_process_redirect()", call_id,  
     2254    status = acquire_call("pjsua_call_process_redirect()", call_id, 
    22552255                          &call, &dlg); 
    22562256    if (status != PJ_SUCCESS) 
     
    23982398        goto on_return; 
    23992399    } 
    2400  
    2401     status = apply_call_setting(call, opt, NULL); 
    2402     if (status != PJ_SUCCESS) { 
    2403         pjsua_perror(THIS_FILE, "Failed to apply call setting", status); 
    2404         goto on_return; 
    2405     } 
    2406  
    2407     /* Create SDP */ 
    2408     if (call->local_hold && (call->opt.flag & PJSUA_CALL_UNHOLD)==0) { 
    2409         status = create_sdp_of_call_hold(call, &sdp); 
    2410     } else { 
    2411         status = pjsua_media_channel_create_sdp(call->index,  
    2412                                                 call->inv->pool_prov, 
    2413                                                 NULL, &sdp, NULL); 
    2414         call->local_hold = PJ_FALSE; 
    2415     } 
    2416     if (status != PJ_SUCCESS) { 
    2417         pjsua_perror(THIS_FILE, "Unable to get SDP from media endpoint",  
    2418                      status); 
    2419         goto on_return; 
    2420     } 
    2421  
    2422     if ((call->opt.flag & PJSUA_CALL_UPDATE_CONTACT) && 
    2423             pjsua_acc_is_valid(call->acc_id)) 
    2424     { 
    2425         new_contact = &pjsua_var.acc[call->acc_id].contact; 
    2426     } 
    2427  
    2428     /* Create re-INVITE with new offer */ 
    2429     status = pjsip_inv_reinvite( call->inv, new_contact, sdp, &tdata); 
    2430     if (status != PJ_SUCCESS) { 
    2431         pjsua_perror(THIS_FILE, "Unable to create re-INVITE", status); 
    2432         goto on_return; 
    2433     } 
    2434  
    2435     /* Add additional headers etc */ 
    2436     pjsua_process_msg_data( tdata, msg_data); 
    2437  
    2438     /* Send the request */ 
    2439     status = pjsip_inv_send_msg( call->inv, tdata); 
    2440     if (status != PJ_SUCCESS) { 
    2441         pjsua_perror(THIS_FILE, "Unable to send re-INVITE", status); 
    2442         goto on_return; 
    2443     } 
    2444  
    2445 on_return: 
    2446     if (dlg) pjsip_dlg_dec_lock(dlg); 
    2447     pj_log_pop_indent(); 
    2448     return status; 
    2449 } 
    2450  
    2451  
    2452 /* 
    2453  * Send UPDATE request. 
    2454  */ 
    2455 PJ_DEF(pj_status_t) pjsua_call_update( pjsua_call_id call_id, 
    2456                                        unsigned options, 
    2457                                        const pjsua_msg_data *msg_data) 
    2458 { 
    2459     pjsua_call *call; 
    2460     pjsip_dialog *dlg = NULL; 
    2461     pj_status_t status; 
    2462  
    2463     status = acquire_call("pjsua_call_update()", call_id, &call, &dlg); 
    2464     if (status != PJ_SUCCESS) 
    2465         goto on_return; 
    2466  
    2467     if (options != call->opt.flag) 
    2468         call->opt.flag = options; 
    2469  
    2470     status = pjsua_call_update2(call_id, NULL, msg_data); 
    2471  
    2472 on_return: 
    2473     if (dlg) pjsip_dlg_dec_lock(dlg); 
    2474     return status; 
    2475 } 
    2476  
    2477  
    2478 /* 
    2479  * Send UPDATE request. 
    2480  */ 
    2481 PJ_DEF(pj_status_t) pjsua_call_update2(pjsua_call_id call_id, 
    2482                                        const pjsua_call_setting *opt, 
    2483                                        const pjsua_msg_data *msg_data) 
    2484 { 
    2485     pjmedia_sdp_session *sdp; 
    2486     pj_str_t *new_contact = NULL; 
    2487     pjsip_tx_data *tdata; 
    2488     pjsua_call *call; 
    2489     pjsip_dialog *dlg = NULL; 
    2490     pj_status_t status; 
    2491  
    2492     PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls, 
    2493                      PJ_EINVAL); 
    2494  
    2495     PJ_LOG(4,(THIS_FILE, "Sending UPDATE on call %d", call_id)); 
    2496     pj_log_push_indent(); 
    2497  
    2498     status = acquire_call("pjsua_call_update2()", call_id, &call, &dlg); 
    2499     if (status != PJ_SUCCESS) 
    2500         goto on_return; 
    25012400 
    25022401    status = apply_call_setting(call, opt, NULL); 
     
    25152414        call->local_hold = PJ_FALSE; 
    25162415    } 
    2517  
    25182416    if (status != PJ_SUCCESS) { 
    25192417        pjsua_perror(THIS_FILE, "Unable to get SDP from media endpoint", 
     
    25282426    } 
    25292427 
    2530     /* Create UPDATE with new offer */ 
    2531     status = pjsip_inv_update(call->inv, new_contact, sdp, &tdata); 
    2532     if (status != PJ_SUCCESS) { 
    2533         pjsua_perror(THIS_FILE, "Unable to create UPDATE request", status); 
     2428    /* Create re-INVITE with new offer */ 
     2429    status = pjsip_inv_reinvite( call->inv, new_contact, sdp, &tdata); 
     2430    if (status != PJ_SUCCESS) { 
     2431        pjsua_perror(THIS_FILE, "Unable to create re-INVITE", status); 
    25342432        goto on_return; 
    25352433    } 
     
    25412439    status = pjsip_inv_send_msg( call->inv, tdata); 
    25422440    if (status != PJ_SUCCESS) { 
    2543         pjsua_perror(THIS_FILE, "Unable to send UPDATE request", status); 
     2441        pjsua_perror(THIS_FILE, "Unable to send re-INVITE", status); 
    25442442        goto on_return; 
    25452443    } 
     
    25532451 
    25542452/* 
     2453 * Send UPDATE request. 
     2454 */ 
     2455PJ_DEF(pj_status_t) pjsua_call_update( pjsua_call_id call_id, 
     2456                                       unsigned options, 
     2457                                       const pjsua_msg_data *msg_data) 
     2458{ 
     2459    pjsua_call *call; 
     2460    pjsip_dialog *dlg = NULL; 
     2461    pj_status_t status; 
     2462 
     2463    status = acquire_call("pjsua_call_update()", call_id, &call, &dlg); 
     2464    if (status != PJ_SUCCESS) 
     2465        goto on_return; 
     2466 
     2467    if (options != call->opt.flag) 
     2468        call->opt.flag = options; 
     2469 
     2470    status = pjsua_call_update2(call_id, NULL, msg_data); 
     2471 
     2472on_return: 
     2473    if (dlg) pjsip_dlg_dec_lock(dlg); 
     2474    return status; 
     2475} 
     2476 
     2477 
     2478/* 
     2479 * Send UPDATE request. 
     2480 */ 
     2481PJ_DEF(pj_status_t) pjsua_call_update2(pjsua_call_id call_id, 
     2482                                       const pjsua_call_setting *opt, 
     2483                                       const pjsua_msg_data *msg_data) 
     2484{ 
     2485    pjmedia_sdp_session *sdp; 
     2486    pj_str_t *new_contact = NULL; 
     2487    pjsip_tx_data *tdata; 
     2488    pjsua_call *call; 
     2489    pjsip_dialog *dlg = NULL; 
     2490    pj_status_t status; 
     2491 
     2492    PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls, 
     2493                     PJ_EINVAL); 
     2494 
     2495    PJ_LOG(4,(THIS_FILE, "Sending UPDATE on call %d", call_id)); 
     2496    pj_log_push_indent(); 
     2497 
     2498    status = acquire_call("pjsua_call_update2()", call_id, &call, &dlg); 
     2499    if (status != PJ_SUCCESS) 
     2500        goto on_return; 
     2501 
     2502    status = apply_call_setting(call, opt, NULL); 
     2503    if (status != PJ_SUCCESS) { 
     2504        pjsua_perror(THIS_FILE, "Failed to apply call setting", status); 
     2505        goto on_return; 
     2506    } 
     2507 
     2508    /* Create SDP */ 
     2509    if (call->local_hold && (call->opt.flag & PJSUA_CALL_UNHOLD)==0) { 
     2510        status = create_sdp_of_call_hold(call, &sdp); 
     2511    } else { 
     2512        status = pjsua_media_channel_create_sdp(call->index, 
     2513                                                call->inv->pool_prov, 
     2514                                                NULL, &sdp, NULL); 
     2515        call->local_hold = PJ_FALSE; 
     2516    } 
     2517 
     2518    if (status != PJ_SUCCESS) { 
     2519        pjsua_perror(THIS_FILE, "Unable to get SDP from media endpoint", 
     2520                     status); 
     2521        goto on_return; 
     2522    } 
     2523 
     2524    if ((call->opt.flag & PJSUA_CALL_UPDATE_CONTACT) && 
     2525            pjsua_acc_is_valid(call->acc_id)) 
     2526    { 
     2527        new_contact = &pjsua_var.acc[call->acc_id].contact; 
     2528    } 
     2529 
     2530    /* Create UPDATE with new offer */ 
     2531    status = pjsip_inv_update(call->inv, new_contact, sdp, &tdata); 
     2532    if (status != PJ_SUCCESS) { 
     2533        pjsua_perror(THIS_FILE, "Unable to create UPDATE request", status); 
     2534        goto on_return; 
     2535    } 
     2536 
     2537    /* Add additional headers etc */ 
     2538    pjsua_process_msg_data( tdata, msg_data); 
     2539 
     2540    /* Send the request */ 
     2541    status = pjsip_inv_send_msg( call->inv, tdata); 
     2542    if (status != PJ_SUCCESS) { 
     2543        pjsua_perror(THIS_FILE, "Unable to send UPDATE request", status); 
     2544        goto on_return; 
     2545    } 
     2546 
     2547on_return: 
     2548    if (dlg) pjsip_dlg_dec_lock(dlg); 
     2549    pj_log_pop_indent(); 
     2550    return status; 
     2551} 
     2552 
     2553 
     2554/* 
    25552555 * Initiate call transfer to the specified address. 
    25562556 */ 
    2557 PJ_DEF(pj_status_t) pjsua_call_xfer( pjsua_call_id call_id,  
     2557PJ_DEF(pj_status_t) pjsua_call_xfer( pjsua_call_id call_id, 
    25582558                                     const pj_str_t *dest, 
    25592559                                     const pjsua_msg_data *msg_data) 
     
    25712571    PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls && 
    25722572                     dest, PJ_EINVAL); 
    2573      
     2573 
    25742574    PJ_LOG(4,(THIS_FILE, "Transferring call %d to %.*s", call_id, 
    25752575                         (int)dest->slen, dest->ptr)); 
     
    25792579    if (status != PJ_SUCCESS) 
    25802580        goto on_return; 
    2581     
     2581 
    25822582    /* Create xfer client subscription. */ 
    25832583    pj_bzero(&xfer_cb, sizeof(xfer_cb)); 
     
    26182618    } 
    26192619 
    2620     /* For simplicity (that's what this program is intended to be!),  
     2620    /* For simplicity (that's what this program is intended to be!), 
    26212621     * leave the original invite session as it is. More advanced application 
    26222622     * may want to hold the INVITE, or terminate the invite, or whatever. 
     
    26332633 * Initiate attended call transfer to the specified address. 
    26342634 */ 
    2635 PJ_DEF(pj_status_t) pjsua_call_xfer_replaces( pjsua_call_id call_id,  
     2635PJ_DEF(pj_status_t) pjsua_call_xfer_replaces( pjsua_call_id call_id, 
    26362636                                              pjsua_call_id dest_call_id, 
    26372637                                              unsigned options, 
     
    26452645    pjsip_uri *uri; 
    26462646    pj_status_t status; 
    2647      
     2647 
    26482648 
    26492649    PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls, 
    26502650                     PJ_EINVAL); 
    2651     PJ_ASSERT_RETURN(dest_call_id>=0 &&  
     2651    PJ_ASSERT_RETURN(dest_call_id>=0 && 
    26522652                      dest_call_id<(int)pjsua_var.ua_cfg.max_calls, 
    26532653                     PJ_EINVAL); 
    2654      
     2654 
    26552655    PJ_LOG(4,(THIS_FILE, "Transferring call %d replacing with call %d", 
    26562656                         call_id, dest_call_id)); 
    26572657    pj_log_push_indent(); 
    26582658 
    2659     status = acquire_call("pjsua_call_xfer_replaces()", dest_call_id,  
     2659    status = acquire_call("pjsua_call_xfer_replaces()", dest_call_id, 
    26602660                          &dest_call, &dest_dlg); 
    26612661    if (status != PJ_SUCCESS) { 
     
    26632663        return status; 
    26642664    } 
    2665          
    2666     /*  
     2665 
     2666    /* 
    26672667     * Create REFER destination URI with Replaces field. 
    26682668     */ 
     
    26722672                      dest_dlg->call_id->id.slen + 
    26732673                      dest_dlg->remote.info->tag.slen + 
    2674                       dest_dlg->local.info->tag.slen + 32  
     2674                      dest_dlg->local.info->tag.slen + 32 
    26752675                      < (long)sizeof(str_dest_buf), 
    26762676                      { status=PJSIP_EURITOOLONG; goto on_error; }); 
     
    26812681 
    26822682    uri = (pjsip_uri*) pjsip_uri_get_uri(dest_dlg->remote.info->uri); 
    2683     len = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, uri,  
     2683    len = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, uri, 
    26842684                          str_dest_buf+1, sizeof(str_dest_buf)-1); 
    26852685    if (len < 0) { 
     
    26922692 
    26932693    /* Build the URI */ 
    2694     len = pj_ansi_snprintf(str_dest_buf + str_dest.slen,  
     2694    len = pj_ansi_snprintf(str_dest_buf + str_dest.slen, 
    26952695                           sizeof(str_dest_buf) - str_dest.slen, 
    26962696                           "?%s" 
     
    27092709    PJ_ASSERT_ON_FAIL(len > 0 && len <= (int)sizeof(str_dest_buf)-str_dest.slen, 
    27102710                      { status=PJSIP_EURITOOLONG; goto on_error; }); 
    2711      
     2711 
    27122712    str_dest.ptr = str_dest_buf; 
    27132713    str_dest.slen += len; 
    27142714 
    27152715    pjsip_dlg_dec_lock(dest_dlg); 
    2716      
     2716 
    27172717    status = pjsua_call_xfer(call_id, &str_dest, msg_data); 
    27182718 
     
    27302730 * Send instant messaging inside INVITE session. 
    27312731 */ 
    2732 PJ_DEF(pj_status_t) pjsua_call_send_im( pjsua_call_id call_id,  
     2732PJ_DEF(pj_status_t) pjsua_call_send_im( pjsua_call_id call_id, 
    27332733                                        const pj_str_t *mime_type, 
    27342734                                        const pj_str_t *content, 
     
    27542754    if (status != PJ_SUCCESS) 
    27552755        goto on_return; 
    2756      
     2756 
    27572757    /* Set default media type if none is specified */ 
    27582758    if (mime_type == NULL) { 
     
    27692769 
    27702770    /* Add accept header. */ 
    2771     pjsip_msg_add_hdr( tdata->msg,  
     2771    pjsip_msg_add_hdr( tdata->msg, 
    27722772                       (pjsip_hdr*)pjsua_im_create_accept(tdata->pool)); 
    27732773 
     
    27972797 
    27982798    /* Send the request. */ 
    2799     status = pjsip_dlg_send_request( call->inv->dlg, tdata,  
     2799    status = pjsip_dlg_send_request( call->inv->dlg, tdata, 
    28002800                                     pjsua_var.mod.id, im_data); 
    28012801    if (status != PJ_SUCCESS) { 
     
    28142814 * Send IM typing indication inside INVITE session. 
    28152815 */ 
    2816 PJ_DEF(pj_status_t) pjsua_call_send_typing_ind( pjsua_call_id call_id,  
     2816PJ_DEF(pj_status_t) pjsua_call_send_typing_ind( pjsua_call_id call_id, 
    28172817                                                pj_bool_t is_typing, 
    28182818                                                const pjsua_msg_data*msg_data) 
     
    30993099        pjmedia_transport_info tpinfo; 
    31003100        pjmedia_ice_transport_info *ice_info; 
    3101          
     3101 
    31023102        if (call_med->tp_st == PJSUA_MED_TP_NULL || 
    31033103            call_med->tp_st == PJSUA_MED_TP_DISABLED || 
     
    31063106            continue; 
    31073107        } 
    3108          
     3108 
    31093109        pjmedia_transport_info_init(&tpinfo); 
    31103110        pjmedia_transport_get_info(call_med->tp, &tpinfo); 
     
    31223122            break; 
    31233123        } 
    3124          
     3124 
    31253125        /* Check if ICE needs to send reinvite */ 
    31263126        if (!ice_need_reinv && 
     
    31373137        } 
    31383138    } 
    3139      
     3139 
    31403140    if (ice_complete && need_reinv) 
    31413141        *need_reinv = ice_need_reinv; 
    3142      
     3142 
    31433143    return ice_complete; 
    31443144} 
     
    31773177     * remote does not support UPDATE method. 
    31783178     */ 
    3179     if (inv->state == PJSIP_INV_STATE_EARLY &&  
     3179    if (inv->state == PJSIP_INV_STATE_EARLY && 
    31803180        pjsip_dlg_remote_has_cap(inv->dlg, PJSIP_H_ALLOW, NULL, &ST_UPDATE)!= 
    31813181        PJSIP_DIALOG_CAP_SUPPORTED) 
     
    31973197        return PJ_SUCCESS; 
    31983198 
    3199      
     3199 
    32003200    /* Okay! So we need to send re-INVITE/UPDATE */ 
    32013201 
     
    32183218                  )); 
    32193219    } 
    3220      
     3220 
    32213221    /* Generate SDP re-offer */ 
    32223222    status = pjsua_media_channel_create_sdp(call->index, pool, NULL, 
     
    32353235    if (need_lock_codec) { 
    32363236        const pjmedia_sdp_session *ref_sdp; 
    3237          
     3237 
    32383238        /* Get local active SDP as reference */ 
    32393239        status = pjmedia_sdp_neg_get_active_local(call->inv->neg, &ref_sdp); 
    32403240        if (status != PJ_SUCCESS) 
    32413241            return status; 
    3242          
     3242 
    32433243        /* Verify media count. Note that remote may add/remove media line 
    32443244         * in the answer. When answer has less media, it must have been 
     
    32623262            pjmedia_sdp_media *m = new_offer->media[i]; 
    32633263            pjsua_call_media *call_med = &call->media[i]; 
    3264      
     3264 
    32653265            /* Verify if media is deactivated */ 
    32663266            if (call_med->state == PJSUA_CALL_MEDIA_NONE || 
     
    32703270                continue; 
    32713271            } 
    3272      
     3272 
    32733273            /* Reset formats */ 
    32743274            m->desc.fmt_count = 0; 
    32753275            pjmedia_sdp_attr_remove_all(&m->attr_count, m->attr, "rtpmap"); 
    32763276            pjmedia_sdp_attr_remove_all(&m->attr_count, m->attr, "fmtp"); 
    3277              
     3277 
    32783278            /* Copy only the first format + any non-AV formats from 
    32793279             * the active local SDP. 
     
    32843284                if (is_non_av_fmt(ref_m, fmt) || (++codec_cnt == 1)) { 
    32853285                    pjmedia_sdp_attr *a; 
    3286                      
     3286 
    32873287                    m->desc.fmt[m->desc.fmt_count++] = *fmt; 
    32883288                    a = pjmedia_sdp_attr_find2(ref_m->attr_count, ref_m->attr, 
     
    33003300    { 
    33013301        const pjmedia_sdp_session *cur_sdp; 
    3302          
     3302 
    33033303        /* Get local active SDP */ 
    33043304        status = pjmedia_sdp_neg_get_active_local(call->inv->neg, &cur_sdp); 
     
    33563356    } 
    33573357 
    3358      
     3358 
    33593359    if (rem_can_update) { 
    33603360        status = pjsip_inv_update(inv, NULL, new_offer, &tdata); 
     
    33883388    if (need_lock_codec) 
    33893389        ++call->lock_codec.retry_cnt; 
    3390      
     3390 
    33913391    return PJ_SUCCESS; 
    33923392} 
     
    33973397 * session state has changed. 
    33983398 */ 
    3399 static void pjsua_call_on_state_changed(pjsip_inv_session *inv,  
     3399static void pjsua_call_on_state_changed(pjsip_inv_session *inv, 
    34003400                                        pjsip_event *e) 
    34013401{ 
     
    34183418            if (call->res_time.sec == 0) 
    34193419                pj_gettimeofday(&call->res_time); 
    3420             call->last_code = (pjsip_status_code)  
     3420            call->last_code = (pjsip_status_code) 
    34213421                              e->body.tsx_state.tsx->status_code; 
    3422             pj_strncpy(&call->last_text,  
     3422            pj_strncpy(&call->last_text, 
    34233423                       &e->body.tsx_state.tsx->status_text, 
    34243424                       sizeof(call->last_text_buf_)); 
     
    34393439            if (call->res_time.sec == 0) 
    34403440                pj_gettimeofday(&call->res_time); 
    3441             if (e->type == PJSIP_EVENT_TSX_STATE &&  
    3442                 e->body.tsx_state.tsx->status_code > call->last_code)  
     3441            if (e->type == PJSIP_EVENT_TSX_STATE && 
     3442                e->body.tsx_state.tsx->status_code > call->last_code) 
    34433443            { 
    3444                 call->last_code = (pjsip_status_code)  
     3444                call->last_code = (pjsip_status_code) 
    34453445                                  e->body.tsx_state.tsx->status_code; 
    3446                 pj_strncpy(&call->last_text,  
     3446                pj_strncpy(&call->last_text, 
    34473447                           &e->body.tsx_state.tsx->status_text, 
    34483448                           sizeof(call->last_text_buf_)); 
     
    34613461            break; 
    34623462        default: 
    3463             call->last_code = (pjsip_status_code)  
     3463            call->last_code = (pjsip_status_code) 
    34643464                              e->body.tsx_state.tsx->status_code; 
    3465             pj_strncpy(&call->last_text,  
     3465            pj_strncpy(&call->last_text, 
    34663466                       &e->body.tsx_state.tsx->status_text, 
    34673467                       sizeof(call->last_text_buf_)); 
     
    34753475        int st_code = -1; 
    34763476        pjsip_evsub_state ev_state = PJSIP_EVSUB_STATE_ACTIVE; 
    3477          
     3477 
    34783478 
    34793479        switch (call->inv->state) { 
     
    35543554 
    35553555        PJSUA_LOCK(); 
    3556          
     3556 
    35573557        pjsua_media_channel_deinit(call->index); 
    35583558 
     
    35773577 * has forked. 
    35783578 */ 
    3579 static void pjsua_call_on_forked( pjsip_inv_session *inv,  
     3579static void pjsua_call_on_forked( pjsip_inv_session *inv, 
    35803580                                  pjsip_event *e) 
    35813581{ 
     
    35923592pjsip_dialog* on_dlg_forked(pjsip_dialog *dlg, pjsip_rx_data *res) 
    35933593{ 
    3594     if (dlg->uac_has_2xx &&  
     3594    if (dlg->uac_has_2xx && 
    35953595        res->msg_info.cseq->method.id == PJSIP_INVITE_METHOD && 
    35963596        pjsip_rdata_get_tsx(res) == NULL && 
    3597         res->msg_info.msg->line.status.code/100 == 2)  
     3597        res->msg_info.msg->line.status.code/100 == 2) 
    35983598    { 
    35993599        pjsip_dialog *forked_dlg; 
     
    36313631 * Disconnect call upon error. 
    36323632 */ 
    3633 static void call_disconnect( pjsip_inv_session *inv,  
     3633static void call_disconnect( pjsip_inv_session *inv, 
    36343634                             int code ) 
    36353635{ 
    3636     pjsua_call *call; 
    36373636    pjsip_tx_data *tdata; 
    36383637    pj_status_t status; 
    3639  
    3640     call = (pjsua_call*) inv->dlg->mod_data[pjsua_var.mod.id]; 
    36413638 
    36423639    status = pjsip_inv_end_session(inv, code, NULL, &tdata); 
     
    36443641        return; 
    36453642 
     3643#if DISABLED_FOR_TICKET_1185 
     3644    pjsua_call *call; 
     3645 
    36463646    /* Add SDP in 488 status */ 
    3647 #if DISABLED_FOR_TICKET_1185 
     3647    call = (pjsua_call*) inv->dlg->mod_data[pjsua_var.mod.id]; 
     3648 
    36483649    if (call && call->tp && tdata->msg->type==PJSIP_RESPONSE_MSG && 
    3649         code==PJSIP_SC_NOT_ACCEPTABLE_HERE)  
     3650        code==PJSIP_SC_NOT_ACCEPTABLE_HERE) 
    36503651    { 
    36513652        pjmedia_sdp_session *local_sdp; 
     
    36543655        pjmedia_transport_info_init(&ti); 
    36553656        pjmedia_transport_get_info(call->med_tp, &ti); 
    3656         status = pjmedia_endpt_create_sdp(pjsua_var.med_endpt, tdata->pool,  
     3657        status = pjmedia_endpt_create_sdp(pjsua_var.med_endpt, tdata->pool, 
    36573658                                          1, &ti.sock_info, &local_sdp); 
    36583659        if (status == PJ_SUCCESS) { 
     
    36993700 
    37003701        /* Disconnect call if we're not in the middle of initializing an 
    3701          * UAS dialog and if this is not a re-INVITE  
     3702         * UAS dialog and if this is not a re-INVITE 
    37023703         */ 
    37033704        if (inv->state != PJSIP_INV_STATE_NULL && 
    3704             inv->state != PJSIP_INV_STATE_CONFIRMED)  
     3705            inv->state != PJSIP_INV_STATE_CONFIRMED) 
    37053706        { 
    37063707            call_disconnect(inv, PJSIP_SC_UNSUPPORTED_MEDIA_TYPE); 
     
    37143715    status = pjmedia_sdp_neg_get_active_local(call->inv->neg, &local_sdp); 
    37153716    if (status != PJ_SUCCESS) { 
    3716         pjsua_perror(THIS_FILE,  
    3717                      "Unable to retrieve currently active local SDP",  
     3717        pjsua_perror(THIS_FILE, 
     3718                     "Unable to retrieve currently active local SDP", 
    37183719                     status); 
    37193720        //call_disconnect(inv, PJSIP_SC_UNSUPPORTED_MEDIA_TYPE); 
     
    37233724    status = pjmedia_sdp_neg_get_active_remote(call->inv->neg, &remote_sdp); 
    37243725    if (status != PJ_SUCCESS) { 
    3725         pjsua_perror(THIS_FILE,  
    3726                      "Unable to retrieve currently active remote SDP",  
     3726        pjsua_perror(THIS_FILE, 
     3727                     "Unable to retrieve currently active remote SDP", 
    37273728                     status); 
    37283729        //call_disconnect(inv, PJSIP_SC_UNSUPPORTED_MEDIA_TYPE); 
     
    37383739    status = pjsua_media_channel_update(call->index, local_sdp, remote_sdp); 
    37393740    if (status != PJ_SUCCESS) { 
    3740         pjsua_perror(THIS_FILE, "Unable to create media session",  
     3741        pjsua_perror(THIS_FILE, "Unable to create media session", 
    37413742                     status); 
    37423743        call_disconnect(inv, PJSIP_SC_NOT_ACCEPTABLE_HERE); 
     
    37683769    unsigned mi; 
    37693770 
    3770     /* Call-hold is done by set the media direction to 'sendonly'  
    3771      * (PJMEDIA_DIR_ENCODING), except when current media direction is  
     3771    /* Call-hold is done by set the media direction to 'sendonly' 
     3772     * (PJMEDIA_DIR_ENCODING), except when current media direction is 
    37723773     * 'inactive' (PJMEDIA_DIR_NONE). 
    37733774     * (See RFC 3264 Section 8.4 and RFC 4317 Section 3.1) 
    37743775     */ 
    3775     /* http://trac.pjsip.org/repos/ticket/880  
     3776    /* http://trac.pjsip.org/repos/ticket/880 
    37763777       if (call->dir != PJMEDIA_DIR_ENCODING) { 
    37773778     */ 
     
    38833884        pjsip_status_code code = PJSIP_SC_OK; 
    38843885        pjsua_call_setting opt = call->opt; 
    3885          
     3886 
    38863887        (*pjsua_var.ua_cfg.cb.on_call_rx_offer)(call->index, offer, NULL, 
    38873888                                                &code, &opt); 
     
    38953896        call->opt = opt; 
    38963897    } 
    3897      
     3898 
    38983899    /* Re-init media for the new remote offer before creating SDP */ 
    38993900    status = apply_call_setting(call, &call->opt, offer); 
     
    39013902        goto on_return; 
    39023903 
    3903     status = pjsua_media_channel_create_sdp(call->index,  
    3904                                             call->inv->pool_prov,  
     3904    status = pjsua_media_channel_create_sdp(call->index, 
     3905                                            call->inv->pool_prov, 
    39053906                                            offer, &answer, NULL); 
    39063907    if (status != PJ_SUCCESS) { 
     
    39723973    /* See if we've put call on hold. */ 
    39733974    if (call->local_hold) { 
    3974         PJ_LOG(4,(THIS_FILE,  
     3975        PJ_LOG(4,(THIS_FILE, 
    39753976                  "Call %d: call is on-hold locally, creating call-hold SDP ", 
    39763977                  call->index)); 
     
    39803981                  call->index)); 
    39813982 
    3982         status = pjsua_media_channel_create_sdp(call->index,  
    3983                                                 call->inv->pool_prov,  
     3983        status = pjsua_media_channel_create_sdp(call->index, 
     3984                                                call->inv->pool_prov, 
    39843985                                                NULL, offer, NULL); 
    39853986    } 
     
    40014002static void xfer_client_on_evsub_state( pjsip_evsub *sub, pjsip_event *event) 
    40024003{ 
    4003      
     4004 
    40044005    PJ_UNUSED_ARG(event); 
    40054006 
     
    40074008 
    40084009    /* 
    4009      * When subscription is accepted (got 200/OK to REFER), check if  
     4010     * When subscription is accepted (got 200/OK to REFER), check if 
    40104011     * subscription suppressed. 
    40114012     */ 
     
    40204021 
    40214022        /* Must be receipt of response message */ 
    4022         pj_assert(event->type == PJSIP_EVENT_TSX_STATE &&  
     4023        pj_assert(event->type == PJSIP_EVENT_TSX_STATE && 
    40234024                  event->body.tsx_state.type == PJSIP_EVENT_RX_MSG); 
    40244025        rdata = event->body.tsx_state.src.rdata; 
     
    40264027        /* Find Refer-Sub header */ 
    40274028        refer_sub = (pjsip_generic_string_hdr*) 
    4028                     pjsip_msg_find_hdr_by_name(rdata->msg_info.msg,  
     4029                    pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, 
    40294030                                               &REFER_SUB, NULL); 
    40304031 
     
    40374038                const pj_str_t ACCEPTED = { "Accepted", 8 }; 
    40384039                pj_bool_t cont = PJ_FALSE; 
    4039                 (*pjsua_var.ua_cfg.cb.on_call_transfer_status)(call->index,  
     4040                (*pjsua_var.ua_cfg.cb.on_call_transfer_status)(call->index, 
    40404041                                                               200, 
    40414042                                                               &ACCEPTED, 
     
    40524053 
    40534054        } else { 
    4054             /* Notify application about call transfer progress.  
     4055            /* Notify application about call transfer progress. 
    40554056             * Initially notify with 100/Accepted status. 
    40564057             */ 
     
    40584059                const pj_str_t ACCEPTED = { "Accepted", 8 }; 
    40594060                pj_bool_t cont = PJ_FALSE; 
    4060                 (*pjsua_var.ua_cfg.cb.on_call_transfer_status)(call->index,  
     4061                (*pjsua_var.ua_cfg.cb.on_call_transfer_status)(call->index, 
    40614062                                                               100, 
    40624063                                                               &ACCEPTED, 
     
    40704071     */ 
    40714072    else if (pjsip_evsub_get_state(sub) == PJSIP_EVSUB_STATE_ACTIVE || 
    4072              pjsip_evsub_get_state(sub) == PJSIP_EVSUB_STATE_TERMINATED)  
     4073             pjsip_evsub_get_state(sub) == PJSIP_EVSUB_STATE_TERMINATED) 
    40734074    { 
    40744075        pjsua_call *call; 
     
    40824083        call = (pjsua_call*) pjsip_evsub_get_mod_data(sub, pjsua_var.mod.id); 
    40834084 
    4084         /* When subscription is terminated, clear the xfer_sub member of  
     4085        /* When subscription is terminated, clear the xfer_sub member of 
    40854086         * the inv_data. 
    40864087         */ 
     
    41084109            body = msg->body; 
    41094110            if (!body) { 
    4110                 PJ_LOG(2,(THIS_FILE,  
     4111                PJ_LOG(2,(THIS_FILE, 
    41114112                          "Warning: received NOTIFY without message body")); 
    41124113                goto on_return; 
     
    41174118                pj_stricmp2(&body->content_type.subtype, "sipfrag") != 0) 
    41184119            { 
    4119                 PJ_LOG(2,(THIS_FILE,  
     4120                PJ_LOG(2,(THIS_FILE, 
    41204121                          "Warning: received NOTIFY with non message/sipfrag " 
    41214122                          "content")); 
     
    41244125 
    41254126            /* Try to parse the content */ 
    4126             status = pjsip_parse_status_line((char*)body->data, body->len,  
     4127            status = pjsip_parse_status_line((char*)body->data, body->len, 
    41274128                                             &status_line); 
    41284129            if (status != PJ_SUCCESS) { 
    4129                 PJ_LOG(2,(THIS_FILE,  
     4130                PJ_LOG(2,(THIS_FILE, 
    41304131                          "Warning: received NOTIFY with invalid " 
    41314132                          "message/sipfrag content")); 
     
    41414142        is_last = (pjsip_evsub_get_state(sub)==PJSIP_EVSUB_STATE_TERMINATED); 
    41424143        cont = !is_last; 
    4143         (*pjsua_var.ua_cfg.cb.on_call_transfer_status)(call->index,  
     4144        (*pjsua_var.ua_cfg.cb.on_call_transfer_status)(call->index, 
    41444145                                                       status_line.code, 
    41454146                                                       &status_line.reason, 
     
    41564157            pjsip_tx_data *tdata; 
    41574158 
    4158             status = pjsip_evsub_initiate(sub, &pjsip_subscribe_method,  
     4159            status = pjsip_evsub_initiate(sub, &pjsip_subscribe_method, 
    41594160                                          0, &tdata); 
    41604161            if (status == PJ_SUCCESS) 
     
    41794180 
    41804181    /* 
    4181      * When subscription is terminated, clear the xfer_sub member of  
     4182     * When subscription is terminated, clear the xfer_sub member of 
    41824183     * the inv_data. 
    41834184     */ 
     
    42544255     */ 
    42554256    ref_by_hdr = (pjsip_hdr*) 
    4256                  pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &str_ref_by,  
     4257                 pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &str_ref_by, 
    42574258                                            NULL); 
    42584259 
     
    42614262    if (pjsua_var.ua_cfg.cb.on_call_transfer_request) { 
    42624263        (*pjsua_var.ua_cfg.cb.on_call_transfer_request)(existing_call->index, 
    4263                                                         &refer_to->hvalue,  
     4264                                                        &refer_to->hvalue, 
    42644265                                                        &code); 
    42654266    } 
     
    42684269    if (pjsua_var.ua_cfg.cb.on_call_transfer_request2) { 
    42694270        (*pjsua_var.ua_cfg.cb.on_call_transfer_request2)(existing_call->index, 
    4270                                                          &refer_to->hvalue,  
     4271                                                         &refer_to->hvalue, 
    42714272                                                         &code, 
    42724273                                                         &call_opt); 
     
    42844285              (int)inv->dlg->remote.info_str.slen, 
    42854286              inv->dlg->remote.info_str.ptr, 
    4286               (int)refer_to->hvalue.slen,  
     4287              (int)refer_to->hvalue.slen, 
    42874288              refer_to->hvalue.ptr)); 
    42884289 
     
    42954296        pjsip_hdr *hdr; 
    42964297 
    4297         status = pjsip_dlg_create_response(inv->dlg, rdata, code, NULL,  
     4298        status = pjsip_dlg_create_response(inv->dlg, rdata, code, NULL, 
    42984299                                           &tdata); 
    42994300        if (status != PJ_SUCCESS) { 
     
    43044305 
    43054306        /* Add Refer-Sub header */ 
    4306         hdr = (pjsip_hdr*)  
     4307        hdr = (pjsip_hdr*) 
    43074308               pjsip_generic_string_hdr_create(tdata->pool, &str_refer_sub, 
    43084309                                              &str_false); 
     
    43484349            pjsip_hdr *hdr; 
    43494350 
    4350             hdr = (pjsip_hdr*)  
    4351                    pjsip_generic_string_hdr_create(inv->dlg->pool,  
     4351            hdr = (pjsip_hdr*) 
     4352                   pjsip_generic_string_hdr_create(inv->dlg->pool, 
    43524353                                                   &str_refer_sub, 
    43534354                                                   &str_true); 
     
    43634364                                    100, NULL, &tdata); 
    43644365        if (status != PJ_SUCCESS) { 
    4365             pjsua_perror(THIS_FILE, "Unable to create NOTIFY to REFER",  
     4366            pjsua_perror(THIS_FILE, "Unable to create NOTIFY to REFER", 
    43664367                         status); 
    43674368            goto on_return; 
     
    43794380     * We need to get a null terminated string from a pj_str_t. 
    43804381     * So grab the pointer from the hvalue and NULL terminate it, knowing 
    4381      * that the NULL position will be occupied by a newline.  
     4382     * that the NULL position will be occupied by a newline. 
    43824383     */ 
    43834384    uri = refer_to->hvalue.ptr; 
     
    43994400    tmp = pj_str(uri); 
    44004401    status = pjsua_call_make_call(existing_call->acc_id, &tmp, &call_opt, 
    4401                                   existing_call->user_data, &msg_data,  
     4402                                  existing_call->user_data, &msg_data, 
    44024403                                  &new_call); 
    44034404    if (status != PJ_SUCCESS) { 
     
    44084409                                       500, NULL, &tdata); 
    44094410            if (status != PJ_SUCCESS) { 
    4410                 pjsua_perror(THIS_FILE, "Unable to create NOTIFY to REFER",  
     4411                pjsua_perror(THIS_FILE, "Unable to create NOTIFY to REFER", 
    44114412                              status); 
    44124413                goto on_return; 
     
    44144415            status = pjsip_xfer_send_request(sub, tdata); 
    44154416            if (status != PJ_SUCCESS) { 
    4416                 pjsua_perror(THIS_FILE, "Unable to send NOTIFY to REFER",  
     4417                pjsua_perror(THIS_FILE, "Unable to send NOTIFY to REFER", 
    44174418                              status); 
    44184419                goto on_return; 
     
    44304431 
    44314432        /* Put the invite_data in the subscription. */ 
    4432         pjsip_evsub_set_mod_data(sub, pjsua_var.mod.id,  
     4433        pjsip_evsub_set_mod_data(sub, pjsua_var.mod.id, 
    44334434                                 &pjsua_var.calls[new_call]); 
    44344435    } 
     
    45124513            pj_list_push_back(&hdr_list, accept_hdr); 
    45134514 
    4514             pjsip_dlg_respond( inv->dlg, rdata, PJSIP_SC_NOT_ACCEPTABLE_HERE,  
     4515            pjsip_dlg_respond( inv->dlg, rdata, PJSIP_SC_NOT_ACCEPTABLE_HERE, 
    45154516                               NULL, &hdr_list, NULL ); 
    45164517            goto on_return; 
     
    45184519 
    45194520        /* Respond with 200 first, so that remote doesn't retransmit in case 
    4520          * the UI takes too long to process the message.  
     4521         * the UI takes too long to process the message. 
    45214522         */ 
    45224523        pjsip_dlg_respond( inv->dlg, rdata, 200, NULL, NULL, NULL); 
     
    46264627 
    46274628    if (pjsua_var.ua_cfg.cb.on_call_redirected) { 
    4628         op = (*pjsua_var.ua_cfg.cb.on_call_redirected)(call->index,  
     4629        op = (*pjsua_var.ua_cfg.cb.on_call_redirected)(call->index, 
    46294630                                                         target, e); 
    46304631    } else { 
  • pjproject/trunk/pjsip/src/test/tsx_uas_test.c

    r4420 r4728  
    11/* $Id$ */ 
    2 /*  
     2/* 
    33 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 
    44 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 
     
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1919 */ 
    2020 
     
    3131 ** 
    3232 ** This file performs various tests for UAC transactions. Each test will have 
    33  ** a different Via branch param so that message receiver module and  
     33 ** a different Via branch param so that message receiver module and 
    3434 ** transaction user module can identify which test is being carried out. 
    3535 ** 
     
    4848 ** 
    4949 ** TEST4_BRANCH_ID 
    50  **     Transaction retransmits last response (if any) without notifying  
     50 **     Transaction retransmits last response (if any) without notifying 
    5151 **     transaction user upon receiving request  retransmissions on TRYING 
    5252 **     state 
     
    6767 ** TEST9_BRANCH_ID 
    6868 **     INVITE transaction MUST cease retransmission of final response when 
    69  **     ACK is received. (Note: PJSIP also retransmit 2xx final response  
     69 **     ACK is received. (Note: PJSIP also retransmit 2xx final response 
    7070 **     until it's terminated by user). 
    7171 **     Transaction also MUST terminate in T4 seconds. 
     
    117117#define TEST4_REQUEST_COUNT     2 
    118118#define TEST5_PROVISIONAL_CODE  100 
    119 #define TEST5_STATUS_CODE       200      
     119#define TEST5_STATUS_CODE       200 
    120120#define TEST5_REQUEST_COUNT     2 
    121121#define TEST5_RESPONSE_COUNT    2 
     
    147147 
    148148/* UAC transaction user module. */ 
    149 static pjsip_module tsx_user =  
     149static pjsip_module tsx_user = 
    150150{ 
    151151    NULL, NULL,                         /* prev and next        */ 
     
    165165 
    166166/* Module to send request. */ 
    167 static pjsip_module msg_sender =  
     167static pjsip_module msg_sender = 
    168168{ 
    169169    NULL, NULL,                         /* prev and next        */ 
     
    242242    pjsip_tx_data *tdata; 
    243243 
    244     status = pjsip_endpt_create_response( endpt, rdata, status_code, NULL,  
     244    status = pjsip_endpt_create_response( endpt, rdata, status_code, NULL, 
    245245                                          &tdata); 
    246246    if (status != PJ_SUCCESS) { 
     
    272272    pj_time_val delay; 
    273273 
    274     status = pjsip_endpt_create_response( endpt, rdata, status_code, NULL,  
     274    status = pjsip_endpt_create_response( endpt, rdata, status_code, NULL, 
    275275                                          &tdata); 
    276276    if (status != PJ_SUCCESS) { 
     
    354354{ 
    355355    if (pj_stricmp2(&tsx->branch, TEST1_BRANCH_ID)==0 || 
    356         pj_stricmp2(&tsx->branch, TEST2_BRANCH_ID)==0)  
     356        pj_stricmp2(&tsx->branch, TEST2_BRANCH_ID)==0) 
    357357    { 
    358358        /* 
     
    375375                test_complete = -100; 
    376376            } 
    377              
     377 
    378378            /* Previous state must be completed. */ 
    379379            if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { 
     
    406406                test_complete = -110; 
    407407            } 
    408              
     408 
    409409            /* Previous state must be completed. */ 
    410410            if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { 
     
    466466            /* Check that status code is status_code. */ 
    467467            if (tsx->status_code != TEST4_STATUS_CODE) { 
    468                 PJ_LOG(3,(THIS_FILE,  
     468                PJ_LOG(3,(THIS_FILE, 
    469469                          "    error: incorrect status code %d " 
    470470                          "(expecting %d)", tsx->status_code, 
     
    472472                test_complete = -120; 
    473473            } 
    474              
     474 
    475475            /* Previous state. */ 
    476476            if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) { 
     
    479479            } 
    480480 
    481         } else if (tsx->state != PJSIP_TSX_STATE_DESTROYED)  
     481        } else if (tsx->state != PJSIP_TSX_STATE_DESTROYED) 
    482482        { 
    483483            PJ_LOG(3,(THIS_FILE, "    error: unexpected state %s (122)", 
     
    503503                test_complete = -130; 
    504504            } 
    505              
     505 
    506506            /* Previous state. */ 
    507507            if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_PROCEEDING) { 
     
    538538            if (tsx->status_code != TEST6_STATUS_CODE) { 
    539539                PJ_LOG(3,(THIS_FILE, "    error: incorrect status code %d " 
    540                           "(expecting %d)", tsx->status_code,  
     540                          "(expecting %d)", tsx->status_code, 
    541541                          TEST6_STATUS_CODE)); 
    542542                test_complete = -140; 
    543543            } 
    544              
     544 
    545545            /* Previous state. */ 
    546546            if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { 
     
    551551        } else if (tsx->state != PJSIP_TSX_STATE_PROCEEDING && 
    552552                   tsx->state != PJSIP_TSX_STATE_COMPLETED && 
    553                    tsx->state != PJSIP_TSX_STATE_DESTROYED)  
     553                   tsx->state != PJSIP_TSX_STATE_DESTROYED) 
    554554        { 
    555555            PJ_LOG(3,(THIS_FILE, "    error: unexpected state %s (142)", 
     
    562562    } else 
    563563    if (pj_stricmp2(&tsx->branch, TEST7_BRANCH_ID)==0 || 
    564         pj_stricmp2(&tsx->branch, TEST8_BRANCH_ID)==0)  
     564        pj_stricmp2(&tsx->branch, TEST8_BRANCH_ID)==0) 
    565565    { 
    566566        /* 
     
    588588                test_complete = -150; 
    589589            } 
    590              
     590 
    591591            /* Previous state. */ 
    592592            if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { 
     
    606606 
    607607                if (tsx->retransmit_count != 10) { 
    608                     PJ_LOG(3,(THIS_FILE,  
     608                    PJ_LOG(3,(THIS_FILE, 
    609609                              "    error: incorrect retransmit count %d " 
    610610                              "(expecting 10)", 
     
    622622                test_complete = -152; 
    623623            } 
    624              
     624 
    625625            /* Previous state. */ 
    626626            if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) { 
     
    657657                test_complete = -160; 
    658658            } 
    659              
     659 
    660660            /* Previous state. */ 
    661661            if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_CONFIRMED) { 
     
    671671                test_complete = -162; 
    672672            } 
    673              
     673 
    674674            /* Previous state. */ 
    675675            if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) { 
     
    686686                test_complete = -164; 
    687687            } 
    688              
     688 
    689689            /* Previous state. */ 
    690690            if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { 
     
    704704    if (pj_stricmp2(&tsx->branch, TEST10_BRANCH_ID)==0 || 
    705705        pj_stricmp2(&tsx->branch, TEST11_BRANCH_ID)==0 || 
    706         pj_stricmp2(&tsx->branch, TEST12_BRANCH_ID)==0)   
     706        pj_stricmp2(&tsx->branch, TEST12_BRANCH_ID)==0) 
    707707    { 
    708708        if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { 
    709              
     709 
    710710            if (!test_complete) 
    711711                test_complete = 1; 
     
    741741 
    742742    if (pj_stricmp2(&branch_param, TEST1_BRANCH_ID) == 0 || 
    743         pj_stricmp2(&branch_param, TEST2_BRANCH_ID) == 0)  
     743        pj_stricmp2(&branch_param, TEST2_BRANCH_ID) == 0) 
    744744    { 
    745745        /* 
    746          * TEST1_BRANCH_ID tests that non-INVITE transaction transmits 2xx  
    747          * final response using correct transport and terminates transaction  
     746         * TEST1_BRANCH_ID tests that non-INVITE transaction transmits 2xx 
     747         * final response using correct transport and terminates transaction 
    748748         * after 32 seconds. 
    749749         * 
     
    754754 
    755755        if (msg->type == PJSIP_REQUEST_MSG) { 
    756             /* On received request, create UAS and respond with final  
    757              * response.  
     756            /* On received request, create UAS and respond with final 
     757             * response. 
    758758             */ 
    759759            pjsip_transaction *tsx; 
     
    811811 
    812812            send_response(rdata, tsx, TEST3_PROVISIONAL_CODE); 
    813             schedule_send_response(rdata, &tsx->transaction_key,  
     813            schedule_send_response(rdata, &tsx->transaction_key, 
    814814                                   TEST3_STATUS_CODE, 2000); 
    815815 
     
    841841    } else if (pj_stricmp2(&branch_param, TEST4_BRANCH_ID) == 0 || 
    842842               pj_stricmp2(&branch_param, TEST5_BRANCH_ID) == 0 || 
    843                pj_stricmp2(&branch_param, TEST6_BRANCH_ID) == 0)  
     843               pj_stricmp2(&branch_param, TEST6_BRANCH_ID) == 0) 
    844844    { 
    845845 
     
    878878        } else { 
    879879            /* Verify the response received. */ 
    880              
     880 
    881881            PJ_LOG(4,(THIS_FILE, "    received response number %d", recv_count)); 
    882882 
     
    893893                    test_complete = -133; 
    894894 
    895                 }  
     895                } 
    896896                if (recv_count > TEST5_RESPONSE_COUNT) { 
    897897                    PJ_LOG(3,(THIS_FILE, "    error: not expecting response!")); 
     
    929929 
    930930    } else if (pj_stricmp2(&branch_param, TEST7_BRANCH_ID) == 0 || 
    931                pj_stricmp2(&branch_param, TEST8_BRANCH_ID) == 0)  
     931               pj_stricmp2(&branch_param, TEST8_BRANCH_ID) == 0) 
    932932    { 
    933933 
     
    972972 
    973973            if (recv_count==1) { 
    974                  
     974 
    975975                if (rdata->msg_info.msg->line.status.code != code) { 
    976976                    PJ_LOG(3,(THIS_FILE,"    error: invalid status code")); 
     
    988988 
    989989                PJ_TIME_VAL_SUB(now, recv_last); 
    990              
     990 
    991991                msec = now.sec*1000 + now.msec; 
    992992                msec_expected = (1 << (recv_count-2)) * pjsip_cfg()->tsx.t1; 
     
    10171017 
    10181018        /* 
    1019          * TEST9_BRANCH_ID tests that the retransmission of INVITE final  
     1019         * TEST9_BRANCH_ID tests that the retransmission of INVITE final 
    10201020         * response should cease when ACK is received. Transaction also MUST 
    10211021         * terminate in T4 seconds. 
     
    10601060 
    10611061                PJ_TIME_VAL_SUB(now, recv_last); 
    1062              
     1062 
    10631063                msec = now.sec*1000 + now.msec; 
    10641064                msec_expected = (1 << (recv_count-2)) * pjsip_cfg()->tsx.t1; 
     
    10821082 
    10831083                status = pjsip_endpt_create_request_from_hdr( 
    1084                             endpt, &pjsip_ack_method,  
     1084                            endpt, &pjsip_ack_method, 
    10851085                            rdata->msg_info.to->uri, 
    10861086                            rdata->msg_info.from, 
    10871087                            rdata->msg_info.to, 
    1088                             NULL,  
     1088                            NULL, 
    10891089                            rdata->msg_info.cid, 
    10901090                            rdata->msg_info.cseq->cseq, 
     
    11211121    } else if (pj_stricmp2(&branch_param, TEST10_BRANCH_ID) == 0 || 
    11221122               pj_stricmp2(&branch_param, TEST11_BRANCH_ID) == 0 || 
    1123                pj_stricmp2(&branch_param, TEST12_BRANCH_ID) == 0)  
     1123               pj_stricmp2(&branch_param, TEST12_BRANCH_ID) == 0) 
    11241124    { 
    11251125        int test_num, code1, code2; 
     
    11321132            test_num=12, code1 = 200, code2 = 0; 
    11331133 
     1134        PJ_UNUSED_ARG(test_num); 
     1135 
    11341136        if (rdata->msg_info.msg->type == PJSIP_REQUEST_MSG) { 
    11351137 
     
    11461148            pjsip_tsx_recv_msg(tsx, rdata); 
    11471149            save_key(tsx); 
    1148              
     1150 
    11491151            schedule_send_response(rdata, &tsx_key, code1, 1000); 
    11501152 
     
    11621164} 
    11631165 
    1164 /*  
    1165  * The generic test framework, used by most of the tests.  
     1166/* 
     1167 * The generic test framework, used by most of the tests. 
    11661168 */ 
    1167 static int perform_test( char *target_uri, char *from_uri,  
    1168                          char *branch_param, int test_time,  
     1169static int perform_test( char *target_uri, char *from_uri, 
     1170                         char *branch_param, int test_time, 
    11691171                         const pjsip_method *method, 
    11701172                         int request_cnt, int request_interval_msec, 
     
    11781180    pj_status_t status; 
    11791181 
    1180     PJ_LOG(3,(THIS_FILE,  
     1182    PJ_LOG(3,(THIS_FILE, 
    11811183              "   please standby, this will take at most %d seconds..", 
    11821184              test_time)); 
     
    11931195    /* Create request. */ 
    11941196    status = pjsip_endpt_create_request( endpt, method, &target, 
    1195                                          &from, &target, NULL, NULL, -1,  
     1197                                         &from, &target, NULL, NULL, -1, 
    11961198                                         NULL, &tdata); 
    11971199    if (status != PJ_SUCCESS) { 
     
    13691371 
    13701372    status = perform_test(TARGET_URI, FROM_URI, branch_id, 5, 
    1371                           &pjsip_options_method,  
     1373                          &pjsip_options_method, 
    13721374                          request_cnt, 1000, 1); 
    13731375    if (status && status != TEST_TIMEOUT_ERROR) 
     
    14231425/***************************************************************************** 
    14241426 ** 
    1425  ** TEST9_BRANCH_ID: retransmission of non-2xx INVITE final response must  
     1427 ** TEST9_BRANCH_ID: retransmission of non-2xx INVITE final response must 
    14261428 ** cease when ACK is received 
    14271429 ** 
     
    14641466        char *branch_id; 
    14651467        char *title; 
    1466     } tests[] =  
     1468    } tests[] = 
    14671469    { 
    14681470        { 0,  10,   TEST10_BRANCH_ID, "test10: failed transport in TRYING state (no delay)" }, 
     
    15381540    tp_flag = pjsip_transport_get_flag_from_type((pjsip_transport_type_e)param->type); 
    15391541 
    1540     pj_ansi_sprintf(TARGET_URI, "sip:bob@127.0.0.1:%d;transport=%s",  
     1542    pj_ansi_sprintf(TARGET_URI, "sip:bob@127.0.0.1:%d;transport=%s", 
    15411543                    param->port, param->tp_type); 
    1542     pj_ansi_sprintf(FROM_URI, "sip:alice@127.0.0.1:%d;transport=%s",  
     1544    pj_ansi_sprintf(FROM_URI, "sip:alice@127.0.0.1:%d;transport=%s", 
    15431545                    param->port, param->tp_type); 
    15441546 
    15451547    /* Check if loop transport is configured. */ 
    1546     status = pjsip_endpt_acquire_transport(endpt, PJSIP_TRANSPORT_LOOP_DGRAM,  
     1548    status = pjsip_endpt_acquire_transport(endpt, PJSIP_TRANSPORT_LOOP_DGRAM, 
    15471549                                      &addr, sizeof(addr), NULL, &loop); 
    15481550    if (status != PJ_SUCCESS) { 
     
    15621564    } 
    15631565 
    1564     /* TEST1_BRANCH_ID: Basic 2xx final response.  
    1565      * TEST2_BRANCH_ID: Basic non-2xx final response.  
     1566    /* TEST1_BRANCH_ID: Basic 2xx final response. 
     1567     * TEST2_BRANCH_ID: Basic non-2xx final response. 
    15661568     */ 
    15671569    status = tsx_basic_final_response_test(); 
     
    15781580     */ 
    15791581    status = tsx_retransmit_last_response_test(TEST4_TITLE, 
    1580                                                TEST4_BRANCH_ID,  
     1582                                               TEST4_BRANCH_ID, 
    15811583                                               TEST4_REQUEST_COUNT, 
    15821584                                               TEST4_STATUS_CODE); 
     
    15871589     */ 
    15881590    status = tsx_retransmit_last_response_test(TEST5_TITLE, 
    1589                                                TEST5_BRANCH_ID,  
     1591                                               TEST5_BRANCH_ID, 
    15901592                                               TEST5_REQUEST_COUNT, 
    15911593                                               TEST5_STATUS_CODE); 
     
    16001602    if ((tp_flag & PJSIP_TRANSPORT_RELIABLE) == 0) { 
    16011603        status = tsx_retransmit_last_response_test(TEST6_TITLE, 
    1602                                                    TEST6_BRANCH_ID,  
     1604                                                   TEST6_BRANCH_ID, 
    16031605                                                   TEST6_REQUEST_COUNT, 
    16041606                                                   TEST6_STATUS_CODE); 
     
    16141616        return status; 
    16151617 
    1616     /* TEST9_BRANCH_ID: retransmission of non-2xx INVITE final response must  
     1618    /* TEST9_BRANCH_ID: retransmission of non-2xx INVITE final response must 
    16171619     * cease when ACK is received 
    16181620     * Only applicable for non-reliable transports. 
  • pjproject/trunk/pjsip/src/test/uri_test.c

    r4641 r4728  
    11/* $Id$ */ 
    2 /*  
     2/* 
    33 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 
    44 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 
     
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1919 */ 
    2020#include "test.h" 
     
    6868static pjsip_uri *create_uri16( pj_pool_t *pool ); 
    6969static pjsip_uri *create_uri17( pj_pool_t *pool ); 
    70 static pjsip_uri *create_uri18( pj_pool_t *pool ); 
    7170static pjsip_uri *create_uri25( pj_pool_t *pool ); 
    7271static pjsip_uri *create_uri26( pj_pool_t *pool ); 
     
    9796    const char      *printed; 
    9897    pj_size_t        len; 
    99 } uri_test_array[] =  
     98} uri_test_array[] = 
    10099{ 
    101100    { 
     
    184183    { 
    185184        /* Excercise strange character sets allowed in display, user, password, 
    186          * host, and port.  
     185         * host, and port. 
    187186         */ 
    188187        PJ_SUCCESS, 
     
    198197    }, 
    199198    { 
    200         /* Another excercise to the allowed character sets to the username  
     199        /* Another excercise to the allowed character sets to the username 
    201200         * and password. 
    202201         */ 
     
    439438{ 
    440439    /* "sip:localhost;pickup=hurry;user=phone;message=I%20am%20sorry" 
    441        "?Subject=Hello%20There&Server=SIP%20Server"  
     440       "?Subject=Hello%20There&Server=SIP%20Server" 
    442441     */ 
    443442    pjsip_sip_uri *url = pjsip_sip_uri_create(pool, 0); 
     
    659658 
    660659    uri->number = pj_str("(44).1234-*#+Deaf"); 
    661     return (pjsip_uri*)uri;     
     660    return (pjsip_uri*)uri; 
    662661} 
    663662 
     
    669668    uri->number = pj_str("+1"); 
    670669    uri->isub_param = pj_str("/:@&$,-_.!~*'()[]/:&$aA1!+="); 
    671     return (pjsip_uri*)uri;     
     670    return (pjsip_uri*)uri; 
    672671} 
    673672 
     
    679678    uri->number = pj_str("+1"); 
    680679    uri->ext_param = pj_str("+123"); 
    681     return (pjsip_uri*)uri;     
     680    return (pjsip_uri*)uri; 
    682681} 
    683682 
     
    689688    uri->number = pj_str("911"); 
    690689    uri->context = pj_str("+1-911"); 
    691     return (pjsip_uri*)uri;     
     690    return (pjsip_uri*)uri; 
    692691} 
    693692 
     
    699698    uri->number = pj_str("911"); 
    700699    uri->context = pj_str("EMERGENCY.EXAMPLE.COM"); 
    701     return (pjsip_uri*)uri;     
     700    return (pjsip_uri*)uri; 
    702701} 
    703702 
     
    709708 
    710709    uri->number = pj_str("911"); 
    711      
     710 
    712711    p = PJ_POOL_ALLOC_T(pool, pjsip_param); 
    713712    p->name = p->value = pj_str("p1"); 
    714713    pj_list_insert_before(&uri->other_param, p); 
    715714 
    716     return (pjsip_uri*)uri;     
     715    return (pjsip_uri*)uri; 
    717716} 
    718717 
     
    750749    url = pjsip_sip_uri_create(pool, 0); 
    751750    url->host = pj_str("localhost"); 
    752      
     751 
    753752    name->uri = (pjsip_uri*)url; 
    754753 
     
    768767    url = pjsip_sip_uri_create(pool, 0); 
    769768    url->host = pj_str("localhost"); 
    770      
     769 
    771770    name->uri = (pjsip_uri*)url; 
    772771 
     
    1000999    avg_parse = 1000000 / avg_parse; 
    10011000 
    1002     PJ_LOG(3,(THIS_FILE,  
    1003               "    %u.%u MB of urls parsed in %d.%03ds (avg=%d urls/sec)",  
     1001    PJ_LOG(3,(THIS_FILE, 
     1002              "    %u.%u MB of urls parsed in %d.%03ds (avg=%d urls/sec)", 
    10041003              (unsigned)(var.parse_len/1000000), (unsigned)kbytes, 
    10051004              elapsed.sec, elapsed.msec, 
     
    10191018    avg_print = 1000000 / avg_print; 
    10201019 
    1021     PJ_LOG(3,(THIS_FILE,  
    1022               "    %u.%u MB of urls printed in %d.%03ds (avg=%d urls/sec)",  
     1020    PJ_LOG(3,(THIS_FILE, 
     1021              "    %u.%u MB of urls printed in %d.%03ds (avg=%d urls/sec)", 
    10231022              (unsigned)(var.print_len/1000000), (unsigned)kbytes, 
    10241023              elapsed.sec, elapsed.msec, 
     
    10381037    avg_cmp = 1000000 / avg_cmp; 
    10391038 
    1040     PJ_LOG(3,(THIS_FILE,  
    1041               "    %u.%u MB of urls compared in %d.%03ds (avg=%d urls/sec)",  
     1039    PJ_LOG(3,(THIS_FILE, 
     1040              "    %u.%u MB of urls compared in %d.%03ds (avg=%d urls/sec)", 
    10421041              (unsigned)(var.cmp_len/1000000), (unsigned)kbytes, 
    10431042              elapsed.sec, elapsed.msec, 
     
    10851084 
    10861085 
    1087     /*  
    1088      * Print maximum parse/sec  
     1086    /* 
     1087     * Print maximum parse/sec 
    10891088     */ 
    10901089    for (i=0, max=0; i<COUNT; ++i) 
  • pjproject/trunk/third_party/ilbc/LPCencode.c

    r638 r4728  
    225225       float lsf[LPC_FILTERORDER * LPC_N_MAX]; 
    226226       float lsfdeq[LPC_FILTERORDER * LPC_N_MAX]; 
    227        int change=0; 
    228227 
    229228       SimpleAnalysis(lsf, data, iLBCenc_inst); 
     
    234233 
    235234 
    236        change=LSF_check(lsfdeq, LPC_FILTERORDER, iLBCenc_inst->lpc_n); 
     235       LSF_check(lsfdeq, LPC_FILTERORDER, iLBCenc_inst->lpc_n); 
    237236       SimpleInterpolateLSF(syntdenum, weightdenum, 
    238237           lsf, lsfdeq, iLBCenc_inst->lsfold, 
  • pjproject/trunk/third_party/ilbc/helpfun.c

    r638 r4728  
    278278   ){ 
    279279       int k,n,m, Nit=2, change=0,pos; 
    280        float tmp; 
     280       //float tmp; 
    281281       static float eps=(float)0.039; /* 50 Hz */ 
    282282       static float eps2=(float)0.0195; 
     
    294294 
    295295                       if (lsf[pos+1]<lsf[pos]) { 
    296                            tmp=lsf[pos+1]; 
     296                           //tmp=lsf[pos+1]; 
    297297                           lsf[pos+1]= lsf[pos]+eps2; 
    298298                           lsf[pos]= lsf[pos+1]-eps2; 
  • pjproject/trunk/third_party/ilbc/iLBC_decode.c

    r638 r4728  
    340340       float cc, maxcc; 
    341341       int idxVec[STATE_LEN]; 
    342        int check; 
    343342       int gain_index[NASUB_MAX*CB_NSTAGES], 
    344343           extra_gain_index[CB_NSTAGES]; 
     
    501500 
    502501               SimplelsfDEQ(lsfdeq, lsf_i, iLBCdec_inst->lpc_n); 
    503                check=LSF_check(lsfdeq, LPC_FILTERORDER, 
     502               LSF_check(lsfdeq, LPC_FILTERORDER, 
    504503                   iLBCdec_inst->lpc_n); 
    505504               DecoderInterpolateLSF(syntdenum, weightdenum, 
  • pjproject/trunk/third_party/resample/src/resamplesubs.c

    r3085 r4728  
    77 * 
    88 * Snippet from the resample.1 man page: 
    9  *  
     9 * 
    1010 * HISTORY 
    1111 * 
     
    1414 * 1981.  It was called SRCONV and was written in SAIL for PDP-10 
    1515 * compatible machines.  The algorithm was first published in 
    16  *  
     16 * 
    1717 * Smith, Julius O. and Phil Gossett. ``A Flexible Sampling-Rate 
    1818 * Conversion Method,'' Proceedings (2): 19.4.1-19.4.4, IEEE Conference 
    1919 * on Acoustics, Speech, and Signal Processing, San Diego, March 1984. 
    20  *  
     20 * 
    2121 * An expanded tutorial based on this paper is available at the Digital 
    2222 * Audio Resampling Home Page given above. 
    23  *  
     23 * 
    2424 * Circa 1988, the SRCONV program was translated from SAIL to C by 
    2525 * Christopher Lee Fraley working with Roger Dannenberg at CMU. 
    26  *  
     26 * 
    2727 * Since then, the C version has been maintained by jos. 
    28  *  
     28 * 
    2929 * Sndlib support was added 6/99 by John Gibson <jgg9c@virginia.edu>. 
    30  *  
     30 * 
    3131 * The resample program is free software distributed in accordance 
    3232 * with the Lesser GNU Public License (LGPL).  There is NO warranty; not 
     
    7878#undef INLINE 
    7979#define INLINE 
    80 #define HAVE_FILTER 0     
     80#define HAVE_FILTER 0 
    8181 
    8282#ifndef NULL 
     
    9595    } else if (v < MIN_HWORD) { 
    9696        v = MIN_HWORD; 
    97     }    
     97    } 
    9898    out = (RES_HWORD) v; 
    9999    return out; 
     
    102102/* Sampling rate conversion using linear interpolation for maximum speed. 
    103103 */ 
    104 static int  
     104static int 
    105105  SrcLinear(const RES_HWORD X[], RES_HWORD Y[], double pFactor, RES_UHWORD nx) 
    106106{ 
     
    110110    RES_HWORD *Ystart, *Yend; 
    111111    RES_WORD v,x1,x2; 
    112      
    113     double dt;                  /* Step through input signal */  
     112 
     113    double dt;                  /* Step through input signal */ 
    114114    RES_UWORD dtb;                  /* Fixed-point version of Dt */ 
    115     RES_UWORD endTime;              /* When time reaches EndTime, return to user */ 
    116      
     115    //RES_UWORD endTime;              /* When time reaches EndTime, return to user */ 
     116 
    117117    dt = 1.0/pFactor;            /* Output sampling period */ 
    118118    dtb = dt*(1<<Np) + 0.5;     /* Fixed-point representation */ 
    119      
     119 
    120120    Ystart = Y; 
    121121    Yend = Ystart + (unsigned)(nx * pFactor + 0.5); 
    122     endTime = time + (1<<Np)*(RES_WORD)nx; 
    123      
    124     // Integer round down in dtb calculation may cause (endTime % dtb > 0),  
     122    //endTime = time + (1<<Np)*(RES_WORD)nx; 
     123 
     124    // Integer round down in dtb calculation may cause (endTime % dtb > 0), 
    125125    // so it may cause resample write pass the output buffer (Y >= Yend). 
    126126    // while (time < endTime) 
     
    140140} 
    141141 
    142 static RES_WORD FilterUp(const RES_HWORD Imp[], const RES_HWORD ImpD[],  
     142static RES_WORD FilterUp(const RES_HWORD Imp[], const RES_HWORD ImpD[], 
    143143                     RES_UHWORD Nwing, RES_BOOL Interp, 
    144144                     const RES_HWORD *Xp, RES_HWORD Ph, RES_HWORD Inc) 
     
    149149    RES_HWORD a = 0; 
    150150    RES_WORD v, t; 
    151      
     151 
    152152    v=0; 
    153153    Hp = &Imp[Ph>>Na]; 
     
    179179 
    180180          Xp += Inc;            /* Input signal step. NO CHECK ON BOUNDS */ 
    181       }  
    182     else  
     181      } 
     182    else 
    183183      while (Hp < End) { 
    184184          t = *Hp;              /* Get filter coeff */ 
     
    203203    RES_WORD v, t; 
    204204    RES_UWORD Ho; 
    205      
     205 
    206206    v=0; 
    207207    Ho = (Ph*(RES_UWORD)dhb)>>Np; 
     
    228228          Xp += Inc;            /* Input signal step. NO CHECK ON BOUNDS */ 
    229229      } 
    230     else  
     230    else 
    231231      while ((Hp = &Imp[Ho>>Na]) < End) { 
    232232          t = *Hp;              /* Get IR sample */ 
     
    245245 * Slightly faster than down-conversion; 
    246246 */ 
    247 static int SrcUp(const RES_HWORD X[], RES_HWORD Y[], double pFactor,  
     247static int SrcUp(const RES_HWORD X[], RES_HWORD Y[], double pFactor, 
    248248                 RES_UHWORD nx, RES_UHWORD pNwing, RES_UHWORD pLpScl, 
    249249                 const RES_HWORD pImp[], const RES_HWORD pImpD[], RES_BOOL Interp) 
     
    252252    RES_HWORD *Ystart, *Yend; 
    253253    RES_WORD v; 
    254      
    255     double dt;                  /* Step through input signal */  
     254 
     255    double dt;                  /* Step through input signal */ 
    256256    RES_UWORD dtb;                  /* Fixed-point version of Dt */ 
    257257    RES_UWORD time = 0; 
    258     RES_UWORD endTime;              /* When time reaches EndTime, return to user */ 
    259      
     258    //RES_UWORD endTime;              /* When time reaches EndTime, return to user */ 
     259 
    260260    dt = 1.0/pFactor;            /* Output sampling period */ 
    261261    dtb = dt*(1<<Np) + 0.5;     /* Fixed-point representation */ 
    262      
     262 
    263263    Ystart = Y; 
    264264    Yend = Ystart + (unsigned)(nx * pFactor + 0.5); 
    265     endTime = time + (1<<Np)*(RES_WORD)nx; 
    266  
    267     // Integer round down in dtb calculation may cause (endTime % dtb > 0),  
     265    //endTime = time + (1<<Np)*(RES_WORD)nx; 
     266 
     267    // Integer round down in dtb calculation may cause (endTime % dtb > 0), 
    268268    // so it may cause resample write pass the output buffer (Y >= Yend). 
    269269    // while (time < endTime) 
     
    289289/* Sampling rate conversion subroutine */ 
    290290 
    291 static int SrcUD(const RES_HWORD X[], RES_HWORD Y[], double pFactor,  
     291static int SrcUD(const RES_HWORD X[], RES_HWORD Y[], double pFactor, 
    292292                 RES_UHWORD nx, RES_UHWORD pNwing, RES_UHWORD pLpScl, 
    293293                 const RES_HWORD pImp[], const RES_HWORD pImpD[], RES_BOOL Interp) 
     
    296296    RES_HWORD *Ystart, *Yend; 
    297297    RES_WORD v; 
    298      
     298 
    299299    double dh;                  /* Step through filter impulse response */ 
    300300    double dt;                  /* Step through input signal */ 
    301301    RES_UWORD time = 0; 
    302     RES_UWORD endTime;          /* When time reaches EndTime, return to user */ 
     302    //RES_UWORD endTime;          /* When time reaches EndTime, return to user */ 
    303303    RES_UWORD dhb, dtb;         /* Fixed-point versions of Dh,Dt */ 
    304      
     304 
    305305    dt = 1.0/pFactor;            /* Output sampling period */ 
    306306    dtb = dt*(1<<Np) + 0.5;     /* Fixed-point representation */ 
    307      
     307 
    308308    dh = MIN(Npc, pFactor*Npc);  /* Filter sampling period */ 
    309309    dhb = dh*(1<<Na) + 0.5;     /* Fixed-point representation */ 
    310      
     310 
    311311    Ystart = Y; 
    312312    Yend = Ystart + (unsigned)(nx * pFactor + 0.5); 
    313     endTime = time + (1<<Np)*(RES_WORD)nx; 
    314  
    315     // Integer round down in dtb calculation may cause (endTime % dtb > 0),  
     313    //endTime = time + (1<<Np)*(RES_WORD)nx; 
     314 
     315    // Integer round down in dtb calculation may cause (endTime % dtb > 0), 
    316316    // so it may cause resample write pass the output buffer (Y >= Yend). 
    317317    // while (time < endTime) 
     
    332332 
    333333 
    334 DECL(int) res_SrcLinear(const RES_HWORD X[], RES_HWORD Y[],  
     334DECL(int) res_SrcLinear(const RES_HWORD X[], RES_HWORD Y[], 
    335335                        double pFactor, RES_UHWORD nx) 
    336336{ 
     
    338338} 
    339339 
    340 DECL(int) res_Resample(const RES_HWORD X[], RES_HWORD Y[], double pFactor,  
     340DECL(int) res_Resample(const RES_HWORD X[], RES_HWORD Y[], double pFactor, 
    341341                       RES_UHWORD nx, RES_BOOL LargeF, RES_BOOL Interp) 
    342342{ 
     
    355355 
    356356        if (LargeF) 
    357             return SrcUD(X, Y, pFactor, nx,  
     357            return SrcUD(X, Y, pFactor, nx, 
    358358                         LARGE_FILTER_NWING, LARGE_FILTER_SCALE * pFactor + 0.5, 
    359359                         LARGE_FILTER_IMP, LARGE_FILTER_IMPD, Interp); 
    360360        else 
    361             return SrcUD(X, Y, pFactor, nx,  
     361            return SrcUD(X, Y, pFactor, nx, 
    362362                         SMALL_FILTER_NWING, SMALL_FILTER_SCALE * pFactor + 0.5, 
    363363                         SMALL_FILTER_IMP, SMALL_FILTER_IMPD, Interp); 
     
    369369{ 
    370370    if (LargeF) 
    371         return (LARGE_FILTER_NMULT + 1) / 2.0  *   
     371        return (LARGE_FILTER_NMULT + 1) / 2.0  * 
    372372                MAX(1.0, 1.0/pFactor); 
    373373    else 
    374         return (SMALL_FILTER_NMULT + 1) / 2.0  *   
     374        return (SMALL_FILTER_NMULT + 1) / 2.0  * 
    375375                MAX(1.0, 1.0/pFactor); 
    376376} 
Note: See TracChangeset for help on using the changeset viewer.