PageRenderTime 57ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/ext/mysqlnd/mysqlnd_charset.c

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