Skip to content

Commit

Permalink
matching_mode honored in cachedbs
Browse files Browse the repository at this point in the history
Function cdb_add_ct_update ignores matching modes set on opensips.cfg, this result in an unexpected behaviour if the user sets matching_mode=0 since multiple records with same contact (but different callid) are stored in the cache database.
This fix checks, before getting the base64 hash, if matching mode is contact only, if yes, the callid string is not included in the resulted base64 hash.
If matching mode is CONTACT_CALLID, this function behaves like before, and the hash is calcuated using contact:callid.
  • Loading branch information
Alessio Garzi committed Aug 13, 2019
1 parent 7b80bdc commit db7eca7
Showing 1 changed file with 38 additions and 18 deletions.
56 changes: 38 additions & 18 deletions modules/usrloc/urecord.c
Expand Up @@ -501,24 +501,44 @@ int cdb_add_ct_update(cdb_dict_t *updates, const ucontact_t *ct, char remove)
int len, base64len;

cdb_key_init(&contacts_key, "contacts");
len = ct->c.len + 1 + ct->callid.len;
base64len = calc_base64_encode_len(len);

if (pkg_str_extend(&ctkey_pkg_buf, len) < 0) {
LM_ERR("oom\n");
return -1;
}

if (pkg_str_extend(&ctkeyb64_pkg_buf, base64len) < 0) {
LM_ERR("oom\n");
return -1;
}

memcpy(ctkey_pkg_buf.s, ct->c.s, ct->c.len);
ctkey_pkg_buf.s[ct->c.len] = ':';
memcpy(ctkey_pkg_buf.s + ct->c.len + 1, ct->callid.s,
ct->callid.len);


switch (matching_mode) {
case CONTACT_ONLY:
len = ct->c.len ;
base64len = calc_base64_encode_len(len);
if (pkg_str_extend(&ctkey_pkg_buf, len) < 0) {
LM_ERR("oom\n");
return -1;
}

if (pkg_str_extend(&ctkeyb64_pkg_buf, base64len) < 0) {
LM_ERR("oom\n");
return -1;
}
memcpy(ctkey_pkg_buf.s, ct->c.s, ct->c.len);
break;
case CONTACT_CALLID:
len = ct->c.len + 1 + ct->callid.len;
base64len = calc_base64_encode_len(len);
if (pkg_str_extend(&ctkey_pkg_buf, len) < 0) {
LM_ERR("oom\n");
return -1;
}

if (pkg_str_extend(&ctkeyb64_pkg_buf, base64len) < 0) {
LM_ERR("oom\n");
return -1;
}
memcpy(ctkey_pkg_buf.s, ct->c.s, ct->c.len);
ctkey_pkg_buf.s[ct->c.len] = ':';
memcpy(ctkey_pkg_buf.s + ct->c.len + 1, ct->callid.s,
ct->callid.len);
break;
default:
LM_CRIT("unknown matching_mode %d\n", matching_mode);
return -1;
}

base64encode((unsigned char *)ctkeyb64_pkg_buf.s,
(unsigned char *)ctkey_pkg_buf.s, len);

Expand Down

0 comments on commit db7eca7

Please sign in to comment.