FS-9043 [mod_kazoo] add kz_export
This commit is contained in:
parent
f8ba116b71
commit
68e0aded0d
|
@ -48,6 +48,10 @@
|
|||
#define MULTIUNSET_LONG_DESC "Unset many channel variables for the channel calling the application."
|
||||
#define MULTIUNSET_SYNTAX "[^^<delim>]<varname> <var2> <var3>"
|
||||
|
||||
#define EXPORT_SHORT_DESC "Export many channel variables"
|
||||
#define EXPORT_LONG_DESC "Export many channel variables for the channel calling the application"
|
||||
#define EXPORT_SYNTAX "[^^<delim>]<varname>=<value> <var2>=<val2>"
|
||||
|
||||
static void base_set (switch_core_session_t *session, const char *data, switch_stack_t stack) {
|
||||
char *var, *val = NULL;
|
||||
|
||||
|
@ -84,6 +88,42 @@ static void base_set (switch_core_session_t *session, const char *data, switch_s
|
|||
}
|
||||
}
|
||||
|
||||
static void base_export (switch_core_session_t *session, const char *data, switch_stack_t stack) {
|
||||
char *var, *val = NULL;
|
||||
|
||||
if (zstr(data)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No variable name specified.\n");
|
||||
} else {
|
||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||
char *expanded = NULL;
|
||||
|
||||
var = switch_core_session_strdup(session, data);
|
||||
|
||||
if (!(val = strchr(var, '='))) {
|
||||
val = strchr(var, ',');
|
||||
}
|
||||
|
||||
if (val) {
|
||||
*val++ = '\0';
|
||||
if (zstr(val)) {
|
||||
val = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (val) {
|
||||
expanded = switch_channel_expand_variables(channel, val);
|
||||
}
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s EXPORT [%s]=[%s]\n", switch_channel_get_name(channel), var,
|
||||
expanded ? expanded : "UNDEF");
|
||||
switch_channel_export_variable_var_check(channel, var, expanded, SWITCH_EXPORT_VARS_VARIABLE, SWITCH_FALSE);
|
||||
|
||||
if (expanded && expanded != val) {
|
||||
switch_safe_free(expanded);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SWITCH_STANDARD_APP(multiset_function) {
|
||||
char delim = ' ';
|
||||
char *arg = (char *) data;
|
||||
|
@ -170,6 +210,30 @@ SWITCH_STANDARD_APP(multiunset_function) {
|
|||
}
|
||||
}
|
||||
|
||||
SWITCH_STANDARD_APP(export_function) {
|
||||
char delim = ' ';
|
||||
char *arg = (char *) data;
|
||||
|
||||
if (!zstr(arg) && *arg == '^' && *(arg+1) == '^') {
|
||||
arg += 2;
|
||||
delim = *arg++;
|
||||
}
|
||||
|
||||
if (arg) {
|
||||
char *array[256] = {0};
|
||||
int i, argc;
|
||||
|
||||
arg = switch_core_session_strdup(session, arg);
|
||||
argc = switch_split(arg, delim, array);
|
||||
|
||||
for(i = 0; i < argc; i++) {
|
||||
base_export(session, array[i], SWITCH_STACK_BOTTOM);
|
||||
}
|
||||
} else {
|
||||
base_export(session, data, SWITCH_STACK_BOTTOM);
|
||||
}
|
||||
}
|
||||
|
||||
void add_kz_dptools(switch_loadable_module_interface_t **module_interface, switch_application_interface_t *app_interface) {
|
||||
SWITCH_ADD_APP(app_interface, "kz_set", SET_SHORT_DESC, SET_LONG_DESC, set_function, SET_SYNTAX,
|
||||
SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC);
|
||||
|
@ -179,4 +243,6 @@ void add_kz_dptools(switch_loadable_module_interface_t **module_interface, switc
|
|||
SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC);
|
||||
SWITCH_ADD_APP(app_interface, "kz_multiunset", MULTISET_SHORT_DESC, MULTISET_LONG_DESC, multiunset_function, MULTIUNSET_SYNTAX,
|
||||
SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC);
|
||||
SWITCH_ADD_APP(app_interface, "kz_export", EXPORT_SHORT_DESC, EXPORT_LONG_DESC, export_function, EXPORT_SYNTAX,
|
||||
SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue