Ejemplo n.º 1
0
/**
 *
 * return values:
			1 - match
			-1 - otherwise
 */
int check_time_rec(struct sip_msg *msg, str *time_str)
{
	tmrec_p time_rec = 0;
	char *p, *s;
	ac_tm_t att;

	p = time_str->s;

	LM_INFO("Parsing : %.*s\n", time_str->len, time_str->s);

	time_rec = tmrec_new(SHM_ALLOC);
	if (time_rec==0) {
		LM_ERR("no more shm mem\n");
		goto error;
	}

	load_TR_value( p, s, time_rec, tr_parse_dtstart, parse_error, done);
	load_TR_value( p, s, time_rec, tr_parse_dtend, parse_error, done);
	load_TR_value( p, s, time_rec, tr_parse_duration, parse_error, done);
	load_TR_value( p, s, time_rec, tr_parse_freq, parse_error, done);
	load_TR_value( p, s, time_rec, tr_parse_until, parse_error, done);
	load_TR_value( p, s, time_rec, tr_parse_interval, parse_error, done);
	load_TR_value( p, s, time_rec, tr_parse_byday, parse_error, done);
	load_TR_value( p, s, time_rec, tr_parse_bymday, parse_error, done);
	load_TR_value( p, s, time_rec, tr_parse_byyday, parse_error, done);
	load_TR_value( p, s, time_rec, tr_parse_byweekno, parse_error, done);
	load_TR_value( p, s, time_rec, tr_parse_bymonth, parse_error, done);

	/* success */

	LM_DBG("Time rec created\n");

done:
	/* shortcut: if there is no dstart, timerec is valid */
	if (time_rec->dtstart==0)
		return 1;

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

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

	/* does the recv_time match the specified interval?  */
	if (check_tmrec( time_rec, &att, 0)!=0)
		return -1;

	return 1;

parse_error:
	LM_ERR("parse error in <%s> around position %i\n",
		time_str->s, (int)(long)(p-time_str->s));
error:
	if (time_rec)
		tmrec_free( time_rec );
	return -1;
}
Ejemplo n.º 2
0
// Validate Passed Time Recurrence Instance
static inline int check_time(tmrec_t *time_rec) {
	ac_tm_t att;

	// No TimeRec: Rule is Valid
	if(time_rec->dtstart == 0)
		return 1;

	// Uncomment to enable Debug
	// timerec_print(time_rec);

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

	// Check_Tmrec will return 0 on successfully time recurrence match
	if(check_tmrec(time_rec, &att, 0) != 0)
		return 0;

	// Recurrence Matched -- Validating Rule
	return 1;
}
Ejemplo n.º 3
0
static inline int
check_time(
		tmrec_t *time_rec
		)
{
	ac_tm_t att;

	/* shortcut: if there is no dstart, timerec is valid */
	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;

	/* does the recv_time match the specified interval?  */
	if (check_tmrec( time_rec, &att, 0)!=0)
		return 0;

	return 1;
}