Skip to content

Commit

Permalink
Move common registrar time-keeping code under lib/reg
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuchircu committed Apr 19, 2017
1 parent 82873f5 commit 1f9aa6d
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/reg/ci.c
Expand Up @@ -98,7 +98,7 @@ ucontact_info_t *pack_ci(struct sip_msg* _m, contact_t* _c,
}
}

ci.last_modified = act_time;
ci.last_modified = get_act_time();

/* set flags */
ci.flags = _f;
Expand Down
2 changes: 2 additions & 0 deletions modules/mid_registrar/gruu.c
Expand Up @@ -32,6 +32,8 @@
#include "../../ut.h"
#include "../../data_lump.h"

#include "../../lib/reg/regtime.h"

#include "mid_registrar.h"
#include "lookup.h"
#include "encode.h"
Expand Down
2 changes: 2 additions & 0 deletions modules/mid_registrar/mid_registrar.c
Expand Up @@ -45,6 +45,8 @@

#include "../../lib/reg/rerrno.h"
#include "../../lib/reg/sip_msg.h"
#include "../../lib/reg/regtime.h"

#include "../../parser/contact/contact.h"
#include "../../parser/contact/parse_contact.h"
#include "../../parser/msg_parser.h"
Expand Down
3 changes: 0 additions & 3 deletions modules/mid_registrar/mid_registrar.h
Expand Up @@ -140,9 +140,6 @@ void mri_free(struct mid_reg_info *mri);
void set_ct(struct mid_reg_info *ct);
struct mid_reg_info *get_ct(void);

time_t get_act_time(void);
void update_act_time(void);

int extract_aor(str* _uri, str* _a,str *sip_instance,str *call_id);

int get_expires_hf(struct sip_msg* _m);
Expand Down
12 changes: 6 additions & 6 deletions modules/registrar/lookup.c
Expand Up @@ -188,7 +188,7 @@ int lookup(struct sip_msg* _m, char* _t, char* _f, char* _s)
return -3;
}

get_act_time();
update_act_time();

