51#define CONFIG_FILE "test_config.conf" 
   52#define CONFIG_INCLUDE_FILE "test_config_include.conf" 
   68const char cat1[] = 
"Capitals";
 
   76const 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);
 
  629        snprintf(temp, 
sizeof(temp), 
"test%d", i);
 
  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);
 
  772        snprintf(temp, 
sizeof(temp), 
"test%d", i);
 
 
  831    snprintf(filename, 
sizeof(filename), 
"%s/%s",
 
 
  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.";
 
  928    before_save = config_stat.st_size;
 
  941    if (config_stat.st_size <= before_save) {
 
  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;
 
 
 1436    if (!strcasecmp(
var->name, 
"customopt")) {
 
 
 1449    .category = 
"^global$",
 
 
 1455    .category = 
"global_defaults",
 
 
 1487    struct ast_sockaddr acl_allow = {{ 0, }}, acl_fail = {{ 0, }};
 
 1494        info->name = 
"config_options_test";
 
 1495        info->category = 
"/config/";
 
 1496        info->summary = 
"Config options 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",
 
 
 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";
 
 
 1905        info->name = 
"variable_list_join_replace";
 
 1906        info->category = 
"/main/config/";
 
 1907        info->summary = 
"Test joining a variable list";
 
 1908        info->description = info->summary;
 
 1920    ast_test_validate(
test, strcmp(
ast_str_buffer(
str), 
"aaa = \"111\", bbb = \"222\", ccc = \"33 33\"") == 0);
 
 1925    ast_test_validate(
test, strcmp(
ast_str_buffer(
str), 
"aaa = \"111\", bbb = \"222\", ccc = \"33 33\"") == 0);
 
 1929    ast_test_validate(
test, strcmp(
ast_str_buffer(
str), 
"aaa = \"111\", bbb = \"222\", ccc = \"33 33\"") == 0);
 
 1934    ast_test_validate(
test, rc == 0);
 
 1936    ast_test_validate(
test, strcmp(
ast_str_buffer(
str), 
"ddd = \"444\", bbb = \"222\", ccc = \"33 33\"") == 0);
 
 1940    ast_test_validate(
test, rc == 0);
 
 1942    ast_test_validate(
test, strcmp(
ast_str_buffer(
str), 
"ddd = \"444\", eee = \"555\", ccc = \"33 33\"") == 0);
 
 
 1955        info->name = 
"variable_list_from_quoted_string";
 
 1956        info->category = 
"/main/config/";
 
 1957        info->summary = 
"Test parsing a string into a variable list";
 
 1958        info->description = info->summary;
 
 1964    parse_string = 
"000= '', 111=, 222 = , 333 = ' ', abc = 'def', ghi = 'j,kl', mno='pq=r', stu = 'vwx=\"yz\", ABC = \"DEF\"'";
 
 1966    ast_test_validate(
test, list != 
NULL);
 
 1969    ast_test_validate(
test,
 
 1970        strcmp(
ast_str_buffer(
str), 
"000^@@|111^@@|222^@@|333^@ @|abc^@def@|ghi^@j,kl@|mno^@pq=r@|stu^@vwx=\"yz\", ABC = \"DEF\"@") == 0);
 
 
Access Control of various sorts.
void ast_free_ha(struct ast_ha *ha)
Free a list of HAs.
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.
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.
static int copy(char *infile, char *outfile)
Utility function to copy a file.
Asterisk main include file. File version handling, generic pbx functions.
#define AO2_GLOBAL_OBJ_STATIC(name)
Define a global object holder to be used to hold an ao2 object, statically initialized.
@ AO2_ALLOC_OPT_LOCK_MUTEX
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
#define ao2_find(container, arg, flags)
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define ao2_global_obj_release(holder)
Release the ao2 object held in the global holder.
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
#define ao2_alloc(data_size, destructor_fn)
static const char config_file[]
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
#define AST_MAX_USER_FIELD
Configuration option-handling.
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.
void aco_info_destroy(struct aco_info *info)
Destroy an initialized aco_info struct.
#define CONFIG_INFO_TEST(name, arr, alloc,...)
@ ACO_PROCESS_ERROR
Their was an error and no changes were applied.
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
int aco_info_init(struct aco_info *info)
Initialize an aco_info structure.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
#define aco_option_register(info, name, matchtype, types, default_val, opt_type, flags,...)
Register a config option.
@ OPT_UINT_T
Type for default option handler for unsigned integers.
@ OPT_CODEC_T
Type for default option handler for format capabilities.
@ OPT_BOOL_T
Type for default option handler for bools (ast_true/ast_false)
@ OPT_BOOLFLAG_T
Type for default option handler for bools (ast_true/ast_false) that are stored in a flag.
@ OPT_ACL_T
Type for default option handler for ACLs.
@ OPT_SOCKADDR_T
Type for default handler for ast_sockaddrs.
@ OPT_INT_T
Type for default option handler for signed integers.
@ OPT_TIMELEN_T
Type for default option handler for time length signed integers.
@ OPT_DOUBLE_T
Type for default option handler for doubles.
@ OPT_STRINGFIELD_T
Type for default option handler for stringfields.
#define aco_option_register_custom(info, name, matchtype, types, default_val, handler, flags)
Register a config option.
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.
#define ACO_TYPES(...)
A helper macro to ensure that aco_info types always have a sentinel.
static char * config_filename
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
Configuration File Parser.
#define ast_config_load(filename, flags)
Load a config file.
struct ast_variable * ast_variable_list_from_quoted_string(const char *input, const char *item_separator, const char *name_value_separator, const char *quote_str)
Parse a string into an ast_variable list. The reverse of ast_variable_list_join.
const char * ast_category_get_name(const struct ast_category *category)
Return the name of the category.
struct ast_category * ast_category_new_template(const char *name, const char *in_file, int lineno)
Create a category making it a template.
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
struct ast_config_include * ast_include_new(struct ast_config *conf, const char *from_file, const char *included_file, int include_type, const char *exec_file, int from_lineno, char *real_included_file_name, int real_included_file_name_size)
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
struct ast_category * ast_category_delete(struct ast_config *cfg, struct ast_category *cat)
Delete a category.
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.
struct ast_config * ast_config_new(void)
Create a new base configuration structure.
void ast_config_hook_unregister(const char *name)
Unregister a config hook.
int ast_category_insert(struct ast_config *config, struct ast_category *cat, const char *match)
Inserts new category.
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.
void ast_category_append(struct ast_config *config, struct ast_category *category)
Appends a category to a config.
void ast_variable_append(struct ast_category *category, struct ast_variable *variable)
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.
struct ast_category * ast_category_new(const char *name, const char *in_file, int lineno)
Create a category.
#define ast_variable_new(name, value, filename)
int ast_variable_list_replace_variable(struct ast_variable **head, struct ast_variable *oldvar, struct ast_variable *newvar)
Replace a variable in the given list with a new variable.
#define ast_variable_list_append(head, new_var)
#define CONFIG_STATUS_FILEUNCHANGED
int ast_parse_arg(const char *arg, enum ast_parse_flags flags, void *p_result,...)
The argument parsing routine.
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
int ast_category_empty(struct ast_category *category)
Removes and destroys all variables in a category.
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.
@ CONFIG_FLAG_FILEUNCHANGED
struct ast_str * ast_variable_list_join(const struct ast_variable *head, const char *item_separator, const char *name_value_separator, const char *quote_char, struct ast_str **str)
Join an ast_variable list with specified separators and quoted values.
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
void ast_variable_insert(struct ast_category *category, struct ast_variable *variable, const char *line)
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.
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.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
config_hook_flags
Flags that affect the behaviour of config hooks.
struct ast_config * ast_config_copy(const struct ast_config *orig)
Copies the contents of one ast_config into another.
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
const char * ast_variable_find(const struct ast_category *category, const char *variable)
Gets a variable value from a specific category structure by name.
struct ast_category * ast_category_get(const struct ast_config *config, const char *category_name, const char *filter)
Retrieve a category if it exists.
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.
Asterisk internal frame definitions.
Support for logging to various files, console and syslog Configuration in file logger....
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
Parse an IPv4 or IPv6 address string.
int ast_sockaddr_cmp(const struct ast_sockaddr *a, const struct ast_sockaddr *b)
Compares two ast_sockaddr structures.
Asterisk file paths, configured in asterisk.conf.
const char * ast_config_AST_CONFIG_DIR
Core PBX routines and definitions.
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
struct ao2_container * container
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define AST_STRING_FIELD(name)
Declare a string field.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
#define ast_str_alloca(init_len)
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
The representation of a single configuration file to be processed.
struct aco_type * types[]
Type information about a category-level configurable object.
aco_type_item_find item_find
aco_type_item_alloc item_alloc
Structure used to handle boolean flags.
internal representation of ACL entries In principle user applications would have no need for this,...
Socket address structure.
Support for dynamic strings.
Structure for variables, used for configurations and for channel variables.
struct test_item * global
struct ao2_container * items
struct test_item * global_defaults
struct ast_format_cap * codeccapopt
const ast_string_field stropt
struct ast_sockaddr sockaddropt
const ast_string_field name
#define AST_TEST_REGISTER(cb)
#define ast_test_status_update(a, b, c...)
#define AST_TEST_UNREGISTER(cb)
#define AST_TEST_DEFINE(hdr)
#define CONFIG_INCLUDE_FILE
static struct ast_config * build_cfg(void)
Build ast_config struct from above definitions.
#define BOOLFLAG3_DEFAULT
#define TEST_PARSE(input, should_succeed, expected_result, flags, result,...)
const char cat1varname1[]
const char cat1varname3[]
const char cat1varvalue3[]
const char cat2varname1[]
#define BOOLFLAG2_DEFAULT
#define ACL_CONFIG_PERMIT
static int test_config_validity(struct ast_config *cfg)
Tests that the contents of an ast_config is what is expected.
const char cat2varvalue3[]
static void * test_item_find(struct ao2_container *container, const char *cat)
static void * test_config_alloc(void)
const char cat2varname2[]
static void test_item_destructor(void *obj)
static struct aco_type global_defaults
const char cat1varname2[]
static int test_item_cmp(void *obj, void *arg, int flags)
static int hook_config_sane
const char cat2varvalue1[]
static const char * item_blacklist[]
static int write_config_file(void)
Write the config file to disk.
static int hook_cb(struct ast_config *cfg)
static void delete_config_file(void)
Delete config file created by write_config_file.
static void test_config_destructor(void *obj)
struct aco_file config_test_conf
static void * test_item_alloc(const char *cat)
const char cat1varvalue2[]
const char cat1varvalue1[]
const char cat2varvalue2[]
static struct aco_type global
#define NOT_EQUAL_FAIL(field, format)
static int load_module(void)
static int customopt_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
static int unload_module(void)
struct association categories[]
#define BOOLFLAG1_DEFAULT
const char cat2varname3[]
static struct aco_type item
int error(const char *format,...)
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ast_set2_flag(p, value, flag)