1 /*
2 +----------------------------------------------------------------------+
3 | PHP Version 7 |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2006-2017 The PHP Group |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: Andrey Hristov <andrey@php.net> |
16 | Ulf Wendel <uw@php.net> |
17 | Georg Richter <georg@php.net> |
18 +----------------------------------------------------------------------+
19 */
20
21 #include "php.h"
22 #include "php_globals.h"
23 #include "mysqlnd.h"
24 #include "mysqlnd_priv.h"
25 #include "mysqlnd_debug.h"
26 #include "mysqlnd_charset.h"
27
28 /* {{{ utf8 functions */
check_mb_utf8mb3_sequence(const char * start,const char * end)29 static unsigned int check_mb_utf8mb3_sequence(const char *start, const char *end)
30 {
31 zend_uchar c;
32
33 if (start >= end) {
34 return 0;
35 }
36
37 c = (zend_uchar) start[0];
38
39 if (c < 0x80) {
40 return 1; /* single byte character */
41 }
42 if (c < 0xC2) {
43 return 0; /* invalid mb character */
44 }
45 if (c < 0xE0) {
46 if (start + 2 > end) {
47 return 0; /* too small */
48 }
49 if (!(((zend_uchar)start[1] ^ 0x80) < 0x40)) {
50 return 0;
51 }
52 return 2;
53 }
54 if (c < 0xF0) {
55 if (start + 3 > end) {
56 return 0; /* too small */
57 }
58 if (!(((zend_uchar)start[1] ^ 0x80) < 0x40 && ((zend_uchar)start[2] ^ 0x80) < 0x40 &&
59 (c >= 0xE1 || (zend_uchar)start[1] >= 0xA0))) {
60 return 0; /* invalid utf8 character */
61 }
62 return 3;
63 }
64 return 0;
65 }
66
67
check_mb_utf8_sequence(const char * start,const char * end)68 static unsigned int check_mb_utf8_sequence(const char *start, const char *end)
69 {
70 zend_uchar c;
71
72 if (start >= end) {
73 return 0;
74 }
75
76 c = (zend_uchar) start[0];
77
78 if (c < 0x80) {
79 return 1; /* single byte character */
80 }
81 if (c < 0xC2) {
82 return 0; /* invalid mb character */
83 }
84 if (c < 0xE0) {
85 if (start + 2 > end) {
86 return 0; /* too small */
87 }
88 if (!(((zend_uchar)start[1] ^ 0x80) < 0x40)) {
89 return 0;
90 }
91 return 2;
92 }
93 if (c < 0xF0) {
94 if (start + 3 > end) {
95 return 0; /* too small */
96 }
97 if (!(((zend_uchar)start[1] ^ 0x80) < 0x40 && ((zend_uchar)start[2] ^ 0x80) < 0x40 &&
98 (c >= 0xE1 || (zend_uchar)start[1] >= 0xA0))) {
99 return 0; /* invalid utf8 character */
100 }
101 return 3;
102 }
103 if (c < 0xF5) {
104 if (start + 4 > end) { /* We need 4 characters */
105 return 0; /* too small */
106 }
107
108 /*
109 UTF-8 quick four-byte mask:
110 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
111 Encoding allows to encode U+00010000..U+001FFFFF
112
113 The maximum character defined in the Unicode standard is U+0010FFFF.
114 Higher characters U+00110000..U+001FFFFF are not used.
115
116 11110000.10010000.10xxxxxx.10xxxxxx == F0.90.80.80 == U+00010000 (min)
117 11110100.10001111.10111111.10111111 == F4.8F.BF.BF == U+0010FFFF (max)
118
119 Valid codes:
120 [F0][90..BF][80..BF][80..BF]
121 [F1][80..BF][80..BF][80..BF]
122 [F2][80..BF][80..BF][80..BF]
123 [F3][80..BF][80..BF][80..BF]
124 [F4][80..8F][80..BF][80..BF]
125 */
126
127 if (!(((zend_uchar)start[1] ^ 0x80) < 0x40 &&
128 ((zend_uchar)start[2] ^ 0x80) < 0x40 &&
129 ((zend_uchar)start[3] ^ 0x80) < 0x40 &&
130 (c >= 0xf1 || (zend_uchar)start[1] >= 0x90) &&
131 (c <= 0xf3 || (zend_uchar)start[1] <= 0x8F)))
132 {
133 return 0; /* invalid utf8 character */
134 }
135 return 4;
136 }
137 return 0;
138 }
139
check_mb_utf8mb3_valid(const char * start,const char * end)140 static unsigned int check_mb_utf8mb3_valid(const char *start, const char *end)
141 {
142 unsigned int len = check_mb_utf8mb3_sequence(start, end);
143 return (len > 1)? len:0;
144 }
145
check_mb_utf8_valid(const char * start,const char * end)146 static unsigned int check_mb_utf8_valid(const char *start, const char *end)
147 {
148 unsigned int len = check_mb_utf8_sequence(start, end);
149 return (len > 1)? len:0;
150 }
151
152
mysqlnd_mbcharlen_utf8mb3(unsigned int utf8)153 static unsigned int mysqlnd_mbcharlen_utf8mb3(unsigned int utf8)
154 {
155 if (utf8 < 0x80) {
156 return 1; /* single byte character */
157 }
158 if (utf8 < 0xC2) {
159 return 0; /* invalid multibyte header */
160 }
161 if (utf8 < 0xE0) {
162 return 2; /* double byte character */
163 }
164 if (utf8 < 0xF0) {
165 return 3; /* triple byte character */
166 }
167 return 0;
168 }
169
170
mysqlnd_mbcharlen_utf8(unsigned int utf8)171 static unsigned int mysqlnd_mbcharlen_utf8(unsigned int utf8)
172 {
173 if (utf8 < 0x80) {
174 return 1; /* single byte character */
175 }
176 if (utf8 < 0xC2) {
177 return 0; /* invalid multibyte header */
178 }
179 if (utf8 < 0xE0) {
180 return 2; /* double byte character */
181 }
182 if (utf8 < 0xF0) {
183 return 3; /* triple byte character */
184 }
185 if (utf8 < 0xF8) {
186 return 4; /* four byte character */
187 }
188 return 0;
189 }
190 /* }}} */
191
192
193 /* {{{ big5 functions */
194 #define valid_big5head(c) (0xA1 <= (unsigned int)(c) && (unsigned int)(c) <= 0xF9)
195 #define valid_big5tail(c) ((0x40 <= (unsigned int)(c) && (unsigned int)(c) <= 0x7E) || \
196 (0xA1 <= (unsigned int)(c) && (unsigned int)(c) <= 0xFE))
197
198 #define isbig5code(c,d) (isbig5head(c) && isbig5tail(d))
199
check_mb_big5(const char * start,const char * end)200 static unsigned int check_mb_big5(const char *start, const char *end)
201 {
202 return (valid_big5head(*(start)) && (end - start) > 1 && valid_big5tail(*(start + 1)) ? 2 : 0);
203 }
204
205
mysqlnd_mbcharlen_big5(unsigned int big5)206 static unsigned int mysqlnd_mbcharlen_big5(unsigned int big5)
207 {
208 return (valid_big5head(big5)) ? 2 : 1;
209 }
210 /* }}} */
211
212
213 /* {{{ cp932 functions */
214 #define valid_cp932head(c) ((0x81 <= (c) && (c) <= 0x9F) || (0xE0 <= (c) && c <= 0xFC))
215 #define valid_cp932tail(c) ((0x40 <= (c) && (c) <= 0x7E) || (0x80 <= (c) && c <= 0xFC))
216
217
check_mb_cp932(const char * start,const char * end)218 static unsigned int check_mb_cp932(const char *start, const char *end)
219 {
220 return (valid_cp932head((zend_uchar)start[0]) && (end - start > 1) &&
221 valid_cp932tail((zend_uchar)start[1])) ? 2 : 0;
222 }
223
224
mysqlnd_mbcharlen_cp932(unsigned int cp932)225 static unsigned int mysqlnd_mbcharlen_cp932(unsigned int cp932)
226 {
227 return (valid_cp932head((zend_uchar)cp932)) ? 2 : 1;
228 }
229 /* }}} */
230
231
232 /* {{{ euckr functions */
233 #define valid_euckr(c) ((0xA1 <= (zend_uchar)(c) && (zend_uchar)(c) <= 0xFE))
234
check_mb_euckr(const char * start,const char * end)235 static unsigned int check_mb_euckr(const char *start, const char *end)
236 {
237 if (end - start <= 1) {
238 return 0; /* invalid length */
239 }
240 if (*(zend_uchar *)start < 0x80) {
241 return 0; /* invalid euckr character */
242 }
243 if (valid_euckr(start[1])) {
244 return 2;
245 }
246 return 0;
247 }
248
249
mysqlnd_mbcharlen_euckr(unsigned int kr)250 static unsigned int mysqlnd_mbcharlen_euckr(unsigned int kr)
251 {
252 return (valid_euckr(kr)) ? 2 : 1;
253 }
254 /* }}} */
255
256
257 /* {{{ eucjpms functions */
258 #define valid_eucjpms(c) (((c) & 0xFF) >= 0xA1 && ((c) & 0xFF) <= 0xFE)
259 #define valid_eucjpms_kata(c) (((c) & 0xFF) >= 0xA1 && ((c) & 0xFF) <= 0xDF)
260 #define valid_eucjpms_ss2(c) (((c) & 0xFF) == 0x8E)
261 #define valid_eucjpms_ss3(c) (((c) & 0xFF) == 0x8F)
262
check_mb_eucjpms(const char * start,const char * end)263 static unsigned int check_mb_eucjpms(const char *start, const char *end)
264 {
265 if (*((zend_uchar *)start) < 0x80) {
266 return 0; /* invalid eucjpms character */
267 }
268 if (valid_eucjpms(start[0]) && (end - start) > 1 && valid_eucjpms(start[1])) {
269 return 2;
270 }
271 if (valid_eucjpms_ss2(start[0]) && (end - start) > 1 && valid_eucjpms_kata(start[1])) {
272 return 2;
273 }
274 if (valid_eucjpms_ss3(start[0]) && (end - start) > 2 && valid_eucjpms(start[1]) &&
275 valid_eucjpms(start[2])) {
276 return 2;
277 }
278 return 0;
279 }
280
281
mysqlnd_mbcharlen_eucjpms(unsigned int jpms)282 static unsigned int mysqlnd_mbcharlen_eucjpms(unsigned int jpms)
283 {
284 if (valid_eucjpms(jpms) || valid_eucjpms_ss2(jpms)) {
285 return 2;
286 }
287 if (valid_eucjpms_ss3(jpms)) {
288 return 3;
289 }
290 return 1;
291 }
292 /* }}} */
293
294
295 /* {{{ gb2312 functions */
296 #define valid_gb2312_head(c) (0xA1 <= (zend_uchar)(c) && (zend_uchar)(c) <= 0xF7)
297 #define valid_gb2312_tail(c) (0xA1 <= (zend_uchar)(c) && (zend_uchar)(c) <= 0xFE)
298
299
check_mb_gb2312(const char * start,const char * end)300 static unsigned int check_mb_gb2312(const char *start, const char *end)
301 {
302 return (valid_gb2312_head((unsigned int)start[0]) && end - start > 1 &&
303 valid_gb2312_tail((unsigned int)start[1])) ? 2 : 0;
304 }
305
306
mysqlnd_mbcharlen_gb2312(unsigned int gb)307 static unsigned int mysqlnd_mbcharlen_gb2312(unsigned int gb)
308 {
309 return (valid_gb2312_head(gb)) ? 2 : 1;
310 }
311 /* }}} */
312
313
314 /* {{{ gbk functions */
315 #define valid_gbk_head(c) (0x81<=(zend_uchar)(c) && (zend_uchar)(c)<=0xFE)
316 #define valid_gbk_tail(c) ((0x40<=(zend_uchar)(c) && (zend_uchar)(c)<=0x7E) || (0x80<=(zend_uchar)(c) && (zend_uchar)(c)<=0xFE))
317
check_mb_gbk(const char * start,const char * end)318 static unsigned int check_mb_gbk(const char *start, const char *end)
319 {
320 return (valid_gbk_head(start[0]) && (end) - (start) > 1 && valid_gbk_tail(start[1])) ? 2 : 0;
321 }
322
mysqlnd_mbcharlen_gbk(unsigned int gbk)323 static unsigned int mysqlnd_mbcharlen_gbk(unsigned int gbk)
324 {
325 return (valid_gbk_head(gbk) ? 2 : 1);
326 }
327 /* }}} */
328
329
330 /* {{{ sjis functions */
331 #define valid_sjis_head(c) ((0x81 <= (c) && (c) <= 0x9F) || (0xE0 <= (c) && (c) <= 0xFC))
332 #define valid_sjis_tail(c) ((0x40 <= (c) && (c) <= 0x7E) || (0x80 <= (c) && (c) <= 0xFC))
333
334
check_mb_sjis(const char * start,const char * end)335 static unsigned int check_mb_sjis(const char *start, const char *end)
336 {
337 return (valid_sjis_head((zend_uchar)start[0]) && (end - start) > 1 && valid_sjis_tail((zend_uchar)start[1])) ? 2 : 0;
338 }
339
340
mysqlnd_mbcharlen_sjis(unsigned int sjis)341 static unsigned int mysqlnd_mbcharlen_sjis(unsigned int sjis)
342 {
343 return (valid_sjis_head((zend_uchar)sjis)) ? 2 : 1;
344 }
345 /* }}} */
346
347
348 /* {{{ ucs2 functions */
check_mb_ucs2(const char * start __attribute ((unused)),const char * end __attribute ((unused)))349 static unsigned int check_mb_ucs2(const char *start __attribute((unused)), const char *end __attribute((unused)))
350 {
351 return 2; /* always 2 */
352 }
353
mysqlnd_mbcharlen_ucs2(unsigned int ucs2 __attribute ((unused)))354 static unsigned int mysqlnd_mbcharlen_ucs2(unsigned int ucs2 __attribute((unused)))
355 {
356 return 2; /* always 2 */
357 }
358 /* }}} */
359
360
361 /* {{{ ujis functions */
362 #define valid_ujis(c) ((0xA1 <= ((c)&0xFF) && ((c)&0xFF) <= 0xFE))
363 #define valid_ujis_kata(c) ((0xA1 <= ((c)&0xFF) && ((c)&0xFF) <= 0xDF))
364 #define valid_ujis_ss2(c) (((c)&0xFF) == 0x8E)
365 #define valid_ujis_ss3(c) (((c)&0xFF) == 0x8F)
366
check_mb_ujis(const char * start,const char * end)367 static unsigned int check_mb_ujis(const char *start, const char *end)
368 {
369 if (*(zend_uchar*)start < 0x80) {
370 return 0; /* invalid ujis character */
371 }
372 if (valid_ujis(*(start)) && valid_ujis(*((start)+1))) {
373 return 2;
374 }
375 if (valid_ujis_ss2(*(start)) && valid_ujis_kata(*((start)+1))) {
376 return 2;
377 }
378 if (valid_ujis_ss3(*(start)) && (end-start) > 2 && valid_ujis(*((start)+1)) && valid_ujis(*((start)+2))) {
379 return 3;
380 }
381 return 0;
382 }
383
384
mysqlnd_mbcharlen_ujis(unsigned int ujis)385 static unsigned int mysqlnd_mbcharlen_ujis(unsigned int ujis)
386 {
387 return (valid_ujis(ujis)? 2: valid_ujis_ss2(ujis)? 2: valid_ujis_ss3(ujis)? 3: 1);
388 }
389 /* }}} */
390
391
392
393 /* {{{ utf16 functions */
394 #define UTF16_HIGH_HEAD(x) ((((zend_uchar) (x)) & 0xFC) == 0xD8)
395 #define UTF16_LOW_HEAD(x) ((((zend_uchar) (x)) & 0xFC) == 0xDC)
396
check_mb_utf16(const char * start,const char * end)397 static unsigned int check_mb_utf16(const char *start, const char *end)
398 {
399 if (start + 2 > end) {
400 return 0;
401 }
402
403 if (UTF16_HIGH_HEAD(*start)) {
404 return (start + 4 <= end) && UTF16_LOW_HEAD(start[2]) ? 4 : 0;
405 }
406
407 if (UTF16_LOW_HEAD(*start)) {
408 return 0;
409 }
410 return 2;
411 }
412
413
mysqlnd_mbcharlen_utf16(unsigned int utf16)414 static uint mysqlnd_mbcharlen_utf16(unsigned int utf16)
415 {
416 return UTF16_HIGH_HEAD(utf16) ? 4 : 2;
417 }
418 /* }}} */
419
420
421 /* {{{ utf32 functions */
check_mb_utf32(const char * start __attribute ((unused)),const char * end __attribute ((unused)))422 static unsigned int check_mb_utf32(const char *start __attribute((unused)), const char *end __attribute((unused)))
423 {
424 return 4;
425 }
426
427
mysqlnd_mbcharlen_utf32(unsigned int utf32 __attribute ((unused)))428 static unsigned int mysqlnd_mbcharlen_utf32(unsigned int utf32 __attribute((unused)))
429 {
430 return 4;
431 }
432 /* }}} */
433
434
435 /* {{{ gb18030 functions */
436 #define is_gb18030_odd(c) (0x81 <= (zend_uchar) (c) && (zend_uchar) (c) <= 0xFE)
437 #define is_gb18030_even_2(c) ((0x40 <= (zend_uchar) (c) && (zend_uchar) (c) <= 0x7E) || (0x80 <= (zend_uchar) (c) && (zend_uchar) (c) <= 0xFE))
438 #define is_gb18030_even_4(c) (0x30 <= (zend_uchar) (c) && (zend_uchar) (c) <= 0x39)
439
440
mysqlnd_mbcharlen_gb18030(unsigned int c)441 static unsigned int mysqlnd_mbcharlen_gb18030(unsigned int c)
442 {
443 if (c <= 0xFF) {
444 return !is_gb18030_odd(c);
445 }
446 if (c > 0xFFFF || !is_gb18030_odd((c >> 8) & 0xFF)) {
447 return 0;
448 }
449 if (is_gb18030_even_2((c & 0xFF))) {
450 return 2;
451 }
452 if (is_gb18030_even_4((c & 0xFF))) {
453 return 4;
454 }
455
456 return 0;
457 }
458
459
my_ismbchar_gb18030(const char * start,const char * end)460 static unsigned int my_ismbchar_gb18030(const char * start, const char * end)
461 {
462 if (end - start <= 1 || !is_gb18030_odd(start[0])) {
463 return 0;
464 }
465
466 if (is_gb18030_even_2(start[1])) {
467 return 2;
468 } else if (end - start > 3 && is_gb18030_even_4(start[1]) && is_gb18030_odd(start[2]) && is_gb18030_even_4(start[3])) {
469 return 4;
470 }
471
472 return 0;
473 }
474 /* }}} */
475
476 /*
477 The server compiles sometimes the full utf-8 (the mb4) as utf8m4, and the old as utf8,
478 for BC reasons. Sometimes, utf8mb4 is just utf8 but the old charsets are utf8mb3.
479 Change easily now, with a macro, could be made compilastion dependable.
480 */
481
482 #define UTF8_MB4 "utf8mb4"
483 #define UTF8_MB3 "utf8"
484
485 /* {{{ mysqlnd_charsets */
486 const MYSQLND_CHARSET mysqlnd_charsets[] =
487 {
488 { 1, "big5","big5_chinese_ci", 1, 2, "", mysqlnd_mbcharlen_big5, check_mb_big5},
489 { 3, "dec8", "dec8_swedish_ci", 1, 1, "", NULL, NULL},
490 { 4, "cp850", "cp850_general_ci", 1, 1, "", NULL, NULL},
491 { 6, "hp8", "hp8_english_ci", 1, 1, "", NULL, NULL},
492 { 7, "koi8r", "koi8r_general_ci", 1, 1, "", NULL, NULL},
493 { 8, "latin1", "latin1_swedish_ci", 1, 1, "", NULL, NULL},
494 { 5, "latin1", "latin1_german1_ci", 1, 1, "", NULL, NULL}, /* should be after 0x8 because swedish_ci is the default collation */
495 { 9, "latin2", "latin2_general_ci", 1, 1, "", NULL, NULL},
496 { 2, "latin2", "latin2_czech_cs", 1, 1, "", NULL, NULL}, /* should be after 0x9 because general_ci is the default collation */
497 { 10, "swe7", "swe7_swedish_ci", 1, 1, "", NULL, NULL},
498 { 11, "ascii", "ascii_general_ci", 1, 1, "", NULL, NULL},
499 { 12, "ujis", "ujis_japanese_ci", 1, 3, "", mysqlnd_mbcharlen_ujis, check_mb_ujis},
500 { 13, "sjis", "sjis_japanese_ci", 1, 2, "", mysqlnd_mbcharlen_sjis, check_mb_sjis},
501 { 16, "hebrew", "hebrew_general_ci", 1, 1, "", NULL, NULL},
502 { 17, "filename", "filename", 1, 5, "", NULL, NULL},
503 { 18, "tis620", "tis620_thai_ci", 1, 1, "", NULL, NULL},
504 { 19, "euckr", "euckr_korean_ci", 1, 2, "", mysqlnd_mbcharlen_euckr, check_mb_euckr},
505 { 21, "latin2", "latin2_hungarian_ci", 1, 1, "", NULL, NULL},
506 { 27, "latin2", "latin2_croatian_ci", 1, 1, "", NULL, NULL},
507 { 22, "koi8u", "koi8u_general_ci", 1, 1, "", NULL, NULL},
508 { 24, "gb2312", "gb2312_chinese_ci", 1, 2, "", mysqlnd_mbcharlen_gb2312, check_mb_gb2312},
509 { 25, "greek", "greek_general_ci", 1, 1, "", NULL, NULL},
510 { 26, "cp1250", "cp1250_general_ci", 1, 1, "", NULL, NULL},
511 { 28, "gbk", "gbk_chinese_ci", 1, 2, "", mysqlnd_mbcharlen_gbk, check_mb_gbk},
512 { 30, "latin5", "latin5_turkish_ci", 1, 1, "", NULL, NULL},
513 { 31, "latin1", "latin1_german2_ci", 1, 1, "", NULL, NULL},
514 { 15, "latin1", "latin1_danish_ci", 1, 1, "", NULL, NULL},
515 { 32, "armscii8", "armscii8_general_ci", 1, 1, "", NULL, NULL},
516 { 33, UTF8_MB3, UTF8_MB3"_general_ci", 1, 3, "UTF-8 Unicode", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
517 { 35, "ucs2", "ucs2_general_ci", 2, 2, "UCS-2 Unicode", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
518 { 36, "cp866", "cp866_general_ci", 1, 1, "", NULL, NULL},
519 { 37, "keybcs2", "keybcs2_general_ci", 1, 1, "", NULL, NULL},
520 { 38, "macce", "macce_general_ci", 1, 1, "", NULL, NULL},
521 { 39, "macroman", "macroman_general_ci", 1, 1, "", NULL, NULL},
522 { 40, "cp852", "cp852_general_ci", 1, 1, "", NULL, NULL},
523 { 41, "latin7", "latin7_general_ci", 1, 1, "", NULL, NULL},
524 { 20, "latin7", "latin7_estonian_cs", 1, 1, "", NULL, NULL},
525 { 57, "cp1256", "cp1256_general_ci", 1, 1, "", NULL, NULL},
526 { 59, "cp1257", "cp1257_general_ci", 1, 1, "", NULL, NULL},
527 { 63, "binary", "binary", 1, 1, "", NULL, NULL},
528 { 97, "eucjpms", "eucjpms_japanese_ci", 1, 3, "", mysqlnd_mbcharlen_eucjpms, check_mb_eucjpms},
529 { 29, "cp1257", "cp1257_lithuanian_ci", 1, 1, "", NULL, NULL},
530 { 31, "latin1", "latin1_german2_ci", 1, 1, "", NULL, NULL},
531 { 34, "cp1250", "cp1250_czech_cs", 1, 1, "", NULL, NULL},
532 { 42, "latin7", "latin7_general_cs", 1, 1, "", NULL, NULL},
533 { 43, "macce", "macce_bin", 1, 1, "", NULL, NULL},
534 { 44, "cp1250", "cp1250_croatian_ci", 1, 1, "", NULL, NULL},
535 { 45, UTF8_MB4, UTF8_MB4"_general_ci", 1, 4, "UTF-8 Unicode", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
536 { 46, UTF8_MB4, UTF8_MB4"_bin", 1, 4, "UTF-8 Unicode", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
537 { 47, "latin1", "latin1_bin", 1, 1, "", NULL, NULL},
538 { 48, "latin1", "latin1_general_ci", 1, 1, "", NULL, NULL},
539 { 49, "latin1", "latin1_general_cs", 1, 1, "", NULL, NULL},
540 { 51, "cp1251", "cp1251_general_ci", 1, 1, "", NULL, NULL},
541 { 14, "cp1251", "cp1251_bulgarian_ci", 1, 1, "", NULL, NULL},
542 { 23, "cp1251", "cp1251_ukrainian_ci", 1, 1, "", NULL, NULL},
543 { 50, "cp1251", "cp1251_bin", 1, 1, "", NULL, NULL},
544 { 52, "cp1251", "cp1251_general_cs", 1, 1, "", NULL, NULL},
545 { 53, "macroman", "macroman_bin", 1, 1, "", NULL, NULL},
546 { 54, "utf16", "utf16_general_ci", 2, 4, "UTF-16 Unicode", mysqlnd_mbcharlen_utf16, check_mb_utf16},
547 { 55, "utf16", "utf16_bin", 2, 4, "UTF-16 Unicode", mysqlnd_mbcharlen_utf16, check_mb_utf16},
548 { 56, "utf16le", "utf16le_general_ci", 2, 4, "UTF-16LE Unicode", mysqlnd_mbcharlen_utf16, check_mb_utf16},
549 { 58, "cp1257", "cp1257_bin", 1, 1, "", NULL, NULL},
550 /*55*/{ 60, "utf32", "utf32_general_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
551 /*55*/{ 61, "utf32", "utf32_bin", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
552 { 62, "utf16le", "utf16le_bin", 2, 4, "UTF-16LE Unicode", mysqlnd_mbcharlen_utf16, check_mb_utf16},
553 { 64, "armscii8", "armscii8_bin", 1, 1, "", NULL, NULL},
554 { 65, "ascii", "ascii_bin", 1, 1, "", NULL, NULL},
555 { 66, "cp1250", "cp1250_bin", 1, 1, "", NULL, NULL},
556 { 67, "cp1256", "cp1256_bin", 1, 1, "", NULL, NULL},
557 { 68, "cp866", "cp866_bin", 1, 1, "", NULL, NULL},
558 { 69, "dec8", "dec8_bin", 1, 1, "", NULL, NULL},
559 { 70, "greek", "greek_bin", 1, 1, "", NULL, NULL},
560 { 71, "hebrew", "hebrew_bin", 1, 1, "", NULL, NULL},
561 { 72, "hp8", "hp8_bin", 1, 1, "", NULL, NULL},
562 { 73, "keybcs2", "keybcs2_bin", 1, 1, "", NULL, NULL},
563 { 74, "koi8r", "koi8r_bin", 1, 1, "", NULL, NULL},
564 { 75, "koi8u", "koi8u_bin", 1, 1, "", NULL, NULL},
565 { 77, "latin2", "latin2_bin", 1, 1, "", NULL, NULL},
566 { 78, "latin5", "latin5_bin", 1, 1, "", NULL, NULL},
567 { 79, "latin7", "latin7_bin", 1, 1, "", NULL, NULL},
568 { 80, "cp850", "cp850_bin", 1, 1, "", NULL, NULL},
569 { 81, "cp852", "cp852_bin", 1, 1, "", NULL, NULL},
570 { 82, "swe7", "swe7_bin", 1, 1, "", NULL, NULL},
571 { 83, UTF8_MB3, UTF8_MB3"_bin", 1, 3, "UTF-8 Unicode", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
572 { 84, "big5", "big5_bin", 1, 2, "", mysqlnd_mbcharlen_big5, check_mb_big5},
573 { 85, "euckr", "euckr_bin", 1, 2, "", mysqlnd_mbcharlen_euckr, check_mb_euckr},
574 { 86, "gb2312", "gb2312_bin", 1, 2, "", mysqlnd_mbcharlen_gb2312, check_mb_gb2312},
575 { 87, "gbk", "gbk_bin", 1, 2, "", mysqlnd_mbcharlen_gbk, check_mb_gbk},
576 { 88, "sjis", "sjis_bin", 1, 2, "", mysqlnd_mbcharlen_sjis, check_mb_sjis},
577 { 89, "tis620", "tis620_bin", 1, 1, "", NULL, NULL},
578 { 90, "ucs2", "ucs2_bin", 2, 2, "UCS-2 Unicode", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
579 { 91, "ujis", "ujis_bin", 1, 3, "", mysqlnd_mbcharlen_ujis, check_mb_ujis},
580 { 92, "geostd8", "geostd8_general_ci", 1, 1, "", NULL, NULL},
581 { 93, "geostd8", "geostd8_bin", 1, 1, "", NULL, NULL},
582 { 94, "latin1", "latin1_spanish_ci", 1, 1, "", NULL, NULL},
583 { 95, "cp932", "cp932_japanese_ci", 1, 2, "", mysqlnd_mbcharlen_cp932, check_mb_cp932},
584 { 96, "cp932", "cp932_bin", 1, 2, "", mysqlnd_mbcharlen_cp932, check_mb_cp932},
585 { 97, "eucjpms", "eucjpms_japanese_ci", 1, 3, "", mysqlnd_mbcharlen_eucjpms, check_mb_eucjpms},
586 { 98, "eucjpms", "eucjpms_bin", 1, 3, "", mysqlnd_mbcharlen_eucjpms, check_mb_eucjpms},
587 { 99, "cp1250", "cp1250_polish_ci", 1, 1, "", NULL, NULL},
588 { 128, "ucs2", "ucs2_unicode_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
589 { 129, "ucs2", "ucs2_icelandic_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
590 { 130, "ucs2", "ucs2_latvian_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
591 { 131, "ucs2", "ucs2_romanian_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
592 { 132, "ucs2", "ucs2_slovenian_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
593 { 133, "ucs2", "ucs2_polish_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
594 { 134, "ucs2", "ucs2_estonian_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
595 { 135, "ucs2", "ucs2_spanish_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
596 { 136, "ucs2", "ucs2_swedish_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
597 { 137, "ucs2", "ucs2_turkish_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
598 { 138, "ucs2", "ucs2_czech_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
599 { 139, "ucs2", "ucs2_danish_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
600 { 140, "ucs2", "ucs2_lithuanian_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
601 { 141, "ucs2", "ucs2_slovak_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
602 { 142, "ucs2", "ucs2_spanish2_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
603 { 143, "ucs2", "ucs2_roman_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
604 { 144, "ucs2", "ucs2_persian_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
605 { 145, "ucs2", "ucs2_esperanto_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
606 { 146, "ucs2", "ucs2_hungarian_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
607 { 147, "ucs2", "ucs2_sinhala_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
608 { 148, "ucs2", "ucs2_german2_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
609 { 149, "ucs2", "ucs2_croatian_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
610 { 150, "ucs2", "ucs2_unicode_520_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
611 { 151, "ucs2", "ucs2_vietnamese_ci", 2, 2, "", mysqlnd_mbcharlen_ucs2, check_mb_ucs2},
612
613 /*56*/{160, "utf32", "utf32_unicode_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
614 /*56*/{161, "utf32", "utf32_icelandic_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
615 /*56*/{162, "utf32", "utf32_latvian_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
616 /*56*/{163, "utf32", "utf32_romanian_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
617 /*56*/{164, "utf32", "utf32_slovenian_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
618 /*56*/{165, "utf32", "utf32_polish_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
619 /*56*/{166, "utf32", "utf32_estonian_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
620 /*56*/{167, "utf32", "utf32_spanish_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
621 /*56*/{168, "utf32", "utf32_swedish_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
622 /*56*/{169, "utf32", "utf32_turkish_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
623 /*56*/{170, "utf32", "utf32_czech_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
624 /*56*/{171, "utf32", "utf32_danish_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
625 /*56*/{172, "utf32", "utf32_lithuanian_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
626 /*56*/{173, "utf32", "utf32_slovak_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
627 /*56*/{174, "utf32", "utf32_spanish2_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
628 /*56*/{175, "utf32", "utf32_roman_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
629 /*56*/{176, "utf32", "utf32_persian_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
630 /*56*/{177, "utf32", "utf32_esperanto_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
631 /*56*/{178, "utf32", "utf32_hungarian_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
632 /*56*/{179, "utf32", "utf32_sinhala_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
633 /*56*/{180, "utf32", "utf32_german2_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
634 /*56*/{181, "utf32", "utf32_croatian_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
635 /*56*/{182, "utf32", "utf32_unicode_520_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
636 /*56*/{183, "utf32", "utf32_vietnamese_ci", 4, 4, "UTF-32 Unicode", mysqlnd_mbcharlen_utf32, check_mb_utf32},
637
638 { 192, UTF8_MB3, UTF8_MB3"_unicode_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
639 { 193, UTF8_MB3, UTF8_MB3"_icelandic_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
640 { 194, UTF8_MB3, UTF8_MB3"_latvian_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
641 { 195, UTF8_MB3, UTF8_MB3"_romanian_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
642 { 196, UTF8_MB3, UTF8_MB3"_slovenian_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
643 { 197, UTF8_MB3, UTF8_MB3"_polish_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
644 { 198, UTF8_MB3, UTF8_MB3"_estonian_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
645 { 199, UTF8_MB3, UTF8_MB3"_spanish_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
646 { 200, UTF8_MB3, UTF8_MB3"_swedish_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
647 { 201, UTF8_MB3, UTF8_MB3"_turkish_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
648 { 202, UTF8_MB3, UTF8_MB3"_czech_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
649 { 203, UTF8_MB3, UTF8_MB3"_danish_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid },
650 { 204, UTF8_MB3, UTF8_MB3"_lithuanian_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid },
651 { 205, UTF8_MB3, UTF8_MB3"_slovak_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
652 { 206, UTF8_MB3, UTF8_MB3"_spanish2_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
653 { 207, UTF8_MB3, UTF8_MB3"_roman_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
654 { 208, UTF8_MB3, UTF8_MB3"_persian_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
655 { 209, UTF8_MB3, UTF8_MB3"_esperanto_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
656 { 210, UTF8_MB3, UTF8_MB3"_hungarian_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
657 { 211, UTF8_MB3, UTF8_MB3"_sinhala_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
658 { 212, UTF8_MB3, UTF8_MB3"_german2_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
659 { 213, UTF8_MB3, UTF8_MB3"_croatian_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
660 { 214, UTF8_MB3, UTF8_MB3"_unicode_520_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
661 { 215, UTF8_MB3, UTF8_MB3"_vietnamese_ci", 1, 3, "", mysqlnd_mbcharlen_utf8mb3, check_mb_utf8mb3_valid},
662
663 { 224, UTF8_MB4, UTF8_MB4"_unicode_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
664 { 225, UTF8_MB4, UTF8_MB4"_icelandic_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
665 { 226, UTF8_MB4, UTF8_MB4"_latvian_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
666 { 227, UTF8_MB4, UTF8_MB4"_romanian_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
667 { 228, UTF8_MB4, UTF8_MB4"_slovenian_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
668 { 229, UTF8_MB4, UTF8_MB4"_polish_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
669 { 230, UTF8_MB4, UTF8_MB4"_estonian_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
670 { 231, UTF8_MB4, UTF8_MB4"_spanish_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
671 { 232, UTF8_MB4, UTF8_MB4"_swedish_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
672 { 233, UTF8_MB4, UTF8_MB4"_turkish_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
673 { 234, UTF8_MB4, UTF8_MB4"_czech_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
674 { 235, UTF8_MB4, UTF8_MB4"_danish_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
675 { 236, UTF8_MB4, UTF8_MB4"_lithuanian_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
676 { 237, UTF8_MB4, UTF8_MB4"_slovak_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
677 { 238, UTF8_MB4, UTF8_MB4"_spanish2_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
678 { 239, UTF8_MB4, UTF8_MB4"_roman_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
679 { 240, UTF8_MB4, UTF8_MB4"_persian_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
680 { 241, UTF8_MB4, UTF8_MB4"_esperanto_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
681 { 242, UTF8_MB4, UTF8_MB4"_hungarian_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
682 { 243, UTF8_MB4, UTF8_MB4"_sinhala_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
683 { 244, UTF8_MB4, UTF8_MB4"_german2_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
684 { 245, UTF8_MB4, UTF8_MB4"_croatian_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
685 { 246, UTF8_MB4, UTF8_MB4"_unicode_520_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
686 { 247, UTF8_MB4, UTF8_MB4"_vietnamese_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
687 { 248, "gb18030", "gb18030_chinese_ci", 1, 4, "", mysqlnd_mbcharlen_gb18030, my_ismbchar_gb18030},
688 { 249, "gb18030", "gb18030_bin", 1, 4, "", mysqlnd_mbcharlen_gb18030, my_ismbchar_gb18030},
689
690 { 254, UTF8_MB3, UTF8_MB3"_general_cs", 1, 3, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
691 { 255, UTF8_MB4, UTF8_MB4"_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
692 { 256, UTF8_MB4, UTF8_MB4"_de_pb_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
693 { 257, UTF8_MB4, UTF8_MB4"_is_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
694 { 258, UTF8_MB4, UTF8_MB4"_lv_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
695 { 259, UTF8_MB4, UTF8_MB4"_ro_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
696 { 260, UTF8_MB4, UTF8_MB4"_sl_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
697 { 261, UTF8_MB4, UTF8_MB4"_pl_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
698 { 262, UTF8_MB4, UTF8_MB4"_et_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
699 { 263, UTF8_MB4, UTF8_MB4"_es_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
700 { 264, UTF8_MB4, UTF8_MB4"_sv_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
701 { 265, UTF8_MB4, UTF8_MB4"_tr_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
702 { 266, UTF8_MB4, UTF8_MB4"_cs_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
703 { 267, UTF8_MB4, UTF8_MB4"_da_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
704 { 268, UTF8_MB4, UTF8_MB4"_lt_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
705 { 269, UTF8_MB4, UTF8_MB4"_sk_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
706 { 270, UTF8_MB4, UTF8_MB4"_es_trad_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
707 { 271, UTF8_MB4, UTF8_MB4"_la_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
708 { 272, UTF8_MB4, UTF8_MB4"_fa_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
709 { 273, UTF8_MB4, UTF8_MB4"_eo_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
710 { 274, UTF8_MB4, UTF8_MB4"_hu_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
711 { 275, UTF8_MB4, UTF8_MB4"_hr_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
712 { 276, UTF8_MB4, UTF8_MB4"_si_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
713 { 277, UTF8_MB4, UTF8_MB4"_vi_0900_ai_ci", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
714 { 278, UTF8_MB4, UTF8_MB4"_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
715 { 279, UTF8_MB4, UTF8_MB4"_de_pb_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
716 { 280, UTF8_MB4, UTF8_MB4"_is_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
717 { 281, UTF8_MB4, UTF8_MB4"_lv_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
718 { 282, UTF8_MB4, UTF8_MB4"_ro_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
719 { 283, UTF8_MB4, UTF8_MB4"_sl_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
720 { 284, UTF8_MB4, UTF8_MB4"_pl_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
721 { 285, UTF8_MB4, UTF8_MB4"_et_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
722 { 286, UTF8_MB4, UTF8_MB4"_es_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
723 { 287, UTF8_MB4, UTF8_MB4"_sv_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
724 { 288, UTF8_MB4, UTF8_MB4"_tr_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
725 { 289, UTF8_MB4, UTF8_MB4"_cs_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
726 { 290, UTF8_MB4, UTF8_MB4"_da_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
727 { 291, UTF8_MB4, UTF8_MB4"_lt_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
728 { 292, UTF8_MB4, UTF8_MB4"_sk_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
729 { 293, UTF8_MB4, UTF8_MB4"_es_trad_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
730 { 294, UTF8_MB4, UTF8_MB4"_la_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
731 { 295, UTF8_MB4, UTF8_MB4"_fa_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
732 { 296, UTF8_MB4, UTF8_MB4"_eo_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
733 { 297, UTF8_MB4, UTF8_MB4"_hu_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
734 { 298, UTF8_MB4, UTF8_MB4"_hr_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
735 { 299, UTF8_MB4, UTF8_MB4"_si_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
736 { 300, UTF8_MB4, UTF8_MB4"_vi_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
737 { 303, UTF8_MB4, UTF8_MB4"_ja_0900_as_cs", 1, 4, "", mysqlnd_mbcharlen_utf8, check_mb_utf8_valid},
738 { 0, NULL, NULL, 0, 0, NULL, NULL, NULL}
739 };
740 /* }}} */
741
742
743 /* {{{ mysqlnd_find_charset_nr */
mysqlnd_find_charset_nr(unsigned int charsetnr)744 PHPAPI const MYSQLND_CHARSET * mysqlnd_find_charset_nr(unsigned int charsetnr)
745 {
746 const MYSQLND_CHARSET * c = mysqlnd_charsets;
747
748 do {
749 if (c->nr == charsetnr) {
750 return c;
751 }
752 ++c;
753 } while (c[0].nr != 0);
754 return NULL;
755 }
756 /* }}} */
757
758
759 /* {{{ mysqlnd_find_charset_name */
mysqlnd_find_charset_name(const char * const name)760 PHPAPI const MYSQLND_CHARSET * mysqlnd_find_charset_name(const char * const name)
761 {
762 if (name) {
763 const MYSQLND_CHARSET * c = mysqlnd_charsets;
764 do {
765 if (!strcasecmp(c->name, name)) {
766 return c;
767 }
768 ++c;
769 } while (c[0].nr != 0);
770 }
771 return NULL;
772 }
773 /* }}} */
774
775
776 /* {{{ mysqlnd_cset_escape_quotes */
mysqlnd_cset_escape_quotes(const MYSQLND_CHARSET * const cset,char * newstr,const char * escapestr,size_t escapestr_len)777 PHPAPI zend_ulong mysqlnd_cset_escape_quotes(const MYSQLND_CHARSET * const cset, char *newstr,
778 const char * escapestr, size_t escapestr_len)
779 {
780 const char *newstr_s = newstr;
781 const char *newstr_e = newstr + 2 * escapestr_len;
782 const char *end = escapestr + escapestr_len;
783 zend_bool escape_overflow = FALSE;
784
785 DBG_ENTER("mysqlnd_cset_escape_quotes");
786
787 for (;escapestr < end; escapestr++) {
788 unsigned int len = 0;
789 /* check unicode characters */
790
791 if (cset->char_maxlen > 1 && (len = cset->mb_valid(escapestr, end))) {
792
793 /* check possible overflow */
794 if ((newstr + len) > newstr_e) {
795 escape_overflow = TRUE;
796 break;
797 }
798 /* copy mb char without escaping it */
799 while (len--) {
800 *newstr++ = *escapestr++;
801 }
802 escapestr--;
803 continue;
804 }
805 if (*escapestr == '\'') {
806 if (newstr + 2 > newstr_e) {
807 escape_overflow = TRUE;
808 break;
809 }
810 *newstr++ = '\'';
811 *newstr++ = '\'';
812 } else {
813 if (newstr + 1 > newstr_e) {
814 escape_overflow = TRUE;
815 break;
816 }
817 *newstr++ = *escapestr;
818 }
819 }
820 *newstr = '\0';
821
822 if (escape_overflow) {
823 DBG_RETURN((ulong)~0);
824 }
825 DBG_RETURN((ulong)(newstr - newstr_s));
826 }
827 /* }}} */
828
829
830 /* {{{ mysqlnd_cset_escape_slashes */
mysqlnd_cset_escape_slashes(const MYSQLND_CHARSET * const cset,char * newstr,const char * escapestr,size_t escapestr_len)831 PHPAPI zend_ulong mysqlnd_cset_escape_slashes(const MYSQLND_CHARSET * const cset, char *newstr,
832 const char * escapestr, size_t escapestr_len)
833 {
834 const char *newstr_s = newstr;
835 const char *newstr_e = newstr + 2 * escapestr_len;
836 const char *end = escapestr + escapestr_len;
837 zend_bool escape_overflow = FALSE;
838
839 DBG_ENTER("mysqlnd_cset_escape_slashes");
840 DBG_INF_FMT("charset=%s", cset->name);
841
842 for (;escapestr < end; escapestr++) {
843 char esc = '\0';
844 unsigned int len = 0;
845
846 /* check unicode characters */
847 if (cset->char_maxlen > 1 && (len = cset->mb_valid(escapestr, end))) {
848 /* check possible overflow */
849 if ((newstr + len) > newstr_e) {
850 escape_overflow = TRUE;
851 break;
852 }
853 /* copy mb char without escaping it */
854 while (len--) {
855 *newstr++ = *escapestr++;
856 }
857 escapestr--;
858 continue;
859 }
860 if (cset->char_maxlen > 1 && cset->mb_charlen(*escapestr) > 1) {
861 esc = *escapestr;
862 } else {
863 switch (*escapestr) {
864 case 0:
865 esc = '0';
866 break;
867 case '\n':
868 esc = 'n';
869 break;
870 case '\r':
871 esc = 'r';
872 break;
873 case '\\':
874 case '\'':
875 case '"':
876 esc = *escapestr;
877 break;
878 case '\032':
879 esc = 'Z';
880 break;
881 }
882 }
883 if (esc) {
884 if (newstr + 2 > newstr_e) {
885 escape_overflow = TRUE;
886 break;
887 }
888 /* copy escaped character */
889 *newstr++ = '\\';
890 *newstr++ = esc;
891 } else {
892 if (newstr + 1 > newstr_e) {
893 escape_overflow = TRUE;
894 break;
895 }
896 /* copy non escaped character */
897 *newstr++ = *escapestr;
898 }
899 }
900 *newstr = '\0';
901
902 if (escape_overflow) {
903 DBG_RETURN((ulong)~0);
904 }
905 DBG_RETURN((ulong)(newstr - newstr_s));
906 }
907 /* }}} */
908
909
910 static struct st_mysqlnd_plugin_charsets mysqlnd_plugin_charsets_plugin =
911 {
912 {
913 MYSQLND_PLUGIN_API_VERSION,
914 "charsets",
915 MYSQLND_VERSION_ID,
916 PHP_MYSQLND_VERSION,
917 "PHP License 3.01",
918 "Andrey Hristov <andrey@php.net>, Ulf Wendel <uw@php.net>, Georg Richter <georg@php.net>",
919 {
920 NULL, /* no statistics , will be filled later if there are some */
921 NULL, /* no statistics */
922 },
923 {
924 NULL /* plugin shutdown */
925 }
926 },
927 {/* methods */
928 mysqlnd_find_charset_nr,
929 mysqlnd_find_charset_name,
930 mysqlnd_cset_escape_quotes,
931 mysqlnd_cset_escape_slashes
932 }
933 };
934
935
936 /* {{{ mysqlnd_charsets_plugin_register */
937 void
mysqlnd_charsets_plugin_register(void)938 mysqlnd_charsets_plugin_register(void)
939 {
940 mysqlnd_plugin_register_ex((struct st_mysqlnd_plugin_header *) &mysqlnd_plugin_charsets_plugin);
941 }
942 /* }}} */
943
944
945 /*
946 * Local variables:
947 * tab-width: 4
948 * c-basic-offset: 4
949 * End:
950 * vim600: noet sw=4 ts=4 fdm=marker
951 * vim<600: noet sw=4 ts=4
952 */
953