Module: kamailio Branch: master Commit: 252d18a032d5c6efbb709b75c0f17cdbd20ac58b URL: https://github.com/kamailio/kamailio/commit/252d18a032d5c6efbb709b75c0f17cdb...
Author: Stefan Mititelu stefan.mititelu92@gmail.com Committer: Stefan Mititelu stefan.mititelu92@gmail.com Date: 2020-02-28T17:12:04+02:00
registrar: add use_expired_contacts config param
Allow/Disallow the usage of the expired contacts.
Useful when some problems happen with new REGISTERs; allow the usage of old REGISTERed contacts.
Default value is 0 meaning "disallow the usage of the expired contacts". (no changes to existing behavior)
Value can be set dinamically via: kamcmd cfg.set_now_int registrar use_expired_contacts 1
---
Modified: src/modules/registrar/config.c Modified: src/modules/registrar/config.h Modified: src/modules/registrar/lookup.c Modified: src/modules/registrar/registrar.c
---
Diff: https://github.com/kamailio/kamailio/commit/252d18a032d5c6efbb709b75c0f17cdb... Patch: https://github.com/kamailio/kamailio/commit/252d18a032d5c6efbb709b75c0f17cdb...
---
diff --git a/src/modules/registrar/config.c b/src/modules/registrar/config.c index 937b9ea736..8a08207216 100644 --- a/src/modules/registrar/config.c +++ b/src/modules/registrar/config.c @@ -40,7 +40,8 @@ struct cfg_group_registrar default_registrar_cfg = { 0, /* retry_after */ 0, /* case_sensitive */ Q_UNSPECIFIED, /* default_q */ - 1 /* append_branches */ + 1, /* append_branches */ + 0 /* use_expired_contacts */ };
void *registrar_cfg = &default_registrar_cfg; @@ -68,5 +69,7 @@ cfg_def_t registrar_cfg_def[] = { "The parameter represents default q value for new contacts."}, /* Q_UNSPECIFIED is -1 */ {"append_branches", CFG_VAR_INT , 0, 0, 0, 0, "If set to 1(default), lookup will put all contacts found in msg structure"}, + {"use_expired_contacts",CFG_VAR_INT , 0, 0, 0, 0, + "Toggles using expired contacts as if they were active."}, {0, 0, 0, 0, 0, 0} }; diff --git a/src/modules/registrar/config.h b/src/modules/registrar/config.h index a6d1076ec1..43f5606bc2 100644 --- a/src/modules/registrar/config.h +++ b/src/modules/registrar/config.h @@ -36,6 +36,7 @@ struct cfg_group_registrar { unsigned int case_sensitive; qvalue_t default_q; unsigned int append_branches; + unsigned int use_expired_contacts; };
extern struct cfg_group_registrar default_registrar_cfg; diff --git a/src/modules/registrar/lookup.c b/src/modules/registrar/lookup.c index 97dd635b38..81f9b7afd9 100644 --- a/src/modules/registrar/lookup.c +++ b/src/modules/registrar/lookup.c @@ -304,7 +304,7 @@ int lookup_helper(struct sip_msg* _m, udomain_t* _d, str* _uri, int _mode) ret = -1; /* look first for an un-expired and suported contact */ while (ptr) { - if(VALID_CONTACT(ptr,act_time)) { + if(VALID_CONTACT(ptr,act_time) || cfg_get(registrar,registrar_cfg,use_expired_contacts)) { if(allowed_method(_m,ptr)) { /* match on instance, if pub-gruu */ if(inst.len>0) { @@ -346,7 +346,7 @@ int lookup_helper(struct sip_msg* _m, udomain_t* _d, str* _uri, int _mode) aor = *ptr->aor; /* test if not expired and contact with suported method */ if(ptr) { - if(!(VALID_CONTACT(ptr,act_time))) { + if(!(VALID_CONTACT(ptr,act_time) || cfg_get(registrar,registrar_cfg,use_expired_contacts))) { goto done; } else if(!allowed_method(_m,ptr)) { ret=-2; @@ -485,7 +485,7 @@ 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) || cfg_get(registrar,registrar_cfg,use_expired_contacts)) && allowed_method(_m, ptr) && reg_lookup_filter_match(ptr)) { path_dst.len = 0; if(ptr->path.s && ptr->path.len) { @@ -847,7 +847,7 @@ int registered4(struct sip_msg* _m, udomain_t* _d, str* _uri, int match_flag,
get_act_time(); for (ptr = r->contacts; ptr; ptr = ptr->next) { - if(!VALID_CONTACT(ptr, act_time)) continue; + if(!(VALID_CONTACT(ptr, act_time) || cfg_get(registrar,registrar_cfg,use_expired_contacts))) continue; if (match_callid.s && /* optionally enforce tighter matching w/ Call-ID */ match_callid.len > 0 && (match_callid.len != ptr->callid.len || diff --git a/src/modules/registrar/registrar.c b/src/modules/registrar/registrar.c index 7f1aa78bd7..11ebbdc8b9 100644 --- a/src/modules/registrar/registrar.c +++ b/src/modules/registrar/registrar.c @@ -248,6 +248,7 @@ static param_export_t params[] = { {"event_callback", PARAM_STR, ®_event_callback }, {"lookup_filter_mode", INT_PARAM, ®_lookup_filter_mode }, {"min_expires_mode", PARAM_INT, ®_min_expires_mode }, + {"use_expired_contacts", INT_PARAM, &default_registrar_cfg.use_expired_contacts }, {0, 0, 0} };