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
32 * $FreeBSD: src/sys/sys/iconv.h,v 1.1.2.1 2001/05/21 08:28:07 bp Exp $
33 * $DragonFly: src/sys/sys/iconv.h,v 1.6 2007/10/03 18:58:20 dillon Exp $
38 #ifndef _SYS_MODULE_H_
39 #include <sys/module.h>
42 #define ICONV_CSNMAXLEN 31 /* maximum length of charset name */
43 #define ICONV_CNVNMAXLEN 31 /* maximum length of converter name */
44 #define ICONV_CSMAXDATALEN 1024 /* maximum size of data associated with cs pair */
47 * Entry for cslist sysctl
49 #define ICONV_CSPAIR_INFO_VER 1
51 struct iconv_cspair_info
{
56 char cs_to
[ICONV_CSNMAXLEN
];
57 char cs_from
[ICONV_CSNMAXLEN
];
61 * Paramters for 'add' sysctl
63 #define ICONV_ADD_VER 1
67 char ia_converter
[ICONV_CNVNMAXLEN
];
68 char ia_to
[ICONV_CSNMAXLEN
];
69 char ia_from
[ICONV_CSNMAXLEN
];
74 struct iconv_add_out
{
82 int kiconv_add_xlat_table(const char *, const char *, const u_char
*);
89 #include <sys/queue.h> /* can't avoid that */
90 #include <sys/sysctl.h> /* can't avoid that */
93 struct iconv_cspairdata
;
96 * iconv converter class definition
98 struct iconv_converter_class
{
100 TAILQ_ENTRY(iconv_converter_class
) cc_link
;
103 struct iconv_cspair
{
104 int cp_id
; /* unique id of charset pair */
105 int cp_refcount
; /* number of references from other pairs */
106 const char * cp_from
;
109 struct iconv_converter_class
* cp_dcp
;
110 struct iconv_cspair
*cp_base
;
111 TAILQ_ENTRY(iconv_cspair
) cp_link
;
114 #define KICONV_CONVERTER(name,size) \
115 static DEFINE_CLASS_EXT(iconv_ ## name, iconv_ ## name ## _class, \
116 iconv_ ## name ## _methods, \
117 (size), iconv_converter_class); \
118 static moduledata_t iconv_ ## name ## _mod = { \
119 "iconv_"#name, iconv_converter_handler, \
120 (void*)&iconv_ ## name ## _class \
122 DECLARE_MODULE(iconv_ ## name, iconv_ ## name ## _mod, SI_SUB_DRIVERS, SI_ORDER_ANY);
124 #define KICONV_CES(name,size) \
125 static DEFINE_CLASS(iconv_ces_ ## name, iconv_ces_ ## name ## _methods, (size)); \
126 static moduledata_t iconv_ces_ ## name ## _mod = { \
127 "iconv_ces_"#name, iconv_cesmod_handler, \
128 (void*)&iconv_ces_ ## name ## _class \
130 DECLARE_MODULE(iconv_ces_ ## name, iconv_ces_ ## name ## _mod, SI_SUB_DRIVERS, SI_ORDER_ANY);
132 #ifdef MALLOC_DECLARE
133 MALLOC_DECLARE(M_ICONV
);
137 * Basic conversion functions
139 int iconv_open(const char *to
, const char *from
, void **handle
);
140 int iconv_close(void *handle
);
141 int iconv_conv(void *handle
, const char **inbuf
,
142 size_t *inbytesleft
, char **outbuf
, size_t *outbytesleft
);
143 char* iconv_convstr(void *handle
, char *dst
, const char *src
);
144 void* iconv_convmem(void *handle
, void *dst
, const void *src
, int size
);
149 int iconv_lookupcp(char **cpp
, const char *s
);
151 int iconv_converter_initstub(struct iconv_converter_class
*dp
);
152 int iconv_converter_donestub(struct iconv_converter_class
*dp
);
153 int iconv_converter_handler(module_t mod
, int type
, void *data
);
156 #define ICDEBUG(format, args...) kprintf("%s: "format, __func__ ,## args)
158 #define ICDEBUG(format, args...)
161 #endif /* !_KERNEL */
163 #endif /* !_SYS_ICONV_H_ */