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