Fix silly newline miss (bug #3555)
[asterisk/asterisk.git] / loader.c
index 5ac59a0..911fb94 100755 (executable)
--- a/loader.c
+++ b/loader.c
@@ -3,7 +3,7 @@
  *
  * Module Loader
  * 
- * Copyright (C) 1999-2004, Digium, Inc.
+ * Copyright (C) 1999 - 2005, Digium, Inc.
  *
  * Mark Spencer <markster@digium.com>
  *
@@ -19,7 +19,6 @@
 #include <asterisk/module.h>
 #include <asterisk/options.h>
 #include <asterisk/config.h>
-#include <asterisk/config_pvt.h>
 #include <asterisk/logger.h>
 #include <asterisk/channel.h>
 #include <asterisk/term.h>
@@ -67,7 +66,7 @@ static int printdigest(unsigned char *d)
                strcat(buf, buf2);
        }
        strcat(buf, "\n");
-       ast_log(LOG_DEBUG, buf);
+       ast_log(LOG_DEBUG, "%s", buf);
        return 0;
 }
 
@@ -105,7 +104,7 @@ AST_MUTEX_DEFINE_STATIC(reloadlock);
 static struct module *module_list=NULL;
 static int modlistver = 0;
 
-int ast_unload_resource(char *resource_name, int force)
+int ast_unload_resource(const char *resource_name, int force)
 {
        struct module *m, *ml = NULL;
        int res = -1;
@@ -169,9 +168,9 @@ char *ast_module_helper(char *line, char *word, int pos, int state, int rpos, in
                ret = strdup(m->resource);
        } else {
                ret = NULL;
-               if (!strncasecmp(word, "astconfig", strlen(word))) {
+               if (!strncasecmp(word, "extconfig", strlen(word))) {
                        if (++which > state)
-                               ret = strdup("astconfig");
+                               ret = strdup("extconfig");
                } else if (!strncasecmp(word, "manager", strlen(word))) {
                        if (++which > state)
                                ret = strdup("manager");
@@ -200,8 +199,8 @@ int ast_module_reload(const char *name)
                ast_verbose("The previous reload command didn't finish yet\n");
                return -1;
        }
-       if (!name || !strcasecmp(name, "astconfig")) {
-               read_ast_cust_config();
+       if (!name || !strcasecmp(name, "extconfig")) {
+               read_config_maps();
                reloaded = 2;
        }
        if (!name || !strcasecmp(name, "manager")) {
@@ -244,7 +243,7 @@ int ast_module_reload(const char *name)
        return reloaded;
 }
 
-int ast_load_resource(char *resource_name)
+static int __load_resource(const char *resource_name, const struct ast_config *cfg)
 {
        static char fn[256];
        int errors=0;
@@ -255,23 +254,16 @@ int ast_load_resource(char *resource_name)
        char *val;
 #endif
        char *key;
-       int o;
-       struct ast_config *cfg;
        char tmp[80];
-       /* Keep the module file parsing silent */
-       o = option_verbose;
+
        if (strncasecmp(resource_name, "res_", 4)) {
-               option_verbose = 0;
-               cfg = ast_load(AST_MODULE_CONFIG);
-               option_verbose = o;
-               if (cfg) {
 #ifdef RTLD_GLOBAL
+               if (cfg) {
                        if ((val = ast_variable_retrieve(cfg, "global", resource_name))
                                        && ast_true(val))
                                flags |= RTLD_GLOBAL;
-#endif
-                       ast_destroy(cfg);
                }
+#endif
        } else {
                /* Resource modules are always loaded global and lazy */
 #ifdef RTLD_GLOBAL
@@ -399,6 +391,23 @@ int ast_load_resource(char *resource_name)
        }
        ast_update_use_count();
        return 0;
+}
+
+int ast_load_resource(const char *resource_name)
+{
+       int o;
+       struct ast_config *cfg = NULL;
+       int res;
+
+       /* Keep the module file parsing silent */
+       o = option_verbose;
+       option_verbose = 0;
+       cfg = ast_config_load(AST_MODULE_CONFIG);
+       option_verbose = o;
+       res = __load_resource(resource_name, cfg);
+       if (cfg)
+               ast_config_destroy(cfg);
+       return res;
 }      
 
 static int ast_resource_exists(char *resource)
@@ -434,7 +443,7 @@ int load_modules()
        char tmp[80];
        if (option_verbose) 
                ast_verbose( "Asterisk Dynamic Loader Starting:\n");
-       cfg = ast_load(AST_MODULE_CONFIG);
+       cfg = ast_config_load(AST_MODULE_CONFIG);
        if (cfg) {
                /* Load explicitly defined modules */
                v = ast_variable_browse(cfg, "modules");
@@ -446,10 +455,10 @@ int load_modules()
                                        ast_verbose( VERBOSE_PREFIX_1 "[%s]", term_color(tmp, v->value, COLOR_BRWHITE, 0, sizeof(tmp)));
                                        fflush(stdout);
                                }
-                               if (ast_load_resource(v->value)) {
+                               if (__load_resource(v->value, cfg)) {
                                        ast_log(LOG_WARNING, "Loading module %s failed!\n", v->value);
                                        if (cfg)
-                                               ast_destroy(cfg);
+                                               ast_config_destroy(cfg);
                                        return -1;
                                }
                        }
@@ -496,10 +505,10 @@ int load_modules()
                                                        ast_verbose( VERBOSE_PREFIX_1 "[%s]", term_color(tmp, d->d_name, COLOR_BRWHITE, 0, sizeof(tmp)));
                                                        fflush(stdout);
                                                }
-                                               if (ast_load_resource(d->d_name)) {
+                                               if (__load_resource(d->d_name, cfg)) {
                                                        ast_log(LOG_WARNING, "Loading module %s failed!\n", d->d_name);
                                                        if (cfg)
-                                                               ast_destroy(cfg);
+                                                               ast_config_destroy(cfg);
                                                        return -1;
                                                }
                                        }
@@ -511,7 +520,7 @@ int load_modules()
                        }
                }
        } 
-       ast_destroy(cfg);
+       ast_config_destroy(cfg);
        return 0;
 }