xref: /onnv-gate/usr/src/uts/common/sys/kiconv.h (revision 5206:34f0b41fc3c5)
1*5206Sis /*
2*5206Sis  * CDDL HEADER START
3*5206Sis  *
4*5206Sis  * The contents of this file are subject to the terms of the
5*5206Sis  * Common Development and Distribution License (the "License").
6*5206Sis  * You may not use this file except in compliance with the License.
7*5206Sis  *
8*5206Sis  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*5206Sis  * or http://www.opensolaris.org/os/licensing.
10*5206Sis  * See the License for the specific language governing permissions
11*5206Sis  * and limitations under the License.
12*5206Sis  *
13*5206Sis  * When distributing Covered Code, include this CDDL HEADER in each
14*5206Sis  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*5206Sis  * If applicable, add the following below this CDDL HEADER, with the
16*5206Sis  * fields enclosed by brackets "[]" replaced with your own identifying
17*5206Sis  * information: Portions Copyright [yyyy] [name of copyright owner]
18*5206Sis  *
19*5206Sis  * CDDL HEADER END
20*5206Sis  */
21*5206Sis /*
22*5206Sis  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*5206Sis  * Use is subject to license terms.
24*5206Sis  */
25*5206Sis 
26*5206Sis #ifndef _SYS_KICONV_H
27*5206Sis #define	_SYS_KICONV_H
28*5206Sis 
29*5206Sis #pragma ident	"%Z%%M%	%I%	%E% SMI"
30*5206Sis 
31*5206Sis #ifdef __cplusplus
32*5206Sis extern "C" {
33*5206Sis #endif
34*5206Sis 
35*5206Sis #include <sys/types.h>
36*5206Sis 
37*5206Sis #ifdef	_KERNEL
38*5206Sis 
39*5206Sis /*
40*5206Sis  * Supported fromcode/tocode values are saved in the following component type
41*5206Sis  * of (name, id) pair. The id values of fromcode and tocode are used to
42*5206Sis  * find out the corresponding code conversions.
43*5206Sis  */
44*5206Sis typedef struct {
45*5206Sis 	char		*name;
46*5206Sis 	size_t		id;
47*5206Sis } kiconv_code_list_t;
48*5206Sis 
49*5206Sis /*
50*5206Sis  * Each unique kiconv code conversion identified by tocode and fromcode ids
51*5206Sis  * have corresponding module id and internal function pointers to open(),
52*5206Sis  * kiconv(), close(), and kiconvstr().
53*5206Sis  */
54*5206Sis typedef struct {
55*5206Sis 	uint16_t	tid;		/* tocode id. */
56*5206Sis 	uint16_t	fid;		/* fromcode id. */
57*5206Sis 	uint16_t	mid;		/* module id. */
58*5206Sis 	void		*(*open)(void);
59*5206Sis 	size_t		(*kiconv)(void *, char **, size_t *, char **, size_t *,
60*5206Sis 			int *);
61*5206Sis 	int		(*close)(void *);
62*5206Sis 	size_t		(*kiconvstr)(char *, size_t *, char *, size_t *, int,
63*5206Sis 			int *);
64*5206Sis } kiconv_conv_list_t;
65*5206Sis 
66*5206Sis /*
67*5206Sis  * Each module id has a corresponding module name that is used to load
68*5206Sis  * the module as needed and a reference counter.
69*5206Sis  */
70*5206Sis typedef struct {
71*5206Sis 	char		*name;
72*5206Sis 	uint_t		refcount;
73*5206Sis } kiconv_mod_list_t;
74*5206Sis 
75*5206Sis /*
76*5206Sis  * The following two data structures are being used to transfer information
77*5206Sis  * on the supported kiconv code conversions from a module to the framework.
78*5206Sis  *
79*5206Sis  * Details can be found from kiconv_ops(9S) and kiconv_module_info(9S)
80*5206Sis  * man pages at PSARC/2007/173.
81*5206Sis  */
82*5206Sis typedef struct {
83*5206Sis 	char		*tocode;
84*5206Sis 	char		*fromcode;
85*5206Sis 	void		*(*kiconv_open)(void);
86*5206Sis 	size_t		(*kiconv)(void *, char **, size_t *, char **, size_t *,
87*5206Sis 			int *);
88*5206Sis 	int		(*kiconv_close)(void *);
89*5206Sis 	size_t		(*kiconvstr)(char *, size_t *, char *, size_t *, int,
90*5206Sis 			int *);
91*5206Sis } kiconv_ops_t;
92*5206Sis 
93*5206Sis typedef struct kiconv_mod_info {
94*5206Sis 	char		*module_name;
95*5206Sis 	size_t		kiconv_num_convs;
96*5206Sis 	kiconv_ops_t	*kiconv_ops_tbl;
97*5206Sis 	size_t		kiconv_num_aliases;
98*5206Sis 	char		**aliases;
99*5206Sis 	char		**canonicals;
100*5206Sis 	int		nowait;
101*5206Sis } kiconv_module_info_t;
102*5206Sis 
103*5206Sis /* The kiconv code conversion descriptor data structure. */
104*5206Sis typedef struct {
105*5206Sis 	void		*handle;	/* Handle from the actual open(). */
106*5206Sis 	size_t		id;		/* Index to the conv_list[]. */
107*5206Sis } kiconv_data_t, *kiconv_t;
108*5206Sis 
109*5206Sis /* Common conversion state data structure. */
110*5206Sis typedef struct {
111*5206Sis 	uint8_t		id;
112*5206Sis 	uint8_t		bom_processed;
113*5206Sis } kiconv_state_data_t, *kiconv_state_t;
114*5206Sis 
115*5206Sis /* Common component types for possible code conversion mapping tables. */
116*5206Sis typedef struct {
117*5206Sis 	uchar_t		u8[3];
118*5206Sis } kiconv_to_utf8_tbl_comp_t;
119*5206Sis 
120*5206Sis typedef struct {
121*5206Sis 	uint32_t	u8:24;
122*5206Sis 	uint32_t	sb:8;
123*5206Sis } kiconv_to_sb_tbl_comp_t;
124*5206Sis 
125*5206Sis /*
126*5206Sis  * The maximum name length for any given codeset or alias names; the following
127*5206Sis  * should be plenty big enough.
128*5206Sis  */
129*5206Sis #define	KICONV_MAX_CODENAME_LEN		63
130*5206Sis 
131*5206Sis /* The following characters do not exist in the normalized code names. */
132*5206Sis #define	KICONV_SKIPPABLE_CHAR(c)	\
133*5206Sis 	((c) == '-' || (c) == '_' || (c) == '.' || (c) == '@')
134*5206Sis 
135*5206Sis /*
136*5206Sis  * When we encounter non-identical characters, as like iconv(3C) we have,
137*5206Sis  * map them into either one of the replacement characters based on what is
138*5206Sis  * the current target tocde.
139*5206Sis  *
140*5206Sis  * The 0xefbfdb in UTF-8 is U+FFFD in Unicode scalar value.
141*5206Sis  */
142*5206Sis #define	KICONV_ASCII_REPLACEMENT_CHAR	('?')
143*5206Sis #define	KICONV_UTF8_REPLACEMENT_CHAR	(0xefbfbd)
144*5206Sis 
145*5206Sis /* Numeric ids for kiconv modules. */
146*5206Sis #define	KICONV_EMBEDDED			(0)
147*5206Sis #define	KICONV_MODULE_ID_JA		(1)
148*5206Sis #define	KICONV_MODULE_ID_SC		(2)
149*5206Sis #define	KICONV_MODULE_ID_KO		(3)
150*5206Sis #define	KICONV_MODULE_ID_TC		(4)
151*5206Sis #define	KICONV_MODULE_ID_EMEA		(5)
152*5206Sis 
153*5206Sis #define	KICONV_MAX_MODULE_ID		KICONV_MODULE_ID_EMEA
154*5206Sis 
155*5206Sis /* Functions used in kiconv conversion and module management. */
156*5206Sis extern void	kiconv_init();
157*5206Sis extern int	kiconv_register_module(kiconv_module_info_t *);
158*5206Sis extern int	kiconv_unregister_module(kiconv_module_info_t *);
159*5206Sis extern size_t	kiconv_module_ref_count(size_t);
160*5206Sis 
161*5206Sis #endif	/* _KERNEL */
162*5206Sis 
163*5206Sis #ifdef __cplusplus
164*5206Sis }
165*5206Sis #endif
166*5206Sis 
167*5206Sis #endif /* _SYS_KICONV_H */
168