internationalize comerr
authorDerrick Brashear <shadow@dementia.org>
Wed, 3 Feb 2010 15:16:53 +0000 (10:16 -0500)
committerDerrick Brashear <shadow@dementia.org>
Tue, 9 Feb 2010 18:21:03 +0000 (10:21 -0800)
reuse the Heimdal method for internationalizing comerr. as a side effect
provide heimdal-compatible com_right.

LICENSE BSD

Change-Id: I6e699125ad3af1d402f14f9462e434c30ad4d1fd
Reviewed-on: http://gerrit.openafs.org/1225
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

acinclude.m4
src/cf/osconf.m4
src/cf/test_package.m4 [new file with mode: 0644]
src/comerr/com_err.h
src/comerr/error_msg.c
src/comerr/error_table.h
src/config/Makefile.config.in
src/finale/translate_et.c
src/kauth/Makefile.in
src/libuafs/Makefile.common.in

index 5750efe..720efbe 100644 (file)
@@ -1445,6 +1445,8 @@ AC_CHECK_TYPES([fsblkcnt_t],,,[
 #endif
 ])
 
+OPENAFS_TEST_PACKAGE(libintl,[#include <libintl.h>],[-lintl],,,INTL)
+
 dnl Don't build PAM on IRIX; the interface doesn't work for us.
 if test "$ac_cv_header_security_pam_modules_h" = yes -a "$enable_pam" = yes; then
         case $AFS_SYSNAME in
index 071feee..61e9403 100644 (file)
@@ -8,7 +8,7 @@ RXDEBUG="-DRXDEBUG"
 SHLIB_SUFFIX="so"
 CCOBJ="$CC"
 MT_CC="$CC"
-XLIBS="${LIB_AFSDB} ${XBSA_XLIBS}"
+XLIBS="${LIB_AFSDB} ${XBSA_XLIBS} ${LIB_libintl}"
 
 dnl debugging and optimization flag defaults
 dnl Note, these are all the defaults for if debug/optimize turned on, and
@@ -541,6 +541,7 @@ case $AFS_SYSNAME in
                EXTRA_VLIBOBJS="fstab.o"
                SHLIB_LINKER="${MT_CC} -dynamiclib"
                SHLIB_SUFFIX="dylib"
+               XLIBS="${LIB_AFSDB} ${XBSA_XLIBS} -framework CoreFoundation"
                ;;
 
        *_darwin_80)
@@ -561,6 +562,7 @@ case $AFS_SYSNAME in
                SHLIB_LINKER="${MT_CC} -dynamiclib"
                SHLIB_SUFFIX="dylib"
                RANLIB="ranlib -c"
+               XLIBS="${LIB_AFSDB} ${XBSA_XLIBS} -framework CoreFoundation"
                ;;
 
        *_darwin_90)
@@ -579,13 +581,14 @@ case $AFS_SYSNAME in
                SHLIB_LINKER="${MT_CC} -dynamiclib"
                SHLIB_SUFFIX="dylib"
                RANLIB="ranlib -c"
+               XLIBS="${LIB_AFSDB} ${XBSA_XLIBS} -framework CoreFoundation"
                ;;
 
        *_darwin_100)
                AFSD_LDFLAGS="-F/System/Library/PrivateFrameworks -framework DiskArbitration -framework SystemConfiguration -framework IOKit -framework CoreFoundation"
                LEX="lex -l"
                MT_CFLAGS='-DAFS_PTHREAD_ENV -D_REENTRANT ${XCFLAGS} ${ARCHFLAGS}'
-               MT_LIBS="-lresolv"
+               MT_LIBS="${LIB_AFSDB} -framework CoreFoundation"
                KROOT=
                KINCLUDES='-I$(KROOT)/System/Library/Frameworks/Kernel.framework/Headers'
                LD="cc"
@@ -599,6 +602,7 @@ case $AFS_SYSNAME in
                SHLIB_LINKER="${MT_CC} -dynamiclib"
                SHLIB_SUFFIX="dylib"
                RANLIB="ranlib"
