]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add api-expansion to switch.conf.xml and fsctl api_expansion command to control allow...
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 27 Jul 2012 23:53:04 +0000 (18:53 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 27 Jul 2012 23:53:04 +0000 (18:53 -0500)
src/include/switch_core.h
src/include/switch_types.h
src/mod/applications/mod_commands/mod_commands.c
src/switch_channel.c
src/switch_core.c
src/switch_event.c

index 007f6a85ad1d24decb2f72947a30ab05f6a8b29e..879951cfdea8f608d749a7bd50d6227c93e61a95 100644 (file)
@@ -323,6 +323,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_free_port(_In_ switch
 SWITCH_DECLARE(void) switch_core_port_allocator_destroy(_Inout_ switch_core_port_allocator_t **alloc);
 ///\}
 
+
+SWITCH_DECLARE(int) switch_core_test_flag(int flag);
+
 ///\defgroup ss Startup/Shutdown
 ///\ingroup core1
 ///\{
index 20ee478bf5756761d24d6a86a04e9c223b51af3f..b4ec3680210e984ac49d3b75e1c103f4a81ad81f 100644 (file)
@@ -322,7 +322,8 @@ typedef enum {
        SCF_THREADED_SYSTEM_EXEC = (1 << 18),
        SCF_SYNC_CLOCK_REQUESTED = (1 << 19),
        SCF_CORE_ODBC_REQ = (1 << 20),
-       SCF_DEBUG_SQL = (1 << 21)
+       SCF_DEBUG_SQL = (1 << 21),
+       SCF_API_EXPANSION = (1 << 22)
 } switch_core_flag_enum_t;
 typedef uint32_t switch_core_flag_t;
 
@@ -1776,6 +1777,7 @@ typedef enum {
        SCSC_SYNC_CLOCK_WHEN_IDLE,
        SCSC_DEBUG_SQL,
        SCSC_SQL,
+       SCSC_API_EXPANSION
 } switch_session_ctl_t;
 
 typedef enum {
index 1cde9b30ce3a7a11e632285e103b8d0164162057..9ed0506efd13048fe0b30b91d453a85a40e3bbb0 100644 (file)
@@ -1854,6 +1854,15 @@ SWITCH_STANDARD_API(ctl_function)
                        switch_core_session_ctl(SCSC_VERBOSE_EVENTS, &arg);
 
                        stream->write_function(stream, "+OK verbose_events is %s \n", arg ? "on" : "off");
+               } else if (!strcasecmp(argv[0], "api_expansion")) {
+                       arg = -1;
+                       if (argv[1]) {
+                               arg = switch_true(argv[1]);
+                       }
+
+                       switch_core_session_ctl(SCSC_API_EXPANSION, &arg);
+
+                       stream->write_function(stream, "+OK api_expansion is %s \n", arg ? "on" : "off");
                } else if (!strcasecmp(argv[0], "threaded_system_exec")) {
                        arg = -1;
                        if (argv[1]) {
index cb434d2712d0ac6b13c94807c4945a3eacd1f522..a8f05f19283aa05d571c3b0cfe1c3b95d8490a33 100644 (file)
@@ -34,6 +34,7 @@
 #include <switch.h>
 #include <switch_channel.h>
 
+
 struct switch_cause_table {
        const char *name;
        switch_call_cause_t cause;
@@ -3591,7 +3592,7 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables_check(switch_channel_t *c
 
                                        if ((sub_val = (char *) switch_channel_get_variable_dup(channel, vname, SWITCH_TRUE, idx))) {
                                                if (var_list && !switch_event_check_permission_list(var_list, vname)) {
-                                                       sub_val = "INVALID";
+                                                       sub_val = "<Variable Expansion Permission Denied>";
                                                }
 
                                                if ((expanded_sub_val = switch_channel_expand_variables_check(channel, sub_val, var_list, api_list, recur+1)) == sub_val) {
@@ -3645,9 +3646,9 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables_check(switch_channel_t *c
                                                        vval = expanded;
                                                }
 
-                                               if (api_list && !switch_event_check_permission_list(api_list, vname)) {
-                                                       func_val = "INVALID";
-                                                       sub_val = "INVALID";
+                                               if (!switch_core_test_flag(SCF_API_EXPANSION) || (api_list && !switch_event_check_permission_list(api_list, vname))) {
+                                                       func_val = NULL;
+                                                       sub_val = "<API Execute Permission Denied>";
                                                } else {
                                                        if (switch_api_execute(vname, vval, channel->session, &stream) == SWITCH_STATUS_SUCCESS) {
                                                                func_val = stream.data;
index 534edf630342d8e66353e79ae5d2bbb36b9c44f5..e5433077b30c5aed9a0fbfdc95c5404d1bd10835 100644 (file)
@@ -1405,6 +1405,12 @@ static void switch_core_set_serial(void)
 }
 
 
+SWITCH_DECLARE(int) switch_core_test_flag(int flag)
+{
+       return switch_test_flag((&runtime), flag);
+}
+
+
 SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switch_bool_t console, const char **err)
 {
        switch_uuid_t uuid;
@@ -1433,6 +1439,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
        switch_set_flag((&runtime.dummy_cng_frame), SFF_CNG);
        switch_set_flag((&runtime), SCF_AUTO_SCHEMAS);
        switch_set_flag((&runtime), SCF_CLEAR_SQL);
+       switch_set_flag((&runtime), SCF_API_EXPANSION);
 #ifdef WIN32
        switch_set_flag((&runtime), SCF_THREADED_SYSTEM_EXEC);
 #endif
@@ -1750,6 +1757,12 @@ static void switch_load_core_config(const char *file)
                                        } else {
                                                switch_clear_flag((&runtime), SCF_CLEAR_SQL);
                                        }
+                               } else if (!strcasecmp(var, "api-expansion")) {
+                                       if (switch_true(val)) {
+                                               switch_set_flag((&runtime), SCF_API_EXPANSION);
+                                       } else {
+                                               switch_clear_flag((&runtime), SCF_API_EXPANSION);
+                                       }
                                } else if (!strcasecmp(var, "enable-early-hangup") && switch_true(val)) {
                                        switch_set_flag((&runtime), SCF_EARLY_HANGUP);
                                } else if (!strcasecmp(var, "colorize-console") && switch_true(val)) {
@@ -2099,6 +2112,18 @@ SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, void *
                        newintval = switch_test_flag((&runtime), SCF_VERBOSE_EVENTS);
                }
                break;
+       case SCSC_API_EXPANSION:
+               if (intval) {
+                       if (oldintval > -1) {
+                               if (oldintval) {
+                                       switch_set_flag((&runtime), SCF_API_EXPANSION);
+                               } else {
+                                       switch_clear_flag((&runtime), SCF_API_EXPANSION);
+                               }
+                       }
+                       newintval = switch_test_flag((&runtime), SCF_API_EXPANSION);
+               }
+               break;
        case SCSC_THREADED_SYSTEM_EXEC:
                if (intval) {
                        if (oldintval > -1) {
index 4bfbbb1ff72381eb0fd506ee4ba464ec59e037b9..5b7891d496499e3be4a3f5e901b4a90395e9257c 100644 (file)
@@ -35,6 +35,7 @@
 #include <switch.h>
 #include <switch_event.h>
 
+
 //#define SWITCH_EVENT_RECYCLE
 #define DISPATCH_QUEUE_LEN 100
 //#define DEBUG_DISPATCH_QUEUES
@@ -2109,7 +2110,7 @@ SWITCH_DECLARE(char *) switch_event_expand_headers_check(switch_event_t *event,
                                                }
 
                                                if (var_list && !switch_event_check_permission_list(var_list, vname)) {
-                                                       sub_val = "INVALID";
+                                                       sub_val = "<Variable Expansion Permission Denied>";
                                                }
 
 
@@ -2161,9 +2162,9 @@ SWITCH_DECLARE(char *) switch_event_expand_headers_check(switch_event_t *event,
                                                        vval = expanded;
                                                }
 
-                                               if (api_list && !switch_event_check_permission_list(api_list, vname)) {
-                                                       func_val = "INVALID";
-                                                       sub_val = "INVALID";
+                                               if (!switch_core_test_flag(SCF_API_EXPANSION) || (api_list && !switch_event_check_permission_list(api_list, vname))) {
+                                                       func_val = NULL;
+                                                       sub_val = "<API execute Permission Denied>";
                                                } else {
                                                        if (switch_api_execute(vname, vval, NULL, &stream) == SWITCH_STATUS_SUCCESS) {
                                                                func_val = stream.data;