Skip to content

Commit

Permalink
mid_registrar: Fix broken AoR throttling with use_domain = 1
Browse files Browse the repository at this point in the history
Enabling both usrloc's "use_domain" and mid-registrar's AoR throttling
mode would cause broken advertised Contact header field URIs such as:

    sip:alice@atlanta.com@10.0.0.10:5060

This patch fixes this issue such that the mid-registrar advertises:

    sip:alice%40atlanta.com@10.0.0.10:5060

Fixes half of issue #1431
  • Loading branch information
liviuchircu committed Aug 14, 2018
1 parent 8369c31 commit 1d6733c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
28 changes: 24 additions & 4 deletions modules/mid_registrar/lookup.c
Expand Up @@ -40,6 +40,7 @@
#include "../../dset.h"

#include "../../mod_fix.h"
#include "../../strcommon.h"

#include "../usrloc/usrloc.h"
#include "../usrloc/urecord.h"
Expand Down Expand Up @@ -68,12 +69,13 @@ static str branch_uris[MAX_BRANCHES-1];

int mid_reg_lookup(struct sip_msg* req, char* _t, char* _f, char* _s)
{
static str unescape_buf;
unsigned int flags;
urecord_t* r;
str aor, uri;
str aor, uri, unesc_aor;
ucontact_t* ptr,*it;
int res, pos;
int ret;
int ret, bak;
str path_dst;
str flags_s;
char* ua = NULL;
Expand Down Expand Up @@ -160,7 +162,6 @@ int mid_reg_lookup(struct sip_msg* req, char* _t, char* _f, char* _s)
idx=0;
}


if (_s) {
if (pv_get_spec_value(req, (pv_spec_p)_s, &val)!=0) {
LM_ERR("failed to get PV value\n");
Expand Down Expand Up @@ -235,10 +236,29 @@ int mid_reg_lookup(struct sip_msg* req, char* _t, char* _f, char* _s)
goto have_contact;
}

if (extract_aor(&uri, &aor,&sip_instance,&call_id) < 0) {
bak = reg_use_domain;
reg_use_domain = 0;
if (extract_aor(&uri, &aor, &sip_instance, &call_id) < 0) {
LM_ERR("failed to extract address of record\n");
reg_use_domain = bak;
return -3;
}
reg_use_domain = bak;

if (reg_use_domain) {
if (pkg_str_extend(&unescape_buf, aor.len + 1) != 0) {
LM_ERR("oom\n");
return -3;
}

unesc_aor = unescape_buf;
if (unescape_param(&aor, &unesc_aor) != 0) {
LM_ERR("failed to unescape aor: %.*s\n", aor.len, aor.s);
return -3;
}

aor = unesc_aor;
}

update_act_time();

Expand Down
25 changes: 21 additions & 4 deletions modules/mid_registrar/save.c
Expand Up @@ -56,6 +56,7 @@
#include "../../lib/reg/regtime.h"

#include "../../trim.h"
#include "../../strcommon.h"

#include "../usrloc/usrloc.h"
#include "../usrloc/urecord.h"
Expand Down Expand Up @@ -142,14 +143,15 @@ void calc_ob_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e, int beha

static int trim_to_single_contact(struct sip_msg *msg, str *aor)
{
static str escape_buf;
contact_t *c = NULL;
struct socket_info *adv_sock;
struct lump *anchor = NULL;
char *buf;
int e, is_dereg = 1, len, len1;
struct hdr_field *ct;
union sockaddr_union _;
str extra_ct_params;
str extra_ct_params, esc_aor;

/* get the source socket on the way to the next hop */
adv_sock = uri2sock(msg, GET_NEXT_HOP(msg), &_, PROTO_NONE);
Expand Down Expand Up @@ -189,8 +191,23 @@ static int trim_to_single_contact(struct sip_msg *msg, str *aor)

extra_ct_params = get_extra_ct_params(msg);

/* < sip: @ :ddddd */
len = 1 + 4 + aor->len + 1 + strlen(adv_sock->address_str.s) + 6 +
if (!reg_use_domain) {
esc_aor = *aor;
} else {
if (pkg_str_extend(&escape_buf, 3 * aor->len + 1) != 0) {
LM_ERR("oom\n");
return -1;
}

esc_aor = escape_buf;
if (escape_param(aor, &esc_aor) != 0) {
LM_ERR("failed to escape AoR string: %.*s\n", aor->len, aor->s);
return -1;
}
}

/* < sip: @ :ddddd */
len = 1 + 4 + esc_aor.len + 1 + strlen(adv_sock->address_str.s) + 6 +
extra_ct_params.len + 1 + 9 + 10 + 1;
/* > ;expires=<integer> \0 */

Expand All @@ -200,7 +217,7 @@ static int trim_to_single_contact(struct sip_msg *msg, str *aor)
return -1;
}

len1 = sprintf(buf, "<sip:%.*s@%s:%s%.*s>", aor->len, aor->s,
len1 = sprintf(buf, "<sip:%.*s@%s:%s%.*s>", esc_aor.len, esc_aor.s,
adv_sock->address_str.s, adv_sock->port_no_str.s,
extra_ct_params.len, extra_ct_params.s);

Expand Down

0 comments on commit 1d6733c

Please sign in to comment.