[svn-commits] seanbright: branch seanbright/cdr-syslog r203634 - in /team/seanbright/cdr-sy...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Jun 26 08:35:13 CDT 2009


Author: seanbright
Date: Fri Jun 26 08:35:09 2009
New Revision: 203634

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=203634
Log:
Update to reflect recent changes in asterisk.  Wrap code to less than 90
characters.  Rename 'level' in sample config to priority to accurately
reflect what it is.

Modified:
    team/seanbright/cdr-syslog/cdr/cdr_syslog.c
    team/seanbright/cdr-syslog/configs/cdr_syslog.conf.sample

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=203634&r1=203633&r2=203634
==============================================================================
--- team/seanbright/cdr-syslog/cdr/cdr_syslog.c (original)
+++ team/seanbright/cdr-syslog/cdr/cdr_syslog.c Fri Jun 26 08:35:09 2009
@@ -1,7 +1,9 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 2009, Sean Bright
+ * Copyright (C) 2009, malleable, LLC.
+ *
+ * Sean Bright <sean at malleable.com>
  *
  * See http://www.asterisk.org for more information about
  * the Asterisk project. Please do not directly contact
@@ -14,9 +16,10 @@
  * at the top of the source tree.
  */
 
-/*! \file
+/*! \file cdr_syslog.c
  *
  * \brief syslog CDR logger
+ * \author Sean Bright <sean at malleable.com>
  *
  * See also
  * \arg \ref Config_cdr
@@ -24,8 +27,8 @@
  */
 
 /*** MODULEINFO
-	<depend>syslog</depend>
- ***/
+	 <depend>syslog</depend>
+***/
 
 #include "asterisk.h"
 
@@ -37,6 +40,8 @@
 #include "asterisk/pbx.h"
 
 #include <syslog.h>
+
+#include "asterisk/syslog.h"
 
 #define CONFIG "cdr_syslog.conf"
 
@@ -50,153 +55,12 @@
 		AST_STRING_FIELD(format);
 		);
 	int facility;
-	int level;
+	int priority;
 	ast_mutex_t lock;
 	AST_LIST_ENTRY(cdr_config) list;
 };
 
 static AST_RWLIST_HEAD_STATIC(sinks, cdr_config);
