summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/sys/kiconv.h
blob: 46dcb4467d1542ae9d0fb290a7c7efd9a3b2c4ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef _SYS_KICONV_H
#define	_SYS_KICONV_H

#ifdef __cplusplus
extern "C" {
#endif

#include <sys/types.h>

#ifdef	_KERNEL

/*
 * Supported fromcode/tocode values are saved in the following component type
 * of (name, id) pair. The id values of fromcode and tocode are used to
 * find out the corresponding code conversions.
 */
typedef struct {
	char		*name;
	size_t		id;
} kiconv_code_list_t;

/*
 * Each unique kiconv code conversion identified by tocode and fromcode ids
 * have corresponding module id and internal function pointers to open(),
 * kiconv(), close(), and kiconvstr().
 */
typedef struct {
	uint16_t	tid;		/* tocode id. */
	uint16_t	fid;		/* fromcode id. */
	uint16_t	mid;		/* module id. */
	void		*(*open)(void);
	size_t		(*kiconv)(void *, char **, size_t *, char **, size_t *,
			int *);
	int		(*close)(void *);
	size_t		(*kiconvstr)(char *, size_t *, char *, size_t *, int,
			int *);
} kiconv_conv_list_t;

/*
 * Each module id has a corresponding module name that is used to load
 * the module as needed and a reference counter.
 */
typedef struct {
	char		*name;
	uint_t		refcount;
} kiconv_mod_list_t;

/*
 * The following two data structures are being used to transfer information
 * on the supported kiconv code conversions from a module to the framework.
 *
 * Details can be found from kiconv_ops(9S) and kiconv_module_info(9S)
 * man pages at PSARC/2007/173.
 */
typedef struct {
	char		*tocode;
	char		*fromcode;
	void		*(*kiconv_open)(void);
	size_t		(*kiconv)(void *, char **, size_t *, char **, size_t *,
			int *);
	int		(*kiconv_close)(void *);
	size_t		(*kiconvstr)(char *, size_t *, char *, size_t *, int,
			int *);
} kiconv_ops_t;

typedef struct kiconv_mod_info {
	char		*module_name;
	size_t		kiconv_num_convs;
	kiconv_ops_t	*kiconv_ops_tbl;
	size_t		kiconv_num_aliases;
	char		**aliases;
	char		**canonicals;
	int		nowait;
} kiconv_module_info_t;

/* The kiconv code conversion descriptor data structure. */
typedef struct {
	void		*handle;	/* Handle from the actual open(). */
	size_t		id;		/* Index to the conv_list[]. */
} kiconv_data_t, *kiconv_t;

/* Common conversion state data structure. */
typedef struct {
	uint8_t		id;
	uint8_t		bom_processed;
} kiconv_state_data_t, *kiconv_state_t;

/* Common component types for possible code conversion mapping tables. */
typedef struct {
	uchar_t		u8[3];
} kiconv_to_utf8_tbl_comp_t;

typedef struct {
	uint32_t	u8:24;
	uint32_t	sb:8;
} kiconv_to_sb_tbl_comp_t;

/*
 * The maximum name length for any given codeset or alias names; the following
 * should be plenty big enough.
 */
#define	KICONV_MAX_CODENAME_LEN		63

/* The following characters do not exist in the normalized code names. */
#define	KICONV_SKIPPABLE_CHAR(c)	\
	((c) == '-' || (c) == '_' || (c) == '.' || (c) == '@')

/*
 * When we encounter non-identical characters, as like iconv(3C) we have,
 * map them into either one of the replacement characters based on what is
 * the current target tocde.
 *
 * The 0xefbfdb in UTF-8 is U+FFFD in Unicode scalar value.
 */
#define	KICONV_ASCII_REPLACEMENT_CHAR	('?')
#define	KICONV_UTF8_REPLACEMENT_CHAR	(0xefbfbd)

/* Numeric ids for kiconv modules. */
#define	KICONV_EMBEDDED			(0)
#define	KICONV_MODULE_ID_JA		(1)
#define	KICONV_MODULE_ID_SC		(2)
#define	KICONV_MODULE_ID_KO		(3)
#define	KICONV_MODULE_ID_TC		(4)
#define	KICONV_MODULE_ID_EMEA		(5)

#define	KICONV_MAX_MODULE_ID		KICONV_MODULE_ID_EMEA

/* Functions used in kiconv conversion and module management. */
extern void	kiconv_init();
extern int	kiconv_register_module(kiconv_module_info_t *);
extern int	kiconv_unregister_module(kiconv_module_info_t *);
extern size_t	kiconv_module_ref_count(size_t);

#endif	/* _KERNEL */

#ifdef __cplusplus
}
#endif

#endif /* _SYS_KICONV_H */