36 #include <switch_private.h> 38 #define CMD_BUFLEN 1024 44 static History *myhistory;
46 static char *hfile = NULL;
58 #define CC_REDISPLAY 8 59 #define CC_REFRESH_BEEP 9 67 #define DELETE_REFRESH_OP 5 74 static int console_bufferInput(
char *
buf,
int len,
char *cmd,
int key);
92 char *cf =
"switch.conf";
98 for (i = 0; i < 12; i++) {
112 if ((i < 1) || (i > 12)) {
134 if (!(new_data = realloc(handle->
data, need))) {
138 handle->
data = new_data;
142 memcpy((uint8_t *) (handle->
data) + handle->
data_len, data, datalen);
145 *(uint8_t *) handle->
end =
'\0';
153 char *end = handle->
end;
172 if ((remaining < need) && handle->
alloc_len) {
177 if ((new_data = realloc(handle->
data, new_len))) {
179 handle->
data = new_data;
190 if (remaining < need) {
215 if ((fd = fopen(path,
"r"))) {
216 char *line_buf = NULL;
233 char **r = (
char **) pArg;
234 *r = strdup(argv[0]);
260 sql =
switch_mprintf(
"select command from aliases where alias='%q'", cmd);
262 sql =
switch_mprintf(
"select command from aliases where alias='%w'", cmd);
276 sql =
switch_mprintf(
"select command from aliases where alias='%q %q'", cmd, arg);
278 sql =
switch_mprintf(
"select command from aliases where alias='%w %w'", cmd, arg);
325 fprintf(handle,
"\n%s\n", (
char *) stream.
data);
329 if (!strcasecmp(xcmd,
"...") || !strcasecmp(xcmd,
"shutdown")) {
333 fprintf(handle,
"Unknown Command: %s\n", xcmd);
347 char *arg = NULL, *alias = NULL;
364 while (*xcmd ==
' ') xcmd++;
368 if (!strncasecmp(xcmd,
"alias", 5)) {
375 for (x = 0; x < argc; x++) {
377 if ((arg = strchr(cmd,
'\r')) != 0 || (arg = strchr(cmd,
'\n')) != 0) {
381 if ((arg = strchr(cmd,
' ')) != 0) {
386 istream->
write_function(istream,
"\nExpand Alias [%s]->[%s]\n\n", cmd, alias);
420 fprintf(stderr,
"Memory Error\n");
425 fprintf(handle,
"%s", data);
433 fprintf(handle,
"[%d] %s %s:%d %s() %s", (
int) getpid(), date, filep, line, func, data);
468 static int comp_callback(
void *pArg,
int argc,
char **argv,
char **columnNames)
471 char *
target = NULL, *str = NULL, *
cur = NULL;
496 if (!
zstr(target) && *target ==
':' && *(target + 1) ==
':' && *(target + 2) ==
'[') {
497 char *p = target + 3, *list = NULL;
500 char *s_argv[100] = { 0 };
501 char *r_argv[1] = { 0 }, *r_cols[1] = {0};
506 for (i = 0; (int)i < argc; i++) {
507 if (!cur || !strncmp(s_argv[i], cur, strlen(cur))) {
508 r_argv[0] = s_argv[i];
517 if (!
zstr(target) && *target ==
':' && *(target + 1) ==
':') {
518 char *r_argv[1] = { 0 }, *r_cols[1] = {0};
522 for (m = matches->
head; m; m = m->
next) {
523 if (!cur || !strncmp(m->
val, cur, strlen(cur))) {
535 fprintf(h->
out,
"[%20s]\t", target);
552 for (i = 0; i < x && i < y; i++) {
558 }
else if (h->
hits == 1) {
564 if ((h->
hits % 3) == 0) {
566 if ((h->
hits % 4) == 0) {
569 fprintf(h->
out,
"\n");
626 #ifdef HAVE_GETIFADDRS 632 struct ifaddrs *addrs, *addr;
635 for(addr = addrs; addr; addr = addr->ifa_next) {
636 if (addr->ifa_flags & IFF_UP) {
656 static int uuid_callback(
void *pArg,
int argc,
char **argv,
char **columnNames)
680 sql =
switch_mprintf(
"select distinct uuid from channels where uuid like '%q%%' and hostname='%q' order by uuid",
706 char *dup = strdup(line);
730 pos = (int)(cursor - line);
741 if ((p = strchr(buf,
'\r')) || (p = strchr(buf,
'\n'))) {
745 while (*buf ==
' ') {
753 el_deletestr(el, sc);
760 while (p >= buf && *p ==
' ') {
768 el_deletestr(el, sc - 1);
774 for (p = buf; p && *p; p++) {
789 h.
len = (int)strlen(buf);
792 fprintf(h.
out,
"\n\n");
802 sql =
switch_mprintf(
"select distinct name from interfaces where type='api' and name like '%q%%' and hostname='%q' order by name",
820 char *dupdup = strdup(dup);
822 char *argv[10] = { 0 };
830 stream.
write_function(&stream,
"select distinct a1 from complete where " "a1 not in (select name from interfaces where hostname='%q') %s ",
840 for (x = 0; x < argc; x++) {
841 if (h.
words + 1 > argc) {
843 stream.
write_function(&stream,
"(a%d like '::%%' or a%d = '' or a%d = '%q')%q",
844 x + 1, x + 1, x + 1,
switch_str_nil(argv[x]), x == argc - 1 ?
"" :
" and ");
846 stream.
write_function(&stream,
"(a%d like '::%%' or a%d = '' or a%d = '%w')%w",
847 x + 1, x + 1, x + 1,
switch_str_nil(argv[x]), x == argc - 1 ?
"" :
" and ");
851 stream.
write_function(&stream,
"(a%d like '::%%' or a%d = '' or a%d like '%q%%')%q",
852 x + 1, x + 1, x + 1,
switch_str_nil(argv[x]), x == argc - 1 ?
"" :
" and ");
854 stream.
write_function(&stream,
"(a%d like '::%%' or a%d = '' or a%d like '%w%%')%w",
855 x + 1, x + 1, x + 1,
switch_str_nil(argv[x]), x == argc - 1 ?
"" :
" and ");
879 fprintf(h.
out,
"\n\n");
895 snprintf(buf,
sizeof(buf),
"%d", h.
len);
907 el_deletestr(el, h.
len);
908 el_insertstr(el, h.
last);
909 el_insertstr(el,
" ");
911 el_deletestr(el, h.
len);
919 console_bufferInput(0, h.
len, (
char *) line, DELETE_REFRESH_OP);
920 console_bufferInput(h.
last, (
int) strlen(h.
last), (
char *) line, 0);
921 console_bufferInput(
" ", 1, (
char *) line, 0);
923 console_bufferInput(0, h.
len, (
char *) line, DELETE_REFRESH_OP);
924 console_bufferInput(h.
partial, (
int) strlen(h.
partial), (
char *) line, 0);
926 console_bufferInput(0, 0, (
char *) line, DELETE_REFRESH_OP);
947 #if defined(HAVE_LIBEDIT) || defined(_MSC_VER) 951 static unsigned char console_fnkey_pressed(
int i)
978 history(myhistory, &ev, H_SAVE, hfile);
985 static char prompt_str[512] =
"";
987 static unsigned char console_f1key(EditLine * el,
int ch)
989 return console_fnkey_pressed(1);
991 static unsigned char console_f2key(EditLine * el,
int ch)
993 return console_fnkey_pressed(2);
995 static unsigned char console_f3key(EditLine * el,
int ch)
997 return console_fnkey_pressed(3);
999 static unsigned char console_f4key(EditLine * el,
int ch)
1001 return console_fnkey_pressed(4);
1003 static unsigned char console_f5key(EditLine * el,
int ch)
1005 return console_fnkey_pressed(5);
1007 static unsigned char console_f6key(EditLine * el,
int ch)
1009 return console_fnkey_pressed(6);
1011 static unsigned char console_f7key(EditLine * el,
int ch)
1013 return console_fnkey_pressed(7);
1015 static unsigned char console_f8key(EditLine * el,
int ch)
1017 return console_fnkey_pressed(8);
1019 static unsigned char console_f9key(EditLine * el,
int ch)
1021 return console_fnkey_pressed(9);
1023 static unsigned char console_f10key(EditLine * el,
int ch)
1025 return console_fnkey_pressed(10);
1027 static unsigned char console_f11key(EditLine * el,
int ch)
1029 return console_fnkey_pressed(11);
1031 static unsigned char console_f12key(EditLine * el,
int ch)
1033 return console_fnkey_pressed(12);
1037 char *prompt(EditLine * e)
1039 if (*prompt_str ==
'\0') {
1055 if (getppid() == 1) {
1065 line = el_gets(el, &count);
1069 char *cmd = strdup(line);
1071 const LineInfo *lf = el_line(el);
1072 char *foo = (
char *) lf->buffer;
1073 if ((p = strrchr(cmd,
'\r')) || (p = strrchr(cmd,
'\n'))) {
1076 assert(cmd != NULL);
1077 history(myhistory, &ev, H_ENTER, line);
1079 el_deletestr(el, strlen(foo) + 1);
1080 memset(foo, 0, strlen(foo));
1092 static unsigned char complete(EditLine * el,
int ch)
1094 const LineInfo *lf = el_line(el);
1112 el_set(el, EL_PROMPT, &prompt);
1113 el_set(el, EL_EDITOR,
"emacs");
1121 el_set(el, EL_ADDFN,
"f1-key",
"F1 KEY PRESS", console_f1key);
1122 el_set(el, EL_ADDFN,
"f2-key",
"F2 KEY PRESS", console_f2key);
1123 el_set(el, EL_ADDFN,
"f3-key",
"F3 KEY PRESS", console_f3key);
1124 el_set(el, EL_ADDFN,
"f4-key",
"F4 KEY PRESS", console_f4key);
1125 el_set(el, EL_ADDFN,
"f5-key",
"F5 KEY PRESS", console_f5key);
1126 el_set(el, EL_ADDFN,
"f6-key",
"F6 KEY PRESS", console_f6key);
1127 el_set(el, EL_ADDFN,
"f7-key",
"F7 KEY PRESS", console_f7key);
1128 el_set(el, EL_ADDFN,
"f8-key",
"F8 KEY PRESS", console_f8key);
1129 el_set(el, EL_ADDFN,
"f9-key",
"F9 KEY PRESS", console_f9key);
1130 el_set(el, EL_ADDFN,
"f10-key",
"F10 KEY PRESS", console_f10key);
1131 el_set(el, EL_ADDFN,
"f11-key",
"F11 KEY PRESS", console_f11key);
1132 el_set(el, EL_ADDFN,
"f12-key",
"F12 KEY PRESS", console_f12key);
1134 el_set(el, EL_BIND,
"\033OP",
"f1-key", NULL);
1135 el_set(el, EL_BIND,
"\033OQ",
"f2-key", NULL);
1136 el_set(el, EL_BIND,
"\033OR",
"f3-key", NULL);
1137 el_set(el, EL_BIND,
"\033OS",
"f4-key", NULL);
1140 el_set(el, EL_BIND,
"\033[11~",
"f1-key", NULL);
1141 el_set(el, EL_BIND,
"\033[12~",
"f2-key", NULL);
1142 el_set(el, EL_BIND,
"\033[13~",
"f3-key", NULL);
1143 el_set(el, EL_BIND,
"\033[14~",
"f4-key", NULL);
1144 el_set(el, EL_BIND,
"\033[15~",
"f5-key", NULL);
1145 el_set(el, EL_BIND,
"\033[17~",
"f6-key", NULL);
1146 el_set(el, EL_BIND,
"\033[18~",
"f7-key", NULL);
1147 el_set(el, EL_BIND,
"\033[19~",
"f8-key", NULL);
1148 el_set(el, EL_BIND,
"\033[20~",
"f9-key", NULL);
1149 el_set(el, EL_BIND,
"\033[21~",
"f10-key", NULL);
1150 el_set(el, EL_BIND,
"\033[23~",
"f11-key", NULL);
1151 el_set(el, EL_BIND,
"\033[24~",
"f12-key", NULL);
1154 el_set(el, EL_ADDFN,
"ed-complete",
"Complete argument", complete);
1155 el_set(el, EL_BIND,
"^I",
"ed-complete", NULL);
1158 el_set(el, EL_BIND,
"\033[3~",
"ed-delete-next-char", NULL);
1160 myhistory = history_init();
1161 if (myhistory == 0) {
1162 fprintf(stderr,
"history could not be initialized\n");
1167 assert(hfile != NULL);
1169 history(myhistory, &ev, H_SETSIZE, 800);
1170 el_set(el, EL_HIST, history, myhistory);
1171 history(myhistory, &ev, H_LOAD, hfile);
1173 el_source(el, NULL);
1189 history(myhistory, &ev, H_SAVE, hfile);
1193 history_end(myhistory);
1202 int iHistorySel = 0;
1204 static int console_history(
char *cmd,
int direction)
1209 if (direction == 0) {
1211 if (iHistory < HISTLEN) {
1212 if (iHistory && strcmp(history[iHistory - 1], cmd)) {
1213 iHistorySel = iHistory;
1214 strcpy(history[iHistory++], cmd);
1215 }
else if (iHistory == 0) {
1216 iHistorySel = iHistory;
1217 strcpy(history[iHistory++], cmd);
1220 iHistory = HISTLEN - 1;
1221 for (i = 0; i < HISTLEN - 1; i++) {
1222 strcpy(history[i], history[i + 1]);
1224 iHistorySel = iHistory;
1225 strcpy(history[iHistory++], cmd);
1229 iHistorySel += direction;
1232 if (iHistorySel < 0) {
1235 if (iHistory && iHistorySel >= iHistory) {
1236 iHistorySel = iHistory - 1;
1238 strcpy(cmd, history[iHistorySel]);
1243 static int console_bufferInput(
char *addchars,
int len,
char *cmd,
int key)
1245 static int iCmdBuffer = 0;
1246 static int iCmdCursor = 0;
1247 static int ignoreNext = 0;
1248 static int insertMode = 1;
1249 static COORD orgPosition;
1250 static char prompt[80];
1255 CONSOLE_SCREEN_BUFFER_INFO info;
1257 hOut = GetStdHandle(STD_OUTPUT_HANDLE);
1258 GetConsoleScreenBufferInfo(hOut, &info);
1259 position = info.dwCursorPosition;
1260 if (iCmdCursor == 0) {
1261 orgPosition = position;
1264 if (key == PROMPT_OP) {
1265 if (strlen(cmd) <
sizeof(prompt)) {
1266 strcpy(prompt, cmd);
1271 if (key == KEY_TAB) {
1275 if (key == KEY_UP || key == KEY_DOWN || key == CLEAR_OP) {
1276 SetConsoleCursorPosition(hOut, orgPosition);
1277 for (i = 0; i < (int) strlen(cmd); i++) {
1280 SetConsoleCursorPosition(hOut, orgPosition);
1285 if (key == DELETE_REFRESH_OP) {
1286 int l = len < (int) strlen(cmd) ?
len : (int) strlen(cmd);
1287 for (i = 0; i < l; i++) {
1288 cmd[--iCmdBuffer] = 0;
1290 iCmdCursor = (int) strlen(cmd);
1291 printf(
"%s", prompt);
1292 GetConsoleScreenBufferInfo(hOut, &info);
1293 orgPosition = info.dwCursorPosition;
1298 if (key == KEY_LEFT) {
1300 if (position.X == 0) {
1302 position.X = info.dwSize.X - 1;
1307 SetConsoleCursorPosition(hOut, position);
1311 if (key == KEY_RIGHT) {
1312 if (iCmdCursor < (
int) strlen(cmd)) {
1313 if (position.X == info.dwSize.X - 1) {
1320 SetConsoleCursorPosition(hOut, position);
1324 if (key == KEY_INSERT) {
1325 insertMode = !insertMode;
1327 if (key == KEY_DELETE) {
1328 if (iCmdCursor < iCmdBuffer) {
1330 for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
1331 cmd[pos] = cmd[pos + 1];
1336 for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
1337 printf(
"%c", cmd[pos]);
1340 SetConsoleCursorPosition(hOut, position);
1343 for (iBuf = 0; iBuf <
len; iBuf++) {
1344 switch (addchars[iBuf]) {
1350 int ret = iCmdBuffer;
1351 if (iCmdBuffer == 0) {
1352 strcpy(cmd,
"Empty");
1353 ret = (int) strlen(cmd);
1355 console_history(cmd, 0);
1356 cmd[iCmdBuffer] = 0;
1366 if (position.X == 0) {
1368 position.X = info.dwSize.X - 1;
1369 SetConsoleCursorPosition(hOut, position);
1372 SetConsoleCursorPosition(hOut, position);
1375 if (iCmdCursor < iCmdBuffer) {
1378 for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
1379 cmd[pos] = cmd[pos + 1];
1384 SetConsoleCursorPosition(hOut, position);
1385 for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
1386 printf(
"%c", cmd[pos]);
1389 SetConsoleCursorPosition(hOut, position);
1391 SetConsoleCursorPosition(hOut, position);
1394 cmd[iCmdBuffer] = 0;
1400 if (iCmdCursor < iCmdBuffer) {
1403 if (position.X == info.dwSize.X - 1) {
1411 for (pos = iCmdBuffer - 1; pos >= iCmdCursor; pos--) {
1412 cmd[pos + 1] = cmd[pos];
1416 cmd[iCmdCursor++] = addchars[iBuf];
1417 printf(
"%c", addchars[iBuf]);
1418 for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
1419 GetConsoleScreenBufferInfo(hOut, &info);
1420 if (info.dwCursorPosition.X == info.dwSize.X - 1 && info.dwCursorPosition.Y == info.dwSize.Y - 1) {
1424 printf(
"%c", cmd[pos]);
1426 SetConsoleCursorPosition(hOut, position);
1428 if (position.X == info.dwSize.X - 1 && position.Y == info.dwSize.Y - 1) {
1431 cmd[iCmdBuffer++] = addchars[iBuf];
1433 printf(
"%c", addchars[iBuf]);
1438 printf(
"Read Console... BUFFER OVERRUN\n");
1447 static BOOL console_readConsole(HANDLE conIn,
char *
buf,
int len,
int *pRed,
int *key)
1449 DWORD recordIndex, bufferIndex, toRead = 0, red;
1450 PINPUT_RECORD pInput;
1452 GetNumberOfConsoleInputEvents(conIn, &toRead);
1453 if (len < (
int) toRead) {
1460 if ((pInput = (PINPUT_RECORD) malloc(toRead *
sizeof(INPUT_RECORD))) == NULL) {
1464 ReadConsoleInput(conIn, pInput, toRead, &red);
1466 for (recordIndex = bufferIndex = 0; recordIndex < red; recordIndex++) {
1467 KEY_EVENT_RECORD keyEvent = pInput[recordIndex].Event.KeyEvent;
1468 if (pInput[recordIndex].EventType == KEY_EVENT && keyEvent.bKeyDown) {
1469 if (keyEvent.wVirtualKeyCode == 38 && keyEvent.wVirtualScanCode == 72) {
1471 console_history(buf, -1);
1473 bufferIndex += (DWORD) strlen(buf);
1475 if (keyEvent.wVirtualKeyCode == 40 && keyEvent.wVirtualScanCode == 80) {
1477 console_history(buf, 1);
1479 bufferIndex += (DWORD) strlen(buf);
1481 if (keyEvent.wVirtualKeyCode == 112 && keyEvent.wVirtualScanCode == 59) {
1482 console_fnkey_pressed(1);
1484 if (keyEvent.wVirtualKeyCode == 113 && keyEvent.wVirtualScanCode == 60) {
1485 console_fnkey_pressed(2);
1487 if (keyEvent.wVirtualKeyCode == 114 && keyEvent.wVirtualScanCode == 61) {
1488 console_fnkey_pressed(3);
1490 if (keyEvent.wVirtualKeyCode == 115 && keyEvent.wVirtualScanCode == 62) {
1491 console_fnkey_pressed(4);
1493 if (keyEvent.wVirtualKeyCode == 116 && keyEvent.wVirtualScanCode == 63) {
1494 console_fnkey_pressed(5);
1496 if (keyEvent.wVirtualKeyCode == 117 && keyEvent.wVirtualScanCode == 64) {
1497 console_fnkey_pressed(6);
1499 if (keyEvent.wVirtualKeyCode == 118 && keyEvent.wVirtualScanCode == 65) {
1500 console_fnkey_pressed(7);
1502 if (keyEvent.wVirtualKeyCode == 119 && keyEvent.wVirtualScanCode == 66) {
1503 console_fnkey_pressed(8);
1505 if (keyEvent.wVirtualKeyCode == 120 && keyEvent.wVirtualScanCode == 67) {
1506 console_fnkey_pressed(9);
1508 if (keyEvent.wVirtualKeyCode == 121 && keyEvent.wVirtualScanCode == 68) {
1509 console_fnkey_pressed(10);
1511 if (keyEvent.wVirtualKeyCode == 122 && keyEvent.wVirtualScanCode == 87) {
1512 console_fnkey_pressed(11);
1514 if (keyEvent.wVirtualKeyCode == 123 && keyEvent.wVirtualScanCode == 88) {
1515 console_fnkey_pressed(12);
1517 if (keyEvent.uChar.AsciiChar == 9) {
1521 if (keyEvent.uChar.AsciiChar == 27) {
1525 if (keyEvent.wVirtualKeyCode == 37 && keyEvent.wVirtualScanCode == 75) {
1528 if (keyEvent.wVirtualKeyCode == 39 && keyEvent.wVirtualScanCode == 77) {
1531 if (keyEvent.wVirtualKeyCode == 45 && keyEvent.wVirtualScanCode == 82) {
1534 if (keyEvent.wVirtualKeyCode == 46 && keyEvent.wVirtualScanCode == 83) {
1537 while (keyEvent.wRepeatCount && keyEvent.uChar.AsciiChar) {
1538 buf[bufferIndex] = keyEvent.uChar.AsciiChar;
1539 if (buf[bufferIndex] ==
'\r') {
1540 buf[bufferIndex] =
'\n';
1543 keyEvent.wRepeatCount--;
1549 *pRed = bufferIndex;
1558 int32_t activity = 1;
1570 console_bufferInput(0, 0, cmd, PROMPT_OP);
1571 memset(cmd, 0,
sizeof(cmd));
1578 HANDLE stdinHandle = GetStdHandle(STD_INPUT_HANDLE);
1581 struct timeval tv = { 0, 20000 };
1594 if (console_readConsole(stdinHandle, keys, (
int)
sizeof(keys), &read, &key)) {
1595 if (console_bufferInput(keys, read, cmd, key)) {
1596 if (!strcmp(cmd,
"Empty")) {
1603 memset(cmd, 0,
sizeof(cmd));
1610 FD_SET(fileno(stdin), &rfds);
1611 FD_SET(fileno(stdin), &efds);
1612 if ((activity = select(fileno(stdin) + 1, &rfds, NULL, &efds, &tv)) < 0) {
1616 if (FD_ISSET(fileno(stdin), &efds)) {
1620 if (!FD_ISSET(fileno(stdin), &rfds)) {
1624 if (activity == 0) {
1629 memset(&cmd, 0,
sizeof(cmd));
1630 for (x = 0; x < (
sizeof(cmd) - 1); x++) {
1633 int y = read(fileno(stdin), cmd,
sizeof(cmd) - 1);
1640 if (cmd[x] ==
'\n') {
1729 if (matches->
count < 2) {
1733 for (i = 1; i < matches->
count; i++) {
1735 sort[1] = matches->
head;
1736 sort[2] = sort[1] ? sort[1]->
next : NULL;
1737 sort[3] = sort[2] ? sort[2]->
next : NULL;
1739 for (j = 1; j <= (matches->
count - i); j++) {
1741 if (strcmp(sort[1]->val, sort[2]->val) > 0) {
1742 sort[1]->next = sort[3];
1743 sort[2]->next = sort[1];
1746 sort[0]->next = sort[2];
1747 if (sort[1] == matches->
head)
1748 matches->
head = sort[2];
1754 sort[2] = sort[1]->
next;
1755 if (sort[3] && sort[3]->next)
1756 sort[3] = sort[3]->
next;
1762 if (sort[3] && sort[3]->next)
1763 sort[3] = sort[3]->
next;
1771 for (i = 1; i < matches->
count; i++)
1786 for(node = (*matches)->head; node; node = node->
next) {
1787 if (!strcasecmp(node->
val, new_val))
return;
1800 (*matches)->dynamic = 1;
1804 match->
val = strdup(new_val);
1806 if ((*matches)->head) {
1807 (*matches)->end->next = match;
1809 (*matches)->head = match;
1812 (*matches)->count++;
1814 (*matches)->end = match;
1837 char *mydata = NULL, *argv[11] = { 0 };
1846 if (
string && (mydata = strdup(
string))) {
1851 if (!strcasecmp(argv[0],
"stickyadd")) {
1852 mystream.
write_function(&mystream,
"insert into complete (sticky, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, hostname) values (1,");
1853 for (x = 0; x < 10; x++) {
1854 if (argv[x + 1] && !strcasecmp(argv[x + 1],
"_any_")) {
1867 }
else if (!strcasecmp(argv[0],
"add")) {
1868 mystream.
write_function(&mystream,
"insert into complete (sticky, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, hostname) values (0,");
1869 for (x = 0; x < 10; x++) {
1870 if (argv[x + 1] && !strcasecmp(argv[x + 1],
"_any_")) {
1884 }
else if (!strcasecmp(argv[0],
"del")) {
1885 char *what = argv[1];
1890 }
else if (!strcasecmp(what,
"*")) {
1894 mystream.
write_function(&mystream,
"delete from complete where ");
1895 for (x = 0; x < argc - 1; x++) {
1921 char *mydata = NULL, *argv[3] = { 0 };
1925 if (
string && (mydata = strdup(
string))) {
1930 if (argc > 2 && !strcmp(argv[1], argv[2])) {
1941 if (!strcasecmp(argv[0],
"stickyadd") && argc == 3) {
1946 sql =
switch_mprintf(
"insert into aliases (sticky, alias, command, hostname) values (1, '%q','%q','%q')",
1949 sql =
switch_mprintf(
"insert into aliases (sticky, alias, command, hostname) values (1, '%w','%w','%w')",
1954 }
else if (!strcasecmp(argv[0],
"add") && argc == 3) {
1959 sql =
switch_mprintf(
"insert into aliases (sticky, alias, command, hostname) values (0, '%q','%q','%q')",
1962 sql =
switch_mprintf(
"insert into aliases (sticky, alias, command, hostname) values (0, '%w','%w','%w')",
1967 }
else if (!strcasecmp(argv[0],
"del") && argc == 2) {
1968 char *what = argv[1];
1969 if (!strcasecmp(what,
"*")) {
switch_xml_t switch_xml_set_attr_d_buf(switch_xml_t xml, const char *name, const char *value)
Wrapper for switch_xml_set_attr() that strdup()s name/value. Value cannot be NULL.
switch_xml_t switch_xml_add_child_d(_In_ switch_xml_t xml, _In_z_ const char *name, _In_ switch_size_t off)
wrapper for switch_xml_add_child() that strdup()s name
#define switch_core_permanent_strdup(_todup)
Copy a string using permanent memory allocation.
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
const char * switch_core_get_switchname(void)
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
switch_status_t switch_console_set_complete(const char *string)
void switch_xml_free(_In_opt_ switch_xml_t xml)
frees the memory allocated for an switch_xml structure
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
const char * switch_xml_attr_soft(_In_ switch_xml_t xml, _In_z_ const char *attr)
returns the value of the requested tag attribute, or "" if not found
switch_xml_t switch_status_t switch_event_running(void)
Determine if the event system has been initialized.
switch_status_t switch_console_shutdown(void)
switch_text_channel_t
A target to write log/debug info to.
#define SWITCH_CHANNEL_LOG
void switch_console_push_match_unique(switch_console_callback_match_t **matches, const char *new_val)
switch_status_t switch_core_hash_destroy(_Inout_ switch_hash_t **hash)
Destroy an existing hash table.
switch_status_t switch_console_execute(char *xcmd, int rec, switch_stream_handle_t *istream)
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
#define switch_core_hash_init(_hash)
switch_console_callback_match_t * my_matches
switch_status_t switch_console_init(switch_memory_pool_t *pool)
switch_status_t switch_console_add_complete_func(const char *name, switch_console_complete_callback_t cb)
switch_status_t switch_console_list_uuid(const char *line, const char *cursor, switch_console_callback_match_t **matches)
void switch_console_sort_matches(switch_console_callback_match_t *matches)
switch_status_t switch_loadable_module_enumerate_available(const char *dir_path, switch_modulename_callback_func_t callback, void *user_data)
Enumerates a list of all modules discovered in a directory.
unsigned int switch_separate_string_string(char *buf, char *delim, _Post_count_(return) char **array, unsigned int arraylen)
switch_status_t switch_api_execute(const char *cmd, const char *arg, switch_core_session_t *session, switch_stream_handle_t *stream)
Execute a registered API command.
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
switch_memory_pool_t * pool
static int comp_callback(void *pArg, int argc, char **argv, char **columnNames)
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
Add a header to an event.
Representation of an event.
void switch_console_printf(switch_text_channel_t channel, const char *file, const char *func, int line, const char *fmt,...)
struct switch_console_callback_match_node * head
switch_status_t switch_time_exp_lt(switch_time_exp_t *result, switch_time_t input)
switch_status_t(* switch_console_complete_callback_t)(const char *, const char *, switch_console_callback_match_t **matches)
A representation of an XML tree.
switch_status_t switch_console_list_interfaces(const char *line, const char *cursor, switch_console_callback_match_t **matches)
void switch_console_free_matches(switch_console_callback_match_t **matches)
switch_status_t switch_console_run_complete_func(const char *func, const char *line, const char *last_word, switch_console_callback_match_t **matches)
switch_xml_t switch_xml_set_txt_d(switch_xml_t xml, const char *txt)
wrapper for switch_xml_set_txt() that strdup()s txt \ sets the character content for the given tag an...
switch_status_t switch_strftime_nocheck(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm)
struct switch_console_callback_match_node * end
static switch_thread_t * thread
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
uint32_t switch_core_flag_t
void switch_console_save_history(void)
switch_status_t switch_console_del_complete_func(const char *name)
switch_status_t switch_stream_write_file_contents(switch_stream_handle_t *stream, const char *path)
switch_status_t switch_cache_db_execute_sql_callback(switch_cache_db_handle_t *dbh, const char *sql, switch_core_db_callback_func_t callback, void *pdata, char **err)
Executes the sql and uses callback for row-by-row processing.
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
void switch_cache_db_release_db_handle(switch_cache_db_handle_t **dbh)
Returns the handle to the pool, handle is NOT available to other threads until the allocating thread ...
switch_hash_t * func_hash
#define SWITCH_MUTEX_NESTED
#define SWITCH_PATH_SEPARATOR
switch_status_t switch_threadattr_detach_set(switch_threadattr_t *attr, int32_t on)
switch_byte_t switch_byte_t * buf
switch_status_t switch_console_set_alias(const char *string)
if((uint32_t)(unpack->cur - unpack->buf) > unpack->buflen)
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
unsigned int switch_separate_string(_In_ char *buf, char delim, _Post_count_(return) char **array, unsigned int arraylen)
Separate a string into an array based on a character delimiter.
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
switch_core_flag_t switch_core_flags(void)
return core flags
#define SWITCH_THREAD_STACKSIZE
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
#define switch_zmalloc(ptr, len)
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
switch_stream_handle_t * stream
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
static char * console_fnkeys[12]
#define SWITCH_CHANNEL_LOG_CLEAN
static int uuid_callback(void *pArg, int argc, char **argv, char **columnNames)
static int alias_callback(void *pArg, int argc, char **argv, char **columnNames)
int switch_vasprintf(_Out_opt_ char **buf, _In_z_ _Printf_format_string_ const char *format, _In_ va_list ap)
FILE * switch_core_data_channel(switch_text_channel_t channel)
Retrieve a FILE stream of a given text channel name.
switch_size_t switch_fp_read_dline(FILE *fd, char **buf, switch_size_t *len)
void switch_cond_next(void)
switch_status_t switch_console_stream_write(switch_stream_handle_t *handle, const char *fmt,...)
#define SWITCH_STANDARD_STREAM(s)
char * switch_copy_string(_Out_z_cap_(dst_size) char *dst, _In_z_ const char *src, _In_ switch_size_t dst_size)
static int modulename_callback(void *pArg, const char *module_name)
switch_status_t switch_cache_db_persistant_execute(switch_cache_db_handle_t *dbh, const char *sql, uint32_t retries)
switch_directories SWITCH_GLOBAL_dirs
switch_status_t switch_console_list_available_modules(const char *line, const char *cursor, switch_console_callback_match_t **matches)
switch_size_t alloc_chunk
#define switch_core_db_handle(_a)
#define switch_str_nil(s)
Make a null string a blank string instead.
struct fspr_thread_mutex_t switch_mutex_t
void switch_core_sql_exec(const char *sql)
switch_stream_handle_write_function_t write_function
switch_status_t
Common return values.
const char *const const char *const path
switch_status_t switch_console_list_loaded_modules(const char *line, const char *cursor, switch_console_callback_match_t **matches)
const cJSON *const target
void switch_console_loop(void)
A simple comand loop that reads input from the terminal.
switch_cache_db_handle_type_t switch_cache_db_get_type(switch_cache_db_handle_t *dbh)
switch_xml_t switch_xml_open_cfg(_In_z_ const char *file_path, _Out_ switch_xml_t *node, _In_opt_ switch_event_t *params)
open a config in the core registry
const char * switch_core_get_hostname(void)
#define switch_core_hash_insert(_h, _k, _d)
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
static switch_bool_t switch_is_file_path(const char *file)
unsigned char switch_console_complete(const char *line, const char *cursor, FILE *console_out, switch_stream_handle_t *stream, switch_xml_t xml)
switch_xml_t switch_xml_child(_In_ switch_xml_t xml, _In_z_ const char *name)
returns the first child tag (one level deeper) with the given name or NULL \ if not found ...
static switch_status_t console_xml_config(void)
switch_status_t switch_loadable_module_enumerate_loaded(switch_modulename_callback_func_t callback, void *user_data)
Enumerates a list of all currently loaded modules.
static int switch_console_process(char *xcmd)
switch_cache_db_handle_type_t switch_core_dbtype(void)
switch_mutex_t * func_mutex
char * switch_console_expand_alias(char *cmd, char *arg)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_status_t switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
switch_status_t switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
FILE * switch_core_get_console(void)
Get the output console.
struct fspr_pool_t switch_memory_pool_t
int32_t switch_core_session_ctl(switch_session_ctl_t cmd, void *val)
send a control message to the core
struct fspr_thread_t switch_thread_t
const char * switch_cut_path(const char *in)
Create a pointer to the file name in a given file path eliminating the directory name.
void switch_console_push_match(switch_console_callback_match_t **matches, const char *new_val)
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
char * switch_vmprintf(const char *zFormat, va_list ap)
struct switch_console_callback_match_node * next
switch_status_t switch_console_stream_raw_write(switch_stream_handle_t *handle, uint8_t *data, switch_size_t datalen)