mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-04 03:50:31 +00:00
Add config framework non-empty string validation requirement option.
Add config framework OPT_CHAR_ARRAY_T and OPT_STRINGFIELD_T non-empty requirement option. There are cases were you don't want a config option string to be empty. To require the option string to be non-empty, just set the aco_option_register() flags parameter to non-zero. * Updated some config framework enum aco_option_type comments. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393034 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -265,7 +265,7 @@ enum aco_option_type {
|
|||||||
* struct test_item {
|
* struct test_item {
|
||||||
* int enabled;
|
* int enabled;
|
||||||
* };
|
* };
|
||||||
aco_option_register(&cfg_info, "enabled", ACO_EXACT, my_types, "no", OPT_BOOL_T, 1, FLDSET(struct test_item, enabled));
|
* aco_option_register(&cfg_info, "enabled", ACO_EXACT, my_types, "no", OPT_BOOL_T, 1, FLDSET(struct test_item, enabled));
|
||||||
* {endcode}
|
* {endcode}
|
||||||
*/
|
*/
|
||||||
OPT_BOOL_T,
|
OPT_BOOL_T,
|
||||||
@@ -284,13 +284,15 @@ enum aco_option_type {
|
|||||||
* struct test_item {
|
* struct test_item {
|
||||||
* unsigned int flags;
|
* unsigned int flags;
|
||||||
* };
|
* };
|
||||||
aco_option_register(&cfg_info, "quiet", ACO_EXACT, my_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct test_item, flags), MY_TYPE_ISQUIET);
|
* aco_option_register(&cfg_info, "quiet", ACO_EXACT, my_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct test_item, flags), MY_TYPE_ISQUIET);
|
||||||
* {endcode}
|
* {endcode}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
OPT_BOOLFLAG_T,
|
OPT_BOOLFLAG_T,
|
||||||
|
|
||||||
/*! \brief Type for default option handler for character arrays
|
/*! \brief Type for default option handler for character array strings
|
||||||
|
* \note aco_option_register flags:
|
||||||
|
* non-zero : String cannot be empty.
|
||||||
|
* 0 : String can be empty.
|
||||||
* \note aco_option_register varargs:
|
* \note aco_option_register varargs:
|
||||||
* CHARFLDSET macro with a field of type char[]
|
* CHARFLDSET macro with a field of type char[]
|
||||||
*
|
*
|
||||||
@@ -299,7 +301,7 @@ enum aco_option_type {
|
|||||||
* struct test_item {
|
* struct test_item {
|
||||||
* char description[128];
|
* char description[128];
|
||||||
* };
|
* };
|
||||||
* aco_option_register(&cfg_info, "description", ACO_EXACT, my_types, "none", OPT_CHAR_ARRAY_T, CHARFLDSET(struct test_item, description));
|
* aco_option_register(&cfg_info, "description", ACO_EXACT, my_types, "none", OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct test_item, description));
|
||||||
* {endcode}
|
* {endcode}
|
||||||
*/
|
*/
|
||||||
OPT_CHAR_ARRAY_T,
|
OPT_CHAR_ARRAY_T,
|
||||||
@@ -338,7 +340,7 @@ enum aco_option_type {
|
|||||||
* double dub;
|
* double dub;
|
||||||
* };
|
* };
|
||||||
* {code}
|
* {code}
|
||||||
* aco_option_register(&cfg_info, "doubleopt", ACO_EXACT, my_types, "3", OPT_DOUBLE_T, FLDSET(struct test_item, dub));
|
* aco_option_register(&cfg_info, "doubleopt", ACO_EXACT, my_types, "3", OPT_DOUBLE_T, 0, FLDSET(struct test_item, dub));
|
||||||
* {endcode}
|
* {endcode}
|
||||||
*/
|
*/
|
||||||
OPT_DOUBLE_T,
|
OPT_DOUBLE_T,
|
||||||
@@ -393,7 +395,8 @@ enum aco_option_type {
|
|||||||
|
|
||||||
/*! \brief Type for default option handler for stringfields
|
/*! \brief Type for default option handler for stringfields
|
||||||
* \note aco_option_register flags:
|
* \note aco_option_register flags:
|
||||||
* none
|
* non-zero : String cannot be empty.
|
||||||
|
* 0 : String can be empty.
|
||||||
* aco_option_register varargs:
|
* aco_option_register varargs:
|
||||||
* STRFLDSET macro with the field being the field created by AST_STRING_FIELD
|
* STRFLDSET macro with the field being the field created by AST_STRING_FIELD
|
||||||
*
|
*
|
||||||
|
@@ -1342,6 +1342,10 @@ static int stringfield_handler_fn(const struct aco_option *opt, struct ast_varia
|
|||||||
ast_string_field *field = (const char **)(obj + opt->args[0]);
|
ast_string_field *field = (const char **)(obj + opt->args[0]);
|
||||||
struct ast_string_field_pool **pool = (struct ast_string_field_pool **)(obj + opt->args[1]);
|
struct ast_string_field_pool **pool = (struct ast_string_field_pool **)(obj + opt->args[1]);
|
||||||
struct ast_string_field_mgr *mgr = (struct ast_string_field_mgr *)(obj + opt->args[2]);
|
struct ast_string_field_mgr *mgr = (struct ast_string_field_mgr *)(obj + opt->args[2]);
|
||||||
|
|
||||||
|
if (opt->flags && ast_strlen_zero(var->value)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
ast_string_field_ptr_set_by_fields(*pool, *mgr, field, var->value);
|
ast_string_field_ptr_set_by_fields(*pool, *mgr, field, var->value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1384,7 +1388,7 @@ static int sockaddr_handler_fn(const struct aco_option *opt, struct ast_variable
|
|||||||
return ast_parse_arg(var->value, PARSE_ADDR | opt->flags, field);
|
return ast_parse_arg(var->value, PARSE_ADDR | opt->flags, field);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \brief Default handler for doing noithing
|
/*! \brief Default handler for doing nothing
|
||||||
*/
|
*/
|
||||||
static int noop_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj)
|
static int noop_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj)
|
||||||
{
|
{
|
||||||
@@ -1400,6 +1404,9 @@ static int chararray_handler_fn(const struct aco_option *opt, struct ast_variabl
|
|||||||
char *field = (char *)(obj + opt->args[0]);
|
char *field = (char *)(obj + opt->args[0]);
|
||||||
size_t len = opt->args[1];
|
size_t len = opt->args[1];
|
||||||
|
|
||||||
|
if (opt->flags && ast_strlen_zero(var->value)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
ast_copy_string(field, var->value, len);
|
ast_copy_string(field, var->value, len);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user