Skip to content

Commit

Permalink
registrar Add option to the save() function to turn off expires varia…
Browse files Browse the repository at this point in the history
…tion when saving a registration
  • Loading branch information
oej committed May 3, 2016
1 parent 0a296e5 commit 55975ad
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 19 deletions.
2 changes: 2 additions & 0 deletions modules/registrar/README
Expand Up @@ -815,6 +815,8 @@ modparam("registrar", "flow_timer", 25)
other contact addresses for AoR not matching current
registration, remove them. This mode ensures one contact per
AoR (user).
+ 0x08 - Do not apply expires_range or default_expires_range to
this registration.
The flags may be given in decimal or hexa format.
* uri (optional - flags param has to be set and can be 0 for default
behavior) - SIP URI to do be used instead of To header URI. It can
Expand Down
7 changes: 7 additions & 0 deletions modules/registrar/doc/registrar_admin.xml
Expand Up @@ -973,6 +973,13 @@ modparam("registrar", "flow_timer", 25)
AoR not matching current registration, remove them.
This mode ensures one contact per AoR (user).</para>
</listitem>
<listitem>
<para><emphasis>0x08</emphasis> - Do not apply
<emphasis>expires_range</emphasis> or
<emphasis>default_expires_range</emphasis> to this
registration.
</para>
</listitem>
</itemizedlist>
<para>The flags may be given in decimal or hexa format.</para>
</listitem>
Expand Down
9 changes: 5 additions & 4 deletions modules/registrar/registrar.h
Expand Up @@ -49,10 +49,11 @@
#define PATH_MODE_LAZY 1
#define PATH_MODE_OFF 0

#define REG_SAVE_MEM_FL (1<<0)
#define REG_SAVE_NORPL_FL (1<<1)
#define REG_SAVE_REPL_FL (1<<2)
#define REG_SAVE_ALL_FL ((1<<3)-1)
#define REG_SAVE_MEM_FL (1<<0)
#define REG_SAVE_NORPL_FL (1<<1)
#define REG_SAVE_REPL_FL (1<<2)
#define REG_SAVE_NOVARIATION_FL (1<<3)
#define REG_SAVE_ALL_FL ((1<<4)-1)

#define REG_OUTBOUND_NONE 0
#define REG_OUTBOUND_SUPPORTED 1
Expand Down
23 changes: 13 additions & 10 deletions modules/registrar/save.c
Expand Up @@ -70,7 +70,7 @@ static int q_override_msg_id;
static qvalue_t q_override_value;

