]> arthur.barton.de Git - netatalk.git/commitdiff
unix charset is UTF8 by default.
authorHAT <hat@fa2.so-net.ne.jp>
Tue, 10 Apr 2012 16:08:32 +0000 (01:08 +0900)
committerHAT <hat@fa2.so-net.ne.jp>
Tue, 10 Apr 2012 16:08:32 +0000 (01:08 +0900)
vol charset is same value as unix charset by default.
If UTF-8 is set, change into UTF8.

NEWS
include/atalk/netatalk_conf.h
libatalk/unicode/charcnv.c
libatalk/util/netatalk_conf.c

diff --git a/NEWS b/NEWS
index 612d6892c9b09fe304b11d131e0a481f8facbde4..854d591cbc33ba74c8618804949a2c7aa660ab92 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,8 @@ Changes in 3.0 alpha3
 =====================
 
 * NEW: afpd: Per volume "login message", NetAFP bug ID #18
+* UPD: unix charset is UTF8 by default
+       vol charset is same value as unix charset by default
 
 Changes in 3.0 alpha2
 =====================
index 4c9148576238b1c77ec47c3aee373ba57c848268..a9ece1a1c6fafeea75011e6f3a526c26da5b66b5 100644 (file)
@@ -31,4 +31,6 @@ extern struct vol *getvolbypath(AFPObj *obj, const char *path);
 extern struct vol *getvolbyname(const char *name);
 extern void       volume_free(struct vol *vol);
 extern void       volume_unlink(struct vol *volume);
+
+extern char* charset_names[];
 #endif
index 455a72622ef9fb0f2aa7543aec6bfe6feb651c57..d3b5fee6e8bd1156b3ca57ef45ab74e05516d78d 100644 (file)
 #ifdef HAVE_USABLE_ICONV
 #include <iconv.h>
 #endif
-#if HAVE_LOCALE_H
-#include <locale.h>
-#endif
-#if HAVE_LANGINFO_H
-#include <langinfo.h>
-#endif
 #include <arpa/inet.h>
 
 #include <atalk/logger.h>
@@ -73,7 +67,7 @@
 #define CHECK_FLAGS(a,b) (((a)!=NULL) ? (*(a) & (b)) : 0 )
 
 static atalk_iconv_t conv_handles[MAX_CHARSETS][MAX_CHARSETS];
-static char* charset_names[MAX_CHARSETS];
+char* charset_names[MAX_CHARSETS];
 static struct charset_functions* charsets[MAX_CHARSETS];
 static char hexdig[] = "0123456789abcdef";
 #define hextoint( c )   ( isdigit( c ) ? c - '0' : c + 10 - 'a' )
@@ -85,67 +79,11 @@ static char hexdig[] = "0123456789abcdef";
 static const char *charset_name(charset_t ch)
 {
     const char *ret = NULL;
-    static int first = 1;
-    static char macname[128];
-    static char unixname[128];
-
-    if (first) {
-        memset(macname, 0, sizeof(macname));
-        memset(unixname, 0, sizeof(unixname));
-        first = 0;
-    }
 
     if (ch == CH_UCS2) ret = "UCS-2";
     else if (ch == CH_UTF8) ret = "UTF8";
     else if (ch == CH_UTF8_MAC) ret = "UTF8-MAC";
-    else if (ch == CH_UNIX) {
-        if (unixname[0] == '\0') {
-            ret = "LOCALE";
-            strlcpy(unixname, ret, sizeof(unixname));
-        }
-        else
-            ret = unixname;
-    }
-    else if (ch == CH_MAC) {
-        if (macname[0] == '\0') {
-            ret = "MAC_ROMAN";
-            strlcpy(macname, ret, sizeof(macname));
-        }
-        else
-            ret = macname;
-    }
-
-    if (!ret)
-        ret = charset_names[ch];
-
-#if defined(CODESET)
-    if (ret && strcasecmp(ret, "LOCALE") == 0) {
-        const char *ln = NULL;
-
-        setlocale(LC_ALL, "");
-        ln = nl_langinfo(CODESET);
-        if (ln) {
-            /* Check whether the charset name is supported
-               by iconv */
-            LOG(log_debug, logtype_default, "Locale charset is '%s'", ln);
-            atalk_iconv_t handle = atalk_iconv_open(ln, "UCS-2");
-            if (handle == (atalk_iconv_t) -1) {
-                LOG(log_warning, logtype_default, "Locale charset '%s' unsupported, using ASCII instead", ln);
-                ln = "ASCII";
-            } else {
-                atalk_iconv_close(handle);
-            }
-            if (ch==CH_UNIX)
-                strlcpy(unixname, ln, sizeof(unixname));
-        }
-        ret = ln;
-    }
-#else /* system doesn't have LOCALE support */
-    LOG(log_warning, logtype_default, "system doesn't have LOCALE support");
-    if (ch == CH_UNIX) ret = NULL;
-#endif
-
-    if (!ret || !*ret) ret = "ASCII";
+    else ret = charset_names[ch];
     return ret;
 }
 
index 309feb950c2cfb2263037c6c008090bc2bd551c7..26c80f112e4812b86b51ec953d21492c533bab7b 100644 (file)
 #include <inttypes.h>
 #include <time.h>
 #include <regex.h>
