Skip to content

Commit

Permalink
time rec support: Remove dead code
Browse files Browse the repository at this point in the history
    * simplify "always false" if conditions
    * get rid of redundant (duplicate) memset() operations
  • Loading branch information
liviuchircu committed Sep 24, 2020
1 parent a100b7a commit dc9b295
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 20 deletions.
5 changes: 1 addition & 4 deletions modules/cfgutils/cfgutils.c
Expand Up @@ -893,11 +893,8 @@ int check_time_rec(struct sip_msg *msg, str *time_str, str *tz,
if (time_rec->dtstart==0)
goto success;

memset( &att, 0, sizeof(att));

/* set current time */
if (ac_tm_set_time(&att, check_time))
goto error;
ac_tm_set_time(&att, check_time);

/* does the recv_time match the specified interval? */
if (check_tmrec( time_rec, &att)!=0)
Expand Down
4 changes: 2 additions & 2 deletions modules/cpl_c/cpl_switches.h
Expand Up @@ -735,8 +735,8 @@ static inline char *run_time_switch( struct cpl_interpreter *intr )
LM_ERR("no more pkg error\n");
goto script_error;
}
if(ac_tm_set_time( &att, intr->recv_time))
goto runtime_error;
ac_tm_set_time( &att, intr->recv_time);

/* let's see how many attributes we have */
nr_attrs = NR_OF_ATTR(kid);
/* get the attributes */
Expand Down
4 changes: 1 addition & 3 deletions modules/dialplan/dp_repl.c
Expand Up @@ -348,9 +348,7 @@ static inline int check_time(tmrec_t *time_rec) {
// timerec_print(time_rec);

// Set Current Time
memset(&att, 0, sizeof(att));
if(ac_tm_set_time(&att, time(0)))
return -1;
ac_tm_set_time(&att, time(0));

// Check_Tmrec will return 0 on successfully time recurrence match
if(check_tmrec(time_rec, &att) != 0)
Expand Down
5 changes: 1 addition & 4 deletions modules/drouting/prefix_tree.c
Expand Up @@ -91,11 +91,8 @@ check_time(
if (time_rec->dtstart==0)
return 1;

memset( &att, 0, sizeof(att));

/* set current time */
if ( ac_tm_set_time( &att, time(0) ) )
return 0;
ac_tm_set_time(&att, time(0));

/* does the recv_time match the specified interval? */
if (check_tmrec( time_rec, &att)!=0)
Expand Down
9 changes: 3 additions & 6 deletions time_rec.c
Expand Up @@ -50,10 +50,8 @@ static inline int strz2int(char *_bp)
return _v;
}

int ac_tm_fill(ac_tm_p _atp, struct tm* _tm)
static inline void ac_tm_fill(ac_tm_p _atp, struct tm* _tm)
{
if(!_atp || !_tm)
return -1;
_atp->t.tm_sec = _tm->tm_sec; /* seconds */
_atp->t.tm_min = _tm->tm_min; /* minutes */
_atp->t.tm_hour = _tm->tm_hour; /* hours */
Expand All @@ -68,7 +66,6 @@ int ac_tm_fill(ac_tm_p _atp, struct tm* _tm)
_atp->yweek = ac_get_yweek(_tm);
_atp->ywday = ac_get_wday_yr(_tm);
_atp->mwday = ac_get_wday_mr(_tm);
return 0;
}


Expand Down Expand Up @@ -142,15 +139,15 @@ time_t tz_adjust_ts(time_t unix_time, const str *tz)



int ac_tm_set_time(ac_tm_p _atp, time_t _t)
void ac_tm_set_time(ac_tm_p _atp, time_t _t)
{
struct tm ltime;

memset(_atp, 0, sizeof *_atp);
_atp->time = _t;

localtime_r(&_t, &ltime);
return ac_tm_fill(_atp, &ltime);
ac_tm_fill(_atp, &ltime);
}

int ac_get_mweek(struct tm* _tm)
Expand Down
2 changes: 1 addition & 1 deletion time_rec.h
Expand Up @@ -144,7 +144,7 @@ typedef struct _tmrec
} tmrec_t, *tmrec_p;


int ac_tm_set_time(ac_tm_p, time_t);
void ac_tm_set_time(ac_tm_p _atp, time_t _t);

int ac_tm_reset(ac_tm_p);

Expand Down

0 comments on commit dc9b295

Please sign in to comment.