add ;; delim to console

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16166 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2010-01-06 02:54:36 +00:00
parent 13c414ea25
commit 135360ba58

View File

@ -295,18 +295,43 @@ char *expand_alias(char *cmd, char *arg)
return exp; return exp;
} }
static int switch_console_process(char *cmd, int rec) static int switch_console_process(char *xcmd, int rec)
{ {
char *arg = NULL, *alias = NULL; char *arg = NULL, *alias = NULL;
switch_stream_handle_t stream = { 0 }; switch_stream_handle_t stream = { 0 };
char *delim = ";;";
FILE *handle = switch_core_get_console();
int argc;
char *argv[128];
int x;
char *dup = strdup(xcmd);
char *cmd;
int r = 1;
if (rec > 100) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Too much recursion!\n");
goto end;
}
if (!strncasecmp(xcmd, "alias", 5)) {
argc = 1;
argv[0] = xcmd;
} else {
argc = switch_separate_string_string(dup, delim, argv, 128);
}
for (x = 0; x < argc; x++) {
cmd = argv[x];
if (!strcmp(cmd, "shutdown") || !strcmp(cmd, "...")) { if (!strcmp(cmd, "shutdown") || !strcmp(cmd, "...")) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Bye!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Bye!\n");
return 0; r = 0;
goto end;
} }
if (!strcmp(cmd, "version")) { if (!strcmp(cmd, "version")) {
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; r = 1;
goto end;
} }
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';
@ -316,15 +341,15 @@ static int switch_console_process(char *cmd, int rec)
*arg++ = '\0'; *arg++ = '\0';
} }
if (!rec && (alias = expand_alias(cmd, arg)) && alias != cmd) { if ((alias = expand_alias(cmd, arg)) && alias != cmd) {
int r = switch_console_process(alias, ++rec); switch_console_process(alias, ++rec);
free(alias); free(alias);
return r; continue;
} }
SWITCH_STANDARD_STREAM(stream); SWITCH_STANDARD_STREAM(stream);
if (stream.data) { switch_assert(stream.data);
FILE *handle = switch_core_get_console();
if (switch_api_execute(cmd, arg, NULL, &stream) == SWITCH_STATUS_SUCCESS) { if (switch_api_execute(cmd, arg, NULL, &stream) == SWITCH_STATUS_SUCCESS) {
if (handle) { if (handle) {
@ -337,12 +362,16 @@ static int switch_console_process(char *cmd, int rec)
fflush(handle); fflush(handle);
} }
} }
free(stream.data); free(stream.data);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
} }
return 1; end:
switch_safe_free(dup);
return r;
} }
SWITCH_DECLARE(void) switch_console_printf(switch_text_channel_t channel, const char *file, const char *func, int line, const char *fmt, ...) SWITCH_DECLARE(void) switch_console_printf(switch_text_channel_t channel, const char *file, const char *func, int line, const char *fmt, ...)