[svn-commits] seanbright: branch seanbright/cdr-syslog r203669 - /team/seanbright/cdr-syslo...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Jun 26 12:09:14 CDT 2009


Author: seanbright
Date: Fri Jun 26 12:09:11 2009
New Revision: 203669

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=203669
Log:
Updates based on Russell and Mark's feedback as well as some other things I noticed addressing those.

Modified:
    team/seanbright/cdr-syslog/cdr/cdr_syslog.c

Modified: team/seanbright/cdr-syslog/cdr/cdr_syslog.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/seanbright/cdr-syslog/cdr/cdr_syslog.c?view=diff&rev=203669&r1=203668&r2=203669
==============================================================================
--- team/seanbright/cdr-syslog/cdr/cdr_syslog.c (original)
+++ team/seanbright/cdr-syslog/cdr/cdr_syslog.c Fri Jun 26 12:09:11 2009
@@ -43,7 +43,7 @@
 
 #include "asterisk/syslog.h"
 
-#define CONFIG "cdr_syslog.conf"
+static const char CONFIG[] = "cdr_syslog.conf";
 
 AST_THREADSTORAGE(syslog_buf);
 
@@ -53,7 +53,7 @@
 	AST_DECLARE_STRING_FIELDS(
 		AST_STRING_FIELD(ident);
 		AST_STRING_FIELD(format);
-		);
+	);
 	int facility;
 	int priority;
 	ast_mutex_t lock;
@@ -125,13 +125,12 @@
 	struct ast_flags config_flags = { 0 };
 	int default_facility = LOG_LOCAL4;
 	int default_priority = LOG_INFO;
-	int res = 0;
-	const char *catg, *tmp;
+	const char *catg = NULL, *tmp;
 
 	cfg = ast_config_load(CONFIG, config_flags);
 	if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) {
 		ast_log(AST_LOG_ERROR,
-			"Unable to load " CONFIG ". Not logging custom CSV CDRs to syslog.\n");
+			"Unable to load %s. Not logging custom CSV CDRs to syslog.\n", CONFIG);
 		return -1;
 	}
 
@@ -157,17 +156,10 @@
 		}
 	}
 
-	for (catg = ast_category_browse(cfg, NULL);
-		 catg;
-		 catg = ast_category_browse(cfg, catg)) {
-		struct ast_variable *var;
+	while ((catg = ast_category_browse(cfg, catg))) {
 		struct cdr_config *sink;
 
 		if (!strcasecmp(catg, "general")) {
-			continue;
-		}
-
-		if (!(var = ast_variable_browse(cfg, catg))) {
 			continue;
 		}
 
@@ -186,6 +178,7 @@
 			break;
 		}
 
+		ast_mutex_init(&sink->lock);
 		ast_string_field_set(sink, ident, catg);
 		ast_string_field_set(sink, format, tmp);
 
@@ -220,7 +213,11 @@
 
 	ast_config_destroy(cfg);
 
-	return res;
+	if (AST_RWLIST_EMPTY(&sinks)) {
+		return -1;
+	}
+
+	return 0;
 }
 
 static int unload_module(void)
@@ -240,27 +237,36 @@
 
 static enum ast_module_load_result load_module(void)
 {
+	int res;
+
 	if (AST_RWLIST_WRLOCK(&sinks)) {
 		ast_log(AST_LOG_ERROR, "Unable to lock sink list.  Load failed.\n");
-		return AST_MODULE_LOAD_FAILURE;
-	}
-
-	load_config();
-	AST_RWLIST_UNLOCK(&sinks);
+		return AST_MODULE_LOAD_DECLINE;
+	}
+
+	res = load_config();
+	AST_RWLIST_UNLOCK(&sinks);
+	if (res) {
+		return AST_MODULE_LOAD_DECLINE;
+	}
 	ast_cdr_register(name, ast_module_info->description, syslog_log);
 	return AST_MODULE_LOAD_SUCCESS;
 }
 
 static int reload(void)
 {
+	int res;
 	if (AST_RWLIST_WRLOCK(&sinks)) {
 		ast_log(AST_LOG_ERROR, "Unable to lock sink list.  Load failed.\n");
-		return AST_MODULE_LOAD_FAILURE;
+		return AST_MODULE_LOAD_DECLINE;
 	}
 
 	free_config();
-	load_config();
-	AST_RWLIST_UNLOCK(&sinks);
+	res = load_config();
+	AST_RWLIST_UNLOCK(&sinks);
+	if (res) {
+		return AST_MODULE_LOAD_DECLINE;
+	}
 	return AST_MODULE_LOAD_SUCCESS;
 }
 
@@ -268,4 +274,4 @@
 	.load = load_module,
 	.unload = unload_module,
 	.reload = reload,
-	);
+);




More information about the svn-commits mailing list