<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/6010">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Jenkins2: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">core: Add PARSE_TIMELEN support to ast_parse_arg and ACO.<br><br>This adds support for parsing timelen values from config files. This<br>includes support for all flags which apply to PARSE_INT32. Support for<br>this parser is added to ACO via the OPT_TIMELEN_T option type.<br><br>Fixes an issue where extra characters provided to ast_app_parse_timelen<br>were ignored, they now cause an error.<br><br>Testing is included.<br><br>ASTERISK-27117 #close<br><br>Change-Id: I6b333feca7e3f83b4ef5bf2636fc0fd613742554<br>---<br>M UPGRADE.txt<br>M configs/samples/config_test.conf.sample<br>M include/asterisk/config.h<br>M include/asterisk/config_options.h<br>M main/app.c<br>M main/config.c<br>M main/config_options.c<br>M tests/test_config.c<br>8 files changed, 233 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/UPGRADE.txt b/UPGRADE.txt<br>index d023f40..334fad3 100644<br>--- a/UPGRADE.txt<br>+++ b/UPGRADE.txt<br>@@ -21,6 +21,12 @@<br> === UPGRADE-12.txt -- Upgrade info for 11 to 12<br> ===========================================================<br> <br>+From 13.17.0 to 13.18.0:<br>+<br>+Core:<br>+ - ast_app_parse_timelen now returns an error if it encounters extra characters<br>+ at the end of the string to be parsed.<br>+<br> From 13.15.0 to 13.16.0:<br> <br> Core:<br>diff --git a/configs/samples/config_test.conf.sample b/configs/samples/config_test.conf.sample<br>index 2fff45e..b7cb212 100644<br>--- a/configs/samples/config_test.conf.sample<br>+++ b/configs/samples/config_test.conf.sample<br>@@ -6,6 +6,10 @@<br> [global]<br> intopt=-1<br> uintopt=1<br>+timelenopt1=1ms<br>+timelenopt2=1s<br>+timelenopt3=1m<br>+timelenopt4=1h<br> doubleopt=0.1<br> sockaddropt=1.2.3.4:1234<br> boolopt=true<br>@@ -23,6 +27,10 @@<br> [item]<br> intopt=-1<br> uintopt=1<br>+timelenopt1=1<br>+timelenopt2=1<br>+timelenopt3=1<br>+timelenopt4=1<br> doubleopt=0.1<br> sockaddropt=1.2.3.4:1234<br> boolopt=true<br>diff --git a/include/asterisk/config.h b/include/asterisk/config.h<br>index 4dc473c..c61cee5 100644<br>--- a/include/asterisk/config.h<br>+++ b/include/asterisk/config.h<br>@@ -1086,6 +1086,11 @@<br> PARSE_UINT16 = 0x0005,<br> #endif<br> <br>+ /* Returns an int processed by ast_app_parse_timelen.<br>+ * The first argument is an enum ast_timelen value (required).<br>+ */<br>+ PARSE_TIMELEN = 0x0006,<br>+<br> /* Returns a struct ast_sockaddr, with optional default value<br> * (passed by reference) and port handling (accept, ignore,<br> * require, forbid). The format is 'ipaddress[:port]'. IPv6 address<br>@@ -1152,6 +1157,12 @@<br> * returns 1, b unchanged<br> * ast_parse_arg("12", PARSE_UINT32|PARSE_IN_RANGE|PARSE_RANGE_DEFAULTS, &a, 1, 10);<br> * returns 1, a = 10<br>+ * ast_parse_arg("223", PARSE_TIMELEN|PARSE_IN_RANGE, &a, TIMELEN_SECONDS, -1000, 1000);<br>+ * returns 0, a = 1000<br>+ * ast_parse_arg("223", PARSE_TIMELEN|PARSE_IN_RANGE, &a, TIMELEN_SECONDS, -1000, 250000);<br>+ * returns 0, a = 223000<br>+ * ast_parse_arg("223", PARSE_TIMELEN|PARSE_IN_RANGE|PARSE_DEFAULT, &a, TIMELEN_SECONDS, 9999, -1000, 250000);<br>+ * returns 0, a = 9999<br> * ast_parse_arg("www.foo.biz:44", PARSE_INADDR, &sa);<br> * returns 0, sa contains address and port<br> * ast_parse_arg("www.foo.biz", PARSE_INADDR|PARSE_PORT_REQUIRE, &sa);<br>diff --git a/include/asterisk/config_options.h b/include/asterisk/config_options.h<br>index 30d0c91..f4c3db1 100644<br>--- a/include/asterisk/config_options.h<br>+++ b/include/asterisk/config_options.h<br>@@ -467,6 +467,31 @@<br> * {endcode}<br> */<br> OPT_YESNO_T,<br>+<br>+ /*! \brief Type for default option handler for time length signed integers<br>+ *<br>+ * \note aco_option_register flags:<br>+ * See flags available for use with the PARSE_TIMELEN type for the ast_parse_arg function<br>+ * aco_option_register varargs:<br>+ * FLDSET macro with the field of type int<br>+ * The remaining varargs for should be arguments compatible with the varargs for the<br>+ * ast_parse_arg function with the PARSE_TIMELEN type and the flags passed in the<br>+ * aco_option_register flags parameter.<br>+ *<br>+ * \note In most situations, it is preferable to not pass the PARSE_DEFAULT flag. If a config<br>+ * contains an invalid value, it is better to let the config loading fail with warnings so that<br>+ * the problem is fixed by the administrator.<br>+ *<br>+ * Example:<br>+ * struct test_item {<br>+ * int timelen;<br>+ * };<br>+ * {code}<br>+ * aco_option_register(&cfg_info, "timelen", ACO_EXACT, my_types, "3", OPT_TIMELEN_T, PARSE_IN_RANGE, FLDSET(struct test_item, intopt), TIMELEN_MILLISECONDS, -10, 10);<br>+ * {endcode}<br>+ */<br>+ OPT_TIMELEN_T,<br>+<br> };<br> <br> /*! \brief A callback function for handling a particular option<br>diff --git a/main/app.c b/main/app.c<br>index ee7cef2..85dc87d 100644<br>--- a/main/app.c<br>+++ b/main/app.c<br>@@ -3069,19 +3069,32 @@<br> case 'h':<br> case 'H':<br> unit = TIMELEN_HOURS;<br>+ if (u[1] != '\0') {<br>+ return -1;<br>+ }<br> break;<br> case 's':<br> case 'S':<br> unit = TIMELEN_SECONDS;<br>+ if (u[1] != '\0') {<br>+ return -1;<br>+ }<br> break;<br> case 'm':<br> case 'M':<br> if (toupper(u[1]) == 'S') {<br> unit = TIMELEN_MILLISECONDS;<br>+ if (u[2] != '\0') {<br>+ return -1;<br>+ }<br> } else if (u[1] == '\0') {<br> unit = TIMELEN_MINUTES;<br>+ } else {<br>+ return -1;<br> }<br> break;<br>+ default:<br>+ return -1;<br> }<br> }<br> <br>diff --git a/main/config.c b/main/config.c<br>index b81a9f6..9be7581 100644<br>--- a/main/config.c<br>+++ b/main/config.c<br>@@ -3743,6 +3743,55 @@<br> break;<br> }<br> <br>+ case PARSE_TIMELEN:<br>+ {<br>+ int x = 0;<br>+ int *result = p_result;<br>+ int def = result ? *result : 0;<br>+ int high = INT_MAX;<br>+ int low = INT_MIN;<br>+ enum ast_timelen defunit;<br>+<br>+ defunit = va_arg(ap, enum ast_timelen);<br>+ /* optional arguments: default value and/or (low, high) */<br>+ if (flags & PARSE_DEFAULT) {<br>+ def = va_arg(ap, int);<br>+ }<br>+ if (flags & (PARSE_IN_RANGE | PARSE_OUT_RANGE)) {<br>+ low = va_arg(ap, int);<br>+ high = va_arg(ap, int);<br>+ }<br>+ if (ast_strlen_zero(arg)) {<br>+ error = 1;<br>+ goto timelen_done;<br>+ }<br>+ error = ast_app_parse_timelen(arg, &x, defunit);<br>+ if (error || x < INT_MIN || x > INT_MAX) {<br>+ /* Parse error, or type out of int bounds */<br>+ error = 1;<br>+ goto timelen_done;<br>+ }<br>+ error = (x < low) || (x > high);<br>+ if (flags & PARSE_RANGE_DEFAULTS) {<br>+ if (x < low) {<br>+ def = low;<br>+ } else if (x > high) {<br>+ def = high;<br>+ }<br>+ }<br>+ if (flags & PARSE_OUT_RANGE) {<br>+ error = !error;<br>+ }<br>+timelen_done:<br>+ if (result) {<br>+ *result = error ? def : x;<br>+ }<br>+<br>+ ast_debug(3, "extract timelen from [%s] in [%d, %d] gives [%d](%d)\n",<br>+ arg, low, high, result ? *result : x, error);<br>+ break;<br>+ }<br>+<br> case PARSE_DOUBLE:<br> {<br> double *result = p_result;<br>diff --git a/main/config_options.c b/main/config_options.c<br>index 81d0ff9..40fae16 100644<br>--- a/main/config_options.c<br>+++ b/main/config_options.c<br>@@ -36,6 +36,7 @@<br> #include "asterisk/config_options.h"<br> #include "asterisk/stringfields.h"<br> #include "asterisk/acl.h"<br>+#include "asterisk/app.h"<br> #include "asterisk/frame.h"<br> #include "asterisk/xmldoc.h"<br> #include "asterisk/cli.h"<br>@@ -120,6 +121,7 @@<br> <br> static int int_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);<br> static int uint_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);<br>+static int timelen_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);<br> static int double_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);<br> static int sockaddr_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);<br> static int stringfield_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);<br>@@ -153,6 +155,7 @@<br> case OPT_SOCKADDR_T: return sockaddr_handler_fn;<br> case OPT_STRINGFIELD_T: return stringfield_handler_fn;<br> case OPT_UINT_T: return uint_handler_fn;<br>+ case OPT_TIMELEN_T: return timelen_handler_fn;<br> <br> case OPT_CUSTOM_T: return NULL;<br> }<br>@@ -1380,6 +1383,39 @@<br> return res;<br> }<br> <br>+/*! \brief Default option handler for timelen signed integers<br>+ * \note For a description of the opt->flags and opt->args values, see the documentation for<br>+ * enum aco_option_type in config_options.h<br>+ */<br>+static int timelen_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj)<br>+{<br>+ int *field = (int *)(obj + opt->args[0]);<br>+ unsigned int flags = PARSE_TIMELEN | opt->flags;<br>+ int res = 0;<br>+ if (opt->flags & PARSE_IN_RANGE) {<br>+ if (opt->flags & PARSE_DEFAULT) {<br>+ res = ast_parse_arg(var->value, flags, field, (enum ast_timelen) opt->args[1], (int) opt->args[2], (int) opt->args[3], opt->args[4]);<br>+ } else {<br>+ res = ast_parse_arg(var->value, flags, field, (enum ast_timelen) opt->args[1], (int) opt->args[2], (int) opt->args[3]);<br>+ }<br>+ if (res) {<br>+ if (opt->flags & PARSE_RANGE_DEFAULTS) {<br>+ ast_log(LOG_WARNING, "Failed to set %s=%s. Set to %d instead due to range limit (%d, %d)\n", var->name, var->value, *field, (int) opt->args[2], (int) opt->args[3]);<br>+ res = 0;<br>+ } else if (opt->flags & PARSE_DEFAULT) {<br>+ ast_log(LOG_WARNING, "Failed to set %s=%s, Set to default value %d instead.\n", var->name, var->value, *field);<br>+ res = 0;<br>+ }<br>+ }<br>+ } else if ((opt->flags & PARSE_DEFAULT) && ast_parse_arg(var->value, flags, field, (enum ast_timelen) opt->args[1], (int) opt->args[2])) {<br>+ ast_log(LOG_WARNING, "Attempted to set %s=%s, but set it to %d instead due to default)\n", var->name, var->value, *field);<br>+ } else {<br>+ res = ast_parse_arg(var->value, flags, field, (enum ast_timelen) opt->args[1]);<br>+ }<br>+<br>+ return res;<br>+}<br>+<br> /*! \brief Default option handler for doubles<br> * \note For a description of the opt->flags and opt->args values, see the documentation for<br> * enum aco_option_type in config_options.h<br>diff --git a/tests/test_config.c b/tests/test_config.c<br>index fd14908..602c3e7 100644<br>--- a/tests/test_config.c<br>+++ b/tests/test_config.c<br>@@ -43,6 +43,7 @@<br> #include "asterisk/config_options.h"<br> #include "asterisk/netsock2.h"<br> #include "asterisk/acl.h"<br>+#include "asterisk/app.h"<br> #include "asterisk/pbx.h"<br> #include "asterisk/frame.h"<br> #include "asterisk/utils.h"<br>@@ -1082,6 +1083,13 @@<br> ast_test_status_update(test, "ast_parse_arg double failed with %f != %f\n", *r, e); \<br> ret = AST_TEST_FAIL; \<br> } \<br>+ } else if (((flags) & PARSE_TYPE) == PARSE_TIMELEN) { \<br>+ int *r = (int *) (void *) result; \<br>+ int e = (int) expected_result; \<br>+ if (*r != e) { \<br>+ ast_test_status_update(test, "ast_parse_arg timelen failed with %d != %d\n", *r, e); \<br>+ ret = AST_TEST_FAIL; \<br>+ } \<br> } \<br> } \<br> *(result) = DEFAULTVAL; \<br>@@ -1092,6 +1100,7 @@<br> int ret = AST_TEST_PASS;<br> int32_t int32_t_val = DEFAULTVAL;<br> uint32_t uint32_t_val = DEFAULTVAL;<br>+ int timelen_val = DEFAULTVAL;<br> double double_val = DEFAULTVAL;<br> <br> switch (cmd) {<br>@@ -1224,6 +1233,60 @@<br> <br> TEST_PARSE(" -123", EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32, &uint32_t_val);<br> <br>+ /* timelen testing */<br>+ TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);<br>+ TEST_PARSE("-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);<br>+ TEST_PARSE("0", EXPECT_SUCCEED, 0, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);<br>+ TEST_PARSE("not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);<br>+ TEST_PARSE("7not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);<br>+<br>+ TEST_PARSE("123s", EXPECT_SUCCEED, 123000, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);<br>+ TEST_PARSE("-123s", EXPECT_SUCCEED, -123000, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);<br>+ TEST_PARSE("1m", EXPECT_SUCCEED, 60000, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);<br>+ TEST_PARSE("1", EXPECT_SUCCEED, 60000, PARSE_TIMELEN, &timelen_val, TIMELEN_MINUTES);<br>+ TEST_PARSE("1h", EXPECT_SUCCEED, 3600000, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);<br>+ TEST_PARSE("1", EXPECT_SUCCEED, 3600000, PARSE_TIMELEN, &timelen_val, TIMELEN_HOURS);<br>+<br>+ TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_TIMELEN | PARSE_DEFAULT, &timelen_val, TIMELEN_MILLISECONDS, 7);<br>+ TEST_PARSE("-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN | PARSE_DEFAULT, &timelen_val, TIMELEN_MILLISECONDS, 7);<br>+ TEST_PARSE("0", EXPECT_SUCCEED, 0, PARSE_TIMELEN | PARSE_DEFAULT, &timelen_val, TIMELEN_MILLISECONDS, 7);<br>+ TEST_PARSE("not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT, &timelen_val, TIMELEN_MILLISECONDS, 7);<br>+ TEST_PARSE("7not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT, &timelen_val, TIMELEN_MILLISECONDS, 7);<br>+<br>+ TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 0, 200);<br>+ TEST_PARSE("-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -200, 100);<br>+ TEST_PARSE("0", EXPECT_SUCCEED, 0, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -1, 0);<br>+ TEST_PARSE("123", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 0, 122);<br>+ TEST_PARSE("-123", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -122, 100);<br>+ TEST_PARSE("0", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 1, 100);<br>+ TEST_PARSE("not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, INT_MIN, INT_MAX);<br>+ TEST_PARSE("7not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, INT_MIN, INT_MAX);<br>+ TEST_PARSE("123", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 0, 200);<br>+ TEST_PARSE("-123", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -200, 100);<br>+ TEST_PARSE("0", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -1, 0);<br>+ TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 0, 122);<br>+ TEST_PARSE("-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -122, 100);<br>+ TEST_PARSE("0", EXPECT_SUCCEED, 0, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 1, 100);<br>+ TEST_PARSE("not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, INT_MIN, INT_MAX);<br>+ TEST_PARSE("7not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, INT_MIN, INT_MAX);<br>+<br>+ TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 0, 200);<br>+ TEST_PARSE("-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -200, 100);<br>+ TEST_PARSE("0", EXPECT_SUCCEED, 0, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -1, 0);<br>+ TEST_PARSE("123", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 0, 122);<br>+ TEST_PARSE("-123", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -122, 100);<br>+ TEST_PARSE("0", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 1, 100);<br>+ TEST_PARSE("not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, INT_MIN, INT_MAX);<br>+ TEST_PARSE("7not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, INT_MIN, INT_MAX);<br>+ TEST_PARSE("123", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 0, 200);<br>+ TEST_PARSE("-123", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -200, 100);<br>+ TEST_PARSE("0", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -1, 0);<br>+ TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 0, 122);<br>+ TEST_PARSE("-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -122, 100);<br>+ TEST_PARSE("0", EXPECT_SUCCEED, 0, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 1, 100);<br>+ TEST_PARSE("not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, INT_MIN, INT_MAX);<br>+ TEST_PARSE("7not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, INT_MIN, INT_MAX);<br>+<br> /* double testing */<br> TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_DOUBLE, &double_val);<br> TEST_PARSE("123.123", EXPECT_SUCCEED, 123.123, PARSE_DOUBLE, &double_val);<br>@@ -1283,6 +1346,10 @@<br> );<br> int32_t intopt;<br> uint32_t uintopt;<br>+ int timelenopt1;<br>+ int timelenopt2;<br>+ int timelenopt3;<br>+ int timelenopt4;<br> unsigned int flags;<br> double doubleopt;<br> struct ast_sockaddr sockaddropt;<br>@@ -1437,6 +1504,8 @@<br> #define INT_CONFIG "-1"<br> #define UINT_DEFAULT "2"<br> #define UINT_CONFIG "1"<br>+#define TIMELEN_DEFAULT "2"<br>+#define TIMELEN_CONFIG "1"<br> #define DOUBLE_DEFAULT "1.1"<br> #define DOUBLE_CONFIG "0.1"<br> #define SOCKADDR_DEFAULT "4.3.2.1:4321"<br>@@ -1471,6 +1540,10 @@<br> /* Register all options */<br> aco_option_register(&cfg_info, "intopt", ACO_EXACT, config_test_conf.types, INT_DEFAULT, OPT_INT_T, 0, FLDSET(struct test_item, intopt));<br> aco_option_register(&cfg_info, "uintopt", ACO_EXACT, config_test_conf.types, UINT_DEFAULT, OPT_UINT_T, 0, FLDSET(struct test_item, uintopt));<br>+ aco_option_register(&cfg_info, "timelenopt1", ACO_EXACT, config_test_conf.types, TIMELEN_DEFAULT, OPT_TIMELEN_T, 0, FLDSET(struct test_item, timelenopt1), TIMELEN_MILLISECONDS);<br>+ aco_option_register(&cfg_info, "timelenopt2", ACO_EXACT, config_test_conf.types, TIMELEN_DEFAULT, OPT_TIMELEN_T, 0, FLDSET(struct test_item, timelenopt2), TIMELEN_SECONDS);<br>+ aco_option_register(&cfg_info, "timelenopt3", ACO_EXACT, config_test_conf.types, TIMELEN_DEFAULT, OPT_TIMELEN_T, 0, FLDSET(struct test_item, timelenopt3), TIMELEN_MINUTES);<br>+ aco_option_register(&cfg_info, "timelenopt4", ACO_EXACT, config_test_conf.types, TIMELEN_DEFAULT, OPT_TIMELEN_T, 0, FLDSET(struct test_item, timelenopt4), TIMELEN_HOURS);<br> aco_option_register(&cfg_info, "doubleopt", ACO_EXACT, config_test_conf.types, DOUBLE_DEFAULT, OPT_DOUBLE_T, 0, FLDSET(struct test_item, doubleopt));<br> aco_option_register(&cfg_info, "sockaddropt", ACO_EXACT, config_test_conf.types, SOCKADDR_DEFAULT, OPT_SOCKADDR_T, 0, FLDSET(struct test_item, sockaddropt));<br> aco_option_register(&cfg_info, "boolopt", ACO_EXACT, config_test_conf.types, BOOL_DEFAULT, OPT_BOOL_T, 1, FLDSET(struct test_item, boolopt));<br>@@ -1492,6 +1565,14 @@<br> <br> ast_parse_arg(INT_DEFAULT, PARSE_INT32, &defaults.intopt);<br> ast_parse_arg(INT_CONFIG, PARSE_INT32, &configs.intopt);<br>+ ast_parse_arg(TIMELEN_DEFAULT, PARSE_TIMELEN, &defaults.timelenopt1, TIMELEN_MILLISECONDS);<br>+ ast_parse_arg(TIMELEN_CONFIG, PARSE_TIMELEN, &configs.timelenopt1, TIMELEN_MILLISECONDS);<br>+ ast_parse_arg(TIMELEN_DEFAULT, PARSE_TIMELEN, &defaults.timelenopt2, TIMELEN_SECONDS);<br>+ ast_parse_arg(TIMELEN_CONFIG, PARSE_TIMELEN, &configs.timelenopt2, TIMELEN_SECONDS);<br>+ ast_parse_arg(TIMELEN_DEFAULT, PARSE_TIMELEN, &defaults.timelenopt3, TIMELEN_MINUTES);<br>+ ast_parse_arg(TIMELEN_CONFIG, PARSE_TIMELEN, &configs.timelenopt3, TIMELEN_MINUTES);<br>+ ast_parse_arg(TIMELEN_DEFAULT, PARSE_TIMELEN, &defaults.timelenopt4, TIMELEN_HOURS);<br>+ ast_parse_arg(TIMELEN_CONFIG, PARSE_TIMELEN, &configs.timelenopt4, TIMELEN_HOURS);<br> ast_parse_arg(UINT_DEFAULT, PARSE_UINT32, &defaults.uintopt);<br> ast_parse_arg(UINT_CONFIG, PARSE_UINT32, &configs.uintopt);<br> ast_parse_arg(DOUBLE_DEFAULT, PARSE_DOUBLE, &defaults.doubleopt);<br>@@ -1553,6 +1634,10 @@<br> <br> NOT_EQUAL_FAIL(intopt, "%d");<br> NOT_EQUAL_FAIL(uintopt, "%u");<br>+ NOT_EQUAL_FAIL(timelenopt1, "%d");<br>+ NOT_EQUAL_FAIL(timelenopt2, "%d");<br>+ NOT_EQUAL_FAIL(timelenopt3, "%d");<br>+ NOT_EQUAL_FAIL(timelenopt4, "%d");<br> NOT_EQUAL_FAIL(boolopt, "%d");<br> NOT_EQUAL_FAIL(flags, "%u");<br> NOT_EQUAL_FAIL(customopt, "%d");<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/6010">change 6010</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/6010"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I6b333feca7e3f83b4ef5bf2636fc0fd613742554 </div>
<div style="display:none"> Gerrit-Change-Number: 6010 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>