mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-17 01:02:12 +00:00
update
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8176 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
1fb841bf6b
commit
0564d81e09
@ -1600,6 +1600,7 @@ SWITCH_DECLARE(switch_bool_t) switch_check_network_list_ip(const char *ip_str, c
|
|||||||
SWITCH_DECLARE(void) switch_time_set_monotonic(switch_bool_t enable);
|
SWITCH_DECLARE(void) switch_time_set_monotonic(switch_bool_t enable);
|
||||||
SWITCH_DECLARE(uint32_t) switch_core_max_dtmf_duration(uint32_t duration);
|
SWITCH_DECLARE(uint32_t) switch_core_max_dtmf_duration(uint32_t duration);
|
||||||
SWITCH_DECLARE(uint32_t) switch_core_default_dtmf_duration(uint32_t duration);
|
SWITCH_DECLARE(uint32_t) switch_core_default_dtmf_duration(uint32_t duration);
|
||||||
|
SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string);
|
||||||
|
|
||||||
///\}
|
///\}
|
||||||
|
|
||||||
|
@ -1888,45 +1888,16 @@ static int show_callback(void *pArg, int argc, char **argv, char **columnNames)
|
|||||||
#define COMPLETE_SYNTAX "add <word>|del [<word>|all]"
|
#define COMPLETE_SYNTAX "add <word>|del [<word>|all]"
|
||||||
SWITCH_STANDARD_API(complete_function)
|
SWITCH_STANDARD_API(complete_function)
|
||||||
{
|
{
|
||||||
char *mydata = NULL, *argv[2] = {0};
|
|
||||||
int fail = 1, argc;
|
|
||||||
char sql[1024] = "";
|
|
||||||
|
|
||||||
if (cmd && (mydata = strdup(cmd))) {
|
switch_status_t status;
|
||||||
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
|
|
||||||
switch_core_db_t *db = switch_core_db_handle();
|
|
||||||
|
|
||||||
if (!strcasecmp(argv[0], "add")) {
|
|
||||||
switch_snprintf(sql, sizeof(sql), "delete from complete where name = '%s'", argv[1]);
|
|
||||||
switch_core_db_persistant_execute(db, sql, 1);
|
|
||||||
switch_snprintf(sql, sizeof(sql), "insert into complete values ('%s')", argv[1]);
|
|
||||||
switch_core_db_persistant_execute(db, sql, 1);
|
|
||||||
stream->write_function(stream, "+OK\n");
|
|
||||||
fail = 0;
|
|
||||||
} else if (!strcasecmp(argv[0], "del")) {
|
|
||||||
char *what = argv[1];
|
|
||||||
if (!strcasecmp(what, "*")) {
|
|
||||||
switch_snprintf(sql, sizeof(sql), "delete from complete");
|
|
||||||
} else {
|
|
||||||
switch_snprintf(sql, sizeof(sql), "delete from complete where name = '%s'", what);
|
|
||||||
}
|
|
||||||
switch_core_db_persistant_execute(db, sql, 1);
|
|
||||||
stream->write_function(stream, "+OK\n");
|
|
||||||
fail = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch_core_db_close(db);
|
if ((status = switch_console_set_complete(cmd)) == SWITCH_STATUS_SUCCESS) {
|
||||||
}
|
stream->write_function(stream, "+OK\n");
|
||||||
}
|
} else {
|
||||||
|
|
||||||
switch_safe_free(mydata);
|
|
||||||
|
|
||||||
if (fail) {
|
|
||||||
stream->write_function(stream, "-USAGE: %s\n", COMPLETE_SYNTAX);
|
stream->write_function(stream, "-USAGE: %s\n", COMPLETE_SYNTAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SHOW_SYNTAX "codec|application|api|dialplan|file|timer|calls|channels"
|
#define SHOW_SYNTAX "codec|application|api|dialplan|file|timer|calls|channels"
|
||||||
|
@ -371,6 +371,7 @@ struct helper {
|
|||||||
EditLine *el;
|
EditLine *el;
|
||||||
int len;
|
int len;
|
||||||
int hits;
|
int hits;
|
||||||
|
int words;
|
||||||
char last[512];
|
char last[512];
|
||||||
FILE *out;
|
FILE *out;
|
||||||
};
|
};
|
||||||
@ -378,10 +379,17 @@ struct helper {
|
|||||||
static int comp_callback(void *pArg, int argc, char **argv, char **columnNames)
|
static int comp_callback(void *pArg, int argc, char **argv, char **columnNames)
|
||||||
{
|
{
|
||||||
struct helper *h = (struct helper *) pArg;
|
struct helper *h = (struct helper *) pArg;
|
||||||
|
char *target = NULL;
|
||||||
fprintf(h->out, "%20s\t", argv[0]);
|
|
||||||
|
|
||||||
switch_copy_string(h->last, argv[0], sizeof(h->last));
|
target = argv[0];
|
||||||
|
|
||||||
|
if (!target) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(h->out, "%20s\t", target);
|
||||||
|
|
||||||
|
switch_copy_string(h->last, target, sizeof(h->last));
|
||||||
|
|
||||||
if ((++h->hits % 4) == 0) {
|
if ((++h->hits % 4) == 0) {
|
||||||
fprintf(h->out, "\n");
|
fprintf(h->out, "\n");
|
||||||
@ -400,7 +408,6 @@ static unsigned char complete(EditLine *el, int ch)
|
|||||||
char *p, *lp = NULL;
|
char *p, *lp = NULL;
|
||||||
char *errmsg = NULL;
|
char *errmsg = NULL;
|
||||||
struct helper h = { el };
|
struct helper h = { el };
|
||||||
int words = 0;
|
|
||||||
unsigned char ret = CC_REDISPLAY;
|
unsigned char ret = CC_REDISPLAY;
|
||||||
|
|
||||||
h.out = switch_core_get_console();
|
h.out = switch_core_get_console();
|
||||||
@ -416,7 +423,7 @@ static unsigned char complete(EditLine *el, int ch)
|
|||||||
for(p = buf; p && *p; p++) {
|
for(p = buf; p && *p; p++) {
|
||||||
if (*p == ' ') {
|
if (*p == ' ') {
|
||||||
lp = p;
|
lp = p;
|
||||||
words++;
|
h.words++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -428,7 +435,7 @@ static unsigned char complete(EditLine *el, int ch)
|
|||||||
|
|
||||||
fprintf(h.out, "\n\n");
|
fprintf(h.out, "\n\n");
|
||||||
|
|
||||||
if (words == 0) {
|
if (h.words == 0) {
|
||||||
sql = switch_mprintf("select distinct name from interfaces where type='api' and name like '%s%%' order by name", buf);
|
sql = switch_mprintf("select distinct name from interfaces where type='api' and name like '%s%%' order by name", buf);
|
||||||
} else {
|
} else {
|
||||||
sql = switch_mprintf("select distinct uuid from channels where uuid like '%s%%' order by uuid", buf);
|
sql = switch_mprintf("select distinct uuid from channels where uuid like '%s%%' order by uuid", buf);
|
||||||
@ -444,14 +451,42 @@ static unsigned char complete(EditLine *el, int ch)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (h.hits != 1) {
|
if (h.hits != 1) {
|
||||||
switch_safe_free(sql);
|
char *dupdup = strdup(dup);
|
||||||
sql = switch_mprintf("select distinct name from complete where name like '%s%%' order by name", buf);
|
switch_assert(dupdup);
|
||||||
switch_core_db_exec(db, sql, comp_callback, &h, &errmsg);
|
int x, argc = 0;
|
||||||
|
char *argv[10] = {0};
|
||||||
|
switch_stream_handle_t stream = { 0 };
|
||||||
|
SWITCH_STANDARD_STREAM(stream);
|
||||||
|
|
||||||
|
|
||||||
|
argc = switch_separate_string(dupdup, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||||
|
|
||||||
|
if (h.words == 0) {
|
||||||
|
stream.write_function(&stream,
|
||||||
|
"select distinct a1 from complete where "
|
||||||
|
"a1 not in (select name from interfaces) and ");
|
||||||
|
} else {
|
||||||
|
stream.write_function(&stream,
|
||||||
|
"select distinct a%d from complete where ", h.words + 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for(x = 0; x < argc; x++) {
|
||||||
|
stream.write_function(&stream, "(a%d = '' or a%d like '%s%%')%s", x+1, x+1, switch_str_nil(argv[x]), x == argc -1 ? "" : " and ");
|
||||||
|
}
|
||||||
|
|
||||||
|
switch_core_db_exec(db, stream.data, comp_callback, &h, &errmsg);
|
||||||
|
|
||||||
if (errmsg) {
|
if (errmsg) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error [%s][%s]\n", sql, errmsg);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error [%s][%s]\n", (char *) stream.data, errmsg);
|
||||||
free(errmsg);
|
free(errmsg);
|
||||||
ret = CC_ERROR;
|
ret = CC_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch_safe_free(dupdup);
|
||||||
|
switch_safe_free(stream.data);
|
||||||
|
|
||||||
|
if (ret == CC_ERROR) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -475,6 +510,51 @@ static unsigned char complete(EditLine *el, int ch)
|
|||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string)
|
||||||
|
{
|
||||||
|
char *mydata = NULL, *argv[11] = {0};
|
||||||
|
int argc, x;
|
||||||
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||||
|
|
||||||
|
if (string && (mydata = strdup(string))) {
|
||||||
|
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
|
||||||
|
switch_core_db_t *db = switch_core_db_handle();
|
||||||
|
switch_stream_handle_t mystream = { 0 };
|
||||||
|
SWITCH_STANDARD_STREAM(mystream);
|
||||||
|
|
||||||
|
if (!strcasecmp(argv[0], "add")) {
|
||||||
|
mystream.write_function(&mystream, "insert into complete values (");
|
||||||
|
for(x = 0; x < 10; x++) {
|
||||||
|
mystream.write_function(&mystream, "'%s'%s", switch_str_nil(argv[x+1]), x == 9 ? ")" : ", ");
|
||||||
|
}
|
||||||
|
switch_core_db_persistant_execute(db, mystream.data, 1);
|
||||||
|
status = SWITCH_STATUS_SUCCESS;
|
||||||
|
} else if (!strcasecmp(argv[0], "del")) {
|
||||||
|
char *what = argv[1];
|
||||||
|
if (!strcasecmp(what, "*")) {
|
||||||
|
switch_core_db_persistant_execute(db, "delete from complete", 1);
|
||||||
|
} else {
|
||||||
|
mystream.write_function(&mystream, "delete from complete where ");
|
||||||
|
for(x = 0; x < argc - 1; x++) {
|
||||||
|
mystream.write_function(&mystream, "a%d = '%s'%s", x+1, switch_str_nil(argv[x+1]), x == argc - 2 ? "" : " and ");
|
||||||
|
}
|
||||||
|
switch_core_db_persistant_execute(db, mystream.data, 1);
|
||||||
|
}
|
||||||
|
status = SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
switch_safe_free(mystream.data);
|
||||||
|
switch_core_db_close(db);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch_safe_free(mydata);
|
||||||
|
|
||||||
|
return status;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SWITCH_DECLARE(void) switch_console_loop(void)
|
SWITCH_DECLARE(void) switch_console_loop(void)
|
||||||
{
|
{
|
||||||
switch_thread_t *thread;
|
switch_thread_t *thread;
|
||||||
|
@ -368,7 +368,16 @@ void switch_core_sqldb_start(switch_memory_pool_t *pool)
|
|||||||
} else {
|
} else {
|
||||||
char create_complete_sql[] =
|
char create_complete_sql[] =
|
||||||
"CREATE TABLE complete (\n"
|
"CREATE TABLE complete (\n"
|
||||||
" name VARCHAR(255)\n"
|
" a1 VARCHAR(255),\n"
|
||||||
|
" a2 VARCHAR(255),\n"
|
||||||
|
" a3 VARCHAR(255),\n"
|
||||||
|
" a4 VARCHAR(255),\n"
|
||||||
|
" a5 VARCHAR(255),\n"
|
||||||
|
" a6 VARCHAR(255),\n"
|
||||||
|
" a7 VARCHAR(255),\n"
|
||||||
|
" a8 VARCHAR(255),\n"
|
||||||
|
" a9 VARCHAR(255),\n"
|
||||||
|
" a10 VARCHAR(255)\n"
|
||||||
");\n";
|
");\n";
|
||||||
|
|
||||||
char create_channels_sql[] =
|
char create_channels_sql[] =
|
||||||
@ -430,7 +439,7 @@ void switch_core_sqldb_start(switch_memory_pool_t *pool)
|
|||||||
switch_core_db_exec(sql_manager.db, "PRAGMA cache_size=8000", NULL, NULL, NULL);
|
switch_core_db_exec(sql_manager.db, "PRAGMA cache_size=8000", NULL, NULL, NULL);
|
||||||
switch_core_db_exec(sql_manager.db, "PRAGMA temp_store=MEMORY;", NULL, NULL, NULL);
|
switch_core_db_exec(sql_manager.db, "PRAGMA temp_store=MEMORY;", NULL, NULL, NULL);
|
||||||
|
|
||||||
switch_core_db_exec(sql_manager.db, create_complete_sql, NULL, NULL, NULL);
|
switch_core_db_test_reactive(sql_manager.db, "select a1 from complete", "DROP TABLE complete", create_complete_sql);
|
||||||
switch_core_db_exec(sql_manager.db, create_channels_sql, NULL, NULL, NULL);
|
switch_core_db_exec(sql_manager.db, create_channels_sql, NULL, NULL, NULL);
|
||||||
switch_core_db_exec(sql_manager.db, create_calls_sql, NULL, NULL, NULL);
|
switch_core_db_exec(sql_manager.db, create_calls_sql, NULL, NULL, NULL);
|
||||||
switch_core_db_exec(sql_manager.db, create_interfaces_sql, NULL, NULL, NULL);
|
switch_core_db_exec(sql_manager.db, create_interfaces_sql, NULL, NULL, NULL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user