+#if HAVE_LOCALE_H
+#include <locale.h>
+#endif
+#if HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
 
 #include <atalk/afp.h>
 #include <atalk/util.h>
@@ -626,16 +632,24 @@ static struct vol *creatvol(AFPObj *obj,
         EC_NULL( volume->v_veto = strdup(val) );
 
     /* vol charset is in [G] and [V] */
-    if (val = getoption(obj->iniconfig, section, "vol charset", preset, NULL))
+    if (val = getoption(obj->iniconfig, section, "vol charset", preset, NULL)) {
+        if (strcasecmp(val, "UTF-8") == 0) {
+            val = strdup("UTF8");
+        }
         EC_NULL( volume->v_volcodepage = strdup(val) );
+    }
     else
         EC_NULL( volume->v_volcodepage = strdup(obj->options.volcodepage) );
 
     /* mac charset is in [G] and [V] */
-    if (val = getoption(obj->iniconfig, section, "mac charset", preset, NULL))
+    if (val = getoption(obj->iniconfig, section, "mac charset", preset, NULL)) {
+        if (strncasecmp(val, "MAC", 3) != 0) {
+            LOG(log_warning, logtype_afpd, "Is '%s' really mac charset? ", val);
+        }
         EC_NULL( volume->v_maccodepage = strdup(val) );
+    }
     else
-        EC_NULL( volume->v_maccodepage = strdup(obj->options.maccodepage) );
+    EC_NULL( volume->v_maccodepage = strdup(obj->options.maccodepage) );
 
     bstring dbpath;
     EC_NULL_LOG( val = iniparser_getstring(obj->iniconfig, INISEC_GLOBAL, "vol dbpath", _PATH_STATEDIR "CNID/") );
@@ -1518,38 +1532,52 @@ int afp_config_parse(AFPObj *AFPObj, char *processname)
 
     /* unix charset is in [G] only */
     if (!(p = iniparser_getstring(config, INISEC_GLOBAL, "unix charset", NULL))) {
-        options->unixcharset = CH_UNIX;
-        options->unixcodepage = strdup("LOCALE");
+        options->unixcodepage = strdup("UTF8");
+        charset_names[CH_UNIX] = strdup("UTF8");
     } else {
-        if ((options->unixcharset = add_charset(p)) == (charset_t)-1) {
-            options->unixcharset = CH_UNIX;
-            options->unixcodepage = strdup("LOCALE");
-            LOG(log_warning, logtype_afpd, "Setting unix charset to '%s' failed", p);
-        } else {
-            options->unixcodepage = strdup(p);
+        if (strcasecmp(p, "LOCALE") == 0) {
+#if defined(CODESET)
+            setlocale(LC_ALL, "");
+            p = nl_langinfo(CODESET);
+            LOG(log_debug, logtype_afpd, "Locale charset is '%s'", p);
+#else /* system doesn't have LOCALE support */
+            LOG(log_warning, logtype_afpd, "system doesn't have LOCALE support");
+            p = strdup("UTF8");
+#endif
+        }
+        if (strcasecmp(p, "UTF-8") == 0) {
+            p = strdup("UTF8");
         }
+        options->unixcodepage = strdup(p);
+        charset_names[CH_UNIX] = strdup(p);
     }
+    options->unixcharset = CH_UNIX;
+    LOG(log_debug, logtype_afpd, "Global unix charset is %s", options->unixcodepage);
 
-    /* vol charset is in [G[ and [V] */
+    /* vol charset is in [G] and [V] */
     if (!(p = iniparser_getstring(config, INISEC_GLOBAL, "vol charset", NULL))) {
-        options->volcodepage = strdup("UTF8");
+        options->volcodepage = strdup(options->unixcodepage);
     } else {
+        if (strcasecmp(p, "UTF-8") == 0) {
+            p = strdup("UTF8");
+        }
         options->volcodepage = strdup(p);
     }
-       
+    LOG(log_debug, logtype_afpd, "Global vol charset is %s", options->volcodepage);
+    
     /* mac charset is in [G] and [V] */
     if (!(p = iniparser_getstring(config, INISEC_GLOBAL, "mac charset", NULL))) {
-        options->maccharset = CH_MAC;
         options->maccodepage = strdup("MAC_ROMAN");
+        charset_names[CH_MAC] = strdup("MAC_ROMAN");
     } else {
-        if ((options->maccharset = add_charset(p)) == (charset_t)-1) {
-            options->maccharset = CH_MAC;
-            options->maccodepage = strdup("MAC_ROMAN");
-            LOG(log_warning, logtype_afpd, "Setting mac charset to '%s' failed", p);
-        } else {
-            options->maccodepage = strdup(p);
+        if (strncasecmp(p, "MAC", 3) != 0) {
+            LOG(log_warning, logtype_afpd, "Is '%s' really mac charset? ", p);
         }
+        options->maccodepage = strdup(p);
+        charset_names[CH_MAC] = strdup(p);
     }
+    options->maccharset = CH_MAC;
+    LOG(log_debug, logtype_afpd, "Global mac charset is %s", options->maccodepage);
 
     /* Check for sane values */
     if (options->tickleval <= 0)