]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/unicode/charcnv.c
Merge master
[netatalk.git] / libatalk / unicode / charcnv.c
index 6deaeb8c6b60bb68c6b6ff26ba1c15d0fcd42af2..7859a228ea1f9756b4a6c5fd72dc585eeff1aadf 100644 (file)
 #if HAVE_LANGINFO_H
 #include <langinfo.h>
 #endif
+#include <arpa/inet.h>
 
-#include <netatalk/endian.h>
 #include <atalk/logger.h>
 #include <atalk/unicode.h>
 #include <atalk/util.h>
+#include <atalk/compat.h>
+
 #include "byteorder.h"
 
 
@@ -139,13 +141,11 @@ static const char *charset_name(charset_t ch)
     if (!ret)
         ret = charset_names[ch];
 
-#if defined(HAVE_NL_LANGINFO) && defined(CODESET)
+#if defined(CODESET)
     if (ret && strcasecmp(ret, "LOCALE") == 0) {
         const char *ln = NULL;
 
-#ifdef HAVE_SETLOCALE
         setlocale(LC_ALL, "");
-#endif
         ln = nl_langinfo(CODESET);
         if (ln) {
             /* Check whether the charset name is supported
@@ -191,7 +191,7 @@ static void lazy_initialize_conv(void)
     }
 }
 
-charset_t add_charset(char* name)
+charset_t add_charset(const char* name)
 {
     static charset_t max_charset_t = NUM_CHARSETS-1;
     charset_t cur_charset_t = max_charset_t+1;
@@ -768,9 +768,9 @@ char * debug_out ( char * seq, size_t len)
  *      for e.g. HFS cdroms.
  */
 
-static size_t pull_charset_flags (charset_t from_set, charset_t cap_set, const char *src, size_t srclen, char* dest, size_t destlen, u_int16_t *flags)
+static size_t pull_charset_flags (charset_t from_set, charset_t cap_set, const char *src, size_t srclen, char* dest, size_t destlen, uint16_t *flags)
 {
-    const u_int16_t option = (flags ? *flags : 0);
+    const uint16_t option = (flags ? *flags : 0);
     size_t i_len, o_len;
     size_t j = 0;
     const char* inbuf = (const char*)src;
@@ -880,15 +880,16 @@ end:
  */
 
 
-static size_t push_charset_flags (charset_t to_set, charset_t cap_set, char* src, size_t srclen, char* dest, size_t destlen, u_int16_t *flags)
+static size_t push_charset_flags (charset_t to_set, charset_t cap_set, char* src, size_t srclen, char* dest, size_t destlen, uint16_t *flags)
 {
-    const u_int16_t option = (flags ? *flags : 0);
+    const uint16_t option = (flags ? *flags : 0);
     size_t i_len, o_len, i;
     size_t j = 0;
     const char* inbuf = (const char*)src;
     char* outbuf = (char*)dest;
     atalk_iconv_t descriptor;
     atalk_iconv_t descriptor_cap;
+    char escch;                 /* 150210: uninitialized OK, depends on j */
 
     descriptor = conv_handles[CH_UCS2][to_set];
     descriptor_cap = conv_handles[CH_UCS2][cap_set];
@@ -920,13 +921,21 @@ static size_t push_charset_flags (charset_t to_set, charset_t cap_set, char* src
         if ((option & CONV_ESCAPEHEX)) {
             for (i = 0; i < i_len; i += 2) {
                 ucs2_t c = SVAL(inbuf, i);
-                if (c == 0x002f) { /* 0x002f = / */
+                switch (c) {
+                case 0x003a: /* 0x003a = ':' */
+                    if ( ! (option & CONV_ALLOW_COLON)) {
+                        errno = EILSEQ;
+                        goto end;
+                    }
+                    escch = c;
+                    j = i_len - i;
+                    i_len = i;
+                    break;
+                case 0x002f: /* 0x002f = '/' */
+                    escch = c;
                     j = i_len - i;
                     i_len = i;
                     break;
-                } else if (c == 0x003a) { /* 0x003a = : */
-                    errno = EILSEQ;
-                    goto end;
                 }
             }
         }
@@ -985,9 +994,27 @@ static size_t push_charset_flags (charset_t to_set, charset_t cap_set, char* src
                 errno = E2BIG;
                 goto end;
             }
-            *outbuf++ = ':';
-            *outbuf++ = '2';
-            *outbuf++ = 'f';
+            switch (escch) {
+            case '/':
+                *outbuf++ = ':';
+                *outbuf++ = '2';
+                *outbuf++ = 'f';
+                break;
+            case ':':
+                *outbuf++ = ':';
+                *outbuf++ = '3';
+                *outbuf++ = 'a';
+                break;
+            default:
+                /*
+                 *  THIS SHOULD NEVER BE REACHED !!!
+                 *  As a safety net I put in a ' ' here
+                 */
+                *outbuf++ = ':';
+                *outbuf++ = '2';
+                *outbuf++ = '0';
+                break;
+            }
             o_len -= 3;
             inbuf += 2;
             i_len -= 2;
@@ -1002,7 +1029,7 @@ end:
  * FIXME the size is a mess we really need a malloc/free logic
  *`dest size must be dest_len +2
  */
-size_t convert_charset ( charset_t from_set, charset_t to_set, charset_t cap_charset, const char *src, size_t src_len, char *dest, size_t dest_len, u_int16_t *flags)
+size_t convert_charset ( charset_t from_set, charset_t to_set, charset_t cap_charset, const char *src, size_t src_len, char *dest, size_t dest_len, uint16_t *flags)
 {
     size_t i_len, o_len;
     ucs2_t *u;