Ignore:
Timestamp:
Mar 5, 2006 11:54:02 AM (18 years ago)
Author:
bennylp
Message:

Added complexity and quality argument, and terminate dialog properly on failures

File:
1 edited

Legend:

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

    r268 r284  
    3838{ 
    3939    pj_str_t dest_uri; 
    40     pjsip_dialog *dlg; 
     40    pjsip_dialog *dlg = NULL; 
    4141    pjmedia_sdp_session *offer; 
    42     pjsip_inv_session *inv; 
     42    pjsip_inv_session *inv = NULL; 
    4343    int call_index = -1; 
    4444    pjsip_tx_data *tdata; 
     
    142142 
    143143on_error: 
    144     PJ_TODO(DESTROY_DIALOG_ON_FAIL); 
     144    if (inv != NULL) { 
     145        pjsip_inv_terminate(inv, PJSIP_SC_OK, PJ_FALSE); 
     146    } else { 
     147        pjsip_dlg_terminate(dlg); 
     148    } 
     149 
    145150    if (call_index != -1) { 
    146151        pjsua.calls[call_index].inv = NULL; 
     
    160165    pjsip_tx_data *response = NULL; 
    161166    unsigned options = 0; 
    162     pjsip_inv_session *inv; 
     167    pjsip_inv_session *inv = NULL; 
    163168    int acc_index; 
    164169    int call_index = -1; 
     
    261266 
    262267        pjsip_dlg_respond(dlg, rdata, 500, NULL, NULL, NULL); 
    263  
    264         // TODO: Need to delete dialog 
     268        pjsip_dlg_terminate(dlg); 
    265269        return PJ_TRUE; 
    266270    } 
     
    287291 
    288292        pjsip_dlg_respond(dlg, rdata, 500, NULL, NULL, NULL); 
    289  
    290         // TODO: Need to delete dialog 
     293        pjsip_inv_terminate(inv, 500, PJ_FALSE); 
    291294 
    292295    } else { 
     
    723726} 
    724727 
     728/* Disconnect call */ 
     729static void call_disconnect(pjsip_inv_session *inv, 
     730                            int st_code) 
     731{ 
     732    pjsip_tx_data *tdata; 
     733    pj_status_t status; 
     734 
     735    status = pjsip_inv_end_session(inv, st_code, NULL, &tdata); 
     736    if (status == PJ_SUCCESS) 
     737        status = pjsip_inv_send_msg(inv, tdata, NULL); 
     738 
     739    if (status != PJ_SUCCESS) { 
     740        pjsua_perror(THIS_FILE, "Unable to disconnect call", status); 
     741    } 
     742} 
    725743 
    726744/* 
     
    744762 
    745763        pjsua_perror(THIS_FILE, "SDP negotiation has failed", status); 
     764 
     765        /* Disconnect call if this is not a re-INVITE */ 
     766        if (inv->state != PJSIP_INV_STATE_CONFIRMED) { 
     767            call_disconnect(inv, PJSIP_SC_UNSUPPORTED_MEDIA_TYPE); 
     768        } 
    746769        return; 
    747770 
     
    763786                     "Unable to retrieve currently active local SDP",  
    764787                     status); 
     788        call_disconnect(inv, PJSIP_SC_UNSUPPORTED_MEDIA_TYPE); 
    765789        return; 
    766790    } 
     
    772796                     "Unable to retrieve currently active remote SDP",  
    773797                     status); 
     798        call_disconnect(inv, PJSIP_SC_UNSUPPORTED_MEDIA_TYPE); 
    774799        return; 
    775800    } 
     
    789814        pjsua_perror(THIS_FILE, "Unable to create media session",  
    790815                     status); 
     816        call_disconnect(inv, PJSIP_SC_UNSUPPORTED_MEDIA_TYPE); 
    791817        return; 
    792818    } 
     
    818844        pjmedia_session_destroy(call->session); 
    819845        call->session = NULL; 
     846        call_disconnect(inv, PJSIP_SC_INTERNAL_SERVER_ERROR); 
    820847        return; 
    821848    } 
     
    910937 * Hangup call. 
    911938 */ 
    912 void pjsua_call_hangup(int call_index, int code) 
     939void pjsua_call_hangup(int call_index) 
    913940{ 
    914941    pjsua_call *call; 
     942    int code; 
    915943    pj_status_t status; 
    916944    pjsip_tx_data *tdata; 
     
    923951        return; 
    924952    } 
     953 
     954    if (call->inv->state == PJSIP_INV_STATE_CONFIRMED) 
     955        code = PJSIP_SC_OK; 
     956    else if (call->inv->role == PJSIP_ROLE_UAS) 
     957        code = PJSIP_SC_DECLINE; 
     958    else 
     959        code = PJSIP_SC_REQUEST_TERMINATED; 
    925960 
    926961    status = pjsip_inv_end_session(call->inv, code, NULL, &tdata); 
     
    11901225 * Terminate all calls. 
    11911226 */ 
    1192 void pjsua_call_hangup_all() 
     1227void pjsua_call_hangup_all(void) 
    11931228{ 
    11941229    int i; 
     
    11961231    for (i=0; i<pjsua.max_calls; ++i) { 
    11971232        pjsip_tx_data *tdata; 
     1233        int st_code; 
    11981234        pjsua_call *call; 
    11991235 
     
    12031239        call = &pjsua.calls[i]; 
    12041240 
    1205         if (pjsip_inv_end_session(call->inv, 410, NULL, &tdata)==0) { 
     1241        if (call->inv->state == PJSIP_INV_STATE_CONFIRMED) { 
     1242            st_code = 200; 
     1243        } else { 
     1244            st_code = PJSIP_SC_GONE; 
     1245        } 
     1246 
     1247        if (pjsip_inv_end_session(call->inv, st_code, NULL, &tdata)==0) { 
    12061248            if (tdata) 
    12071249                pjsip_inv_send_msg(call->inv, tdata, NULL); 
Note: See TracChangeset for help on using the changeset viewer.