51 #define CONFIG_FILE "test_config.conf" 52 #define CONFIG_INCLUDE_FILE "test_config_include.conf" 68 const char cat1[] =
"Capitals";
76 const char cat2[] =
"Protagonists";
119 struct pair *var_iter;
140 var_iter = &cat_iter->
vars[j];
167 const char *cat_iter =
NULL;
173 if (strcmp(cat_iter,
categories[i].category)) {
200 info->name =
"copy_config";
201 info->category =
"/main/config/";
202 info->summary =
"Test copying configuration";
204 "Ensure that variables and categories are copied correctly";
240 const char *cat_name;
241 const char *var_value;
246 info->name =
"config_basic_ops";
247 info->category =
"/main/config/";
248 info->summary =
"Test basic config ops";
249 info->description =
"Test basic config ops";
261 for(i = 0; i < 5; i++) {
262 snprintf(temp,
sizeof(temp),
"test%d", i);
271 snprintf(temp,
sizeof(temp),
"test%d", i);
313 snprintf(temp,
sizeof(temp),
"test%d", i);
336 snprintf(temp,
sizeof(temp),
"test%d", i);
353 snprintf(temp,
sizeof(temp),
"test%d", i);
354 if (strcmp(cat_name, temp)) {
388 for(i = 0; i < 5; i++) {
389 snprintf(temp,
sizeof(temp),
"test%d", i);
392 if (strcmp(cat_name, temp)) {
405 if (strcmp(cat_name,
"test0")) {
415 if (strcmp(cat_name,
"test1")) {
423 if (strcmp(cat_name,
"test2")) {
434 if (strcmp(cat_name,
"test1")) {
441 if (strcmp(cat_name,
"test3")) {
448 if (strcmp(cat_name,
"test4")) {
475 if (!var_value || strcmp(var_value,
"bbb0")) {
482 if (!var_value || strcmp(var_value,
"bbb0")) {
519 if (!strcmp(cat_name,
"test3")) {
520 snprintf(temp,
sizeof(temp),
"bbb%d", i);
523 if (!var_value || strcmp(var_value, temp)) {
529 if (!var->
value || strcmp(var->
value, temp)) {
547 if (strcmp(var_value,
"value1") != 0) {
553 if (strcmp(var_value,
"value3") != 0) {
576 info->name =
"config_filtered_ops";
577 info->category =
"/main/config/";
578 info->summary =
"Test filtered config ops";
579 info->description =
"Test filtered config ops";
591 for(i = 0; i < 5; i++) {
592 snprintf(temp,
sizeof(temp),
"test%d", i);
598 for(i = 0; i < 5; i++) {
599 snprintf(temp,
sizeof(temp),
"test%d", i);
609 snprintf(temp,
sizeof(temp),
"test%d", i);
615 if (!value || strcmp(value,
"a")) {
629 snprintf(temp,
sizeof(temp),
"test%d", i);
635 if (!value || strcmp(value,
"b")) {
651 if (strcmp(value,
"b")) {
670 if (strcmp(value,
"a")) {
718 info->name =
"config_template_ops";
719 info->category =
"/main/config/";
720 info->summary =
"Test template config ops";
721 info->description =
"Test template config ops";
733 for(i = 0; i < 5; i++) {
734 snprintf(temp,
sizeof(temp),
"test%d", i);
740 for(i = 0; i < 5; i++) {
741 snprintf(temp,
sizeof(temp),
"test%d", i);
751 snprintf(temp,
sizeof(temp),
"test%d", i);
757 if (!value || strcmp(value,
"a")) {
772 snprintf(temp,
sizeof(temp),
"test%d", i);
778 if (!value || strcmp(value,
"a")) {
831 snprintf(filename,
sizeof(filename),
"%s/%s",
833 config_file = fopen(filename,
"w");
841 fprintf(config_file,
"[%s]\n",
categories[i].category);
843 fprintf(config_file,
"%s = %s\n",
859 snprintf(filename,
sizeof(filename),
"%s/%s",
892 struct stat config_stat;
897 info->name =
"config_save";
898 info->category =
"/main/config/";
899 info->summary =
"Test config save";
901 "Test configuration save.";
927 stat(config_filename, &config_stat);
928 before_save = config_stat.st_size;
940 stat(config_filename, &config_stat);
941 if (config_stat.st_size <= before_save) {
950 unlink(config_filename);
951 unlink(include_filename);
966 info->name =
"config_hook";
967 info->category =
"/main/config/";
968 info->summary =
"Test config hooks";
970 "Ensure that config hooks are called at approriate times," 971 "not called at inappropriate times, and that all information" 972 "that should be present is present.";
1052 #define TOOBIG_I32 "2147483649" 1053 #define TOOSMALL_I32 "-2147483649" 1054 #define TOOBIG_U32 "4294967297" 1055 #define TOOSMALL_U32 "-4294967297" 1056 #define DEFAULTVAL 42 1057 #define EPSILON 0.001 1059 #define TEST_PARSE(input, should_succeed, expected_result, flags, result, ...) do {\ 1060 int __res = ast_parse_arg(input, (flags), result, ##__VA_ARGS__); \ 1061 if (!__res == !should_succeed) { \ 1062 ast_test_status_update(test, "ast_parse_arg failed on '%s'. %d/%d\n", input, __res, should_succeed); \ 1063 ret = AST_TEST_FAIL; \ 1065 if (((flags) & PARSE_TYPE) == PARSE_INT32) { \ 1066 int32_t *r = (int32_t *) (void *) result; \ 1067 int32_t e = (int32_t) expected_result; \ 1069 ast_test_status_update(test, "ast_parse_arg int32_t failed with %d != %d\n", *r, e); \ 1070 ret = AST_TEST_FAIL; \ 1072 } else if (((flags) & PARSE_TYPE) == PARSE_UINT32) { \ 1073 uint32_t *r = (uint32_t *) (void *) result; \ 1074 uint32_t e = (uint32_t) expected_result; \ 1076 ast_test_status_update(test, "ast_parse_arg uint32_t failed with %u != %u\n", *r, e); \ 1077 ret = AST_TEST_FAIL; \ 1079 } else if (((flags) & PARSE_TYPE) == PARSE_DOUBLE) { \ 1080 double *r = (double *) (void *) result; \ 1081 double e = (double) expected_result; \ 1082 if (fabs(*r - e) > EPSILON) { \ 1083 ast_test_status_update(test, "ast_parse_arg double failed with %f != %f\n", *r, e); \ 1084 ret = AST_TEST_FAIL; \ 1086 } else if (((flags) & PARSE_TYPE) == PARSE_TIMELEN) { \ 1087 int *r = (int *) (void *) result; \ 1088 int e = (int) expected_result; \ 1090 ast_test_status_update(test, "ast_parse_arg timelen failed with %d != %d\n", *r, e); \ 1091 ret = AST_TEST_FAIL; \ 1095 *(result) = DEFAULTVAL; \ 1108 info->name =
"ast_parse_arg";
1109 info->category =
"/config/";
1110 info->summary =
"Test the output of ast_parse_arg";
1112 "Ensures that ast_parse_arg behaves as expected";
1369 struct test_item *one = obj, *two = arg;
1370 const char *
match = (flags &
OBJ_KEY) ? arg : two->name;
1436 if (!strcasecmp(var->
name,
"customopt")) {
1447 .item_offset = offsetof(
struct test_config, global),
1449 .category =
"^global$",
1453 .item_offset = offsetof(
struct test_config, global_defaults),
1455 .category =
"global_defaults",
1474 .types =
ACO_TYPES(&global, &global_defaults, &item),
1487 struct ast_sockaddr acl_allow = {{ 0, }}, acl_fail = {{ 0, }};
1494 info->name =
"config_options_test";
1495 info->category =
"/config/";
1496 info->summary =
"Config opptions unit test";
1498 "Tests the Config Options API";
1504 #define INT_DEFAULT "-2" 1505 #define INT_CONFIG "-1" 1506 #define UINT_DEFAULT "2" 1507 #define UINT_CONFIG "1" 1508 #define TIMELEN_DEFAULT "2" 1509 #define TIMELEN_CONFIG "1" 1510 #define DOUBLE_DEFAULT "1.1" 1511 #define DOUBLE_CONFIG "0.1" 1512 #define SOCKADDR_DEFAULT "4.3.2.1:4321" 1513 #define SOCKADDR_CONFIG "1.2.3.4:1234" 1514 #define BOOL_DEFAULT "false" 1515 #define BOOL_CONFIG "true" 1516 #define BOOLFLAG1_DEFAULT "false" 1517 #define BOOLFLAG1_CONFIG "true" 1518 #define BOOLFLAG2_DEFAULT "false" 1519 #define BOOLFLAG2_CONFIG "false" 1520 #define BOOLFLAG3_DEFAULT "false" 1521 #define BOOLFLAG3_CONFIG "true" 1522 #define ACL_DEFAULT NULL 1523 #define ACL_CONFIG_PERMIT "1.2.3.4/32" 1524 #define ACL_CONFIG_DENY "0.0.0.0/0" 1525 #define CODEC_DEFAULT "!all,alaw" 1526 #define CODEC_CONFIG "!all,ulaw,g729" 1527 #define STR_DEFAULT "default" 1528 #define STR_CONFIG "test" 1529 #define CUSTOM_DEFAULT "no" 1530 #define CUSTOM_CONFIG "yes" 1532 #define BOOLFLAG1 1 << 0 1533 #define BOOLFLAG2 1 << 1 1534 #define BOOLFLAG3 1 << 2 1618 if (!(item_defaults =
ao2_find(cfg->items,
"item_defaults",
OBJ_KEY))) {
1622 arr[0] = cfg->global;
1624 arr[2] = cfg->global_defaults;
1625 arr[3] = item_defaults;
1628 #define NOT_EQUAL_FAIL(field, format) \ 1629 if (arr[x]->field != control->field) { \ 1630 ast_test_status_update(test, "%s did not match: " format " != " format " with x = %d\n", #field, arr[x]->field, control->field, x); \ 1631 res = AST_TEST_FAIL; \ 1633 for (x = 0; x < 4; x++) {
1663 if (strcasecmp(arr[x]->stropt, control->
stropt)) {
1695 info->name =
"config_dialplan_function";
1696 info->category =
"/main/config/";
1697 info->summary =
"Test AST_CONFIG dialplan function";
1698 info->description =
"Test AST_CONFIG dialplan function";
1704 snprintf(filename,
sizeof(filename),
"%s/%s",
1706 config_file = fopen(filename,
"w");
1723 fclose(config_file);
1844 info->name =
"variable_lists_match";
1845 info->category =
"/main/config/";
1846 info->summary =
"Test ast_variable_lists_match";
1847 info->description =
"Test ast_variable_lists_match";
1854 ast_test_validate(
test, var);
1857 ast_test_validate(
test, var);
1861 ast_test_validate(
test, var);
1868 ast_test_validate(
test, var);
1875 ast_test_validate(
test, var);
1882 ast_test_validate(
test, var);
Type for default handler for ast_sockaddrs.
struct ast_category * ast_category_new(const char *name, const char *in_file, int lineno)
Create a category.
struct ast_variable * next
Type for default option handler for format capabilities.
const char cat2varvalue3[]
static int unload_module(void)
struct aco_file config_test_conf
#define BOOLFLAG2_DEFAULT
aco_type_item_find item_find
struct ast_config_include * ast_include_new(struct ast_config *conf, const char *from_file, const char *included_file, int is_exec, const char *exec_file, int from_lineno, char *real_included_file_name, int real_included_file_name_size)
#define AST_MODULE_INFO_STANDARD(keystr, desc)
int ast_config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator)
Save a config text file preserving the pre 13.2 behavior.
const ast_string_field name
Asterisk main include file. File version handling, generic pbx functions.
static const char config_file[]
void ast_variable_insert(struct ast_category *category, struct ast_variable *variable, const char *line)
#define ACL_CONFIG_PERMIT
static struct aco_type global
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
#define aco_option_register_custom(info, name, matchtype, types, default_val, handler, flags)
Register a config option.
const char cat2varvalue1[]
int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
Parse an IPv4 or IPv6 address string.
#define ast_set2_flag(p, value, flag)
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
int ast_func_read2(struct ast_channel *chan, const char *function, struct ast_str **str, ssize_t maxlen)
executes a read operation on a function
static AO2_GLOBAL_OBJ_STATIC(global_obj)
struct ast_category * ast_category_delete(struct ast_config *cfg, struct ast_category *category)
Delete a category.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
const char cat2varvalue2[]
const char cat1varname2[]
static int hook_config_sane
#define aco_option_register(info, name, matchtype, types, default_val, opt_type, flags,...)
Register a config option.
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
CONFIG_INFO_TEST(cfg_info, global_obj, test_config_alloc,.files=ACO_FILES(&config_test_conf),)
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
Structure for variables, used for configurations and for channel variables.
struct ao2_container * items
#define AST_TEST_REGISTER(cb)
enum ast_acl_sense ast_apply_ha(const struct ast_ha *ha, const struct ast_sockaddr *addr)
Apply a set of rules to a given IP address.
const char cat1varvalue2[]
enum aco_process_status aco_process_config(struct aco_info *info, int reload)
Process a config info via the options registered with an aco_info.
static struct aco_type item
#define ao2_global_obj_ref(holder)
static int copy(char *infile, char *outfile)
Utility function to copy a file.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Type for default option handler for bools (ast_true/ast_false) that are stored in a flag...
#define ast_str_alloca(init_len)
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
int ast_sockaddr_cmp(const struct ast_sockaddr *a, const struct ast_sockaddr *b)
Compares two ast_sockaddr structures.
The representation of a single configuration file to be processed.
const char * ast_variable_find_last_in_list(const struct ast_variable *list, const char *variable)
Gets the value of the LAST occurrence of a variable from a variable list.
Socket address structure.
#define ACO_TYPES(...)
A helper macro to ensure that aco_info types always have a sentinel.
#define CONFIG_INCLUDE_FILE
struct ast_category * ast_category_browse_filtered(struct ast_config *config, const char *category_name, struct ast_category *prev, const char *filter)
Browse categories with filters.
struct test_item * global
static void * test_item_find(struct ao2_container *container, const char *cat)
static void * test_config_alloc(void)
internal representation of ACL entries In principle user applications would have no need for this...
struct ast_format_cap * codeccapopt
Configuration File Parser.
void ast_config_hook_unregister(const char *name)
Unregister a config hook.
#define ast_config_load(filename, flags)
Load a config file.
static char * config_filename
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
const char cat1varname1[]
int aco_info_init(struct aco_info *info)
Initialize an aco_info structure.
Asterisk file paths, configured in asterisk.conf.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Type for default option handler for unsigned integers.
#define ast_test_status_update(a, b, c...)
int ast_config_hook_register(const char *name, const char *filename, const char *module, enum config_hook_flags flags, config_hook_cb hook)
Register a config hook for a particular file and module.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Access Control of various sorts.
const char cat1varvalue1[]
#define AST_STRING_FIELD(name)
Declare a string field.
Asterisk internal frame definitions.
#define ao2_ref(o, delta)
static int write_config_file(void)
Write the config file to disk.
const char cat2varname1[]
void ast_config_destroy(struct ast_config *config)
Destroys a config.
const char * ast_variable_find_in_list(const struct ast_variable *list, const char *variable)
Gets the value of a variable from a variable list by name.
aco_type_item_alloc item_alloc
struct ao2_container * container
const char cat2varname2[]
#define ast_variable_new(name, value, filename)
int aco_option_register_deprecated(struct aco_info *info, const char *name, struct aco_type **types, const char *aliased_to)
Register a deprecated (and aliased) config option.
struct ast_config * ast_config_new(void)
Create a new base configuration structure.
struct ast_variable * ast_variable_list_append_hint(struct ast_variable **head, struct ast_variable *search_hint, struct ast_variable *new_var)
Appends a variable list to the end of another list.
Core PBX routines and definitions.
static void * test_item_alloc(const char *cat)
#define CONFIG_STATUS_FILEUNCHANGED
Their was an error and no changes were applied.
struct ast_sockaddr sockaddropt
Configuration option-handling.
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
struct association categories[]
const char * ast_config_AST_CONFIG_DIR
void aco_info_destroy(struct aco_info *info)
Destroy an initialized aco_info struct.
#define AST_TEST_UNREGISTER(cb)
#define ao2_global_obj_release(holder)
Type for default option handler for bools (ast_true/ast_false)
int ast_category_insert(struct ast_config *config, struct ast_category *cat, const char *match)
Inserts new category.
static int load_module(void)
AST_TEST_DEFINE(copy_config)
#define BOOLFLAG3_DEFAULT
#define ao2_alloc(data_size, destructor_fn)
#define TEST_PARSE(input, should_succeed, expected_result, flags, result,...)
const char cat1varname3[]
struct ast_config * ast_config_copy(const struct ast_config *orig)
Copies the contents of one ast_config into another.
#define BOOLFLAG1_DEFAULT
const char cat1varvalue3[]
Type for default option handler for ACLs.
const ast_string_field stropt
Type for default option handler for doubles.
int ast_parse_arg(const char *arg, enum ast_parse_flags flags, void *result,...)
The argument parsing routine.
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
const char * ast_variable_find(const struct ast_category *category, const char *variable)
Gets a variable value from a specific category structure by name.
#define ao2_find(container, arg, flags)
const char cat2varname3[]
struct test_item * global_defaults
static void test_item_destructor(void *obj)
Structure used to handle boolean flags.
static struct aco_type global_defaults
Support for logging to various files, console and syslog Configuration in file logger.conf.
config_hook_flags
Flags that affect the behaviour of config hooks.
void ast_variable_append(struct ast_category *category, struct ast_variable *variable)
void ast_category_append(struct ast_config *config, struct ast_category *cat)
Appends a category to a config.
static const char * item_blacklist[]
struct ast_category * ast_category_new_template(const char *name, const char *in_file, int lineno)
Create a category making it a template.
void ast_free_ha(struct ast_ha *ha)
Free a list of HAs.
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
static void delete_config_file(void)
Delete config file created by write_config_file.
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
int ast_category_empty(struct ast_category *category)
Removes and destroys all variables in a category.
#define NOT_EQUAL_FAIL(field, format)
int ast_variable_lists_match(const struct ast_variable *left, const struct ast_variable *right, int exact_match)
Tests 2 variable lists to see if they match.
Type for default option handler for time length signed integers.
Type information about a category-level configurable object.
static struct configs configs
Type for default option handler for stringfields.
struct ast_ha * ast_append_ha(const char *sense, const char *stuff, struct ast_ha *path, int *error)
Add a new rule to a list of HAs.
int error(const char *format,...)
struct ast_category * ast_category_get(const struct ast_config *config, const char *category_name, const char *filter)
Retrieve a category if it exists.
static struct ast_config * build_cfg(void)
Build ast_config struct from above definitions.
struct aco_type * types[]
Type for default option handler for signed integers.
#define ASTERISK_GPL_KEY
The text the key() function should return.
static int hook_cb(struct ast_config *cfg)
Asterisk module definitions.
static void test_config_destructor(void *obj)
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
static int test_config_validity(struct ast_config *cfg)
Tests that the contents of an ast_config is what is expected.
static int test_item_cmp(void *obj, void *arg, int flags)
#define ast_variable_list_append(head, new_var)
const char * ast_category_get_name(const struct ast_category *category)
Return the name of the category.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
static int customopt_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.