]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add set_global
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 9 Nov 2007 15:55:40 +0000 (15:55 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 9 Nov 2007 15:55:40 +0000 (15:55 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6194 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/applications/mod_dptools/mod_dptools.c
src/switch_core.c

index bd6e5ca3bad8b6447545c9c7da29f1baaf02e887..68b2d6703871bc14404a6715a9b16063a17166c0 100644 (file)
@@ -360,6 +360,30 @@ SWITCH_STANDARD_APP(set_function)
        }
 }
 
+SWITCH_STANDARD_APP(set_global_function)
+{
+       char *var, *val = NULL;
+
+       if (switch_strlen_zero(data)) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n");
+       } else {
+               var = strdup(data);
+               assert(var);
+               val = strchr(var, '=');
+
+               if (val) {
+                       *val++ = '\0';
+                       if (switch_strlen_zero(val)) {
+                               val = NULL;
+                       }
+               }
+
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SET GLOBAL [%s]=[%s]\n", var, val ? val : "UNDEF");
+               switch_core_set_variable(var, val);
+               free(var);
+       }
+}
+
 
 SWITCH_STANDARD_APP(set_profile_var_function)
 {
@@ -1319,6 +1343,7 @@ SWITCH_STANDARD_APP(audio_bridge_function)
 #define SCHED_HANGUP_DESCR "Schedule a hangup in the future"
 #define UNSET_LONG_DESC "Unset a channel varaible for the channel calling the application."
 #define SET_LONG_DESC "Set a channel varaible for the channel calling the application."
+#define SET_GLOBAL_LONG_DESC "Set a global varaible."
 #define SET_PROFILE_VAR_LONG_DESC "Set a caller profile varaible for the channel calling the application."
 #define EXPORT_LONG_DESC "Set and export a channel varaible for the channel calling the application."
 #define LOG_LONG_DESC "Logs a channel varaible for the channel calling the application."
@@ -1351,6 +1376,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
        SWITCH_ADD_APP(app_interface, "event", "Fire an event", "Fire an event", event_function, "", SAF_SUPPORT_NOMEDIA);
        SWITCH_ADD_APP(app_interface, "export", "Export a channel varaible across a bridge", EXPORT_LONG_DESC, export_function, "<varname>=<value>", SAF_SUPPORT_NOMEDIA);
        SWITCH_ADD_APP(app_interface, "set", "Set a channel varaible", SET_LONG_DESC, set_function, "<varname>=<value>", SAF_SUPPORT_NOMEDIA);
+       SWITCH_ADD_APP(app_interface, "set_global", "Set a global varaible", SET_GLOBAL_LONG_DESC, set_global_function, "<varname>=<value>", SAF_SUPPORT_NOMEDIA);
        SWITCH_ADD_APP(app_interface, "set_profile_var", "Set a caller profile varaible", SET_PROFILE_VAR_LONG_DESC, set_profile_var_function, "<varname>=<value>", SAF_SUPPORT_NOMEDIA);
        SWITCH_ADD_APP(app_interface, "unset", "Unset a channel varaible", UNSET_LONG_DESC, unset_function, "<varname>", SAF_SUPPORT_NOMEDIA);
        SWITCH_ADD_APP(app_interface, "ring_ready", "Indicate Ring_Ready", "Indicate Ring_Ready on a channel.", ring_ready_function, "", SAF_SUPPORT_NOMEDIA);
index 122d9e16db7bb5fe1451718c2f0a0e6090b5d121..f3f7f7678f5e88c6fa6b057736d147866e749a55 100644 (file)
@@ -141,12 +141,26 @@ SWITCH_DECLARE(const switch_state_handler_table_t *) switch_core_get_state_handl
 
 SWITCH_DECLARE(char *) switch_core_get_variable(const char *varname)
 {
-       return (char *) switch_core_hash_find(runtime.global_vars, varname);
+       char *val;
+       switch_mutex_lock(runtime.throttle_mutex);
+       val = (char *) switch_core_hash_find(runtime.global_vars, varname);
+       switch_mutex_unlock(runtime.throttle_mutex);
+       return val;
 }
 
 SWITCH_DECLARE(void) switch_core_set_variable(const char *varname, const char *value)
 {
-       switch_core_hash_insert(runtime.global_vars, switch_core_strdup(runtime.memory_pool, varname), switch_core_strdup(runtime.memory_pool, value));
+       char *val;
+
+       switch_mutex_lock(runtime.throttle_mutex);
+       val = (char *) switch_core_hash_find(runtime.global_vars, varname);
+       if (val) {
+               free(val);
+       }
+       if (value) {
+               switch_core_hash_insert(runtime.global_vars, varname, strdup(value));
+       }
+       switch_mutex_unlock(runtime.throttle_mutex);
 }
 
 SWITCH_DECLARE(char *) switch_core_get_uuid(void)