FreeTDS API

Macros | Enumerations | Functions | Variables
iconv.c File Reference

Handle character conversions to/from server. More...

`#include <config.h>`
`#include <stdarg.h>`
`#include <stdio.h>`
`#include <assert.h>`
`#include <freetds/tds.h>`
`#include <freetds/iconv.h>`
`#include <freetds/bool.h>`
`#include <freetds/bytes.h>`
`#include <freetds/encodings.h>`
`#include <freetds/charset_lookup.h>`
Include dependency graph for iconv.c:

## Macros
#define | CHARSIZE(charset)
#define | CHUNK_ALLOC 4
#define | TDS_ICONV_ENCODING_TABLES

## Enumerations
enum | { OPT_VERSION = 0x01, OPT_TIMER = 0x02, OPT_NOFOOTER = 0x04, OPT_NOHEADER = 0x08, OPT_QUIET = 0x10, OPT_VERBOSE = 0x20, OPT_INSTANCES = 0x40, POS_ISO1, POS_UTF8, POS_UCS2LE, POS_UCS2BE, MUL_STARTED = 1, ASN1_SEQUENCE = ASN1_TAG_SEQUENCE, CS_USERNAME = 9100, CS_USERNAME = 9100, CS_PASSWORD = 9101, CS_PASSWORD = 9101, CS_APPNAME = 9102, CS_APPNAME = 9102, CS_HOSTNAME = 9103, CS_HOSTNAME = 9103, CS_LOGIN_STATUS = 9104, CS_LOGIN_STATUS = 9104, CS_TDS_VERSION = 9105, CS_TDS_VERSION = 9105, CS_CHARSETCNV = 9106, CS_CHARSETCNV = 9106, CS_PACKETSIZE = 9107, CS_PACKETSIZE = 9107, CS_USERDATA = 9108, CS_USERDATA = 9108, CS_NETIO = 9110, CS_NETIO = 9110, CS_TEXTLIMIT = 9112, CS_TEXTLIMIT = 9112, CS_HIDDEN_KEYS = 9113, CS_HIDDEN_KEYS = 9113, CS_VERSION = 9114, CS_VERSION = 9114, CS_IFILE = 9115, CS_IFILE = 9115, CS_LOGIN_TIMEOUT = 9116, CS_LOGIN_TIMEOUT = 9116, CS_TIMEOUT = 9117, CS_TIMEOUT = 9117, CS_MAX_CONNECT = 9118, CS_MAX_CONNECT = 9118, CS_EXPOSE_FMTS = 9120, CS_EXPOSE_FMTS = 9120, CS_EXTRA_INF = 9121, CS_EXTRA_INF = 9121, CS_ANSI_BINDS = 9123, CS_ANSI_BINDS = 9123, CS_BULK_LOGIN = 9124, CS_BULK_LOGIN = 9124, CS_LOC_PROP = 9125, CS_LOC_PROP = 9125, CS_PARENT_HANDLE = 9130, CS_PARENT_HANDLE = 9130, CS_EED_CMD = 9131, CS_EED_CMD = 9131, CS_DIAG_TIMEOUT = 9132, CS_DIAG_TIMEOUT = 9132, CS_DISABLE_POLL = 9133, CS_DISABLE_POLL = 9133, CS_SEC_ENCRYPTION = 9135, CS_SEC_ENCRYPTION = 9135, CS_SEC_CHALLENGE = 9136, CS_SEC_CHALLENGE = 9136, CS_SEC_NEGOTIATE = 9137, CS_SEC_NEGOTIATE = 9137, CS_CON_STATUS = 9143, CS_CON_STATUS = 9143, CS_VER_STRING = 9144, CS_VER_STRING = 9144, CS_SERVERNAME = 9146, CS_SERVERNAME = 9146, CS_SEC_APPDEFINED = 9149, CS_SEC_APPDEFINED = 9149, CS_STICKY_BINDS = 9151, CS_STICKY_BINDS = 9151, CS_SEC_NETWORKAUTH = 9175, CS_SEC_NETWORKAUTH = 9175, CS_SEC_DELEGATION = 9176, CS_SEC_DELEGATION = 9176, CS_SEC_MUTUALAUTH = 9177, CS_SEC_MUTUALAUTH = 9177, CS_SEC_SERVERPRINCIPAL = 9188, CS_SEC_SERVERPRINCIPAL = 9188, CS_SERVERADDR = 9206, CS_SERVERADDR = 9206, CS_PORT = 9300, CS_PORT = 9300, CS_CLIENTCHARSET = 9301, CS_CLIENTCHARSET = 9301, CS_DATABASE, dblib_msdblib = 0, TDS_CHARSET_ISO_8859_1 = 0, TDS_CHARSET_UTF_8 = 1, TDS_CHARSET_UCS_2LE = 2, TDS_CHARSET_UCS_2BE = 3, TDS_CHARSET_ARMSCII_8 = 4, TDS_CHARSET_BIG_5 = 5, TDS_CHARSET_BIG5_HKSCS = 6, TDS_CHARSET_C99 = 7, TDS_CHARSET_CHINESE = 8, TDS_CHARSET_CN = 9, TDS_CHARSET_CN_GB = 10, TDS_CHARSET_CN_GB_ISOIR165 = 11, TDS_CHARSET_CP1133 = 12, TDS_CHARSET_CP1250 = 13, TDS_CHARSET_CP1251 = 14, TDS_CHARSET_CP1252 = 15, TDS_CHARSET_CP1253 = 16, TDS_CHARSET_CP1254 = 17, TDS_CHARSET_CP1255 = 18, TDS_CHARSET_CP1256 = 19, TDS_CHARSET_CP1257 = 20, TDS_CHARSET_CP1258 = 21, TDS_CHARSET_CP1361 = 22, TDS_CHARSET_CP437 = 23, TDS_CHARSET_CP850 = 24, TDS_CHARSET_CP862 = 25, TDS_CHARSET_CP866 = 26, TDS_CHARSET_CP874 = 27, TDS_CHARSET_CP932 = 28, TDS_CHARSET_CP936 = 29, TDS_CHARSET_CP949 = 30, TDS_CHARSET_CP950 = 31, TDS_CHARSET_EUC_JP = 32, TDS_CHARSET_EUC_KR = 33, TDS_CHARSET_EUC_TW = 34, TDS_CHARSET_GB18030 = 35, TDS_CHARSET_GEORGIAN_ACADEMY = 36, TDS_CHARSET_GEORGIAN_PS = 37, TDS_CHARSET_HZ = 38, TDS_CHARSET_ISO_2022_CN = 39, TDS_CHARSET_ISO_2022_CN_EXT = 40, TDS_CHARSET_ISO_2022_JP = 41, TDS_CHARSET_ISO_2022_JP_1 = 42, TDS_CHARSET_ISO_2022_JP_2 = 43, TDS_CHARSET_ISO_2022_KR = 44, TDS_CHARSET_ISO_8859_10 = 45, TDS_CHARSET_ISO_8859_13 = 46, TDS_CHARSET_ISO_8859_14 = 47, TDS_CHARSET_ISO_8859_15 = 48, TDS_CHARSET_ISO_8859_16 = 49, TDS_CHARSET_ISO_8859_2 = 50, TDS_CHARSET_ISO_8859_3 = 51, TDS_CHARSET_ISO_8859_4 = 52, TDS_CHARSET_ISO_8859_5 = 53, TDS_CHARSET_ISO_8859_6 = 54, TDS_CHARSET_ISO_8859_7 = 55, TDS_CHARSET_ISO_8859_8 = 56, TDS_CHARSET_ISO_8859_9 = 57, TDS_CHARSET_ISO_IR_14 = 58, TDS_CHARSET_ISO_IR_149 = 59, TDS_CHARSET_ISO_IR_159 = 60, TDS_CHARSET_ISO_IR_166 = 61, TDS_CHARSET_ISO_IR_87 = 62, TDS_CHARSET_JAVA = 63, TDS_CHARSET_JISX0201_1976 = 64, TDS_CHARSET_KOI8_R = 65, TDS_CHARSET_KOI8_RU = 66, TDS_CHARSET_KOI8_T = 67, TDS_CHARSET_KOI8_U = 68, TDS_CHARSET_MAC = 69, TDS_CHARSET_MACARABIC = 70, TDS_CHARSET_MACCENTRALEUROPE = 71, TDS_CHARSET_MACCROATIAN = 72, TDS_CHARSET_MACCYRILLIC = 73, TDS_CHARSET_MACGREEK = 74, TDS_CHARSET_MACHEBREW = 75, TDS_CHARSET_MACICELAND = 76, TDS_CHARSET_MACROMANIA = 77, TDS_CHARSET_MACTHAI = 78, TDS_CHARSET_MACTURKISH = 79, TDS_CHARSET_MACUKRAINE = 80, TDS_CHARSET_MULELAO_1 = 81, TDS_CHARSET_NEXTSTEP = 82, TDS_CHARSET_ROMAN8 = 83, TDS_CHARSET_SJIS = 84, TDS_CHARSET_TCVN = 85, TDS_CHARSET_UCS_4BE = 86, TDS_CHARSET_UCS_4LE = 87, TDS_CHARSET_US_ASCII = 88, TDS_CHARSET_UTF_16BE = 89, TDS_CHARSET_UTF_16LE = 90, TDS_CHARSET_UTF_32BE = 91, TDS_CHARSET_UTF_32LE = 92, TDS_CHARSET_UTF_7 = 93, TDS_CHARSET_VISCII = 94, TDS_NUM_CHARSETS = 95, ODBC_PARAM_SIZE, TDS_OPT_ARITHOVERFLOW = 0x01, TDS_OPT_NUMERICTRUNC = 0x02, TDS_CUR_ISTAT_UNUSED = 0x00, TDS_CUR_ISTAT_DECLARED = 0x01, TDS_CUR_ISTAT_OPEN = 0x02, TDS_CUR_ISTAT_CLOSED = 0x04, TDS_CUR_ISTAT_RDONLY = 0x08, TDS_CUR_ISTAT_UPDATABLE = 0x10, TDS_CUR_ISTAT_ROWCNT = 0x20, TDS_CUR_ISTAT_DEALLOC = 0x40, SYBCHAR = 47, SYBCHAR = 47, SYBVARCHAR = 39, SYBVARCHAR = 39, SYBINTN = 38, SYBINTN = 38, SYBINT1 = 48, SYBINT1 = 48, SYBINT2 = 52, SYBINT2 = 52, SYBINT4 = 56, SYBINT4 = 56, SYBINT8 = 127, SYBINT8 = 127, SYBFLT8 = 62, SYBFLT8 = 62, SYBDATETIME = 61, SYBDATETIME = 61, SYBBIT = 50, SYBBIT = 50, SYBBITN = 104, SYBBITN = 104, SYBTEXT = 35, SYBTEXT = 35, SYBNTEXT = 99, SYBNTEXT = 99, SYBIMAGE = 34, SYBIMAGE = 34, SYBMONEY4 = 122, SYBMONEY4 = 122, SYBMONEY = 60, SYBMONEY = 60, SYBDATETIME4 = 58, SYBDATETIME4 = 58, SYBREAL = 59, SYBREAL = 59, SYBBINARY = 45, SYBBINARY = 45, SYBVOID = 31, SYBVOID = 31, SYBVARBINARY = 37, SYBVARBINARY = 37, SYBNUMERIC = 108, SYBNUMERIC = 108, SYBDECIMAL = 106, SYBDECIMAL = 106, SYBFLTN = 109, SYBFLTN = 109, SYBMONEYN = 110, SYBMONEYN = 110, SYBDATETIMN = 111, SYBDATETIMN = 111, SYBNVARCHAR = 103, SYBNVARCHAR = 103, SYBDATE = 49, SYBDATE = 49, SYBTIME = 51, SYBTIME = 51, SYBBIGDATETIME = 187, SYBBIGDATETIME = 187, SYBBIGTIME = 188, SYBBIGTIME = 188, SYBMSDATE = 40, SYBMSDATE = 40, SYBMSTIME = 41, SYBMSTIME = 41, SYBMSDATETIME2 = 42, SYBMSDATETIME2 = 42, SYBMSDATETIMEOFFSET = 43, SYBMSDATETIMEOFFSET = 43 }

