[asterisk-commits] rmudgett: branch rmudgett/ast_verb r405155 - /team/rmudgett/ast_verb/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 8 12:53:57 CST 2014


Author: rmudgett
Date: Wed Jan  8 12:53:55 2014
New Revision: 405155

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=405155
Log:
Send verbose command on rasterisk connect.

Modified:
    team/rmudgett/ast_verb/main/asterisk.c
    team/rmudgett/ast_verb/main/cli.c

Modified: team/rmudgett/ast_verb/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/ast_verb/main/asterisk.c?view=diff&rev=405155&r1=405154&r2=405155
==============================================================================
--- team/rmudgett/ast_verb/main/asterisk.c (original)
+++ team/rmudgett/ast_verb/main/asterisk.c Wed Jan  8 12:53:55 2014
@@ -2126,26 +2126,31 @@
 		*++prev = '\0';
 
 		if (strncasecmp(shrunk, "core set verbose ", 17) == 0) {
-			int verbose_new;
-
 			/*
 			 * We need to still set the rasterisk option_verbose in case we are
 			 * talking to an earlier version which doesn't prefilter verbose
 			 * levels.  This is really a compromise as we should always take
-			 * what the server sends.
+			 * whatever the server sends.
 			 */
 
-			if (strncasecmp(shrunk + 17, "atleast ", 8) == 0) {
-				if (sscanf(shrunk + 25, "%30d", &verbose_new) == 1) {
-					if (ast_verb_console_get() < verbose_new) {
+			if (!strncasecmp(shrunk + 17, "off", 3)) {
+				ast_verb_console_set(0);
+			} else {
+				int verbose_new;
+				int atleast;
+				int is_silent;
+
+				atleast = 8;
+				if (strncasecmp(shrunk + 17, "atleast ", atleast)) {
+					atleast = 0;
+				}
+
+				is_silent = (tolower(shrunk[17 + atleast]) == 's') ? 1 : 0;
+
+				if (sscanf(shrunk + 17 + atleast + is_silent, "%30d", &verbose_new) == 1) {
+					if (!atleast || ast_verb_console_get() < verbose_new) {
 						ast_verb_console_set(verbose_new);
 					}
-				}
-			} else if (strncasecmp(shrunk + 17, "off", 3) == 0) {
-				ast_verb_console_set(0);
-			} else {
-				if (sscanf(shrunk + 17, "%30d", &verbose_new) == 1) {
-					ast_verb_console_set(verbose_new);
 				}
 			}
 		}
@@ -2470,6 +2475,31 @@
 #endif /* ! LOW_MEMORY */
 };
 
+static void send_rasterisk_connect_commands(void)
+{
+	/*
+	 * Tell the server asterisk instance about the verbose level
+	 * initially desired.
+	 */
+	if (option_verbose) {
+		char buf[80];
+
+		/*
+		 * The 's' prefixed to the level indicates to silence
+		 * the confirmation message.  Older Asterisk versions
+		 * will generate an error and not set the level.
+		 */
+		snprintf(buf, sizeof(buf), "core set verbose s%d", option_verbose);
+		fdsend(ast_consock, buf);
+	}
+
+	if (!ast_opt_mute) {
+		fdsend(ast_consock, "logger mute silent");
+	} else {
+		printf("log and verbose output currently muted ('logger mute' to unmute)\n");
+	}
+}
+
 static int ast_el_read_char(EditLine *editline, char *cp)
 {
 	int num_read = 0;
@@ -2523,10 +2553,7 @@
 							fprintf(stderr, "Reconnect succeeded after %.3f seconds\n", 1.0 / reconnects_per_second * tries);
 							printf("%s", term_quit());
 							WELCOME_MESSAGE;
-							if (!ast_opt_mute)
-								fdsend(ast_consock, "logger mute silent");
-							else
-								printf("log and verbose output currently muted ('logger mute' to unmute)\n");
+							send_rasterisk_connect_commands();
 							break;
 						} else
 							usleep(1000000 / reconnects_per_second);
@@ -3034,24 +3061,6 @@
 	char *ebuf;
 	int num = 0;
 
-/*
- * BUGBUG could make rasterisk send "core set verbose <level>" when it connects to support the -v and asterisk.conf verbose options.
- *
- * Possibly change the command to accept "core set verbose r<level>" to make
- * it quiet and to make earlier versions of asterisk fail to set the level
- * on the main console.
- *
- * Don't send the verbose command on connect if option_verbose is zero
- * for rasterisk connections since that will be the default.
- *
- * BUGBUG need to set option_verbose = 0 if -x is specified.
- */
-	/*
-	 * Remote console cannot support -v option since that is set by
-	 * the Asterisk server process.
-	 */
-	option_verbose = 0;
-
 	memset(&sig_flags, 0, sizeof(sig_flags));
 	signal(SIGINT, __remote_quit_handler);
 	signal(SIGTERM, __remote_quit_handler);
@@ -3085,11 +3094,7 @@
 	else
 		pid = -1;
 	if (!data) {
-		if (!ast_opt_mute) {
-			fdsend(ast_consock, "logger mute silent");
-		} else {
-			printf("log and verbose output currently muted ('logger mute' to unmute)\n");
-		}
+		send_rasterisk_connect_commands();
 	}
 
 	if (ast_opt_exec && data) {  /* hack to print output then exit if asterisk -rx is used */

Modified: team/rmudgett/ast_verb/main/cli.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/ast_verb/main/cli.c?view=diff&rev=405155&r1=405154&r2=405155
==============================================================================
--- team/rmudgett/ast_verb/main/cli.c (original)
+++ team/rmudgett/ast_verb/main/cli.c Wed Jan  8 12:53:55 2014
@@ -575,6 +575,7 @@
 	int oldval;
 	int newlevel;
 	int atleast = 0;
+	int is_silent = 0;
 	const char *argv3 = a->argv ? S_OR(a->argv[3], "") : "";
 
 	switch (cmd) {
@@ -631,7 +632,16 @@
 		if (a->argc != e->args + atleast + 1) {
 			return CLI_SHOWUSAGE;
 		}
-		if (sscanf(a->argv[e->args + atleast], "%30d", &newlevel) != 1) {
+
+		/*
+		 * If the <level> is prefixed with a 's' then we want to
+		 * set the new level silently.
+		 */
+		if (tolower(a->argv[e->args + atleast][0]) == 's') {
+			is_silent = 1;
+		}
+
+		if (sscanf(a->argv[e->args + atleast] + is_silent, "%30d", &newlevel) != 1) {
 			return CLI_SHOWUSAGE;
 		}
 	}
@@ -642,6 +652,11 @@
 		ast_verb_console_set(newlevel);
 	} else {
 		newlevel = oldval;
+	}
+
+	if (is_silent) {
+		/* Be silent after setting the level. */
+		return CLI_SUCCESS;
 	}
 
 	/* Report verbose level status */




More information about the asterisk-commits mailing list