Skip to content

Commit 603fdc4

Browse files
committed
TELECOM-9088: topology_hiding: force SIPS in contact header when needed
https://www.rfc-editor.org/rfc/rfc3261.html#section-12.1.1 "If the request that initiated the dialog contained a SIPS URI in the Request-URI or in the top Record-Route header field value, if there was any, or the Contact header field if there was no Record-Route header field, the Contact header field in the response MUST be a SIPS URI."
1 parent 957fc1d commit 603fdc4

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

modules/dialog/dlg_hash.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ struct dlg_cell
165165
int rt_on_timeout;
166166
int rt_on_hangup;
167167

168+
unsigned int force_sips_contact;
169+
168170
#ifdef DBG_DIALOG
169171
struct struct_hist *hist;
170172
#endif

modules/topology_hiding/topo_hiding_logic.c

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,26 @@ static char * topo_ct_param_copy(char *buf, str *name, str *val, int should_quot
369369
return buf;
370370
}
371371

372+
static int is_forced_sips_contact_required(const struct sip_msg* msg, const struct dlg_cell* dlg, const uri_type ct_type) {
373+
str top_rr;
374+
375+
if (dlg->state != DLG_STATE_UNCONFIRMED) return 0;
376+
377+
// RURI is SIPS
378+
if (msg->parsed_uri_ok && msg->parsed_uri.type == SIPS_URI_T) return 1;
379+
380+
if (msg->record_route == NULL) {
381+
// RR is NULL and Contact is SIPS
382+
if (ct_type == SIPS_URI_T) return 1;
383+
} else {
384+
// Top RR is SIPS
385+
top_rr = ((rr_t*)msg->record_route->parsed)->nameaddr.uri;
386+
if ((top_rr.len > 5 && strncmp(top_rr.s, "sips:", 5) == 0)) return 1;
387+
}
388+
389+
return 0;
390+
}
391+
372392
static int topo_dlg_replace_contact(struct sip_msg* msg, struct dlg_cell* dlg)
373393
{
374394
char *prefix=NULL,*suffix=NULL,*p,*p_init,*ct_username=NULL;
@@ -379,6 +399,7 @@ static int topo_dlg_replace_contact(struct sip_msg* msg, struct dlg_cell* dlg)
379399
param_t *it;
380400
str *rr_param;
381401
struct lump* lump;
402+
uri_type ct_type;
382403

383404
if(!msg->contact)
384405
{
@@ -408,6 +429,8 @@ static int topo_dlg_replace_contact(struct sip_msg* msg, struct dlg_cell* dlg)
408429
} else {
409430
ct_username = ctu.user.s;
410431
ct_username_len = ctu.user.len;
432+
ct_type = ctu.type;
433+
if (ct_type == SIPS_URI_T) prefix_len += 1;
411434
LM_DBG("Trying to propagate username [%.*s]\n",ct_username_len,
412435
ct_username);
413436
if (ct_username_len > 0) {
@@ -419,6 +442,8 @@ static int topo_dlg_replace_contact(struct sip_msg* msg, struct dlg_cell* dlg)
419442
if (dlg_api.is_mod_flag_set(dlg,TOPOH_DID_IN_USER))
420443
prefix_len += RR_DLG_PARAM_SIZE + 1;
421444

445+
if (dlg->force_sips_contact && ct_type == SIP_URI_T) prefix_len += 1;
446+
422447
prefix = pkg_malloc(prefix_len);
423448
if (!prefix) {
424449
LM_ERR("no more pkg\n");
@@ -474,14 +499,22 @@ static int topo_dlg_replace_contact(struct sip_msg* msg, struct dlg_cell* dlg)
474499
rr_param = dlg_api.get_rr_param();
475500

476501
p = prefix;
477-
memcpy( p, "<sip:", 5);
478-
p += 5;
502+
if (dlg->force_sips_contact) {
503+
memcpy(p, "<sips:", 6);
504+
p += 6;
505+
} else {
506+
memcpy(p, "<sip:", 5);
507+
p += 5;
508+
}
509+
510+
if (is_forced_sips_contact_required(msg, dlg, ct_type)) dlg->force_sips_contact = 1;
511+
479512
if (dlg_api.is_mod_flag_set(dlg,TOPOH_KEEP_USER) && ct_username_len > 0) {
480513
memcpy( p, ct_username, ct_username_len);
481514
p += ct_username_len;
482515
}
483516
if (dlg_api.is_mod_flag_set(dlg,TOPOH_DID_IN_USER)) {
484-
if (p==prefix+5)
517+
if (p == prefix + prefix_len)
485518
*(p++) = 'X';
486519
/* add '.' */
487520
*(p++) = DLG_SEPARATOR;
@@ -505,7 +538,7 @@ static int topo_dlg_replace_contact(struct sip_msg* msg, struct dlg_cell* dlg)
505538
return -1;
506539
}
507540
}
508-
if (p!=prefix+5)
541+
if (p != prefix + prefix_len)
509542
*(p++) = '@';
510543

511544
prefix_len = p - prefix;

0 commit comments

Comments
 (0)