PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/mysqlnd - mysqlnd_charset.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 123 271 45.4 %
Date: 2014-07-21 Functions: 23 35 65.7 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Tue, 22 Jul 2014 01:33:13 +0000 (2 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.