Ignore:
Timestamp:
Feb 7, 2006 12:34:11 PM (18 years ago)
Author:
bennylp
Message:

Initial implementation of invite session abstraction, and updated pjsua for the new framework

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip/sip_dialog.c

    r132 r139  
    3838#define THIS_FILE       "sip_dialog.c" 
    3939 
     40long pjsip_dlg_lock_tls_id; 
    4041 
    4142PJ_DEF(pj_bool_t) pjsip_method_creates_dialog(const pjsip_method *m) 
     
    7374    pj_sprintf(dlg->obj_name, "dlg%p", dlg); 
    7475    dlg->ua = ua; 
     76    dlg->endpt = endpt; 
    7577 
    7678    status = pj_mutex_create_recursive(pool, "dlg%p", &dlg->mutex); 
     
    9395    if (dlg->mutex) 
    9496        pj_mutex_destroy(dlg->mutex); 
    95     pjsip_endpt_release_pool(pjsip_ua_get_endpt(dlg->ua), dlg->pool); 
     97    pjsip_endpt_release_pool(dlg->endpt, dlg->pool); 
    9698} 
    9799 
     
    145147    /* Randomize local CSeq. */ 
    146148    dlg->local.first_cseq = pj_rand() % 0x7FFFFFFFL; 
    147     dlg->local.cseq = dlg->local.cseq; 
     149    dlg->local.cseq = dlg->local.first_cseq; 
    148150 
    149151    /* Init local contact. */ 
     
    184186 
    185187    /* Init client authentication session. */ 
    186     status = pjsip_auth_clt_init(&dlg->auth_sess, pjsip_ua_get_endpt(ua),  
     188    status = pjsip_auth_clt_init(&dlg->auth_sess, dlg->endpt,  
    187189                                 dlg->pool, 0); 
    188190    if (status != PJ_SUCCESS) 
     
    343345 
    344346    /* Init client authentication session. */ 
    345     status = pjsip_auth_clt_init(&dlg->auth_sess, pjsip_ua_get_endpt(ua), 
     347    status = pjsip_auth_clt_init(&dlg->auth_sess, dlg->endpt, 
    346348                                 dlg->pool, 0); 
    347349    if (status != PJ_SUCCESS) 
     
    507509    } 
    508510 
     511    /* Log */ 
     512    PJ_LOG(5,(dlg->obj_name, "Dialog destroyed")); 
     513 
    509514    /* Destroy this dialog. */ 
    510515    pj_mutex_destroy(dlg->mutex); 
    511     pjsip_endpt_release_pool(pjsip_ua_get_endpt(dlg->ua), dlg->pool); 
     516    pjsip_endpt_release_pool(dlg->endpt, dlg->pool); 
    512517 
    513518    return PJ_SUCCESS; 
     
    630635    dlg->mod_data[mod->id] = mod_data; 
    631636 
     637    /* Increment count. */ 
     638    ++dlg->usage_cnt; 
     639 
    632640    pj_mutex_unlock(dlg->mutex); 
    633641 
     
    664672     * dialog. 
    665673     */ 
    666     status = pjsip_endpt_create_request_from_hdr(pjsip_ua_get_endpt(dlg->ua), 
     674    status = pjsip_endpt_create_request_from_hdr(dlg->endpt, 
    667675                                                 method, 
    668676                                                 dlg->target, 
     
    810818        } 
    811819 
    812         *p_tsx = tsx; 
     820        if (p_tsx) 
     821            *p_tsx = tsx; 
    813822 
    814823    } else { 
    815         status = pjsip_endpt_send_request_stateless( 
    816                     pjsip_ua_get_endpt(dlg->ua), tdata, NULL, NULL); 
     824        status = pjsip_endpt_send_request_stateless(dlg->endpt, tdata,  
     825                                                    NULL, NULL); 
    817826        if (status != PJ_SUCCESS) 
    818827            goto on_error; 
    819828 
    820         *p_tsx = NULL; 
     829        if (p_tsx) 
     830            *p_tsx = NULL; 
    821831    } 
    822832 
     
    833843    pjsip_tx_data_dec_ref( tdata ); 
    834844 
    835     *p_tsx = NULL; 
     845    if (p_tsx) 
     846        *p_tsx = NULL; 
    836847    return status; 
    837848} 
     
    853864 
    854865    /* Create generic response. */ 
    855     status = pjsip_endpt_create_response(pjsip_ua_get_endpt(dlg->ua), 
     866    status = pjsip_endpt_create_response(dlg->endpt, 
    856867                                         rdata, st_code, st_text, &tdata); 
    857868    if (status != PJ_SUCCESS) 
     
    915926        if (st_class==2 || st_code==405) { 
    916927            const pjsip_hdr *c_hdr; 
    917             c_hdr = pjsip_endpt_get_capability(pjsip_ua_get_endpt(dlg->ua), 
     928            c_hdr = pjsip_endpt_get_capability(dlg->endpt, 
    918929                                               PJSIP_H_ALLOW, NULL); 
    919930            if (c_hdr) { 
     
    926937        if (st_class==2) { 
    927938            const pjsip_hdr *c_hdr; 
    928             c_hdr = pjsip_endpt_get_capability(pjsip_ua_get_endpt(dlg->ua), 
     939            c_hdr = pjsip_endpt_get_capability(dlg->endpt, 
    929940                                               PJSIP_H_SUPPORTED, NULL); 
    930941            if (c_hdr) { 
     
    10571068         */ 
    10581069        pj_mutex_unlock(dlg->mutex); 
    1059         pjsip_endpt_respond_stateless(pjsip_ua_get_endpt(dlg->ua), 
     1070        pjsip_endpt_respond_stateless(dlg->endpt, 
    10601071                                      rdata, 500, NULL, NULL, NULL); 
    10611072        return; 
     
    10951106                  "Dialog will response with 500 (Internal Server Error)", 
    10961107                  pjsip_rx_data_get_info(rdata))); 
    1097         status = pjsip_endpt_create_response(pjsip_ua_get_endpt(dlg->ua),  
     1108        status = pjsip_endpt_create_response(dlg->endpt,  
    10981109                                             rdata,  
    10991110                                             PJSIP_SC_INTERNAL_SERVER_ERROR,  
     
    11261137    pj_mutex_lock(dlg->mutex); 
    11271138 
     1139    /* Check that rdata already has dialog in mod_data. */ 
     1140    pj_assert(pjsip_rdata_get_dlg(rdata) == dlg); 
     1141 
    11281142    /* Update the remote tag, if none is specified yet. */ 
    11291143    if (dlg->remote.info->tag.slen == 0 && rdata->msg_info.to->tag.slen != 0) { 
     
    11341148    } 
    11351149 
    1136     /* Check that rdata already has dialog in mod_data. */ 
    1137     pj_assert(pjsip_rdata_get_dlg(rdata) == dlg); 
     1150    /* Update remote target when receiving certain response messages. */ 
     1151    if (pjsip_method_creates_dialog(&rdata->msg_info.cseq->method) && 
     1152        rdata->msg_info.msg->line.status.code/100 == 2) 
     1153    { 
     1154        pjsip_contact_hdr *contact; 
     1155 
     1156        contact = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT,  
     1157                                     NULL); 
     1158        if (contact) { 
     1159            dlg->remote.contact = pjsip_hdr_clone(dlg->pool, contact); 
     1160            dlg->target = dlg->remote.contact->uri; 
     1161        } 
     1162    } 
    11381163 
    11391164    /* Pass to dialog usages. */ 
     
    11861211        dlg->sess_count == 0)  
    11871212    { 
     1213        /* Unregister this dialog from the transaction. */ 
     1214        tsx->mod_data[dlg->ua->id] = NULL; 
     1215 
    11881216        /* Time to destroy dialog. */ 
    11891217        unregister_and_destroy_dialog(dlg); 
Note: See TracChangeset for help on using the changeset viewer.