Merge pull request #196 in FS/freeswitch from ~ARTURZ/freeswitch:FS-7304-dialplan-reversed-ranges to master
* commit '2d07448822b673af2de6b4b0b4bfcd68b96f3d01': FS-7304: Multiple and reversed ranges for XML dialplan date and time conditions
This commit is contained in:
commit
9a6c29f8f7
|
@ -3464,42 +3464,21 @@ SWITCH_DECLARE(switch_bool_t) switch_dow_cmp(const char *exp, int val)
|
||||||
|
|
||||||
SWITCH_DECLARE(int) switch_number_cmp(const char *exp, int val)
|
SWITCH_DECLARE(int) switch_number_cmp(const char *exp, int val)
|
||||||
{
|
{
|
||||||
char *p;
|
// Expression exp must be a comma separated list of numbers or ranges.
|
||||||
|
// To match numbers not in range 9-17, enter the reversed range 18-8.
|
||||||
if ((p = strchr(exp, '-'))) {
|
for (;; ++exp) {
|
||||||
int min;
|
int a = strtol(exp, (char **)&exp, 10);
|
||||||
int max;
|
if (*exp != '-') {
|
||||||
|
if (a == val)
|
||||||
min = atol(exp);
|
|
||||||
p++;
|
|
||||||
max = atol(p);
|
|
||||||
|
|
||||||
if (val >= min && val <= max) {
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
} else if ((p = strchr(exp, ','))) {
|
|
||||||
const char *cur = exp;
|
|
||||||
p++;
|
|
||||||
while (cur) {
|
|
||||||
if (atol(cur) == val) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
cur = p;
|
|
||||||
if (p && p + 1) {
|
|
||||||
if ((p = strchr((p + 1), ','))) {
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (atol(exp) == val) {
|
int b = strtol(++exp, (char **)&exp, 10);
|
||||||
|
if (a <= b ? (val >= a && val <=b ) : (val >= a || val <= b))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
if (*exp != ',')
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SWITCH_DECLARE(int) switch_tod_cmp(const char *exp, int val)
|
SWITCH_DECLARE(int) switch_tod_cmp(const char *exp, int val)
|
||||||
|
|
Loading…
Reference in New Issue