mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-17 17:22:21 +00:00
fs_cli: cleanup whitespace and reindent
This commit is contained in:
parent
33998df974
commit
a78ec2588a
@ -39,7 +39,7 @@ static int WARN_STOP = 0;
|
|||||||
#define KEY_INSERT 8
|
#define KEY_INSERT 8
|
||||||
#define PROMPT_OP 9
|
#define PROMPT_OP 9
|
||||||
|
|
||||||
static int console_bufferInput (char* buf, int len, char *cmd, int key);
|
static int console_bufferInput (char *buf, int len, char *cmd, int key);
|
||||||
static unsigned char esl_console_complete(const char *buffer, const char *cursor);
|
static unsigned char esl_console_complete(const char *buffer, const char *cursor);
|
||||||
#else
|
#else
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
@ -80,94 +80,46 @@ static int running = 1;
|
|||||||
static int thread_running = 0;
|
static int thread_running = 0;
|
||||||
static char *filter_uuid;
|
static char *filter_uuid;
|
||||||
|
|
||||||
|
/* If a fnkey is configured then process the command */
|
||||||
/*
|
|
||||||
* If a fnkey is configured then process the command
|
|
||||||
*/
|
|
||||||
static unsigned char console_fnkey_pressed(int i)
|
static unsigned char console_fnkey_pressed(int i)
|
||||||
{
|
{
|
||||||
const char *c;
|
const char *c;
|
||||||
|
|
||||||
assert((i > 0) && (i <= 12));
|
assert((i > 0) && (i <= 12));
|
||||||
|
|
||||||
c = global_profile->console_fnkeys[i - 1];
|
c = global_profile->console_fnkeys[i - 1];
|
||||||
|
|
||||||
/* This new line is necessary to avoid output to begin after the ">" of the CLI's prompt */
|
/* This new line is necessary to avoid output to begin after the ">" of the CLI's prompt */
|
||||||
printf("%s\n", c);
|
printf("%s\n", c);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
if (c == NULL) {
|
if (c == NULL) {
|
||||||
esl_log(ESL_LOG_ERROR, "FUNCTION KEY F%d IS NOT BOUND, please edit your config.\n", i);
|
esl_log(ESL_LOG_ERROR, "FUNCTION KEY F%d IS NOT BOUND, please edit your config.\n", i);
|
||||||
return CC_REDISPLAY;
|
return CC_REDISPLAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process_command(global_handle, c)) {
|
if (process_command(global_handle, c)) {
|
||||||
running = thread_running = 0;
|
running = thread_running = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CC_REDISPLAY;
|
return CC_REDISPLAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_EDITLINE
|
#ifdef HAVE_EDITLINE
|
||||||
static char *prompt(EditLine * e)
|
static char *prompt(EditLine *e) { return prompt_str; }
|
||||||
{
|
|
||||||
return prompt_str;
|
|
||||||
}
|
|
||||||
|
|
||||||
static EditLine *el;
|
static EditLine *el;
|
||||||
static History *myhistory;
|
static History *myhistory;
|
||||||
static HistEvent ev;
|
static HistEvent ev;
|
||||||
|
|
||||||
static unsigned char console_f1key(EditLine * el, int ch)
|
static unsigned char console_f1key(EditLine *el, int ch) { return console_fnkey_pressed(1); }
|
||||||
{
|
static unsigned char console_f2key(EditLine *el, int ch) { return console_fnkey_pressed(2); }
|
||||||
return console_fnkey_pressed(1);
|
static unsigned char console_f3key(EditLine *el, int ch) { return console_fnkey_pressed(3); }
|
||||||
}
|
static unsigned char console_f4key(EditLine *el, int ch) { return console_fnkey_pressed(4); }
|
||||||
static unsigned char console_f2key(EditLine * el, int ch)
|
static unsigned char console_f5key(EditLine *el, int ch) { return console_fnkey_pressed(5); }
|
||||||
{
|
static unsigned char console_f6key(EditLine *el, int ch) { return console_fnkey_pressed(6); }
|
||||||
return console_fnkey_pressed(2);
|
static unsigned char console_f7key(EditLine *el, int ch) { return console_fnkey_pressed(7); }
|
||||||
}
|
static unsigned char console_f8key(EditLine *el, int ch) { return console_fnkey_pressed(8); }
|
||||||
static unsigned char console_f3key(EditLine * el, int ch)
|
static unsigned char console_f9key(EditLine *el, int ch) { return console_fnkey_pressed(9); }
|
||||||
{
|
static unsigned char console_f10key(EditLine *el, int ch) { return console_fnkey_pressed(10); }
|
||||||
return console_fnkey_pressed(3);
|
static unsigned char console_f11key(EditLine *el, int ch) { return console_fnkey_pressed(11); }
|
||||||
}
|
static unsigned char console_f12key(EditLine *el, int ch) { return console_fnkey_pressed(12); }
|
||||||
static unsigned char console_f4key(EditLine * el, int ch)
|
|
||||||
{
|
|
||||||
return console_fnkey_pressed(4);
|
|
||||||
}
|
|
||||||
static unsigned char console_f5key(EditLine * el, int ch)
|
|
||||||
{
|
|
||||||
return console_fnkey_pressed(5);
|
|
||||||
}
|
|
||||||
static unsigned char console_f6key(EditLine * el, int ch)
|
|
||||||
{
|
|
||||||
return console_fnkey_pressed(6);
|
|
||||||
}
|
|
||||||
static unsigned char console_f7key(EditLine * el, int ch)
|
|
||||||
{
|
|
||||||
return console_fnkey_pressed(7);
|
|
||||||
}
|
|
||||||
static unsigned char console_f8key(EditLine * el, int ch)
|
|
||||||
{
|
|
||||||
return console_fnkey_pressed(8);
|
|
||||||
}
|
|
||||||
static unsigned char console_f9key(EditLine * el, int ch)
|
|
||||||
{
|
|
||||||
return console_fnkey_pressed(9);
|
|
||||||
}
|
|
||||||
static unsigned char console_f10key(EditLine * el, int ch)
|
|
||||||
{
|
|
||||||
return console_fnkey_pressed(10);
|
|
||||||
}
|
|
||||||
static unsigned char console_f11key(EditLine * el, int ch)
|
|
||||||
{
|
|
||||||
return console_fnkey_pressed(11);
|
|
||||||
}
|
|
||||||
static unsigned char console_f12key(EditLine * el, int ch)
|
|
||||||
{
|
|
||||||
return console_fnkey_pressed(12);
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned char console_eofkey(EditLine * el, int ch)
|
static unsigned char console_eofkey(EditLine *el, int ch)
|
||||||
{
|
{
|
||||||
LineInfo *line;
|
LineInfo *line;
|
||||||
/* only exit if empty line */
|
/* only exit if empty line */
|
||||||
@ -194,7 +146,6 @@ static int console_history (char *cmd, int direction)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
static int first;
|
static int first;
|
||||||
|
|
||||||
if (direction == 0) {
|
if (direction == 0) {
|
||||||
first = 1;
|
first = 1;
|
||||||
if (iHistory < HISTLEN) {
|
if (iHistory < HISTLEN) {
|
||||||
@ -209,8 +160,7 @@ static int console_history (char *cmd, int direction)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
iHistory = HISTLEN-1;
|
iHistory = HISTLEN-1;
|
||||||
for (i = 0; i < HISTLEN-1; i++)
|
for (i = 0; i < HISTLEN-1; i++) {
|
||||||
{
|
|
||||||
strcpy(history[i], history[i+1]);
|
strcpy(history[i], history[i+1]);
|
||||||
}
|
}
|
||||||
iHistorySel = iHistory;
|
iHistorySel = iHistory;
|
||||||
@ -233,7 +183,7 @@ static int console_history (char *cmd, int direction)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int console_bufferInput (char* addchars, int len, char *cmd, int key)
|
static int console_bufferInput (char *addchars, int len, char *cmd, int key)
|
||||||
{
|
{
|
||||||
static int iCmdBuffer = 0;
|
static int iCmdBuffer = 0;
|
||||||
static int iCmdCursor = 0;
|
static int iCmdCursor = 0;
|
||||||
@ -243,7 +193,6 @@ static int console_bufferInput (char* addchars, int len, char *cmd, int key)
|
|||||||
static char prompt [80];
|
static char prompt [80];
|
||||||
int iBuf;
|
int iBuf;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
HANDLE hOut;
|
HANDLE hOut;
|
||||||
CONSOLE_SCREEN_BUFFER_INFO info;
|
CONSOLE_SCREEN_BUFFER_INFO info;
|
||||||
COORD position;
|
COORD position;
|
||||||
@ -253,14 +202,12 @@ static int console_bufferInput (char* addchars, int len, char *cmd, int key)
|
|||||||
if (iCmdCursor == 0) {
|
if (iCmdCursor == 0) {
|
||||||
orgPosition = position;
|
orgPosition = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key == PROMPT_OP) {
|
if (key == PROMPT_OP) {
|
||||||
if (strlen(cmd) < sizeof(prompt)) {
|
if (strlen(cmd) < sizeof(prompt)) {
|
||||||
strcpy(prompt, cmd);
|
strcpy(prompt, cmd);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key == KEY_TAB) {
|
if (key == KEY_TAB) {
|
||||||
esl_console_complete(cmd, cmd+iCmdBuffer);
|
esl_console_complete(cmd, cmd+iCmdBuffer);
|
||||||
return 0;
|
return 0;
|
||||||
@ -287,7 +234,6 @@ static int console_bufferInput (char* addchars, int len, char *cmd, int key)
|
|||||||
printf("%s", cmd);
|
printf("%s", cmd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key == KEY_LEFT) {
|
if (key == KEY_LEFT) {
|
||||||
if (iCmdCursor) {
|
if (iCmdCursor) {
|
||||||
if (position.X == 0) {
|
if (position.X == 0) {
|
||||||
@ -297,7 +243,6 @@ static int console_bufferInput (char* addchars, int len, char *cmd, int key)
|
|||||||
else {
|
else {
|
||||||
position.X -= 1;
|
position.X -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetConsoleCursorPosition(hOut, position);
|
SetConsoleCursorPosition(hOut, position);
|
||||||
iCmdCursor--;
|
iCmdCursor--;
|
||||||
}
|
}
|
||||||
@ -311,7 +256,6 @@ static int console_bufferInput (char* addchars, int len, char *cmd, int key)
|
|||||||
else {
|
else {
|
||||||
position.X += 1;
|
position.X += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetConsoleCursorPosition(hOut, position);
|
SetConsoleCursorPosition(hOut, position);
|
||||||
iCmdCursor++;
|
iCmdCursor++;
|
||||||
}
|
}
|
||||||
@ -362,7 +306,6 @@ static int console_bufferInput (char* addchars, int len, char *cmd, int key)
|
|||||||
}
|
}
|
||||||
cmd[pos] = 0;
|
cmd[pos] = 0;
|
||||||
iCmdBuffer--;
|
iCmdBuffer--;
|
||||||
|
|
||||||
SetConsoleCursorPosition(hOut, position);
|
SetConsoleCursorPosition(hOut, position);
|
||||||
for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
|
for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
|
||||||
printf("%c", cmd[pos]);
|
printf("%c", cmd[pos]);
|
||||||
@ -382,7 +325,6 @@ static int console_bufferInput (char* addchars, int len, char *cmd, int key)
|
|||||||
if (!ignoreNext) {
|
if (!ignoreNext) {
|
||||||
if (iCmdCursor < iCmdBuffer) {
|
if (iCmdCursor < iCmdBuffer) {
|
||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
if (position.X == info.dwSize.X-1) {
|
if (position.X == info.dwSize.X-1) {
|
||||||
position.Y += 1;
|
position.Y += 1;
|
||||||
position.X = 0;
|
position.X = 0;
|
||||||
@ -390,7 +332,6 @@ static int console_bufferInput (char* addchars, int len, char *cmd, int key)
|
|||||||
else {
|
else {
|
||||||
position.X += 1;
|
position.X += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (insertMode) {
|
if (insertMode) {
|
||||||
for (pos = iCmdBuffer-1; pos >= iCmdCursor; pos--) {
|
for (pos = iCmdBuffer-1; pos >= iCmdCursor; pos--) {
|
||||||
cmd[pos+1] = cmd[pos];
|
cmd[pos+1] = cmd[pos];
|
||||||
@ -428,12 +369,10 @@ static int console_bufferInput (char* addchars, int len, char *cmd, int key)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static BOOL console_readConsole(HANDLE conIn, char *buf, int len, int *pRed, int *key)
|
||||||
static BOOL console_readConsole(HANDLE conIn, char* buf, int len, int* pRed, int *key)
|
|
||||||
{
|
{
|
||||||
DWORD recordIndex, bufferIndex, toRead, red;
|
DWORD recordIndex, bufferIndex, toRead, red;
|
||||||
PINPUT_RECORD pInput;
|
PINPUT_RECORD pInput;
|
||||||
|
|
||||||
GetNumberOfConsoleInputEvents(conIn, &toRead);
|
GetNumberOfConsoleInputEvents(conIn, &toRead);
|
||||||
if (len < (int)toRead) {
|
if (len < (int)toRead) {
|
||||||
toRead = len;
|
toRead = len;
|
||||||
@ -441,13 +380,11 @@ static BOOL console_readConsole(HANDLE conIn, char* buf, int len, int* pRed, int
|
|||||||
if (toRead == 0) {
|
if (toRead == 0) {
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pInput = (PINPUT_RECORD) malloc(toRead * sizeof(INPUT_RECORD))) == NULL) {
|
if ((pInput = (PINPUT_RECORD) malloc(toRead * sizeof(INPUT_RECORD))) == NULL) {
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
*key = 0;
|
*key = 0;
|
||||||
ReadConsoleInput(conIn, pInput, toRead, &red);
|
ReadConsoleInput(conIn, pInput, toRead, &red);
|
||||||
|
|
||||||
for (recordIndex = bufferIndex = 0; recordIndex < red; recordIndex++) {
|
for (recordIndex = bufferIndex = 0; recordIndex < red; recordIndex++) {
|
||||||
KEY_EVENT_RECORD keyEvent = pInput[recordIndex].Event.KeyEvent;
|
KEY_EVENT_RECORD keyEvent = pInput[recordIndex].Event.KeyEvent;
|
||||||
if (pInput[recordIndex].EventType == KEY_EVENT && keyEvent.bKeyDown) {
|
if (pInput[recordIndex].EventType == KEY_EVENT && keyEvent.bKeyDown) {
|
||||||
@ -526,7 +463,6 @@ static BOOL console_readConsole(HANDLE conIn, char* buf, int len, int* pRed, int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(pInput);
|
free(pInput);
|
||||||
*pRed = bufferIndex;
|
*pRed = bufferIndex;
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
@ -537,14 +473,11 @@ static BOOL console_readConsole(HANDLE conIn, char* buf, int len, int* pRed, int
|
|||||||
static void handle_SIGINT(int sig)
|
static void handle_SIGINT(int sig)
|
||||||
{
|
{
|
||||||
if (sig);
|
if (sig);
|
||||||
|
|
||||||
if (!CONNECTED) {
|
if (!CONNECTED) {
|
||||||
fprintf(stdout, "Interrupted.\n");
|
fprintf(stdout, "Interrupted.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
WARN_STOP = 1;
|
WARN_STOP = 1;
|
||||||
|
|
||||||
signal(SIGINT, handle_SIGINT);
|
signal(SIGINT, handle_SIGINT);
|
||||||
#ifdef SIGTSTP
|
#ifdef SIGTSTP
|
||||||
signal(SIGTSTP, handle_SIGINT);
|
signal(SIGTSTP, handle_SIGINT);
|
||||||
@ -562,15 +495,14 @@ static void handle_SIGQUIT(int sig)
|
|||||||
static HANDLE hStdout;
|
static HANDLE hStdout;
|
||||||
static WORD wOldColorAttrs;
|
static WORD wOldColorAttrs;
|
||||||
static CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
|
static CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
|
||||||
|
|
||||||
static WORD
|
static WORD
|
||||||
#else
|
#else
|
||||||
static const char*
|
static const char*
|
||||||
#endif
|
#endif
|
||||||
COLORS[] = { ESL_SEQ_DEFAULT_COLOR, ESL_SEQ_FRED, ESL_SEQ_FRED,
|
COLORS[] = { ESL_SEQ_DEFAULT_COLOR, ESL_SEQ_FRED, ESL_SEQ_FRED, ESL_SEQ_FRED,
|
||||||
ESL_SEQ_FRED, ESL_SEQ_FMAGEN, ESL_SEQ_FCYAN, ESL_SEQ_FGREEN, ESL_SEQ_FYELLOW };
|
ESL_SEQ_FMAGEN, ESL_SEQ_FCYAN, ESL_SEQ_FGREEN, ESL_SEQ_FYELLOW };
|
||||||
|
|
||||||
static int usage(char *name){
|
static int usage(char *name) {
|
||||||
printf("Usage: %s [-H <host>] [-P <port>] [-p <secret>] [-d <level>] [-x command] [-t <timeout_ms>] [profile]\n\n", name);
|
printf("Usage: %s [-H <host>] [-P <port>] [-p <secret>] [-d <level>] [-x command] [-t <timeout_ms>] [profile]\n\n", name);
|
||||||
printf(" -?,-h --help Usage Information\n");
|
printf(" -?,-h --help Usage Information\n");
|
||||||
printf(" -H, --host=hostname Host to connect\n");
|
printf(" -H, --host=hostname Host to connect\n");
|
||||||
@ -590,15 +522,11 @@ static int usage(char *name){
|
|||||||
|
|
||||||
static void *msg_thread_run(esl_thread_t *me, void *obj)
|
static void *msg_thread_run(esl_thread_t *me, void *obj)
|
||||||
{
|
{
|
||||||
|
|
||||||
esl_handle_t *handle = (esl_handle_t *) obj;
|
esl_handle_t *handle = (esl_handle_t *) obj;
|
||||||
|
|
||||||
thread_running = 1;
|
thread_running = 1;
|
||||||
|
|
||||||
while(thread_running && handle->connected) {
|
while(thread_running && handle->connected) {
|
||||||
esl_status_t status = esl_recv_event_timed(handle, 10, 1, NULL);
|
esl_status_t status = esl_recv_event_timed(handle, 10, 1, NULL);
|
||||||
int aok = 1;
|
int aok = 1;
|
||||||
|
|
||||||
if (status == ESL_FAIL) {
|
if (status == ESL_FAIL) {
|
||||||
if (aok) esl_log(ESL_LOG_WARNING, "Disconnected.\n");
|
if (aok) esl_log(ESL_LOG_WARNING, "Disconnected.\n");
|
||||||
running = -1; thread_running = 0;
|
running = -1; thread_running = 0;
|
||||||
@ -607,7 +535,6 @@ static void *msg_thread_run(esl_thread_t *me, void *obj)
|
|||||||
fd_set can_write;
|
fd_set can_write;
|
||||||
int fd;
|
int fd;
|
||||||
struct timeval to;
|
struct timeval to;
|
||||||
|
|
||||||
fd = fileno(stdout);
|
fd = fileno(stdout);
|
||||||
memset(&to, 0, sizeof(to));
|
memset(&to, 0, sizeof(to));
|
||||||
FD_ZERO(&can_write);
|
FD_ZERO(&can_write);
|
||||||
@ -620,34 +547,29 @@ static void *msg_thread_run(esl_thread_t *me, void *obj)
|
|||||||
aok = 0;
|
aok = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (handle->last_event) {
|
if (handle->last_event) {
|
||||||
const char *type = esl_event_get_header(handle->last_event, "content-type");
|
const char *type = esl_event_get_header(handle->last_event, "content-type");
|
||||||
int known = 0;
|
int known = 0;
|
||||||
|
|
||||||
if (!esl_strlen_zero(type)) {
|
if (!esl_strlen_zero(type)) {
|
||||||
if (aok && !strcasecmp(type, "log/data")) {
|
if (aok && !strcasecmp(type, "log/data")) {
|
||||||
const char *userdata = esl_event_get_header(handle->last_event, "user-data");
|
const char *userdata = esl_event_get_header(handle->last_event, "user-data");
|
||||||
|
|
||||||
if (esl_strlen_zero(userdata) || esl_strlen_zero(filter_uuid) || !strcasecmp(filter_uuid, userdata)) {
|
if (esl_strlen_zero(userdata) || esl_strlen_zero(filter_uuid) || !strcasecmp(filter_uuid, userdata)) {
|
||||||
int level = 0;
|
int level = 0;
|
||||||
const char *lname = esl_event_get_header(handle->last_event, "log-level");
|
const char *lname = esl_event_get_header(handle->last_event, "log-level");
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
DWORD len = (DWORD) strlen(handle->last_event->body);
|
DWORD len = (DWORD) strlen(handle->last_event->body);
|
||||||
DWORD outbytes = 0;
|
DWORD outbytes = 0;
|
||||||
#endif
|
#endif
|
||||||
if (lname) {
|
if (lname) {
|
||||||
level = atoi(lname);
|
level = atoi(lname);
|
||||||
}
|
}
|
||||||
|
#ifdef WIN32
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
SetConsoleTextAttribute(hStdout, COLORS[level]);
|
SetConsoleTextAttribute(hStdout, COLORS[level]);
|
||||||
WriteFile(hStdout, handle->last_event->body, len, &outbytes, NULL);
|
WriteFile(hStdout, handle->last_event->body, len, &outbytes, NULL);
|
||||||
SetConsoleTextAttribute(hStdout, wOldColorAttrs);
|
SetConsoleTextAttribute(hStdout, wOldColorAttrs);
|
||||||
#else
|
#else
|
||||||
printf("%s%s%s", COLORS[level], handle->last_event->body, ESL_SEQ_DEFAULT_COLOR);
|
printf("%s%s%s", COLORS[level], handle->last_event->body, ESL_SEQ_DEFAULT_COLOR);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
known++;
|
known++;
|
||||||
} else if (!strcasecmp(type, "text/disconnect-notice")) {
|
} else if (!strcasecmp(type, "text/disconnect-notice")) {
|
||||||
@ -658,11 +580,9 @@ static void *msg_thread_run(esl_thread_t *me, void *obj)
|
|||||||
esl_event_serialize(handle->last_ievent, &foo, ESL_FALSE);
|
esl_event_serialize(handle->last_ievent, &foo, ESL_FALSE);
|
||||||
printf("RECV EVENT\n%s\n", foo);
|
printf("RECV EVENT\n%s\n", foo);
|
||||||
free(foo);
|
free(foo);
|
||||||
|
|
||||||
known++;
|
known++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aok && !known) {
|
if (aok && !known) {
|
||||||
char *foo;
|
char *foo;
|
||||||
printf("INCOMING DATA [%s]\n%s\n", type, handle->last_event->body ? handle->last_event->body : "");
|
printf("INCOMING DATA [%s]\n%s\n", type, handle->last_event->body ? handle->last_event->body : "");
|
||||||
@ -672,25 +592,20 @@ static void *msg_thread_run(esl_thread_t *me, void *obj)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WARN_STOP) {
|
if (WARN_STOP) {
|
||||||
if (aok) printf("Type control-D or /exit or /quit or /bye to exit.\n\n");
|
if (aok) printf("Type control-D or /exit or /quit or /bye to exit.\n\n");
|
||||||
WARN_STOP = 0;
|
WARN_STOP = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_running = 0;
|
thread_running = 0;
|
||||||
esl_log(ESL_LOG_DEBUG, "Thread Done\n");
|
esl_log(ESL_LOG_DEBUG, "Thread Done\n");
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int process_command(esl_handle_t *handle, const char *cmd)
|
static int process_command(esl_handle_t *handle, const char *cmd)
|
||||||
{
|
{
|
||||||
if ((*cmd == '/' && cmd++) || !strncasecmp(cmd, "...", 3)) {
|
if ((*cmd == '/' && cmd++) || !strncasecmp(cmd, "...", 3)) {
|
||||||
|
|
||||||
if (!strcasecmp(cmd, "help")) {
|
if (!strcasecmp(cmd, "help")) {
|
||||||
printf(
|
printf(
|
||||||
"Command \tDescription\n"
|
"Command \tDescription\n"
|
||||||
@ -704,12 +619,9 @@ static int process_command(esl_handle_t *handle, const char *cmd)
|
|||||||
"/debug [0-7] \tSet debug level.\n"
|
"/debug [0-7] \tSet debug level.\n"
|
||||||
"\n"
|
"\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
if (!strcasecmp(cmd, "exit") ||
|
||||||
if (
|
|
||||||
!strcasecmp(cmd, "exit") ||
|
|
||||||
!strcasecmp(cmd, "quit") ||
|
!strcasecmp(cmd, "quit") ||
|
||||||
!strcasecmp(cmd, "...") ||
|
!strcasecmp(cmd, "...") ||
|
||||||
!strcasecmp(cmd, "bye")
|
!strcasecmp(cmd, "bye")
|
||||||
@ -718,34 +630,27 @@ static int process_command(esl_handle_t *handle, const char *cmd)
|
|||||||
return -1;
|
return -1;
|
||||||
} else if (!strncasecmp(cmd, "uuid", 4)) {
|
} else if (!strncasecmp(cmd, "uuid", 4)) {
|
||||||
cmd += 4;
|
cmd += 4;
|
||||||
|
|
||||||
while (*cmd && *cmd == ' ') {
|
while (*cmd && *cmd == ' ') {
|
||||||
cmd++;
|
cmd++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!esl_strlen_zero(cmd)) {
|
if (!esl_strlen_zero(cmd)) {
|
||||||
filter_uuid = strdup(cmd);
|
filter_uuid = strdup(cmd);
|
||||||
} else {
|
} else {
|
||||||
esl_safe_free(filter_uuid);
|
esl_safe_free(filter_uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("UUID filtering %s\n", filter_uuid ? "enabled" : "disabled");
|
printf("UUID filtering %s\n", filter_uuid ? "enabled" : "disabled");
|
||||||
|
} else if (!strncasecmp(cmd, "event", 5) ||
|
||||||
} else if (
|
|
||||||
!strncasecmp(cmd, "event", 5) ||
|
|
||||||
!strncasecmp(cmd, "noevents", 8) ||
|
!strncasecmp(cmd, "noevents", 8) ||
|
||||||
!strncasecmp(cmd, "nixevent", 8) ||
|
!strncasecmp(cmd, "nixevent", 8) ||
|
||||||
!strncasecmp(cmd, "log", 3) ||
|
!strncasecmp(cmd, "log", 3) ||
|
||||||
!strncasecmp(cmd, "nolog", 5) ||
|
!strncasecmp(cmd, "nolog", 5) ||
|
||||||
!strncasecmp(cmd, "filter", 6)
|
!strncasecmp(cmd, "filter", 6)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
esl_send_recv(handle, cmd);
|
esl_send_recv(handle, cmd);
|
||||||
|
|
||||||
printf("%s\n", handle->last_sr_reply);
|
printf("%s\n", handle->last_sr_reply);
|
||||||
} else if (!strncasecmp(cmd, "debug", 5)){
|
} else if (!strncasecmp(cmd, "debug", 5)) {
|
||||||
int tmp_debug = atoi(cmd+6);
|
int tmp_debug = atoi(cmd+6);
|
||||||
if (tmp_debug > -1 && tmp_debug < 8){
|
if (tmp_debug > -1 && tmp_debug < 8) {
|
||||||
esl_global_set_default_logger(tmp_debug);
|
esl_global_set_default_logger(tmp_debug);
|
||||||
printf("fs_cli debug level set to %d\n", tmp_debug);
|
printf("fs_cli debug level set to %d\n", tmp_debug);
|
||||||
} else {
|
} else {
|
||||||
@ -757,7 +662,6 @@ static int process_command(esl_handle_t *handle, const char *cmd)
|
|||||||
} else {
|
} else {
|
||||||
char cmd_str[1024] = "";
|
char cmd_str[1024] = "";
|
||||||
const char *err = NULL;
|
const char *err = NULL;
|
||||||
|
|
||||||
snprintf(cmd_str, sizeof(cmd_str), "api %s\nconsole_execute: true\n\n", cmd);
|
snprintf(cmd_str, sizeof(cmd_str), "api %s\nconsole_execute: true\n\n", cmd);
|
||||||
if (esl_send_recv(handle, cmd_str)) {
|
if (esl_send_recv(handle, cmd_str)) {
|
||||||
printf("Socket interrupted, bye!\n");
|
printf("Socket interrupted, bye!\n");
|
||||||
@ -771,24 +675,19 @@ static int process_command(esl_handle_t *handle, const char *cmd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_profile(const char *name, cli_profile_t **profile)
|
static int get_profile(const char *name, cli_profile_t **profile)
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
for (x = 0; x < pcount; x++) {
|
for (x = 0; x < pcount; x++) {
|
||||||
if (!strcmp(profiles[x].name, name)) {
|
if (!strcmp(profiles[x].name, name)) {
|
||||||
*profile = &profiles[x];
|
*profile = &profiles[x];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -799,9 +698,7 @@ static const char *basic_gets(int *cnt)
|
|||||||
{
|
{
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
int x = 0;
|
int x = 0;
|
||||||
|
|
||||||
printf("%s", prompt_str);
|
printf("%s", prompt_str);
|
||||||
|
|
||||||
memset(&command_buf, 0, sizeof(command_buf));
|
memset(&command_buf, 0, sizeof(command_buf));
|
||||||
for (x = 0; x < (sizeof(command_buf) - 1); x++) {
|
for (x = 0; x < (sizeof(command_buf) - 1); x++) {
|
||||||
int c = getchar();
|
int c = getchar();
|
||||||
@ -810,27 +707,21 @@ static const char *basic_gets(int *cnt)
|
|||||||
command_buf[y - 1] = '\0';
|
command_buf[y - 1] = '\0';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
command_buf[x] = (char) c;
|
command_buf[x] = (char) c;
|
||||||
|
|
||||||
if (command_buf[x] == '\n') {
|
if (command_buf[x] == '\n') {
|
||||||
command_buf[x] = '\0';
|
command_buf[x] = '\0';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*cnt = x;
|
*cnt = x;
|
||||||
#else
|
#else
|
||||||
int read, key;
|
int read, key;
|
||||||
char keys[CMD_BUFLEN];
|
char keys[CMD_BUFLEN];
|
||||||
HANDLE stdinHandle = GetStdHandle(STD_INPUT_HANDLE);
|
HANDLE stdinHandle = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
|
|
||||||
console_bufferInput (0, 0, prompt_str, PROMPT_OP);
|
console_bufferInput (0, 0, prompt_str, PROMPT_OP);
|
||||||
printf("%s", prompt_str);
|
printf("%s", prompt_str);
|
||||||
|
|
||||||
*cnt = 0;
|
*cnt = 0;
|
||||||
memset(&command_buf, 0, sizeof(command_buf));
|
memset(&command_buf, 0, sizeof(command_buf));
|
||||||
|
|
||||||
while (!*cnt) {
|
while (!*cnt) {
|
||||||
if (console_readConsole(stdinHandle, keys, (int)sizeof(keys), &read, &key)) {
|
if (console_readConsole(stdinHandle, keys, (int)sizeof(keys), &read, &key)) {
|
||||||
*cnt = console_bufferInput(keys, read, command_buf, key);
|
*cnt = console_bufferInput(keys, read, command_buf, key);
|
||||||
@ -841,17 +732,13 @@ static const char *basic_gets(int *cnt)
|
|||||||
Sleep(20);
|
Sleep(20);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return command_buf;
|
return command_buf;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static void print_banner(FILE *stream)
|
static void print_banner(FILE *stream)
|
||||||
{
|
{
|
||||||
fprintf(stream,
|
fprintf(stream,
|
||||||
|
|
||||||
|
|
||||||
" _____ ____ ____ _ ___ \n"
|
" _____ ____ ____ _ ___ \n"
|
||||||
" | ___/ ___| / ___| | |_ _| \n"
|
" | ___/ ___| / ___| | |_ _| \n"
|
||||||
" | |_ \\___ \\ | | | | | | \n"
|
" | |_ \\___ \\ | | | | | | \n"
|
||||||
@ -869,7 +756,6 @@ static void print_banner(FILE *stream)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void set_fn_keys(cli_profile_t *profile)
|
static void set_fn_keys(cli_profile_t *profile)
|
||||||
{
|
{
|
||||||
profile->console_fnkeys[0] = "help";
|
profile->console_fnkeys[0] = "help";
|
||||||
@ -896,72 +782,55 @@ static unsigned char esl_console_complete(const char *buffer, const char *cursor
|
|||||||
char *buf = dup;
|
char *buf = dup;
|
||||||
int pos = 0, sc = 0;
|
int pos = 0, sc = 0;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
if (!esl_strlen_zero(cursor) && !esl_strlen_zero(buffer)) {
|
if (!esl_strlen_zero(cursor) && !esl_strlen_zero(buffer)) {
|
||||||
pos = (int)(cursor - buffer);
|
pos = (int)(cursor - buffer);
|
||||||
}
|
}
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
*(buf + pos) = '\0';
|
*(buf + pos) = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((p = strchr(buf, '\r')) || (p = strchr(buf, '\n'))) {
|
if ((p = strchr(buf, '\r')) || (p = strchr(buf, '\n'))) {
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*buf == ' ') {
|
while (*buf == ' ') {
|
||||||
buf++;
|
buf++;
|
||||||
sc++;
|
sc++;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_EDITLINE
|
#ifdef HAVE_EDITLINE
|
||||||
if (!*buf && sc) {
|
if (!*buf && sc) {
|
||||||
el_deletestr(el, sc);
|
el_deletestr(el, sc);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sc = 0;
|
sc = 0;
|
||||||
|
|
||||||
p = end_of_p(buf);
|
p = end_of_p(buf);
|
||||||
while(p >= buf && *p == ' ') {
|
while(p >= buf && *p == ' ') {
|
||||||
sc++;
|
sc++;
|
||||||
p--;
|
p--;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_EDITLINE
|
#ifdef HAVE_EDITLINE
|
||||||
if (sc > 1) {
|
if (sc > 1) {
|
||||||
el_deletestr(el, sc - 1);
|
el_deletestr(el, sc - 1);
|
||||||
*(p + 2) = '\0';
|
*(p + 2) = '\0';
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
if (*cursor) {
|
if (*cursor) {
|
||||||
snprintf(cmd_str, sizeof(cmd_str), "api console_complete c=%ld;%s\n\n", (long)pos, buf);
|
snprintf(cmd_str, sizeof(cmd_str), "api console_complete c=%ld;%s\n\n", (long)pos, buf);
|
||||||
} else {
|
} else {
|
||||||
snprintf(cmd_str, sizeof(cmd_str), "api console_complete %s\n\n", buf);
|
snprintf(cmd_str, sizeof(cmd_str), "api console_complete %s\n\n", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
esl_send_recv(global_handle, cmd_str);
|
esl_send_recv(global_handle, cmd_str);
|
||||||
|
|
||||||
|
|
||||||
if (global_handle->last_sr_event && global_handle->last_sr_event->body) {
|
if (global_handle->last_sr_event && global_handle->last_sr_event->body) {
|
||||||
char *r = global_handle->last_sr_event->body;
|
char *r = global_handle->last_sr_event->body;
|
||||||
char *w, *p1;
|
char *w, *p1;
|
||||||
|
|
||||||
if (r) {
|
if (r) {
|
||||||
if ((w = strstr(r, "\n\nwrite="))) {
|
if ((w = strstr(r, "\n\nwrite="))) {
|
||||||
int len = 0;
|
int len = 0;
|
||||||
*w = '\0';
|
*w = '\0';
|
||||||
w += 8;
|
w += 8;
|
||||||
|
|
||||||
len = atoi(w);
|
len = atoi(w);
|
||||||
|
|
||||||
if ((p1= strchr(w, ':'))) {
|
if ((p1= strchr(w, ':'))) {
|
||||||
w = p1+ 1;
|
w = p1+ 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s\n\n\n", r);
|
printf("%s\n\n\n", r);
|
||||||
|
|
||||||
#ifdef HAVE_EDITLINE
|
#ifdef HAVE_EDITLINE
|
||||||
el_deletestr(el, len);
|
el_deletestr(el, len);
|
||||||
el_insertstr(el, w);
|
el_insertstr(el, w);
|
||||||
@ -971,7 +840,6 @@ static unsigned char esl_console_complete(const char *buffer, const char *cursor
|
|||||||
console_bufferInput(w, (int)strlen(w), (char*)buffer, 0);
|
console_bufferInput(w, (int)strlen(w), (char*)buffer, 0);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
printf("%s\n", r);
|
printf("%s\n", r);
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
@ -979,25 +847,20 @@ static unsigned char esl_console_complete(const char *buffer, const char *cursor
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
esl_safe_free(dup);
|
esl_safe_free(dup);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_EDITLINE
|
#ifdef HAVE_EDITLINE
|
||||||
static unsigned char complete(EditLine * el, int ch)
|
static unsigned char complete(EditLine *el, int ch)
|
||||||
{
|
{
|
||||||
const LineInfo *lf = el_line(el);
|
const LineInfo *lf = el_line(el);
|
||||||
|
|
||||||
return esl_console_complete(lf->buffer, lf->cursor);
|
return esl_console_complete(lf->buffer, lf->cursor);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
esl_handle_t handle = {{0}};
|
esl_handle_t handle = {{0}};
|
||||||
@ -1007,7 +870,6 @@ int main(int argc, char *argv[])
|
|||||||
esl_config_t cfg;
|
esl_config_t cfg;
|
||||||
cli_profile_t *profile = NULL;
|
cli_profile_t *profile = NULL;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
char hfile[512] = "/etc/fs_cli_history";
|
char hfile[512] = "/etc/fs_cli_history";
|
||||||
char cfile[512] = "/etc/fs_cli.conf";
|
char cfile[512] = "/etc/fs_cli.conf";
|
||||||
@ -1036,7 +898,6 @@ int main(int argc, char *argv[])
|
|||||||
{"timeout", 1, 0, 't'},
|
{"timeout", 1, 0, 't'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
char temp_host[128];
|
char temp_host[128];
|
||||||
int argv_host = 0;
|
int argv_host = 0;
|
||||||
char temp_user[256];
|
char temp_user[256];
|
||||||
@ -1059,13 +920,10 @@ int main(int argc, char *argv[])
|
|||||||
strncpy(internal_profile.name, "internal", sizeof(internal_profile.name));
|
strncpy(internal_profile.name, "internal", sizeof(internal_profile.name));
|
||||||
internal_profile.port = 8021;
|
internal_profile.port = 8021;
|
||||||
set_fn_keys(&internal_profile);
|
set_fn_keys(&internal_profile);
|
||||||
|
|
||||||
|
|
||||||
if (home) {
|
if (home) {
|
||||||
snprintf(hfile, sizeof(hfile), "%s/.fs_cli_history", home);
|
snprintf(hfile, sizeof(hfile), "%s/.fs_cli_history", home);
|
||||||
snprintf(cfile, sizeof(cfile), "%s/.fs_cli_conf", home);
|
snprintf(cfile, sizeof(cfile), "%s/.fs_cli_conf", home);
|
||||||
}
|
}
|
||||||
|
|
||||||
signal(SIGINT, handle_SIGINT);
|
signal(SIGINT, handle_SIGINT);
|
||||||
#ifdef SIGTSTP
|
#ifdef SIGTSTP
|
||||||
signal(SIGTSTP, handle_SIGINT);
|
signal(SIGTSTP, handle_SIGINT);
|
||||||
@ -1074,20 +932,18 @@ int main(int argc, char *argv[])
|
|||||||
signal(SIGQUIT, handle_SIGQUIT);
|
signal(SIGQUIT, handle_SIGQUIT);
|
||||||
#endif
|
#endif
|
||||||
esl_global_set_default_logger(6); /* default debug level to 6 (info) */
|
esl_global_set_default_logger(6); /* default debug level to 6 (info) */
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
opt = getopt_long(argc, argv, "H:U:P:S:u:p:d:x:l:t:qrRhi?", options, &option_index);
|
opt = getopt_long(argc, argv, "H:U:P:S:u:p:d:x:l:t:qrRhi?", options, &option_index);
|
||||||
if (opt == -1) break;
|
if (opt == -1) break;
|
||||||
switch (opt)
|
switch (opt) {
|
||||||
{
|
|
||||||
case 'H':
|
case 'H':
|
||||||
esl_set_string(temp_host, optarg);
|
esl_set_string(temp_host, optarg);
|
||||||
argv_host = 1;
|
argv_host = 1;
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
temp_port= atoi(optarg);
|
temp_port= atoi(optarg);
|
||||||
if (temp_port > 0 && temp_port < 65536){
|
if (temp_port > 0 && temp_port < 65536) {
|
||||||
argv_port = 1;
|
argv_port = 1;
|
||||||
} else {
|
} else {
|
||||||
printf("ERROR: Port must be in range 1 - 65535\n");
|
printf("ERROR: Port must be in range 1 - 65535\n");
|
||||||
@ -1104,7 +960,7 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
temp_log=atoi(optarg);
|
temp_log=atoi(optarg);
|
||||||
if (temp_log < 0 || temp_log > 7){
|
if (temp_log < 0 || temp_log > 7) {
|
||||||
printf("ERROR: Debug level should be 0 - 7.\n");
|
printf("ERROR: Debug level should be 0 - 7.\n");
|
||||||
argv_error = 1;
|
argv_error = 1;
|
||||||
} else {
|
} else {
|
||||||
@ -1142,20 +998,16 @@ int main(int argc, char *argv[])
|
|||||||
opt = 0;
|
opt = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (argv_error) {
|
||||||
if (argv_error){
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
return usage(argv[0]);
|
return usage(argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(rv = esl_config_open_file(&cfg, cfile))) {
|
if (!(rv = esl_config_open_file(&cfg, cfile))) {
|
||||||
rv = esl_config_open_file(&cfg, dft_cfile);
|
rv = esl_config_open_file(&cfg, dft_cfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rv) {
|
if (rv) {
|
||||||
char *var, *val;
|
char *var, *val;
|
||||||
char cur_cat[128] = "";
|
char cur_cat[128] = "";
|
||||||
|
|
||||||
while (esl_config_next_pair(&cfg, &var, &val)) {
|
while (esl_config_next_pair(&cfg, &var, &val)) {
|
||||||
if (strcmp(cur_cat, cfg.category)) {
|
if (strcmp(cur_cat, cfg.category)) {
|
||||||
esl_set_string(cur_cat, cfg.category);
|
esl_set_string(cur_cat, cfg.category);
|
||||||
@ -1167,7 +1019,6 @@ int main(int argc, char *argv[])
|
|||||||
esl_log(ESL_LOG_DEBUG, "Found Profile [%s]\n", profiles[pcount].name);
|
esl_log(ESL_LOG_DEBUG, "Found Profile [%s]\n", profiles[pcount].name);
|
||||||
pcount++;
|
pcount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcasecmp(var, "host")) {
|
if (!strcasecmp(var, "host")) {
|
||||||
esl_set_string(profiles[pcount-1].host, val);
|
esl_set_string(profiles[pcount-1].host, val);
|
||||||
} else if (!strcasecmp(var, "user")) {
|
} else if (!strcasecmp(var, "user")) {
|
||||||
@ -1181,7 +1032,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
} else if (!strcasecmp(var, "debug")) {
|
} else if (!strcasecmp(var, "debug")) {
|
||||||
int dt = atoi(val);
|
int dt = atoi(val);
|
||||||
if (dt > -1 && dt < 8){
|
if (dt > -1 && dt < 8) {
|
||||||
profiles[pcount-1].debug = dt;
|
profiles[pcount-1].debug = dt;
|
||||||
}
|
}
|
||||||
} else if(!strcasecmp(var, "loglevel")) {
|
} else if(!strcasecmp(var, "loglevel")) {
|
||||||
@ -1190,10 +1041,8 @@ int main(int argc, char *argv[])
|
|||||||
profiles[pcount-1].quiet = esl_true(val);
|
profiles[pcount-1].quiet = esl_true(val);
|
||||||
} else if (!strncasecmp(var, "key_F", 5)) {
|
} else if (!strncasecmp(var, "key_F", 5)) {
|
||||||
char *key = var + 5;
|
char *key = var + 5;
|
||||||
|
|
||||||
if (key) {
|
if (key) {
|
||||||
int i = atoi(key);
|
int i = atoi(key);
|
||||||
|
|
||||||
if (i > 0 && i < 13) {
|
if (i > 0 && i < 13) {
|
||||||
profiles[pcount-1].console_fnkeys[i - 1] = strdup(val);
|
profiles[pcount-1].console_fnkeys[i - 1] = strdup(val);
|
||||||
}
|
}
|
||||||
@ -1202,44 +1051,35 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
esl_config_close_file(&cfg);
|
esl_config_close_file(&cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optind < argc) {
|
if (optind < argc) {
|
||||||
get_profile(argv[optind], &profile);
|
get_profile(argv[optind], &profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!profile) {
|
if (!profile) {
|
||||||
if (get_profile("default", &profile)) {
|
if (get_profile("default", &profile)) {
|
||||||
esl_log(ESL_LOG_DEBUG, "profile default does not exist using builtin profile\n");
|
esl_log(ESL_LOG_DEBUG, "profile default does not exist using builtin profile\n");
|
||||||
profile = &internal_profile;
|
profile = &internal_profile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (temp_log < 0 ) {
|
if (temp_log < 0 ) {
|
||||||
esl_global_set_default_logger(profile->debug);
|
esl_global_set_default_logger(profile->debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv_host) {
|
if (argv_host) {
|
||||||
esl_set_string(profile->host, temp_host);
|
esl_set_string(profile->host, temp_host);
|
||||||
}
|
}
|
||||||
if (argv_port) {
|
if (argv_port) {
|
||||||
profile->port = (esl_port_t)temp_port;
|
profile->port = (esl_port_t)temp_port;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv_user) {
|
if (argv_user) {
|
||||||
esl_set_string(profile->user, temp_user);
|
esl_set_string(profile->user, temp_user);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv_pass) {
|
if (argv_pass) {
|
||||||
esl_set_string(profile->pass, temp_pass);
|
esl_set_string(profile->pass, temp_pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*argv_loglevel) {
|
if (*argv_loglevel) {
|
||||||
esl_set_string(profile->loglevel, argv_loglevel);
|
esl_set_string(profile->loglevel, argv_loglevel);
|
||||||
profile->quiet = 0;
|
profile->quiet = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
esl_log(ESL_LOG_DEBUG, "Using profile %s [%s]\n", profile->name, profile->host);
|
esl_log(ESL_LOG_DEBUG, "Using profile %s [%s]\n", profile->name, profile->host);
|
||||||
|
|
||||||
if (argv_host) {
|
if (argv_host) {
|
||||||
if (argv_port && profile->port != 8021) {
|
if (argv_port && profile->port != 8021) {
|
||||||
snprintf(prompt_str, sizeof(prompt_str), "freeswitch@%s:%u@%s> ", profile->host, profile->port, profile->name);
|
snprintf(prompt_str, sizeof(prompt_str), "freeswitch@%s:%u@%s> ", profile->host, profile->port, profile->name);
|
||||||
@ -1249,11 +1089,8 @@ int main(int argc, char *argv[])
|
|||||||
} else {
|
} else {
|
||||||
snprintf(prompt_str, sizeof(prompt_str), "freeswitch@%s> ", profile->name);
|
snprintf(prompt_str, sizeof(prompt_str), "freeswitch@%s> ", profile->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
connect:
|
connect:
|
||||||
|
|
||||||
CONNECTED = 0;
|
CONNECTED = 0;
|
||||||
|
|
||||||
while (--loops > 0) {
|
while (--loops > 0) {
|
||||||
memset(&handle, 0, sizeof(handle));
|
memset(&handle, 0, sizeof(handle));
|
||||||
if (esl_connect(&handle, profile->host, profile->port, profile->user, profile->pass)) {
|
if (esl_connect(&handle, profile->host, profile->port, profile->user, profile->pass)) {
|
||||||
@ -1274,7 +1111,6 @@ int main(int argc, char *argv[])
|
|||||||
if (!ctl_c) {
|
if (!ctl_c) {
|
||||||
CONNECTED = 1;
|
CONNECTED = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (temp_log < 0 ) {
|
if (temp_log < 0 ) {
|
||||||
esl_global_set_default_logger(profile->debug);
|
esl_global_set_default_logger(profile->debug);
|
||||||
} else {
|
} else {
|
||||||
@ -1283,11 +1119,8 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (argv_exec) {
|
||||||
|
|
||||||
if (argv_exec){
|
|
||||||
const char *err = NULL;
|
const char *err = NULL;
|
||||||
|
|
||||||
snprintf(cmd_str, sizeof(cmd_str), "api %s\n\n", argv_command);
|
snprintf(cmd_str, sizeof(cmd_str), "api %s\n\n", argv_command);
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
esl_status_t status = esl_send_recv_timed(&handle, cmd_str, timeout);
|
esl_status_t status = esl_send_recv_timed(&handle, cmd_str, timeout);
|
||||||
@ -1299,7 +1132,6 @@ int main(int argc, char *argv[])
|
|||||||
} else {
|
} else {
|
||||||
esl_send_recv(&handle, cmd_str);
|
esl_send_recv(&handle, cmd_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handle.last_sr_event) {
|
if (handle.last_sr_event) {
|
||||||
if (handle.last_sr_event->body) {
|
if (handle.last_sr_event->body) {
|
||||||
printf("%s\n", handle.last_sr_event->body);
|
printf("%s\n", handle.last_sr_event->body);
|
||||||
@ -1307,14 +1139,11 @@ int main(int argc, char *argv[])
|
|||||||
printf("Error: %s!\n", err + 4);
|
printf("Error: %s!\n", err + 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
esl_disconnect(&handle);
|
esl_disconnect(&handle);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
global_handle = &handle;
|
global_handle = &handle;
|
||||||
global_profile = profile;
|
global_profile = profile;
|
||||||
|
|
||||||
esl_thread_create_detached(msg_thread_run, &handle);
|
esl_thread_create_detached(msg_thread_run, &handle);
|
||||||
|
|
||||||
#ifdef HAVE_EDITLINE
|
#ifdef HAVE_EDITLINE
|
||||||
@ -1336,7 +1165,6 @@ int main(int argc, char *argv[])
|
|||||||
el_set(el, EL_ADDFN, "f10-key", "F10 KEY PRESS", console_f10key);
|
el_set(el, EL_ADDFN, "f10-key", "F10 KEY PRESS", console_f10key);
|
||||||
el_set(el, EL_ADDFN, "f11-key", "F11 KEY PRESS", console_f11key);
|
el_set(el, EL_ADDFN, "f11-key", "F11 KEY PRESS", console_f11key);
|
||||||
el_set(el, EL_ADDFN, "f12-key", "F12 KEY PRESS", console_f12key);
|
el_set(el, EL_ADDFN, "f12-key", "F12 KEY PRESS", console_f12key);
|
||||||
|
|
||||||
el_set(el, EL_ADDFN, "EOF-key", "EOF (^D) KEY PRESS", console_eofkey);
|
el_set(el, EL_ADDFN, "EOF-key", "EOF (^D) KEY PRESS", console_eofkey);
|
||||||
|
|
||||||
el_set(el, EL_BIND, "\033OP", "f1-key", NULL);
|
el_set(el, EL_BIND, "\033OP", "f1-key", NULL);
|
||||||
@ -1344,7 +1172,6 @@ int main(int argc, char *argv[])
|
|||||||
el_set(el, EL_BIND, "\033OR", "f3-key", NULL);
|
el_set(el, EL_BIND, "\033OR", "f3-key", NULL);
|
||||||
el_set(el, EL_BIND, "\033OS", "f4-key", NULL);
|
el_set(el, EL_BIND, "\033OS", "f4-key", NULL);
|
||||||
|
|
||||||
|
|
||||||
el_set(el, EL_BIND, "\033[11~", "f1-key", NULL);
|
el_set(el, EL_BIND, "\033[11~", "f1-key", NULL);
|
||||||
el_set(el, EL_BIND, "\033[12~", "f2-key", NULL);
|
el_set(el, EL_BIND, "\033[12~", "f2-key", NULL);
|
||||||
el_set(el, EL_BIND, "\033[13~", "f3-key", NULL);
|
el_set(el, EL_BIND, "\033[13~", "f3-key", NULL);
|
||||||
@ -1371,9 +1198,7 @@ int main(int argc, char *argv[])
|
|||||||
history(myhistory, &ev, H_SETSIZE, 800);
|
history(myhistory, &ev, H_SETSIZE, 800);
|
||||||
el_set(el, EL_HIST, history, myhistory);
|
el_set(el, EL_HIST, history, myhistory);
|
||||||
history(myhistory, &ev, H_LOAD, hfile);
|
history(myhistory, &ev, H_LOAD, hfile);
|
||||||
|
|
||||||
el_source(el, NULL);
|
el_source(el, NULL);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
@ -1381,49 +1206,38 @@ int main(int argc, char *argv[])
|
|||||||
wOldColorAttrs = csbiInfo.wAttributes;
|
wOldColorAttrs = csbiInfo.wAttributes;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!argv_quiet && !profile->quiet) {
|
if (!argv_quiet && !profile->quiet) {
|
||||||
snprintf(cmd_str, sizeof(cmd_str), "log %s\n\n", profile->loglevel);
|
snprintf(cmd_str, sizeof(cmd_str), "log %s\n\n", profile->loglevel);
|
||||||
esl_send_recv(&handle, cmd_str);
|
esl_send_recv(&handle, cmd_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
print_banner(stdout);
|
print_banner(stdout);
|
||||||
|
|
||||||
esl_log(ESL_LOG_INFO, "FS CLI Ready.\nenter /help for a list of commands.\n");
|
esl_log(ESL_LOG_INFO, "FS CLI Ready.\nenter /help for a list of commands.\n");
|
||||||
printf("%s\n", handle.last_sr_reply);
|
printf("%s\n", handle.last_sr_reply);
|
||||||
|
|
||||||
while (running > 0) {
|
while (running > 0) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
#ifdef HAVE_EDITLINE
|
#ifdef HAVE_EDITLINE
|
||||||
line = el_gets(el, &count);
|
line = el_gets(el, &count);
|
||||||
#else
|
#else
|
||||||
line = basic_gets(&count);
|
line = basic_gets(&count);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (count > 1) {
|
if (count > 1) {
|
||||||
if (!esl_strlen_zero(line)) {
|
if (!esl_strlen_zero(line)) {
|
||||||
char *cmd = strdup(line);
|
char *cmd = strdup(line);
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
#ifdef HAVE_EDITLINE
|
#ifdef HAVE_EDITLINE
|
||||||
const LineInfo *lf = el_line(el);
|
const LineInfo *lf = el_line(el);
|
||||||
char *foo = (char *) lf->buffer;
|
char *foo = (char *) lf->buffer;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((p = strrchr(cmd, '\r')) || (p = strrchr(cmd, '\n'))) {
|
if ((p = strrchr(cmd, '\r')) || (p = strrchr(cmd, '\n'))) {
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
}
|
}
|
||||||
assert(cmd != NULL);
|
assert(cmd != NULL);
|
||||||
|
|
||||||
#ifdef HAVE_EDITLINE
|
#ifdef HAVE_EDITLINE
|
||||||
history(myhistory, &ev, H_ENTER, line);
|
history(myhistory, &ev, H_ENTER, line);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((r = process_command(&handle, cmd))) {
|
if ((r = process_command(&handle, cmd))) {
|
||||||
running = r;
|
running = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_EDITLINE
|
#ifdef HAVE_EDITLINE
|
||||||
el_deletestr(el, strlen(foo) + 1);
|
el_deletestr(el, strlen(foo) + 1);
|
||||||
memset(foo, 0, strlen(foo));
|
memset(foo, 0, strlen(foo));
|
||||||
@ -1431,30 +1245,32 @@ int main(int argc, char *argv[])
|
|||||||
free(cmd);
|
free(cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (running < 0 && reconnect) {
|
if (running < 0 && reconnect) {
|
||||||
running = 1;
|
running = 1;
|
||||||
loops = 120;
|
loops = 120;
|
||||||
goto connect;
|
goto connect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_EDITLINE
|
#ifdef HAVE_EDITLINE
|
||||||
done:
|
done:
|
||||||
history(myhistory, &ev, H_SAVE, hfile);
|
history(myhistory, &ev, H_SAVE, hfile);
|
||||||
|
|
||||||
/* Clean up our memory */
|
/* Clean up our memory */
|
||||||
history_end(myhistory);
|
history_end(myhistory);
|
||||||
el_end(el);
|
el_end(el);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
esl_disconnect(&handle);
|
esl_disconnect(&handle);
|
||||||
|
|
||||||
thread_running = 0;
|
thread_running = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* For Emacs:
|
||||||
|
* Local Variables:
|
||||||
|
* mode:c
|
||||||
|
* indent-tabs-mode:t
|
||||||
|
* tab-width:4
|
||||||
|
* c-basic-offset:4
|
||||||
|
* End:
|
||||||
|
* For VIM:
|
||||||
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
||||||
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user