Add a massive set of changes for converting to use the ast_debug() macro.
[asterisk/asterisk.git] / main / config.c
index b1d30aa..ad71384 100644 (file)
@@ -140,7 +140,8 @@ static void CB_RESET(char **comment_buffer, char **lline_buffer)
 
 static struct ast_comment *ALLOC_COMMENT(const char *buffer)
 { 
-       struct ast_comment *x = ast_calloc(1,sizeof(struct ast_comment)+strlen(buffer)+1);
+       struct ast_comment *x;
+       x = ast_calloc(1, sizeof(*x)+strlen(buffer)+1);
        strcpy(x->cmt, buffer);
        return x;
 }
@@ -215,7 +216,7 @@ void ast_variables_destroy(struct ast_variable *v)
        while (v) {
                vn = v;
                v = v->next;
-               free(vn);
+               ast_free(vn);
        }
 }
 
@@ -344,7 +345,7 @@ void ast_category_append(struct ast_config *config, struct ast_category *categor
 void ast_category_destroy(struct ast_category *cat)
 {
        ast_variables_destroy(cat->root);
-       free(cat);
+       ast_free(cat);
 }
 
 static struct ast_category *next_available_category(struct ast_category *cat)
@@ -522,7 +523,7 @@ int ast_category_delete(struct ast_config *cfg, const char *category)
                                if (cat == cfg->last)
                                        cfg->last = NULL;
                        }
-                       free(cat);
+                       ast_free(cat);
                        return 0;
                }
                prev = cat;
@@ -543,7 +544,7 @@ int ast_category_delete(struct ast_config *cfg, const char *category)
                                if (cat == cfg->last)
                                        cfg->last = NULL;
                        }
-                       free(cat);
+                       ast_free(cat);
                        return 0;
                }
                prev = cat;
@@ -564,9 +565,9 @@ void ast_config_destroy(struct ast_config *cfg)
                ast_variables_destroy(cat->root);
                catn = cat;
                cat = cat->next;
-               free(catn);
+               ast_free(catn);
        }
-       free(cfg);
+       ast_free(cfg);
 }
 
 struct ast_category *ast_config_get_current_category(const struct ast_config *cfg)
@@ -631,7 +632,6 @@ static int process_text_line(struct ast_config *cfg, struct ast_category **cat,
                                } else if (!strcasecmp(cur, "+")) {
                                        *cat = category_get(cfg, catname, 1);
                                        if (!(*cat)) {
-                                               ast_config_destroy(cfg);
                                                if (newcat)
                                                        ast_category_destroy(newcat);
                                                ast_log(LOG_WARNING, "Category addition requested, but category '%s' does not exist, line %d of %s\n", catname, lineno, configfile);
@@ -829,15 +829,13 @@ static struct ast_config *config_text_file_load(const char *database, const char
                        fflush(stdout);
                }
                if (!(f = fopen(fn, "r"))) {
-                       if (option_debug)
-                               ast_log(LOG_DEBUG, "No file to parse: %s\n", fn);
+                       ast_debug(1, "No file to parse: %s\n", fn);
                        if (option_verbose > 1)
                                ast_verbose( "Not found (%s)\n", strerror(errno));
                        continue;
                }
                count++;
-               if (option_debug)
-                       ast_log(LOG_DEBUG, "Parsing %s\n", fn);
+               ast_debug(1, "Parsing %s\n", fn);
                if (option_verbose > 1)
                        ast_verbose("Found\n");
                while (!feof(f)) {
@@ -935,8 +933,8 @@ static struct ast_config *config_text_file_load(const char *database, const char
 #endif
 
        if (cfg && cfg->include_level == 1 && withcomments && comment_buffer) {
-               free(comment_buffer);
-               free(lline_buffer);
+               ast_free(comment_buffer);
+               ast_free(lline_buffer);
                comment_buffer = NULL;
                lline_buffer = NULL;
                comment_buffer_size = 0;
@@ -1028,8 +1026,7 @@ int config_text_file_save(const char *configfile, const struct ast_config *cfg,
                if ((option_verbose > 1) && !option_debug)
                        ast_verbose("Saved\n");
        } else {
-               if (option_debug)
-                       ast_log(LOG_DEBUG, "Unable to open for writing: %s\n", fn);
+               ast_debug(1, "Unable to open for writing: %s\n", fn);
                if (option_verbose > 1)
                        ast_verbose(VERBOSE_PREFIX_2 "Unable to write (%s)", strerror(errno));
                return -1;
@@ -1047,7 +1044,7 @@ static void clear_config_maps(void)
        while (config_maps) {
                map = config_maps;
                config_maps = config_maps->next;
-               free(map);
+               ast_free(map);
        }
                
        ast_mutex_unlock(&config_lock);
@@ -1270,6 +1267,8 @@ struct ast_config *ast_config_internal_load(const char *filename, struct ast_con
 
        if (result)
                result->include_level--;
+       else
+               cfg->include_level--;
 
        return result;
 }
@@ -1344,7 +1343,7 @@ struct ast_variable *ast_load_realtime(const char *family, ...)
        /* Eliminate blank entries */
        for (cur = res; cur; cur = cur->next) {
                if (freeme) {
-                       free(freeme);
+                       ast_free(freeme);
                        freeme = NULL;
                }