[asterisk-commits] rmudgett: trunk r187634 - /trunk/channels/chan_misdn.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 10 09:50:45 CDT 2009


Author: rmudgett
Date: Fri Apr 10 09:50:42 2009
New Revision: 187634

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=187634
Log:
Make chan_misdn_log() avoid generating the log message if logging is disabled.

Modified:
    trunk/channels/chan_misdn.c

Modified: trunk/channels/chan_misdn.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/channels/chan_misdn.c?view=diff&rev=187634&r1=187633&r2=187634
==============================================================================
--- trunk/channels/chan_misdn.c (original)
+++ trunk/channels/chan_misdn.c Fri Apr 10 09:50:42 2009
@@ -6732,40 +6732,44 @@
 	char buf[1024];
 	char port_buf[8];
 
-	if (! ((0 <= port) && (port <= max_ports))) {
+	if (!(0 <= port && port <= max_ports)) {
 		ast_log(LOG_WARNING, "cb_log called with out-of-range port number! (%d)\n", port);
 		port = 0;
 		level = -1;
+	} else if (!(level == -1
+		|| (misdn_debug_only[port]
+			? (level == 1 && misdn_debug[port]) || level == misdn_debug[port]
+			: level <= misdn_debug[port])
+		|| (level <= misdn_debug[0] && !ast_strlen_zero(global_tracefile)))) {
+		/*
+		 * We are not going to print anything so lets not
+		 * go to all the work of generating a string.
+		 */
+		return;
 	}
 
 	snprintf(port_buf, sizeof(port_buf), "P[%2d] ", port);
-
 	va_start(ap, tmpl);
 	vsnprintf(buf, sizeof(buf), tmpl, ap);
 	va_end(ap);
 
 	if (level == -1) {
 		ast_log(LOG_WARNING, "%s", buf);
-	} else if (misdn_debug_only[port] ?
-			(level == 1 && misdn_debug[port]) || (level == misdn_debug[port])
-		 : level <= misdn_debug[port]) {
-
+	} else if (misdn_debug_only[port]
+		? (level == 1 && misdn_debug[port]) || level == misdn_debug[port]
+		: level <= misdn_debug[port]) {
 		ast_console_puts(port_buf);
 		ast_console_puts(buf);
 	}
 
-	if ((level <= misdn_debug[0]) && !ast_strlen_zero(global_tracefile) ) {
+	if (level <= misdn_debug[0] && !ast_strlen_zero(global_tracefile)) {
 		char ctimebuf[30];
-		time_t tm = time(NULL);
-		char *tmp = ctime_r(&tm, ctimebuf), *p;
-
-		FILE *fp = fopen(global_tracefile, "a+");
-
-		p = strchr(tmp, '\n');
-		if (p) {
-			*p = ':';
-		}
-
+		time_t tm;
+		char *tmp;
+		char *p;
+		FILE *fp;
+
+		fp = fopen(global_tracefile, "a+");
 		if (!fp) {
 			ast_console_puts("Error opening Tracefile: [ ");
 			ast_console_puts(global_tracefile);
@@ -6773,9 +6777,15 @@
 
 			ast_console_puts(strerror(errno));
 			ast_console_puts("\n");
-			return ;
-		}
-
+			return;
+		}
+
+		tm = time(NULL);
+		tmp = ctime_r(&tm, ctimebuf);
+		p = strchr(tmp, '\n');
+		if (p) {
+			*p = ':';
+		}
 		fputs(tmp, fp);
 		fputs(" ", fp);
 		fputs(port_buf, fp);




More information about the asterisk-commits mailing list