]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add module_exists api call
authorBrian West <brian@freeswitch.org>
Thu, 10 Jul 2008 14:41:31 +0000 (14:41 +0000)
committerBrian West <brian@freeswitch.org>
Thu, 10 Jul 2008 14:41:31 +0000 (14:41 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8984 d0543943-73ff-0310-b7d9-9358b9ac24b2

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

index 36817e96c3b05646b281dd0a60478d2d5b9bd85a..a70380144050f26bb1c1835ff1eeaf28188cddbb 100644 (file)
@@ -241,6 +241,13 @@ SWITCH_DECLARE(switch_status_t) switch_api_execute(const char *cmd, const char *
 */
 SWITCH_DECLARE(switch_status_t) switch_loadable_module_load_module(char *dir, char *fname, switch_bool_t runtime, const char **err);
 
+/*!
+  \brief Check if a module is loaded
+  \param mod the module name
+  \return the status
+*/
+SWITCH_DECLARE(switch_status_t) switch_loadable_module_exists(const char *mod);
+
 /*!
   \brief Unoad a module
   \param dir the directory where the module resides
index 47d79e6958f0d4f5d75d097663a86409562cde2d..c1405aec0f0252562deba3d531a0203e27a86ad3 100644 (file)
@@ -196,6 +196,21 @@ SWITCH_STANDARD_API(url_decode_function)
        
 }
 
+SWITCH_STANDARD_API(module_exists_function)
+{
+       if (!switch_strlen_zero(cmd)) {
+               if(switch_loadable_module_exists(cmd) == SWITCH_STATUS_SUCCESS) {
+                       stream->write_function(stream, "true");
+               } else {
+                       stream->write_function(stream, "false");
+
+               }               
+       }
+
+    return SWITCH_STATUS_SUCCESS;
+}
+
+
 SWITCH_STANDARD_API(url_encode_function)
 {
        char *reply = "";
@@ -2431,6 +2446,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
        SWITCH_ADD_API(commands_api_interface, "user_data", "find user data", user_data_function, "<user>@<domain> [var|param] <name>");
        SWITCH_ADD_API(commands_api_interface, "url_encode", "url encode a string", url_encode_function, "<string>");
        SWITCH_ADD_API(commands_api_interface, "url_decode", "url decode a string", url_decode_function, "<string>");
+       SWITCH_ADD_API(commands_api_interface, "module_exists", "check if module exists", module_exists_function, "<module>");
 
        /* indicate that the module should continue to be loaded */
        return SWITCH_STATUS_NOUNLOAD;
index 47c1ba57c48b7e5162da82005d4a20349b783dd2..e5be4654da87227648ff5ffddf08748aaf6fb5a1 100644 (file)
@@ -830,7 +830,24 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_load_module(char *dir, ch
 
 }
 
+SWITCH_DECLARE(switch_status_t) switch_loadable_module_exists(const char *mod)
+{
+       switch_status_t status;  
+
+       if (switch_strlen_zero(mod)) {
+               return SWITCH_STATUS_FALSE;
+       }
+
+       switch_mutex_lock(loadable_modules.mutex);
+       if (switch_core_hash_find(loadable_modules.module_hash, mod)) {
+               status = SWITCH_STATUS_SUCCESS;
+       } else {
+               status = SWITCH_STATUS_FALSE;
+       }
+       switch_mutex_unlock(loadable_modules.mutex);
 
+       return status;
+}
 
 SWITCH_DECLARE(switch_status_t) switch_loadable_module_unload_module(char *dir, char *fname, const char **err)
 {