Skip to content

Commit

Permalink
topos: adding param contact_host
Browse files Browse the repository at this point in the history
  • Loading branch information
jchavanton committed Jul 18, 2018
1 parent 5054ddf commit 8454dac
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
25 changes: 25 additions & 0 deletions src/modules/topos/doc/topos_admin.xml
Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions src/modules/topos/topos_mod.c
Expand Up @@ -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;

Expand Down Expand Up @@ -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}
};

Expand Down
27 changes: 21 additions & 6 deletions src/modules/topos/tps_storage.c
Expand Up @@ -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;

Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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++;
Expand Down

0 comments on commit 8454dac

Please sign in to comment.