+               XLIBS="${LIB_AFSDB} ${XBSA_XLIBS} -framework CoreFoundation"
                ;;
 
        ppc_linux*)
@@ -628,7 +632,7 @@ case $AFS_SYSNAME in
                SHLIB_SUFFIX="o"
                TXLIBS="-lcurses"
                XCFLAGS="-K -D_NONSTD_TYPES -D_MBI=void"
-               XLIBS="${LIB_AFSDB} -ldl"
+               XLIBS="${LIB_AFSDB} ${LIB_libintl} -ldl"
                SHLIB_LINKER="${MT_CC} -bM:SRE -berok"
                AIX32=""
                AIX64="#"
@@ -647,7 +651,7 @@ case $AFS_SYSNAME in
                SHLIB_SUFFIX="o"
                TXLIBS="-lcurses"
                XCFLAGS="-K -D_NONSTD_TYPES -D_MBI=void"
-               XLIBS="${LIB_AFSDB} -ldl"
+               XLIBS="${LIB_AFSDB} ${LIB_libintl} -ldl"
                SHLIB_LINKER="${MT_CC} -bM:SRE -berok"
                AIX32=""
                AIX64=""
@@ -665,7 +669,7 @@ case $AFS_SYSNAME in
                SHLIB_SUFFIX="o"
                TXLIBS="-lcurses"
                XCFLAGS="-K -D_NONSTD_TYPES -D_MBI=void"
-               XLIBS="${LIB_AFSDB} -ldl"
+               XLIBS="${LIB_AFSDB} ${LIB_libintl} -ldl"
                SHLIB_LINKER="${MT_CC} -bM:SRE -berok"
                AIX32=""
                AIX64=""
@@ -683,7 +687,7 @@ case $AFS_SYSNAME in
                SHLIB_SUFFIX="o"
                TXLIBS="-lcurses"
                XCFLAGS="-K -D_NONSTD_TYPES -D_MBI=void"
-               XLIBS="${LIB_AFSDB} -ldl"
+               XLIBS="${LIB_AFSDB} ${LIB_libintl} -ldl"
                SHLIB_LINKER="${MT_CC} -bM:SRE -berok"
                AIX32=""
                AIX64=""
@@ -701,7 +705,7 @@ case $AFS_SYSNAME in
                SHLIB_SUFFIX="o"
                TXLIBS="-lcurses"
                XCFLAGS="-K -D_NONSTD_TYPES -D_MBI=void"
-               XLIBS="${LIB_AFSDB} -ldl"
+               XLIBS="${LIB_AFSDB} ${LIB_libintl} -ldl"
                SHLIB_LINKER="${MT_CC} -bM:SRE -berok"
                AIX32="#"
                AIX64=""
