nsswitch: Fix paths for Samba4 blackbox wbinfo test
[Samba/nascimento.git] / source3 / include / charset.h
blob1c2a5fb5f093d345d40bdb748e8abf2980c63846
1 /*
2 Unix SMB/CIFS implementation.
3 charset defines
4 Copyright (C) Andrew Tridgell 2001
5 Copyright (C) Jelmer Vernooij 2002
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 struct smb_iconv_convenience;
23 /* this defines the charset types used in samba */
24 typedef enum {CH_UTF16LE=0, CH_UTF16=0, CH_UNIX=1, CH_DISPLAY=2, CH_DOS=3, CH_UTF8=4, CH_UTF16BE=5} charset_t;
26 #define NUM_CHARSETS 6
28 /*
29 * for each charset we have a function that pushes from that charset to a ucs2
30 * buffer, and a function that pulls from ucs2 buffer to that charset.
31 * */
33 struct charset_functions {
34 const char *name;
35 size_t (*pull)(void *, const char **inbuf, size_t *inbytesleft,
36 char **outbuf, size_t *outbytesleft);
37 size_t (*push)(void *, const char **inbuf, size_t *inbytesleft,
38 char **outbuf, size_t *outbytesleft);
39 struct charset_functions *prev, *next;
43 * This is auxiliary struct used by source/script/gen-8-bit-gap.sh script
44 * during generation of an encoding table for charset module
45 * */
47 struct charset_gap_table {
48 uint16 start;
49 uint16 end;
50 int32 idx;
54 * Define stub for charset module which implements 8-bit encoding with gaps.
55 * Encoding tables for such module should be produced from glibc's CHARMAPs
56 * using script source/script/gen-8bit-gap.sh
57 * CHARSETNAME is CAPITALIZED charset name
59 * */
60 #define SMB_GENERATE_CHARSET_MODULE_8_BIT_GAP(CHARSETNAME) \
61 static size_t CHARSETNAME ## _push(void *cd, const char **inbuf, size_t *inbytesleft, \
62 char **outbuf, size_t *outbytesleft) \
63 { \
64 while (*inbytesleft >= 2 && *outbytesleft >= 1) { \
65 int i; \
66 int done = 0; \
68 uint16 ch = SVAL(*inbuf,0); \
70 for (i=0; from_idx[i].start != 0xffff; i++) { \
71 if ((from_idx[i].start <= ch) && (from_idx[i].end >= ch)) { \
72 ((unsigned char*)(*outbuf))[0] = from_ucs2[from_idx[i].idx+ch]; \
73 (*inbytesleft) -= 2; \
74 (*outbytesleft) -= 1; \
75 (*inbuf) += 2; \
76 (*outbuf) += 1; \
77 done = 1; \
78 break; \
79 } \
80 } \
81 if (!done) { \
82 errno = EINVAL; \
83 return -1; \
84 } \
86 } \
88 if (*inbytesleft == 1) { \
89 errno = EINVAL; \
90 return -1; \
91 } \
93 if (*inbytesleft > 1) { \
94 errno = E2BIG; \
95 return -1; \
96 } \
98 return 0; \
99 } \
101 static size_t CHARSETNAME ## _pull(void *cd, const char **inbuf, size_t *inbytesleft, \
102 char **outbuf, size_t *outbytesleft) \
104 while (*inbytesleft >= 1 && *outbytesleft >= 2) { \
105 *(uint16*)(*outbuf) = to_ucs2[((unsigned char*)(*inbuf))[0]]; \
106 (*inbytesleft) -= 1; \
107 (*outbytesleft) -= 2; \
108 (*inbuf) += 1; \
109 (*outbuf) += 2; \
112 if (*inbytesleft > 0) { \
113 errno = E2BIG; \
114 return -1; \
117 return 0; \
120 struct charset_functions CHARSETNAME ## _functions = \
121 {#CHARSETNAME, CHARSETNAME ## _pull, CHARSETNAME ## _push}; \
123 NTSTATUS charset_ ## CHARSETNAME ## _init(void); \
124 NTSTATUS charset_ ## CHARSETNAME ## _init(void) \
126 return smb_register_charset(& CHARSETNAME ## _functions); \