Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TELECOM-9088: topology_hiding: force SIPS in contact header when needed #53

Open
wants to merge 1 commit into
base: 3.2-genesys
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/dialog/dlg_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ struct dlg_cell
int rt_on_timeout;
int rt_on_hangup;

unsigned int force_sips_contact;

#ifdef DBG_DIALOG
struct struct_hist *hist;
#endif
Expand Down
41 changes: 37 additions & 4 deletions modules/topology_hiding/topo_hiding_logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,26 @@ static char * topo_ct_param_copy(char *buf, str *name, str *val, int should_quot
return buf;
}

static int is_forced_sips_contact_required(const struct sip_msg* msg, const struct dlg_cell* dlg, const uri_type ct_type) {
str top_rr;

if (dlg->state != DLG_STATE_UNCONFIRMED) return 0;

// RURI is SIPS
if (msg->parsed_uri_ok && msg->parsed_uri.type == SIPS_URI_T) return 1;

if (msg->record_route == NULL) {
// There is no RR and Contact is SIPS
if (ct_type == SIPS_URI_T) return 1;
} else {
// Top RR is SIPS
top_rr = ((rr_t*)msg->record_route->parsed)->nameaddr.uri;
if (top_rr.len > 5 && strncmp(top_rr.s, "sips:", 5) == 0) return 1;
}

return 0;
}

static int topo_dlg_replace_contact(struct sip_msg* msg, struct dlg_cell* dlg)
{
char *prefix=NULL,*suffix=NULL,*p,*p_init,*ct_username=NULL;
Expand All @@ -379,6 +399,7 @@ static int topo_dlg_replace_contact(struct sip_msg* msg, struct dlg_cell* dlg)
param_t *it;
str *rr_param;
struct lump* lump;
uri_type ct_type = ERROR_URI_T;

if(!msg->contact)
{
Expand Down Expand Up @@ -408,6 +429,8 @@ static int topo_dlg_replace_contact(struct sip_msg* msg, struct dlg_cell* dlg)
} else {
ct_username = ctu.user.s;
ct_username_len = ctu.user.len;
ct_type = ctu.type;
if (ct_type == SIPS_URI_T) prefix_len += 1;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If RURI and Top RR are sip:, meanwhile the Contact header is sips:, then we should send out sip: in the Contact header if I understand correctly (Contact header only matter when RR is empty). In that case, this part may be broken, as it will calculate with the length of sips:, but later, it will send out sip: with it. I have to rethink this part.

LM_DBG("Trying to propagate username [%.*s]\n",ct_username_len,
ct_username);
if (ct_username_len > 0) {
Expand All @@ -419,6 +442,8 @@ static int topo_dlg_replace_contact(struct sip_msg* msg, struct dlg_cell* dlg)
if (dlg_api.is_mod_flag_set(dlg,TOPOH_DID_IN_USER))
prefix_len += RR_DLG_PARAM_SIZE + 1;

if (dlg->force_sips_contact && ct_type == SIP_URI_T) prefix_len += 1;

prefix = pkg_malloc(prefix_len);
if (!prefix) {
LM_ERR("no more pkg\n");
Expand Down Expand Up @@ -474,14 +499,22 @@ static int topo_dlg_replace_contact(struct sip_msg* msg, struct dlg_cell* dlg)
rr_param = dlg_api.get_rr_param();

p = prefix;
memcpy( p, "<sip:", 5);
p += 5;
if (dlg->force_sips_contact) {
memcpy(p, "<sips:", 6);
p += 6;
} else {
memcpy(p, "<sip:", 5);
p += 5;
}

if (is_forced_sips_contact_required(msg, dlg, ct_type)) dlg->force_sips_contact = 1;

if (dlg_api.is_mod_flag_set(dlg,TOPOH_KEEP_USER) && ct_username_len > 0) {
memcpy( p, ct_username, ct_username_len);
p += ct_username_len;
}
if (dlg_api.is_mod_flag_set(dlg,TOPOH_DID_IN_USER)) {
if (p==prefix+5)
if (p == prefix + prefix_len)
*(p++) = 'X';
/* add '.' */
*(p++) = DLG_SEPARATOR;
Expand All @@ -505,7 +538,7 @@ static int topo_dlg_replace_contact(struct sip_msg* msg, struct dlg_cell* dlg)
return -1;
}
}
if (p!=prefix+5)
if (p != prefix + prefix_len)
*(p++) = '@';

prefix_len = p - prefix;
Expand Down