The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/iconv.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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$
   33  */
   34 #ifndef _SYS_ICONV_H_
   35 #define _SYS_ICONV_H_
   36 
   37 #define ICONV_CSNMAXLEN         31      /* maximum length of charset name */
   38 #define ICONV_CNVNMAXLEN        31      /* maximum length of converter name */
   39 /* maximum size of data associated with cs pair */
   40 #define ICONV_CSMAXDATALEN      (sizeof(caddr_t) * 0x200 + sizeof(uint32_t) * 0x200 * 0x80)
   41 
   42 #define XLAT16_ACCEPT_NULL_OUT          0x01000000
   43 #define XLAT16_ACCEPT_NULL_IN           0x02000000
   44 #define XLAT16_HAS_LOWER_CASE           0x04000000
   45 #define XLAT16_HAS_UPPER_CASE           0x08000000
   46 #define XLAT16_HAS_FROM_LOWER_CASE      0x10000000
   47 #define XLAT16_HAS_FROM_UPPER_CASE      0x20000000
   48 #define XLAT16_IS_3BYTE_CHR             0x40000000
   49 
   50 #define KICONV_LOWER            1       /* tolower converted character */
   51 #define KICONV_UPPER            2       /* toupper converted character */
   52 #define KICONV_FROM_LOWER       4       /* tolower source character, then convert */
   53 #define KICONV_FROM_UPPER       8       /* toupper source character, then convert */
   54 #define KICONV_WCTYPE           16      /* towlower/towupper characters */
   55 
   56 #define ENCODING_UNICODE        "UTF-16BE"
   57 #define KICONV_WCTYPE_NAME      "_wctype"
   58 
   59 /*
   60  * Entry for cslist sysctl
   61  */
   62 #define ICONV_CSPAIR_INFO_VER   1
   63 
   64 struct iconv_cspair_info {
   65         int     cs_version;
   66         int     cs_id;
   67         int     cs_base;
   68         int     cs_refcount;
   69         char    cs_to[ICONV_CSNMAXLEN];
   70         char    cs_from[ICONV_CSNMAXLEN];
   71 };
   72 
   73 /*
   74  * Paramters for 'add' sysctl
   75  */
   76 #define ICONV_ADD_VER   1
   77 
   78 struct iconv_add_in {
   79         int     ia_version;
   80         char    ia_converter[ICONV_CNVNMAXLEN];
   81         char    ia_to[ICONV_CSNMAXLEN];
   82         char    ia_from[ICONV_CSNMAXLEN];
   83         int     ia_datalen;
   84         const void *ia_data;
   85 };
   86 
   87 struct iconv_add_out {
   88         int     ia_csid;
   89 };
   90 
   91 #ifndef _KERNEL
   92 
   93 __BEGIN_DECLS
   94 
   95 #define KICONV_VENDOR_MICSFT    1       /* Microsoft Vendor Code for quirk */
   96 
   97 int   kiconv_add_xlat_table(const char *, const char *, const u_char *);
   98 int   kiconv_add_xlat16_cspair(const char *, const char *, int);
   99 int   kiconv_add_xlat16_cspairs(const char *, const char *);
  100 int   kiconv_add_xlat16_table(const char *, const char *, const void *, int);
  101 int   kiconv_lookupconv(const char *drvname);
  102 int   kiconv_lookupcs(const char *tocode, const char *fromcode);
  103 const char *kiconv_quirkcs(const char *, int);
  104 
  105 __END_DECLS
  106 
  107 #else /* !_KERNEL */
  108 
  109 #include <sys/kobj.h>
  110 #include <sys/module.h>                 /* can't avoid that */
  111 #include <sys/queue.h>                  /* can't avoid that */
  112 #include <sys/sysctl.h>                 /* can't avoid that */
  113 
  114 struct iconv_cspair;
  115 struct iconv_cspairdata;
  116 
  117 /*
  118  * iconv converter class definition
  119  */
  120 struct iconv_converter_class {
  121         KOBJ_CLASS_FIELDS;
  122         TAILQ_ENTRY(iconv_converter_class)      cc_link;
  123 };
  124 
  125 struct iconv_cspair {
  126         int             cp_id;          /* unique id of charset pair */
  127         int             cp_refcount;    /* number of references from other pairs */
  128         const char *    cp_from;
  129         const char *    cp_to;
  130         void *          cp_data;
  131         struct iconv_converter_class * cp_dcp;
  132         struct iconv_cspair *cp_base;
  133         TAILQ_ENTRY(iconv_cspair)       cp_link;
  134 };
  135 
  136 #define KICONV_CONVERTER(name,size)                     \
  137     static struct iconv_converter_class iconv_ ## name ## _class = { \
  138         "iconv_"#name, iconv_ ## name ## _methods, size, NULL \
  139     };                                                  \
  140     static moduledata_t iconv_ ## name ## _mod = {      \
  141         "iconv_"#name, iconv_converter_handler,         \
  142         (void*)&iconv_ ## name ## _class                \
  143     };                                                  \
  144     DECLARE_MODULE(iconv_ ## name, iconv_ ## name ## _mod, SI_SUB_DRIVERS, SI_ORDER_ANY);
  145 
  146 #define KICONV_CES(name,size)                           \
  147     static DEFINE_CLASS(iconv_ces_ ## name, iconv_ces_ ## name ## _methods, (size)); \
  148     static moduledata_t iconv_ces_ ## name ## _mod = {  \
  149         "iconv_ces_"#name, iconv_cesmod_handler,        \
  150         (void*)&iconv_ces_ ## name ## _class            \
  151     };                                                  \
  152     DECLARE_MODULE(iconv_ces_ ## name, iconv_ces_ ## name ## _mod, SI_SUB_DRIVERS, SI_ORDER_ANY);
  153 
  154 #ifdef MALLOC_DECLARE
  155 MALLOC_DECLARE(M_ICONV);
  156 #endif
  157 
  158 /*
  159  * Basic conversion functions
  160  */
  161 int iconv_open(const char *to, const char *from, void **handle);
  162 int iconv_close(void *handle);
  163 int iconv_conv(void *handle, const char **inbuf,
  164         size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
  165 int iconv_conv_case(void *handle, const char **inbuf,
  166         size_t *inbytesleft, char **outbuf, size_t *outbytesleft, int casetype);
  167 int iconv_convchr(void *handle, const char **inbuf,
  168         size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
  169 int iconv_convchr_case(void *handle, const char **inbuf,
  170         size_t *inbytesleft, char **outbuf, size_t *outbytesleft, int casetype);
  171 int iconv_add(const char *converter, const char *to, const char *from);
  172 char* iconv_convstr(void *handle, char *dst, const char *src);
  173 void* iconv_convmem(void *handle, void *dst, const void *src, int size);
  174 int iconv_vfs_refcount(const char *fsname);
  175 
  176 int towlower(int c, void *handle);
  177 int towupper(int c, void *handle);
  178 
  179 /*
  180  * Bridge struct of iconv functions
  181  */
  182 struct iconv_functions {
  183         int (*open)(const char *to, const char *from, void **handle);
  184         int (*close)(void *handle);
  185         int (*conv)(void *handle, const char **inbuf, size_t *inbytesleft,
  186                 char **outbuf, size_t *outbytesleft);
  187         int (*conv_case)(void *handle, const char **inbuf, size_t *inbytesleft,
  188                 char **outbuf, size_t *outbytesleft, int casetype);
  189         int (*convchr)(void *handle, const char **inbuf, size_t *inbytesleft,
  190                 char **outbuf, size_t *outbytesleft);
  191         int (*convchr_case)(void *handle, const char **inbuf, size_t *inbytesleft,
  192                 char **outbuf, size_t *outbytesleft, int casetype);
  193 };
  194 
  195 #define VFS_DECLARE_ICONV(fsname)                                       \
  196         static struct iconv_functions fsname ## _iconv_core = {         \
  197                 iconv_open,                                             \
  198                 iconv_close,                                            \
  199                 iconv_conv,                                             \
  200                 iconv_conv_case,                                        \
  201                 iconv_convchr,                                          \
  202                 iconv_convchr_case                                      \
  203         };                                                              \
  204         extern struct iconv_functions *fsname ## _iconv;                \
  205         static int fsname ## _iconv_mod_handler(module_t mod,           \
  206                 int type, void *d);                                     \
  207         static int                                                      \
  208         fsname ## _iconv_mod_handler(module_t mod, int type, void *d)   \
  209         {                                                               \
  210                 int error = 0;                                          \
  211                 switch(type) {                                          \
  212                 case MOD_LOAD:                                          \
  213                         fsname ## _iconv = & fsname ## _iconv_core;     \
  214                         break;                                          \
  215                 case MOD_UNLOAD:                                        \
  216                         error = iconv_vfs_refcount(#fsname);            \
  217                         if (error)                                      \
  218                                 return (EBUSY);                         \
  219                         fsname ## _iconv = NULL;                        \
  220                         break;                                          \
  221                 default:                                                \
  222                         error = EINVAL;                                 \
  223                         break;                                          \
  224                 }                                                       \
  225                 return (error);                                         \
  226         }                                                               \
  227         static moduledata_t fsname ## _iconv_mod = {                    \
  228                 #fsname"_iconv",                                        \
  229                 fsname ## _iconv_mod_handler,                           \
  230                 NULL                                                    \
  231         };                                                              \
  232         DECLARE_MODULE(fsname ## _iconv, fsname ## _iconv_mod,          \
  233                        SI_SUB_DRIVERS, SI_ORDER_ANY);                   \
  234         MODULE_DEPEND(fsname ## _iconv, fsname, 1, 1, 1);               \
  235         MODULE_DEPEND(fsname ## _iconv, libiconv, 2, 2, 2);             \
  236         MODULE_VERSION(fsname ## _iconv, 1)
  237 
  238 /*
  239  * Internal functions
  240  */
  241 int iconv_lookupcp(char **cpp, const char *s);
  242 
  243 int iconv_converter_initstub(struct iconv_converter_class *dp);
  244 int iconv_converter_donestub(struct iconv_converter_class *dp);
  245 int iconv_converter_tolowerstub(int c, void *handle);
  246 int iconv_converter_handler(module_t mod, int type, void *data);
  247 
  248 #ifdef ICONV_DEBUG
  249 #define ICDEBUG(format, ...) printf("%s: "format, __func__ , __VA_ARGS__)
  250 #else
  251 #define ICDEBUG(format, ...)
  252 #endif
  253 
  254 #endif /* !_KERNEL */
  255 
  256 #endif /* !_SYS_ICONV_H_ */

Cache object: 58dafd2e2f5139e28b62e20696bd5c59


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.