Fixed #1081: Implement ICE option tag (RFC 5678)


git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@3222 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip/include/pjsip-ua/sip_inv.h b/pjsip/include/pjsip-ua/sip_inv.h
index a2281e4..122a148 100644
--- a/pjsip/include/pjsip-ua/sip_inv.h
+++ b/pjsip/include/pjsip-ua/sip_inv.h
@@ -295,6 +295,16 @@
      */
     PJSIP_INV_SUPPORT_UPDATE	= 4,
 
+    /**
+     * Indicate support for ICE
+     */
+    PJSIP_INV_SUPPORT_ICE	= 8,
+
+    /**
+     * Require ICE support.
+     */
+    PJSIP_INV_REQUIRE_ICE	= 16,
+
     /** 
      * Require reliable provisional response extension. 
      */
@@ -309,7 +319,7 @@
      * Session timer extension will always be used even when peer doesn't
      * support/want session timer.
      */
-    PJSIP_INV_ALWAYS_USE_TIMER	= 128,
+    PJSIP_INV_ALWAYS_USE_TIMER	= 128
 
 };
 
diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h
index 36a1148..add306b 100644
--- a/pjsip/include/pjsua-lib/pjsua.h
+++ b/pjsip/include/pjsua-lib/pjsua.h
@@ -306,6 +306,18 @@
 #endif
 
 /**
+ * Controls whether PJSUA-LIB should add ICE media feature tag
+ * parameter (the ";+sip.ice" parameter) to Contact header if ICE
+ * is enabled in the config.
+ *
+ * Default: 1
+ */
+#ifndef PJSUA_ADD_ICE_TAGS
+#   define PJSUA_ADD_ICE_TAGS		1
+#endif
+
+
+/**
  * Logging configuration, which can be (optionally) specified when calling
  * #pjsua_init(). Application must call #pjsua_logging_config_default() to
  * initialize this structure with the default values.
diff --git a/pjsip/src/pjsip-ua/sip_inv.c b/pjsip/src/pjsip-ua/sip_inv.c
index dab68d4..b522b3b 100644
--- a/pjsip/src/pjsip-ua/sip_inv.c
+++ b/pjsip/src/pjsip-ua/sip_inv.c
@@ -777,6 +777,8 @@
 	*options |= PJSIP_INV_SUPPORT_100REL;
     if (*options & PJSIP_INV_REQUIRE_TIMER)
 	*options |= PJSIP_INV_SUPPORT_TIMER;
+    if (*options & PJSIP_INV_REQUIRE_ICE)
+	*options |= PJSIP_INV_SUPPORT_ICE;
 
     /* Get the message in rdata */
     msg = rdata->msg_info.msg;
@@ -948,12 +950,15 @@
 	unsigned i;
 	const pj_str_t STR_100REL = { "100rel", 6};
 	const pj_str_t STR_TIMER = { "timer", 5};
+	const pj_str_t STR_ICE = { "ice", 3 };
 
 	for (i=0; i<sup_hdr->count; ++i) {
 	    if (pj_stricmp(&sup_hdr->values[i], &STR_100REL)==0)
 		rem_option |= PJSIP_INV_SUPPORT_100REL;
-	    if (pj_stricmp(&sup_hdr->values[i], &STR_TIMER)==0)
+	    else if (pj_stricmp(&sup_hdr->values[i], &STR_TIMER)==0)
 		rem_option |= PJSIP_INV_SUPPORT_TIMER;
+	    else if (pj_stricmp(&sup_hdr->values[i], &STR_ICE)==0)
+		rem_option |= PJSIP_INV_SUPPORT_ICE;
 	}
     }
 
@@ -965,6 +970,7 @@
 	const pj_str_t STR_100REL = { "100rel", 6};
 	const pj_str_t STR_REPLACES = { "replaces", 8 };
 	const pj_str_t STR_TIMER = { "timer", 5 };
+	const pj_str_t STR_ICE = { "ice", 3 };
 	unsigned unsupp_cnt = 0;
 	pj_str_t unsupp_tags[PJSIP_GENERIC_ARRAY_MAX_COUNT];
 	
@@ -986,6 +992,10 @@
 						  NULL, &STR_REPLACES);
 		if (!supp)
 		    unsupp_tags[unsupp_cnt++] = req_hdr->values[i];
+	    } else if ((*options & PJSIP_INV_SUPPORT_ICE) &&
+		pj_stricmp(&req_hdr->values[i], &STR_ICE)==0)
+	    {
+		rem_option |= PJSIP_INV_REQUIRE_ICE;
 
 	    } else if (!pjsip_endpt_has_capability(endpt, PJSIP_H_SUPPORTED,
 						   NULL, &req_hdr->values[i]))
diff --git a/pjsip/src/pjsua-lib/pjsua_acc.c b/pjsip/src/pjsua-lib/pjsua_acc.c
index 9bd3020..62c2451 100644
--- a/pjsip/src/pjsua-lib/pjsua_acc.c
+++ b/pjsip/src/pjsua-lib/pjsua_acc.c
@@ -237,6 +237,22 @@
 	acc->cred[acc->cred_cnt++] = pjsua_var.ua_cfg.cred_info[i];
     }
 
+    /* If ICE is enabled, add "+sip.ice" media feature tag in account's
+     * contact params.
+     */
+#if PJSUA_ADD_ICE_TAGS
+    if (pjsua_var.media_cfg.enable_ice) {
+	unsigned new_len;
+	pj_str_t new_prm;
+
+	new_len = acc_cfg->contact_params.slen + 10;
+	new_prm.ptr = (char*)pj_pool_alloc(acc->pool, new_len);
+	pj_strcpy(&new_prm, &acc_cfg->contact_params);
+	pj_strcat2(&new_prm, ";+sip.ice");
+	acc_cfg->contact_params = new_prm;
+    }
+#endif
+
     status = pjsua_pres_init_acc(acc_id);
     if (status != PJ_SUCCESS)
 	return status;
diff --git a/pjsip/src/pjsua-lib/pjsua_call.c b/pjsip/src/pjsua-lib/pjsua_call.c
index 8cd8ce5..7fce1e4 100644
--- a/pjsip/src/pjsua-lib/pjsua_call.c
+++ b/pjsip/src/pjsua-lib/pjsua_call.c
@@ -840,6 +840,8 @@
 	options |= PJSIP_INV_REQUIRE_100REL;
     if (pjsua_var.acc[acc_id].cfg.require_timer)
 	options |= PJSIP_INV_REQUIRE_TIMER;
+    if (pjsua_var.media_cfg.enable_ice)
+	options |= PJSIP_INV_SUPPORT_ICE;
 
     status = pjsip_inv_verify_request2(rdata, &options, offer, answer, NULL,
 				       pjsua_var.endpt, &response);