diff --git a/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c b/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c index b71711bf7a..2d84ec04a9 100644 --- a/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c +++ b/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c @@ -154,18 +154,18 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt) } channel = switch_core_session_get_channel(session); - assert(channel != NULL); + switch_assert(channel != NULL); if (!caller_profile) { caller_profile = switch_channel_get_caller_profile(channel); } - if (caller_profile && !switch_strlen_zero(caller_profile->destination_number)) { - context = caller_profile->context ? caller_profile->context : "default"; - } else { + if (!caller_profile || switch_strlen_zero(caller_profile->destination_number)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Obtaining Profile!\n"); return NULL; } + + context = caller_profile->context ? caller_profile->context : "default"; if (!switch_config_open_file(&cfg, cf)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); @@ -188,7 +188,7 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt) char *argument = NULL; char *expression = NULL, expression_buf[1024] = ""; char substituted[2048] = ""; - char *field_data = caller_profile->destination_number; + const char *field_data = caller_profile->destination_number; int proceed = 0; switch_regex_t *re = NULL; int ovector[30] = {0}; @@ -220,7 +220,7 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt) field_data = field_expanded; } } else { - field_data = (char *)switch_caller_get_field_by_name(caller_profile, var); + field_data = switch_caller_get_field_by_name(caller_profile, var); } } @@ -236,6 +236,10 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt) expression = pattern; } + if (!field_data) { + field_data = ""; + } + if (!(proceed = switch_regex_perform(field_data, expression, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) { switch_regex_safe_free(re); switch_safe_free(field_expanded); @@ -275,6 +279,10 @@ SWITCH_STANDARD_DIALPLAN(asterisk_dialplan_hunt) argument = ""; } + if (!field_data) { + field_data = ""; + } + if (strchr(expression, '(')) { switch_perform_substitution(re, proceed, argument, field_data, substituted, sizeof(substituted), ovector); argument = substituted;