Ignore:
Timestamp:
Nov 27, 2008 12:06:46 AM (15 years ago)
Author:
bennylp
Message:

Ticket #10: handle redirection response in the invite session

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c

    r2315 r2370  
    6565                                            pjsip_transaction *tsx, 
    6666                                            pjsip_event *e); 
     67 
     68/* 
     69 * Redirection handler. 
     70 */ 
     71static void pjsua_call_on_redirected(pjsip_inv_session *inv,  
     72                                     const pjsip_uri *target, 
     73                                     pjsip_redirect_op *cmd,  
     74                                     const pjsip_event *e); 
    6775 
    6876 
     
    157165    inv_cb.on_create_offer = &pjsua_call_on_create_offer; 
    158166    inv_cb.on_tsx_state_changed = &pjsua_call_on_tsx_state_changed; 
    159  
     167    inv_cb.on_redirected = &pjsua_call_on_redirected; 
    160168 
    161169    /* Initialize invite session module: */ 
     
    14311439 
    14321440    return PJ_SUCCESS; 
     1441} 
     1442 
     1443 
     1444/* 
     1445 * Accept or reject redirection. 
     1446 */ 
     1447PJ_DEF(pj_status_t) pjsua_call_process_redirect( pjsua_call_id call_id, 
     1448                                                 pjsip_redirect_op cmd) 
     1449{ 
     1450    pjsua_call *call; 
     1451    pjsip_dialog *dlg; 
     1452    pj_status_t status; 
     1453 
     1454    PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls, 
     1455                     PJ_EINVAL); 
     1456 
     1457    status = acquire_call("pjsua_call_process_redirect()", call_id,  
     1458                          &call, &dlg); 
     1459    if (status != PJ_SUCCESS) 
     1460        return status; 
     1461 
     1462    status = pjsip_inv_process_redirect(call->inv, cmd, NULL); 
     1463 
     1464    pjsip_dlg_dec_lock(dlg); 
     1465 
     1466    return status; 
    14331467} 
    14341468 
     
    28282862            if (call->res_time.sec == 0) 
    28292863                pj_gettimeofday(&call->res_time); 
    2830             if (e->body.tsx_state.tsx->status_code > call->last_code) { 
     2864            if (e->type == PJSIP_EVENT_TSX_STATE &&  
     2865                e->body.tsx_state.tsx->status_code > call->last_code)  
     2866            { 
    28312867                call->last_code = (pjsip_status_code)  
    28322868                                  e->body.tsx_state.tsx->status_code; 
    28332869                pj_strncpy(&call->last_text,  
    28342870                           &e->body.tsx_state.tsx->status_text, 
     2871                           sizeof(call->last_text_buf_)); 
     2872            } else { 
     2873                call->last_code = PJSIP_SC_REQUEST_TERMINATED; 
     2874                pj_strncpy(&call->last_text, 
     2875                           pjsip_get_status_text(call->last_code), 
    28352876                           sizeof(call->last_text_buf_)); 
    28362877            } 
     
    37713812    PJSUA_UNLOCK(); 
    37723813} 
     3814 
     3815 
     3816/* Redirection handler */ 
     3817static void pjsua_call_on_redirected(pjsip_inv_session *inv,  
     3818                                     const pjsip_uri *target, 
     3819                                     pjsip_redirect_op *cmd,  
     3820                                     const pjsip_event *e) 
     3821{ 
     3822    pjsua_call *call = (pjsua_call*) inv->dlg->mod_data[pjsua_var.mod.id]; 
     3823 
     3824    PJSUA_LOCK(); 
     3825 
     3826    if (pjsua_var.ua_cfg.cb.on_call_redirected) { 
     3827        (*pjsua_var.ua_cfg.cb.on_call_redirected)(call->index, target, cmd, e); 
     3828    } else { 
     3829        PJ_LOG(4,(THIS_FILE, "Unhandled redirection for call %d " 
     3830                  "(callback not implemented by application). Disconnecting " 
     3831                  "call.", 
     3832                  call->index)); 
     3833        *cmd = PJSIP_REDIRECT_STOP; 
     3834    } 
     3835 
     3836    PJSUA_UNLOCK(); 
     3837} 
     3838 
Note: See TracChangeset for help on using the changeset viewer.