switch_ivr_dmachine_callback_t callback,
void *user_data)
{
- switch_ivr_dmachine_binding_t *binding;
+ switch_ivr_dmachine_binding_t *binding = NULL, *ptr;
switch_size_t len;
dm_binding_head_t *headp;
+ const char *msg = "";
if (strlen(digits) > DMACHINE_MAX_DIGIT_LEN -1) {
return SWITCH_STATUS_FALSE;
headp = switch_core_alloc(dmachine->pool, sizeof(*headp));
switch_core_hash_insert(dmachine->binding_hash, realm, headp);
}
+
+ for(ptr = headp->binding_list; ptr; ptr = ptr->next) {
+ if ((ptr->is_regex && !strcmp(ptr->digits, digits+1)) || !strcmp(ptr->digits, digits)) {
+ msg = "Reuse Existing ";
+ binding = ptr;
+ binding->callback = callback;
+ binding->user_data = user_data;
+ goto done;
+ }
+ }
+
binding = switch_core_alloc(dmachine->pool, sizeof(*binding));
dmachine->max_digit_len = (uint32_t) len;
}
+ done:
+
if (binding->is_regex) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digit parser %s: binding %s/%s/%d callback: %p data: %p\n",
- dmachine->name, digits, realm, key, (void *)(intptr_t) callback, user_data);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%sDigit parser %s: binding %s/%s/%d callback: %p data: %p\n",
+ msg, dmachine->name, digits, realm, key, (void *)(intptr_t) callback, user_data);
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digit parser %s: binding %s/%s/%d callback: %p data: %p\n",
- dmachine->name, digits, realm, key, (void *)(intptr_t) callback, user_data);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%sDigit parser %s: binding %s/%s/%d callback: %p data: %p\n",
+ msg, dmachine->name, digits, realm, key, (void *)(intptr_t) callback, user_data);
}
return SWITCH_STATUS_SUCCESS;
{
dm_match_t best = DM_MATCH_NONE;
switch_ivr_dmachine_binding_t *bp, *exact_bp = NULL, *partial_bp = NULL, *both_bp = NULL, *r_bp = NULL;
- int pmatches = 0;
+ int pmatches = 0, ematches = 0;
if (!dmachine->cur_digit_len || !dmachine->realm) goto end;
} else {
if (!strncmp(dmachine->digits, bp->digits, strlen(dmachine->digits))) {
pmatches++;
+ ematches = 1;
}
}
}
} else {
int pmatch = !strncmp(dmachine->digits, bp->digits, strlen(dmachine->digits));
- if (!exact_bp && pmatch && (pmatches == 1 || is_timeout) && !strcmp(bp->digits, dmachine->digits)) {
+ if (!exact_bp && pmatch && (pmatches == 1 || ematches == 1 || is_timeout) && !strcmp(bp->digits, dmachine->digits)) {
best = DM_MATCH_EXACT;
exact_bp = bp;
if (dmachine->cur_digit_len == dmachine->max_digit_len) break;