forked from Mirrors/freeswitch
add console_complete_xml api
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@15967 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
7d6ff98fc6
commit
d2c72cf569
@ -85,7 +85,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_run_complete_func(const char *fun
|
||||
const char *last_word, switch_console_callback_match_t **matches);
|
||||
SWITCH_DECLARE(void) switch_console_push_match(switch_console_callback_match_t **matches, const char *new_val);
|
||||
SWITCH_DECLARE(void) switch_console_free_matches(switch_console_callback_match_t **matches);
|
||||
SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const char *last_word, FILE *console_out, switch_stream_handle_t *stream);
|
||||
SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const char *cursor, FILE *console_out, switch_stream_handle_t *stream, switch_xml_t xml);
|
||||
|
||||
SWITCH_END_EXTERN_C
|
||||
#endif
|
||||
|
@ -785,10 +785,40 @@ SWITCH_STANDARD_API(console_complete_function)
|
||||
}
|
||||
}
|
||||
|
||||
switch_console_complete(cmd, cursor, NULL, stream);
|
||||
switch_console_complete(cmd, cursor, NULL, stream, NULL);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
SWITCH_STANDARD_API(console_complete_xml_function)
|
||||
{
|
||||
const char *p, *cursor = NULL;
|
||||
int c;
|
||||
switch_xml_t xml = switch_xml_new("complete");
|
||||
char *sxml;
|
||||
|
||||
if (zstr(cmd)) {
|
||||
cmd = " ";
|
||||
}
|
||||
|
||||
if ((p = strstr(cmd, "c="))) {
|
||||
p += 2;
|
||||
c = atoi(p);
|
||||
if ((p = strchr(p, ';'))) {
|
||||
cmd = p + 1;
|
||||
cursor = cmd + c;
|
||||
}
|
||||
}
|
||||
|
||||
switch_console_complete(cmd, cursor, NULL, NULL, xml);
|
||||
|
||||
sxml = switch_xml_toxml(xml, SWITCH_TRUE);
|
||||
stream->write_function(stream, "%s", sxml);
|
||||
free(sxml);
|
||||
|
||||
switch_xml_free(xml);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
SWITCH_STANDARD_API(eval_function)
|
||||
{
|
||||
@ -3814,6 +3844,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
|
||||
SWITCH_ADD_API(commands_api_interface, "complete", "Complete", complete_function, COMPLETE_SYNTAX);
|
||||
SWITCH_ADD_API(commands_api_interface, "cond", "Eval a conditional", cond_function, "<expr> ? <true val> : <false val>");
|
||||
SWITCH_ADD_API(commands_api_interface, "console_complete", "", console_complete_function, "<line>");
|
||||
SWITCH_ADD_API(commands_api_interface, "console_complete_xml", "", console_complete_xml_function, "<line>");
|
||||
SWITCH_ADD_API(commands_api_interface, "create_uuid", "Create a uuid", uuid_function, UUID_SYNTAX);
|
||||
SWITCH_ADD_API(commands_api_interface, "db_cache", "db cache management", db_cache_function, "status");
|
||||
SWITCH_ADD_API(commands_api_interface, "domain_exists", "check if a domain exists", domain_exists_function, "<domain>");
|
||||
|
@ -395,6 +395,8 @@ struct helper {
|
||||
char partial[512];
|
||||
FILE *out;
|
||||
switch_stream_handle_t *stream;
|
||||
switch_xml_t xml;
|
||||
int xml_off;
|
||||
};
|
||||
|
||||
static int comp_callback(void *pArg, int argc, char **argv, char **columnNames)
|
||||
@ -443,6 +445,9 @@ static int comp_callback(void *pArg, int argc, char **argv, char **columnNames)
|
||||
if (h->stream) {
|
||||
h->stream->write_function(h->stream, "[%20s]\t", target);
|
||||
}
|
||||
if (h->xml) {
|
||||
switch_xml_set_txt_d(switch_xml_add_child_d(h->xml, "match", h->xml_off++), target);
|
||||
}
|
||||
|
||||
switch_copy_string(h->last, target, sizeof(h->last));
|
||||
h->hits++;
|
||||
@ -524,7 +529,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_list_uuid(const char *line, const
|
||||
}
|
||||
|
||||
|
||||
SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const char *cursor, FILE *console_out, switch_stream_handle_t *stream)
|
||||
SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const char *cursor, FILE *console_out, switch_stream_handle_t *stream, switch_xml_t xml)
|
||||
{
|
||||
switch_cache_db_handle_t *db = NULL;
|
||||
char *sql = NULL;
|
||||
@ -550,6 +555,7 @@ SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const ch
|
||||
|
||||
h.out = console_out;
|
||||
h.stream = stream;
|
||||
h.xml = xml;
|
||||
|
||||
if (pos > 0) {
|
||||
*(buf + pos) = '\0';
|
||||
@ -671,6 +677,20 @@ SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const ch
|
||||
} else if (h.hits > 1 && !zstr(h.partial)) {
|
||||
h.stream->write_function(h.stream, "write=%d:%s", h.len, h.partial);
|
||||
}
|
||||
}
|
||||
|
||||
if (h.xml) {
|
||||
switch_xml_t x_write = switch_xml_add_child_d(h.xml, "write", h.xml_off++);
|
||||
char buf[32];
|
||||
|
||||
snprintf(buf, sizeof(buf), "%d", h.len);
|
||||
switch_xml_set_attr_d_buf(x_write, "length", buf);
|
||||
|
||||
if (h.hits == 1 && !zstr(h.last)) {
|
||||
switch_xml_set_txt_d(x_write, h.last);
|
||||
} else if (h.hits > 1 && !zstr(h.partial)) {
|
||||
switch_xml_set_txt_d(x_write, h.partial);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SWITCH_HAVE_LIBEDIT
|
||||
@ -841,7 +861,7 @@ static unsigned char complete(EditLine * el, int ch)
|
||||
{
|
||||
const LineInfo *lf = el_line(el);
|
||||
|
||||
return switch_console_complete(lf->buffer, lf->cursor, switch_core_get_console(), NULL);
|
||||
return switch_console_complete(lf->buffer, lf->cursor, switch_core_get_console(), NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user