FreeTDS API
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tdsiconv.h
1 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2  * Copyright (C) 2002, 2003, 2004 Brian Bruns
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 
20 #ifndef _tds_iconv_h_
21 #define _tds_iconv_h_
22 
23 /* $Id: tdsiconv.h,v 1.40 2010-07-25 08:40:19 freddy77 Exp $ */
24 
25 #if HAVE_ICONV
26 #include <iconv.h>
27 #else
28 /* Define iconv_t for src/replacements/iconv.c. */
29 #undef iconv_t
30 typedef void *iconv_t;
31 #endif /* HAVE_ICONV */
32 
33 #if HAVE_ERRNO_H
34 #include <errno.h>
35 #endif
36 
37 #if HAVE_WCHAR_H
38 #include <wchar.h>
39 #endif
40 
41 /* The following EILSEQ advice is borrowed verbatim from GNU iconv. */
42 /* Some systems, like SunOS 4, don't have EILSEQ. Some systems, like BSD/OS,
43  have EILSEQ in a different header. On these systems, define EILSEQ
44  ourselves. */
45 #ifndef EILSEQ
46 # define EILSEQ ENOENT
47 #endif
48 
49 #if HAVE_STDLIB_H
50 #include <stdlib.h>
51 #endif /* HAVE_STDLIB_H */
52 
53 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
54 #pragma GCC visibility push(hidden)
55 #endif
56 
57 #ifdef __cplusplus
58 extern "C"
59 {
60 #endif
61 
62 #if ! HAVE_ICONV
63 iconv_t tds_sys_iconv_open(const char *tocode, const char *fromcode);
64 size_t tds_sys_iconv(iconv_t cd, const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft);
65 int tds_sys_iconv_close(iconv_t cd);
66 #else
67 #define tds_sys_iconv_open iconv_open
68 #define tds_sys_iconv iconv
69 #define tds_sys_iconv_close iconv_close
70 #endif /* !HAVE_ICONV */
71 
72 
73 typedef enum
74 { to_server, to_client } TDS_ICONV_DIRECTION;
75 
76 typedef struct _character_set_alias
77 {
78  const char *alias;
79  int canonic;
81 
82 typedef struct tds_errno_message_flags {
83  unsigned int e2big:1;
84  unsigned int eilseq:1;
85  unsigned int einval:1;
87 
89 {
90  TDS_ENCODING client_charset;
91  TDS_ENCODING server_charset;
92 
93 #define TDS_ENCODING_INDIRECT 1
94 #define TDS_ENCODING_SWAPBYTE 2
95 #define TDS_ENCODING_MEMCPY 4
96  unsigned int flags;
97 
98  iconv_t to_wire; /* conversion from client charset to server's format */
99  iconv_t from_wire; /* conversion from server's format to client charset */
100 
101  iconv_t to_wire2; /* conversion from client charset to server's format - indirect */
102  iconv_t from_wire2; /* conversion from server's format to client charset - indirect */
103 
104  /*
105  * Suppress error messages that would otherwise be emitted by tds_iconv().
106  * Functions that process large buffers ask tds_iconv to convert it in "chunks".
107  * We don't want to emit spurious EILSEQ errors or multiple errors for one
108  * buffer. tds_iconv() checks this structure before emiting a message, and
109  * adds to it whenever it emits one. Callers that handle a particular situation themselves
110  * can prepopulate it.
111  */
112  TDS_ERRNO_MESSAGE_FLAGS suppress;
113 };
114 
115 /* We use ICONV_CONST for tds_iconv(), even if we don't have iconv() */
116 #ifndef ICONV_CONST
117 # define ICONV_CONST const
118 #endif
119 
120 size_t tds_iconv_fread(iconv_t cd, FILE * stream, size_t field_len, size_t term_len, char *outbuf, size_t * outbytesleft);
121 size_t tds_iconv(TDSSOCKET * tds, const TDSICONV * char_conv, TDS_ICONV_DIRECTION io,
122  const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft);
123 const char *tds_canonical_charset_name(const char *charset_name);
124 const char *tds_sybase_charset_name(const char *charset_name);
125 TDSICONV *tds_iconv_get(TDSSOCKET * tds, const char *client_charset, const char *server_charset);
126 
127 #ifdef __cplusplus
128 }
129 #endif
130 
131 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
132 #pragma GCC visibility pop
133 #endif
134 
135 #endif /* _tds_iconv_h_ */