diff options
author | Corey Farrell <git@cfware.com> | 2017-07-10 15:04:58 -0400 |
---|---|---|
committer | Corey Farrell <git@cfware.com> | 2017-07-13 11:44:14 -0400 |
commit | 78a50b034368d3a21f81dfce0fc740021092d7f1 (patch) | |
tree | 56bf02121d7a13e674b39b68081325a0a46fd0df /main/config.c | |
parent | b0e184f0a7e70dc916c0bc982128934cd1fe7076 (diff) |
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
Diffstat (limited to 'main/config.c')
-rw-r--r-- | main/config.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/main/config.c b/main/config.c index a3e09f67e..3d8dcfb3d 100644 --- a/main/config.c +++ b/main/config.c @@ -3741,6 +3741,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; |