فهرست منبع

topos: add functionality to set a variable host part for the Contact header

- add functionality to set a variable host part for the Contact header
- could be refactored to use a xavp instead of avp, together with the other
  parameters in this area ([a,b]_contact_avp)
Henning Westerholt 4 سال پیش
والد
کامیت
c970241557
3فایلهای تغییر یافته به همراه60 افزوده شده و 7 حذف شده
  1. 29 1
      src/modules/topos/doc/topos_admin.xml
  2. 13 1
      src/modules/topos/topos_mod.c
  3. 18 5
      src/modules/topos/tps_storage.c

+ 29 - 1
src/modules/topos/doc/topos_admin.xml

@@ -292,7 +292,8 @@ modparam("topos", "event_mode", 2)
 		<title><varname>contact_host</varname> (str)</title>
 		<para>
 			You may need to control the host part of the Contact header added
-			by topos.
+			by topos. If the contact_host_avp parameter is set, this value is
+			ignored.
 
 			For example when using TLS with TOPOS the remote UAS must be able to open
 			a new TLS socket to the contact header.
@@ -433,6 +434,33 @@ modparam("topos", "b_contact_avp", "$avp(tps-bct)")
 ...
 modparam("topos", "rr_update", 1)
 ...
+</programlisting>
+		</example>
+	</section>
+	<section id="topos.p.contact_host_avp">
+		<title><varname>contact_host_avp</varname> (str)</title>
+		<para>
+			You may need to control the host part of the Contact header added
+			by topos. This parameter allows to take the value from an AVP
+			during run-time. If this parameter is set, the contact_host
+			parameter is ignored.
+
+			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 empty, not set.
+		</emphasis>
+		</para>
+		<example>
+		<title>Set <varname>contact_host_avp</varname> parameter</title>
+		<programlisting format="linespecific">
+...
+modparam("topos", "contact_host_avp", "$avp(contact_host)")
+...
 </programlisting>
 		</example>
 	</section>

+ 13 - 1
src/modules/topos/topos_mod.c

@@ -96,6 +96,8 @@ static int _tps_eventrt_sending = -1;
 static str _tps_eventrt_sending_name = str_init("topos:msg-sending");
 str _tps_contact_host = str_init("");
 int _tps_contact_mode = 0;
+str _tps_contact_host_avp = str_init("");
+pv_spec_t _tps_contact_host_avp_spec;
 str _tps_cparam_name = str_init("tps");
 str _tps_acontact_avp;
 str _tps_bcontact_avp;
@@ -142,7 +144,8 @@ static param_export_t params[]={
 	{"cparam_name",		PARAM_STR, &_tps_cparam_name},
 	{"a_contact_avp",	PARAM_STR, &_tps_acontact_avp},
 	{"b_contact_avp",	PARAM_STR, &_tps_bcontact_avp},
-	{"rr_update",       PARAM_INT, &_tps_rr_update},
+	{"contact_host_avp",    PARAM_STR, &_tps_contact_host_avp},
+	{"rr_update",		PARAM_INT, &_tps_rr_update},
 	{0,0,0}
 };
 
@@ -235,6 +238,15 @@ static int mod_init(void)
 		}
 	}
 
+	if(_tps_contact_host_avp.len > 0 && _tps_contact_host_avp.s != NULL) {
+		if(pv_parse_spec(&_tps_contact_host_avp, &_tps_contact_host_avp_spec) == 0
+				|| _tps_contact_host_avp_spec.type != PVT_AVP) {
+			LM_ERR("malformed or non AVP %.*s AVP definition\n",
+			_tps_contact_host_avp.len, _tps_contact_host_avp.s);
+			return -1;
+		}
+	}
+
 	sr_event_register_cb(SREV_NET_DATA_IN,  tps_msg_received);
 	sr_event_register_cb(SREV_NET_DATA_OUT, tps_msg_sent);
 

+ 18 - 5
src/modules/topos/tps_storage.c

@@ -61,6 +61,8 @@ extern str _tps_acontact_avp;
 extern str _tps_bcontact_avp;
 extern pv_spec_t _tps_acontact_spec;
 extern pv_spec_t _tps_bcontact_spec;
+extern str _tps_contact_host_avp;
+extern pv_spec_t _tps_contact_host_avp_spec;
 
 #define TPS_STORAGE_LOCK_SIZE	1<<9
 static gen_lock_set_t *_tps_storage_lock_set = NULL;
@@ -343,12 +345,23 @@ int tps_storage_fill_contact(sip_msg_t *msg, tps_data_t *td, str *uuid, int dir,
 			td->cp++;
 		}
 
-		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;
+		// contact_host AVP takes preference
+		if (_tps_contact_host_avp.len) {
+			if ((pv_get_spec_value(msg, &_tps_contact_host_avp_spec, &pv_val) != 0) &&
+					(pv_val.flags & PV_VAL_STR) && (pv_val.rs.len <= 0)) {
+				LM_ERR("could not evaluate contact_host AVP\n");
+				return -1;
+			}
+			memcpy(td->cp, pv_val.rs.s, pv_val.rs.len);
+			td->cp += pv_val.rs.len;
 		} else {
-			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 = ':';