diff --git a/src/cf/test_package.m4 b/src/cf/test_package.m4
new file mode 100644 (file)
index 0000000..5afe81a
--- /dev/null
@@ -0,0 +1,83 @@
+AC_DEFUN([OPENAFS_TEST_PACKAGE],[
+AC_ARG_WITH($1,
+[  --with-$1=dir                use $1 in dir])
+AC_ARG_WITH($1-lib,
+[  --with-$1-lib=dir            use $1 libraries in dir],
+[if test "$withval" = "yes" -o "$withval" = "no"; then
+  AC_MSG_ERROR([No argument for --with-$1-lib])
+elif test "X$with_$1" = "X"; then
+  with_$1=yes
+fi])
+AC_ARG_WITH($1-include,
+[  --with-$1-include=dir        use $1 headers in dir],
+[if test "$withval" = "yes" -o "$withval" = "no"; then
+  AC_MSG_ERROR([No argument for --with-$1-include])
+elif test "X$with_$1" = "X"; then
+  with_$1=yes
+fi])
+
+AC_MSG_CHECKING(for $1)
+
+case "$with_$1" in
+yes) ;;
+no)  ;;
+"")  ;;
+*)   if test "$with_$1_include" = ""; then
+       with_$1_include="$with_$1/include"
+       fi
+       if test "$with_$1_lib" = ""; then
+          with_$1_lib="$with_$1/lib$abilibdirext"
+          fi
+          ;;
+esac
+header_dirs=
+lib_dirs=
+d='$5'
+for i in $d; do
+    header_dirs="$header_dirs $i/include"
+    lib_dirs="$lib_dirs $i/lib$abilibdirext"
+done
+
+case "$with_$1_include" in
+yes) ;;
+no)  ;;
+*)   header_dirs="$with_$1_include $header_dirs";;
+esac
+case "$with_$1_lib" in
+yes) ;;
+no)  ;;
+*)   lib_dirs="$with_$1_lib $lib_dirs";;
+esac
+
+save_CFLAGS="$CFLAGS"
+save_LIBS="$LIBS"
+ires= lres=
+for i in $header_dirs; do
+    CFLAGS="-I$i $save_CFLAGS"
+    AC_TRY_COMPILE([$2],,ires=$i;break)
+done
+for i in $lib_dirs; do
+    LIBS="-L$i $3 $4 $save_LIBS"
+    AC_TRY_LINK([$2],,lres=$i;break)
+done
+CFLAGS="$save_CFLAGS"
+LIBS="$save_LIBS"
+
+if test "$ires" -a "$lres" -a "$with_$1" != "no"; then
+   $1_includedir="$ires"
+   $1_libdir="$lres"
+   INCLUDE_$1="-I$$1_includedir"
+   LIB_$1="-L$$1_libdir $3"
+   AC_DEFINE_UNQUOTED(m4_toupper($1),1,[Define if you have the $1 package.])
+   AC_DEFINE_UNQUOTED(m4_toupper(HAVE_$1),1,[Define if you have the $1 package.])
+   with_$1=yes
+   AC_MSG_RESULT([headers $ires, libraries $lres])
+else
+       INCLUDE_$1=
+       LIB_$1=
+       with_$1=no
+       AC_MSG_RESULT($with_$1)
+fi
+AC_SUBST(INCLUDE_$1)
+AC_SUBST(LIB_$1)
+])
index 7e357ff..4e47735 100644 (file)
@@ -21,6 +21,7 @@ extern void afs_com_err_va(const char *whoami, afs_int32 code, const char *fmt,
 
 extern const char *afs_error_table_name(afs_int32);
 extern const char *afs_error_message(afs_int32);
+extern const char *afs_error_message_localize(afs_int32 code, char *str, size_t len);
 extern
 void (*afs_set_com_err_hook
       (void (*)(const char *, afs_int32, const char *, va_list)))
index afa0c97..bd82275 100644 (file)
 #include <stdio.h>
 #include "error_table.h"
 #include "mit-sipb-cr.h"
+#ifdef HAVE_LIBINTL
+#include <libintl.h>
+#endif
+#ifdef AFS_DARWIN70_ENV
+#include <CoreFoundation/CoreFoundation.h>
+#endif
 #include <afs/errors.h>
 #include <afs/afsutil.h>
 #include <string.h>
@@ -109,43 +115,93 @@ volume_message(int code)
        return "unknown volume error";
 }
 
