2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2001
5 Copyright (C) Jelmer Vernooij 2002
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 /* This is a public header file that is installed as part of Samba.
22 * If you remove any functions or change their signature, update
23 * the so version number. */
30 /* this defines the charset types used in samba */
31 typedef enum {CH_UTF16=0, CH_UNIX, CH_DOS, CH_UTF8, CH_UTF16BE} charset_t;
33 #define NUM_CHARSETS 5
36 * for each charset we have a function that pulls from that charset to
37 * a ucs2 buffer, and a function that pushes to a ucs2 buffer
40 struct charset_functions {
42 size_t (*pull)(void *, const char **inbuf, size_t *inbytesleft,
43 char **outbuf, size_t *outbytesleft);
44 size_t (*push)(void *, const char **inbuf, size_t *inbytesleft,
45 char **outbuf, size_t *outbytesleft);
46 struct charset_functions *prev, *next;
49 /* this type is used for manipulating unicode codepoints */
50 typedef uint32_t codepoint_t;
52 #define INVALID_CODEPOINT ((codepoint_t)-1)
55 /* generic iconv conversion structure */
56 typedef struct smb_iconv_s {
57 size_t (*direct)(void *cd, const char **inbuf, size_t *inbytesleft,
58 char **outbuf, size_t *outbytesleft);
59 size_t (*pull)(void *cd, const char **inbuf, size_t *inbytesleft,
60 char **outbuf, size_t *outbytesleft);
61 size_t (*push)(void *cd, const char **inbuf, size_t *inbytesleft,
62 char **outbuf, size_t *outbytesleft);
63 void *cd_direct, *cd_pull, *cd_push;
66 /* string manipulation flags */
67 #define STR_TERMINATE 1
71 #define STR_NOALIGN 16
72 #define STR_NO_RANGE_CHECK 32
73 #define STR_LEN8BIT 64
74 #define STR_TERMINATE_ASCII 128 /* only terminate if ascii */
75 #define STR_LEN_NOTERM 256 /* the length field is the unterminated length */
77 struct loadparm_context;
78 struct smb_iconv_convenience;
80 /* replace some string functions with multi-byte
82 #define strlower(s) strlower_m(s)
83 #define strupper(s) strupper_m(s)
85 char *strchr_m(const char *s, char c);
86 size_t strlen_m_term(const char *s);
87 size_t strlen_m(const char *s);
88 char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength);
89 void string_replace_m(char *s, char oldc, char newc);
90 bool strcsequal_m(const char *s1,const char *s2);
91 bool strequal_m(const char *s1, const char *s2);
92 int strncasecmp_m(const char *s1, const char *s2, size_t n);
93 bool next_token(const char **ptr,char *buff, const char *sep, size_t bufsize);
94 int strcasecmp_m(const char *s1, const char *s2);
95 size_t count_chars_m(const char *s, char c);
96 void strupper_m(char *s);
97 void strlower_m(char *s);
98 char *strupper_talloc(TALLOC_CTX *ctx, const char *src);
99 char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *src);
100 char *strupper_talloc_n(TALLOC_CTX *ctx, const char *src, size_t n);
101 char *strlower_talloc(TALLOC_CTX *ctx, const char *src);
102 bool strhasupper(const char *string);
103 bool strhaslower(const char *string);
104 char *strrchr_m(const char *s, char c);
105 char *strchr_m(const char *s, char c);
107 ssize_t push_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src);
108 ssize_t push_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const char *src);
109 ssize_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src);
110 ssize_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src);
111 ssize_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const void *src);
112 ssize_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src);
113 ssize_t push_string(void *dest, const char *src, size_t dest_len, int flags);
114 ssize_t pull_string(char *dest, const void *src, size_t dest_len, size_t src_len, int flags);
116 ssize_t convert_string_talloc(TALLOC_CTX *ctx,
117 charset_t from, charset_t to,
118 void const *src, size_t srclen,
121 ssize_t convert_string(charset_t from, charset_t to,
122 void const *src, size_t srclen,
123 void *dest, size_t destlen);
127 codepoint_t next_codepoint(struct smb_iconv_convenience *ic,
128 const char *str, size_t *size);
129 ssize_t push_codepoint(struct smb_iconv_convenience *ic,
130 char *str, codepoint_t c);
131 codepoint_t toupper_m(codepoint_t val);
132 codepoint_t tolower_m(codepoint_t val);
133 int codepoint_cmpi(codepoint_t c1, codepoint_t c2);
135 /* Iconv convenience functions */
136 struct smb_iconv_convenience *smb_iconv_convenience_init(TALLOC_CTX *mem_ctx,
137 const char *dos_charset,
138 const char *unix_charset,
141 ssize_t convert_string_convenience(struct smb_iconv_convenience *ic,
142 charset_t from, charset_t to,
143 void const *src, size_t srclen,
144 void *dest, size_t destlen);
145 ssize_t convert_string_talloc_descriptor(TALLOC_CTX *ctx, smb_iconv_t descriptor, void const *src, size_t srclen, void **dest);
146 ssize_t convert_string_talloc_convenience(TALLOC_CTX *ctx,
147 struct smb_iconv_convenience *ic,
148 charset_t from, charset_t to,
149 void const *src, size_t srclen,
152 smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode);
153 int smb_iconv_close(smb_iconv_t cd);
154 size_t smb_iconv(smb_iconv_t cd,
155 const char **inbuf, size_t *inbytesleft,
156 char **outbuf, size_t *outbytesleft);
157 smb_iconv_t smb_iconv_open_ex(TALLOC_CTX *mem_ctx, const char *tocode,
158 const char *fromcode, bool native_iconv);
160 void load_case_tables(void);
161 bool charset_register_backend(const void *_funcs);
163 #endif /* __CHARSET_H__ */