2 * Copyright (c) 2000-2001, Boris Popov
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Boris Popov.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #define ICONV_CSNMAXLEN 31 /* maximum length of charset name */
38 #define ICONV_CNVNMAXLEN 31 /* maximum length of converter name */
39 /* maximum size of data associated with cs pair */
40 #define ICONV_CSMAXDATALEN (sizeof(caddr_t) * 0x200 + sizeof(uint32_t) * 0x200 * 0x80)
42 #define XLAT16_ACCEPT_NULL_OUT 0x01000000
43 #define XLAT16_ACCEPT_NULL_IN 0x02000000
44 #define XLAT16_HAS_LOWER_CASE 0x04000000
45 #define XLAT16_HAS_UPPER_CASE 0x08000000
46 #define XLAT16_HAS_FROM_LOWER_CASE 0x10000000
47 #define XLAT16_HAS_FROM_UPPER_CASE 0x20000000
48 #define XLAT16_IS_3BYTE_CHR 0x40000000
50 #define KICONV_LOWER 1 /* tolower converted character */
51 #define KICONV_UPPER 2 /* toupper converted character */
52 #define KICONV_FROM_LOWER 4 /* tolower source character, then convert */
53 #define KICONV_FROM_UPPER 8 /* toupper source character, then convert */
56 * Entry for cslist sysctl
58 #define ICONV_CSPAIR_INFO_VER 1
60 struct iconv_cspair_info {
65 char cs_to[ICONV_CSNMAXLEN];
66 char cs_from[ICONV_CSNMAXLEN];
70 * Paramters for 'add' sysctl
72 #define ICONV_ADD_VER 1
76 char ia_converter[ICONV_CNVNMAXLEN];
77 char ia_to[ICONV_CSNMAXLEN];
78 char ia_from[ICONV_CSNMAXLEN];
83 struct iconv_add_out {
91 #define ENCODING_UNICODE "UTF-16BE"
92 #define KICONV_VENDOR_MICSFT 1 /* Microsoft Vendor Code for quirk */
94 int kiconv_add_xlat_table(const char *, const char *, const u_char *);
95 int kiconv_add_xlat16_cspair(const char *, const char *, int);
96 int kiconv_add_xlat16_cspairs(const char *, const char *);
97 int kiconv_add_xlat16_table(const char *, const char *, const void *, int);
98 const char *kiconv_quirkcs(const char *, int);
104 #include <sys/kobj.h>
105 #include <sys/module.h> /* can't avoid that */
106 #include <sys/queue.h> /* can't avoid that */
107 #include <sys/sysctl.h> /* can't avoid that */
110 struct iconv_cspairdata;
113 * iconv converter class definition
115 struct iconv_converter_class {
117 TAILQ_ENTRY(iconv_converter_class) cc_link;
120 struct iconv_cspair {
121 int cp_id; /* unique id of charset pair */
122 int cp_refcount; /* number of references from other pairs */
123 const char * cp_from;
126 struct iconv_converter_class * cp_dcp;
127 struct iconv_cspair *cp_base;
128 TAILQ_ENTRY(iconv_cspair) cp_link;
131 #define KICONV_CONVERTER(name,size) \
132 static struct iconv_converter_class iconv_ ## name ## _class = { \
133 "iconv_"#name, iconv_ ## name ## _methods, size, NULL \
135 static moduledata_t iconv_ ## name ## _mod = { \
136 "iconv_"#name, iconv_converter_handler, \
137 (void*)&iconv_ ## name ## _class \
139 DECLARE_MODULE(iconv_ ## name, iconv_ ## name ## _mod, SI_SUB_DRIVERS, SI_ORDER_ANY);
141 #define KICONV_CES(name,size) \
142 static DEFINE_CLASS(iconv_ces_ ## name, iconv_ces_ ## name ## _methods, (size)); \
143 static moduledata_t iconv_ces_ ## name ## _mod = { \
144 "iconv_ces_"#name, iconv_cesmod_handler, \
145 (void*)&iconv_ces_ ## name ## _class \
147 DECLARE_MODULE(iconv_ces_ ## name, iconv_ces_ ## name ## _mod, SI_SUB_DRIVERS, SI_ORDER_ANY);
149 #ifdef MALLOC_DECLARE
150 MALLOC_DECLARE(M_ICONV);
154 * Basic conversion functions
156 int iconv_open(const char *to, const char *from, void **handle);
157 int iconv_close(void *handle);
158 int iconv_conv(void *handle, const char **inbuf,
159 size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
160 int iconv_conv_case(void *handle, const char **inbuf,
161 size_t *inbytesleft, char **outbuf, size_t *outbytesleft, int casetype);
162 int iconv_convchr(void *handle, const char **inbuf,
163 size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
164 int iconv_convchr_case(void *handle, const char **inbuf,
165 size_t *inbytesleft, char **outbuf, size_t *outbytesleft, int casetype);
166 char* iconv_convstr(void *handle, char *dst, const char *src);
167 void* iconv_convmem(void *handle, void *dst, const void *src, int size);
168 int iconv_vfs_refcount(const char *fsname);
171 * Bridge struct of iconv functions
173 struct iconv_functions {
174 int (*open)(const char *to, const char *from, void **handle);
175 int (*close)(void *handle);
176 int (*conv)(void *handle, const char **inbuf, size_t *inbytesleft,
177 char **outbuf, size_t *outbytesleft);
178 int (*conv_case)(void *handle, const char **inbuf, size_t *inbytesleft,
179 char **outbuf, size_t *outbytesleft, int casetype);
180 int (*convchr)(void *handle, const char **inbuf, size_t *inbytesleft,
181 char **outbuf, size_t *outbytesleft);
182 int (*convchr_case)(void *handle, const char **inbuf, size_t *inbytesleft,
183 char **outbuf, size_t *outbytesleft, int casetype);
186 #define VFS_DECLARE_ICONV(fsname) \
187 static struct iconv_functions fsname ## _iconv_core = { \
195 extern struct iconv_functions *fsname ## _iconv; \
196 static int fsname ## _iconv_mod_handler(module_t mod, \
197 int type, void *d); \
199 fsname ## _iconv_mod_handler(module_t mod, int type, void *d) \
204 fsname ## _iconv = & fsname ## _iconv_core; \
207 error = iconv_vfs_refcount(#fsname); \
210 fsname ## _iconv = NULL; \
218 static moduledata_t fsname ## _iconv_mod = { \
220 fsname ## _iconv_mod_handler, \
223 DECLARE_MODULE(fsname ## _iconv, fsname ## _iconv_mod, \
224 SI_SUB_DRIVERS, SI_ORDER_ANY); \
225 MODULE_DEPEND(fsname ## _iconv, fsname, 1, 1, 1); \
226 MODULE_DEPEND(fsname ## _iconv, libiconv, 2, 2, 2); \
227 MODULE_VERSION(fsname ## _iconv, 1)
232 int iconv_lookupcp(char **cpp, const char *s);
234 int iconv_converter_initstub(struct iconv_converter_class *dp);
235 int iconv_converter_donestub(struct iconv_converter_class *dp);
236 int iconv_converter_handler(module_t mod, int type, void *data);
239 #define ICDEBUG(format, ...) printf("%s: "format, __func__ , __VA_ARGS__)
241 #define ICDEBUG(format, ...)
244 #endif /* !_KERNEL */
246 #endif /* !_SYS_ICONV_H_ */