]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-11184 [core] retry xml_locate_language for primary language
authorlazedo <luis.azedo@factorlusitano.com>
Thu, 7 Jun 2018 08:45:34 +0000 (08:45 +0000)
committerlazedo <luis.azedo@factorlusitano.com>
Tue, 12 Feb 2019 15:50:20 +0000 (15:50 +0000)
src/switch_xml.c

index 4ef0e9ec6cbe33223333bf741da4caa9abccc03a..398a7e23751c04587fe95f3ca1e2a9c34aad7be6 100644 (file)
@@ -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