Skip to content

Commit

Permalink
[registrar] address issues on #3318 (bflag filtering for remove())
Browse files Browse the repository at this point in the history
On top of 43726f8
* be clear the param holds a single Branch Flag
* use fixup to resolve the flag only once (suggested by @liviuchircu)
  • Loading branch information
bogdan-iancu committed Apr 25, 2024
1 parent 43726f8 commit 7fce69b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
6 changes: 3 additions & 3 deletions modules/registrar/doc/registrar_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ save("location", , , "vip");

<section id="func_remove" xreflabel="remove()">
<title>
<function moreinfo="none">remove(domain, AOR[, [contact][, [next_hop][, [sip_instance], [bflags]]]])</function>
<function moreinfo="none">remove(domain, AOR[, [contact][, [next_hop][, [sip_instance], [bflag]]]])</function>
</title>
<para>
Explicitly remove contacts behind a given address-of-record.
Expand Down Expand Up @@ -613,8 +613,8 @@ save("location", , , "vip");
</listitem>
<listitem>
<para>
<emphasis>blfags (string, optional)</emphasis> - a
Branch flags to be used for filtering purposes.
<emphasis>blfag (string, optional)</emphasis> - a
Branch Flag to be used for filtering purposes.
</para>
</listitem>
</itemizedlist>
Expand Down
18 changes: 17 additions & 1 deletion modules/registrar/reg_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ static int save_flags_fixup(void** param);
static int save_flags_fixup_free(void** param);
static int lookup_flags_fixup(void** param);
static int lookup_flags_fixup_free(void** param);
static int bflag_fixup(void** param);

/*! \brief Functions */
static int add_sock_hdr(struct sip_msg* msg, str *str);
Expand Down Expand Up @@ -155,7 +156,7 @@ static const cmd_export_t cmds[] = {
{CMD_PARAM_STR|CMD_PARAM_OPT,0,0},
{CMD_PARAM_STR|CMD_PARAM_OPT,0,0},
{CMD_PARAM_STR|CMD_PARAM_OPT,0,0},
{CMD_PARAM_STR|CMD_PARAM_OPT,0,0}, {0,0,0}},
{CMD_PARAM_STR|CMD_PARAM_OPT, bflag_fixup,0}, {0,0,0}},
REQUEST_ROUTE|ONREPLY_ROUTE},
{"remove_ip_port", (cmd_function)_remove_ip_port, {
{CMD_PARAM_STR, 0, 0},
Expand Down Expand Up @@ -430,6 +431,21 @@ static int domain_fixup(void** param)
return 0;
}


static int bflag_fixup(void** param)
{
unsigned int mask;

if ((mask=fixup_flag( FLAG_TYPE_BRANCH, (str*)*param))==NAMED_FLAG_ERROR)
return E_UNSPEC;

*param = (void*)(unsigned long)mask;

return 0;
}



static int save_flags_fixup(void **param)
{
struct save_flags default_flags;
Expand Down
17 changes: 6 additions & 11 deletions modules/registrar/save.c
Original file line number Diff line number Diff line change
Expand Up @@ -911,18 +911,18 @@ int save(struct sip_msg* _m, void* _d, void* _f, str* _s, str* _owtag)
* @contact_gp: contact URI to be deleted
* @next_hop_gp: IP/domain in front of contacts to be deleted
* @sip_instance_gp: delete contacts with given "+sip_instance"
* @bflags: delete contacts which the specific branch flags
* @bflag: delete contacts which the specific branch flag mask
*
* @return: 1 on success, negative on failure
*/
int _remove(struct sip_msg *msg, void *udomain, str *aor_uri, str *match_ct,
str *match_next_hop, str *match_sin, str* bflags_s)
str *match_next_hop, str *match_sin, int* bflag)
{
struct hostent delete_nh_he, *he;
urecord_t *record;
ucontact_t *contact, *it;
str aor_user;
int ret = 1,bflags=0;
int ret = 1;
unsigned short delete_port = 0;

if (extract_aor(aor_uri, &aor_user, 0, 0, reg_use_domain) < 0) {
Expand All @@ -940,7 +940,7 @@ int _remove(struct sip_msg *msg, void *udomain, str *aor_uri, str *match_ct,
}

/* without any additional filtering, delete the whole urecord entry */
if (!match_ct && !match_next_hop && !match_sin && !bflags_s) {
if (!match_ct && !match_next_hop && !match_sin && (!bflag ||!*bflag)) {
if (ul.delete_urecord((udomain_t *)udomain, &aor_user, record, 0) != 0) {
LM_ERR("failed to delete urecord for aor '%.*s'\n",
aor_user.len, aor_user.s);
Expand All @@ -951,11 +951,6 @@ int _remove(struct sip_msg *msg, void *udomain, str *aor_uri, str *match_ct,
goto out_unlock;
}

if (bflags_s) {
bflags = get_flag_id_by_name(FLAG_TYPE_BRANCH, bflags_s->s, bflags_s->len);
bflags = 1<<bflags;
}

if (match_ct)
LM_DBG("Delete by contact: [%.*s]\n", match_ct->len, match_ct->s);

Expand Down Expand Up @@ -1024,8 +1019,8 @@ int _remove(struct sip_msg *msg, void *udomain, str *aor_uri, str *match_ct,
continue;
}

if (bflags != 0) {
if ((contact->cflags & bflags) == 0)
if (bflag && *bflag) {
if ((contact->cflags & *(bflag)) == 0)
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/registrar/save.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
int save(struct sip_msg* _m, void* _d, void* _f, str* _s, str* _owtag);

int _remove(struct sip_msg *msg, void *udomain, str *aor_gp, str *contact_gp,
str *next_hop_gp, str *sip_instance, str *bflags);
str *next_hop_gp, str *sip_instance, int *bflag);

int _remove_ip_port(struct sip_msg *msg, str *ip, int *port, void *udomain, str* aor);

Expand Down

0 comments on commit 7fce69b

Please sign in to comment.