예제 #1
0
static int w_tmrec_match(struct sip_msg* msg, char* rec, char* t)
{
	str rv;
	time_t tv;
	int ti;
	ac_tm_t act;
	tmrec_t tmr;

	if(msg==NULL)
		return -1;

	if(fixup_get_svalue(msg, (gparam_t*)rec, &rv)!=0)
	{
		LM_ERR("invalid time recurrence parameter value\n");
		return -1;
	}

	if(t!=NULL)
	{
		if(fixup_get_ivalue(msg, (gparam_t*)t, &ti)!=0)
		{
			LM_ERR("invalid time stamp parameter value\n");
			return -1;
		}
		tv = (time_t)ti;
	} else {
		tv = time(NULL);
	}

	memset(&act, 0, sizeof(act));
	memset(&tmr, 0, sizeof(tmr));

	/* parse time recurrence definition */
	if(tr_parse_recurrence_string(&tmr, rv.s, tmrec_separator)<0)
		return -1;

	/* if there is no dstart, timerec is valid */
	if (tmr.dtstart==0)
		goto done;

	/* set current time */
	if (ac_tm_set_time(&act, tv)<0)
		goto error;

	/* match the specified recurence */
	if (tr_check_recurrence(&tmr, &act, 0)!=0)
		goto error;

done:
	tmrec_destroy(&tmr);
	ac_tm_destroy(&act);
	return 1;

error:
	tmrec_destroy(&tmr);
	ac_tm_destroy(&act);
	return -1;
}
예제 #2
0
파일: cfgutils.c 프로젝트: rrb3942/opensips
/**
 *
 * 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;
}
예제 #3
0
파일: dp_repl.c 프로젝트: Danfx/opensips
// 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;
}
예제 #4
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;
}