[sr-dev] git:master:8454dac6: topos: adding param contact_host

Julien Chavanton jchavanton at gmail.com
Tue Aug 14 09:58:52 CEST 2018


Module: kamailio
Branch: master
Commit: 8454dac69187516921a20686c9d9085a5db6728b
URL: https://github.com/kamailio/kamailio/commit/8454dac69187516921a20686c9d9085a5db6728b

Author: Julien Chavanton <jchavanton at gmail.com>
Committer: Julien Chavanton <jchavanton at gmail.com>
Date: 2018-07-18T11:16:29-07:00

topos: adding param contact_host

---

Modified: src/modules/topos/doc/topos_admin.xml
Modified: src/modules/topos/topos_mod.c
Modified: src/modules/topos/tps_storage.c

---

Diff:  https://github.com/kamailio/kamailio/commit/8454dac69187516921a20686c9d9085a5db6728b.diff
Patch: https://github.com/kamailio/kamailio/commit/8454dac69187516921a20686c9d9085a5db6728b.patch

---

diff --git a/src/modules/topos/doc/topos_admin.xml b/src/modules/topos/doc/topos_admin.xml
index 8a423fdc84..3d6e5ac5d7 100644
--- a/src/modules/topos/doc/topos_admin.xml
+++ b/src/modules/topos/doc/topos_admin.xml
@@ -275,6 +275,31 @@ end
 ...
 modparam("topos", "event_mode", 2)
 ...
+</programlisting>
+		</example>
+	</section>
+	<section id="topos.p.contact_host">
+		<title><varname>contact_host</varname> (str)</title>
+		<para>
+			You may need to control the host part of the Contact header added
+			by topos.
+
+			For example when using TLS with TOPOS the remote UAS must be able to open
+			a new TLS socket to the contact header.
+			In this case, the contact header must contain a domain name with a trusted CA
+			signed certitificate.
+		</para>
+		<para>
+		<emphasis>
+			Default value is taken from the Record-Route URI.
+		</emphasis>
+		</para>
+		<example>
+		<title>Set <varname>contact_host</varname> parameter</title>
+		<programlisting format="linespecific">
+...
+modparam("topos", "contact_host", "proxy.domain.com")
+...
 </programlisting>
 		</example>
 	</section>
diff --git a/src/modules/topos/topos_mod.c b/src/modules/topos/topos_mod.c
index 1bd9eb6571..43711f2fe9 100644
--- a/src/modules/topos/topos_mod.c
+++ b/src/modules/topos/topos_mod.c
@@ -93,6 +93,7 @@ static str _tps_eventrt_callback = STR_NULL;
 static str _tps_eventrt_outgoing_name = str_init("topos:msg-outgoing");
 static int _tps_eventrt_sending = -1;
 static str _tps_eventrt_sending_name = str_init("topos:msg-sending");
+str _tps_contact_host = str_init("");
 
 sanity_api_t scb;
 
@@ -129,6 +130,7 @@ static param_export_t params[]={
 	{"clean_interval",	PARAM_INT, &_tps_clean_interval},
 	{"event_callback",	PARAM_STR, &_tps_eventrt_callback},
 	{"event_mode",		PARAM_STR, &_tps_eventrt_mode},
+	{"contact_host",	PARAM_STR, &_tps_contact_host},
 	{0,0,0}
 };
 
diff --git a/src/modules/topos/tps_storage.c b/src/modules/topos/tps_storage.c
index 08bf15ec8a..8d9a888356 100644
--- a/src/modules/topos/tps_storage.c
+++ b/src/modules/topos/tps_storage.c
@@ -53,6 +53,8 @@ extern sruid_t _tps_sruid;
 extern db1_con_t* _tps_db_handle;
 extern db_func_t _tpsdbf;
 
+extern str _tps_contact_host;
+
 #define TPS_STORAGE_LOCK_SIZE	1<<9
 static gen_lock_set_t *_tps_storage_lock_set = NULL;
 
@@ -219,14 +221,20 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir)
 		return 0;
 	}
 
-	if(td->cp + 8 + (2*uuid->len) + sv.len >= td->cbuf + TPS_DATA_SIZE) {
-		LM_ERR("insufficient data buffer\n");
-		return -1;
-	}
 	if (parse_uri(sv.s, sv.len, &puri) < 0) {
 		LM_ERR("failed to parse the uri\n");
 		return -1;
 	}
+
+	int contact_len = sv.len;
+	if (_tps_contact_host.len)
+		contact_len = sv.len - puri.host.len + _tps_contact_host.len;
+
+	if(td->cp + 8 + (2*uuid->len) + contact_len >= td->cbuf + TPS_DATA_SIZE) {
+		LM_ERR("insufficient data buffer\n");
+		return -1;
+	}
+
 	if(dir==TPS_DIR_DOWNSTREAM) {
 		td->b_uuid.s = td->cp;
 		*td->cp = 'b';
@@ -263,8 +271,15 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir)
 	td->cp += uuid->len;
 	*td->cp = '@';
 	td->cp++;
-	memcpy(td->cp, puri.host.s, puri.host.len);
-	td->cp += puri.host.len;
+
+	if (_tps_contact_host.len) { // using configured hostname in the contact header
+		memcpy(td->cp, _tps_contact_host.s, _tps_contact_host.len);
+		td->cp += _tps_contact_host.len;
+	} else {
+		memcpy(td->cp, puri.host.s, puri.host.len);
+		td->cp += puri.host.len;
+	}
+
 	if(puri.port.len>0) {
 		*td->cp = ':';
 		td->cp++;




More information about the sr-dev mailing list