lib/util/charset: Remove 'display charset'
[samba.git] / lib / util / charset / charset.h
index 494a4ebc1a5599fcb71a25e5d8d76b62ca5fc73a..b36c461003bf6b76639221c062ea2884f33da8b9 100644 (file)
@@ -28,7 +28,7 @@
 #include <talloc.h>
 
 /* this defines the charset types used in samba */
-typedef enum {CH_UTF16LE=0, CH_UTF16=0, CH_UNIX, CH_DISPLAY, CH_DOS, CH_UTF8, CH_UTF16BE, CH_UTF16MUNGED} charset_t;
+typedef enum {CH_UTF16LE=0, CH_UTF16=0, CH_UNIX, CH_DOS, CH_UTF8, CH_UTF16BE, CH_UTF16MUNGED} charset_t;
 
 #define NUM_CHARSETS 7
 
@@ -48,15 +48,6 @@ typedef uint16_t smb_ucs2_t;
 /* 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
@@ -112,14 +103,17 @@ typedef struct smb_iconv_s {
 #define STR_LEN_NOTERM 256 /* the length field is the unterminated length */
 
 struct loadparm_context;
-struct smb_iconv_convenience;
-
-/* replace some string functions with multi-byte
-   versions */
-#define strlower(s) strlower_m(s)
-#define strupper(s) strupper_m(s)
+struct smb_iconv_handle;
 
 char *strchr_m(const char *s, char c);
+/**
+ * Calculate the number of units (8 or 16-bit, depending on the
+ * destination charset), that would be needed to convert the input
+ * string which is expected to be in in src_charset encoding to the
+ * destination charset (which should be a unicode charset).
+ */
+size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
+                          const char *s, charset_t src_charset, charset_t dst_charset);
 size_t strlen_m_ext(const char *s, charset_t src_charset, charset_t dst_charset);
 size_t strlen_m_ext_term(const char *s, charset_t src_charset,
                         charset_t dst_charset);
@@ -131,19 +125,30 @@ void string_replace_m(char *s, char oldc, char newc);
 bool strcsequal(const char *s1,const char *s2);
 bool strequal_m(const char *s1, const char *s2);
 int strncasecmp_m(const char *s1, const char *s2, size_t n);
+int strncasecmp_m_handle(struct smb_iconv_handle *iconv_handle,
+                        const char *s1, const char *s2, size_t n);
 bool next_token(const char **ptr,char *buff, const char *sep, size_t bufsize);
+int strcasecmp_m_handle(struct smb_iconv_handle *iconv_handle,
+                       const char *s1, const char *s2);
 int strcasecmp_m(const char *s1, const char *s2);
 size_t count_chars_m(const char *s, char c);
-void strupper_m(char *s);
-void strlower_m(char *s);
 char *strupper_talloc(TALLOC_CTX *ctx, const char *src);
 char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *src);
+char *strupper_talloc_n_handle(struct smb_iconv_handle *iconv_handle,
+                               TALLOC_CTX *ctx, const char *src, size_t n);
 char *strupper_talloc_n(TALLOC_CTX *ctx, const char *src, size_t n);
+ char *strlower_talloc_handle(struct smb_iconv_handle *iconv_handle,
+                             TALLOC_CTX *ctx, const char *src);
 char *strlower_talloc(TALLOC_CTX *ctx, const char *src);
 bool strhasupper(const char *string);
+bool strhaslower_handle(struct smb_iconv_handle *ic,
+                       const char *string);
 bool strhaslower(const char *string);
+bool strhasupper_handle(struct smb_iconv_handle *ic,
+                       const char *string);
 char *strrchr_m(const char *s, char c);
 char *strchr_m(const char *s, char c);
+char *strstr_m(const char *src, const char *findstr);
 
 bool push_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src, size_t *converted_size);
 bool push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src, size_t *converted_size);
@@ -159,20 +164,28 @@ bool convert_string_talloc(TALLOC_CTX *ctx,
                           void const *src, size_t srclen, 
                           void *dest, size_t *converted_size);
 
-size_t convert_string(charset_t from, charset_t to,
+bool convert_string(charset_t from, charset_t to,
                      void const *src, size_t srclen, 
-                     void *dest, size_t destlen);
+                     void *dest, size_t destlen,
+                     size_t *converted_size);
+bool convert_string_error(charset_t from, charset_t to,
+                         void const *src, size_t srclen,
+                         void *dest, size_t destlen,
+                         size_t *converted_size);
 
 ssize_t iconv_talloc(TALLOC_CTX *mem_ctx, 
                                       smb_iconv_t cd,
                                       void const *src, size_t srclen, 
                                       void *dest);
 
-extern struct smb_iconv_convenience *global_iconv_convenience;
-struct smb_iconv_convenience *get_iconv_convenience(void);
-smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic,
+extern struct smb_iconv_handle *global_iconv_handle;
+struct smb_iconv_handle *get_iconv_handle(void);
+struct smb_iconv_handle *get_iconv_testing_handle(TALLOC_CTX *mem_ctx, 
+                                                 const char *dos_charset, 
+                                                 const char *unix_charset);
+smb_iconv_t get_conv_handle(struct smb_iconv_handle *ic,
                            charset_t from, charset_t to);
