]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add terminators to dmachine and a way to use them in dp_tools and httapi
authorAnthony Minessale <anthm@freeswitch.org>
Mon, 21 Jan 2013 21:36:35 +0000 (15:36 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Mon, 21 Jan 2013 21:36:35 +0000 (15:36 -0600)
src/include/switch_core.h
src/mod/applications/mod_dptools/mod_dptools.c
src/mod/applications/mod_httapi/mod_httapi.c
src/switch_ivr_async.c

index 68e592b9dfe65cfd7a826434321d71fcc0c28d46..575e4601aee8b8b0fbc1cb32f9d69b4801c072e6 100644 (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);
 
 /*! 
index e45f7215bc18d95c6839cfaa8c15da7935b76fc7..d90fb29d6a61aae3c5454a906f10ab45e25dff72 100755 (executable)
@@ -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>]"
index 34073260de29275a0e9735d5c2a1315136c48bae..cc5fea89eb5768f2de62ed5a5672c7dd224881de 100644 (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;
        }
index 38425f19e4239d183c30ac29d500c97dabc2a447..80d945f875505162d5be03fd500369b4321069d5 100644 (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) {