[asterisk-commits] russell: branch group/newcdr r202222 - in /team/group/newcdr: cel/ configs/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Jun 20 15:52:15 CDT 2009


Author: russell
Date: Sat Jun 20 15:52:04 2009
New Revision: 202222

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=202222
Log:
Fixes/cleanups for cel_manager

 - Remove unused and broken code for handling custom mappings
 - move the one configuration option into cel.conf
 - use standard return values from load_config()

Removed:
    team/group/newcdr/configs/cel_manager.conf.sample
Modified:
    team/group/newcdr/cel/cel_manager.c
    team/group/newcdr/configs/cel.conf.sample

Modified: team/group/newcdr/cel/cel_manager.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/cel/cel_manager.c?view=diff&rev=202222&r1=202221&r2=202222
==============================================================================
--- team/group/newcdr/cel/cel_manager.c (original)
+++ team/group/newcdr/cel/cel_manager.c Sat Jun 20 15:52:04 2009
@@ -45,91 +45,13 @@
 #include "asterisk/manager.h"
 #include "asterisk/config.h"
 
-#define DATE_FORMAT     "%Y-%m-%d %T"
-#define CONF_FILE	    "cel_manager.conf"
+static const char DATE_FORMAT[] = "%Y-%m-%d %T";
 
-#define CUSTOM_FIELDS_BUF_SIZE 1024
+static const char CONF_FILE[] = "cel.conf";
 
-struct ast_str *customfields;
+static int enablecel;
 
-static int enablecel = 0;
-static struct ast_event_sub *event_sub = NULL;
-static void manager_log(const struct ast_event *event, void *userdata);
-
-static int load_config(int reload)
-{
-	char *cat = NULL;
-	struct ast_config *cfg;
-	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
-	struct ast_variable *v;
-	int newenablecel = 0;
-
-	cfg = ast_config_load(CONF_FILE, config_flags);
-	if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
-		ast_log(LOG_NOTICE,"CEL manager backend: config file has not changed.\n");
-		return 0;
-	}
-
-	if (reload && customfields) {
-		ast_free(customfields);
-	}
-	customfields = NULL;
-
-	if (!cfg) {
-		ast_log(LOG_WARNING, "Failed to load configuration file. CEL manager Module not activated.\n");
-		/* Standard configuration */
-		enablecel = 0;
-		return 0;
-	}
-
-	if (!ast_variable_browse(cfg, "general")) {
-		/* nothing configured */
-		ast_config_destroy(cfg);
-		ast_log(LOG_NOTICE, "cel_manager has no [general] category, nothing to configure.\n");
-		return 0;
-	}
-
-	while ((cat = ast_category_browse(cfg, cat))) {
-		if (!strcasecmp(cat, "general")) {
-			v = ast_variable_browse(cfg, cat);
-			while (v) {
-				if (!strcasecmp(v->name, "enabled")) {
-					newenablecel = ast_true(v->value);
-				}
-				v = v->next;
-			}
-		} else if (!strcasecmp(cat, "mappings")) {
-			customfields = ast_str_create(CUSTOM_FIELDS_BUF_SIZE);
-			for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
-				if (customfields && !ast_strlen_zero(v->name) && !ast_strlen_zero(v->value)) {
-					if ((ast_str_strlen(customfields) + strlen(v->value) + strlen(v->name) + 14) < ast_str_size(customfields)) {
-						ast_str_append(&customfields, -1, "%s: ${CDR(%s)}\r\n", v->value, v->name);
-						ast_log(LOG_NOTICE, "Added mapping %s: ${CDR(%s)}\n", v->value, v->name);
-					} else {
-						ast_log(LOG_WARNING, "No more buffer space to add other custom fields\n");
-						break;
-					}
-				}
-			}
-		}
-	}
-
-	ast_config_destroy(cfg);
-
-	if (enablecel && !newenablecel) {
-		if (event_sub) {
-			event_sub = ast_event_unsubscribe(event_sub);
-		}
-	} else if (!enablecel && newenablecel) {
-		event_sub = ast_event_subscribe(AST_EVENT_CEL, manager_log, "Manager Event Logging", NULL, AST_EVENT_IE_END);
-		if (!event_sub) {
-			ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CEL handling\n");
-		}
-	}
-	enablecel = newenablecel;
-
-	return 1;
-}
+static struct ast_event_sub *event_sub;
 
 static void manager_log(const struct ast_event *event, void *userdata)
 {
@@ -177,24 +99,71 @@
 		record.user_field, record.peer);
 }
 
+static int load_config(int reload)
+{
+	char *cat = NULL;
+	struct ast_config *cfg;
+	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
+	struct ast_variable *v;
+	int newenablecel = 0;
+
+	cfg = ast_config_load(CONF_FILE, config_flags);
+	if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
+		return -1;
+	}
+
+	if (!cfg) {
+		ast_log(LOG_WARNING, "Failed to load configuration file. CEL manager Module not activated.\n");
+		enablecel = 0;
+		return -1;
+	}
+
+	while ((cat = ast_category_browse(cfg, cat))) {
+		if (strcasecmp(cat, "manager")) {
+			continue;
+		}
+
+		for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
+			if (!strcasecmp(v->name, "enabled")) {
+				newenablecel = ast_true(v->value);
+			} else {
+				ast_log(LOG_NOTICE, "Unknown option '%s' specified "
+						"for cel_manager.\n", v->name);
+			}
+		}
+	}
+
+	ast_config_destroy(cfg);
+
+	if (enablecel && !newenablecel) {
+		if (event_sub) {
+			event_sub = ast_event_unsubscribe(event_sub);
+		}
+	} else if (!enablecel && newenablecel) {
+		event_sub = ast_event_subscribe(AST_EVENT_CEL, manager_log, "Manager Event Logging", NULL, AST_EVENT_IE_END);
+		if (!event_sub) {
+			ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CEL handling\n");
+		}
+	}
+	enablecel = newenablecel;
+
+	return 0;
+}
+
 static int unload_module(void)
 {
 	if (event_sub) {
 		event_sub = ast_event_unsubscribe(event_sub);
 	}
-	if (customfields) {
-		ast_free(customfields);
-	}
-	customfields = NULL;
 	return 0;
 }
 
 static int load_module(void)
 {
-	/* Configuration file */
-	if (!load_config(0)) {
+	if (load_config(0)) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
+
 	return AST_MODULE_LOAD_SUCCESS;
 }
 

Modified: team/group/newcdr/configs/cel.conf.sample
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/configs/cel.conf.sample?view=diff&rev=202222&r1=202221&r2=202222
==============================================================================
--- team/group/newcdr/configs/cel.conf.sample (original)
+++ team/group/newcdr/configs/cel.conf.sample Sat Jun 20 15:52:04 2009
@@ -53,5 +53,8 @@
 
 ;dateformat = %ld.%06ld
 
-[csv]
-usegmtime=yes ;log date/time in GMT
+[manager]
+; CEL over AMI - cel_manager.so
+
+; Set to 'yes' to enable.  Disabled by deafult.
+;enabled = yes




More information about the asterisk-commits mailing list