#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>
#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' )
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;
}
#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>
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/") );
/* 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)