add terminators to dmachine and a way to use them in dp_tools and httapi

This commit is contained in:
Anthony Minessale 2013-01-21 15:36:35 -06:00
parent 75dfa6516b
commit dd8784a9e0
4 changed files with 49 additions and 2 deletions

View File

@ -756,7 +756,7 @@ SWITCH_DECLARE(void) switch_core_session_set_dmachine(switch_core_session_t *ses
SWITCH_DECLARE(switch_ivr_dmachine_t *) switch_core_session_get_dmachine(switch_core_session_t *session, switch_digit_action_target_t target);
SWITCH_DECLARE(switch_digit_action_target_t) switch_ivr_dmachine_get_target(switch_ivr_dmachine_t *dmachine);
SWITCH_DECLARE(void) switch_ivr_dmachine_set_target(switch_ivr_dmachine_t *dmachine, switch_digit_action_target_t target);
SWITCH_DECLARE(switch_status_t) switch_ivr_dmachine_set_terminators(switch_ivr_dmachine_t *dmachine, const char *terminators);
SWITCH_DECLARE(switch_status_t) switch_core_session_set_codec_slin(switch_core_session_t *session, switch_slin_data_t *data);
/*!

View File

@ -336,6 +336,7 @@ static void bind_to_session(switch_core_session_t *session,
struct action_binding *act;
switch_ivr_dmachine_t *dmachine;
switch_channel_t *channel = switch_core_session_get_channel(session);
const char *terminators = NULL;
if (!(dmachine = switch_core_session_get_dmachine(session, target))) {
uint32_t digit_timeout = 1500;
@ -363,6 +364,10 @@ static void bind_to_session(switch_core_session_t *session,
act->target = bind_target;
act->session = session;
switch_ivr_dmachine_bind(dmachine, act->realm, act->input, 0, digit_action_callback, act);
if ((terminators = switch_channel_get_variable(channel, "bda_terminators"))) {
switch_ivr_dmachine_set_terminators(dmachine, terminators);
}
}
#define BIND_DIGIT_ACTION_USAGE "<realm>,<digits|~regex>,<string>[,<value>][,<dtmf target leg>][,<event target leg>]"

View File

@ -374,6 +374,7 @@ static switch_status_t parse_playback(const char *tag_name, client_t *client, sw
const char *action = switch_xml_attr(tag, "action");
const char *digit_timeout_ = switch_xml_attr(tag, "digit-timeout");
const char *input_timeout_ = switch_xml_attr(tag, "input-timeout");
const char *terminators = switch_xml_attr(tag, "terminators");
const char *tts_engine = NULL;
const char *tts_voice = NULL;
char *loops_ = (char *) switch_xml_attr(tag, "loops");
@ -559,6 +560,10 @@ static switch_status_t parse_playback(const char *tag_name, client_t *client, sw
}
switch_ivr_dmachine_set_realm(dmachine, realm);
if (!zstr(terminators)) {
switch_ivr_dmachine_set_terminators(dmachine, terminators);
}
myargs.dmachine = dmachine;
args = &myargs;
}
@ -915,6 +920,7 @@ static switch_status_t parse_record(const char *tag_name, client_t *client, swit
const char *action = switch_xml_attr(tag, "action");
const char *sub_action = NULL;
const char *digit_timeout_ = switch_xml_attr(tag, "digit-timeout");
const char *terminators = switch_xml_attr(tag, "terminators");
char *loops_ = (char *) switch_xml_attr(tag, "loops");
int loops = 0;
switch_status_t status = SWITCH_STATUS_SUCCESS;
@ -1032,6 +1038,10 @@ static switch_status_t parse_record(const char *tag_name, client_t *client, swit
}
switch_ivr_dmachine_set_realm(dmachine, realm);
if (!zstr(terminators)) {
switch_ivr_dmachine_set_terminators(dmachine, terminators);
}
myargs.dmachine = dmachine;
args = &myargs;
}

View File

@ -51,6 +51,8 @@ typedef struct switch_ivr_dmachine_binding switch_ivr_dmachine_binding_t;
typedef struct {
switch_ivr_dmachine_binding_t *binding_list;
switch_ivr_dmachine_binding_t *tail;
char *name;
char *terminators;
} dm_binding_head_t;
struct switch_ivr_dmachine {
@ -187,6 +189,21 @@ SWITCH_DECLARE(void) switch_ivr_dmachine_destroy(switch_ivr_dmachine_t **dmachin
}
}
SWITCH_DECLARE(switch_status_t) switch_ivr_dmachine_set_terminators(switch_ivr_dmachine_t *dmachine, const char *terminators)
{
if (!dmachine->realm) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No realm selected.\n");
return SWITCH_STATUS_FALSE;
}
dmachine->realm->terminators = switch_core_strdup(dmachine->pool, terminators);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Digit parser %s: Setting terminators for realm '%s' to '%s'\n",
dmachine->name, dmachine->realm->name, terminators);
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status_t) switch_ivr_dmachine_set_realm(switch_ivr_dmachine_t *dmachine, const char *realm)
{
dm_binding_head_t *headp = switch_core_hash_find(dmachine->binding_hash, realm);
@ -198,7 +215,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_dmachine_set_realm(switch_ivr_dmachin
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Digit parser %s: Error Setting realm to '%s'\n", dmachine->name, realm);
return SWITCH_STATUS_FALSE;
}
@ -248,6 +265,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_dmachine_bind(switch_ivr_dmachine_t *
if (!(headp = switch_core_hash_find(dmachine->binding_hash, realm))) {
headp = switch_core_alloc(dmachine->pool, sizeof(*headp));
headp->name = switch_core_strdup(dmachine->pool, realm);
switch_core_hash_insert(dmachine->binding_hash, realm, headp);
}
@ -345,6 +363,20 @@ static dm_match_t switch_ivr_dmachine_check_match(switch_ivr_dmachine_t *dmachin
}
}
if (!zstr(dmachine->realm->terminators)) {
char *p = dmachine->realm->terminators;
char *q;
while(p && *p) {
if ((q=strrchr(dmachine->digits, *p))) {
*q = '\0';
is_timeout = 1;
break;
}
p++;
}
}
for(bp = dmachine->realm->binding_list; bp; bp = bp->next) {
if (bp->is_regex) {
if (bp->rmatch) {