/*! \brief
* Process request that contained a star, in that case,
* Process request that contained a star (*) as a contact, in that case,
* we will remove all bindings with the given username
* from the usrloc and return 200 OK response
*/
Expand Down Expand Up @@ -448,7 +448,7 @@ int reg_get_crt_max_contacts(void)
* and insert all contacts from the message that have expires
* > 0
*/
static inline int insert_contacts(struct sip_msg* _m, udomain_t* _d, str* _a, int _use_regid)
static inline int insert_contacts(struct sip_msg* _m, udomain_t* _d, str* _a, int _use_regid, int novariation)
{
ucontact_info_t* ci;
urecord_t* r = NULL;
Expand Down Expand Up @@ -482,7 +482,7 @@ static inline int insert_contacts(struct sip_msg* _m, udomain_t* _d, str* _a, in
maxc = reg_get_crt_max_contacts();
for( num=0,r=0,ci=0 ; _c ; _c = get_next_contact(_c) ) {
/* calculate expires */
calc_contact_expires(_m, _c->expires, &expires);
calc_contact_expires(_m, _c->expires, &expires, novariation);
/* Skip contacts with zero expires */
if (expires == 0)
continue;
Expand Down Expand Up @@ -592,7 +592,7 @@ static int test_max_contacts(struct sip_msg* _m, urecord_t* _r, contact_t* _c,

for( ; _c ; _c = get_next_contact(_c) ) {
/* calculate expires */
calc_contact_expires(_m, _c->expires, &e);
calc_contact_expires(_m, _c->expires, &e, 0);

ret = ul.get_ucontact_by_instance( _r, &_c->uri, ci, &cont);
if (ret==-1) {
Expand Down Expand Up @@ -632,7 +632,7 @@ static int test_max_contacts(struct sip_msg* _m, urecord_t* _r, contact_t* _c,
* 3) If contact in usrloc exists and expires
* == 0, delete contact
*/
static inline int update_contacts(struct sip_msg* _m, urecord_t* _r, int _mode, int _use_regid)
static inline int update_contacts(struct sip_msg* _m, urecord_t* _r, int _mode, int _use_regid, int novariation)
{
ucontact_info_t *ci;
ucontact_t *c, *ptr, *ptr0;
Expand Down Expand Up @@ -679,7 +679,7 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r, int _mode,
updated=0;
for( ; _c ; _c = get_next_contact(_c) ) {
/* calculate expires */
calc_contact_expires(_m, _c->expires, &expires);
calc_contact_expires(_m, _c->expires, &expires, novariation);

/* pack the contact info */
if ( (ci=pack_ci( 0, _c, expires, 0, _use_regid))==0 ) {
Expand Down Expand Up @@ -817,7 +817,7 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r, int _mode,
* contained some contact header fields
*/
static inline int add_contacts(struct sip_msg* _m, udomain_t* _d,
str* _a, int _mode, int _use_regid)
str* _a, int _mode, int _use_regid, int novariation)
{
int res;
int ret;
Expand All @@ -839,7 +839,7 @@ static inline int add_contacts(struct sip_msg* _m, udomain_t* _d,
}

if (res == 0) { /* Contacts found */
if ((ret=update_contacts(_m, r, _mode, _use_regid)) < 0) {
if ((ret=update_contacts(_m, r, _mode, _use_regid, novariation)) < 0) {
build_contact(_m, r->contacts, &u->host);
ul.release_urecord(r);
ul.unlock_udomain(_d, _a);
Expand All @@ -848,7 +848,7 @@ static inline int add_contacts(struct sip_msg* _m, udomain_t* _d,
build_contact(_m, r->contacts, &u->host);
ul.release_urecord(r);
} else {
if (insert_contacts(_m, _d, _a, _use_regid) < 0) {
if (insert_contacts(_m, _d, _a, _use_regid, novariation) < 0) {
ul.unlock_udomain(_d, _a);
return -4;
}
Expand Down Expand Up @@ -876,6 +876,8 @@ int save(struct sip_msg* _m, udomain_t* _d, int _cflags, str *_uri)
param_t *params;
contact_t *contact;
int use_ob = 1, use_regid = 1;
int novariation = 0;


u = parse_to_uri(_m);
if(u==NULL)
Expand Down Expand Up @@ -973,6 +975,7 @@ int save(struct sip_msg* _m, udomain_t* _d, int _cflags, str *_uri)
}

mem_only = is_cflag_set(REG_SAVE_MEM_FL)?FL_MEM:FL_NONE;
novariation = is_cflag_set(REG_SAVE_NOVARIATION_FL)? 1:0;

if (c == 0) {
if (st) {
Expand All @@ -984,7 +987,7 @@ int save(struct sip_msg* _m, udomain_t* _d, int _cflags, str *_uri)
}
} else {
mode = is_cflag_set(REG_SAVE_REPL_FL)?1:0;
if ((ret=add_contacts(_m, (udomain_t*)_d, &aor, mode, use_regid)) < 0)
if ((ret=add_contacts(_m, (udomain_t*)_d, &aor, mode, use_regid, novariation)) < 0)
goto error;
ret = (ret==0)?1:ret;
}
Expand Down
14 changes: 10 additions & 4 deletions modules/registrar/sip_msg.c
Expand Up @@ -48,10 +48,13 @@ static struct hdr_field* act_contact;
*/
static inline int randomize_expires( int expires, int range )
{
int range_min;

/* if no range is given just return expires */
if(range == 0) return expires;
if(range == 0)
return expires;

int range_min = expires - (float)range/100 * expires;
range_min = expires - (float)range/100 * expires;

return range_min + (float)(rand()%100)/100 * ( expires - range_min );
}
Expand Down Expand Up @@ -240,9 +243,10 @@ contact_t* get_next_contact(contact_t* _c)
* 3) If the message contained no expires header field, use
* the default value
*/
void calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e)
void calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e, int novariation)
{
int range = 0;

if (!_ep || !_ep->body.len) {
*_e = get_expires_hf(_m);

Expand All @@ -263,7 +267,9 @@ void calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e)

if ( *_e != 0 )
{
*_e = randomize_expires( *_e, range );
if (!novariation) {
*_e = randomize_expires( *_e, range );
}

if (*_e < cfg_get(registrar, registrar_cfg, min_expires)) {
*_e = cfg_get(registrar, registrar_cfg, min_expires);
Expand Down
3 changes: 2 additions & 1 deletion modules/registrar/sip_msg.h
Expand Up @@ -69,8 +69,9 @@ contact_t* get_next_contact(contact_t* _c);
* header field in the same way
* 3) If the message contained no expires header field, use
* the default value
* If novariation is not set, the expires range will not be applied (variation in accepted expiry)
*/
void calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e);
void calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e, int novariation);


/*! \brief
Expand Down

0 comments on commit 55975ad

Please sign in to comment.