-const char *
-afs_error_message(afs_int32 code)
+#ifdef AFS_DARWIN70_ENV
+static_inline const char *
+_intlize(const char *msg, int base, char *str, size_t len)
+{
+    char domain[12 +20];
+    CFStringRef cfstring = CFStringCreateWithCString(kCFAllocatorSystemDefault,
+                                                    msg,
+                                                    kCFStringEncodingUTF8);
+    CFStringRef cfdomain;
+    CFBundleRef OpenAFSBundle = CFBundleGetBundleWithIdentifier(CFSTR("org.openafs.filesystems.afs"));
+
+    if (!str)
+       return msg;
+    snprintf(domain, sizeof(domain), "heim_com_err%d", base);
+    cfdomain = CFStringCreateWithCString(kCFAllocatorSystemDefault, domain,
+                                        kCFStringEncodingUTF8);
+    if (OpenAFSBundle != NULL)
+       cfstring = CFBundleCopyLocalizedString(OpenAFSBundle, cfstring,
+                                              cfstring, cfdomain);
+    CFStringGetCString(cfstring, str, len, kCFStringEncodingUTF8);
+    CFRelease(cfstring);
+    CFRelease(cfdomain);
+    return str;
+}
+#else
+static_inline const char *
+_intlize(const char *msg, int base, char *str, size_t len)
+{
+    char domain[12 +20];
+    if (!str)
+       return msg;
+    snprintf(domain, sizeof(domain), "heim_com_err%d", base);
+#if defined(HAVE_LIBINTL)
+    strlcpy(str, dgettext(domain, msg), len);
+#endif
+    return str;
+}
+#endif
+
+static const char *
+afs_error_message_int(struct et_list *list, afs_int32 code, char *str, size_t len)
 {
     int offset;
     struct et_list *et;
-    int table_num;
+    int table_num, unlock = 0;
     int started = 0;
     char *cp;
-    char *err_msg;
+    const char *err_msg;
 
     /* check for rpc errors first */
     if (code < 0)
-       return negative_message(code);
+       return _intlize(negative_message(code), -1, str, len);
 
     offset = code & ((1 << ERRCODE_RANGE) - 1);
     table_num = code - offset;
     if (!table_num) {
        if ((err_msg = strerror(offset)) != NULL)
-           return (err_msg);
+           return _intlize(err_msg, 0, str, len);
        else if (offset < 140)
-           return volume_message(code);
+           return _intlize(volume_message(code), 0, str, len);
        else
            goto oops;
     }
-    LOCK_ET_LIST;
-    for (et = _et_list; et; et = et->next) {
+    if (list) {
+       et = list;
+    } else {
+       LOCK_ET_LIST;
+       unlock = 1;
+       et = _et_list;
+    }
+    for (; et; et = et->next) {
        if (et->table->base == table_num) {
            /* This is the right table */
            if (et->table->n_msgs <= offset)
                goto oops;
-           UNLOCK_ET_LIST;
-           return (et->table->msgs[offset]);
+           err_msg = _intlize(et->table->msgs[offset], et->table->base,
+                              str, len);
+           if (unlock)
+               UNLOCK_ET_LIST;
+           return err_msg;
        }
     }
   oops:
-    UNLOCK_ET_LIST;
-    strlcpy(buffer, "Unknown code ", sizeof buffer);
+    if (unlock)
+       UNLOCK_ET_LIST;
+    /* Unknown code can be included in the negative errors catalog */
+    _intlize("Unknown code ", -1, buffer, sizeof buffer);
     if (table_num) {
        strlcat(buffer, afs_error_table_name(table_num), sizeof buffer);
        strlcat(buffer, " ", sizeof buffer);
@@ -168,6 +224,30 @@ afs_error_message(afs_int32 code)
     return (buffer);
 }
 
+const char *
+afs_error_message_localize(afs_int32 code, char *str, size_t len)
+{
+    return afs_error_message_int((struct et_list *)0, code, str, len);
+}
+
+const char *
+afs_com_right_r(struct et_list *list, long code, char *str, size_t len)
+{
+    return afs_error_message_int(list, (afs_int32)code, str, len);
+}
+
+const char *
+afs_com_right(struct et_list *list, long code)
+{
+    return afs_error_message_int(list, (afs_int32)code, (char *)0, 0);
+}
+
+const char *
+afs_error_message(afs_int32 code)
+{
+    return afs_error_message_int((struct et_list *)0, code, (char *)0, 0);
+}
+
 void
 afs_add_to_error_table(struct et_list *new_table)
 {
index e26b1c9..642cd95 100644 (file)
@@ -27,6 +27,9 @@ struct et_list {
 
 extern char const *afs_error_table_name(afs_int32 num);
 extern void afs_add_to_error_table(struct et_list *new_table);
+extern const char *afs_com_right(struct et_list *list, long code);
+extern const char *afs_com_right_r(struct et_list *list, long code, char *str, size_t len);
+
 #ifdef AFS_OLD_COM_ERR
 #define error_table_name        afs_error_table_name
 #define add_to_error_table(X) afs_add_to_error_table(X)
index c19fb46..49ad5de 100644 (file)
@@ -44,12 +44,14 @@ DARWIN_INFOFILE=@DARWIN_INFOFILE@
 DBG = @DBG@
 DEST = @DEST@
 FSINCLUDES = @FSINCLUDES@
+INCLUDE_LIBINTL = @INCLUDE_libintl@
 KERN_DBG = @KERN_DBG@
 KERN_OPTMZ = @KERN_OPTMZ@
 LD = @LD@
 LEX = @LEX@
 LIB_AFSDB = @LIB_AFSDB@
 LIBS = @LIBS@
+LIB_LIBINTL = @LIB_libintl@
 LINUX_KERNEL_PATH = @LINUX_KERNEL_PATH@
 LINUX_KERNEL_BUILD = @LINUX_KERNEL_BUILD@
 LINUX_LIBAFS_NAME = @LINUX_LIBAFS_NAME@
@@ -127,7 +129,7 @@ SHELL = /bin/sh
 # conditionalise them on that.
 
 COMMON_INCL=-I${TOP_OBJDIR}/src/config -I${TOP_INCDIR} -I${srcdir} -I.
-COMMON_CFLAGS=${DBG} ${OPTMZ} ${COMMON_INCL}
+COMMON_CFLAGS=${DBG} ${OPTMZ} ${COMMON_INCL} ${INCLUDE_LIBINTL}
 
 CFLAGS=${COMMON_CFLAGS} ${XCFLAGS} ${ARCHFLAGS} $(CFLAGS_NOERROR)
 LDFLAGS=${XLDFLAGS} ${ARCHFLAGS}
index 80159c0..136d332 100644 (file)
@@ -36,6 +36,7 @@ main(int argc, char *argv[])
     int i;
     afs_int32 code;
     afs_int32 offset;
+    char msgbuf[BUFSIZ];
 
 #ifdef AFS_AIX32_ENV
     /*
@@ -72,7 +73,7 @@ main(int argc, char *argv[])
        offset = code & ((1 << ERRCODE_RANGE) - 1);
 
        printf("%d (%s).%d = %s\n", (int)code, afs_error_table_name(code),
-              (int)offset, afs_error_message(code));
+              (int)offset, afs_error_message_localize(code, msgbuf, BUFSIZ));
     }
     return 0;
 }
index 934a4d5..4c7d1b5 100644 (file)
@@ -233,7 +233,7 @@ ka-forwarder: ka-forwarder.o
 rebuild.o: rebuild.c $(INCLS) AFS_component_version_number.o
 
 rebuild: rebuild.o kautils.o $(LIBS)
-       ${CC} ${LDFLAGS} -o rebuild rebuild.o kautils.o $(LIBS)
+       ${CC} ${LDFLAGS} -o rebuild rebuild.o kautils.o $(LIBS) ${XLIBS}
 
 #
 # Install targets
index b8aeed6..8f33816 100644 (file)
@@ -51,7 +51,7 @@ COMMON_INCLUDE = -I. -I.. -I../nfs \
         -I${TOP_OBJDIR}/src/vlserver \
        -I${TOP_OBJDIR}/src/libuafs \
         -I${TOP_INCDIR} \
-        -I${TOP_INCDIR}/afs 
+        -I${TOP_INCDIR}/afs @INCLUDE_libintl@
 
 # Build rules - CC and CFLAGS are defined in system specific MakefileProtos.