mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-02-08 08:51:50 +00:00
make help an api command, still need to add syntax and descriptions to the db so we can output those as well.
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3002 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
c822f94125
commit
e9af9e02fe
@ -384,6 +384,7 @@ struct holder {
|
|||||||
switch_stream_handle_t *stream;
|
switch_stream_handle_t *stream;
|
||||||
char *http;
|
char *http;
|
||||||
uint32_t count;
|
uint32_t count;
|
||||||
|
int print_title;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int show_callback(void *pArg, int argc, char **argv, char **columnNames){
|
static int show_callback(void *pArg, int argc, char **argv, char **columnNames){
|
||||||
@ -391,7 +392,7 @@ static int show_callback(void *pArg, int argc, char **argv, char **columnNames){
|
|||||||
int x;
|
int x;
|
||||||
|
|
||||||
|
|
||||||
if (holder->count == 0) {
|
if (holder->print_title && holder->count == 0) {
|
||||||
if (holder->http) {
|
if (holder->http) {
|
||||||
holder->stream->write_function(holder->stream, "\n<tr>");
|
holder->stream->write_function(holder->stream, "\n<tr>");
|
||||||
}
|
}
|
||||||
@ -432,6 +433,7 @@ static switch_status_t show_function(char *cmd, switch_core_session_t *session,
|
|||||||
char *errmsg;
|
char *errmsg;
|
||||||
switch_core_db_t *db = switch_core_db_handle();
|
switch_core_db_t *db = switch_core_db_handle();
|
||||||
struct holder holder = {0};
|
struct holder holder = {0};
|
||||||
|
int help = 0;
|
||||||
|
|
||||||
if (session) {
|
if (session) {
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
@ -441,6 +443,8 @@ static switch_status_t show_function(char *cmd, switch_core_session_t *session,
|
|||||||
holder.http = switch_event_get_header(stream->event, "http-host");
|
holder.http = switch_event_get_header(stream->event, "http-host");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
holder.print_title = 1;
|
||||||
|
|
||||||
if (!cmd) {
|
if (!cmd) {
|
||||||
sprintf (sql, "select * from interfaces");
|
sprintf (sql, "select * from interfaces");
|
||||||
}
|
}
|
||||||
@ -456,6 +460,17 @@ static switch_status_t show_function(char *cmd, switch_core_session_t *session,
|
|||||||
else if ( !strcmp(cmd,"channels")) {
|
else if ( !strcmp(cmd,"channels")) {
|
||||||
sprintf (sql, "select * from 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 {
|
else {
|
||||||
stream->write_function(stream, "USAGE: %s\n", show_api_interface.syntax);
|
stream->write_function(stream, "USAGE: %s\n", show_api_interface.syntax);
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
@ -474,11 +489,13 @@ static switch_status_t show_function(char *cmd, switch_core_session_t *session,
|
|||||||
holder.stream->write_function(holder.stream, "</table>");
|
holder.stream->write_function(holder.stream, "</table>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (errmsg) {
|
if (errmsg) {
|
||||||
stream->write_function(stream, "SQL ERR [%s]\n",errmsg);
|
stream->write_function(stream, "SQL ERR [%s]\n",errmsg);
|
||||||
switch_core_db_free(errmsg);
|
switch_core_db_free(errmsg);
|
||||||
errmsg = NULL;
|
errmsg = NULL;
|
||||||
|
} else if (help) {
|
||||||
|
if (holder.count == 0)
|
||||||
|
stream->write_function(stream, "No such command.\n");
|
||||||
} else {
|
} else {
|
||||||
stream->write_function(stream, "\n%u total.\n", holder.count);
|
stream->write_function(stream, "\n%u total.\n", holder.count);
|
||||||
}
|
}
|
||||||
@ -487,14 +504,39 @@ static switch_status_t show_function(char *cmd, switch_core_session_t *session,
|
|||||||
return SWITCH_STATUS_SUCCESS;
|
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 = {
|
static switch_api_interface_t ctl_api_interface = {
|
||||||
/*.interface_name */ "fsctl",
|
/*.interface_name */ "fsctl",
|
||||||
/*.desc */ "control messages",
|
/*.desc */ "control messages",
|
||||||
/*.function */ ctl_function,
|
/*.function */ ctl_function,
|
||||||
/*.syntax */ "fsctl [hupall|pause|resume|shutdown]",
|
/*.syntax */ "fsctl [hupall|pause|resume|shutdown]",
|
||||||
/*.next */
|
/*.next */ &help_api_interface
|
||||||
};
|
};
|
||||||
|
|
||||||
static switch_api_interface_t uuid_bridge_api_interface = {
|
static switch_api_interface_t uuid_bridge_api_interface = {
|
||||||
|
@ -112,14 +112,6 @@ static int switch_console_process(char *cmd)
|
|||||||
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CONSOLE, "FreeSwitch Version %s\n", SWITCH_VERSION_FULL);
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CONSOLE, "FreeSwitch Version %s\n", SWITCH_VERSION_FULL);
|
||||||
return 1;
|
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 ) {
|
if ((arg = strchr(cmd, '\r')) != 0 || (arg = strchr(cmd, '\n')) != 0 ) {
|
||||||
*arg = '\0';
|
*arg = '\0';
|
||||||
arg = NULL;
|
arg = NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user