Skip to content

Commit

Permalink
registrar: new parameter lookup_filter_mode
Browse files Browse the repository at this point in the history
- control what filters should be applied for lookup(...) operations
- filter values are specified via filed of xavp_cfg
- implemented filter for branch flags matching
  • Loading branch information
miconda committed Apr 15, 2019
1 parent 96421ea commit 97f7d24
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
62 changes: 57 additions & 5 deletions src/modules/registrar/lookup.c
Expand Up @@ -45,6 +45,54 @@
#include "lookup.h"
#include "config.h"


extern int reg_lookup_filter_mode;

typedef struct reg_lookup_filter {
uint32_t factive;
uint32_t bflags;
} reg_lookup_filter_t;

static reg_lookup_filter_t _reg_lookup_filter;

static void reg_lookup_filter_init(void)
{
str filter_bflags = str_init("rlf_bflags");
sr_xavp_t *vavp = NULL;

if(reg_lookup_filter_mode==0 || reg_xavp_cfg.s==NULL) {
return;
}
memset(&_reg_lookup_filter, 0, sizeof(reg_lookup_filter_t));

if((reg_lookup_filter_mode & 1)
&& (vavp = xavp_get_child_with_ival(&reg_xavp_cfg,
&filter_bflags)) != NULL) {
if(vavp->val.v.i != 0) {
_reg_lookup_filter.bflags = (uint32_t)vavp->val.v.i;
_reg_lookup_filter.factive = 1;
}
}
return;
}

static int reg_lookup_filter_match(ucontact_t* ptr)
{
if(reg_lookup_filter_mode==0 || reg_xavp_cfg.s==NULL) {
return 1;
}
if(_reg_lookup_filter.factive==0) {
return 1;
}
if(_reg_lookup_filter.bflags!=0) {
if((_reg_lookup_filter.bflags & ptr->cflags)==0) {
return 0;
}
}
return 1;

}

static int has_to_tag(struct sip_msg* msg)
{
if (parse_to_header(msg) < 0) return 0;
Expand Down Expand Up @@ -223,6 +271,7 @@ int lookup_helper(struct sip_msg* _m, udomain_t* _d, str* _uri, int _mode)
}

get_act_time();
reg_lookup_filter_init();

if(puri.gr.s==NULL || puri.gr_val.len>0)
{
Expand Down Expand Up @@ -251,10 +300,12 @@ int lookup_helper(struct sip_msg* _m, udomain_t* _d, str* _uri, int _mode)
break;
}
} else {
/* no-gruu - found by address */
LM_DBG("contact for [%.*s] found by address\n",
aor.len, ZSW(aor.s));
break;
if(reg_lookup_filter_match(ptr)) {
/* no-gruu - found by address */
LM_DBG("contact for [%.*s] found by address\n",
aor.len, ZSW(aor.s));
break;
}
}
} else {
LM_DBG("contact for [%.*s] cannot handle the SIP method\n",
Expand Down Expand Up @@ -417,7 +468,8 @@ int lookup_helper(struct sip_msg* _m, udomain_t* _d, str* _uri, int _mode)
if (!cfg_get(registrar, registrar_cfg, append_branches)) goto done;

for( ; ptr ; ptr = ptr->next ) {
if (VALID_CONTACT(ptr, act_time) && allowed_method(_m, ptr)) {
if (VALID_CONTACT(ptr, act_time) && allowed_method(_m, ptr)
&& reg_lookup_filter_match(ptr)) {
path_dst.len = 0;
if(ptr->path.s && ptr->path.len) {
path_str = ptr->path;
Expand Down
3 changes: 3 additions & 0 deletions src/modules/registrar/registrar.c
Expand Up @@ -135,6 +135,8 @@ str sock_hdr_name = {0,0};
int reg_expire_event_rt = -1; /* default disabled */
str reg_event_callback = STR_NULL;

int reg_lookup_filter_mode = 0;

sr_kemi_eng_t *keng = NULL;

#define RCV_NAME "received"
Expand Down Expand Up @@ -239,6 +241,7 @@ static param_export_t params[] = {
{"flow_timer", INT_PARAM, &reg_flow_timer },
{"contact_max_size", INT_PARAM, &contact_max_size },
{"event_callback", PARAM_STR, &reg_event_callback },
{"lookup_filter_mode", INT_PARAM, &reg_lookup_filter_mode },
{0, 0, 0}
};

Expand Down

0 comments on commit 97f7d24

Please sign in to comment.