Fix cdr_manager, such that if the config file is created past load, it'll
authorTilghman Lesher <tilghman@meg.abyt.es>
Fri, 21 Sep 2007 17:36:17 +0000 (17:36 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Fri, 21 Sep 2007 17:36:17 +0000 (17:36 +0000)
start logging (and conversely, if the config file is destroyed or deactivated,
the logging is disabled).  Reported by Juggie via IRC, fix by me.

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

cdr/cdr_manager.c

index 028b4a8..17b4f03 100644 (file)
@@ -52,12 +52,15 @@ static char *name = "cdr_manager";
 static int enablecdr = 0;
 struct ast_str *customfields;
 
+static int manager_log(struct ast_cdr *cdr);
+
 static int load_config(int reload)
 {
        char *cat = NULL;
        struct ast_config *cfg;
        struct ast_variable *v;
        struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
+       int newenablecdr = 0;
 
        cfg = ast_config_load(CONF_FILE, config_flags);
        if (cfg == CONFIG_STATUS_FILEUNCHANGED)
@@ -71,6 +74,8 @@ static int load_config(int reload)
        if (!cfg) {
                /* Standard configuration */
                ast_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n");
+               if (enablecdr)
+                       ast_cdr_unregister(name);
                enablecdr = 0;
                return 0;
        }
@@ -79,9 +84,8 @@ static int load_config(int reload)
                if (!strcasecmp(cat, "general")) {
                        v = ast_variable_browse(cfg, cat);
                        while (v) {
-                               if (!strcasecmp(v->name, "enabled")) {
-                                       enablecdr = ast_true(v->value);
-                               }
+                               if (!strcasecmp(v->name, "enabled"))
+                                       newenablecdr = ast_true(v->value);
                                
                                v = v->next;
                        }
@@ -105,6 +109,12 @@ static int load_config(int reload)
        }
        
        ast_config_destroy(cfg);
+
+       if (enablecdr && !newenablecdr)
+               ast_cdr_unregister(name);
+       else if (!enablecdr && newenablecdr)
+               ast_cdr_register(name, "Asterisk Manager Interface CDR Backend", manager_log);
+
        return 1;
 }
 
@@ -178,18 +188,11 @@ static int unload_module(void)
 
 static int load_module(void)
 {
-       int res;
-
        /* Configuration file */
        if (!load_config(0))
                return AST_MODULE_LOAD_DECLINE;
-       
-       res = ast_cdr_register(name, "Asterisk Manager Interface CDR Backend", manager_log);
-       if (res) {
-               ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CDR handling\n");
-       }
-       
-       return res;
+
+       return AST_MODULE_LOAD_SUCCESS;
 }
 
 static int reload(void)