[asterisk-commits] anthonyl: branch anthonyl/history-cli r44887 - in /team/anthonyl/history-cli:...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Oct 11 09:15:27 MST 2006


Author: anthonyl
Date: Wed Oct 11 11:15:26 2006
New Revision: 44887

URL: http://svn.digium.com/view/asterisk?rev=44887&view=rev
Log:
some small changes

Modified:
    team/anthonyl/history-cli/channels/chan_skinny.c
    team/anthonyl/history-cli/main/cli.c

Modified: team/anthonyl/history-cli/channels/chan_skinny.c
URL: http://svn.digium.com/view/asterisk/team/anthonyl/history-cli/channels/chan_skinny.c?rev=44887&r1=44886&r2=44887&view=diff
==============================================================================
--- team/anthonyl/history-cli/channels/chan_skinny.c (original)
+++ team/anthonyl/history-cli/channels/chan_skinny.c Wed Oct 11 11:15:26 2006
@@ -746,8 +746,8 @@
 	int  data_len;  /* total length of the message */
 	char *human;    /* human readable form of what the message is */
 	int (* const message_handler)(void); 
-} skinny_messages[] {
-	{ }
+} skinny_messages[] = {
+	{ NULL,NULL,NULL,NULL,NULL}
 };
 
 /*****************************

Modified: team/anthonyl/history-cli/main/cli.c
URL: http://svn.digium.com/view/asterisk/team/anthonyl/history-cli/main/cli.c?rev=44887&r1=44886&r2=44887&view=diff
==============================================================================
--- team/anthonyl/history-cli/main/cli.c (original)
+++ team/anthonyl/history-cli/main/cli.c Wed Oct 11 11:15:26 2006
@@ -56,10 +56,72 @@
 /*! \brief Initial buffer size for resulting strings in ast_cli() */
 #define AST_CLI_INITLEN   256
 
+struct ast_history {
+	int line_num;
+	/* this should mark what type of console message this is warning/debug/notice/protocol specific */
+	int class; 
+	char *line;
+	AST_LIST_ENTRY(ast_history) list;
+};
+
+/* list head for the history buffer */
+static AST_LIST_HEAD_STATIC(history_list, ast_history);
+static int ast_history_count = 0;
+static int ast_history_max   = 50;
+
+/* short history routine (core history cli 10) */
+void ast_cli_display_history(int amt)
+{
+	struct ast_history *p = NULL;
+	int elm=0;
+	
+	AST_LIST_LOCK(&history_list);
+	
+	if (AST_LIST_EMPTY(&history_list)) {
+		ast_verbose("History: there is no histroy here\n");
+		AST_LIST_UNLOCK(&history_list);
+		return;
+	}
+	
+	AST_LIST_TRAVERSE(&history_list,p,list) {
+		ast_verbose("--------------------------------------\n");
+		ast_verbose("history:%i %s",elm,p->line);
+	        if (elm++ > amt) 
+		    break;
+	}
+
+	AST_LIST_UNLOCK(&history_list);
+	ast_verbose("History: there were %i elements\n",elm);
+	
+	return;
+}
+
+void ast_cli_append_history(char *p, int type)
+{
+	struct ast_history *history;
+	
+	if (!p)
+		return;
+
+	history = ast_calloc(1,sizeof(*history));
+
+	if (!history)
+		return;
+
+	/* we need a bitmask of the display for output */
+	AST_LIST_LOCK(&history_list);
+	AST_LIST_INSERT_HEAD(&history_list,history,list);
+	AST_LIST_UNLOCK(&history_list);
+	
+	return;
+}
+
 void ast_cli(int fd, char *fmt, ...)
 {
 	int res;
 	struct ast_dynamic_str *buf;
+	struct ast_history *history;
+	
 	va_list ap;
 
 	if (!(buf = ast_dynamic_str_thread_get(&ast_cli_buf, AST_CLI_INITLEN)))
@@ -69,8 +131,25 @@
 	res = ast_dynamic_str_thread_set_va(&buf, 0, &ast_cli_buf, fmt, ap);
 	va_end(ap);
 
-	if (res != AST_DYNSTR_BUILD_FAILED)
+	history = ast_calloc(1,sizeof(*history));
+
+	if (!history) {
+		ast_log(LOG_ERROR,"Cli: we ran out of memory!\n");
+		return;
+	}
+	
+	if (res != AST_DYNSTR_BUILD_FAILED) {
+		history->line = malloc(strlen(buf->str)+1);
+		if (!history->line) {
+
+		} else {
+			AST_LIST_LOCK(&history_list);
+			strcpy(history->line,buf->str);
+			AST_LIST_INSERT_HEAD(&history_list,history,list);
+			AST_LIST_UNLOCK(&history_list);
+		}
 		ast_carefulwrite(fd, buf->str, strlen(buf->str), 100);
+	}
 }
 
 static AST_LIST_HEAD_STATIC(helpers, ast_cli_entry);
@@ -137,6 +216,10 @@
 "       Lists all currently active channels with channel group(s) specified.\n"
 "       Optional regular expression pattern is matched to group names for each\n"
 "       channel.\n";
+
+/* standard help from the ast_history thingie */
+static char history_list_help[] =
+"Usage: list history of output from the asterisk cli\n";
 
 static int handle_load(int fd, int argc, char *argv[])
 {
@@ -1034,6 +1117,9 @@
 	{ { "soft", "hangup", NULL },
 	handle_softhangup, "Request a hangup on a given channel",
 	softhangup_help, complete_ch_3 },
+	
+	{ {"core", "history", NULL },
+	  ast_cli_display_history,NULL},
 };
 
 /*! \brief initialize the _full_cmd string in * each of the builtins. */



More information about the asterisk-commits mailing list