From dd3d0d6f5244d50251b9e9e1bebfc591f795fecb Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Wed, 14 Nov 2012 18:43:45 +0100 Subject: [PATCH] First implementation based on libmysql 3.23.58 and php's mysqlnd extension --- .bzrignore | 13 + CMakeLists.txt | 117 +- COPYING.LIB | 203 +- LibmysqlTypes.txt | 24 + README | 4 +- examples/CMakeLists.txt | 18 + examples/mysql_affected_rows.c | 82 + examples/mysql_debug.c | 40 + examples/test_output.c | 72 + include/config-win.h | 83 +- include/errmsg.h | 6 +- include/global.h | 46 +- include/m_ctype.h | 11 +- include/m_string.h | 49 +- include/my_config.h | 275 -- include/my_config.h.in | 2 + include/my_global.h | 92 +- include/my_list.h | 2 +- include/my_net.h | 4 +- include/my_pthread.h | 33 +- include/{mysql_stmt.h => my_stmt.h} | 65 +- include/my_sys.h | 48 +- include/mysql.h | 121 +- include/mysql/client_plugin.h | 175 + include/mysql/plugin_auth.h | 107 + include/mysql/plugin_auth_common.h | 107 + include/mysql_com.h | 68 +- include/mysql_version.h | 23 - include/mysql_version.h.in | 1 + include/mysqld_error.h | 19 +- include/sha1.h | 2 +- include/thr_alarm.h | 4 +- include/violite.h | 25 +- libmysql/CMakeLists.txt | 103 +- libmysql/array.c | 2 +- libmysql/bchange.c | 4 +- libmysql/bmove_upp.c | 4 +- libmysql/charset.c | 16 +- libmysql/client_plugin.c | 459 +++ libmysql/cmake_install.cmake | 34 - libmysql/conf_to_src.c | 143 - libmysql/ctype.c | 68 - libmysql/dbug.c | 14 +- libmysql/default.c | 14 +- libmysql/errmsg.c | 11 +- libmysql/get_password.c | 10 +- libmysql/getopt.c | 4 - libmysql/getopt1.c | 4 +- libmysql/getvar.c | 112 - libmysql/hash.c | 640 ---- libmysql/int2str.c | 16 +- libmysql/libmysql.c | 1122 +++--- libmysql/libmysql_exports.def | 107 + libmysql/mf_cache.c | 123 - libmysql/mf_casecnv.c | 267 -- libmysql/mf_iocache.c | 614 --- libmysql/mf_pack.c | 2 +- libmysql/mf_path.c | 4 +- libmysql/my_alloc.c | 10 +- libmysql/my_auth.c | 737 ++++ libmysql/my_charset.c | 828 +++++ libmysql/my_create.c | 4 +- libmysql/my_gethostbyname.c | 2 +- libmysql/my_getwd.c | 2 +- libmysql/my_init.c | 16 +- libmysql/my_lib.c | 6 +- libmysql/my_loaddata.c | 255 ++ libmysql/my_malloc.c | 4 +- libmysql/my_net.c | 4 +- libmysql/my_once.c | 2 +- libmysql/my_open.c | 4 +- libmysql/my_pread.c | 146 - libmysql/my_pthread.c | 45 +- libmysql/my_realloc.c | 2 +- libmysql/my_static.c | 4 +- libmysql/{mysql_stmt.c => my_stmt.c} | 594 +-- .../{mysql_stmt_codec.c => my_stmt_codec.c} | 120 +- libmysql/my_thr_init.c | 16 +- libmysql/my_vsnprintf.c | 119 + libmysql/mysql_charset.c | 3304 ----------------- libmysql/net.c | 139 +- libmysql/password.c | 124 +- libmysql/safemalloc.c | 28 +- libmysql/sha1.c | 2 +- libmysql/spprintf.c | 810 ---- libmysql/strcend.c | 36 +- libmysql/strfill.c | 2 +- libmysql/string.c | 6 +- libmysql/strmake.c | 4 +- libmysql/strto.c | 210 ++ libmysql/strtoll.c | 176 +- libmysql/strxnmov.c | 48 + libmysql/thr_mutex.c | 6 +- libmysql/typelib.c | 2 +- libmysql/violite.c | 83 +- mysql_config/CMakeLists.txt | 30 + mysql_config/mysql_config.c.in | 101 + zlib/CMakeLists.txt | 4 +- zlib/gzguts.h | 3 + 99 files changed, 5669 insertions(+), 8207 deletions(-) create mode 100644 .bzrignore create mode 100644 examples/CMakeLists.txt create mode 100644 examples/mysql_affected_rows.c create mode 100644 examples/mysql_debug.c create mode 100644 examples/test_output.c delete mode 100644 include/my_config.h rename include/{mysql_stmt.h => my_stmt.h} (85%) create mode 100644 include/mysql/client_plugin.h create mode 100644 include/mysql/plugin_auth.h create mode 100644 include/mysql/plugin_auth_common.h delete mode 100644 include/mysql_version.h mode change 100755 => 100644 libmysql/CMakeLists.txt create mode 100644 libmysql/client_plugin.c delete mode 100644 libmysql/cmake_install.cmake delete mode 100644 libmysql/conf_to_src.c delete mode 100644 libmysql/ctype.c delete mode 100644 libmysql/getvar.c delete mode 100644 libmysql/hash.c create mode 100644 libmysql/libmysql_exports.def delete mode 100644 libmysql/mf_cache.c delete mode 100644 libmysql/mf_casecnv.c delete mode 100644 libmysql/mf_iocache.c create mode 100644 libmysql/my_auth.c create mode 100644 libmysql/my_charset.c create mode 100644 libmysql/my_loaddata.c delete mode 100644 libmysql/my_pread.c rename libmysql/{mysql_stmt.c => my_stmt.c} (64%) rename libmysql/{mysql_stmt_codec.c => my_stmt_codec.c} (89%) create mode 100644 libmysql/my_vsnprintf.c delete mode 100644 libmysql/mysql_charset.c delete mode 100644 libmysql/spprintf.c create mode 100644 libmysql/strto.c create mode 100644 libmysql/strxnmov.c create mode 100644 mysql_config/CMakeLists.txt create mode 100644 mysql_config/mysql_config.c.in diff --git a/.bzrignore b/.bzrignore new file mode 100644 index 000000000..390bcd3cf --- /dev/null +++ b/.bzrignore @@ -0,0 +1,13 @@ +CMakeCache.txt +CMakeFiles/* +*.cmake +Makefile +include/my_config.h +include/mysql_version.h +CMakeFiles +mysql_config/mysql_config.c +examples/mysql_affected_rows +examples/mysql_debug +examples/test_output +libmysql.so.* +mysql_config/mysql_config diff --git a/CMakeLists.txt b/CMakeLists.txt index af9bdf612..cd2c74269 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,29 +25,60 @@ ENDIF(CMAKE_COMPILER_IS_GNUCXX) # various defines for generating include/mysql_version.h SET(PROTOCOL_VERSION 10) # we adapted new password option from PHP's mysqlnd ! -SET(MYSQL_CLIENT_VERSION "3.23.59") -SET(MYSQL_VERSION_ID "32359") +SET(MYSQL_CLIENT_VERSION_MAJOR "5") +SET(MYSQL_CLIENT_VERSION_MINOR "3") +SET(MYSQL_CLIENT_VERSION_PATCH "1") +SET(MYSQL_CLIENT_VERSION "${MYSQL_CLIENT_VERSION_MAJOR}.${MYSQL_CLIENT_VERSION_MINOR}.${MYSQL_CLIENT_VERSION_PATCH}") +MATH(EXPR MYSQL_VERSION_ID "${MYSQL_CLIENT_VERSION_MAJOR} * 10000 + + ${MYSQL_CLIENT_VERSION_MINOR} * 100 + + ${MYSQL_CLIENT_VERSION_PATCH}") IF (NOT MYSQL_PORT) SET(MYSQL_PORT 3306) ENDIF (NOT MYSQL_PORT) +IF(NOT MYSQL_UNIX_ADDR) + SET(MYSQL_UNIX_ADDR "/tmp/mysql.sock") +ENDIF(NOT MYSQL_UNIX_ADDR) +# todo: we don't character sets in share - all is compiled in SET(SHAREDIR "share") SET(DEFAULT_CHARSET_HOME "${CMAKE_INSTALL_PREFIX}") -# check for various include files -INCLUDE(LibmysqlIncludeFiles.txt) -# check for various functions -INCLUDE(LibmysqlFunctions.txt) -# check for various types -INCLUDE(LibmysqlTypes.txt) +FIND_PACKAGE(Threads) +IF(${CMAKE_HAVE_PTHREAD_H}) + SET(CMAKE_REQUIRED_INCLUDES pthread.h) +ENDIF(${CMAKE_HAVE_PTHREAD_H}) #Check for threads IF(WIN32) SET(HAVE_THREADS 1) + ADD_DEFINITIONS(-DHAVE_DLOPEN) + ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996" ) ELSEIF(WIN32) SET(HAVE_THREADS ${CMAKE_USE_PTHREADS}) ENDIF(WIN32) +FIND_LIBRARY(DL_LIBRARY dl) +IF(DL_LIBRARY) + SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${CMAKE_DL_LIBS}) +ENDIF(DL_LIBRARY) + +# check for various include files +INCLUDE(LibmysqlIncludeFiles.txt) +# check for various functions +INCLUDE(LibmysqlFunctions.txt) +# check for various types +INCLUDE(LibmysqlTypes.txt) + + + +#Check for OpenSSL +#INCLUDE(FindOpenSSL) +#IF(OPENSSL_FOUND) +# ADD_DEFINITIONS(-DHAVE_OPENSSL) +# FIND_LIBRARY(SSL_LIBRARIES NAMES libeay32 crypto) +#ENDIF(OPENSSL_FOUND) + MESSAGE(STATUS "writing configuration files") CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/mysql_version.h.in @@ -57,9 +88,69 @@ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/my_config.h.in ADD_SUBDIRECTORY(zlib) ADD_SUBDIRECTORY(libmysql) +ADD_SUBDIRECTORY(examples) +IF(NOT WIN32) + ADD_SUBDIRECTORY(mysql_config) +ENDIF(NOT WIN32) + +IF(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/unittest) + MESSAGE(STATUS "found unittests") + ADD_SUBDIRECTORY(unittest/mytap) + ADD_SUBDIRECTORY(unittest/libmysql) +ENDIF(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/unittest) + +IF(WIN32) + SET(CMAKE_INSTALL_PREFIX "") +ENDIF(WIN32) + + +SET(CPACK_VERSION_MAJOR ${MYSQL_CLIENT_VERSION_MAJOR}) +SET(CPACK_VERSION_MINOR ${MYSQL_CLIENT_VERSION_MINOR}) +SET(CPACK_VERSION_PATCH ${MYSQL_CLIENT_VERSION_PATCH}) + +SET(CPACK_PACKAGE_VENDOR "Monty Program AB") +SET(CPACK_PACKAGE_DESCRIPTION "MariaDB client library. A library for connecting to MariaDB and MySQL servers") +SET(CPACK_PACKAGE_NAME "mariadb_client") +SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING.LIB") +SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README") +SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${MYSQL_CLIENT_VERSION}-src") + +SET(CPACK_SOURCE_IGNORE_FILES +.bzr/ +CMakeCache.txt +cmake_dist.cmake +CPackSourceConfig.cmake +CPackConfig.cmake +.build/ +html/ +unittest +/cmake_install.cmake +/CTestTestfile.cmake +/CMakeFiles/ +/version_resources/ +/_CPack_Packages/ +.*gz$ +.*zip$ +.*so$ +.*so.*$ +.*dll$ +.*a$ +.*pdb$ +/CMakeFiles/ +/version_resources/ +/_CPack_Packages/ +Makefile$ +include/my_config.h$ +/autom4te.cache/ +errmsg.sys$ +) + +IF(NOT WIN32) + SET(CPACK_GENERATOR "TGZ") + SET(CPACK_SOURCE_GENERATOR "TGZ") +ELSEIF(NOT WIN32) + SET(CPACK_GENERATOR "ZIP") + SET(CPACK_SOURCE_GENERATOR "ZIP") +ENDIF(NOT WIN32) -IF(IS_DIRECTORY unittest) -MESSAGE(STATUS "found unittests") -ADD_SUBDIRECTORY(unittest/mytap) -ADD_SUBDIRECTORY(unittest/libmysql) -ENDIF(IS_DIRECTORY unittest) +INCLUDE(CPack) diff --git a/COPYING.LIB b/COPYING.LIB index 5bc8fb2c8..4362b4915 100644 --- a/COPYING.LIB +++ b/COPYING.LIB @@ -1,13 +1,14 @@ - GNU LIBRARY GENERAL PUBLIC LICENSE - Version 2, June 1991 + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 - Copyright (C) 1991 Free Software Foundation, Inc. + Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. -[This is the first released version of the library GPL. It is - numbered 2 because it goes with version 2 of the ordinary GPL.] +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] Preamble @@ -16,97 +17,109 @@ freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. - This license, the Library General Public License, applies to some -specially designated Free Software Foundation software, and to any -other libraries whose authors decide to use it. You can use it for -your libraries, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if -you distribute copies of the library, or if you modify it. +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source -code. If you link a program with the library, you must provide -complete object files to the recipients so that they can relink them -with the library, after making changes to the library and recompiling +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. - Our method of protecting your rights has two steps: (1) copyright -the library, and (2) offer you this license which gives you legal + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. - Also, for each distributor's protection, we want to make certain -that everyone understands that there is no warranty for this free -library. If the library is modified by someone else and passed on, we -want its recipients to know that what they have is not the original -version, so that any problems introduced by others will not reflect on -the original authors' reputations. + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that companies distributing free -software will individually obtain patent licenses, thus in effect -transforming the program into proprietary software. To prevent this, -we have made it clear that any patent must be licensed for everyone's -free use or not licensed at all. - - Most GNU software, including some libraries, is covered by the ordinary -GNU General Public License, which was designed for utility programs. This -license, the GNU Library General Public License, applies to certain -designated libraries. This license is quite different from the ordinary -one; be sure to read it in full, and don't assume that anything in it is -the same as in the ordinary license. - - The reason we have a separate public license for some libraries is that -they blur the distinction we usually make between modifying or adding to a -program and simply using it. Linking a program with a library, without -changing the library, is in some sense simply using the library, and is -analogous to running a utility program or application program. However, in -a textual and legal sense, the linked executable is a combined work, a -derivative of the original library, and the ordinary General Public License -treats it as such. - - Because of this blurred distinction, using the ordinary General -Public License for libraries did not effectively promote software -sharing, because most developers did not use the libraries. We -concluded that weaker conditions might promote sharing better. - - However, unrestricted linking of non-free programs would deprive the -users of those programs of all benefit from the free status of the -libraries themselves. This Library General Public License is intended to -permit developers of non-free programs to use free libraries, while -preserving your freedom as a user of such programs to change the free -libraries that are incorporated in them. (We have not seen how to achieve -this as regards changes in header files, but we have achieved it as regards -changes in the actual functions of the Library.) The hope is that this -will lead to faster development of free libraries. + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The -former contains code derived from the library, while the latter only -works together with the library. - - Note that it is possible for a library to be covered by the ordinary -General Public License rather than by this special one. +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. - GNU LIBRARY GENERAL PUBLIC LICENSE + GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - 0. This License Agreement applies to any software library which -contains a notice placed by the copyright holder or other authorized -party saying it may be distributed under the terms of this Library -General Public License (also called "this License"). Each licensee is -addressed as "you". + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs @@ -133,7 +146,7 @@ such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. - + 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an @@ -255,7 +268,7 @@ distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. - 6. As an exception to the Sections above, you may also compile or + 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit @@ -282,23 +295,31 @@ of these things: Library will not necessarily be able to recompile the application to use the modified definitions.) - b) Accompany the work with a written offer, valid for at + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. - c) If distribution of the work is made by offering access to copy + d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. - d) Verify that the user has already received a copy of these + e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, -the source code distributed need not include anything that is normally -distributed (in either source or binary form) with the major +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. @@ -347,7 +368,7 @@ Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to +You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent @@ -390,7 +411,7 @@ excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new -versions of the Library General Public License from time to time. +versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. @@ -453,16 +474,16 @@ convey the exclusion of warranty; and each file should have at least the Copyright (C) This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public + modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. + version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. + Lesser General Public License for more details. - You should have received a copy of the GNU Library General Public + You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/LibmysqlTypes.txt b/LibmysqlTypes.txt index 0597b3e65..3a6e5848a 100644 --- a/LibmysqlTypes.txt +++ b/LibmysqlTypes.txt @@ -3,6 +3,7 @@ # You will find the appropiate defines in # include/my_config.h.in INCLUDE (CheckTypeSize) +INCLUDE (CheckCXXSourceCompiles) SET(CMAKE_EXTRA_INCLUDE_FILES signal.h) CHECK_TYPE_SIZE(sigset_t SIZEOF_SIGSET_T) @@ -81,3 +82,26 @@ IF(IS_VOID_QSORT) ELSE(IS_VOID_QSORT) SET(RETQSORTTYPE "int") ENDIF(IS_VOID_QSORT) + +# +# SOCKET_SIZE +# +IF(WIN32) + SET(SOCKET_SIZE_TYPE int) +ELSE(WIN32) + FOREACH(CHECK_TYPE "socklen_t" "size_t" "int") + IF (NOT SOCKET_SIZE_TYPE) + CHECK_CXX_SOURCE_COMPILES(" + #include + int main() + { + getsockname(0, 0, (${CHECK_TYPE} *)0); + return 0; + }" + SOCKET_SIZE_FOUND_${CHECK_TYPE}) + IF(SOCKET_SIZE_FOUND_${CHECK_TYPE}) + SET(SOCKET_SIZE_TYPE ${CHECK_TYPE}) + ENDIF(SOCKET_SIZE_FOUND_${CHECK_TYPE}) + ENDIF (NOT SOCKET_SIZE_TYPE) + ENDFOREACH() +ENDIF(WIN32) diff --git a/README b/README index 8bdae3a92..b1cc0f4b4 100644 --- a/README +++ b/README @@ -8,8 +8,8 @@ The following are the main known limitations: - float to string conversion for prepared statements doesn't work correctly - - It doesn't compile on windows (should not be hard to fix; It's mainly - the compiler environment files that is missing) + - SSL support + - Win64 support not yet ready If you want to be part of this development effort, you can discuss this at maria-developers@lists.launchpad.org. diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 000000000..b79985c2a --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,18 @@ +SET(EXAMPLE_FILES "mysql_affected_rows" + "mysql_debug") + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) + +ENABLE_TESTING() + +# this will be the main tests which saves output +# from example files +ADD_EXECUTABLE(test_output test_output.c) + +FOREACH(EXAMPLE_FILE ${EXAMPLE_FILES}) + SET(XML_EXAMPLE_FILES $XML_EXAMPLE_FILES "examples/${EXAMPLE_FILE}.c") + ADD_EXECUTABLE(${EXAMPLE_FILE} ${EXAMPLE_FILE}.c) + TARGET_LINK_LIBRARIES(${EXAMPLE_FILE} mysqlclient) + ADD_TEST(TEST_${EXAMPLE_FILE} ./${EXECUTABLE_OUTPUT_PATH}/test_output ./${EXAMPLE_FILE} ${CMAKE_SOURCE_DIR}/examples/${EXAMPLE_FILE}.out ${CMAKE_SOURCE_DIR}/examples/${EXAMPLE_FILE}.exp) + +ENDFOREACH(EXAMPLE_FILE ${EXAMPLE_FILES}) diff --git a/examples/mysql_affected_rows.c b/examples/mysql_affected_rows.c new file mode 100644 index 000000000..c72ce8de6 --- /dev/null +++ b/examples/mysql_affected_rows.c @@ -0,0 +1,82 @@ +#include +#include +#include +#include + +void show_error(MYSQL *mysql) +{ + printf("Error(%d) [%s] \"%s\"", mysql_errno(mysql), + mysql_sqlstate(mysql), + mysql_error(mysql)); + mysql_close(mysql); + exit(-1); +} + +int main(int argc, char *argv[]) +{ + MYSQL *mysql; + const char *query; + MYSQL_RES *result; + + mysql= mysql_init(NULL); + if (!mysql_real_connect(mysql, "localhost", "example", "example_pw", + "example_db", 0, "/tmp/mysql.sock", 0)) + show_error(mysql); + + query= "DROP TABLE IF EXISTS affected_rows"; + if (mysql_real_query(mysql, query, strlen(query))) + show_error(mysql); + + query= "CREATE TABLE affected_rows (id int not null, my_name varchar(50)," + "PRIMARY KEY(id))"; + if (mysql_real_query(mysql, query, strlen(query))) + show_error(mysql); + + /* Affected rows with INSERT statement */ + query= "INSERT INTO affected_rows VALUES (1, \"First value\")," + "(2, \"Second value\")"; + if (mysql_real_query(mysql, query, strlen(query))) + show_error(mysql); + printf("Affected_rows after INSERT: %lu\n", + (unsigned long) mysql_affected_rows(mysql)); + + /* Affected rows with REPLACE statement */ + query= "REPLACE INTO affected_rows VALUES (1, \"First value\")," + "(2, \"Second value\")"; + if (mysql_real_query(mysql, query, strlen(query))) + show_error(mysql); + printf("Affected_rows after REPLACE: %lu\n", + (unsigned long) mysql_affected_rows(mysql)); + + /* Affected rows with UPDATE statement */ + query= "UPDATE affected_rows SET id=1 WHERE id=1"; + if (mysql_real_query(mysql, query, strlen(query))) + show_error(mysql); + printf("Affected_rows after UPDATE: %lu\n", + (unsigned long) mysql_affected_rows(mysql)); + + query= "UPDATE affected_rows SET my_name=\"Monty\" WHERE id=1"; + if (mysql_real_query(mysql, query, strlen(query))) + show_error(mysql); + printf("Affected_rows after UPDATE: %lu\n", + (unsigned long) mysql_affected_rows(mysql)); + + /* Affected rows after select */ + query= "SELECT id, my_name FROM affected_rows"; + if (mysql_real_query(mysql, query, strlen(query))) + show_error(mysql); + result= mysql_store_result(mysql); + printf("Affected_rows after SELECT and storing result set: %lu\n", + (unsigned long) mysql_affected_rows(mysql)); + mysql_free_result(result); + + /* Affected rows with DELETE statment */ + query= "DELETE FROM affected_rows"; + if (mysql_real_query(mysql, query, strlen(query))) + show_error(mysql); + printf("Affected_rows after DELETE: %lu\n", + (unsigned long) mysql_affected_rows(mysql)); + + mysql_close(mysql); + return 0; +} diff --git a/examples/mysql_debug.c b/examples/mysql_debug.c new file mode 100644 index 000000000..380cb7165 --- /dev/null +++ b/examples/mysql_debug.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include + +void show_error(MYSQL *mysql) +{ + printf("Error(%d) [%s] \"%s\"", mysql_errno(mysql), + mysql_sqlstate(mysql), + mysql_error(mysql)); + mysql_close(mysql); + exit(-1); +} + +int main(int argc, char *argv[]) +{ + MYSQL *mysql; + const char *query; + + mysql_debug("d:t:O"); + + mysql= mysql_init(NULL); + + if (!mysql_real_connect(mysql, "localhost", "example", "example_pw", + "example_db", 0, "/tmp/mysql.sock", 0)) + show_error(mysql); + + query= "DROP TABLE IF EXISTS debug_example"; + if (mysql_real_query(mysql, query, strlen(query))) + show_error(mysql); + + query= "CREATE TABLE debug_example (id int not null, my_name varchar(50)," + "PRIMARY KEY(id))"; + if (mysql_real_query(mysql, query, strlen(query))) + show_error(mysql); + + mysql_close(mysql); + + return 0; +} diff --git a/examples/test_output.c b/examples/test_output.c new file mode 100644 index 000000000..6f38e3f52 --- /dev/null +++ b/examples/test_output.c @@ -0,0 +1,72 @@ +#include +#include +#include +#ifdef _WIN32 +#define popen _popen +#define pclose _pclose +#endif +int main(int argc, char *argv[]) +{ + char cmd_output[1024]; + char cmd_exp[1024]; + FILE *fp_exec, *fp_out, *fp_exp; + + if (argc < 3) + { + printf("Syntax: test_output test output expected"); + exit(-1); + } + if (!(fp_exec= popen(argv[1], "r"))) + { + printf("Failed to run %s\n", argv[1]); + exit(-1); + } + + if (!(fp_out= fopen(argv[2], "w"))) + { + printf("Failed to open %s for write\n", argv[2]); + exit(-1); + } + + while (NULL != fgets(cmd_output, sizeof(cmd_output-1), fp_exec)) + { + fputs(cmd_output, fp_out); + } + pclose(fp_exec); + fflush(fp_out); + fclose(fp_out); + + if (argc == 3) + return 0; + + if (!(fp_exp= fopen(argv[3], "r"))) + { + /* if no exp file exists, we just return + without an error = skip check */ + return(0); + } + if (!(fp_out= fopen(argv[2], "r"))) + { + printf("Failed to open %s for read\n", argv[2]); + exit(-1); + } + + while (fgets(cmd_exp, sizeof(cmd_exp)-1, fp_exp)) + { + if (!fgets(cmd_output, sizeof(cmd_output)-1, fp_out)) + { + printf("Can't read from output file\n"); + goto error; + } + if (strcmp(cmd_output, cmd_exp)) + { + printf("output and expected output are different\n"); + goto error; + } + } + return 0; +error: + fclose(fp_exp); + fclose(fp_out); + return 1; +} diff --git a/include/config-win.h b/include/config-win.h index 7770546f8..cefadc945 100644 --- a/include/config-win.h +++ b/include/config-win.h @@ -17,19 +17,21 @@ /* Defines for Win32 to make it compatible for MySQL */ +#ifndef _config_win_h_ +#define _config_win_h_ + #include -#include +#include +#include #include /* Because of rint() */ #include #include #include +#include +#include -#if defined(__NT__) -#define SYSTEM_TYPE "NT" -#elif defined(__WIN2000__) -#define SYSTEM_TYPE "WIN2000" -#else -#define SYSTEM_TYPE "Win95/Win98" +#ifndef THREAD + #define THREAD #endif #ifdef _WIN64 @@ -37,9 +39,6 @@ #else #define MACHINE_TYPE "i32" /* Define to machine type name */ #endif /* _WIN64 */ -#ifndef __WIN__ -#define __WIN__ /* To make it easier in VC++ */ -#endif /* File and lock constants */ #define O_SHARE 0x1000 /* Open file in sharing mode */ @@ -97,7 +96,6 @@ typedef __int64 os_off_t; #ifdef _WIN64 typedef UINT_PTR rf_SetTimer; #else -typedef unsigned int size_t; typedef uint rf_SetTimer; #endif @@ -115,9 +113,6 @@ typedef uint rf_SetTimer; #define HUGE_PTR #define STDCALL __stdcall /* Used by libmysql.dll */ -#ifndef UNDEF_THREAD_HACK -#define THREAD -#endif #define VOID_SIGHANDLER #define SIZEOF_CHAR 1 #define SIZEOF_LONG 4 @@ -170,6 +165,8 @@ inline double ulonglong2double(ulonglong value) #define inline __inline #endif /* __cplusplus */ +#define __attribute(A) + #if SIZEOF_OFF_T > 4 #define lseek(A,B,C) _lseeki64((A),(longlong) (B),(C)) #define tell(A) _telli64(A) @@ -177,49 +174,17 @@ inline double ulonglong2double(ulonglong value) #define STACK_DIRECTION -1 -/* Optimized store functions for Intel x86 */ - -#define sint2korr(A) (*((int16 *) (A))) -#define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \ - (((uint32) 255L << 24) | \ - (((uint32) (uchar) (A)[2]) << 16) |\ - (((uint32) (uchar) (A)[1]) << 8) | \ - ((uint32) (uchar) (A)[0])) : \ - (((uint32) (uchar) (A)[2]) << 16) |\ - (((uint32) (uchar) (A)[1]) << 8) | \ - ((uint32) (uchar) (A)[0]))) -#define sint4korr(A) (*((long *) (A))) -#define uint2korr(A) (*((uint16 *) (A))) -#define uint3korr(A) (long) (*((unsigned long *) (A)) & 0xFFFFFF) -#define uint4korr(A) (*((unsigned long *) (A))) -#define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\ - (((uint32) ((uchar) (A)[1])) << 8) +\ - (((uint32) ((uchar) (A)[2])) << 16) +\ - (((uint32) ((uchar) (A)[3])) << 24)) +\ - (((ulonglong) ((uchar) (A)[4])) << 32)) -#define uint8korr(A) (*((ulonglong *) (A))) -#define sint8korr(A) (*((longlong *) (A))) -#define int2store(T,A) *((uint16*) (T))= (uint16) (A) -#define int3store(T,A) { *(T)= (uchar) ((A));\ - *(T+1)=(uchar) (((uint) (A) >> 8));\ - *(T+2)=(uchar) (((A) >> 16)); } -#define int4store(T,A) *((long *) (T))= (long) (A) -#define int5store(T,A) { *(T)= (uchar)((A));\ - *((T)+1)=(uchar) (((A) >> 8));\ - *((T)+2)=(uchar) (((A) >> 16));\ - *((T)+3)=(uchar) (((A) >> 24)); \ - *((T)+4)=(uchar) (((A) >> 32)); } -#define int8store(T,A) *((ulonglong *) (T))= (ulonglong) (A) - -#define doubleget(V,M) { *((long *) &V) = *((long*) M); \ - *(((long *) &V)+1) = *(((long*) M)+1); } -#define doublestore(T,V) { *((long *) T) = *((long*) &V); \ - *(((long *) T)+1) = *(((long*) &V)+1); } -#define float4get(V,M) { *((long *) &(V)) = *((long*) (M)); } -#define float8get(V,M) doubleget((V),(M)) -#define float4store(V,M) memcpy((byte*) V,(byte*) (&M),sizeof(float)) -#define float8store(V,M) doublestore((V),(M)) - +/* redefine deprecated functions +#define sprintf sprintf_s +#define strcpy strcpy_s +#define strcat strcat_s +#define fopen fopen_r +#define freopen freopen_r +#define getenv _dupenv_s +*/ +#ifdef _WIN32 +#include +#endif #define HAVE_PERROR #define HAVE_VFPRINT @@ -247,7 +212,6 @@ inline double ulonglong2double(ulonglong value) #define HAVE_ALLOCA #define HAVE_STRPBRK #define HAVE_STRSTR -#define HAVE_COMPRESS #ifdef NOT_USED #define HAVE_SNPRINTF /* Gave link error */ @@ -298,3 +262,6 @@ inline double ulonglong2double(ulonglong value) #define statistic_add(V,C,L) (V)+=(C) #endif #define statistic_increment(V,L) thread_safe_increment((V),(L)) +#define strcasecmp(A,B) _stricmp((A),(B)) + +#endif diff --git a/include/errmsg.h b/include/errmsg.h index f4e07b966..5ef5b32e5 100644 --- a/include/errmsg.h +++ b/include/errmsg.h @@ -27,6 +27,7 @@ extern const char *client_errors[]; /* Error messages */ } #endif + #define CR_MIN_ERROR 2000 /* For easier client code */ #define CR_MAX_ERROR 2999 #if defined(OS2) && defined( MYSQL_SERVER) @@ -57,6 +58,7 @@ extern const char *client_errors[]; /* Error messages */ #define CR_NAMEDPIPESETSTATE_ERROR 2018 #define CR_CANT_READ_CHARSET 2019 #define CR_NET_PACKET_TOO_LARGE 2020 +#define CR_MALFORMED_PACKET 2027 #define CR_NO_PREPARE_STMT 2030 #define CR_PARAMS_NOT_BOUND 2031 #define CR_INVALID_PARAMETER_NO 2034 @@ -64,7 +66,9 @@ extern const char *client_errors[]; /* Error messages */ #define CR_NO_DATA 2051 #define CR_NO_STMT_METADATA 2052 #define CR_NOT_IMPLEMENTED 2054 +#define CR_SERVER_LOST_EXTENDED 2055 #define CR_NEW_STMT_METADATA 2057 -#define CR_ALREADY_CONNECTED 2058 +#define CR_AUTH_PLUGIN_CANNOT_LOAD 2058 +#define CR_ALREADY_CONNECTED 2059 #define SQLSTATE_UNKNOWN "HY000" diff --git a/include/global.h b/include/global.h index b8b118cd8..a6ba5f431 100644 --- a/include/global.h +++ b/include/global.h @@ -21,30 +21,8 @@ #ifndef _global_h #define _global_h -#if defined( __EMX__) && !defined( MYSQL_SERVER) -/* moved here to use below VOID macro redefinition */ -#define INCL_BASE -#define INCL_NOPMAPI -#include -#endif /* __EMX__ */ - -#ifdef __CYGWIN__ -/* We use a Unix API, so pretend it's not Windows */ -#undef WIN -#undef WIN32 -#undef _WIN -#undef _WIN32 -#undef _WIN64 -#undef __WIN__ -#undef __WIN32__ -#define HAVE_ERRNO_AS_DEFINE -#endif /* __CYGWIN__ */ - - -#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32) +#ifdef _WIN32 #include -#elif defined(OS2) -#include #else #include #if defined(__cplusplus) && defined(inline) @@ -76,7 +54,7 @@ #define __STDC_EXT__ 1 /* To get large file support on hpux */ #endif -#if defined(THREAD) && !defined(__WIN__) && !defined(OS2) +#if defined(THREAD) && !defined(_WIN32) #ifndef _POSIX_PTHREAD_SEMANTICS #define _POSIX_PTHREAD_SEMANTICS /* We want posix threads */ #endif @@ -225,9 +203,7 @@ #define POSIX_MISTAKE 1 /* regexp: Fix stupid spec error */ #define USE_REGEX 1 /* We want the use the regex library */ /* Do not define for ultra sparcs */ -#ifndef OS2 #define USE_BMOVE512 1 /* Use this unless the system bmove is faster */ -#endif /* Paranoid settings. Define I_AM_PARANOID if you are paranoid */ #ifdef I_AM_PARANOID @@ -270,11 +246,6 @@ int __void__; #define min(a, b) ((a) < (b) ? (a) : (b)) #endif -#if defined(__EMX__) || !defined(HAVE_UINT) -typedef unsigned int uint; -typedef unsigned short ushort; -#endif - #define sgn(a) (((a) < 0) ? -1 : ((a) > 0) ? 1 : 0) #define swap(t,a,b) { register t dummy; dummy = a; a = b; b = dummy; } #define test(a) ((a) ? 1 : 0) @@ -416,13 +387,8 @@ typedef SOCKET_SIZE_TYPE size_socket; #define FN_DEVCHAR ':' #ifndef FN_LIBCHAR -#ifdef __EMX__ -#define FN_LIBCHAR '\\' -#define FN_ROOTDIR "\\" -#else #define FN_LIBCHAR '/' #define FN_ROOTDIR "/" -#endif #define MY_NFILE 1024 /* This is only used to save filenames */ #endif @@ -454,7 +420,7 @@ typedef SOCKET_SIZE_TYPE size_socket; #define NO_PISAM /* Not needed anymore */ #define NO_MISAM /* Not needed anymore */ #define NO_HASH /* Not needed anymore */ -#ifdef __WIN__ +#ifdef _WIN32 #define NO_DIR_LIBRARY /* Not standar dir-library */ #define USE_MY_STAT_STRUCT /* For my_lib */ #endif @@ -476,7 +442,7 @@ extern void init_my_atof(void); extern double my_atof(const char*); #endif #undef remove /* Crashes MySQL on SCO 5.0.0 */ -#ifndef __WIN__ +#ifndef _WIN32 #ifdef OS2 #define closesocket(A) soclose(A) #else @@ -644,11 +610,11 @@ typedef ulonglong my_off_t; typedef unsigned long my_off_t; #endif #define MY_FILEPOS_ERROR (~(my_off_t) 0) -#if !defined(__WIN__) && !defined(OS2) +#if !defined(_WIN32) && !defined(OS2) typedef off_t os_off_t; #endif -#if defined(__WIN__) +#if defined(_WIN32) #define socket_errno WSAGetLastError() #define SOCKET_EINTR WSAEINTR #define SOCKET_EAGAIN WSAEINPROGRESS diff --git a/include/m_ctype.h b/include/m_ctype.h index 9b322daf5..98d8eb3a9 100644 --- a/include/m_ctype.h +++ b/include/m_ctype.h @@ -37,14 +37,15 @@ extern "C" { typedef struct charset_info_st { uint nr; /* so far only 1 byte for charset */ + uint state; + char *csname; char *name; - char *collation; + char *comment; + char *dir; uint char_minlen; uint char_maxlen; uint (*mb_charlen)(uint c); uint (*mb_valid)(const char *start, const char *end); - uchar *ctype; - uint mbmaxlen; } CHARSET_INFO; extern const CHARSET_INFO compiled_charsets[]; @@ -53,6 +54,6 @@ extern CHARSET_INFO *default_charset_info; CHARSET_INFO *find_compiled_charset(uint cs_number); CHARSET_INFO *find_compiled_charset_by_name(const char *name); -unsigned long mysql_cset_escape_quotes(const CHARSET_INFO *cset, char *newstr, const char *escapestr, size_t escapestr_len); -unsigned long mysql_cset_escape_slashes(const CHARSET_INFO *cset, char *newstr, const char *escapestr, size_t escapestr_len); +size_t mysql_cset_escape_quotes(const CHARSET_INFO *cset, char *newstr, const char *escapestr, size_t escapestr_len); +size_t mysql_cset_escape_slashes(const CHARSET_INFO *cset, char *newstr, const char *escapestr, size_t escapestr_len); #endif diff --git a/include/m_string.h b/include/m_string.h index 7eb2f1fe6..9b94d51b5 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -82,7 +82,7 @@ # define bmove_allign(A,B,C) memcpy((A),(B),(C)) #endif -#if defined(__cplusplus) && !defined(OS2) +#if defined(__cplusplus) extern "C" { #endif @@ -108,14 +108,6 @@ extern char NEAR _dig_vec[]; /* Declared in int2str() */ #define memcpy_fixed(A,B,C) memcpy((A),(B),(C)) #endif -#ifdef MSDOS -#undef bmove_allign -#define bmove512(A,B,C) bmove_allign(A,B,C) -#define my_itoa(A,B,C) itoa(A,B,C) -#define my_ltoa(A,B,C) ltoa(A,B,C) -extern void bmove_allign(gptr dst,const gptr src,uint len); -#endif - #if (!defined(USE_BMOVE512) || defined(HAVE_purify)) && !defined(bmove512) #define bmove512(A,B,C) memcpy(A,B,C) #endif @@ -123,44 +115,44 @@ extern void bmove_allign(gptr dst,const gptr src,uint len); /* Prototypes for string functions */ #if !defined(bfill) && !defined(HAVE_BFILL) -extern void bfill(gptr dst,uint len,pchar fill); +extern void bfill(gptr dst, size_t len, pchar fill); #endif #if !defined(bzero) && !defined(HAVE_BZERO) -extern void bzero(gptr dst,uint len); +extern void bzero(gptr dst, size_t len); #endif #if !defined(bcmp) && !defined(HAVE_BCMP) -extern int bcmp(const char *s1,const char *s2,uint len); +extern int bcmp(const char *s1,const char *s2, size_t len); #ifdef HAVE_purify -extern int my_bcmp(const char *s1,const char *s2,uint len); +extern int my_bcmp(const char *s1,const char *s2, size_t len); #define bcmp(A,B,C) my_bcmp((A),(B),(C)) #endif #endif #ifndef bmove512 -extern void bmove512(gptr dst,const gptr src,uint len); +extern void bmove512(gptr dst,const gptr src, size_t len); #endif #if !defined(HAVE_BMOVE) && !defined(bmove) -extern void bmove(char *dst, const char *src,uint len); +extern void bmove(char *dst, const char *src, size_t len); #endif -extern void bmove_upp(char *dst,const char *src,uint len); -extern void bchange(char *dst,uint old_len,const char *src, - uint new_len,uint tot_len); -extern void strappend(char *s,uint len,pchar fill); +extern void bmove_upp(char *dst,const char *src, size_t len); +extern void bchange(char *dst, size_t old_len, const char *src, + size_t new_len, size_t tot_len); +extern void strappend(char *s,size_t len,pchar fill); extern char *strend(const char *s); -extern char *strcend(const char *, pchar); +extern char *strcend(const char *, char); extern char *strfield(char *src,int fields,int chars,int blanks, int tabch); -extern char *strfill(my_string s,uint len,pchar fill); +extern char *strfill(my_string s, size_t len, pchar fill); extern uint strinstr(const char *str,const char *search); extern uint r_strinstr(reg1 my_string str,int from, reg4 my_string search); extern char *strkey(char *dst,char *head,char *tail,char *flags); -extern char *strmake(char *dst,const char *src,uint length); +extern char *strmake(char *dst,const char *src, size_t length); #ifndef strmake_overlapp -extern char *strmake_overlapp(char *dst,const char *src, uint length); +extern char *strmake_overlapp(char *dst,const char *src, size_t length); #endif #ifndef strmov @@ -172,9 +164,9 @@ extern char *strcont(const char *src,const char *set); extern char *strxcat _VARARGS((char *dst,const char *src, ...)); extern char *strxmov _VARARGS((char *dst,const char *src, ...)); extern char *strxcpy _VARARGS((char *dst,const char *src, ...)); -extern char *strxncat _VARARGS((char *dst,uint len, const char *src, ...)); -extern char *strxnmov _VARARGS((char *dst,uint len, const char *src, ...)); -extern char *strxncpy _VARARGS((char *dst,uint len, const char *src, ...)); +extern char *strxncat _VARARGS((char *dst, size_t len, const char *src, ...)); +extern char *strxnmov _VARARGS((char *dst, size_t len, const char *src, ...)); +extern char *strxncpy _VARARGS((char *dst, size_t len, const char *src, ...)); /* Prototypes of normal stringfunctions (with may ours) */ @@ -188,9 +180,6 @@ extern int strcmp(const char *, const char *); extern size_t strlen(const char *); #endif #endif -#ifndef HAVE_STRNLEN -extern uint strnlen(const char *s, uint n); -#endif #if !defined(__cplusplus) #ifndef HAVE_STRPBRK @@ -238,7 +227,7 @@ extern ulonglong strtoull(const char *str, char **ptr, int base); #endif #endif -#if defined(__cplusplus) && !defined(OS2) +#if defined(__cplusplus) } #endif #endif diff --git a/include/my_config.h b/include/my_config.h deleted file mode 100644 index 586066644..000000000 --- a/include/my_config.h +++ /dev/null @@ -1,275 +0,0 @@ - -#define HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE 1 - -/* - * Include file constants (processed in LibmysqlIncludeFiles.txt 1 - */ -#define HAVE_ALLOCA_H 1 -#define HAVE_ARPA_INET_H 1 -#define HAVE_CRYPT_H 1 -#define HAVE_DIRENT_H 1 -#define HAVE_DLFCN_H 1 -#define HAVE_EXECINFO_H 1 -#define HAVE_FCNTL_H 1 -#define HAVE_FENV_H 1 -#define HAVE_FLOAT_H 1 -/* #undef HAVE_FPU_CONTROL_H */ -#define HAVE_GRP_H 1 -/* #undef HAVE_IEEEFP_H */ -#define HAVE_LIMITS_H 1 -#define HAVE_MALLOC_H 1 -#define HAVE_MEMORY_H 1 -#define HAVE_NETINET_IN_H 1 -#define HAVE_PATHS_H 1 -#define HAVE_PWD_H 1 -#define HAVE_SCHED_H 1 -/* #undef HAVE_SELECT_H */ -#define HAVE_STDDEF_H 1 -#define HAVE_STDINT_H 1 -#define HAVE_STDLIB_H 1 -#define HAVE_STRING_H 1 -#define HAVE_STRINGS_H 1 -/* #undef HAVE_SYNCH_H */ -/* #undef HAVE_SYS_FPU_H */ -#define HAVE_SYS_IOCTL_H 1 -#define HAVE_SYS_IPC_H 1 -#define HAVE_SYS_MMAN_H 1 -#define HAVE_SYS_PRCTL_H 1 -#define HAVE_SYS_SELECT_H 1 -#define HAVE_SYS_SHM_H 1 -#define HAVE_SYS_SOCKET_H 1 -#define HAVE_SYS_STAT_H 1 -/* #undef HAVE_SYS_STREAM_H */ -#define HAVE_SYS_TIMEB_H 1 -#define HAVE_SYS_TYPES_H 1 -#define HAVE_SYS_UN_H 1 -/* #undef HAVE_SYSENT_H */ -#define HAVE_TERMIO_H 1 -#define HAVE_TERMIOS_H 1 -#define HAVE_UNISTD_H 1 -#define HAVE_UTIME_H 1 - -/* - * function definitions - processed in LibmysqlFunctions.txt - */ -#define HAVE_ACCESS 1 -/* #undef HAVE_AIOWAIT */ -#define HAVE_ALARM 1 -/* #undef HAVE_ALLOCA */ -#define HAVE_BCMP 1 -/* #undef HAVE_BFILL */ -/* #undef HAVE_BMOVE */ -#define HAVE_BZERO 1 -/* #undef HAVE_CLOCK_GETTIME */ -/* #undef HAVE_COMPRESS */ -/* #undef HAVE_CRYPT */ -/* #undef HAVE_DLERROR */ -/* #undef HAVE_DLOPEN */ -#define HAVE_FCHMOD 1 -#define HAVE_FCNTL 1 -/* #undef HAVE_FCONVERT */ -#define HAVE_FDATASYNC 1 -/* #undef HAVE_FESETROUND */ -#define HAVE_FINITE 1 -#define HAVE_FSEEKO 1 -#define HAVE_FSYNC 1 -#define HAVE_GETADDRINFO 1 -#define HAVE_GETCWD 1 -#define HAVE_GETHOSTBYADDR_R 1 -#define HAVE_GETHOSTBYNAME_R 1 -/* #undef HAVE_GETHRTIME */ -#define HAVE_GETNAMEINFO 1 -#define HAVE_GETPAGESIZE 1 -#define HAVE_GETPASS 1 -/* #undef HAVE_GETPASSPHRASE */ -#define HAVE_GETPWNAM 1 -#define HAVE_GETPWUID 1 -#define HAVE_GETRLIMIT 1 -#define HAVE_GETRUSAGE 1 -#define HAVE_GETWD 1 -#define HAVE_GMTIME_R 1 -#define HAVE_INITGROUPS 1 -#define HAVE_LDIV 1 -#define HAVE_LOCALTIME_R 1 -/* #undef HAVE_LOG2 */ -#define HAVE_LONGJMP 1 -#define HAVE_LSTAT 1 -#define HAVE_MADVISE 1 -#define HAVE_MALLINFO 1 -#define HAVE_MEMALIGN 1 -#define HAVE_MEMCPY 1 -#define HAVE_MEMMOVE 1 -#define HAVE_MKSTEMP 1 -#define HAVE_MLOCK 1 -#define HAVE_MLOCKALL 1 -#define HAVE_MMAP 1 -#define HAVE_MMAP64 1 -#define HAVE_PERROR 1 -#define HAVE_POLL 1 -#define HAVE_PREAD 1 -/* #undef HAVE_PTHREAD_ATTR_CREATE */ -/* #undef HAVE_PTHREAD_ATTR_GETSTACKSIZE */ -/* #undef HAVE_PTHREAD_ATTR_SETPRIO */ -#define HAVE_PTHREAD_ATTR_SETSCHEDPARAM 1 -#define HAVE_PTHREAD_ATTR_SETSCOPE 1 -/* #undef HAVE_PTHREAD_ATTR_SETSTACKSIZE */ -/* #undef HAVE_PTHREAD_CONDATTR_CREATE */ -/* #undef HAVE_PTHREAD_INIT */ -/* #undef HAVE_PTHREAD_KEY_DELETE */ -/* #undef HAVE_PTHREAD_KILL */ -/* #undef HAVE_PTHREAD_RWLOCK_RDLOCK */ -/* #undef HAVE_PTHREAD_SETPRIO_NP */ -#define HAVE_PTHREAD_SETSCHEDPARAM 1 -/* #undef HAVE_PTHREAD_SIGMASK */ -/* #undef HAVE_PTHREAD_THREADMASK */ -/* #undef HAVE_PTHREAD_YIELD_NP */ -#define HAVE_READDIR_R 1 -#define HAVE_READLINK 1 -#define HAVE_REALPATH 1 -#define HAVE_RENAME 1 -#define HAVE_SCHED_YIELD 1 -#define HAVE_SELECT 1 -/* #undef HAVE_SETFD */ -/* #undef HAVE_SETFILEPOINTER */ -#define HAVE_SIGNAL 1 -#define HAVE_SIGACTION 1 -/* #undef HAVE_SIGTHREADMASK */ -#define HAVE_SIGWAIT 1 -#define HAVE_SLEEP 1 -#define HAVE_SNPRINTF 1 -#define HAVE_STPCPY 1 -#define HAVE_STRERROR 1 -/* #undef HAVE_STRLCPY */ -#define HAVE_STRNLEN 1 -#define HAVE_STRPBRK 1 -#define HAVE_STRSEP 1 -#define HAVE_STRSTR 1 -#define HAVE_STRTOK_R 1 -#define HAVE_STRTOL 1 -#define HAVE_STRTOLL 1 -#define HAVE_STRTOUL 1 -#define HAVE_STRTOULL 1 -/* #undef HAVE_TELL */ -/* #undef HAVE_THR_SETCONCURRENCY */ -/* #undef HAVE_THR_YIELD */ -#define HAVE_VASPRINTF 1 -#define HAVE_VSNPRINTF 1 - -/* - * types and sizes - */ -/* Types we may use */ -#define SIZEOF_CHAR 1 -#if SIZEOF_CHAR -# define HAVE_CHAR 1 -#endif - -#define SIZEOF_CHARP 8 -#if SIZEOF_CHARP -# define HAVE_CHARP 1 -#endif - -#define SIZEOF_SHORT 2 -#if SIZEOF_SHORT -# define HAVE_SHORT 1 -#endif - -#define SIZEOF_INT 4 -#if SIZEOF_INT -# define HAVE_INT 1 -#endif - -#define SIZEOF_LONG 8 -#if SIZEOF_LONG -# define HAVE_LONG 1 -#endif - -#define SIZEOF_LONG_LONG 8 -#if SIZEOF_LONG_LONG -# define HAVE_LONG_LONG 1 -#endif - -#define SIZEOF_OFF_T 8 -#if SIZEOF_OFF_T -# define HAVE_OFF_T 1 -#endif - -#define SIZEOF_SIGSET_T 128 -#if SIZEOF_SIGSET_T -# define HAVE_SIGSET_T 1 -#endif - -#define SIZEOF_SIZE_T 8 -#if SIZEOF_SIZE_T -# define HAVE_SIZE_T 1 -#endif - -/* #undef SIZEOF_UCHAR */ -#if SIZEOF_UCHAR -# define HAVE_UCHAR 1 -#endif - -#define SIZEOF_UINT 4 -#if SIZEOF_UINT -# define HAVE_UINT 1 -#endif - -#define SIZEOF_ULONG 8 -#if SIZEOF_ULONG -# define HAVE_ULONG 1 -#endif - -/* #undef SIZEOF_INT8 */ -#if SIZEOF_INT8 -# define HAVE_INT8 1 -#endif -/* #undef SIZEOF_UINT8 */ -#if SIZEOF_UINT8 -# define HAVE_UINT8 1 -#endif - -/* #undef SIZEOF_INT16 */ -#if SIZEOF_INT16 -# define HAVE_INT16 1 -#endif -/* #undef SIZEOF_UINT16 */ -#if SIZEOF_UINT16 -# define HAVE_UINT16 1 -#endif - -/* #undef SIZEOF_INT32 */ -#if SIZEOF_INT32 -# define HAVE_INT32 1 -#endif -/* #undef SIZEOF_UINT32 */ -#if SIZEOF_UINT32 -# define HAVE_UINT32 1 -#endif -/* #undef SIZEOF_U_INT32_T */ -#if SIZEOF_U_INT32_T -# define HAVE_U_INT32_T 1 -#endif - -/* #undef SIZEOF_INT64 */ -#if SIZEOF_INT64 -# define HAVE_INT64 1 -#endif -/* #undef SIZEOF_UINT64 */ -#if SIZEOF_UINT64 -# define HAVE_UINT64 1 -#endif - -/* #undef SIZEOF_SOCKLEN_T */ -#if SIZEOF_SOCKLEN_T -# define HAVE_SOCKLEN_T 1 -#endif - -#define RETSIGTYPE void -#define RETQSORTTYPE void - -/* - * various other defines - */ -/* #undef HAVE_THREADS */ -#define SHAREDIR "share" -#define DEFAULT_CHARSET_HOME "/usr/local" diff --git a/include/my_config.h.in b/include/my_config.h.in index 37267455b..39ad75bfa 100644 --- a/include/my_config.h.in +++ b/include/my_config.h.in @@ -264,6 +264,8 @@ # define HAVE_SOCKLEN_T 1 #endif +#cmakedefine SOCKET_SIZE_TYPE @SOCKET_SIZE_TYPE@ + #cmakedefine RETSIGTYPE @RETSIGTYPE@ #cmakedefine RETQSORTTYPE @RETQSORTTYPE@ diff --git a/include/my_global.h b/include/my_global.h index e1788845f..d6cfea852 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -21,30 +21,9 @@ #ifndef _global_h #define _global_h -#if defined( __EMX__) && !defined( MYSQL_SERVER) -/* moved here to use below VOID macro redefinition */ -#define INCL_BASE -#define INCL_NOPMAPI -#include -#endif /* __EMX__ */ - -#ifdef __CYGWIN__ -/* We use a Unix API, so pretend it's not Windows */ -#undef WIN -#undef WIN32 -#undef _WIN -#undef _WIN32 -#undef _WIN64 -#undef __WIN__ -#undef __WIN32__ -#define HAVE_ERRNO_AS_DEFINE -#endif /* __CYGWIN__ */ - - -#ifdef __WIN__ + +#ifdef _WIN32 #include -#elif defined(OS2) -#include #else #include #if defined(__cplusplus) && defined(inline) @@ -76,7 +55,7 @@ #define __STDC_EXT__ 1 /* To get large file support on hpux */ #endif -#if defined(THREAD) && !defined(__WIN__) && !defined(OS2) +#if defined(THREAD) && !defined(_WIN32) #ifndef _POSIX_PTHREAD_SEMANTICS #define _POSIX_PTHREAD_SEMANTICS /* We want posix threads */ #endif @@ -224,6 +203,7 @@ double my_ulonglong2double(unsigned long long A); #include #endif #include /* Recommended by debian */ +#include /* Go around some bugs in different OS and compilers */ #if defined(_HPUX_SOURCE) && defined(HAVE_SYS_STREAM_H) @@ -247,9 +227,7 @@ double my_ulonglong2double(unsigned long long A); #define POSIX_MISTAKE 1 /* regexp: Fix stupid spec error */ #define USE_REGEX 1 /* We want the use the regex library */ /* Do not define for ultra sparcs */ -#ifndef OS2 #define USE_BMOVE512 1 /* Use this unless the system bmove is faster */ -#endif /* Paranoid settings. Define I_AM_PARANOID if you are paranoid */ #ifdef I_AM_PARANOID @@ -279,8 +257,10 @@ int __void__; #if defined(_lint) || defined(FORCE_INIT_OF_VARS) #define LINT_INIT(var) var=0 /* No uninitialize-warning */ +#define LINT_INIT_STRUCT(var) bzero(&var, sizeof(var)) /* No uninitialize-warning */ #else #define LINT_INIT(var) +#define LINT_INIT_STRUCT(var) #endif /* Define some useful general macros */ @@ -360,8 +340,9 @@ typedef unsigned short ushort; /* Some types that is different between systems */ typedef int File; /* File descriptor */ -#ifndef Socket_defined +#ifndef my_socket_defined typedef int my_socket; /* File descriptor for sockets */ +#define my_socket_defined #define INVALID_SOCKET -1 #endif /* Type for fuctions that handles signals */ @@ -394,7 +375,7 @@ typedef int (*qsort_cmp)(const void *,const void *); #ifdef HAVE_SYS_SOCKET_H #include #endif -/* typedef SOCKET_SIZE_TYPE size_socket; */ + #endif #ifndef SOCKOPT_OPTLEN_TYPE @@ -483,7 +464,7 @@ typedef int (*qsort_cmp)(const void *,const void *); #define NO_PISAM /* Not needed anymore */ #define NO_MISAM /* Not needed anymore */ #define NO_HASH /* Not needed anymore */ -#ifdef __WIN__ +#ifdef _WIN32 #define NO_DIR_LIBRARY /* Not standar dir-library */ #define USE_MY_STAT_STRUCT /* For my_lib */ #endif @@ -505,17 +486,14 @@ extern void init_my_atof(void); extern double my_atof(const char*); #endif #undef remove /* Crashes MySQL on SCO 5.0.0 */ -#ifndef __WIN__ -#ifdef OS2 -#define closesocket(A) soclose(A) -#else +#ifndef _WIN32 #define closesocket(A) close(A) #endif #ifndef ulonglong2double #define ulonglong2double(A) ((double) (A)) #define my_off_t2double(A) ((double) (A)) #endif -#endif + #ifndef offsetof #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) @@ -684,24 +662,17 @@ typedef ulonglong my_off_t; typedef unsigned long my_off_t; #endif #define MY_FILEPOS_ERROR (~(my_off_t) 0) -#if !defined(__WIN__) && !defined(OS2) +#ifndef _WIN32 typedef off_t os_off_t; #endif -#if defined(__WIN__) +#if defined(_WIN32) #define socket_errno WSAGetLastError() #define SOCKET_EINTR WSAEINTR #define SOCKET_EAGAIN WSAEINPROGRESS #define SOCKET_ENFILE ENFILE #define SOCKET_EMFILE EMFILE -#elif defined(OS2) -#define socket_errno sock_errno() -#define SOCKET_EINTR SOCEINTR -#define SOCKET_EAGAIN SOCEINPROGRESS -#define SOCKET_EWOULDBLOCK SOCEWOULDBLOCK -#define SOCKET_ENFILE SOCENFILE -#define SOCKET_EMFILE SOCEMFILE -#define closesocket(A) soclose(A) +#define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK #else /* Unix */ #define socket_errno errno #define closesocket(A) close(A) @@ -761,7 +732,7 @@ typedef char bool; /* Ordinary boolean values 0 1 */ #define NOT_FIXED_DEC 31 -#ifdef __WIN__ +#ifdef _WIN32 #define MYSQLND_LLU_SPEC "%I64u" #define MYSQLND_LL_SPEC "%I64d" #ifndef L64 @@ -773,7 +744,7 @@ typedef char bool; /* Ordinary boolean values 0 1 */ #ifndef L64 #define L64(x) x##LL #endif /* L64 */ -#endif /* __WIN__ */ +#endif /* _WIN32 */ /* ** Define-funktions for reading and storing in machine independent format ** (low byte first) @@ -782,7 +753,7 @@ typedef char bool; /* Ordinary boolean values 0 1 */ /* Optimized store functions for Intel x86 */ #define int1store(T,A) *((int8*) (T)) = (A) #define uint1korr(A) (*(((uint8*)(A)))) -#if defined(__i386__) || defined(__WIN__) +#if defined(__i386__) || defined(_WIN32) #define sint2korr(A) (*((int16 *) (A))) #define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \ (((uint32) 255L << 24) | \ @@ -794,7 +765,7 @@ typedef char bool; /* Ordinary boolean values 0 1 */ ((uint32) (uchar) (A)[0]))) #define sint4korr(A) (*((long *) (A))) #define uint2korr(A) (*((uint16 *) (A))) -#if defined(HAVE_purify) && !defined(__WIN__) +#if defined(HAVE_purify) && !defined(_WIN32) #define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\ (((uint32) ((uchar) (A)[1])) << 8) +\ (((uint32) ((uchar) (A)[2])) << 16)) @@ -1075,4 +1046,29 @@ do { doubleget_union _tmp; \ #define statistic_add(V,C,L) (V)+=(C) #endif +#ifdef _WIN32 +#define SO_EXT ".dll" +#elif defined(__APPLE__) +#define SO_EXT ".dylib" +#else +#define SO_EXT ".so" +#endif + +#ifdef HAVE_DLOPEN +#ifdef _WIN32 +#define dlsym(lib, name) GetProcAddress((HMODULE)lib, name) +#define dlopen(libname, unused) LoadLibraryEx(libname, NULL, 0) +#define dlclose(lib) FreeLibrary((HMODULE)lib) +#elif defined(HAVE_DLFCN_H) +#include +#endif +#if HAVE_DLERROR +#define dlerror() "" +#endif +#endif + +#ifndef RTLD_NOW +#define RTLD_NOW 1 +#endif + #endif /* _global_h */ diff --git a/include/my_list.h b/include/my_list.h index bb2657307..a5621367d 100644 --- a/include/my_list.h +++ b/include/my_list.h @@ -34,7 +34,7 @@ extern LIST *list_delete(LIST *root,LIST *element); extern LIST *list_cons(void *data,LIST *root); extern LIST *list_reverse(LIST *root); extern void list_free(LIST *root,unsigned int free_data); -extern uint list_length(LIST *list); +extern unsigned int list_length(LIST *list); extern int list_walk(LIST *list,list_walk_action action,gptr argument); #define rest(a) ((a)->next) diff --git a/include/my_net.h b/include/my_net.h index a4910d8af..89efc655b 100644 --- a/include/my_net.h +++ b/include/my_net.h @@ -22,7 +22,7 @@ extern "C" { #endif /* __cplusplus */ -#if !defined(MSDOS) && !defined(__WIN__) && !defined(__BEOS__) +#if !defined(MSDOS) && !defined(_WIN32) && !defined(__BEOS__) #ifdef HAVE_SYS_SOCKET_H #include #endif @@ -32,7 +32,7 @@ extern "C" { #ifdef HAVE_ARPA_INET_H #include #endif -#endif /* !defined(MSDOS) && !defined(__WIN__) */ +#endif /* !defined(MSDOS) && !defined(_WIN32) */ void my_inet_ntoa(struct in_addr in, char *buf); diff --git a/include/my_pthread.h b/include/my_pthread.h index f31fa1130..49768a58b 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -29,7 +29,7 @@ extern "C" { #endif /* __cplusplus */ -#if defined(__WIN__) || defined(OS2) +#if defined(_WIN32) || defined(OS2) #ifdef OS2 typedef ULONG HANDLE; @@ -60,20 +60,20 @@ typedef struct st_pthread_link { typedef struct { uint32 waiting; -#ifdef OS2 - HEV semaphore; -#else - HANDLE semaphore; -#endif -} pthread_cond_t; + enum { + SIGNAL = 0, + BROADCAST = 1, + MAX_EVENTS = 2 + } EVENTS; + HANDLE events[MAX_EVENTS]; + CRITICAL_SECTION waiters_count_lock; +} pthread_cond_t; -#ifndef OS2 struct timespec { /* For pthread_cond_timedwait() */ time_t tv_sec; long tv_nsec; }; -#endif typedef int pthread_mutexattr_t; #define win_pthread_self my_thread_var->pthread_self @@ -104,7 +104,6 @@ struct tm *localtime_r(const time_t *timep,struct tm *tmp); void pthread_exit(void *a); /* was #define pthread_exit(A) ExitThread(A)*/ #ifndef OS2 -#define ETIMEDOUT 145 /* Win32 doesn't have this */ #define getpid() GetCurrentThreadId() #endif #define pthread_self() win_pthread_self @@ -132,15 +131,7 @@ void pthread_exit(void *a); /* was #define pthread_exit(A) ExitThread(A)*/ #endif /* USE_TLS */ #define pthread_equal(A,B) ((A) == (B)) -#ifdef OS2 -extern int pthread_mutex_init (pthread_mutex_t *, const pthread_mutexattr_t *); -extern int pthread_mutex_lock (pthread_mutex_t *); -extern int pthread_mutex_unlock (pthread_mutex_t *); -extern int pthread_mutex_destroy (pthread_mutex_t *); -#define my_pthread_setprio(A,B) DosSetPriority(PRTYS_THREAD,PRTYC_NOCHANGE, B, A) -#define pthread_kill(A,B) raise(B) -#define pthread_exit(A) pthread_dummy() -#else +#ifdef _WIN32 #define pthread_mutex_init(A,B) InitializeCriticalSection(A) #define pthread_mutex_lock(A) (EnterCriticalSection(A),0) #define pthread_mutex_trylock(A) (WaitForSingleObject((A), 0) == WAIT_TIMEOUT) @@ -148,7 +139,7 @@ extern int pthread_mutex_destroy (pthread_mutex_t *); #define pthread_mutex_destroy(A) DeleteCriticalSection(A) #define my_pthread_setprio(A,B) SetThreadPriority(GetCurrentThread(), (B)) #define pthread_kill(A,B) pthread_dummy(0) -#endif /* OS2 */ +#endif /* _WIN32 */ /* Dummy defines for easier code */ #define pthread_attr_setdetachstate(A,B) pthread_dummy(0) @@ -427,7 +418,7 @@ struct tm *localtime_r(const time_t *clock, struct tm *res); #define HAVE_PTHREAD_KILL #endif -#endif /* defined(__WIN__) */ +#endif /* defined(_WIN32) */ #if defined(HPUX) && !defined(DONT_REMAP_PTHREAD_FUNCTIONS) #undef pthread_cond_timedwait diff --git a/include/mysql_stmt.h b/include/my_stmt.h similarity index 85% rename from include/mysql_stmt.h rename to include/my_stmt.h index 91c2e8d57..6b8bd67a8 100644 --- a/include/mysql_stmt.h +++ b/include/my_stmt.h @@ -23,21 +23,21 @@ #define MYSQL_NO_DATA 100 #define MYSQL_DATA_TRUNCATED 101 -#define MYSQL_DEFAULT_PREFETCH_ROWS (ulong) 1 +#define MYSQL_DEFAULT_PREFETCH_ROWS (unsigned long) 1 #define SET_CLIENT_STMT_ERROR(a, b, c, d) \ { \ - (a).error_no= (b);\ - strncpy((a).sqlstate, (c), sizeof((a).sqlstate));\ - strncpy((a).error, (d) ? (d) : ER((b)), sizeof((a).error));\ + (a)->last_errno= (b);\ + strncpy((a)->sqlstate, (c), sizeof((a)->sqlstate));\ + strncpy((a)->last_error, (d) ? (d) : ER((b)), sizeof((a)->last_error));\ } #define CLEAR_CLIENT_STMT_ERROR(a) \ { \ - (a).error_no= 0;\ - strcpy((a).sqlstate, "00000");\ - (a).error[0]= 0;\ + (a)->last_errno= 0;\ + strcpy((a)->sqlstate, "00000");\ + (a)->last_error[0]= 0;\ } #define MYSQL_PS_SKIP_RESULT_W_LEN -1 @@ -48,13 +48,7 @@ typedef struct st_mysql_stmt MYSQL_STMT; typedef MYSQL_RES* (*mysql_stmt_use_or_store_func)(MYSQL_STMT *); -/* -enum enum_mysql_stmt_state -{ - MYSQL_STMT_INIT_DONE= 1, MYSQL_STMT_PREPARE_DONE, MYSQL_STMT_EXECUTE_DONE, - MYSQL_STMT_FETCH_DONE -}; -*/ + enum enum_stmt_attr_type { STMT_ATTR_UPDATE_MAX_LENGTH, @@ -142,7 +136,7 @@ struct st_mysqlnd_stmt_methods MYSQL_RES * (*store_result)(const MYSQL_STMT * stmt); MYSQL_RES * (*get_result)(const MYSQL_STMT * stmt); my_bool (*free_result)(const MYSQL_STMT * stmt); - my_bool (*seek_data)(const const MYSQL_STMT * stmt, my_ulonglong row); + my_bool (*seek_data)(const MYSQL_STMT * stmt, my_ulonglong row); my_bool (*reset)(const MYSQL_STMT * stmt); my_bool (*close)(const MYSQL_STMT * stmt); /* private */ my_bool (*dtor)(const MYSQL_STMT * stmt); /* use this for mysqlnd_stmt_close */ @@ -156,17 +150,17 @@ struct st_mysqlnd_stmt_methods const char * const data, unsigned long length); MYSQL_RES *(*get_parameter_metadata)(const MYSQL_STMT * stmt); MYSQL_RES *(*get_result_metadata)(const MYSQL_STMT * stmt); - my_ulonglong (*get_last_insert_id)(const const MYSQL_STMT * stmt); - my_ulonglong (*get_affected_rows)(const const MYSQL_STMT * stmt); - my_ulonglong (*get_num_rows)(const const MYSQL_STMT * stmt); + my_ulonglong (*get_last_insert_id)(const MYSQL_STMT * stmt); + my_ulonglong (*get_affected_rows)(const MYSQL_STMT * stmt); + my_ulonglong (*get_num_rows)(const MYSQL_STMT * stmt); - unsigned int (*get_param_count)(const const MYSQL_STMT * stmt); - unsigned int (*get_field_count)(const const MYSQL_STMT * stmt); - unsigned int (*get_warning_count)(const const MYSQL_STMT * stmt); + unsigned int (*get_param_count)(const MYSQL_STMT * stmt); + unsigned int (*get_field_count)(const MYSQL_STMT * stmt); + unsigned int (*get_warning_count)(const MYSQL_STMT * stmt); - unsigned int (*get_error_no)(const const MYSQL_STMT * stmt); - const char * (*get_error_str)(const const MYSQL_STMT * stmt); - const char * (*get_sqlstate)(const const MYSQL_STMT * stmt); + unsigned int (*get_error_no)(const MYSQL_STMT * stmt); + const char * (*get_error_str)(const MYSQL_STMT * stmt); + const char * (*get_sqlstate)(const MYSQL_STMT * stmt); my_bool (*get_attribute)(const MYSQL_STMT * stmt, enum enum_stmt_attr_type attr_type, const void * value); my_bool (*set_attribute)(const MYSQL_STMT * stmt, enum enum_stmt_attr_type attr_type, const void * value); @@ -177,7 +171,7 @@ typedef int (*mysql_stmt_fetch_row_func)(MYSQL_STMT *stmt, unsigned char **row) struct st_mysql_stmt { MEM_ROOT mem_root; - MYSQL *conn; + MYSQL *mysql; unsigned long stmt_id; unsigned long flags;/* cursor is set here */ enum_mysqlnd_stmt_state state; @@ -185,15 +179,18 @@ struct st_mysql_stmt unsigned int field_count; unsigned int param_count; unsigned char send_types_to_server; - MYSQL_BIND *param_bind; - MYSQL_BIND *result_bind; + MYSQL_BIND *params; + MYSQL_BIND *bind; MYSQL_DATA result; /* we don't use mysqlnd's result set logic */ MYSQL_ROWS *result_cursor; my_bool bind_result_done; + my_bool bind_param_done; mysql_upsert_status upsert_status; - mysql_error_info error_info; + unsigned int last_errno; + char last_error[MYSQL_ERRMSG_SIZE+1]; + char sqlstate[SQLSTATE_LENGTH + 1]; my_bool update_max_length; unsigned long prefetch_rows; @@ -213,14 +210,14 @@ struct st_mysql_perm_bind { ps_field_fetch_func func; /* should be signed int */ int pack_len; - ulong max_len; + unsigned long max_len; }; extern struct st_mysql_perm_bind mysql_ps_fetch_functions[MYSQL_TYPE_GEOMETRY + 1]; -ulong net_safe_read(MYSQL *mysql); +unsigned long net_safe_read(MYSQL *mysql); void mysql_init_ps_subsystem(void); -ulong net_field_length(unsigned char **packet); -int simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, uint length, my_bool skipp_check); +unsigned long net_field_length(unsigned char **packet); +int simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, size_t length, my_bool skipp_check); /* * function prototypes */ @@ -255,4 +252,6 @@ my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt); MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_tell(MYSQL_STMT *stmt); MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_seek(MYSQL_STMT *stmt, MYSQL_ROW_OFFSET new_row); unsigned long STDCALL mysql_stmt_param_count(MYSQL_STMT *stmt); -my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number, const char *data, ulong length); +my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt, unsigned int param_number, const char *data, unsigned long length); +my_ulonglong STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt); +my_ulonglong STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt); diff --git a/include/my_sys.h b/include/my_sys.h index 55f2f2c29..c93f015da 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -135,11 +135,11 @@ extern ulonglong safemalloc_mem_limit; #define TERMINATE(A) {} #define QUICK_SAFEMALLOC #define NORMAL_SAFEMALLOC -extern gptr my_malloc(uint Size,myf MyFlags); +extern gptr my_malloc(size_t Size,myf MyFlags); #define my_malloc_ci(SZ,FLAG) my_malloc( SZ, FLAG ) -extern gptr my_realloc(gptr oldpoint,uint Size,myf MyFlags); +extern gptr my_realloc(gptr oldpoint, size_t Size,myf MyFlags); extern void my_no_flags_free(gptr ptr); -extern gptr my_memdup(const byte *from,uint length,myf MyFlags); +extern gptr my_memdup(const byte *from, size_t length,myf MyFlags); extern my_string my_strdup(const char *from,myf MyFlags); extern my_string my_strndup(const char *from, size_t length, myf MyFlags); #define my_free(PTR,FG) my_no_flags_free(PTR) @@ -197,7 +197,8 @@ extern uint get_charset_number(const char *cs_name); extern const char *get_charset_name(uint cs_number); extern CHARSET_INFO *get_charset(uint cs_number, myf flags); extern my_bool set_default_charset(uint cs, myf flags); -extern CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags); +extern CHARSET_INFO *get_charset_by_name(const char *cs_name); +extern CHARSET_INFO *get_charset_by_nr(uint cs_number); extern my_bool set_default_charset_by_name(const char *cs_name, myf flags); extern void free_charsets(void); extern char *list_charsets(myf want_flags); /* my_free() this string... */ @@ -223,7 +224,7 @@ extern int NEAR my_umask, /* Default creation mask */ NEAR my_safe_to_handle_signal, /* Set when allowed to SIGTSTP */ NEAR my_dont_interrupt; /* call remember_intr when set */ extern my_bool NEAR mysys_uses_curses, my_use_symdir; -extern long lCurMemory,lMaxMemory; /* from safemalloc */ +extern size_t lCurMemory,lMaxMemory; /* from safemalloc */ extern ulong my_default_record_cache_size; extern my_bool NEAR my_disable_locking,NEAR my_disable_async_io, @@ -239,6 +240,11 @@ typedef struct wild_file_pack /* Struct to hold info when selecting files */ my_string *wild; /* Pointer to wildcards */ } WF_PACK; +struct my_rnd_struct { + unsigned long seed1,seed2,max_value; + double max_value_dbl; +}; + typedef struct st_typelib { /* Different types saved here */ uint count; /* How many types */ const char *name; /* Name of typelib */ @@ -285,7 +291,7 @@ typedef struct st_dynamic_array { typedef struct st_dynamic_string { char *str; - uint length,max_length,alloc_increment; + size_t length,max_length,alloc_increment; } DYNAMIC_STRING; @@ -363,10 +369,10 @@ typedef struct st_changeable_var { #ifndef ST_USED_MEM_DEFINED #define ST_USED_MEM_DEFINED -typedef struct st_used_mem { /* struct for once_alloc */ - struct st_used_mem *next; /* Next block in use */ - unsigned int left; /* memory left in block */ - unsigned int size; /* Size of block */ +typedef struct st_used_mem { /* struct for once_alloc */ + struct st_used_mem *next; /* Next block in use */ + size_t left; /* memory left in block */ + size_t size; /* Size of block */ } USED_MEM; typedef struct st_mem_root { @@ -423,14 +429,14 @@ extern uint my_fwrite(FILE *stream,const byte *Buffer,uint Count, myf MyFlags); extern my_off_t my_fseek(FILE *stream,my_off_t pos,int whence,myf MyFlags); extern my_off_t my_ftell(FILE *stream,myf MyFlags); -extern gptr _mymalloc(uint uSize,const char *sFile, +extern gptr _mymalloc(size_t uSize,const char *sFile, uint uLine, myf MyFlag); -extern gptr _myrealloc(gptr pPtr,uint uSize,const char *sFile, +extern gptr _myrealloc(gptr pPtr,size_t uSize,const char *sFile, uint uLine, myf MyFlag); extern gptr my_multi_malloc _VARARGS((myf MyFlags, ...)); extern void _myfree(gptr pPtr,const char *sFile,uint uLine, myf MyFlag); extern int _sanity(const char *sFile,unsigned int uLine); -extern gptr _my_memdup(const byte *from,uint length, +extern gptr _my_memdup(const byte *from, size_t length, const char *sFile, uint uLine,myf MyFlag); extern my_string _my_strdup(const char *from, const char *sFile, uint uLine, myf MyFlag); @@ -580,10 +586,10 @@ extern int find_type(my_string x,TYPELIB *typelib,uint full_name); extern void make_type(my_string to,uint nr,TYPELIB *typelib); extern const char *get_type(TYPELIB *typelib,uint nr); extern my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str, - uint init_alloc,uint alloc_increment); + size_t init_alloc, size_t alloc_increment); extern my_bool dynstr_append(DYNAMIC_STRING *str, const char *append); my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append, - uint length); + size_t length); extern my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str); extern my_bool dynstr_realloc(DYNAMIC_STRING *str, ulong additional_size); extern void dynstr_free(DYNAMIC_STRING *str); @@ -592,18 +598,18 @@ my_bool set_changeable_var(my_string str,CHANGEABLE_VAR *vars); my_bool set_changeable_varval(const char *var, ulong val, CHANGEABLE_VAR *vars); #ifdef HAVE_MLOCK -extern byte *my_malloc_lock(uint length,myf flags); +extern byte *my_malloc_lock(size_t length,myf flags); extern void my_free_lock(byte *ptr,myf flags); #else #define my_malloc_lock(A,B) my_malloc((A),(B)) #define my_free_lock(A,B) my_free((A),(B)) #endif #define alloc_root_inited(A) ((A)->min_malloc != 0) -void init_alloc_root(MEM_ROOT *mem_root, uint block_size, uint pre_alloc_size); -gptr alloc_root(MEM_ROOT *mem_root,unsigned int Size); +void init_alloc_root(MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size); +gptr alloc_root(MEM_ROOT *mem_root, size_t Size); void free_root(MEM_ROOT *root, myf MyFLAGS); char *strdup_root(MEM_ROOT *root,const char *str); -char *memdup_root(MEM_ROOT *root,const char *str,uint len); +char *memdup_root(MEM_ROOT *root,const char *str, size_t len); void load_defaults(const char *conf_file, const char **groups, int *argc, char ***argv); void free_defaults(char **argv); @@ -613,10 +619,10 @@ my_bool my_uncompress(byte *, ulong *, ulong *); byte *my_compress_alloc(const byte *packet, ulong *len, ulong *complen); ulong checksum(const byte *mem, uint count); -#if defined(_MSC_VER) && !defined(__WIN__) +#if defined(_MSC_VER) && !defined(_WIN32) extern void sleep(int sec); #endif -#ifdef __WIN__ +#ifdef _WIN32 extern my_bool have_tcpip; /* Is set if tcpip is used */ #endif diff --git a/include/mysql.h b/include/mysql.h index afd5ee072..00a1f67b8 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -20,14 +20,6 @@ #ifndef _mysql_h #define _mysql_h -#ifdef __CYGWIN__ /* CYGWIN implements a UNIX API */ -#undef WIN -#undef _WIN -#undef _WIN32 -#undef _WIN64 -#undef __WIN__ -#endif - #ifndef MYSQL_SERVER #ifdef __cplusplus extern "C" { @@ -38,25 +30,39 @@ extern "C" { #ifndef _global_h /* If not standard header */ #include #ifdef __LCC__ -#include /* For windows */ +#include /* For windows */ #endif typedef char my_bool; -#if (defined(_WIN32) || defined(_WIN64)) && !defined(__WIN__) -#define __WIN__ -#endif -#if !defined(__WIN__) + +#if !defined(_WIN32) #define STDCALL #else +#include #define STDCALL __stdcall #endif typedef char * gptr; + + +#ifndef my_socket_defined +#define my_socket_defined +#ifdef _WIN32 +#define my_socket SOCKET +#else +typedef int my_socket; +#endif +#endif +#endif +#include "mysql_com.h" +#include "mysql_version.h" +#include "my_list.h" + #ifndef ST_USED_MEM_DEFINED #define ST_USED_MEM_DEFINED -typedef struct st_used_mem { /* struct for once_alloc */ - struct st_used_mem *next; /* Next block in use */ - unsigned int left; /* memory left in block */ - unsigned int size; /* size of block */ +typedef struct st_used_mem { /* struct for once_alloc */ + struct st_used_mem *next; /* Next block in use */ + size_t left; /* memory left in block */ + size_t size; /* Size of block */ } USED_MEM; typedef struct st_mem_root { @@ -71,19 +77,6 @@ typedef struct st_mem_root { } MEM_ROOT; #endif -#ifndef my_socket_defined -#ifdef __WIN__ -#define my_socket SOCKET -#else -typedef int my_socket; -#endif -#endif -#endif -#include "mysql_com.h" -#include "mysql_version.h" -#include "my_list.h" - - extern unsigned int mysql_port; extern char *mysql_unix_port; @@ -125,12 +118,13 @@ typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */ #if defined(NO_CLIENT_LONG_LONG) typedef unsigned long my_ulonglong; -#elif defined (__WIN__) +#elif defined (_WIN32) typedef unsigned __int64 my_ulonglong; #else typedef unsigned long long my_ulonglong; #endif + #define SET_CLIENT_ERROR(a, b, c, d) \ { \ (a)->net.last_errno= (b);\ @@ -202,12 +196,18 @@ enum mysql_status { MYSQL_STATUS_READY, MYSQL_STATUS_QUIT_SENT, /* object is "destroyed" at this stage */ }; +enum mysql_protocol_type +{ + MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET, + MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY +}; + struct st_mysql_options { unsigned int connect_timeout, read_timeout, write_timeout; unsigned int port, protocol; unsigned long client_flag; char *host,*user,*password,*unix_socket,*db; - struct st_dynamic_array *init_commands; + char *init_command; char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name; char *ssl_key; /* PEM key file */ char *ssl_cert; /* PEM cert file */ @@ -222,14 +222,14 @@ struct st_mysql_options { enum mysql_option methods_to_use; char *client_ip; my_bool secure_auth; - + my_bool report_data_truncation; /* function pointers for local infile support */ int (*local_infile_init)(void **, const char *, void *); int (*local_infile_read)(void *, char *, unsigned int); void (*local_infile_end)(void *); int (*local_infile_error)(void *, char *, unsigned int); void *local_infile_userdata; - struct st_mysql_options_extension *extension; + struct st_mysql_options_extention *extension; }; typedef struct st_mysql { @@ -237,9 +237,9 @@ typedef struct st_mysql { unsigned char *connector_fd; /* ConnectorFd for SSL */ char *host,*user,*passwd,*unix_socket,*server_version,*host_info; char *info,*db; - struct charset_info_st *charset; /* character set */ - MYSQL_FIELD *fields; - MEM_ROOT field_alloc; + const struct charset_info_st *charset; /* character set */ + MYSQL_FIELD *fields; + MEM_ROOT field_alloc; my_ulonglong affected_rows; my_ulonglong insert_id; /* id if insert on table with NEXTNR */ my_ulonglong extra_info; /* Used by mysqlshow */ @@ -269,6 +269,17 @@ typedef struct st_mysql { } MYSQL; +struct st_mysql_options_extention { + char *plugin_dir; + char *default_auth; + void (*report_progress)(const MYSQL *mysql, + unsigned int stage, + unsigned int max_stage, + double progress, + const char *proc_info, + unsigned int proc_info_length); +}; + typedef struct st_mysql_res { my_ulonglong row_count; unsigned int field_count, current_field; @@ -310,7 +321,20 @@ typedef struct character_set unsigned int mbmaxlen; /* max. length for multibyte strings */ } MY_CHARSET_INFO; +/* Local infile support functions */ +#define LOCAL_INFILE_ERROR_LEN 512 + +void STDCALL mysql_set_local_infile_handler(MYSQL *mysql, + int (*local_infile_init)(void **, const char *, void *), + int (*local_infile_read)(void *, char *, unsigned int), + void (*local_infile_end)(void *), + int (*local_infile_error)(void *, char*, unsigned int), + void *); + +void mysql_set_local_infile_default(MYSQL *mysql); +void my_set_error(MYSQL *mysql, unsigned int error_nr, + const char *sqlstate, const char *format, ...); /* Functions to get information from the MYSQL and MYSQL_RES structures */ /* Should definitely be used if one uses shared libraries */ @@ -377,7 +401,6 @@ int STDCALL mysql_ping(MYSQL *mysql); char * STDCALL mysql_stat(MYSQL *mysql); char * STDCALL mysql_get_server_info(MYSQL *mysql); unsigned long STDCALL mysql_get_server_version(MYSQL *mysql); -char * STDCALL mysql_get_client_info(void); char * STDCALL mysql_get_host_info(MYSQL *mysql); unsigned int STDCALL mysql_get_proto_info(MYSQL *mysql); MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild); @@ -404,28 +427,22 @@ unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql, char *to,const char *from, unsigned long length); void STDCALL mysql_debug(const char *debug); -char * STDCALL mysql_odbc_escape_string(MYSQL *mysql, - char *to, - unsigned long to_length, - const char *from, - unsigned long from_length, - void *param, - char * - (*extend_buffer) - (void *, char *to, - unsigned long *length)); +#define mysql_debug_init(A) mysql_debug((A)); +void STDCALL mysql_debug_end(); void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name); unsigned int STDCALL mysql_thread_safe(void); unsigned int STDCALL mysql_warning_count(MYSQL *mysql); const char * STDCALL mysql_sqlstate(MYSQL *mysql); -int STDCALL mysql_server_init(int argc __attribute__((unused)), - char **argv __attribute__((unused)), - char **groups __attribute__((unused))); +int STDCALL mysql_server_init(int argc, char **argv, char **groups); void STDCALL mysql_server_end(void); void STDCALL mysql_thread_end(void); my_bool STDCALL mysql_thread_init(void); +int STDCALL mysql_set_server_option(MYSQL *mysql, + enum enum_mysql_set_option option); +const char * STDCALL mysql_get_client_info(void); +unsigned long STDCALL mysql_get_client_version(void); -#include +#include #define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT) diff --git a/include/mysql/client_plugin.h b/include/mysql/client_plugin.h new file mode 100644 index 000000000..399a4bb4b --- /dev/null +++ b/include/mysql/client_plugin.h @@ -0,0 +1,175 @@ +/* Copyright (C) 2010, 2011 Sergei Golubchik and Monty Program Ab + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA */ + +/** + @file + + MySQL Client Plugin API + + This file defines the API for plugins that work on the client side +*/ +#ifndef MYSQL_CLIENT_PLUGIN_INCLUDED +#define MYSQL_CLIENT_PLUGIN_INCLUDED + +#ifndef MYSQL_ABI_CHECK +#include +#include +#endif + +#ifndef PLUGINDIR +#define PLUGINDIR "lib/plugin" +#endif + +/* known plugin types */ +#define MYSQL_CLIENT_reserved1 0 +#define MYSQL_CLIENT_reserved2 1 +#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN 2 + +#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION 0x0100 + +#define MYSQL_CLIENT_MAX_PLUGINS 3 + +#define mysql_declare_client_plugin(X) \ + struct st_mysql_client_plugin_ ## X \ + _mysql_client_plugin_declaration_ = { \ + MYSQL_CLIENT_ ## X ## _PLUGIN, \ + MYSQL_CLIENT_ ## X ## _PLUGIN_INTERFACE_VERSION, +#define mysql_end_client_plugin } + +/* generic plugin header structure */ +#define MYSQL_CLIENT_PLUGIN_HEADER \ + int type; \ + unsigned int interface_version; \ + const char *name; \ + const char *author; \ + const char *desc; \ + unsigned int version[3]; \ + int (*init)(char *, size_t, int, va_list); \ + int (*deinit)(); + +struct st_mysql_client_plugin +{ + MYSQL_CLIENT_PLUGIN_HEADER +}; + +struct st_mysql; + +/******** authentication plugin specific declarations *********/ +#include + +struct st_mysql_client_plugin_AUTHENTICATION +{ + MYSQL_CLIENT_PLUGIN_HEADER + int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql); +}; + +/** + type of the mysql_authentication_dialog_ask function + + @param mysql mysql + @param type type of the input + 1 - ordinary string input + 2 - password string + @param prompt prompt + @param buf a buffer to store the use input + @param buf_len the length of the buffer + + @retval a pointer to the user input string. + It may be equal to 'buf' or to 'mysql->password'. + In all other cases it is assumed to be an allocated + string, and the "dialog" plugin will free() it. +*/ +typedef char *(*mysql_authentication_dialog_ask_t)(struct st_mysql *mysql, + int type, const char *prompt, char *buf, int buf_len); +/******** using plugins ************/ + +/** + loads a plugin and initializes it + + @param mysql MYSQL structure. only MYSQL_PLUGIN_DIR option value is used, + and last_errno/last_error, for error reporting + @param name a name of the plugin to load + @param type type of plugin that should be loaded, -1 to disable type check + @param argc number of arguments to pass to the plugin initialization + function + @param ... arguments for the plugin initialization function + + @retval + a pointer to the loaded plugin, or NULL in case of a failure +*/ +struct st_mysql_client_plugin * +mysql_load_plugin(struct st_mysql *mysql, const char *name, int type, + int argc, ...); + +/** + loads a plugin and initializes it, taking va_list as an argument + + This is the same as mysql_load_plugin, but take va_list instead of + a list of arguments. + + @param mysql MYSQL structure. only MYSQL_PLUGIN_DIR option value is used, + and last_errno/last_error, for error reporting + @param name a name of the plugin to load + @param type type of plugin that should be loaded, -1 to disable type check + @param argc number of arguments to pass to the plugin initialization + function + @param args arguments for the plugin initialization function + + @retval + a pointer to the loaded plugin, or NULL in case of a failure +*/ +struct st_mysql_client_plugin * +mysql_load_plugin_v(struct st_mysql *mysql, const char *name, int type, + int argc, va_list args); + +/** + finds an already loaded plugin by name, or loads it, if necessary + + @param mysql MYSQL structure. only MYSQL_PLUGIN_DIR option value is used, + and last_errno/last_error, for error reporting + @param name a name of the plugin to load + @param type type of plugin that should be loaded + + @retval + a pointer to the plugin, or NULL in case of a failure +*/ +struct st_mysql_client_plugin * +mysql_client_find_plugin(struct st_mysql *mysql, const char *name, int type); + +/** + adds a plugin structure to the list of loaded plugins + + This is useful if an application has the necessary functionality + (for example, a special load data handler) statically linked into + the application binary. It can use this function to register the plugin + directly, avoiding the need to factor it out into a shared object. + + @param mysql MYSQL structure. It is only used for error reporting + @param plugin an st_mysql_client_plugin structure to register + + @retval + a pointer to the plugin, or NULL in case of a failure +*/ +struct st_mysql_client_plugin * +mysql_client_register_plugin(struct st_mysql *mysql, + struct st_mysql_client_plugin *plugin); + +extern struct st_mysql_client_plugin *mysql_client_builtins[]; + +#endif + + diff --git a/include/mysql/plugin_auth.h b/include/mysql/plugin_auth.h new file mode 100644 index 000000000..6a43d14ff --- /dev/null +++ b/include/mysql/plugin_auth.h @@ -0,0 +1,107 @@ +#ifndef MYSQL_PLUGIN_AUTH_COMMON_INCLUDED +/* Copyright (C) 2010 Sergei Golubchik and Monty Program Ab + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +/** + @file + + This file defines constants and data structures that are the same for + both client- and server-side authentication plugins. +*/ +#define MYSQL_PLUGIN_AUTH_COMMON_INCLUDED + +/** the max allowed length for a user name */ +#define MYSQL_USERNAME_LENGTH 48 + +/** + return values of the plugin authenticate_user() method. +*/ + +/** + Authentication failed. Additionally, all other CR_xxx values + (libmysql error code) can be used too. + + The client plugin may set the error code and the error message directly + in the MYSQL structure and return CR_ERROR. If a CR_xxx specific error + code was returned, an error message in the MYSQL structure will be + overwritten. If CR_ERROR is returned without setting the error in MYSQL, + CR_UNKNOWN_ERROR will be user. +*/ +#define CR_ERROR 0 +/** + Authentication (client part) was successful. It does not mean that the + authentication as a whole was successful, usually it only means + that the client was able to send the user name and the password to the + server. If CR_OK is returned, the libmysql reads the next packet expecting + it to be one of OK, ERROR, or CHANGE_PLUGIN packets. +*/ +#define CR_OK -1 +/** + Authentication was successful. + It means that the client has done its part successfully and also that + a plugin has read the last packet (one of OK, ERROR, CHANGE_PLUGIN). + In this case, libmysql will not read a packet from the server, + but it will use the data at mysql->net.read_pos. + + A plugin may return this value if the number of roundtrips in the + authentication protocol is not known in advance, and the client plugin + needs to read one packet more to determine if the authentication is finished + or not. +*/ +#define CR_OK_HANDSHAKE_COMPLETE -2 + +typedef struct st_plugin_vio_info +{ + enum { MYSQL_VIO_INVALID, MYSQL_VIO_TCP, MYSQL_VIO_SOCKET, + MYSQL_VIO_PIPE, MYSQL_VIO_MEMORY } protocol; + int socket; /**< it's set, if the protocol is SOCKET or TCP */ +#ifdef _WIN32 + HANDLE handle; /**< it's set, if the protocol is PIPE or MEMORY */ +#endif +} MYSQL_PLUGIN_VIO_INFO; + +/** + Provides plugin access to communication channel +*/ +typedef struct st_plugin_vio +{ + /** + Plugin provides a pointer reference and this function sets it to the + contents of any incoming packet. Returns the packet length, or -1 if + the plugin should terminate. + */ + int (*read_packet)(struct st_plugin_vio *vio, + unsigned char **buf); + + /** + Plugin provides a buffer with data and the length and this + function sends it as a packet. Returns 0 on success, 1 on failure. + */ + int (*write_packet)(struct st_plugin_vio *vio, + const unsigned char *packet, + int packet_len); + + /** + Fills in a st_plugin_vio_info structure, providing the information + about the connection. + */ + void (*info)(struct st_plugin_vio *vio, struct st_plugin_vio_info *info); + +} MYSQL_PLUGIN_VIO; + +#endif + diff --git a/include/mysql/plugin_auth_common.h b/include/mysql/plugin_auth_common.h new file mode 100644 index 000000000..6a43d14ff --- /dev/null +++ b/include/mysql/plugin_auth_common.h @@ -0,0 +1,107 @@ +#ifndef MYSQL_PLUGIN_AUTH_COMMON_INCLUDED +/* Copyright (C) 2010 Sergei Golubchik and Monty Program Ab + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +/** + @file + + This file defines constants and data structures that are the same for + both client- and server-side authentication plugins. +*/ +#define MYSQL_PLUGIN_AUTH_COMMON_INCLUDED + +/** the max allowed length for a user name */ +#define MYSQL_USERNAME_LENGTH 48 + +/** + return values of the plugin authenticate_user() method. +*/ + +/** + Authentication failed. Additionally, all other CR_xxx values + (libmysql error code) can be used too. + + The client plugin may set the error code and the error message directly + in the MYSQL structure and return CR_ERROR. If a CR_xxx specific error + code was returned, an error message in the MYSQL structure will be + overwritten. If CR_ERROR is returned without setting the error in MYSQL, + CR_UNKNOWN_ERROR will be user. +*/ +#define CR_ERROR 0 +/** + Authentication (client part) was successful. It does not mean that the + authentication as a whole was successful, usually it only means + that the client was able to send the user name and the password to the + server. If CR_OK is returned, the libmysql reads the next packet expecting + it to be one of OK, ERROR, or CHANGE_PLUGIN packets. +*/ +#define CR_OK -1 +/** + Authentication was successful. + It means that the client has done its part successfully and also that + a plugin has read the last packet (one of OK, ERROR, CHANGE_PLUGIN). + In this case, libmysql will not read a packet from the server, + but it will use the data at mysql->net.read_pos. + + A plugin may return this value if the number of roundtrips in the + authentication protocol is not known in advance, and the client plugin + needs to read one packet more to determine if the authentication is finished + or not. +*/ +#define CR_OK_HANDSHAKE_COMPLETE -2 + +typedef struct st_plugin_vio_info +{ + enum { MYSQL_VIO_INVALID, MYSQL_VIO_TCP, MYSQL_VIO_SOCKET, + MYSQL_VIO_PIPE, MYSQL_VIO_MEMORY } protocol; + int socket; /**< it's set, if the protocol is SOCKET or TCP */ +#ifdef _WIN32 + HANDLE handle; /**< it's set, if the protocol is PIPE or MEMORY */ +#endif +} MYSQL_PLUGIN_VIO_INFO; + +/** + Provides plugin access to communication channel +*/ +typedef struct st_plugin_vio +{ + /** + Plugin provides a pointer reference and this function sets it to the + contents of any incoming packet. Returns the packet length, or -1 if + the plugin should terminate. + */ + int (*read_packet)(struct st_plugin_vio *vio, + unsigned char **buf); + + /** + Plugin provides a buffer with data and the length and this + function sends it as a packet. Returns 0 on success, 1 on failure. + */ + int (*write_packet)(struct st_plugin_vio *vio, + const unsigned char *packet, + int packet_len); + + /** + Fills in a st_plugin_vio_info structure, providing the information + about the connection. + */ + void (*info)(struct st_plugin_vio *vio, struct st_plugin_vio_info *info); + +} MYSQL_PLUGIN_VIO; + +#endif + diff --git a/include/mysql_com.h b/include/mysql_com.h index 726da3978..9a31183df 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -32,19 +32,21 @@ #define NAME_CHAR_LEN 64 #define NAME_LEN 256 /* Field/table name length */ #define HOSTNAME_LENGTH 60 +#define SYSTEM_MB_MAX_CHAR_LENGTH 3 #define USERNAME_CHAR_LENGTH 16 -#define USERNAME_LENGTH 64 +#define USERNAME_LENGTH USERNAME_CHAR_LENGTH * SYSTEM_MB_MAX_CHAR_LENGTH #define SERVER_VERSION_LENGTH 60 #define SQLSTATE_LENGTH 5 #define SCRAMBLE_LENGTH 20 +#define SCRAMBLE_LENGTH_323 8 #define LOCAL_HOST "localhost" #define LOCAL_HOST_NAMEDPIPE "." -#if defined(__WIN__) && !defined( _CUSTOMCONFIG_) +#if defined(_WIN32) && !defined( _CUSTOMCONFIG_) #define MYSQL_NAMEDPIPE "MySQL" #define MYSQL_SERVICENAME "MySql" -#endif /* __WIN__ */ +#endif /* _WIN32 */ enum enum_server_command @@ -96,6 +98,10 @@ enum enum_server_command #define AUTO_INCREMENT_FLAG 512 /* field is a autoincrement field */ #define TIMESTAMP_FLAG 1024 /* Field is a timestamp */ #define SET_FLAG 2048 /* field is a set */ +/* new since 3.23.58 */ +#define NO_DEFAULT_VALUE_FLAG 4096 /* Field doesn't have default value */ +#define ON_UPDATE_NOW_FLAG 8192 /* Field is set to NOW on UPDATE */ +/* end new */ #define NUM_FLAG 32768 /* Field is num (for clients) */ #define PART_KEY_FLAG 16384 /* Intern; Part of some key */ #define GROUP_FLAG 32768 /* Intern: Group field */ @@ -136,6 +142,7 @@ enum enum_server_command #define CLIENT_MULTI_STATEMENTS (1UL << 16) #define CLIENT_MULTI_RESULTS (1UL << 17) #define CLIENT_PS_MULTI_RESULTS (1UL << 18) +#define CLIENT_PLUGIN_AUTH (1UL << 19) #define CLIENT_PROGRESS (1UL << 29) /* client supports progress indicator */ #define CLIENT_SUPPORTED_FLAGS (CLIENT_LONG_PASSWORD | \ @@ -159,6 +166,15 @@ enum enum_server_command CLIENT_MULTI_RESULTS |\ CLIENT_PROGRESS) +#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD |\ + CLIENT_LONG_FLAG |\ + CLIENT_TRANSACTIONS |\ + CLIENT_SECURE_CONNECTION |\ + CLIENT_MULTI_RESULTS | \ + CLIENT_PS_MULTI_RESULTS |\ + CLIENT_PROTOCOL_41 |\ + CLIENT_PLUGIN_AUTH) + #define CLIENT_DEFAULT_FLAGS ((CLIENT_SUPPORTED_FLAGS & ~CLIENT_COMPRESS)\ & ~CLIENT_SSL) @@ -222,6 +238,13 @@ typedef struct st_net { #define packet_error ((unsigned int) -1) +/* used by mysql_set_server_option */ +enum enum_mysql_set_option +{ + MYSQL_OPTION_MULTI_STATEMENTS_ON, + MYSQL_OPTION_MULTI_STATEMENTS_OFF +}; + enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY, MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG, MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE, @@ -245,6 +268,32 @@ enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY, #define FIELD_TYPE_CHAR FIELD_TYPE_TINY /* For compability */ #define FIELD_TYPE_INTERVAL FIELD_TYPE_ENUM /* For compability */ +#define FIELD_TYPE_DECIMAL MYSQL_TYPE_DECIMAL +#define FIELD_TYPE_NEWDECIMAL MYSQL_TYPE_NEWDECIMAL +#define FIELD_TYPE_TINY MYSQL_TYPE_TINY +#define FIELD_TYPE_SHORT MYSQL_TYPE_SHORT +#define FIELD_TYPE_LONG MYSQL_TYPE_LONG +#define FIELD_TYPE_FLOAT MYSQL_TYPE_FLOAT +#define FIELD_TYPE_DOUBLE MYSQL_TYPE_DOUBLE +#define FIELD_TYPE_NULL MYSQL_TYPE_NULL +#define FIELD_TYPE_TIMESTAMP MYSQL_TYPE_TIMESTAMP +#define FIELD_TYPE_LONGLONG MYSQL_TYPE_LONGLONG +#define FIELD_TYPE_INT24 MYSQL_TYPE_INT24 +#define FIELD_TYPE_DATE MYSQL_TYPE_DATE +#define FIELD_TYPE_TIME MYSQL_TYPE_TIME +#define FIELD_TYPE_DATETIME MYSQL_TYPE_DATETIME +#define FIELD_TYPE_YEAR MYSQL_TYPE_YEAR +#define FIELD_TYPE_NEWDATE MYSQL_TYPE_NEWDATE +#define FIELD_TYPE_ENUM MYSQL_TYPE_ENUM +#define FIELD_TYPE_SET MYSQL_TYPE_SET +#define FIELD_TYPE_TINY_BLOB MYSQL_TYPE_TINY_BLOB +#define FIELD_TYPE_MEDIUM_BLOB MYSQL_TYPE_MEDIUM_BLOB +#define FIELD_TYPE_LONG_BLOB MYSQL_TYPE_LONG_BLOB +#define FIELD_TYPE_BLOB MYSQL_TYPE_BLOB +#define FIELD_TYPE_VAR_STRING MYSQL_TYPE_VAR_STRING +#define FIELD_TYPE_STRING MYSQL_TYPE_STRING +#define FIELD_TYPE_GEOMETRY MYSQL_TYPE_GEOMETRY +#define FIELD_TYPE_BIT MYSQL_TYPE_BIT extern unsigned long max_allowed_packet; extern unsigned long net_buffer_length; @@ -255,11 +304,11 @@ int my_net_init(NET *net, Vio *vio); void net_end(NET *net); void net_clear(NET *net); int net_flush(NET *net); -int my_net_write(NET *net,const char *packet,unsigned long len); +int my_net_write(NET *net,const char *packet, size_t len); int net_write_command(NET *net,unsigned char command,const char *packet, - unsigned long len); + size_t len); int net_real_write(NET *net,const char *packet,unsigned long len); -ulong my_net_read(NET *net); +unsigned long my_net_read(NET *net); struct rand_struct { unsigned long seed1,seed2,max_value; @@ -295,6 +344,8 @@ typedef struct st_udf_init #define COMP_HEADER_SIZE 3 /* compression header extra size */ /* Prototypes to password functions */ +#define native_password_plugin_name "mysql_native_password" +#define old_password_plugin_name "mysql_old_password" #ifdef __cplusplus extern "C" { @@ -306,13 +357,12 @@ double rnd(struct rand_struct *); void make_scrambled_password(char *to,const char *password); void get_salt_from_password(unsigned long *res,const char *password); void make_password_from_salt(char *to, unsigned long *hash_res); -char *scramble(char *to,const char *message,const char *password, - my_bool old_ver); +char *scramble_323(char *to,const char *message,const char *password); void my_scramble_41(const unsigned char *buffer, const char *scramble, const char *password); my_bool check_scramble(const char *, const char *message, unsigned long *salt,my_bool old_ver); char *get_tty_password(char *opt_message); -void hash_password(unsigned long *result, const char *password); +void hash_password(unsigned long *result, const char *password, size_t len); /* Some other useful functions */ diff --git a/include/mysql_version.h b/include/mysql_version.h deleted file mode 100644 index 16b53d945..000000000 --- a/include/mysql_version.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright Abandoned 1996, 1999, 2001 MySQL AB - This file is public domain and comes with NO WARRANTY of any kind */ - -/* Version numbers for protocol & mysqld */ - -#ifdef _CUSTOMCONFIG_ -#include -#else -#define PROTOCOL_VERSION 10 -#define MYSQL_SERVER_VERSION "3.23.59" -#define MYSQL_SERVER_SUFFIX "" -#define FRM_VER -#define MYSQL_VERSION_ID 32359 -#define MYSQL_PORT 3306 -#define MYSQL_UNIX_ADDR "" -#define MYSQL_CONFIG_NAME "my" - -/* mysqld compile time options */ -#ifndef MYSQL_CHARSET -#define MYSQL_CHARSET "" -#endif -#endif - diff --git a/include/mysql_version.h.in b/include/mysql_version.h.in index 06232342c..d35712751 100644 --- a/include/mysql_version.h.in +++ b/include/mysql_version.h.in @@ -7,6 +7,7 @@ #include #else #define PROTOCOL_VERSION @PROTOCOL_VERSION@ +#define MYSQL_CLIENT_VERSION "@MYSQL_CLIENT_VERSION@" #define MYSQL_SERVER_VERSION "@MYSQL_CLIENT_VERSION@" #define MYSQL_SERVER_SUFFIX "@MYSQL_SERVER_SUFFIX@" #define FRM_VER @DOT_FRM_VERSION@ diff --git a/include/mysqld_error.h b/include/mysqld_error.h index f0fb11c18..4c88efe03 100644 --- a/include/mysqld_error.h +++ b/include/mysqld_error.h @@ -1,20 +1,5 @@ -/* Copyright (C) 2000 MySQL AB - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -/* Definefile for error messagenumbers */ +/* This file is automaticly generated from errmsg.sys ; Do not edit! */ +/* mysqld server error messagenumbers */ #define ER_HASHCHK 1000 #define ER_NISAMCHK 1001 diff --git a/include/sha1.h b/include/sha1.h index 0c4efc01a..79743af5a 100644 --- a/include/sha1.h +++ b/include/sha1.h @@ -35,7 +35,7 @@ typedef struct { } MYSQL_SHA1_CTX; void MYSQL_SHA1Init(MYSQL_SHA1_CTX *); -void MYSQL_SHA1Update(MYSQL_SHA1_CTX *, const unsigned char *, unsigned int); +void MYSQL_SHA1Update(MYSQL_SHA1_CTX *, const unsigned char *, size_t); void MYSQL_SHA1Final(unsigned char[20], MYSQL_SHA1_CTX *); #endif diff --git a/include/thr_alarm.h b/include/thr_alarm.h index 1f3fed1d2..c14deb0cb 100644 --- a/include/thr_alarm.h +++ b/include/thr_alarm.h @@ -59,7 +59,7 @@ typedef struct st_thr_alarm_entry #define thr_end_alarm(A) #else -#if defined(__WIN__) +#if defined(_WIN32) typedef struct st_thr_alarm_entry { rf_SetTimer crono; @@ -79,7 +79,7 @@ typedef int thr_alarm_entry; #define thr_got_alarm(thr_alarm) (**(thr_alarm)) -#endif /* __WIN__ */ +#endif /* _WIN32 */ typedef thr_alarm_entry* thr_alarm_t; diff --git a/include/violite.h b/include/violite.h index 49df6994d..0ee6204a9 100644 --- a/include/violite.h +++ b/include/violite.h @@ -23,6 +23,8 @@ #ifndef vio_violite_h_ #define vio_violite_h_ + + #include "my_net.h" /* needed because of struct in_addr */ #ifdef HAVE_VIO @@ -47,7 +49,7 @@ enum enum_vio_type { VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, Vio* vio_new(my_socket sd, enum enum_vio_type type, my_bool localhost); -#ifdef __WIN__ +#ifdef _WIN32 Vio* vio_new_win32pipe(HANDLE hPipe); #endif void vio_delete(Vio* vio); @@ -92,6 +94,10 @@ const char* vio_description( Vio* vio); /* Return the type of the connection */ enum enum_vio_type vio_type(Vio* vio); +/* set timeout */ +void vio_read_timeout(Vio *vio, uint seconds); +void vio_write_timeout(Vio *vio, uint seconds); + /* Return last error number */ int vio_errno(Vio *vio); @@ -110,6 +116,23 @@ void vio_in_addr(Vio *vio, struct in_addr *in); /* Return 1 if there is data to be read */ my_bool vio_poll_read(Vio *vio,uint timeout); + +#ifndef _WIN32 +#define HANDLE void * +#endif + +struct st_vio +{ + my_socket sd; /* my_socket - real or imaginary */ + HANDLE hPipe; + my_bool localhost; /* Are we from localhost? */ + int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */ + struct sockaddr_in local; /* Local internet address */ + struct sockaddr_in remote; /* Remote internet address */ + enum enum_vio_type type; /* Type of connection */ + char desc[30]; /* String description */ +}; + #ifdef __cplusplus } #endif diff --git a/libmysql/CMakeLists.txt b/libmysql/CMakeLists.txt old mode 100755 new mode 100644 index 725d61d88..3d56b9d55 --- a/libmysql/CMakeLists.txt +++ b/libmysql/CMakeLists.txt @@ -1,21 +1,98 @@ -INCLUDE_DIRECTORIES(BEFORE SYSTEM - ${CMAKE_SOURCE_DIR}/include +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include + ${CMAKE_SOURCE_DIR}/zlib ${CMAKE_SOURCE_DIR}/libmysql) +SET(LIBMYSQL_VERSION "16.0.0") + ADD_DEFINITIONS(-D ENABLED_LOCAL_INFILE) ADD_DEFINITIONS(-D HAVE_COMPRESS) +ADD_DEFINITIONS(-D THREAD) -SET(LIBMYSQL_SOURCES array.c bchange.c bmove.c bmove_upp.c mysql_charset.c violite.c net.c charset.c conf_to_src.c ctype.c dbug.c default.c errmsg.c - errors.c getopt1.c getopt.c get_password.c getvar.c hash.c int2str.c is_prefix.c libmysql.c list.c - llstr.c longlong2str.c mf_cache.c mf_casecnv.c mf_dirname.c mf_fn_ext.c mf_format.c - mf_iocache.c mf_loadpath.c mf_pack.c mf_path.c mf_tempfile.c mf_unixpath.c mf_wcomp.c mulalloc.c - my_alloc.c my_compress.c my_create.c my_delete.c my_div.c my_error.c my_fopen.c my_fstream.c - my_gethostbyname.c my_getwd.c my_init.c my_lib.c my_malloc.c my_messnc.c my_net.c - my_once.c my_open.c my_port.c my_pread.c my_pthread.c my_read.c my_realloc.c my_seek.c my_static.c - my_symlink.c my_thr_init.c my_write.c password.c safemalloc.c str2int.c strcend.c strcont.c - strend.c strfill.c string.c strinstr.c strmake.c strmov.c strnlen.c strnmov.c - strtoll.c strtoull.c strxmov.c thr_mutex.c typelib.c sha1.c mysql_stmt.c mysql_stmt_codec.c) +SET(LIBMYSQL_SOURCES array.c bchange.c bmove.c bmove_upp.c my_charset.c + violite.c net.c charset.c dbug.c default.c + errmsg.c my_vsnprintf.c errors.c getopt1.c getopt.c + get_password.c int2str.c is_prefix.c + libmysql.c list.c llstr.c longlong2str.c + mf_dirname.c mf_fn_ext.c mf_format.c + mf_loadpath.c mf_pack.c mf_path.c + mf_tempfile.c mf_unixpath.c mf_wcomp.c mulalloc.c + my_alloc.c my_compress.c my_create.c my_delete.c my_div.c + my_error.c my_fopen.c my_fstream.c my_gethostbyname.c + my_getwd.c my_init.c my_lib.c my_malloc.c my_messnc.c + my_net.c my_once.c my_open.c my_port.c + my_pthread.c my_read.c my_realloc.c my_seek.c my_static.c + my_symlink.c my_thr_init.c my_write.c password.c + safemalloc.c str2int.c strcend.c strcont.c + strend.c strfill.c string.c strinstr.c strmake.c + strmov.c strnmov.c strtoll.c strtoull.c + strxmov.c strxnmov.c thr_mutex.c typelib.c sha1.c my_stmt.c + my_loaddata.c my_stmt_codec.c client_plugin.c my_auth.c) ADD_LIBRARY(mysqlclient STATIC ${LIBMYSQL_SOURCES}) -TARGET_LINK_LIBRARIES(mysqlclient m zlib) +TARGET_LINK_LIBRARIES(mysqlclient ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS} zlib) + +IF(UNIX) + TARGET_LINK_LIBRARIES(mysqlclient m) +ENDIF(UNIX) + +ADD_LIBRARY(libmysql SHARED ${LIBMYSQL_SOURCES}) +TARGET_LINK_LIBRARIES(libmysql ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS} zlib) + +IF(WIN32) + TARGET_LINK_LIBRARIES(libmysql ws2_32) + TARGET_LINK_LIBRARIES(mysqlclient ws2_32) +ENDIF(WIN32) + +IF(OPENSSL_LIBRARIES) + TARGET_LINK_LIBRARIES(mysqlclient ${SSL_LIBRARIES}) + TARGET_LINK_LIBRARIES(libmysql ${SSL_LIBRARIES}) +ENDIF(OPENSSL_LIBRARIES) + +IF(NOT WIN32) + # we don't want a liblibmysql + SET_TARGET_PROPERTIES(libmysql PROPERTIES PREFIX "") +ENDIF(NOT WIN32) + +# remove decimal points +STRING(REGEX REPLACE "\\..+" "" LIBMYSQL_SO_VERSION ${LIBMYSQL_VERSION}) +SET_TARGET_PROPERTIES(libmysql PROPERTIES VERSION ${LIBMYSQL_VERSION} + SOVERSION ${LIBMYSQL_SO_VERSION}) + +IF(NOT WIN32) + ADD_CUSTOM_COMMAND(OUTPUT "libmysqlclient${CMAKE_SHARED_LIBRARY_SUFFIX}" + "libmysqlclient_r${CMAKE_SHARED_LIBRARY_SUFFIX}" + COMMAND ${CMAKE_COMMAND} ARGS -E remove -f libmysqlclient${CMAKE_SHARED_LIBRARY_SUFFIX} + COMMAND ${CMAKE_COMMAND} ARGS -E create_symlink libmysql${CMAKE_SHARED_LIBRARY_SUFFIX} libmysqlclient${CMAKE_SHARED_LIBRARY_SUFFIX} + COMMAND ${CMAKE_COMMAND} ARGS -E remove -f libmysqlclient_r${CMAKE_SHARED_LIBRARY_SUFFIX} + COMMAND ${CMAKE_COMMAND} ARGS -E create_symlink libmysql${CMAKE_SHARED_LIBRARY_SUFFIX} libmysqlclient_r${CMAKE_SHARED_LIBRARY_SUFFIX} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/libmysql + DEPENDS libmysql) + + ADD_CUSTOM_TARGET(LIBMYSQL_SYMLINKS + ALL + DEPENDS "libmysqlclient${CMAKE_SHARED_LIBRARY_SUFFIX}" + "libmysqlclient_r${CMAKE_SHARED_LIBRARY_SUFFIX}") +ENDIF(NOT WIN32) + +# +# Installation +# +IF(WIN32) + INSTALL(TARGETS + libmysql mysqlclient + RUNTIME DESTINATION "lib" + LIBRARY DESTINATION "lib" + ARCHIVE DESTINATION "lib") +ELSE(WIN32) + INSTALL(TARGETS + libmysql mysqlclient + LIBRARY DESTINATION "lib" + ARCHIVE DESTINATION "lib") + INSTALL(FILES ${CMAKE_BINARY_DIR}/libmysql/libmysqlclient${CMAKE_SHARED_LIBRARY_SUFFIX} + ${CMAKE_BINARY_DIR}/libmysql/libmysqlclient_r${CMAKE_SHARED_LIBRARY_SUFFIX} + DESTINATION "lib") +ENDIF(WIN32) + +INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include + DESTINATION .) diff --git a/libmysql/array.c b/libmysql/array.c index cf1630499..addfa2467 100644 --- a/libmysql/array.c +++ b/libmysql/array.c @@ -17,7 +17,7 @@ /* Handling of arrays that can grow dynamicly. */ -#ifdef __WIN__) +#ifdef _WIN32 #undef SAFEMALLOC /* Problems with threads */ #endif diff --git a/libmysql/bchange.c b/libmysql/bchange.c index 68b1434de..f71bcf531 100644 --- a/libmysql/bchange.c +++ b/libmysql/bchange.c @@ -28,9 +28,9 @@ #include #include "m_string.h" -void bchange(register char *dst, uint old_length, register const char *src, uint new_length, uint tot_length) +void bchange(register char *dst, size_t old_length, register const char *src, size_t new_length, size_t tot_length) { - uint rest=tot_length-old_length; + size_t rest=tot_length-old_length; if (old_length < new_length) bmove_upp(dst+rest+new_length,dst+tot_length,rest); else diff --git a/libmysql/bmove_upp.c b/libmysql/bmove_upp.c index 5b8f27385..92df08ecb 100644 --- a/libmysql/bmove_upp.c +++ b/libmysql/bmove_upp.c @@ -30,7 +30,7 @@ #if defined(MC68000) && defined(DS90) /* 0 <= len <= 65535 */ -void bmove_upp(byte *dst, const byte *src,uint len) +void bmove_upp(byte *dst, const byte *src, size_t len) { asm(" movl 12(a7),d0 "); asm(" subql #1,d0 "); @@ -43,7 +43,7 @@ asm(".L5: "); } #else -void bmove_upp(register char *dst, register const char *src, register uint len) +void bmove_upp(register char *dst, register const char *src, register size_t len) { while (len-- != 0) *--dst = *--src; } diff --git a/libmysql/charset.c b/libmysql/charset.c index dc723243d..66c28d977 100644 --- a/libmysql/charset.c +++ b/libmysql/charset.c @@ -21,16 +21,16 @@ #include #include +CHARSET_INFO *default_charset_info = (CHARSET_INFO *)&compiled_charsets[5]; - -CHARSET_INFO *get_charset(uint cs_number, myf flags) +CHARSET_INFO *get_charset_by_nr(uint cs_number) { int i= 0; while (compiled_charsets[i].nr && cs_number != compiled_charsets[i].nr) i++; - return (compiled_charsets[i].nr) ? &compiled_charsets[i] : NULL; + return (compiled_charsets[i].nr) ? (CHARSET_INFO *)&compiled_charsets[i] : NULL; } my_bool set_default_charset(uint cs, myf flags) @@ -38,7 +38,7 @@ my_bool set_default_charset(uint cs, myf flags) CHARSET_INFO *new_charset; DBUG_ENTER("set_default_charset"); DBUG_PRINT("enter",("character set: %d",(int) cs)); - new_charset = get_charset(cs, flags); + new_charset = get_charset_by_nr(cs); if (!new_charset) { DBUG_PRINT("error",("Couldn't set default character set")); @@ -48,14 +48,14 @@ my_bool set_default_charset(uint cs, myf flags) DBUG_RETURN(FALSE); } -CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags) +CHARSET_INFO *get_charset_by_name(const char *cs_name) { int i= 0; - while (compiled_charsets[i].nr && strcmp(cs_name, compiled_charsets[i].name) != NULL) + while (compiled_charsets[i].nr && strcmp(cs_name, compiled_charsets[i].name) != 0) i++; - return (compiled_charsets[i].nr) ? &compiled_charsets[i] : NULL; + return (compiled_charsets[i].nr) ? (CHARSET_INFO *)&compiled_charsets[i] : NULL; } my_bool set_default_charset_by_name(const char *cs_name, myf flags) @@ -63,7 +63,7 @@ my_bool set_default_charset_by_name(const char *cs_name, myf flags) CHARSET_INFO *new_charset; DBUG_ENTER("set_default_charset_by_name"); DBUG_PRINT("enter",("character set: %s", cs_name)); - new_charset = get_charset_by_name(cs_name, flags); + new_charset = get_charset_by_name(cs_name); if (!new_charset) { DBUG_PRINT("error",("Couldn't set default character set")); diff --git a/libmysql/client_plugin.c b/libmysql/client_plugin.c new file mode 100644 index 000000000..26a04705a --- /dev/null +++ b/libmysql/client_plugin.c @@ -0,0 +1,459 @@ +/* Copyright (C) 2010, 2011 Sergei Golubchik and Monty Program Ab + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA */ + +/** + @file + + Support code for the client side (libmysql) plugins + + Client plugins are somewhat different from server plugins, they are simpler. + + They do not need to be installed or in any way explicitly loaded on the + client, they are loaded automatically on demand. + One client plugin per shared object, soname *must* match the plugin name. + + There is no reference counting and no unloading either. +*/ + +#if _MSC_VER +/* Silence warnings about variable 'unused' being used. */ +#define FORCE_INIT_OF_VARS 1 +#endif + +#include +#include "mysql.h" +#include +#include +#ifdef THREAD +#include +#else +#include +#endif + +#include "errmsg.h" +#include + +struct st_client_plugin_int { + struct st_client_plugin_int *next; + void *dlhandle; + struct st_mysql_client_plugin *plugin; +}; + +static my_bool initialized= 0; +static MEM_ROOT mem_root; + +#define plugin_declarations_sym "_mysql_client_plugin_declaration_" + +static uint plugin_version[MYSQL_CLIENT_MAX_PLUGINS]= +{ + 0, /* these two are taken by Connector/C */ + 0, /* these two are taken by Connector/C */ + MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION +}; + +/* + Loaded plugins are stored in a linked list. + The list is append-only, the elements are added to the head (like in a stack). + The elements are added under a mutex, but the list can be read and traversed + without any mutex because once an element is added to the list, it stays + there. The main purpose of a mutex is to prevent two threads from + loading the same plugin twice in parallel. +*/ +struct st_client_plugin_int *plugin_list[MYSQL_CLIENT_MAX_PLUGINS]; +#ifdef THREAD +static pthread_mutex_t LOCK_load_client_plugin; +#endif + +static int is_not_initialized(MYSQL *mysql, const char *name) +{ + if (initialized) + return 0; + + my_set_error(mysql, CR_AUTH_PLUGIN_CANNOT_LOAD, + SQLSTATE_UNKNOWN, ER(CR_AUTH_PLUGIN_CANNOT_LOAD), + name, "not initialized"); + return 1; +} + + +/** + finds a plugin in the list + + @param name plugin name to search for + @param type plugin type + + @note this does NOT necessarily need a mutex, take care! + + @retval a pointer to a found plugin or 0 +*/ + +static struct st_mysql_client_plugin *find_plugin(const char *name, int type) +{ + struct st_client_plugin_int *p; + + DBUG_ASSERT(initialized); + DBUG_ASSERT(type >= 0 && type < MYSQL_CLIENT_MAX_PLUGINS); + if (type < 0 || type >= MYSQL_CLIENT_MAX_PLUGINS) + return 0; + + for (p= plugin_list[type]; p; p= p->next) + { + if (strcmp(p->plugin->name, name) == 0) + return p->plugin; + } + return NULL; +} + + +/** + verifies the plugin and adds it to the list + + @param mysql MYSQL structure (for error reporting) + @param plugin plugin to install + @param dlhandle a handle to the shared object (returned by dlopen) + or 0 if the plugin was not dynamically loaded + @param argc number of arguments in the 'va_list args' + @param args arguments passed to the plugin initialization function + + @retval a pointer to an installed plugin or 0 +*/ + +static struct st_mysql_client_plugin * +add_plugin(MYSQL *mysql, struct st_mysql_client_plugin *plugin, void *dlhandle, + int argc, va_list args) +{ + const char *errmsg; + struct st_client_plugin_int plugin_int, *p; + char errbuf[1024]; + + DBUG_ASSERT(initialized); + + plugin_int.plugin= plugin; + plugin_int.dlhandle= dlhandle; + + if (plugin->type >= MYSQL_CLIENT_MAX_PLUGINS) + { + errmsg= "Unknown client plugin type"; + goto err1; + } + + if (plugin->interface_version < plugin_version[plugin->type] || + (plugin->interface_version >> 8) > + (plugin_version[plugin->type] >> 8)) + { + errmsg= "Incompatible client plugin interface"; + goto err1; + } + + /* Call the plugin initialization function, if any */ + if (plugin->init && plugin->init(errbuf, sizeof(errbuf), argc, args)) + { + errmsg= errbuf; + goto err1; + } + + p= (struct st_client_plugin_int *) + memdup_root(&mem_root, (char *)&plugin_int, sizeof(plugin_int)); + + if (!p) + { + errmsg= "Out of memory"; + goto err2; + } + + safe_mutex_assert_owner(&LOCK_load_client_plugin); + + p->next= plugin_list[plugin->type]; + plugin_list[plugin->type]= p; + + return plugin; + +err2: + if (plugin->deinit) + plugin->deinit(); +err1: + if (dlhandle) + (void)dlclose(dlhandle); + my_set_error(mysql, CR_AUTH_PLUGIN_CANNOT_LOAD, SQLSTATE_UNKNOWN, + ER(CR_AUTH_PLUGIN_CANNOT_LOAD), plugin->name, errmsg); + return NULL; +} + + +/** + Loads plugins which are specified in the environment variable + LIBMYSQL_PLUGINS. + + Multiple plugins must be separated by semicolon. This function doesn't + return or log an error. + + The function is be called by mysql_client_plugin_init + + @todo + Support extended syntax, passing parameters to plugins, for example + LIBMYSQL_PLUGINS="plugin1(param1,param2);plugin2;..." + or + LIBMYSQL_PLUGINS="plugin1=int:param1,str:param2;plugin2;..." +*/ + +static void load_env_plugins(MYSQL *mysql) +{ + char *plugs, *free_env, *s= getenv("LIBMYSQL_PLUGINS"); + + /* no plugins to load */ + if (!s) + return; + + free_env= plugs= my_strdup(s, MYF(MY_WME)); + + do { + if ((s= strchr(plugs, ';'))) + *s= '\0'; + mysql_load_plugin(mysql, plugs, -1, 0); + plugs= s + 1; + } while (s); + + my_free(free_env, MYF(0)); +} + +/********** extern functions to be used by libmysql *********************/ + +/** + Initializes the client plugin layer. + + This function must be called before any other client plugin function. + + @retval 0 successful + @retval != 0 error occured +*/ + +int mysql_client_plugin_init() +{ + MYSQL mysql; + struct st_mysql_client_plugin **builtin; + va_list unused; + LINT_INIT_STRUCT(unused); + + if (initialized) + return 0; + + bzero(&mysql, sizeof(mysql)); /* dummy mysql for set_mysql_extended_error */ + + pthread_mutex_init(&LOCK_load_client_plugin, MY_MUTEX_INIT_SLOW); + init_alloc_root(&mem_root, 128, 128); + + bzero(&plugin_list, sizeof(plugin_list)); + + initialized= 1; + + pthread_mutex_lock(&LOCK_load_client_plugin); + + for (builtin= mysql_client_builtins; *builtin; builtin++) + add_plugin(&mysql, *builtin, 0, 0, unused); + + pthread_mutex_unlock(&LOCK_load_client_plugin); + + load_env_plugins(&mysql); + + return 0; +} + + +/** + Deinitializes the client plugin layer. + + Unloades all client plugins and frees any associated resources. +*/ + +void mysql_client_plugin_deinit() +{ + int i; + struct st_client_plugin_int *p; + + if (!initialized) + return; + + for (i=0; i < MYSQL_CLIENT_MAX_PLUGINS; i++) + for (p= plugin_list[i]; p; p= p->next) + { + if (p->plugin->deinit) + p->plugin->deinit(); + if (p->dlhandle) + (void)dlclose(p->dlhandle); + } + + bzero(&plugin_list, sizeof(plugin_list)); + initialized= 0; + free_root(&mem_root, MYF(0)); + pthread_mutex_destroy(&LOCK_load_client_plugin); +} + +/************* public facing functions, for client consumption *********/ + +/* see for a full description */ +struct st_mysql_client_plugin * +mysql_client_register_plugin(MYSQL *mysql, + struct st_mysql_client_plugin *plugin) +{ + va_list unused; + LINT_INIT_STRUCT(unused); + + if (is_not_initialized(mysql, plugin->name)) + return NULL; + + pthread_mutex_lock(&LOCK_load_client_plugin); + + /* make sure the plugin wasn't loaded meanwhile */ + if (find_plugin(plugin->name, plugin->type)) + { + my_set_error(mysql, CR_AUTH_PLUGIN_CANNOT_LOAD, + SQLSTATE_UNKNOWN, ER(CR_AUTH_PLUGIN_CANNOT_LOAD), + plugin->name, "it is already loaded"); + plugin= NULL; + } + else + plugin= add_plugin(mysql, plugin, 0, 0, unused); + + pthread_mutex_unlock(&LOCK_load_client_plugin); + return plugin; +} + + +/* see for a full description */ +struct st_mysql_client_plugin * +mysql_load_plugin_v(MYSQL *mysql, const char *name, int type, + int argc, va_list args) +{ + const char *errmsg; +#ifdef _WIN32 + char errbuf[255]; +#endif + char dlpath[FN_REFLEN+1]; + void *sym, *dlhandle; + struct st_mysql_client_plugin *plugin; + + if (is_not_initialized(mysql, name)) + return NULL; + + pthread_mutex_lock(&LOCK_load_client_plugin); + + /* make sure the plugin wasn't loaded meanwhile */ + if (type >= 0 && find_plugin(name, type)) + { + errmsg= "it is already loaded"; + goto err; + } + + /* Compile dll path */ + strxnmov(dlpath, sizeof(dlpath) - 1, + mysql->options.extension && mysql->options.extension->plugin_dir ? + mysql->options.extension->plugin_dir : PLUGINDIR, "/", + name, SO_EXT, NullS); + + /* Open new dll handle */ + if (!(dlhandle= dlopen(dlpath, RTLD_NOW))) + { +#ifdef _WIN32 + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR)&errbuf, 255, NULL); + errmsg= errbuf; +#else + errmsg= dlerror(); +#endif + goto err; + } + + if (!(sym= dlsym(dlhandle, plugin_declarations_sym))) + { + errmsg= "not a plugin"; + (void)dlclose(dlhandle); + goto err; + } + + plugin= (struct st_mysql_client_plugin*)sym; + + if (type >=0 && type != plugin->type) + { + errmsg= "type mismatch"; + goto err; + } + + if (strcmp(name, plugin->name)) + { + errmsg= "name mismatch"; + goto err; + } + + if (type < 0 && find_plugin(name, plugin->type)) + { + errmsg= "it is already loaded"; + goto err; + } + + plugin= add_plugin(mysql, plugin, dlhandle, argc, args); + + pthread_mutex_unlock(&LOCK_load_client_plugin); + + return plugin; + +err: + pthread_mutex_unlock(&LOCK_load_client_plugin); + my_set_error(mysql, CR_AUTH_PLUGIN_CANNOT_LOAD, SQLSTATE_UNKNOWN, + ER(CR_AUTH_PLUGIN_CANNOT_LOAD), name, errmsg); + return NULL; +} + + +/* see for a full description */ +struct st_mysql_client_plugin * +mysql_load_plugin(MYSQL *mysql, const char *name, int type, int argc, ...) +{ + struct st_mysql_client_plugin *p; + va_list args; + va_start(args, argc); + p= mysql_load_plugin_v(mysql, name, type, argc, args); + va_end(args); + return p; +} + + +/* see for a full description */ +struct st_mysql_client_plugin * +mysql_client_find_plugin(MYSQL *mysql, const char *name, int type) +{ + struct st_mysql_client_plugin *p; + + if (is_not_initialized(mysql, name)) + return NULL; + + if (type < 0 || type >= MYSQL_CLIENT_MAX_PLUGINS) + { + my_set_error(mysql, CR_AUTH_PLUGIN_CANNOT_LOAD, SQLSTATE_UNKNOWN, + ER(CR_AUTH_PLUGIN_CANNOT_LOAD), name, "invalid type"); + } + + if ((p= find_plugin(name, type))) + return p; + + /* not found, load it */ + return mysql_load_plugin(mysql, name, type, 0); +} + + diff --git a/libmysql/cmake_install.cmake b/libmysql/cmake_install.cmake deleted file mode 100644 index 2eb2c080c..000000000 --- a/libmysql/cmake_install.cmake +++ /dev/null @@ -1,34 +0,0 @@ -# Install script for directory: /home/georg/priv/monty/libmysql-lgpl-3.23/libmysql - -# Set the install prefix -IF(NOT DEFINED CMAKE_INSTALL_PREFIX) - SET(CMAKE_INSTALL_PREFIX "/usr/local") -ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX) -STRING(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") - -# Set the install configuration name. -IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) - IF(BUILD_TYPE) - STRING(REGEX REPLACE "^[^A-Za-z0-9_]+" "" - CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}") - ELSE(BUILD_TYPE) - SET(CMAKE_INSTALL_CONFIG_NAME "Debug") - ENDIF(BUILD_TYPE) - MESSAGE(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"") -ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) - -# Set the component getting installed. -IF(NOT CMAKE_INSTALL_COMPONENT) - IF(COMPONENT) - MESSAGE(STATUS "Install component: \"${COMPONENT}\"") - SET(CMAKE_INSTALL_COMPONENT "${COMPONENT}") - ELSE(COMPONENT) - SET(CMAKE_INSTALL_COMPONENT) - ENDIF(COMPONENT) -ENDIF(NOT CMAKE_INSTALL_COMPONENT) - -# Install shared libraries without execute permission? -IF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE) - SET(CMAKE_INSTALL_SO_NO_EXE "0") -ENDIF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE) - diff --git a/libmysql/conf_to_src.c b/libmysql/conf_to_src.c deleted file mode 100644 index 016c17a2d..000000000 --- a/libmysql/conf_to_src.c +++ /dev/null @@ -1,143 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* can't use -lmysys because this prog is used to create -lstrings */ - -#include -#include -#include -#include -#include - -#define CHARSETS_SUBDIR "share/charsets" -#define CTYPE_TABLE_SIZE 257 -#define TO_LOWER_TABLE_SIZE 256 -#define TO_UPPER_TABLE_SIZE 256 -#define SORT_ORDER_TABLE_SIZE 256 -#define ROW_LEN 16 - -void print_arrays_for(char *set); - -char *prog; -char buf[1024], *p, *endptr; - -int -main(int argc, char **argv) -{ - prog = *argv; - - if (argc < 2) { - fprintf(stderr, "usage: %s source-dir [charset [, charset]]\n", prog); - exit(EXIT_FAILURE); - } - - --argc; ++argv; /* skip program name */ - - if (chdir(*argv) != 0) { - fprintf(stderr, "%s: can't cd to %s\n", prog, *argv); - exit(EXIT_FAILURE); - } - --argc; ++argv; - - if (chdir(CHARSETS_SUBDIR) != 0) { - fprintf(stderr, "%s: can't cd to %s\n", prog, CHARSETS_SUBDIR); - exit(EXIT_FAILURE); - } - - while (argc--) - print_arrays_for(*argv++); - - exit(EXIT_SUCCESS); -} - -void -print_array(FILE *f, const char *set, const char *name, int n) -{ - int i; - char val[100]; - - printf("uchar %s_%s[] = {\n", name, set); - - p = buf; - *buf = '\0'; - for (i = 0; i < n; ++i) - { - /* get a word from f */ - endptr = p; - for (;;) - { - while (isspace(*endptr)) - ++endptr; - if (*endptr && *endptr != '#') /* not comment */ - break; - if ((fgets(buf, sizeof(buf), f)) == NULL) - return; /* XXX: break silently */ - endptr = buf; - } - - p = val; - while (!isspace(*endptr)) - *p++ = *endptr++; - *p = '\0'; - p = endptr; - - /* write the value out */ - - if (i == 0 || i % ROW_LEN == n % ROW_LEN) - printf(" "); - - printf("%3d", (unsigned char) strtol(val, (char **) NULL, 16)); - - if (i < n - 1) - printf(","); - - if ((i+1) % ROW_LEN == n % ROW_LEN) - printf("\n"); - } - - printf("};\n\n"); -} - -void -print_arrays_for(char *set) -{ - FILE *f; - - sprintf(buf, "%s.conf", set); - - if ((f = fopen(buf, "r")) == NULL) { - fprintf(stderr, "%s: can't read conf file for charset %s\n", prog, set); - exit(EXIT_FAILURE); - } - - printf("\ -/* The %s character set. Generated automatically by configure and\n\ - * the %s program\n\ - */\n\n", - set, prog); - - /* it would be nice if this used the code in mysys/charset.c, but... */ - print_array(f, set, "ctype", CTYPE_TABLE_SIZE); - print_array(f, set, "to_lower", TO_LOWER_TABLE_SIZE); - print_array(f, set, "to_upper", TO_UPPER_TABLE_SIZE); - print_array(f, set, "sort_order", SORT_ORDER_TABLE_SIZE); - printf("\n"); - - fclose(f); - - return; -} diff --git a/libmysql/ctype.c b/libmysql/ctype.c deleted file mode 100644 index edb2d691f..000000000 --- a/libmysql/ctype.c +++ /dev/null @@ -1,68 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include -#include -#include - -/* generated by make, using conf_to_src */ -/* #include "ctype_extra_sources.c" */ - -/* generated by configure */ -/* #include "ctype_autoconf.c" */ - -CHARSET_INFO *default_charset_info = &compiled_charsets[5]; - -CHARSET_INFO *find_compiled_charset(uint cs_number) -{ - CHARSET_INFO *cs; - for (cs = compiled_charsets; cs->nr > 0; cs++) - if (cs->nr == cs_number) - return cs; - - return NULL; -} - -CHARSET_INFO *find_compiled_charset_by_name(const char *name) -{ - CHARSET_INFO *cs; - for (cs = compiled_charsets; cs->nr > 0; cs++) - if (!strcmp(cs->name, name)) - return cs; - - return NULL; -} - -uint compiled_charset_number(const char *name) -{ - CHARSET_INFO *cs; - for (cs = compiled_charsets; cs->nr > 0; cs++) - if (!strcmp(cs->name, name)) - return cs->nr; - - return 0; /* this mimics find_type() */ -} - -const char *compiled_charset_name(uint charset_number) -{ - CHARSET_INFO *cs; - for (cs = compiled_charsets; cs->nr > 0; cs++) - if (cs->nr == charset_number) - return cs->name; - - return "?"; /* this mimics get_type() */ -} diff --git a/libmysql/dbug.c b/libmysql/dbug.c index 378e03692..1a0aeaef7 100644 --- a/libmysql/dbug.c +++ b/libmysql/dbug.c @@ -72,7 +72,7 @@ #include #include #include -#if defined(MSDOS) || defined(__WIN__) +#if defined(MSDOS) || defined(_WIN32) #include #endif @@ -123,7 +123,7 @@ * Typedefs to make things more obvious. */ -#ifndef __WIN__ +#ifndef _WIN32 typedef int BOOLEAN; #else #define BOOLEAN BOOL @@ -275,10 +275,8 @@ static BOOLEAN DoTrace(CODE_STATE *state); /* Test to see if file is writable */ #if !(!defined(HAVE_ACCESS) || defined(MSDOS)) static BOOLEAN Writable(char *pathname); - /* Change file owner and group */ -static void ChangeOwner(char *pathname); - /* Allocate memory for runtime support */ #endif + /* Allocate memory for runtime support */ static char *DbugMalloc(int size); /* Remove leading pathname components */ static char *BaseName(const char *pathname); @@ -317,6 +315,8 @@ static char *static_strtok(char *s1,pchar chr); #endif #ifndef MSDOS #define ChangeOwner(name) +#else +static void ChangeOwner(char *pathname); #endif /* @@ -1923,7 +1923,7 @@ static void dbug_flush(CODE_STATE *state) if (stack->flags & FLUSH_ON_WRITE) #endif { -#if defined(MSDOS) || defined(__WIN__) +#if defined(MSDOS) || defined(_WIN32) if (_db_fp_ != stdout && _db_fp_ != stderr) { if (!(freopen(stack->name,"a",_db_fp_))) @@ -1990,7 +1990,7 @@ static unsigned long Clock () return ((ru.ru_utime.tv_sec * 1000) + (ru.ru_utime.tv_usec / 1000)); } -#elif defined(MSDOS) || defined(__WIN__) || defined(OS2) +#elif defined(MSDOS) || defined(_WIN32) || defined(OS2) static ulong Clock() { diff --git a/libmysql/default.c b/libmysql/default.c index 33345c75d..927c3d88f 100644 --- a/libmysql/default.c +++ b/libmysql/default.c @@ -47,7 +47,7 @@ char *defaults_extra_file=0; /* Which directories are searched for options (and in which order) */ const char *default_directories[]= { -#ifdef __WIN__ +#ifdef _WIN32 "C:/", #else "/etc/", @@ -56,14 +56,14 @@ const char *default_directories[]= { DATADIR, #endif "", /* Place for defaults_extra_dir */ -#ifndef __WIN__ +#ifndef _WIN32 "~/", #endif NullS, }; #define default_ext ".cnf" /* extension for config file */ -#ifdef __WIN__ +#ifdef _WIN32 #include #define windows_ext ".ini" #endif @@ -141,7 +141,7 @@ void load_defaults(const char *conf_file, const char **groups, } else { -#ifdef __WIN__ +#ifdef _WIN32 char system_dir[FN_REFLEN]; GetWindowsDirectory(system_dir,sizeof(system_dir)); if (search_default_file(&args, &alloc, system_dir, conf_file, windows_ext, @@ -244,7 +244,7 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, strmov(name,config_file); } fn_format(name,name,"","",4); -#if !defined(__WIN__) && !defined(OS2) +#if !defined(_WIN32) && !defined(OS2) { MY_STAT stat_info; if (!my_stat(name,&stat_info,MYF(0))) @@ -364,7 +364,7 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, void print_defaults(const char *conf_file, const char **groups) { -#ifdef __WIN__ +#ifdef _WIN32 bool have_ext=fn_ext(conf_file)[0] != 0; #endif char name[FN_REFLEN]; @@ -375,7 +375,7 @@ void print_defaults(const char *conf_file, const char **groups) fputs(conf_file,stdout); else { -#ifdef __WIN__ +#ifdef _WIN32 GetWindowsDirectory(name,sizeof(name)); printf("%s\\%s%s ",name,conf_file,have_ext ? "" : windows_ext); #endif diff --git a/libmysql/errmsg.c b/libmysql/errmsg.c index a10a3cc59..40a6b9fff 100644 --- a/libmysql/errmsg.c +++ b/libmysql/errmsg.c @@ -21,6 +21,7 @@ #include #include #include "errmsg.h" +#include #ifdef GERMAN const char *client_errors[]= @@ -39,7 +40,7 @@ const char *client_errors[]= "%-.64s via TCP/IP", "Error in server handshake", "Lost connection to MySQL server during query", - "Commands out of sync; You can't run this command now", + "Commands out of sync; you can't run this command now", "Verbindung ueber Named Pipe; Host: %-.64s", "Kann nicht auf Named Pipe warten. Host: %-.64s pipe: %-.32s (%lu)", "Kann Named Pipe nicht oeffnen. Host: %-.64s pipe: %-.32s (%lu)", @@ -93,7 +94,7 @@ const char *client_errors[]= /* 2011 */ "%-.64s via TCP/IP", /* 2012 */ "Error in server handshake", /* 2013 */ "Lost connection to MySQL server during query", -/* 2014 */ "Commands out of sync; You can't run this command now", +/* 2014 */ "Commands out of sync; you can't run this command now", /* 2015 */ "%-.64s via named pipe", /* 2016 */ "Can't wait for named pipe to host: %-.64s pipe: %-.32s (%lu)", /* 2017 */ "Can't open named pipe to host: %-.64s pipe: %-.32s (%lu)", @@ -106,7 +107,7 @@ const char *client_errors[]= /* 2024 */ "", /* 2025 */ "", /* 2026 */ "", -/* 2027 */ "", +/* 2027 */ "received malformed packet", /* 2028 */ "", /* 2029 */ "", /* 2030 */ "", @@ -137,7 +138,9 @@ const char *client_errors[]= /* 2055 */ "", /* 2056 */ "", /* 2057 */ "The number of parameters in bound buffers differs from number of columns in resultset", -/* 2058 */ "Can't connect twice. Already connected" +/* 2058 */ "Can't connect twice. Already connected", +/* 2059 */ "Plugin %s could not be loaded: %s", + "" }; #endif diff --git a/libmysql/get_password.c b/libmysql/get_password.c index 4941c9b43..69d690632 100644 --- a/libmysql/get_password.c +++ b/libmysql/get_password.c @@ -35,7 +35,7 @@ #include #endif /* HAVE_PWD_H */ #else /* ! HAVE_GETPASS */ -#if !defined( __WIN__) && !defined(OS2) +#if !defined( _WIN32) && !defined(OS2) #include #ifdef HAVE_TERMIOS_H /* For tty-password */ #include @@ -55,14 +55,14 @@ #endif #else #include -#endif /* __WIN__ */ +#endif /* _WIN32 */ #endif /* HAVE_GETPASS */ #ifdef HAVE_GETPASSPHRASE /* For Solaris */ -#define getpass(A) getpassphrase(A) + #define getpass(A) getpassphrase(A) #endif -#if defined( __WIN__) || defined(OS2) +#if defined( _WIN32) || defined(OS2) /* were just going to fake it here and get input from the keyboard */ char *get_tty_password(char *opt_message) @@ -208,4 +208,4 @@ char *get_tty_password(char *opt_message) DBUG_RETURN(my_strdup(buff,MYF(MY_FAE))); } -#endif /*__WIN__*/ +#endif /*_WIN32*/ diff --git a/libmysql/getopt.c b/libmysql/getopt.c index 35db805d9..cbec6678f 100644 --- a/libmysql/getopt.c +++ b/libmysql/getopt.c @@ -176,10 +176,6 @@ static char *posixly_correct; /* Avoid depending on library functions or files whose names are inconsistent. */ -#ifndef OS2 -char *getenv (const char *); -#endif - static char * my_index (const char *str, int chr) { diff --git a/libmysql/getopt1.c b/libmysql/getopt1.c index 15f3c8f54..d89f7bcc3 100644 --- a/libmysql/getopt1.c +++ b/libmysql/getopt1.c @@ -47,9 +47,9 @@ Cambridge, MA 02139, USA. */ #if defined (_LIBC) || !defined (__GNU_LIBRARY__) -#ifndef __WIN__ +#ifndef _WIN32 #include -#endif /* __WIN__ */ +#endif /* _WIN32 */ #ifndef NULL #define NULL 0 diff --git a/libmysql/getvar.c b/libmysql/getvar.c deleted file mode 100644 index 90ab59924..000000000 --- a/libmysql/getvar.c +++ /dev/null @@ -1,112 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* Allow use of the -O variable= option to set long variables */ - -#include "mysys_priv.h" -#include -#include - - /* set all changeable variables */ - -void set_all_changeable_vars(CHANGEABLE_VAR *vars) -{ - for ( ; vars->name ; vars++) - *vars->varptr= vars->def_value; -} - - -my_bool set_changeable_varval(const char* var, ulong val, - CHANGEABLE_VAR *vars) -{ - char buffer[256]; - sprintf( buffer, "%s=%lu", var, (unsigned long) val ); - return set_changeable_var( buffer, vars ); -} - - -my_bool set_changeable_var(my_string str,CHANGEABLE_VAR *vars) -{ - char endchar; - my_string end; - DBUG_ENTER("set_changeable_var"); - DBUG_PRINT("enter",("%s",str)); - - if (str) - { - if (!(end=strchr(str,'='))) - fprintf(stderr,"Can't find '=' in expression '%s' to option -O\n",str); - else - { - uint length,found_count=0; - CHANGEABLE_VAR *var,*found; - my_string var_end; - const char *name; - longlong num; - - /* Skip end space from variable */ - for (var_end=end ; end > str && isspace(var_end[-1]) ; var_end--) ; - length=(uint) (var_end-str); - /* Skip start space from argument */ - for (end++ ; isspace(*end) ; end++) ; - - for (var=vars,found=0 ; (name=var->name) ; var++) - { - if (!my_casecmp(name,str,length)) - { - found=var; found_count++; - if (!name[length]) - { - found_count=1; - break; - } - } - } - if (found_count == 0) - { - fprintf(stderr,"No variable match for: -O '%s'\n",str); - DBUG_RETURN(1); - } - if (found_count > 1) - { - fprintf(stderr,"Variable prefix '%*s' is not unique\n",length,str); - DBUG_RETURN(1); - } - - num=strtoll(end, (char **)NULL, 10); endchar=strend(end)[-1]; - if (endchar == 'k' || endchar == 'K') - num*=1024; - else if (endchar == 'm' || endchar == 'M') - num*=1024L*1024L; - else if (endchar == 'g' || endchar == 'G') - num*=1024L*1024L*1024L; - else if (!isdigit(endchar)) - { - fprintf(stderr,"Unknown prefix used for variable value '%s'\n",str); - DBUG_RETURN(1); - } - if (num < (longlong) found->min_value) - num=(longlong) found->min_value; - else if (num > 0 && (ulonglong) num > (ulonglong) (ulong) found->max_value) - num=(longlong) (ulong) found->max_value; - num=((num- (longlong) found->sub_size) / (ulonglong) found->block_size); - (*found->varptr)= (long) (num*(ulonglong) found->block_size); - DBUG_RETURN(0); - } - } - DBUG_RETURN(1); -} diff --git a/libmysql/hash.c b/libmysql/hash.c deleted file mode 100644 index 602823e6d..000000000 --- a/libmysql/hash.c +++ /dev/null @@ -1,640 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* The hash functions used for saveing keys */ -/* One of key_length or key_length_offset must be given */ -/* Key length of 0 isn't allowed */ - -#include "mysys_priv.h" -#include -#include -#include "hash.h" - -#define NO_RECORD ((uint) -1) -#define LOWFIND 1 -#define LOWUSED 2 -#define HIGHFIND 4 -#define HIGHUSED 8 - -static uint hash_mask(uint hashnr,uint buffmax,uint maxlength); -static void movelink(HASH_LINK *array,uint pos,uint next_link,uint newlink); -static uint calc_hashnr(const byte *key,uint length); -static uint calc_hashnr_caseup(const byte *key,uint length); -static int hashcmp(HASH *hash,HASH_LINK *pos,const byte *key,uint length); - - -my_bool _hash_init(HASH *hash,uint size,uint key_offset,uint key_length, - hash_get_key get_key, - void (*free_element)(void*),uint flags CALLER_INFO_PROTO) -{ - DBUG_ENTER("hash_init"); - DBUG_PRINT("enter",("hash: %lx size: %d",hash,size)); - - hash->records=0; - if (my_init_dynamic_array_ci(&hash->array,sizeof(HASH_LINK),size,0)) - { - hash->free=0; /* Allow call to hash_free */ - DBUG_RETURN(TRUE); - } - hash->key_offset=key_offset; - hash->key_length=key_length; - hash->blength=1; - hash->current_record= NO_RECORD; /* For the future */ - hash->get_key=get_key; - hash->free=free_element; - hash->flags=flags; - if (flags & HASH_CASE_INSENSITIVE) - hash->calc_hashnr=calc_hashnr_caseup; - else - hash->calc_hashnr=calc_hashnr; - DBUG_RETURN(0); -} - - -void hash_free(HASH *hash) -{ - DBUG_ENTER("hash_free"); - if (hash->free) - { - uint i,records; - HASH_LINK *data=dynamic_element(&hash->array,0,HASH_LINK*); - for (i=0,records=hash->records ; i < records ; i++) - (*hash->free)(data[i].data); - hash->free=0; - } - delete_dynamic(&hash->array); - hash->records=0; - DBUG_VOID_RETURN; -} - - /* some helper functions */ - -/* - This function is char* instead of byte* as HPUX11 compiler can't - handle inline functions that are not defined as native types -*/ - -inline char* -hash_key(HASH *hash,const byte *record,uint *length,my_bool first) -{ - if (hash->get_key) - return (*hash->get_key)(record,length,first); - *length=hash->key_length; - return (byte*) record+hash->key_offset; -} - - /* Calculate pos according to keys */ - -static uint hash_mask(uint hashnr,uint buffmax,uint maxlength) -{ - if ((hashnr & (buffmax-1)) < maxlength) return (hashnr & (buffmax-1)); - return (hashnr & ((buffmax >> 1) -1)); -} - -static uint hash_rec_mask(HASH *hash,HASH_LINK *pos,uint buffmax, - uint maxlength) -{ - uint length; - byte *key= (byte*) hash_key(hash,pos->data,&length,0); - return hash_mask((*hash->calc_hashnr)(key,length),buffmax,maxlength); -} - -#ifndef NEW_HASH_FUNCTION - - /* Calc hashvalue for a key */ - -static uint calc_hashnr(const byte *key,uint length) -{ - register uint nr=1, nr2=4; - while (length--) - { - nr^= (((nr & 63)+nr2)*((uint) (uchar) *key++))+ (nr << 8); - nr2+=3; - } - return((uint) nr); -} - - /* Calc hashvalue for a key, case indepenently */ - -static uint calc_hashnr_caseup(const byte *key,uint length) -{ - register uint nr=1, nr2=4; - while (length--) - { - nr^= (((nr & 63)+nr2)*((uint) (uchar) toupper(*key++)))+ (nr << 8); - nr2+=3; - } - return((uint) nr); -} - -#else - -/* - * Fowler/Noll/Vo hash - * - * The basis of the hash algorithm was taken from an idea sent by email to the - * IEEE Posix P1003.2 mailing list from Phong Vo (kpv@research.att.com) and - * Glenn Fowler (gsf@research.att.com). Landon Curt Noll (chongo@toad.com) - * later improved on their algorithm. - * - * The magic is in the interesting relationship between the special prime - * 16777619 (2^24 + 403) and 2^32 and 2^8. - * - * This hash produces the fewest collisions of any function that we've seen so - * far, and works well on both numbers and strings. - */ - -uint calc_hashnr(const byte *key, uint len) -{ - const byte *end=key+len; - uint hash; - for (hash = 0; key < end; key++) - { - hash *= 16777619; - hash ^= (uint) *(uchar*) key; - } - return (hash); -} - -uint calc_hashnr_caseup(const byte *key, uint len) -{ - const byte *end=key+len; - uint hash; - for (hash = 0; key < end; key++) - { - hash *= 16777619; - hash ^= (uint) (uchar) toupper(*key); - } - return (hash); -} - -#endif - - -#ifndef __SUNPRO_C /* SUNPRO can't handle this */ -inline -#endif -unsigned int rec_hashnr(HASH *hash,const byte *record) -{ - uint length; - byte *key= (byte*) hash_key(hash,record,&length,0); - return (*hash->calc_hashnr)(key,length); -} - - - /* Search after a record based on a key */ - /* Sets info->current_ptr to found record */ - -gptr hash_search(HASH *hash,const byte *key,uint length) -{ - HASH_LINK *pos; - uint flag,idx; - DBUG_ENTER("hash_search"); - - flag=1; - if (hash->records) - { - idx=hash_mask((*hash->calc_hashnr)(key,length ? length : - hash->key_length), - hash->blength,hash->records); - do - { - pos= dynamic_element(&hash->array,idx,HASH_LINK*); - if (!hashcmp(hash,pos,key,length)) - { - DBUG_PRINT("exit",("found key at %d",idx)); - hash->current_record= idx; - DBUG_RETURN (pos->data); - } - if (flag) - { - flag=0; /* Reset flag */ - if (hash_rec_mask(hash,pos,hash->blength,hash->records) != idx) - break; /* Wrong link */ - } - } - while ((idx=pos->next) != NO_RECORD); - } - hash->current_record= NO_RECORD; - DBUG_RETURN(0); -} - - /* Get next record with identical key */ - /* Can only be called if previous calls was hash_search */ - -gptr hash_next(HASH *hash,const byte *key,uint length) -{ - HASH_LINK *pos; - uint idx; - - if (hash->current_record != NO_RECORD) - { - HASH_LINK *data=dynamic_element(&hash->array,0,HASH_LINK*); - for (idx=data[hash->current_record].next; idx != NO_RECORD ; idx=pos->next) - { - pos=data+idx; - if (!hashcmp(hash,pos,key,length)) - { - hash->current_record= idx; - return pos->data; - } - } - hash->current_record=NO_RECORD; - } - return 0; -} - - - /* Change link from pos to new_link */ - -static void movelink(HASH_LINK *array,uint find,uint next_link,uint newlink) -{ - HASH_LINK *old_link; - do - { - old_link=array+next_link; - } - while ((next_link=old_link->next) != find); - old_link->next= newlink; - return; -} - - /* Compare a key in a record to a whole key. Return 0 if identical */ - -static int hashcmp(HASH *hash,HASH_LINK *pos,const byte *key,uint length) -{ - uint rec_keylength; - byte *rec_key= (byte*) hash_key(hash,pos->data,&rec_keylength,1); - return (length && length != rec_keylength) || - (hash->flags & HASH_CASE_INSENSITIVE ? - my_casecmp(rec_key,key,rec_keylength) : - memcmp(rec_key,key,rec_keylength)); -} - - - /* Write a hash-key to the hash-index */ - -my_bool hash_insert(HASH *info,const byte *record) -{ - int flag; - uint halfbuff,hash_nr,first_index,idx; - byte *ptr_to_rec,*ptr_to_rec2; - HASH_LINK *data,*empty,*gpos,*gpos2,*pos; - - LINT_INIT(gpos); LINT_INIT(gpos2); - LINT_INIT(ptr_to_rec); LINT_INIT(ptr_to_rec2); - - flag=0; - if (!(empty=(HASH_LINK*) alloc_dynamic(&info->array))) - return(TRUE); /* No more memory */ - - info->current_record= NO_RECORD; - data=dynamic_element(&info->array,0,HASH_LINK*); - halfbuff= info->blength >> 1; - - idx=first_index=info->records-halfbuff; - if (idx != info->records) /* If some records */ - { - do - { - pos=data+idx; - hash_nr=rec_hashnr(info,pos->data); - if (flag == 0) /* First loop; Check if ok */ - if (hash_mask(hash_nr,info->blength,info->records) != first_index) - break; - if (!(hash_nr & halfbuff)) - { /* Key will not move */ - if (!(flag & LOWFIND)) - { - if (flag & HIGHFIND) - { - flag=LOWFIND | HIGHFIND; - /* key shall be moved to the current empty position */ - gpos=empty; - ptr_to_rec=pos->data; - empty=pos; /* This place is now free */ - } - else - { - flag=LOWFIND | LOWUSED; /* key isn't changed */ - gpos=pos; - ptr_to_rec=pos->data; - } - } - else - { - if (!(flag & LOWUSED)) - { - /* Change link of previous LOW-key */ - gpos->data=ptr_to_rec; - gpos->next=(uint) (pos-data); - flag= (flag & HIGHFIND) | (LOWFIND | LOWUSED); - } - gpos=pos; - ptr_to_rec=pos->data; - } - } - else - { /* key will be moved */ - if (!(flag & HIGHFIND)) - { - flag= (flag & LOWFIND) | HIGHFIND; - /* key shall be moved to the last (empty) position */ - gpos2 = empty; empty=pos; - ptr_to_rec2=pos->data; - } - else - { - if (!(flag & HIGHUSED)) - { - /* Change link of previous hash-key and save */ - gpos2->data=ptr_to_rec2; - gpos2->next=(uint) (pos-data); - flag= (flag & LOWFIND) | (HIGHFIND | HIGHUSED); - } - gpos2=pos; - ptr_to_rec2=pos->data; - } - } - } - while ((idx=pos->next) != NO_RECORD); - - if ((flag & (LOWFIND | LOWUSED)) == LOWFIND) - { - gpos->data=ptr_to_rec; - gpos->next=NO_RECORD; - } - if ((flag & (HIGHFIND | HIGHUSED)) == HIGHFIND) - { - gpos2->data=ptr_to_rec2; - gpos2->next=NO_RECORD; - } - } - /* Check if we are at the empty position */ - - idx=hash_mask(rec_hashnr(info,record),info->blength,info->records+1); - pos=data+idx; - if (pos == empty) - { - pos->data=(byte*) record; - pos->next=NO_RECORD; - } - else - { - /* Check if more records in same hash-nr family */ - empty[0]=pos[0]; - gpos=data+hash_rec_mask(info,pos,info->blength,info->records+1); - if (pos == gpos) - { - pos->data=(byte*) record; - pos->next=(uint) (empty - data); - } - else - { - pos->data=(byte*) record; - pos->next=NO_RECORD; - movelink(data,(uint) (pos-data),(uint) (gpos-data),(uint) (empty-data)); - } - } - if (++info->records == info->blength) - info->blength+= info->blength; - return(0); -} - - -/****************************************************************************** -** Remove one record from hash-table. The record with the same record -** ptr is removed. -** if there is a free-function it's called for record if found -******************************************************************************/ - -my_bool hash_delete(HASH *hash,byte *record) -{ - uint blength,pos2,pos_hashnr,lastpos_hashnr,idx,empty_index; - HASH_LINK *data,*lastpos,*gpos,*pos,*pos3,*empty; - DBUG_ENTER("hash_delete"); - if (!hash->records) - DBUG_RETURN(1); - - blength=hash->blength; - data=dynamic_element(&hash->array,0,HASH_LINK*); - /* Search after record with key */ - pos=data+ hash_mask(rec_hashnr(hash,record),blength,hash->records); - gpos = 0; - - while (pos->data != record) - { - gpos=pos; - if (pos->next == NO_RECORD) - DBUG_RETURN(1); /* Key not found */ - pos=data+pos->next; - } - - if ( --(hash->records) < hash->blength >> 1) hash->blength>>=1; - hash->current_record= NO_RECORD; - lastpos=data+hash->records; - - /* Remove link to record */ - empty=pos; empty_index=(uint) (empty-data); - if (gpos) - gpos->next=pos->next; /* unlink current ptr */ - else if (pos->next != NO_RECORD) - { - empty=data+(empty_index=pos->next); - pos->data=empty->data; - pos->next=empty->next; - } - - if (empty == lastpos) /* last key at wrong pos or no next link */ - goto exit; - - /* Move the last key (lastpos) */ - lastpos_hashnr=rec_hashnr(hash,lastpos->data); - /* pos is where lastpos should be */ - pos=data+hash_mask(lastpos_hashnr,hash->blength,hash->records); - if (pos == empty) /* Move to empty position. */ - { - empty[0]=lastpos[0]; - goto exit; - } - pos_hashnr=rec_hashnr(hash,pos->data); - /* pos3 is where the pos should be */ - pos3= data+hash_mask(pos_hashnr,hash->blength,hash->records); - if (pos != pos3) - { /* pos is on wrong posit */ - empty[0]=pos[0]; /* Save it here */ - pos[0]=lastpos[0]; /* This should be here */ - movelink(data,(uint) (pos-data),(uint) (pos3-data),empty_index); - goto exit; - } - pos2= hash_mask(lastpos_hashnr,blength,hash->records+1); - if (pos2 == hash_mask(pos_hashnr,blength,hash->records+1)) - { /* Identical key-positions */ - if (pos2 != hash->records) - { - empty[0]=lastpos[0]; - movelink(data,(uint) (lastpos-data),(uint) (pos-data),empty_index); - goto exit; - } - idx= (uint) (pos-data); /* Link pos->next after lastpos */ - } - else idx= NO_RECORD; /* Different positions merge */ - - empty[0]=lastpos[0]; - movelink(data,idx,empty_index,pos->next); - pos->next=empty_index; - -exit: - VOID(pop_dynamic(&hash->array)); - if (hash->free) - (*hash->free)((byte*) record); - DBUG_RETURN(0); -} - - /* - Update keys when record has changed. - This is much more efficent than using a delete & insert. - */ - -my_bool hash_update(HASH *hash,byte *record,byte *old_key,uint old_key_length) -{ - uint idx,new_index,new_pos_index,blength,records,empty; - HASH_LINK org_link,*data,*previous,*pos; - DBUG_ENTER("hash_update"); - - data=dynamic_element(&hash->array,0,HASH_LINK*); - blength=hash->blength; records=hash->records; - - /* Search after record with key */ - - idx=hash_mask((*hash->calc_hashnr)(old_key,(old_key_length ? - old_key_length : - hash->key_length)), - blength,records); - new_index=hash_mask(rec_hashnr(hash,record),blength,records); - if (idx == new_index) - DBUG_RETURN(0); /* Nothing to do (No record check) */ - previous=0; - for (;;) - { - - if ((pos= data+idx)->data == record) - break; - previous=pos; - if ((idx=pos->next) == NO_RECORD) - DBUG_RETURN(1); /* Not found in links */ - } - hash->current_record= NO_RECORD; - org_link= *pos; - empty=idx; - - /* Relink record from current chain */ - - if (!previous) - { - if (pos->next != NO_RECORD) - { - empty=pos->next; - *pos= data[pos->next]; - } - } - else - previous->next=pos->next; /* unlink pos */ - - /* Move data to correct position */ - pos=data+new_index; - new_pos_index=hash_rec_mask(hash,pos,blength,records); - if (new_index != new_pos_index) - { /* Other record in wrong position */ - data[empty] = *pos; - movelink(data,new_index,new_pos_index,empty); - org_link.next=NO_RECORD; - data[new_index]= org_link; - } - else - { /* Link in chain at right position */ - org_link.next=data[new_index].next; - data[empty]=org_link; - data[new_index].next=empty; - } - DBUG_RETURN(0); -} - - -byte *hash_element(HASH *hash,uint idx) -{ - if (idx < hash->records) - return dynamic_element(&hash->array,idx,HASH_LINK*)->data; - return 0; -} - - -#ifndef DBUG_OFF - -my_bool hash_check(HASH *hash) -{ - int error; - uint i,rec_link,found,max_links,seek,links,idx; - uint records,blength; - HASH_LINK *data,*hash_info; - - records=hash->records; blength=hash->blength; - data=dynamic_element(&hash->array,0,HASH_LINK*); - error=0; - - for (i=found=max_links=seek=0 ; i < records ; i++) - { - if (hash_rec_mask(hash,data+i,blength,records) == i) - { - found++; seek++; links=1; - for (idx=data[i].next ; - idx != NO_RECORD && found < records + 1; - idx=hash_info->next) - { - if (idx >= records) - { - DBUG_PRINT("error", - ("Found pointer outside array to %d from link starting at %d", - idx,i)); - error=1; - } - hash_info=data+idx; - seek+= ++links; - if ((rec_link=hash_rec_mask(hash,hash_info,blength,records)) != i) - { - DBUG_PRINT("error", - ("Record in wrong link at %d: Start %d Record: %lx Record-link %d", idx,i,hash_info->data,rec_link)); - error=1; - } - else - found++; - } - if (links > max_links) max_links=links; - } - } - if (found != records) - { - DBUG_PRINT("error",("Found %ld of %ld records")); - error=1; - } - if (records) - DBUG_PRINT("info", - ("records: %ld seeks: %d max links: %d hitrate: %.2f", - records,seek,max_links,(float) seek / (float) records)); - return error; -} -#endif diff --git a/libmysql/int2str.c b/libmysql/int2str.c index 813daee2f..17bcb3fc1 100644 --- a/libmysql/int2str.c +++ b/libmysql/int2str.c @@ -104,25 +104,23 @@ char *int2str(register long int val, register char *dst, register int radix) radix 10 / -10 */ -char *int10_to_str(long int val,char *dst,int radix) +char *int10_to_str(long int val, char *dst, int radix) { char buffer[65]; register char *p; long int new_val; + unsigned long int uval= (unsigned long int)val; - if (radix < 0) /* -10 */ + if (radix < 0 && val < 0) /* -10 */ { - if (val < 0) - { - *dst++ = '-'; - val = -val; - } + *dst++ = '-'; + uval = (unsigned long int)0-uval; } p = &buffer[sizeof(buffer)-1]; *p = '\0'; - new_val= (long) ((unsigned long int) val / 10); - *--p = '0'+ (char) ((unsigned long int) val - (unsigned long) new_val * 10); + new_val= (long)(uval / 10); + *--p = '0'+ (char)(uval - (unsigned long)new_val * 10); val = new_val; while (val != 0) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 31c1402d5..7db8b0b38 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -22,10 +22,7 @@ *************************************************************************************/ #include -#ifdef __WIN__ -#include -#include -#endif + #include #include #include @@ -40,7 +37,7 @@ #ifdef HAVE_PWD_H #include #endif -#if !defined(MSDOS) && !defined(__WIN__) +#if !defined(MSDOS) && !defined(_WIN32) #include #include #include @@ -55,8 +52,8 @@ #ifdef HAVE_SYS_UN_H # include #endif -#if defined(THREAD) && !defined(__WIN__) -#include /* because of signal() */ #endif #ifndef INADDR_NONE #define INADDR_NONE -1 @@ -67,26 +64,31 @@ static my_bool mysql_client_init=0; extern my_bool my_init_done; extern my_bool mysql_ps_subsystem_initialized; +extern my_bool mysql_handle_local_infile(MYSQL *mysql, const char *filename); +extern const CHARSET_INFO * mysql_find_charset_nr(uint charsetnr); +extern const CHARSET_INFO * mysql_find_charset_name(const char * const name); +extern int run_plugin_auth(MYSQL *mysql, char *data, uint data_len, + const char *data_plugin, const char *db); uint mysql_port=0; my_string mysql_unix_port=0; -#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG | CLIENT_TRANSACTIONS | \ - CLIENT_SECURE_CONNECTION | CLIENT_MULTI_RESULTS | \ - CLIENT_PS_MULTI_RESULTS | CLIENT_PROTOCOL_41) -#ifdef __WIN__ +#ifdef _WIN32 #define CONNECT_TIMEOUT 20 #else #define CONNECT_TIMEOUT 0 #endif -#if defined(MSDOS) || defined(__WIN__) +#if defined(MSDOS) || defined(_WIN32) // socket_errno is defined in my_global.h for all platforms #define perror(A) #else #include #define SOCKET_ERROR -1 -#endif /* __WIN__ */ +#endif /* _WIN32 */ + +#include +#define native_password_plugin_name "mysql_native_password" const char *unknown_sqlstate= "HY000"; MYSQL_DATA *read_rows (MYSQL *mysql,MYSQL_FIELD *fields, @@ -94,20 +96,22 @@ MYSQL_DATA *read_rows (MYSQL *mysql,MYSQL_FIELD *fields, static int read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths); static void end_server(MYSQL *mysql); -static void read_user_name(char *name); +static void mysql_close_memory(MYSQL *mysql); +void read_user_name(char *name); static void append_wild(char *to,char *end,const char *wild); static my_bool mysql_reconnect(MYSQL *mysql); -static int send_file_to_server(MYSQL *mysql,const char *filename); static sig_handler pipe_sig_handler(int sig); -static ulong mysql_sub_escape_string(CHARSET_INFO *charset_info, char *to, - const char *from, ulong length); +static int cli_report_progress(MYSQL *mysql, uchar *packet, uint length); + +extern int mysql_client_plugin_init(); +extern void mysql_client_plugin_deinit(); /* Let the user specify that we don't want SIGPIPE; This doesn't however work with threaded applications as we can have multiple read in progress. */ -#if !defined(__WIN__) && defined(SIGPIPE) && !defined(THREAD) +#if !defined(_WIN32) && defined(SIGPIPE) && !defined(THREAD) #define init_sigpipe_variables sig_return old_signal_handler=(sig_return) 0; #define set_sigpipe(mysql) if ((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE) old_signal_handler=signal(SIGPIPE,pipe_sig_handler) #define reset_sigpipe(mysql) if ((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE) signal(SIGPIPE,old_signal_handler); @@ -117,6 +121,7 @@ static ulong mysql_sub_escape_string(CHARSET_INFO *charset_info, char *to, #define reset_sigpipe(mysql) #endif + /**************************************************************************** * A modified version of connect(). connect2() allows you to specify * a timeout value, in seconds, that we should wait until we @@ -129,7 +134,7 @@ static ulong mysql_sub_escape_string(CHARSET_INFO *charset_info, char *to, static int connect2(my_socket s, const struct sockaddr *name, uint namelen, uint timeout) { -#if defined(__WIN__) || defined(OS2) +#if defined(_WIN32) || defined(OS2) return connect(s, (struct sockaddr*) name, namelen); #else int flags, res, s_err; @@ -232,7 +237,7 @@ static int connect2(my_socket s, const struct sockaddr *name, uint namelen, ** Create a named pipe connection */ -#ifdef __WIN__ +#ifdef _WIN32 HANDLE create_named_pipe(NET *net, uint connect_timeout, char **arg_host, char **arg_unix_socket) @@ -302,12 +307,12 @@ HANDLE create_named_pipe(NET *net, uint connect_timeout, char **arg_host, /* net_get_error */ void net_get_error(char *buf, size_t buf_len, - char *error, int error_len, + char *error, size_t error_len, unsigned int *error_no, char *sqlstate) { char *p= buf; - int error_msg_len= 0; + size_t error_msg_len= 0; if (buf_len > 2) { @@ -344,6 +349,7 @@ net_safe_read(MYSQL *mysql) ulong len=0; init_sigpipe_variables +restart: /* Don't give sigpipe errors if the client doesn't want them */ set_sigpipe(mysql); if (net->vio != 0) @@ -352,13 +358,11 @@ net_safe_read(MYSQL *mysql) if (len == packet_error || len == 0) { -/* DBUG_PRINT("error",("Wrong connection or packet. fd: %s len: %d", - vio_description(net->vio),len)); */ end_server(mysql); - net->last_errno=(net->last_errno == ER_NET_PACKET_TOO_LARGE ? + my_set_error(mysql, net->last_errno == ER_NET_PACKET_TOO_LARGE ? CR_NET_PACKET_TOO_LARGE: - CR_SERVER_LOST); - strmov(net->last_error,ER(net->last_errno)); + CR_SERVER_LOST, + SQLSTATE_UNKNOWN, 0); return(packet_error); } if (net->read_pos[0] == 255) @@ -366,27 +370,37 @@ net_safe_read(MYSQL *mysql) if (len > 3) { char *pos=(char*) net->read_pos+1; - if (mysql->protocol_version > 9) - { /* New client protocol */ - net->last_errno=uint2korr(pos); - pos+=2; - len-=2; - /* Beginning from 4.1 also sqlstate will be delivered */ - if (pos[0]== '#') - strmake(net->sqlstate, pos+1, SQLSTATE_LENGTH); + uint last_errno=uint2korr(pos); + pos+=2; + len-=2; + + if (last_errno== 65535 && + (mysql->server_capabilities & CLIENT_PROGRESS)) + { + if (cli_report_progress(mysql, (uchar *)pos, (uint) (len-1))) + { + /* Wrong packet */ + my_set_error(mysql, CR_MALFORMED_PACKET, unknown_sqlstate, 0); + return (packet_error); + } + goto restart; + } + net->last_errno= last_errno; + if (pos[0]== '#') + { + strmake(net->sqlstate, pos+1, SQLSTATE_LENGTH); + pos+= SQLSTATE_LENGTH + 1; } else { - net->last_errno=CR_UNKNOWN_ERROR; - len--; + strmov(net->sqlstate, SQLSTATE_UNKNOWN); } (void) strmake(net->last_error,(char*) pos, min(len,sizeof(net->last_error)-1)); } else { - net->last_errno=CR_UNKNOWN_ERROR; - (void) strmov(net->last_error,ER(net->last_errno)); + my_set_error(mysql, CR_UNKNOWN_ERROR, SQLSTATE_UNKNOWN, 0); } mysql->server_status= ~SERVER_MORE_RESULTS_EXIST; @@ -398,6 +412,38 @@ net_safe_read(MYSQL *mysql) return len; } +/* + Report progress to the client + + RETURN VALUES + 0 ok + 1 error +*/ +static int cli_report_progress(MYSQL *mysql, uchar *packet, uint length) +{ + uint stage, max_stage, proc_length; + double progress; + uchar *start= packet; + + if (length < 5) + return 1; /* Wrong packet */ + + if (!(mysql->options.extension && mysql->options.extension->report_progress)) + return 0; /* No callback, ignore packet */ + + packet++; /* Ignore number of strings */ + stage= (uint) *packet++; + max_stage= (uint) *packet++; + progress= uint3korr(packet)/1000.0; + packet+= 3; + proc_length= net_field_length(&packet); + if (packet + proc_length > start + length) + return 1; /* Wrong packet */ + (*mysql->options.extension->report_progress)(mysql, stage, max_stage, + progress, (char*) packet, + proc_length); + return 0; +} /* Get the length of next field. Change parameter to point at fieldstart */ ulong @@ -475,20 +521,24 @@ void free_rows(MYSQL_DATA *cur) int simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, - uint length, my_bool skipp_check) + size_t length, my_bool skipp_check) { NET *net= &mysql->net; int result= -1; init_sigpipe_variables + DBUG_ENTER("simple_command"); + + DBUG_PRINT("info", ("server_command: %d packet_size: %u", command, length)); + /* Don't give sigpipe errors if the client doesn't want them */ set_sigpipe(mysql); if (mysql->net.vio == 0) { /* Do reconnect if possible */ if (mysql_reconnect(mysql)) { - SET_CLIENT_ERROR(mysql, CR_SERVER_GONE_ERROR, unknown_sqlstate, 0); - goto end; + DBUG_PRINT("info", ("reconnect failed")); + DBUG_RETURN(1); } } if (mysql->status != MYSQL_STATUS_READY || @@ -500,6 +550,8 @@ simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, mysql->net.last_error[0]=0; mysql->net.last_errno=0; + strmov(mysql->net.sqlstate, "00000"); + mysql->info=0; mysql->affected_rows= ~(my_ulonglong) 0; net_clear(net); /* Clear receive buffer */ @@ -512,8 +564,7 @@ simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, DBUG_PRINT("error",("Can't send command to server. Error: %d",socket_errno)); if (net->last_errno == ER_NET_PACKET_TOO_LARGE) { - net->last_errno=CR_NET_PACKET_TOO_LARGE; - strmov(net->last_error,ER(net->last_errno)); + my_set_error(mysql, CR_NET_PACKET_TOO_LARGE, SQLSTATE_UNKNOWN, 0); goto end; } end_server(mysql); @@ -522,18 +573,19 @@ simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, if (net_write_command(net,(uchar) command,arg, length ? length : (ulong) strlen(arg))) { - net->last_errno= CR_SERVER_GONE_ERROR; - strmov(net->last_error,ER(net->last_errno)); + my_set_error(mysql, CR_SERVER_GONE_ERROR, SQLSTATE_UNKNOWN, 0); goto end; } } result=0; - if (!skipp_check) + if (!skipp_check) { result= ((mysql->packet_length=net_safe_read(mysql)) == packet_error ? -1 : 0); + DBUG_PRINT("info", ("packet_length=%llu", mysql->packet_length)); + } end: reset_sigpipe(mysql); - return result; + DBUG_RETURN(result); } @@ -553,8 +605,8 @@ struct passwd *getpwuid(uid_t); char* getlogin(void); #endif -#if !defined(MSDOS) && ! defined(VMS) && !defined(__WIN__) && !defined(OS2) -static void read_user_name(char *name) +#if !defined(MSDOS) && ! defined(VMS) && !defined(_WIN32) && !defined(OS2) +void read_user_name(char *name) { DBUG_ENTER("read_user_name"); if (geteuid() == 0) @@ -584,15 +636,15 @@ static void read_user_name(char *name) #else /* If MSDOS || VMS */ -static void read_user_name(char *name) +void read_user_name(char *name) { - char *str=getenv("USER"); /* ODBC will send user variable */ + char *str=getenv("USERNAME"); /* ODBC will send user variable */ strmake(name,str ? str : "ODBC", USERNAME_LENGTH); } #endif -#ifdef __WIN__ +#ifdef _WIN32 static my_bool is_NT(void) { char *os=getenv("OS"); @@ -629,6 +681,14 @@ append_wild(char *to, char *end, const char *wild) /************************************************************************** ** Init debugging if MYSQL_DEBUG environment variable is found **************************************************************************/ +void STDCALL mysql_debug_end() +{ + if (_db_on_) + { + DEBUGGER_OFF; + DBUG_POP(); + } +} void STDCALL mysql_debug(const char *debug __attribute__((unused))) @@ -741,12 +801,45 @@ static const char *default_options[]= "ssl-key" ,"ssl-cert" ,"ssl-ca" ,"ssl-capath", "character-sets-dir", "default-character-set", "interactive-timeout", "connect-timeout", "local-infile", "disable-local-infile", - NullS + "ssl-cipher", "max-allowed-packet", "protocol", "shared-memory-base-name", + "multi-results", "multi-statements", "multi-queries", "secure-auth", + "report-data-truncation", "plugin-dir", "default-auth", + NULL +}; + +enum option_val +{ + OPT_port=1, OPT_socket, OPT_compress, OPT_password, OPT_pipe, + OPT_timeout, OPT_user, OPT_init_command, OPT_host, OPT_database, + OPT_debug, OPT_return_found_rows, OPT_ssl_key, OPT_ssl_cert, + OPT_ssl_ca, OPT_ssl_capath, OPT_charset_dir, + OPT_charset_name, OPT_interactive_timeout, + OPT_connect_timeout, OPT_local_infile, OPT_disable_local_infile, + OPT_ssl_cipher, OPT_max_allowed_packet, OPT_protocol, OPT_shared_memory_base_name, + OPT_multi_results, OPT_multi_statements, OPT_multi_queries, OPT_secure_auth, + OPT_report_data_truncation, OPT_plugin_dir, OPT_default_auth }; static TYPELIB option_types={array_elements(default_options)-1, "options",default_options}; +#define extension_set(OPTS, X, VAL) \ + if (!(OPTS)->extension) \ + (OPTS)->extension= (struct st_mysql_options_extention *) \ + my_malloc(sizeof(struct st_mysql_options_extention), \ + MYF(MY_WME | MY_ZEROFILL)); \ + (OPTS)->extension->X= VAL; + +#define extension_set_string(OPTS, X, STR) \ + if ((OPTS)->extension) \ + my_free((OPTS)->extension->X, MYF(MY_ALLOW_ZERO_PTR)); \ + extension_set(OPTS, X, my_strdup((STR), MYF(MY_WME))); + +const char *protocol_names[]= {"TCP", "SOCKED", "PIPE", "MEMORY", NULL}; +static TYPELIB protocol_types= {array_elements(protocol_names)-1, + "protocol names", + protocol_names}; + static void mysql_read_default_options(struct st_mysql_options *options, const char *filename,const char *group) { @@ -779,43 +872,43 @@ static void mysql_read_default_options(struct st_mysql_options *options, for (end= *option ; *(end= strcend(end,'_')) ; ) *end= '-'; switch (find_type(*option+2,&option_types,2)) { - case 1: /* port */ + case OPT_port: if (opt_arg) options->port=atoi(opt_arg); break; - case 2: /* socket */ + case OPT_socket: if (opt_arg) { my_free(options->unix_socket,MYF(MY_ALLOW_ZERO_PTR)); options->unix_socket=my_strdup(opt_arg,MYF(MY_WME)); } break; - case 3: /* compress */ + case OPT_compress: options->compress=1; break; - case 4: /* password */ + case OPT_password: if (opt_arg) { my_free(options->password,MYF(MY_ALLOW_ZERO_PTR)); options->password=my_strdup(opt_arg,MYF(MY_WME)); } break; - case 5: /* pipe */ + case OPT_pipe: options->named_pipe=1; /* Force named pipe */ break; - case 20: /* connect_timeout */ - case 6: /* timeout */ + case OPT_connect_timeout: + case OPT_timeout: if (opt_arg) options->connect_timeout=atoi(opt_arg); break; - case 7: /* user */ + case OPT_user: if (opt_arg) { my_free(options->user,MYF(MY_ALLOW_ZERO_PTR)); options->user=my_strdup(opt_arg,MYF(MY_WME)); } break; - case 8: /* init-command */ + case OPT_init_command: if (opt_arg) { /* todo @@ -824,70 +917,110 @@ static void mysql_read_default_options(struct st_mysql_options *options, */ } break; - case 9: /* host */ + case OPT_host: if (opt_arg) { my_free(options->host,MYF(MY_ALLOW_ZERO_PTR)); options->host=my_strdup(opt_arg,MYF(MY_WME)); } break; - case 10: /* database */ + case OPT_database: if (opt_arg) { my_free(options->db,MYF(MY_ALLOW_ZERO_PTR)); options->db=my_strdup(opt_arg,MYF(MY_WME)); } break; - case 11: /* debug */ + case OPT_debug: mysql_debug(opt_arg ? opt_arg : "d:t:o,/tmp/client.trace"); break; - case 12: /* return-found-rows */ + case OPT_return_found_rows: options->client_flag|=CLIENT_FOUND_ROWS; break; #ifdef HAVE_OPENSSL - case 13: /* ssl_key */ + case OPT_ssl_key: my_free(options->ssl_key, MYF(MY_ALLOW_ZERO_PTR)); - options->ssl_key = my_strdup(opt_arg, MYF(MY_WME)); - break; - case 14: /* ssl_cert */ + options->ssl_key = my_strdup(opt_arg, MYF(MY_WME)); + break; + case OPT_ssl_cert: my_free(options->ssl_cert, MYF(MY_ALLOW_ZERO_PTR)); - options->ssl_cert = my_strdup(opt_arg, MYF(MY_WME)); - break; - case 15: /* ssl_ca */ + options->ssl_cert = my_strdup(opt_arg, MYF(MY_WME)); + break; + case OPT_ssl_ca: my_free(options->ssl_ca, MYF(MY_ALLOW_ZERO_PTR)); - options->ssl_ca = my_strdup(opt_arg, MYF(MY_WME)); - break; - case 16: /* ssl_capath */ - my_free(options->ssl_capath, MYF(MY_ALLOW_ZERO_PTR)); - options->ssl_capath = my_strdup(opt_arg, MYF(MY_WME)); - break; + options->ssl_ca = my_strdup(opt_arg, MYF(MY_WME)); + break; + case OPT_ssl_capath: + my_free(options->ssl_capath, MYF(MY_ALLOW_ZERO_PTR)); + options->ssl_capath = my_strdup(opt_arg, MYF(MY_WME)); + break; + case OPT_ssl_cipher: + break; #else - case 13: /* Ignore SSL options */ - case 14: - case 15: - case 16: - break; + case OPT_ssl_key: + case OPT_ssl_cert: + case OPT_ssl_ca: + case OPT_ssl_capath: + case OPT_ssl_cipher: + break; #endif /* HAVE_OPENSSL */ - case 17: /* charset-lib */ + case OPT_charset_dir: my_free(options->charset_dir,MYF(MY_ALLOW_ZERO_PTR)); - options->charset_dir = my_strdup(opt_arg, MYF(MY_WME)); + options->charset_dir = my_strdup(opt_arg, MYF(MY_WME)); break; - case 18: + case OPT_charset_name: my_free(options->charset_name,MYF(MY_ALLOW_ZERO_PTR)); - options->charset_name = my_strdup(opt_arg, MYF(MY_WME)); + options->charset_name = my_strdup(opt_arg, MYF(MY_WME)); break; - case 19: /* Interactive-timeout */ + case OPT_interactive_timeout: options->client_flag|= CLIENT_INTERACTIVE; break; - case 21: + case OPT_local_infile: if (!opt_arg || atoi(opt_arg) != 0) options->client_flag|= CLIENT_LOCAL_FILES; else options->client_flag&= ~CLIENT_LOCAL_FILES; break; - case 22: + case OPT_disable_local_infile: options->client_flag&= CLIENT_LOCAL_FILES; break; + case OPT_max_allowed_packet: + if(opt_arg) + options->max_allowed_packet= atoi(opt_arg); + case OPT_protocol: + options->protocol= find_type(opt_arg, &protocol_types, 0); +#ifndef _WIN32 + if (options->protocol < 0 || options->protocol > 1) +#else + if (options->protocol < 0) +#endif + { + fprintf(stderr, + "Unknown or unsupported protocol %s", + opt_arg); + } + break; + case OPT_shared_memory_base_name: + /* todo */ + break; + case OPT_multi_results: + options->client_flag|= CLIENT_MULTI_RESULTS; + break; + case OPT_multi_statements: + case OPT_multi_queries: + options->client_flag|= CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS; + break; + case OPT_report_data_truncation: + if (opt_arg) + options->report_data_truncation= atoi(opt_arg); + else + options->report_data_truncation= 1; + break; + case OPT_secure_auth: + case OPT_plugin_dir: + case OPT_default_auth: + /* todo */ + break; default: DBUG_PRINT("warning",("unknown option: %s",option[0])); } @@ -925,9 +1058,9 @@ unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, MYSQL_ROWS *row; MYSQL_FIELD *field,*result; char *p; - DBUG_ENTER("unpack_fields"); unsigned int i, field_count= sizeof(rset_field_offsets)/sizeof(size_t)/2; + DBUG_ENTER("unpack_fields"); field=result=(MYSQL_FIELD*) alloc_root(alloc,sizeof(MYSQL_FIELD)*fields); if (!result) DBUG_RETURN(0); @@ -942,8 +1075,10 @@ unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, *(unsigned int *)(((char *)field) + rset_field_offsets[i*2+1])= 0; break; default: - *(char **)(((char *)field) + rset_field_offsets[i*2])= strdup_root(alloc, (char *)row->data[i]); - *(unsigned int *)(((char *)field) + rset_field_offsets[i*2+1])= row->data[i+1] - row->data[i] - 1; + *(char **)(((char *)field) + rset_field_offsets[i*2])= + strdup_root(alloc, (char *)row->data[i]); + *(unsigned int *)(((char *)field) + rset_field_offsets[i*2+1])= + (uint)(row->data[i+1] - row->data[i] - 1); break; } } @@ -1144,7 +1279,10 @@ mysql_init(MYSQL *mysql) else bzero((char*) (mysql),sizeof(*(mysql))); mysql->options.connect_timeout=CONNECT_TIMEOUT; -#if defined(SIGPIPE) && defined(THREAD) && !defined(__WIN__) + mysql->charset= default_charset_info; + strmov(mysql->net.sqlstate, "00000"); + mysql->net.last_error[0]= mysql->net.last_errno= 0; +#if defined(SIGPIPE) && defined(THREAD) && !defined(_WIN32) if (!((mysql)->client_flag & CLIENT_IGNORE_SIGPIPE)) (void) signal(SIGPIPE,pipe_sig_handler); #endif @@ -1161,7 +1299,7 @@ mysql_init(MYSQL *mysql) -#ifdef HAVE_OPENSSL +//#ifdef HAVE_OPENSSL /************************************************************************** ** Fill in SSL part of MYSQL structure and set 'use_ssl' flag. ** NB! Errors are not reported until you do mysql_real_connect. @@ -1175,8 +1313,8 @@ mysql_ssl_set(MYSQL *mysql, const char *key, const char *cert, mysql->options.ssl_cert = cert==0 ? 0 : my_strdup(cert,MYF(0)); mysql->options.ssl_ca = ca==0 ? 0 : my_strdup(ca,MYF(0)); mysql->options.ssl_capath = capath==0 ? 0 : my_strdup(capath,MYF(0)); - mysql->options.use_ssl = true; - mysql->connector_fd = new_VioSSLConnectorFd(key, cert, ca, capath); + mysql->options.use_ssl = 1; + //mysql->connector_fd = new_VioSSLConnectorFd(key, cert, ca, capath); return 0; } @@ -1187,6 +1325,7 @@ char * STDCALL mysql_ssl_cipher(MYSQL *mysql) { // return (char *)mysql->net.vio->cipher_description(); + return NULL; } @@ -1195,23 +1334,7 @@ mysql_ssl_cipher(MYSQL *mysql) ** NB! Errors are not reported until you do mysql_real_connect. **************************************************************************/ -int STDCALL -mysql_ssl_clear(MYSQL *mysql) -{ - my_free(mysql->options.ssl_key, MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.ssl_cert, MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.ssl_ca, MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.ssl_capath, MYF(MY_ALLOW_ZERO_PTR)); - mysql->options.ssl_key = 0; - mysql->options.ssl_cert = 0; - mysql->options.ssl_ca = 0; - mysql->options.ssl_capath = 0; - mysql->options.use_ssl = false; - mysql->connector_fd->delete(); - mysql->connector_fd = 0; - return 0; -} -#endif /* HAVE_OPENSSL */ +//#endif /* HAVE_OPENSSL */ /************************************************************************** ** Connect to sql server @@ -1246,14 +1369,17 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, const char *passwd, const char *db, uint port, const char *unix_socket,unsigned long client_flag) { - char buff[NAME_LEN+USERNAME_LENGTH+100],charset_name_buff[16]; - char *end,*host_info,*charset_name; + char buff[NAME_LEN+USERNAME_LENGTH+100]; + char *end, *end_pkt, *host_info, + *charset_name= NULL; my_socket sock; + char *scramble_data; + const char * scramble_plugin; uint32 ip_addr; struct sockaddr_in sock_addr; - uint pkt_length; + uint pkt_length, scramble_len, pkt_scramble_len= 0; NET *net= &mysql->net; -#ifdef __WIN__ +#ifdef _WIN32 HANDLE hPipe=INVALID_HANDLE_VALUE; #endif #ifdef HAVE_SYS_UN_H @@ -1339,13 +1465,13 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, mysql->options.connect_timeout) <0) { DBUG_PRINT("error",("Got error %d on connect to local server",socket_errno)); - net->last_errno=CR_CONNECTION_ERROR; - sprintf(net->last_error,ER(net->last_errno),unix_socket,socket_errno); + my_set_error(mysql, CR_CONNECTION_ERROR, SQLSTATE_UNKNOWN, ER(CR_CONNECTION_ERROR), + unix_socket, socket_errno); goto error; } } else -#elif defined(__WIN__) +#elif defined(_WIN32) { if ((unix_socket || !host && is_NT() || @@ -1390,8 +1516,8 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, /* _WIN64 ; Assume that the (int) range is enough for socket() */ if ((sock = (my_socket) socket(AF_INET,SOCK_STREAM,0)) == SOCKET_ERROR) { - net->last_errno=CR_IPSOCK_ERROR; - sprintf(net->last_error,ER(net->last_errno),socket_errno); + my_set_error(mysql, CR_IPSOCK_ERROR, SQLSTATE_UNKNOWN, ER(CR_IPSOCK_ERROR), + socket_errno); goto error; } net->vio = vio_new(sock,VIO_TYPE_TCPIP,FALSE); @@ -1415,8 +1541,8 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, &tmp_errno); if (!hp) { - net->last_errno=CR_UNKNOWN_HOST; - sprintf(net->last_error, ER(CR_UNKNOWN_HOST), host, tmp_errno); + my_set_error(mysql, CR_UNKNOWN_HOST, SQLSTATE_UNKNOWN, ER(CR_UNKNOWN_HOST), + host, tmp_errno); my_gethostbyname_r_free(); goto error; } @@ -1428,8 +1554,8 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, mysql->options.connect_timeout) <0) { DBUG_PRINT("error",("Got error %d on connect to '%s'",socket_errno,host)); - net->last_errno= CR_CONN_HOST_ERROR; - sprintf(net->last_error ,ER(CR_CONN_HOST_ERROR), host, socket_errno); + my_set_error(mysql, CR_CONN_HOST_ERROR, SQLSTATE_UNKNOWN, + ER(CR_CONN_HOST_ERROR), host, socket_errno); goto error; } } @@ -1442,20 +1568,31 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, goto error; } vio_keepalive(net->vio,TRUE); + strmov(mysql->net.sqlstate, "00000"); + + + /* set read timeout */ + if (mysql->options.read_timeout) + vio_read_timeout(net->vio, mysql->options.read_timeout); + + /* set write timeout */ + if (mysql->options.write_timeout) + vio_write_timeout(net->vio, mysql->options.read_timeout); + /* Get version info */ mysql->protocol_version= PROTOCOL_VERSION; /* Assume this */ if (mysql->options.connect_timeout && vio_poll_read(net->vio, mysql->options.connect_timeout)) { - net->last_errno= CR_SERVER_LOST; - strmov(net->last_error,ER(net->last_errno)); + my_set_error(mysql, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); goto error; } if ((pkt_length=net_safe_read(mysql)) == packet_error) goto error; end= (char *)net->read_pos; + end_pkt= (char *)net->read_pos + pkt_length; /* Check if version of protocoll matches current one */ @@ -1483,67 +1620,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, PROTOCOL_VERSION); goto error; } - - mysql->server_version= my_strdup(end, MYF(0)); - end+= strlen(mysql->server_version) + 1; - - mysql->thread_id=uint4korr(end); - end+=4; - - /* This is the first part of scramble packet. In 4.1 and later - a second package will follow later */ - strmake(mysql->scramble_buff, end, SCRAMBLE_LENGTH_323); - end+=8; - - /* 1st pad */ - end++; - - mysql->server_capabilities=uint2korr(end); - end+= 2; - - mysql->server_language= end[0]; - end++; - - mysql->server_status= uint2korr(end); - end+= 2; - - /* pad 2 */ - end+= 13; - - /* second scramble package */ - if ((size_t) ((uchar *)end - net->read_pos) < pkt_length) - { - memcpy(mysql->scramble_buff + SCRAMBLE_LENGTH_323, - end, SCRAMBLE_LENGTH - SCRAMBLE_LENGTH_323); - } - - /* Set character set */ - if ((charset_name=mysql->options.charset_name)) - { - mysql->charset=get_charset_by_name(mysql->options.charset_name, - MYF(MY_WME)); - } - else if (mysql->server_language) - { - charset_name=charset_name_buff; - sprintf(charset_name,"%d",mysql->server_language); /* In case of errors */ - if (!(mysql->charset = - get_charset((uint8) mysql->server_language, MYF(MY_WME)))) - mysql->charset = default_charset_info; /* shouldn't be fatal */ - - } - else - mysql->charset=default_charset_info; - - if (!mysql->charset) - { - net->last_errno=CR_CANT_READ_CHARSET; - sprintf(net->last_error,ER(net->last_errno), - charset_name ? charset_name : "unknown", - "compiled_in"); - goto error; - } - /* Save connection information */ if (!user) user=""; if (!passwd) passwd=""; @@ -1553,7 +1629,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, &mysql->host, (uint) strlen(host)+1, &mysql->unix_socket,unix_socket ? (uint) strlen(unix_socket)+1 : (uint) 1, -// &mysql->server_version, (uint) (end - (char*) net->read_pos), + &mysql->server_version, (uint) (end - (char*) net->read_pos), NullS) || !(mysql->user=my_strdup(user,MYF(0))) || !(mysql->passwd=my_strdup(passwd,MYF(0)))) @@ -1570,136 +1646,122 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, mysql->port=port; client_flag|=mysql->options.client_flag; - /* Send client information for access check */ - client_flag|=CLIENT_CAPABILITIES; - - /* if we support multiple statements in one query, we have to support - also multiple result sets */ - if (client_flag & CLIENT_MULTI_STATEMENTS) - client_flag|= CLIENT_MULTI_RESULTS; - -#ifdef HAVE_OPENSSL - if (mysql->options.use_ssl) - client_flag|=CLIENT_SSL; -#endif /* HAVE_OPENSSL */ + mysql->server_version= my_strdup(end, MYF(0)); + end+= strlen(mysql->server_version) + 1; - if (db) - client_flag|=CLIENT_CONNECT_WITH_DB; + mysql->thread_id=uint4korr(end); + end+=4; -#ifndef HAVE_COMPRESS - client_flag&= ~CLIENT_COMPRESS; -#endif + /* This is the first part of scramble packet. In 4.1 and later + a second package will follow later */ + scramble_data= end; + scramble_len= SCRAMBLE_LENGTH_323 + 1; + scramble_plugin= old_password_plugin_name; + end+= SCRAMBLE_LENGTH_323; - /* check if all options are supported by server, if not remove them */ - client_flag= ((client_flag & ~CLIENT_PROTOCOL_41) | (client_flag & mysql->server_capabilities)); - client_flag= ((client_flag & ~CLIENT_COMPRESS) | (client_flag & mysql->server_capabilities)); - client_flag= ((client_flag & ~CLIENT_SSL) | (client_flag & mysql->server_capabilities)); + /* 1st pad */ + end++; -#ifdef HAVE_COMPRESS - if ((mysql->server_capabilities & CLIENT_COMPRESS) && - (mysql->options.compress || (client_flag & CLIENT_COMPRESS))) - client_flag|=CLIENT_COMPRESS; /* We will use compression */ - else -#endif - client_flag&= ~CLIENT_COMPRESS; + if (end + 1<= end_pkt) + { + mysql->server_capabilities=uint2korr(end); + } -#ifdef HAVE_OPENSSL - if ((mysql->server_capabilities & CLIENT_SSL) && - (mysql->options.use_ssl || (client_flag & CLIENT_SSL))) + /* mysql 5.5 protocol */ + if (end + 18 <= end_pkt) { - DBUG_PRINT("info", ("Changing IO layer to SSL")); - client_flag |= CLIENT_SSL; + mysql->server_language= uint1korr(end + 2); + mysql->server_status= uint2korr(end + 3); + mysql->server_capabilities|= uint2korr(end + 5) << 16; + pkt_scramble_len= uint1korr(end + 7); } - else + /* pad 2 */ + end+= 18; + + /* second scramble package */ + if (end + SCRAMBLE_LENGTH - SCRAMBLE_LENGTH_323 + 1 <= end_pkt) { - if (client_flag & CLIENT_SSL) + memcpy(end - SCRAMBLE_LENGTH_323, scramble_data, SCRAMBLE_LENGTH_323); + scramble_data= end - SCRAMBLE_LENGTH_323; + if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH) + { + scramble_len= pkt_scramble_len; + scramble_plugin= scramble_data + scramble_len; + if (scramble_data + scramble_len > end_pkt) + scramble_len= end_pkt - scramble_data; + } else { - DBUG_PRINT("info", ("Leaving IO layer intact because server doesn't support SSL")); + scramble_len= end_pkt - scramble_data; + scramble_plugin= native_password_plugin_name; } - client_flag &= ~CLIENT_SSL; + } else + mysql->server_capabilities&= ~CLIENT_SECURE_CONNECTION; + + /* Set character set */ + if (mysql->options.charset_name) + mysql->charset= mysql_find_charset_name(mysql->options.charset_name); + else if (mysql->server_language) + mysql->charset= mysql_find_charset_nr(mysql->server_language); + else + mysql->charset=default_charset_info; + + if (!mysql->charset) + { + net->last_errno=CR_CANT_READ_CHARSET; + sprintf(net->last_error,ER(net->last_errno), + charset_name ? charset_name : "unknown", + "compiled_in"); + goto error; } -#endif /* HAVE_OPENSSL */ - end= buff; - int4store(end, client_flag); - end+= 4; - int4store(end, net->max_packet); - end+= 4; - /* we use the charset implementation from PHP's mysqlnd extension which has the - same character set numbers */ - *end++= mysql->charset->nr; + mysql->client_flag= client_flag; - /* filler */ - bzero(end, 23); - end+= 23; + if (run_plugin_auth(mysql, scramble_data, scramble_len, + scramble_plugin, db)) + goto error; - mysql->client_flag=client_flag; + if (mysql->client_flag & CLIENT_COMPRESS) + net->compress= 1; -#ifdef HAVE_OPENSSL - /* Oops.. are we careful enough to not send ANY information */ - /* without encryption? */ - if (client_flag & CLIENT_SSL) + /* last part: select default db */ + if (db && !mysql->db) { - if (my_net_write(net,buff,(uint) (2)) || net_flush(net)) + if (mysql_select_db(mysql, db)) + { + my_set_error(mysql, CR_SERVER_LOST, unknown_sqlstate, + ER(CR_SERVER_LOST_EXTENDED), + "Setting intital database", + errno); goto error; - /* Do the SSL layering. */ - DBUG_PRINT("info", ("IO layer change in progress...")); - VioSSLConnectorFd* connector_fd = (VioSSLConnectorFd*) - (mysql->connector_fd); - VioSocket* vio_socket = (VioSocket*)(mysql->net.vio); - VioSSL* vio_ssl = connector_fd->connect(vio_socket); - mysql->net.vio = (NetVio*)(vio_ssl); - } -#endif /* HAVE_OPENSSL */ + } + } DBUG_PRINT("info",("Server version = '%s' capabilites: %ld status: %d client_flag: %d", mysql->server_version,mysql->server_capabilities, mysql->server_status, client_flag)); - if (user && user[0]) - strmake(end,user,32); /* Max user name */ - else - read_user_name((char*) end); -#ifdef _CUSTOMCONFIG_ -#include "_cust_libmysql.h"; -#endif - end+= strlen(user); - *end++= '\0'; - - /* todo : check server capatibilites for secure_connection */ - if (passwd && passwd[0]) - { - *end++= SCRAMBLE_LENGTH; - my_scramble_41((const unsigned char *)end, mysql->scramble_buff, passwd); - end+= SCRAMBLE_LENGTH; - } - else - *end++= 0; - - if (db && (mysql->server_capabilities & CLIENT_CONNECT_WITH_DB)) - { - end=strmake(end,db,NAME_LEN); - mysql->db=my_strdup(db,MYF(MY_WME)); - db=0; - } - if (my_net_write(net,buff,(uint) (end-buff)) || net_flush(net) || - net_safe_read(mysql) == packet_error) - goto error; - if (client_flag & CLIENT_COMPRESS) /* We will use compression */ - net->compress=1; - if (db && mysql_select_db(mysql,db)) - goto error; -/* todo if (mysql->options.init_command) { - my_bool reconnect=mysql->reconnect; - mysql->reconnect=0; - if (mysql_query(mysql,mysql->options.init_command)) + MYSQL_RES *res; + int status; + /* Avoid reconnect in mysql_real_connect */ + my_bool save_reconnect= mysql->reconnect; + + mysql->reconnect= 0; + + if (mysql_query(mysql, mysql->options.init_command)) goto error; - mysql_free_result(mysql_use_result(mysql)); - mysql->reconnect=reconnect; + + /* handle possible multi results */ + do { + if ((res= mysql_use_result(mysql))) + mysql_free_result(res); + status= mysql_next_result(mysql); + } while (status == 0); + mysql->reconnect= save_reconnect; } -*/ + + strmov(mysql->net.sqlstate, "00000"); DBUG_PRINT("exit",("Mysql handler: %lx",mysql)); reset_sigpipe(mysql); @@ -1710,11 +1772,9 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, DBUG_PRINT("error",("message: %u (%s)",net->last_errno,net->last_error)); { /* Free alloced memory */ - my_bool free_me=mysql->free_me; end_server(mysql); - mysql->free_me=0; - mysql_close(mysql); - mysql->free_me=free_me; + /* only free the allocated memory, user needs to call mysql_close */ + mysql_close_memory(mysql); } DBUG_RETURN(0); } @@ -1723,6 +1783,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, static my_bool mysql_reconnect(MYSQL *mysql) { MYSQL tmp_mysql; + LIST *li_stmt= mysql->stmts; DBUG_ENTER("mysql_reconnect"); if (!mysql->reconnect || @@ -1730,6 +1791,7 @@ static my_bool mysql_reconnect(MYSQL *mysql) { /* Allov reconnect next time */ mysql->server_status&= ~SERVER_STATUS_IN_TRANS; + my_set_error(mysql, CR_SERVER_GONE_ERROR, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); } mysql_init(&tmp_mysql); @@ -1738,13 +1800,28 @@ static my_bool mysql_reconnect(MYSQL *mysql) if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd, mysql->db, mysql->port, mysql->unix_socket, mysql->client_flag)) + { + my_set_error(mysql, tmp_mysql.net.last_errno, + tmp_mysql.net.sqlstate, + tmp_mysql.net.last_error); DBUG_RETURN(1); + } tmp_mysql.free_me=mysql->free_me; mysql->free_me=0; mysql_close(mysql); *mysql=tmp_mysql; net_clear(&mysql->net); mysql->affected_rows= ~(my_ulonglong) 0; + + /* reset the connection in all active statements + todo: check stmt->mysql in mysql_stmt* functions ! */ + for (;li_stmt;li_stmt= li_stmt->next) + { + MYSQL_STMT *stmt= (MYSQL_STMT *)li_stmt->data; + stmt->mysql= NULL; + stmt->state= MYSQL_STMT_INITTED; + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + } DBUG_RETURN(0); } @@ -1756,9 +1833,11 @@ static my_bool mysql_reconnect(MYSQL *mysql) my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, const char *passwd, const char *db) { - char buffer[USERNAME_LENGTH + SCRAMBLE_LENGTH + NAME_LEN + 2]; - char *p= buffer; - ulong pkt_len; + const CHARSET_INFO *s_cs= mysql->charset; + char *s_user= mysql->user, + *s_passwd= mysql->passwd, + *s_db= mysql->db; + int rc; DBUG_ENTER("mysql_change_user"); @@ -1769,58 +1848,45 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, if (!db) db=""; - if (mysql->options.charset_name) - mysql->charset=get_charset_by_name(mysql->options.charset_name, - MYF(MY_WME)); + if (mysql->options.charset_name) + mysql->charset =mysql_find_charset_name(mysql->options.charset_name); else if (mysql->server_language) - mysql->charset=find_compiled_charset(mysql->server_language); + mysql->charset=mysql_find_charset_nr(mysql->server_language); else mysql->charset=default_charset_info; + mysql->user= (char *)user; + mysql->passwd= (char *)passwd; + mysql->db= (char *)db; + rc= run_plugin_auth(mysql, 0, 0, 0, db); - /* 1. user name */ - memcpy(p, user, MIN(strlen(user), USERNAME_LENGTH)); - p+= MIN(strlen(user), USERNAME_LENGTH); - *p++= 0; - - /* 2. password scramble length, followed by scramble or \0 */ - if (passwd[0]) + if (rc==0) { - *p++= SCRAMBLE_LENGTH; - my_scramble_41((const unsigned char *)p, mysql->scramble_buff, passwd); - p+= SCRAMBLE_LENGTH; - } - else - *p++= 0; + LIST *li_stmt= mysql->stmts; + my_free(s_user,MYF(MY_ALLOW_ZERO_PTR)); + my_free(s_passwd,MYF(MY_ALLOW_ZERO_PTR)); + my_free(s_db,MYF(MY_ALLOW_ZERO_PTR)); + + mysql->user= my_strdup(user,MYF(MY_WME)); + mysql->passwd=my_strdup(passwd,MYF(MY_WME)); + mysql->db= db ? my_strdup(db,MYF(MY_WME)) : 0; - /* 3. database */ - if (db[0]) + for (;li_stmt;li_stmt= li_stmt->next) + { + MYSQL_STMT *stmt= (MYSQL_STMT *)li_stmt->data; + stmt->mysql= NULL; + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + }/* detach stmts */ + mysql->stmts= NULL; + + } else { - memcpy(p, db, MIN(strlen(db), NAME_LEN)); - p+= MIN(strlen(db), NAME_LEN); + mysql->user= s_user; + mysql->passwd= s_passwd; + mysql->db= s_db; + mysql->charset= s_cs; } - *p++= 0; - - /* 4. character set number */ - int2store(p, mysql->charset->nr); - p+= 2; - - simple_command(mysql, MYSQL_COM_CHANGE_USER, buffer, p - buffer, 1); - - /* read response */ - if (packet_error == (pkt_len= net_safe_read(mysql))) - DBUG_RETURN(1); - - /* todo: are the statements still valid or do we set an error ? */ - - my_free(mysql->user,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->passwd,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR)); - - mysql->user= my_strdup(user,MYF(MY_WME)); - mysql->passwd=my_strdup(passwd,MYF(MY_WME)); - mysql->db= db ? my_strdup(db,MYF(MY_WME)) : 0; - DBUG_RETURN(0); + DBUG_RETURN(rc); } @@ -1848,6 +1914,37 @@ mysql_select_db(MYSQL *mysql, const char *db) ** If handle is alloced by mysql connect free it. *************************************************************************/ +static void mysql_close_memory(MYSQL *mysql) +{ + my_free(mysql->user,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->passwd,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->server_version,MYF(MY_ALLOW_ZERO_PTR)); + mysql->server_version=mysql->user=mysql->passwd=mysql->db=0; +} + + + +void my_set_error(MYSQL *mysql, + unsigned int error_nr, + const char *sqlstate, + const char *format, + ...) +{ + va_list ap; + + DBUG_ENTER("my_set_error"); + + mysql->net.last_errno= error_nr; + strncpy(mysql->net.sqlstate, sqlstate, SQLSTATE_LENGTH); + va_start(ap, format); + my_vsnprintf(mysql->net.last_error, MYSQL_ERRMSG_SIZE, + format ? format : ER(error_nr), ap); + DBUG_PRINT("info", ("error(%d) %s", error_nr, mysql->net.last_error)); + va_end(ap); + DBUG_VOID_RETURN; +} + void STDCALL mysql_close(MYSQL *mysql) { @@ -1865,18 +1962,20 @@ mysql_close(MYSQL *mysql) } /* reset the connection in all active statements - todo: check stmt->conn in mysql_stmt* functions ! */ + todo: check stmt->mysql in mysql_stmt* functions ! */ for (;li_stmt;li_stmt= li_stmt->next) { MYSQL_STMT *stmt= (MYSQL_STMT *)li_stmt->data; - stmt->conn= NULL; - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + stmt->mysql= NULL; + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); } - my_free(mysql->host_info,MYF(MY_ALLOW_ZERO_PTR)); + mysql_close_memory(mysql); + //my_free(mysql->host_info,MYF(MY_ALLOW_ZERO_PTR)); my_free(mysql->user,MYF(MY_ALLOW_ZERO_PTR)); my_free(mysql->passwd,MYF(MY_ALLOW_ZERO_PTR)); my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR)); my_free(mysql->server_version,MYF(MY_ALLOW_ZERO_PTR)); + mysql->host_info=mysql->user=mysql->passwd=mysql->db=0; /* todo my_free(mysql->options.init_command,MYF(MY_ALLOW_ZERO_PTR)); @@ -1891,7 +1990,6 @@ mysql_close(MYSQL *mysql) my_free(mysql->options.charset_dir,MYF(MY_ALLOW_ZERO_PTR)); my_free(mysql->options.charset_name,MYF(MY_ALLOW_ZERO_PTR)); /* Clear pointers for better safety */ - mysql->host_info=mysql->user=mysql->passwd=mysql->db=0; bzero((char*) &mysql->options,sizeof(mysql->options)); mysql->net.vio= 0; #ifdef HAVE_OPENSSL @@ -1936,7 +2034,7 @@ int STDCALL mysql_read_query_result(MYSQL *mysql) ulong length; DBUG_ENTER("mysql_read_query_result"); - if ((length = net_safe_read(mysql)) == packet_error) + if (!mysql || (length = net_safe_read(mysql)) == packet_error) DBUG_RETURN(1); free_old_query(mysql); /* Free old result */ get_info: @@ -1955,7 +2053,8 @@ int STDCALL mysql_read_query_result(MYSQL *mysql) } if (field_count == NULL_LENGTH) /* LOAD DATA LOCAL INFILE */ { - int error=send_file_to_server(mysql,(char*) pos); + int error=mysql_handle_local_infile(mysql, (char *)pos); + if ((length=net_safe_read(mysql)) == packet_error || error) DBUG_RETURN(-1); goto get_info; /* Get info packet */ @@ -1981,67 +2080,13 @@ mysql_real_query(MYSQL *mysql, const char *query, uint length) { DBUG_ENTER("mysql_real_query"); DBUG_PRINT("enter",("handle: %lx",mysql)); - DBUG_PRINT("query",("Query = \"%s\"",query)); + DBUG_PRINT("query",("Query = \"%.255s\" length=%u",query, length)); + if (simple_command(mysql,MYSQL_COM_QUERY,query,length,1)) DBUG_RETURN(-1); DBUG_RETURN(mysql_read_query_result(mysql)); } -static int -send_file_to_server(MYSQL *mysql, const char *filename) -{ - int fd, readcount; - char buf[IO_SIZE*15],*tmp_name; - DBUG_ENTER("send_file_to_server"); - - fn_format(buf,filename,"","",4); /* Convert to client format */ - if (!(tmp_name=my_strdup(buf,MYF(0)))) - { - SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); - DBUG_RETURN(-1); - } - if ((fd = my_open(tmp_name,O_RDONLY, MYF(0))) < 0) - { - mysql->net.last_errno=EE_FILENOTFOUND; - sprintf(buf,EE(mysql->net.last_errno),tmp_name,errno); - strmake(mysql->net.last_error,buf,sizeof(mysql->net.last_error)-1); - my_net_write(&mysql->net,"",0); net_flush(&mysql->net); - my_free(tmp_name,MYF(0)); - DBUG_RETURN(-1); - } - - while ((readcount = (int) my_read(fd,buf,sizeof(buf),MYF(0))) > 0) - { - if (my_net_write(&mysql->net,buf,readcount)) - { - SET_CLIENT_ERROR(mysql, CR_SERVER_LOST, unknown_sqlstate, 0); - DBUG_PRINT("error",("Lost connection to MySQL server during LOAD DATA of local file")); - (void) my_close(fd,MYF(0)); - my_free(tmp_name,MYF(0)); - DBUG_RETURN(-1); - } - } - (void) my_close(fd,MYF(0)); - /* Send empty packet to mark end of file */ - if (my_net_write(&mysql->net,"",0) || net_flush(&mysql->net)) - { - /* ??? */ - SET_CLIENT_ERROR(mysql, CR_SERVER_LOST, unknown_sqlstate, 0); - sprintf(mysql->net.last_error,ER(mysql->net.last_errno),socket_errno); - my_free(tmp_name,MYF(0)); - DBUG_RETURN(-1); - } - if (readcount < 0) - { - sprintf(buf,EE(mysql->net.last_errno),tmp_name,errno); - SET_CLIENT_ERROR(mysql, EE_READ, buf, unknown_sqlstate); - my_free(tmp_name,MYF(0)); - DBUG_RETURN(-1); - } - DBUG_RETURN(0); -} - - /************************************************************************** ** Alloc result struct for buffered results. All rows are read to buffer. ** mysql_data_seek may be used. @@ -2132,12 +2177,9 @@ mysql_use_result(MYSQL *mysql) DBUG_RETURN(result); /* Data is read to be fetched */ } - - /************************************************************************** ** Return next field of the query results **************************************************************************/ - MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *result) { @@ -2146,11 +2188,9 @@ mysql_fetch_field(MYSQL_RES *result) return &result->fields[result->current_field++]; } - /************************************************************************** ** Return next row of the query results **************************************************************************/ - MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *res) { @@ -2198,7 +2238,7 @@ ulong * STDCALL mysql_fetch_lengths(MYSQL_RES *res) { ulong *lengths,*prev_length; - byte *start; + char *start; MYSQL_ROW column,end; if (!(column=res->current_row)) @@ -2489,10 +2529,10 @@ mysql_get_proto_info(MYSQL *mysql) return (mysql->protocol_version); } -char * STDCALL +const char * STDCALL mysql_get_client_info(void) { - return (char*) MYSQL_SERVER_VERSION; + return (char*) MYSQL_CLIENT_VERSION; } @@ -2507,6 +2547,7 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg) break; case MYSQL_OPT_COMPRESS: mysql->options.compress= 1; /* Remember for connect */ + mysql->options.client_flag|= CLIENT_COMPRESS; break; case MYSQL_OPT_NAMED_PIPE: mysql->options.named_pipe=1; /* Force named pipe */ @@ -2518,10 +2559,8 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg) mysql->options.client_flag&= ~CLIENT_LOCAL_FILES; break; case MYSQL_INIT_COMMAND: - /* todo my_free(mysql->options.init_command,MYF(MY_ALLOW_ZERO_PTR)); mysql->options.init_command=my_strdup(arg,MYF(MY_WME)); - */ break; case MYSQL_READ_DEFAULT_FILE: my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR)); @@ -2532,8 +2571,8 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg) mysql->options.my_cnf_group=my_strdup(arg,MYF(MY_WME)); break; case MYSQL_SET_CHARSET_DIR: - my_free(mysql->options.charset_dir,MYF(MY_ALLOW_ZERO_PTR)); - mysql->options.charset_dir=my_strdup(arg,MYF(MY_WME)); + /* not supported in this version. Since all character sets + are internally available, we don't throw an error */ break; case MYSQL_SET_CHARSET_NAME: my_free(mysql->options.charset_name,MYF(MY_ALLOW_ZERO_PTR)); @@ -2542,6 +2581,33 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const char *arg) case MYSQL_OPT_RECONNECT: mysql->reconnect= *(uint *)arg; break; + case MYSQL_OPT_PROTOCOL: +#ifdef _WIN32 + if (*(uint *)arg > MYSQL_PROTOCOL_PIPE) +#else + if (*(uint *)arg > MYSQL_PROTOCOL_SOCKET) +#endif + DBUG_RETURN(-1); + mysql->options.protocol= *(uint *)arg; + break; + case MYSQL_OPT_READ_TIMEOUT: + mysql->options.read_timeout= *(uint *)arg; + break; + case MYSQL_OPT_WRITE_TIMEOUT: + mysql->options.write_timeout= *(uint *)arg; + break; + case MYSQL_REPORT_DATA_TRUNCATION: + mysql->options.report_data_truncation= *(uint *)arg; + break; + case MYSQL_OPT_PROGRESS_CALLBACK: + if (!mysql->options.extension) + mysql->options.extension= (struct st_mysql_options_extention *) + my_malloc(sizeof(struct st_mysql_options_extention), + MYF(MY_WME | MY_ZEROFILL)); + if (mysql->options.extension) + mysql->options.extension->report_progress= + (void (*)(const MYSQL *, uint, uint, double, const char *, uint)) arg; + break; default: DBUG_RETURN(-1); } @@ -2564,6 +2630,7 @@ unsigned int STDCALL mysql_num_fields(MYSQL_RES *res) return res->field_count; } +/* deprecated */ my_bool STDCALL mysql_eof(MYSQL_RES *res) { return res->eof; @@ -2676,7 +2743,7 @@ ulong STDCALL mysql_thread_id(MYSQL *mysql) const char * STDCALL mysql_character_set_name(MYSQL *mysql) { - return mysql->charset->name; + return mysql->charset->csname; } @@ -2700,9 +2767,9 @@ uint STDCALL mysql_thread_safe(void) */ ulong STDCALL -mysql_escape_string(char *to,const char *from,ulong length) +mysql_escape_string(char *to,const char *from, ulong length) { - return mysql_sub_escape_string(default_charset_info,to,from,length); + return (ulong)mysql_cset_escape_slashes(default_charset_info, to, from, length); } ulong STDCALL @@ -2710,166 +2777,30 @@ mysql_real_escape_string(MYSQL *mysql, char *to,const char *from, ulong length) { if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES) - return mysql_cset_escape_quotes(mysql->charset, to, from, length); + return (ulong)mysql_cset_escape_quotes(mysql->charset, to, from, length); else - return mysql_cset_escape_slashes(mysql->charset, to, from, length); -} - - -static ulong -mysql_sub_escape_string(CHARSET_INFO *charset_info, char *to, - const char *from, ulong length) -{ - const char *to_start=to; - const char *end; -#ifdef USE_MB - my_bool use_mb_flag=use_mb(charset_info); -#endif - for (end=from+length; from != end ; from++) - { -#ifdef USE_MB - int l; - if (use_mb_flag && (l = my_ismbchar(charset_info, from, end))) - { - while (l--) - *to++ = *from++; - from--; - continue; - } -#endif - switch (*from) { - case 0: /* Must be escaped for 'mysql' */ - *to++= '\\'; - *to++= '0'; - break; - case '\n': /* Must be escaped for logs */ - *to++= '\\'; - *to++= 'n'; - break; - case '\r': - *to++= '\\'; - *to++= 'r'; - break; - case '\\': - *to++= '\\'; - *to++= '\\'; - break; - case '\'': - *to++= '\\'; - *to++= '\''; - break; - case '"': /* Better safe than sorry */ - *to++= '\\'; - *to++= '"'; - break; - case '\032': /* This gives problems on Win32 */ - *to++= '\\'; - *to++= 'Z'; - break; - default: - *to++= *from; - } - } - *to=0; - return (ulong) (to-to_start); -} - - -char * STDCALL -mysql_odbc_escape_string(MYSQL *mysql, - char *to, ulong to_length, - const char *from, ulong from_length, - void *param, - char * (*extend_buffer) - (void *, char *, ulong *)) -{ - char *to_end=to+to_length-5; - const char *end; -#ifdef USE_MB - my_bool use_mb_flag=use_mb(mysql->charset); -#endif - - for (end=from+from_length; from != end ; from++) - { - if (to >= to_end) - { - to_length = (ulong) (end-from)+512; /* We want this much more */ - if (!(to=(*extend_buffer)(param, to, &to_length))) - return to; - to_end=to+to_length-5; - } -#ifdef USE_MB - { - int l; - if (use_mb_flag && (l = my_ismbchar(mysql->charset, from, end))) - { - while (l--) - *to++ = *from++; - from--; - continue; - } - } -#endif - switch (*from) { - case 0: /* Must be escaped for 'mysql' */ - *to++= '\\'; - *to++= '0'; - break; - case '\n': /* Must be escaped for logs */ - *to++= '\\'; - *to++= 'n'; - break; - case '\r': - *to++= '\\'; - *to++= 'r'; - break; - case '\\': - *to++= '\\'; - *to++= '\\'; - break; - case '\'': - *to++= '\\'; - *to++= '\''; - break; - case '"': /* Better safe than sorry */ - *to++= '\\'; - *to++= '"'; - break; - case '\032': /* This gives problems on Win32 */ - *to++= '\\'; - *to++= 'Z'; - break; - default: - *to++= *from; - } - } - return to; + return (ulong)mysql_cset_escape_slashes(mysql->charset, to, from, length); } void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name) { char *to; -#ifdef USE_MB - my_bool use_mb_flag=use_mb(mysql->charset); - char *end; - LINT_INIT(end); + my_bool use_mb_flag= (mysql->charset->char_maxlen > 1); + char *end= 0; if (use_mb_flag) for (end=name; *end ; end++) ; -#endif for (to=name ; *name ; name++) { -#ifdef USE_MB int l; - if (use_mb_flag && (l = my_ismbchar( mysql->charset, name , end ) ) ) + if (use_mb_flag && (l = mysql->charset->mb_valid(name , end))) { while (l--) *to++ = *name++; name--; continue; } -#endif if (*name == '\\' && name[1]) name++; *to++= *name; @@ -2877,7 +2808,6 @@ myodbc_remove_escape(MYSQL *mysql,char *name) *to=0; } - void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *cs) { DBUG_ENTER("mysql_get_character_set_info"); @@ -2886,8 +2816,8 @@ void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *cs) DBUG_VOID_RETURN; cs->number= mysql->charset->nr; - cs->csname= mysql->charset->name; - cs->name= mysql->charset->collation; + cs->csname= mysql->charset->csname; + cs->name= mysql->charset->name; cs->state= 0; cs->comment= NULL; cs->dir= NULL; @@ -2899,18 +2829,18 @@ void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *cs) int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname) { - CHARSET_INFO *cs; + const CHARSET_INFO *cs; DBUG_ENTER("mysql_set_character_set"); if (!csname) goto error; - if ((cs= get_charset_by_name(csname, 0))) + if ((cs= mysql_find_charset_name(csname))) { char buff[64]; - snprintf(buff, 63, "SET NAMES %s", cs->name); - if (!mysql_real_query(mysql, buff, strlen(buff))) + my_snprintf(buff, 63, "SET NAMES %s", cs->csname); + if (!mysql_real_query(mysql, buff, (uint)strlen(buff))) { mysql->charset= cs; DBUG_RETURN(0); @@ -2918,7 +2848,8 @@ int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname) } error: - SET_CLIENT_ERROR(mysql, CR_CANT_READ_CHARSET, SQLSTATE_UNKNOWN, 0); + my_set_error(mysql, CR_CANT_READ_CHARSET, SQLSTATE_UNKNOWN, + 0, csname, "compiled_in"); DBUG_RETURN(mysql->net.last_errno); } @@ -2943,11 +2874,14 @@ int STDCALL mysql_server_init(int argc __attribute__((unused)), mysql_client_init=1; my_init(); /* Will init threads */ init_client_errs(); + if (mysql_client_plugin_init()) + return 1; if (!mysql_port) { struct servent *serv_ptr; - mysql_port = MYSQL_PORT; char *env; + + mysql_port = MYSQL_PORT; if ((serv_ptr = getservbyname("mysql", "tcp"))) mysql_port = (uint) ntohs((ushort) serv_ptr->s_port); if ((env = getenv("MYSQL_TCP_PORT"))) @@ -2956,7 +2890,7 @@ int STDCALL mysql_server_init(int argc __attribute__((unused)), if (!mysql_unix_port) { char *env; -#ifdef __WIN__ +#ifdef _WIN32 mysql_unix_port = (char*) MYSQL_NAMEDPIPE; #else mysql_unix_port = (char*) MYSQL_UNIX_ADDR; @@ -2965,7 +2899,7 @@ int STDCALL mysql_server_init(int argc __attribute__((unused)), mysql_unix_port = env; } mysql_debug(NullS); -#if defined(SIGPIPE) && !defined(THREAD) && !defined(__WIN__) +#if defined(SIGPIPE) && !defined(THREAD) && !defined(_WIN32) (void) signal(SIGPIPE,SIG_IGN); #endif } @@ -2983,6 +2917,8 @@ void STDCALL mysql_server_end() if (!mysql_client_init) return; + mysql_client_plugin_deinit(); + if (my_init_done) my_end(0); #ifdef THREAD @@ -3004,6 +2940,36 @@ my_bool STDCALL mysql_thread_init() void STDCALL mysql_thread_end() { #ifdef THREAD - return my_thread_end(); + my_thread_end(); #endif } + +int STDCALL mysql_set_server_option(MYSQL *mysql, + enum enum_mysql_set_option option) +{ + char buffer[2]; + DBUG_ENTER("mysql_set_server_option"); + int2store(buffer, (uint)option); + DBUG_RETURN(simple_command(mysql, MYSQL_COM_SET_OPTION, buffer, sizeof(buffer), 0)); +} + +ulong STDCALL mysql_get_client_version(void) +{ + return MYSQL_VERSION_ID; +} + +ulong STDCALL mysql_hex_string(char *to, const char *from, + unsigned long len) +{ + char *start= to; + char hexdigits[]= "012345679ABCDEF"; + + while (len--) + { + *to++= hexdigits[*from >> 4]; + *to++= hexdigits[*from & 0x0F]; + from++; + } + *to= 0; + return (to - start); +} diff --git a/libmysql/libmysql_exports.def b/libmysql/libmysql_exports.def new file mode 100644 index 000000000..5a842043d --- /dev/null +++ b/libmysql/libmysql_exports.def @@ -0,0 +1,107 @@ +EXPORTS + get_tty_password + load_defaults + mysql_thread_end + mysql_thread_init + myodbc_remove_escape + mysql_affected_rows + mysql_autocommit + mysql_stmt_bind_param + mysql_stmt_bind_result + mysql_change_user + mysql_character_set_name + mysql_close + mysql_commit + mysql_data_seek + mysql_debug + mysql_dump_debug_info + mysql_eof + mysql_errno + mysql_error + mysql_escape_string + mysql_hex_string + mysql_stmt_execute + mysql_stmt_fetch + mysql_stmt_fetch_column + mysql_fetch_field + mysql_fetch_field_direct + mysql_fetch_fields + mysql_fetch_lengths + mysql_fetch_row + mysql_field_count + mysql_field_seek + mysql_field_tell + mysql_free_result + mysql_get_client_info + mysql_get_host_info + mysql_get_proto_info + mysql_get_server_info + mysql_get_client_version + ;mysql_get_ssl_cipher + mysql_info + mysql_init + mysql_insert_id + mysql_kill + mysql_set_server_option + mysql_list_dbs + mysql_list_fields + mysql_list_processes + mysql_list_tables + mysql_more_results + mysql_next_result + mysql_num_fields + mysql_num_rows + mysql_options + mysql_stmt_param_count + ;mysql_stmt_param_metadata + mysql_ping + mysql_stmt_result_metadata + mysql_query + mysql_read_query_result + mysql_real_connect + mysql_real_escape_string + mysql_real_query + mysql_refresh + mysql_rollback + mysql_row_seek + mysql_row_tell + mysql_select_db + mysql_stmt_send_long_data + mysql_send_query + mysql_shutdown + mysql_ssl_set + mysql_stat + mysql_stmt_affected_rows + mysql_stmt_close + mysql_stmt_reset + mysql_stmt_data_seek + mysql_stmt_errno + mysql_stmt_error + mysql_stmt_free_result + mysql_stmt_num_rows + mysql_stmt_row_seek + mysql_stmt_row_tell + mysql_stmt_store_result + mysql_store_result + mysql_thread_id + mysql_thread_safe + mysql_use_result + mysql_warning_count + mysql_stmt_sqlstate + mysql_sqlstate + mysql_get_server_version + mysql_stmt_prepare + mysql_stmt_init + mysql_stmt_insert_id + mysql_stmt_attr_get + mysql_stmt_attr_set + mysql_stmt_field_count + mysql_set_local_infile_default + mysql_set_local_infile_handler + mysql_server_init + mysql_server_end + mysql_set_character_set + mysql_get_character_set_info + ;mysql_stmt_next_result + + diff --git a/libmysql/mf_cache.c b/libmysql/mf_cache.c deleted file mode 100644 index 85b6b19b3..000000000 --- a/libmysql/mf_cache.c +++ /dev/null @@ -1,123 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* Open a temporary file and cache it with io_cache. Delete it on close */ - -#include "mysys_priv.h" -#include -#include "my_static.h" -#include "mysys_err.h" - - /* - Remove an open tempfile so that it doesn't survive - if we crash; If the operating system doesn't support - this, just remember the file name for later removal - */ - -static my_bool cache_remove_open_tmp(IO_CACHE *cache __attribute__((unused)), - const char *name) -{ -#if O_TEMPORARY == 0 -#if !defined(CANT_DELETE_OPEN_FILES) - /* The following should always succeed */ - (void) my_delete(name,MYF(MY_WME | ME_NOINPUT)); -#else - int length; - if (!(cache->file_name= - (char*) my_malloc((length=strlen(name)+1),MYF(MY_WME)))) - { - my_close(cache->file,MYF(0)); - cache->file = -1; - errno=my_errno=ENOMEM; - return 1; - } - memcpy(cache->file_name,name,length); -#endif -#endif /* O_TEMPORARY == 0 */ - return 0; -} - - /* - ** Open tempfile cached by IO_CACHE - ** Should be used when no seeks are done (only reinit_io_buff) - ** Return 0 if cache is inited ok - ** The actual file is created when the IO_CACHE buffer gets filled - ** If dir is not given, use TMPDIR. - */ - -my_bool open_cached_file(IO_CACHE *cache, const char* dir, const char *prefix, - uint cache_size, myf cache_myflags) -{ - DBUG_ENTER("open_cached_file"); - cache->dir= dir ? my_strdup(dir,MYF(cache_myflags & MY_WME)) : (char*) 0; - cache->prefix= (prefix ? my_strdup(prefix,MYF(cache_myflags & MY_WME)) : - (char*) 0); - cache->file_name=0; - cache->buffer=0; /* Mark that not open */ - if (!init_io_cache(cache,-1,cache_size,WRITE_CACHE,0L,0, - MYF(cache_myflags | MY_NABP))) - { - DBUG_RETURN(0); - } - my_free(cache->dir, MYF(MY_ALLOW_ZERO_PTR)); - my_free(cache->prefix,MYF(MY_ALLOW_ZERO_PTR)); - DBUG_RETURN(1); -} - - /* Create the temporary file */ - -my_bool real_open_cached_file(IO_CACHE *cache) -{ - char name_buff[FN_REFLEN]; - int error=1; - DBUG_ENTER("real_open_cached_file"); - if ((cache->file=create_temp_file(name_buff, cache->dir, cache->prefix, - (O_RDWR | O_BINARY | O_TRUNC | - O_TEMPORARY | O_SHORT_LIVED), - MYF(MY_WME))) >= 0) - { - error=0; - cache_remove_open_tmp(cache, name_buff); - } - DBUG_RETURN(error); -} - - -void close_cached_file(IO_CACHE *cache) -{ - DBUG_ENTER("close_cached_file"); - if (my_b_inited(cache)) - { - File file=cache->file; - cache->file= -1; /* Don't flush data */ - (void) end_io_cache(cache); - if (file >= 0) - { - (void) my_close(file,MYF(0)); -#ifdef CANT_DELETE_OPEN_FILES - if (cache->file_name) - { - (void) my_delete(cache->file_name,MYF(MY_WME | ME_NOINPUT)); - my_free(cache->file_name,MYF(0)); - } -#endif - } - my_free(cache->dir,MYF(MY_ALLOW_ZERO_PTR)); - my_free(cache->prefix,MYF(MY_ALLOW_ZERO_PTR)); - } - DBUG_VOID_RETURN; -} diff --git a/libmysql/mf_casecnv.c b/libmysql/mf_casecnv.c deleted file mode 100644 index af2a30b29..000000000 --- a/libmysql/mf_casecnv.c +++ /dev/null @@ -1,267 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - Functions to convert to lover_case and to upper_case in scandinavia. - - case_sort converts a character string to a representaion that can - be compared by strcmp to find with is alfabetical bigger. - (lower- and uppercase letters is compared as the same) -*/ - -#include "mysys_priv.h" -#include -#include - - /* string to uppercase */ - -void caseup_str(my_string str) -{ -#ifdef USE_MB - if (use_mb(default_charset_info)) - { - register uint32 l; - register char *end=str+(uint) strlen(str); - while (*str) - { - if ((l=my_ismbchar(default_charset_info, str,end))) str+=l; - else *str=toupper(*str),++str; - } - } - else -#endif - while ((*str = toupper(*str)) != 0) - str++; -} /* caseup_str */ - - /* string to lowercase */ - -void casedn_str(my_string str) -{ -#ifdef USE_MB - if (use_mb(default_charset_info)) - { - register uint32 l; - register char *end=str+(uint) strlen(str); - while (*str) - { - if ((l=my_ismbchar(default_charset_info, str,end))) str+=l; - else *str=tolower(*str),++str; - } - } - else -#endif - while ((*str= tolower(*str)) != 0) - str++; -} /* casedn_str */ - - - /* to uppercase */ - -void caseup(my_string str, uint length) -{ -#ifdef USE_MB - if (use_mb(default_charset_info)) - { - register uint32 l; - register char *end=str+length; - while (str0 ; length--, str++) - *str= toupper(*str); -} /* caseup */ - - /* to lowercase */ - -void casedn(my_string str, uint length) -{ -#ifdef USE_MB - if (use_mb(default_charset_info)) - { - register uint32 l; - register char *end=str+length; - while (str0 ; length--, str++) - *str= tolower(*str); -} /* casedn */ - - /* to sort-string that can be compared to get text in order */ - -void case_sort(my_string str, uint length) -{ -/* todo: can we remove this? - for ( ; length>0 ; length--, str++) - *str= (char) my_sort_order[(uchar) *str]; -*/ -} /* case_sort */ - - /* find string in another with no case_sensivity */ - -/* ToDo: This function should be modified to support multibyte charset. - However it is not used untill 3.23.5. - Wei He (hewei@mail.ied.ac.cn) -*/ - -my_string my_strcasestr(const char *str, const char *search) -{ - uchar *i,*j,*pos; - - pos=(uchar*) str; -skipp: - while (*pos != '\0') - { - if (toupper((uchar) *pos++) == toupper((uchar) *search)) - { - i=(uchar*) pos; j=(uchar*) search+1; - while (*j) - if (toupper(*i++) != toupper(*j++)) goto skipp; - return ((char*) pos-1); - } - } - return ((my_string) 0); -} /* strcstr */ - - - /* compare strings without regarding to case */ - -int my_strcasecmp(const char *s, const char *t) -{ -#ifdef USE_MB - if (use_mb(default_charset_info)) - { - register uint32 l; - register const char *end=s+(uint) strlen(s); - while (spos_in_file to a higher value to skip bytes in file if - also info->rc_pos is set to info->rc_end. - If called through open_cached_file(), then the temporary file will - only be created if a write exeeds the file buffer or if one calls - flush_io_cache(). -*/ - -#define MAP_TO_USE_RAID -#include "mysys_priv.h" -#include -#ifdef HAVE_AIOWAIT -#include "mysys_err.h" -#include -static void my_aiowait(my_aio_result *result); -#endif - - - /* - ** if cachesize == 0 then use default cachesize (from s-file) - ** if file == -1 then real_open_cached_file() will be called. - ** returns 0 if ok - */ - -int init_io_cache(IO_CACHE *info, File file, uint cachesize, - enum cache_type type, my_off_t seek_offset, - pbool use_async_io, myf cache_myflags) -{ - uint min_cache; - DBUG_ENTER("init_io_cache"); - DBUG_PRINT("enter",("type: %d pos: %ld",(int) type, (ulong) seek_offset)); - - info->file=file; - if (!cachesize) - if (! (cachesize= my_default_record_cache_size)) - DBUG_RETURN(1); /* No cache requested */ - min_cache=use_async_io ? IO_SIZE*4 : IO_SIZE*2; - if (type == READ_CACHE) - { /* Assume file isn't growing */ - if (cache_myflags & MY_DONT_CHECK_FILESIZE) - { - cache_myflags &= ~MY_DONT_CHECK_FILESIZE; - } - else - { - my_off_t file_pos,end_of_file; - if ((file_pos=my_tell(file,MYF(0)) == MY_FILEPOS_ERROR)) - DBUG_RETURN(1); - end_of_file=my_seek(file,0L,MY_SEEK_END,MYF(0)); - if (end_of_file < seek_offset) - end_of_file=seek_offset; - VOID(my_seek(file,file_pos,MY_SEEK_SET,MYF(0))); - if ((my_off_t) cachesize > end_of_file-seek_offset+IO_SIZE*2-1) - { - cachesize=(uint) (end_of_file-seek_offset)+IO_SIZE*2-1; - use_async_io=0; /* No nead to use async */ - } - } - } - - for (;;) - { - cachesize=(uint) ((ulong) (cachesize + min_cache-1) & - (ulong) ~(min_cache-1)); - if (cachesize < min_cache) - cachesize = min_cache; - if ((info->buffer= - (byte*) my_malloc(cachesize, - MYF((cache_myflags & ~ MY_WME) | - (cachesize == min_cache ? MY_WME : 0)))) != 0) - break; /* Enough memory found */ - if (cachesize == min_cache) - DBUG_RETURN(2); /* Can't alloc cache */ - cachesize= (uint) ((long) cachesize*3/4); /* Try with less memory */ - } - info->pos_in_file=seek_offset; - info->read_length=info->buffer_length=cachesize; - info->seek_not_done= test(file >= 0); /* Seek not done */ - info->myflags=cache_myflags & ~(MY_NABP | MY_FNABP); - info->rc_request_pos=info->rc_pos=info->buffer; - - if (type == READ_CACHE) - { - info->rc_end=info->buffer; /* Nothing in cache */ - } - else /* type == WRITE_CACHE */ - { - info->rc_end=info->buffer+info->buffer_length- (seek_offset & (IO_SIZE-1)); - } - info->end_of_file=MY_FILEPOS_ERROR; /* May be changed by user */ - info->type=type; - info->error=0; - info->read_function=_my_b_read; -#ifdef HAVE_AIOWAIT - if (use_async_io && ! my_disable_async_io) - { - DBUG_PRINT("info",("Using async io")); - info->read_length/=2; - info->read_function=_my_b_async_read; - } - info->inited=info->aio_result.pending=0; -#endif - DBUG_RETURN(0); -} /* init_io_cache */ - - - /* Wait until current request is ready */ - -#ifdef HAVE_AIOWAIT -static void my_aiowait(my_aio_result *result) -{ - if (result->pending) - { - struct aio_result_t *tmp; - for (;;) - { - if ((int) (tmp=aiowait((struct timeval *) 0)) == -1) - { - if (errno == EINTR) - continue; - DBUG_PRINT("error",("No aio request, error: %d",errno)); - result->pending=0; /* Assume everythings is ok */ - break; - } - ((my_aio_result*) tmp)->pending=0; - if ((my_aio_result*) tmp == result) - break; - } - } - return; -} -#endif - - /* Use this to reset cache to start or other type */ - /* Some simple optimizing is done when reinit in current buffer */ - -my_bool reinit_io_cache(IO_CACHE *info, enum cache_type type, - my_off_t seek_offset, - pbool use_async_io __attribute__((unused)), - pbool clear_cache) -{ - DBUG_ENTER("reinit_io_cache"); - - info->seek_not_done= test(info->file >= 0); /* Seek not done */ - if (! clear_cache && - seek_offset >= info->pos_in_file && - seek_offset <= info->pos_in_file + - (uint) (info->rc_end - info->rc_request_pos)) - { /* use current buffer */ - if (info->type == WRITE_CACHE && type == READ_CACHE) - { - info->rc_end=info->rc_pos; - info->end_of_file=my_b_tell(info); - } - else if (info->type == READ_CACHE && type == WRITE_CACHE) - info->rc_end=info->buffer+info->buffer_length; - info->rc_pos=info->rc_request_pos+(seek_offset-info->pos_in_file); -#ifdef HAVE_AIOWAIT - my_aiowait(&info->aio_result); /* Wait for outstanding req */ -#endif - } - else - { - if (info->type == WRITE_CACHE && type == READ_CACHE) - info->end_of_file=my_b_tell(info); - if (flush_io_cache(info)) - DBUG_RETURN(1); - info->pos_in_file=seek_offset; - info->rc_request_pos=info->rc_pos=info->buffer; - if (type == READ_CACHE) - { - info->rc_end=info->buffer; /* Nothing in cache */ - } - else - { - info->rc_end=info->buffer+info->buffer_length- - (seek_offset & (IO_SIZE-1)); - info->end_of_file=MY_FILEPOS_ERROR; /* May be changed by user */ - } - } - info->type=type; - info->error=0; - info->read_function=_my_b_read; -#ifdef HAVE_AIOWAIT - if (use_async_io && ! my_disable_async_io && - ((ulong) info->buffer_length < - (ulong) (info->end_of_file - seek_offset))) - { - info->read_length=info->buffer_length/2; - info->read_function=_my_b_async_read; - } - info->inited=0; -#endif - DBUG_RETURN(0); -} /* init_io_cache */ - - - - /* Read buffered. Returns 1 if can't read requested characters */ - /* Returns 0 if record read */ - -int _my_b_read(register IO_CACHE *info, byte *Buffer, uint Count) -{ - uint length,diff_length,left_length; - my_off_t max_length, pos_in_file; - - memcpy(Buffer,info->rc_pos, - (size_t) (left_length=(uint) (info->rc_end-info->rc_pos))); - Buffer+=left_length; - Count-=left_length; - pos_in_file=info->pos_in_file+(uint) (info->rc_end - info->buffer); - if (info->seek_not_done) - { /* File touched, do seek */ - VOID(my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0))); - info->seek_not_done=0; - } - diff_length=(uint) (pos_in_file & (IO_SIZE-1)); - if (Count >= (uint) (IO_SIZE+(IO_SIZE-diff_length))) - { /* Fill first intern buffer */ - uint read_length; - if (info->end_of_file == pos_in_file) - { /* End of file */ - info->error=(int) left_length; - return 1; - } - length=(Count & (uint) ~(IO_SIZE-1))-diff_length; - if ((read_length=my_read(info->file,Buffer,(uint) length,info->myflags)) - != (uint) length) - { - info->error= read_length == (uint) -1 ? -1 : - (int) (read_length+left_length); - return 1; - } - Count-=length; - Buffer+=length; - pos_in_file+=length; - left_length+=length; - diff_length=0; - } - max_length=info->end_of_file - pos_in_file; - if (max_length > info->read_length-diff_length) - max_length=info->read_length-diff_length; - - if (!max_length) - { - if (Count) - { - info->error= left_length; /* We only got this many char */ - return 1; - } - length=0; /* Didn't read any chars */ - } - else if ((length=my_read(info->file,info->buffer,(uint) max_length, - info->myflags)) < Count || - length == (uint) -1) - { - if (length != (uint) -1) - memcpy(Buffer,info->buffer,(size_t) length); - info->error= length == (uint) -1 ? -1 : (int) (length+left_length); - return 1; - } - info->rc_pos=info->buffer+Count; - info->rc_end=info->buffer+length; - info->pos_in_file=pos_in_file; - memcpy(Buffer,info->buffer,(size_t) Count); - return 0; -} - - -#ifdef HAVE_AIOWAIT - -int _my_b_async_read(register IO_CACHE *info, byte *Buffer, uint Count) -{ - uint length,read_length,diff_length,left_length,use_length,org_Count; - my_off_t max_length; - my_off_t next_pos_in_file; - byte *read_buffer; - - memcpy(Buffer,info->rc_pos, - (size_t) (left_length=(uint) (info->rc_end-info->rc_pos))); - Buffer+=left_length; - org_Count=Count; - Count-=left_length; - - if (info->inited) - { /* wait for read block */ - info->inited=0; /* No more block to read */ - my_aiowait(&info->aio_result); /* Wait for outstanding req */ - if (info->aio_result.result.aio_errno) - { - if (info->myflags & MY_WME) - my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG), - my_filename(info->file), - info->aio_result.result.aio_errno); - my_errno=info->aio_result.result.aio_errno; - info->error= -1; - return(1); - } - if (! (read_length = (uint) info->aio_result.result.aio_return) || - read_length == (uint) -1) - { - my_errno=0; /* For testing */ - info->error= (read_length == (uint) -1 ? -1 : - (int) (read_length+left_length)); - return(1); - } - info->pos_in_file+=(uint) (info->rc_end - info->rc_request_pos); - - if (info->rc_request_pos != info->buffer) - info->rc_request_pos=info->buffer; - else - info->rc_request_pos=info->buffer+info->read_length; - info->rc_pos=info->rc_request_pos; - next_pos_in_file=info->aio_read_pos+read_length; - - /* Check if pos_in_file is changed - (_ni_read_cache may have skipped some bytes) */ - - if (info->aio_read_pos < info->pos_in_file) - { /* Fix if skipped bytes */ - if (info->aio_read_pos + read_length < info->pos_in_file) - { - read_length=0; /* Skipp block */ - next_pos_in_file=info->pos_in_file; - } - else - { - my_off_t offset= (info->pos_in_file - info->aio_read_pos); - info->pos_in_file=info->aio_read_pos; /* Whe are here */ - info->rc_pos=info->rc_request_pos+offset; - read_length-=offset; /* Bytes left from rc_pos */ - } - } -#ifndef DBUG_OFF - if (info->aio_read_pos > info->pos_in_file) - { - my_errno=EINVAL; - return(info->read_length= -1); - } -#endif - /* Copy found bytes to buffer */ - length=min(Count,read_length); - memcpy(Buffer,info->rc_pos,(size_t) length); - Buffer+=length; - Count-=length; - left_length+=length; - info->rc_end=info->rc_pos+read_length; - info->rc_pos+=length; - } - else - next_pos_in_file=(info->pos_in_file+ (uint) - (info->rc_end - info->rc_request_pos)); - - /* If reading large blocks, or first read or read with skipp */ - if (Count) - { - if (next_pos_in_file == info->end_of_file) - { - info->error=(int) (read_length+left_length); - return 1; - } - VOID(my_seek(info->file,next_pos_in_file,MY_SEEK_SET,MYF(0))); - read_length=IO_SIZE*2- (uint) (next_pos_in_file & (IO_SIZE-1)); - if (Count < read_length) - { /* Small block, read to cache */ - if ((read_length=my_read(info->file,info->rc_request_pos, - read_length, info->myflags)) == (uint) -1) - return info->error= -1; - use_length=min(Count,read_length); - memcpy(Buffer,info->rc_request_pos,(size_t) use_length); - info->rc_pos=info->rc_request_pos+Count; - info->rc_end=info->rc_request_pos+read_length; - info->pos_in_file=next_pos_in_file; /* Start of block in cache */ - next_pos_in_file+=read_length; - - if (Count != use_length) - { /* Didn't find hole block */ - if (info->myflags & (MY_WME | MY_FAE | MY_FNABP) && Count != org_Count) - my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), - my_filename(info->file),my_errno); - info->error=(int) (read_length+left_length); - return 1; - } - } - else - { /* Big block, don't cache it */ - if ((read_length=my_read(info->file,Buffer,(uint) Count,info->myflags)) - != Count) - { - info->error= read_length == (uint) -1 ? -1 : read_length+left_length; - return 1; - } - info->rc_pos=info->rc_end=info->rc_request_pos; - info->pos_in_file=(next_pos_in_file+=Count); - } - } - - /* Read next block with asyncronic io */ - max_length=info->end_of_file - next_pos_in_file; - diff_length=(next_pos_in_file & (IO_SIZE-1)); - - if (max_length > (my_off_t) info->read_length - diff_length) - max_length= (my_off_t) info->read_length - diff_length; - if (info->rc_request_pos != info->buffer) - read_buffer=info->buffer; - else - read_buffer=info->buffer+info->read_length; - info->aio_read_pos=next_pos_in_file; - if (max_length) - { - info->aio_result.result.aio_errno=AIO_INPROGRESS; /* Marker for test */ - DBUG_PRINT("aioread",("filepos: %ld length: %ld", - (ulong) next_pos_in_file,(ulong) max_length)); - if (aioread(info->file,read_buffer,(int) max_length, - (my_off_t) next_pos_in_file,MY_SEEK_SET, - &info->aio_result.result)) - { /* Skipp async io */ - my_errno=errno; - DBUG_PRINT("error",("got error: %d, aio_result: %d from aioread, async skipped", - errno, info->aio_result.result.aio_errno)); - if (info->rc_request_pos != info->buffer) - { - bmove(info->buffer,info->rc_request_pos, - (uint) (info->rc_end - info->rc_pos)); - info->rc_request_pos=info->buffer; - info->rc_pos-=info->read_length; - info->rc_end-=info->read_length; - } - info->read_length=info->buffer_length; /* Use hole buffer */ - info->read_function=_my_b_read; /* Use normal IO_READ next */ - } - else - info->inited=info->aio_result.pending=1; - } - return 0; /* Block read, async in use */ -} /* _my_b_async_read */ -#endif - - -/* Read one byte when buffer is empty */ - -int _my_b_get(IO_CACHE *info) -{ - byte buff; - if ((*(info)->read_function)(info,&buff,1)) - return my_b_EOF; - return (int) (uchar) buff; -} - - /* Returns != 0 if error on write */ - -int _my_b_write(register IO_CACHE *info, const byte *Buffer, uint Count) -{ - uint rest_length,length; - - rest_length=(uint) (info->rc_end - info->rc_pos); - memcpy(info->rc_pos,Buffer,(size_t) rest_length); - Buffer+=rest_length; - Count-=rest_length; - info->rc_pos+=rest_length; - if (flush_io_cache(info)) - return 1; - if (Count >= IO_SIZE) - { /* Fill first intern buffer */ - length=Count & (uint) ~(IO_SIZE-1); - if (info->seek_not_done) - { /* File touched, do seek */ - VOID(my_seek(info->file,info->pos_in_file,MY_SEEK_SET,MYF(0))); - info->seek_not_done=0; - } - if (my_write(info->file,Buffer,(uint) length,info->myflags | MY_NABP)) - return info->error= -1; - Count-=length; - Buffer+=length; - info->pos_in_file+=length; - } - memcpy(info->rc_pos,Buffer,(size_t) Count); - info->rc_pos+=Count; - return 0; -} - - -/* - Write a block to disk where part of the data may be inside the record - buffer. As all write calls to the data goes through the cache, - we will never get a seek over the end of the buffer -*/ - -int my_block_write(register IO_CACHE *info, const byte *Buffer, uint Count, - my_off_t pos) -{ - uint length; - int error=0; - - if (pos < info->pos_in_file) - { - /* Of no overlap, write everything without buffering */ - if (pos + Count <= info->pos_in_file) - return my_pwrite(info->file, Buffer, Count, pos, - info->myflags | MY_NABP); - /* Write the part of the block that is before buffer */ - length= (uint) (info->pos_in_file - pos); - if (my_pwrite(info->file, Buffer, length, pos, info->myflags | MY_NABP)) - info->error=error=-1; - Buffer+=length; - pos+= length; - Count-= length; - } - - /* Check if we want to write inside the used part of the buffer.*/ - length= (uint) (info->rc_end - info->buffer); - if (pos < info->pos_in_file + length) - { - uint offset= (uint) (pos - info->pos_in_file); - length-=offset; - if (length > Count) - length=Count; - memcpy(info->buffer+offset, Buffer, length); - Buffer+=length; - Count-= length; - /* Fix length of buffer if the new data was larger */ - if (info->buffer+length > info->rc_pos) - info->rc_pos=info->buffer+length; - if (!Count) - return (error); - } - /* Write at the end of the current buffer; This is the normal case */ - if (_my_b_write(info, Buffer, Count)) - error= -1; - return error; -} - - /* Flush write cache */ - -int flush_io_cache(IO_CACHE *info) -{ - uint length; - DBUG_ENTER("flush_io_cache"); - - if (info->type == WRITE_CACHE) - { - if (info->file == -1) - { - if (real_open_cached_file(info)) - DBUG_RETURN((info->error= -1)); - } - if (info->rc_pos != info->buffer) - { - length=(uint) (info->rc_pos - info->buffer); - if (info->seek_not_done) - { /* File touched, do seek */ - if (my_seek(info->file,info->pos_in_file,MY_SEEK_SET,MYF(0)) == - MY_FILEPOS_ERROR) - DBUG_RETURN((info->error= -1)); - info->seek_not_done=0; - } - info->rc_pos=info->buffer; - info->pos_in_file+=length; - info->rc_end=(info->buffer+info->buffer_length- - (info->pos_in_file & (IO_SIZE-1))); - if (my_write(info->file,info->buffer,length,info->myflags | MY_NABP)) - DBUG_RETURN((info->error= -1)); - DBUG_RETURN(0); - } - } -#ifdef HAVE_AIOWAIT - else - { - my_aiowait(&info->aio_result); /* Wait for outstanding req */ - info->inited=0; - } -#endif - DBUG_RETURN(0); -} - - -int end_io_cache(IO_CACHE *info) -{ - int error=0; - DBUG_ENTER("end_io_cache"); - if (info->buffer) - { - if (info->file != -1) /* File doesn't exist */ - error=flush_io_cache(info); - my_free((gptr) info->buffer,MYF(MY_WME)); - info->buffer=info->rc_pos=(byte*) 0; - } - DBUG_RETURN(error); -} /* end_io_cache */ diff --git a/libmysql/mf_pack.c b/libmysql/mf_pack.c index b442af7e9..68be4aa22 100644 --- a/libmysql/mf_pack.c +++ b/libmysql/mf_pack.c @@ -35,7 +35,7 @@ static my_string NEAR_F expand_tilde(my_string *path); void pack_dirname(my_string to, const char *from) { int cwd_err; - uint d_length,length,buff_length; + uint d_length,length,buff_length= 0; my_string start; char buff[FN_REFLEN]; DBUG_ENTER("pack_dirname"); diff --git a/libmysql/mf_path.c b/libmysql/mf_path.c index 9a88b938e..c53157deb 100644 --- a/libmysql/mf_path.c +++ b/libmysql/mf_path.c @@ -74,7 +74,7 @@ my_string my_path(my_string to, const char *progname, /* test if file without filename is found in path */ /* Returns to if found and to has dirpart if found, else NullS */ -#if defined(MSDOS) || defined(__WIN__) || defined(__EMX__) || defined(OS2) +#if defined(MSDOS) || defined(_WIN32) || defined(__EMX__) || defined(OS2) #define F_OK 0 #define PATH_SEP ';' #define PROGRAM_EXTENSION ".exe" @@ -107,7 +107,7 @@ static char *find_file_in_path(char *to, const char *name) } } } -#ifdef __WIN__ +#ifdef _WIN32 to[0]=FN_CURLIB; strxmov(to+1,dir,name,ext,NullS); if (!access(to,F_OK)) /* Test in current dir */ diff --git a/libmysql/my_alloc.c b/libmysql/my_alloc.c index 8839e580c..f1a2c3ddc 100644 --- a/libmysql/my_alloc.c +++ b/libmysql/my_alloc.c @@ -21,7 +21,7 @@ #include #include -void init_alloc_root(MEM_ROOT *mem_root, uint block_size, uint pre_alloc_size) +void init_alloc_root(MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size) { mem_root->free=mem_root->used=0; mem_root->min_malloc=32; @@ -42,7 +42,7 @@ void init_alloc_root(MEM_ROOT *mem_root, uint block_size, uint pre_alloc_size) #endif } -gptr alloc_root(MEM_ROOT *mem_root,unsigned int Size) +gptr alloc_root(MEM_ROOT *mem_root, size_t Size) { #if defined(HAVE_purify) && defined(EXTRA_DEBUG) reg1 USED_MEM *next; @@ -58,7 +58,7 @@ gptr alloc_root(MEM_ROOT *mem_root,unsigned int Size) mem_root->used=next; return (gptr) (((char*) next)+ALIGN_SIZE(sizeof(USED_MEM))); #else - uint get_size,max_left; + size_t get_size,max_left; gptr point; reg1 USED_MEM *next; reg2 USED_MEM **prev; @@ -137,7 +137,7 @@ void free_root(MEM_ROOT *root, myf MyFlags) char *strdup_root(MEM_ROOT *root,const char *str) { - uint len= (uint) strlen(str)+1; + size_t len= strlen(str)+1; char *pos; if ((pos=alloc_root(root,len))) memcpy(pos,str,len); @@ -145,7 +145,7 @@ char *strdup_root(MEM_ROOT *root,const char *str) } -char *memdup_root(MEM_ROOT *root,const char *str,uint len) +char *memdup_root(MEM_ROOT *root, const char *str, size_t len) { char *pos; if ((pos=alloc_root(root,len))) diff --git a/libmysql/my_auth.c b/libmysql/my_auth.c new file mode 100644 index 000000000..9a0396777 --- /dev/null +++ b/libmysql/my_auth.c @@ -0,0 +1,737 @@ +#include +#include +#include +#include +#include +#include +#include + +typedef struct st_mysql_client_plugin_AUTHENTICATION auth_plugin_t; +static int client_mpvio_write_packet(struct st_plugin_vio*, const uchar*, size_t); +static int native_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql); +static int old_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql); +extern void read_user_name(char *name); + +#define compile_time_assert(A) \ +do {\ + typedef char constraint[(A) ? 1 : -1];\ +} while (0); + +static auth_plugin_t native_password_client_plugin= +{ + MYSQL_CLIENT_AUTHENTICATION_PLUGIN, + MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION, + native_password_plugin_name, + "R.J.Silk, Sergei Golubchik", + "Native MySQL authentication", + {1, 0, 0}, + NULL, + NULL, + native_password_auth_client +}; + +static auth_plugin_t old_password_client_plugin= +{ + MYSQL_CLIENT_AUTHENTICATION_PLUGIN, + MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION, + old_password_plugin_name, + "R.J.Silk, Sergei Golubchik", + "Old MySQL-3.23 authentication", + {1, 0, 0}, + NULL, + NULL, + old_password_auth_client +}; + +struct st_mysql_client_plugin *mysql_client_builtins[]= +{ + (struct st_mysql_client_plugin *)&native_password_client_plugin, + 0 +}; + +/* this is a "superset" of MYSQL_PLUGIN_VIO, in C++ I use inheritance */ +typedef struct { + int (*read_packet)(struct st_plugin_vio *vio, uchar **buf); + int (*write_packet)(struct st_plugin_vio *vio, const uchar *pkt, size_t pkt_len); + void (*info)(struct st_plugin_vio *vio, struct st_plugin_vio_info *info); + /* -= end of MYSQL_PLUGIN_VIO =- */ + MYSQL *mysql; + auth_plugin_t *plugin; /**< what plugin we're under */ + const char *db; + struct { + uchar *pkt; /**< pointer into NET::buff */ + uint pkt_len; + } cached_server_reply; + uint packets_read, packets_written; /**< counters for send/received packets */ + my_bool mysql_change_user; /**< if it's mysql_change_user() */ + int last_read_packet_len; /**< the length of the last *read* packet */ +} MCPVIO_EXT; + +static int native_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) +{ + int pkt_len; + uchar *pkt; + + if (((MCPVIO_EXT *)vio)->mysql_change_user) + { + /* + in mysql_change_user() the client sends the first packet. + we use the old scramble. + */ + pkt= (uchar*)mysql->scramble_buff; + pkt_len= SCRAMBLE_LENGTH + 1; + } + else + { + /* read the scramble */ + if ((pkt_len= vio->read_packet(vio, &pkt)) < 0) + return CR_ERROR; + + if (pkt_len != SCRAMBLE_LENGTH + 1) + return CR_SERVER_HANDSHAKE_ERR; + + /* save it in MYSQL */ + memcpy(mysql->scramble_buff, pkt, SCRAMBLE_LENGTH); + mysql->scramble_buff[SCRAMBLE_LENGTH] = 0; + } + + if (mysql->passwd[0]) + { + char scrambled[SCRAMBLE_LENGTH + 1]; + my_scramble_41((uchar *)scrambled, (char*)pkt, mysql->passwd); + if (vio->write_packet(vio, (uchar*)scrambled, SCRAMBLE_LENGTH)) + return CR_ERROR; + } + else + if (vio->write_packet(vio, 0, 0)) /* no password */ + return CR_ERROR; + + return CR_OK; +} + + +/** + client authentication plugin that does old MySQL authentication + using an 8-byte (4.0-) scramble +*/ + +static int old_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) +{ + uchar *pkt; + int pkt_len; + + if (((MCPVIO_EXT *)vio)->mysql_change_user) + { + /* + in mysql_change_user() the client sends the first packet. + we use the old scramble. + */ + pkt= (uchar*)mysql->scramble_buff; + pkt_len= SCRAMBLE_LENGTH_323 + 1; + } + else + { + /* read the scramble */ + if ((pkt_len= vio->read_packet(vio, &pkt)) < 0) + return CR_ERROR; + + if (pkt_len != SCRAMBLE_LENGTH_323 + 1 && + pkt_len != SCRAMBLE_LENGTH + 1) + return CR_SERVER_HANDSHAKE_ERR; + + /* save it in MYSQL */ + memcpy(mysql->scramble_buff, pkt, pkt_len); + mysql->scramble_buff[pkt_len] = 0; + } + + if (mysql->passwd[0]) + { + char scrambled[SCRAMBLE_LENGTH_323 + 1]; + scramble_323(scrambled, (char*)pkt, mysql->passwd); + if (vio->write_packet(vio, (uchar*)scrambled, SCRAMBLE_LENGTH_323 + 1)) + return CR_ERROR; + } + else + if (vio->write_packet(vio, 0, 0)) /* no password */ + return CR_ERROR; + + return CR_OK; +} + +/** + sends a COM_CHANGE_USER command with a caller provided payload + + Packet format: + + Bytes Content + ----- ---- + n user name - \0-terminated string + n password + 3.23 scramble - \0-terminated string (9 bytes) + otherwise - length (1 byte) coded + n database name - \0-terminated string + 2 character set number (if the server >= 4.1.x) + n client auth plugin name - \0-terminated string, + (if the server supports plugin auth) + + @retval 0 ok + @retval 1 error +*/ + +static int send_change_user_packet(MCPVIO_EXT *mpvio, + const uchar *data, int data_len) +{ + MYSQL *mysql= mpvio->mysql; + char *buff, *end; + int res= 1; + + buff= my_alloca(USERNAME_LENGTH+1 + data_len+1 + NAME_LEN+1 + 2 + NAME_LEN+1); + + end= strmake(buff, mysql->user, USERNAME_LENGTH) + 1; + + if (!data_len) + *end++= 0; + else + { + if (mysql->client_flag & CLIENT_SECURE_CONNECTION) + { + DBUG_ASSERT(data_len <= 255); + if (data_len > 255) + { + my_set_error(mysql, CR_MALFORMED_PACKET, SQLSTATE_UNKNOWN, 0); + goto error; + } + *end++= data_len; + } + else + { + DBUG_ASSERT(data_len == SCRAMBLE_LENGTH_323 + 1); + DBUG_ASSERT(data[SCRAMBLE_LENGTH_323] == 0); + } + memcpy(end, data, data_len); + end+= data_len; + } + end= strmake(end, mpvio->db ? mpvio->db : "", NAME_LEN) + 1; + + if (mysql->server_capabilities & CLIENT_PROTOCOL_41) + { + int2store(end, (ushort) mysql->charset->nr); + end+= 2; + } + + if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH) + end= strmake(end, mpvio->plugin->name, NAME_LEN) + 1; + + res= simple_command(mysql, MYSQL_COM_CHANGE_USER, + buff, (ulong)(end-buff), 1); + +error: + my_afree(buff); + return res; +} + + +/** + sends a client authentication packet (second packet in the 3-way handshake) + + Packet format (when the server is 4.0 or earlier): + + Bytes Content + ----- ---- + 2 client capabilities + 3 max packet size + n user name, \0-terminated + 9 scramble_323, \0-terminated + + Packet format (when the server is 4.1 or newer): + + Bytes Content + ----- ---- + 4 client capabilities + 4 max packet size + 1 charset number + 23 reserved (always 0) + n user name, \0-terminated + n plugin auth data (e.g. scramble), length (1 byte) coded + n database name, \0-terminated + (if CLIENT_CONNECT_WITH_DB is set in the capabilities) + n client auth plugin name - \0-terminated string, + (if CLIENT_PLUGIN_AUTH is set in the capabilities) + + @retval 0 ok + @retval 1 error +*/ + +static int send_client_reply_packet(MCPVIO_EXT *mpvio, + const uchar *data, int data_len) +{ + MYSQL *mysql= mpvio->mysql; + NET *net= &mysql->net; + char *buff, *end; + + /* see end= buff+32 below, fixed size of the packet is 32 bytes */ + buff= my_alloca(33 + USERNAME_LENGTH + data_len + NAME_LEN + NAME_LEN); + + mysql->client_flag|= mysql->options.client_flag; + mysql->client_flag|= CLIENT_CAPABILITIES; + + if (mysql->client_flag & CLIENT_MULTI_STATEMENTS) + mysql->client_flag|= CLIENT_MULTI_RESULTS; + +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) + if (mysql->options.ssl_key || mysql->options.ssl_cert || + mysql->options.ssl_ca || mysql->options.ssl_capath || + mysql->options.ssl_cipher) + mysql->options.use_ssl= 1; + if (mysql->options.use_ssl) + mysql->client_flag|= CLIENT_SSL; +#endif /* HAVE_OPENSSL && !EMBEDDED_LIBRARY*/ + if (mpvio->db) + mysql->client_flag|= CLIENT_CONNECT_WITH_DB; + + /* Remove options that server doesn't support */ + mysql->client_flag= mysql->client_flag & + (~(CLIENT_COMPRESS | CLIENT_SSL | CLIENT_PROTOCOL_41) + | mysql->server_capabilities); + +#ifndef HAVE_COMPRESS + mysql->client_flag&= ~CLIENT_COMPRESS; +#endif + + if (mysql->client_flag & CLIENT_PROTOCOL_41) + { + /* 4.1 server and 4.1 client has a 32 byte option flag */ + int4store(buff,mysql->client_flag); + int4store(buff+4, net->max_packet_size); + buff[8]= (char) mysql->charset->nr; + bzero(buff+9, 32-9); + end= buff+32; + } + else + { + int2store(buff, mysql->client_flag); + int3store(buff+2, net->max_packet_size); + end= buff+5; + } +#ifdef HAVE_OPENSSL + if (mysql->client_flag & CLIENT_SSL) + { + /* Do the SSL layering. */ + struct st_mysql_options *options= &mysql->options; + struct st_VioSSLFd *ssl_fd; + char error_string[1024]; + + /* + Send mysql->client_flag, max_packet_size - unencrypted otherwise + the server does not know we want to do SSL + */ + if (my_net_write(net, (uchar*)buff, (size_t) (end-buff)) || net_flush(net)) + { + my_set_error(mysql, CR_SERVER_LOST, SQLSTATE_UNKNOWN, + ER(CR_SERVER_LOST_EXTENDED), + "sending connection information to server", + errno); + goto error; + } + + /* Create the VioSSLConnectorFd - init SSL and load certs */ + if (!(ssl_fd= new_VioSSLConnectorFd(options->ssl_key, + options->ssl_cert, + options->ssl_ca, + options->ssl_capath, + options->ssl_cipher))) + { + my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, 0); + goto error; + } + mysql->connector_fd= (void*)ssl_fd; + + /* Connect to the server */ + DBUG_PRINT("info", ("IO layer change in progress...")); + if (sslconnect(ssl_fd, net->vio, + (long) (mysql->options.connect_timeout), + error_string)) + { + my_set_error(mysql, CR_SSL_CONNECTION_ERROR, + SQLSTATE_UNKNOWN, "SSL error: %s", + error_string[0] ? error_string : + ER(CR_SSL_CONNECTION_ERROR)); + goto error; + } + DBUG_PRINT("info", ("IO layer change done!")); + + /* Verify server cert */ + if ((mysql->client_flag & CLIENT_SSL_VERIFY_SERVER_CERT) && + ssl_verify_server_cert(net->vio, mysql->host)) + { + my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, 0); + goto error; + } + } +#endif /* HAVE_OPENSSL */ + + DBUG_PRINT("info",("Server version = '%s' capabilites: %lu status: %u client_flag: %lu", + mysql->server_version, mysql->server_capabilities, + mysql->server_status, mysql->client_flag)); + + compile_time_assert(MYSQL_USERNAME_LENGTH == USERNAME_LENGTH); + + /* This needs to be changed as it's not useful with big packets */ + if (mysql->user[0]) + strmake(end, mysql->user, USERNAME_LENGTH); + else + read_user_name(end); + + /* We have to handle different version of handshake here */ + DBUG_PRINT("info",("user: %s",end)); + end= strend(end) + 1; + if (data_len) + { + if (mysql->server_capabilities & CLIENT_SECURE_CONNECTION) + { + *end++= data_len; + memcpy(end, data, data_len); + end+= data_len; + } + else + { + DBUG_ASSERT(data_len == SCRAMBLE_LENGTH_323 + 1); /* incl. \0 at the end */ + memcpy(end, data, data_len); + end+= data_len; + } + } + else + *end++= 0; + + /* Add database if needed */ + if (mpvio->db && (mysql->server_capabilities & CLIENT_CONNECT_WITH_DB)) + { + end= strmake(end, mpvio->db, NAME_LEN) + 1; + mysql->db= my_strdup(mpvio->db, MYF(MY_WME)); + } + + if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH) + end= strmake(end, mpvio->plugin->name, NAME_LEN) + 1; + + /* Write authentication package */ + if (my_net_write(net, buff, (size_t) (end-buff)) || net_flush(net)) + { + my_set_error(mysql, CR_SERVER_LOST, SQLSTATE_UNKNOWN, + ER(CR_SERVER_LOST_EXTENDED), + "sending authentication information", + errno); + goto error; + } + my_afree(buff); + return 0; + +error: + my_afree(buff); + return 1; +} + +/** + vio->read_packet() callback method for client authentication plugins + + This function is called by a client authentication plugin, when it wants + to read data from the server. +*/ + +static int client_mpvio_read_packet(struct st_plugin_vio *mpv, uchar **buf) +{ + MCPVIO_EXT *mpvio= (MCPVIO_EXT*)mpv; + MYSQL *mysql= mpvio->mysql; + ulong pkt_len; + + /* there are cached data left, feed it to a plugin */ + if (mpvio->cached_server_reply.pkt) + { + *buf= mpvio->cached_server_reply.pkt; + mpvio->cached_server_reply.pkt= 0; + mpvio->packets_read++; + return mpvio->cached_server_reply.pkt_len; + } + + if (mpvio->packets_read == 0) + { + /* + the server handshake packet came from the wrong plugin, + or it's mysql_change_user(). Either way, there is no data + for a plugin to read. send a dummy packet to the server + to initiate a dialog. + */ + if (client_mpvio_write_packet(mpv, 0, 0)) + return (int)packet_error; + } + + /* otherwise read the data */ + pkt_len= net_safe_read(mysql); + mpvio->last_read_packet_len= pkt_len; + *buf= mysql->net.read_pos; + + /* was it a request to change plugins ? */ + if (**buf == 254) + return (int)packet_error; /* if yes, this plugin shan't continue */ + + /* + the server sends \1\255 or \1\254 instead of just \255 or \254 - + for us to not confuse it with an error or "change plugin" packets. + We remove this escaping \1 here. + + See also server_mpvio_write_packet() where the escaping is done. + */ + if (pkt_len && **buf == 1) + { + (*buf)++; + pkt_len--; + } + mpvio->packets_read++; + return pkt_len; +} + +/** + vio->write_packet() callback method for client authentication plugins + + This function is called by a client authentication plugin, when it wants + to send data to the server. + + It transparently wraps the data into a change user or authentication + handshake packet, if neccessary. +*/ + +static int client_mpvio_write_packet(struct st_plugin_vio *mpv, + const uchar *pkt, size_t pkt_len) +{ + int res; + MCPVIO_EXT *mpvio= (MCPVIO_EXT*)mpv; + + if (mpvio->packets_written == 0) + { + if (mpvio->mysql_change_user) + res= send_change_user_packet(mpvio, pkt, pkt_len); + else + res= send_client_reply_packet(mpvio, pkt, pkt_len); + } + else + { + NET *net= &mpvio->mysql->net; + if (mpvio->mysql->thd) + res= 1; /* no chit-chat in embedded */ + else + res= my_net_write(net, (char *)pkt, pkt_len) || net_flush(net); + if (res) + my_set_error(mpvio->mysql, CR_SERVER_LOST, SQLSTATE_UNKNOWN, + ER(CR_SERVER_LOST_EXTENDED), + "sending authentication information", + errno); + } + mpvio->packets_written++; + return res; +} + +/** + fills MYSQL_PLUGIN_VIO_INFO structure with the information about the + connection +*/ + +void mpvio_info(Vio *vio, MYSQL_PLUGIN_VIO_INFO *info) +{ + bzero(info, sizeof(*info)); + switch (vio->type) { + case VIO_TYPE_TCPIP: + info->protocol= MYSQL_VIO_TCP; + info->socket= vio->sd; + return; + case VIO_TYPE_SOCKET: + info->protocol= MYSQL_VIO_SOCKET; + info->socket= vio->sd; + return; + case VIO_TYPE_SSL: + { + struct sockaddr addr; + SOCKET_SIZE_TYPE addrlen= sizeof(addr); + if (getsockname(vio->sd, &addr, &addrlen)) + return; + info->protocol= addr.sa_family == AF_UNIX ? + MYSQL_VIO_SOCKET : MYSQL_VIO_TCP; + info->socket= vio->sd; + return; + } +#ifdef _WIN32 + case VIO_TYPE_NAMEDPIPE: + info->protocol= MYSQL_VIO_PIPE; + info->handle= vio->hPipe; + return; +/* not supported yet + case VIO_TYPE_SHARED_MEMORY: + info->protocol= MYSQL_VIO_MEMORY; + info->handle= vio->handle_file_map; + return; +*/ +#endif + default: DBUG_ASSERT(0); + } +} + +static void client_mpvio_info(MYSQL_PLUGIN_VIO *vio, + MYSQL_PLUGIN_VIO_INFO *info) +{ + MCPVIO_EXT *mpvio= (MCPVIO_EXT*)vio; + mpvio_info(mpvio->mysql->net.vio, info); +} + +/** + Client side of the plugin driver authentication. + + @note this is used by both the mysql_real_connect and mysql_change_user + + @param mysql mysql + @param data pointer to the plugin auth data (scramble) in the + handshake packet + @param data_len the length of the data + @param data_plugin a plugin that data were prepared for + or 0 if it's mysql_change_user() + @param db initial db to use, can be 0 + + @retval 0 ok + @retval 1 error +*/ + +int run_plugin_auth(MYSQL *mysql, char *data, uint data_len, + const char *data_plugin, const char *db) +{ + const char *auth_plugin_name; + auth_plugin_t *auth_plugin; + MCPVIO_EXT mpvio; + ulong pkt_length; + int res; + + /* determine the default/initial plugin to use */ + if (mysql->options.extension && mysql->options.extension->default_auth && + mysql->server_capabilities & CLIENT_PLUGIN_AUTH) + { + auth_plugin_name= mysql->options.extension->default_auth; + if (!(auth_plugin= (auth_plugin_t*) mysql_client_find_plugin(mysql, + auth_plugin_name, MYSQL_CLIENT_AUTHENTICATION_PLUGIN))) + return 1; /* oops, not found */ + } + else + { + auth_plugin= mysql->server_capabilities & CLIENT_PROTOCOL_41 ? + &native_password_client_plugin : &old_password_client_plugin; + auth_plugin_name= auth_plugin->name; + } + + mysql->net.last_errno= 0; /* just in case */ + + if (data_plugin && strcmp(data_plugin, auth_plugin_name)) + { + /* data was prepared for a different plugin, don't show it to this one */ + data= 0; + data_len= 0; + } + + mpvio.mysql_change_user= data_plugin == 0; + mpvio.cached_server_reply.pkt= (uchar*)data; + mpvio.cached_server_reply.pkt_len= data_len; + mpvio.read_packet= client_mpvio_read_packet; + mpvio.write_packet= client_mpvio_write_packet; + mpvio.info= client_mpvio_info; + mpvio.mysql= mysql; + mpvio.packets_read= mpvio.packets_written= 0; + mpvio.db= db; + mpvio.plugin= auth_plugin; + + res= auth_plugin->authenticate_user((struct st_plugin_vio *)&mpvio, mysql); + + compile_time_assert(CR_OK == -1); + compile_time_assert(CR_ERROR == 0); + if (res > CR_OK && mysql->net.read_pos[0] != 254) + { + /* + the plugin returned an error. write it down in mysql, + unless the error code is CR_ERROR and mysql->net.last_errno + is already set (the plugin has done it) + */ + if (res > CR_ERROR) + my_set_error(mysql, res, SQLSTATE_UNKNOWN, 0); + else + if (!mysql->net.last_errno) + my_set_error(mysql, CR_UNKNOWN_ERROR, SQLSTATE_UNKNOWN, 0); + return 1; + } + + /* read the OK packet (or use the cached value in mysql->net.read_pos */ + if (res == CR_OK) + pkt_length= net_safe_read(mysql); + else /* res == CR_OK_HANDSHAKE_COMPLETE */ + pkt_length= mpvio.last_read_packet_len; + + if (pkt_length == packet_error) + { + if (mysql->net.last_errno == CR_SERVER_LOST) + my_set_error(mysql, CR_SERVER_LOST, SQLSTATE_UNKNOWN, + ER(CR_SERVER_LOST_EXTENDED), + "reading authorization packet", + errno); + return 1; + } + + if (mysql->net.read_pos[0] == 254) + { + /* The server asked to use a different authentication plugin */ + if (pkt_length == 1) + { + /* old "use short scramble" packet */ + auth_plugin_name= old_password_plugin_name; + mpvio.cached_server_reply.pkt= (uchar*)mysql->scramble_buff; + mpvio.cached_server_reply.pkt_len= SCRAMBLE_LENGTH + 1; + } + else + { + /* new "use different plugin" packet */ + uint len; + auth_plugin_name= (char*)mysql->net.read_pos + 1; + len= strlen(auth_plugin_name); /* safe as my_net_read always appends \0 */ + mpvio.cached_server_reply.pkt_len= pkt_length - len - 2; + mpvio.cached_server_reply.pkt= mysql->net.read_pos + len + 2; + } + + if (!(auth_plugin= (auth_plugin_t *) mysql_client_find_plugin(mysql, + auth_plugin_name, MYSQL_CLIENT_AUTHENTICATION_PLUGIN))) + return 1; + + mpvio.plugin= auth_plugin; + res= auth_plugin->authenticate_user((struct st_plugin_vio *)&mpvio, mysql); + + if (res > CR_OK) + { + if (res > CR_ERROR) + my_set_error(mysql, res, SQLSTATE_UNKNOWN, 0); + else + if (!mysql->net.last_errno) + my_set_error(mysql, CR_UNKNOWN_ERROR, SQLSTATE_UNKNOWN, 0); + return 1; + } + + if (res != CR_OK_HANDSHAKE_COMPLETE) + { + /* Read what server thinks about out new auth message report */ + if (net_safe_read(mysql) == packet_error) + { + if (mysql->net.last_errno == CR_SERVER_LOST) + my_set_error(mysql, CR_SERVER_LOST, SQLSTATE_UNKNOWN, + ER(CR_SERVER_LOST_EXTENDED), + "reading final connect information", + errno); + return 1; + } + } + } + /* + net->read_pos[0] should always be 0 here if the server implements + the protocol correctly + */ + return mysql->net.read_pos[0] != 0; +} + diff --git a/libmysql/my_charset.c b/libmysql/my_charset.c new file mode 100644 index 000000000..12e05963f --- /dev/null +++ b/libmysql/my_charset.c @@ -0,0 +1,828 @@ +/**************************************************************************** + Copyright (C) 2011 Monty Program AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA +*****************************************************************************/ + +/* The implementation for character set support was ported from PHP's mysqlnd + extension, written by Andrey Hristov, Georg Richter and Ulf Wendel + + Original file header: + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 2006-2011 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Georg Richter | + | Andrey Hristov | + | Ulf Wendel | + +----------------------------------------------------------------------+ +*/ + +#ifndef _WIN32 +#include +#include +#else +#include +#endif +#include +#include + +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 2006-2011 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Georg Richter | + | Andrey Hristov | + | Ulf Wendel | + +----------------------------------------------------------------------+ +*/ + +/* {{{ utf8 functions */ +static unsigned int check_mb_utf8mb3_sequence(const char *start, const char *end) +{ + uchar c; + + if (start >= end) { + return 0; + } + + c = (uchar) start[0]; + + if (c < 0x80) { + return 1; /* single byte character */ + } + if (c < 0xC2) { + return 0; /* invalid mb character */ + } + if (c < 0xE0) { + if (start + 2 > end) { + return 0; /* too small */ + } + if (!(((uchar)start[1] ^ 0x80) < 0x40)) { + return 0; + } + return 2; + } + if (c < 0xF0) { + if (start + 3 > end) { + return 0; /* too small */ + } + if (!(((uchar)start[1] ^ 0x80) < 0x40 && ((uchar)start[2] ^ 0x80) < 0x40 && + (c >= 0xE1 || (uchar)start[1] >= 0xA0))) { + return 0; /* invalid utf8 character */ + } + return 3; + } + return 0; +} + + +static unsigned int check_mb_utf8_sequence(const char *start, const char *end) +{ + uchar c; + + if (start >= end) { + return 0; + } + + c = (uchar) start[0]; + + if (c < 0x80) { + return 1; /* single byte character */ + } + if (c < 0xC2) { + return 0; /* invalid mb character */ + } + if (c < 0xE0) { + if (start + 2 > end) { + return 0; /* too small */ + } + if (!(((uchar)start[1] ^ 0x80) < 0x40)) { + return 0; + } + return 2; + } + if (c < 0xF0) { + if (start + 3 > end) { + return 0; /* too small */ + } + if (!(((uchar)start[1] ^ 0x80) < 0x40 && ((uchar)start[2] ^ 0x80) < 0x40 && + (c >= 0xE1 || (uchar)start[1] >= 0xA0))) { + return 0; /* invalid utf8 character */ + } + return 3; + } + if (c < 0xF5) { + if (start + 4 > end) { /* We need 4 characters */ + return 0; /* too small */ + } + + /* + UTF-8 quick four-byte mask: + 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx + Encoding allows to encode U+00010000..U+001FFFFF + + The maximum character defined in the Unicode standard is U+0010FFFF. + Higher characters U+00110000..U+001FFFFF are not used. + + 11110000.10010000.10xxxxxx.10xxxxxx == F0.90.80.80 == U+00010000 (min) + 11110100.10001111.10111111.10111111 == F4.8F.BF.BF == U+0010FFFF (max) + + Valid codes: + [F0][90..BF][80..BF][80..BF] + [F1][80..BF][80..BF][80..BF] + [F2][80..BF][80..BF][80..BF] + [F3][80..BF][80..BF][80..BF] + [F4][80..8F][80..BF][80..BF] + */ + + if (!(((uchar)start[1] ^ 0x80) < 0x40 && + ((uchar)start[2] ^ 0x80) < 0x40 && + ((uchar)start[3] ^ 0x80) < 0x40 && + (c >= 0xf1 || (uchar)start[1] >= 0x90) && + (c <= 0xf3 || (uchar)start[1] <= 0x8F))) + { + return 0; /* invalid utf8 character */ + } + return 4; + } + return 0; +} + +static unsigned int check_mb_utf8mb3_valid(const char *start, const char *end) +{ + unsigned int len = check_mb_utf8mb3_sequence(start, end); + return (len > 1)? len:0; +} + +static unsigned int check_mb_utf8_valid(const char *start, const char *end) +{ + unsigned int len = check_mb_utf8_sequence(start, end); + return (len > 1)? len:0; +} + + +static unsigned int mysql_mbcharlen_utf8mb3(unsigned int utf8) +{ + if (utf8 < 0x80) { + return 1; /* single byte character */ + } + if (utf8 < 0xC2) { + return 0; /* invalid multibyte header */ + } + if (utf8 < 0xE0) { + return 2; /* double byte character */ + } + if (utf8 < 0xF0) { + return 3; /* triple byte character */ + } + return 0; +} + + +static unsigned int mysql_mbcharlen_utf8(unsigned int utf8) +{ + if (utf8 < 0x80) { + return 1; /* single byte character */ + } + if (utf8 < 0xC2) { + return 0; /* invalid multibyte header */ + } + if (utf8 < 0xE0) { + return 2; /* double byte character */ + } + if (utf8 < 0xF0) { + return 3; /* triple byte character */ + } + if (utf8 < 0xF8) { + return 4; /* four byte character */ + } + return 0; +} +/* }}} */ + + +/* {{{ big5 functions */ +#define valid_big5head(c) (0xA1 <= (unsigned int)(c) && (unsigned int)(c) <= 0xF9) +#define valid_big5tail(c) ((0x40 <= (unsigned int)(c) && (unsigned int)(c) <= 0x7E) || \ + (0xA1 <= (unsigned int)(c) && (unsigned int)(c) <= 0xFE)) + +#define isbig5code(c,d) (isbig5head(c) && isbig5tail(d)) + +static unsigned int check_mb_big5(const char *start, const char *end) +{ + return (valid_big5head(*(start)) && (end - start) > 1 && valid_big5tail(*(start + 1)) ? 2 : 0); +} + + +static unsigned int mysql_mbcharlen_big5(unsigned int big5) +{ + return (valid_big5head(big5)) ? 2 : 1; +} +/* }}} */ + + +/* {{{ cp932 functions */ +#define valid_cp932head(c) ((0x81 <= (c) && (c) <= 0x9F) || (0xE0 <= (c) && c <= 0xFC)) +#define valid_cp932tail(c) ((0x40 <= (c) && (c) <= 0x7E) || (0x80 <= (c) && c <= 0xFC)) + + +static unsigned int check_mb_cp932(const char *start, const char *end) +{ + return (valid_cp932head((uchar)start[0]) && (end - start > 1) && + valid_cp932tail((uchar)start[1])) ? 2 : 0; +} + + +static unsigned int mysql_mbcharlen_cp932(unsigned int cp932) +{ + return (valid_cp932head((uchar)cp932)) ? 2 : 1; +} +/* }}} */ + + +/* {{{ euckr functions */ +#define valid_euckr(c) ((0xA1 <= (uchar)(c) && (uchar)(c) <= 0xFE)) + +static unsigned int check_mb_euckr(const char *start, const char *end) +{ + if (end - start <= 1) { + return 0; /* invalid length */ + } + if (*(uchar *)start < 0x80) { + return 0; /* invalid euckr character */ + } + if (valid_euckr(start[1])) { + return 2; + } + return 0; +} + + +static unsigned int mysql_mbcharlen_euckr(unsigned int kr) +{ + return (valid_euckr(kr)) ? 2 : 1; +} +/* }}} */ + + +/* {{{ eucjpms functions */ +#define valid_eucjpms(c) (((c) & 0xFF) >= 0xA1 && ((c) & 0xFF) <= 0xFE) +#define valid_eucjpms_kata(c) (((c) & 0xFF) >= 0xA1 && ((c) & 0xFF) <= 0xDF) +#define valid_eucjpms_ss2(c) (((c) & 0xFF) == 0x8E) +#define valid_eucjpms_ss3(c) (((c) & 0xFF) == 0x8F) + +static unsigned int check_mb_eucjpms(const char *start, const char *end) +{ + if (*((uchar *)start) < 0x80) { + return 0; /* invalid eucjpms character */ + } + if (valid_eucjpms(start[0]) && (end - start) > 1 && valid_eucjpms(start[1])) { + return 2; + } + if (valid_eucjpms_ss2(start[0]) && (end - start) > 1 && valid_eucjpms_kata(start[1])) { + return 2; + } + if (valid_eucjpms_ss3(start[0]) && (end - start) > 2 && valid_eucjpms(start[1]) && + valid_eucjpms(start[2])) { + return 2; + } + return 0; +} + + +static unsigned int mysql_mbcharlen_eucjpms(unsigned int jpms) +{ + if (valid_eucjpms(jpms) || valid_eucjpms_ss2(jpms)) { + return 2; + } + if (valid_eucjpms_ss3(jpms)) { + return 3; + } + return 1; +} +/* }}} */ + + +/* {{{ gb2312 functions */ +#define valid_gb2312_head(c) (0xA1 <= (uchar)(c) && (uchar)(c) <= 0xF7) +#define valid_gb2312_tail(c) (0xA1 <= (uchar)(c) && (uchar)(c) <= 0xFE) + + +static unsigned int check_mb_gb2312(const char *start, const char *end) +{ + return (valid_gb2312_head((unsigned int)start[0]) && end - start > 1 && + valid_gb2312_tail((unsigned int)start[1])) ? 2 : 0; +} + + +static unsigned int mysql_mbcharlen_gb2312(unsigned int gb) +{ + return (valid_gb2312_head(gb)) ? 2 : 1; +} +/* }}} */ + + +/* {{{ gbk functions */ +#define valid_gbk_head(c) (0x81<=(uchar)(c) && (uchar)(c)<=0xFE) +#define valid_gbk_tail(c) ((0x40<=(uchar)(c) && (uchar)(c)<=0x7E) || (0x80<=(uchar)(c) && (uchar)(c)<=0xFE)) + +static unsigned int check_mb_gbk(const char *start, const char *end) +{ + return (valid_gbk_head(start[0]) && (end) - (start) > 1 && valid_gbk_tail(start[1])) ? 2 : 0; +} + +static unsigned int mysql_mbcharlen_gbk(unsigned int gbk) +{ + return (valid_gbk_head(gbk) ? 2 : 1); +} +/* }}} */ + + +/* {{{ sjis functions */ +#define valid_sjis_head(c) ((0x81 <= (c) && (c) <= 0x9F) || (0xE0 <= (c) && (c) <= 0xFC)) +#define valid_sjis_tail(c) ((0x40 <= (c) && (c) <= 0x7E) || (0x80 <= (c) && (c) <= 0xFC)) + + +static unsigned int check_mb_sjis(const char *start, const char *end) +{ + return (valid_sjis_head((uchar)start[0]) && (end - start) > 1 && valid_sjis_tail((uchar)start[1])) ? 2 : 0; +} + + +static unsigned int mysql_mbcharlen_sjis(unsigned int sjis) +{ + return (valid_sjis_head((uchar)sjis)) ? 2 : 1; +} +/* }}} */ + + +/* {{{ ucs2 functions */ +static unsigned int check_mb_ucs2(const char *start __attribute((unused)), const char *end __attribute((unused))) +{ + return 2; /* always 2 */ +} + +static unsigned int mysql_mbcharlen_ucs2(unsigned int ucs2 __attribute((unused))) +{ + return 2; /* always 2 */ +} +/* }}} */ + + +/* {{{ ujis functions */ +#define valid_ujis(c) ((0xA1 <= ((c)&0xFF) && ((c)&0xFF) <= 0xFE)) +#define valid_ujis_kata(c) ((0xA1 <= ((c)&0xFF) && ((c)&0xFF) <= 0xDF)) +#define valid_ujis_ss2(c) (((c)&0xFF) == 0x8E) +#define valid_ujis_ss3(c) (((c)&0xFF) == 0x8F) + +static unsigned int check_mb_ujis(const char *start, const char *end) +{ + if (*(uchar*)start < 0x80) { + return 0; /* invalid ujis character */ + } + if (valid_ujis(*(start)) && valid_ujis(*((start)+1))) { + return 2; + } + if (valid_ujis_ss2(*(start)) && valid_ujis_kata(*((start)+1))) { + return 2; + } + if (valid_ujis_ss3(*(start)) && (end-start) > 2 && valid_ujis(*((start)+1)) && valid_ujis(*((start)+2))) { + return 3; + } + return 0; +} + + +static unsigned int mysql_mbcharlen_ujis(unsigned int ujis) +{ + return (valid_ujis(ujis)? 2: valid_ujis_ss2(ujis)? 2: valid_ujis_ss3(ujis)? 3: 1); +} +/* }}} */ + + + +/* {{{ utf16 functions */ +#define UTF16_HIGH_HEAD(x) ((((uchar) (x)) & 0xFC) == 0xD8) +#define UTF16_LOW_HEAD(x) ((((uchar) (x)) & 0xFC) == 0xDC) + +static unsigned int check_mb_utf16(const char *start, const char *end) +{ + if (start + 2 > end) { + return 0; + } + + if (UTF16_HIGH_HEAD(*start)) { + return (start + 4 <= end) && UTF16_LOW_HEAD(start[2]) ? 4 : 0; + } + + if (UTF16_LOW_HEAD(*start)) { + return 0; + } + return 2; +} + + +static uint mysql_mbcharlen_utf16(unsigned int utf16) +{ + return UTF16_HIGH_HEAD(utf16) ? 4 : 2; +} +/* }}} */ + + +/* {{{ utf32 functions */ +static uint +check_mb_utf32(const char *start __attribute((unused)), const char *end __attribute((unused))) +{ + return 4; +} + + +static uint +mysql_mbcharlen_utf32(unsigned int utf32 __attribute((unused))) +{ + return 4; +} +/* }}} */ + +/* + The server compiles sometimes the full utf-8 (the mb4) as utf8m4, and the old as utf8, + for BC reasons. Sometimes, utf8mb4 is just utf8 but the old charsets are utf8mb3. + Change easily now, with a macro, could be made compilastion dependable. +*/ + +#define UTF8_MB4 "utf8mb4" +#define UTF8_MB3 "utf8" + +/* {{{ mysql_charsets */ +const CHARSET_INFO compiled_charsets[] = +{ + { 1, 1, "big5","big5_chinese_ci", "", "", 1, 2, mysql_mbcharlen_big5, check_mb_big5}, + { 3, 1, "dec8", "dec8_swedisch_ci", "", "", 1, 1, NULL, NULL}, + { 4, 1, "cp850", "cp850_general_ci", "", "", 1, 1, NULL, NULL}, + { 6, 1, "hp8", "hp8_english_ci", "", "", 1, 1, NULL, NULL}, + { 7, 1, "koi8r", "koi8r_general_ci", "", "", 1, 1, NULL, NULL}, + { 8, 1, "latin1", "latin1_swedish_ci", "", "", 1, 1, NULL, NULL}, + { 9, 1, "latin2", "latin2_general_ci", "", "", 1, 1, NULL, NULL}, + { 10, 1, "swe7", "swe7_swedish_ci", "", "", 1, 1, NULL, NULL}, + { 11, 1, "ascii", "ascii_general_ci", "", "", 1, 1, NULL, NULL}, + { 12, 1, "ujis", "ujis_japanese_ci", "", "", 1, 3, mysql_mbcharlen_ujis, check_mb_ujis}, + { 13, 1, "sjis", "sjis_japanese_ci", "", "", 1, 2, mysql_mbcharlen_sjis, check_mb_sjis}, + { 16, 1, "hebrew", "hebrew_general_ci", "", "", 1, 1, NULL, NULL}, + { 18, 1, "tis620", "tis620_thai_ci", "", "", 1, 1, NULL, NULL}, + { 19, 1, "euckr", "euckr_korean_ci", "", "", 1, 2, mysql_mbcharlen_euckr, check_mb_euckr}, + { 22, 1, "koi8u", "koi8u_general_ci", "", "", 1, 1, NULL, NULL}, + { 24, 1, "gb2312", "gb2312_chinese_ci", "", "", 1, 2, mysql_mbcharlen_gb2312, check_mb_gb2312}, + { 25, 1, "greek", "greek_general_ci", "", "", 1, 1, NULL, NULL}, + { 26, 1, "cp1250", "cp1250_general_ci", "", "", 1, 1, NULL, NULL}, + { 28, 1, "gbk", "gbk_chinese_ci", "", "", 1, 2, mysql_mbcharlen_gbk, check_mb_gbk}, + { 30, 1, "latin5", "latin5_turkish_ci", "", "", 1, 1, NULL, NULL}, + { 32, 1, "armscii8", "armscii8_general_ci", "", "", 1, 1, NULL, NULL}, + { 33, 1, UTF8_MB3, UTF8_MB3"_general_ci", "UTF-8 Unicode", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 35, 1, "ucs2", "ucs2_general_ci", "UCS-2 Unicode", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 36, 1, "cp866", "cp866_general_ci", "", "", 1, 1, NULL, NULL}, + { 37, 1, "keybcs2", "keybcs2_general_ci", "", "", 1, 1, NULL, NULL}, + { 38, 1, "macce", "macce_general_ci", "", "", 1, 1, NULL, NULL}, + { 39, 1, "macroman", "macroman_general_ci", "", "", 1, 1, NULL, NULL}, + { 40, 1, "cp852", "cp852_general_ci", "", "", 1, 1, NULL, NULL}, + { 41, 1, "latin7", "latin7_general_ci", "", "", 1, 1, NULL, NULL}, + { 51, 1, "cp1251", "cp1251_general_ci", "", "", 1, 1, NULL, NULL}, + { 57, 1, "cp1256", "cp1256_general_ci", "", "", 1, 1, NULL, NULL}, + { 59, 1, "cp1257", "cp1257_general_ci", "", "", 1, 1, NULL, NULL}, + { 63, 1, "binary", "binary", "", "", 1, 1, NULL, NULL}, + { 92, 1, "geostd8", "geostd8_general_ci", "", "", 1, 1, NULL, NULL}, + { 95, 1, "cp932", "cp932_japanese_ci", "", "", 1, 2, mysql_mbcharlen_cp932, check_mb_cp932}, + { 97, 1, "eucjpms", "eucjpms_japanese_ci", "", "", 1, 3, mysql_mbcharlen_eucjpms, check_mb_eucjpms}, + { 2, 1, "latin2", "latin2_czech_cs", "", "", 1, 1, NULL, NULL}, + { 5, 1, "latin1", "latin1_german_ci", "", "", 1, 1, NULL, NULL}, + { 14, 1, "cp1251", "cp1251_bulgarian_ci", "", "", 1, 1, NULL, NULL}, + { 15, 1, "latin1", "latin1_danish_ci", "", "", 1, 1, NULL, NULL}, + { 17, 1, "filename", "filename", "", "", 1, 5, NULL, NULL}, + { 20, 1, "latin7", "latin7_estonian_cs", "", "", 1, 1, NULL, NULL}, + { 21, 1, "latin2", "latin2_hungarian_ci", "", "", 1, 1, NULL, NULL}, + { 23, 1, "cp1251", "cp1251_ukrainian_ci", "", "", 1, 1, NULL, NULL}, + { 27, 1, "latin2", "latin2_croatian_ci", "", "", 1, 1, NULL, NULL}, + { 29, 1, "cp1257", "cp1257_lithunian_ci", "", "", 1, 1, NULL, NULL}, + { 31, 1, "latin1", "latin1_german2_ci", "", "", 1, 1, NULL, NULL}, + { 34, 1, "cp1250", "cp1250_czech_cs", "", "", 1, 1, NULL, NULL}, + { 42, 1, "latin7", "latin7_general_cs", "", "", 1, 1, NULL, NULL}, + { 43, 1, "macce", "macce_bin", "", "", 1, 1, NULL, NULL}, + { 44, 1, "cp1250", "cp1250_croatian_ci", "", "", 1, 1, NULL, NULL}, + { 45, 1, UTF8_MB4, UTF8_MB4"_general_ci", "UTF-8 Unicode", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 46, 1, UTF8_MB4, UTF8_MB4"_bin", "UTF-8 Unicode", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 47, 1, "latin1", "latin1_bin", "", "", 1, 1, NULL, NULL}, + { 48, 1, "latin1", "latin1_general_ci", "", "", 1, 1, NULL, NULL}, + { 49, 1, "latin1", "latin1_general_cs", "", "", 1, 1, NULL, NULL}, + { 50, 1, "cp1251", "cp1251_bin", "", "", 1, 1, NULL, NULL}, + { 52, 1, "cp1251", "cp1251_general_cs", "", "", 1, 1, NULL, NULL}, + { 53, 1, "macroman", "macroman_bin", "", "", 1, 1, NULL, NULL}, + { 54, 1, "utf16", "utf16_general_ci", "UTF_16 Unicode", "", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 55, 1, "utf16", "utf16_bin", "UTF-16 Unicode", "", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 58, 1, "cp1257", "cp1257_bin", "", "", 1, 1, NULL, NULL}, +#ifdef USED_TO_BE_SO_BEFORE_MYSQL_5_5 + { 60, 1, "armascii8", "armascii8_bin", "", "", 1, 1, NULL, NULL}, +#endif + { 60, 1, "utf32", "utf32_general_ci", "UTF-32 Unicode", "", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 61, 1, "utf32", "utf32_bin", "UTF-32 Unicode", "", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 65, 1, "ascii", "ascii_bin", "", "", 1, 1, NULL, NULL}, + { 66, 1, "cp1250", "cp1250_bin", "", "", 1, 1, NULL, NULL}, + { 67, 1, "cp1256", "cp1256_bin", "", "", 1, 1, NULL, NULL}, + { 68, 1, "cp866", "cp866_bin", "", "", 1, 1, NULL, NULL}, + { 69, 1, "dec8", "dec8_bin", "", "", 1, 1, NULL, NULL}, + { 70, 1, "greek", "greek_bin", "", "", 1, 1, NULL, NULL}, + { 71, 1, "hebew", "hebrew_bin", "", "", 1, 1, NULL, NULL}, + { 72, 1, "hp8", "hp8_bin", "", "", 1, 1, NULL, NULL}, + { 73, 1, "keybcs2", "keybcs2_bin", "", "", 1, 1, NULL, NULL}, + { 74, 1, "koi8r", "koi8r_bin", "", "", 1, 1, NULL, NULL}, + { 75, 1, "koi8u", "koi8u_bin", "", "", 1, 1, NULL, NULL}, + { 77, 1, "latin2", "latin2_bin", "", "", 1, 1, NULL, NULL}, + { 78, 1, "latin5", "latin5_bin", "", "", 1, 1, NULL, NULL}, + { 79, 1, "latin7", "latin7_bin", "", "", 1, 1, NULL, NULL}, + { 80, 1, "cp850", "cp850_bin", "", "", 1, 1, NULL, NULL}, + { 81, 1, "cp852", "cp852_bin", "", "", 1, 1, NULL, NULL}, + { 82, 1, "swe7", "swe7_bin", "", "", 1, 1, NULL, NULL}, + { 93, 1, "geostd8", "geostd8_bin", "", "", 1, 1, NULL, NULL}, + { 83, 1, UTF8_MB3, UTF8_MB3"_bin", "UTF-8 Unicode", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 84, 1, "big5", "big5_bin", "", "", 1, 2, mysql_mbcharlen_big5, check_mb_big5}, + { 85, 1, "euckr", "euckr_bin", "", "", 1, 2, mysql_mbcharlen_euckr, check_mb_euckr}, + { 86, 1, "gb2312", "gb2312_bin", "", "", 1, 2, mysql_mbcharlen_gb2312, check_mb_gb2312}, + { 87, 1, "gbk", "gbk_bin", "", "", 1, 2, mysql_mbcharlen_gbk, check_mb_gbk}, + { 88, 1, "sjis", "sjis_bin", "", "", 1, 2, mysql_mbcharlen_sjis, check_mb_sjis}, + { 89, 1, "tis620", "tis620_bin", "", "", 1, 1, NULL, NULL}, + { 90, 1, "ucs2", "ucs2_bin", "UCS-2 Unicode", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 91, 1, "ujis", "ujis_bin", "", "", 1, 3, mysql_mbcharlen_ujis, check_mb_ujis}, + { 94, 1, "latin1", "latin1_spanish_ci", "", "", 1, 1, NULL, NULL}, + { 96, 1, "cp932", "cp932_bin", "", "", 1, 2, mysql_mbcharlen_cp932, check_mb_cp932}, + { 99, 1, "cp1250", "cp1250_polish_ci", "", "", 1, 1, NULL, NULL}, + { 98, 1, "eucjpms", "eucjpms_bin", "", "", 1, 3, mysql_mbcharlen_eucjpms, check_mb_eucjpms}, + { 128, 1, "ucs2", "ucs2_unicode_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 129, 1, "ucs2", "ucs2_icelandic_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 130, 1, "ucs2", "ucs2_latvian_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 131, 1, "ucs2", "ucs2_romanian_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 132, 1, "ucs2", "ucs2_slovenian_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 133, 1, "ucs2", "ucs2_polish_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 134, 1, "ucs2", "ucs2_estonian_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 135, 1, "ucs2", "ucs2_spanish_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 136, 1, "ucs2", "ucs2_swedish_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 137, 1, "ucs2", "ucs2_turkish_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 138, 1, "ucs2", "ucs2_czech_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 139, 1, "ucs2", "ucs2_danish_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 140, 1, "ucs2", "ucs2_lithunian_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 141, 1, "ucs2", "ucs2_slovak_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 142, 1, "ucs2", "ucs2_spanish2_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 143, 1, "ucs2", "ucs2_roman_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 144, 1, "ucs2", "ucs2_persian_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 145, 1, "ucs2", "ucs2_esperanto_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 146, 1, "ucs2", "ucs2_hungarian_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 147, 1, "ucs2", "ucs2_sinhala_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 149, 1, "ucs2", "ucs2_croatian_ci", "", "", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, /* MDB */ + + { 192, 1, UTF8_MB3, UTF8_MB3"_general_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 193, 1, UTF8_MB3, UTF8_MB3"_icelandic_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 194, 1, UTF8_MB3, UTF8_MB3"_latvian_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 195, 1, UTF8_MB3, UTF8_MB3"_romanian_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 196, 1, UTF8_MB3, UTF8_MB3"_slovenian_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 197, 1, UTF8_MB3, UTF8_MB3"_polish_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 198, 1, UTF8_MB3, UTF8_MB3"_estonian_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 119, 1, UTF8_MB3, UTF8_MB3"_spanish_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 200, 1, UTF8_MB3, UTF8_MB3"_swedish_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 201, 1, UTF8_MB3, UTF8_MB3"_turkish_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 202, 1, UTF8_MB3, UTF8_MB3"_czech_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 203, 1, UTF8_MB3, UTF8_MB3"_danish_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid }, + { 204, 1, UTF8_MB3, UTF8_MB3"_lithunian_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid }, + { 205, 1, UTF8_MB3, UTF8_MB3"_slovak_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 206, 1, UTF8_MB3, UTF8_MB3"_spanish2_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 207, 1, UTF8_MB3, UTF8_MB3"_roman_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 208, 1, UTF8_MB3, UTF8_MB3"_persian_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 209, 1, UTF8_MB3, UTF8_MB3"_esperanto_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 210, 1, UTF8_MB3, UTF8_MB3"_hungarian_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 211, 1, UTF8_MB3, UTF8_MB3"_sinhala_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 213, 1, UTF8_MB3, UTF8_MB3"_croatian_ci", "", "", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, /*MDB*/ + + { 224, 1, UTF8_MB4, UTF8_MB4"_unicode_ci", "", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 225, 1, UTF8_MB4, UTF8_MB4"_icelandic_ci", "", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 226, 1, UTF8_MB4, UTF8_MB4"_latvian_ci", "", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 227, 1, UTF8_MB4, UTF8_MB4"_romanian_ci", "", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 228, 1, UTF8_MB4, UTF8_MB4"_slovenian_ci", "", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 229, 1, UTF8_MB4, UTF8_MB4"_polish_ci", "", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 230, 1, UTF8_MB4, UTF8_MB4"_estonian_ci", "", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 231, 1, UTF8_MB4, UTF8_MB4"_spanish_ci", "", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 232, 1, UTF8_MB4, UTF8_MB4"_swedish_ci", "", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 233, 1, UTF8_MB4, UTF8_MB4"_turkish_ci", "", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 234, 1, UTF8_MB4, UTF8_MB4"_czech_ci", "", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 235, 1, UTF8_MB4, UTF8_MB4"_danish_ci", "", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 236, 1, UTF8_MB4, UTF8_MB4"_lithuanian_ci", "", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 237, 1, UTF8_MB4, UTF8_MB4"_slovak_ci", "", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 238, 1, UTF8_MB4, UTF8_MB4"_spanish2_ci", "", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 239, 1, UTF8_MB4, UTF8_MB4"_roman_ci", "", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 240, 1, UTF8_MB4, UTF8_MB4"_persian_ci", "", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 241, 1, UTF8_MB4, UTF8_MB4"_esperanto_ci", "", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 242, 1, UTF8_MB4, UTF8_MB4"_hungarian_ci", "", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 243, 1, UTF8_MB4, UTF8_MB4"_sinhala_ci", "", "", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + + { 254, 1, UTF8_MB3, UTF8_MB3"_general_cs", "", "", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 0, 0, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL} +}; +/* }}} */ + + +/* {{{ mysql_find_charset_nr */ +const CHARSET_INFO * mysql_find_charset_nr(unsigned int charsetnr) +{ + const CHARSET_INFO * c = compiled_charsets; + DBUG_ENTER("mysql_find_charset_nr"); + + do { + if (c->nr == charsetnr) { + DBUG_PRINT("info", ("found character set %d %s", c->nr, c->csname)); + DBUG_RETURN(c); + } + ++c; + } while (c[0].nr != 0); + DBUG_RETURN(NULL); +} +/* }}} */ + + +/* {{{ mysql_find_charset_name */ +CHARSET_INFO * mysql_find_charset_name(const char *name) +{ + CHARSET_INFO *c = (CHARSET_INFO *)compiled_charsets; + DBUG_ENTER("mysql_find_charset_nr"); + + do { + if (!strcasecmp(c->csname, name)) { + DBUG_PRINT("info", ("found character set %d %s", c->nr, c->csname)); + DBUG_RETURN(c); + } + ++c; + } while (c[0].nr != 0); + return NULL; +} +/* }}} */ + + +/* {{{ mysql_cset_escape_quotes */ +size_t mysql_cset_escape_quotes(const CHARSET_INFO *cset, char *newstr, + const char * escapestr, size_t escapestr_len ) +{ + const char *newstr_s = newstr; + const char *newstr_e = newstr + 2 * escapestr_len; + const char *end = escapestr + escapestr_len; + my_bool escape_overflow = FALSE; + + DBUG_ENTER("mysql_cset_escape_quotes"); + + for (;escapestr < end; escapestr++) { + unsigned int len = 0; + /* check unicode characters */ + + if (cset->char_maxlen > 1 && (len = cset->mb_valid(escapestr, end))) { + + /* check possible overflow */ + if ((newstr + len) > newstr_e) { + escape_overflow = TRUE; + break; + } + /* copy mb char without escaping it */ + while (len--) { + *newstr++ = *escapestr++; + } + escapestr--; + continue; + } + if (*escapestr == '\'') { + if (newstr + 2 > newstr_e) { + escape_overflow = TRUE; + break; + } + *newstr++ = '\''; + *newstr++ = '\''; + } else { + if (newstr + 1 > newstr_e) { + escape_overflow = TRUE; + break; + } + *newstr++ = *escapestr; + } + } + *newstr = '\0'; + + if (escape_overflow) { + DBUG_RETURN((size_t)~0); + } + DBUG_RETURN((size_t)(newstr - newstr_s)); +} +/* }}} */ + + +/* {{{ mysql_cset_escape_slashes */ +size_t mysql_cset_escape_slashes(const CHARSET_INFO * cset, char *newstr, + const char * escapestr, size_t escapestr_len ) +{ + const char *newstr_s = newstr; + const char *newstr_e = newstr + 2 * escapestr_len; + const char *end = escapestr + escapestr_len; + my_bool escape_overflow = FALSE; + + DBUG_ENTER("mysql_cset_escape_slashes"); + DBUG_PRINT("info", ("charset=%s", cset->name)); + + for (;escapestr < end; escapestr++) { + char esc = '\0'; + unsigned int len = 0; + + /* check unicode characters */ + if (cset->char_maxlen > 1 && (len = cset->mb_valid(escapestr, end))) { + /* check possible overflow */ + if ((newstr + len) > newstr_e) { + escape_overflow = TRUE; + break; + } + /* copy mb char without escaping it */ + while (len--) { + *newstr++ = *escapestr++; + } + escapestr--; + continue; + } + if (cset->char_maxlen > 1 && cset->mb_charlen(*escapestr) > 1) { + esc = *escapestr; + } else { + switch (*escapestr) { + case 0: + esc = '0'; + break; + case '\n': + esc = 'n'; + break; + case '\r': + esc = 'r'; + break; + case '\\': + case '\'': + case '"': + esc = *escapestr; + break; + case '\032': + esc = 'Z'; + break; + } + } + if (esc) { + if (newstr + 2 > newstr_e) { + escape_overflow = TRUE; + break; + } + /* copy escaped character */ + *newstr++ = '\\'; + *newstr++ = esc; + } else { + if (newstr + 1 > newstr_e) { + escape_overflow = TRUE; + break; + } + /* copy non escaped character */ + *newstr++ = *escapestr; + } + } + *newstr = '\0'; + + if (escape_overflow) { + DBUG_RETURN((size_t)~0); + } + DBUG_RETURN((size_t)(newstr - newstr_s)); +} +/* }}} */ diff --git a/libmysql/my_create.c b/libmysql/my_create.c index 5a10b0fd8..fe4555838 100644 --- a/libmysql/my_create.c +++ b/libmysql/my_create.c @@ -20,7 +20,7 @@ #include #include "mysys_err.h" #include -#if defined(MSDOS) || defined(__WIN__) || defined(__EMX__) || defined(OS2) +#if defined(MSDOS) || defined(_WIN32) || defined(__EMX__) || defined(OS2) #include #endif @@ -48,7 +48,7 @@ File my_create(const char *FileName, int CreateFlags, int access_flags, #elif defined(VMS) fd = open((my_string) FileName, access_flags | O_CREAT, 0, "ctx=stm","ctx=bin"); -#elif defined(MSDOS) || defined(__WIN__) || defined(__EMX__) || defined(OS2) +#elif defined(MSDOS) || defined(_WIN32) || defined(__EMX__) || defined(OS2) if (access_flags & O_SHARE) fd = sopen((my_string) FileName, access_flags | O_CREAT | O_BINARY, SH_DENYNO, MY_S_IREAD | MY_S_IWRITE); diff --git a/libmysql/my_gethostbyname.c b/libmysql/my_gethostbyname.c index ffbfc424d..7938fe978 100644 --- a/libmysql/my_gethostbyname.c +++ b/libmysql/my_gethostbyname.c @@ -19,7 +19,7 @@ #include "mysys_priv.h" #include -#if !defined(MSDOS) && !defined(__WIN__) +#if !defined(MSDOS) && !defined(_WIN32) #include #endif #include diff --git a/libmysql/my_getwd.c b/libmysql/my_getwd.c index 6bdea813f..8f4db13e5 100644 --- a/libmysql/my_getwd.c +++ b/libmysql/my_getwd.c @@ -23,7 +23,7 @@ #ifdef HAVE_GETWD #include #endif -#if defined(MSDOS) || defined(__WIN__) +#if defined(MSDOS) || defined(_WIN32) #include #include #include diff --git a/libmysql/my_init.c b/libmysql/my_init.c index 2151897d8..af96352d6 100644 --- a/libmysql/my_init.c +++ b/libmysql/my_init.c @@ -30,7 +30,7 @@ #include #include #endif -#ifdef __WIN__ +#ifdef _WIN32 #ifdef _MSC_VER #include #include @@ -72,7 +72,7 @@ void my_init(void) pthread_init(); /* Must be called before DBUG_ENTER */ #endif my_thread_global_init(); -#if !defined( __WIN__) && !defined(OS2) +#ifndef _WIN32 sigfillset(&my_signals); /* signals blocked by mf_brkhant */ #endif #endif /* THREAD */ @@ -100,7 +100,7 @@ void my_init(void) #endif DBUG_PRINT("exit",("home: '%s'",home_dir)); } -#ifdef __WIN__ +#ifdef _WIN32 win32_init_tcp_ip(); #endif DBUG_VOID_RETURN; @@ -145,12 +145,12 @@ Voluntary context switches %ld, Involuntary context switches %ld\n", rus.ru_msgsnd, rus.ru_msgrcv, rus.ru_nsignals, rus.ru_nvcsw, rus.ru_nivcsw); #endif -#if defined(MSDOS) && !defined(__WIN__) +#if defined(MSDOS) && !defined(_WIN32) fprintf(info_file,"\nRun time: %.1f\n",(double) clock()/CLOCKS_PER_SEC); #endif #if defined(SAFEMALLOC) TERMINATE(stderr); /* Give statistic on screen */ -#elif defined(__WIN__) && defined(_MSC_VER) +#elif defined(_WIN32) && defined(_MSC_VER) _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE ); _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDERR ); _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE ); @@ -169,14 +169,14 @@ Voluntary context switches %ld, Involuntary context switches %ld\n", my_thread_end(); my_thread_global_end(); #endif -#ifdef __WIN__ +#ifdef _WIN32 if (have_tcpip); WSACleanup( ); -#endif /* __WIN__ */ +#endif /* _WIN32 */ my_init_done=0; } /* my_end */ -#ifdef __WIN__ +#ifdef _WIN32 /* This code is specially for running MySQL, but it should work in diff --git a/libmysql/my_lib.c b/libmysql/my_lib.c index 8181cfff3..e3566bf38 100644 --- a/libmysql/my_lib.c +++ b/libmysql/my_lib.c @@ -40,7 +40,7 @@ # if defined(HAVE_NDIR_H) # include # endif -# if defined(MSDOS) || defined(__WIN__) +# if defined(MSDOS) || defined(_WIN32) # include # ifdef __BORLANDC__ # include @@ -88,7 +88,7 @@ static int comp_names(struct fileinfo *a, struct fileinfo *b) } /* comp_names */ -#if !defined(MSDOS) && !defined(__WIN__) +#if !defined(MSDOS) && !defined(_WIN32) MY_DIR *my_dir(const char *path, myf MyFlags) { @@ -336,7 +336,7 @@ my_string directory_file_name (my_string dst, const char *src) #endif /* VMS */ } /* directory_file_name */ -#elif defined(__WIN__) +#elif defined(_WIN32) /* ***************************************************************************** diff --git a/libmysql/my_loaddata.c b/libmysql/my_loaddata.c new file mode 100644 index 000000000..036ec983e --- /dev/null +++ b/libmysql/my_loaddata.c @@ -0,0 +1,255 @@ +/************************************************************************************ + Copyright (C) 2000, 2011 MySQL AB & MySQL Finland AB & TCX DataKonsult AB, + Monty Program AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + Part of this code includes code from the PHP project which + is freely available from http://www.php.net +*************************************************************************************/ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 2006-2011 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Georg Richter | + | Andrey Hristov | + | Ulf Wendel | + +----------------------------------------------------------------------+ +*/ + +#include "my_global.h" +#include +#include +#include +#include "errmsg.h" +#include "mysql.h" +#include + +typedef struct st_mysql_infile_info +{ + int fd; + int error_no; + char error_msg[MYSQL_ERRMSG_SIZE + 1]; + const char *filename; +} MYSQL_INFILE_INFO; + +/* {{{ mysql_local_infile_init */ +static +int mysql_local_infile_init(void **ptr, const char *filename, void *userdata) +{ + MYSQL_INFILE_INFO *info; + + DBUG_ENTER("mysql_local_infile_init"); + + info = (MYSQL_INFILE_INFO *)my_malloc(sizeof(MYSQL_INFILE_INFO), MYF(MY_ZEROFILL)); + if (!info) { + DBUG_RETURN(1); + } + + *ptr = info; + + info->filename = filename; + info->fd = my_open(info->filename, O_RDONLY, MYF(0)); + + if (info->fd < 0) + { + my_snprintf((char *)info->error_msg, sizeof(info->error_msg), + "Can't open file '%-.64s'.", filename); + info->error_no = EE_FILENOTFOUND; + DBUG_RETURN(1); + } + DBUG_RETURN(0); +} +/* }}} */ + + +/* {{{ mysql_local_infile_read */ +static +int mysql_local_infile_read(void *ptr, char * buf, unsigned int buf_len) +{ + MYSQL_INFILE_INFO *info = (MYSQL_INFILE_INFO *)ptr; + int count; + + DBUG_ENTER("mysql_local_infile_read"); + + count= my_read(info->fd, buf, buf_len, MYF(0)); + + if (count < 0) + { + strcpy(info->error_msg, "Error reading file"); + info->error_no = EE_READ; + } + DBUG_RETURN(count); +} +/* }}} */ + + +/* {{{ mysql_local_infile_error */ +static +int mysql_local_infile_error(void *ptr, char *error_buf, unsigned int error_buf_len) +{ + MYSQL_INFILE_INFO *info = (MYSQL_INFILE_INFO *)ptr; + + DBUG_ENTER("mysql_local_infile_error"); + + if (info) { + strncpy(error_buf, info->error_msg, error_buf_len); + DBUG_RETURN(info->error_no); + } + + strncpy(error_buf, "Unknown error", error_buf_len); + DBUG_RETURN(CR_UNKNOWN_ERROR); +} +/* }}} */ + + +/* {{{ mysql_local_infile_end */ +static +void mysql_local_infile_end(void *ptr) +{ + MYSQL_INFILE_INFO *info = (MYSQL_INFILE_INFO *)ptr; + + DBUG_ENTER("mysql_local_infile_end"); + + if (info) + { + if (info->fd) + { + my_close(info->fd, MYF(0)); + info->fd= 0; + } + my_free(ptr, MYF(0)); + } + DBUG_VOID_RETURN; +} +/* }}} */ + + +/* {{{ mysql_local_infile_default */ +void mysql_set_local_infile_default(MYSQL *conn) +{ + DBUG_ENTER("mysql_local_infile_default"); + conn->options.local_infile_init = mysql_local_infile_init; + conn->options.local_infile_read = mysql_local_infile_read; + conn->options.local_infile_error = mysql_local_infile_error; + conn->options.local_infile_end = mysql_local_infile_end; + DBUG_VOID_RETURN; +} +/* }}} */ + +/* {{{ mysql_set_local_infile_handler */ +void STDCALL mysql_set_local_infile_handler(MYSQL *conn, + int (*local_infile_init)(void **, const char *, void *), + int (*local_infile_read)(void *, char *, uint), + void (*local_infile_end)(void *), + int (*local_infile_error)(void *, char *, uint), + void *userdata) +{ + DBUG_ENTER("mysql_set_local_infile_handler"); + conn->options.local_infile_init= local_infile_init; + conn->options.local_infile_read= local_infile_read; + conn->options.local_infile_end= local_infile_end; + conn->options.local_infile_error= local_infile_error; + conn->options.local_infile_userdata = userdata; + DBUG_VOID_RETURN; +} +/* }}} */ + +/* {{{ mysql_handle_local_infile */ +my_bool mysql_handle_local_infile(MYSQL *conn, const char *filename) +{ + unsigned int buflen= 4096; + unsigned int bufread; + unsigned char *buf= NULL; + void *info= NULL; + my_bool result= 1; + + DBUG_ENTER("mysql_handle_local_infile"); + + if (!(conn->options.client_flag & CLIENT_LOCAL_FILES)) { + my_set_error(conn, CR_UNKNOWN_ERROR, SQLSTATE_UNKNOWN, "Load data local infile forbidden"); + /* write empty packet to server */ + my_net_write(&conn->net, "", 0); + net_flush(&conn->net); + goto infile_error; + } + + /* check if all callback functions exist */ + if (!conn->options.local_infile_init || !conn->options.local_infile_end || + !conn->options.local_infile_read || !conn->options.local_infile_error) + mysql_set_local_infile_default(conn); + + /* allocate buffer for reading data */ + buf = (uchar *)my_malloc(buflen, MYF(0)); + + /* init handler: allocate read buffer and open file */ + if (conn->options.local_infile_init(&info, filename, + conn->options.local_infile_userdata)) + { + char tmp_buf[MYSQL_ERRMSG_SIZE]; + int tmp_errno; + + tmp_errno= conn->options.local_infile_error(info, tmp_buf, sizeof(tmp_buf)); + my_set_error(conn, tmp_errno, SQLSTATE_UNKNOWN, tmp_buf); + my_net_write(&conn->net, "", 0); + net_flush(&conn->net); + goto infile_error; + } + + /* read data */ + while ((bufread= conn->options.local_infile_read(info, (char *)buf, buflen)) > 0) + { + if (my_net_write(&conn->net, (char *)buf, bufread)) + { + my_set_error(conn, CR_SERVER_LOST, SQLSTATE_UNKNOWN, NULL); + goto infile_error; + } + } + + /* send empty packet for eof */ + if (my_net_write(&conn->net, "", 0) || net_flush(&conn->net)) + { + my_set_error(conn, CR_SERVER_LOST, SQLSTATE_UNKNOWN, NULL); + goto infile_error; + } + + /* error during read occured */ + if (bufread < 0) + { + char tmp_buf[MYSQL_ERRMSG_SIZE]; + int tmp_errno= conn->options.local_infile_error(info, tmp_buf, sizeof(tmp_buf)); + my_set_error(conn, tmp_errno, SQLSTATE_UNKNOWN, tmp_buf); + goto infile_error; + } + + result = 0; + +infile_error: + conn->options.local_infile_end(info); + my_free((char *)buf, MYF(0)); + DBUG_RETURN(result); +} +/* }}} */ diff --git a/libmysql/my_malloc.c b/libmysql/my_malloc.c index 1382712c0..37ee60c6c 100644 --- a/libmysql/my_malloc.c +++ b/libmysql/my_malloc.c @@ -25,7 +25,7 @@ /* My memory allocator */ -gptr my_malloc(unsigned int Size, myf MyFlags) +gptr my_malloc(size_t Size, myf MyFlags) { gptr point; DBUG_ENTER("my_malloc"); @@ -65,7 +65,7 @@ void my_no_flags_free(gptr ptr) /* malloc and copy */ -gptr my_memdup(const byte *from, uint length, myf MyFlags) +gptr my_memdup(const byte *from, size_t length, myf MyFlags) { gptr ptr; if ((ptr=my_malloc(length,MyFlags)) != 0) diff --git a/libmysql/my_net.c b/libmysql/my_net.c index 575c843f2..2e6fa03b2 100644 --- a/libmysql/my_net.c +++ b/libmysql/my_net.c @@ -21,7 +21,7 @@ #include /* for thread safe my_inet_ntoa */ -#if !defined(MSDOS) && !defined(__WIN__) +#if !defined(MSDOS) && !defined(_WIN32) #include #ifdef HAVE_SYS_SOCKET_H #include @@ -32,7 +32,7 @@ #ifdef HAVE_ARPA_INET_H #include #endif -#endif /* !defined(MSDOS) && !defined(__WIN__) */ +#endif /* !defined(MSDOS) && !defined(_WIN32) */ void my_inet_ntoa(struct in_addr in, char *buf) { diff --git a/libmysql/my_once.c b/libmysql/my_once.c index 0b8b5addc..15ce18e16 100644 --- a/libmysql/my_once.c +++ b/libmysql/my_once.c @@ -30,7 +30,7 @@ gptr my_once_alloc(unsigned int Size, myf MyFlags) { - uint get_size,max_left; + size_t get_size,max_left; gptr point; reg1 USED_MEM *next; reg2 USED_MEM **prev; diff --git a/libmysql/my_open.c b/libmysql/my_open.c index 748113528..c21d7b31c 100644 --- a/libmysql/my_open.c +++ b/libmysql/my_open.c @@ -20,7 +20,7 @@ #include "mysys_err.h" #include #include -#if defined(MSDOS) || defined(__WIN__) || defined(__EMX__) || defined(OS2) +#if defined(MSDOS) || defined(_WIN32) || defined(__EMX__) || defined(OS2) #include #endif @@ -35,7 +35,7 @@ File my_open(const char *FileName, int Flags, myf MyFlags) DBUG_ENTER("my_open"); DBUG_PRINT("my",("Name: '%s' Flags: %d MyFlags: %d", FileName, Flags, MyFlags)); -#if defined(MSDOS) || defined(__WIN__) || defined(__EMX__) || defined(OS2) +#if defined(MSDOS) || defined(_WIN32) || defined(__EMX__) || defined(OS2) if (Flags & O_SHARE) fd = sopen((my_string) FileName, (Flags & ~O_SHARE) | O_BINARY, SH_DENYNO, MY_S_IREAD | MY_S_IWRITE); diff --git a/libmysql/my_pread.c b/libmysql/my_pread.c deleted file mode 100644 index 5c7d0be58..000000000 --- a/libmysql/my_pread.c +++ /dev/null @@ -1,146 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include "mysys_err.h" -#include -#ifdef HAVE_PREAD -#include -#endif - - /* Read a chunk of bytes from a file */ - -uint my_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset, - myf MyFlags) -{ - uint readbytes; - int error; - DBUG_ENTER("my_pread"); - DBUG_PRINT("my",("Fd: %d Seek: %lu Buffer: %lx Count: %u MyFlags: %d", - Filedes, (ulong) offset, Buffer, Count, MyFlags)); - - for (;;) - { -#ifndef __WIN__ - errno=0; /* Linux doesn't reset this */ -#endif -#ifndef HAVE_PREAD - pthread_mutex_lock(&my_file_info[Filedes].mutex); - readbytes= (uint) -1; - error= (lseek(Filedes, offset, MY_SEEK_SET) == -1L || - (readbytes = (uint) read(Filedes, Buffer, Count)) != Count); - pthread_mutex_unlock(&my_file_info[Filedes].mutex); -#else - error=((readbytes = (uint) pread(Filedes, Buffer, Count, offset)) != Count); -#endif - if (error) - { - my_errno=errno; - DBUG_PRINT("warning",("Read only %ld bytes off %ld from %d, errno: %d", - readbytes,Count,Filedes,my_errno)); -#ifdef THREAD - if (readbytes == 0 && errno == EINTR) - continue; /* Interrupted */ -#endif - if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) - { - if ((int) readbytes == -1) - my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG), - my_filename(Filedes),my_errno); - else if (MyFlags & (MY_NABP | MY_FNABP)) - my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), - my_filename(Filedes),my_errno); - } - if ((int) readbytes == -1 || (MyFlags & (MY_FNABP | MY_NABP))) - DBUG_RETURN(MY_FILE_ERROR); /* Return with error */ - } - if (MyFlags & (MY_NABP | MY_FNABP)) - DBUG_RETURN(0); /* Read went ok; Return 0 */ - DBUG_RETURN(readbytes); /* purecov: inspected */ - } -} /* my_pread */ - - - /* Write a chunk of bytes to a file */ - -uint my_pwrite(int Filedes, const byte *Buffer, uint Count, my_off_t offset, - myf MyFlags) -{ - uint writenbytes,errors; - ulong written; - DBUG_ENTER("my_pwrite"); - DBUG_PRINT("my",("Fd: %d Seek: %lu Buffer: %lx Count: %d MyFlags: %d", - Filedes, (ulong) offset,Buffer, Count, MyFlags)); - errors=0; written=0L; - - for (;;) - { -#ifndef HAVE_PREAD - int error; - writenbytes= (uint) -1; - pthread_mutex_lock(&my_file_info[Filedes].mutex); - error=(lseek(Filedes, offset, MY_SEEK_SET) != -1L && - (writenbytes = (uint) write(Filedes, Buffer, Count)) == Count); - pthread_mutex_unlock(&my_file_info[Filedes].mutex); - if (error) - break; -#else - if ((writenbytes = (uint) pwrite(Filedes, Buffer, Count,offset)) == Count) - break; -#endif - if ((int) writenbytes != -1) - { /* Safegueard */ - written+=writenbytes; - Buffer+=writenbytes; - Count-=writenbytes; - offset+=writenbytes; - } - my_errno=errno; - DBUG_PRINT("error",("Write only %d bytes",writenbytes)); -#ifndef NO_BACKGROUND -#ifdef THREAD - if (my_thread_var->abort) - MyFlags&= ~ MY_WAIT_IF_FULL; /* End if aborted by user */ -#endif - if (my_errno == ENOSPC && (MyFlags & MY_WAIT_IF_FULL)) - { - if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE)) - my_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH), - my_filename(Filedes)); - VOID(sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC)); - continue; - } - if ((writenbytes == 0 && my_errno == EINTR) || - (writenbytes > 0 && (uint) writenbytes != (uint) -1)) - continue; /* Retry */ -#endif - if (MyFlags & (MY_NABP | MY_FNABP)) - { - if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) - { - my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG), - my_filename(Filedes),my_errno); - } - DBUG_RETURN(MY_FILE_ERROR); /* Error on read */ - } - else - break; /* Return bytes written */ - } - if (MyFlags & (MY_NABP | MY_FNABP)) - DBUG_RETURN(0); /* Want only errors */ - DBUG_RETURN(writenbytes+written); /* purecov: inspected */ -} /* my_write */ diff --git a/libmysql/my_pthread.c b/libmysql/my_pthread.c index ecd3631f5..fd8dcd336 100644 --- a/libmysql/my_pthread.c +++ b/libmysql/my_pthread.c @@ -26,6 +26,49 @@ #include #include +#ifdef _WIN32 + +int +pthread_cond_init (pthread_cond_t *cv, const pthread_condattr_t *attr) +{ + DBUG_ENTER("pthread_cond_init"); + /* Initialize the count to 0 */ + cv->waiting = 0; + + /* Create an auto-reset and manual-reset event */ + if (!(cv->events[SIGNAL] = CreateEvent (NULL, FALSE, FALSE, NULL)) || + !(cv->events[BROADCAST] = CreateEvent (NULL, TRUE, FALSE, NULL))) + { + DBUG_RETURN(GetLastError()); + } + DBUG_RETURN(0); +} + +int pthread_cond_timedwait(pthread_cond_t *cond, + pthread_mutex_t *mutex, + struct timespec *abstime) +{ + int result= 0; + return result == WAIT_TIMEOUT ? ETIMEDOUT : 0; +} + +int pthread_cond_wait(pthread_cond_t *cv, pthread_mutex_t *mutex) +{ + return pthread_cond_timedwait(cv,mutex,NULL); +} + +int pthread_cond_destroy(pthread_cond_t *cv) +{ + DeleteCriticalSection(&cv->waiters_count_lock); + + if (CloseHandle(cv->events[SIGNAL]) == 0 || + CloseHandle(cv->events[BROADCAST]) == 0) + return EINVAL; + return 0; +} + +#endif + #if (defined(__BSD__) || defined(_BSDI_VERSION)) && !defined(HAVE_mit_thread) #define SCHED_POLICY SCHED_RR #else @@ -144,7 +187,7 @@ struct tm *localtime_r(const time_t *clock, struct tm *res) ** Author: Gary Wisniewski , much modified by Monty ****************************************************************************/ -#if !defined(HAVE_SIGWAIT) && !defined(HAVE_mit_thread) && !defined(sigwait) && !defined(__WIN__) && !defined(HAVE_rts_threads) && !defined(HAVE_NONPOSIX_SIGWAIT) && !defined(HAVE_DEC_3_2_THREADS) && !defined(OS2) +#if !defined(HAVE_SIGWAIT) && !defined(HAVE_mit_thread) && !defined(sigwait) && !defined(_WIN32) && !defined(HAVE_rts_threads) && !defined(HAVE_NONPOSIX_SIGWAIT) && !defined(HAVE_DEC_3_2_THREADS) && !defined(OS2) #if !defined(DONT_USE_SIGSUSPEND) diff --git a/libmysql/my_realloc.c b/libmysql/my_realloc.c index 7ab75d476..8fede1fd6 100644 --- a/libmysql/my_realloc.c +++ b/libmysql/my_realloc.c @@ -24,7 +24,7 @@ /* My memory re allocator */ -gptr my_realloc(gptr oldpoint, uint Size, myf MyFlags) +gptr my_realloc(gptr oldpoint, size_t Size, myf MyFlags) { gptr point; DBUG_ENTER("my_realloc"); diff --git a/libmysql/my_static.c b/libmysql/my_static.c index 72bf7207e..949d5d167 100644 --- a/libmysql/my_static.c +++ b/libmysql/my_static.c @@ -70,8 +70,8 @@ uint sf_malloc_prehunc=0, /* If you have problem with core- */ sf_malloc_endhunc=0, /* dump when malloc-message.... */ /* set theese to 64 or 128 */ sf_malloc_quick=0; /* set if no calls to sanity */ -long lCurMemory = 0L; /* Current memory usage */ -long lMaxMemory = 0L; /* Maximum memory usage */ +size_t lCurMemory = 0L; /* Current memory usage */ +size_t lMaxMemory = 0L; /* Maximum memory usage */ uint cNewCount = 0; /* Number of times NEW() was called */ byte *sf_min_adress= (byte*) ~(unsigned long) 0L, *sf_max_adress= (byte*) 0L; diff --git a/libmysql/mysql_stmt.c b/libmysql/my_stmt.c similarity index 64% rename from libmysql/mysql_stmt.c rename to libmysql/my_stmt.c index 0efe74602..0b27f3e99 100644 --- a/libmysql/mysql_stmt.c +++ b/libmysql/my_stmt.c @@ -17,13 +17,29 @@ 51 Franklin St., Fifth Floor, Boston, MA 02110, USA *****************************************************************************/ -/* The implementation for preoared statements was ported from PHP's mysqlnd - extension, written by Andrey Hristov, Georg Richter and Ulf Wendel */ +/* The implementation for prepared statements was ported from PHP's mysqlnd + extension, written by Andrey Hristov, Georg Richter and Ulf Wendel + + Original file header: + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 2006-2011 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Georg Richter | + | Andrey Hristov | + | Ulf Wendel | + +----------------------------------------------------------------------+ +*/ -#ifdef __WIN__ -#include -#include -#endif #include "my_global.h" #include #include @@ -44,33 +60,33 @@ static my_bool is_null= 1; const char * const mysql_stmt_not_prepared = "Statement not prepared"; - my_bool is_supported_buffer_type(enum enum_field_types type) { switch (type) { - case MYSQL_TYPE_TINY: - case MYSQL_TYPE_NULL: - case MYSQL_TYPE_SHORT: - case MYSQL_TYPE_YEAR: + case MYSQL_TYPE_BIT: + case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_DATE: + case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_DECIMAL: + case MYSQL_TYPE_DOUBLE: + case MYSQL_TYPE_FLOAT: + case MYSQL_TYPE_GEOMETRY: case MYSQL_TYPE_INT24: case MYSQL_TYPE_LONG: + case MYSQL_TYPE_LONG_BLOB: case MYSQL_TYPE_LONGLONG: - case MYSQL_TYPE_FLOAT: - case MYSQL_TYPE_DOUBLE: + case MYSQL_TYPE_MEDIUM_BLOB: + case MYSQL_TYPE_NEWDATE: + case MYSQL_TYPE_NEWDECIMAL: + case MYSQL_TYPE_NULL: + case MYSQL_TYPE_SHORT: + case MYSQL_TYPE_STRING: case MYSQL_TYPE_TIME: - case MYSQL_TYPE_DATE: - case MYSQL_TYPE_DATETIME: case MYSQL_TYPE_TIMESTAMP: + case MYSQL_TYPE_TINY: case MYSQL_TYPE_TINY_BLOB: - case MYSQL_TYPE_MEDIUM_BLOB: - case MYSQL_TYPE_LONG_BLOB: - case MYSQL_TYPE_BLOB: - case MYSQL_TYPE_BIT: case MYSQL_TYPE_VAR_STRING: - case MYSQL_TYPE_STRING: - case MYSQL_TYPE_DECIMAL: - case MYSQL_TYPE_NEWDECIMAL: - case MYSQL_TYPE_NEWDATE: + case MYSQL_TYPE_YEAR: return 1; break; default: @@ -91,28 +107,26 @@ static int stmt_unbuffered_fetch(MYSQL_STMT *stmt, uchar **row) DBUG_ENTER("stmt_unbuffered_fetch"); - pkt_len= net_safe_read(stmt->conn); + pkt_len= net_safe_read(stmt->mysql); DBUG_PRINT("info",("packet_length= %ld",pkt_len)); if (pkt_len == packet_error) { stmt->fetch_row_func= stmt_unbuffered_eof; - DBUG_RETURN(MYSQL_NO_DATA); + DBUG_RETURN(1); } - if (stmt->conn->net.read_pos[0] == 254) + if (stmt->mysql->net.read_pos[0] == 254) { *row = NULL; stmt->fetch_row_func= stmt_unbuffered_eof; DBUG_RETURN(MYSQL_NO_DATA); } else - *row = stmt->conn->net.read_pos; - return 0; + *row = stmt->mysql->net.read_pos; + DBUG_RETURN(0); } - - static int stmt_buffered_fetch(MYSQL_STMT *stmt, uchar **row) { if (!stmt->result_cursor) @@ -139,15 +153,15 @@ static int stmt_read_all_rows(MYSQL_STMT *stmt) pprevious= &result->data; - while ((packet_len = net_safe_read(stmt->conn)) != packet_error) + while ((packet_len = net_safe_read(stmt->mysql)) != packet_error) { - p= stmt->conn->net.read_pos; + p= stmt->mysql->net.read_pos; if (packet_len > 7 || p[0] != 254) { /* allocate space for rows */ if (!(current= (MYSQL_ROWS *)alloc_root(&result->alloc, sizeof(MYSQL_ROWS) + packet_len))) { - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); } current->data= (MYSQL_ROW)(current + 1); @@ -161,7 +175,7 @@ static int stmt_read_all_rows(MYSQL_STMT *stmt) { uchar *null_ptr, bit_offset= 4; uchar *cp= p; - int i; + uint i; cp++; /* skip first byte */ null_ptr= cp; @@ -175,13 +189,15 @@ static int stmt_read_all_rows(MYSQL_STMT *stmt) case -1: { size_t len= net_field_length(&cp); + cp+= len; if (len > stmt->fields[i].max_length) - stmt->fields[i].max_length= len; + stmt->fields[i].max_length= (ulong)len; } break; default: if (!stmt->fields[i].max_length) stmt->fields[i].max_length= mysql_ps_fetch_functions[stmt->fields[i].type].max_len; + cp+= mysql_ps_fetch_functions[stmt->fields[i].type].pack_len; break; } } @@ -201,16 +217,16 @@ static int stmt_read_all_rows(MYSQL_STMT *stmt) *pprevious= 0; /* sace status info */ p++; - stmt->upsert_status.warning_count= stmt->conn->warning_count= uint2korr(p); + stmt->upsert_status.warning_count= stmt->mysql->warning_count= uint2korr(p); p+=2; - stmt->conn->server_status= uint2korr(p); + stmt->mysql->server_status= uint2korr(p); stmt->result_cursor= result->data; DBUG_RETURN(0); } } stmt->result_cursor= 0; - SET_CLIENT_STMT_ERROR(stmt->error_info, stmt->conn->net.last_errno, stmt->conn->net.sqlstate, - stmt->conn->net.last_error); + SET_CLIENT_STMT_ERROR(stmt, stmt->mysql->net.last_errno, stmt->mysql->net.sqlstate, + stmt->mysql->net.last_error); DBUG_RETURN(1); } @@ -223,7 +239,7 @@ static int stmt_cursor_fetch(MYSQL_STMT *stmt, uchar **row) if (stmt->state < MYSQL_STMT_USE_OR_STORE_CALLED) { - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); } @@ -234,7 +250,7 @@ static int stmt_cursor_fetch(MYSQL_STMT *stmt, uchar **row) int4store(buf, stmt->stmt_id); int4store(buf + STMT_ID_LENGTH, stmt->prefetch_rows); - if (simple_command(stmt->conn, MYSQL_COM_STMT_FETCH, (char *)buf, sizeof(buf), 1)) + if (simple_command(stmt->mysql, MYSQL_COM_STMT_FETCH, (char *)buf, sizeof(buf), 1)) DBUG_RETURN(1); /* free previously allocated buffer */ @@ -251,21 +267,21 @@ static int stmt_cursor_fetch(MYSQL_STMT *stmt, uchar **row) static void stmt_flush_unbuffered(MYSQL_STMT *stmt) { ulong packet_len; - while ((packet_len = net_safe_read(stmt->conn)) != packet_error) - if (packet_len < 8 || stmt->conn->net.read_pos[0] == 254) + while ((packet_len = net_safe_read(stmt->mysql)) != packet_error) + if (packet_len < 8 && stmt->mysql->net.read_pos[0] == 254) return; } static int stmt_fetch_to_bind(MYSQL_STMT *stmt, unsigned char *row) { - int i; + uint i; size_t truncations= 0; unsigned char *null_ptr, bit_offset= 4; - DBUG_ENTER("stmt_fetch-to_bind"); + DBUG_ENTER("stmt_fetch_to_bind"); if (!stmt->bind_result_done) /* nothing to do */ - return 0; + DBUG_RETURN(0); row++; /* skip status byte */ null_ptr= row; @@ -276,18 +292,19 @@ static int stmt_fetch_to_bind(MYSQL_STMT *stmt, unsigned char *row) /* save row position for fetching values in pieces */ if (*null_ptr & bit_offset) { - *stmt->result_bind[i].is_null= 1; - stmt->result_bind[i].row_ptr= NULL; + *stmt->bind[i].is_null= 1; + stmt->bind[i].row_ptr= NULL; } else { - if (!stmt->result_bind[i].length) - stmt->result_bind[i].length= &stmt->result_bind[i].length_value; - if (!stmt->result_bind[i].is_null) - stmt->result_bind[i].is_null= &stmt->result_bind[i].is_null_value; - *stmt->result_bind[i].is_null= 0; - stmt->result_bind[i].row_ptr= row; - mysql_ps_fetch_functions[stmt->fields[i].type].func(&stmt->result_bind[i], &stmt->fields[i], &row); - truncations+= *stmt->result_bind[i].error; + if (!stmt->bind[i].length) + stmt->bind[i].length= &stmt->bind[i].length_value; + if (!stmt->bind[i].is_null) + stmt->bind[i].is_null= &stmt->bind[i].is_null_value; + *stmt->bind[i].is_null= 0; + stmt->bind[i].row_ptr= row; + mysql_ps_fetch_functions[stmt->fields[i].type].func(&stmt->bind[i], &stmt->fields[i], &row); + if (stmt->mysql->options.report_data_truncation) + truncations+= *stmt->bind[i].error; } if (!((bit_offset <<=1) & 255)) { @@ -295,12 +312,12 @@ static int stmt_fetch_to_bind(MYSQL_STMT *stmt, unsigned char *row) null_ptr++; } } - return (truncations) ? MYSQL_DATA_TRUNCATED : 0; + DBUG_RETURN((truncations) ? MYSQL_DATA_TRUNCATED : 0); } MYSQL_RES *_mysql_stmt_use_result(MYSQL_STMT *stmt) { - MYSQL *mysql= stmt->conn; + MYSQL *mysql= stmt->mysql; DBUG_ENTER("mysql_stmt_use_result"); @@ -313,7 +330,7 @@ MYSQL_RES *_mysql_stmt_use_result(MYSQL_STMT *stmt) DBUG_RETURN(NULL); } - CLEAR_CLIENT_STMT_ERROR(stmt->error_info); + CLEAR_CLIENT_STMT_ERROR(stmt); stmt->state = MYSQL_STMT_USE_OR_STORE_CALLED; if (!stmt->cursor_exists) @@ -349,31 +366,33 @@ unsigned char *mysql_net_store_length(unsigned char *packet, my_ulonglong length int store_param(MYSQL_STMT *stmt, int column, unsigned char **p) { - switch (stmt->param_bind[column].buffer_type) { + DBUG_ENTER("store_param"); + DBUG_PRINT("info", ("column: %d type: x%x", column, stmt->params[column].buffer_type)); + switch (stmt->params[column].buffer_type) { case MYSQL_TYPE_TINY: - int1store(*p, *(uchar *)stmt->param_bind[column].buffer); + int1store(*p, *(uchar *)stmt->params[column].buffer); (*p) += 1; break; case MYSQL_TYPE_SHORT: case MYSQL_TYPE_YEAR: - int2store(*p, *(short *)stmt->param_bind[column].buffer); + int2store(*p, *(short *)stmt->params[column].buffer); (*p) += 2; break; case MYSQL_TYPE_FLOAT: - float4store(*p, *(float *)stmt->param_bind[column].buffer); + float4store(*p, *(float *)stmt->params[column].buffer); (*p) += 4; break; case MYSQL_TYPE_DOUBLE: - float8store(*p, *(double *)stmt->param_bind[column].buffer); + float8store(*p, *(double *)stmt->params[column].buffer); (*p) += 8; break; case MYSQL_TYPE_LONGLONG: - int8store(*p, *(my_ulonglong *)stmt->param_bind[column].buffer); + int8store(*p, *(my_ulonglong *)stmt->params[column].buffer); (*p) += 8; break; case MYSQL_TYPE_LONG: case MYSQL_TYPE_INT24: - int4store(*p, *(int32 *)stmt->param_bind[column].buffer); + int4store(*p, *(int32 *)stmt->params[column].buffer); (*p) += 4; break; case MYSQL_TYPE_TIME: @@ -388,9 +407,9 @@ int store_param(MYSQL_STMT *stmt, int column, unsigned char **p) 8 1 second; 9-13 4 second_part */ - MYSQL_TIME *t= (MYSQL_TIME *)stmt->param_bind[column].buffer; + MYSQL_TIME *t= (MYSQL_TIME *)stmt->params[column].buffer; char t_buffer[14]; - uint len= *stmt->param_bind[column].length; + uint len= *stmt->params[column].length; t_buffer[0]= len; t_buffer[1]= t->neg ? 1 : 0; @@ -419,9 +438,9 @@ int store_param(MYSQL_STMT *stmt, int column, unsigned char **p) 7 1 second 8-11 4 secondpart */ - MYSQL_TIME *t= (MYSQL_TIME *)stmt->param_bind[column].buffer; + MYSQL_TIME *t= (MYSQL_TIME *)stmt->params[column].buffer; char t_buffer[12]; - uint len= *stmt->param_bind[column].length; + uint len= *stmt->params[column].length; t_buffer[0]= len; int2store(t_buffer + 1, t->year); @@ -446,21 +465,22 @@ int store_param(MYSQL_STMT *stmt, int column, unsigned char **p) case MYSQL_TYPE_DECIMAL: case MYSQL_TYPE_NEWDECIMAL: { - ulong len= (ulong)*stmt->param_bind[column].length; + ulong len= (ulong)*stmt->params[column].length; /* to is after p. The latter hasn't been moved */ uchar *to = mysql_net_store_length(*p, len); + DBUG_PRINT("info", ("len=x%x", len)); if (len) - memcpy(to, stmt->param_bind[column].buffer, len); + memcpy(to, stmt->params[column].buffer, len); (*p) = to + len; } break; default: /* unsupported parameter type */ - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_UNSUPPORTED_PARAM_TYPE, SQLSTATE_UNKNOWN, ""); - return 1; + SET_CLIENT_STMT_ERROR(stmt, CR_UNSUPPORTED_PARAM_TYPE, SQLSTATE_UNKNOWN, ""); + DBUG_RETURN(1); } - return 0; + DBUG_RETURN(0); } /* {{{ mysqlnd_stmt_execute_generate_request */ @@ -485,10 +505,12 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req size_t length= 9000; size_t free_bytes= 0; size_t data_size= 0; - int i; + uint i; uchar *start= NULL, *p; + DBUG_ENTER("mysql_stmt_execute_generate_request"); + if (!(start= p= (uchar *)my_malloc(length, MYF(MY_WME | MY_ZEROFILL)))) goto mem_error; @@ -526,7 +548,7 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req if (free_bytes < stmt->param_count * 2 + 20) { uchar *buf; - ulonglong offset= p - start; + size_t offset= p - start; length= offset + stmt->param_count * 2 + 20; if (!(buf= (uchar *)my_malloc(length, MYF(MY_WME | MY_ZEROFILL)))) goto mem_error; @@ -538,22 +560,22 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req for (i = 0; i < stmt->param_count; i++) { /* this differs from mysqlnd, c api supports unsinged !! */ - uint buffer_type= stmt->param_bind[i].buffer_type | (stmt->param_bind[i].is_unsigned ? 32768 : 0); + uint buffer_type= stmt->params[i].buffer_type | (stmt->params[i].is_unsigned ? 32768 : 0); int2store(p, buffer_type); p+= 2; } } /* calculate data size */ for (i = 0; i < stmt->param_count; i++) { - if (stmt->param_bind[i].buffer && !stmt->param_bind[i].is_null) - stmt->param_bind[i].is_null = &is_not_null; - if (!stmt->param_bind[i].length) - stmt->param_bind[i].length= &stmt->param_bind[i].length_value; - if (!*stmt->param_bind[i].is_null) + if (stmt->params[i].buffer && !stmt->params[i].is_null) + stmt->params[i].is_null = &is_not_null; + if (!stmt->params[i].length) + stmt->params[i].length= &stmt->params[i].length_value; + if (!*stmt->params[i].is_null && !stmt->params[i].long_data_used) { - switch (stmt->param_bind[i].buffer_type) { + switch (stmt->params[i].buffer_type) { case MYSQL_TYPE_NULL: - stmt->param_bind[i].is_null = &is_null; + stmt->params[i].is_null = &is_null; break; case MYSQL_TYPE_TINY_BLOB: case MYSQL_TYPE_MEDIUM_BLOB: @@ -570,10 +592,10 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req case MYSQL_TYPE_BIT: case MYSQL_TYPE_SET: data_size+= 5; /* max 8 bytes for size */ - data_size+= *stmt->param_bind[i].length; + data_size+= *stmt->params[i].length; break; default: - data_size+= mysql_ps_fetch_functions[stmt->param_bind[i].buffer_type].pack_len; + data_size+= mysql_ps_fetch_functions[stmt->params[i].buffer_type].pack_len; break; } } @@ -584,7 +606,7 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req if (free_bytes < data_size + 20) { uchar *buf; - ulonglong offset= p - start; + size_t offset= p - start; length= offset + data_size + 20; if (!(buf= (uchar *)my_malloc(length, MYF(MY_WME | MY_ZEROFILL)))) goto mem_error; @@ -595,13 +617,14 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req } for (i = 0; i < stmt->param_count; i++) { - if (stmt->param_bind[i].long_data_used) { - stmt->param_bind[i].long_data_used= 0; + if (stmt->params[i].long_data_used) { + stmt->params[i].long_data_used= 0; } else { - if (!stmt->param_bind[i].buffer || *stmt->param_bind[i].is_null || stmt->param_bind[i].buffer_type == MYSQL_TYPE_NULL) { + if (!stmt->params[i].buffer || *stmt->params[i].is_null || stmt->params[i].buffer_type == MYSQL_TYPE_NULL) { (start + null_byte_offset)[i/8] |= (unsigned char) (1 << (i & 7)); } else { + DBUG_PRINT("info", ("storing parameter %d at offset %d", i, p - start)); store_param(stmt, i, &p); } } @@ -609,14 +632,14 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req } stmt->send_types_to_server= 0; *request_len = (p - start); - return start; + DBUG_RETURN(start); mem_error: - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); my_free((gptr)start, MYF(ALLOW_ZERO_PTR)); *request_len= 0; - return NULL; + DBUG_RETURN(NULL); } /* }}} */ @@ -630,12 +653,12 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req \param[in] stmt The statement handle ******************************************************************************* */ -my_ulonglong mysql_stmt_affected_rows(MYSQL_STMT *stmt) +my_ulonglong STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt) { return stmt->upsert_status.affected_rows; } -my_bool mysql_stmt_attr_get(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, void *value) +my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, void *value) { DBUG_ENTER("mysql_stmt_attr_get"); @@ -655,7 +678,7 @@ my_bool mysql_stmt_attr_get(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type DBUG_RETURN(0); } -my_bool mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, const void *value) +my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, const void *value) { DBUG_ENTER("mysql_stmt_attr_get"); @@ -666,7 +689,7 @@ my_bool mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type case STMT_ATTR_CURSOR_TYPE: { if (*(ulong *)value > (unsigned long) CURSOR_TYPE_READ_ONLY) { - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_NOT_IMPLEMENTED, SQLSTATE_UNKNOWN, "Not implemented"); + SET_CLIENT_STMT_ERROR(stmt, CR_NOT_IMPLEMENTED, SQLSTATE_UNKNOWN, "Not implemented"); DBUG_RETURN(1); } stmt->flags = *(ulong *)value; @@ -680,64 +703,67 @@ my_bool mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type break; } default: - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_NOT_IMPLEMENTED, SQLSTATE_UNKNOWN, "Not implemented"); + SET_CLIENT_STMT_ERROR(stmt, CR_NOT_IMPLEMENTED, SQLSTATE_UNKNOWN, "Not implemented"); DBUG_RETURN(1); } DBUG_RETURN(0); } -my_bool mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bind) +my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bind) { DBUG_ENTER("mysql_stmt_bind_param"); if (stmt->state < MYSQL_STMT_PREPARED) { - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_NO_PREPARE_STMT, SQLSTATE_UNKNOWN, mysql_stmt_not_prepared); + SET_CLIENT_STMT_ERROR(stmt, CR_NO_PREPARE_STMT, SQLSTATE_UNKNOWN, mysql_stmt_not_prepared); DBUG_RETURN(1); } if (stmt->param_count && bind) { - int i; + uint i; - memcpy(stmt->param_bind, bind, sizeof(MYSQL_BIND) * stmt->param_count); + memcpy(stmt->params, bind, sizeof(MYSQL_BIND) * stmt->param_count); stmt->send_types_to_server= 1; for (i=0; i < stmt->param_count; i++) { - if (!stmt->param_bind[i].is_null) - stmt->param_bind[i].is_null= &is_not_null; + if (!stmt->params[i].is_null) + stmt->params[i].is_null= &is_not_null; + + if (stmt->params[i].long_data_used) + stmt->params[i].long_data_used= 0; - if (!stmt->param_bind[i].length) - stmt->param_bind[i].length= &stmt->param_bind[i].buffer_length; + if (!stmt->params[i].length) + stmt->params[i].length= &stmt->params[i].buffer_length; - switch(stmt->param_bind[i].buffer_type) { + switch(stmt->params[i].buffer_type) { case MYSQL_TYPE_NULL: - stmt->param_bind[i].is_null= &is_null; + stmt->params[i].is_null= &is_null; break; case MYSQL_TYPE_TINY: - stmt->param_bind[i].buffer_length= 1; + stmt->params[i].buffer_length= 1; break; case MYSQL_TYPE_SHORT: case MYSQL_TYPE_YEAR: - stmt->param_bind[i].buffer_length= 2; + stmt->params[i].buffer_length= 2; break; case MYSQL_TYPE_LONG: case MYSQL_TYPE_FLOAT: - stmt->param_bind[i].buffer_length= 4; + stmt->params[i].buffer_length= 4; break; case MYSQL_TYPE_LONGLONG: case MYSQL_TYPE_DOUBLE: - stmt->param_bind[i].buffer_length= 8; + stmt->params[i].buffer_length= 8; break; case MYSQL_TYPE_DATETIME: case MYSQL_TYPE_TIMESTAMP: - stmt->param_bind[i].buffer_length= 12; + stmt->params[i].buffer_length= 12; break; case MYSQL_TYPE_TIME: - stmt->param_bind[i].buffer_length= 13; + stmt->params[i].buffer_length= 13; break; case MYSQL_TYPE_DATE: - stmt->param_bind[i].buffer_length= 5; + stmt->params[i].buffer_length= 5; break; case MYSQL_TYPE_STRING: case MYSQL_TYPE_VAR_STRING: @@ -749,86 +775,88 @@ my_bool mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bind) case MYSQL_TYPE_NEWDECIMAL: break; default: - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_UNSUPPORTED_PARAM_TYPE, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_UNSUPPORTED_PARAM_TYPE, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); break; } } } - CLEAR_CLIENT_STMT_ERROR(stmt->error_info); + stmt->bind_param_done= stmt->send_types_to_server= 1; + + CLEAR_CLIENT_STMT_ERROR(stmt); DBUG_RETURN(0); } -my_bool mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) +my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) { - int i; + uint i; DBUG_ENTER("mysql_stmt_bind_result"); if (stmt->state < MYSQL_STMT_PREPARED) { - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_NO_PREPARE_STMT, SQLSTATE_UNKNOWN, mysql_stmt_not_prepared); + SET_CLIENT_STMT_ERROR(stmt, CR_NO_PREPARE_STMT, SQLSTATE_UNKNOWN, mysql_stmt_not_prepared); DBUG_RETURN(1); } if (!stmt->field_count) { - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_NO_STMT_METADATA, SQLSTATE_UNKNOWN, "todo: metadata error"); + SET_CLIENT_STMT_ERROR(stmt, CR_NO_STMT_METADATA, SQLSTATE_UNKNOWN, "todo: metadata error"); DBUG_RETURN(1); } if (!bind) DBUG_RETURN(1); - memcpy(stmt->result_bind, bind, sizeof(MYSQL_BIND) * stmt->field_count); + memcpy(stmt->bind, bind, sizeof(MYSQL_BIND) * stmt->field_count); for (i=0; i < stmt->field_count; i++) { if (!is_supported_buffer_type(bind[i].buffer_type)) { - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_UNSUPPORTED_PARAM_TYPE, SQLSTATE_UNKNOWN, ""); + SET_CLIENT_STMT_ERROR(stmt, CR_UNSUPPORTED_PARAM_TYPE, SQLSTATE_UNKNOWN, ""); DBUG_RETURN(1); } - if (!stmt->result_bind[i].is_null) - stmt->result_bind[i].is_null= &stmt->result_bind[i].is_null_value; - if (!stmt->result_bind[i].length) - stmt->result_bind[i].length= &stmt->result_bind[i].length_value; - if (!stmt->result_bind[i].error) - stmt->result_bind[i].error= &stmt->result_bind[i].error_value; + if (!stmt->bind[i].is_null) + stmt->bind[i].is_null= &stmt->bind[i].is_null_value; + if (!stmt->bind[i].length) + stmt->bind[i].length= &stmt->bind[i].length_value; + if (!stmt->bind[i].error) + stmt->bind[i].error= &stmt->bind[i].error_value; /* set length values for numeric types */ switch(bind[i].buffer_type) { case MYSQL_TYPE_NULL: - *stmt->result_bind[i].length= stmt->result_bind[i].length_value= 0; + *stmt->bind[i].length= stmt->bind[i].length_value= 0; break; case MYSQL_TYPE_TINY: - *stmt->result_bind[i].length= stmt->result_bind[i].length_value= 1; + *stmt->bind[i].length= stmt->bind[i].length_value= 1; break; case MYSQL_TYPE_SHORT: case MYSQL_TYPE_YEAR: - *stmt->result_bind[i].length= stmt->result_bind[i].length_value= 2; + *stmt->bind[i].length= stmt->bind[i].length_value= 2; break; case MYSQL_TYPE_INT24: case MYSQL_TYPE_LONG: case MYSQL_TYPE_FLOAT: - *stmt->result_bind[i].length= stmt->result_bind[i].length_value= 4; + *stmt->bind[i].length= stmt->bind[i].length_value= 4; break; case MYSQL_TYPE_LONGLONG: case MYSQL_TYPE_DOUBLE: - *stmt->result_bind[i].length= stmt->result_bind[i].length_value= 8; + *stmt->bind[i].length= stmt->bind[i].length_value= 8; break; case MYSQL_TYPE_TIME: case MYSQL_TYPE_DATE: case MYSQL_TYPE_DATETIME: case MYSQL_TYPE_TIMESTAMP: - *stmt->result_bind[i].length= stmt->result_bind[i].length_value= sizeof(MYSQL_TIME); + *stmt->bind[i].length= stmt->bind[i].length_value= sizeof(MYSQL_TIME); break; default: break; } } stmt->bind_result_done= 1; - CLEAR_CLIENT_STMT_ERROR(stmt->error_info); + CLEAR_CLIENT_STMT_ERROR(stmt); DBUG_RETURN(0); } @@ -840,27 +868,26 @@ my_bool net_stmt_close(MYSQL_STMT *stmt, my_bool remove) free_root(&stmt->result.alloc, MYF(00)); /* allocated in mysql_stmt_store_result */ free_root(&stmt->mem_root,MYF(0)); - if (stmt->conn) + if (stmt->mysql) { - CLEAR_CLIENT_ERROR(stmt->conn); + CLEAR_CLIENT_ERROR(stmt->mysql); /* remove from stmt list */ if (remove) - stmt->conn->stmts= list_delete(stmt->conn->stmts, &stmt->list); + stmt->mysql->stmts= list_delete(stmt->mysql->stmts, &stmt->list); /* check if all data are fetched */ - if (stmt->conn->status != MYSQL_STATUS_READY) + if (stmt->mysql->status != MYSQL_STATUS_READY) { stmt_flush_unbuffered(stmt); - stmt->conn->status= MYSQL_STATUS_READY; + stmt->mysql->status= MYSQL_STATUS_READY; } if (stmt->state > MYSQL_STMT_INITTED) { int4store(stmt_id, stmt->stmt_id); - if (simple_command(stmt->conn,MYSQL_COM_STMT_CLOSE, stmt_id, sizeof(stmt_id), 1)) + if (simple_command(stmt->mysql,MYSQL_COM_STMT_CLOSE, stmt_id, sizeof(stmt_id), 1)) { - SET_CLIENT_STMT_ERROR(stmt->error_info, stmt->conn->net.last_errno, stmt->conn->net.sqlstate, - stmt->conn->net.last_error); + SET_CLIENT_STMT_ERROR(stmt, stmt->mysql->net.last_errno, stmt->mysql->net.sqlstate, stmt->mysql->net.last_error); return 1; } } @@ -868,7 +895,7 @@ my_bool net_stmt_close(MYSQL_STMT *stmt, my_bool remove) return 0; } -my_bool mysql_stmt_close(MYSQL_STMT *stmt) +my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt) { DBUG_ENTER("mysql_stmt_close"); @@ -878,45 +905,47 @@ my_bool mysql_stmt_close(MYSQL_STMT *stmt) DBUG_RETURN(0); } -void mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong offset) +void STDCALL mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong offset) { my_ulonglong i= offset; - DBUG_ENTER("mysql_stmt_data_seel"); + MYSQL_ROWS *ptr= stmt->result.data; + DBUG_ENTER("mysql_stmt_data_seek"); - if (offset >= stmt->result.rows) - DBUG_VOID_RETURN; + DBUG_PRINT("info", ("total rows: %llu offset: %llu", stmt->result.rows, offset)); - stmt->result_cursor= stmt->result.data; + while(i-- && ptr) + ptr= ptr->next; - while(i-- && stmt->result_cursor) - stmt->result_cursor= stmt->result_cursor->next; + stmt->result_cursor= ptr; DBUG_VOID_RETURN; } -unsigned int mysql_stmt_errno(MYSQL_STMT *stmt) +unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT *stmt) { - return stmt->error_info.error_no; + return stmt->last_errno; } -const char *mysql_stmt_error(MYSQL_STMT *stmt) +const char * STDCALL mysql_stmt_error(MYSQL_STMT *stmt) { - return (const char *)stmt->error_info.error; + return (const char *)stmt->last_error; } -int mysql_stmt_fetch(MYSQL_STMT *stmt) +int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt) { unsigned char *row; int rc; DBUG_ENTER("mysql_stmt_fetch"); - if (stmt->state == MYSQL_STMT_EXECUTED) - return 1; + if (stmt->state <= MYSQL_STMT_EXECUTED) + { + DBUG_RETURN(1); + } if (stmt->state < MYSQL_STMT_WAITING_USE_OR_STORE || !stmt->field_count) { - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); } else if (stmt->state== MYSQL_STMT_WAITING_USE_OR_STORE) { @@ -931,31 +960,32 @@ int mysql_stmt_fetch(MYSQL_STMT *stmt) if ((rc= stmt->fetch_row_func(stmt, &row))) { stmt->state= MYSQL_STMT_FETCH_DONE; - stmt->conn->status= MYSQL_STATUS_READY; + stmt->mysql->status= MYSQL_STATUS_READY; /* to fetch data again, stmt must be executed again */ DBUG_RETURN(MYSQL_NO_DATA); } if ((rc= stmt_fetch_to_bind(stmt, row))) + { DBUG_RETURN(rc); - + } stmt->state= MYSQL_STMT_USER_FETCHING; - CLEAR_CLIENT_ERROR(stmt->conn); - CLEAR_CLIENT_STMT_ERROR(stmt->error_info); + CLEAR_CLIENT_ERROR(stmt->mysql); + CLEAR_CLIENT_STMT_ERROR(stmt); DBUG_RETURN(0); } -int mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind, unsigned int column, unsigned long offset) +int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind, unsigned int column, unsigned long offset) { DBUG_ENTER("mysql_stmt_fetch"); if (stmt->state < MYSQL_STMT_USER_FETCHING || column >= stmt->field_count || stmt->state == MYSQL_STMT_FETCH_DONE) { - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_NO_DATA, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_NO_DATA, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); } - if (!stmt->result_bind[column].row_ptr) + if (!stmt->bind[column].row_ptr) { /* we set row_ptr only for columns which contain data, so this must be a NULL column */ if (bind[0].is_null) @@ -965,9 +995,9 @@ int mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind, unsigned int col { unsigned char *save_ptr; if (bind[0].length) - *bind[0].length= stmt->result_bind[column].length_value; + *bind[0].length= stmt->bind[column].length_value; else - *bind[0].length= *stmt->result_bind[column].length; + *bind[0].length= *stmt->bind[column].length; if (bind[0].is_null) *bind[0].is_null= 0; else @@ -976,19 +1006,19 @@ int mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind, unsigned int col bind[0].error= &bind[0].error_value; *bind[0].error= 0; bind[0].offset= offset; - save_ptr= stmt->result_bind[column].row_ptr; - mysql_ps_fetch_functions[stmt->fields[column].type].func(&bind[0], &stmt->fields[column], &stmt->result_bind[column].row_ptr); - stmt->result_bind[column].row_ptr= save_ptr; + save_ptr= stmt->bind[column].row_ptr; + mysql_ps_fetch_functions[stmt->fields[column].type].func(&bind[0], &stmt->fields[column], &stmt->bind[column].row_ptr); + stmt->bind[column].row_ptr= save_ptr; } DBUG_RETURN(0); } -unsigned int mysql_stmt_field_count(MYSQL_STMT *stmt) +unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt) { return stmt->field_count; } -my_bool mysql_stmt_free_result(MYSQL_STMT *stmt) +my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt) { return mysql_stmt_reset(stmt); } @@ -1001,18 +1031,18 @@ MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql) if (!stmt) { - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(NULL); } /* fill mysql's stmt list */ stmt->list.data= stmt; - stmt->conn= mysql; + stmt->mysql= mysql; mysql->stmts= list_add(mysql->stmts, &stmt->list); /* clear flags */ - strcpy(stmt->error_info.sqlstate, "00000"); + strcpy(stmt->sqlstate, "00000"); stmt->state= MYSQL_STMT_INITTED; @@ -1029,12 +1059,12 @@ my_bool stmt_read_prepare_response(MYSQL_STMT *stmt) DBUG_ENTER("read_prepare_response"); - if ((packet_length= net_safe_read(stmt->conn)) == packet_error) + if ((packet_length= net_safe_read(stmt->mysql)) == packet_error) DBUG_RETURN(1); DBUG_PRINT("info",("packet_length= %ld",packet_length)); - p= (uchar *)stmt->conn->net.read_pos; + p= (uchar *)stmt->mysql->net.read_pos; if (0xFF == p[0]) /* Error occured */ { @@ -1061,7 +1091,7 @@ my_bool stmt_get_param_metadata(MYSQL_STMT *stmt) DBUG_ENTER("stmt_get_param_metadata"); - if (!(result= read_rows(stmt->conn, (MYSQL_FIELD *)0, 7))) + if (!(result= read_rows(stmt->mysql, (MYSQL_FIELD *)0, 7))) DBUG_RETURN(1); free_rows(result); @@ -1073,11 +1103,11 @@ my_bool stmt_read_result_metadata(MYSQL_STMT *stmt) MYSQL_DATA *result; DBUG_ENTER("stmt_read_result_metadata"); - if (!(result= read_rows(stmt->conn, (MYSQL_FIELD *)0, 7))) + if (!(result= read_rows(stmt->mysql, (MYSQL_FIELD *)0, 7))) DBUG_RETURN(1); if (!(stmt->fields= unpack_fields(result,&stmt->mem_root, stmt->field_count, 0, - stmt->conn->server_capabilities))) + stmt->mysql->server_capabilities & CLIENT_LONG_FLAG))) DBUG_RETURN(1); DBUG_RETURN(0); } @@ -1087,16 +1117,16 @@ int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, unsigned lon int rc= 1; DBUG_ENTER("mysql_stmt_prepare"); - if (!stmt->conn) + if (!stmt->mysql) { - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); } /* clear flags */ - CLEAR_CLIENT_STMT_ERROR(stmt->error_info); - CLEAR_CLIENT_ERROR(stmt->conn); - stmt->upsert_status.affected_rows= stmt->conn->affected_rows= (my_ulonglong) ~0; + CLEAR_CLIENT_STMT_ERROR(stmt); + CLEAR_CLIENT_ERROR(stmt->mysql); + stmt->upsert_status.affected_rows= stmt->mysql->affected_rows= (my_ulonglong) ~0; /* check if we have to clear results */ if (stmt->state > MYSQL_STMT_INITTED) @@ -1113,11 +1143,11 @@ int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, unsigned lon stmt->field_count= 0; int4store(stmt_id, stmt->stmt_id); - if (simple_command(stmt->conn, MYSQL_COM_STMT_CLOSE, stmt_id, sizeof(stmt_id), 1)) + if (simple_command(stmt->mysql, MYSQL_COM_STMT_CLOSE, stmt_id, sizeof(stmt_id), 1)) goto fail; } - if (simple_command(stmt->conn,MYSQL_COM_STMT_PREPARE, query, length, 1)) + if (simple_command(stmt->mysql,MYSQL_COM_STMT_PREPARE, query, length, 1)) goto fail; if (stmt_read_prepare_response(stmt)) @@ -1137,18 +1167,18 @@ int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, unsigned lon /* allocated bind buffer for parameters */ if (stmt->param_count) { - if (!(stmt->param_bind= (MYSQL_BIND *)alloc_root(&stmt->mem_root, stmt->param_count * sizeof(MYSQL_BIND)))) + if (!(stmt->params= (MYSQL_BIND *)alloc_root(&stmt->mem_root, stmt->param_count * sizeof(MYSQL_BIND)))) { - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto fail; } } /* allocated bind buffer for result */ if (stmt->field_count) { - if (!(stmt->result_bind= (MYSQL_BIND *)alloc_root(&stmt->mem_root, stmt->field_count * sizeof(MYSQL_BIND)))) + if (!(stmt->bind= (MYSQL_BIND *)alloc_root(&stmt->mem_root, stmt->field_count * sizeof(MYSQL_BIND)))) { - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto fail; } } @@ -1157,8 +1187,8 @@ int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, unsigned lon fail: stmt->state= MYSQL_STMT_INITTED; - SET_CLIENT_STMT_ERROR(stmt->error_info, stmt->conn->net.last_errno, stmt->conn->net.sqlstate, - stmt->conn->net.last_error); + SET_CLIENT_STMT_ERROR(stmt, stmt->mysql->net.last_errno, stmt->mysql->net.sqlstate, + stmt->mysql->net.last_error); DBUG_RETURN(rc); } @@ -1166,41 +1196,41 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) { DBUG_ENTER("mysql_stmt_store_result"); - /* test_pure_coverage requires checking of error_no */ - if (stmt->error_info.error_no) - DBUG_RETURN(1); - - if (!stmt->conn) + if (!stmt->mysql) { - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); } if (!stmt->field_count) DBUG_RETURN(0); + /* test_pure_coverage requires checking of error_no */ + if (stmt->last_errno) + DBUG_RETURN(1); + if (stmt->state < MYSQL_STMT_EXECUTED) { - SET_CLIENT_ERROR(stmt->conn, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_ERROR(stmt->mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); } /* if stmt is a cursor, we need to tell server to send all rows */ - if (stmt->cursor_exists && stmt->conn->status == MYSQL_STATUS_READY) + if (stmt->cursor_exists && stmt->mysql->status == MYSQL_STATUS_READY) { char buff[STMT_ID_LENGTH + 4]; int4store(buff, stmt->stmt_id); int4store(buff + STMT_ID_LENGTH, (int)~0); - if (simple_command(stmt->conn, MYSQL_COM_STMT_FETCH, buff, sizeof(buff), 1)) + if (simple_command(stmt->mysql, MYSQL_COM_STMT_FETCH, buff, sizeof(buff), 1)) DBUG_RETURN(1); /* todo: cursor */ } - else if (stmt->conn->status != MYSQL_STATUS_GET_RESULT) + else if (stmt->mysql->status != MYSQL_STATUS_GET_RESULT) { - SET_CLIENT_ERROR(stmt->conn, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_ERROR(stmt->mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); } @@ -1210,17 +1240,17 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) free_root(&stmt->result.alloc, 0); stmt->result.data= NULL; stmt->result.rows= 0; - stmt->conn->status= MYSQL_STATUS_READY; + stmt->mysql->status= MYSQL_STATUS_READY; DBUG_RETURN(1); } stmt->result_cursor= stmt->result.data; stmt->fetch_row_func= stmt_buffered_fetch; - stmt->conn->status= MYSQL_STATUS_READY; + stmt->mysql->status= MYSQL_STATUS_READY; stmt->state= MYSQL_STMT_USE_OR_STORE_CALLED; /* set affected rows: see bug 2247 */ stmt->upsert_status.affected_rows= stmt->result.rows; - stmt->conn->affected_rows= stmt->result.rows; + stmt->mysql->affected_rows= stmt->result.rows; DBUG_RETURN(0); } @@ -1234,22 +1264,22 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) DBUG_ENTER("mysql_stmt_execute"); - if (!stmt->conn) + if (!stmt->mysql) { - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); } if (stmt->state < MYSQL_STMT_PREPARED) { - SET_CLIENT_ERROR(stmt->conn, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_ERROR(stmt->mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); } - if (stmt->param_count && !stmt->param_bind) + if (stmt->param_count && !stmt->bind_param_done) { - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_PARAMS_NOT_BOUND, SQLSTATE_UNKNOWN, + SET_CLIENT_STMT_ERROR(stmt, CR_PARAMS_NOT_BOUND, SQLSTATE_UNKNOWN, "No data supplied for parameters in prepared statement"); DBUG_RETURN(1); } @@ -1263,7 +1293,7 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) { stmt_flush_unbuffered(stmt); stmt->state= MYSQL_STMT_PREPARED; - stmt->conn->status= MYSQL_STATUS_READY; + stmt->mysql->status= MYSQL_STATUS_READY; } /* clear data, in case mysql_stmt_store_result was called */ @@ -1277,61 +1307,66 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) request= (char *)mysql_stmt_execute_generate_request(stmt, &request_len); DBUG_PRINT("info",("request_len=%ld", request_len)); - ret= test(simple_command(stmt->conn, MYSQL_COM_STMT_EXECUTE, request, request_len, 1) || - mysql_read_query_result(stmt->conn)); + ret= test(simple_command(stmt->mysql, MYSQL_COM_STMT_EXECUTE, request, request_len, 1) || + mysql_read_query_result(stmt->mysql)); if (request) my_free(request, MYF(0)); + /* if a reconnect occured, our connection handle is invalid */ + if (!stmt->mysql) + DBUG_RETURN(1); + /* update affected rows, also if an error occured */ - stmt->upsert_status.affected_rows= stmt->conn->affected_rows; + stmt->upsert_status.affected_rows= stmt->mysql->affected_rows; if (ret) { - SET_CLIENT_STMT_ERROR(stmt->error_info, stmt->conn->net.last_errno, stmt->conn->net.sqlstate, - stmt->conn->net.last_error); + SET_CLIENT_STMT_ERROR(stmt, stmt->mysql->net.last_errno, stmt->mysql->net.sqlstate, + stmt->mysql->net.last_error); + stmt->state= MYSQL_STMT_PREPARED; DBUG_RETURN(1); } - stmt->upsert_status.last_insert_id= stmt->conn->insert_id; - stmt->upsert_status.server_status= stmt->conn->server_status; - stmt->upsert_status.warning_count= stmt->conn->warning_count; + stmt->upsert_status.last_insert_id= stmt->mysql->insert_id; + stmt->upsert_status.server_status= stmt->mysql->server_status; + stmt->upsert_status.warning_count= stmt->mysql->warning_count; - CLEAR_CLIENT_ERROR(stmt->conn); - CLEAR_CLIENT_STMT_ERROR(stmt->error_info); + CLEAR_CLIENT_ERROR(stmt->mysql); + CLEAR_CLIENT_STMT_ERROR(stmt); stmt->execute_count++; stmt->send_types_to_server= 0; stmt->state= MYSQL_STMT_EXECUTED; - if (stmt->conn->field_count) + if (stmt->mysql->field_count) { if (!stmt->field_count) /* fix for ps_bug: test_misc */ { uint i; if (!(stmt->fields= (MYSQL_FIELD *)alloc_root(&stmt->mem_root, - sizeof(MYSQL_FIELD) * stmt->conn->field_count))) + sizeof(MYSQL_FIELD) * stmt->mysql->field_count))) { /*todo: set error */ DBUG_RETURN(1); } - stmt->field_count= stmt->conn->field_count; + stmt->field_count= stmt->mysql->field_count; for (i=0; i < stmt->field_count; i++) { - stmt->fields[i].db= strdup_root(&stmt->mem_root, stmt->conn->fields[i].db); - stmt->fields[i].table= strdup_root(&stmt->mem_root, stmt->conn->fields[i].table); - stmt->fields[i].org_table= strdup_root(&stmt->mem_root, stmt->conn->fields[i].org_table); - stmt->fields[i].name= strdup_root(&stmt->mem_root, stmt->conn->fields[i].name); - stmt->fields[i].org_name= strdup_root(&stmt->mem_root, stmt->conn->fields[i].org_name); - stmt->fields[i].def= stmt->conn->fields[i].def ? strdup_root(&stmt->mem_root, stmt->conn->fields[i].def) : NULL; + stmt->fields[i].db= strdup_root(&stmt->mem_root, stmt->mysql->fields[i].db); + stmt->fields[i].table= strdup_root(&stmt->mem_root, stmt->mysql->fields[i].table); + stmt->fields[i].org_table= strdup_root(&stmt->mem_root, stmt->mysql->fields[i].org_table); + stmt->fields[i].name= strdup_root(&stmt->mem_root, stmt->mysql->fields[i].name); + stmt->fields[i].org_name= strdup_root(&stmt->mem_root, stmt->mysql->fields[i].org_name); + stmt->fields[i].def= stmt->mysql->fields[i].def ? strdup_root(&stmt->mem_root, stmt->mysql->fields[i].def) : NULL; } } if (stmt->upsert_status.server_status & SERVER_STATUS_CURSOR_EXISTS) { stmt->cursor_exists = TRUE; - stmt->conn->status = MYSQL_STATUS_READY; + stmt->mysql->status = MYSQL_STATUS_READY; /* Only cursor read */ stmt->default_rset_handler = _mysql_stmt_use_result; @@ -1358,21 +1393,21 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) stmt->state= MYSQL_STMT_WAITING_USE_OR_STORE; /* in certain cases parameter types can change: For example see bug 4026 (SELECT ?), so we need to update field information */ - if (stmt->conn->field_count == stmt->field_count) + if (stmt->mysql->field_count == stmt->field_count) { uint i; for (i=0; i < stmt->field_count; i++) { - stmt->fields[i].type= stmt->conn->fields[i].type; - stmt->fields[i].length= stmt->conn->fields[i].length; - stmt->fields[i].flags= stmt->conn->fields[i].flags; - stmt->fields[i].decimals= stmt->conn->fields[i].decimals; - stmt->fields[i].charsetnr= stmt->conn->fields[i].charsetnr; + stmt->fields[i].type= stmt->mysql->fields[i].type; + stmt->fields[i].length= stmt->mysql->fields[i].length; + stmt->fields[i].flags= stmt->mysql->fields[i].flags; + stmt->fields[i].decimals= stmt->mysql->fields[i].decimals; + stmt->fields[i].charsetnr= stmt->mysql->fields[i].charsetnr; } } else { /* table was altered, see test_wl4166_2 */ - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_NEW_STMT_METADATA, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_NEW_STMT_METADATA, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); } } @@ -1386,14 +1421,14 @@ my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt) DBUG_ENTER("mysql_stmt_reset"); - if (!stmt->conn) + if (!stmt->mysql) { - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); } - CLEAR_CLIENT_ERROR(stmt->conn); - CLEAR_CLIENT_STMT_ERROR(stmt->error_info); + CLEAR_CLIENT_ERROR(stmt->mysql); + CLEAR_CLIENT_STMT_ERROR(stmt); if (stmt->stmt_id) @@ -1404,33 +1439,33 @@ my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt) stmt->state = MYSQL_STMT_USER_FETCHING; } - if (stmt->conn->status!= MYSQL_STATUS_READY && stmt->field_count) + if (stmt->mysql->status!= MYSQL_STATUS_READY && stmt->field_count) { stmt_flush_unbuffered(stmt); - stmt->conn->status= MYSQL_STATUS_READY; + stmt->mysql->status= MYSQL_STATUS_READY; } /* reset statement on server side */ - if (stmt->conn->status == MYSQL_STATUS_READY) + if (stmt->mysql->status == MYSQL_STATUS_READY) { int4store(cmd_buf, stmt->stmt_id); - if ((ret= simple_command(stmt->conn,MYSQL_COM_STMT_RESET, (char *)cmd_buf, sizeof(cmd_buf), 0))) - SET_CLIENT_STMT_ERROR(stmt->error_info, stmt->conn->net.last_errno, stmt->conn->net.sqlstate, - stmt->conn->net.last_error); + if ((ret= simple_command(stmt->mysql,MYSQL_COM_STMT_RESET, (char *)cmd_buf, sizeof(cmd_buf), 0))) + SET_CLIENT_STMT_ERROR(stmt, stmt->mysql->net.last_errno, stmt->mysql->net.sqlstate, + stmt->mysql->net.last_error); } - if (stmt->param_bind) { + if (stmt->params) { ulonglong i; for (i=0; i < stmt->param_count; i++) - if (stmt->param_bind[i].long_data_used) - stmt->param_bind[i].long_data_used= 0; + if (stmt->params[i].long_data_used) + stmt->params[i].long_data_used= 0; } stmt->state= MYSQL_STMT_PREPARED; - stmt->upsert_status.affected_rows= stmt->conn->affected_rows; - stmt->upsert_status.last_insert_id= stmt->conn->insert_id; - stmt->upsert_status.server_status= stmt->conn->server_status; - stmt->upsert_status.warning_count= stmt->conn->warning_count; - stmt->conn->status= MYSQL_STATUS_READY; + stmt->upsert_status.affected_rows= stmt->mysql->affected_rows; + stmt->upsert_status.last_insert_id= stmt->mysql->insert_id; + stmt->upsert_status.server_status= stmt->mysql->server_status; + stmt->upsert_status.warning_count= stmt->mysql->warning_count; + stmt->mysql->status= MYSQL_STATUS_READY; } DBUG_RETURN(ret); @@ -1448,7 +1483,7 @@ MYSQL_RES * STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt) /* aloocate result set structutr and copy stmt information */ if (!(res= (MYSQL_RES *)my_malloc(sizeof(MYSQL_RES), MYF(MY_WME | MY_ZEROFILL)))) { - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(NULL); } @@ -1459,7 +1494,7 @@ MYSQL_RES * STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt) const char * STDCALL mysql_stmt_sqlstate(MYSQL_STMT *stmt) { - return stmt->error_info.sqlstate; + return stmt->sqlstate; } MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_tell(MYSQL_STMT *stmt) @@ -1489,22 +1524,22 @@ my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number, { DBUG_ENTER("mysql_stmt_send_long_data"); - CLEAR_CLIENT_ERROR(stmt->conn); - CLEAR_CLIENT_STMT_ERROR(stmt->error_info); + CLEAR_CLIENT_ERROR(stmt->mysql); + CLEAR_CLIENT_STMT_ERROR(stmt); - if (stmt->state < MYSQL_STMT_PREPARED || !stmt->param_bind) + if (stmt->state < MYSQL_STMT_PREPARED || !stmt->params) { - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_NO_PREPARE_STMT, SQLSTATE_UNKNOWN, mysql_stmt_not_prepared); + SET_CLIENT_STMT_ERROR(stmt, CR_NO_PREPARE_STMT, SQLSTATE_UNKNOWN, mysql_stmt_not_prepared); DBUG_RETURN(1); } if (param_number >= stmt->param_count) { - SET_CLIENT_STMT_ERROR(stmt->error_info, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); } - if (stmt->conn->status== MYSQL_STATUS_READY && (length || !stmt->param_bind[param_number].long_data_used)) + if (stmt->mysql->status== MYSQL_STATUS_READY && (length || !stmt->params[param_number].long_data_used)) { int ret; size_t packet_len; @@ -1512,10 +1547,21 @@ my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number, int4store(cmd_buff, stmt->stmt_id); int2store(cmd_buff + STMT_ID_LENGTH, param_number); memcpy(cmd_buff + STMT_ID_LENGTH + 2, data, length); - stmt->param_bind[param_number].long_data_used= 1; - ret= simple_command(stmt->conn,MYSQL_COM_STMT_SEND_LONG_DATA, (char *)cmd_buff, packet_len, 1); + stmt->params[param_number].long_data_used= 1; + ret= simple_command(stmt->mysql,MYSQL_COM_STMT_SEND_LONG_DATA, (char *)cmd_buff, packet_len, 1); my_free((gptr)cmd_buff, MYF(MY_WME)); DBUG_RETURN(ret); } DBUG_RETURN(1); } + +my_ulonglong STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt) +{ + return stmt->upsert_status.last_insert_id; +} + +my_ulonglong STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt) +{ + return stmt->result.rows; +} + diff --git a/libmysql/mysql_stmt_codec.c b/libmysql/my_stmt_codec.c similarity index 89% rename from libmysql/mysql_stmt_codec.c rename to libmysql/my_stmt_codec.c index fc3b949f1..93304aff5 100644 --- a/libmysql/mysql_stmt_codec.c +++ b/libmysql/my_stmt_codec.c @@ -17,8 +17,28 @@ 51 Franklin St., Fifth Floor, Boston, MA 02110, USA *****************************************************************************/ -/* The implementation for preoared statements was ported from PHP's mysqlnd - extension, written by Andrey Hristov, Georg Richter and Ulf Wendel */ +/* The implementation for prepared statements was ported from PHP's mysqlnd + extension, written by Andrey Hristov, Georg Richter and Ulf Wendel + + Original file header: + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 2006-2011 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Georg Richter | + | Andrey Hristov | + | Ulf Wendel | + +----------------------------------------------------------------------+ +*/ #include "my_global.h" #include @@ -33,8 +53,10 @@ #define UINT_MAX32 0xFFFFFFFFL #define UINT_MAX24 0x00FFFFFF #define UINT_MAX16 0xFFFF +#ifndef INT_MIN8 #define INT_MIN8 (~0x7F) #define INT_MAX8 0x7F +#endif #define UINT_MAX8 0xFF #if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN) @@ -101,7 +123,7 @@ static longlong my_atoll(const char *number, const char *end, int *error) { char buffer[255]; longlong llval= 0; - int i; + size_t i; /* set error at the following conditions: - string contains invalid character(s) - length > 254 @@ -155,7 +177,7 @@ double my_atod(const char *number, const char *end, int *error) return val; } -my_bool str_to_TIME(const char *str, uint length, MYSQL_TIME *tm) +my_bool str_to_TIME(const char *str, size_t length, MYSQL_TIME *tm) { my_bool is_time=0, is_date=0, has_time_frac=0; char *p= (char *)str; @@ -197,7 +219,7 @@ my_bool str_to_TIME(const char *str, uint length, MYSQL_TIME *tm) } -static void convert_from_string(MYSQL_BIND *r_param, char *buffer, uint len) +static void convert_from_string(MYSQL_BIND *r_param, char *buffer, size_t len) { int error= 0; switch (r_param->buffer_type) @@ -230,7 +252,7 @@ static void convert_from_string(MYSQL_BIND *r_param, char *buffer, uint len) case MYSQL_TYPE_LONGLONG: { longlong val= my_atoll(buffer, buffer + len, &error); - *r_param->error= error > 0; + *r_param->error= error > 0; /* no need to check for truncation */ longlongstore(r_param->buffer, val); r_param->buffer_length= sizeof(longlong); } @@ -238,18 +260,16 @@ static void convert_from_string(MYSQL_BIND *r_param, char *buffer, uint len) case MYSQL_TYPE_DOUBLE: { double val= my_atod(buffer, buffer + len, &error); - *r_param->error= error > 0; + *r_param->error= error > 0; /* no need to check for truncation */ float8store(r_param->buffer, val); - //*(double *)r_param->buffer= r_param->is_unsigned ? (ulonglong)val : (double)val; r_param->buffer_length= sizeof(double); } break; case MYSQL_TYPE_FLOAT: { - float val= my_atod(buffer, buffer + len, &error); - *r_param->error= error > 0; + float val= (float)my_atod(buffer, buffer + len, &error); + *r_param->error= error > 0; /* no need to check for truncation */ float4store(r_param->buffer, val); -// *(float *)r_param->buffer= r_param->is_unsigned ? (ulonglong)val : (float)val; r_param->buffer_length= sizeof(float); } break; @@ -285,7 +305,7 @@ static void convert_from_string(MYSQL_BIND *r_param, char *buffer, uint len) ((char *)r_param->buffer)[copylen]= '\0'; *r_param->error= (copylen > r_param->buffer_length); - *r_param->length= len; + *r_param->length= (ulong)len; } break; } @@ -340,7 +360,7 @@ static void convert_from_long(MYSQL_BIND *r_param, const MYSQL_FIELD *field, lon char *endptr; uint len; - endptr= int10_to_str(val, buffer, is_unsigned ? 10 : -10); + endptr= longlong10_to_str(val, buffer, is_unsigned ? 10 : -10); len= (uint)(endptr - buffer); /* check if field flag is zerofill */ @@ -485,31 +505,52 @@ static void convert_from_float(MYSQL_BIND *r_param, const MYSQL_FIELD *field, do case MYSQL_TYPE_SHORT: case MYSQL_TYPE_YEAR: { - ushort sval= (r_param->is_unsigned) ? (ushort)val : (short)val; - shortstore(buf, sval); - *r_param->error= check_trunc_val != (r_param->is_unsigned ? *(ushort *)buf : *(short *)buf); + if (r_param->is_unsigned) + { + ushort sval= (ushort)val; + shortstore(buf, sval); + *r_param->error= check_trunc_val != (double)sval; + } else { + short sval= (short)val; + shortstore(buf, sval); + *r_param->error= check_trunc_val != (double)sval; + } r_param->buffer_length= 2; } break; case MYSQL_TYPE_LONG: { - ulong lval= (r_param->is_unsigned) ? (ulong)val : (long)val; - longstore(buf, lval); - *r_param->error= check_trunc_val != (r_param->is_unsigned ? (double)(*(uint32 *)buf) : (double)(*(uint32 *)buf)); + if (r_param->is_unsigned) + { + uint32 lval= (uint32)val; + longstore(buf, lval); + *r_param->error= (check_trunc_val != (double)lval); + } else { + int32 lval= (int32)val; + longstore(buf, lval); + *r_param->error= (check_trunc_val != (double)lval); + } r_param->buffer_length= 4; } break; case MYSQL_TYPE_LONGLONG: { - ulong llval= (r_param->is_unsigned) ? (ulonglong)val : (ulonglong)val; - longlongstore(buf, llval); - *r_param->error= check_trunc_val != (r_param->is_unsigned ? *(ulonglong *)buf : *(longlong *)buf); + if (r_param->is_unsigned) + { + ulonglong llval= (ulonglong)val; + longlongstore(buf, llval); + *r_param->error= (check_trunc_val != (double)llval); + } else { + longlong llval= (longlong)val; + longlongstore(buf, llval); + *r_param->error= (check_trunc_val != (double)llval); + } r_param->buffer_length= 8; } break; case MYSQL_TYPE_FLOAT: { - float fval= (double)val; + float fval= (float)val; memcpy(buf, &fval, sizeof(float)); *r_param->error= (*(float*)buf != fval); r_param->buffer_length= 4; @@ -526,14 +567,14 @@ static void convert_from_float(MYSQL_BIND *r_param, const MYSQL_FIELD *field, do #define MAX_DOUBLE_STRING_REP_LENGTH 300 char buff[MAX_DOUBLE_STRING_REP_LENGTH]; char *end; - int length; + size_t length; length= MIN(MAX_DOUBLE_STRING_REP_LENGTH - 1, r_param->buffer_length); /* TODO: move this to a header shared between client and server. */ if (field->decimals >= NOT_FIXED_DEC) { - sprintf(buff, "%-*.*g", length-1, DBL_DIG, val); + sprintf(buff, "%-*.*g", (int) length-1, DBL_DIG, val); length= strlen(buff); } else @@ -630,7 +671,7 @@ static void convert_to_datetime(MYSQL_TIME *t, unsigned char **row, uint len, en { unsigned char *to= *row; int has_date= 0, has_time= 0; - int offset= 7; + uint offset= 7; if (type == MYSQL_TYPE_TIME) { @@ -740,28 +781,13 @@ static void ps_fetch_string(MYSQL_BIND *r_param, const MYSQL_FIELD *field, unsigned char **row) { + /* C-API differs from PHP. While PHP just converts string to string, + C-API needs to convert the string to the defined type with in + the result bind buffer. + */ ulong field_length= net_field_length(row); - convert_from_string(r_param, (char *)*row, field_length); -/* switch (r_param->buffer_type) - { - case MYSQL_TYPE_STRING: - case MYSQL_TYPE_VAR_STRING: - case MYSQL_TYPE_DECIMAL: - { - ulong c= MIN(r_param->buffer_length, field_length); - memcpy(r_param->buffer, (char *)*row, c); - - if (c < r_param->buffer_length) - ((char *)r_param->buffer)[c]= 0; - r_param->buffer_length= field_length; - *r_param->error= c < field_length; - } - break; - default: - convert_from_string(r_param, (char *)*row, field_length); - break; - } */ + convert_from_string(r_param, (char *)*row, field_length); (*row) += field_length; } /* }}} */ @@ -831,7 +857,7 @@ void mysql_init_ps_subsystem(void) mysql_ps_fetch_functions[MYSQL_TYPE_DATE].pack_len = 5; mysql_ps_fetch_functions[MYSQL_TYPE_DATE].max_len = 10; - mysql_ps_fetch_functions[MYSQL_TYPE_NEWDATE].func = ps_fetch_datetime; + mysql_ps_fetch_functions[MYSQL_TYPE_NEWDATE].func = ps_fetch_string; mysql_ps_fetch_functions[MYSQL_TYPE_NEWDATE].pack_len = MYSQL_PS_SKIP_RESULT_W_LEN; mysql_ps_fetch_functions[MYSQL_TYPE_NEWDATE].max_len = -1; diff --git a/libmysql/my_thr_init.c b/libmysql/my_thr_init.c index 2782576d8..d925f2a04 100644 --- a/libmysql/my_thr_init.c +++ b/libmysql/my_thr_init.c @@ -75,8 +75,8 @@ my_bool my_thread_global_init(void) pthread_mutex_init(&THR_LOCK_heap,MY_MUTEX_INIT_FAST); pthread_mutex_init(&THR_LOCK_net,MY_MUTEX_INIT_FAST); pthread_mutex_init(&THR_LOCK_charset,MY_MUTEX_INIT_FAST); -#if defined( __WIN__) || defined(OS2) - win_pthread_init(); +#ifdef _WIN32 + /* win_pthread_init(); */ #endif #ifndef HAVE_LOCALTIME_R pthread_mutex_init(&LOCK_localtime_r,MY_MUTEX_INIT_SLOW); @@ -115,10 +115,10 @@ static long thread_id=0; my_bool my_thread_init(void) { struct st_my_thread_var *tmp; -#if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX) +#if !defined(_WIN32) || defined(USE_TLS) || ! defined(SAFE_MUTEX) pthread_mutex_lock(&THR_LOCK_lock); #endif -#if !defined(__WIN__) || defined(USE_TLS) +#if !defined(_WIN32) || defined(USE_TLS) if (my_pthread_getspecific(struct st_my_thread_var *,THR_KEY_mysys)) { pthread_mutex_unlock(&THR_LOCK_lock); @@ -137,7 +137,7 @@ my_bool my_thread_init(void) #else if (THR_KEY_mysys.id) /* Already initialized */ { -#if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX) +#if !defined(_WIN32) || defined(USE_TLS) || ! defined(SAFE_MUTEX) pthread_mutex_unlock(&THR_LOCK_lock); #endif return 0; @@ -147,7 +147,7 @@ my_bool my_thread_init(void) tmp->id= ++thread_id; pthread_mutex_init(&tmp->mutex,MY_MUTEX_INIT_FAST); pthread_cond_init(&tmp->suspend, NULL); -#if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX) +#if !defined(_WIN32) || defined(USE_TLS) || ! defined(SAFE_MUTEX) pthread_mutex_unlock(&THR_LOCK_lock); #endif return 0; @@ -169,11 +169,11 @@ void my_thread_end(void) pthread_cond_destroy(&tmp->suspend); #endif pthread_mutex_destroy(&tmp->mutex); -#if (!defined(__WIN__) && !defined(OS2)) || defined(USE_TLS) +#if (!defined(_WIN32) && !defined(OS2)) || defined(USE_TLS) free(tmp); #endif } -#if (!defined(__WIN__) && !defined(OS2)) || defined(USE_TLS) +#if (!defined(_WIN32) && !defined(OS2)) || defined(USE_TLS) pthread_setspecific(THR_KEY_mysys,0); #endif } diff --git a/libmysql/my_vsnprintf.c b/libmysql/my_vsnprintf.c new file mode 100644 index 000000000..9bc33e28b --- /dev/null +++ b/libmysql/my_vsnprintf.c @@ -0,0 +1,119 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +#include "mysys_priv.h" +#include "mysys_err.h" +#include +#include +#include + + +int my_snprintf(char* to, size_t n, const char* fmt, ...) +{ + int result; + va_list args; + va_start(args,fmt); + result= my_vsnprintf(to, n, fmt, args); + va_end(args); + return result; +} + + +int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap) +{ + char *start=to, *end=to+n-1; + for (; *fmt ; fmt++) + { + if (fmt[0] != '%') + { + if (to == end) /* End of buffer */ + break; + *to++= *fmt; /* Copy ordinary char */ + continue; + } + /* Skipp if max size is used (to be compatible with printf) */ + fmt++; + while (isdigit(*fmt) || *fmt == '.' || *fmt == '-') + fmt++; + if (*fmt == 'l') + fmt++; + if (*fmt == 's') /* String parameter */ + { + reg2 char *par = va_arg(ap, char *); + uint plen; + if (!par) par = (char*)"(null)"; + plen = (uint) strlen(par); + if ((uint) (end-to) > plen) /* Replace if possible */ + { + to=strmov(to,par); + continue; + } + } + else if (*fmt == 'd' || *fmt == 'u') /* Integer parameter */ + { + register int iarg; + if ((uint) (end-to) < 16) + break; + iarg = va_arg(ap, int); + if (*fmt == 'd') + to=int10_to_str((long) iarg,to, -10); + else + to=int10_to_str((long) (uint) iarg,to,10); + continue; + } + /* We come here on '%%', unknown code or too long parameter */ + if (to == end) + break; + *to++='%'; /* % used as % or unknown code */ + } + *to='\0'; /* End of errmessage */ + return (uint) (to - start); +} + + +#ifdef MAIN +static void my_printf(const char * fmt, ...) +{ + char buf[32]; + int n; + va_list ar; + va_start(ar, fmt); + n = my_vsnprintf(buf, sizeof(buf),fmt, ar); + printf(buf); + printf("n=%d, strlen=%d\n", n, strlen(buf)); + va_end(ar); +} + + +int main() +{ + + my_printf("Hello\n"); + my_printf("Hello int, %d\n", 1); + my_printf("Hello string '%s'\n", "I am a string"); + my_printf("Hello hack hack hack hack hack hack hack %d\n", 1); + my_printf("Hello %d hack %d\n", 1, 4); + my_printf("Hello %d hack hack hack hack hack %d\n", 1, 4); + my_printf("Hello '%s' hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n", "hack"); + my_printf("Hello hhhhhhhhhhhhhh %d sssssssssssssss\n", 1); + my_printf("Hello %u\n", 1); + my_printf("conn %ld to: '%-.64s' user: '%-.32s' host:\ + `%-.64s' (%-.64s)", 1, 0,0,0,0); + return 0; +} +#endif + diff --git a/libmysql/mysql_charset.c b/libmysql/mysql_charset.c deleted file mode 100644 index 810e15573..000000000 --- a/libmysql/mysql_charset.c +++ /dev/null @@ -1,3304 +0,0 @@ -/**************************************************************************** - Copyright (C) 2011 Monty Program AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not see - or write to the Free Software Foundation, Inc., - 51 Franklin St., Fifth Floor, Boston, MA 02110, USA -*****************************************************************************/ - -/* The implementation for preoared statements was ported from PHP's mysqlnd - extension, written by Andrey Hristov, Georg Richter and Ulf Wendel */ - -#ifndef __WIN__ -#include -#include -#else -#include -#endif -#include -#include - -/* {{{ utf8 functions */ - -static uchar ctype_utf8[] = { - 0, - 32, 32, 32, 32, 32, 32, 32, 32, 32, 40, 40, 40, 40, 40, 32, 32, - 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, - 72, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 132,132,132,132,132,132,132,132,132,132, 16, 16, 16, 16, 16, 16, - 16,129,129,129,129,129,129, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 16, 16, 16, 16, 16, - 16,130,130,130,130,130,130, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 16, 16, 16, 16, 32, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0 -}; - - -static uint check_mb_utf8_sequence(const char *start, const char *end) -{ - unsigned char c; - - if (start >= end) { - return 0; - } - - c = (unsigned char) start[0]; - - if (c < 0x80) { - return 1; /* single byte character */ - } - if (c < 0xC2) { - return 0; /* invalid mb character */ - } - if (c < 0xE0) { - if (start + 2 > end) { - return 0; /* too small */ - } - if (!(((unsigned char)start[1] ^ 0x80) < 0x40)) { - return 0; - } - return 2; - } - if (c < 0xF0) { - if (start + 3 > end) { - return 0; /* too small */ - } - if (!(((unsigned char)start[1] ^ 0x80) < 0x40 && ((unsigned char)start[2] ^ 0x80) < 0x40 && - (c >= 0xE1 || (unsigned char)start[1] >= 0xA0))) { - return 0; /* invalid utf8 character */ - } - return 3; - } - return 0; -} - -static uint check_mb_utf8_valid(const char *start, const char *end) -{ - uint len = check_mb_utf8_sequence(start, end); - return (len > 1)? len:0; -} - -static uint mysql_mbcharlen_utf8(uint utf8) -{ - if (utf8 < 0x80) { - return 1; /* single byte character */ - } - if (utf8 < 0xC2) { - return 0; /* invalid multibyte header */ - } - if (utf8 < 0xE0) { - return 2; /* double byte character */ - } - if (utf8 < 0xF0) { - return 3; /* triple byte character */ - } - /* We still don't support characters out of the BMP */ - - return 0; -} -/* }}} */ - -/* {{{ utf16 functions */ -#define UTF16_HIGH_HEAD(x) ((((uchar) (x)) & 0xFC) == 0xD8) -#define UTF16_LOW_HEAD(x) ((((uchar) (x)) & 0xFC) == 0xDC) - -static unsigned int check_mb_utf16(const char *start, const char *end) -{ - if (start + 2 > end) { - return 0; - } - - if (UTF16_HIGH_HEAD(*start)) { - return (start + 4 <= end) && UTF16_LOW_HEAD(start[2]) ? 4 : 0; - } - - if (UTF16_LOW_HEAD(*start)) { - return 0; - } - return 2; -} - - -static uint mysql_mbcharlen_utf16(unsigned int utf16) -{ - return UTF16_HIGH_HEAD(utf16) ? 4 : 2; -} -/* }}} */ - - -/* {{{ utf32 functions */ -static uint -check_mb_utf32(const char *start __attribute((unused)), const char *end __attribute((unused))) -{ - return 4; -} - - -static uint -mysql_mbcharlen_utf32(unsigned int utf32 __attribute((unused))) -{ - return 4; -} -/* }}} */ - - -/* {{{ big5 functions */ -uchar ctype_big5[257] = -{ - 0, /* For standard library */ - 32,32,32,32,32,32,32,32,32,40,40,40,40,40,32,32, - 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, - 72,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, - 132,132,132,132,132,132,132,132,132,132,16,16,16,16,16,16, - 16,129,129,129,129,129,129,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,16,16,16,16,16, - 16,130,130,130,130,130,130,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,16,16,16,16,32, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -}; - - -#define valid_big5head(c) (0xA1 <= (uint)(c) && (uint)(c) <= 0xF9) -#define valid_big5tail(c) ((0x40 <= (uint)(c) && (uint)(c) <= 0x7E) || \ - (0xA1 <= (uint)(c) && (uint)(c) <= 0xFE)) - -#define isbig5code(c,d) (isbig5head(c) && isbig5tail(d)) - -static uint check_mb_big5(const char *start, const char *end) -{ - return (valid_big5head(*(start)) && (end - start) > 1 && valid_big5tail(*(start + 1)) ? 2 : 0); -} - - -static uint mysql_mbcharlen_big5(uint big5) -{ - return (valid_big5head(big5)) ? 2 : 1; -} -/* }}} */ - - -/* {{{ cp932 functions */ -static uchar ctype_cp932[257] = -{ - 0, /* For standard library */ - 0040, 0040, 0040, 0040, 0040, 0040, 0040, 0040, /* NUL ^A - ^G */ - 0040, 0050, 0050, 0050, 0050, 0050, 0040, 0040, /* ^H - ^O */ - 0040, 0040, 0040, 0040, 0040, 0040, 0040, 0040, /* ^P - ^W */ - 0040, 0040, 0040, 0040, 0040, 0040, 0040, 0040, /* ^X - ^Z ^[ ^\ ^] ^^ ^_ */ - 0110, 0020, 0020, 0020, 0020, 0020, 0020, 0020, /* SPC ! " # $ % ^ ' */ - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, /* ( ) * + , - . / */ - 0204, 0204, 0204, 0204, 0204, 0204, 0204, 0204, /* 0 1 2 3 4 5 6 7 */ - 0204, 0204, 0020, 0020, 0020, 0020, 0020, 0020, /* 8 9 : ; < = > ? */ - 0020, 0201, 0201, 0201, 0201, 0201, 0201, 0001, /* @ A B C D E F G */ - 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, /* H I J K L M N O */ - 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, /* P Q R S T U V W */ - 0001, 0001, 0001, 0020, 0020, 0020, 0020, 0020, /* X Y Z [ \ ] ^ _ */ - 0020, 0202, 0202, 0202, 0202, 0202, 0202, 0002, /* ` a b c d e f g */ - 0002, 0002, 0002, 0002, 0002, 0002, 0002, 0002, /* h i j k l m n o */ - 0002, 0002, 0002, 0002, 0002, 0002, 0002, 0002, /* p q r s t u v w */ - 0002, 0002, 0002, 0020, 0020, 0020, 0020, 0040, /* x y z { | } + DEL */ - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0000, 0000, 0000 -}; - - -#define valid_cp932head(c) ((0x81 <= (c) && (c) <= 0x9F) || (0xE0 <= (c) && c <= 0xFC)) -#define valid_cp932tail(c) ((0x40 <= (c) && (c) <= 0x7E) || (0x80 <= (c) && c <= 0xFC)) - - -static uint check_mb_cp932(const char *start, const char *end) -{ - return (valid_cp932head((unsigned char)start[0]) && (end - start > 1) && - valid_cp932tail((unsigned char)start[1])) ? 2 : 0; -} - - -static uint mysql_mbcharlen_cp932(uint cp932) -{ - return (valid_cp932head((unsigned char)cp932)) ? 2 : 1; -} -/* }}} */ - - -/* {{{ euckr functions */ -#define valid_euckr(c) ((0xA1 <= (unsigned char)(c) && (unsigned char)(c) <= 0xFE)) - -static uint check_mb_euckr(const char *start, const char *end) -{ - if (end - start <= 1) { - return 0; /* invalid length */ - } - if (*(unsigned char *)start < 0x80) { - return 0; /* invalid euckr character */ - } - if (valid_euckr(start[1])) { - return 2; - } - return 0; -} - - -static uint mysql_mbcharlen_euckr(uint kr) -{ - return (valid_euckr(kr)) ? 2 : 1; -} -/* }}} */ - - -/* {{{ eucjpms functions */ -#define valid_eucjpms(c) (((c) & 0xFF) >= 0xA1 && ((c) & 0xFF) <= 0xFE) -#define valid_eucjpms_kata(c) (((c) & 0xFF) >= 0xA1 && ((c) & 0xFF) <= 0xDF) -#define valid_eucjpms_ss2(c) (((c) & 0xFF) == 0x8E) -#define valid_eucjpms_ss3(c) (((c) & 0xFF) == 0x8F) - -static uint check_mb_eucjpms(const char *start, const char *end) -{ - if (*((unsigned char *)start) < 0x80) { - return 0; /* invalid eucjpms character */ - } - if (valid_eucjpms(start[0]) && (end - start) > 1 && valid_eucjpms(start[1])) { - return 2; - } - if (valid_eucjpms_ss2(start[0]) && (end - start) > 1 && valid_eucjpms_kata(start[1])) { - return 2; - } - if (valid_eucjpms_ss3(start[0]) && (end - start) > 2 && valid_eucjpms(start[1]) && - valid_eucjpms(start[2])) { - return 2; - } - return 0; -} - - -static uint mysql_mbcharlen_eucjpms(uint jpms) -{ - if (valid_eucjpms(jpms) || valid_eucjpms_ss2(jpms)) { - return 2; - } - if (valid_eucjpms_ss3(jpms)) { - return 3; - } - return 1; -} -/* }}} */ - - -/* {{{ gb2312 functions */ -#define valid_gb2312_head(c) (0xA1 <= (unsigned char)(c) && (unsigned char)(c) <= 0xF7) -#define valid_gb2312_tail(c) (0xA1 <= (unsigned char)(c) && (unsigned char)(c) <= 0xFE) - - -static uint check_mb_gb2312(const char *start, const char *end) -{ - return (valid_gb2312_head((uint)start[0]) && end - start > 1 && - valid_gb2312_tail((uint)start[1])) ? 2 : 0; -} - - -static uint mysql_mbcharlen_gb2312(uint gb) -{ - return (valid_gb2312_head(gb)) ? 2 : 1; -} -/* }}} */ - - -/* {{{ gbk functions */ -#define valid_gbk_head(c) (0x81<=(unsigned char)(c) && (unsigned char)(c)<=0xFE) -#define valid_gbk_tail(c) ((0x40<=(unsigned char)(c) && (unsigned char)(c)<=0x7E) || (0x80<=(unsigned char)(c) && (unsigned char)(c)<=0xFE)) - -static uint check_mb_gbk(const char *start, const char *end) -{ - return (valid_gbk_head(start[0]) && (end) - (start) > 1 && valid_gbk_tail(start[1])) ? 2 : 0; -} - -static uint mysql_mbcharlen_gbk(uint gbk) -{ - return (valid_gbk_head(gbk) ? 2 : 1); -} -/* }}} */ - - -/* {{{ sjis functions */ -#define valid_sjis_head(c) ((0x81 <= (c) && (c) <= 0x9F) && \ - (0xE0 <= (c) && (c) <= 0xFC)) -#define valid_sjis_tail(c) ((0x40 <= (c) && (c) <= 0x7E) && \ - (0x80 <= (c) && (c) <= 0x7C)) -uchar ctype_sjis[257] = -{ - 0, /* For standard library */ - 0040, 0040, 0040, 0040, 0040, 0040, 0040, 0040, /* NUL ^A - ^G */ - 0040, 0050, 0050, 0050, 0050, 0050, 0040, 0040, /* ^H - ^O */ - 0040, 0040, 0040, 0040, 0040, 0040, 0040, 0040, /* ^P - ^W */ - 0040, 0040, 0040, 0040, 0040, 0040, 0040, 0040, /* ^X - ^Z ^[ ^\ ^] ^^ ^_ */ - 0110, 0020, 0020, 0020, 0020, 0020, 0020, 0020, /* SPC ! " # $ % ^ ' */ - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, /* ( ) * + , - . / */ - 0204, 0204, 0204, 0204, 0204, 0204, 0204, 0204, /* 0 1 2 3 4 5 6 7 */ - 0204, 0204, 0020, 0020, 0020, 0020, 0020, 0020, /* 8 9 : ; < = > ? */ - 0020, 0201, 0201, 0201, 0201, 0201, 0201, 0001, /* @ A B C D E F G */ - 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, /* H I J K L M N O */ - 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, /* P Q R S T U V W */ - 0001, 0001, 0001, 0020, 0020, 0020, 0020, 0020, /* X Y Z [ \ ] ^ _ */ - 0020, 0202, 0202, 0202, 0202, 0202, 0202, 0002, /* ` a b c d e f g */ - 0002, 0002, 0002, 0002, 0002, 0002, 0002, 0002, /* h i j k l m n o */ - 0002, 0002, 0002, 0002, 0002, 0002, 0002, 0002, /* p q r s t u v w */ - 0002, 0002, 0002, 0020, 0020, 0020, 0020, 0040, /* x y z { | } + DEL */ - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0000, 0000, 0000 -}; - - -static uint check_mb_sjis(const char *start, const char *end) -{ - return (valid_sjis_head((unsigned char)start[0]) && (end - start) > 1 && valid_sjis_tail((unsigned char)start[1])) ? 2 : 0; -} - - -static uint mysql_mbcharlen_sjis(uint sjis) -{ - return (valid_sjis_head((unsigned char)sjis)) ? 2 : 1; -} -/* }}} */ - - -/* {{{ ucs2 functions */ -static uint check_mb_ucs2(const char *start __attribute__((unused)), const char *end __attribute__((unused))) -{ - return 2; /* always 2 */ -} - -static uint mysql_mbcharlen_ucs2(uint ucs2 __attribute__((unused))) -{ - return 2; /* always 2 */ -} -/* }}} */ - - -/* {{{ ujis functions */ -#define valid_ujis(c) ((0xA1 <= ((c)&0xFF) && ((c)&0xFF) <= 0xFE)) -#define valid_ujis_kata(c) ((0xA1 <= ((c)&0xFF) && ((c)&0xFF) <= 0xDF)) -#define valid_ujis_ss2(c) (((c)&0xFF) == 0x8E) -#define valid_ujis_ss3(c) (((c)&0xFF) == 0x8F) - -uchar ctype_ujis[257] = -{ - 0, /* For standard library */ - 0040, 0040, 0040, 0040, 0040, 0040, 0040, 0040, /* NUL ^A - ^G */ - 0040, 0050, 0050, 0050, 0050, 0050, 0040, 0040, /* ^H - ^O */ - 0040, 0040, 0040, 0040, 0040, 0040, 0040, 0040, /* ^P - ^W */ - 0040, 0040, 0040, 0040, 0040, 0040, 0040, 0040, /* ^X - ^Z ^[ ^\ ^] ^^ ^_ */ - 0110, 0020, 0020, 0020, 0020, 0020, 0020, 0020, /* SPC ! " # $ % ^ ' */ - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, /* ( ) * + , - . / */ - 0204, 0204, 0204, 0204, 0204, 0204, 0204, 0204, /* 0 1 2 3 4 5 6 7 */ - 0204, 0204, 0020, 0020, 0020, 0020, 0020, 0020, /* 8 9 : ; < = > ? */ - 0020, 0201, 0201, 0201, 0201, 0201, 0201, 0001, /* @ A B C D E F G */ - 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, /* H I J K L M N O */ - 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, /* P Q R S T U V W */ - 0001, 0001, 0001, 0020, 0020, 0020, 0020, 0020, /* X Y Z [ \ ] ^ _ */ - 0020, 0202, 0202, 0202, 0202, 0202, 0202, 0002, /* ` a b c d e f g */ - 0002, 0002, 0002, 0002, 0002, 0002, 0002, 0002, /* h i j k l m n o */ - 0002, 0002, 0002, 0002, 0002, 0002, 0002, 0002, /* p q r s t u v w */ - 0002, 0002, 0002, 0020, 0020, 0020, 0020, 0040, /* x y z { | } + DEL */ - 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, - 0000, 0000, 0000, 0000, 0000, 0000, 0020, 0020, - 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, - 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, - 0000, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0020, - 0020, 0020, 0020, 0020, 0020, 0020, 0020, 0000, -}; - - - -static uint check_mb_ujis(const char *start, const char *end) -{ - if (*(unsigned char*)start < 0x80) { - return 0; /* invalid ujis character */ - } - if (valid_ujis(*(start)) && valid_ujis(*((start)+1))) { - return 2; - } - if (valid_ujis_ss2(*(start)) && valid_ujis_kata(*((start)+1))) { - return 2; - } - if (valid_ujis_ss3(*(start)) && (end-start) > 2 && valid_ujis(*((start)+1)) && valid_ujis(*((start)+2))) { - return 3; - } - return 0; -} - - -static uint mysql_mbcharlen_ujis(uint ujis) -{ - return (valid_ujis(ujis)? 2: valid_ujis_ss2(ujis)? 2: valid_ujis_ss3(ujis)? 3: 1); -} -/* }}} */ - -uchar ctype_dec8_swedish_ci[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02 -}; - - -uchar ctype_cp850_general_ci[] = { -0x00, -0x20,0x30,0x30,0x30,0x30,0x30,0x30,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x30,0x30, -0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x20,0x30,0x30,0x30,0x30,0x30, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x30, -0x01,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x01,0x01, -0x01,0x02,0x01,0x02,0x02,0x02,0x02,0x02,0x02,0x01,0x01,0x02,0x10,0x01,0x10,0x10, -0x02,0x02,0x02,0x02,0x02,0x01,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x10,0x10,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x10,0x10,0x10,0x02,0x01,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x02,0x01,0x01,0x01,0x01,0x02,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10,0x01,0x10, -0x01,0x02,0x01,0x01,0x02,0x01,0x10,0x02,0x01,0x01,0x01,0x01,0x02,0x01,0x10,0x10, -0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x20 -}; - -uchar ctype_hp8_english_ci[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x20,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x20,0x20,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x10,0x10,0x02,0x10,0x10,0x10,0x10,0x10,0x10,0x02,0x10,0x02,0x02, -0x01,0x10,0x10,0x01,0x02,0x10,0x10,0x02,0x01,0x10,0x01,0x01,0x01,0x10,0x10,0x10, -0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x20,0x20,0x20,0x20,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x20 -}; - - -uchar ctype_koi8r_general_ci[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x02,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x01,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01 -}; - -static uchar ctype_latin1[] = { - 0, - 32, 32, 32, 32, 32, 32, 32, 32, 32, 40, 40, 40, 40, 40, 32, 32, - 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, - 72, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 132,132,132,132,132,132,132,132,132,132, 16, 16, 16, 16, 16, 16, - 16,129,129,129,129,129,129, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 16, 16, 16, 16, 16, - 16,130,130,130,130,130,130, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 16, 16, 16, 16, 32, - 16, 0, 16, 2, 16, 16, 16, 16, 16, 16, 1, 16, 1, 0, 1, 0, - 0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 2, 16, 2, 0, 2, 1, - 72, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 16, 1, 1, 1, 1, 1, 1, 1, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 16, 2, 2, 2, 2, 2, 2, 2, 2 -}; - - -uchar ctype_latin1_general_ci[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x10,0x00,0x10,0x02,0x10,0x10,0x10,0x10,0x10,0x10,0x01,0x10,0x01,0x00,0x01,0x00, -0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x02,0x10,0x02,0x00,0x02,0x01, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02 -}; - -uchar ctype_latin1_general_cs[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x10,0x00,0x10,0x02,0x10,0x10,0x10,0x10,0x10,0x10,0x01,0x10,0x01,0x00,0x01,0x00, -0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x02,0x10,0x02,0x00,0x02,0x01, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02 -}; - -uchar ctype_latin2_general_ci[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x48,0x01,0x10,0x01,0x10,0x01,0x01,0x10,0x10,0x01,0x01,0x01,0x01,0x10,0x01,0x01, -0x10,0x02,0x10,0x02,0x10,0x02,0x02,0x10,0x10,0x02,0x02,0x02,0x02,0x10,0x02,0x02, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x10,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10 -}; - -uchar ctype_cp1251_bin[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x00, -0x01,0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x01,0x01,0x01, -0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x02,0x02,0x02,0x02, -0x00,0x01,0x02,0x01,0x00,0x01,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x00,0x01, -0x00,0x00,0x01,0x02,0x02,0x00,0x00,0x00,0x02,0x00,0x02,0x00,0x02,0x01,0x02,0x02, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02 -}; - -uchar ctype_cp1251_general_ci[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x00, -0x01,0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x01,0x01,0x01, -0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x02,0x02,0x02,0x02, -0x00,0x01,0x02,0x01,0x00,0x01,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x00,0x01, -0x00,0x00,0x01,0x02,0x02,0x00,0x00,0x00,0x02,0x00,0x02,0x00,0x02,0x01,0x02,0x02, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02 -}; - -uchar ctype_cp1251_general_cs[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x00, -0x01,0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x01,0x01,0x01, -0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x02,0x02,0x02,0x02, -0x00,0x01,0x02,0x01,0x00,0x01,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x00,0x01, -0x00,0x00,0x01,0x02,0x02,0x00,0x00,0x00,0x02,0x00,0x02,0x00,0x02,0x01,0x02,0x02, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02 -}; - -char ctype_macroman_bin[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x10, -0x20,0x01,0x01,0x01,0x01,0x01,0x01,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02, -0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x01,0x01,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x20,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x00,0x01,0x01,0x01,0x01,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 -}; - -uchar ctype_cp1256_general_ci[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x00,0x00, -0x00,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x00,0x03,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x03,0x00, -0x03,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00, -0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x00,0x00, -0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x00,0x00,0x00,0x10, -0x00,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03, -0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x00,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03, -0x02,0x03,0x02,0x03,0x03,0x03,0x03,0x02,0x02,0x02,0x02,0x02,0x03,0x03,0x02,0x02, -0x03,0x03,0x03,0x03,0x02,0x03,0x03,0x00,0x03,0x02,0x03,0x02,0x02,0x00,0x00,0x00 -}; - -uchar ctype_cp1257_bin[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x00,0x01, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x02, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00 -}; - -uchar ctype_cp1257_general_ci[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x00,0x01, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x02, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00 -}; - -uchar ctype_armscii8_bin[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02, -0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02, -0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02, -0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02, -0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x10,0x10 -}; - -uchar ctype_cp1250_bin[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x20,0x20,0x10,0x20,0x10,0x10,0x10,0x10,0x20,0x10,0x01,0x10,0x01,0x01,0x01,0x01, -0x20,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x20,0x10,0x02,0x10,0x02,0x02,0x02,0x02, -0x48,0x10,0x10,0x01,0x10,0x01,0x10,0x01,0x10,0x10,0x01,0x10,0x10,0x10,0x10,0x01, -0x10,0x10,0x10,0x02,0x10,0x10,0x10,0x10,0x10,0x02,0x02,0x10,0x01,0x10,0x02,0x02, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10 -}; - -uchar ctype_cp1256_bin[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x00,0x00, -0x00,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x00,0x03,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x03,0x00, -0x03,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00, -0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x00,0x00, -0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x00,0x00,0x00,0x10, -0x00,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03, -0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x00,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03, -0x02,0x03,0x02,0x03,0x03,0x03,0x03,0x02,0x02,0x02,0x02,0x02,0x03,0x03,0x02,0x02, -0x03,0x03,0x03,0x03,0x02,0x03,0x03,0x00,0x03,0x02,0x03,0x02,0x02,0x00,0x00,0x00 -}; - -uchar ctype_cp866_bin[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x00, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48 -}; - -uchar ctype_dec8_bin[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02 -}; - -uchar ctype_greek_bin[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x48,0x10,0x10,0x10,0x00,0x00,0x10,0x10,0x10,0x10,0x00,0x10,0x10,0x10,0x00,0x10, -0x10,0x10,0x10,0x10,0x10,0x10,0x01,0x10,0x01,0x01,0x01,0x10,0x01,0x10,0x01,0x01, -0x02,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00 -}; - -uchar ctype_hebrew_general_ci[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x00,0x20,0x20,0x00 -}; - -uchar ctype_hebrew_bin[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x00,0x20,0x20,0x00 -}; - -uchar ctype_keybcs2_bin[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x00, -0x01,0x02,0x82,0x02,0x02,0x01,0x01,0x02,0x82,0x81,0x01,0x01,0x02,0x02,0x01,0x01, -0x81,0x02,0x01,0x02,0x02,0x01,0x02,0x01,0x02,0x01,0x01,0x01,0x01,0x01,0x01,0x02, -0x02,0x02,0x02,0x02,0x02,0x01,0x01,0x01,0x02,0x02,0x02,0x01,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x02,0x02,0x01,0x02,0x01,0x02,0x00,0x02,0x01,0x01,0x01,0x02,0x00,0x02,0x02,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x48 -}; - -uchar ctype_koi8r_bin[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x02,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x01,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01 -}; - -uchar ctype_koi8u_bin[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x02,0x02,0x10,0x02,0x02,0x10,0x10,0x10,0x10,0x10,0x02,0x10,0x10, -0x10,0x10,0x10,0x01,0x01,0x10,0x01,0x01,0x10,0x10,0x10,0x10,0x10,0x01,0x10,0x10, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01 -}; - -uchar ctype_latin2_bin[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x48,0x01,0x10,0x01,0x10,0x01,0x01,0x10,0x10,0x01,0x01,0x01,0x01,0x10,0x01,0x01, -0x10,0x02,0x10,0x02,0x10,0x02,0x02,0x10,0x10,0x02,0x02,0x02,0x02,0x10,0x02,0x02, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x10,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10 -}; - -uchar ctype_latin5_bin[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02 -}; - -uchar ctype_latin7_bin[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x01,0x20,0x10,0x20,0x10,0x10,0x00,0x00,0x20,0x10,0x20,0x10,0x20,0x10,0x10,0x10, -0x20,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x20,0x00,0x20,0x10,0x20,0x10,0x10,0x20, -0x48,0x20,0x10,0x10,0x10,0x20,0x10,0x10,0x10,0x10,0x01,0x10,0x10,0x10,0x10,0x01, -0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x02,0x10,0x10,0x10,0x10,0x02, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10 -}; - -uchar ctype_cp850_bin[] = { -0x00, -0x20,0x30,0x30,0x30,0x30,0x30,0x30,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x30,0x30, -0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x20,0x30,0x30,0x30,0x30,0x30, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x30, -0x01,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x01,0x01, -0x01,0x02,0x01,0x02,0x02,0x02,0x02,0x02,0x02,0x01,0x01,0x02,0x10,0x01,0x10,0x10, -0x02,0x02,0x02,0x02,0x02,0x01,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x10,0x10,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x10,0x10,0x10,0x02,0x01,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x02,0x01,0x01,0x01,0x01,0x02,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10,0x01,0x10, -0x01,0x02,0x01,0x01,0x02,0x01,0x10,0x02,0x01,0x01,0x01,0x01,0x02,0x01,0x10,0x10, -0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x20 -}; - -uchar ctype_cp852_bin[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x00, -0x01,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x01,0x02,0x02,0x01,0x01,0x01, -0x01,0x01,0x02,0x02,0x02,0x01,0x02,0x01,0x02,0x01,0x01,0x01,0x02,0x01,0x00,0x02, -0x02,0x02,0x02,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x00,0x02,0x01,0x01,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x02,0x00,0x00,0x00,0x00,0x01,0x02,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x02,0x01,0x01,0x01,0x02,0x01,0x01,0x01,0x02,0x00,0x00,0x00,0x00,0x01,0x01,0x00, -0x01,0x02,0x01,0x01,0x02,0x02,0x01,0x02,0x01,0x01,0x02,0x01,0x02,0x01,0x02,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x01,0x02,0x00,0x48 -}; - -uchar ctype_swe7_swedish_ci[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x01,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10, -0x01,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x20, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 -}; - -uchar ctype_swe7_bin[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x01,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10, -0x01,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x20, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 -}; - -uchar ctype_geostd8_general_ci[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x00,0x00,0x10,0x00,0x10,0x10,0x10,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x00, -0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00, -0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03, -0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03, -0x03,0x03,0x03,0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 -}; - -uchar ctype_geostd8_bin[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x00,0x00,0x10,0x00,0x10,0x10,0x10,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x00, -0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00, -0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03, -0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03, -0x03,0x03,0x03,0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 -}; - -uchar ctype_latin1_spanish_ci[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x10,0x00,0x10,0x02,0x10,0x10,0x10,0x10,0x10,0x10,0x01,0x10,0x01,0x00,0x01,0x00, -0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x02,0x10,0x02,0x00,0x02,0x01, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02 -}; - -uchar ctype_cp1250_polish_ci[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x20,0x20,0x10,0x20,0x10,0x10,0x10,0x10,0x20,0x10,0x01,0x10,0x01,0x01,0x01,0x01, -0x20,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x20,0x10,0x02,0x10,0x02,0x02,0x02,0x02, -0x48,0x10,0x10,0x01,0x10,0x01,0x10,0x01,0x10,0x10,0x01,0x10,0x10,0x10,0x10,0x01, -0x10,0x10,0x10,0x02,0x10,0x10,0x10,0x10,0x10,0x02,0x02,0x10,0x01,0x10,0x02,0x02, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10 -}; - -uchar ctype_ascii_general_ci[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 -}; - -uchar ctype_ascii_bin[] = { -0x00, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x28,0x28,0x28,0x28,0x20,0x20, -0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, -0x48,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, -0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x10,0x10,0x10,0x10,0x10, -0x10,0x81,0x81,0x81,0x81,0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, -0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x10,0x10,0x10,0x10,0x10, -0x10,0x82,0x82,0x82,0x82,0x82,0x82,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, -0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x10,0x10,0x10,0x10,0x20, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 -}; - -/* {{{ compiled_charsets */ -const CHARSET_INFO compiled_charsets[] = -{ - { 1, "big5","big5_chinese_ci", 1, 2, mysql_mbcharlen_big5, check_mb_big5, ctype_big5}, - { 3, "dec8", "dec8_swedish_ci", 1, 1, NULL, NULL, ctype_dec8_swedish_ci}, - { 4, "cp850", "cp850_general_ci", 1, 1, NULL, NULL, ctype_cp850_general_ci}, - { 6, "hp8", "hp8_english_ci", 1, 1, NULL, NULL, ctype_hp8_english_ci}, - { 7, "koi8r", "koi8r_general_ci", 1, 1, NULL, NULL, ctype_koi8r_general_ci}, - { 8, "latin1", "latin1_swedish_ci", 1, 1, NULL, NULL, ctype_latin1}, - { 9, "latin2", "latin2_general_ci", 1, 1, NULL, NULL, ctype_latin2_general_ci}, - { 10, "swe7", "swe7_swedish_ci", 1, 1, NULL, NULL, ctype_swe7_swedish_ci}, - { 11, "ascii", "ascii_general_ci", 1, 1, NULL, NULL, ctype_ascii_general_ci}, - { 12, "ujis", "ujis_japanese_ci", 1, 3, mysql_mbcharlen_ujis, check_mb_ujis, ctype_ujis}, - { 13, "sjis", "sjis_japanese_ci", 1, 2, mysql_mbcharlen_sjis, check_mb_sjis, ctype_sjis,}, - { 16, "hebrew", "hebrew_general_ci", 1, 1, NULL, NULL, ctype_hebrew_general_ci}, - { 18, "tis620", "tis620_thai_ci", 1, 1, NULL, NULL}, - { 19, "euckr", "euckr_korean_ci", 1, 2, mysql_mbcharlen_euckr, check_mb_euckr}, - { 22, "koi8u", "koi8u_general_ci", 1, 1, NULL, NULL}, - { 24, "gb2312", "gb2312_chinese_ci", 1, 2, mysql_mbcharlen_gb2312, check_mb_gb2312}, - { 25, "greek", "greek_general_ci", 1, 1, NULL, NULL}, - { 26, "cp1250", "cp1250_general_ci", 1, 1, NULL, NULL}, - { 28, "gbk", "gbk_chinese_ci", 1, 2, mysql_mbcharlen_gbk, check_mb_gbk}, - { 30, "latin5", "latin5_turkish_ci", 1, 1, NULL, NULL}, - { 32, "armscii8", "armscii8_general_ci", 1, 1, NULL, NULL}, - { 33, "utf8", "utf8_general_ci", 1, 2, mysql_mbcharlen_utf8, check_mb_utf8_valid}, - { 35, "ucs2", "ucs2_general_ci", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 36, "cp866", "cp866_general_ci", 1, 1, NULL, NULL}, - { 37, "keybcs2", "keybcs2_general_ci", 1, 1, NULL, NULL}, - { 38, "macce", "macce_general_ci", 1, 1, NULL, NULL}, - { 39, "macroman", "macroman_general_ci", 1, 1, NULL, NULL}, - { 40, "cp852", "cp852_general_ci", 1, 1, NULL, NULL}, - { 41, "latin7", "latin7_general_ci", 1, 1, NULL, NULL}, - { 51, "cp1251", "cp1251_general_ci", 1, 1, NULL, NULL}, - { 57, "cp1256", "cp1256_general_ci", 1, 1, NULL, NULL}, - { 59, "cp1257", "cp1257_general_ci", 1, 1, NULL, NULL}, - { 63, "binary", "binary", 1, 1, NULL, NULL}, - { 92, "geostd8", "geostd8_general_ci", 1, 1, NULL, NULL}, - { 95, "cp932", "cp932_japanese_ci", 1, 2, mysql_mbcharlen_cp932, check_mb_cp932}, - { 97, "eucjpms", "eucjpms_japanese_ci", 1, 3, mysql_mbcharlen_eucjpms, check_mb_eucjpms}, - { 2, "latin2", "latin2_czech_cs", 1, 1, NULL, NULL}, - { 5, "latin1", "latin1_german_ci", 1, 1, NULL, NULL}, - { 14, "cp1251", "cp1251_bulgarian_ci", 1, 1, NULL, NULL}, - { 15, "latin1", "latin1_danish_ci", 1, 1, NULL, NULL}, - { 17, "filename", "filename", 1, 5, NULL, NULL}, - { 20, "latin7", "latin7_estonian_cs", 1, 1, NULL, NULL}, - { 21, "latin2", "latin2_hungarian_ci", 1, 1, NULL, NULL}, - { 23, "cp1251", "cp1251_ukrainian_ci", 1, 1, NULL, NULL}, - { 27, "latin2", "latin2_croatian_ci", 1, 1, NULL, NULL}, - { 29, "cp1257", "cp1257_lithunian_ci", 1, 1, NULL, NULL}, - { 31, "latin1", "latin1_german2_ci", 1, 1, NULL, NULL}, - { 34, "cp1250", "cp1250_czech_cs", 1, 1, NULL, NULL}, - { 42, "latin7", "latin7_general_cs", 1, 1, NULL, NULL}, - { 43, "macce", "macce_bin", 1, 1, NULL, NULL}, - { 44, "cp1250", "cp1250_croatian_ci", 1, 1, NULL, NULL}, - { 47, "latin1", "latin1_bin", 1, 1, NULL, NULL}, - { 48, "latin1", "latin1_general_ci", 1, 1, NULL, NULL}, - { 49, "latin1", "latin1_general_cs", 1, 1, NULL, NULL}, - { 50, "cp1251", "cp1251_bin", 1, 1, NULL, NULL}, - { 52, "cp1251", "cp1251_general_cs", 1, 1, NULL, NULL}, - { 53, "macroman", "macroman_bin", 1, 1, NULL, NULL}, - { 54, "utf16", "utf16_general_ci", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, - { 55, "utf16", "utf16_bin", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, - { 58, "cp1257", "cp1257_bin", 1, 1, NULL, NULL}, - { 60, "utf32", "utf32_general_ci", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, - { 61, "utf32", "utf32_bin", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, -// { 60, "armascii8", "armascii8_bin", 1, 1, NULL, NULL}, - { 65, "ascii", "ascii_bin", 1, 1, NULL, NULL, ctype_ascii_bin}, - { 66, "cp1250", "cp1250_bin", 1, 1, NULL, NULL}, - { 67, "cp1256", "cp1256_bin", 1, 1, NULL, NULL}, - { 68, "cp866", "cp866_bin", 1, 1, NULL, NULL}, - { 69, "dec8", "dec8_bin", 1, 1, NULL, NULL}, - { 70, "greek", "greek_bin", 1, 1, NULL, NULL}, - { 71, "hebew", "hebrew_bin", 1, 1, NULL, NULL, ctype_hebrew_bin}, - { 72, "hp8", "hp8_bin", 1, 1, NULL, NULL}, - { 73, "keybcs2", "keybcs2_bin", 1, 1, NULL, NULL}, - { 74, "koi8r", "koi8r_bin", 1, 1, NULL, NULL}, - { 75, "koi8u", "koi8u_bin", 1, 1, NULL, NULL}, - { 77, "latin2", "latin2_bin", 1, 1, NULL, NULL}, - { 78, "latin5", "latin5_bin", 1, 1, NULL, NULL}, - { 79, "latin7", "latin7_bin", 1, 1, NULL, NULL}, - { 80, "cp850", "cp850_bin", 1, 1, NULL, NULL}, - { 81, "cp852", "cp852_bin", 1, 1, NULL, NULL}, - { 82, "swe7", "swe7_bin", 1, 1, NULL, NULL}, - { 93, "geostd8", "geostd8_bin", 1, 1, NULL, NULL}, - { 83, "utf8", "utf8_bin", 1, 2, mysql_mbcharlen_utf8, check_mb_utf8_valid}, - { 84, "big5", "big5_bin", 1, 2, mysql_mbcharlen_big5, check_mb_big5}, - { 85, "euckr", "euckr_bin", 1, 2, mysql_mbcharlen_euckr, check_mb_euckr}, - { 86, "gb2312", "gb2312_bin", 1, 2, mysql_mbcharlen_gb2312, check_mb_gb2312}, - { 87, "gbk", "gbk_bin", 1, 2, mysql_mbcharlen_gbk, check_mb_gbk}, - { 88, "sjis", "sjis_bin", 1, 2, mysql_mbcharlen_sjis, check_mb_sjis}, - { 89, "tis620", "tis620_bin", 1, 1, NULL, NULL}, - { 90, "ucs2", "ucs2_bin", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 91, "ujis", "ujis_bin", 1, 3, mysql_mbcharlen_ujis, check_mb_ujis}, - { 94, "latin1", "latin1_spanish_ci", 1, 1, NULL, NULL}, - { 96, "cp932", "cp932_bin", 1, 2, mysql_mbcharlen_cp932, check_mb_cp932, ctype_cp932}, - { 99, "cp1250", "cp1250_polish_ci", 1, 1, NULL, NULL}, - { 98, "eucjpms", "eucjpms_bin", 1, 3, mysql_mbcharlen_eucjpms, check_mb_eucjpms}, - { 128, "ucs2", "ucs2_unicode_ci", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 129, "ucs2", "ucs2_icelandic_ci", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 130, "ucs2", "ucs2_latvian_ci", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 131, "ucs2", "ucs2_romanian_ci", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 132, "ucs2", "ucs2_slovenian_ci", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 133, "ucs2", "ucs2_polish_ci", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 134, "ucs2", "ucs2_estonian_ci", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 135, "ucs2", "ucs2_spanish_ci", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 136, "ucs2", "ucs2_swedish_ci", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 137, "ucs2", "ucs2_turkish_ci", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 138, "ucs2", "ucs2_czech_ci", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 139, "ucs2", "ucs2_danish_ci", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 140, "ucs2", "ucs2_lithunian_ci", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 141, "ucs2", "ucs2_slovak_ci", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 142, "ucs2", "ucs2_spanish2_ci", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 143, "ucs2", "ucs2_roman_ci", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 144, "ucs2", "ucs2_persian_ci", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 145, "ucs2", "ucs2_esperanto_ci", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 146, "ucs2", "ucs2_hungarian_ci", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, - { 192, "utf8", "utf8_general_ci", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid}, - { 193, "utf8", "utf8_icelandic_ci", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid}, - { 194, "utf8", "utf8_latvian_ci", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid}, - { 195, "utf8", "utf8_romanian_ci", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid}, - { 196, "utf8", "utf8_slovenian_ci", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid}, - { 197, "utf8", "utf8_polish_ci", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid}, - { 198, "utf8", "utf8_estonian_ci", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid}, - { 119, "utf8", "utf8_spanish_ci", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid}, - { 200, "utf8", "utf8_swedish_ci", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid}, - { 201, "utf8", "utf8_turkish_ci", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid}, - { 202, "utf8", "utf8_czech_ci", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid}, - { 203, "utf8", "utf8_danish_ci", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid }, - { 204, "utf8", "utf8_lithunian_ci", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid }, - { 205, "utf8", "utf8_slovak_ci", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid}, - { 206, "utf8", "utf8_spanish2_ci", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid}, - { 207, "utf8", "utf8_roman_ci", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid}, - { 208, "utf8", "utf8_persian_ci", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid}, - { 209, "utf8", "utf8_esperanto_ci", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid}, - { 210, "utf8", "utf8_hungarian_ci", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid}, - { 254, "utf8", "utf8_general_cs", 1, 2, mysql_mbcharlen_utf8, check_mb_utf8_valid }, - { 0, NULL, NULL, 0, 0, NULL, NULL} -}; -/* }}} */ - - -/* {{{ mysql_find_charset_nr */ -const CHARSET_INFO * mysql_find_charset_nr(uint charsetnr) -{ - const CHARSET_INFO * c = compiled_charsets; - - do { - if (c->nr == charsetnr) { - return c; - } - ++c; - } while (c[0].nr != 0); - return NULL; -} -/* }}} */ - - -/* {{{ mysql_find_charset_name */ -const CHARSET_INFO * mysql_find_charset_name(const char * const name) -{ - const CHARSET_INFO *c = compiled_charsets; - - do { -#ifndef __WIN__ - if (!strcasecmp(c->name, name)) { -#else - if (!_stricmp(c->name, name)) { -#endif - return c; - } - ++c; - } while (c[0].nr != 0); - return NULL; -} -/* }}} */ - - -/* {{{ mysql_cset_escape_quotes */ -unsigned long mysql_cset_escape_quotes(const CHARSET_INFO * const cset, char *newstr, - const char *escapestr, size_t escapestr_len) -{ - const char *newstr_s = newstr; - const char *newstr_e = newstr + 2 * escapestr_len; - const char *end = escapestr + escapestr_len; - my_bool escape_overflow = FALSE; - - DBUG_ENTER("mysql_cset_escape_quotes"); - - for (;escapestr < end; escapestr++) { - uint len = 0; - /* check unicode characters */ - - if (cset->char_maxlen > 1 && (len = cset->mb_valid(escapestr, end))) { - - /* check possible overflow */ - if ((newstr + len) > newstr_e) { - escape_overflow = TRUE; - break; - } - /* copy mb char without escaping it */ - while (len--) { - *newstr++ = *escapestr++; - } - escapestr--; - continue; - } - if (*escapestr == '\'') { - if (newstr + 2 > newstr_e) { - escape_overflow = TRUE; - break; - } - *newstr++ = '\''; - *newstr++ = '\''; - } else { - if (newstr + 1 > newstr_e) { - escape_overflow = TRUE; - break; - } - *newstr++ = *escapestr; - } - } - *newstr = '\0'; - - if (escape_overflow) { - DBUG_RETURN((unsigned long)~0); - } - DBUG_RETURN((unsigned long)(newstr - newstr_s)); -} -/* }}} */ - - -/* {{{ mysql_cset_escape_slashes */ -unsigned long mysql_cset_escape_slashes(const CHARSET_INFO * const cset, char *newstr, - const char *escapestr, size_t escapestr_len) -{ - const char *newstr_s = newstr; - const char *newstr_e = newstr + 2 * escapestr_len; - const char *end = escapestr + escapestr_len; - my_bool escape_overflow = FALSE; - - DBUG_ENTER("mysql_cset_escape_slashes"); - - for (;escapestr < end; escapestr++) { - char esc = '\0'; - uint len = 0; - - /* check unicode characters */ - if (cset->char_maxlen > 1 && (len = cset->mb_valid(escapestr, end))) { - /* check possible overflow */ - if ((newstr + len) > newstr_e) { - escape_overflow = TRUE; - break; - } - /* copy mb char without escaping it */ - while (len--) { - *newstr++ = *escapestr++; - } - escapestr--; - continue; - } - if (cset->char_maxlen > 1 && cset->mb_charlen(*escapestr) > 1) { - esc = *escapestr; - } else { - switch (*escapestr) { - case 0: - esc = '0'; - break; - case '\n': - esc = 'n'; - break; - case '\r': - esc = 'r'; - break; - case '\\': - case '\'': - case '"': - esc = *escapestr; - break; - case '\032': - esc = 'Z'; - break; - } - } - if (esc) { - if (newstr + 2 > newstr_e) { - escape_overflow = TRUE; - break; - } - /* copy escaped character */ - *newstr++ = '\\'; - *newstr++ = esc; - } else { - if (newstr + 1 > newstr_e) { - escape_overflow = TRUE; - break; - } - /* copy non escaped character */ - *newstr++ = *escapestr; - } - } - *newstr = '\0'; - - if (escape_overflow) { - DBUG_RETURN((unsigned long)~0); - } - DBUG_RETURN((unsigned long)(newstr - newstr_s)); -} -/* }}} */ - -/* The following code is from libmysql and is under the following license */ - -/* Copyright (C) 2000 MySQL AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; version 2 - of the License. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* UTF8 according RFC 2279 */ -/* Written by Alexander Barkov */ - - -typedef struct unicase_info_st -{ - uint16 toupper; - uint16 tolower; - uint16 sort; -} MY_UNICASE_INFO; - - -static MY_UNICASE_INFO plane00[]={ - {0x0000,0x0000,0x0000}, {0x0001,0x0001,0x0001}, - {0x0002,0x0002,0x0002}, {0x0003,0x0003,0x0003}, - {0x0004,0x0004,0x0004}, {0x0005,0x0005,0x0005}, - {0x0006,0x0006,0x0006}, {0x0007,0x0007,0x0007}, - {0x0008,0x0008,0x0008}, {0x0009,0x0009,0x0009}, - {0x000A,0x000A,0x000A}, {0x000B,0x000B,0x000B}, - {0x000C,0x000C,0x000C}, {0x000D,0x000D,0x000D}, - {0x000E,0x000E,0x000E}, {0x000F,0x000F,0x000F}, - {0x0010,0x0010,0x0010}, {0x0011,0x0011,0x0011}, - {0x0012,0x0012,0x0012}, {0x0013,0x0013,0x0013}, - {0x0014,0x0014,0x0014}, {0x0015,0x0015,0x0015}, - {0x0016,0x0016,0x0016}, {0x0017,0x0017,0x0017}, - {0x0018,0x0018,0x0018}, {0x0019,0x0019,0x0019}, - {0x001A,0x001A,0x001A}, {0x001B,0x001B,0x001B}, - {0x001C,0x001C,0x001C}, {0x001D,0x001D,0x001D}, - {0x001E,0x001E,0x001E}, {0x001F,0x001F,0x001F}, - {0x0020,0x0020,0x0020}, {0x0021,0x0021,0x0021}, - {0x0022,0x0022,0x0022}, {0x0023,0x0023,0x0023}, - {0x0024,0x0024,0x0024}, {0x0025,0x0025,0x0025}, - {0x0026,0x0026,0x0026}, {0x0027,0x0027,0x0027}, - {0x0028,0x0028,0x0028}, {0x0029,0x0029,0x0029}, - {0x002A,0x002A,0x002A}, {0x002B,0x002B,0x002B}, - {0x002C,0x002C,0x002C}, {0x002D,0x002D,0x002D}, - {0x002E,0x002E,0x002E}, {0x002F,0x002F,0x002F}, - {0x0030,0x0030,0x0030}, {0x0031,0x0031,0x0031}, - {0x0032,0x0032,0x0032}, {0x0033,0x0033,0x0033}, - {0x0034,0x0034,0x0034}, {0x0035,0x0035,0x0035}, - {0x0036,0x0036,0x0036}, {0x0037,0x0037,0x0037}, - {0x0038,0x0038,0x0038}, {0x0039,0x0039,0x0039}, - {0x003A,0x003A,0x003A}, {0x003B,0x003B,0x003B}, - {0x003C,0x003C,0x003C}, {0x003D,0x003D,0x003D}, - {0x003E,0x003E,0x003E}, {0x003F,0x003F,0x003F}, - {0x0040,0x0040,0x0040}, {0x0041,0x0061,0x0041}, - {0x0042,0x0062,0x0042}, {0x0043,0x0063,0x0043}, - {0x0044,0x0064,0x0044}, {0x0045,0x0065,0x0045}, - {0x0046,0x0066,0x0046}, {0x0047,0x0067,0x0047}, - {0x0048,0x0068,0x0048}, {0x0049,0x0069,0x0049}, - {0x004A,0x006A,0x004A}, {0x004B,0x006B,0x004B}, - {0x004C,0x006C,0x004C}, {0x004D,0x006D,0x004D}, - {0x004E,0x006E,0x004E}, {0x004F,0x006F,0x004F}, - {0x0050,0x0070,0x0050}, {0x0051,0x0071,0x0051}, - {0x0052,0x0072,0x0052}, {0x0053,0x0073,0x0053}, - {0x0054,0x0074,0x0054}, {0x0055,0x0075,0x0055}, - {0x0056,0x0076,0x0056}, {0x0057,0x0077,0x0057}, - {0x0058,0x0078,0x0058}, {0x0059,0x0079,0x0059}, - {0x005A,0x007A,0x005A}, {0x005B,0x005B,0x005B}, - {0x005C,0x005C,0x005C}, {0x005D,0x005D,0x005D}, - {0x005E,0x005E,0x005E}, {0x005F,0x005F,0x005F}, - {0x0060,0x0060,0x0060}, {0x0041,0x0061,0x0041}, - {0x0042,0x0062,0x0042}, {0x0043,0x0063,0x0043}, - {0x0044,0x0064,0x0044}, {0x0045,0x0065,0x0045}, - {0x0046,0x0066,0x0046}, {0x0047,0x0067,0x0047}, - {0x0048,0x0068,0x0048}, {0x0049,0x0069,0x0049}, - {0x004A,0x006A,0x004A}, {0x004B,0x006B,0x004B}, - {0x004C,0x006C,0x004C}, {0x004D,0x006D,0x004D}, - {0x004E,0x006E,0x004E}, {0x004F,0x006F,0x004F}, - {0x0050,0x0070,0x0050}, {0x0051,0x0071,0x0051}, - {0x0052,0x0072,0x0052}, {0x0053,0x0073,0x0053}, - {0x0054,0x0074,0x0054}, {0x0055,0x0075,0x0055}, - {0x0056,0x0076,0x0056}, {0x0057,0x0077,0x0057}, - {0x0058,0x0078,0x0058}, {0x0059,0x0079,0x0059}, - {0x005A,0x007A,0x005A}, {0x007B,0x007B,0x007B}, - {0x007C,0x007C,0x007C}, {0x007D,0x007D,0x007D}, - {0x007E,0x007E,0x007E}, {0x007F,0x007F,0x007F}, - {0x0080,0x0080,0x0080}, {0x0081,0x0081,0x0081}, - {0x0082,0x0082,0x0082}, {0x0083,0x0083,0x0083}, - {0x0084,0x0084,0x0084}, {0x0085,0x0085,0x0085}, - {0x0086,0x0086,0x0086}, {0x0087,0x0087,0x0087}, - {0x0088,0x0088,0x0088}, {0x0089,0x0089,0x0089}, - {0x008A,0x008A,0x008A}, {0x008B,0x008B,0x008B}, - {0x008C,0x008C,0x008C}, {0x008D,0x008D,0x008D}, - {0x008E,0x008E,0x008E}, {0x008F,0x008F,0x008F}, - {0x0090,0x0090,0x0090}, {0x0091,0x0091,0x0091}, - {0x0092,0x0092,0x0092}, {0x0093,0x0093,0x0093}, - {0x0094,0x0094,0x0094}, {0x0095,0x0095,0x0095}, - {0x0096,0x0096,0x0096}, {0x0097,0x0097,0x0097}, - {0x0098,0x0098,0x0098}, {0x0099,0x0099,0x0099}, - {0x009A,0x009A,0x009A}, {0x009B,0x009B,0x009B}, - {0x009C,0x009C,0x009C}, {0x009D,0x009D,0x009D}, - {0x009E,0x009E,0x009E}, {0x009F,0x009F,0x009F}, - {0x00A0,0x00A0,0x00A0}, {0x00A1,0x00A1,0x00A1}, - {0x00A2,0x00A2,0x00A2}, {0x00A3,0x00A3,0x00A3}, - {0x00A4,0x00A4,0x00A4}, {0x00A5,0x00A5,0x00A5}, - {0x00A6,0x00A6,0x00A6}, {0x00A7,0x00A7,0x00A7}, - {0x00A8,0x00A8,0x00A8}, {0x00A9,0x00A9,0x00A9}, - {0x00AA,0x00AA,0x00AA}, {0x00AB,0x00AB,0x00AB}, - {0x00AC,0x00AC,0x00AC}, {0x00AD,0x00AD,0x00AD}, - {0x00AE,0x00AE,0x00AE}, {0x00AF,0x00AF,0x00AF}, - {0x00B0,0x00B0,0x00B0}, {0x00B1,0x00B1,0x00B1}, - {0x00B2,0x00B2,0x00B2}, {0x00B3,0x00B3,0x00B3}, - {0x00B4,0x00B4,0x00B4}, {0x039C,0x00B5,0x039C}, - {0x00B6,0x00B6,0x00B6}, {0x00B7,0x00B7,0x00B7}, - {0x00B8,0x00B8,0x00B8}, {0x00B9,0x00B9,0x00B9}, - {0x00BA,0x00BA,0x00BA}, {0x00BB,0x00BB,0x00BB}, - {0x00BC,0x00BC,0x00BC}, {0x00BD,0x00BD,0x00BD}, - {0x00BE,0x00BE,0x00BE}, {0x00BF,0x00BF,0x00BF}, - {0x00C0,0x00E0,0x0041}, {0x00C1,0x00E1,0x0041}, - {0x00C2,0x00E2,0x0041}, {0x00C3,0x00E3,0x0041}, - {0x00C4,0x00E4,0x0041}, {0x00C5,0x00E5,0x0041}, - {0x00C6,0x00E6,0x00C6}, {0x00C7,0x00E7,0x0043}, - {0x00C8,0x00E8,0x0045}, {0x00C9,0x00E9,0x0045}, - {0x00CA,0x00EA,0x0045}, {0x00CB,0x00EB,0x0045}, - {0x00CC,0x00EC,0x0049}, {0x00CD,0x00ED,0x0049}, - {0x00CE,0x00EE,0x0049}, {0x00CF,0x00EF,0x0049}, - {0x00D0,0x00F0,0x00D0}, {0x00D1,0x00F1,0x004E}, - {0x00D2,0x00F2,0x004F}, {0x00D3,0x00F3,0x004F}, - {0x00D4,0x00F4,0x004F}, {0x00D5,0x00F5,0x004F}, - {0x00D6,0x00F6,0x004F}, {0x00D7,0x00D7,0x00D7}, - {0x00D8,0x00F8,0x00D8}, {0x00D9,0x00F9,0x0055}, - {0x00DA,0x00FA,0x0055}, {0x00DB,0x00FB,0x0055}, - {0x00DC,0x00FC,0x0055}, {0x00DD,0x00FD,0x0059}, - {0x00DE,0x00FE,0x00DE}, {0x00DF,0x00DF,0x00DF}, - {0x00C0,0x00E0,0x0041}, {0x00C1,0x00E1,0x0041}, - {0x00C2,0x00E2,0x0041}, {0x00C3,0x00E3,0x0041}, - {0x00C4,0x00E4,0x0041}, {0x00C5,0x00E5,0x0041}, - {0x00C6,0x00E6,0x00C6}, {0x00C7,0x00E7,0x0043}, - {0x00C8,0x00E8,0x0045}, {0x00C9,0x00E9,0x0045}, - {0x00CA,0x00EA,0x0045}, {0x00CB,0x00EB,0x0045}, - {0x00CC,0x00EC,0x0049}, {0x00CD,0x00ED,0x0049}, - {0x00CE,0x00EE,0x0049}, {0x00CF,0x00EF,0x0049}, - {0x00D0,0x00F0,0x00D0}, {0x00D1,0x00F1,0x004E}, - {0x00D2,0x00F2,0x004F}, {0x00D3,0x00F3,0x004F}, - {0x00D4,0x00F4,0x004F}, {0x00D5,0x00F5,0x004F}, - {0x00D6,0x00F6,0x004F}, {0x00F7,0x00F7,0x00F7}, - {0x00D8,0x00F8,0x00D8}, {0x00D9,0x00F9,0x0055}, - {0x00DA,0x00FA,0x0055}, {0x00DB,0x00FB,0x0055}, - {0x00DC,0x00FC,0x0055}, {0x00DD,0x00FD,0x0059}, - {0x00DE,0x00FE,0x00DE}, {0x0178,0x00FF,0x0059} -}; - - - -static MY_UNICASE_INFO plane01[]={ - {0x0100,0x0101,0x0041}, {0x0100,0x0101,0x0041}, - {0x0102,0x0103,0x0041}, {0x0102,0x0103,0x0041}, - {0x0104,0x0105,0x0041}, {0x0104,0x0105,0x0041}, - {0x0106,0x0107,0x0043}, {0x0106,0x0107,0x0043}, - {0x0108,0x0109,0x0043}, {0x0108,0x0109,0x0043}, - {0x010A,0x010B,0x0043}, {0x010A,0x010B,0x0043}, - {0x010C,0x010D,0x0043}, {0x010C,0x010D,0x0043}, - {0x010E,0x010F,0x0044}, {0x010E,0x010F,0x0044}, - {0x0110,0x0111,0x0110}, {0x0110,0x0111,0x0110}, - {0x0112,0x0113,0x0045}, {0x0112,0x0113,0x0045}, - {0x0114,0x0115,0x0045}, {0x0114,0x0115,0x0045}, - {0x0116,0x0117,0x0045}, {0x0116,0x0117,0x0045}, - {0x0118,0x0119,0x0045}, {0x0118,0x0119,0x0045}, - {0x011A,0x011B,0x0045}, {0x011A,0x011B,0x0045}, - {0x011C,0x011D,0x0047}, {0x011C,0x011D,0x0047}, - {0x011E,0x011F,0x0047}, {0x011E,0x011F,0x0047}, - {0x0120,0x0121,0x0047}, {0x0120,0x0121,0x0047}, - {0x0122,0x0123,0x0047}, {0x0122,0x0123,0x0047}, - {0x0124,0x0125,0x0048}, {0x0124,0x0125,0x0048}, - {0x0126,0x0127,0x0126}, {0x0126,0x0127,0x0126}, - {0x0128,0x0129,0x0049}, {0x0128,0x0129,0x0049}, - {0x012A,0x012B,0x0049}, {0x012A,0x012B,0x0049}, - {0x012C,0x012D,0x0049}, {0x012C,0x012D,0x0049}, - {0x012E,0x012F,0x0049}, {0x012E,0x012F,0x0049}, - {0x0130,0x0069,0x0049}, {0x0049,0x0131,0x0049}, - {0x0132,0x0133,0x0132}, {0x0132,0x0133,0x0132}, - {0x0134,0x0135,0x004A}, {0x0134,0x0135,0x004A}, - {0x0136,0x0137,0x004B}, {0x0136,0x0137,0x004B}, - {0x0138,0x0138,0x0138}, {0x0139,0x013A,0x004C}, - {0x0139,0x013A,0x004C}, {0x013B,0x013C,0x004C}, - {0x013B,0x013C,0x004C}, {0x013D,0x013E,0x004C}, - {0x013D,0x013E,0x004C}, {0x013F,0x0140,0x013F}, - {0x013F,0x0140,0x013F}, {0x0141,0x0142,0x0141}, - {0x0141,0x0142,0x0141}, {0x0143,0x0144,0x004E}, - {0x0143,0x0144,0x004E}, {0x0145,0x0146,0x004E}, - {0x0145,0x0146,0x004E}, {0x0147,0x0148,0x004E}, - {0x0147,0x0148,0x004E}, {0x0149,0x0149,0x0149}, - {0x014A,0x014B,0x014A}, {0x014A,0x014B,0x014A}, - {0x014C,0x014D,0x004F}, {0x014C,0x014D,0x004F}, - {0x014E,0x014F,0x004F}, {0x014E,0x014F,0x004F}, - {0x0150,0x0151,0x004F}, {0x0150,0x0151,0x004F}, - {0x0152,0x0153,0x0152}, {0x0152,0x0153,0x0152}, - {0x0154,0x0155,0x0052}, {0x0154,0x0155,0x0052}, - {0x0156,0x0157,0x0052}, {0x0156,0x0157,0x0052}, - {0x0158,0x0159,0x0052}, {0x0158,0x0159,0x0052}, - {0x015A,0x015B,0x0053}, {0x015A,0x015B,0x0053}, - {0x015C,0x015D,0x0053}, {0x015C,0x015D,0x0053}, - {0x015E,0x015F,0x0053}, {0x015E,0x015F,0x0053}, - {0x0160,0x0161,0x0053}, {0x0160,0x0161,0x0053}, - {0x0162,0x0163,0x0054}, {0x0162,0x0163,0x0054}, - {0x0164,0x0165,0x0054}, {0x0164,0x0165,0x0054}, - {0x0166,0x0167,0x0166}, {0x0166,0x0167,0x0166}, - {0x0168,0x0169,0x0055}, {0x0168,0x0169,0x0055}, - {0x016A,0x016B,0x0055}, {0x016A,0x016B,0x0055}, - {0x016C,0x016D,0x0055}, {0x016C,0x016D,0x0055}, - {0x016E,0x016F,0x0055}, {0x016E,0x016F,0x0055}, - {0x0170,0x0171,0x0055}, {0x0170,0x0171,0x0055}, - {0x0172,0x0173,0x0055}, {0x0172,0x0173,0x0055}, - {0x0174,0x0175,0x0057}, {0x0174,0x0175,0x0057}, - {0x0176,0x0177,0x0059}, {0x0176,0x0177,0x0059}, - {0x0178,0x00FF,0x0059}, {0x0179,0x017A,0x005A}, - {0x0179,0x017A,0x005A}, {0x017B,0x017C,0x005A}, - {0x017B,0x017C,0x005A}, {0x017D,0x017E,0x005A}, - {0x017D,0x017E,0x005A}, {0x0053,0x017F,0x0053}, - {0x0180,0x0180,0x0180}, {0x0181,0x0253,0x0181}, - {0x0182,0x0183,0x0182}, {0x0182,0x0183,0x0182}, - {0x0184,0x0185,0x0184}, {0x0184,0x0185,0x0184}, - {0x0186,0x0254,0x0186}, {0x0187,0x0188,0x0187}, - {0x0187,0x0188,0x0187}, {0x0189,0x0256,0x0189}, - {0x018A,0x0257,0x018A}, {0x018B,0x018C,0x018B}, - {0x018B,0x018C,0x018B}, {0x018D,0x018D,0x018D}, - {0x018E,0x01DD,0x018E}, {0x018F,0x0259,0x018F}, - {0x0190,0x025B,0x0190}, {0x0191,0x0192,0x0191}, - {0x0191,0x0192,0x0191}, {0x0193,0x0260,0x0193}, - {0x0194,0x0263,0x0194}, {0x01F6,0x0195,0x01F6}, - {0x0196,0x0269,0x0196}, {0x0197,0x0268,0x0197}, - {0x0198,0x0199,0x0198}, {0x0198,0x0199,0x0198}, - {0x019A,0x019A,0x019A}, {0x019B,0x019B,0x019B}, - {0x019C,0x026F,0x019C}, {0x019D,0x0272,0x019D}, - {0x019E,0x019E,0x019E}, {0x019F,0x0275,0x019F}, - {0x01A0,0x01A1,0x004F}, {0x01A0,0x01A1,0x004F}, - {0x01A2,0x01A3,0x01A2}, {0x01A2,0x01A3,0x01A2}, - {0x01A4,0x01A5,0x01A4}, {0x01A4,0x01A5,0x01A4}, - {0x01A6,0x0280,0x01A6}, {0x01A7,0x01A8,0x01A7}, - {0x01A7,0x01A8,0x01A7}, {0x01A9,0x0283,0x01A9}, - {0x01AA,0x01AA,0x01AA}, {0x01AB,0x01AB,0x01AB}, - {0x01AC,0x01AD,0x01AC}, {0x01AC,0x01AD,0x01AC}, - {0x01AE,0x0288,0x01AE}, {0x01AF,0x01B0,0x0055}, - {0x01AF,0x01B0,0x0055}, {0x01B1,0x028A,0x01B1}, - {0x01B2,0x028B,0x01B2}, {0x01B3,0x01B4,0x01B3}, - {0x01B3,0x01B4,0x01B3}, {0x01B5,0x01B6,0x01B5}, - {0x01B5,0x01B6,0x01B5}, {0x01B7,0x0292,0x01B7}, - {0x01B8,0x01B9,0x01B8}, {0x01B8,0x01B9,0x01B8}, - {0x01BA,0x01BA,0x01BA}, {0x01BB,0x01BB,0x01BB}, - {0x01BC,0x01BD,0x01BC}, {0x01BC,0x01BD,0x01BC}, - {0x01BE,0x01BE,0x01BE}, {0x01F7,0x01BF,0x01F7}, - {0x01C0,0x01C0,0x01C0}, {0x01C1,0x01C1,0x01C1}, - {0x01C2,0x01C2,0x01C2}, {0x01C3,0x01C3,0x01C3}, - {0x01C4,0x01C6,0x01C4}, {0x01C4,0x01C6,0x01C4}, - {0x01C4,0x01C6,0x01C4}, {0x01C7,0x01C9,0x01C7}, - {0x01C7,0x01C9,0x01C7}, {0x01C7,0x01C9,0x01C7}, - {0x01CA,0x01CC,0x01CA}, {0x01CA,0x01CC,0x01CA}, - {0x01CA,0x01CC,0x01CA}, {0x01CD,0x01CE,0x0041}, - {0x01CD,0x01CE,0x0041}, {0x01CF,0x01D0,0x0049}, - {0x01CF,0x01D0,0x0049}, {0x01D1,0x01D2,0x004F}, - {0x01D1,0x01D2,0x004F}, {0x01D3,0x01D4,0x0055}, - {0x01D3,0x01D4,0x0055}, {0x01D5,0x01D6,0x0055}, - {0x01D5,0x01D6,0x0055}, {0x01D7,0x01D8,0x0055}, - {0x01D7,0x01D8,0x0055}, {0x01D9,0x01DA,0x0055}, - {0x01D9,0x01DA,0x0055}, {0x01DB,0x01DC,0x0055}, - {0x01DB,0x01DC,0x0055}, {0x018E,0x01DD,0x018E}, - {0x01DE,0x01DF,0x0041}, {0x01DE,0x01DF,0x0041}, - {0x01E0,0x01E1,0x0041}, {0x01E0,0x01E1,0x0041}, - {0x01E2,0x01E3,0x00C6}, {0x01E2,0x01E3,0x00C6}, - {0x01E4,0x01E5,0x01E4}, {0x01E4,0x01E5,0x01E4}, - {0x01E6,0x01E7,0x0047}, {0x01E6,0x01E7,0x0047}, - {0x01E8,0x01E9,0x004B}, {0x01E8,0x01E9,0x004B}, - {0x01EA,0x01EB,0x004F}, {0x01EA,0x01EB,0x004F}, - {0x01EC,0x01ED,0x004F}, {0x01EC,0x01ED,0x004F}, - {0x01EE,0x01EF,0x01B7}, {0x01EE,0x01EF,0x01B7}, - {0x01F0,0x01F0,0x004A}, {0x01F1,0x01F3,0x01F1}, - {0x01F1,0x01F3,0x01F1}, {0x01F1,0x01F3,0x01F1}, - {0x01F4,0x01F5,0x0047}, {0x01F4,0x01F5,0x0047}, - {0x01F6,0x0195,0x01F6}, {0x01F7,0x01BF,0x01F7}, - {0x01F8,0x01F9,0x004E}, {0x01F8,0x01F9,0x004E}, - {0x01FA,0x01FB,0x0041}, {0x01FA,0x01FB,0x0041}, - {0x01FC,0x01FD,0x00C6}, {0x01FC,0x01FD,0x00C6}, - {0x01FE,0x01FF,0x00D8}, {0x01FE,0x01FF,0x00D8} -}; - -static MY_UNICASE_INFO plane02[]={ - {0x0200,0x0201,0x0041}, {0x0200,0x0201,0x0041}, - {0x0202,0x0203,0x0041}, {0x0202,0x0203,0x0041}, - {0x0204,0x0205,0x0045}, {0x0204,0x0205,0x0045}, - {0x0206,0x0207,0x0045}, {0x0206,0x0207,0x0045}, - {0x0208,0x0209,0x0049}, {0x0208,0x0209,0x0049}, - {0x020A,0x020B,0x0049}, {0x020A,0x020B,0x0049}, - {0x020C,0x020D,0x004F}, {0x020C,0x020D,0x004F}, - {0x020E,0x020F,0x004F}, {0x020E,0x020F,0x004F}, - {0x0210,0x0211,0x0052}, {0x0210,0x0211,0x0052}, - {0x0212,0x0213,0x0052}, {0x0212,0x0213,0x0052}, - {0x0214,0x0215,0x0055}, {0x0214,0x0215,0x0055}, - {0x0216,0x0217,0x0055}, {0x0216,0x0217,0x0055}, - {0x0218,0x0219,0x0053}, {0x0218,0x0219,0x0053}, - {0x021A,0x021B,0x0054}, {0x021A,0x021B,0x0054}, - {0x021C,0x021D,0x021C}, {0x021C,0x021D,0x021C}, - {0x021E,0x021F,0x0048}, {0x021E,0x021F,0x0048}, - {0x0220,0x0220,0x0220}, {0x0221,0x0221,0x0221}, - {0x0222,0x0223,0x0222}, {0x0222,0x0223,0x0222}, - {0x0224,0x0225,0x0224}, {0x0224,0x0225,0x0224}, - {0x0226,0x0227,0x0041}, {0x0226,0x0227,0x0041}, - {0x0228,0x0229,0x0045}, {0x0228,0x0229,0x0045}, - {0x022A,0x022B,0x004F}, {0x022A,0x022B,0x004F}, - {0x022C,0x022D,0x004F}, {0x022C,0x022D,0x004F}, - {0x022E,0x022F,0x004F}, {0x022E,0x022F,0x004F}, - {0x0230,0x0231,0x004F}, {0x0230,0x0231,0x004F}, - {0x0232,0x0233,0x0059}, {0x0232,0x0233,0x0059}, - {0x0234,0x0234,0x0234}, {0x0235,0x0235,0x0235}, - {0x0236,0x0236,0x0236}, {0x0237,0x0237,0x0237}, - {0x0238,0x0238,0x0238}, {0x0239,0x0239,0x0239}, - {0x023A,0x023A,0x023A}, {0x023B,0x023B,0x023B}, - {0x023C,0x023C,0x023C}, {0x023D,0x023D,0x023D}, - {0x023E,0x023E,0x023E}, {0x023F,0x023F,0x023F}, - {0x0240,0x0240,0x0240}, {0x0241,0x0241,0x0241}, - {0x0242,0x0242,0x0242}, {0x0243,0x0243,0x0243}, - {0x0244,0x0244,0x0244}, {0x0245,0x0245,0x0245}, - {0x0246,0x0246,0x0246}, {0x0247,0x0247,0x0247}, - {0x0248,0x0248,0x0248}, {0x0249,0x0249,0x0249}, - {0x024A,0x024A,0x024A}, {0x024B,0x024B,0x024B}, - {0x024C,0x024C,0x024C}, {0x024D,0x024D,0x024D}, - {0x024E,0x024E,0x024E}, {0x024F,0x024F,0x024F}, - {0x0250,0x0250,0x0250}, {0x0251,0x0251,0x0251}, - {0x0252,0x0252,0x0252}, {0x0181,0x0253,0x0181}, - {0x0186,0x0254,0x0186}, {0x0255,0x0255,0x0255}, - {0x0189,0x0256,0x0189}, {0x018A,0x0257,0x018A}, - {0x0258,0x0258,0x0258}, {0x018F,0x0259,0x018F}, - {0x025A,0x025A,0x025A}, {0x0190,0x025B,0x0190}, - {0x025C,0x025C,0x025C}, {0x025D,0x025D,0x025D}, - {0x025E,0x025E,0x025E}, {0x025F,0x025F,0x025F}, - {0x0193,0x0260,0x0193}, {0x0261,0x0261,0x0261}, - {0x0262,0x0262,0x0262}, {0x0194,0x0263,0x0194}, - {0x0264,0x0264,0x0264}, {0x0265,0x0265,0x0265}, - {0x0266,0x0266,0x0266}, {0x0267,0x0267,0x0267}, - {0x0197,0x0268,0x0197}, {0x0196,0x0269,0x0196}, - {0x026A,0x026A,0x026A}, {0x026B,0x026B,0x026B}, - {0x026C,0x026C,0x026C}, {0x026D,0x026D,0x026D}, - {0x026E,0x026E,0x026E}, {0x019C,0x026F,0x019C}, - {0x0270,0x0270,0x0270}, {0x0271,0x0271,0x0271}, - {0x019D,0x0272,0x019D}, {0x0273,0x0273,0x0273}, - {0x0274,0x0274,0x0274}, {0x019F,0x0275,0x019F}, - {0x0276,0x0276,0x0276}, {0x0277,0x0277,0x0277}, - {0x0278,0x0278,0x0278}, {0x0279,0x0279,0x0279}, - {0x027A,0x027A,0x027A}, {0x027B,0x027B,0x027B}, - {0x027C,0x027C,0x027C}, {0x027D,0x027D,0x027D}, - {0x027E,0x027E,0x027E}, {0x027F,0x027F,0x027F}, - {0x01A6,0x0280,0x01A6}, {0x0281,0x0281,0x0281}, - {0x0282,0x0282,0x0282}, {0x01A9,0x0283,0x01A9}, - {0x0284,0x0284,0x0284}, {0x0285,0x0285,0x0285}, - {0x0286,0x0286,0x0286}, {0x0287,0x0287,0x0287}, - {0x01AE,0x0288,0x01AE}, {0x0289,0x0289,0x0289}, - {0x01B1,0x028A,0x01B1}, {0x01B2,0x028B,0x01B2}, - {0x028C,0x028C,0x028C}, {0x028D,0x028D,0x028D}, - {0x028E,0x028E,0x028E}, {0x028F,0x028F,0x028F}, - {0x0290,0x0290,0x0290}, {0x0291,0x0291,0x0291}, - {0x01B7,0x0292,0x01B7}, {0x0293,0x0293,0x0293}, - {0x0294,0x0294,0x0294}, {0x0295,0x0295,0x0295}, - {0x0296,0x0296,0x0296}, {0x0297,0x0297,0x0297}, - {0x0298,0x0298,0x0298}, {0x0299,0x0299,0x0299}, - {0x029A,0x029A,0x029A}, {0x029B,0x029B,0x029B}, - {0x029C,0x029C,0x029C}, {0x029D,0x029D,0x029D}, - {0x029E,0x029E,0x029E}, {0x029F,0x029F,0x029F}, - {0x02A0,0x02A0,0x02A0}, {0x02A1,0x02A1,0x02A1}, - {0x02A2,0x02A2,0x02A2}, {0x02A3,0x02A3,0x02A3}, - {0x02A4,0x02A4,0x02A4}, {0x02A5,0x02A5,0x02A5}, - {0x02A6,0x02A6,0x02A6}, {0x02A7,0x02A7,0x02A7}, - {0x02A8,0x02A8,0x02A8}, {0x02A9,0x02A9,0x02A9}, - {0x02AA,0x02AA,0x02AA}, {0x02AB,0x02AB,0x02AB}, - {0x02AC,0x02AC,0x02AC}, {0x02AD,0x02AD,0x02AD}, - {0x02AE,0x02AE,0x02AE}, {0x02AF,0x02AF,0x02AF}, - {0x02B0,0x02B0,0x02B0}, {0x02B1,0x02B1,0x02B1}, - {0x02B2,0x02B2,0x02B2}, {0x02B3,0x02B3,0x02B3}, - {0x02B4,0x02B4,0x02B4}, {0x02B5,0x02B5,0x02B5}, - {0x02B6,0x02B6,0x02B6}, {0x02B7,0x02B7,0x02B7}, - {0x02B8,0x02B8,0x02B8}, {0x02B9,0x02B9,0x02B9}, - {0x02BA,0x02BA,0x02BA}, {0x02BB,0x02BB,0x02BB}, - {0x02BC,0x02BC,0x02BC}, {0x02BD,0x02BD,0x02BD}, - {0x02BE,0x02BE,0x02BE}, {0x02BF,0x02BF,0x02BF}, - {0x02C0,0x02C0,0x02C0}, {0x02C1,0x02C1,0x02C1}, - {0x02C2,0x02C2,0x02C2}, {0x02C3,0x02C3,0x02C3}, - {0x02C4,0x02C4,0x02C4}, {0x02C5,0x02C5,0x02C5}, - {0x02C6,0x02C6,0x02C6}, {0x02C7,0x02C7,0x02C7}, - {0x02C8,0x02C8,0x02C8}, {0x02C9,0x02C9,0x02C9}, - {0x02CA,0x02CA,0x02CA}, {0x02CB,0x02CB,0x02CB}, - {0x02CC,0x02CC,0x02CC}, {0x02CD,0x02CD,0x02CD}, - {0x02CE,0x02CE,0x02CE}, {0x02CF,0x02CF,0x02CF}, - {0x02D0,0x02D0,0x02D0}, {0x02D1,0x02D1,0x02D1}, - {0x02D2,0x02D2,0x02D2}, {0x02D3,0x02D3,0x02D3}, - {0x02D4,0x02D4,0x02D4}, {0x02D5,0x02D5,0x02D5}, - {0x02D6,0x02D6,0x02D6}, {0x02D7,0x02D7,0x02D7}, - {0x02D8,0x02D8,0x02D8}, {0x02D9,0x02D9,0x02D9}, - {0x02DA,0x02DA,0x02DA}, {0x02DB,0x02DB,0x02DB}, - {0x02DC,0x02DC,0x02DC}, {0x02DD,0x02DD,0x02DD}, - {0x02DE,0x02DE,0x02DE}, {0x02DF,0x02DF,0x02DF}, - {0x02E0,0x02E0,0x02E0}, {0x02E1,0x02E1,0x02E1}, - {0x02E2,0x02E2,0x02E2}, {0x02E3,0x02E3,0x02E3}, - {0x02E4,0x02E4,0x02E4}, {0x02E5,0x02E5,0x02E5}, - {0x02E6,0x02E6,0x02E6}, {0x02E7,0x02E7,0x02E7}, - {0x02E8,0x02E8,0x02E8}, {0x02E9,0x02E9,0x02E9}, - {0x02EA,0x02EA,0x02EA}, {0x02EB,0x02EB,0x02EB}, - {0x02EC,0x02EC,0x02EC}, {0x02ED,0x02ED,0x02ED}, - {0x02EE,0x02EE,0x02EE}, {0x02EF,0x02EF,0x02EF}, - {0x02F0,0x02F0,0x02F0}, {0x02F1,0x02F1,0x02F1}, - {0x02F2,0x02F2,0x02F2}, {0x02F3,0x02F3,0x02F3}, - {0x02F4,0x02F4,0x02F4}, {0x02F5,0x02F5,0x02F5}, - {0x02F6,0x02F6,0x02F6}, {0x02F7,0x02F7,0x02F7}, - {0x02F8,0x02F8,0x02F8}, {0x02F9,0x02F9,0x02F9}, - {0x02FA,0x02FA,0x02FA}, {0x02FB,0x02FB,0x02FB}, - {0x02FC,0x02FC,0x02FC}, {0x02FD,0x02FD,0x02FD}, - {0x02FE,0x02FE,0x02FE}, {0x02FF,0x02FF,0x02FF} -}; - -static MY_UNICASE_INFO plane03[]={ - {0x0300,0x0300,0x0300}, {0x0301,0x0301,0x0301}, - {0x0302,0x0302,0x0302}, {0x0303,0x0303,0x0303}, - {0x0304,0x0304,0x0304}, {0x0305,0x0305,0x0305}, - {0x0306,0x0306,0x0306}, {0x0307,0x0307,0x0307}, - {0x0308,0x0308,0x0308}, {0x0309,0x0309,0x0309}, - {0x030A,0x030A,0x030A}, {0x030B,0x030B,0x030B}, - {0x030C,0x030C,0x030C}, {0x030D,0x030D,0x030D}, - {0x030E,0x030E,0x030E}, {0x030F,0x030F,0x030F}, - {0x0310,0x0310,0x0310}, {0x0311,0x0311,0x0311}, - {0x0312,0x0312,0x0312}, {0x0313,0x0313,0x0313}, - {0x0314,0x0314,0x0314}, {0x0315,0x0315,0x0315}, - {0x0316,0x0316,0x0316}, {0x0317,0x0317,0x0317}, - {0x0318,0x0318,0x0318}, {0x0319,0x0319,0x0319}, - {0x031A,0x031A,0x031A}, {0x031B,0x031B,0x031B}, - {0x031C,0x031C,0x031C}, {0x031D,0x031D,0x031D}, - {0x031E,0x031E,0x031E}, {0x031F,0x031F,0x031F}, - {0x0320,0x0320,0x0320}, {0x0321,0x0321,0x0321}, - {0x0322,0x0322,0x0322}, {0x0323,0x0323,0x0323}, - {0x0324,0x0324,0x0324}, {0x0325,0x0325,0x0325}, - {0x0326,0x0326,0x0326}, {0x0327,0x0327,0x0327}, - {0x0328,0x0328,0x0328}, {0x0329,0x0329,0x0329}, - {0x032A,0x032A,0x032A}, {0x032B,0x032B,0x032B}, - {0x032C,0x032C,0x032C}, {0x032D,0x032D,0x032D}, - {0x032E,0x032E,0x032E}, {0x032F,0x032F,0x032F}, - {0x0330,0x0330,0x0330}, {0x0331,0x0331,0x0331}, - {0x0332,0x0332,0x0332}, {0x0333,0x0333,0x0333}, - {0x0334,0x0334,0x0334}, {0x0335,0x0335,0x0335}, - {0x0336,0x0336,0x0336}, {0x0337,0x0337,0x0337}, - {0x0338,0x0338,0x0338}, {0x0339,0x0339,0x0339}, - {0x033A,0x033A,0x033A}, {0x033B,0x033B,0x033B}, - {0x033C,0x033C,0x033C}, {0x033D,0x033D,0x033D}, - {0x033E,0x033E,0x033E}, {0x033F,0x033F,0x033F}, - {0x0340,0x0340,0x0340}, {0x0341,0x0341,0x0341}, - {0x0342,0x0342,0x0342}, {0x0343,0x0343,0x0343}, - {0x0344,0x0344,0x0344}, {0x0399,0x0345,0x0399}, - {0x0346,0x0346,0x0346}, {0x0347,0x0347,0x0347}, - {0x0348,0x0348,0x0348}, {0x0349,0x0349,0x0349}, - {0x034A,0x034A,0x034A}, {0x034B,0x034B,0x034B}, - {0x034C,0x034C,0x034C}, {0x034D,0x034D,0x034D}, - {0x034E,0x034E,0x034E}, {0x034F,0x034F,0x034F}, - {0x0350,0x0350,0x0350}, {0x0351,0x0351,0x0351}, - {0x0352,0x0352,0x0352}, {0x0353,0x0353,0x0353}, - {0x0354,0x0354,0x0354}, {0x0355,0x0355,0x0355}, - {0x0356,0x0356,0x0356}, {0x0357,0x0357,0x0357}, - {0x0358,0x0358,0x0358}, {0x0359,0x0359,0x0359}, - {0x035A,0x035A,0x035A}, {0x035B,0x035B,0x035B}, - {0x035C,0x035C,0x035C}, {0x035D,0x035D,0x035D}, - {0x035E,0x035E,0x035E}, {0x035F,0x035F,0x035F}, - {0x0360,0x0360,0x0360}, {0x0361,0x0361,0x0361}, - {0x0362,0x0362,0x0362}, {0x0363,0x0363,0x0363}, - {0x0364,0x0364,0x0364}, {0x0365,0x0365,0x0365}, - {0x0366,0x0366,0x0366}, {0x0367,0x0367,0x0367}, - {0x0368,0x0368,0x0368}, {0x0369,0x0369,0x0369}, - {0x036A,0x036A,0x036A}, {0x036B,0x036B,0x036B}, - {0x036C,0x036C,0x036C}, {0x036D,0x036D,0x036D}, - {0x036E,0x036E,0x036E}, {0x036F,0x036F,0x036F}, - {0x0370,0x0370,0x0370}, {0x0371,0x0371,0x0371}, - {0x0372,0x0372,0x0372}, {0x0373,0x0373,0x0373}, - {0x0374,0x0374,0x0374}, {0x0375,0x0375,0x0375}, - {0x0376,0x0376,0x0376}, {0x0377,0x0377,0x0377}, - {0x0378,0x0378,0x0378}, {0x0379,0x0379,0x0379}, - {0x037A,0x037A,0x037A}, {0x037B,0x037B,0x037B}, - {0x037C,0x037C,0x037C}, {0x037D,0x037D,0x037D}, - {0x037E,0x037E,0x037E}, {0x037F,0x037F,0x037F}, - {0x0380,0x0380,0x0380}, {0x0381,0x0381,0x0381}, - {0x0382,0x0382,0x0382}, {0x0383,0x0383,0x0383}, - {0x0384,0x0384,0x0384}, {0x0385,0x0385,0x0385}, - {0x0386,0x03AC,0x0391}, {0x0387,0x0387,0x0387}, - {0x0388,0x03AD,0x0395}, {0x0389,0x03AE,0x0397}, - {0x038A,0x03AF,0x0399}, {0x038B,0x038B,0x038B}, - {0x038C,0x03CC,0x039F}, {0x038D,0x038D,0x038D}, - {0x038E,0x03CD,0x03A5}, {0x038F,0x03CE,0x03A9}, - {0x0390,0x0390,0x0399}, {0x0391,0x03B1,0x0391}, - {0x0392,0x03B2,0x0392}, {0x0393,0x03B3,0x0393}, - {0x0394,0x03B4,0x0394}, {0x0395,0x03B5,0x0395}, - {0x0396,0x03B6,0x0396}, {0x0397,0x03B7,0x0397}, - {0x0398,0x03B8,0x0398}, {0x0399,0x03B9,0x0399}, - {0x039A,0x03BA,0x039A}, {0x039B,0x03BB,0x039B}, - {0x039C,0x03BC,0x039C}, {0x039D,0x03BD,0x039D}, - {0x039E,0x03BE,0x039E}, {0x039F,0x03BF,0x039F}, - {0x03A0,0x03C0,0x03A0}, {0x03A1,0x03C1,0x03A1}, - {0x03A2,0x03A2,0x03A2}, {0x03A3,0x03C3,0x03A3}, - {0x03A4,0x03C4,0x03A4}, {0x03A5,0x03C5,0x03A5}, - {0x03A6,0x03C6,0x03A6}, {0x03A7,0x03C7,0x03A7}, - {0x03A8,0x03C8,0x03A8}, {0x03A9,0x03C9,0x03A9}, - {0x03AA,0x03CA,0x0399}, {0x03AB,0x03CB,0x03A5}, - {0x0386,0x03AC,0x0391}, {0x0388,0x03AD,0x0395}, - {0x0389,0x03AE,0x0397}, {0x038A,0x03AF,0x0399}, - {0x03B0,0x03B0,0x03A5}, {0x0391,0x03B1,0x0391}, - {0x0392,0x03B2,0x0392}, {0x0393,0x03B3,0x0393}, - {0x0394,0x03B4,0x0394}, {0x0395,0x03B5,0x0395}, - {0x0396,0x03B6,0x0396}, {0x0397,0x03B7,0x0397}, - {0x0398,0x03B8,0x0398}, {0x0399,0x03B9,0x0399}, - {0x039A,0x03BA,0x039A}, {0x039B,0x03BB,0x039B}, - {0x039C,0x03BC,0x039C}, {0x039D,0x03BD,0x039D}, - {0x039E,0x03BE,0x039E}, {0x039F,0x03BF,0x039F}, - {0x03A0,0x03C0,0x03A0}, {0x03A1,0x03C1,0x03A1}, - {0x03A3,0x03C2,0x03A3}, {0x03A3,0x03C3,0x03A3}, - {0x03A4,0x03C4,0x03A4}, {0x03A5,0x03C5,0x03A5}, - {0x03A6,0x03C6,0x03A6}, {0x03A7,0x03C7,0x03A7}, - {0x03A8,0x03C8,0x03A8}, {0x03A9,0x03C9,0x03A9}, - {0x03AA,0x03CA,0x0399}, {0x03AB,0x03CB,0x03A5}, - {0x038C,0x03CC,0x039F}, {0x038E,0x03CD,0x03A5}, - {0x038F,0x03CE,0x03A9}, {0x03CF,0x03CF,0x03CF}, - {0x0392,0x03D0,0x0392}, {0x0398,0x03D1,0x0398}, - {0x03D2,0x03D2,0x03D2}, {0x03D3,0x03D3,0x03D2}, - {0x03D4,0x03D4,0x03D2}, {0x03A6,0x03D5,0x03A6}, - {0x03A0,0x03D6,0x03A0}, {0x03D7,0x03D7,0x03D7}, - {0x03D8,0x03D8,0x03D8}, {0x03D9,0x03D9,0x03D9}, - {0x03DA,0x03DB,0x03DA}, {0x03DA,0x03DB,0x03DA}, - {0x03DC,0x03DD,0x03DC}, {0x03DC,0x03DD,0x03DC}, - {0x03DE,0x03DF,0x03DE}, {0x03DE,0x03DF,0x03DE}, - {0x03E0,0x03E1,0x03E0}, {0x03E0,0x03E1,0x03E0}, - {0x03E2,0x03E3,0x03E2}, {0x03E2,0x03E3,0x03E2}, - {0x03E4,0x03E5,0x03E4}, {0x03E4,0x03E5,0x03E4}, - {0x03E6,0x03E7,0x03E6}, {0x03E6,0x03E7,0x03E6}, - {0x03E8,0x03E9,0x03E8}, {0x03E8,0x03E9,0x03E8}, - {0x03EA,0x03EB,0x03EA}, {0x03EA,0x03EB,0x03EA}, - {0x03EC,0x03ED,0x03EC}, {0x03EC,0x03ED,0x03EC}, - {0x03EE,0x03EF,0x03EE}, {0x03EE,0x03EF,0x03EE}, - {0x039A,0x03F0,0x039A}, {0x03A1,0x03F1,0x03A1}, - {0x03A3,0x03F2,0x03A3}, {0x03F3,0x03F3,0x03F3}, - {0x03F4,0x03F4,0x03F4}, {0x03F5,0x03F5,0x03F5}, - {0x03F6,0x03F6,0x03F6}, {0x03F7,0x03F7,0x03F7}, - {0x03F8,0x03F8,0x03F8}, {0x03F9,0x03F9,0x03F9}, - {0x03FA,0x03FA,0x03FA}, {0x03FB,0x03FB,0x03FB}, - {0x03FC,0x03FC,0x03FC}, {0x03FD,0x03FD,0x03FD}, - {0x03FE,0x03FE,0x03FE}, {0x03FF,0x03FF,0x03FF} -}; - -static MY_UNICASE_INFO plane04[]={ - {0x0400,0x0450,0x0415}, {0x0401,0x0451,0x0415}, - {0x0402,0x0452,0x0402}, {0x0403,0x0453,0x0413}, - {0x0404,0x0454,0x0404}, {0x0405,0x0455,0x0405}, - {0x0406,0x0456,0x0406}, {0x0407,0x0457,0x0406}, - {0x0408,0x0458,0x0408}, {0x0409,0x0459,0x0409}, - {0x040A,0x045A,0x040A}, {0x040B,0x045B,0x040B}, - {0x040C,0x045C,0x041A}, {0x040D,0x045D,0x0418}, - {0x040E,0x045E,0x0423}, {0x040F,0x045F,0x040F}, - {0x0410,0x0430,0x0410}, {0x0411,0x0431,0x0411}, - {0x0412,0x0432,0x0412}, {0x0413,0x0433,0x0413}, - {0x0414,0x0434,0x0414}, {0x0415,0x0435,0x0415}, - {0x0416,0x0436,0x0416}, {0x0417,0x0437,0x0417}, - {0x0418,0x0438,0x0418}, {0x0419,0x0439,0x0419}, - {0x041A,0x043A,0x041A}, {0x041B,0x043B,0x041B}, - {0x041C,0x043C,0x041C}, {0x041D,0x043D,0x041D}, - {0x041E,0x043E,0x041E}, {0x041F,0x043F,0x041F}, - {0x0420,0x0440,0x0420}, {0x0421,0x0441,0x0421}, - {0x0422,0x0442,0x0422}, {0x0423,0x0443,0x0423}, - {0x0424,0x0444,0x0424}, {0x0425,0x0445,0x0425}, - {0x0426,0x0446,0x0426}, {0x0427,0x0447,0x0427}, - {0x0428,0x0448,0x0428}, {0x0429,0x0449,0x0429}, - {0x042A,0x044A,0x042A}, {0x042B,0x044B,0x042B}, - {0x042C,0x044C,0x042C}, {0x042D,0x044D,0x042D}, - {0x042E,0x044E,0x042E}, {0x042F,0x044F,0x042F}, - {0x0410,0x0430,0x0410}, {0x0411,0x0431,0x0411}, - {0x0412,0x0432,0x0412}, {0x0413,0x0433,0x0413}, - {0x0414,0x0434,0x0414}, {0x0415,0x0435,0x0415}, - {0x0416,0x0436,0x0416}, {0x0417,0x0437,0x0417}, - {0x0418,0x0438,0x0418}, {0x0419,0x0439,0x0419}, - {0x041A,0x043A,0x041A}, {0x041B,0x043B,0x041B}, - {0x041C,0x043C,0x041C}, {0x041D,0x043D,0x041D}, - {0x041E,0x043E,0x041E}, {0x041F,0x043F,0x041F}, - {0x0420,0x0440,0x0420}, {0x0421,0x0441,0x0421}, - {0x0422,0x0442,0x0422}, {0x0423,0x0443,0x0423}, - {0x0424,0x0444,0x0424}, {0x0425,0x0445,0x0425}, - {0x0426,0x0446,0x0426}, {0x0427,0x0447,0x0427}, - {0x0428,0x0448,0x0428}, {0x0429,0x0449,0x0429}, - {0x042A,0x044A,0x042A}, {0x042B,0x044B,0x042B}, - {0x042C,0x044C,0x042C}, {0x042D,0x044D,0x042D}, - {0x042E,0x044E,0x042E}, {0x042F,0x044F,0x042F}, - {0x0400,0x0450,0x0415}, {0x0401,0x0451,0x0415}, - {0x0402,0x0452,0x0402}, {0x0403,0x0453,0x0413}, - {0x0404,0x0454,0x0404}, {0x0405,0x0455,0x0405}, - {0x0406,0x0456,0x0406}, {0x0407,0x0457,0x0406}, - {0x0408,0x0458,0x0408}, {0x0409,0x0459,0x0409}, - {0x040A,0x045A,0x040A}, {0x040B,0x045B,0x040B}, - {0x040C,0x045C,0x041A}, {0x040D,0x045D,0x0418}, - {0x040E,0x045E,0x0423}, {0x040F,0x045F,0x040F}, - {0x0460,0x0461,0x0460}, {0x0460,0x0461,0x0460}, - {0x0462,0x0463,0x0462}, {0x0462,0x0463,0x0462}, - {0x0464,0x0465,0x0464}, {0x0464,0x0465,0x0464}, - {0x0466,0x0467,0x0466}, {0x0466,0x0467,0x0466}, - {0x0468,0x0469,0x0468}, {0x0468,0x0469,0x0468}, - {0x046A,0x046B,0x046A}, {0x046A,0x046B,0x046A}, - {0x046C,0x046D,0x046C}, {0x046C,0x046D,0x046C}, - {0x046E,0x046F,0x046E}, {0x046E,0x046F,0x046E}, - {0x0470,0x0471,0x0470}, {0x0470,0x0471,0x0470}, - {0x0472,0x0473,0x0472}, {0x0472,0x0473,0x0472}, - {0x0474,0x0475,0x0474}, {0x0474,0x0475,0x0474}, - {0x0476,0x0477,0x0474}, {0x0476,0x0477,0x0474}, - {0x0478,0x0479,0x0478}, {0x0478,0x0479,0x0478}, - {0x047A,0x047B,0x047A}, {0x047A,0x047B,0x047A}, - {0x047C,0x047D,0x047C}, {0x047C,0x047D,0x047C}, - {0x047E,0x047F,0x047E}, {0x047E,0x047F,0x047E}, - {0x0480,0x0481,0x0480}, {0x0480,0x0481,0x0480}, - {0x0482,0x0482,0x0482}, {0x0483,0x0483,0x0483}, - {0x0484,0x0484,0x0484}, {0x0485,0x0485,0x0485}, - {0x0486,0x0486,0x0486}, {0x0487,0x0487,0x0487}, - {0x0488,0x0488,0x0488}, {0x0489,0x0489,0x0489}, - {0x048A,0x048A,0x048A}, {0x048B,0x048B,0x048B}, - {0x048C,0x048D,0x048C}, {0x048C,0x048D,0x048C}, - {0x048E,0x048F,0x048E}, {0x048E,0x048F,0x048E}, - {0x0490,0x0491,0x0490}, {0x0490,0x0491,0x0490}, - {0x0492,0x0493,0x0492}, {0x0492,0x0493,0x0492}, - {0x0494,0x0495,0x0494}, {0x0494,0x0495,0x0494}, - {0x0496,0x0497,0x0496}, {0x0496,0x0497,0x0496}, - {0x0498,0x0499,0x0498}, {0x0498,0x0499,0x0498}, - {0x049A,0x049B,0x049A}, {0x049A,0x049B,0x049A}, - {0x049C,0x049D,0x049C}, {0x049C,0x049D,0x049C}, - {0x049E,0x049F,0x049E}, {0x049E,0x049F,0x049E}, - {0x04A0,0x04A1,0x04A0}, {0x04A0,0x04A1,0x04A0}, - {0x04A2,0x04A3,0x04A2}, {0x04A2,0x04A3,0x04A2}, - {0x04A4,0x04A5,0x04A4}, {0x04A4,0x04A5,0x04A4}, - {0x04A6,0x04A7,0x04A6}, {0x04A6,0x04A7,0x04A6}, - {0x04A8,0x04A9,0x04A8}, {0x04A8,0x04A9,0x04A8}, - {0x04AA,0x04AB,0x04AA}, {0x04AA,0x04AB,0x04AA}, - {0x04AC,0x04AD,0x04AC}, {0x04AC,0x04AD,0x04AC}, - {0x04AE,0x04AF,0x04AE}, {0x04AE,0x04AF,0x04AE}, - {0x04B0,0x04B1,0x04B0}, {0x04B0,0x04B1,0x04B0}, - {0x04B2,0x04B3,0x04B2}, {0x04B2,0x04B3,0x04B2}, - {0x04B4,0x04B5,0x04B4}, {0x04B4,0x04B5,0x04B4}, - {0x04B6,0x04B7,0x04B6}, {0x04B6,0x04B7,0x04B6}, - {0x04B8,0x04B9,0x04B8}, {0x04B8,0x04B9,0x04B8}, - {0x04BA,0x04BB,0x04BA}, {0x04BA,0x04BB,0x04BA}, - {0x04BC,0x04BD,0x04BC}, {0x04BC,0x04BD,0x04BC}, - {0x04BE,0x04BF,0x04BE}, {0x04BE,0x04BF,0x04BE}, - {0x04C0,0x04C0,0x04C0}, {0x04C1,0x04C2,0x0416}, - {0x04C1,0x04C2,0x0416}, {0x04C3,0x04C4,0x04C3}, - {0x04C3,0x04C4,0x04C3}, {0x04C5,0x04C5,0x04C5}, - {0x04C6,0x04C6,0x04C6}, {0x04C7,0x04C8,0x04C7}, - {0x04C7,0x04C8,0x04C7}, {0x04C9,0x04C9,0x04C9}, - {0x04CA,0x04CA,0x04CA}, {0x04CB,0x04CC,0x04CB}, - {0x04CB,0x04CC,0x04CB}, {0x04CD,0x04CD,0x04CD}, - {0x04CE,0x04CE,0x04CE}, {0x04CF,0x04CF,0x04CF}, - {0x04D0,0x04D1,0x0410}, {0x04D0,0x04D1,0x0410}, - {0x04D2,0x04D3,0x0410}, {0x04D2,0x04D3,0x0410}, - {0x04D4,0x04D5,0x04D4}, {0x04D4,0x04D5,0x04D4}, - {0x04D6,0x04D7,0x0415}, {0x04D6,0x04D7,0x0415}, - {0x04D8,0x04D9,0x04D8}, {0x04D8,0x04D9,0x04D8}, - {0x04DA,0x04DB,0x04D8}, {0x04DA,0x04DB,0x04D8}, - {0x04DC,0x04DD,0x0416}, {0x04DC,0x04DD,0x0416}, - {0x04DE,0x04DF,0x0417}, {0x04DE,0x04DF,0x0417}, - {0x04E0,0x04E1,0x04E0}, {0x04E0,0x04E1,0x04E0}, - {0x04E2,0x04E3,0x0418}, {0x04E2,0x04E3,0x0418}, - {0x04E4,0x04E5,0x0418}, {0x04E4,0x04E5,0x0418}, - {0x04E6,0x04E7,0x041E}, {0x04E6,0x04E7,0x041E}, - {0x04E8,0x04E9,0x04E8}, {0x04E8,0x04E9,0x04E8}, - {0x04EA,0x04EB,0x04E8}, {0x04EA,0x04EB,0x04E8}, - {0x04EC,0x04ED,0x042D}, {0x04EC,0x04ED,0x042D}, - {0x04EE,0x04EF,0x0423}, {0x04EE,0x04EF,0x0423}, - {0x04F0,0x04F1,0x0423}, {0x04F0,0x04F1,0x0423}, - {0x04F2,0x04F3,0x0423}, {0x04F2,0x04F3,0x0423}, - {0x04F4,0x04F5,0x0427}, {0x04F4,0x04F5,0x0427}, - {0x04F6,0x04F6,0x04F6}, {0x04F7,0x04F7,0x04F7}, - {0x04F8,0x04F9,0x042B}, {0x04F8,0x04F9,0x042B}, - {0x04FA,0x04FA,0x04FA}, {0x04FB,0x04FB,0x04FB}, - {0x04FC,0x04FC,0x04FC}, {0x04FD,0x04FD,0x04FD}, - {0x04FE,0x04FE,0x04FE}, {0x04FF,0x04FF,0x04FF} -}; - -static MY_UNICASE_INFO plane05[]={ - {0x0500,0x0500,0x0500}, {0x0501,0x0501,0x0501}, - {0x0502,0x0502,0x0502}, {0x0503,0x0503,0x0503}, - {0x0504,0x0504,0x0504}, {0x0505,0x0505,0x0505}, - {0x0506,0x0506,0x0506}, {0x0507,0x0507,0x0507}, - {0x0508,0x0508,0x0508}, {0x0509,0x0509,0x0509}, - {0x050A,0x050A,0x050A}, {0x050B,0x050B,0x050B}, - {0x050C,0x050C,0x050C}, {0x050D,0x050D,0x050D}, - {0x050E,0x050E,0x050E}, {0x050F,0x050F,0x050F}, - {0x0510,0x0510,0x0510}, {0x0511,0x0511,0x0511}, - {0x0512,0x0512,0x0512}, {0x0513,0x0513,0x0513}, - {0x0514,0x0514,0x0514}, {0x0515,0x0515,0x0515}, - {0x0516,0x0516,0x0516}, {0x0517,0x0517,0x0517}, - {0x0518,0x0518,0x0518}, {0x0519,0x0519,0x0519}, - {0x051A,0x051A,0x051A}, {0x051B,0x051B,0x051B}, - {0x051C,0x051C,0x051C}, {0x051D,0x051D,0x051D}, - {0x051E,0x051E,0x051E}, {0x051F,0x051F,0x051F}, - {0x0520,0x0520,0x0520}, {0x0521,0x0521,0x0521}, - {0x0522,0x0522,0x0522}, {0x0523,0x0523,0x0523}, - {0x0524,0x0524,0x0524}, {0x0525,0x0525,0x0525}, - {0x0526,0x0526,0x0526}, {0x0527,0x0527,0x0527}, - {0x0528,0x0528,0x0528}, {0x0529,0x0529,0x0529}, - {0x052A,0x052A,0x052A}, {0x052B,0x052B,0x052B}, - {0x052C,0x052C,0x052C}, {0x052D,0x052D,0x052D}, - {0x052E,0x052E,0x052E}, {0x052F,0x052F,0x052F}, - {0x0530,0x0530,0x0530}, {0x0531,0x0561,0x0531}, - {0x0532,0x0562,0x0532}, {0x0533,0x0563,0x0533}, - {0x0534,0x0564,0x0534}, {0x0535,0x0565,0x0535}, - {0x0536,0x0566,0x0536}, {0x0537,0x0567,0x0537}, - {0x0538,0x0568,0x0538}, {0x0539,0x0569,0x0539}, - {0x053A,0x056A,0x053A}, {0x053B,0x056B,0x053B}, - {0x053C,0x056C,0x053C}, {0x053D,0x056D,0x053D}, - {0x053E,0x056E,0x053E}, {0x053F,0x056F,0x053F}, - {0x0540,0x0570,0x0540}, {0x0541,0x0571,0x0541}, - {0x0542,0x0572,0x0542}, {0x0543,0x0573,0x0543}, - {0x0544,0x0574,0x0544}, {0x0545,0x0575,0x0545}, - {0x0546,0x0576,0x0546}, {0x0547,0x0577,0x0547}, - {0x0548,0x0578,0x0548}, {0x0549,0x0579,0x0549}, - {0x054A,0x057A,0x054A}, {0x054B,0x057B,0x054B}, - {0x054C,0x057C,0x054C}, {0x054D,0x057D,0x054D}, - {0x054E,0x057E,0x054E}, {0x054F,0x057F,0x054F}, - {0x0550,0x0580,0x0550}, {0x0551,0x0581,0x0551}, - {0x0552,0x0582,0x0552}, {0x0553,0x0583,0x0553}, - {0x0554,0x0584,0x0554}, {0x0555,0x0585,0x0555}, - {0x0556,0x0586,0x0556}, {0x0557,0x0557,0x0557}, - {0x0558,0x0558,0x0558}, {0x0559,0x0559,0x0559}, - {0x055A,0x055A,0x055A}, {0x055B,0x055B,0x055B}, - {0x055C,0x055C,0x055C}, {0x055D,0x055D,0x055D}, - {0x055E,0x055E,0x055E}, {0x055F,0x055F,0x055F}, - {0x0560,0x0560,0x0560}, {0x0531,0x0561,0x0531}, - {0x0532,0x0562,0x0532}, {0x0533,0x0563,0x0533}, - {0x0534,0x0564,0x0534}, {0x0535,0x0565,0x0535}, - {0x0536,0x0566,0x0536}, {0x0537,0x0567,0x0537}, - {0x0538,0x0568,0x0538}, {0x0539,0x0569,0x0539}, - {0x053A,0x056A,0x053A}, {0x053B,0x056B,0x053B}, - {0x053C,0x056C,0x053C}, {0x053D,0x056D,0x053D}, - {0x053E,0x056E,0x053E}, {0x053F,0x056F,0x053F}, - {0x0540,0x0570,0x0540}, {0x0541,0x0571,0x0541}, - {0x0542,0x0572,0x0542}, {0x0543,0x0573,0x0543}, - {0x0544,0x0574,0x0544}, {0x0545,0x0575,0x0545}, - {0x0546,0x0576,0x0546}, {0x0547,0x0577,0x0547}, - {0x0548,0x0578,0x0548}, {0x0549,0x0579,0x0549}, - {0x054A,0x057A,0x054A}, {0x054B,0x057B,0x054B}, - {0x054C,0x057C,0x054C}, {0x054D,0x057D,0x054D}, - {0x054E,0x057E,0x054E}, {0x054F,0x057F,0x054F}, - {0x0550,0x0580,0x0550}, {0x0551,0x0581,0x0551}, - {0x0552,0x0582,0x0552}, {0x0553,0x0583,0x0553}, - {0x0554,0x0584,0x0554}, {0x0555,0x0585,0x0555}, - {0x0556,0x0586,0x0556}, {0x0587,0x0587,0x0587}, - {0x0588,0x0588,0x0588}, {0x0589,0x0589,0x0589}, - {0x058A,0x058A,0x058A}, {0x058B,0x058B,0x058B}, - {0x058C,0x058C,0x058C}, {0x058D,0x058D,0x058D}, - {0x058E,0x058E,0x058E}, {0x058F,0x058F,0x058F}, - {0x0590,0x0590,0x0590}, {0x0591,0x0591,0x0591}, - {0x0592,0x0592,0x0592}, {0x0593,0x0593,0x0593}, - {0x0594,0x0594,0x0594}, {0x0595,0x0595,0x0595}, - {0x0596,0x0596,0x0596}, {0x0597,0x0597,0x0597}, - {0x0598,0x0598,0x0598}, {0x0599,0x0599,0x0599}, - {0x059A,0x059A,0x059A}, {0x059B,0x059B,0x059B}, - {0x059C,0x059C,0x059C}, {0x059D,0x059D,0x059D}, - {0x059E,0x059E,0x059E}, {0x059F,0x059F,0x059F}, - {0x05A0,0x05A0,0x05A0}, {0x05A1,0x05A1,0x05A1}, - {0x05A2,0x05A2,0x05A2}, {0x05A3,0x05A3,0x05A3}, - {0x05A4,0x05A4,0x05A4}, {0x05A5,0x05A5,0x05A5}, - {0x05A6,0x05A6,0x05A6}, {0x05A7,0x05A7,0x05A7}, - {0x05A8,0x05A8,0x05A8}, {0x05A9,0x05A9,0x05A9}, - {0x05AA,0x05AA,0x05AA}, {0x05AB,0x05AB,0x05AB}, - {0x05AC,0x05AC,0x05AC}, {0x05AD,0x05AD,0x05AD}, - {0x05AE,0x05AE,0x05AE}, {0x05AF,0x05AF,0x05AF}, - {0x05B0,0x05B0,0x05B0}, {0x05B1,0x05B1,0x05B1}, - {0x05B2,0x05B2,0x05B2}, {0x05B3,0x05B3,0x05B3}, - {0x05B4,0x05B4,0x05B4}, {0x05B5,0x05B5,0x05B5}, - {0x05B6,0x05B6,0x05B6}, {0x05B7,0x05B7,0x05B7}, - {0x05B8,0x05B8,0x05B8}, {0x05B9,0x05B9,0x05B9}, - {0x05BA,0x05BA,0x05BA}, {0x05BB,0x05BB,0x05BB}, - {0x05BC,0x05BC,0x05BC}, {0x05BD,0x05BD,0x05BD}, - {0x05BE,0x05BE,0x05BE}, {0x05BF,0x05BF,0x05BF}, - {0x05C0,0x05C0,0x05C0}, {0x05C1,0x05C1,0x05C1}, - {0x05C2,0x05C2,0x05C2}, {0x05C3,0x05C3,0x05C3}, - {0x05C4,0x05C4,0x05C4}, {0x05C5,0x05C5,0x05C5}, - {0x05C6,0x05C6,0x05C6}, {0x05C7,0x05C7,0x05C7}, - {0x05C8,0x05C8,0x05C8}, {0x05C9,0x05C9,0x05C9}, - {0x05CA,0x05CA,0x05CA}, {0x05CB,0x05CB,0x05CB}, - {0x05CC,0x05CC,0x05CC}, {0x05CD,0x05CD,0x05CD}, - {0x05CE,0x05CE,0x05CE}, {0x05CF,0x05CF,0x05CF}, - {0x05D0,0x05D0,0x05D0}, {0x05D1,0x05D1,0x05D1}, - {0x05D2,0x05D2,0x05D2}, {0x05D3,0x05D3,0x05D3}, - {0x05D4,0x05D4,0x05D4}, {0x05D5,0x05D5,0x05D5}, - {0x05D6,0x05D6,0x05D6}, {0x05D7,0x05D7,0x05D7}, - {0x05D8,0x05D8,0x05D8}, {0x05D9,0x05D9,0x05D9}, - {0x05DA,0x05DA,0x05DA}, {0x05DB,0x05DB,0x05DB}, - {0x05DC,0x05DC,0x05DC}, {0x05DD,0x05DD,0x05DD}, - {0x05DE,0x05DE,0x05DE}, {0x05DF,0x05DF,0x05DF}, - {0x05E0,0x05E0,0x05E0}, {0x05E1,0x05E1,0x05E1}, - {0x05E2,0x05E2,0x05E2}, {0x05E3,0x05E3,0x05E3}, - {0x05E4,0x05E4,0x05E4}, {0x05E5,0x05E5,0x05E5}, - {0x05E6,0x05E6,0x05E6}, {0x05E7,0x05E7,0x05E7}, - {0x05E8,0x05E8,0x05E8}, {0x05E9,0x05E9,0x05E9}, - {0x05EA,0x05EA,0x05EA}, {0x05EB,0x05EB,0x05EB}, - {0x05EC,0x05EC,0x05EC}, {0x05ED,0x05ED,0x05ED}, - {0x05EE,0x05EE,0x05EE}, {0x05EF,0x05EF,0x05EF}, - {0x05F0,0x05F0,0x05F0}, {0x05F1,0x05F1,0x05F1}, - {0x05F2,0x05F2,0x05F2}, {0x05F3,0x05F3,0x05F3}, - {0x05F4,0x05F4,0x05F4}, {0x05F5,0x05F5,0x05F5}, - {0x05F6,0x05F6,0x05F6}, {0x05F7,0x05F7,0x05F7}, - {0x05F8,0x05F8,0x05F8}, {0x05F9,0x05F9,0x05F9}, - {0x05FA,0x05FA,0x05FA}, {0x05FB,0x05FB,0x05FB}, - {0x05FC,0x05FC,0x05FC}, {0x05FD,0x05FD,0x05FD}, - {0x05FE,0x05FE,0x05FE}, {0x05FF,0x05FF,0x05FF} -}; - -static MY_UNICASE_INFO plane1E[]={ - {0x1E00,0x1E01,0x0041}, {0x1E00,0x1E01,0x0041}, - {0x1E02,0x1E03,0x0042}, {0x1E02,0x1E03,0x0042}, - {0x1E04,0x1E05,0x0042}, {0x1E04,0x1E05,0x0042}, - {0x1E06,0x1E07,0x0042}, {0x1E06,0x1E07,0x0042}, - {0x1E08,0x1E09,0x0043}, {0x1E08,0x1E09,0x0043}, - {0x1E0A,0x1E0B,0x0044}, {0x1E0A,0x1E0B,0x0044}, - {0x1E0C,0x1E0D,0x0044}, {0x1E0C,0x1E0D,0x0044}, - {0x1E0E,0x1E0F,0x0044}, {0x1E0E,0x1E0F,0x0044}, - {0x1E10,0x1E11,0x0044}, {0x1E10,0x1E11,0x0044}, - {0x1E12,0x1E13,0x0044}, {0x1E12,0x1E13,0x0044}, - {0x1E14,0x1E15,0x0045}, {0x1E14,0x1E15,0x0045}, - {0x1E16,0x1E17,0x0045}, {0x1E16,0x1E17,0x0045}, - {0x1E18,0x1E19,0x0045}, {0x1E18,0x1E19,0x0045}, - {0x1E1A,0x1E1B,0x0045}, {0x1E1A,0x1E1B,0x0045}, - {0x1E1C,0x1E1D,0x0045}, {0x1E1C,0x1E1D,0x0045}, - {0x1E1E,0x1E1F,0x0046}, {0x1E1E,0x1E1F,0x0046}, - {0x1E20,0x1E21,0x0047}, {0x1E20,0x1E21,0x0047}, - {0x1E22,0x1E23,0x0048}, {0x1E22,0x1E23,0x0048}, - {0x1E24,0x1E25,0x0048}, {0x1E24,0x1E25,0x0048}, - {0x1E26,0x1E27,0x0048}, {0x1E26,0x1E27,0x0048}, - {0x1E28,0x1E29,0x0048}, {0x1E28,0x1E29,0x0048}, - {0x1E2A,0x1E2B,0x0048}, {0x1E2A,0x1E2B,0x0048}, - {0x1E2C,0x1E2D,0x0049}, {0x1E2C,0x1E2D,0x0049}, - {0x1E2E,0x1E2F,0x0049}, {0x1E2E,0x1E2F,0x0049}, - {0x1E30,0x1E31,0x004B}, {0x1E30,0x1E31,0x004B}, - {0x1E32,0x1E33,0x004B}, {0x1E32,0x1E33,0x004B}, - {0x1E34,0x1E35,0x004B}, {0x1E34,0x1E35,0x004B}, - {0x1E36,0x1E37,0x004C}, {0x1E36,0x1E37,0x004C}, - {0x1E38,0x1E39,0x004C}, {0x1E38,0x1E39,0x004C}, - {0x1E3A,0x1E3B,0x004C}, {0x1E3A,0x1E3B,0x004C}, - {0x1E3C,0x1E3D,0x004C}, {0x1E3C,0x1E3D,0x004C}, - {0x1E3E,0x1E3F,0x004D}, {0x1E3E,0x1E3F,0x004D}, - {0x1E40,0x1E41,0x004D}, {0x1E40,0x1E41,0x004D}, - {0x1E42,0x1E43,0x004D}, {0x1E42,0x1E43,0x004D}, - {0x1E44,0x1E45,0x004E}, {0x1E44,0x1E45,0x004E}, - {0x1E46,0x1E47,0x004E}, {0x1E46,0x1E47,0x004E}, - {0x1E48,0x1E49,0x004E}, {0x1E48,0x1E49,0x004E}, - {0x1E4A,0x1E4B,0x004E}, {0x1E4A,0x1E4B,0x004E}, - {0x1E4C,0x1E4D,0x004F}, {0x1E4C,0x1E4D,0x004F}, - {0x1E4E,0x1E4F,0x004F}, {0x1E4E,0x1E4F,0x004F}, - {0x1E50,0x1E51,0x004F}, {0x1E50,0x1E51,0x004F}, - {0x1E52,0x1E53,0x004F}, {0x1E52,0x1E53,0x004F}, - {0x1E54,0x1E55,0x0050}, {0x1E54,0x1E55,0x0050}, - {0x1E56,0x1E57,0x0050}, {0x1E56,0x1E57,0x0050}, - {0x1E58,0x1E59,0x0052}, {0x1E58,0x1E59,0x0052}, - {0x1E5A,0x1E5B,0x0052}, {0x1E5A,0x1E5B,0x0052}, - {0x1E5C,0x1E5D,0x0052}, {0x1E5C,0x1E5D,0x0052}, - {0x1E5E,0x1E5F,0x0052}, {0x1E5E,0x1E5F,0x0052}, - {0x1E60,0x1E61,0x0053}, {0x1E60,0x1E61,0x0053}, - {0x1E62,0x1E63,0x0053}, {0x1E62,0x1E63,0x0053}, - {0x1E64,0x1E65,0x0053}, {0x1E64,0x1E65,0x0053}, - {0x1E66,0x1E67,0x0053}, {0x1E66,0x1E67,0x0053}, - {0x1E68,0x1E69,0x0053}, {0x1E68,0x1E69,0x0053}, - {0x1E6A,0x1E6B,0x0054}, {0x1E6A,0x1E6B,0x0054}, - {0x1E6C,0x1E6D,0x0054}, {0x1E6C,0x1E6D,0x0054}, - {0x1E6E,0x1E6F,0x0054}, {0x1E6E,0x1E6F,0x0054}, - {0x1E70,0x1E71,0x0054}, {0x1E70,0x1E71,0x0054}, - {0x1E72,0x1E73,0x0055}, {0x1E72,0x1E73,0x0055}, - {0x1E74,0x1E75,0x0055}, {0x1E74,0x1E75,0x0055}, - {0x1E76,0x1E77,0x0055}, {0x1E76,0x1E77,0x0055}, - {0x1E78,0x1E79,0x0055}, {0x1E78,0x1E79,0x0055}, - {0x1E7A,0x1E7B,0x0055}, {0x1E7A,0x1E7B,0x0055}, - {0x1E7C,0x1E7D,0x0056}, {0x1E7C,0x1E7D,0x0056}, - {0x1E7E,0x1E7F,0x0056}, {0x1E7E,0x1E7F,0x0056}, - {0x1E80,0x1E81,0x0057}, {0x1E80,0x1E81,0x0057}, - {0x1E82,0x1E83,0x0057}, {0x1E82,0x1E83,0x0057}, - {0x1E84,0x1E85,0x0057}, {0x1E84,0x1E85,0x0057}, - {0x1E86,0x1E87,0x0057}, {0x1E86,0x1E87,0x0057}, - {0x1E88,0x1E89,0x0057}, {0x1E88,0x1E89,0x0057}, - {0x1E8A,0x1E8B,0x0058}, {0x1E8A,0x1E8B,0x0058}, - {0x1E8C,0x1E8D,0x0058}, {0x1E8C,0x1E8D,0x0058}, - {0x1E8E,0x1E8F,0x0059}, {0x1E8E,0x1E8F,0x0059}, - {0x1E90,0x1E91,0x005A}, {0x1E90,0x1E91,0x005A}, - {0x1E92,0x1E93,0x005A}, {0x1E92,0x1E93,0x005A}, - {0x1E94,0x1E95,0x005A}, {0x1E94,0x1E95,0x005A}, - {0x1E96,0x1E96,0x0048}, {0x1E97,0x1E97,0x0054}, - {0x1E98,0x1E98,0x0057}, {0x1E99,0x1E99,0x0059}, - {0x1E9A,0x1E9A,0x1E9A}, {0x1E60,0x1E9B,0x0053}, - {0x1E9C,0x1E9C,0x1E9C}, {0x1E9D,0x1E9D,0x1E9D}, - {0x1E9E,0x1E9E,0x1E9E}, {0x1E9F,0x1E9F,0x1E9F}, - {0x1EA0,0x1EA1,0x0041}, {0x1EA0,0x1EA1,0x0041}, - {0x1EA2,0x1EA3,0x0041}, {0x1EA2,0x1EA3,0x0041}, - {0x1EA4,0x1EA5,0x0041}, {0x1EA4,0x1EA5,0x0041}, - {0x1EA6,0x1EA7,0x0041}, {0x1EA6,0x1EA7,0x0041}, - {0x1EA8,0x1EA9,0x0041}, {0x1EA8,0x1EA9,0x0041}, - {0x1EAA,0x1EAB,0x0041}, {0x1EAA,0x1EAB,0x0041}, - {0x1EAC,0x1EAD,0x0041}, {0x1EAC,0x1EAD,0x0041}, - {0x1EAE,0x1EAF,0x0041}, {0x1EAE,0x1EAF,0x0041}, - {0x1EB0,0x1EB1,0x0041}, {0x1EB0,0x1EB1,0x0041}, - {0x1EB2,0x1EB3,0x0041}, {0x1EB2,0x1EB3,0x0041}, - {0x1EB4,0x1EB5,0x0041}, {0x1EB4,0x1EB5,0x0041}, - {0x1EB6,0x1EB7,0x0041}, {0x1EB6,0x1EB7,0x0041}, - {0x1EB8,0x1EB9,0x0045}, {0x1EB8,0x1EB9,0x0045}, - {0x1EBA,0x1EBB,0x0045}, {0x1EBA,0x1EBB,0x0045}, - {0x1EBC,0x1EBD,0x0045}, {0x1EBC,0x1EBD,0x0045}, - {0x1EBE,0x1EBF,0x0045}, {0x1EBE,0x1EBF,0x0045}, - {0x1EC0,0x1EC1,0x0045}, {0x1EC0,0x1EC1,0x0045}, - {0x1EC2,0x1EC3,0x0045}, {0x1EC2,0x1EC3,0x0045}, - {0x1EC4,0x1EC5,0x0045}, {0x1EC4,0x1EC5,0x0045}, - {0x1EC6,0x1EC7,0x0045}, {0x1EC6,0x1EC7,0x0045}, - {0x1EC8,0x1EC9,0x0049}, {0x1EC8,0x1EC9,0x0049}, - {0x1ECA,0x1ECB,0x0049}, {0x1ECA,0x1ECB,0x0049}, - {0x1ECC,0x1ECD,0x004F}, {0x1ECC,0x1ECD,0x004F}, - {0x1ECE,0x1ECF,0x004F}, {0x1ECE,0x1ECF,0x004F}, - {0x1ED0,0x1ED1,0x004F}, {0x1ED0,0x1ED1,0x004F}, - {0x1ED2,0x1ED3,0x004F}, {0x1ED2,0x1ED3,0x004F}, - {0x1ED4,0x1ED5,0x004F}, {0x1ED4,0x1ED5,0x004F}, - {0x1ED6,0x1ED7,0x004F}, {0x1ED6,0x1ED7,0x004F}, - {0x1ED8,0x1ED9,0x004F}, {0x1ED8,0x1ED9,0x004F}, - {0x1EDA,0x1EDB,0x004F}, {0x1EDA,0x1EDB,0x004F}, - {0x1EDC,0x1EDD,0x004F}, {0x1EDC,0x1EDD,0x004F}, - {0x1EDE,0x1EDF,0x004F}, {0x1EDE,0x1EDF,0x004F}, - {0x1EE0,0x1EE1,0x004F}, {0x1EE0,0x1EE1,0x004F}, - {0x1EE2,0x1EE3,0x004F}, {0x1EE2,0x1EE3,0x004F}, - {0x1EE4,0x1EE5,0x0055}, {0x1EE4,0x1EE5,0x0055}, - {0x1EE6,0x1EE7,0x0055}, {0x1EE6,0x1EE7,0x0055}, - {0x1EE8,0x1EE9,0x0055}, {0x1EE8,0x1EE9,0x0055}, - {0x1EEA,0x1EEB,0x0055}, {0x1EEA,0x1EEB,0x0055}, - {0x1EEC,0x1EED,0x0055}, {0x1EEC,0x1EED,0x0055}, - {0x1EEE,0x1EEF,0x0055}, {0x1EEE,0x1EEF,0x0055}, - {0x1EF0,0x1EF1,0x0055}, {0x1EF0,0x1EF1,0x0055}, - {0x1EF2,0x1EF3,0x0059}, {0x1EF2,0x1EF3,0x0059}, - {0x1EF4,0x1EF5,0x0059}, {0x1EF4,0x1EF5,0x0059}, - {0x1EF6,0x1EF7,0x0059}, {0x1EF6,0x1EF7,0x0059}, - {0x1EF8,0x1EF9,0x0059}, {0x1EF8,0x1EF9,0x0059}, - {0x1EFA,0x1EFA,0x1EFA}, {0x1EFB,0x1EFB,0x1EFB}, - {0x1EFC,0x1EFC,0x1EFC}, {0x1EFD,0x1EFD,0x1EFD}, - {0x1EFE,0x1EFE,0x1EFE}, {0x1EFF,0x1EFF,0x1EFF} -}; - -static MY_UNICASE_INFO plane1F[]={ - {0x1F08,0x1F00,0x0391}, {0x1F09,0x1F01,0x0391}, - {0x1F0A,0x1F02,0x0391}, {0x1F0B,0x1F03,0x0391}, - {0x1F0C,0x1F04,0x0391}, {0x1F0D,0x1F05,0x0391}, - {0x1F0E,0x1F06,0x0391}, {0x1F0F,0x1F07,0x0391}, - {0x1F08,0x1F00,0x0391}, {0x1F09,0x1F01,0x0391}, - {0x1F0A,0x1F02,0x0391}, {0x1F0B,0x1F03,0x0391}, - {0x1F0C,0x1F04,0x0391}, {0x1F0D,0x1F05,0x0391}, - {0x1F0E,0x1F06,0x0391}, {0x1F0F,0x1F07,0x0391}, - {0x1F18,0x1F10,0x0395}, {0x1F19,0x1F11,0x0395}, - {0x1F1A,0x1F12,0x0395}, {0x1F1B,0x1F13,0x0395}, - {0x1F1C,0x1F14,0x0395}, {0x1F1D,0x1F15,0x0395}, - {0x1F16,0x1F16,0x1F16}, {0x1F17,0x1F17,0x1F17}, - {0x1F18,0x1F10,0x0395}, {0x1F19,0x1F11,0x0395}, - {0x1F1A,0x1F12,0x0395}, {0x1F1B,0x1F13,0x0395}, - {0x1F1C,0x1F14,0x0395}, {0x1F1D,0x1F15,0x0395}, - {0x1F1E,0x1F1E,0x1F1E}, {0x1F1F,0x1F1F,0x1F1F}, - {0x1F28,0x1F20,0x0397}, {0x1F29,0x1F21,0x0397}, - {0x1F2A,0x1F22,0x0397}, {0x1F2B,0x1F23,0x0397}, - {0x1F2C,0x1F24,0x0397}, {0x1F2D,0x1F25,0x0397}, - {0x1F2E,0x1F26,0x0397}, {0x1F2F,0x1F27,0x0397}, - {0x1F28,0x1F20,0x0397}, {0x1F29,0x1F21,0x0397}, - {0x1F2A,0x1F22,0x0397}, {0x1F2B,0x1F23,0x0397}, - {0x1F2C,0x1F24,0x0397}, {0x1F2D,0x1F25,0x0397}, - {0x1F2E,0x1F26,0x0397}, {0x1F2F,0x1F27,0x0397}, - {0x1F38,0x1F30,0x0399}, {0x1F39,0x1F31,0x0399}, - {0x1F3A,0x1F32,0x0399}, {0x1F3B,0x1F33,0x0399}, - {0x1F3C,0x1F34,0x0399}, {0x1F3D,0x1F35,0x0399}, - {0x1F3E,0x1F36,0x0399}, {0x1F3F,0x1F37,0x0399}, - {0x1F38,0x1F30,0x0399}, {0x1F39,0x1F31,0x0399}, - {0x1F3A,0x1F32,0x0399}, {0x1F3B,0x1F33,0x0399}, - {0x1F3C,0x1F34,0x0399}, {0x1F3D,0x1F35,0x0399}, - {0x1F3E,0x1F36,0x0399}, {0x1F3F,0x1F37,0x0399}, - {0x1F48,0x1F40,0x039F}, {0x1F49,0x1F41,0x039F}, - {0x1F4A,0x1F42,0x039F}, {0x1F4B,0x1F43,0x039F}, - {0x1F4C,0x1F44,0x039F}, {0x1F4D,0x1F45,0x039F}, - {0x1F46,0x1F46,0x1F46}, {0x1F47,0x1F47,0x1F47}, - {0x1F48,0x1F40,0x039F}, {0x1F49,0x1F41,0x039F}, - {0x1F4A,0x1F42,0x039F}, {0x1F4B,0x1F43,0x039F}, - {0x1F4C,0x1F44,0x039F}, {0x1F4D,0x1F45,0x039F}, - {0x1F4E,0x1F4E,0x1F4E}, {0x1F4F,0x1F4F,0x1F4F}, - {0x1F50,0x1F50,0x03A5}, {0x1F59,0x1F51,0x03A5}, - {0x1F52,0x1F52,0x03A5}, {0x1F5B,0x1F53,0x03A5}, - {0x1F54,0x1F54,0x03A5}, {0x1F5D,0x1F55,0x03A5}, - {0x1F56,0x1F56,0x03A5}, {0x1F5F,0x1F57,0x03A5}, - {0x1F58,0x1F58,0x1F58}, {0x1F59,0x1F51,0x03A5}, - {0x1F5A,0x1F5A,0x1F5A}, {0x1F5B,0x1F53,0x03A5}, - {0x1F5C,0x1F5C,0x1F5C}, {0x1F5D,0x1F55,0x03A5}, - {0x1F5E,0x1F5E,0x1F5E}, {0x1F5F,0x1F57,0x03A5}, - {0x1F68,0x1F60,0x03A9}, {0x1F69,0x1F61,0x03A9}, - {0x1F6A,0x1F62,0x03A9}, {0x1F6B,0x1F63,0x03A9}, - {0x1F6C,0x1F64,0x03A9}, {0x1F6D,0x1F65,0x03A9}, - {0x1F6E,0x1F66,0x03A9}, {0x1F6F,0x1F67,0x03A9}, - {0x1F68,0x1F60,0x03A9}, {0x1F69,0x1F61,0x03A9}, - {0x1F6A,0x1F62,0x03A9}, {0x1F6B,0x1F63,0x03A9}, - {0x1F6C,0x1F64,0x03A9}, {0x1F6D,0x1F65,0x03A9}, - {0x1F6E,0x1F66,0x03A9}, {0x1F6F,0x1F67,0x03A9}, - {0x1FBA,0x1F70,0x0391}, {0x1FBB,0x1F71,0x1FBB}, - {0x1FC8,0x1F72,0x0395}, {0x1FC9,0x1F73,0x1FC9}, - {0x1FCA,0x1F74,0x0397}, {0x1FCB,0x1F75,0x1FCB}, - {0x1FDA,0x1F76,0x0399}, {0x1FDB,0x1F77,0x1FDB}, - {0x1FF8,0x1F78,0x039F}, {0x1FF9,0x1F79,0x1FF9}, - {0x1FEA,0x1F7A,0x03A5}, {0x1FEB,0x1F7B,0x1FEB}, - {0x1FFA,0x1F7C,0x03A9}, {0x1FFB,0x1F7D,0x1FFB}, - {0x1F7E,0x1F7E,0x1F7E}, {0x1F7F,0x1F7F,0x1F7F}, - {0x1F88,0x1F80,0x0391}, {0x1F89,0x1F81,0x0391}, - {0x1F8A,0x1F82,0x0391}, {0x1F8B,0x1F83,0x0391}, - {0x1F8C,0x1F84,0x0391}, {0x1F8D,0x1F85,0x0391}, - {0x1F8E,0x1F86,0x0391}, {0x1F8F,0x1F87,0x0391}, - {0x1F88,0x1F80,0x0391}, {0x1F89,0x1F81,0x0391}, - {0x1F8A,0x1F82,0x0391}, {0x1F8B,0x1F83,0x0391}, - {0x1F8C,0x1F84,0x0391}, {0x1F8D,0x1F85,0x0391}, - {0x1F8E,0x1F86,0x0391}, {0x1F8F,0x1F87,0x0391}, - {0x1F98,0x1F90,0x0397}, {0x1F99,0x1F91,0x0397}, - {0x1F9A,0x1F92,0x0397}, {0x1F9B,0x1F93,0x0397}, - {0x1F9C,0x1F94,0x0397}, {0x1F9D,0x1F95,0x0397}, - {0x1F9E,0x1F96,0x0397}, {0x1F9F,0x1F97,0x0397}, - {0x1F98,0x1F90,0x0397}, {0x1F99,0x1F91,0x0397}, - {0x1F9A,0x1F92,0x0397}, {0x1F9B,0x1F93,0x0397}, - {0x1F9C,0x1F94,0x0397}, {0x1F9D,0x1F95,0x0397}, - {0x1F9E,0x1F96,0x0397}, {0x1F9F,0x1F97,0x0397}, - {0x1FA8,0x1FA0,0x03A9}, {0x1FA9,0x1FA1,0x03A9}, - {0x1FAA,0x1FA2,0x03A9}, {0x1FAB,0x1FA3,0x03A9}, - {0x1FAC,0x1FA4,0x03A9}, {0x1FAD,0x1FA5,0x03A9}, - {0x1FAE,0x1FA6,0x03A9}, {0x1FAF,0x1FA7,0x03A9}, - {0x1FA8,0x1FA0,0x03A9}, {0x1FA9,0x1FA1,0x03A9}, - {0x1FAA,0x1FA2,0x03A9}, {0x1FAB,0x1FA3,0x03A9}, - {0x1FAC,0x1FA4,0x03A9}, {0x1FAD,0x1FA5,0x03A9}, - {0x1FAE,0x1FA6,0x03A9}, {0x1FAF,0x1FA7,0x03A9}, - {0x1FB8,0x1FB0,0x0391}, {0x1FB9,0x1FB1,0x0391}, - {0x1FB2,0x1FB2,0x0391}, {0x1FBC,0x1FB3,0x0391}, - {0x1FB4,0x1FB4,0x0391}, {0x1FB5,0x1FB5,0x1FB5}, - {0x1FB6,0x1FB6,0x0391}, {0x1FB7,0x1FB7,0x0391}, - {0x1FB8,0x1FB0,0x0391}, {0x1FB9,0x1FB1,0x0391}, - {0x1FBA,0x1F70,0x0391}, {0x1FBB,0x1F71,0x1FBB}, - {0x1FBC,0x1FB3,0x0391}, {0x1FBD,0x1FBD,0x1FBD}, - {0x0399,0x1FBE,0x0399}, {0x1FBF,0x1FBF,0x1FBF}, - {0x1FC0,0x1FC0,0x1FC0}, {0x1FC1,0x1FC1,0x1FC1}, - {0x1FC2,0x1FC2,0x0397}, {0x1FCC,0x1FC3,0x0397}, - {0x1FC4,0x1FC4,0x0397}, {0x1FC5,0x1FC5,0x1FC5}, - {0x1FC6,0x1FC6,0x0397}, {0x1FC7,0x1FC7,0x0397}, - {0x1FC8,0x1F72,0x0395}, {0x1FC9,0x1F73,0x1FC9}, - {0x1FCA,0x1F74,0x0397}, {0x1FCB,0x1F75,0x1FCB}, - {0x1FCC,0x1FC3,0x0397}, {0x1FCD,0x1FCD,0x1FCD}, - {0x1FCE,0x1FCE,0x1FCE}, {0x1FCF,0x1FCF,0x1FCF}, - {0x1FD8,0x1FD0,0x0399}, {0x1FD9,0x1FD1,0x0399}, - {0x1FD2,0x1FD2,0x0399}, {0x1FD3,0x1FD3,0x1FD3}, - {0x1FD4,0x1FD4,0x1FD4}, {0x1FD5,0x1FD5,0x1FD5}, - {0x1FD6,0x1FD6,0x0399}, {0x1FD7,0x1FD7,0x0399}, - {0x1FD8,0x1FD0,0x0399}, {0x1FD9,0x1FD1,0x0399}, - {0x1FDA,0x1F76,0x0399}, {0x1FDB,0x1F77,0x1FDB}, - {0x1FDC,0x1FDC,0x1FDC}, {0x1FDD,0x1FDD,0x1FDD}, - {0x1FDE,0x1FDE,0x1FDE}, {0x1FDF,0x1FDF,0x1FDF}, - {0x1FE8,0x1FE0,0x03A5}, {0x1FE9,0x1FE1,0x03A5}, - {0x1FE2,0x1FE2,0x03A5}, {0x1FE3,0x1FE3,0x1FE3}, - {0x1FE4,0x1FE4,0x03A1}, {0x1FEC,0x1FE5,0x03A1}, - {0x1FE6,0x1FE6,0x03A5}, {0x1FE7,0x1FE7,0x03A5}, - {0x1FE8,0x1FE0,0x03A5}, {0x1FE9,0x1FE1,0x03A5}, - {0x1FEA,0x1F7A,0x03A5}, {0x1FEB,0x1F7B,0x1FEB}, - {0x1FEC,0x1FE5,0x03A1}, {0x1FED,0x1FED,0x1FED}, - {0x1FEE,0x1FEE,0x1FEE}, {0x1FEF,0x1FEF,0x1FEF}, - {0x1FF0,0x1FF0,0x1FF0}, {0x1FF1,0x1FF1,0x1FF1}, - {0x1FF2,0x1FF2,0x03A9}, {0x1FFC,0x1FF3,0x03A9}, - {0x1FF4,0x1FF4,0x03A9}, {0x1FF5,0x1FF5,0x1FF5}, - {0x1FF6,0x1FF6,0x03A9}, {0x1FF7,0x1FF7,0x03A9}, - {0x1FF8,0x1F78,0x039F}, {0x1FF9,0x1F79,0x1FF9}, - {0x1FFA,0x1F7C,0x03A9}, {0x1FFB,0x1F7D,0x1FFB}, - {0x1FFC,0x1FF3,0x03A9}, {0x1FFD,0x1FFD,0x1FFD}, - {0x1FFE,0x1FFE,0x1FFE}, {0x1FFF,0x1FFF,0x1FFF} -}; - -static MY_UNICASE_INFO plane21[]={ - {0x2100,0x2100,0x2100}, {0x2101,0x2101,0x2101}, - {0x2102,0x2102,0x2102}, {0x2103,0x2103,0x2103}, - {0x2104,0x2104,0x2104}, {0x2105,0x2105,0x2105}, - {0x2106,0x2106,0x2106}, {0x2107,0x2107,0x2107}, - {0x2108,0x2108,0x2108}, {0x2109,0x2109,0x2109}, - {0x210A,0x210A,0x210A}, {0x210B,0x210B,0x210B}, - {0x210C,0x210C,0x210C}, {0x210D,0x210D,0x210D}, - {0x210E,0x210E,0x210E}, {0x210F,0x210F,0x210F}, - {0x2110,0x2110,0x2110}, {0x2111,0x2111,0x2111}, - {0x2112,0x2112,0x2112}, {0x2113,0x2113,0x2113}, - {0x2114,0x2114,0x2114}, {0x2115,0x2115,0x2115}, - {0x2116,0x2116,0x2116}, {0x2117,0x2117,0x2117}, - {0x2118,0x2118,0x2118}, {0x2119,0x2119,0x2119}, - {0x211A,0x211A,0x211A}, {0x211B,0x211B,0x211B}, - {0x211C,0x211C,0x211C}, {0x211D,0x211D,0x211D}, - {0x211E,0x211E,0x211E}, {0x211F,0x211F,0x211F}, - {0x2120,0x2120,0x2120}, {0x2121,0x2121,0x2121}, - {0x2122,0x2122,0x2122}, {0x2123,0x2123,0x2123}, - {0x2124,0x2124,0x2124}, {0x2125,0x2125,0x2125}, - {0x2126,0x03C9,0x2126}, {0x2127,0x2127,0x2127}, - {0x2128,0x2128,0x2128}, {0x2129,0x2129,0x2129}, - {0x212A,0x006B,0x212A}, {0x212B,0x00E5,0x212B}, - {0x212C,0x212C,0x212C}, {0x212D,0x212D,0x212D}, - {0x212E,0x212E,0x212E}, {0x212F,0x212F,0x212F}, - {0x2130,0x2130,0x2130}, {0x2131,0x2131,0x2131}, - {0x2132,0x2132,0x2132}, {0x2133,0x2133,0x2133}, - {0x2134,0x2134,0x2134}, {0x2135,0x2135,0x2135}, - {0x2136,0x2136,0x2136}, {0x2137,0x2137,0x2137}, - {0x2138,0x2138,0x2138}, {0x2139,0x2139,0x2139}, - {0x213A,0x213A,0x213A}, {0x213B,0x213B,0x213B}, - {0x213C,0x213C,0x213C}, {0x213D,0x213D,0x213D}, - {0x213E,0x213E,0x213E}, {0x213F,0x213F,0x213F}, - {0x2140,0x2140,0x2140}, {0x2141,0x2141,0x2141}, - {0x2142,0x2142,0x2142}, {0x2143,0x2143,0x2143}, - {0x2144,0x2144,0x2144}, {0x2145,0x2145,0x2145}, - {0x2146,0x2146,0x2146}, {0x2147,0x2147,0x2147}, - {0x2148,0x2148,0x2148}, {0x2149,0x2149,0x2149}, - {0x214A,0x214A,0x214A}, {0x214B,0x214B,0x214B}, - {0x214C,0x214C,0x214C}, {0x214D,0x214D,0x214D}, - {0x214E,0x214E,0x214E}, {0x214F,0x214F,0x214F}, - {0x2150,0x2150,0x2150}, {0x2151,0x2151,0x2151}, - {0x2152,0x2152,0x2152}, {0x2153,0x2153,0x2153}, - {0x2154,0x2154,0x2154}, {0x2155,0x2155,0x2155}, - {0x2156,0x2156,0x2156}, {0x2157,0x2157,0x2157}, - {0x2158,0x2158,0x2158}, {0x2159,0x2159,0x2159}, - {0x215A,0x215A,0x215A}, {0x215B,0x215B,0x215B}, - {0x215C,0x215C,0x215C}, {0x215D,0x215D,0x215D}, - {0x215E,0x215E,0x215E}, {0x215F,0x215F,0x215F}, - {0x2160,0x2170,0x2160}, {0x2161,0x2171,0x2161}, - {0x2162,0x2172,0x2162}, {0x2163,0x2173,0x2163}, - {0x2164,0x2174,0x2164}, {0x2165,0x2175,0x2165}, - {0x2166,0x2176,0x2166}, {0x2167,0x2177,0x2167}, - {0x2168,0x2178,0x2168}, {0x2169,0x2179,0x2169}, - {0x216A,0x217A,0x216A}, {0x216B,0x217B,0x216B}, - {0x216C,0x217C,0x216C}, {0x216D,0x217D,0x216D}, - {0x216E,0x217E,0x216E}, {0x216F,0x217F,0x216F}, - {0x2160,0x2170,0x2160}, {0x2161,0x2171,0x2161}, - {0x2162,0x2172,0x2162}, {0x2163,0x2173,0x2163}, - {0x2164,0x2174,0x2164}, {0x2165,0x2175,0x2165}, - {0x2166,0x2176,0x2166}, {0x2167,0x2177,0x2167}, - {0x2168,0x2178,0x2168}, {0x2169,0x2179,0x2169}, - {0x216A,0x217A,0x216A}, {0x216B,0x217B,0x216B}, - {0x216C,0x217C,0x216C}, {0x216D,0x217D,0x216D}, - {0x216E,0x217E,0x216E}, {0x216F,0x217F,0x216F}, - {0x2180,0x2180,0x2180}, {0x2181,0x2181,0x2181}, - {0x2182,0x2182,0x2182}, {0x2183,0x2183,0x2183}, - {0x2184,0x2184,0x2184}, {0x2185,0x2185,0x2185}, - {0x2186,0x2186,0x2186}, {0x2187,0x2187,0x2187}, - {0x2188,0x2188,0x2188}, {0x2189,0x2189,0x2189}, - {0x218A,0x218A,0x218A}, {0x218B,0x218B,0x218B}, - {0x218C,0x218C,0x218C}, {0x218D,0x218D,0x218D}, - {0x218E,0x218E,0x218E}, {0x218F,0x218F,0x218F}, - {0x2190,0x2190,0x2190}, {0x2191,0x2191,0x2191}, - {0x2192,0x2192,0x2192}, {0x2193,0x2193,0x2193}, - {0x2194,0x2194,0x2194}, {0x2195,0x2195,0x2195}, - {0x2196,0x2196,0x2196}, {0x2197,0x2197,0x2197}, - {0x2198,0x2198,0x2198}, {0x2199,0x2199,0x2199}, - {0x219A,0x219A,0x219A}, {0x219B,0x219B,0x219B}, - {0x219C,0x219C,0x219C}, {0x219D,0x219D,0x219D}, - {0x219E,0x219E,0x219E}, {0x219F,0x219F,0x219F}, - {0x21A0,0x21A0,0x21A0}, {0x21A1,0x21A1,0x21A1}, - {0x21A2,0x21A2,0x21A2}, {0x21A3,0x21A3,0x21A3}, - {0x21A4,0x21A4,0x21A4}, {0x21A5,0x21A5,0x21A5}, - {0x21A6,0x21A6,0x21A6}, {0x21A7,0x21A7,0x21A7}, - {0x21A8,0x21A8,0x21A8}, {0x21A9,0x21A9,0x21A9}, - {0x21AA,0x21AA,0x21AA}, {0x21AB,0x21AB,0x21AB}, - {0x21AC,0x21AC,0x21AC}, {0x21AD,0x21AD,0x21AD}, - {0x21AE,0x21AE,0x21AE}, {0x21AF,0x21AF,0x21AF}, - {0x21B0,0x21B0,0x21B0}, {0x21B1,0x21B1,0x21B1}, - {0x21B2,0x21B2,0x21B2}, {0x21B3,0x21B3,0x21B3}, - {0x21B4,0x21B4,0x21B4}, {0x21B5,0x21B5,0x21B5}, - {0x21B6,0x21B6,0x21B6}, {0x21B7,0x21B7,0x21B7}, - {0x21B8,0x21B8,0x21B8}, {0x21B9,0x21B9,0x21B9}, - {0x21BA,0x21BA,0x21BA}, {0x21BB,0x21BB,0x21BB}, - {0x21BC,0x21BC,0x21BC}, {0x21BD,0x21BD,0x21BD}, - {0x21BE,0x21BE,0x21BE}, {0x21BF,0x21BF,0x21BF}, - {0x21C0,0x21C0,0x21C0}, {0x21C1,0x21C1,0x21C1}, - {0x21C2,0x21C2,0x21C2}, {0x21C3,0x21C3,0x21C3}, - {0x21C4,0x21C4,0x21C4}, {0x21C5,0x21C5,0x21C5}, - {0x21C6,0x21C6,0x21C6}, {0x21C7,0x21C7,0x21C7}, - {0x21C8,0x21C8,0x21C8}, {0x21C9,0x21C9,0x21C9}, - {0x21CA,0x21CA,0x21CA}, {0x21CB,0x21CB,0x21CB}, - {0x21CC,0x21CC,0x21CC}, {0x21CD,0x21CD,0x21CD}, - {0x21CE,0x21CE,0x21CE}, {0x21CF,0x21CF,0x21CF}, - {0x21D0,0x21D0,0x21D0}, {0x21D1,0x21D1,0x21D1}, - {0x21D2,0x21D2,0x21D2}, {0x21D3,0x21D3,0x21D3}, - {0x21D4,0x21D4,0x21D4}, {0x21D5,0x21D5,0x21D5}, - {0x21D6,0x21D6,0x21D6}, {0x21D7,0x21D7,0x21D7}, - {0x21D8,0x21D8,0x21D8}, {0x21D9,0x21D9,0x21D9}, - {0x21DA,0x21DA,0x21DA}, {0x21DB,0x21DB,0x21DB}, - {0x21DC,0x21DC,0x21DC}, {0x21DD,0x21DD,0x21DD}, - {0x21DE,0x21DE,0x21DE}, {0x21DF,0x21DF,0x21DF}, - {0x21E0,0x21E0,0x21E0}, {0x21E1,0x21E1,0x21E1}, - {0x21E2,0x21E2,0x21E2}, {0x21E3,0x21E3,0x21E3}, - {0x21E4,0x21E4,0x21E4}, {0x21E5,0x21E5,0x21E5}, - {0x21E6,0x21E6,0x21E6}, {0x21E7,0x21E7,0x21E7}, - {0x21E8,0x21E8,0x21E8}, {0x21E9,0x21E9,0x21E9}, - {0x21EA,0x21EA,0x21EA}, {0x21EB,0x21EB,0x21EB}, - {0x21EC,0x21EC,0x21EC}, {0x21ED,0x21ED,0x21ED}, - {0x21EE,0x21EE,0x21EE}, {0x21EF,0x21EF,0x21EF}, - {0x21F0,0x21F0,0x21F0}, {0x21F1,0x21F1,0x21F1}, - {0x21F2,0x21F2,0x21F2}, {0x21F3,0x21F3,0x21F3}, - {0x21F4,0x21F4,0x21F4}, {0x21F5,0x21F5,0x21F5}, - {0x21F6,0x21F6,0x21F6}, {0x21F7,0x21F7,0x21F7}, - {0x21F8,0x21F8,0x21F8}, {0x21F9,0x21F9,0x21F9}, - {0x21FA,0x21FA,0x21FA}, {0x21FB,0x21FB,0x21FB}, - {0x21FC,0x21FC,0x21FC}, {0x21FD,0x21FD,0x21FD}, - {0x21FE,0x21FE,0x21FE}, {0x21FF,0x21FF,0x21FF} -}; - -static MY_UNICASE_INFO plane24[]={ - {0x2400,0x2400,0x2400}, {0x2401,0x2401,0x2401}, - {0x2402,0x2402,0x2402}, {0x2403,0x2403,0x2403}, - {0x2404,0x2404,0x2404}, {0x2405,0x2405,0x2405}, - {0x2406,0x2406,0x2406}, {0x2407,0x2407,0x2407}, - {0x2408,0x2408,0x2408}, {0x2409,0x2409,0x2409}, - {0x240A,0x240A,0x240A}, {0x240B,0x240B,0x240B}, - {0x240C,0x240C,0x240C}, {0x240D,0x240D,0x240D}, - {0x240E,0x240E,0x240E}, {0x240F,0x240F,0x240F}, - {0x2410,0x2410,0x2410}, {0x2411,0x2411,0x2411}, - {0x2412,0x2412,0x2412}, {0x2413,0x2413,0x2413}, - {0x2414,0x2414,0x2414}, {0x2415,0x2415,0x2415}, - {0x2416,0x2416,0x2416}, {0x2417,0x2417,0x2417}, - {0x2418,0x2418,0x2418}, {0x2419,0x2419,0x2419}, - {0x241A,0x241A,0x241A}, {0x241B,0x241B,0x241B}, - {0x241C,0x241C,0x241C}, {0x241D,0x241D,0x241D}, - {0x241E,0x241E,0x241E}, {0x241F,0x241F,0x241F}, - {0x2420,0x2420,0x2420}, {0x2421,0x2421,0x2421}, - {0x2422,0x2422,0x2422}, {0x2423,0x2423,0x2423}, - {0x2424,0x2424,0x2424}, {0x2425,0x2425,0x2425}, - {0x2426,0x2426,0x2426}, {0x2427,0x2427,0x2427}, - {0x2428,0x2428,0x2428}, {0x2429,0x2429,0x2429}, - {0x242A,0x242A,0x242A}, {0x242B,0x242B,0x242B}, - {0x242C,0x242C,0x242C}, {0x242D,0x242D,0x242D}, - {0x242E,0x242E,0x242E}, {0x242F,0x242F,0x242F}, - {0x2430,0x2430,0x2430}, {0x2431,0x2431,0x2431}, - {0x2432,0x2432,0x2432}, {0x2433,0x2433,0x2433}, - {0x2434,0x2434,0x2434}, {0x2435,0x2435,0x2435}, - {0x2436,0x2436,0x2436}, {0x2437,0x2437,0x2437}, - {0x2438,0x2438,0x2438}, {0x2439,0x2439,0x2439}, - {0x243A,0x243A,0x243A}, {0x243B,0x243B,0x243B}, - {0x243C,0x243C,0x243C}, {0x243D,0x243D,0x243D}, - {0x243E,0x243E,0x243E}, {0x243F,0x243F,0x243F}, - {0x2440,0x2440,0x2440}, {0x2441,0x2441,0x2441}, - {0x2442,0x2442,0x2442}, {0x2443,0x2443,0x2443}, - {0x2444,0x2444,0x2444}, {0x2445,0x2445,0x2445}, - {0x2446,0x2446,0x2446}, {0x2447,0x2447,0x2447}, - {0x2448,0x2448,0x2448}, {0x2449,0x2449,0x2449}, - {0x244A,0x244A,0x244A}, {0x244B,0x244B,0x244B}, - {0x244C,0x244C,0x244C}, {0x244D,0x244D,0x244D}, - {0x244E,0x244E,0x244E}, {0x244F,0x244F,0x244F}, - {0x2450,0x2450,0x2450}, {0x2451,0x2451,0x2451}, - {0x2452,0x2452,0x2452}, {0x2453,0x2453,0x2453}, - {0x2454,0x2454,0x2454}, {0x2455,0x2455,0x2455}, - {0x2456,0x2456,0x2456}, {0x2457,0x2457,0x2457}, - {0x2458,0x2458,0x2458}, {0x2459,0x2459,0x2459}, - {0x245A,0x245A,0x245A}, {0x245B,0x245B,0x245B}, - {0x245C,0x245C,0x245C}, {0x245D,0x245D,0x245D}, - {0x245E,0x245E,0x245E}, {0x245F,0x245F,0x245F}, - {0x2460,0x2460,0x2460}, {0x2461,0x2461,0x2461}, - {0x2462,0x2462,0x2462}, {0x2463,0x2463,0x2463}, - {0x2464,0x2464,0x2464}, {0x2465,0x2465,0x2465}, - {0x2466,0x2466,0x2466}, {0x2467,0x2467,0x2467}, - {0x2468,0x2468,0x2468}, {0x2469,0x2469,0x2469}, - {0x246A,0x246A,0x246A}, {0x246B,0x246B,0x246B}, - {0x246C,0x246C,0x246C}, {0x246D,0x246D,0x246D}, - {0x246E,0x246E,0x246E}, {0x246F,0x246F,0x246F}, - {0x2470,0x2470,0x2470}, {0x2471,0x2471,0x2471}, - {0x2472,0x2472,0x2472}, {0x2473,0x2473,0x2473}, - {0x2474,0x2474,0x2474}, {0x2475,0x2475,0x2475}, - {0x2476,0x2476,0x2476}, {0x2477,0x2477,0x2477}, - {0x2478,0x2478,0x2478}, {0x2479,0x2479,0x2479}, - {0x247A,0x247A,0x247A}, {0x247B,0x247B,0x247B}, - {0x247C,0x247C,0x247C}, {0x247D,0x247D,0x247D}, - {0x247E,0x247E,0x247E}, {0x247F,0x247F,0x247F}, - {0x2480,0x2480,0x2480}, {0x2481,0x2481,0x2481}, - {0x2482,0x2482,0x2482}, {0x2483,0x2483,0x2483}, - {0x2484,0x2484,0x2484}, {0x2485,0x2485,0x2485}, - {0x2486,0x2486,0x2486}, {0x2487,0x2487,0x2487}, - {0x2488,0x2488,0x2488}, {0x2489,0x2489,0x2489}, - {0x248A,0x248A,0x248A}, {0x248B,0x248B,0x248B}, - {0x248C,0x248C,0x248C}, {0x248D,0x248D,0x248D}, - {0x248E,0x248E,0x248E}, {0x248F,0x248F,0x248F}, - {0x2490,0x2490,0x2490}, {0x2491,0x2491,0x2491}, - {0x2492,0x2492,0x2492}, {0x2493,0x2493,0x2493}, - {0x2494,0x2494,0x2494}, {0x2495,0x2495,0x2495}, - {0x2496,0x2496,0x2496}, {0x2497,0x2497,0x2497}, - {0x2498,0x2498,0x2498}, {0x2499,0x2499,0x2499}, - {0x249A,0x249A,0x249A}, {0x249B,0x249B,0x249B}, - {0x249C,0x249C,0x249C}, {0x249D,0x249D,0x249D}, - {0x249E,0x249E,0x249E}, {0x249F,0x249F,0x249F}, - {0x24A0,0x24A0,0x24A0}, {0x24A1,0x24A1,0x24A1}, - {0x24A2,0x24A2,0x24A2}, {0x24A3,0x24A3,0x24A3}, - {0x24A4,0x24A4,0x24A4}, {0x24A5,0x24A5,0x24A5}, - {0x24A6,0x24A6,0x24A6}, {0x24A7,0x24A7,0x24A7}, - {0x24A8,0x24A8,0x24A8}, {0x24A9,0x24A9,0x24A9}, - {0x24AA,0x24AA,0x24AA}, {0x24AB,0x24AB,0x24AB}, - {0x24AC,0x24AC,0x24AC}, {0x24AD,0x24AD,0x24AD}, - {0x24AE,0x24AE,0x24AE}, {0x24AF,0x24AF,0x24AF}, - {0x24B0,0x24B0,0x24B0}, {0x24B1,0x24B1,0x24B1}, - {0x24B2,0x24B2,0x24B2}, {0x24B3,0x24B3,0x24B3}, - {0x24B4,0x24B4,0x24B4}, {0x24B5,0x24B5,0x24B5}, - {0x24B6,0x24D0,0x24B6}, {0x24B7,0x24D1,0x24B7}, - {0x24B8,0x24D2,0x24B8}, {0x24B9,0x24D3,0x24B9}, - {0x24BA,0x24D4,0x24BA}, {0x24BB,0x24D5,0x24BB}, - {0x24BC,0x24D6,0x24BC}, {0x24BD,0x24D7,0x24BD}, - {0x24BE,0x24D8,0x24BE}, {0x24BF,0x24D9,0x24BF}, - {0x24C0,0x24DA,0x24C0}, {0x24C1,0x24DB,0x24C1}, - {0x24C2,0x24DC,0x24C2}, {0x24C3,0x24DD,0x24C3}, - {0x24C4,0x24DE,0x24C4}, {0x24C5,0x24DF,0x24C5}, - {0x24C6,0x24E0,0x24C6}, {0x24C7,0x24E1,0x24C7}, - {0x24C8,0x24E2,0x24C8}, {0x24C9,0x24E3,0x24C9}, - {0x24CA,0x24E4,0x24CA}, {0x24CB,0x24E5,0x24CB}, - {0x24CC,0x24E6,0x24CC}, {0x24CD,0x24E7,0x24CD}, - {0x24CE,0x24E8,0x24CE}, {0x24CF,0x24E9,0x24CF}, - {0x24B6,0x24D0,0x24B6}, {0x24B7,0x24D1,0x24B7}, - {0x24B8,0x24D2,0x24B8}, {0x24B9,0x24D3,0x24B9}, - {0x24BA,0x24D4,0x24BA}, {0x24BB,0x24D5,0x24BB}, - {0x24BC,0x24D6,0x24BC}, {0x24BD,0x24D7,0x24BD}, - {0x24BE,0x24D8,0x24BE}, {0x24BF,0x24D9,0x24BF}, - {0x24C0,0x24DA,0x24C0}, {0x24C1,0x24DB,0x24C1}, - {0x24C2,0x24DC,0x24C2}, {0x24C3,0x24DD,0x24C3}, - {0x24C4,0x24DE,0x24C4}, {0x24C5,0x24DF,0x24C5}, - {0x24C6,0x24E0,0x24C6}, {0x24C7,0x24E1,0x24C7}, - {0x24C8,0x24E2,0x24C8}, {0x24C9,0x24E3,0x24C9}, - {0x24CA,0x24E4,0x24CA}, {0x24CB,0x24E5,0x24CB}, - {0x24CC,0x24E6,0x24CC}, {0x24CD,0x24E7,0x24CD}, - {0x24CE,0x24E8,0x24CE}, {0x24CF,0x24E9,0x24CF}, - {0x24EA,0x24EA,0x24EA}, {0x24EB,0x24EB,0x24EB}, - {0x24EC,0x24EC,0x24EC}, {0x24ED,0x24ED,0x24ED}, - {0x24EE,0x24EE,0x24EE}, {0x24EF,0x24EF,0x24EF}, - {0x24F0,0x24F0,0x24F0}, {0x24F1,0x24F1,0x24F1}, - {0x24F2,0x24F2,0x24F2}, {0x24F3,0x24F3,0x24F3}, - {0x24F4,0x24F4,0x24F4}, {0x24F5,0x24F5,0x24F5}, - {0x24F6,0x24F6,0x24F6}, {0x24F7,0x24F7,0x24F7}, - {0x24F8,0x24F8,0x24F8}, {0x24F9,0x24F9,0x24F9}, - {0x24FA,0x24FA,0x24FA}, {0x24FB,0x24FB,0x24FB}, - {0x24FC,0x24FC,0x24FC}, {0x24FD,0x24FD,0x24FD}, - {0x24FE,0x24FE,0x24FE}, {0x24FF,0x24FF,0x24FF} -}; - -static MY_UNICASE_INFO planeFF[]={ - {0xFF00,0xFF00,0xFF00}, {0xFF01,0xFF01,0xFF01}, - {0xFF02,0xFF02,0xFF02}, {0xFF03,0xFF03,0xFF03}, - {0xFF04,0xFF04,0xFF04}, {0xFF05,0xFF05,0xFF05}, - {0xFF06,0xFF06,0xFF06}, {0xFF07,0xFF07,0xFF07}, - {0xFF08,0xFF08,0xFF08}, {0xFF09,0xFF09,0xFF09}, - {0xFF0A,0xFF0A,0xFF0A}, {0xFF0B,0xFF0B,0xFF0B}, - {0xFF0C,0xFF0C,0xFF0C}, {0xFF0D,0xFF0D,0xFF0D}, - {0xFF0E,0xFF0E,0xFF0E}, {0xFF0F,0xFF0F,0xFF0F}, - {0xFF10,0xFF10,0xFF10}, {0xFF11,0xFF11,0xFF11}, - {0xFF12,0xFF12,0xFF12}, {0xFF13,0xFF13,0xFF13}, - {0xFF14,0xFF14,0xFF14}, {0xFF15,0xFF15,0xFF15}, - {0xFF16,0xFF16,0xFF16}, {0xFF17,0xFF17,0xFF17}, - {0xFF18,0xFF18,0xFF18}, {0xFF19,0xFF19,0xFF19}, - {0xFF1A,0xFF1A,0xFF1A}, {0xFF1B,0xFF1B,0xFF1B}, - {0xFF1C,0xFF1C,0xFF1C}, {0xFF1D,0xFF1D,0xFF1D}, - {0xFF1E,0xFF1E,0xFF1E}, {0xFF1F,0xFF1F,0xFF1F}, - {0xFF20,0xFF20,0xFF20}, {0xFF21,0xFF41,0xFF21}, - {0xFF22,0xFF42,0xFF22}, {0xFF23,0xFF43,0xFF23}, - {0xFF24,0xFF44,0xFF24}, {0xFF25,0xFF45,0xFF25}, - {0xFF26,0xFF46,0xFF26}, {0xFF27,0xFF47,0xFF27}, - {0xFF28,0xFF48,0xFF28}, {0xFF29,0xFF49,0xFF29}, - {0xFF2A,0xFF4A,0xFF2A}, {0xFF2B,0xFF4B,0xFF2B}, - {0xFF2C,0xFF4C,0xFF2C}, {0xFF2D,0xFF4D,0xFF2D}, - {0xFF2E,0xFF4E,0xFF2E}, {0xFF2F,0xFF4F,0xFF2F}, - {0xFF30,0xFF50,0xFF30}, {0xFF31,0xFF51,0xFF31}, - {0xFF32,0xFF52,0xFF32}, {0xFF33,0xFF53,0xFF33}, - {0xFF34,0xFF54,0xFF34}, {0xFF35,0xFF55,0xFF35}, - {0xFF36,0xFF56,0xFF36}, {0xFF37,0xFF57,0xFF37}, - {0xFF38,0xFF58,0xFF38}, {0xFF39,0xFF59,0xFF39}, - {0xFF3A,0xFF5A,0xFF3A}, {0xFF3B,0xFF3B,0xFF3B}, - {0xFF3C,0xFF3C,0xFF3C}, {0xFF3D,0xFF3D,0xFF3D}, - {0xFF3E,0xFF3E,0xFF3E}, {0xFF3F,0xFF3F,0xFF3F}, - {0xFF40,0xFF40,0xFF40}, {0xFF21,0xFF41,0xFF21}, - {0xFF22,0xFF42,0xFF22}, {0xFF23,0xFF43,0xFF23}, - {0xFF24,0xFF44,0xFF24}, {0xFF25,0xFF45,0xFF25}, - {0xFF26,0xFF46,0xFF26}, {0xFF27,0xFF47,0xFF27}, - {0xFF28,0xFF48,0xFF28}, {0xFF29,0xFF49,0xFF29}, - {0xFF2A,0xFF4A,0xFF2A}, {0xFF2B,0xFF4B,0xFF2B}, - {0xFF2C,0xFF4C,0xFF2C}, {0xFF2D,0xFF4D,0xFF2D}, - {0xFF2E,0xFF4E,0xFF2E}, {0xFF2F,0xFF4F,0xFF2F}, - {0xFF30,0xFF50,0xFF30}, {0xFF31,0xFF51,0xFF31}, - {0xFF32,0xFF52,0xFF32}, {0xFF33,0xFF53,0xFF33}, - {0xFF34,0xFF54,0xFF34}, {0xFF35,0xFF55,0xFF35}, - {0xFF36,0xFF56,0xFF36}, {0xFF37,0xFF57,0xFF37}, - {0xFF38,0xFF58,0xFF38}, {0xFF39,0xFF59,0xFF39}, - {0xFF3A,0xFF5A,0xFF3A}, {0xFF5B,0xFF5B,0xFF5B}, - {0xFF5C,0xFF5C,0xFF5C}, {0xFF5D,0xFF5D,0xFF5D}, - {0xFF5E,0xFF5E,0xFF5E}, {0xFF5F,0xFF5F,0xFF5F}, - {0xFF60,0xFF60,0xFF60}, {0xFF61,0xFF61,0xFF61}, - {0xFF62,0xFF62,0xFF62}, {0xFF63,0xFF63,0xFF63}, - {0xFF64,0xFF64,0xFF64}, {0xFF65,0xFF65,0xFF65}, - {0xFF66,0xFF66,0xFF66}, {0xFF67,0xFF67,0xFF67}, - {0xFF68,0xFF68,0xFF68}, {0xFF69,0xFF69,0xFF69}, - {0xFF6A,0xFF6A,0xFF6A}, {0xFF6B,0xFF6B,0xFF6B}, - {0xFF6C,0xFF6C,0xFF6C}, {0xFF6D,0xFF6D,0xFF6D}, - {0xFF6E,0xFF6E,0xFF6E}, {0xFF6F,0xFF6F,0xFF6F}, - {0xFF70,0xFF70,0xFF70}, {0xFF71,0xFF71,0xFF71}, - {0xFF72,0xFF72,0xFF72}, {0xFF73,0xFF73,0xFF73}, - {0xFF74,0xFF74,0xFF74}, {0xFF75,0xFF75,0xFF75}, - {0xFF76,0xFF76,0xFF76}, {0xFF77,0xFF77,0xFF77}, - {0xFF78,0xFF78,0xFF78}, {0xFF79,0xFF79,0xFF79}, - {0xFF7A,0xFF7A,0xFF7A}, {0xFF7B,0xFF7B,0xFF7B}, - {0xFF7C,0xFF7C,0xFF7C}, {0xFF7D,0xFF7D,0xFF7D}, - {0xFF7E,0xFF7E,0xFF7E}, {0xFF7F,0xFF7F,0xFF7F}, - {0xFF80,0xFF80,0xFF80}, {0xFF81,0xFF81,0xFF81}, - {0xFF82,0xFF82,0xFF82}, {0xFF83,0xFF83,0xFF83}, - {0xFF84,0xFF84,0xFF84}, {0xFF85,0xFF85,0xFF85}, - {0xFF86,0xFF86,0xFF86}, {0xFF87,0xFF87,0xFF87}, - {0xFF88,0xFF88,0xFF88}, {0xFF89,0xFF89,0xFF89}, - {0xFF8A,0xFF8A,0xFF8A}, {0xFF8B,0xFF8B,0xFF8B}, - {0xFF8C,0xFF8C,0xFF8C}, {0xFF8D,0xFF8D,0xFF8D}, - {0xFF8E,0xFF8E,0xFF8E}, {0xFF8F,0xFF8F,0xFF8F}, - {0xFF90,0xFF90,0xFF90}, {0xFF91,0xFF91,0xFF91}, - {0xFF92,0xFF92,0xFF92}, {0xFF93,0xFF93,0xFF93}, - {0xFF94,0xFF94,0xFF94}, {0xFF95,0xFF95,0xFF95}, - {0xFF96,0xFF96,0xFF96}, {0xFF97,0xFF97,0xFF97}, - {0xFF98,0xFF98,0xFF98}, {0xFF99,0xFF99,0xFF99}, - {0xFF9A,0xFF9A,0xFF9A}, {0xFF9B,0xFF9B,0xFF9B}, - {0xFF9C,0xFF9C,0xFF9C}, {0xFF9D,0xFF9D,0xFF9D}, - {0xFF9E,0xFF9E,0xFF9E}, {0xFF9F,0xFF9F,0xFF9F}, - {0xFFA0,0xFFA0,0xFFA0}, {0xFFA1,0xFFA1,0xFFA1}, - {0xFFA2,0xFFA2,0xFFA2}, {0xFFA3,0xFFA3,0xFFA3}, - {0xFFA4,0xFFA4,0xFFA4}, {0xFFA5,0xFFA5,0xFFA5}, - {0xFFA6,0xFFA6,0xFFA6}, {0xFFA7,0xFFA7,0xFFA7}, - {0xFFA8,0xFFA8,0xFFA8}, {0xFFA9,0xFFA9,0xFFA9}, - {0xFFAA,0xFFAA,0xFFAA}, {0xFFAB,0xFFAB,0xFFAB}, - {0xFFAC,0xFFAC,0xFFAC}, {0xFFAD,0xFFAD,0xFFAD}, - {0xFFAE,0xFFAE,0xFFAE}, {0xFFAF,0xFFAF,0xFFAF}, - {0xFFB0,0xFFB0,0xFFB0}, {0xFFB1,0xFFB1,0xFFB1}, - {0xFFB2,0xFFB2,0xFFB2}, {0xFFB3,0xFFB3,0xFFB3}, - {0xFFB4,0xFFB4,0xFFB4}, {0xFFB5,0xFFB5,0xFFB5}, - {0xFFB6,0xFFB6,0xFFB6}, {0xFFB7,0xFFB7,0xFFB7}, - {0xFFB8,0xFFB8,0xFFB8}, {0xFFB9,0xFFB9,0xFFB9}, - {0xFFBA,0xFFBA,0xFFBA}, {0xFFBB,0xFFBB,0xFFBB}, - {0xFFBC,0xFFBC,0xFFBC}, {0xFFBD,0xFFBD,0xFFBD}, - {0xFFBE,0xFFBE,0xFFBE}, {0xFFBF,0xFFBF,0xFFBF}, - {0xFFC0,0xFFC0,0xFFC0}, {0xFFC1,0xFFC1,0xFFC1}, - {0xFFC2,0xFFC2,0xFFC2}, {0xFFC3,0xFFC3,0xFFC3}, - {0xFFC4,0xFFC4,0xFFC4}, {0xFFC5,0xFFC5,0xFFC5}, - {0xFFC6,0xFFC6,0xFFC6}, {0xFFC7,0xFFC7,0xFFC7}, - {0xFFC8,0xFFC8,0xFFC8}, {0xFFC9,0xFFC9,0xFFC9}, - {0xFFCA,0xFFCA,0xFFCA}, {0xFFCB,0xFFCB,0xFFCB}, - {0xFFCC,0xFFCC,0xFFCC}, {0xFFCD,0xFFCD,0xFFCD}, - {0xFFCE,0xFFCE,0xFFCE}, {0xFFCF,0xFFCF,0xFFCF}, - {0xFFD0,0xFFD0,0xFFD0}, {0xFFD1,0xFFD1,0xFFD1}, - {0xFFD2,0xFFD2,0xFFD2}, {0xFFD3,0xFFD3,0xFFD3}, - {0xFFD4,0xFFD4,0xFFD4}, {0xFFD5,0xFFD5,0xFFD5}, - {0xFFD6,0xFFD6,0xFFD6}, {0xFFD7,0xFFD7,0xFFD7}, - {0xFFD8,0xFFD8,0xFFD8}, {0xFFD9,0xFFD9,0xFFD9}, - {0xFFDA,0xFFDA,0xFFDA}, {0xFFDB,0xFFDB,0xFFDB}, - {0xFFDC,0xFFDC,0xFFDC}, {0xFFDD,0xFFDD,0xFFDD}, - {0xFFDE,0xFFDE,0xFFDE}, {0xFFDF,0xFFDF,0xFFDF}, - {0xFFE0,0xFFE0,0xFFE0}, {0xFFE1,0xFFE1,0xFFE1}, - {0xFFE2,0xFFE2,0xFFE2}, {0xFFE3,0xFFE3,0xFFE3}, - {0xFFE4,0xFFE4,0xFFE4}, {0xFFE5,0xFFE5,0xFFE5}, - {0xFFE6,0xFFE6,0xFFE6}, {0xFFE7,0xFFE7,0xFFE7}, - {0xFFE8,0xFFE8,0xFFE8}, {0xFFE9,0xFFE9,0xFFE9}, - {0xFFEA,0xFFEA,0xFFEA}, {0xFFEB,0xFFEB,0xFFEB}, - {0xFFEC,0xFFEC,0xFFEC}, {0xFFED,0xFFED,0xFFED}, - {0xFFEE,0xFFEE,0xFFEE}, {0xFFEF,0xFFEF,0xFFEF}, - {0xFFF0,0xFFF0,0xFFF0}, {0xFFF1,0xFFF1,0xFFF1}, - {0xFFF2,0xFFF2,0xFFF2}, {0xFFF3,0xFFF3,0xFFF3}, - {0xFFF4,0xFFF4,0xFFF4}, {0xFFF5,0xFFF5,0xFFF5}, - {0xFFF6,0xFFF6,0xFFF6}, {0xFFF7,0xFFF7,0xFFF7}, - {0xFFF8,0xFFF8,0xFFF8}, {0xFFF9,0xFFF9,0xFFF9}, - {0xFFFA,0xFFFA,0xFFFA}, {0xFFFB,0xFFFB,0xFFFB}, - {0xFFFC,0xFFFC,0xFFFC}, {0xFFFD,0xFFFD,0xFFFD}, - {0xFFFE,0xFFFE,0xFFFE}, {0xFFFF,0xFFFF,0xFFFF} -}; - -MY_UNICASE_INFO *my_unicase_default[256]={ - plane00, plane01, plane02, plane03, plane04, plane05, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, plane1E, plane1F, - NULL, plane21, NULL, NULL, plane24, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, planeFF - -}; - -#define MY_CS_ILSEQ 0 /* Wrong by sequence: wb_wc */ -#define MY_CS_TOOSMALL -101 /* Need at least one byte: wc_mb and mb_wc */ -#define MY_CS_TOOSMALL2 -102 /* Need at least two bytes: wc_mb and mb_wc */ -#define MY_CS_TOOSMALL3 -103 /* Need at least three bytes: wc_mb and mb_wc */ -#define MY_CS_TOOSMALL4 -104 /* Need at least 4 bytes: wc_mb and mb_wc */ -#define MY_CS_TOOSMALL5 -105 /* Need at least 5 bytes: wc_mb and mb_wc */ -#define MY_CS_TOOSMALL6 -106 /* Need at least 6 bytes: wc_mb and mb_wc */ - - -static int my_utf8_uni(ulong * pwc, const uchar *s, const uchar *e) -{ - uchar c; - - if (s >= e) - return MY_CS_TOOSMALL; - - c= s[0]; - if (c < 0x80) - { - *pwc = c; - return 1; - } - else if (c < 0xc2) - return MY_CS_ILSEQ; - else if (c < 0xe0) - { - if (s+2 > e) /* We need 2 characters */ - return MY_CS_TOOSMALL2; - - if (!((s[1] ^ 0x80) < 0x40)) - return MY_CS_ILSEQ; - - *pwc = ((ulong) (c & 0x1f) << 6) | (ulong) (s[1] ^ 0x80); - return 2; - } - else if (c < 0xf0) - { - if (s+3 > e) /* We need 3 characters */ - return MY_CS_TOOSMALL3; - - if (!((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 && - (c >= 0xe1 || s[1] >= 0xa0))) - return MY_CS_ILSEQ; - - *pwc = ((ulong) (c & 0x0f) << 12) | - ((ulong) (s[1] ^ 0x80) << 6) | - (ulong) (s[2] ^ 0x80); - - return 3; - } -#ifdef UNICODE_32BIT - else if (c < 0xf8 && sizeof(my_wc_t)*8 >= 32) - { - if (s+4 > e) /* We need 4 characters */ - return MY_CS_TOOSMALL4; - - if (!((s[1] ^ 0x80) < 0x40 && - (s[2] ^ 0x80) < 0x40 && - (s[3] ^ 0x80) < 0x40 && - (c >= 0xf1 || s[1] >= 0x90))) - return MY_CS_ILSEQ; - - *pwc = ((ulong) (c & 0x07) << 18) | - ((ulong) (s[1] ^ 0x80) << 12) | - ((ulong) (s[2] ^ 0x80) << 6) | - (ulong) (s[3] ^ 0x80); - - return 4; - } - else if (c < 0xfc && sizeof(my_wc_t)*8 >= 32) - { - if (s+5 >e) /* We need 5 characters */ - return MY_CS_TOOSMALL5; - - if (!((s[1] ^ 0x80) < 0x40 && - (s[2] ^ 0x80) < 0x40 && - (s[3] ^ 0x80) < 0x40 && - (s[4] ^ 0x80) < 0x40 && - (c >= 0xf9 || s[1] >= 0x88))) - return MY_CS_ILSEQ; - - *pwc = ((ulong) (c & 0x03) << 24) | - ((ulong) (s[1] ^ 0x80) << 18) | - ((ulong) (s[2] ^ 0x80) << 12) | - ((ulong) (s[3] ^ 0x80) << 6) | - (ulong) (s[4] ^ 0x80); - return 5; - } - else if (c < 0xfe && sizeof(my_wc_t)*8 >= 32) - { - if ( s+6 >e ) /* We need 6 characters */ - return MY_CS_TOOSMALL6; - - if (!((s[1] ^ 0x80) < 0x40 && - (s[2] ^ 0x80) < 0x40 && - (s[3] ^ 0x80) < 0x40 && - (s[4] ^ 0x80) < 0x40 && - (s[5] ^ 0x80) < 0x40 && - (c >= 0xfd || s[1] >= 0x84))) - return MY_CS_ILSEQ; - - *pwc = ((ulong) (c & 0x01) << 30) - | ((ulong) (s[1] ^ 0x80) << 24) - | ((ulong) (s[2] ^ 0x80) << 18) - | ((ulong) (s[3] ^ 0x80) << 12) - | ((ulong) (s[4] ^ 0x80) << 6) - | (ulong) (s[5] ^ 0x80); - return 6; - } -#endif - return MY_CS_ILSEQ; -} - -#define MY_CS_ILUNI 0 /* Cannot encode Unicode to charset: wc_mb */ -#define MY_CS_TOOSMALLN(n) (-100-(n)) - -static int my_uni_utf8(ulong wc, uchar *r, uchar *e) -{ - int count; - - if (r >= e) - return MY_CS_TOOSMALL; - - if (wc < 0x80) - count = 1; - else if (wc < 0x800) - count = 2; - else if (wc < 0x10000) - count = 3; -#ifdef UNICODE_32BIT - else if (wc < 0x200000) - count = 4; - else if (wc < 0x4000000) - count = 5; - else if (wc <= 0x7fffffff) - count = 6; -#endif - else return MY_CS_ILUNI; - - /* - e is a character after the string r, not the last character of it. - Because of it (r+count > e), not (r+count-1 >e ) - */ - if ( r+count > e ) - return MY_CS_TOOSMALLN(count); - - switch (count) { - /* Fall through all cases!!! */ -#ifdef UNICODE_32BIT - case 6: r[5] = (uchar) (0x80 | (wc & 0x3f)); wc = wc >> 6; wc |= 0x4000000; - case 5: r[4] = (uchar) (0x80 | (wc & 0x3f)); wc = wc >> 6; wc |= 0x200000; - case 4: r[3] = (uchar) (0x80 | (wc & 0x3f)); wc = wc >> 6; wc |= 0x10000; -#endif - case 3: r[2] = (uchar) (0x80 | (wc & 0x3f)); wc = wc >> 6; wc |= 0x800; - case 2: r[1] = (uchar) (0x80 | (wc & 0x3f)); wc = wc >> 6; wc |= 0xc0; - case 1: r[0] = (uchar) wc; - } - return count; -} - - -static int mysql_caseup_utf8(const char *src, size_t srclen, char *dst, size_t dstlen) -{ - ulong wc; - int srcres, dstres; - const char *srcend = src + srclen; - char *dstend = dst + dstlen, *dst0 = dst; - MY_UNICASE_INFO **uni_plane= my_unicase_default; - - while ((src < srcend) && (srcres= my_utf8_uni(&wc, (uchar *) src, (uchar*) srcend)) > 0) { - int plane = (wc>>8) & 0xFF; - wc = uni_plane[plane] ? uni_plane[plane][wc & 0xFF].toupper : wc; - if ((dstres = my_uni_utf8(wc, (uchar*) dst, (uchar*) dstend)) <= 0) { - break; - } - src += srcres; - dst += dstres; - } - return (size_t) (dst - dst0); -} - -char * mysql_utf8_strup(const char *src, size_t srclen) -{ - size_t dstlen; - char *dst; - if (srclen == 0) { - srclen = strlen(src); - } - dst = malloc(dstlen = srclen * 4); - if (!dst) { - return NULL; - } - dst[mysql_caseup_utf8(src, srclen, dst, dstlen)] = '\0'; - return dst; -} - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/libmysql/net.c b/libmysql/net.c index c2446f4dd..7349905c1 100644 --- a/libmysql/net.c +++ b/libmysql/net.c @@ -22,9 +22,6 @@ ** 3 byte length & 1 byte package-number. */ -#ifdef __WIN__ -#include -#endif #include #include #include @@ -40,23 +37,17 @@ #define MAX_PACKET_LENGTH (256L*256L*256L-1) -#ifdef MYSQL_SERVER -ulong max_allowed_packet=65536; -extern ulong net_read_timeout,net_write_timeout; -extern uint test_flags; -#else -ulong max_allowed_packet=MAX_PACKET_LENGTH; +ulong max_allowed_packet=1024L * 1024L * 1024L; ulong net_read_timeout= NET_READ_TIMEOUT; ulong net_write_timeout= NET_WRITE_TIMEOUT; -#endif ulong net_buffer_length=8192; /* Default length. Enlarged if necessary */ -#if !defined(__WIN__) && !defined(MSDOS) +#if !defined(_WIN32) && !defined(MSDOS) #include #else #undef MYSQL_SERVER /* Win32 can't handle interrupts */ #endif -#if !defined(MSDOS) && !defined(__WIN__) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__) +#if !defined(MSDOS) && !defined(_WIN32) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__) #include #include #include @@ -108,7 +99,7 @@ extern pthread_mutex_t LOCK_bytes_sent , LOCK_bytes_received; */ #define TEST_BLOCKING 8 -static int net_write_buff(NET *net,const char *packet,uint len); +static int net_write_buff(NET *net,const char *packet, size_t len); /* Init with packet info */ @@ -134,7 +125,7 @@ int my_net_init(NET *net, Vio* vio) if (vio != 0) /* If real connection */ { net->fd = vio_fd(vio); /* For perl DBI/DBD */ -#if defined(MYSQL_SERVER) && !defined(___WIN__) && !defined(__EMX__) && !defined(OS2) +#if defined(MYSQL_SERVER) && !defined(__WIN32) && !defined(__EMX__) && !defined(OS2) if (!(test_flags & TEST_BLOCKING)) vio_blocking(vio, FALSE); #endif @@ -151,29 +142,35 @@ void net_end(NET *net) /* Realloc the packet buffer */ -static my_bool net_realloc(NET *net, ulong length) +static my_bool net_realloc(NET *net, size_t length) { uchar *buff; ulong pkt_length; + + DBUG_ENTER("net_realloc"); + DBUG_PRINT("info", ("length: %lu max_allowed_packet: %lu", + (ulong)length, max_allowed_packet)); + if (length >= max_allowed_packet) { DBUG_PRINT("error",("Packet too large (%lu)", length)); net->error=1; net->last_errno=ER_NET_PACKET_TOO_LARGE; - return 1; + DBUG_RETURN(1); } pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1); if (!(buff=(uchar*) my_realloc((char*) net->buff, pkt_length, MYF(MY_WME)))) { + DBUG_PRINT("info", ("Out of memory")); net->error=1; #ifdef MYSQL_SERVER net->last_errno=ER_OUT_OF_RESOURCES; #endif - return 1; + DBUG_RETURN(1); } net->buff=net->write_pos=buff; net->buff_end=buff+(net->max_packet=pkt_length); - return 0; + DBUG_RETURN(0); } /* Remove unwanted characters from connection */ @@ -228,7 +225,7 @@ int net_flush(NET *net) */ int -my_net_write(NET *net,const char *packet,ulong len) +my_net_write(NET *net, const char *packet, size_t len) { uchar buff[NET_HEADER_SIZE]; if (len >= MAX_PACKET_LENGTH) @@ -245,39 +242,62 @@ my_net_write(NET *net,const char *packet,ulong len) } int -net_write_command(NET *net,uchar command,const char *packet,ulong len) +net_write_command(NET *net, uchar command, + const char *packet, size_t len) { uchar buff[NET_HEADER_SIZE+1]; - uint length=len+1; /* 1 extra byte for command */ + size_t buff_size= NET_HEADER_SIZE + 1; + size_t length= 1 + len; /* 1 extra byte for command */ int rc; + + buff[4]=command; + if (length >= MAX_PACKET_LENGTH) { - net->error=1; - net->last_errno=ER_NET_PACKET_TOO_LARGE; - return 1; + len= MAX_PACKET_LENGTH - 1; + do + { + int3store(buff, MAX_PACKET_LENGTH); + buff[3]= (net->compress) ? 0 : (uchar) (net->pkt_nr++); + + if (net_write_buff(net, (char *)buff, buff_size) || + net_write_buff(net, packet, len)) + return(1); + packet+= len; + length-= MAX_PACKET_LENGTH; + len= MAX_PACKET_LENGTH; + buff_size= NET_HEADER_SIZE; /* don't send command for further packets */ + } while (length >= MAX_PACKET_LENGTH); + len= length; } int3store(buff,length); buff[3]= (net->compress) ? 0 : (uchar) (net->pkt_nr++); - buff[4]=command; - rc= test (net_write_buff(net,buff,5) || net_write_buff(net,packet,len) || net_flush(net)); + rc= test (net_write_buff(net,(char *)buff, buff_size) || + net_write_buff(net,packet,len) || + net_flush(net)); return rc; } static int -net_write_buff(NET *net,const char *packet,uint len) +net_write_buff(NET *net,const char *packet, size_t len) { - uint left_length=(uint) (net->buff_end - net->write_pos); + size_t left_length=(size_t) (net->buff_end - net->write_pos); - while (len > left_length) + if (len > left_length) { - memcpy((char*) net->write_pos,packet,left_length); - if (net_real_write(net,(char*) net->buff,net->max_packet)) - return 1; - net->write_pos=net->buff; - packet+=left_length; - len-=left_length; - left_length=net->max_packet; + if (net->write_pos != net->buff) + { + memcpy((char*) net->write_pos,packet,left_length); + if (net_real_write(net,(char*) net->buff, + (size_t)(net->write_pos - net->buff) + left_length)) + return 1; + packet+=left_length; + len-=left_length; + net->write_pos= net->buff; + } + if (len > net->max_packet) + return(test(net_real_write(net, packet, len))); } memcpy((char*) net->write_pos,packet,len); net->write_pos+=len; @@ -292,7 +312,7 @@ net_real_write(NET *net,const char *packet,ulong len) int length; char *pos,*end; thr_alarm_t alarmed; -#if !defined(__WIN__) && !defined(__EMX__) && !defined(OS2) +#if !defined(_WIN32) && !defined(__EMX__) && !defined(OS2) ALARM alarm_buff; #endif uint retry_count=0; @@ -350,7 +370,7 @@ net_real_write(NET *net,const char *packet,ulong len) if ((int) (length=vio_write(net->vio,pos,(int) (end-pos))) <= 0) { my_bool interrupted = vio_should_retry(net->vio); -#if (!defined(__WIN__) && !defined(__EMX__) && !defined(OS2)) +#if (!defined(_WIN32) && !defined(__EMX__) && !defined(OS2)) if ((interrupted || length==0) && !thr_alarm_in_use(&alarmed)) { if (!thr_alarm(&alarmed,(uint) net_write_timeout,&alarm_buff)) @@ -375,7 +395,7 @@ net_real_write(NET *net,const char *packet,ulong len) } } else -#endif /* (!defined(__WIN__) && !defined(__EMX__)) */ +#endif /* (!defined(_WIN32) && !defined(__EMX__)) */ if (thr_alarm_in_use(&alarmed) && !thr_got_alarm(&alarmed) && interrupted) { @@ -403,7 +423,7 @@ net_real_write(NET *net,const char *packet,ulong len) pos+=length; statistic_add(bytes_sent,length,&LOCK_bytes_sent); } -#ifndef __WIN__ +#ifndef _WIN32 end: #endif #ifdef HAVE_COMPRESS @@ -462,18 +482,18 @@ static void my_net_skip_rest(NET *net, ulong remain, thr_alarm_t *alarmed, static ulong -my_real_read(NET *net, ulong *complen) +my_real_read(NET *net, size_t *complen) { uchar *pos; - ulong length; + size_t length; uint i,retry_count=0; ulong len=packet_error; thr_alarm_t alarmed; -#if (!defined(__WIN__) && !defined(__EMX__) && !defined(OS2)) || defined(MYSQL_SERVER) +#if (!defined(_WIN32) && !defined(__EMX__) && !defined(OS2)) || defined(MYSQL_SERVER) ALARM alarm_buff; #endif my_bool net_blocking=vio_is_blocking(net->vio); - ulong remain= (net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE : + size_t remain= (net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE : NET_HEADER_SIZE); *complen = 0; @@ -496,7 +516,7 @@ my_real_read(NET *net, ulong *complen) DBUG_PRINT("info",("vio_read returned %d, errno: %d", length, vio_errno(net->vio))); -#if (!defined(__WIN__) && !defined(__EMX__) && !defined(OS2)) || defined(MYSQL_SERVER) +#if (!defined(_WIN32) && !defined(__EMX__) && !defined(OS2)) || defined(MYSQL_SERVER) /* We got an error that there was no data on the socket. We now set up an alarm to not 'read forever', change the socket to non blocking @@ -533,7 +553,7 @@ my_real_read(NET *net, ulong *complen) continue; } } -#endif /* (!defined(__WIN__) && !defined(__EMX__)) || defined(MYSQL_SERVER) */ +#endif /* (!defined(_WIN32) && !defined(__EMX__)) || defined(MYSQL_SERVER) */ if (thr_alarm_in_use(&alarmed) && !thr_got_alarm(&alarmed) && interrupted) { /* Probably in MIT threads */ @@ -554,10 +574,6 @@ my_real_read(NET *net, ulong *complen) DBUG_PRINT("error",("Couldn't read packet: remain: %d errno: %d length: %d alarmed: %d", remain,vio_errno(net->vio),length,alarmed)); len= packet_error; net->error=2; /* Close socket */ -#ifdef MYSQL_SERVER - net->last_errno= (interrupted ? ER_NET_READ_INTERRUPTED : - ER_NET_READ_ERROR); -#endif goto end; } remain -= (ulong) length; @@ -597,12 +613,14 @@ my_real_read(NET *net, ulong *complen) #endif len=uint3korr(net->buff+net->where_b); + if (!len) + goto end; helping = max(len,*complen) + net->where_b; /* The necessary size of net->buff */ if (helping >= net->max_packet) { /* We must allocate one extra byte for the end null */ - if (net_realloc(net,helping+1)) + if (net_realloc(net,helping)) { #ifdef MYSQL_SERVER if (i == 1) @@ -635,7 +653,22 @@ ulong my_net_read(NET *net) if (!net->compress) { #endif - len = my_real_read (net,&complen); + len = my_real_read (net,(size_t *)&complen); + if (len == MAX_PACKET_LENGTH) + { + /* multi packet read */ + size_t length= 0; + ulong last_pos= net->where_b; + + do + { + length+= len; + net->where_b+= len; + } while (len == MAX_PACKET_LENGTH); + net->where_b= last_pos; + if (len != packet_error) + len+= length; + } net->read_pos = net->buff + net->where_b; if (len != packet_error) net->read_pos[len]=0; /* Safeguard for mysql_use_result */ @@ -675,7 +708,7 @@ ulong my_net_read(NET *net) net->buf_length=0; } - if ((len = my_real_read(net,&complen)) == packet_error) + if ((len = my_real_read(net,(size_t *)&complen)) == packet_error) break; if (my_uncompress((byte*) net->buff + net->where_b, &len, &complen)) { diff --git a/libmysql/password.c b/libmysql/password.c index 7d924a04b..7e6e59005 100644 --- a/libmysql/password.c +++ b/libmysql/password.c @@ -68,11 +68,12 @@ double rnd(struct rand_struct *rand_st) return (((double) rand_st->seed1)/rand_st->max_value_dbl); } -void hash_password(ulong *result, const char *password) +void hash_password(ulong *result, const char *password, size_t len) { register ulong nr=1345345333L, add=7, nr2=0x12345671L; ulong tmp; - for (; *password ; password++) + const char *password_end= password + len; + for (; password < password_end; password++) { if (*password == ' ' || *password == '\t') continue; /* skipp space in password */ @@ -86,13 +87,6 @@ void hash_password(ulong *result, const char *password) return; } -void make_scrambled_password(char *to,const char *password) -{ - ulong hash_res[2]; - hash_password(hash_res,password); - sprintf(to,"%08lx%08lx",hash_res[0],hash_res[1]); -} - static inline unsigned int char_val(char X) { return (uint) (X >= '0' && X <= '9' ? X-'0' : @@ -100,6 +94,59 @@ static inline unsigned int char_val(char X) X-'a'+10); } +/* + * Genererate a new message based on message and password + * The same thing is done in client and server and the results are checked. + */ + +/* scramble for 4.1 servers + * Code based on php_nysqlnd_scramble function from PHP's mysqlnd extension, + * written by Andrey Hristov (andrey@php.net) + * License: PHP License 3.0 + */ +void my_crypt(unsigned char *buffer, const unsigned char *s1, const unsigned char *s2, size_t len) +{ + const unsigned char *s1_end= s1 + len; + while (s1 < s1_end) { + *buffer++= *s1++ ^ *s2++; + } +} + +void my_scramble_41(const unsigned char *buffer, const char *scramble, const char *password) +{ + MYSQL_SHA1_CTX context; + unsigned char sha1[SHA1_MAX_LENGTH]; + unsigned char sha2[SHA1_MAX_LENGTH]; + + + /* Phase 1: hash password */ + MYSQL_SHA1Init(&context); + MYSQL_SHA1Update(&context, (unsigned char *)password, strlen((char *)password)); + MYSQL_SHA1Final(sha1, &context); + + /* Phase 2: hash sha1 */ + MYSQL_SHA1Init(&context); + MYSQL_SHA1Update(&context, (unsigned char*)sha1, SHA1_MAX_LENGTH); + MYSQL_SHA1Final(sha2, &context); + + /* Phase 3: hash scramble + sha2 */ + MYSQL_SHA1Init(&context); + MYSQL_SHA1Update(&context, (unsigned char *)scramble, SCRAMBLE_LENGTH); + MYSQL_SHA1Update(&context, (unsigned char*)sha2, SHA1_MAX_LENGTH); + MYSQL_SHA1Final((unsigned char *)buffer, &context); + + /* let's crypt buffer now */ + my_crypt((uchar *)buffer, (const unsigned char *)buffer, (const unsigned char *)sha1, SHA1_MAX_LENGTH); +} +/* }}} */ + +void make_scrambled_password(char *to,const char *password) +{ + ulong hash_res[2]; + hash_password(hash_res,password, strlen(password)); + sprintf(to,"%08lx%08lx",hash_res[0],hash_res[1]); +} + /* ** This code assumes that len(password) is divideable with 8 and that ** res is big enough (2 in mysql) @@ -133,24 +180,19 @@ void make_password_from_salt(char *to, ulong *hash_res) * The same thing is done in client and server and the results are checked. */ -char *scramble(char *to,const char *message,const char *password, - my_bool old_ver) +char *scramble_323(char *to,const char *message,const char *password) { struct rand_struct rand_st; ulong hash_pass[2],hash_message[2]; if (password && password[0]) { char *to_start=to; - hash_password(hash_pass,password); - hash_password(hash_message,message); - if (old_ver) - old_randominit(&rand_st,hash_pass[0] ^ hash_message[0]); - else - randominit(&rand_st,hash_pass[0] ^ hash_message[0], - hash_pass[1] ^ hash_message[1]); + hash_password(hash_pass, password, strlen(password)); + hash_password(hash_message, message, strlen(message)); + randominit(&rand_st,hash_pass[0] ^ hash_message[0], + hash_pass[1] ^ hash_message[1]); while (*message++) *to++= (char) (floor(rnd(&rand_st)*31)+64); - if (!old_ver) { /* Make it harder to break */ char extra=(char) (floor(rnd(&rand_st)*31)); while (to_start != to) @@ -161,48 +203,6 @@ char *scramble(char *to,const char *message,const char *password, return to; } -/* scramble for 4.1 servers - * Code based on php_nysqlnd_scramble function from PHP's mysqlnd extension, - * written by Andrey Hristov (andrey@php.net) - * License: PHP License 3.0 - */ -void my_crypt(unsigned char *buffer, const unsigned char *s1, const unsigned char *s2, size_t len) -{ - const unsigned char *s1_end= s1 + len; - while (s1 < s1_end) { - *buffer++= *s1++ ^ *s2++; - } -} - -void my_scramble_41(const unsigned char *buffer, const char *scramble, const char *password) -{ - MYSQL_SHA1_CTX context; - unsigned char sha1[SHA1_MAX_LENGTH]; - unsigned char sha2[SHA1_MAX_LENGTH]; - - - /* Phase 1: hash password */ - MYSQL_SHA1Init(&context); - MYSQL_SHA1Update(&context, (unsigned char *)password, strlen((char *)password)); - MYSQL_SHA1Final(sha1, &context); - - /* Phase 2: hash sha1 */ - MYSQL_SHA1Init(&context); - MYSQL_SHA1Update(&context, (unsigned char*)sha1, SHA1_MAX_LENGTH); - MYSQL_SHA1Final(sha2, &context); - - /* Phase 3: hash scramble + sha2 */ - MYSQL_SHA1Init(&context); - MYSQL_SHA1Update(&context, (unsigned char *)scramble, SCRAMBLE_LENGTH); - MYSQL_SHA1Update(&context, (unsigned char*)sha2, SHA1_MAX_LENGTH); - MYSQL_SHA1Final((unsigned char *)buffer, &context); - - /* let's crypt buffer now */ - my_crypt((uchar *)buffer, (const unsigned char *)buffer, (const unsigned char *)sha1, SHA1_MAX_LENGTH); -} -/* }}} */ - - my_bool check_scramble(const char *scrambled, const char *message, ulong *hash_pass, my_bool old_ver) @@ -212,7 +212,7 @@ my_bool check_scramble(const char *scrambled, const char *message, char buff[16],*to,extra; /* Big enough for check */ const char *pos; - hash_password(hash_message,message); + hash_password(hash_message,message, strlen(message)); if (old_ver) old_randominit(&rand_st,hash_pass[0] ^ hash_message[0]); else diff --git a/libmysql/safemalloc.c b/libmysql/safemalloc.c index 0bf9341e3..e326beea7 100644 --- a/libmysql/safemalloc.c +++ b/libmysql/safemalloc.c @@ -121,7 +121,7 @@ static int _checkchunk(struct remember *pRec, const char *sFile, uint uLine); * Allocate some memory. */ -gptr _mymalloc (uint uSize, const char *sFile, uint uLine, myf MyFlags) +gptr _mymalloc (size_t uSize, const char *sFile, uint uLine, myf MyFlags) { struct remember *pTmp; DBUG_ENTER("_mymalloc"); @@ -154,9 +154,9 @@ gptr _mymalloc (uint uSize, const char *sFile, uint uLine, myf MyFlags) my_errno=errno; sprintf(buff,"Out of memory at line %d, '%s'", uLine, sFile); my_message(EE_OUTOFMEMORY,buff,MYF(ME_BELL+ME_WAITTANG)); - sprintf(buff,"needed %d byte (%ldk), memory in use: %ld bytes (%ldk)", - uSize, (uSize + 1023L) / 1024L, - lMaxMemory, (lMaxMemory + 1023L) / 1024L); + sprintf(buff,"needed %ld byte (%ldk), memory in use: %lu bytes (%ldk)", + (long) uSize, (long) ((uSize + 1023L) / 1024L), + (long) lMaxMemory, (long) (lMaxMemory + 1023L) / 1024L); my_message(EE_OUTOFMEMORY,buff,MYF(ME_BELL+ME_WAITTANG)); } DBUG_PRINT("error",("Out of memory, in use: %ld at line %d, '%s'", @@ -211,7 +211,7 @@ gptr _mymalloc (uint uSize, const char *sFile, uint uLine, myf MyFlags) * Free then old memoryblock */ -gptr _myrealloc (register gptr pPtr, register uint uSize, +gptr _myrealloc (register gptr pPtr, register size_t uSize, const char *sFile, uint uLine, myf MyFlags) { struct remember *pRec; @@ -242,7 +242,7 @@ gptr _myrealloc (register gptr pPtr, register uint uSize, if ((ptr=_mymalloc(uSize,sFile,uLine,MyFlags))) /* Allocate new area */ { - uSize=min(uSize,pRec-> uDataSize); /* Move as much as possibly */ + uSize=min(uSize,pRec->uDataSize); /* Move as much as possibly */ memcpy((byte*) ptr,pPtr,(size_t) uSize); /* Copy old data */ _myfree(pPtr,sFile,uLine,0); /* Free not needed area */ } @@ -393,10 +393,10 @@ void TERMINATE (FILE *file) { if (file) { - fprintf(file, "Memory that was not free'ed (%ld bytes):\n",lCurMemory); + fprintf(file, "Memory that was not free'ed (%zu bytes):\n",lCurMemory); (void) fflush(file); } - DBUG_PRINT("safe",("Memory that was not free'ed (%ld bytes):",lCurMemory)); + DBUG_PRINT("safe",("Memory that was not free'ed (%zu bytes):",lCurMemory)); while (pPtr) { if (file) @@ -418,7 +418,7 @@ void TERMINATE (FILE *file) /* Report the memory usage statistics */ if (file) { - fprintf (file, "Maximum memory usage: %ld bytes (%ldk)\n", + fprintf (file, "Maximum memory usage: %zu bytes (%ldk)\n", lMaxMemory, (lMaxMemory + 1023L) / 1024L); (void) fflush(file); } @@ -434,7 +434,7 @@ void TERMINATE (FILE *file) static int _checkchunk (register struct remember *pRec, const char *sFile, uint uLine) { - reg1 uint uSize; + reg1 size_t uSize; reg2 my_string magicp; reg3 int flag=0; @@ -454,7 +454,7 @@ static int _checkchunk (register struct remember *pRec, const char *sFile, } /* Check for a possible overrun */ - uSize = pRec -> uDataSize; + uSize = pRec->uDataSize; magicp = &(pRec -> aData[uSize+sf_malloc_prehunc]); if (*magicp++ != MAGICEND0 || *magicp++ != MAGICEND1 || @@ -502,12 +502,12 @@ int _sanity (const char *sFile, uint uLine) /* malloc and copy */ -gptr _my_memdup(const byte *from, uint length, const char *sFile, uint uLine, +gptr _my_memdup(const byte *from, size_t length, const char *sFile, uint uLine, myf MyFlags) { gptr ptr; if ((ptr=_mymalloc(length,sFile,uLine,MyFlags)) != 0) - memcpy((byte*) ptr, (byte*) from,(size_t) length); + memcpy((byte*) ptr, (byte*) from, length); return(ptr); } /*_my_memdup */ @@ -516,7 +516,7 @@ my_string _my_strdup(const char *from, const char *sFile, uint uLine, myf MyFlags) { gptr ptr; - uint length=(uint) strlen(from)+1; + size_t length= strlen(from)+1; if ((ptr=_mymalloc(length,sFile,uLine,MyFlags)) != 0) memcpy((byte*) ptr, (byte*) from,(size_t) length); return((my_string) ptr); diff --git a/libmysql/sha1.c b/libmysql/sha1.c index 2bc746794..4966d4656 100644 --- a/libmysql/sha1.c +++ b/libmysql/sha1.c @@ -102,7 +102,7 @@ void MYSQL_SHA1Init(MYSQL_SHA1_CTX * context) context. */ void MYSQL_SHA1Update(MYSQL_SHA1_CTX * context, const unsigned char *input, - unsigned int inputLen) + size_t inputLen) { unsigned int i, index, partLen; diff --git a/libmysql/spprintf.c b/libmysql/spprintf.c deleted file mode 100644 index 88442c10a..000000000 --- a/libmysql/spprintf.c +++ /dev/null @@ -1,810 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger | - +----------------------------------------------------------------------+ -*/ - -/* $Id: spprintf.c,v 1.25.2.2.2.10.2.1 2007/10/01 15:22:41 iliaa Exp $ */ - -/* This is the spprintf implementation. - * It has emerged from apache snprintf. See original header: - */ - -/* ==================================================================== - * Copyright (c) 1995-1998 The Apache Group. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the Apache Group - * for use in the Apache HTTP server project (http://www.apache.org/)." - * - * 4. The names "Apache Server" and "Apache Group" must not be used to - * endorse or promote products derived from this software without - * prior written permission. - * - * 5. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the Apache Group - * for use in the Apache HTTP server project (http://www.apache.org/)." - * - * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Group and was originally based - * on public domain software written at the National Center for - * Supercomputing Applications, University of Illinois, Urbana-Champaign. - * For more information on the Apache Group and the Apache HTTP server - * project, please see . - * - * This code is based on, and used with the permission of, the - * SIO stdio-replacement strx_* functions by Panos Tsirigotis - * for xinetd. - */ -#include "my_global.h" -#include -#include -#include -#include -#include "mysql.h" -#include "mysql_priv.h" -#include "mysql_version.h" -#include "mysqld_error.h" -#include "errmsg.h" - -#include "mysql_mm.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_INTTYPES_H -#include -#endif - -#ifdef HAVE_LOCALE_H -#include -#define LCONV_DECIMAL_POINT (*lconv->decimal_point) -#else -#define LCONV_DECIMAL_POINT '.' -#endif - -#include "snprintf.h" - -#define NUL '\0' -#define INT_NULL ((int *)0) - -#define S_NULL "(null)" -#define S_NULL_LEN 6 - -#define FLOAT_DIGITS 6 -#define EXPONENT_LENGTH 10 - -#include "smart_str.h" - -/* {{{ macros */ - -/* - * NUM_BUF_SIZE is the size of the buffer used for arithmetic conversions - * - * XXX: this is a magic number; do not decrease it - */ -#define NUM_BUF_SIZE 512 - -/* - * The INS_CHAR macro inserts a character in the buffer. - * - * NOTE: Evaluation of the ch argument should not have any side-effects - */ -#define INS_CHAR_NR(xbuf, ch) do { \ - smart_str_appendc(xbuf, ch); \ -} while (0) - -#define INS_STRING(xbuf, s, slen) do { \ - smart_str_appendl(xbuf, s, slen); \ -} while (0) - -#define INS_CHAR(xbuf, ch) \ - INS_CHAR_NR(xbuf, ch) - -/* - * Macro that does padding. The padding is done by printing - * the character ch. - */ -#define PAD(xbuf, count, ch) do { \ - if ((count) > 0) { \ - size_t newlen; \ - smart_str_alloc(xbuf, (count), 0); \ - memset(xbuf->c + xbuf->len, ch, (count)); \ - xbuf->len += (count); \ - } \ -} while (0) - -#define NUM(c) (c - '0') - -#define STR_TO_DEC(str, num) do { \ - num = NUM(*str++); \ - while (isdigit((int)*str)) { \ - num *= 10; \ - num += NUM(*str++); \ - if (num >= INT_MAX / 10) { \ - while (isdigit((int)*str++)); \ - break; \ - } \ - } \ -} while (0) - -/* - * This macro does zero padding so that the precision - * requirement is satisfied. The padding is done by - * adding '0's to the left of the string that is going - * to be printed. - */ -#define FIX_PRECISION(adjust, precision, s, s_len) do { \ - if (adjust) \ - while (s_len < precision) { \ - *--s = '0'; \ - s_len++; \ - } \ -} while (0) - -/* }}} */ - -/* - * Do format conversion placing the output in buffer - */ -static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap) /* {{{ */ -{ - register char *s = NULL; - char *q; - int s_len; - - register int min_width = 0; - int precision = 0; - enum { - LEFT, RIGHT - } adjust; - char pad_char; - char prefix_char; - - double fp_num; - wide_int i_num = (wide_int) 0; - u_wide_int ui_num; - - char num_buf[NUM_BUF_SIZE]; - char char_buf[2]; /* for printing %% and % */ - -#ifdef HAVE_LOCALE_H - struct lconv *lconv = NULL; -#endif - - /* - * Flag variables - */ - length_modifier_e modifier; - boolean_e alternate_form; - boolean_e print_sign; - boolean_e print_blank; - boolean_e adjust_precision; - boolean_e adjust_width; - bool_int is_negative; - - while (*fmt) { - if (*fmt != '%') { - INS_CHAR(xbuf, *fmt); - } else { - /* - * Default variable settings - */ - adjust = RIGHT; - alternate_form = print_sign = print_blank = NO; - pad_char = ' '; - prefix_char = NUL; - - fmt++; - - /* - * Try to avoid checking for flags, width or precision - */ - if (isascii((int)*fmt) && !islower((int)*fmt)) { - /* - * Recognize flags: -, #, BLANK, + - */ - for (;; fmt++) { - if (*fmt == '-') - adjust = LEFT; - else if (*fmt == '+') - print_sign = YES; - else if (*fmt == '#') - alternate_form = YES; - else if (*fmt == ' ') - print_blank = YES; - else if (*fmt == '0') - pad_char = '0'; - else - break; - } - - /* - * Check if a width was specified - */ - if (isdigit((int)*fmt)) { - STR_TO_DEC(fmt, min_width); - adjust_width = YES; - } else if (*fmt == '*') { - min_width = va_arg(ap, int); - fmt++; - adjust_width = YES; - if (min_width < 0) { - adjust = LEFT; - min_width = -min_width; - } - } else - adjust_width = NO; - - /* - * Check if a precision was specified - * - * XXX: an unreasonable amount of precision may be specified - * resulting in overflow of num_buf. Currently we - * ignore this possibility. - */ - if (*fmt == '.') { - adjust_precision = YES; - fmt++; - if (isdigit((int)*fmt)) { - STR_TO_DEC(fmt, precision); - } else if (*fmt == '*') { - precision = va_arg(ap, int); - fmt++; - if (precision < 0) - precision = 0; - } else - precision = 0; - } else - adjust_precision = NO; - } else - adjust_precision = adjust_width = NO; - - /* - * Modifier check - */ - switch (*fmt) { - case 'L': - fmt++; - modifier = LM_LONG_DOUBLE; - break; - case 'I': - fmt++; -#if SIZEOF_LONG_LONG - if (*fmt == '6' && *(fmt+1) == '4') { - fmt += 2; - modifier = LM_LONG_LONG; - } else -#endif - if (*fmt == '3' && *(fmt+1) == '2') { - fmt += 2; - modifier = LM_LONG; - } else { -#ifdef _WIN64 - modifier = LM_LONG_LONG; -#else - modifier = LM_LONG; -#endif - } - break; - case 'l': - fmt++; -#if SIZEOF_LONG_LONG - if (*fmt == 'l') { - fmt++; - modifier = LM_LONG_LONG; - } else -#endif - modifier = LM_LONG; - break; - case 'z': - fmt++; - modifier = LM_SIZE_T; - break; - case 'j': - fmt++; -#if SIZEOF_INTMAX_T - modifier = LM_INTMAX_T; -#else - modifier = LM_SIZE_T; -#endif - break; - case 't': - fmt++; -#if SIZEOF_PTRDIFF_T - modifier = LM_PTRDIFF_T; -#else - modifier = LM_SIZE_T; -#endif - break; - case 'h': - fmt++; - if (*fmt == 'h') { - fmt++; - } - /* these are promoted to int, so no break */ - default: - modifier = LM_STD; - break; - } - - /* - * Argument extraction and printing. - * First we determine the argument type. - * Then, we convert the argument to a string. - * On exit from the switch, s points to the string that - * must be printed, s_len has the length of the string - * The precision requirements, if any, are reflected in s_len. - * - * NOTE: pad_char may be set to '0' because of the 0 flag. - * It is reset to ' ' by non-numeric formats - */ - switch (*fmt) { - case 'u': - switch(modifier) { - default: - i_num = (wide_int) va_arg(ap, unsigned int); - break; - case LM_LONG_DOUBLE: - goto fmt_error; - case LM_LONG: - i_num = (wide_int) va_arg(ap, unsigned long int); - break; - case LM_SIZE_T: - i_num = (wide_int) va_arg(ap, size_t); - break; -#if SIZEOF_LONG_LONG - case LM_LONG_LONG: - i_num = (wide_int) va_arg(ap, u_wide_int); - break; -#endif -#if SIZEOF_INTMAX_T - case LM_INTMAX_T: - i_num = (wide_int) va_arg(ap, uintmax_t); - break; -#endif -#if SIZEOF_PTRDIFF_T - case LM_PTRDIFF_T: - i_num = (wide_int) va_arg(ap, ptrdiff_t); - break; -#endif - } - /* - * The rest also applies to other integer formats, so fall - * into that case. - */ - case 'd': - case 'i': - /* - * Get the arg if we haven't already. - */ - if ((*fmt) != 'u') { - switch(modifier) { - default: - i_num = (wide_int) va_arg(ap, int); - break; - case LM_LONG_DOUBLE: - goto fmt_error; - case LM_LONG: - i_num = (wide_int) va_arg(ap, long int); - break; - case LM_SIZE_T: -#if SIZEOF_SSIZE_T - i_num = (wide_int) va_arg(ap, ssize_t); -#else - i_num = (wide_int) va_arg(ap, size_t); -#endif - break; -#if SIZEOF_LONG_LONG - case LM_LONG_LONG: - i_num = (wide_int) va_arg(ap, wide_int); - break; -#endif -#if SIZEOF_INTMAX_T - case LM_INTMAX_T: - i_num = (wide_int) va_arg(ap, intmax_t); - break; -#endif -#if SIZEOF_PTRDIFF_T - case LM_PTRDIFF_T: - i_num = (wide_int) va_arg(ap, ptrdiff_t); - break; -#endif - } - } - s = ap_php_conv_10(i_num, (*fmt) == 'u', &is_negative, - &num_buf[NUM_BUF_SIZE], &s_len); - FIX_PRECISION(adjust_precision, precision, s, s_len); - - if (*fmt != 'u') { - if (is_negative) - prefix_char = '-'; - else if (print_sign) - prefix_char = '+'; - else if (print_blank) - prefix_char = ' '; - } - break; - - - case 'o': - switch(modifier) { - default: - ui_num = (u_wide_int) va_arg(ap, unsigned int); - break; - case LM_LONG_DOUBLE: - goto fmt_error; - case LM_LONG: - ui_num = (u_wide_int) va_arg(ap, unsigned long int); - break; - case LM_SIZE_T: - ui_num = (u_wide_int) va_arg(ap, size_t); - break; -#if SIZEOF_LONG_LONG - case LM_LONG_LONG: - ui_num = (u_wide_int) va_arg(ap, u_wide_int); - break; -#endif -#if SIZEOF_INTMAX_T - case LM_INTMAX_T: - ui_num = (u_wide_int) va_arg(ap, uintmax_t); - break; -#endif -#if SIZEOF_PTRDIFF_T - case LM_PTRDIFF_T: - ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); - break; -#endif - } - s = ap_php_conv_p2(ui_num, 3, *fmt, - &num_buf[NUM_BUF_SIZE], &s_len); - FIX_PRECISION(adjust_precision, precision, s, s_len); - if (alternate_form && *s != '0') { - *--s = '0'; - s_len++; - } - break; - - - case 'x': - case 'X': - switch(modifier) { - default: - ui_num = (u_wide_int) va_arg(ap, unsigned int); - break; - case LM_LONG_DOUBLE: - goto fmt_error; - case LM_LONG: - ui_num = (u_wide_int) va_arg(ap, unsigned long int); - break; - case LM_SIZE_T: - ui_num = (u_wide_int) va_arg(ap, size_t); - break; -#if SIZEOF_LONG_LONG - case LM_LONG_LONG: - ui_num = (u_wide_int) va_arg(ap, u_wide_int); - break; -#endif -#if SIZEOF_INTMAX_T - case LM_INTMAX_T: - ui_num = (u_wide_int) va_arg(ap, uintmax_t); - break; -#endif -#if SIZEOF_PTRDIFF_T - case LM_PTRDIFF_T: - ui_num = (u_wide_int) va_arg(ap, ptrdiff_t); - break; -#endif - } - s = ap_php_conv_p2(ui_num, 4, *fmt, - &num_buf[NUM_BUF_SIZE], &s_len); - FIX_PRECISION(adjust_precision, precision, s, s_len); - if (alternate_form && i_num != 0) { - *--s = *fmt; /* 'x' or 'X' */ - *--s = '0'; - s_len += 2; - } - break; - - - case 's': - case 'v': - s = va_arg(ap, char *); - if (s != NULL) { - s_len = strlen(s); - if (adjust_precision && precision < s_len) - s_len = precision; - } else { - s = S_NULL; - s_len = S_NULL_LEN; - } - pad_char = ' '; - break; - - - case 'f': - case 'F': - case 'e': - case 'E': - switch(modifier) { - case LM_LONG_DOUBLE: - fp_num = (double) va_arg(ap, long double); - break; - case LM_STD: - fp_num = va_arg(ap, double); - break; - default: - goto fmt_error; - } - - if (zend_isnan(fp_num)) { - s = "nan"; - s_len = 3; - } else if (zend_isinf(fp_num)) { - s = "inf"; - s_len = 3; - } else { -#ifdef HAVE_LOCALE_H - if (!lconv) { - lconv = localeconv(); - } -#endif - s = php_conv_fp((*fmt == 'f')?'F':*fmt, fp_num, alternate_form, - (adjust_precision == NO) ? FLOAT_DIGITS : precision, - (*fmt == 'f')?LCONV_DECIMAL_POINT:'.', - &is_negative, &num_buf[1], &s_len); - if (is_negative) - prefix_char = '-'; - else if (print_sign) - prefix_char = '+'; - else if (print_blank) - prefix_char = ' '; - } - break; - - - case 'g': - case 'k': - case 'G': - case 'H': - switch(modifier) { - case LM_LONG_DOUBLE: - fp_num = (double) va_arg(ap, long double); - break; - case LM_STD: - fp_num = va_arg(ap, double); - break; - default: - goto fmt_error; - } - - if (zend_isnan(fp_num)) { - s = "NAN"; - s_len = 3; - break; - } else if (zend_isinf(fp_num)) { - if (fp_num > 0) { - s = "INF"; - s_len = 3; - } else { - s = "-INF"; - s_len = 4; - } - break; - } - - if (adjust_precision == NO) - precision = FLOAT_DIGITS; - else if (precision == 0) - precision = 1; - /* - * * We use &num_buf[ 1 ], so that we have room for the sign - */ -#ifdef HAVE_LOCALE_H - if (!lconv) { - lconv = localeconv(); - } -#endif - s = php_gcvt(fp_num, precision, (*fmt=='H' || *fmt == 'k') ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', &num_buf[1]); - if (*s == '-') - prefix_char = *s++; - else if (print_sign) - prefix_char = '+'; - else if (print_blank) - prefix_char = ' '; - - s_len = strlen(s); - - if (alternate_form && (q = strchr(s, '.')) == NULL) - s[s_len++] = '.'; - break; - - - case 'c': - char_buf[0] = (char) (va_arg(ap, int)); - s = &char_buf[0]; - s_len = 1; - pad_char = ' '; - break; - - - case '%': - char_buf[0] = '%'; - s = &char_buf[0]; - s_len = 1; - pad_char = ' '; - break; - - - case 'n': - *(va_arg(ap, int *)) = xbuf->len; - goto skip_output; - - /* - * Always extract the argument as a "char *" pointer. We - * should be using "void *" but there are still machines - * that don't understand it. - * If the pointer size is equal to the size of an unsigned - * integer we convert the pointer to a hex number, otherwise - * we print "%p" to indicate that we don't handle "%p". - */ - case 'p': - if (sizeof(char *) <= sizeof(u_wide_int)) { - ui_num = (u_wide_int)((size_t) va_arg(ap, char *)); - s = ap_php_conv_p2(ui_num, 4, 'x', - &num_buf[NUM_BUF_SIZE], &s_len); - if (ui_num != 0) { - *--s = 'x'; - *--s = '0'; - s_len += 2; - } - } else { - s = "%p"; - s_len = 2; - } - pad_char = ' '; - break; - - - case NUL: - /* - * The last character of the format string was %. - * We ignore it. - */ - continue; - - -fmt_error: - /* - * The default case is for unrecognized %'s. - * We print % to help the user identify what - * option is not understood. - * This is also useful in case the user wants to pass - * the output of format_converter to another function - * that understands some other % (like syslog). - * Note that we can't point s inside fmt because the - * unknown could be preceded by width etc. - */ - default: - char_buf[0] = '%'; - char_buf[1] = *fmt; - s = char_buf; - s_len = 2; - pad_char = ' '; - break; - } - - if (prefix_char != NUL) { - *--s = prefix_char; - s_len++; - } - if (adjust_width && adjust == RIGHT && min_width > s_len) { - if (pad_char == '0' && prefix_char != NUL) { - INS_CHAR(xbuf, *s); - s++; - s_len--; - min_width--; - } - PAD(xbuf, min_width - s_len, pad_char); - } - /* - * Print the string s. - */ - INS_STRING(xbuf, s, s_len); - - if (adjust_width && adjust == LEFT && min_width > s_len) - PAD(xbuf, min_width - s_len, pad_char); - } -skip_output: - fmt++; - } - return; -} -/* }}} */ - -/* - * This is the general purpose conversion function. - */ -int vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) /* {{{ */ -{ - smart_str xbuf; - memset(&xbuf, 0, sizeof(xbuf)); - - xbuf_format_converter(&xbuf, format, ap); - - if (max_len && xbuf.len > max_len) { - xbuf.len = max_len; - } - smart_str_0(&xbuf); - - *pbuf = xbuf.c; - - return xbuf.len; -} -/* }}} */ - -int spprintf(char **pbuf, size_t max_len, const char *format, ...) /* {{{ */ -{ - int cc; - va_list ap; - - va_start(ap, format); - cc = vspprintf(pbuf, max_len, format, ap); - va_end(ap); - return (cc); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/libmysql/strcend.c b/libmysql/strcend.c index d4a41ca53..0b7e9acf7 100644 --- a/libmysql/strcend.c +++ b/libmysql/strcend.c @@ -27,30 +27,22 @@ #include #include "m_string.h" -#if defined(MC68000) && defined(DS90) - -char *strcend(const char *s, pchar c) -{ -asm(" movl 4(a7),a0 "); -asm(" movl 8(a7),d1 "); -asm(".L2: movb (a0)+,d0 "); -asm(" cmpb d0,d1 "); -asm(" beq .L1 "); -asm(" tstb d0 "); -asm(" bne .L2 "); -asm(".L1: movl a0,d0 "); -asm(" subql #1,d0 "); -} - -#else - -char *strcend(register const char *s, register pchar c) +/** + \fn char *strcend + \brief returns a pointer to the first occurence of specified stopchar + \param str char * + \param stopchar char + + returns a poimter to the first occurence of stopchar or to null char, + if stopchar wasn't found. +*/ +char *strcend(register const char *str, register char stopchar) { for (;;) { - if (*s == (char) c) return (char*) s; - if (!*s++) return (char*) s-1; + if (*str == stopchar) + return (char*) str; + if (!*str++) + return (char*) str-1; } } - -#endif diff --git a/libmysql/strfill.c b/libmysql/strfill.c index 2f9bfc137..0559f171e 100644 --- a/libmysql/strfill.c +++ b/libmysql/strfill.c @@ -28,7 +28,7 @@ #include #include "m_string.h" -my_string strfill(my_string s,uint len,pchar fill) +my_string strfill(my_string s, size_t len, pchar fill) { while (len--) *s++ = fill; *(s) = '\0'; diff --git a/libmysql/string.c b/libmysql/string.c index 96a503c11..bb7934c9f 100644 --- a/libmysql/string.c +++ b/libmysql/string.c @@ -25,7 +25,7 @@ #include my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str, - uint init_alloc, uint alloc_increment) + size_t init_alloc, size_t alloc_increment) { uint length; DBUG_ENTER("init_dynamic_string"); @@ -97,12 +97,12 @@ my_bool dynstr_append(DYNAMIC_STRING *str, const char *append) my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append, - uint length) + size_t length) { char *new_ptr; if (str->length+length >= str->max_length) { - uint new_length=(str->length+length+str->alloc_increment)/ + size_t new_length=(str->length+length+str->alloc_increment)/ str->alloc_increment; new_length*=str->alloc_increment; if (!(new_ptr=(char*) my_realloc(str->str,new_length,MYF(MY_WME)))) diff --git a/libmysql/strmake.c b/libmysql/strmake.c index 96f220c29..c78209478 100644 --- a/libmysql/strmake.c +++ b/libmysql/strmake.c @@ -31,7 +31,7 @@ #ifdef BAD_STRING_COMPILER -char *strmake(char *dst,const char *src,uint length) +char *strmake(char *dst,const char *src, size_t length) { reg1 char *res; @@ -44,7 +44,7 @@ char *strmake(char *dst,const char *src,uint length) #define strmake strmake_overlapp /* Use orginal for overlapping str */ #endif -char *strmake(register char *dst, register const char *src, uint length) +char *strmake(register char *dst, register const char *src, size_t length) { while (length--) if (! (*dst++ = *src++)) diff --git a/libmysql/strto.c b/libmysql/strto.c new file mode 100644 index 000000000..54ff2214f --- /dev/null +++ b/libmysql/strto.c @@ -0,0 +1,210 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +/* + strtol,strtoul,strtoll,strtoull + convert string to long, unsigned long, long long or unsigned long long. + strtoxx(char *src,char **ptr,int base) + converts the string pointed to by src to an long of appropriate long and + returnes it. It skips leading spaces and tabs (but not newlines, formfeeds, + backspaces), then it accepts an optional sign and a sequence of digits + in the specified radix. + If the value of ptr is not (char **)NULL, a pointer to the character + terminating the scan is returned in the location pointed to by ptr. + Trailing spaces will NOT be skipped. + + If an error is detected, the result will be LONG_MIN, 0 or LONG_MAX, + (or LONGLONG..) and errno will be set to + EDOM if there are no digits + ERANGE if the result would overflow. + the ptr will be set to src. + This file is based on the strtol from the the GNU C Library. + it can be compiled with the UNSIGNED and/or LONGLONG flag set +*/ + +#define strtoll glob_strtoll /* Fix for True64 */ + +#include +#include "m_string.h" +#include "m_ctype.h" +#include "my_sys.h" /* defines errno */ +#include + +#undef strtoull +#undef strtoll +#undef strtoul +#undef strtol +#ifdef USE_LONGLONG +#define UTYPE_MAX (~(ulonglong) 0) +#define TYPE_MIN LONGLONG_MIN +#define TYPE_MAX LONGLONG_MAX +#define longtype longlong +#define ulongtype ulonglong +#ifdef USE_UNSIGNED +#define function ulongtype strtoull +#else +#define function longtype strtoll +#endif +#else +#define UTYPE_MAX (ulong) ~0L +#define TYPE_MIN LONG_MIN +#define TYPE_MAX LONG_MAX +#define longtype long +#define ulongtype unsigned long +#ifdef USE_UNSIGNED +#define function ulongtype strtoul +#else +#define function longtype strtol +#endif +#endif + + +/* Convert NPTR to an `unsigned long int' or `long int' in base BASE. + If BASE is 0 the base is determined by the presence of a leading + zero, indicating octal or a leading "0x" or "0X", indicating hexadecimal. + If BASE is < 2 or > 36, it is reset to 10. + If ENDPTR is not NULL, a pointer to the character after the last + one converted is stored in *ENDPTR. */ + + +function (const char *nptr,char **endptr,int base) +{ + int negative; + register ulongtype cutoff; + register unsigned int cutlim; + register ulongtype i; + register const char *s; + register unsigned char c; + const char *save; + int overflow; + + if (base < 0 || base == 1 || base > 36) + base = 10; + + s = nptr; + + /* Skip white space. */ + while (isspace (*s)) + ++s; + if (*s == '\0') + { + goto noconv; + } + + /* Check for a sign. */ + if (*s == '-') + { + negative = 1; + ++s; + } + else if (*s == '+') + { + negative = 0; + ++s; + } + else + negative = 0; + + if (base == 16 && s[0] == '0' && toupper (s[1]) == 'X') + s += 2; + + /* If BASE is zero, figure it out ourselves. */ + if (base == 0) + { + if (*s == '0') + { + if (toupper (s[1]) == 'X') + { + s += 2; + base = 16; + } + else + base = 8; + } + else + base = 10; + } + + /* Save the pointer so we can check later if anything happened. */ + save = s; + + cutoff = UTYPE_MAX / (unsigned long int) base; + cutlim = (uint) (UTYPE_MAX % (unsigned long int) base); + + overflow = 0; + i = 0; + for (c = *s; c != '\0'; c = *++s) + { + if (isdigit (c)) + c -= '0'; + else if (isalpha (c)) + c = toupper (c) - 'A' + 10; + else + break; + if (c >= base) + break; + /* Check for overflow. */ + if (i > cutoff || (i == cutoff && c > cutlim)) + overflow = 1; + else + { + i *= (ulongtype) base; + i += c; + } + } + + /* Check if anything actually happened. */ + if (s == save) + goto noconv; + + /* Store in ENDPTR the address of one character + past the last character we converted. */ + if (endptr != NULL) + *endptr = (char *) s; + +#ifndef USE_UNSIGNED + /* Check for a value that is within the range of + `unsigned long int', but outside the range of `long int'. */ + if (negative) + { + if (i > (ulongtype) TYPE_MIN) + overflow = 1; + } + else if (i > (ulongtype) TYPE_MAX) + overflow = 1; +#endif + + if (overflow) + { + my_errno=ERANGE; +#ifdef USE_UNSIGNED + return UTYPE_MAX; +#else + return negative ? TYPE_MIN : TYPE_MAX; +#endif + } + + /* Return the result of the appropriate sign. */ + return (negative ? -((longtype) i) : (longtype) i); + +noconv: + /* There was no number to convert. */ + my_errno=EDOM; + if (endptr != NULL) + *endptr = (char *) nptr; + return 0L; +} diff --git a/libmysql/strtoll.c b/libmysql/strtoll.c index 6050eba28..45924e142 100644 --- a/libmysql/strtoll.c +++ b/libmysql/strtoll.c @@ -21,5 +21,179 @@ #include #if !defined(HAVE_STRTOLL) && defined(HAVE_LONG_LONG) #define USE_LONGLONG -#include "strto.c" + +#define strtoll glob_strtoll /* Fix for True64 */ + +#include +#include "m_string.h" +#include "m_ctype.h" +#include "my_sys.h" /* defines errno */ +#include + +#undef strtoull +#undef strtoll +#undef strtoul +#undef strtol +#ifdef USE_LONGLONG +#define UTYPE_MAX (~(ulonglong) 0) +#define TYPE_MIN LONGLONG_MIN +#define TYPE_MAX LONGLONG_MAX +#define longtype longlong +#define ulongtype ulonglong +#ifdef USE_UNSIGNED +#define function ulongtype strtoull +#else +#define function longtype strtoll +#endif +#else +#define UTYPE_MAX (ulong) ~0L +#define TYPE_MIN LONG_MIN +#define TYPE_MAX LONG_MAX +#define longtype long +#define ulongtype unsigned long +#ifdef USE_UNSIGNED +#define function ulongtype strtoul +#else +#define function longtype strtol +#endif +#endif + + +/* Convert NPTR to an `unsigned long int' or `long int' in base BASE. + If BASE is 0 the base is determined by the presence of a leading + zero, indicating octal or a leading "0x" or "0X", indicating hexadecimal. + If BASE is < 2 or > 36, it is reset to 10. + If ENDPTR is not NULL, a pointer to the character after the last + one converted is stored in *ENDPTR. */ + + +function (const char *nptr,char **endptr,int base) +{ + int negative; + register ulongtype cutoff; + register unsigned int cutlim; + register ulongtype i; + register const char *s; + register unsigned char c; + const char *save; + int overflow; + + if (base < 0 || base == 1 || base > 36) + base = 10; + + s = nptr; + + /* Skip white space. */ + while (isspace (*s)) + ++s; + if (*s == '\0') + { + goto noconv; + } + + /* Check for a sign. */ + if (*s == '-') + { + negative = 1; + ++s; + } + else if (*s == '+') + { + negative = 0; + ++s; + } + else + negative = 0; + + if (base == 16 && s[0] == '0' && toupper (s[1]) == 'X') + s += 2; + + /* If BASE is zero, figure it out ourselves. */ + if (base == 0) + { + if (*s == '0') + { + if (toupper (s[1]) == 'X') + { + s += 2; + base = 16; + } + else + base = 8; + } + else + base = 10; + } + + /* Save the pointer so we can check later if anything happened. */ + save = s; + + cutoff = UTYPE_MAX / (unsigned long int) base; + cutlim = (uint) (UTYPE_MAX % (unsigned long int) base); + + overflow = 0; + i = 0; + for (c = *s; c != '\0'; c = *++s) + { + if (isdigit (c)) + c -= '0'; + else if (isalpha (c)) + c = toupper (c) - 'A' + 10; + else + break; + if (c >= base) + break; + /* Check for overflow. */ + if (i > cutoff || (i == cutoff && c > cutlim)) + overflow = 1; + else + { + i *= (ulongtype) base; + i += c; + } + } + + /* Check if anything actually happened. */ + if (s == save) + goto noconv; + + /* Store in ENDPTR the address of one character + past the last character we converted. */ + if (endptr != NULL) + *endptr = (char *) s; + +#ifndef USE_UNSIGNED + /* Check for a value that is within the range of + `unsigned long int', but outside the range of `long int'. */ + if (negative) + { + if (i > (ulongtype) TYPE_MIN) + overflow = 1; + } + else if (i > (ulongtype) TYPE_MAX) + overflow = 1; +#endif + + if (overflow) + { + my_errno=ERANGE; +#ifdef USE_UNSIGNED + return UTYPE_MAX; +#else + return negative ? TYPE_MIN : TYPE_MAX; +#endif + } + + /* Return the result of the appropriate sign. */ + return (negative ? -((longtype) i) : (longtype) i); + +noconv: + /* There was no number to convert. */ + my_errno=EDOM; + if (endptr != NULL) + *endptr = (char *) nptr; + return 0L; +} + + #endif diff --git a/libmysql/strxnmov.c b/libmysql/strxnmov.c new file mode 100644 index 000000000..d5167f69f --- /dev/null +++ b/libmysql/strxnmov.c @@ -0,0 +1,48 @@ +/* File : strxnmov.c + Author : Richard A. O'Keefe. + Updated: 2 June 1984 + Defines: strxnmov() + + strxnmov(dst, len, src1, ..., srcn, NullS) + moves the first len characters of the concatenation of src1,...,srcn + to dst. If there aren't that many characters, a NUL character will + be added to the end of dst to terminate it properly. This gives the + same effect as calling strxcpy(buff, src1, ..., srcn, NullS) with a + large enough buffer, and then calling strnmov(dst, buff, len). + It is just like strnmov except that it concatenates multiple sources. + Beware: the last argument should be the null character pointer. + Take VERY great care not to omit it! Also be careful to use NullS + and NOT to use 0, as on some machines 0 is not the same size as a + character pointer, or not the same bit pattern as NullS. + + Note: strxnmov is like strnmov in that it moves up to len + characters; dst will be padded on the right with one NUL characters if + needed. +*/ + +#include +#include "m_string.h" +#include + +char *strxnmov(char *dst, size_t len, const char *src, ...) +{ + va_list pvar; + char *end_of_dst=dst+len; + + va_start(pvar,src); + while (src != NullS) + { + do + { + if (dst == end_of_dst) + goto end; + } + while ((*dst++ = *src++)); + dst--; + src = va_arg(pvar, char *); + } + *dst=0; +end: + va_end(pvar); + return dst; +} diff --git a/libmysql/thr_mutex.c b/libmysql/thr_mutex.c index 340f14618..a985c58b4 100644 --- a/libmysql/thr_mutex.c +++ b/libmysql/thr_mutex.c @@ -101,7 +101,7 @@ int safe_mutex_unlock(safe_mutex_t *mp,const char *file, uint line) abort(); } mp->count--; -#ifdef __WIN__ +#ifdef _WIN32 pthread_mutex_unlock(&mp->mutex); error=0; #else @@ -112,7 +112,7 @@ int safe_mutex_unlock(safe_mutex_t *mp,const char *file, uint line) fflush(stderr); abort(); } -#endif /* __WIN__ */ +#endif /* _WIN32 */ pthread_mutex_unlock(&mp->global); return error; } @@ -216,7 +216,7 @@ int safe_mutex_destroy(safe_mutex_t *mp, const char *file, uint line) fflush(stderr); abort(); } -#ifdef __WIN__ +#ifdef _WIN32 pthread_mutex_destroy(&mp->global); pthread_mutex_destroy(&mp->mutex); #else diff --git a/libmysql/typelib.c b/libmysql/typelib.c index b18959442..7e1fb623c 100644 --- a/libmysql/typelib.c +++ b/libmysql/typelib.c @@ -33,7 +33,7 @@ int find_type(my_string x, TYPELIB *typelib, uint full_name) { - int find,pos,findpos; + int find,pos,findpos= 0; reg1 my_string i; reg2 const char *j; DBUG_ENTER("find_type"); diff --git a/libmysql/violite.c b/libmysql/violite.c index 8fa13a672..691664a19 100644 --- a/libmysql/violite.c +++ b/libmysql/violite.c @@ -22,10 +22,9 @@ the file descriptior. */ -#include - #ifndef HAVE_VIO /* is Vio suppored by the Vio lib ? */ +#include #include #include #include @@ -42,7 +41,12 @@ #include #endif -#if !defined(MSDOS) && !defined(__WIN__) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__) && !defined(__FreeBSD__) +#ifdef _WIN32 +#define socklen_t int +#pragma comment (lib, "ws2_32") +#endif + +#if !defined(MSDOS) && !defined(_WIN32) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__) && !defined(__FreeBSD__) #include #include #if !defined(alpha_linux_port) @@ -54,28 +58,13 @@ #define ioctlsocket ioctl #endif /* defined(__EMX__) */ -#if defined(MSDOS) || defined(__WIN__) +#if defined(MSDOS) || defined(_WIN32) #define O_NONBLOCK 1 /* For emulation of fcntl() */ #endif #ifndef EWOULDBLOCK #define SOCKET_EWOULDBLOCK SOCKET_EAGAIN #endif -#ifndef __WIN__ -#define HANDLE void * -#endif - -struct st_vio -{ - my_socket sd; /* my_socket - real or imaginary */ - HANDLE hPipe; - my_bool localhost; /* Are we from localhost? */ - int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */ - struct sockaddr_in local; /* Local internet address */ - struct sockaddr_in remote; /* Remote internet address */ - enum enum_vio_type type; /* Type of connection */ - char desc[30]; /* String description */ -}; typedef void *vio_ptr; typedef char *vio_cstring; @@ -95,6 +84,38 @@ static void vio_reset(Vio* vio, enum enum_vio_type type, vio->localhost= localhost; } +void vio_timeout(Vio *vio, int type, uint seconds) +{ +#ifdef _WIN32 + uint timeout= seconds * 1000; /* milli secs */ +#else + struct timeval timeout; + timeout.tv_sec= seconds; + timeout.tv_usec= 0; +#endif + + if (setsockopt(vio->sd, SOL_SOCKET, type, +#ifdef _WIN32 + (const char *)&timeout, +#else + (const void *)&timeout, +#endif + sizeof(timeout))) + { + DBUG_PRINT("error", ("setsockopt failed. Errno: %d", errno)); + } +} + +void vio_read_timeout(Vio *vio, uint seconds) +{ + vio_timeout(vio, SO_RCVTIMEO, seconds); +} + +void vio_write_timeout(Vio *vio, uint seconds) +{ + vio_timeout(vio, SO_SNDTIMEO, seconds); +} + /* Open the socket or TCP/IP connection and read the fnctl() status */ Vio *vio_new(my_socket sd, enum enum_vio_type type, my_bool localhost) @@ -108,14 +129,14 @@ Vio *vio_new(my_socket sd, enum enum_vio_type type, my_bool localhost) sprintf(vio->desc, (vio->type == VIO_TYPE_SOCKET ? "socket (%d)" : "TCP/IP (%d)"), vio->sd); -#if !defined(___WIN__) && !defined(__EMX__) && !defined(OS2) +#if !defined(__WIN32) && !defined(__EMX__) && !defined(OS2) #if !defined(NO_FCNTL_NONBLOCK) vio->fcntl_mode = fcntl(sd, F_GETFL); #elif defined(HAVE_SYS_IOCTL_H) /* hpux */ /* Non blocking sockets doesn't work good on HPUX 11.0 */ (void) ioctl(sd,FIOSNBIO,0); #endif -#else /* !defined(__WIN__) && !defined(__EMX__) */ +#else /* !defined(_WIN32) && !defined(__EMX__) */ { /* set to blocking mode by default */ ulong arg=0, r; @@ -127,7 +148,7 @@ Vio *vio_new(my_socket sd, enum enum_vio_type type, my_bool localhost) } -#ifdef __WIN__ +#ifdef _WIN32 Vio *vio_new_win32pipe(HANDLE hPipe) { @@ -166,7 +187,7 @@ int vio_read(Vio * vio, gptr buf, int size) int r; DBUG_ENTER("vio_read"); DBUG_PRINT("enter", ("sd=%d size=%d", vio->sd, size)); -#if defined( __WIN__) || defined(OS2) +#if defined( _WIN32) || defined(OS2) if (vio->type == VIO_TYPE_NAMEDPIPE) { DWORD length; @@ -183,7 +204,7 @@ int vio_read(Vio * vio, gptr buf, int size) #else errno=0; /* For linux */ r = read(vio->sd, buf, size); -#endif /* __WIN__ */ +#endif /* _WIN32 */ #ifndef DBUG_OFF if (r < 0) { @@ -200,7 +221,7 @@ int vio_write(Vio * vio, const gptr buf, int size) int r; DBUG_ENTER("vio_write"); DBUG_PRINT("enter", ("sd=%d size=%d", vio->sd, size)); -#if defined( __WIN__) || defined(OS2) +#if defined( _WIN32) || defined(OS2) if ( vio->type == VIO_TYPE_NAMEDPIPE) { DWORD length; @@ -216,7 +237,7 @@ int vio_write(Vio * vio, const gptr buf, int size) r = send(vio->sd, buf, size,0); #else r = write(vio->sd, buf, size); -#endif /* __WIN__ */ +#endif /* _WIN32 */ #ifndef DBUG_OFF if (r < 0) { @@ -234,7 +255,7 @@ int vio_blocking(Vio * vio, my_bool set_blocking_mode) DBUG_ENTER("vio_blocking"); DBUG_PRINT("enter", ("set_blocking_mode: %d", (int) set_blocking_mode)); -#if !defined(___WIN__) && !defined(__EMX__) && !defined(OS2) +#if !defined(__WIN32) && !defined(__EMX__) && !defined(OS2) #if !defined(NO_FCNTL_NONBLOCK) if (vio->sd >= 0) @@ -248,7 +269,7 @@ int vio_blocking(Vio * vio, my_bool set_blocking_mode) r = fcntl(vio->sd, F_SETFL, vio->fcntl_mode); } #endif /* !defined(NO_FCNTL_NONBLOCK) */ -#else /* !defined(__WIN__) && !defined(__EMX__) */ +#else /* !defined(_WIN32) && !defined(__EMX__) */ #ifndef __EMX__ if (vio->type != VIO_TYPE_NAMEDPIPE) #endif @@ -268,7 +289,7 @@ int vio_blocking(Vio * vio, my_bool set_blocking_mode) if (old_fcntl != vio->fcntl_mode) r = ioctlsocket(vio->sd,FIONBIO,(void*) &arg, sizeof(arg)); } -#endif /* !defined(__WIN__) && !defined(__EMX__) */ +#endif /* !defined(_WIN32) && !defined(__EMX__) */ DBUG_RETURN(r); } @@ -339,7 +360,7 @@ int vio_close(Vio * vio) { int r; DBUG_ENTER("vio_close"); -#ifdef __WIN__ +#ifdef _WIN32 if (vio->type == VIO_TYPE_NAMEDPIPE) { #if defined(__NT__) && defined(MYSQL_SERVER) @@ -349,7 +370,7 @@ int vio_close(Vio * vio) r=CloseHandle(vio->hPipe); } else if (vio->type != VIO_CLOSED) -#endif /* __WIN__ */ +#endif /* _WIN32 */ { r=0; if (shutdown(vio->sd,2)) diff --git a/mysql_config/CMakeLists.txt b/mysql_config/CMakeLists.txt new file mode 100644 index 000000000..60a1c43b6 --- /dev/null +++ b/mysql_config/CMakeLists.txt @@ -0,0 +1,30 @@ +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) + +# Figure out additional libraries for use with -lmysql + +FOREACH (dep ${libmysql_LIB_DEPENDS}) + STRING(REGEX MATCH "^-.*$" out "${dep}") + IF(out) + SET(extra_dynamic_LDFLAGS "${extra_dynamic_LDFLAGS} ${dep}") + ENDIF(out) +ENDFOREACH(dep) + +IF(UNIX) + IF(DL_LIBRARY) + SET(extra_dynamic_LDFLAGS "${extra_dynamic_LDFLAGS} -ldl") + ENDIF(DL_LIBRARY) + IF(MATH_LIBRARY) + SET(extra_dynamic_LDFLAGS "${extra_dynamic_LDFLAGS} -lm") + ENDIF(MATH_LIBRARY) +ENDIF(UNIX) + +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/mysql_config.c.in + ${CMAKE_CURRENT_BINARY_DIR}/mysql_config.c @ONLY) + +ADD_EXECUTABLE(mysql_config ${CMAKE_CURRENT_BINARY_DIR}/mysql_config.c) +TARGET_LINK_LIBRARIES(mysql_config mysqlclient) + +# Installation +# +INSTALL(TARGETS mysql_config + DESTINATION "bin") diff --git a/mysql_config/mysql_config.c.in b/mysql_config/mysql_config.c.in new file mode 100644 index 000000000..0c6b02102 --- /dev/null +++ b/mysql_config/mysql_config.c.in @@ -0,0 +1,101 @@ +#include +#include +#include +#include + +#define INCLUDE "-I@CMAKE_INSTALL_PREFIX@/include" +#define LIBS "-L@CMAKE_INSTALL_PREFIX@/lib -lmysql" \ + "@extra_dynamic_LDFLAGS@" +#define CFLAGS INCLUDE "@CMAKE_C_FLAGS@" +#define VERSION "@MYSQL_CLIENT_VERSION@" +#define SOCKET "@MYSQL_UNIX_ADDR@" +#define PORT "@MYSQL_PORT@" + +static struct option long_options[]= +{ + {"cflags", no_argument, 0, 'a'}, + {"help", no_argument, 0, 'b'}, + {"include", no_argument, 0, 'c'}, + {"libs", no_argument, 0, 'd'}, + {"libs_r", no_argument, 0, 'e'}, + {"version", no_argument, 0, 'f'}, + {"socket", no_argument, 0, 'g'}, + {"port", no_argument, 0, 'h'}, + {NULL, 0, 0, 0} +}; + +static char *values[]= +{ + CFLAGS, + NULL, + INCLUDE, + LIBS, + LIBS, + VERSION, + SOCKET, + PORT +}; + +void usage(void) +{ + int i=0; + puts("Copyright 2011 Monty Program AB"); + puts("Get compiler flags for using the MariaDB client library."); + printf("Usage: %s [OPTIONS]\n", my_progname); + while (long_options[i].name) + { + if (values[i]) + printf(" --%-12s [%s]\n", long_options[i].name, values[i]); + i++; + } +} + + +int main(int argc, char **argv) +{ + int error; + int c; + my_progname= argv[0]; + + if (argc <= 1) + { + usage(); + exit(1); + } + + while(1) + { + int option_index= 0; + c= getopt_long(argc, argv, "abcdef", long_options, &option_index); + + switch(c) { + case 'a': + puts(CFLAGS); + break; + case 'b': + usage(); + break; + case 'c': + puts(INCLUDE); + break; + case 'd': + case 'e': + puts(LIBS); + break; + case 'f': + puts(VERSION); + break; + case 'g': + puts(SOCKET); + break; + case 'h': + puts(PORT); + break; + default: + exit(0); + } + } + + exit(0); +} + diff --git a/zlib/CMakeLists.txt b/zlib/CMakeLists.txt index d53e998a8..d51d97f85 100644 --- a/zlib/CMakeLists.txt +++ b/zlib/CMakeLists.txt @@ -1,7 +1,9 @@ -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/extlib/zlib) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/zlib) SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG") SET(SOURCE_FILES adler32.c compress.c crc32.c deflate.c example.c gzclose.c gzlib.c gzread.c gzwrite.c infback.c inffast.c inflate.c inftrees.c minigzip.c trees.c uncompr.c zutil.c) ADD_LIBRARY(zlib ${SOURCE_FILES}) +SET_TARGET_PROPERTIES(zlib PROPERTIES COMPILE_FLAGS + "${CMAKE_SHARED_LIBRARY_C_FLAGS}") diff --git a/zlib/gzguts.h b/zlib/gzguts.h index 0f8fb79f8..466442db3 100644 --- a/zlib/gzguts.h +++ b/zlib/gzguts.h @@ -24,6 +24,9 @@ # include # include # include +#ifndef _WIN32 +# include +#endif #endif #include