mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 15:45:18 +00:00
core: Add PARSE_TIMELEN support to ast_parse_arg and ACO.
This adds support for parsing timelen values from config files. This includes support for all flags which apply to PARSE_INT32. Support for this parser is added to ACO via the OPT_TIMELEN_T option type. Fixes an issue where extra characters provided to ast_app_parse_timelen were ignored, they now cause an error. Testing is included. ASTERISK-27117 #close Change-Id: I6b333feca7e3f83b4ef5bf2636fc0fd613742554
This commit is contained in:
@@ -3743,6 +3743,55 @@ uint32_done:
|
||||
break;
|
||||
}
|
||||
|
||||
case PARSE_TIMELEN:
|
||||
{
|
||||
int x = 0;
|
||||
int *result = p_result;
|
||||
int def = result ? *result : 0;
|
||||
int high = INT_MAX;
|
||||
int low = INT_MIN;
|
||||
enum ast_timelen defunit;
|
||||
|
||||
defunit = va_arg(ap, enum ast_timelen);
|
||||
/* optional arguments: default value and/or (low, high) */
|
||||
if (flags & PARSE_DEFAULT) {
|
||||
def = va_arg(ap, int);
|
||||
}
|
||||
if (flags & (PARSE_IN_RANGE | PARSE_OUT_RANGE)) {
|
||||
low = va_arg(ap, int);
|
||||
high = va_arg(ap, int);
|
||||
}
|
||||
if (ast_strlen_zero(arg)) {
|
||||
error = 1;
|
||||
goto timelen_done;
|
||||
}
|
||||
error = ast_app_parse_timelen(arg, &x, defunit);
|
||||
if (error || x < INT_MIN || x > INT_MAX) {
|
||||
/* Parse error, or type out of int bounds */
|
||||
error = 1;
|
||||
goto timelen_done;
|
||||
}
|
||||
error = (x < low) || (x > high);
|
||||
if (flags & PARSE_RANGE_DEFAULTS) {
|
||||
if (x < low) {
|
||||
def = low;
|
||||
} else if (x > high) {
|
||||
def = high;
|
||||
}
|
||||
}
|
||||
if (flags & PARSE_OUT_RANGE) {
|
||||
error = !error;
|
||||
}
|
||||
timelen_done:
|
||||
if (result) {
|
||||
*result = error ? def : x;
|
||||
}
|
||||
|
||||
ast_debug(3, "extract timelen from [%s] in [%d, %d] gives [%d](%d)\n",
|
||||
arg, low, high, result ? *result : x, error);
|
||||
break;
|
||||
}
|
||||
|
||||
case PARSE_DOUBLE:
|
||||
{
|
||||
double *result = p_result;
|
||||
|
Reference in New Issue
Block a user