* struct test_item {
* 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}
*/
OPT_BOOL_T,
* struct test_item {
* 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}
*/
-
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:
* CHARFLDSET macro with a field of type char[]
*
* struct test_item {
* 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}
*/
OPT_CHAR_ARRAY_T,
* double dub;
* };
* {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}
*/
OPT_DOUBLE_T,
/*! \brief Type for default option handler for stringfields
* \note aco_option_register flags:
- * none
+ * non-zero : String cannot be empty.
+ * 0 : String can be empty.
* aco_option_register varargs:
* STRFLDSET macro with the field being the field created by AST_STRING_FIELD
*
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_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);
return 0;
}
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)
{
char *field = (char *)(obj + opt->args[0]);
size_t len = opt->args[1];
+ if (opt->flags && ast_strlen_zero(var->value)) {
+ return -1;
+ }
ast_copy_string(field, var->value, len);
return 0;
}