]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Ensure global types in the config framework are initialized
authorKinsey Moore <kmoore@digium.com>
Fri, 20 Sep 2013 22:35:00 +0000 (22:35 +0000)
committerKinsey Moore <kmoore@digium.com>
Fri, 20 Sep 2013 22:35:00 +0000 (22:35 +0000)
If a config object was allocated but one of its global objects was
never encountered, then the global object's defaults were never
applied. Ensure that global objects are initialized properly upon
allocation instead of on configuration.

Review: https://reviewboard.asterisk.org/r/2866/

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@399564 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/config_options.c

index e2547e698f12de80cbb791056ae29d3b6fbe0a03..3cc71711e4a9e11081cd4cb817403e37f304c34c 100644 (file)
@@ -370,10 +370,6 @@ static int process_category(struct ast_config *cfg, struct aco_info *info, struc
        }
 
        if (type->type == ACO_GLOBAL && *field) {
-               if (aco_set_defaults(type, cat, *field)) {
-                       ast_log(LOG_ERROR, "In %s: Setting defaults for %s failed\n", file->filename, cat);
-                       return -1;
-               }
                if (aco_process_category_options(type, cfg, cat, *field)) {
                        ast_log(LOG_ERROR, "In %s: Processing options for %s failed\n", file->filename, cat);
                        return -1;
@@ -504,6 +500,28 @@ enum aco_process_status aco_process_config(struct aco_info *info, int reload)
 
        while (res != ACO_PROCESS_ERROR && (file = info->files[x++])) {
                const char *filename = file->filename;
+               struct aco_type *match;
+               int i;
+
+               /* set defaults for global objects */
+               for (i = 0, match = file->types[i]; match; match = file->types[++i]) {
+                       void **field = info->internal->pending + match->item_offset;
+
+                       if (match->type != ACO_GLOBAL || !*field) {
+                               continue;
+                       }
+
+                       if (aco_set_defaults(match, match->category, *field)) {
+                               ast_log(LOG_ERROR, "In %s: Setting defaults for %s failed\n", file->filename, match->category);
+                               res = ACO_PROCESS_ERROR;
+                               break;
+                       }
+               }
+
+               if (res == ACO_PROCESS_ERROR) {
+                       break;
+               }
+
 try_alias:
                if (!(cfg = ast_config_load(filename, cfg_flags))) {
                        if (file->alias && strcmp(file->alias, filename)) {