[asterisk-scf-commits] asterisk-scf/release/pjproject.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Aug 1 18:17:20 CDT 2011


branch "master" has been updated
       via  d7780631be411856e61d1633e39961e319916307 (commit)
      from  6360b96e03e5cf651d5b310f0303db101cd1832d (commit)

Summary of changes:
 pjsip/include/pjsip-ua/sip_inv.h |   26 +++++++++++++++++++
 pjsip/src/pjsip-ua/sip_inv.c     |   50 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 0 deletions(-)


- Log -----------------------------------------------------------------
commit d7780631be411856e61d1633e39961e319916307
Author: Joshua Colp <jcolp at digium.com>
Date:   Mon Aug 1 20:17:27 2011 -0300

    Add ability to delay responding to an INVITE.

diff --git a/pjsip/include/pjsip-ua/sip_inv.h b/pjsip/include/pjsip-ua/sip_inv.h
index ba72ea5..ebd09d3 100644
--- a/pjsip/include/pjsip-ua/sip_inv.h
+++ b/pjsip/include/pjsip-ua/sip_inv.h
@@ -215,6 +215,21 @@ typedef struct pjsip_inv_callback
     void (*on_send_ack)(pjsip_inv_session *inv, pjsip_rx_data *rdata);
 
     /**
+     * This callback is called when the framework is going to send a response
+     * to an incoming re-invite. It allows the application to stop or delay
+     * the response until an appropriate time, useful if the local SDP is not
+     * known at the time of reception of the reinvite.
+     *
+     * Application can set the SDP answer with #pjsip_inv_set_sdp_answer().
+     *
+     * The application should eventually call pjsip_inv_send_reinvite_response once
+     * the local SDP has been determined and set using the above.
+     *
+     * This callback is optional.
+     */
+    void (*on_send_reinvite_response)(pjsip_inv_session *inv, pjsip_tx_data *tdata);
+
+    /**
      * This callback is called when the session is about to resend the 
      * INVITE request to the specified target, following the previously
      * received redirection response.
@@ -855,6 +870,17 @@ PJ_DECL(pj_status_t) pjsip_inv_create_ack(pjsip_inv_session *inv,
 PJ_DECL(pj_status_t) pjsip_inv_send_msg(pjsip_inv_session *inv,
 					pjsip_tx_data *tdata);
 
+/**
+ * Send response to reinvite.
+ *
+ * @param inv           The invite session.
+ * @param tdata         The message to be sent.
+ *
+ * @return              PJ_SUCCESS if response could be sent.
+ */
+PJ_DECL(pj_status_t) pjsip_inv_send_reinvite_response(pjsip_inv_session *inv,
+                                                      pjsip_tx_data *tdata);
+
 
 /**
  * Get the invite session for the dialog, if any.
diff --git a/pjsip/src/pjsip-ua/sip_inv.c b/pjsip/src/pjsip-ua/sip_inv.c
index 104d841..884b523 100644
--- a/pjsip/src/pjsip-ua/sip_inv.c
+++ b/pjsip/src/pjsip-ua/sip_inv.c
@@ -2636,6 +2636,52 @@ PJ_DEF(pj_status_t) pjsip_inv_send_msg( pjsip_inv_session *inv,
     return PJ_SUCCESS;
 }
 
+/**
+ * Send a response to a reinvite.
+ */
+PJ_DEF(pj_status_t) pjsip_inv_send_reinvite_response(pjsip_inv_session *inv,
+    pjsip_tx_data *tdata)
+{
+    pj_status_t status;
+
+    // Perform SDP negotiation so our SDP will get added to the answer
+    status = process_answer(inv, 200, tdata, NULL);
+
+    if (status != PJ_SUCCESS) {
+	/*
+	 * SDP negotiation has failed.
+	 */
+	pj_status_t rc;
+	pj_str_t reason;
+
+	/* Create 500 response */
+	reason = pj_str("SDP negotiation failed");
+	rc = pjsip_dlg_modify_response(inv->dlg, tdata, 500, &reason);
+	if (rc == PJ_SUCCESS) {
+	    pjsip_warning_hdr *w;
+	    const pj_str_t *endpt_name;
+
+	    endpt_name = pjsip_endpt_name(inv->dlg->endpt);
+	    w = pjsip_warning_hdr_create_from_status(tdata->pool,
+		endpt_name,
+		status);
+	    if (w)
+		pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)w);
+
+	    pjsip_inv_send_msg(inv, tdata);
+	}
+	return rc;
+    }
+
+    /* Invoke Session Timers */
+    pjsip_timer_update_resp(inv, tdata);
+
+    /* Send 2xx regardless of the status of negotiation */
+    status = pjsip_inv_send_msg(inv, tdata);
+    
+    return status;
+}
+
 
 /*
  * Respond to incoming CANCEL request.
@@ -3978,6 +4024,10 @@ static void inv_on_state_confirmed( pjsip_inv_session *inv, pjsip_event *e)
 	     */
 	    sdp_info = pjsip_rdata_get_sdp_info(rdata);
 	    if (sdp_info->sdp != NULL) {
+		if (mod_inv.cb.on_send_reinvite_response) {
+		    (*mod_inv.cb.on_send_reinvite_response)(inv, tdata);
+		    return;
+		}
 		status = process_answer(inv, 200, tdata, NULL);
 	    } else {
 		/* INVITE does not have SDP. 

-----------------------------------------------------------------------


-- 
asterisk-scf/release/pjproject.git



More information about the asterisk-scf-commits mailing list