From 9d9b44e5f6a50f7ee890422921cba1cb5598da11 Mon Sep 17 00:00:00 2001 From: lazedo <luis.azedo@factorlusitano.com> Date: Thu, 7 Jun 2018 08:45:34 +0000 Subject: [PATCH] FS-11184 [core] retry xml_locate_language for primary language --- src/switch_xml.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/switch_xml.c b/src/switch_xml.c index 4ef0e9ec6c..398a7e2375 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -3144,7 +3144,7 @@ SWITCH_DECLARE(int) switch_xml_std_datetime_check(switch_xml_t xcond, int *offse return time_match; } -SWITCH_DECLARE(switch_status_t) switch_xml_locate_language(switch_xml_t *root, switch_xml_t *node, switch_event_t *params, switch_xml_t *language, switch_xml_t *phrases, switch_xml_t *macros, const char *str_language) { +SWITCH_DECLARE(switch_status_t) switch_xml_locate_language_ex(switch_xml_t *root, switch_xml_t *node, switch_event_t *params, switch_xml_t *language, switch_xml_t *phrases, switch_xml_t *macros, const char *str_language) { switch_status_t status = SWITCH_STATUS_FALSE; if (switch_xml_locate("languages", NULL, NULL, NULL, root, node, params, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) { @@ -3201,6 +3201,24 @@ done: return status; } +SWITCH_DECLARE(switch_status_t) switch_xml_locate_language(switch_xml_t *root, switch_xml_t *node, switch_event_t *params, switch_xml_t *language, switch_xml_t *phrases, switch_xml_t *macros, const char *str_language) { + switch_status_t status; + + if ((status = switch_xml_locate_language_ex(root, node, params, language, phrases, macros, str_language)) != SWITCH_STATUS_SUCCESS) { + const char *str_language_dup = strdup(str_language); + char *secondary; + if ((secondary=strchr(str_language_dup, '-')) != NULL) { + *secondary++ = '\0'; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "language %s not found. trying %s by removing %s\n", str_language, str_language_dup, secondary); + switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "lang", str_language_dup); + status = switch_xml_locate_language_ex(root, node, params, language, phrases, macros, str_language_dup); + } + switch_safe_free(str_language_dup); + } + + return status; +} + #ifdef WIN32 /* * globbing functions for windows, part of libc on unix, this code was cut and paste from