switch_utils: Add day of week 3 letter initial usage in "wday" field in the dialplan. Example : mon-fri. Using number as before is still supported. Several public switch function are available.
This commit is contained in:
parent
c9fcce0869
commit
59ec8ced59
|
@ -680,6 +680,9 @@ SWITCH_DECLARE(switch_bool_t) switch_network_list_validate_ip_token(switch_netwo
|
||||||
|
|
||||||
SWITCH_DECLARE(int) switch_inet_pton(int af, const char *src, void *dst);
|
SWITCH_DECLARE(int) switch_inet_pton(int af, const char *src, void *dst);
|
||||||
|
|
||||||
|
SWITCH_DECLARE(const char *) switch_dow_int2str(int val);
|
||||||
|
SWITCH_DECLARE(int) switch_dow_str2int(const char *exp);
|
||||||
|
SWITCH_DECLARE(int) 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);
|
||||||
SWITCH_DECLARE(int) switch_tod_cmp(const char *exp, int val);
|
SWITCH_DECLARE(int) switch_tod_cmp(const char *exp, int val);
|
||||||
|
|
||||||
|
|
|
@ -2466,6 +2466,82 @@ SWITCH_DECLARE(int) switch_isxdigit(int c)
|
||||||
return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & (_N | _X)));
|
return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & (_N | _X)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *DOW[] = {
|
||||||
|
"sat",
|
||||||
|
"sun",
|
||||||
|
"mon",
|
||||||
|
"tue",
|
||||||
|
"wed",
|
||||||
|
"thu",
|
||||||
|
"fri",
|
||||||
|
"sat",
|
||||||
|
"sun",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
SWITCH_DECLARE(const char *) switch_dow_int2str(int val) {
|
||||||
|
if (val >= sizeof(DOW) / sizeof (const char*)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return DOW[val];
|
||||||
|
}
|
||||||
|
|
||||||
|
SWITCH_DECLARE(int) switch_dow_str2int(const char *exp) {
|
||||||
|
int ret = -1;
|
||||||
|
int x = -1;
|
||||||
|
for (x = 0;; x++) {
|
||||||
|
if (!DOW[x]) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcasecmp(DOW[x], exp)) {
|
||||||
|
ret = x;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
SWITCH_DECLARE(int) switch_dow_cmp(const char *exp, int val)
|
||||||
|
{
|
||||||
|
char *dup = strdup(exp);
|
||||||
|
char *p_start;
|
||||||
|
char *p_end;
|
||||||
|
int ret = 0;
|
||||||
|
int start, end;
|
||||||
|
|
||||||
|
switch_assert(dup);
|
||||||
|
|
||||||
|
p_start = dup;
|
||||||
|
|
||||||
|
if ((p_end=strchr(dup, '-'))) {
|
||||||
|
*p_end++ = '\0';
|
||||||
|
} else {
|
||||||
|
p_end = p_start;
|
||||||
|
}
|
||||||
|
if (strlen(p_start) == 3) {
|
||||||
|
start = switch_dow_str2int(p_start);
|
||||||
|
} else {
|
||||||
|
start = atol(p_start);
|
||||||
|
}
|
||||||
|
if (strlen(p_end) == 3) {
|
||||||
|
end = switch_dow_str2int(p_end);
|
||||||
|
} else {
|
||||||
|
end = atol(p_end);
|
||||||
|
}
|
||||||
|
/* Following used for this example : mon-sat = 2-0, so we need to make 0(sat) + 7 */
|
||||||
|
if (end < start) {
|
||||||
|
end += 7;
|
||||||
|
}
|
||||||
|
if (start != -1 && end != -1 && val >= start && val <= end) {
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch_safe_free(dup);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
SWITCH_DECLARE(int) switch_number_cmp(const char *exp, int val)
|
SWITCH_DECLARE(int) switch_number_cmp(const char *exp, int val)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
|
|
@ -2733,9 +2733,9 @@ SWITCH_DECLARE(int) switch_xml_std_datetime_check(switch_xml_t xcond) {
|
||||||
|
|
||||||
if (time_match && xwday) {
|
if (time_match && xwday) {
|
||||||
int test = tm.tm_wday + 1;
|
int test = tm.tm_wday + 1;
|
||||||
time_match = switch_number_cmp(xwday, test);
|
time_match = switch_dow_cmp(xwday, test);
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9,
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9,
|
||||||
"XML DateTime Check: day of week[%d] =~ %s (%s)\n", test, xwday, time_match ? "PASS" : "FAIL");
|
"XML DateTime Check: day of week[%s] =~ %s (%s)\n", switch_dow_int2str(test), xwday, time_match ? "PASS" : "FAIL");
|
||||||
}
|
}
|
||||||
if (time_match && xhour) {
|
if (time_match && xhour) {
|
||||||
int test = tm.tm_hour;
|
int test = tm.tm_hour;
|
||||||
|
|
Loading…
Reference in New Issue