diff options
author | Bryan Ferris <bferris@google.com> | 2019-06-21 10:25:17 -0700 |
---|---|---|
committer | Huizi Yang <yanghuiz@google.com> | 2019-10-08 13:25:58 -0700 |
commit | a7ce39ea6e8d314ba79e223f65de27dc2e8242df (patch) | |
tree | ff10b1784fa8bb9526cc90e9bf096bb86fba165b /cups/language.c | |
parent | c502782684f80d59143311acbb334205784ea036 (diff) | |
download | libcups-oreo-mr1-security-release.tar.gz |
Update libcups to v2.2.9 RESTRICT AUTOMERGEandroid-security-8.1.0_r93android-security-8.1.0_r92android-security-8.1.0_r91android-security-8.1.0_r90android-security-8.1.0_r89android-security-8.1.0_r88android-security-8.1.0_r87android-security-8.1.0_r86android-security-8.1.0_r85android-security-8.1.0_r84android-security-8.1.0_r83android-security-8.1.0_r82android-8.1.0_r81android-8.1.0_r80android-8.1.0_r79android-8.1.0_r78android-8.1.0_r77android-8.1.0_r76android-8.1.0_r75android-8.1.0_r74android-8.1.0_r73android-8.1.0_r72android-8.1.0_r71security-oc-mr1-releaseoreo-mr1-security-release
Bug: 111210196
Test: adb shell am instrument -w android.print.cts/android.support.test.runner.AndroidJUnitRunner
Change-Id: Idb1ecb93551bf6f77527513ddfb3de4bfd70c092
(cherry picked from commit 1d296f843dadb333dc298f0b7d9c528c604dfdad)
Diffstat (limited to 'cups/language.c')
-rw-r--r-- | cups/language.c | 76 |
1 files changed, 67 insertions, 9 deletions
diff --git a/cups/language.c b/cups/language.c index f3a3496b..61280c0f 100644 --- a/cups/language.c +++ b/cups/language.c @@ -21,11 +21,11 @@ #ifdef HAVE_LANGINFO_H # include <langinfo.h> #endif /* HAVE_LANGINFO_H */ -#ifdef WIN32 +#ifdef _WIN32 # include <io.h> #else # include <unistd.h> -#endif /* WIN32 */ +#endif /* _WIN32 */ #ifdef HAVE_COREFOUNDATION_H # include <CoreFoundation/CoreFoundation.h> #endif /* HAVE_COREFOUNDATION_H */ @@ -123,7 +123,9 @@ static const _apple_language_locale_t apple_language_locale[] = { "nb", "no" }, { "nb_NO", "no" }, { "zh-Hans", "zh_CN" }, + { "zh_HANS", "zh_CN" }, { "zh-Hant", "zh_TW" }, + { "zh_HANT", "zh_TW" }, { "zh-Hant_CN", "zh_TW" } }; #endif /* __APPLE__ */ @@ -254,7 +256,15 @@ _cupsAppleLocale(CFStringRef languageName, /* I - Apple language ID */ { int i; /* Looping var */ CFStringRef localeName; /* Locale as a CF string */ +#ifdef DEBUG + char temp[1024]; /* Temporary string */ + + if (!CFStringGetCString(languageName, temp, (CFIndex)sizeof(temp), kCFStringEncodingASCII)) + temp[0] = '\0'; + + DEBUG_printf(("_cupsAppleLocale(languageName=%p(%s), locale=%p, localsize=%d)", (void *)languageName, temp, (void *)locale, (int)localesize)); +#endif /* DEBUG */ localeName = CFLocaleCreateCanonicalLocaleIdentifierFromString(kCFAllocatorDefault, languageName); @@ -267,6 +277,8 @@ _cupsAppleLocale(CFStringRef languageName, /* I - Apple language ID */ if (!CFStringGetCString(localeName, locale, (CFIndex)localesize, kCFStringEncodingASCII)) *locale = '\0'; + DEBUG_printf(("_cupsAppleLocale: locale=\"%s\"", locale)); + CFRelease(localeName); /* @@ -278,8 +290,12 @@ _cupsAppleLocale(CFStringRef languageName, /* I - Apple language ID */ sizeof(apple_language_locale[0])); i ++) { - if (!strcmp(locale, apple_language_locale[i].language)) + size_t len = strlen(apple_language_locale[i].language); + + if (!strcmp(locale, apple_language_locale[i].language) || + (!strncmp(locale, apple_language_locale[i].language, len) && (locale[len] == '_' || locale[len] == '-'))) { + DEBUG_printf(("_cupsAppleLocale: Updating locale to \"%s\".", apple_language_locale[i].locale)); strlcpy(locale, apple_language_locale[i].locale, localesize); break; } @@ -296,7 +312,10 @@ _cupsAppleLocale(CFStringRef languageName, /* I - Apple language ID */ } if (!*locale) + { + DEBUG_puts("_cupsAppleLocale: Returning NULL."); return (NULL); + } /* * Convert language subtag into region subtag... @@ -304,10 +323,14 @@ _cupsAppleLocale(CFStringRef languageName, /* I - Apple language ID */ if (locale[2] == '-') locale[2] = '_'; + else if (locale[3] == '-') + locale[3] = '_'; if (!strchr(locale, '.')) strlcat(locale, ".UTF-8", localesize); + DEBUG_printf(("_cupsAppleLocale: Returning \"%s\".", locale)); + return (locale); } #endif /* __APPLE__ */ @@ -669,6 +692,15 @@ cupsLangGet(const char *language) /* I - Language or locale */ *ptr++ = (char)toupper(*language & 255); *ptr = '\0'; + + /* + * Map Chinese region codes to legacy country codes. + */ + + if (!strcmp(language, "zh") && !strcmp(country, "HANS")) + strlcpy(country, "CN", sizeof(country)); + if (!strcmp(language, "zh") && !strcmp(country, "HANT")) + strlcpy(country, "TW", sizeof(country)); } if (*language == '.' && !charset[0]) @@ -688,7 +720,7 @@ cupsLangGet(const char *language) /* I - Language or locale */ * Force a POSIX locale for an invalid language name... */ - if (strlen(langname) != 2) + if (strlen(langname) != 2 && strlen(langname) != 3) { strlcpy(langname, "C", sizeof(langname)); country[0] = '\0'; @@ -828,6 +860,9 @@ _cupsLangString(cups_lang_t *lang, /* I - Language */ { const char *s; /* Localized message */ + + DEBUG_printf(("_cupsLangString(lang=%p, message=\"%s\")", (void *)lang, message)); + /* * Range check input... */ @@ -1126,6 +1161,8 @@ _cupsMessageLookup(cups_array_t *a, /* I - Message array */ *match; /* Matching message */ + DEBUG_printf(("_cupsMessageLookup(a=%p, m=\"%s\")", (void *)a, m)); + /* * Lookup the message string; if it doesn't exist in the catalog, * then return the message that was passed to us... @@ -1336,11 +1373,13 @@ appleMessageLoad(const char *locale) /* I - Locale ID */ { char filename[1024], /* Path to cups.strings file */ applelang[256], /* Apple language ID */ - baselang[3]; /* Base language */ + baselang[4]; /* Base language */ CFURLRef url; /* URL to cups.strings file */ CFReadStreamRef stream = NULL; /* File stream */ CFPropertyListRef plist = NULL; /* Localization file */ #ifdef DEBUG + const char *cups_strings = getenv("CUPS_STRINGS"); + /* Test strings file */ CFErrorRef error = NULL; /* Error when opening file */ #endif /* DEBUG */ @@ -1351,6 +1390,15 @@ appleMessageLoad(const char *locale) /* I - Locale ID */ * Load the cups.strings file... */ +#ifdef DEBUG + if (cups_strings) + { + DEBUG_puts("1appleMessageLoad: Using debug CUPS_STRINGS file."); + strlcpy(filename, cups_strings, sizeof(filename)); + } + else +#endif /* DEBUG */ + snprintf(filename, sizeof(filename), CUPS_BUNDLEDIR "/Resources/%s.lproj/cups.strings", _cupsAppleLanguage(locale, applelang, sizeof(applelang))); @@ -1363,6 +1411,7 @@ appleMessageLoad(const char *locale) /* I - Locale ID */ * Try with original locale string... */ + DEBUG_printf(("1appleMessageLoad: \"%s\": %s", filename, strerror(errno))); snprintf(filename, sizeof(filename), CUPS_BUNDLEDIR "/Resources/%s.lproj/cups.strings", locale); } @@ -1374,18 +1423,23 @@ appleMessageLoad(const char *locale) /* I - Locale ID */ * Try with just the language code... */ + DEBUG_printf(("1appleMessageLoad: \"%s\": %s", filename, strerror(errno))); + strlcpy(baselang, locale, sizeof(baselang)); + if (baselang[3] == '-' || baselang[3] == '_') + baselang[3] = '\0'; + snprintf(filename, sizeof(filename), CUPS_BUNDLEDIR "/Resources/%s.lproj/cups.strings", baselang); } - DEBUG_printf(("1appleMessageLoad: filename=\"%s\"", filename)); - if (access(filename, 0)) { /* * Try alternate lproj directory names... */ + DEBUG_printf(("1appleMessageLoad: \"%s\": %s", filename, strerror(errno))); + if (!strncmp(locale, "en", 2)) locale = "English"; else if (!strncmp(locale, "nb", 2)) @@ -1402,7 +1456,7 @@ appleMessageLoad(const char *locale) /* I - Locale ID */ locale = "Japanese"; else if (!strncmp(locale, "es", 2)) locale = "Spanish"; - else if (!strcmp(locale, "zh_HK") || !strncmp(locale, "zh-Hant", 7)) + else if (!strcmp(locale, "zh_HK") || !strncasecmp(locale, "zh-Hant", 7) || !strncasecmp(locale, "zh_Hant", 7)) { /* * <rdar://problem/22130168> @@ -1423,14 +1477,18 @@ appleMessageLoad(const char *locale) /* I - Locale ID */ */ strlcpy(baselang, locale, sizeof(baselang)); + if (baselang[2] == '-' || baselang[2] == '_') + baselang[2] = '\0'; + locale = baselang; } snprintf(filename, sizeof(filename), CUPS_BUNDLEDIR "/Resources/%s.lproj/cups.strings", locale); - DEBUG_printf(("1appleMessageLoad: alternate filename=\"%s\"", filename)); } + DEBUG_printf(("1appleMessageLoad: filename=\"%s\"", filename)); + url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (UInt8 *)filename, (CFIndex)strlen(filename), false); |