Fixed #1209: new enhancement: Option to update Contact URI when sending re-INVITE or UPDATE

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@3452 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h
index f780317..2aa83c5 100644
--- a/pjsip/include/pjsua-lib/pjsua.h
+++ b/pjsip/include/pjsua-lib/pjsua.h
@@ -3022,7 +3022,33 @@
 
 } pjsua_call_info;
 
+/**
+ * Flags to be given to various call APIs. More than one flags may be
+ * specified by bitmasking them.
+ */
+typedef enum pjsua_call_flag
+{
+    /**
+     * When the call is being put on hold, specify this flag to unhold it.
+     * This flag is only valid for #pjsua_call_reinvite() and
+     * #pjsua_call_update(). Note: for compatibility reason, this flag
+     * must have value of 1 because previously the unhold option is
+     * specified as boolean value.
+     */
+    PJSUA_CALL_UNHOLD = 1,
 
+    /**
+     * Update the local invite session's contact with the contact URI from
+     * the account. This flag is only valid for #pjsua_call_reinvite() and
+     * #pjsua_call_update(). This flag is useful in IP address change
+     * situation, after the local account's Contact has been updated
+     * (typically with re-registration) use this flag to update the invite
+     * session with the new Contact and to inform this new Contact to the
+     * remote peer with the outgoing re-INVITE or UPDATE
+     */
+    PJSUA_CALL_UPDATE_CONTACT = 2
+
+} pjsua_call_flag;
 
 /**
  * Get maximum number of calls configured in pjsua.
@@ -3312,22 +3338,23 @@
  * the media state of the call has changed.
  *
  * @param call_id	Call identification.
- * @param unhold	If this argument is non-zero and the call is locally
- *			held, this will release the local hold.
+ * @param options	Bitmask of pjsua_call_flag constants. Note that
+ * 			for compatibility, specifying PJ_TRUE here is
+ * 			equal to specifying PJSUA_CALL_UNHOLD flag.
  * @param msg_data	Optional message components to be sent with
  *			the request.
  *
  * @return		PJ_SUCCESS on success, or the appropriate error code.
  */
 PJ_DECL(pj_status_t) pjsua_call_reinvite(pjsua_call_id call_id,
-					 pj_bool_t unhold,
+					 unsigned options,
 					 const pjsua_msg_data *msg_data);
 
 /**
  * Send UPDATE request.
  *
  * @param call_id	Call identification.
- * @param options	Must be zero for now.
+ * @param options	Bitmask of pjsua_call_flag constants.
  * @param msg_data	Optional message components to be sent with
  *			the request.
  *
diff --git a/pjsip/src/pjsua-lib/pjsua_call.c b/pjsip/src/pjsua-lib/pjsua_call.c
index 5a4ab2f..4d95066 100644
--- a/pjsip/src/pjsua-lib/pjsua_call.c
+++ b/pjsip/src/pjsua-lib/pjsua_call.c
@@ -1660,10 +1660,11 @@
  * Send re-INVITE (to release hold).
  */
 PJ_DEF(pj_status_t) pjsua_call_reinvite( pjsua_call_id call_id,
-					 pj_bool_t unhold,
+                                         unsigned options,
 					 const pjsua_msg_data *msg_data)
 {
     pjmedia_sdp_session *sdp;
+    pj_str_t *new_contact = NULL;
     pjsip_tx_data *tdata;
     pjsua_call *call;
     pjsip_dialog *dlg;
@@ -1684,7 +1685,7 @@
     }
 
     /* Create SDP */
-    if (call->local_hold && !unhold) {
+    if (call->local_hold && (options & PJSUA_CALL_UNHOLD)==0) {
 	status = create_sdp_of_call_hold(call, &sdp);
     } else {
 	status = pjsua_media_channel_create_sdp(call->index, 
@@ -1699,8 +1700,14 @@
 	return status;
     }
 
+    if ((options & PJSUA_CALL_UPDATE_CONTACT) &
+	    pjsua_acc_is_valid(call->acc_id))
+    {
+	new_contact = &pjsua_var.acc[call->acc_id].contact;
+    }
+
     /* Create re-INVITE with new offer */
-    status = pjsip_inv_reinvite( call->inv, NULL, sdp, &tdata);
+    status = pjsip_inv_reinvite( call->inv, new_contact, sdp, &tdata);
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to create re-INVITE", status);
 	pjsip_dlg_dec_lock(dlg);
@@ -1732,6 +1739,7 @@
 				       const pjsua_msg_data *msg_data)
 {
     pjmedia_sdp_session *sdp;
+    pj_str_t *new_contact = NULL;
     pjsip_tx_data *tdata;
     pjsua_call *call;
     pjsip_dialog *dlg;
@@ -1757,8 +1765,14 @@
 	return status;
     }
 
+    if ((options & PJSUA_CALL_UPDATE_CONTACT) &
+	    pjsua_acc_is_valid(call->acc_id))
+    {
+	new_contact = &pjsua_var.acc[call->acc_id].contact;
+    }
+
     /* Create UPDATE with new offer */
-    status = pjsip_inv_update(call->inv, NULL, sdp, &tdata);
+    status = pjsip_inv_update(call->inv, new_contact, sdp, &tdata);
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to create UPDATE request", status);
 	pjsip_dlg_dec_lock(dlg);