]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
centralize api interface
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 23 Dec 2005 02:55:25 +0000 (02:55 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 23 Dec 2005 02:55:25 +0000 (02:55 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@197 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_loadable_module.h
src/mod/mod_xmpp_event/mod_xmpp_event.c
src/switch_console.c
src/switch_loadable_module.c

index 39ba990df3e22f8dbac978e5e86903905a220e06..1d7e8f49a7c6163c30ca541e5c4f7633e630494b 100644 (file)
@@ -58,6 +58,7 @@ SWITCH_DECLARE(switch_application_interface *) loadable_module_get_application_i
 SWITCH_DECLARE(switch_api_interface *) loadable_module_get_api_interface(char *name);
 SWITCH_DECLARE(int) loadable_module_get_codecs(switch_memory_pool *pool, switch_codec_interface **array, int arraylen);
 SWITCH_DECLARE(int) loadable_module_get_codecs_sorted(switch_memory_pool *pool, switch_codec_interface **array, int arraylen, char **prefs, int preflen);
+SWITCH_DECLARE(switch_status) switch_api_execute(char *cmd, char *arg, char *retbuf, size_t len);
 SWITCH_DECLARE(void) loadable_module_shutdown(void);
 
 #ifdef __cplusplus
index 9add6719b25aefa3e1ece52aab89b60ed4952c69..b06cee9714bd18a04390595498f41b47330b30a7 100644 (file)
@@ -206,11 +206,10 @@ int on_stream (struct session *sess, int type, iks *node)
 
 int on_msg (void *user_data, ikspak *pak)
 {
-       switch_api_interface *api;
+       switch_event *event;
        char *cmd = iks_find_cdata (pak->x, "body");
        char *arg = NULL;
-       switch_event *event;
-       char retbuf[512] = "";
+       char retbuf[1024] = "";
        char *p;
 
        if ((p = strchr(cmd, '\r'))) {
@@ -222,17 +221,8 @@ int on_msg (void *user_data, ikspak *pak)
        if ((arg = strchr(cmd, ' '))) {
                *arg++ = '\0';
        } 
-       if (arg && (p = strchr(arg, '\r'))) {
-               *p++ = '\0';
-       } else if ((p = strchr(cmd, '\n'))) {
-               *p++ = '\0';
-       }
 
-       if ((api = loadable_module_get_api_interface(cmd))) {
-               api->function(arg, retbuf, sizeof(retbuf));
-       } else {
-               snprintf(retbuf, sizeof(retbuf), "INVALID COMMAND [%s]", cmd);
-       }
+       switch_api_execute(cmd, arg, retbuf, sizeof(retbuf));
 
        if (switch_event_create(&event, SWITCH_EVENT_API) == SWITCH_STATUS_SUCCESS) {
                if (cmd) {
index f59c0a70ac15ff81d1367a3a724d422081e536fc..4f9d974faa8359c8fbe4c17da6d8485c7a1c19b5 100644 (file)
@@ -34,8 +34,8 @@
 
 static int switch_console_process(char *cmd)
 {
-switch_api_interface *api;
 char *arg = NULL;
+ char retbuf[1024] = "";
 
 #ifdef EMBED_PERL
        const char *perlhelp = "perl - execute some perl. (print to STDERR if you want to see it.)\n";
@@ -58,14 +58,6 @@ char *arg = NULL;
        }
 
 
-       if ((api = loadable_module_get_api_interface(cmd))) {
-               char retbuf[512] = "";
-               api->function(arg, retbuf, sizeof(retbuf));
-               switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "API CALL [%s(%s)] output:\n%s\n", cmd, arg ? arg : "", retbuf);
-               return 1;
-       }
-       
-
 #ifdef EMBED_PERL
        if (!strncmp(cmd, "perl ", 5)) {
                cmd += 5;
@@ -74,7 +66,12 @@ char *arg = NULL;
                return 1;
        }
 #endif
-       switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Unknown Command: %s\n", cmd);
+
+       if (switch_api_execute(cmd, arg, retbuf, sizeof(retbuf)) == SWITCH_STATUS_SUCCESS) {
+               switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "API CALL [%s(%s)] output:\n%s\n", cmd, arg ? arg : "", retbuf);
+       } else {
+               switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Unknown Command: %s\n", cmd);
+       }
        return 1;
 }
 
index b9cda82f7fdcec90515f601e4c0c96b1159b3235..19a395b7a9a42a2495fe7343bfefd3a2044a5f62 100644 (file)
@@ -406,3 +406,17 @@ SWITCH_DECLARE(int) loadable_module_get_codecs_sorted(switch_memory_pool *pool,
 
        return i;
 }
+
+SWITCH_DECLARE(switch_status) switch_api_execute(char *cmd, char *arg, char *retbuf, size_t len)
+{
+       switch_api_interface *api;
+
+       if ((api = loadable_module_get_api_interface(cmd))) {
+               api->function(arg, retbuf, len);
+       } else {
+               snprintf(retbuf, len, "INVALID COMMAND [%s]", cmd);
+               return SWITCH_STATUS_FALSE;
+       }
+
+       return SWITCH_STATUS_SUCCESS;
+}