Merge pull request #308 in FS/freeswitch from ~FRANCOIS/freeswitch-fs-7198:master to master
* commit '48b44832b2902831c86e96ca7fa29680eec7defa': FS-7198 add coma separated values and reverse ranges for time-of-day and day-of-week matches
This commit is contained in:
commit
934e445b6f
|
@ -3320,37 +3320,24 @@ SWITCH_DECLARE(int) switch_fulldate_cmp(const char *exp, switch_time_t *ts)
|
||||||
char *dup = strdup(exp);
|
char *dup = strdup(exp);
|
||||||
char *sStart;
|
char *sStart;
|
||||||
char *sEnd;
|
char *sEnd;
|
||||||
|
char *cur;
|
||||||
|
char *p;
|
||||||
|
|
||||||
switch_assert(dup);
|
switch_assert(dup);
|
||||||
|
|
||||||
sStart = dup;
|
cur = dup;
|
||||||
if ((sEnd=strchr(dup, '~'))) {
|
if ((p = strchr(cur, ','))) {
|
||||||
char *sDate = sStart;
|
*p++ = '\0';
|
||||||
char *sTime;
|
}
|
||||||
*sEnd++ = '\0';
|
|
||||||
if ((sTime=strchr(sStart, ' '))) {
|
|
||||||
switch_time_t tsStart;
|
|
||||||
struct tm tmTmp;
|
|
||||||
int year = 1970, month = 1, day = 1;
|
|
||||||
int hour = 0, min = 0, sec = 0;
|
|
||||||
*sTime++ = '\0';
|
|
||||||
|
|
||||||
memset(&tmTmp, 0, sizeof(tmTmp));
|
while (cur) {
|
||||||
switch_split_date(sDate, &year, &month, &day);
|
sStart = cur;
|
||||||
switch_split_time(sTime, &hour, &min, &sec);
|
if ((sEnd=strchr(cur, '~'))) {
|
||||||
tmTmp.tm_year = year-1900;
|
char *sDate = sStart;
|
||||||
tmTmp.tm_mon = month-1;
|
char *sTime;
|
||||||
tmTmp.tm_mday = day;
|
*sEnd++ = '\0';
|
||||||
|
if ((sTime=strchr(sStart, ' '))) {
|
||||||
tmTmp.tm_hour = hour;
|
switch_time_t tsStart;
|
||||||
tmTmp.tm_min = min;
|
|
||||||
tmTmp.tm_sec = sec;
|
|
||||||
tmTmp.tm_isdst = 0;
|
|
||||||
tsStart = mktime(&tmTmp);
|
|
||||||
|
|
||||||
sDate = sEnd;
|
|
||||||
if ((sTime=strchr(sEnd, ' '))) {
|
|
||||||
switch_time_t tsEnd;
|
|
||||||
struct tm tmTmp;
|
struct tm tmTmp;
|
||||||
int year = 1970, month = 1, day = 1;
|
int year = 1970, month = 1, day = 1;
|
||||||
int hour = 0, min = 0, sec = 0;
|
int hour = 0, min = 0, sec = 0;
|
||||||
|
@ -3367,14 +3354,44 @@ SWITCH_DECLARE(int) switch_fulldate_cmp(const char *exp, switch_time_t *ts)
|
||||||
tmTmp.tm_min = min;
|
tmTmp.tm_min = min;
|
||||||
tmTmp.tm_sec = sec;
|
tmTmp.tm_sec = sec;
|
||||||
tmTmp.tm_isdst = 0;
|
tmTmp.tm_isdst = 0;
|
||||||
tsEnd = mktime(&tmTmp);
|
tsStart = mktime(&tmTmp);
|
||||||
|
|
||||||
if (tsStart <= *ts/1000000 && tsEnd > *ts/1000000) {
|
sDate = sEnd;
|
||||||
switch_safe_free(dup);
|
if ((sTime=strchr(sEnd, ' '))) {
|
||||||
return 1;
|
switch_time_t tsEnd;
|
||||||
|
struct tm tmTmp;
|
||||||
|
int year = 1970, month = 1, day = 1;
|
||||||
|
int hour = 0, min = 0, sec = 0;
|
||||||
|
*sTime++ = '\0';
|
||||||
|
|
||||||
|
memset(&tmTmp, 0, sizeof(tmTmp));
|
||||||
|
switch_split_date(sDate, &year, &month, &day);
|
||||||
|
switch_split_time(sTime, &hour, &min, &sec);
|
||||||
|
tmTmp.tm_year = year-1900;
|
||||||
|
tmTmp.tm_mon = month-1;
|
||||||
|
tmTmp.tm_mday = day;
|
||||||
|
|
||||||
|
tmTmp.tm_hour = hour;
|
||||||
|
tmTmp.tm_min = min;
|
||||||
|
tmTmp.tm_sec = sec;
|
||||||
|
tmTmp.tm_isdst = 0;
|
||||||
|
tsEnd = mktime(&tmTmp);
|
||||||
|
|
||||||
|
if (tsStart <= *ts/1000000 && tsEnd > *ts/1000000) {
|
||||||
|
switch_safe_free(dup);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cur = p;
|
||||||
|
if (p) {
|
||||||
|
if ((p = strchr(p, ','))) {
|
||||||
|
*p++ = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
switch_safe_free(dup);
|
switch_safe_free(dup);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -3711,7 +3728,7 @@ SWITCH_DECLARE(switch_bool_t) switch_dow_cmp(const char *exp, int val)
|
||||||
} else {
|
} else {
|
||||||
/* Valid day found */
|
/* Valid day found */
|
||||||
if (range_start != DOW_EOF) { /* Evaluating a range */
|
if (range_start != DOW_EOF) { /* Evaluating a range */
|
||||||
if (val >= range_start && val <= cur) {
|
if (range_start <= cur ? (val >= range_start && val <= cur) : (val >= range_start || val <= cur)) {
|
||||||
return SWITCH_TRUE;
|
return SWITCH_TRUE;
|
||||||
}
|
}
|
||||||
range_start = DOW_EOF;
|
range_start = DOW_EOF;
|
||||||
|
@ -3754,35 +3771,56 @@ SWITCH_DECLARE(int) switch_tod_cmp(const char *exp, int val)
|
||||||
char *maxh;
|
char *maxh;
|
||||||
char *maxm;
|
char *maxm;
|
||||||
char *maxs;
|
char *maxs;
|
||||||
|
char *cur;
|
||||||
|
char *p;
|
||||||
|
int range_start, range_end;
|
||||||
|
|
||||||
switch_assert(dup);
|
switch_assert(dup);
|
||||||
|
|
||||||
minh = dup;
|
cur = dup;
|
||||||
if ((minm=strchr(dup, ':'))) {
|
if ((p = strchr(cur, ','))) {
|
||||||
*minm++ = '\0';
|
*p++ = '\0';
|
||||||
if ((maxh=strchr(minm, '-'))) {
|
}
|
||||||
if ((maxm=strchr(maxh, ':'))) {
|
|
||||||
*maxh++ = '\0';
|
|
||||||
*maxm++ = '\0';
|
|
||||||
/* Check if min/max seconds are present */
|
|
||||||
if ((mins=strchr(minm, ':'))) {
|
|
||||||
*mins++ = '\0';
|
|
||||||
} else {
|
|
||||||
mins = "00";
|
|
||||||
}
|
|
||||||
if ((maxs=strchr(maxm, ':'))) {
|
|
||||||
*maxs++ = '\0';
|
|
||||||
} else {
|
|
||||||
maxs = "00";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (val >= (atol(minh) * 60 * 60) + (atol(minm) * 60) + atol(mins) && val < (atol(maxh) * 60 * 60) + (atol(maxm) * 60) + atol(maxs)) {
|
while (cur) {
|
||||||
switch_safe_free(dup);
|
minh = cur;
|
||||||
return 1;
|
if ((minm=strchr(cur, ':'))) {
|
||||||
|
*minm++ = '\0';
|
||||||
|
if ((maxh=strchr(minm, '-'))) {
|
||||||
|
if ((maxm=strchr(maxh, ':'))) {
|
||||||
|
*maxh++ = '\0';
|
||||||
|
*maxm++ = '\0';
|
||||||
|
/* Check if min/max seconds are present */
|
||||||
|
if ((mins=strchr(minm, ':'))) {
|
||||||
|
*mins++ = '\0';
|
||||||
|
} else {
|
||||||
|
mins = "00";
|
||||||
|
}
|
||||||
|
if ((maxs=strchr(maxm, ':'))) {
|
||||||
|
*maxs++ = '\0';
|
||||||
|
} else {
|
||||||
|
maxs = "00";
|
||||||
|
}
|
||||||
|
|
||||||
|
range_start = (atol(minh) * 60 * 60) + (atol(minm) * 60) + atol(mins);
|
||||||
|
range_end = (atol(maxh) * 60 * 60) + (atol(maxm) * 60) + atol(maxs);
|
||||||
|
if (range_start <= range_end ? (val >= range_start && val <= range_end) : (val >= range_start || val <= range_end)) {
|
||||||
|
switch_safe_free(dup);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cur = p;
|
||||||
|
if (p) {
|
||||||
|
if ((p = strchr(p, ','))) {
|
||||||
|
*p++ = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_safe_free(dup);
|
switch_safe_free(dup);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue