Changed pjsip_dlg_send_request() API to NOT return transaction as it is not safe against race condition

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@376 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip/include/pjsip/sip_dialog.h b/pjsip/include/pjsip/sip_dialog.h
index 42ce7ba..c365a8d 100644
--- a/pjsip/include/pjsip/sip_dialog.h
+++ b/pjsip/include/pjsip/sip_dialog.h
@@ -408,14 +408,18 @@
  *
  * @param dlg		    The dialog.
  * @param tdata		    The request message to be sent.
- * @param p_tsx		    Optional argument to receive the transaction 
- *			    instance used to send the request.
+ * @param mod_data_id	    Optional module data index to put an optional data
+ *			    into the transaction. If no module data is to be
+ *			    attached, this value should be -1.
+ * @param mod_data	    Optional module data to be attached to the 
+ *			    transaction at mod_data_id index.
  *
  * @return		    PJ_SUCCESS on success.
  */
 PJ_DECL(pj_status_t) pjsip_dlg_send_request (	pjsip_dialog *dlg,
 						pjsip_tx_data *tdata,
-						pjsip_transaction **p_tsx );
+						int mod_data_id,
+						void *mod_data);
 
 
 /**
diff --git a/pjsip/src/pjsip-simple/evsub.c b/pjsip/src/pjsip-simple/evsub.c
index a91232c..9a9b852 100644
--- a/pjsip/src/pjsip-simple/evsub.c
+++ b/pjsip/src/pjsip-simple/evsub.c
@@ -1148,7 +1148,7 @@
     pjsip_dlg_inc_lock(sub->dlg);
 
     /* Send the request. */
-    status = pjsip_dlg_send_request(sub->dlg, tdata, NULL);
+    status = pjsip_dlg_send_request(sub->dlg, tdata, -1, NULL);
     if (status != PJ_SUCCESS)
 	goto on_return;
 
@@ -1482,7 +1482,7 @@
 					       event->body.tsx_state.src.rdata,
 					       tsx->last_tx, &tdata);
 	    if (status == PJ_SUCCESS) 
-		status = pjsip_dlg_send_request(sub->dlg, tdata, NULL);
+		status = pjsip_dlg_send_request(sub->dlg, tdata, -1, NULL);
 	    
 	    if (status != PJ_SUCCESS) {
 		/* Authentication failed! */
@@ -1869,7 +1869,7 @@
 	    status = pjsip_auth_clt_reinit_req( &sub->dlg->auth_sess, rdata, 
 						tsx->last_tx, &tdata);
 	    if (status == PJ_SUCCESS)
-		status = pjsip_dlg_send_request( sub->dlg, tdata, NULL );
+		status = pjsip_dlg_send_request( sub->dlg, tdata, -1, NULL );
 
 	    if (status != PJ_SUCCESS) {
 		/* Can't authenticate. Terminate session (?) */
diff --git a/pjsip/src/pjsip-ua/sip_inv.c b/pjsip/src/pjsip-ua/sip_inv.c
index 54acb0a..593a914 100644
--- a/pjsip/src/pjsip-ua/sip_inv.c
+++ b/pjsip/src/pjsip-ua/sip_inv.c
@@ -176,7 +176,7 @@
 	return status;
     }
 
-    status = pjsip_dlg_send_request(inv->dlg, tdata, NULL);
+    status = pjsip_dlg_send_request(inv->dlg, tdata, -1, NULL);
     if (status != PJ_SUCCESS) {
 	/* Better luck next time */
 	pj_assert(!"Unable to send ACK!");
@@ -1580,17 +1580,19 @@
 	      pjsip_tx_data_get_info(tdata)));
 
     if (tdata->msg->type == PJSIP_REQUEST_MSG) {
-	pjsip_transaction *tsx;
 	struct tsx_inv_data *tsx_inv_data;
 
-	status = pjsip_dlg_send_request(inv->dlg, tdata, &tsx);
-	if (status != PJ_SUCCESS)
-	    return status;
+	pjsip_dlg_inc_lock(inv->dlg);
 
-	tsx_inv_data = pj_pool_zalloc(tsx->pool, sizeof(struct tsx_inv_data));
+	tsx_inv_data = pj_pool_zalloc(inv->pool, sizeof(struct tsx_inv_data));
 	tsx_inv_data->inv = inv;
 
-	tsx->mod_data[mod_inv.mod.id] = tsx_inv_data;
+	pjsip_dlg_dec_lock(inv->dlg);
+
+	status = pjsip_dlg_send_request(inv->dlg, tdata, mod_inv.mod.id, 
+					tsx_inv_data);
+	if (status != PJ_SUCCESS)
+	    return status;
 
     } else {
 	pjsip_cseq_hdr *cseq;
diff --git a/pjsip/src/pjsip/sip_dialog.c b/pjsip/src/pjsip/sip_dialog.c
index 59b2d25..9076a13 100644
--- a/pjsip/src/pjsip/sip_dialog.c
+++ b/pjsip/src/pjsip/sip_dialog.c
@@ -931,7 +931,8 @@
  */
 PJ_DEF(pj_status_t) pjsip_dlg_send_request( pjsip_dialog *dlg,
 					    pjsip_tx_data *tdata,
-					    pjsip_transaction **p_tsx )
+					    int mod_data_id,
+					    void *mod_data)
 {
     pjsip_transaction *tsx;
     pjsip_msg *msg = tdata->msg;
@@ -978,6 +979,10 @@
 	 */
 	tsx->mod_data[dlg->ua->id] = dlg;
 
+	/* Copy optional caller's mod_data, if present */
+	if (mod_data_id >= 0 && mod_data_id < PJSIP_MAX_MODULE)
+	    tsx->mod_data[mod_data_id] = mod_data;
+
 	/* Increment transaction counter. */
 	++dlg->tsx_count;
 
@@ -988,17 +993,12 @@
 	    goto on_error;
 	}
 
-	if (p_tsx)
-	    *p_tsx = tsx;
-
     } else {
 	status = pjsip_endpt_send_request_stateless(dlg->endpt, tdata, 
 						    NULL, NULL);
 	if (status != PJ_SUCCESS)
 	    goto on_error;
 
-	if (p_tsx)
-	    *p_tsx = NULL;
     }
 
     /* Unlock dialog, may destroy dialog. */
@@ -1013,8 +1013,6 @@
     /* Whatever happen delete the message. */
     pjsip_tx_data_dec_ref( tdata );
 
-    if (p_tsx)
-	*p_tsx = NULL;
     return status;
 }
 
diff --git a/pjsip/src/pjsua-lib/pjsua_call.c b/pjsip/src/pjsua-lib/pjsua_call.c
index d18a59d..5597688 100644
--- a/pjsip/src/pjsua-lib/pjsua_call.c
+++ b/pjsip/src/pjsua-lib/pjsua_call.c
@@ -1330,7 +1330,7 @@
     }
 
     /* Send the request. */
-    status = pjsip_dlg_send_request( call->inv->dlg, tdata, NULL);
+    status = pjsip_dlg_send_request( call->inv->dlg, tdata, -1, NULL);
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to send MESSAGE request", status);
 	goto on_return;
@@ -1373,7 +1373,7 @@
 						     NULL, NULL, -1);
 
     /* Send the request. */
-    status = pjsip_dlg_send_request( call->inv->dlg, tdata, NULL);
+    status = pjsip_dlg_send_request( call->inv->dlg, tdata, -1, NULL);
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to send MESSAGE request", status);
 	goto on_return;