Related to ticket #61: added new invite session API pjsip_inv_verify_request() which takes additional remote SDP, to avoid parsing SDP multiple times

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@1733 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip/include/pjsip-ua/sip_inv.h b/pjsip/include/pjsip-ua/sip_inv.h
index 78fdbc6..bfcc11c 100644
--- a/pjsip/include/pjsip-ua/sip_inv.h
+++ b/pjsip/include/pjsip-ua/sip_inv.h
@@ -394,6 +394,8 @@
  *			Otherwise application MUST specify the endpt argument
  *			(this is useful e.g. when application wants to send 
  *			the response statelessly).
+ *
+ * @see pjsip_inv_verify_request2()
  */
 PJ_DECL(pj_status_t) pjsip_inv_verify_request(	pjsip_rx_data *rdata,
 						unsigned *options,
@@ -402,6 +404,20 @@
 						pjsip_endpoint *endpt,
 						pjsip_tx_data **tdata);
 
+/**
+ * Variant of #pjsip_inv_verify_request() which allows application to specify
+ * the parsed SDP in the \a offer argument. This is useful to avoid having to
+ * re-parse the SDP in the incoming request.
+ *
+ * @see pjsip_inv_verify_request()
+ */
+PJ_DECL(pj_status_t) pjsip_inv_verify_request2( pjsip_rx_data *rdata,
+						unsigned *options,
+						const pjmedia_sdp_session *offer,
+						const pjmedia_sdp_session *answer,
+						pjsip_dialog *dlg,
+						pjsip_endpoint *endpt,
+						pjsip_tx_data **tdata);
 
 /**
  * Create UAS invite session for the specified dialog in dlg. Application 
diff --git a/pjsip/src/pjsip-ua/sip_inv.c b/pjsip/src/pjsip-ua/sip_inv.c
index c4c6331..ee5274f 100644
--- a/pjsip/src/pjsip-ua/sip_inv.c
+++ b/pjsip/src/pjsip-ua/sip_inv.c
@@ -676,12 +676,13 @@
 /*
  * Verify incoming INVITE request.
  */
-PJ_DEF(pj_status_t) pjsip_inv_verify_request(pjsip_rx_data *rdata,
-					     unsigned *options,
-					     const pjmedia_sdp_session *l_sdp,
-					     pjsip_dialog *dlg,
-					     pjsip_endpoint *endpt,
-					     pjsip_tx_data **p_tdata)
+PJ_DEF(pj_status_t) pjsip_inv_verify_request2(pjsip_rx_data *rdata,
+					      unsigned *options,
+					      const pjmedia_sdp_session *r_sdp,
+					      const pjmedia_sdp_session *l_sdp,
+					      pjsip_dialog *dlg,
+					      pjsip_endpoint *endpt,
+					      pjsip_tx_data **p_tdata)
 {
     pjsip_msg *msg;
     pjsip_allow_hdr *allow;
@@ -722,10 +723,10 @@
     /* Init response header list */
     pj_list_init(&res_hdr_list);
 
-    /* Check the request body, see if it'inv something that we support
-     * (i.e. SDP). 
+    /* Check the request body, see if it's something that we support,
+     * only when the body hasn't been parsed before.
      */
-    if (msg->body) {
+    if (r_sdp==NULL && msg->body) {
 	pjsip_msg_body *body = msg->body;
 	pj_str_t str_application = {"application", 11};
 	pj_str_t str_sdp = { "sdp", 3 };
@@ -777,6 +778,10 @@
 	    goto on_return;
 	}
 
+	r_sdp = sdp;
+    }
+
+    if (r_sdp) {
 	/* Negotiate with local SDP */
 	if (l_sdp) {
 	    pjmedia_sdp_neg *neg;
@@ -787,7 +792,7 @@
 
 	    /* Create SDP negotiator */
 	    status = pjmedia_sdp_neg_create_w_remote_offer(
-			    rdata->tp_info.pool, l_sdp, sdp, &neg);
+			    rdata->tp_info.pool, l_sdp, r_sdp, &neg);
 	    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
 
 	    /* Negotiate SDP */
@@ -1027,6 +1032,21 @@
     return status;
 }
 
+
+/*
+ * Verify incoming INVITE request.
+ */
+PJ_DEF(pj_status_t) pjsip_inv_verify_request( pjsip_rx_data *rdata,
+					      unsigned *options,
+					      const pjmedia_sdp_session *l_sdp,
+					      pjsip_dialog *dlg,
+					      pjsip_endpoint *endpt,
+					      pjsip_tx_data **p_tdata)
+{
+    return pjsip_inv_verify_request2(rdata, options, NULL, l_sdp, dlg, 
+				     endpt, p_tdata);
+}
+
 /*
  * Create UAS invite session.
  */