improve dmachine stuff some more

This commit is contained in:
Anthony Minessale
2010-10-08 13:50:15 -05:00
parent 8a7f8cd22e
commit 1d921b1cfa
6 changed files with 233 additions and 63 deletions
+65 -19
View File
@@ -96,12 +96,30 @@ SWITCH_STANDARD_DIALPLAN(inline_dialplan_hunt)
}
struct action_binding {
char *realm;
char *input;
char *string;
char *value;
switch_core_session_t *session;
};
static switch_status_t digit_nomatch_action_callback(switch_ivr_dmachine_match_t *match)
{
switch_core_session_t *session = (switch_core_session_t *) match->user_data;
switch_channel_t *channel = switch_core_session_get_channel(session);
char str[DMACHINE_MAX_DIGIT_LEN + 2];
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Digit NOT match binding [%s]\n",
switch_channel_get_name(channel), match->match_digits);
/* send it back around flagged to skip the dmachine */
switch_snprintf(str, sizeof(str), "!%s", match->match_digits);
switch_channel_queue_dtmf_string(channel, str);
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t digit_action_callback(switch_ivr_dmachine_match_t *match)
{
struct action_binding *act = (struct action_binding *) match->user_data;
@@ -141,32 +159,64 @@ static switch_status_t digit_action_callback(switch_ivr_dmachine_match_t *match)
return SWITCH_STATUS_SUCCESS;
}
#define CLEAR_DIGIT_ACTION_USAGE ""
#define CLEAR_DIGIT_ACTION_USAGE "<realm>|all"
SWITCH_STANDARD_APP(clear_digit_action_function)
{
//switch_channel_t *channel = switch_core_session_get_channel(session);
switch_ivr_dmachine_t *dmachine;
char *realm = (char *) data;
if ((dmachine = switch_core_session_get_dmachine(session))) {
switch_core_session_set_dmachine(session, NULL);
switch_ivr_dmachine_destroy(&dmachine);
if (zstr(realm) || !strcasecmp(realm, "all")) {
switch_core_session_set_dmachine(session, NULL);
switch_ivr_dmachine_destroy(&dmachine);
} else {
switch_ivr_dmachine_clear_realm(dmachine, realm);
}
}
}
#define BIND_DIGIT_ACTION_USAGE "<digits|~regex>,<string>,<value>"
#define DIGIT_ACTION_SET_REALM_USAGE "<realm>"
SWITCH_STANDARD_APP(digit_action_set_realm_function)
{
switch_ivr_dmachine_t *dmachine;
char *realm = (char *) data;
if (zstr(data)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Syntax Error, USAGE %s\n", DIGIT_ACTION_SET_REALM_USAGE);
return;
}
if ((dmachine = switch_core_session_get_dmachine(session))) {
switch_ivr_dmachine_set_realm(dmachine, realm);
}
}
#define BIND_DIGIT_ACTION_USAGE "<realm>,<digits|~regex>,<string>,<value>"
SWITCH_STANDARD_APP(bind_digit_action_function)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_ivr_dmachine_t *dmachine;
char *mydata;
int argc = 0;
char *argv[3] = { 0 };
char *argv[4] = { 0 };
struct action_binding *act;
if (zstr(data)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Syntax Error, USAGE %s\n", BIND_DIGIT_ACTION_USAGE);
return;
}
mydata = switch_core_session_strdup(session, data);
argc = switch_separate_string(mydata, ',', argv, (sizeof(argv) / sizeof(argv[0])));
if (argc < 4 || zstr(argv[0]) || zstr(argv[1]) || zstr(argv[2]) || zstr(argv[3])) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Syntax Error, USAGE %s\n", BIND_DIGIT_ACTION_USAGE);
return;
}
if (!(dmachine = switch_core_session_get_dmachine(session))) {
uint32_t digit_timeout = 1500;
@@ -186,26 +236,19 @@ SWITCH_STANDARD_APP(bind_digit_action_function)
input_timeout = tmp;
}
switch_ivr_dmachine_create(&dmachine, NULL, digit_timeout, input_timeout);
switch_ivr_dmachine_create(&dmachine, "DPTOOLS", NULL, digit_timeout, input_timeout, NULL, digit_nomatch_action_callback, session);
switch_core_session_set_dmachine(session, dmachine);
}
mydata = switch_core_session_strdup(session, data);
argc = switch_separate_string(mydata, ',', argv, (sizeof(argv) / sizeof(argv[0])));
if (argc < 3 || zstr(argv[0]) || zstr(argv[1]) || zstr(argv[2])) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Syntax Error, USAGE %s\n", BIND_DIGIT_ACTION_USAGE);
return;
}
act = switch_core_session_alloc(session, sizeof(*act));
act->input = argv[0];
act->string = argv[1];
act->value = argv[2];
act->realm = argv[0];
act->input = argv[1];
act->string = argv[2];
act->value = argv[3];
act->session = session;
switch_ivr_dmachine_bind(dmachine, act->input, 0, digit_action_callback, act);
switch_ivr_dmachine_bind(dmachine, act->realm, act->input, 0, digit_action_callback, act);
}
@@ -3398,6 +3441,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
SWITCH_ADD_APP(app_interface, "clear_digit_action", "clear all digit bindings", "",
clear_digit_action_function, CLEAR_DIGIT_ACTION_USAGE, SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "digit_action_set_realm", "change binding realm", "",
digit_action_set_realm_function, DIGIT_ACTION_SET_REALM_USAGE, SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "privacy", "Set privacy on calls", "Set caller privacy on calls.", privacy_function, "off|on|name|full|number",
SAF_SUPPORT_NOMEDIA);