add api-expansion to switch.conf.xml and fsctl api_expansion command to control allowing apis to be expanded via variable expansion

This commit is contained in:
Anthony Minessale 2012-07-27 18:53:04 -05:00
parent cfb2335406
commit 293429f78d
6 changed files with 50 additions and 9 deletions

View 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
///\{

View 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 {

View 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]) {

View 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;

View 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) {

View 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;