FreeTDS API: include/tdsiconv.h Source File

Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

# tdsiconv.h

    00001 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
    00002  * Copyright (C) 2002, 2003, 2004  Brian Bruns
    00003  *
    00004  * This library is free software; you can redistribute it and/or
    00005  * modify it under the terms of the GNU Library General Public
    00006  * License as published by the Free Software Foundation; either
    00007  * version 2 of the License, or (at your option) any later version.
    00008  *
    00009  * This library is distributed in the hope that it will be useful,
    00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012  * Library General Public License for more details.
    00013  *
    00014  * You should have received a copy of the GNU Library General Public
    00015  * License along with this library; if not, write to the
    00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00017  * Boston, MA 02111-1307, USA.
    00018  */
    00019
    00020 #ifndef _tds_iconv_h_
    00021 #define _tds_iconv_h_
    00022
    00023 /* $Id: tdsiconv.h,v 1.35 2005/10/11 08:52:30 freddy77 Exp $ */
    00024
    00025 #if HAVE_ICONV
    00026 #include <iconv.h>
    00027 #else
    00028 /* Define iconv_t for src/replacements/iconv.c. */
    00029 #undef iconv_t
    00030 typedef void *iconv_t;
    00031 #endif /* HAVE_ICONV */
    00032
    00033 #if HAVE_ERRNO_H
    00034 #include <errno.h>
    00035 #endif
    00036
    00037 #if HAVE_WCHAR_H
    00038 #include <wchar.h>
    00039 #endif
    00040
    00041 /* The following EILSEQ advice is borrowed verbatim from GNU iconv.  */
    00042 /* Some systems, like SunOS 4, don't have EILSEQ. Some systems, like BSD/OS,
    00043    have EILSEQ in a different header.  On these systems, define EILSEQ
    00044    ourselves. */
    00045 #ifndef EILSEQ
    00046 # define EILSEQ ENOENT
    00047 #endif
    00048
    00049 #if HAVE_STDLIB_H
    00050 #include <stdlib.h>
    00051 #endif /* HAVE_STDLIB_H */
    00052
    00053 #ifdef __cplusplus
    00054 extern "C"
    00055 {
    00056 #endif
    00057
    00058 #if ! HAVE_ICONV
    00059
    00060         /* FYI, the first 4 entries look like this:
    00061          *      {"ISO-8859-1",  1, 1}, -> 0
    00062          *      {"US-ASCII",    1, 4}, -> 1
    00063          *      {"UCS-2LE",     2, 2}, -> 2
    00064          *      {"UCS-2BE",     2, 2}, -> 3
    00065          *
    00066          * These conversions are supplied by src/replacements/iconv.c for the sake of those who don't
    00067          * have or otherwise need an iconv.
    00068          */
    00069 enum ICONV_CD_VALUE
    00070 {
    00071           Like_to_Like = 0x100
    00072         , Latin1_ASCII  = 0x01
    00073         , ASCII_Latin1  = 0x10
    00074
    00075         , Latin1_UCS2LE = 0x02
    00076         , UCS2LE_Latin1 = 0x20
    00077         , ASCII_UCS2LE  = 0x12
    00078         , UCS2LE_ASCII  = 0x21
    00079
    00080         , Latin1_UTF8   = 0x03
    00081         , UTF8_Latin1   = 0x30
    00082         , ASCII_UTF8    = 0x13
    00083         , UTF8_ASCII    = 0x31
    00084         , UCS2LE_UTF8   = 0x23
    00085         , UTF8_UCS2LE   = 0x32
    00086
    00087 #ifdef DOS32X
    00088         , WinEE_UCS2LE  = 0x42
    00089         , UCS2LE_WinEE  = 0x24
    00090         , WinCYR_UCS2LE = 0x52
    00091         , UCS2LE_WinCYR = 0x25
    00092         , WinTUR_UCS2LE = 0x62
    00093         , UCS2LE_WinTUR = 0x26
    00094         , WinARA_UCS2LE = 0x72
    00095         , UCS2LE_WinARA = 0x27
    00096 #endif
    00097         /* these aren't needed
    00098          * , Latin1_UCS2BE = 0x03
    00099          * , UCS2BE_Latin1 = 0x30
    00100          */
    00101 };
    00102
    00103 iconv_t tds_sys_iconv_open(const char *tocode, const char *fromcode);
    00104 size_t tds_sys_iconv(iconv_t cd, const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft);
    00105 int tds_sys_iconv_close(iconv_t cd);
    00106 #else
    00107 #define tds_sys_iconv_open iconv_open
    00108 #define tds_sys_iconv iconv
    00109 #define tds_sys_iconv_close iconv_close
    00110 #endif /* !HAVE_ICONV */
    00111
    00112
    00113 typedef enum
    00114 { to_server, to_client } TDS_ICONV_DIRECTION;
    00115
    00116 typedef struct _character_set_alias
    00117 {
    00118         const char *alias;
    00119         int canonic;
    00120 } CHARACTER_SET_ALIAS;
    00121
    00122 typedef struct _tds_errno_message_flags {
    00123         unsigned int e2big:1;
    00124         unsigned int eilseq:1;
    00125         unsigned int einval:1;
    00126 } TDS_ERRNO_MESSAGE_FLAGS;
    00127
    00128 struct tdsiconvinfo
    00129 {
    00130         TDS_ENCODING client_charset;
    00131         TDS_ENCODING server_charset;
    00132
    00133 #define TDS_ENCODING_INDIRECT 1
    00134 #define TDS_ENCODING_SWAPBYTE 2
    00135 #define TDS_ENCODING_MEMCPY   4
    00136         unsigned int flags;
    00137
    00138         iconv_t to_wire;        /* conversion from client charset to server's format */
    00139         iconv_t from_wire;      /* conversion from server's format to client charset */
    00140
    00141         iconv_t to_wire2;       /* conversion from client charset to server's format - indirect */
    00142         iconv_t from_wire2;     /* conversion from server's format to client charset - indirect */
    00143
    00144         /*
    00145          * Suppress error messages that would otherwise be emitted by tds_iconv().
    00146          * Functions that process large buffers ask tds_iconv to convert it in "chunks".
    00147          * We don't want to emit spurious EILSEQ errors or multiple errors for one
    00148          * buffer.  tds_iconv() checks this structure before emiting a message, and
    00149          * adds to it whenever it emits one.  Callers that handle a particular situation themselves
    00150          * can prepopulate it.
    00151          */
    00152         TDS_ERRNO_MESSAGE_FLAGS suppress;
    00153 };
    00154
    00155 /* We use ICONV_CONST for tds_iconv(), even if we don't have iconv() */
    00156 #ifndef ICONV_CONST
    00157 # define ICONV_CONST const
    00158 #endif
    00159
    00160 size_t tds_iconv_fread(iconv_t cd, FILE * stream, size_t field_len, size_t term_len, char *outbuf, size_t * outbytesleft);
    00161 size_t tds_iconv(TDSSOCKET * tds, const TDSICONV * char_conv, TDS_ICONV_DIRECTION io,
    00162                  const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft);
    00163 const char *tds_canonical_charset_name(const char *charset_name);
    00164 const char *tds_sybase_charset_name(const char *charset_name);
    00165
    00166 #ifdef __cplusplus
    00167 }
    00168 #endif
    00169
    00170 #endif /* _tds_iconv_h_ */