Ignore:
Timestamp:
Feb 19, 2006 3:37:19 PM (18 years ago)
Author:
bennylp
Message:

SIMPLE test with FWD, and added more info in UI

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip-ua/sip_reg.c

    r167 r201  
    2626#include <pjsip/sip_auth_msg.h> 
    2727#include <pjsip/sip_errno.h> 
     28#include <pj/assert.h> 
     29#include <pj/guid.h> 
     30#include <pj/os.h> 
    2831#include <pj/pool.h> 
     32#include <pj/log.h> 
    2933#include <pj/string.h> 
    30 #include <pj/guid.h> 
    31 #include <pj/log.h> 
    32 #include <pj/assert.h> 
    3334 
    3435 
     
    5455    pjsip_cid_hdr               *cid_hdr; 
    5556    pjsip_cseq_hdr              *cseq_hdr; 
     57    pj_str_t                     from_uri; 
    5658    pjsip_from_hdr              *from_hdr; 
    5759    pjsip_to_hdr                *to_hdr; 
     
    6971    /* Auto refresh registration. */ 
    7072    pj_bool_t                    auto_reg; 
     73    pj_time_val                  last_reg; 
     74    pj_time_val                  next_reg; 
    7175    pj_timer_entry               timer; 
    7276}; 
     
    111115PJ_DEF(pj_status_t) pjsip_regc_destroy(pjsip_regc *regc) 
    112116{ 
     117    PJ_ASSERT_RETURN(regc, PJ_EINVAL); 
     118 
    113119    if (regc->pending_tsx) { 
    114120        regc->_delete_flag = 1; 
     
    116122    } else { 
    117123        pjsip_endpt_release_pool(regc->endpt, regc->pool); 
     124    } 
     125 
     126    return PJ_SUCCESS; 
     127} 
     128 
     129 
     130PJ_DEF(pj_status_t) pjsip_regc_get_info( pjsip_regc *regc, 
     131                                         pjsip_regc_info *info ) 
     132{ 
     133    PJ_ASSERT_RETURN(regc && info, PJ_EINVAL); 
     134 
     135    info->server_uri = regc->str_srv_url; 
     136    info->client_uri = regc->from_uri; 
     137    info->is_busy = (regc->pending_tsx != 0); 
     138    info->auto_reg = regc->auto_reg; 
     139    info->interval = regc->expires; 
     140     
     141    if (regc->pending_tsx) 
     142        info->next_reg = 0; 
     143    else if (regc->auto_reg == 0) 
     144        info->next_reg = 0; 
     145    else if (regc->expires < 0) 
     146        info->next_reg = regc->expires; 
     147    else { 
     148        pj_time_val now, next_reg; 
     149 
     150        next_reg = regc->next_reg; 
     151        pj_gettimeofday(&now); 
     152        PJ_TIME_VAL_SUB(next_reg, now); 
     153        info->next_reg = next_reg.sec; 
    118154    } 
    119155 
     
    195231 
    196232    /* Set "From" header. */ 
    197     pj_strdup_with_null(regc->pool, &tmp, from_url); 
     233    pj_strdup_with_null(regc->pool, &regc->from_uri, from_url); 
     234    tmp = regc->from_uri; 
    198235    regc->from_hdr = pjsip_from_hdr_create(regc->pool); 
    199236    regc->from_hdr->uri = pjsip_parse_uri(regc->pool, tmp.ptr, tmp.slen,  
     
    326363    pjsip_tx_data *tdata; 
    327364 
     365    PJ_ASSERT_RETURN(regc && p_tdata, PJ_EINVAL); 
     366 
    328367    status = create_request(regc, &tdata); 
    329368    if (status != PJ_SUCCESS) 
     
    356395    pj_status_t status; 
    357396 
     397    PJ_ASSERT_RETURN(regc && p_tdata, PJ_EINVAL); 
     398 
    358399    if (regc->timer.id != 0) { 
    359400        pjsip_endpt_cancel_timer(regc->endpt, &regc->timer); 
     
    378419                                                const pj_str_t contact[] ) 
    379420{ 
     421    PJ_ASSERT_RETURN(regc, PJ_EINVAL); 
    380422    return set_contact( regc, contact_cnt, contact ); 
    381423} 
     
    385427                                                pj_uint32_t expires ) 
    386428{ 
     429    PJ_ASSERT_RETURN(regc, PJ_EINVAL); 
    387430    set_expires( regc, expires ); 
    388431    return PJ_SUCCESS; 
     
    390433 
    391434 
    392 static void call_callback(pjsip_regc *regc, int status, const pj_str_t *reason, 
     435static void call_callback(pjsip_regc *regc, pj_status_t status, int st_code,  
     436                          const pj_str_t *reason, 
    393437                          pjsip_rx_data *rdata, pj_int32_t expiration, 
    394438                          int contact_cnt, pjsip_contact_hdr *contact[]) 
     
    399443    cbparam.regc = regc; 
    400444    cbparam.token = regc->token; 
    401     cbparam.code = status; 
     445    cbparam.status = status; 
     446    cbparam.code = st_code; 
    402447    cbparam.reason = *reason; 
    403448    cbparam.rdata = rdata; 
     
    428473        char errmsg[PJ_ERR_MSG_SIZE]; 
    429474        pj_str_t reason = pj_strerror(status, errmsg, sizeof(errmsg)); 
    430         call_callback(regc, -1, &reason, NULL, -1, 0, NULL); 
     475        call_callback(regc, status, 400, &reason, NULL, -1, 0, NULL); 
    431476    } 
    432477} 
     
    438483    pjsip_transaction *tsx = event->body.tsx_state.tsx; 
    439484     
     485    /* Decrement pending transaction counter. */ 
     486    --regc->pending_tsx; 
     487 
    440488    /* If registration data has been deleted by user then remove registration  
    441489     * data from transaction's callback, and don't call callback. 
    442490     */ 
    443491    if (regc->_delete_flag) { 
    444         --regc->pending_tsx; 
     492 
     493        /* Nothing to do */ 
     494        ; 
    445495 
    446496    } else if (tsx->status_code == PJSIP_SC_PROXY_AUTHENTICATION_REQUIRED || 
     
    456506 
    457507        if (status == PJ_SUCCESS) { 
    458             --regc->pending_tsx; 
    459508            pjsip_regc_send(regc, tdata); 
    460509            return; 
    461510        } else { 
    462             call_callback(regc, tsx->status_code, &rdata->msg_info.msg->line.status.reason, 
     511            call_callback(regc, status, tsx->status_code,  
     512                          &rdata->msg_info.msg->line.status.reason, 
    463513                          rdata, -1, 0, NULL); 
    464             --regc->pending_tsx; 
    465514        } 
    466515    } else { 
     
    513562                regc->timer.user_data = regc; 
    514563                pjsip_endpt_schedule_timer( regc->endpt, &regc->timer, &delay); 
     564                pj_gettimeofday(&regc->last_reg); 
     565                regc->next_reg = regc->last_reg; 
     566                regc->next_reg.sec += delay.sec; 
    515567            } 
    516568 
     
    523575        /* Call callback. */ 
    524576        if (expiration == 0xFFFF) expiration = -1; 
    525         call_callback(regc, tsx->status_code,  
     577        call_callback(regc, PJ_SUCCESS, tsx->status_code,  
    526578                      (rdata ? &rdata->msg_info.msg->line.status.reason  
    527579                        : pjsip_get_status_text(tsx->status_code)), 
     
    529581                      contact_cnt, contact); 
    530582 
    531         --regc->pending_tsx; 
    532583    } 
    533584 
     
    544595    /* Make sure we don't have pending transaction. */ 
    545596    if (regc->pending_tsx) { 
    546         pj_str_t reason = pj_str("Transaction in progress"); 
    547         call_callback(regc, -1, &reason, NULL, -1, 0, NULL); 
    548597        pjsip_tx_data_dec_ref( tdata ); 
    549         return PJ_EINVALIDOP; 
     598        return PJSIP_EBUSY; 
    550599    } 
    551600 
     
    560609    if (status==PJ_SUCCESS) 
    561610        ++regc->pending_tsx; 
    562     else { 
    563         char errmsg[PJ_ERR_MSG_SIZE]; 
    564         pj_str_t reason = pj_strerror(status, errmsg, sizeof(errmsg)); 
    565         call_callback(regc, status, &reason, NULL, -1, 0, NULL); 
    566     } 
    567611 
    568612    return status; 
Note: See TracChangeset for help on using the changeset viewer.