mysqlnd_charset.c 33 KB

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