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)) {
130 if (need >= handle->data_size) {
132 need += handle->alloc_chunk;
134 if (!(new_data = realloc(handle->data, need))) {
138 handle->data = new_data;
139 handle->data_size = need;
142 memcpy((uint8_t *) (handle->data) + handle->data_len, data, datalen);
143 handle->data_len += datalen;
144 handle->end = (uint8_t *) (handle->data) + handle->data_len;
145 *(uint8_t *) handle->end =
'\0';
153 char *
buf = handle->data;
154 char *end = handle->end;
158 if (handle->data_len >= handle->data_size) {
170 switch_size_t remaining = handle->data_size - handle->data_len;
173 if ((remaining < need) && handle->alloc_len) {
177 new_len = handle->data_size + need + handle->alloc_chunk;
178 if ((new_data = realloc(handle->data, new_len))) {
179 handle->data_size = handle->alloc_len = new_len;
180 handle->data = new_data;
182 remaining = handle->data_size - handle->data_len;
183 handle->end = (uint8_t *) (handle->data) + handle->data_len;
192 if (remaining < need) {
197 handle->data_len = strlen(buf);
198 handle->end = (uint8_t *) (handle->data) + handle->data_len;
217 if ((fd = fopen(path,
"r"))) {
218 char *line_buf = NULL;
222 stream->write_function(stream,
"%s", line_buf);
235 char **r = (
char **) pArg;
236 *r = strdup(argv[0]);
262 sql =
switch_mprintf(
"select command from aliases where alias='%q'", cmd);
264 sql =
switch_mprintf(
"select command from aliases where alias='%w'", cmd);
278 sql =
switch_mprintf(
"select command from aliases where alias='%q %q'", cmd, arg);
280 sql =
switch_mprintf(
"select command from aliases where alias='%w %w'", cmd, arg);
327 fprintf(handle,
"\n%s\n", (
char *) stream.
data);
331 if (!strcasecmp(xcmd,
"...") || !strcasecmp(xcmd,
"shutdown")) {
335 fprintf(handle,
"Unknown Command: %s\n", xcmd);
349 char *arg = NULL, *alias = NULL;
355 char *dup = strdup(xcmd);
366 if (!strncasecmp(xcmd,
"alias", 5)) {
373 for (x = 0; x < argc; x++) {
375 if ((arg = strchr(cmd,
'\r')) != 0 || (arg = strchr(cmd,
'\n')) != 0) {
379 if ((arg = strchr(cmd,
' ')) != 0) {
384 istream->write_function(istream,
"\nExpand Alias [%s]->[%s]\n\n", cmd, alias);
418 fprintf(stderr,
"Memory Error\n");
423 fprintf(handle,
"%s", data);
431 fprintf(handle,
"[%d] %s %s:%d %s() %s", (
int) getpid(), date, filep, line, func, data);
466 static int comp_callback(
void *pArg,
int argc,
char **argv,
char **columnNames)
469 char *target = NULL, *str = NULL, *
cur = NULL;
494 if (!
zstr(target) && *target ==
':' && *(target + 1) ==
':' && *(target + 2) ==
'[') {
495 char *p = target + 3, *list = NULL;
498 char *s_argv[100] = { 0 };
499 char *r_argv[1] = { 0 }, *r_cols[1] = {0};
504 for (i = 0; (int)i < argc; i++) {
505 if (!cur || !strncmp(s_argv[i], cur, strlen(cur))) {
506 r_argv[0] = s_argv[i];
515 if (!
zstr(target) && *target ==
':' && *(target + 1) ==
':') {
516 char *r_argv[1] = { 0 }, *r_cols[1] = {0};
520 for (m = matches->
head; m; m = m->
next) {
521 if (!cur || !strncmp(m->
val, cur, strlen(cur))) {
533 fprintf(h->
out,
"[%20s]\t", target);
550 for (i = 0; i < x && i < y; i++) {
556 }
else if (h->
hits == 1) {
562 if ((h->
hits % 3) == 0) {
564 if ((h->
hits % 4) == 0) {
567 fprintf(h->
out,
"\n");
624 #ifdef HAVE_GETIFADDRS
630 struct ifaddrs *addrs, *addr;
633 for(addr = addrs; addr; addr = addr->ifa_next) {
634 if (addr->ifa_flags & IFF_UP) {
654 static int uuid_callback(
void *pArg,
int argc,
char **argv,
char **columnNames)
678 sql =
switch_mprintf(
"select distinct uuid from channels where uuid like '%q%%' and hostname='%q' order by uuid",
704 char *dup = strdup(line);
727 pos = (int)(cursor - line);
738 if ((p = strchr(buf,
'\r')) || (p = strchr(buf,
'\n'))) {
742 while (*buf ==
' ') {
750 el_deletestr(el, sc);
757 while (p >= buf && *p ==
' ') {
765 el_deletestr(el, sc - 1);
771 for (p = buf; p && *p; p++) {
786 h.
len = (int)strlen(buf);
789 fprintf(h.
out,
"\n\n");
799 sql =
switch_mprintf(
"select distinct name from interfaces where type='api' and name like '%q%%' and hostname='%q' order by name",
817 char *dupdup = strdup(dup);
819 char *argv[10] = { 0 };
827 stream.
write_function(&stream,
"select distinct a1 from complete where " "a1 not in (select name from interfaces where hostname='%s') %s ",
837 for (x = 0; x < argc && x < 11; x++) {
838 if (h.
words + 1 > argc) {
840 stream.
write_function(&stream,
"(a%d like '::%%' or a%d = '' or a%d = '%q')%q",
841 x + 1, x + 1, x + 1,
switch_str_nil(argv[x]), x == argc - 1 ?
"" :
" and ");
843 stream.
write_function(&stream,
"(a%d like '::%%' or a%d = '' or a%d = '%w')%w",
844 x + 1, x + 1, x + 1,
switch_str_nil(argv[x]), x == argc - 1 ?
"" :
" and ");
848 stream.
write_function(&stream,
"(a%d like '::%%' or a%d = '' or a%d like '%q%%')%q",
849 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 '%w%%')%w",
852 x + 1, x + 1, x + 1,
switch_str_nil(argv[x]), x == argc - 1 ?
"" :
" and ");
876 fprintf(h.
out,
"\n\n");
892 snprintf(buf,
sizeof(buf),
"%d", h.
len);
904 el_deletestr(el, h.
len);
905 el_insertstr(el, h.
last);
906 el_insertstr(el,
" ");
908 el_deletestr(el, h.
len);
916 console_bufferInput(0, h.
len, (
char *) line, DELETE_REFRESH_OP);
917 console_bufferInput(h.
last, (
int) strlen(h.
last), (
char *) line, 0);
918 console_bufferInput(
" ", 1, (
char *) line, 0);
920 console_bufferInput(0, h.
len, (
char *) line, DELETE_REFRESH_OP);
921 console_bufferInput(h.
partial, (
int) strlen(h.
partial), (
char *) line, 0);
923 console_bufferInput(0, 0, (
char *) line, DELETE_REFRESH_OP);
944 #if defined(HAVE_LIBEDIT) || defined(_MSC_VER)
948 static unsigned char console_fnkey_pressed(
int i)
975 history(myhistory, &ev, H_SAVE, hfile);
982 static char prompt_str[512] =
"";
984 static unsigned char console_f1key(EditLine * el,
int ch)
986 return console_fnkey_pressed(1);
988 static unsigned char console_f2key(EditLine * el,
int ch)
990 return console_fnkey_pressed(2);
992 static unsigned char console_f3key(EditLine * el,
int ch)
994 return console_fnkey_pressed(3);
996 static unsigned char console_f4key(EditLine * el,
int ch)
998 return console_fnkey_pressed(4);
1000 static unsigned char console_f5key(EditLine * el,
int ch)
1002 return console_fnkey_pressed(5);
1004 static unsigned char console_f6key(EditLine * el,
int ch)
1006 return console_fnkey_pressed(6);
1008 static unsigned char console_f7key(EditLine * el,
int ch)
1010 return console_fnkey_pressed(7);
1012 static unsigned char console_f8key(EditLine * el,
int ch)
1014 return console_fnkey_pressed(8);
1016 static unsigned char console_f9key(EditLine * el,
int ch)
1018 return console_fnkey_pressed(9);
1020 static unsigned char console_f10key(EditLine * el,
int ch)
1022 return console_fnkey_pressed(10);
1024 static unsigned char console_f11key(EditLine * el,
int ch)
1026 return console_fnkey_pressed(11);
1028 static unsigned char console_f12key(EditLine * el,
int ch)
1030 return console_fnkey_pressed(12);
1034 char *prompt(EditLine * e)
1036 if (*prompt_str ==
'\0') {
1052 if (getppid() == 1) {
1062 line = el_gets(el, &count);
1066 char *cmd = strdup(line);
1068 const LineInfo *lf = el_line(el);
1069 char *foo = (
char *) lf->buffer;
1070 if ((p = strrchr(cmd,
'\r')) || (p = strrchr(cmd,
'\n'))) {
1073 assert(cmd != NULL);
1074 history(myhistory, &ev, H_ENTER, line);
1076 el_deletestr(el, strlen(foo) + 1);
1077 memset(foo, 0, strlen(foo));
1089 static unsigned char complete(EditLine * el,
int ch)
1091 const LineInfo *lf = el_line(el);
1109 el_set(el, EL_PROMPT, &prompt);
1110 el_set(el, EL_EDITOR,
"emacs");
1118 el_set(el, EL_ADDFN,
"f1-key",
"F1 KEY PRESS", console_f1key);
1119 el_set(el, EL_ADDFN,
"f2-key",
"F2 KEY PRESS", console_f2key);
1120 el_set(el, EL_ADDFN,
"f3-key",
"F3 KEY PRESS", console_f3key);
1121 el_set(el, EL_ADDFN,
"f4-key",
"F4 KEY PRESS", console_f4key);
1122 el_set(el, EL_ADDFN,
"f5-key",
"F5 KEY PRESS", console_f5key);
1123 el_set(el, EL_ADDFN,
"f6-key",
"F6 KEY PRESS", console_f6key);
1124 el_set(el, EL_ADDFN,
"f7-key",
"F7 KEY PRESS", console_f7key);
1125 el_set(el, EL_ADDFN,
"f8-key",
"F8 KEY PRESS", console_f8key);
1126 el_set(el, EL_ADDFN,
"f9-key",
"F9 KEY PRESS", console_f9key);
1127 el_set(el, EL_ADDFN,
"f10-key",
"F10 KEY PRESS", console_f10key);
1128 el_set(el, EL_ADDFN,
"f11-key",
"F11 KEY PRESS", console_f11key);
1129 el_set(el, EL_ADDFN,
"f12-key",
"F12 KEY PRESS", console_f12key);
1131 el_set(el, EL_BIND,
"\033OP",
"f1-key", NULL);
1132 el_set(el, EL_BIND,
"\033OQ",
"f2-key", NULL);
1133 el_set(el, EL_BIND,
"\033OR",
"f3-key", NULL);
1134 el_set(el, EL_BIND,
"\033OS",
"f4-key", NULL);
1137 el_set(el, EL_BIND,
"\033[11~",
"f1-key", NULL);
1138 el_set(el, EL_BIND,
"\033[12~",
"f2-key", NULL);
1139 el_set(el, EL_BIND,
"\033[13~",
"f3-key", NULL);
1140 el_set(el, EL_BIND,
"\033[14~",
"f4-key", NULL);
1141 el_set(el, EL_BIND,
"\033[15~",
"f5-key", NULL);
1142 el_set(el, EL_BIND,
"\033[17~",
"f6-key", NULL);
1143 el_set(el, EL_BIND,
"\033[18~",
"f7-key", NULL);
1144 el_set(el, EL_BIND,
"\033[19~",
"f8-key", NULL);
1145 el_set(el, EL_BIND,
"\033[20~",
"f9-key", NULL);
1146 el_set(el, EL_BIND,
"\033[21~",
"f10-key", NULL);
1147 el_set(el, EL_BIND,
"\033[23~",
"f11-key", NULL);
1148 el_set(el, EL_BIND,
"\033[24~",
"f12-key", NULL);
1151 el_set(el, EL_ADDFN,
"ed-complete",
"Complete argument", complete);
1152 el_set(el, EL_BIND,
"^I",
"ed-complete", NULL);
1155 el_set(el, EL_BIND,
"\033[3~",
"ed-delete-next-char", NULL);
1157 myhistory = history_init();
1158 if (myhistory == 0) {
1159 fprintf(stderr,
"history could not be initialized\n");
1164 assert(hfile != NULL);
1166 history(myhistory, &ev, H_SETSIZE, 800);
1167 el_set(el, EL_HIST, history, myhistory);
1168 history(myhistory, &ev, H_LOAD, hfile);
1170 el_source(el, NULL);
1186 history(myhistory, &ev, H_SAVE, hfile);
1190 history_end(myhistory);
1199 int iHistorySel = 0;
1201 static int console_history(
char *cmd,
int direction)
1206 if (direction == 0) {
1208 if (iHistory < HISTLEN) {
1209 if (iHistory && strcmp(history[iHistory - 1], cmd)) {
1210 iHistorySel = iHistory;
1211 strcpy(history[iHistory++], cmd);
1212 }
else if (iHistory == 0) {
1213 iHistorySel = iHistory;
1214 strcpy(history[iHistory++], cmd);
1217 iHistory = HISTLEN - 1;
1218 for (i = 0; i < HISTLEN - 1; i++) {
1219 strcpy(history[i], history[i + 1]);
1221 iHistorySel = iHistory;
1222 strcpy(history[iHistory++], cmd);
1226 iHistorySel += direction;
1229 if (iHistorySel < 0) {
1232 if (iHistory && iHistorySel >= iHistory) {
1233 iHistorySel = iHistory - 1;
1235 strcpy(cmd, history[iHistorySel]);
1240 static int console_bufferInput(
char *addchars,
int len,
char *cmd,
int key)
1242 static int iCmdBuffer = 0;
1243 static int iCmdCursor = 0;
1244 static int ignoreNext = 0;
1245 static int insertMode = 1;
1246 static COORD orgPosition;
1247 static char prompt[80];
1252 CONSOLE_SCREEN_BUFFER_INFO info;
1254 hOut = GetStdHandle(STD_OUTPUT_HANDLE);
1255 GetConsoleScreenBufferInfo(hOut, &info);
1256 position = info.dwCursorPosition;
1257 if (iCmdCursor == 0) {
1258 orgPosition = position;
1261 if (key == PROMPT_OP) {
1262 if (strlen(cmd) <
sizeof(prompt)) {
1263 strcpy(prompt, cmd);
1268 if (key == KEY_TAB) {
1272 if (key == KEY_UP || key == KEY_DOWN || key == CLEAR_OP) {
1273 SetConsoleCursorPosition(hOut, orgPosition);
1274 for (i = 0; i < (int) strlen(cmd); i++) {
1277 SetConsoleCursorPosition(hOut, orgPosition);
1282 if (key == DELETE_REFRESH_OP) {
1283 int l = len < (int) strlen(cmd) ? len : (int) strlen(cmd);
1284 for (i = 0; i < l; i++) {
1285 cmd[--iCmdBuffer] = 0;
1287 iCmdCursor = (int) strlen(cmd);
1288 printf(
"%s", prompt);
1289 GetConsoleScreenBufferInfo(hOut, &info);
1290 orgPosition = info.dwCursorPosition;
1295 if (key == KEY_LEFT) {
1297 if (position.X == 0) {
1299 position.X = info.dwSize.X - 1;
1304 SetConsoleCursorPosition(hOut, position);
1308 if (key == KEY_RIGHT) {
1309 if (iCmdCursor < (
int) strlen(cmd)) {
1310 if (position.X == info.dwSize.X - 1) {
1317 SetConsoleCursorPosition(hOut, position);
1321 if (key == KEY_INSERT) {
1322 insertMode = !insertMode;
1324 if (key == KEY_DELETE) {
1325 if (iCmdCursor < iCmdBuffer) {
1327 for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
1328 cmd[pos] = cmd[pos + 1];
1333 for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
1334 printf(
"%c", cmd[pos]);
1337 SetConsoleCursorPosition(hOut, position);
1340 for (iBuf = 0; iBuf <
len; iBuf++) {
1341 switch (addchars[iBuf]) {
1347 int ret = iCmdBuffer;
1348 if (iCmdBuffer == 0) {
1349 strcpy(cmd,
"Empty");
1350 ret = (int) strlen(cmd);
1352 console_history(cmd, 0);
1353 cmd[iCmdBuffer] = 0;
1363 if (position.X == 0) {
1365 position.X = info.dwSize.X - 1;
1366 SetConsoleCursorPosition(hOut, position);
1369 SetConsoleCursorPosition(hOut, position);
1372 if (iCmdCursor < iCmdBuffer) {
1375 for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
1376 cmd[pos] = cmd[pos + 1];
1381 SetConsoleCursorPosition(hOut, position);
1382 for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
1383 printf(
"%c", cmd[pos]);
1386 SetConsoleCursorPosition(hOut, position);
1388 SetConsoleCursorPosition(hOut, position);
1391 cmd[iCmdBuffer] = 0;
1397 if (iCmdCursor < iCmdBuffer) {
1400 if (position.X == info.dwSize.X - 1) {
1408 for (pos = iCmdBuffer - 1; pos >= iCmdCursor; pos--) {
1409 cmd[pos + 1] = cmd[pos];
1413 cmd[iCmdCursor++] = addchars[iBuf];
1414 printf(
"%c", addchars[iBuf]);
1415 for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
1416 GetConsoleScreenBufferInfo(hOut, &info);
1417 if (info.dwCursorPosition.X == info.dwSize.X - 1 && info.dwCursorPosition.Y == info.dwSize.Y - 1) {
1421 printf(
"%c", cmd[pos]);
1423 SetConsoleCursorPosition(hOut, position);
1425 if (position.X == info.dwSize.X - 1 && position.Y == info.dwSize.Y - 1) {
1428 cmd[iCmdBuffer++] = addchars[iBuf];
1430 printf(
"%c", addchars[iBuf]);
1435 printf(
"Read Console... BUFFER OVERRUN\n");
1444 static BOOL console_readConsole(HANDLE conIn,
char *
buf,
int len,
int *pRed,
int *key)
1446 DWORD recordIndex, bufferIndex, toRead = 0, red;
1447 PINPUT_RECORD pInput;
1449 GetNumberOfConsoleInputEvents(conIn, &toRead);
1450 if (len < (
int) toRead) {
1457 if ((pInput = (PINPUT_RECORD) malloc(toRead *
sizeof(INPUT_RECORD))) == NULL) {
1461 ReadConsoleInput(conIn, pInput, toRead, &red);
1463 for (recordIndex = bufferIndex = 0; recordIndex < red; recordIndex++) {
1464 KEY_EVENT_RECORD keyEvent = pInput[recordIndex].Event.KeyEvent;
1465 if (pInput[recordIndex].EventType == KEY_EVENT && keyEvent.bKeyDown) {
1466 if (keyEvent.wVirtualKeyCode == 38 && keyEvent.wVirtualScanCode == 72) {
1468 console_history(buf, -1);
1470 bufferIndex += (DWORD) strlen(buf);
1472 if (keyEvent.wVirtualKeyCode == 40 && keyEvent.wVirtualScanCode == 80) {
1474 console_history(buf, 1);
1476 bufferIndex += (DWORD) strlen(buf);
1478 if (keyEvent.wVirtualKeyCode == 112 && keyEvent.wVirtualScanCode == 59) {
1479 console_fnkey_pressed(1);
1481 if (keyEvent.wVirtualKeyCode == 113 && keyEvent.wVirtualScanCode == 60) {
1482 console_fnkey_pressed(2);
1484 if (keyEvent.wVirtualKeyCode == 114 && keyEvent.wVirtualScanCode == 61) {
1485 console_fnkey_pressed(3);
1487 if (keyEvent.wVirtualKeyCode == 115 && keyEvent.wVirtualScanCode == 62) {
1488 console_fnkey_pressed(4);
1490 if (keyEvent.wVirtualKeyCode == 116 && keyEvent.wVirtualScanCode == 63) {
1491 console_fnkey_pressed(5);
1493 if (keyEvent.wVirtualKeyCode == 117 && keyEvent.wVirtualScanCode == 64) {
1494 console_fnkey_pressed(6);
1496 if (keyEvent.wVirtualKeyCode == 118 && keyEvent.wVirtualScanCode == 65) {
1497 console_fnkey_pressed(7);
1499 if (keyEvent.wVirtualKeyCode == 119 && keyEvent.wVirtualScanCode == 66) {
1500 console_fnkey_pressed(8);
1502 if (keyEvent.wVirtualKeyCode == 120 && keyEvent.wVirtualScanCode == 67) {
1503 console_fnkey_pressed(9);
1505 if (keyEvent.wVirtualKeyCode == 121 && keyEvent.wVirtualScanCode == 68) {
1506 console_fnkey_pressed(10);
1508 if (keyEvent.wVirtualKeyCode == 122 && keyEvent.wVirtualScanCode == 87) {
1509 console_fnkey_pressed(11);
1511 if (keyEvent.wVirtualKeyCode == 123 && keyEvent.wVirtualScanCode == 88) {
1512 console_fnkey_pressed(12);
1514 if (keyEvent.uChar.AsciiChar == 9) {
1518 if (keyEvent.uChar.AsciiChar == 27) {
1522 if (keyEvent.wVirtualKeyCode == 37 && keyEvent.wVirtualScanCode == 75) {
1525 if (keyEvent.wVirtualKeyCode == 39 && keyEvent.wVirtualScanCode == 77) {
1528 if (keyEvent.wVirtualKeyCode == 45 && keyEvent.wVirtualScanCode == 82) {
1531 if (keyEvent.wVirtualKeyCode == 46 && keyEvent.wVirtualScanCode == 83) {
1534 while (keyEvent.wRepeatCount && keyEvent.uChar.AsciiChar) {
1535 buf[bufferIndex] = keyEvent.uChar.AsciiChar;
1536 if (buf[bufferIndex] ==
'\r') {
1537 buf[bufferIndex] =
'\n';
1540 keyEvent.wRepeatCount--;
1546 *pRed = bufferIndex;
1555 int32_t activity = 1;
1567 console_bufferInput(0, 0, cmd, PROMPT_OP);
1568 memset(cmd, 0,
sizeof(cmd));
1575 HANDLE stdinHandle = GetStdHandle(STD_INPUT_HANDLE);
1578 struct timeval tv = { 0, 20000 };
1591 if (console_readConsole(stdinHandle, keys, (
int)
sizeof(keys), &read, &key)) {
1592 if (console_bufferInput(keys, read, cmd, key)) {
1593 if (!strcmp(cmd,
"Empty")) {
1600 memset(cmd, 0,
sizeof(cmd));
1607 FD_SET(fileno(stdin), &rfds);
1608 FD_SET(fileno(stdin), &efds);
1609 if ((activity = select(fileno(stdin) + 1, &rfds, NULL, &efds, &tv)) < 0) {
1613 if (FD_ISSET(fileno(stdin), &efds)) {
1617 if (!FD_ISSET(fileno(stdin), &rfds)) {
1621 if (activity == 0) {
1626 memset(&cmd, 0,
sizeof(cmd));
1627 for (x = 0; x < (
sizeof(cmd) - 1); x++) {
1630 int y = read(fileno(stdin), cmd,
sizeof(cmd) - 1);
1637 if (cmd[x] ==
'\n') {
1726 if (matches->count < 2) {
1730 for (i = 1; i < matches->count; i++) {
1732 sort[1] = matches->head;
1733 sort[2] = sort[1] ? sort[1]->next : NULL;
1734 sort[3] = sort[2] ? sort[2]->next : NULL;
1736 for (j = 1; j <= (matches->count - i); j++) {
1738 if (strcmp(sort[1]->val, sort[2]->val) > 0) {
1739 sort[1]->next = sort[3];
1740 sort[2]->next = sort[1];
1743 sort[0]->next = sort[2];
1744 if (sort[1] == matches->head)
1745 matches->head = sort[2];
1751 sort[2] = sort[1]->next;
1752 if (sort[3] && sort[3]->next)
1753 sort[3] = sort[3]->next;
1759 if (sort[3] && sort[3]->next)
1760 sort[3] = sort[3]->next;
1768 for (i = 1; i < matches->count; i++)
1783 for(node = (*matches)->head; node; node = node->
next) {
1784 if (!strcasecmp(node->
val, new_val))
return;
1797 (*matches)->dynamic = 1;
1801 match->
val = strdup(new_val);
1803 if ((*matches)->head) {
1804 (*matches)->end->next = match;
1806 (*matches)->head = match;
1809 (*matches)->count++;
1811 (*matches)->end = match;
1834 char *mydata = NULL, *argv[11] = { 0 };
1843 if (
string && (mydata = strdup(
string))) {
1848 if (!strcasecmp(argv[0],
"stickyadd")) {
1849 mystream.
write_function(&mystream,
"insert into complete values (1,");
1850 for (x = 0; x < 10; x++) {
1851 if (argv[x + 1] && !strcasecmp(argv[x + 1],
"_any_")) {
1864 }
else if (!strcasecmp(argv[0],
"add")) {
1865 mystream.
write_function(&mystream,
"insert into complete values (0,");
1866 for (x = 0; x < 10; x++) {
1867 if (argv[x + 1] && !strcasecmp(argv[x + 1],
"_any_")) {
1881 }
else if (!strcasecmp(argv[0],
"del")) {
1882 char *what = argv[1];
1887 }
else if (!strcasecmp(what,
"*")) {
1891 mystream.
write_function(&mystream,
"delete from complete where ");
1892 for (x = 0; x < argc - 1; x++) {
1918 char *mydata = NULL, *argv[3] = { 0 };
1922 if (
string && (mydata = strdup(
string))) {
1927 if (argc > 2 && !strcmp(argv[1], argv[2])) {
1938 if (!strcasecmp(argv[0],
"stickyadd") && argc == 3) {
1943 sql =
switch_mprintf(
"insert into aliases (sticky, alias, command, hostname) values (1, '%q','%q','%q')",
1946 sql =
switch_mprintf(
"insert into aliases (sticky, alias, command, hostname) values (1, '%w','%w','%w')",
1951 }
else if (!strcasecmp(argv[0],
"add") && argc == 3) {
1956 sql =
switch_mprintf(
"insert into aliases (sticky, alias, command, hostname) values (0, '%q','%q','%q')",
1959 sql =
switch_mprintf(
"insert into aliases (sticky, alias, command, hostname) values (0, '%w','%w','%w')",
1964 }
else if (!strcasecmp(argv[0],
"del") && argc == 2) {
1965 char *what = argv[1];
1966 if (!strcasecmp(what,
"*")) {
#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_console_complete_callback_t)(const char *, const char *, switch_console_callback_match_t **matches)
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.
#define switch_xml_add_child_d(xml, name, off)
wrapper for switch_xml_add_child() that strdup()s name
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)
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_status_t switch_strftime_nocheck(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm)
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)
if((uint32_t)(unpack->cur-unpack->buf) > unpack->buflen)
switch_byte_t switch_byte_t * buf
switch_status_t switch_console_set_alias(const char *string)
#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)
#define switch_core_db_handle(_a)
#define switch_str_nil(s)
Make a null string a blank string instead.
void switch_core_sql_exec(const char *sql)
#define switch_xml_set_attr_d_buf(xml, name, value)
switch_stream_handle_write_function_t write_function
struct apr_thread_mutex_t switch_mutex_t
switch_status_t
Common return values.
switch_status_t switch_console_list_loaded_modules(const char *line, const char *cursor, switch_console_callback_match_t **matches)
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)
struct apr_thread_t switch_thread_t
#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)
#define switch_xml_set_txt_d(xml, txt)
wrapper for switch_xml_set_txt() that strdup()s txt \ sets the character content for the given tag an...
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)
struct apr_pool_t switch_memory_pool_t
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.
int32_t switch_core_session_ctl(switch_session_ctl_t cmd, void *val)
send a control message to the core
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)