Ports -> pkgsrc
[dragonfly.git] / sys / sys / iconv.h
1 /*
2  * Copyright (c) 2000-2001, Boris Popov
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
19  *
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
30  * SUCH DAMAGE.
31  *
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.4 2006/05/20 02:42:13 dillon Exp $
34  */
35 #ifndef _SYS_ICONV_H_
36 #define _SYS_ICONV_H_
37
38 #ifndef _SYS_MODULE_H_
39 #include <sys/module.h>
40 #endif
41
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 */
45
46 /*
47  * Entry for cslist sysctl
48  */
49 #define ICONV_CSPAIR_INFO_VER   1
50
51 struct iconv_cspair_info {
52         int     cs_version;
53         int     cs_id;
54         int     cs_base;
55         int     cs_refcount;
56         char    cs_to[ICONV_CSNMAXLEN];
57         char    cs_from[ICONV_CSNMAXLEN];
58 };
59
60 /*
61  * Paramters for 'add' sysctl
62  */
63 #define ICONV_ADD_VER   1
64
65 struct iconv_add_in {
66         int     ia_version;
67         char    ia_converter[ICONV_CNVNMAXLEN];
68         char    ia_to[ICONV_CSNMAXLEN];
69         char    ia_from[ICONV_CSNMAXLEN];
70         int     ia_datalen;
71         const void *ia_data;
72 };
73
74 struct iconv_add_out {
75         int     ia_csid;
76 };
77
78 #ifndef _KERNEL
79
80 __BEGIN_DECLS
81
82 int   kiconv_add_xlat_table(const char *, const char *, const u_char *);
83
84 __END_DECLS
85
86 #else /* !_KERNEL */
87
88 #include <sys/kobj.h>
89 #include <sys/queue.h>                  /* can't avoid that */
90 #include <sys/sysctl.h>                 /* can't avoid that */
91
92 struct iconv_cspair;
93 struct iconv_cspairdata;
94
95 /*
96  * iconv converter class definition
97  */
98 struct iconv_converter_class {
99         KOBJ_CLASS_FIELDS;
100         TAILQ_ENTRY(iconv_converter_class)      cc_link;
101 };
102
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;
107         const char *    cp_to;
108         void *          cp_data;
109         struct iconv_converter_class * cp_dcp;
110         struct iconv_cspair *cp_base;
111         TAILQ_ENTRY(iconv_cspair)       cp_link;
112 };
113
114 #define KICONV_CONVERTER(name,size)                             \
115     static DEFINE_CLASS(iconv_ ## name, iconv_ ## name ## _methods, (size)); \
116     static moduledata_t iconv_ ## name ## _mod = {      \
117         "iconv_"#name, iconv_converter_handler,         \
118         (void*)&iconv_ ## name ## _class                \
119     };                                                  \
120     DECLARE_MODULE(iconv_ ## name, iconv_ ## name ## _mod, SI_SUB_DRIVERS, SI_ORDER_ANY);
121
122 #define KICONV_CES(name,size)                           \
123     static DEFINE_CLASS(iconv_ces_ ## name, iconv_ces_ ## name ## _methods, (size)); \
124     static moduledata_t iconv_ces_ ## name ## _mod = {  \
125         "iconv_ces_"#name, iconv_cesmod_handler,        \
126         (void*)&iconv_ces_ ## name ## _class            \
127     };                                                  \
128     DECLARE_MODULE(iconv_ces_ ## name, iconv_ces_ ## name ## _mod, SI_SUB_DRIVERS, SI_ORDER_ANY);
129
130 #ifdef MALLOC_DECLARE
131 MALLOC_DECLARE(M_ICONV);
132 #endif
133
134 /*
135  * Basic conversion functions
136  */
137 int iconv_open(const char *to, const char *from, void **handle);
138 int iconv_close(void *handle);
139 int iconv_conv(void *handle, const char **inbuf,
140         size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
141 char* iconv_convstr(void *handle, char *dst, const char *src);
142 void* iconv_convmem(void *handle, void *dst, const void *src, int size);
143
144 /*
145  * Internal functions
146  */
147 int iconv_lookupcp(char **cpp, const char *s);
148
149 int iconv_converter_initstub(struct iconv_converter_class *dp);
150 int iconv_converter_donestub(struct iconv_converter_class *dp);
151 int iconv_converter_handler(module_t mod, int type, void *data);
152
153 #ifdef ICONV_DEBUG
154 #define ICDEBUG(format, args...) printf("%s: "format, __func__ ,## args)
155 #else
156 #define ICDEBUG(format, args...)
157 #endif
158
159 #endif /* !_KERNEL */
160
161 #endif /* !_SYS_ICONV_H_ */