[asterisk-commits] mogorman: trunk r47491 - in /trunk: include/asterisk/ main/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Nov 10 19:12:27 MST 2006


Author: mogorman
Date: Fri Nov 10 20:12:27 2006
New Revision: 47491

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47491
Log:
safe terminal output is sweet.

Modified:
    trunk/include/asterisk/term.h
    trunk/main/logger.c
    trunk/main/term.c

Modified: trunk/include/asterisk/term.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/term.h?view=diff&rev=47491&r1=47490&r2=47491
==============================================================================
--- trunk/include/asterisk/term.h (original)
+++ trunk/include/asterisk/term.h Fri Nov 10 20:12:27 2006
@@ -59,6 +59,8 @@
 
 char *term_strip(char *outbuf, char *inbuf, int maxout);
 
+void term_filter_escapes(char *line);
+
 char *term_prompt(char *outbuf, const char *inbuf, int maxout);
 
 char *term_prep(void);

Modified: trunk/main/logger.c
URL: http://svn.digium.com/view/asterisk/trunk/main/logger.c?view=diff&rev=47491&r1=47490&r2=47491
==============================================================================
--- trunk/main/logger.c (original)
+++ trunk/main/logger.c Fri Nov 10 20:12:27 2006
@@ -716,8 +716,10 @@
 			va_start(ap, fmt);
 			res = ast_dynamic_str_thread_set_va(&buf, BUFSIZ, &log_buf, fmt, ap);
 			va_end(ap);
-			if (res != AST_DYNSTR_BUILD_FAILED)
+			if (res != AST_DYNSTR_BUILD_FAILED) {
+				term_filter_escapes(buf->str);
 				fputs(buf->str, stdout);
+			}
 		}
 		return;
 	}
@@ -781,7 +783,8 @@
 					term_color(tmp2, file, COLOR_BRWHITE, 0, sizeof(tmp2)),
 					term_color(tmp3, linestr, COLOR_BRWHITE, 0, sizeof(tmp3)),
 					term_color(tmp4, function, COLOR_BRWHITE, 0, sizeof(tmp4)));
-
+				/*filter to the console!*/
+				term_filter_escapes(buf->str);
 				ast_console_puts_mutable(buf->str);
 				
 				va_start(ap, fmt);
@@ -892,6 +895,9 @@
 
 	if (res == AST_DYNSTR_BUILD_FAILED)
 		return;
+	
+	/* filter out possibly hazardous escape sequences */
+	term_filter_escapes(buf->str);
 
 	AST_LIST_LOCK(&verbosers);
 	AST_LIST_TRAVERSE(&verbosers, v, list)

Modified: trunk/main/term.c
URL: http://svn.digium.com/view/asterisk/trunk/main/term.c?view=diff&rev=47491&r1=47490&r2=47491
==============================================================================
--- trunk/main/term.c (original)
+++ trunk/main/term.c Fri Nov 10 20:12:27 2006
@@ -264,6 +264,34 @@
 	return outbuf;
 }
 
+
+/* filter escape sequences */
+void term_filter_escapes(char *line)
+ {
+	 int i;
+   
+	 for (i=0; i < strlen(line); i++) {
+		 if (line[i] == ESC) {					 
+			 if (line[i+1] == '\x5b') {
+				 switch (line[i+2]) {
+				 	case '\x30':
+						 break;
+					 case '\x31':
+						 break;
+					 case '\x33':
+						 break;
+					 default:
+						 /* replace ESC with a space */
+						 line[i] = ' ';
+				 }
+			 } else {
+				 /* replace ESC with a space */
+				 line[i] = ' ';
+			 }
+		 } 
+	 }
+ }
+
 char *term_prep(void)
 {
 	return prepdata;



More information about the asterisk-commits mailing list