[Freeswitch-svn] [commit] r3002 - in freeswitch/trunk/src: . mod/applications/mod_commands

Freeswitch SVN mikej at freeswitch.org
Sun Oct 8 04:09:58 EDT 2006


Author: mikej
Date: Sun Oct  8 04:09:57 2006
New Revision: 3002

Modified:
   freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
   freeswitch/trunk/src/switch_console.c

Log:
make help an api command, still need to add syntax and descriptions to the db so we can output those as well.

Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	Sun Oct  8 04:09:57 2006
@@ -384,6 +384,7 @@
 	switch_stream_handle_t *stream;
 	char *http;
 	uint32_t count;
+	int print_title;
 };
 
 static int show_callback(void *pArg, int argc, char **argv, char **columnNames){
@@ -391,7 +392,7 @@
 	int x;
 
 
-	if (holder->count == 0) {
+	if (holder->print_title && holder->count == 0) {
 		if (holder->http) {
 			holder->stream->write_function(holder->stream, "\n<tr>");
 		}
@@ -432,6 +433,7 @@
 	char *errmsg;
 	switch_core_db_t *db = switch_core_db_handle();
 	struct holder holder = {0};
+	int help = 0;
 
 	if (session) {
 		return SWITCH_STATUS_FALSE;
@@ -441,6 +443,8 @@
         holder.http = switch_event_get_header(stream->event, "http-host");
     } 
 
+	holder.print_title = 1;
+
     if (!cmd) {
         sprintf (sql, "select * from interfaces");
     }
@@ -456,6 +460,17 @@
     else if ( !strcmp(cmd,"channels")) {
         sprintf (sql, "select * from channels");
     }
+    else if (!strncasecmp(cmd, "help", 4)) {
+		char *cmdname = NULL;
+		help = 1;
+		holder.print_title = 0;
+		if ((cmdname = strchr(cmd, ' ')) != 0) {
+			*cmdname++ = '\0';
+	        sprintf (sql, "select name from interfaces where type = 'api' and name = '%s'", cmdname);
+		} else {
+	        sprintf (sql, "select name from interfaces where type = 'api'");
+		}
+    }
     else {
 		stream->write_function(stream, "USAGE: %s\n", show_api_interface.syntax);
         return SWITCH_STATUS_SUCCESS;
@@ -474,11 +489,13 @@
 		holder.stream->write_function(holder.stream, "</table>");
 	}
 
-
 	if (errmsg) {
 		stream->write_function(stream, "SQL ERR [%s]\n",errmsg);
 		switch_core_db_free(errmsg);
 		errmsg = NULL;
+	} else if (help) {
+		if (holder.count == 0)
+			stream->write_function(stream, "No such command.\n");
 	} else {
 		stream->write_function(stream, "\n%u total.\n", holder.count);
 	}
@@ -487,14 +504,39 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
+static switch_status_t help_function(char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream)
+{
+	char showcmd[1024];
+	int all = 0;
+	if (switch_strlen_zero(cmd)) {
+		sprintf (showcmd, "help");
+		all = 1;
+	} else {
+		sprintf (showcmd, "help %s", cmd);
+	}
 
+	if (all)
+		stream->write_function(stream, "\nValid Commands:\n\n");
+	show_function(showcmd, session, stream);
+	if (all)
+		stream->write_function(stream, "version\n" "help - umm yeah..\n" "shutdown - stop the program\n\n");
+	return SWITCH_STATUS_SUCCESS;
+}
 
+static switch_api_interface_t help_api_interface = {
+	/*.interface_name */ "help",
+	/*.desc */ "Show help for all the api commands",
+	/*.function */ help_function,
+	/*.syntax */ "help",
+	/*.next */ NULL
+};
+
 static switch_api_interface_t ctl_api_interface = {
 	/*.interface_name */ "fsctl",
 	/*.desc */ "control messages",
 	/*.function */ ctl_function,
 	/*.syntax */ "fsctl [hupall|pause|resume|shutdown]",
-	/*.next */ 
+	/*.next */ &help_api_interface
 };
 
 static switch_api_interface_t uuid_bridge_api_interface = {

Modified: freeswitch/trunk/src/switch_console.c
==============================================================================
--- freeswitch/trunk/src/switch_console.c	(original)
+++ freeswitch/trunk/src/switch_console.c	Sun Oct  8 04:09:57 2006
@@ -112,14 +112,6 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CONSOLE, "FreeSwitch Version %s\n", SWITCH_VERSION_FULL);
 		return 1;
 	}
-	if (!strcmp(cmd, "help")) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,
-							  "\n"
-							  "Valid Commands:\n\n"
-							  "version\n" "help - umm yeah..\n" "shutdown - stop the program\n\n");
-		return 1;
-	}
-
 	if ((arg = strchr(cmd, '\r')) != 0  || (arg = strchr(cmd, '\n')) != 0 )  {
 		*arg = '\0';
 		arg = NULL;



More information about the Freeswitch-svn mailing list