Ticket #817: pjsip-2830-allow_cancel_reinvite.patch

File pjsip-2830-allow_cancel_reinvite.patch, 3.2 KB (added by bennylp, 14 years ago)

From Saúl Ibarra Corretgé: this patch should complete the missing part. The attached patch builds and sends a CANCEL request to an ongoing re-INVITE. I made the patch and tested on PJSIP 1.0.x version, but AFAIS there should be no problem in applying it to latest trunk.

  • pjsip/include/pjsip-ua/sip_inv.h

     
    687687 
    688688 
    689689 
     690 /**  
     691 * Creates a CANCEL request for an ongoing re-INVITE transaction. 
     692 * 
     693 * @param inv           The invite session. 
     694 * @param p_tdata       Pointer to receive the message to be created. Note 
     695 *                      that it's possible to receive NULL here while the 
     696 *                      function returns PJ_SUCCESS, see the description. 
     697 * 
     698 * @return              PJ_SUCCESS if termination is initiated. 
     699 */ 
     700PJ_DECL(pj_status_t) pjsip_inv_cancel_reinvite( pjsip_inv_session *inv, 
     701                                            pjsip_tx_data **p_tdata ); 
     702 
     703 
     704 
     705 
    690706/** 
    691707 * Create a re-INVITE request.  
    692708 * 
  • pjsip/src/pjsip-ua/sip_inv.c

     
    19361936    return PJ_SUCCESS; 
    19371937} 
    19381938 
     1939/* 
     1940 * Cancel re-INVITE transaction. 
     1941 */ 
     1942PJ_DEF(pj_status_t) pjsip_inv_cancel_reinvite(  pjsip_inv_session *inv, 
     1943                                            pjsip_tx_data **p_tdata ) 
     1944{ 
     1945    pjsip_tx_data *tdata; 
     1946    pj_status_t status; 
     1947 
     1948    /* Verify arguments. */ 
     1949    PJ_ASSERT_RETURN(inv && p_tdata, PJ_EINVAL); 
     1950 
     1951    /* Create appropriate message. */ 
     1952    switch (inv->state) { 
     1953    case PJSIP_INV_STATE_CONFIRMED: 
     1954        /* MUST have the original UAC INVITE transaction  */ 
     1955        PJ_ASSERT_RETURN(inv->invite_tsx != NULL, PJ_EBUG); 
     1956 
     1957        /* CANCEL should only be called when we have received a 
     1958         * provisional response. If we haven't received any responses, 
     1959         * just destroy the transaction. 
     1960         */ 
     1961        if (inv->invite_tsx->status_code < 100) { 
     1962            inv->pending_cancel = PJ_TRUE; 
     1963            *p_tdata = NULL; 
     1964            PJ_LOG(4, (inv->obj_name, "Delaying CANCEL since no " 
     1965                       "provisional response is received yet")); 
     1966            return PJ_SUCCESS; 
     1967        } 
     1968 
     1969        status = pjsip_endpt_create_cancel(inv->dlg->endpt,  
     1970                                           inv->invite_tsx->last_tx, 
     1971                                           &tdata); 
     1972        if (status != PJ_SUCCESS) 
     1973            return status; 
     1974        break; 
     1975 
     1976    default: 
     1977        /* We can send a CANCEL to a re-INVITE if the INVITE session is not confirmed. */ 
     1978        status = PJ_FALSE; 
     1979        break; 
     1980    } 
     1981 
     1982    if (status != PJ_SUCCESS) 
     1983        return status; 
     1984 
     1985    *p_tdata = tdata; 
     1986    return PJ_SUCCESS; 
     1987} 
     1988 
    19391989/* Following redirection recursion, get next target from the target set and 
    19401990 * notify user. 
    19411991 * 
     
    37463796            /* Save pending invite transaction */ 
    37473797            inv->invite_tsx = tsx; 
    37483798 
     3799        } else if (tsx->state == PJSIP_TSX_STATE_PROCEEDING) { 
     3800             
     3801            /* CANCEL the re-INVITE if necessary */ 
     3802            if (inv->pending_cancel) { 
     3803                pj_status_t status; 
     3804                pjsip_tx_data *cancel; 
     3805 
     3806                inv->pending_cancel = PJ_FALSE; 
     3807 
     3808                status = pjsip_inv_cancel_reinvite(inv, &cancel); 
     3809                if (status == PJ_SUCCESS && cancel) 
     3810                    status = pjsip_inv_send_msg(inv, cancel); 
     3811            } 
     3812 
    37493813        } else if (tsx->state == PJSIP_TSX_STATE_TERMINATED && 
    37503814                   tsx->status_code/100 == 2)  
    37513815        {