Sync smb_iconv_t type, convert_string return type with Samba 3 equivalents.
[ira/wip.git] / lib / util / charset / charset.h
index 041eaeace7a7d9991b830d3af335818a00a66ad9..3acdde30ad87f3e45bc05c441dff1b30a93caf80 100644 (file)
@@ -28,9 +28,9 @@
 #include <talloc.h>
 
 /* this defines the charset types used in samba */
-typedef enum {CH_UTF16=0, CH_UNIX, CH_DOS, CH_UTF8, CH_UTF16BE} charset_t;
+typedef enum {CH_UTF16=0, CH_UNIX, CH_DOS, CH_UTF8, CH_UTF16BE, CH_UTF16MUNGED} charset_t;
 
-#define NUM_CHARSETS 5
+#define NUM_CHARSETS 6
 
 /*
  *   for each charset we have a function that pulls from that charset to
@@ -61,6 +61,7 @@ typedef struct smb_iconv_s {
        size_t (*push)(void *cd, const char **inbuf, size_t *inbytesleft,
                       char **outbuf, size_t *outbytesleft);
        void *cd_direct, *cd_pull, *cd_push;
+       char *from_name, *to_name;
 } *smb_iconv_t;
 
 /* string manipulation flags */
@@ -76,7 +77,6 @@ typedef struct smb_iconv_s {
 
 struct loadparm_context;
 struct smb_iconv_convenience;
-extern struct smb_iconv_convenience *global_smb_iconv_convenience;
 
 /* replace some string functions with multi-byte
    versions */
@@ -85,15 +85,16 @@ extern struct smb_iconv_convenience *global_smb_iconv_convenience;
 
 char *strchr_m(const char *s, char c);
 size_t strlen_m_term(const char *s);
+size_t strlen_m_term_null(const char *s);
 size_t strlen_m(const char *s);
 char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength);
-void string_replace_w(char *s, char oldc, char newc);
-bool strcsequal_w(const char *s1,const char *s2);
-bool strequal_w(const char *s1, const char *s2);
+void string_replace_m(char *s, char oldc, char newc);
+bool strcsequal_m(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);
 bool next_token(const char **ptr,char *buff, const char *sep, size_t bufsize);
 int strcasecmp_m(const char *s1, const char *s2);
-size_t count_chars_w(const char *s, char c);
+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);
@@ -105,34 +106,57 @@ bool strhaslower(const char *string);
 char *strrchr_m(const char *s, char c);
 char *strchr_m(const char *s, char c);
 
+ssize_t push_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src);
+ssize_t push_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const char *src);
+ssize_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src);
+ssize_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src);
+ssize_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const void *src);
+ssize_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src);
+ssize_t push_string(void *dest, const char *src, size_t dest_len, int flags);
+ssize_t pull_string(char *dest, const void *src, size_t dest_len, size_t src_len, int flags);
+
+ssize_t convert_string_talloc(TALLOC_CTX *ctx, 
+                                      charset_t from, charset_t to, 
+                                      void const *src, size_t srclen, 
+                                      void **dest, bool allow_badcharcnv);
+
+size_t convert_string(charset_t from, charset_t to,
+                               void const *src, size_t srclen, 
+                               void *dest, size_t destlen, bool allow_badcharcnv);
+
+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;
+
+codepoint_t next_codepoint(const char *str, size_t *size);
+
 /* codepoints */
-codepoint_t next_codepoint(struct smb_iconv_convenience *ic, 
+codepoint_t next_codepoint_convenience(struct smb_iconv_convenience *ic, 
                            const char *str, size_t *size);
 ssize_t push_codepoint(struct smb_iconv_convenience *ic, 
                                char *str, codepoint_t c);
-codepoint_t toupper_w(codepoint_t val);
-codepoint_t tolower_w(codepoint_t val);
+codepoint_t toupper_m(codepoint_t val);
+codepoint_t tolower_m(codepoint_t val);
 int codepoint_cmpi(codepoint_t c1, codepoint_t c2);
-ssize_t push_string(struct smb_iconv_convenience *ic, void *dest, const char *src, size_t dest_len, int flags);
-ssize_t pull_string(struct smb_iconv_convenience *ic,
-                   char *dest, const void *src, size_t dest_len, size_t src_len, int flags);
-ssize_t convert_string(struct smb_iconv_convenience *ic,
+
+/* 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);
+
+ssize_t convert_string_convenience(struct smb_iconv_convenience *ic,
                                charset_t from, charset_t to,
                                void const *src, size_t srclen, 
-                               void *dest, size_t destlen);
-ssize_t convert_string_talloc_descriptor(TALLOC_CTX *ctx, smb_iconv_t descriptor, void const *src, size_t srclen, void **dest);
-ssize_t convert_string_talloc(TALLOC_CTX *ctx, 
+                               void *dest, size_t destlen, bool allow_badcharcnv);
+ssize_t convert_string_talloc_convenience(TALLOC_CTX *ctx, 
                                       struct smb_iconv_convenience *ic, 
                                       charset_t from, charset_t to, 
                                       void const *src, size_t srclen, 
-                                      void **dest);
-ssize_t push_ascii_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const char *src);
-ssize_t push_ucs2_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, void **dest, const char *src);
-ssize_t push_utf8_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const char *src);
-ssize_t pull_ascii_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const char *src);
-ssize_t pull_ucs2_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const void *src);
-ssize_t pull_utf8_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const char *src);
-
+                                      void **dest, bool allow_badcharcnv);
 /* iconv */
 smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode);
 int smb_iconv_close(smb_iconv_t cd);
@@ -142,12 +166,6 @@ size_t smb_iconv(smb_iconv_t cd,
 smb_iconv_t smb_iconv_open_ex(TALLOC_CTX *mem_ctx, const char *tocode, 
                              const char *fromcode, bool native_iconv);
 
-/* iconv convenience */
-struct smb_iconv_convenience *smb_iconv_convenience_init(TALLOC_CTX *mem_ctx,
-                                                        const char *dos_charset,
-                                                        const char *unix_charset,
-                                                        bool native_iconv);
-
 void load_case_tables(void);
 bool charset_register_backend(const void *_funcs);