## Functions
static void | _iconv_close (iconv_t *cd)
static int | collate2charset (TDSCONNECTION *conn, TDS_UCHAR collate[5])
static size_t | skip_one_input_sequence (iconv_t cd, const TDS_ENCODING *charset, const char **input, size_t *input_size)
| Move the input sequence pointer to the next valid position. More...
void | tds7_srv_charset_changed (TDSCONNECTION *conn, TDS_UCHAR collation[5])
int | tds_canonical_charset (const char *charset_name)
| Determine canonical iconv character set. More...
const char * | tds_canonical_charset_name (const char *charset_name)
| Determine canonical iconv character set name. More...
size_t | tds_iconv (TDSSOCKET *tds, TDSICONV *conv, TDS_ICONV_DIRECTION io, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
| Wrapper around iconv(3). More...
int | tds_iconv_alloc (TDSCONNECTION *conn)
| Allocate iconv stuff. More...
void | tds_iconv_close (TDSCONNECTION *conn)
static void | tds_iconv_err (TDSSOCKET *tds, int err)
void | tds_iconv_free (TDSCONNECTION *conn)
TDSICONV * | tds_iconv_from_collate (TDSCONNECTION *conn, TDS_UCHAR collate[5])
| Get iconv information from a LCID (to support different column encoding under MSSQL2K)
TDSICONV * | tds_iconv_get (TDSCONNECTION *conn, const char *client_charset, const char *server_charset)
TDSICONV * | tds_iconv_get_info (TDSCONNECTION *conn, int canonic_client, int canonic_server)
| Get a iconv info structure, allocate and initialize if needed.
static void | tds_iconv_info_close (TDSICONV *char_conv)
static int | tds_iconv_info_init (TDSICONV *char_conv, int client_canonical, int server_canonical)
| Open iconv descriptors to convert between character sets (both directions). More...
static int | tds_iconv_init (void)
| Initialize charset searching for UTF-8, UCS-2 and ISO8859-1.
TDSRET | tds_iconv_open (TDSCONNECTION *conn, const char *charset, int use_utf16)
static void | tds_iconv_reset (TDSICONV *conv)
static const char * | tds_set_iconv_name (int charset)
| Get iconv name given canonic.
void | tds_srv_charset_changed (TDSCONNECTION *conn, const char *charset)
static void | tds_srv_charset_changed_num (TDSCONNECTION *conn, int canonic_charset_num)

## Variables
static int | iconv_initialized = 0
static const char * | iconv_names [TDS_VECTOR_SIZE(canonic_charsets)]
struct {
char data [15]
uint8_t len
} | test_strings [4]
static const char * | ucs2name

## Detailed Description

Handle character conversions to/from server.

## Macro Definition Documentation

## ◆ CHARSIZE

#define CHARSIZE | ( |  | charset | ) |

Value:
( ((charset)->min_bytes_per_char == (charset)->max_bytes_per_char )? \
(charset)->min_bytes_per_char : 0 )

## Function Documentation

## ◆ tds_iconv_alloc()

int tds_iconv_alloc | ( | TDSCONNECTION * | conn | ) |

Allocate iconv stuff.

Returns
  0 for success

## Variable Documentation

## ◆ test_strings

const { ... } test_strings[4]

Initial value:
= {
{ 4, "Ao\xD3\xE5" },
{ 6, "Ao\xC3\x93\xC3\xA5" },
{ 8, "A\x00o\x000\xD3\x00\xE5\x00" },
{ 8, "\x00" "A\x00o\x000\xD3\x00\xE5" },
}