Main Page Modules Compound List File List Compound Members File Members Related Pages

# tdsiconv.h

    00001 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
    00002  * Copyright (C) 2002, 2003  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 static char rcsid_tds_iconv_h[] = "$Id: tdsiconv.h,v 1.28 2003/12/12 10:43:16 freddy77 Exp $";
    00024 static void *no_unused_tds_iconv_h_warn[] = { rcsid_tds_iconv_h, no_unused_tds_iconv_h_warn };
    00025
    00026 #if HAVE_ICONV
    00027 #include <iconv.h>
    00028 #else
    00029 /* Define iconv_t for src/replacements/iconv.c. */
    00030 #undef iconv_t
    00031 typedef void *iconv_t;
    00032 #endif /* HAVE_ICONV */
    00033
    00034 #if HAVE_ERRNO_H
    00035 #include <errno.h>
    00036 #endif
    00037
    00038 #if HAVE_WCHAR_H
    00039 #include <wchar.h>
    00040 #endif
    00041
    00042 /* The following EILSEQ advice is borrowed verbatim from GNU iconv.  */
    00043 /* Some systems, like SunOS 4, don't have EILSEQ. Some systems, like BSD/OS,
    00044    have EILSEQ in a different header.  On these systems, define EILSEQ
    00045    ourselves. */
    00046 #ifndef EILSEQ
    00047 # define EILSEQ ENOENT
    00048 #endif
    00049
    00050 #if HAVE_STDLIB_H
    00051 #include <stdlib.h>
    00052 #endif /* HAVE_STDLIB_H */
    00053
    00054 #ifdef __cplusplus
    00055 extern "C"
    00056 {
    00057 #endif
    00058
    00059 #if ! HAVE_ICONV
    00060
    00061         /* FYI, the first 4 entries look like this:
    00062          *      {"ISO-8859-1",  1, 1}, -> 0
    00063          *      {"US-ASCII",    1, 4}, -> 1
    00064          *      {"UCS-2LE",     2, 2}, -> 2
    00065          *      {"UCS-2BE",     2, 2}, -> 3
    00066          *
    00067          * These conversions are supplied by src/replacements/iconv.c for the sake of those who don't
    00068          * have or otherwise need an iconv.
    00069          */
    00070 enum ICONV_CD_VALUE
    00071 {
    00072           Like_to_Like = 0x100
    00073         , Latin1_ASCII  = 0x01
    00074         , ASCII_Latin1  = 0x10
    00075
    00076         , Latin1_UCS2LE = 0x02
    00077         , UCS2LE_Latin1 = 0x20
    00078         , ASCII_UCS2LE  = 0x12
    00079         , UCS2LE_ASCII  = 0x21
    00080
    00081         , Latin1_UTF8   = 0x03
    00082         , UTF8_Latin1   = 0x30
    00083         , ASCII_UTF8    = 0x13
    00084         , UTF8_ASCII    = 0x31
    00085         , UCS2LE_UTF8   = 0x23
    00086         , UTF8_UCS2LE   = 0x32
    00087         /* these aren't needed
    00088          * , Latin1_UCS2BE = 0x03
    00089          * , UCS2BE_Latin1 = 0x30
    00090          */
    00091 };
    00092
    00093 iconv_t tds_rep_iconv_open(const char *tocode, const char *fromcode);
    00094 size_t tds_rep_iconv(iconv_t cd, const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft);
    00095 int tds_rep_iconv_close(iconv_t cd);
    00096 #define iconv_open tds_rep_iconv_open
    00097 #define iconv tds_rep_iconv
    00098 #define iconv_close tds_rep_iconv_close
    00099 #endif /* !HAVE_ICONV */
    00100
    00101
    00102 typedef enum
    00103 { to_server, to_client } TDS_ICONV_DIRECTION;
    00104
    00105 typedef struct _character_set_alias
    00106 {
    00107         const char *alias;
    00108         int canonic;
    00109 } CHARACTER_SET_ALIAS;
    00110
    00111 typedef struct _tds_errno_message_flags {
    00112         unsigned int e2big:1;
    00113         unsigned int eilseq:1;
    00114         unsigned int einval:1;
    00115 } TDS_ERRNO_MESSAGE_FLAGS;
    00116
    00117 struct tdsiconvinfo
    00118 {
    00119         TDS_ENCODING client_charset;
    00120         TDS_ENCODING server_charset;
    00121
    00122 #define TDS_ENCODING_INDIRECT 1
    00123 #define TDS_ENCODING_SWAPBYTE 2
    00124 #define TDS_ENCODING_MEMCPY   4
    00125         unsigned int flags;
    00126
    00127         iconv_t to_wire;        /* conversion from client charset to server's format */
    00128         iconv_t from_wire;      /* conversion from server's format to client charset */
    00129
    00130         iconv_t to_wire2;       /* conversion from client charset to server's format - indirect */
    00131         iconv_t from_wire2;     /* conversion from server's format to client charset - indirect */
    00132
    00133         /*
    00134          * Suppress error messages that would otherwise be emitted by tds_iconv().
    00135          * Functions that process large buffers ask tds_iconv to convert it in "chunks".
    00136          * We don't want to emit spurious EILSEQ errors or multiple errors for one
    00137          * buffer.  tds_iconv() checks this structure before emiting a message, and
    00138          * adds to it whenever it emits one.  Callers that handle a particular situation themselves
    00139          * can prepopulate it.
    00140          */
    00141         TDS_ERRNO_MESSAGE_FLAGS suppress;
    00142 };
    00143
    00144 /* We use ICONV_CONST for tds_iconv(), even if we don't have iconv() */
    00145 #ifndef ICONV_CONST
    00146 # define ICONV_CONST const
    00147 #endif
    00148
    00149 size_t tds_iconv_fread(iconv_t cd, FILE * stream, size_t field_len, size_t term_len, char *outbuf, size_t * outbytesleft);
    00150 size_t tds_iconv(TDSSOCKET * tds, const TDSICONVINFO * iconv_info, TDS_ICONV_DIRECTION io,
    00151                  const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft);
    00152 const char *tds_canonical_charset_name(const char *charset_name);
    00153 const char *tds_sybase_charset_name(const char *charset_name);
    00154
    00155 #ifdef __cplusplus
    00156 }
    00157 #endif
    00158
    00159 #endif /* _tds_iconv_h_ */