lib/charset/charcnv: add next_codepoint_convenience_ext() that accepts input charset.
[samba.git] / lib / util / charset / charset.h
index 2c8aa41ad5c78287c4ce627b4664dfaacfbef0b9..7960631484dcf771ccc4c1900c3fca2669d31463 100644 (file)
@@ -39,6 +39,24 @@ typedef enum {CH_UTF16LE=0, CH_UTF16=0, CH_UNIX, CH_DISPLAY, CH_DOS, CH_UTF8, CH
 
 typedef uint16_t smb_ucs2_t;
 
+#ifdef WORDS_BIGENDIAN
+#define UCS2_SHIFT 8
+#else
+#define UCS2_SHIFT 0
+#endif
+
+/* turn a 7 bit character into a ucs2 character */
+#define UCS2_CHAR(c) ((c) << UCS2_SHIFT)
+
+/* return an ascii version of a ucs2 character */
+#define UCS2_TO_CHAR(c) (((c) >> UCS2_SHIFT) & 0xff)
+
+/* Copy into a smb_ucs2_t from a possibly unaligned buffer. Return the copied smb_ucs2_t */
+#define COPY_UCS2_CHAR(dest,src) (((unsigned char *)(dest))[0] = ((unsigned char *)(src))[0],\
+                               ((unsigned char *)(dest))[1] = ((unsigned char *)(src))[1], (dest))
+
+
+
 /*
  *   for each charset we have a function that pulls from that charset to
  *     a ucs2 buffer, and a function that pushes to a ucs2 buffer
@@ -154,6 +172,9 @@ codepoint_t next_codepoint(const char *str, size_t *size);
 ssize_t push_codepoint(char *str, codepoint_t c);
 
 /* codepoints */
+codepoint_t next_codepoint_convenience_ext(struct smb_iconv_convenience *ic,
+                           const char *str, charset_t src_charset,
+                           size_t *size);
 codepoint_t next_codepoint_convenience(struct smb_iconv_convenience *ic, 
                            const char *str, size_t *size);
 ssize_t push_codepoint_convenience(struct smb_iconv_convenience *ic, 
@@ -163,10 +184,11 @@ codepoint_t tolower_m(codepoint_t val);
 int codepoint_cmpi(codepoint_t c1, codepoint_t c2);
 
 /* Iconv convenience functions */
-struct smb_iconv_convenience *smb_iconv_convenience_init(TALLOC_CTX *mem_ctx,
-                                                        const char *dos_charset,
-                                                        const char *unix_charset,
-                                                        bool native_iconv);
+struct smb_iconv_convenience *smb_iconv_convenience_reinit(TALLOC_CTX *mem_ctx,
+                                                          const char *dos_charset,
+                                                          const char *unix_charset,
+                                                          bool native_iconv,
+                                                          struct smb_iconv_convenience *old_ic);
 
 bool convert_string_convenience(struct smb_iconv_convenience *ic,
                                charset_t from, charset_t to,
@@ -242,7 +264,7 @@ static size_t CHARSETNAME ## _pull(void *cd, const char **inbuf, size_t *inbytes
                         char **outbuf, size_t *outbytesleft)                                   \
 {                                                                                              \
        while (*inbytesleft >= 1 && *outbytesleft >= 2) {                                       \
-               *(uint16*)(*outbuf) = to_ucs2[((unsigned char*)(*inbuf))[0]];                   \
+               SSVAL(*outbuf, 0, to_ucs2[((unsigned char*)(*inbuf))[0]]);                      \
                (*inbytesleft)  -= 1;                                                           \
                (*outbytesleft) -= 2;                                                           \
                (*inbuf)  += 1;                                                                 \