ul.lock_udomain((udomain_t*)_t, &aor);
res = ul.get_urecord((udomain_t*)_t, &aor, &r);
Expand All @@ -215,7 +215,7 @@ int lookup(struct sip_msg* _m, char* _t, char* _f, char* _s)
/* look first for an un-expired and suported contact */
search_valid_contact:
while ( (ptr) &&
!(VALID_CONTACT(ptr,act_time) && (ret=-2) && allowed_method(_m,ptr,flags)))
!(VALID_CONTACT(ptr,get_act_time()) && (ret=-2) && allowed_method(_m,ptr,flags)))
ptr = ptr->next;
if (ptr==0) {
/* nothing found */
Expand Down Expand Up @@ -261,7 +261,7 @@ int lookup(struct sip_msg* _m, char* _t, char* _f, char* _s)

it = ptr->next;
while ( it ) {
if (VALID_CONTACT(it,act_time)) {
if (VALID_CONTACT(it,get_act_time())) {
if (it->instance.len-2 == sip_instance.len && sip_instance.s &&
memcmp(it->instance.s+1,sip_instance.s,sip_instance.len) == 0)
if (it->last_modified > ptr->last_modified) {
Expand Down Expand Up @@ -341,7 +341,7 @@ int lookup(struct sip_msg* _m, char* _t, char* _f, char* _s)

do {
for( ; ptr ; ptr = ptr->next ) {
if (VALID_CONTACT(ptr, act_time) && allowed_method(_m,ptr,flags)) {
if (VALID_CONTACT(ptr, get_act_time()) && allowed_method(_m,ptr,flags)) {
path_dst.len = 0;
if(ptr->path.s && ptr->path.len
&& get_path_dst_uri(&ptr->path, &path_dst) < 0) {
Expand Down Expand Up @@ -520,13 +520,13 @@ int is_registered(struct sip_msg* _m, char *_d, char* _a)
}

CHECK_DOMAIN(ud);
get_act_time();
update_act_time();

LM_DBG("checking aor <%.*s>\n",aor.len,aor.s);
ul.lock_udomain(ud, &aor);
if (ul.get_urecord(ud, &aor, &r) == 0) {
for ( c=r->contacts; c && (ret==NOT_FOUND); c=c->next ) {
if (VALID_CONTACT(c,act_time)) {
if (VALID_CONTACT(c,get_act_time())) {
/* populate the 'attributes' avp */
if (attr_avp_name != -1) {
istr.s = c->attr;
Expand Down
10 changes: 5 additions & 5 deletions modules/registrar/reply.c
Expand Up @@ -104,7 +104,7 @@ static inline int calc_temp_gruu_len(str* aor,str* instance,str *callid)
{
int time_len,temp_gr_len;

int2str((unsigned long)act_time,&time_len);
int2str((unsigned long)get_act_time(),&time_len);
temp_gr_len = time_len + aor->len + instance->len - 2 + callid->len + 3; /* <instance> and blank spaces */
temp_gr_len = (temp_gr_len/3 + (temp_gr_len%3?1:0))*4; /* base64 encoding */
return temp_gr_len;
Expand All @@ -123,7 +123,7 @@ static inline unsigned int calc_buf_len(ucontact_t* c,int build_gruu,

len = 0;
while(c) {
if (VALID_CONTACT(c, act_time)) {
if (VALID_CONTACT(c, get_act_time())) {
if (len) len += CONTACT_SEP_LEN;
len += 2 /* < > */ + c->c.len;
qlen = len_q(c->q);
Expand Down Expand Up @@ -186,7 +186,7 @@ char * build_temp_gruu(str *aor,str *instance,str *callid,int *len)
{
int time_len,i;
char *p;
char *time_str = int2str((unsigned long)act_time,&time_len);
char *time_str = int2str((unsigned long)get_act_time(),&time_len);
str *magic;

*len = time_len + aor->len + instance->len + callid->len + 3 - 2; /* +3 blank spaces, -2 discarded chars of instance in memcpy below */
Expand Down Expand Up @@ -255,7 +255,7 @@ int build_contact(ucontact_t* c,struct sip_msg *_m)

fl = 0;
while(c) {
if (VALID_CONTACT(c, act_time)) {
if (VALID_CONTACT(c, get_act_time())) {
if (fl) {
memcpy(p, CONTACT_SEP, CONTACT_SEP_LEN);
p += CONTACT_SEP_LEN;
Expand All @@ -278,7 +278,7 @@ int build_contact(ucontact_t* c,struct sip_msg *_m)

memcpy(p, EXPIRES_PARAM, EXPIRES_PARAM_LEN);
p += EXPIRES_PARAM_LEN;
cp = int2str((int)(c->expires - act_time), &len);
cp = int2str((int)(c->expires - get_act_time()), &len);
memcpy(p, cp, len);
p += len;

Expand Down
14 changes: 7 additions & 7 deletions modules/registrar/save.c
Expand Up @@ -309,7 +309,7 @@ static inline int insert_contacts(struct sip_msg* _m, contact_t* _c,
}

if ( tcp_check && e_max>0 ) {
e_max -= act_time;
e_max -= get_act_time();
trans_set_dst_attr( &_m->rcv, DST_FCNTL_SET_LIFETIME,
(void*)(long)(e_max + 10) );
}
Expand Down Expand Up @@ -364,7 +364,7 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
if (_sctx->max_contacts) {
c = _r->contacts;
while(c) {
if (VALID_CONTACT(c, act_time)) num++;
if (VALID_CONTACT(c, get_act_time())) num++;
c = c->next;
}
}
Expand Down Expand Up @@ -402,7 +402,7 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
so remove the oldest valid one to prevent this */
for( c_it=_r->contacts,c_last=NULL ; c_it ;
c_it=c_it->next )
if (VALID_CONTACT(c_it, act_time))
if (VALID_CONTACT(c_it, get_act_time()))
c_last=c_it;
if (c_last==NULL) {
LM_CRIT("BUG - overflow detected but no valid "
Expand Down Expand Up @@ -454,7 +454,7 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
/* do update */
/* if the contact to be updated is not valid, it will be after
* update, so need to compensate the total number of contact */
if ( !VALID_CONTACT(c,act_time) )
if ( !VALID_CONTACT(c,get_act_time()) )
num++;
while ( _sctx->max_contacts && num>_sctx->max_contacts ) {
if (_sctx->flags&REG_SAVE_FORCE_REG_FLAG) {
Expand All @@ -463,7 +463,7 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
(but not the one to be updated !) */
for( c_it=_r->contacts,c_last=NULL ; c_it ;
c_it=c_it->next )
if (VALID_CONTACT(c_it, act_time) && c_it!=c)
if (VALID_CONTACT(c_it, get_act_time()) && c_it!=c)
c_last=c_it;
if (c_last==NULL) {
LM_CRIT("BUG - overflow detected but no "
Expand Down Expand Up @@ -513,7 +513,7 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
}

if ( tcp_check && e_max>-1 ) {
if (e_max) e_max -= act_time;
if (e_max) e_max -= get_act_time();
trans_set_dst_attr( &_m->rcv, DST_FCNTL_SET_LIFETIME,
(void*)(long)(e_max + 10) );
}
Expand Down Expand Up @@ -662,7 +662,7 @@ int save_aux(struct sip_msg* _m, str* forced_binding, char* _d, char* _f, char*
c = get_first_contact(_m);
}

get_act_time();
update_act_time();

if (_s) {
if (pv_get_spec_value( _m, (pv_spec_p)_s, &val)!=0) {
Expand Down
20 changes: 11 additions & 9 deletions modules/registrar/sip_msg.c
Expand Up @@ -33,10 +33,12 @@
#include "../../parser/parse_expires.h"
#include "../../ut.h"
#include "../../qvalue.h"

#include "../../lib/reg/rerrno.h"
#include "../../lib/reg/sip_msg.h"
#include "../../lib/reg/regtime.h"

#include "reg_mod.h" /* Module parameters */
#include "regtime.h" /* act_time */
#include "sip_msg.h"


Expand All @@ -54,11 +56,11 @@ static inline int get_expires_hf(struct sip_msg* _m)
p = (exp_body_t*)_m->expires->parsed;
if (p->valid) {
if (p->val != 0) {
return p->val + act_time;
return p->val + get_act_time();
} else return 0;
} else return act_time + default_expires;
} else return get_act_time() + default_expires;
} else {
return act_time + default_expires;
return get_act_time() + default_expires;
}
}

Expand Down Expand Up @@ -92,15 +94,15 @@ void calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e, struct save
*_e = default_expires;
}
/* Convert to absolute value */
if (*_e != 0) *_e += act_time;
if (*_e != 0) *_e += get_act_time();
}

if ((*_e != 0) && ((*_e - act_time) < min_exp)) {
*_e = min_exp + act_time;
if ((*_e != 0) && ((*_e - get_act_time()) < min_exp)) {
*_e = min_exp + get_act_time();
}

if ((*_e != 0) && max_exp && ((*_e - act_time) > max_exp)) {
*_e = max_exp + act_time;
if ((*_e != 0) && max_exp && ((*_e - get_act_time()) > max_exp)) {
*_e = max_exp + get_act_time();
}
}

0 comments on commit 1f9aa6d

Please sign in to comment.