[asterisk-commits] tilghman: trunk r83466 - /trunk/cdr/cdr_manager.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Sep 21 12:36:18 CDT 2007


Author: tilghman
Date: Fri Sep 21 12:36:17 2007
New Revision: 83466

URL: http://svn.digium.com/view/asterisk?view=rev&rev=83466
Log:
Fix cdr_manager, such that if the config file is created past load, it'll
start logging (and conversely, if the config file is destroyed or deactivated,
the logging is disabled).  Reported by Juggie via IRC, fix by me.

Modified:
    trunk/cdr/cdr_manager.c

Modified: trunk/cdr/cdr_manager.c
URL: http://svn.digium.com/view/asterisk/trunk/cdr/cdr_manager.c?view=diff&rev=83466&r1=83465&r2=83466
==============================================================================
--- trunk/cdr/cdr_manager.c (original)
+++ trunk/cdr/cdr_manager.c Fri Sep 21 12:36:17 2007
@@ -52,12 +52,15 @@
 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 @@
 	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 @@
 		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 @@
 	}
 	
 	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 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)




More information about the asterisk-commits mailing list