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

Added API to terminate dialog prematurely. Affect: dialog, invite sessions, evsub, and presence

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip-simple/evsub.c

    r275 r283  
    199199    unsigned              option;       /**< Options.                       */ 
    200200    pjsip_evsub_user      user;         /**< Callback.                      */ 
     201    pj_bool_t             call_cb;      /**< Notify callback?               */ 
    201202    pjsip_role_e          role;         /**< UAC=subscriber, UAS=notifier   */ 
    202203    pjsip_evsub_state     state;        /**< Subscription state.            */ 
     
    510511                       const pj_str_t *state_str, pjsip_event *event) 
    511512{ 
     513    pjsip_evsub_state prev_state = sub->state; 
    512514    pj_str_t old_state_str = sub->state_str; 
    513515 
     
    526528              sub->state_str.ptr)); 
    527529 
    528     if (sub->user.on_evsub_state) 
     530    if (sub->user.on_evsub_state && sub->call_cb) 
    529531        (*sub->user.on_evsub_state)(sub, event); 
    530532 
    531     if (state == PJSIP_EVSUB_STATE_TERMINATED) { 
    532          
     533    if (state == PJSIP_EVSUB_STATE_TERMINATED && 
     534        prev_state != PJSIP_EVSUB_STATE_TERMINATED)  
     535    { 
    533536        if (sub->pending_tsx == 0) { 
    534537            evsub_destroy(sub); 
     
    560563    case TIMER_TYPE_UAC_REFRESH: 
    561564        /* Time for UAC to refresh subscription */ 
    562         if (sub->user.on_client_refresh) { 
     565        if (sub->user.on_client_refresh && sub->call_cb) { 
    563566            (*sub->user.on_client_refresh)(sub); 
    564567        } else { 
     
    577580    case TIMER_TYPE_UAS_TIMEOUT: 
    578581        /* Refresh from UAC has not been received */ 
    579         if (sub->user.on_server_timeout) { 
     582        if (sub->user.on_server_timeout && sub->call_cb) { 
    580583            (*sub->user.on_server_timeout)(sub); 
    581584        } else { 
     
    653656    sub->pkg = pkg; 
    654657    sub->role = role; 
     658    sub->call_cb = PJ_TRUE; 
    655659    sub->option = option; 
    656660    sub->state = PJSIP_EVSUB_STATE_NULL; 
     
    838842} 
    839843 
     844 
     845/* 
     846 * Forcefully destroy subscription. 
     847 */ 
     848PJ_DEF(pj_status_t) pjsip_evsub_terminate( pjsip_evsub *sub, 
     849                                           pj_bool_t notify ) 
     850{ 
     851    PJ_ASSERT_RETURN(sub, PJ_EINVAL); 
     852 
     853    pjsip_dlg_inc_lock(sub->dlg); 
     854 
     855    if (sub->pending_tsx) { 
     856        pj_assert(!"Unable to terminate when there's pending tsx"); 
     857        pjsip_dlg_dec_lock(sub->dlg); 
     858        return PJ_EINVALIDOP; 
     859    } 
     860 
     861    sub->call_cb = notify; 
     862    set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, NULL, NULL); 
     863 
     864    pjsip_dlg_dec_lock(sub->dlg); 
     865    return PJ_SUCCESS; 
     866} 
    840867 
    841868/* 
     
    16141641         * if any. 
    16151642         */ 
    1616         if (st_code==200 && sub->user.on_rx_notify) { 
     1643        if (st_code==200 && sub->user.on_rx_notify && sub->call_cb) { 
    16171644            (*sub->user.on_rx_notify)(sub, rdata, &st_code, &st_text,  
    16181645                                      &res_hdr, &body); 
     
    17821809        pj_list_init(&res_hdr); 
    17831810 
    1784         (*sub->user.on_rx_refresh)(sub, rdata, &st_code, &st_text,  
    1785                                    &res_hdr, &body); 
     1811        if (sub->user.on_rx_refresh && sub->call_cb) { 
     1812            (*sub->user.on_rx_refresh)(sub, rdata, &st_code, &st_text,  
     1813                                       &res_hdr, &body); 
     1814        } 
    17861815 
    17871816        /* Application MUST specify final response! */ 
     
    18871916 
    18881917    /* Call on_tsx_state callback, if any. */ 
    1889     if (sub->user.on_tsx_state) 
     1918    if (sub->user.on_tsx_state && sub->call_cb) 
    18901919        (*sub->user.on_tsx_state)(sub, tsx, event); 
    18911920 
Note: See TracChangeset for help on using the changeset viewer.