-const char *charset_name(struct smb_iconv_convenience *ic, charset_t ch);
+const char *charset_name(struct smb_iconv_handle *ic, charset_t ch);
 
 codepoint_t next_codepoint_ext(const char *str, charset_t src_charset,
                               size_t *size);
@@ -180,12 +193,12 @@ 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,
+codepoint_t next_codepoint_handle_ext(struct smb_iconv_handle *ic,
                            const char *str, charset_t src_charset,
                            size_t *size);
-codepoint_t next_codepoint_convenience(struct smb_iconv_convenience *ic, 
+codepoint_t next_codepoint_handle(struct smb_iconv_handle *ic,
                            const char *str, size_t *size);
-ssize_t push_codepoint_convenience(struct smb_iconv_convenience *ic, 
+ssize_t push_codepoint_handle(struct smb_iconv_handle *ic,
                                char *str, codepoint_t c);
 
 codepoint_t toupper_m(codepoint_t val);
@@ -195,19 +208,24 @@ bool isupper_m(codepoint_t val);
 int codepoint_cmpi(codepoint_t c1, codepoint_t c2);
 
 /* Iconv convenience functions */
-struct smb_iconv_convenience *smb_iconv_convenience_reinit(TALLOC_CTX *mem_ctx,
+struct smb_iconv_handle *smb_iconv_handle_reinit(TALLOC_CTX *mem_ctx,
                                                           const char *dos_charset,
                                                           const char *unix_charset,
-                                                          const char *display_charset,
                                                           bool native_iconv,
-                                                          struct smb_iconv_convenience *old_ic);
+                                                          struct smb_iconv_handle *old_ic);
 
-bool convert_string_convenience(struct smb_iconv_convenience *ic,
+bool convert_string_handle(struct smb_iconv_handle *ic,
                                charset_t from, charset_t to,
                                void const *src, size_t srclen, 
                                void *dest, size_t destlen, size_t *converted_size);
-bool convert_string_talloc_convenience(TALLOC_CTX *ctx, 
-                                      struct smb_iconv_convenience *ic, 
+bool convert_string_error_handle(struct smb_iconv_handle *ic,
+                                charset_t from, charset_t to,
+                                void const *src, size_t srclen,
+                                void *dest, size_t destlen,
+                                size_t *converted_size);
+
+bool convert_string_talloc_handle(TALLOC_CTX *ctx,
+                                      struct smb_iconv_handle *ic,
                                       charset_t from, charset_t to, 
                                       void const *src, size_t srclen, 
                                       void *dest, size_t *converted_size);
@@ -224,6 +242,26 @@ void load_case_tables(void);
 void load_case_tables_library(void);
 bool smb_register_charset(const struct charset_functions *funcs_in);
 
+/* The following definitions come from util_unistr_w.c  */
+
+size_t strlen_w(const smb_ucs2_t *src);
+size_t strnlen_w(const smb_ucs2_t *src, size_t max);
+smb_ucs2_t *strchr_w(const smb_ucs2_t *s, smb_ucs2_t c);
+smb_ucs2_t *strchr_wa(const smb_ucs2_t *s, char c);
+smb_ucs2_t *strrchr_w(const smb_ucs2_t *s, smb_ucs2_t c);
+smb_ucs2_t *strnrchr_w(const smb_ucs2_t *s, smb_ucs2_t c, unsigned int n);
+smb_ucs2_t *strstr_w(const smb_ucs2_t *s, const smb_ucs2_t *ins);
+bool strlower_w(smb_ucs2_t *s);
+bool strupper_w(smb_ucs2_t *s);
+int strcmp_w(const smb_ucs2_t *a, const smb_ucs2_t *b);
+int strcasecmp_w(const smb_ucs2_t *a, const smb_ucs2_t *b);
+int strncasecmp_w(const smb_ucs2_t *a, const smb_ucs2_t *b, size_t len);
+int strcmp_wa(const smb_ucs2_t *a, const char *b);
+int toupper_ascii(int c);
+int tolower_ascii(int c);
+int isupper_ascii(int c);
+int islower_ascii(int c);
+
 /*
  *   Define stub for charset module which implements 8-bit encoding with gaps.
  *   Encoding tables for such module should be produced from glibc's CHARMAPs
@@ -239,7 +277,7 @@ static size_t CHARSETNAME ## _push(void *cd, const char **inbuf, size_t *inbytes
                int i;                                                                          \
                int done = 0;                                                                   \
                                                                                                \
-               uint16 ch = SVAL(*inbuf,0);                                                     \
+               uint16_t ch = SVAL(*inbuf,0);                                                   \
                                                                                                \
                for (i=0; from_idx[i].start != 0xffff; i++) {                                   \
                        if ((from_idx[i].start <= ch) && (from_idx[i].end >= ch)) {             \