]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add console_complete_xml api
authorMathieu Rene <mrene@avgs.ca>
Tue, 15 Dec 2009 18:26:06 +0000 (18:26 +0000)
committerMathieu Rene <mrene@avgs.ca>
Tue, 15 Dec 2009 18:26:06 +0000 (18:26 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@15967 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_console.h
src/mod/applications/mod_commands/mod_commands.c
src/switch_console.c

index f90b878f13dbea6cb9e1ef1de3d9e35258c3e754..7e2968335ba5b2dd91dace350903fb45c4b92a50 100644 (file)
@@ -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
index 52d19a601fa9a231ea833604befde5e8e72c34d1..637fcf37335b7cc072946baa3227db4a51fee58f 100644 (file)
@@ -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>");
index 4437b8d43bf348b6ef9fbfe7d2f03762b74b5506..4b83ee943d74f3735decd0e1334a0b1cc0fa95ad 100644 (file)
@@ -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);
 }