-
-struct name_to_id_map {
-	const char * const name;
-	int value;
-};
-
-static const int INVALID_NAME = ~0;
-
-static const struct name_to_id_map facilities[] = {
-#if defined(HAVE_SYSLOG_FACILITY_LOG_AUTH)
-	{ "auth",     LOG_AUTH     },
-#endif
-#if defined(HAVE_SYSLOG_FACILITY_LOG_AUTHPRIV)
-	{ "authpriv", LOG_AUTHPRIV },
-#endif
-#if defined(HAVE_SYSLOG_FACILITY_LOG_CRON)
-	{ "cron",     LOG_CRON     },
-#endif
-#if defined(HAVE_SYSLOG_FACILITY_LOG_DAEMON)
-	{ "daemon",   LOG_DAEMON   },
-#endif
-#if defined(HAVE_SYSLOG_FACILITY_LOG_FTP)
-	{ "ftp",      LOG_FTP      },
-#endif
-#if defined(HAVE_SYSLOG_FACILITY_LOG_KERN)
-	{ "kern",     LOG_KERN     },
-#endif
-#if defined(HAVE_SYSLOG_FACILITY_LOG_LOCAL0)
-	{ "local0",   LOG_LOCAL0   },
-#endif
-#if defined(HAVE_SYSLOG_FACILITY_LOG_LOCAL1)
-	{ "local1",   LOG_LOCAL1   },
-#endif
-#if defined(HAVE_SYSLOG_FACILITY_LOG_LOCAL2)
-	{ "local2",   LOG_LOCAL2   },
-#endif
-#if defined(HAVE_SYSLOG_FACILITY_LOG_LOCAL3)
-	{ "local3",   LOG_LOCAL3   },
-#endif
-#if defined(HAVE_SYSLOG_FACILITY_LOG_LOCAL4)
-	{ "local4",   LOG_LOCAL4   },
-#endif
-#if defined(HAVE_SYSLOG_FACILITY_LOG_LOCAL5)
-	{ "local5",   LOG_LOCAL5   },
-#endif
-#if defined(HAVE_SYSLOG_FACILITY_LOG_LOCAL6)
-	{ "local6",   LOG_LOCAL6   },
-#endif
-#if defined(HAVE_SYSLOG_FACILITY_LOG_LOCAL7)
-	{ "local7",   LOG_LOCAL7   },
-#endif
-#if defined(HAVE_SYSLOG_FACILITY_LOG_LPR)
-	{ "lpr",      LOG_LPR      },
-#endif
-#if defined(HAVE_SYSLOG_FACILITY_LOG_MAIL)
-	{ "mail",     LOG_MAIL     },
-#endif
-#if defined(HAVE_SYSLOG_FACILITY_LOG_NEWS)
-	{ "news",     LOG_NEWS     },
-#endif
-#if defined(HAVE_SYSLOG_FACILITY_LOG_SYSLOG)
-	{ "syslog",   LOG_SYSLOG   },
-#endif
-#if defined(HAVE_SYSLOG_FACILITY_LOG_USER)
-	{ "user",     LOG_USER     },
-#endif
-#if defined(HAVE_SYSLOG_FACILITY_LOG_UUCP)
-	{ "uucp",     LOG_UUCP     },
-#endif
-};
-
-static const struct name_to_id_map levels[] = {
-#if defined(HAVE_SYSLOG_LEVEL_LOG_EMERG)
-	{ "emerg",   LOG_EMERG   },
-#endif
-#if defined(HAVE_SYSLOG_LEVEL_LOG_ALERT)
-	{ "alert",   LOG_ALERT   },
-#endif
-#if defined(HAVE_SYSLOG_LEVEL_LOG_CRIT)
-	{ "crit",    LOG_CRIT    },
-#endif
-#if defined(HAVE_SYSLOG_LEVEL_LOG_ERR)
-	{ "err",     LOG_ERR     },
-#endif
-#if defined(HAVE_SYSLOG_LEVEL_LOG_WARNING)
-	{ "warning", LOG_WARNING },
-#endif
-#if defined(HAVE_SYSLOG_LEVEL_LOG_NOTICE)
-	{ "notice",  LOG_NOTICE  },
-#endif
-#if defined(HAVE_SYSLOG_LEVEL_LOG_INFO)
-	{ "info",    LOG_INFO    },
-#endif
-#if defined(HAVE_SYSLOG_LEVEL_LOG_DEBUG)
-	{ "debug",   LOG_DEBUG   },
-#endif
-};
-
-static int map_facility_name(const char *facility)
-{
-	size_t i;
-	for (i = 0; i < ARRAY_LEN(facilities); i++) {
-		if (!strcasecmp(facility, facilities[i].name)) {
-			return facilities[i].value;
-		}
-	}
-	return INVALID_NAME;
-}
-
-static const char *map_facility_value(int facility)
-{
-	size_t i;
-	for (i = 0; i < ARRAY_LEN(facilities); i++) {
-		if (facility == facilities[i].value) {
-			return facilities[i].name;
-		}
-	}
-	return NULL;
-}
-
-static int map_level_name(const char *level)
-{
-	size_t i;
-	for (i = 0; i < ARRAY_LEN(levels); i++) {
-		if (!strcasecmp(level, levels[i].name)) {
-			return levels[i].value;
-		}
-	}
-	return INVALID_NAME;
-}
-
-static const char *map_level_value(int level)
-{
-	size_t i;
-	for (i = 0; i < ARRAY_LEN(levels); i++) {
-		if (level == levels[i].value) {
-			return levels[i].name;
-		}
-	}
-	return NULL;
-}
 
 static void free_config(void)
 {
@@ -213,7 +77,8 @@
 	struct ast_str *str;
 	struct cdr_config *sink;
 
-	/* Batching saves memory management here.  Otherwise, it's the same as doing an allocation and free each time. */
+	/* Batching saves memory management here.  Otherwise, it's the same as doing an
+	   allocation and free each time. */
 	if (!(str = ast_str_thread_get(&syslog_buf, 16))) {
 		return -1;
 	}
@@ -243,7 +108,7 @@
 		ast_mutex_lock(&sink->lock);
 
 		openlog(sink->ident, LOG_CONS, sink->facility);
-		syslog(sink->level, "%s", ast_str_buffer(str));
+		syslog(sink->priority, "%s", ast_str_buffer(str));
 		closelog();
 
 		ast_mutex_unlock(&sink->lock);
@@ -261,38 +126,42 @@
 	struct ast_config *cfg;
 	struct ast_flags config_flags = { 0 };
 	int default_facility = LOG_LOCAL4;
-	int default_level = LOG_INFO;
+	int default_priority = LOG_INFO;
 	int res = 0;
 	const char *catg, *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");
+		ast_log(AST_LOG_ERROR,
+			"Unable to load " CONFIG ". Not logging custom CSV CDRs to syslog.\n");
 		return -1;
 	}
 
 	if (!(ast_strlen_zero(tmp = ast_variable_retrieve(cfg, "general", "facility")))) {
-		int facility = map_facility_name(tmp);		if (facility == INVALID_NAME) {
-			ast_log(AST_LOG_WARNING, "Invalid facility '%s' specified, defaulting to '%s'\n",
-					tmp,
-					map_facility_value(default_facility));
+		int facility = ast_syslog_facility(tmp);
+		if (facility < 0) {
+			ast_log(AST_LOG_WARNING,
+				"Invalid facility '%s' specified, defaulting to '%s'\n",
+				tmp, ast_syslog_facility_name(default_facility));
 		} else {
 			default_facility = facility;
 		}
 	}
 
-	if (!(ast_strlen_zero(tmp = ast_variable_retrieve(cfg, "general", "level")))) {
-		int level = map_level_name(tmp);
-		if (level == INVALID_NAME) {
-			ast_log(AST_LOG_WARNING, "Invalid level '%s' specified, defaulting to '%s'\n",
-					tmp,
-					map_level_value(default_level));
-		} else {
-			default_level = level;
-		}
-	}
-
-	for (catg = ast_category_browse(cfg, NULL); catg; catg = ast_category_browse(cfg, catg)) {
+	if (!(ast_strlen_zero(tmp = ast_variable_retrieve(cfg, "general", "priority")))) {
+		int priority = ast_syslog_priority(tmp);
+		if (priority < 0) {
+			ast_log(AST_LOG_WARNING,
+				"Invalid priority '%s' specified, defaulting to '%s'\n",
+				tmp, ast_syslog_priority_name(default_priority));
+		} else {
+			default_priority = priority;
+		}
+	}
+
+	for (catg = ast_category_browse(cfg, NULL);
+		 catg;
+		 catg = ast_category_browse(cfg, catg)) {
 		struct ast_variable *var;
 		struct cdr_config *sink;
 
@@ -305,14 +174,16 @@
 		}
 
 		if (ast_strlen_zero(tmp = ast_variable_retrieve(cfg, catg, "template"))) {
-			ast_log(AST_LOG_WARNING, "No 'template' parameter found for '%s'.  Skipping.\n", catg);
+			ast_log(AST_LOG_WARNING,
+				"No 'template' parameter found for '%s'.  Skipping.\n", catg);
 			continue;
 		}
 
 		sink = ast_calloc_with_stringfields(1, struct cdr_config, 1024);
 
 		if (!sink) {
-			ast_log(AST_LOG_ERROR, "Unable to allocate memory for configuration settings.\n");
+			ast_log(AST_LOG_ERROR,
+				"Unable to allocate memory for configuration settings.\n");
 			free_config();
 			break;
 		}
@@ -323,28 +194,26 @@
 		if (ast_strlen_zero(tmp = ast_variable_retrieve(cfg, catg, "facility"))) {
 			sink->facility = default_facility;
 		} else {
-			int facility = map_facility_name(tmp);
-			if (facility == INVALID_NAME) {
-				ast_log(AST_LOG_WARNING, "Invalid facility '%s' specified for '%s,' defaulting to '%s'\n",
-						tmp,
-						catg,
-						map_facility_value(default_facility));
+			int facility = ast_syslog_facility(tmp);
+			if (facility < 0) {
+				ast_log(AST_LOG_WARNING,
+					"Invalid facility '%s' specified for '%s,' defaulting to '%s'\n",
+					tmp, catg, ast_syslog_facility_name(default_facility));
 			} else {
 				sink->facility = facility;
 			}
 		}
 
-		if (ast_strlen_zero(tmp = ast_variable_retrieve(cfg, catg, "level"))) {
-			sink->level = default_level;
-		} else {
-			int level = map_level_name(tmp);
-			if (level == INVALID_NAME) {
-				ast_log(AST_LOG_WARNING, "Invalid level '%s' specified for '%s,' defaulting to '%s'\n",
-						tmp,
-						catg,
-						map_level_value(default_level));
+		if (ast_strlen_zero(tmp = ast_variable_retrieve(cfg, catg, "priority"))) {
+			sink->priority = default_priority;
+		} else {
+			int priority = ast_syslog_priority(tmp);
+			if (priority < 0) {
+				ast_log(AST_LOG_WARNING,
+					"Invalid priority '%s' specified for '%s,' defaulting to '%s'\n",
+					tmp, catg, ast_syslog_priority_name(default_priority));
 			} else {
-				sink->level = level;
+				sink->priority = priority;
 			}
 		}
 
@@ -398,7 +267,7 @@
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Customizable syslog CDR Backend",
-				.load = load_module,
-				.unload = unload_module,
-				.reload = reload,
-				);
+	.load = load_module,
+	.unload = unload_module,
+	.reload = reload,
+	);

Modified: team/seanbright/cdr-syslog/configs/cdr_syslog.conf.sample
URL: http://svn.asterisk.org/svn-view/asterisk/team/seanbright/cdr-syslog/configs/cdr_syslog.conf.sample?view=diff&rev=203634&r1=203633&r2=203634
==============================================================================
--- team/seanbright/cdr-syslog/configs/cdr_syslog.conf.sample (original)
+++ team/seanbright/cdr-syslog/configs/cdr_syslog.conf.sample Fri Jun 26 08:35:09 2009
@@ -34,10 +34,10 @@
 ;facility=local0
 
 ;
-; The level signifies the importance of the logged message, but we consider
-; these informational (info) messages by default.  We allow customization so that
-; your syslog.conf settings can more easily filter CDR logging. This can be any
-; of the following:
+; The priority signifies the importance of the logged message, but we consider
+; these informational (info) messages by default.  We allow customization so
+; that your syslog.conf settings can more easily filter CDR logging. This can be
+; any of the following:
 ;
 ;  emerg
 ;  alert
@@ -49,11 +49,11 @@
 ;  debug
 ;
 ; The default is 'info'
-;level=warn
+;priority=warn
 
 ;[cdr-master]
 ;facility = local0
-;level = info
+;priority = info
 ;template = "${CDR(clid)}","${CDR(src)}","${CDR(dst)}","${CDR(dcontext)}","${CDR(channel)}","${CDR(dstchannel)}","${CDR(lastapp)}","${CDR(lastdata)}","${CDR(start)}","${CDR(answer)}","${CDR(end)}","${CDR(duration)}","${CDR(billsec)}","${CDR(disposition)}","${CDR(amaflags)}","${CDR(accountcode)}","${CDR(uniqueid)}","${CDR(userfield)}"
 
 ;[cdr-simple]




More information about the svn-commits mailing list