diff options
author | Alexandra Ellwood <lxs@mit.edu> | 2008-10-24 00:57:10 +0000 |
---|---|---|
committer | Alexandra Ellwood <lxs@mit.edu> | 2008-10-24 00:57:10 +0000 |
commit | ca5593dbd4286e34c0248df3123e66222913e045 (patch) | |
tree | af1f37074c869159ebcc62b9c5c03f350682c08f /src | |
parent | 70296e1f530313283f9a48dd0ec467e5c280a79d (diff) | |
download | krb5-ca5593dbd4286e34c0248df3123e66222913e045.tar.gz krb5-ca5593dbd4286e34c0248df3123e66222913e045.tar.xz krb5-ca5593dbd4286e34c0248df3123e66222913e045.zip |
Add support for localizing krb5 errors on Mac OS X.
Split into a separate function to make it easier to add
support for other localization techniques.
ticket: 6245
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20913 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src')
-rw-r--r-- | src/util/support/errors.c | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/src/util/support/errors.c b/src/util/support/errors.c index d1aa485c5..cec10337f 100644 --- a/src/util/support/errors.c +++ b/src/util/support/errors.c @@ -11,6 +11,11 @@ #include "k5-platform.h" #include "supp-int.h" +#ifdef __APPLE__ +#import <CoreFoundation/CoreFoundation.h> +#include "kim_library_private.h" +#endif + /* It would be nice to just use error_message() always. Pity that it's defined in a library that depends on this one, and we're not allowed to make circular dependencies. */ @@ -48,7 +53,7 @@ krb5int_vset_error (struct errinfo *ep, long code, va_list args2; if (ep->msg && ep->msg != ep->scratch_buf) { - free (ep->msg); + free ((char *) ep->msg); ep->msg = NULL; } ep->code = code; @@ -66,6 +71,60 @@ krb5int_vset_error (struct errinfo *ep, long code, ep->msg = p ? p : ep->scratch_buf; } +static inline char * +krb5int_get_localized_error (const char *string) +{ + char *loc_string = NULL; + +#ifdef __APPLE__ + if (kim_library_allow_home_directory_access ()) { + CFStringRef cfstring = NULL; + + cfstring = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, + string, + kCFStringEncodingUTF8, + kCFAllocatorNull); + if (cfstring) { + CFStringRef loc_cfstring = NULL; + + loc_cfstring = CFCopyLocalizedString(cfstring, ""); + if (loc_cfstring) { + char *loc_ptr = NULL; + + /* check if loc_cfstring is a UTF8 string internally + * so we can avoid using CFStringGetMaximumSizeForEncoding */ + loc_ptr = (char *) CFStringGetCStringPtr(loc_cfstring, + kCFStringEncodingUTF8); + if (loc_ptr) { + loc_string = strdup(loc_ptr); + + } else { + CFIndex len = 0; + + len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(loc_cfstring), + kCFStringEncodingUTF8) + 1; + + loc_string = malloc(len); + if (loc_string) { + if (!CFStringGetCString(loc_cfstring, loc_string, + len, kCFStringEncodingUTF8)) { + /* Conversion to C string failed. */ + free (loc_string); + loc_string = NULL; + } + } + } + + CFRelease(loc_cfstring); + } + + CFRelease(cfstring); + } + } +#endif + return loc_string; +} + const char * krb5int_get_error (struct errinfo *ep, long code) { @@ -130,7 +189,13 @@ krb5int_get_error (struct errinfo *ep, long code) unlock(); goto format_number; } - r2 = strdup (r); + + r2 = krb5int_get_localized_error(r); + + if (r2 == NULL) { + r2 = strdup(r); + } + if (r2 == NULL) { strncpy(ep->scratch_buf, r, sizeof(ep->scratch_buf)); unlock(); |