1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Add MariaDB Connector/C as a built-in alternative (v3.2.3).

This commit is contained in:
Sandu Liviu Catalin 2021-09-21 20:59:01 +03:00
parent f192767853
commit b4bf96ce4b
372 changed files with 90819 additions and 11 deletions

View File

@ -15,6 +15,8 @@ option(ENABLE_API21 "Build for 2.1 API." OFF)
option(ENABLE_DISCORD "Enable built-in Discord support" ON) option(ENABLE_DISCORD "Enable built-in Discord support" ON)
option(ENABLE_DISCORD_VOICE "Enable voice support in Discord library" OFF) option(ENABLE_DISCORD_VOICE "Enable voice support in Discord library" OFF)
option(ENABLE_OFFICIAL "Enable compatibility with official legacy plug-in" ON) option(ENABLE_OFFICIAL "Enable compatibility with official legacy plug-in" ON)
# As a fall-back for certain situations (mainly some docker ubuntu containers)
option(ENABLE_BUILTIN_MYSQL_C "Enable built-in MySQL connector library" ON)
#option(FORCE_32BIT_BIN "Create a 32-bit executable binary if the compiler defaults to 64-bit." OFF) #option(FORCE_32BIT_BIN "Create a 32-bit executable binary if the compiler defaults to 64-bit." OFF)
# This option should only be available in certain conditions # This option should only be available in certain conditions
if(WIN32 AND MINGW) if(WIN32 AND MINGW)

View File

@ -155,7 +155,7 @@ if(ENABLE_DISCORD)
) )
endif() endif()
# Link to POCO libraries # Link to POCO libraries
target_link_libraries(SqModule Poco::Foundation Poco::Crypto Poco::Data Poco::Net Poco::JSON Poco::XML) target_link_libraries(SqModule Poco::Foundation Poco::Crypto Poco::Data Poco::Net)
# Does POCO have SQLite support? # Does POCO have SQLite support?
if(ENABLE_DATA_SQLITE) if(ENABLE_DATA_SQLITE)
if(NOT POCO_UNBUNDLED) if(NOT POCO_UNBUNDLED)
@ -170,9 +170,12 @@ if(ENABLE_DATA_SQLITE)
# Include legacy implementation sources # Include legacy implementation sources
target_sources(SqModule PRIVATE Library/SQLite.hpp Library/SQLite.cpp) target_sources(SqModule PRIVATE Library/SQLite.hpp Library/SQLite.cpp)
endif() endif()
# Does POCO have MySLQ support? # Do we have built-in MYSQL enabled?
if (NOT ENABLE_BUILTIN_MYSQL_C)
find_package(MySQL) find_package(MySQL)
if(MYSQL_FOUND) endif()
# Does POCO have MySLQ support?
if(ENABLE_BUILTIN_MYSQL_C OR MYSQL_FOUND)
message(STATUS "MySQL was enabled") message(STATUS "MySQL was enabled")
# Link the libraries # Link the libraries
target_link_libraries(SqModule Poco::DataMySQL) target_link_libraries(SqModule Poco::DataMySQL)

View File

@ -9,6 +9,14 @@ add_subdirectory(CPR)
add_subdirectory(UTF8) add_subdirectory(UTF8)
add_subdirectory(PUGIXML) add_subdirectory(PUGIXML)
add_subdirectory(CivetWeb) add_subdirectory(CivetWeb)
if (ENABLE_BUILTIN_MYSQL_C)
set(WITH_MSI OFF CACHE INTERNAL "" FORCE)
set(WITH_UNIT_TESTS OFF CACHE INTERNAL "" FORCE)
set(WITH_EXTERNAL_ZLIB ON CACHE INTERNAL "" FORCE)
set(WITH_CURL ON CACHE INTERNAL "" FORCE)
set(WITH_SSL ON CACHE INTERNAL "" FORCE)
add_subdirectory(MDBC)
endif()
set(BUILD_TESTING OFF CACHE INTERNAL "" FORCE) set(BUILD_TESTING OFF CACHE INTERNAL "" FORCE)
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "" FORCE) set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "" FORCE)
add_subdirectory(MaxmindDB) add_subdirectory(MaxmindDB)

517
vendor/MDBC/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,517 @@
# CMakeLists.txt
# This is the LGPL libmariadb project.
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12 FATAL_ERROR)
INCLUDE(CheckFunctionExists)
IF(COMMAND CMAKE_POLICY)
SET(NEW_POLICIES CMP0003 CMP0022 CMP0023 CMP0077 CMP0069 CMP0075)
FOREACH(TYPE OLD NEW)
FOREACH(P ${${TYPE}_POLICIES})
IF(POLICY ${P})
CMAKE_POLICY(SET ${P} ${TYPE})
ENDIF()
ENDFOREACH()
ENDFOREACH()
ENDIF()
PROJECT(mariadb-connector-c C)
# Is C/C built as subproject?
get_directory_property(IS_SUBPROJECT PARENT_DIRECTORY)
# do not inherit include directories from the parent project
SET_PROPERTY(DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
FOREACH(V WITH_MYSQLCOMPAT WITH_MSI WITH_SIGNCODE WITH_RTC WITH_UNIT_TESTS
WITH_DYNCOL WITH_EXTERNAL_ZLIB WITH_CURL WITH_SQLITE WITH_SSL WITH_ICONV
DEFAULT_CHARSET INSTALL_LAYOUT WITH_TEST_SRCPKG)
SET(${V} ${${OPT}${V}})
ENDFOREACH()
#SET(PACKAGE_STATUS_SUFFIX "rc")
SET(CC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
SET(CC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
SET(CPACK_PACKAGE_VERSION_MAJOR 3)
SET(CPACK_PACKAGE_VERSION_MINOR 2)
SET(CPACK_PACKAGE_VERSION_PATCH 3)
SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
MATH(EXPR MARIADB_PACKAGE_VERSION_ID "${CPACK_PACKAGE_VERSION_MAJOR} * 10000 +
${CPACK_PACKAGE_VERSION_MINOR} * 100 +
${CPACK_PACKAGE_VERSION_PATCH}")
MACRO(ADD_OPTION _name _text _default)
IF(NOT DEFINED ${_name})
OPTION(${OPT}${_name} "${_text}" "${_default}")
ELSE()
OPTION(${OPT}${_name} "${_text}" "${${_name}}")
ENDIF()
ENDMACRO()
### Options ###
IF(NOT WIN32)
ADD_OPTION(WITH_MYSQLCOMPAT "creates libmysql* symbolic links" OFF)
ELSE()
ADD_OPTION(WITH_MSI "Build MSI installation package" OFF)
ADD_OPTION(WITH_SIGNCODE "digitally sign files" OFF)
ADD_OPTION(WITH_RTC "enables run time checks for debug builds" OFF)
ADD_OPTION(WITH_ICONV "enables character set conversion" OFF)
ENDIF()
ADD_OPTION(WITH_UNIT_TESTS "build test suite" ON)
ADD_OPTION(WITH_DYNCOL "Enables support of dynamic columns" ON)
ADD_OPTION(WITH_EXTERNAL_ZLIB "Enables use of external zlib" OFF)
ADD_OPTION(WITH_CURL "Enables use of curl" ON)
ADD_OPTION(WITH_SSL "Enables use of TLS/SSL library" ON)
###############
INCLUDE(${CC_SOURCE_DIR}/cmake/misc.cmake)
INCLUDE(FindCURL)
IF(WITH_SIGNCODE)
IF(WIN32 AND NOT SIGN_OPTIONS)
SET(SIGN_OPTIONS /a /t http://timestamp.verisign.com/scripts/timstamp.dll)
ELSE()
SEPARATE_ARGUMENTS(SIGN_OPTIONS)
ENDIF()
MARK_AS_ADVANCED(SIGN_OPTIONS)
ENDIF()
SET(MARIADB_CONNECTOR_C_COPYRIGHT "2013-2017 MariaDB Corporation Ab")
IF(WITH_RTC)
SET(RTC_OPTIONS "/RTC1 /RTCc")
ENDIF()
INCLUDE(${CC_SOURCE_DIR}/cmake/plugins.cmake)
IF(WIN32)
FILE(REMOVE ${CC_BINARY_DIR}/win/packaging/plugin.conf)
INCLUDE(${CC_SOURCE_DIR}/cmake/version_info.cmake)
ENDIF()
IF(NOT IS_SUBPROJECT)
IF(MSVC)
# Speedup system tests
INCLUDE(${CC_SOURCE_DIR}/cmake/WindowsCache.cmake)
ADD_DEFINITIONS(-DWIN32_LEAN_AND_MEAN)
IF (MSVC)
SET(CONFIG_TYPES "DEBUG" "RELEASE" "RELWITHDEBINFO")
FOREACH(BUILD_TYPE ${CONFIG_TYPES})
FOREACH(COMPILER CXX C)
SET(COMPILER_FLAGS "${CMAKE_${COMPILER}_FLAGS_${BUILD_TYPE}}")
IF (NOT COMPILER_FLAGS STREQUAL "")
IF(NOT WITH_ASAN)
STRING(REPLACE "/MD" "/MT" COMPILER_FLAGS ${COMPILER_FLAGS})
IF (BUILD_TYPE STREQUAL "DEBUG")
SET(COMPILER_FLAGS "${COMPILER_FLAGS} ${RTC_OPTIONS}")
ENDIF()
ENDIF()
STRING(REPLACE "/Zi" "/Z7" COMPILER_FLAGS ${COMPILER_FLAGS})
MESSAGE (STATUS "CMAKE_${COMPILER}_FLAGS_${BUILD_TYPE}= ${COMPILER_FLAGS}")
SET(CMAKE_${COMPILER}_FLAGS_${BUILD_TYPE} ${COMPILER_FLAGS})
ENDIF()
ENDFOREACH()
ENDFOREACH()
ENDIF()
ENDIF()
ENDIF(NOT IS_SUBPROJECT)
# Disable dbug information for release builds
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DDBUG_OFF")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DDBUG_OFF")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -DDBUG_OFF")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DDBUG_OFF")
IF(CMAKE_COMPILER_IS_GNUCC)
INCLUDE(CheckCCompilerFlag)
#SET(GCC_FLAGS -Wunused -Wlogical-op -Wno-uninitialized -Wall -Wextra -Wformat-security -Wno-init-self -Wwrite-strings -Wshift-count-overflow -Wdeclaration-after-statement -Wno-undef -Wno-unknown-pragmas)
FOREACH(GCC_FLAG ${GCC_FLAGS})
CHECK_C_COMPILER_FLAG("${GCC_FLAG}" HAS_${GCC_FLAG}_FLAG)
IF(${HAS_${GCC_FLAG}_FLAG})
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_FLAG}")
ENDIF()
ENDFOREACH()
ENDIF()
# If the build type isn't specified, set to Relwithdebinfo as default.
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "RelWithDebInfo")
ENDIF()
# various defines for generating include/mysql_version.h
INCLUDE(FindGit)
IF(GIT_EXECUTABLE AND EXISTS ${CC_SOURCE_DIR}/.git)
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY ${CC_SOURCE_DIR}
OUTPUT_VARIABLE OUT RESULT_VARIABLE RES)
IF(RES EQUAL 0)
STRING(REGEX REPLACE "\n$" "" CC_SOURCE_REVISION "${OUT}")
ENDIF()
ENDIF()
SET(PROTOCOL_VERSION 10) # we adapted new password option from PHP's mysqlnd !
# if C/C is build as subproject inside MariaDB server tree we will
# use the version defined by server
IF(MAJOR_VERSION)
SET(MARIADB_CLIENT_VERSION_MAJOR ${MAJOR_VERSION})
SET(MARIADB_CLIENT_VERSION_MINOR ${MINOR_VERSION})
SET(MARIADB_CLIENT_VERSION_PATCH ${PATCH_VERSION})
SET(MARIADB_CLIENT_VERSION_EXTRA ${EXTRA_VERSION})
ELSE()
SET(MARIADB_CLIENT_VERSION_MAJOR "10")
SET(MARIADB_CLIENT_VERSION_MINOR "5")
SET(MARIADB_CLIENT_VERSION_PATCH "5")
SET(MARIADB_CLIENT_VERSION_EXTRA "")
ENDIF()
SET(MARIADB_CLIENT_VERSION "${MARIADB_CLIENT_VERSION_MAJOR}.${MARIADB_CLIENT_VERSION_MINOR}.${MARIADB_CLIENT_VERSION_PATCH}${MARIADB_CLIENT_VERSION_EXTRA}")
SET(MARIADB_BASE_VERSION "mariadb-${MARIADB_CLIENT_VERSION_MAJOR}.${MARIADB_CLIENT_VERSION_MINOR}")
MATH(EXPR MARIADB_VERSION_ID "${MARIADB_CLIENT_VERSION_MAJOR} * 10000 +
${MARIADB_CLIENT_VERSION_MINOR} * 100 +
${MARIADB_CLIENT_VERSION_PATCH}")
IF (NOT MARIADB_PORT)
SET(MARIADB_PORT 3306)
ENDIF ()
IF(NOT MARIADB_UNIX_ADDR)
SET(MARIADB_UNIX_ADDR "/tmp/mysql.sock")
ENDIF()
INCLUDE("${CC_SOURCE_DIR}/cmake/install.cmake")
IF(NOT PLUGINDIR)
SET(PLUGINDIR "${CMAKE_INSTALL_PREFIX}/${INSTALL_PLUGINDIR}")
ENDIF()
# todo: we don't character sets in share - all is compiled in
SET(SHAREDIR "share")
SET(DEFAULT_CHARSET_HOME "${CMAKE_INSTALL_PREFIX}")
INCLUDE(${CC_SOURCE_DIR}/cmake/SearchLibrary.cmake)
IF(WITH_EXTERNAL_ZLIB)
IF(NOT ZLIB_FOUND)
FIND_PACKAGE(ZLIB REQUIRED)
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
SET(LIBZ ${ZLIB_LIBRARY})
ELSE()
# ZLIB was already specified by another (parent) project
SET(INTERNAL_ZLIB_LIBRARY ${ZLIB_LIBRARY})
ENDIF()
ENDIF()
IF(NOT WIN32)
INCLUDE(TestBigEndian)
TEST_BIG_ENDIAN(HAVE_BIGENDIAN)
ENDIF()
# check for various include files
INCLUDE(${CC_SOURCE_DIR}/cmake/CheckIncludeFiles.cmake)
# check for various functions
INCLUDE(${CC_SOURCE_DIR}/cmake/CheckFunctions.cmake)
# check for various types
INCLUDE(${CC_SOURCE_DIR}/cmake/CheckTypes.cmake)
IF(UNIX)
SEARCH_LIBRARY(LIBM floor m)
SEARCH_LIBRARY(LIBPTHREAD pthread_getspecific "pthread;pthreads")
SEARCH_LIBRARY(LIBNSL gethostbyname_r "nsl_r;nsl")
SEARCH_LIBRARY(LIBSOCKET setsockopt socket)
FIND_PACKAGE(Threads)
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${LIBNSL} ${LIBBIND} ${LIBICONV} ${LIBZ}
${LIBSOCKET} ${CMAKE_DL_LIBS} ${LIBM} ${LIBPTHREAD})
SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${LIBNSL} ${LIBBIND} ${LIBICONV} ${LIBZ}
${LIBSOCKET} ${CMAKE_DL_LIBS} ${LIBM} ${LIBPTHREAD})
#remove possible dups from required libraries
LIST(LENGTH CMAKE_REQUIRED_LIBRARIES rllength)
IF(${rllength} GREATER 0)
LIST(REMOVE_DUPLICATES CMAKE_REQUIRED_LIBRARIES)
ENDIF()
ENDIF()
IF(CMAKE_HAVE_PTHREAD_H)
SET(CMAKE_REQUIRED_INCLUDES pthread.h)
ENDIF()
IF(DBUG_OFF)
ADD_DEFINITIONS(-DDBUG_OFF=1)
ENDIF()
ADD_DEFINITIONS(-DMARIADB_SYSTEM_TYPE="${CMAKE_SYSTEM_NAME}")
ADD_DEFINITIONS(-DMARIADB_MACHINE_TYPE="${CMAKE_SYSTEM_PROCESSOR}")
IF(WIN32)
SET(HAVE_THREADS 1)
ADD_DEFINITIONS(-DHAVE_DLOPEN)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
IF(MSVC)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996" )
ENDIF()
ELSEIF()
SET(HAVE_THREADS ${CMAKE_USE_PTHREADS})
ENDIF()
IF(NOT DEFAULT_CHARSET)
SET(DEFAULT_CHARSET "utf8mb4")
ENDIF()
# convert SSL options to uppercase
IF(WITH_SSL)
STRING(TOUPPER ${WITH_SSL} WITH_SSL)
ENDIF()
IF(WITH_SSL STREQUAL "ON")
IF(WIN32)
SET(WITH_SSL "SCHANNEL")
ELSE()
SET(WITH_SSL "OPENSSL")
ENDIF()
ENDIF()
IF(NOT WITH_SSL STREQUAL "OFF")
IF(WITH_SSL STREQUAL "OPENSSL")
IF (NOT OPENSSL_FOUND)
FIND_PACKAGE(OpenSSL)
ENDIF()
IF(OPENSSL_FOUND)
ADD_DEFINITIONS(-DHAVE_OPENSSL -DHAVE_TLS)
SET(SSL_SOURCES "${CC_SOURCE_DIR}/libmariadb/secure/openssl.c")
SET(SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
IF(WIN32)
CHECK_INCLUDE_FILES (${OPENSSL_INCLUDE_DIR}/openssl/applink.c HAVE_OPENSSL_APPLINK_C)
ENDIF()
INCLUDE_DIRECTORIES(BEFORE ${OPENSSL_INCLUDE_DIR})
TRY_RUN(LIBRESSL_RESULT HAVE_LIBRESSL
${CMAKE_BINARY_DIR}
${CC_SOURCE_DIR}/cmake/libressl_version.c
COMPILE_DEFINITIONS "-I${OPENSSL_INCLUDE_DIR}"
RUN_OUTPUT_VARIABLE LIBRESSL_VERSION)
IF(HAVE_LIBRESSL)
ADD_DEFINITIONS(-DHAVE_LIBRESSL)
SET(TLS_LIBRARY_VERSION ${LIBRESSL_VERSION})
ELSE()
SET(TLS_LIBRARY_VERSION "OpenSSL ${OPENSSL_VERSION}")
ENDIF()
ELSE()
MESSAGE1(TLS_LIBRARY_VERSION "OpenSSL/LibreSSL not found")
ENDIF()
ENDIF()
IF(WITH_SSL STREQUAL "GNUTLS")
FIND_PACKAGE(GnuTLS "3.3.24" REQUIRED)
IF(GNUTLS_FOUND)
ADD_DEFINITIONS(-DHAVE_GNUTLS -DHAVE_TLS)
SET(SSL_SOURCES "${CC_SOURCE_DIR}/libmariadb/secure/gnutls.c")
SET(SSL_LIBRARIES ${GNUTLS_LIBRARY})
SET(TLS_LIBRARY_VERSION "GnuTLS ${GNUTLS_VERSION_STRING}")
INCLUDE_DIRECTORIES(${GNUTLS_INCLUDE_DIR})
ELSE()
MESSAGE(FATAL_ERROR "GnuTLS not found")
ENDIF()
ENDIF()
IF(WIN32)
IF(WITH_SSL STREQUAL "SCHANNEL")
ADD_DEFINITIONS(-DHAVE_SCHANNEL -DHAVE_TLS)
SET(SSL_SOURCES "${CC_SOURCE_DIR}/libmariadb/secure/schannel.c"
"${CC_SOURCE_DIR}/libmariadb/secure/ma_schannel.c"
"${CC_SOURCE_DIR}/libmariadb/secure/schannel_certs.c")
INCLUDE_DIRECTORIES("${CC_SOURCE_DIR}/plugins/pvio/")
SET(SSL_LIBRARIES secur32)
SET(TLS_LIBRARY_VERSION "Schannel ${CMAKE_SYSTEM_VERSION}")
ENDIF()
ENDIF()
MESSAGE1(TLS_LIBRARY_VERSION "TLS library/version: ${TLS_LIBRARY_VERSION}")
MARK_AS_ADVANCED(SSL_SOURCES)
ENDIF()
SET(ENABLED_LOCAL_INFILE "AUTO" CACHE STRING "If we should should enable LOAD DATA LOCAL by default (OFF/ON/AUTO)")
MARK_AS_ADVANCED(ENABLED_LOCAL_INFILE)
IF (ENABLED_LOCAL_INFILE MATCHES "^(0|FALSE)$")
SET(ENABLED_LOCAL_INFILE OFF)
ELSEIF(ENABLED_LOCAL_INFILE MATCHES "^(1|TRUE)$")
SET(ENABLED_LOCAL_INFILE ON)
ELSEIF (NOT ENABLED_LOCAL_INFILE MATCHES "^(ON|OFF|AUTO)$")
MESSAGE(FATAL_ERROR "ENABLED_LOCAL_INFILE must be one of OFF, ON, AUTO")
ENDIF()
IF(WITH_ICONV)
IF(NOT WIN32)
INCLUDE(${CC_SOURCE_DIR}/cmake/FindIconv.cmake)
ENDIF()
ENDIF()
CONFIGURE_FILE(${CC_SOURCE_DIR}/include/ma_config.h.in
${CC_BINARY_DIR}/include/ma_config.h)
CONFIGURE_FILE(${CC_SOURCE_DIR}/include/ma_config.h.in
${CC_BINARY_DIR}/include/config.h)
CONFIGURE_FILE(${CC_SOURCE_DIR}/include/mariadb_version.h.in
${CC_BINARY_DIR}/include/mariadb_version.h)
INCLUDE_DIRECTORIES(${CC_BINARY_DIR}/include)
IF(WIN32)
SET(SYSTEM_LIBS ws2_32 advapi32 kernel32 shlwapi crypt32 ${LIBZ})
ELSE()
SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${LIBPTHREAD} ${CMAKE_DL_LIBS} ${LIBM})
IF(ICONV_EXTERNAL)
SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${ICONV_LIBRARIES})
ENDIF()
ENDIF()
IF(WITH_SSL)
SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${SSL_LIBRARIES})
ENDIF()
MESSAGE1(SYSTEM_LIBS "SYSTEM_LIBS ${SYSTEM_LIBS}")
MARK_AS_ADVANCED(SYSTEM_LIBS)
IF(NOT REMOTEIO_PLUGIN_TYPE MATCHES "OFF")
IF(CURL_FOUND)
INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS})
IF(REMOTEIO_PLUGIN_TYPE MATCHES "STATIC")
SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${CURL_LIBRARIES})
ENDIF()
ADD_DEFINITIONS("-DHAVE_REMOTEIO=1")
ENDIF()
ENDIF()
IF(NOT WIN32)
IF(NOT AUTH_GSSAPI_PLUGIN_TYPE MATCHES "OFF")
INCLUDE(${CC_SOURCE_DIR}/cmake/FindGSSAPI.cmake)
IF(GSSAPI_FOUND)
INCLUDE_DIRECTORIES(${GSSAPI_INCS})
IF(AUTH_GSSAPI_PLUGIN_TYPE MATCHES "STATIC")
SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${GSSAPI_LIBS})
ENDIF()
ENDIF()
ENDIF()
ENDIF()
INCLUDE(${CC_SOURCE_DIR}/plugins/CMakeLists.txt)
ADD_SUBDIRECTORY(include)
ADD_SUBDIRECTORY(libmariadb)
IF(NOT WIN32)
ADD_SUBDIRECTORY(mariadb_config)
ENDIF()
IF(IS_DIRECTORY ${CC_SOURCE_DIR}/unittest)
IF(WITH_UNIT_TESTS)
ADD_SUBDIRECTORY(unittest/mytap)
ADD_SUBDIRECTORY(unittest/libmariadb)
ENDIF()
ENDIF()
IF(CLIENT_DOCS)
INSTALL(DIRECTORY ${CLIENT_DOCS}
DESTINATION ${DOCS_INSTALL_DIR_${INSTALL_LAYOUT}}
COMPONENT SharedLibraries)
ENDIF()
IF(UNIX)
ADD_SUBDIRECTORY(man)
ENDIF()
IF(WIN32 AND WITH_MSI AND CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
ADD_SUBDIRECTORY(win/packaging)
ENDIF()
MESSAGE1(SYSTEM_PROCESSOR "SYSTEM processor: ${CMAKE_SYSTEM_PROCESSOR}")
SET(CPACK_PACKAGE_VENDOR "MariaDB Corporation Ab")
SET(CPACK_PACKAGE_DESCRIPTION "MariaDB Connector/C. A library for connecting to MariaDB and MySQL servers")
SET(CPACK_PACKAGE_NAME "mariadb_connector_c")
STRING(TOLOWER ${CMAKE_SYSTEM_NAME} system_name)
SET(CPACK_RESOURCE_FILE_LICENSE "${CC_SOURCE_DIR}/COPYING.LIB")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CC_SOURCE_DIR}/README")
INCLUDE(cmake/ConnectorName.cmake)
IF(NOT PACKAGE_STATUS_SUFFIX)
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-src")
IF(PACKAGE_PLATFORM_SUFFIX)
SET(CPACK_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${PACKAGE_PLATFORM_SUFFIX}")
ELSE()
SET(CPACK_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${system_name}-${CMAKE_SYSTEM_PROCESSOR}")
ENDIF()
ELSE()
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${PACKAGE_STATUS_SUFFIX}-src")
IF(PACKAGE_PLATFORM_SUFFIX)
SET(CPACK_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${PACKAGE_STATUS_SUFFIX}-${PACKAGE_PLATFORM_SUFFIX}")
ELSE()
SET(CPACK_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${PACKAGE_STATUS_SUFFIX}-${system_name}-${CMAKE_SYSTEM_PROCESSOR}")
ENDIF()
ENDIF()
# Build source packages
IF(GIT_BUILD_SRCPKG)
# get branch name
EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} show-branch OUTPUT_VARIABLE git_branch)
STRING(REGEX MATCH "\\[([^]]+)\\]" git_branch ${git_branch})
STRING(REGEX REPLACE "\\[|\\]" "" GIT_BRANCH ${git_branch})
MESSAGE1(GIT_BRANCH "${GIT_BRANCH}")
IF(WIN32)
EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} archive ${GIT_BRANCH} --format=zip --prefix=${CPACK_SOURCE_PACKAGE_FILE_NAME}/ --output=${CPACK_SOURCE_PACKAGE_FILE_NAME}.zip)
ELSE()
EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} archive ${GIT_BRANCH} --format=zip --prefix=${CPACK_SOURCE_PACKAGE_FILE_NAME}/ --output=${CPACK_SOURCE_PACKAGE_FILE_NAME}.zip)
EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} archive ${GIT_BRANCH} --format=tar --prefix=${CPACK_SOURCE_PACKAGE_FILE_NAME}/ --output=${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar)
EXECUTE_PROCESS(COMMAND gzip -9 -f ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar)
ENDIF()
ENDIF()
SET(CPACK_SOURCE_IGNORE_FILES
\\\\.git/
\\\\.gitignore
\\\\.gitattributes
CMakeCache\\\\.txt
cmake_dist\\\\.cmake
CPackConfig\\\\.cmake
mariadb_config\\\\.c$
\\\\.build/
html/
unittest
/cmake_install.cmake
/CTestTestfile.cmake
/CPackSourceConfig.cmake
/CMakeFiles/
/version_resources/
/_CPack_Packages/
\\\\.gz$
\\\\.zip$
mariadb_config/mariadb_config$
/CMakeFiles/
/version_resources/
/_CPack_Packages/
Makefile$
include/my_config\\\\.h$
)
IF(WITH_TEST_SRCPKG)
SET(PACKAGE_FILE ${CC_SOURCE_DIR}/package.name)
FILE(REMOVE ${PACKAGE_FILE})
FILE(WRITE ${PACKAGE_FILE} ${CPACK_SOURCE_PACKAGE_FILE_NAME})
ENDIF()
IF(WIN32)
SET(CPACK_GENERATOR "ZIP")
SET(CPACK_SOURCE_GENERATOR "ZIP")
ELSE()
SET(CPACK_GENERATOR "TGZ")
SET(CPACK_SOURCE_GENERATOR "TGZ")
ENDIF()
INCLUDE(CPack)
IF(WITH_EXTERNAL_ZLIB)
SET(zlib_status ${WITH_EXTERNAL_ZLIB})
ELSE()
SET(zlib_status "yes (using bundled zlib)")
ENDIF()
MESSAGE1(STATUS "MariaDB Connector/c configuration:
-- Static PLUGINS ${PLUGINS_STATIC}
-- Dynamic PLUGINS ${PLUGINS_DYNAMIC}
-- CPack generation: ${CPACK_GENERATOR}
-- SSL support: ${WITH_SSL} Libs: ${SSL_LIBRARIES}
-- Zlib support: ${zlib_status}
-- Installation layout: ${INSTALL_LAYOUT}
-- Include files will be installed in ${INSTALL_INCLUDEDIR}
-- Libraries will be installed in ${INSTALL_LIBDIR}
-- Binaries will be installed in ${INSTALL_BINDIR}
-- Documentation included from ${CLIENT_DOCS}
-- Required: ${CMAKE_REQUIRED_LIBRARIES}")

502
vendor/MDBC/COPYING.LIB vendored Normal file
View File

@ -0,0 +1,502 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
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 Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
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 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
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 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.
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.
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, 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, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
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
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
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
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
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 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
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
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.
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.
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 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.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
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 with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
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 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.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
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
Lesser General Public License for more details.
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
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

15
vendor/MDBC/README vendored Normal file
View File

@ -0,0 +1,15 @@
This is LGPL MariaDB client library that can be used to connect to MySQL
or MariaDB.
This code is based on the LGPL libmysql client library from MySQL 3.23
and PHP's mysqlnd extension.
This product includes PHP software, freely available from
<http://www.php.net/software/>
If you want to be part of this development effort, you can discuss this at
maria-developers@lists.launchpad.org.
To report a bug you'll need to signup for an account at https://jira.mariadb.org
The MariaDB team

16
vendor/MDBC/appveyor-download.bat vendored Normal file
View File

@ -0,0 +1,16 @@
@echo off
set archive=http://ftp.hosteurope.de/mirror/archive.mariadb.org//mariadb-%DB%/winx64-packages/mariadb-%DB%-winx64.msi
set last=http://mirror.i3d.net/pub/mariadb//mariadb-%DB%/winx64-packages/mariadb-%DB%-winx64.msi
curl -fLsS -o server.msi %archive%
if %ERRORLEVEL% == 0 goto end
curl -fLsS -o server.msi %last%
if %ERRORLEVEL% == 0 goto end
echo Failure Reason Given is %errorlevel%
exit /b %errorlevel%
:end
echo "File found".

41
vendor/MDBC/appveyor.yml vendored Normal file
View File

@ -0,0 +1,41 @@
version: 3.0.8;{build}
branches:
only:
- 3.1
environment:
matrix:
- DB: '10.2.38'
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_PARAM: 'Visual Studio 15 2017 Win64'
- DB: '10.3.29'
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_PARAM: 'Visual Studio 15 2017 Win64'
- DB: '10.4.19'
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_PARAM: 'Visual Studio 15 2017 Win64'
- DB: '10.5.10'
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_PARAM: 'Visual Studio 15 2017 Win64'
configuration: RelWithDebInfo
clone_folder: c:\projects\mariadb-connector-c
before_build:
- cmd: appveyor-download.bat
- cmd: msiexec /i server.msi INSTALLDIR=c:\projects\server SERVICENAME=mariadb ALLOWREMOTEROOTACCESS=true /qn
- cmd: "\"c:\\projects\\server\\bin\\mysql.exe\" -e \"create database testc\" --user=root"
- cmd: set MARIADB_CC_TEST=1
- cmd: set MYSQL_TEST_USER=root
- cmd: set MYSQL_TEST_HOST=127.0.0.1
- cmd: set MYSQL_TEST_PASSWD=
- cmd: set MYSQL_TEST_PORT=3306
- cmd: set MYSQL_TEST_DB=testc
- cmd: cmake -G "%CMAKE_PARAM%" -DCMAKE_BUILD_TYPE=RelWithDebInfo
build:
project: mariadb-connector-c.sln
parallel: true
verbosity: minimal
test_script:
- cmd: cd c:\projects\mariadb-connector-c\unittest\libmariadb
- cmd: set MARIADB_PLUGIN_DIR=cd c:\projects\mariadb-connector-c\plugins\lib\RelWithDebInfo
- cmd: ctest -V

17
vendor/MDBC/client/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,17 @@
INCLUDE_DIRECTORIES(${CC_SOURCE_DIR}/include)
IF(WIN32)
SET_VERSION_INFO("TARGET:mariadb_client_plugin_info"
"FILE_TYPE:VFT_APP"
"SOURCE_FILE:client/ma_plugin_info.c"
"ORIGINAL_FILE_NAME:mariadb_client_plugin_info.exe"
"FILE_DESCRIPTION:Client plugin viewer")
ENDIF()
ADD_EXECUTABLE(mariadb_client_plugin_info ${mariadb_client_plugin_info_RC} ma_plugin_info.c)
TARGET_LINK_LIBRARIES(mariadb_client_plugin_info mariadbclient)
INSTALL(TARGETS mariadb_client_plugin_info
DESTINATION ${INSTALL_BINDIR}
COMPONENT SharedLibraries)
SIGN_TARGET(mariadb_client_plugin_info)

211
vendor/MDBC/client/ma_plugin_info.c vendored Normal file
View File

@ -0,0 +1,211 @@
#include <my_global.h>
#include <my_sys.h>
#include <mysql.h>
#include <mysql/client_plugin.h>
#include <getopt.h>
#include <stdio.h>
#include <my_dir.h>
#include <ma_string.h>
#define CLIENT_PLUGIN_INFO_VERSION "1.0.0"
static struct option long_options[]=
{
{"all", no_argument, 0, 'a'},
{"builtin", no_argument, 0, 'b'},
{"dynamic", no_argument, 0, 'd'},
{"directory", 1, 0, 'p'},
{"plugin_name", 1, 0, 'n'},
{"version", no_argument, 0, 'v'},
{"help", no_argument, 0, '?'},
{NULL, 0, 0, 0}
};
static char *values[] =
{
"show information for all plugins",
"show information for builtin plugins",
"show information for dynamic plugins",
"show information for dynamic plugins in specified directory",
"show information for specified plugin",
"show version information",
"display this help and exit",
NULL
};
struct st_plugin_type
{
int type;
char *typename;
};
#ifndef _WIN32
int my_errno=0;
#endif
static struct st_plugin_type plugin_types[]=
{
{MYSQL_CLIENT_AUTHENTICATION_PLUGIN, "authentication"},
{MARIADB_CLIENT_PVIO_PLUGIN, "virtual IO"},
{MARIADB_CLIENT_TRACE_PLUGIN, "trace"},
{MARIADB_CLIENT_REMOTEIO_PLUGIN, "remote file access"},
{MARIADB_CLIENT_CONNECTION_PLUGIN, "connection handler"},
{0, "unknown"}
};
static void version()
{
printf("%s Version %s\n", ma_progname, CLIENT_PLUGIN_INFO_VERSION);
}
static void usage(void)
{
int i=0;
printf("%s Version %s\n", ma_progname, CLIENT_PLUGIN_INFO_VERSION);
puts("Copyright 2015 MariaDB Corporation AB");
puts("Show client plugin information for MariaDB Connector/C.");
printf("Usage: %s [OPTIONS] [plugin_name]\n", ma_progname);
while (long_options[i].name)
{
printf(" --%-12s -%s\n", long_options[i].name, values[i]);
i++;
}
}
static char *ma_get_type_name(int type)
{
int i=0;
while (plugin_types[i].type)
{
if (type== plugin_types[i].type)
return plugin_types[i].typename;
i++;
}
return plugin_types[i].typename;
}
static void show_plugin_info(struct st_mysql_client_plugin *plugin, my_bool builtin)
{
printf("Name: %s\n", plugin->name);
printf("Type: %s\n", ma_get_type_name(plugin->type));
printf("Desc: %s\n", plugin->desc);
printf("Author: %s\n", plugin->author);
printf("License: %s\n", plugin->license);
printf("Version: %d.%d.%d\n", plugin->version[0], plugin->version[1], plugin->version[2]);
printf("API Version: 0x%04X\n", plugin->interface_version);
printf("Build type: %s\n", builtin ? "builtin" : "dynamic");
printf("\n");
}
static void show_builtin()
{
struct st_mysql_client_plugin **builtin;
for (builtin= mysql_client_builtins; *builtin; builtin++)
show_plugin_info(*builtin, TRUE);
}
static void show_file(char *filename)
{
char dlpath[FN_REFLEN+1];
void *sym, *dlhandle;
struct st_mysql_client_plugin *plugin;
char *env_plugin_dir= getenv("MARIADB_PLUGIN_DIR");
char *has_so_ext= strstr(filename, SO_EXT);
if (!strchr(filename, FN_LIBCHAR))
snprintf(dlpath, sizeof(dlpath) - 1, "%s/%s%s",
(env_plugin_dir) ? env_plugin_dir : PLUGINDIR,
filename,
has_so_ext ? "" : SO_EXT);
else
strcpy(dlpath, filename);
if ((dlhandle= dlopen((const char *)dlpath, RTLD_NOW)))
{
if (sym= dlsym(dlhandle, plugin_declarations_sym))
{
plugin= (struct st_mysql_client_plugin *)sym;
show_plugin_info(plugin, 0);
}
dlclose(dlhandle);
}
}
static void show_dynamic(const char *directory)
{
MY_DIR *dir= NULL;
unsigned int i;
char *plugin_dir= directory ? (char *)directory : getenv("MARIADB_PLUGIN_DIR");
if (!plugin_dir)
plugin_dir= PLUGINDIR;
printf("plugin_dir %s\n", plugin_dir);
dir= my_dir(plugin_dir, 0);
if (!dir || !dir->number_off_files)
{
printf("No plugins found in %s\n", plugin_dir);
goto end;
}
for (i=0; i < dir->number_off_files; i++)
{
char *p= strstr(dir->dir_entry[i].name, SO_EXT);
if (p)
show_file(dir->dir_entry[i].name);
}
end:
if (dir)
my_dirend(dir);
}
int main(int argc, char *argv[])
{
int option_index= 0;
int c;
ma_progname= argv[0];
mysql_server_init(0, NULL, NULL);
if (argc <= 1)
{
usage();
exit(1);
}
c= getopt_long(argc, argv, "bdapnvh?", long_options, &option_index);
switch(c) {
case 'a': /* all */
show_builtin();
show_dynamic(NULL);
break;
case 'b': /* builtin */
show_builtin();
break;
case 'd': /* dynamic */
show_dynamic(NULL);
break;
case 'v':
version();
break;
case 'n':
if (argc > 2)
show_file(argv[2]);
break;
case 'p':
if (argc > 2)
show_dynamic(argv[2]);
break;
case '?':
usage();
break;
default:
printf("unrecocognized option: %s", argv[1]);
exit(1);
}
exit(0);
}

22
vendor/MDBC/cmake/COPYING-CMAKE-SCRIPTS vendored Normal file
View File

@ -0,0 +1,22 @@
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 copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 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 AUTHOR 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.

30
vendor/MDBC/cmake/CheckFunctions.cmake vendored Normal file
View File

@ -0,0 +1,30 @@
#
# Copyright (C) 2013-2016 MariaDB Corporation AB
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the COPYING-CMAKE-SCRIPTS file.
#
# This file is included by CMakeLists.txt and
# checks for various functions.
# You will find the appropriate defines in
# include/my_config.h.in
INCLUDE(CheckFunctionExists)
CHECK_FUNCTION_EXISTS (alloca HAVE_ALLOCA)
CHECK_FUNCTION_EXISTS (dlerror HAVE_DLERROR)
CHECK_FUNCTION_EXISTS (dlopen HAVE_DLOPEN)
CHECK_FUNCTION_EXISTS (fcntl HAVE_FCNTL)
CHECK_FUNCTION_EXISTS (memcpy HAVE_MEMCPY)
CHECK_FUNCTION_EXISTS (nl_langinfo HAVE_NL_LANGINFO)
CHECK_FUNCTION_EXISTS (setlocale HAVE_SETLOCALE)
CHECK_FUNCTION_EXISTS (poll HAVE_POLL)
CHECK_FUNCTION_EXISTS (getpwuid HAVE_GETPWUID)
IF(HAVE_FILE_UCONTEXT_H)
CHECK_FUNCTION_EXISTS (makecontext HAVE_UCONTEXT_H)
ENDIF()
CHECK_FUNCTION_EXISTS (cuserid HAVE_CUSERID)

View File

@ -0,0 +1,58 @@
#
# Copyright (C) 2013-2016 MariaDB Corporation AB
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the COPYING-CMAKE-SCRIPTS file.
#
# This file is included by CMakeLists.txt and
# checks for various header files.
# You will find the appropriate defines in
# include/my_config.h.in
INCLUDE(CheckIncludeFiles)
CHECK_INCLUDE_FILES (alloca.h HAVE_ALLOCA_H)
CHECK_INCLUDE_FILES (arpa/inet.h HAVE_ARPA_INET_H)
CHECK_INCLUDE_FILES (dlfcn.h HAVE_DLFCN_H)
CHECK_INCLUDE_FILES (fcntl.h HAVE_FCNTL_H)
CHECK_INCLUDE_FILES (float.h HAVE_FLOAT_H)
CHECK_INCLUDE_FILES (limits.h HAVE_LIMITS_H)
CHECK_INCLUDE_FILES (linux/limits.h HAVE_LINUX_LIMITS_H)
CHECK_INCLUDE_FILES (pwd.h HAVE_PWD_H)
CHECK_INCLUDE_FILES (sched.h HAVE_SCHED_H)
CHECK_INCLUDE_FILES (select.h HAVE_SELECT_H)
CHECK_INCLUDE_FILES (signal.h INCLUDE_SIGNAL)
IF(INCLUDE_SIGNAL)
SET(HAVE_SIGNAL 1)
SET(CMAKE_EXTRA_INCLUDE_FILES signal.h)
ENDIF(INCLUDE_SIGNAL)
CHECK_INCLUDE_FILES (stddef.h HAVE_STDDEF_H)
CHECK_INCLUDE_FILES (stdint.h HAVE_STDINT_H)
IF(HAVE_STDINT_H)
SET(CMAKE_EXTRA_INCLUDE_FILES stdint.h)
ENDIF(HAVE_STDINT_H)
CHECK_INCLUDE_FILES (stdlib.h HAVE_STDLIB_H)
CHECK_INCLUDE_FILES (string.h HAVE_STRING_H)
CHECK_INCLUDE_FILES (strings.h HAVE_STRINGS_H)
CHECK_INCLUDE_FILES (sys/ioctl.h HAVE_SYS_IOCTL_H)
CHECK_INCLUDE_FILES (sys/select.h HAVE_SYS_SELECT_H)
CHECK_INCLUDE_FILES (sys/socket.h HAVE_SYS_SOCKET_H)
CHECK_INCLUDE_FILES (sys/types.h HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILES (sys/stat.h HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILES (sys/un.h HAVE_SYS_UN_H)
CHECK_INCLUDE_FILES (unistd.h HAVE_UNISTD_H)
CHECK_INCLUDE_FILES (utime.h HAVE_UTIME_H)
IF(APPLE)
SET(CMAKE_REQUIRED_DEFINITIONS -D_XOPEN_SOURCE=600)
ENDIF()
CHECK_INCLUDE_FILES (ucontext.h HAVE_FILE_UCONTEXT_H)
IF(NOT HAVE_FILE_UCONTEXT_H)
CHECK_INCLUDE_FILES (sys/ucontext.h HAVE_FILE_UCONTEXT_H)
ENDIF()

62
vendor/MDBC/cmake/CheckTypes.cmake vendored Normal file
View File

@ -0,0 +1,62 @@
#
# Copyright (C) 2013-2016 MariaDB Corporation AB
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the COPYING-CMAKE-SCRIPTS file.
#
# This file is included by CMakeLists.txt and
# checks for type sizes.
# You will find the appropriate defines in
# include/my_config.h.in
INCLUDE (CheckTypeSize)
SET(CMAKE_EXTRA_INCLUDE_FILES signal.h)
CHECK_TYPE_SIZE("char *" SIZEOF_CHARP)
CHECK_TYPE_SIZE(int SIZEOF_INT)
CHECK_TYPE_SIZE(long SIZEOF_LONG)
CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
SET(CMAKE_EXTRA_INCLUDE_FILES stdio.h)
CHECK_TYPE_SIZE(size_t SIZEOF_SIZE_T)
SET(CMAKE_EXTRA_INCLUDE_FILES sys/types.h)
CHECK_TYPE_SIZE(uchar SIZEOF_UCHAR)
CHECK_TYPE_SIZE(uint SIZEOF_UINT)
CHECK_TYPE_SIZE(ulong SIZEOF_ULONG)
CHECK_TYPE_SIZE(int8 SIZEOF_INT8)
CHECK_TYPE_SIZE(uint8 SIZEOF_UINT8)
CHECK_TYPE_SIZE(int16 SIZEOF_INT16)
CHECK_TYPE_SIZE(uint16 SIZEOF_UINT16)
CHECK_TYPE_SIZE(int32 SIZEOF_INT32)
CHECK_TYPE_SIZE(uint32 SIZEOF_UINT32)
CHECK_TYPE_SIZE(int64 SIZEOF_INT64)
CHECK_TYPE_SIZE(uint64 SIZEOF_UINT64)
CHECK_TYPE_SIZE(socklen_t SIZEOF_SOCKLEN_T)
#
# Compile testing
#
INCLUDE (CheckCSourceCompiles)
#
# 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_C_SOURCE_COMPILES("
#include <sys/socket.h>
int main(int argc, char **argv)
{
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)

34
vendor/MDBC/cmake/ConnectorName.cmake vendored Normal file
View File

@ -0,0 +1,34 @@
#
# Copyright (C) 2013-2016 MariaDB Corporation AB
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the COPYING-CMAKE-SCRIPTS file.
#
MACRO(GET_CONNECTOR_PACKAGE_NAME name)
# check if we have 64bit
IF(SIZEOF_VOIDP EQUAL 8)
SET(IS64 1)
ENDIF()
SET (PLAFORM_NAME CMAKE_SYSTEM_NAME)
SET (MACHINE_NAME CMAKE_SYSTEM_PROCESSOR)
SET (CONCAT_SIGN "-")
IF(CMAKE_SYSTEM_NAME MATCHES "Windows")
SET(PLATFORM_NAME "win")
SET(CONCAT_SIGN "")
IF(IS64)
IF(CMAKE_C_COMPILER_ARCHITECTURE_ID)
STRING(TOLOWER "${CMAKE_C_COMPILER_ARCHITECTURE_ID}" MACHINE_NAME)
ELSE()
SET(MACHINE_NAME x64)
ENDIF()
ELSE()
SET(MACHINE_NAME "32")
ENDIF()
ENDIF()
SET(product_name "mysql-connector-c-${CPACK_PACKAGE_VERSION}-${PLATFORM_NAME}${CONCAT_SIGN}${MACHINE_NAME}")
STRING(TOLOWER ${product_name} ${name})
ENDMACRO()

110
vendor/MDBC/cmake/FindGSSAPI.cmake vendored Normal file
View File

@ -0,0 +1,110 @@
#
# Copyright (C) 2013-2016 MariaDB Corporation AB
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the COPYING-CMAKE-SCRIPTS file.
#
# - Try to detect the GSSAPI support
# Once done this will define
#
# GSSAPI_FOUND - system supports GSSAPI
# GSSAPI_INCS - the GSSAPI include directory
# GSSAPI_LIBS - the libraries needed to use GSSAPI
# GSSAPI_FLAVOR - the type of API - MIT or HEIMDAL
# Copyright (c) 2006, Pino Toscano, <toscano.pino@tiscali.it>
#
# 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 copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 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 AUTHOR 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.
if(GSSAPI_LIBS AND GSSAPI_FLAVOR)
# in cache already
set(GSSAPI_FOUND TRUE)
else(GSSAPI_LIBS AND GSSAPI_FLAVOR)
find_program(KRB5_CONFIG NAMES krb5-config PATHS
/opt/local/bin
/usr/lib/mit/bin/
ONLY_CMAKE_FIND_ROOT_PATH # this is required when cross compiling with cmake 2.6 and ignored with cmake 2.4, Alex
)
mark_as_advanced(KRB5_CONFIG)
#reset vars
set(GSSAPI_INCS)
set(GSSAPI_LIBS)
set(GSSAPI_FLAVOR)
if(KRB5_CONFIG)
set(HAVE_KRB5_GSSAPI TRUE)
exec_program(${KRB5_CONFIG} ARGS --libs gssapi RETURN_VALUE _return_VALUE OUTPUT_VARIABLE GSSAPI_LIBS)
if(_return_VALUE)
message(STATUS "GSSAPI configure check failed.")
set(HAVE_KRB5_GSSAPI FALSE)
endif(_return_VALUE)
IF(CMAKE_SYSTEM_NAME MATCHES AIX)
string(REGEX REPLACE "-Wl[A-Za-z0-9_/,:-]*[ $]?" "" GSSAPI_LIBS "${GSSAPI_LIBS}")
string(REGEX REPLACE "-L[A-Za-z0-9_/,:-]*[ $]?" "" GSSAPI_LIBS "${GSSAPI_LIBS}")
ENDIF()
exec_program(${KRB5_CONFIG} ARGS --cflags gssapi RETURN_VALUE _return_VALUE OUTPUT_VARIABLE GSSAPI_INCS)
string(REGEX REPLACE "(\r?\n)+$" "" GSSAPI_INCS "${GSSAPI_INCS}")
string(REGEX REPLACE " *-I" ";" GSSAPI_INCS "${GSSAPI_INCS}")
exec_program(${KRB5_CONFIG} ARGS --vendor RETURN_VALUE _return_VALUE OUTPUT_VARIABLE gssapi_flavor_tmp)
set(GSSAPI_FLAVOR_MIT)
if(gssapi_flavor_tmp MATCHES ".*Massachusetts.*")
set(GSSAPI_FLAVOR "MIT")
else(gssapi_flavor_tmp MATCHES ".*Massachusetts.*")
set(GSSAPI_FLAVOR "HEIMDAL")
endif(gssapi_flavor_tmp MATCHES ".*Massachusetts.*")
if(NOT HAVE_KRB5_GSSAPI)
if (gssapi_flavor_tmp MATCHES "Sun Microsystems.*")
message(STATUS "Solaris Kerberos does not have GSSAPI; this is normal.")
set(GSSAPI_LIBS)
set(GSSAPI_INCS)
else(gssapi_flavor_tmp MATCHES "Sun Microsystems.*")
message(WARNING "${KRB5_CONFIG} failed unexpectedly.")
endif(gssapi_flavor_tmp MATCHES "Sun Microsystems.*")
endif(NOT HAVE_KRB5_GSSAPI)
if(GSSAPI_LIBS) # GSSAPI_INCS can be also empty, so don't rely on that
set(GSSAPI_FOUND TRUE CACHE STRING "")
message(STATUS "Found GSSAPI: ${GSSAPI_LIBS}")
set(GSSAPI_INCS ${GSSAPI_INCS} CACHE STRING "")
set(GSSAPI_LIBS ${GSSAPI_LIBS} CACHE STRING "")
set(GSSAPI_FLAVOR ${GSSAPI_FLAVOR} CACHE STRING "")
mark_as_advanced(GSSAPI_INCS GSSAPI_LIBS GSSAPI_FLAVOR)
endif(GSSAPI_LIBS)
endif(KRB5_CONFIG)
endif(GSSAPI_LIBS AND GSSAPI_FLAVOR)

82
vendor/MDBC/cmake/FindIconv.cmake vendored Normal file
View File

@ -0,0 +1,82 @@
#
# Copyright (C) 2010 Michael Bell <michael.bell@web.de>
# 2015-2016 MariaDB Corporation AB
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the COPYING-CMAKE-SCRIPTS file.
#
# ICONV_EXTERNAL - Iconv is an external library (not libc)
# ICONV_FOUND - system has Iconv
# ICONV_INCLUDE_DIR - the Iconv include directory
# ICONV_LIBRARIES - Link these to use Iconv
# ICONV_SECOND_ARGUMENT_IS_CONST - the second argument for iconv() is const
# ICONV_VERSION - Iconv version string
if (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
# Already in cache, be silent
set(ICONV_FIND_QUIETLY TRUE)
endif (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
find_path(ICONV_INCLUDE_DIR iconv.h)
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
# There is some libiconv.so in /usr/local that must
# be avoided, iconv routines are in libc
ELSEIF(APPLE)
find_library(ICONV_LIBRARIES NAMES iconv libiconv PATHS
/usr/lib/
NO_CMAKE_SYSTEM_PATH)
SET(ICONV_EXTERNAL TRUE)
ELSE()
find_library(ICONV_LIBRARIES NAMES iconv libiconv libiconv-2)
IF(ICONV_LIBRARIES)
SET(ICONV_EXTERNAL TRUE)
ENDIF()
ENDIF()
if (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
set (ICONV_FOUND TRUE)
endif (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
IF(ICONV_EXTERNAL)
set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
ENDIF()
if (ICONV_FOUND)
include(CheckCSourceCompiles)
CHECK_C_SOURCE_COMPILES("
#include <iconv.h>
int main(){
iconv_t conv = 0;
const char* in = 0;
size_t ilen = 0;
char* out = 0;
size_t olen = 0;
iconv(conv, &in, &ilen, &out, &olen);
return 0;
}
" ICONV_SECOND_ARGUMENT_IS_CONST )
ADD_DEFINITIONS(-DHAVE_ICONV)
endif (ICONV_FOUND)
set (CMAKE_REQUIRED_INCLUDES)
set (CMAKE_REQUIRED_LIBRARIES)
if (ICONV_FOUND)
if (NOT ICONV_FIND_QUIETLY)
message (STATUS "Found Iconv: ${ICONV_LIBRARIES}")
endif (NOT ICONV_FIND_QUIETLY)
else (ICONV_FOUND)
if (Iconv_FIND_REQUIRED)
message (FATAL_ERROR "Could not find Iconv")
endif (Iconv_FIND_REQUIRED)
endif (ICONV_FOUND)
MARK_AS_ADVANCED(
ICONV_INCLUDE_DIR
ICONV_LIBRARIES
ICONV_EXTERNAL
ICONV_SECOND_ARGUMENT_IS_CONST
)

29
vendor/MDBC/cmake/SearchLibrary.cmake vendored Normal file
View File

@ -0,0 +1,29 @@
#
# Copyright (C) 2013-2016 MariaDB Corporation AB
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the COPYING-CMAKE-SCRIPTS file.
#
INCLUDE(CheckFunctionExists)
INCLUDE(CheckLibraryExists)
FUNCTION(SEARCH_LIBRARY library_name function liblist)
IF(${${library_name}})
RETURN()
ENDIF()
CHECK_FUNCTION_EXISTS(${function} IS_${function}_LIBC_FUNC)
IF(IS_${function}_LIBC_FUNC)
SET(${library_name} "" PARENT_SCOPE)
RETURN()
ENDIF()
FOREACH(lib ${liblist})
CHECK_LIBRARY_EXISTS(${lib} ${function} "" HAVE_${function}_IN_${lib})
IF(HAVE_${function}_IN_${lib})
SET(${library_name} ${lib} PARENT_SCOPE)
SET(HAVE_${library_name} 1 PARENT_SCOPE)
RETURN()
ENDIF()
ENDFOREACH()
ENDFUNCTION()

392
vendor/MDBC/cmake/WindowsCache.cmake vendored Normal file
View File

@ -0,0 +1,392 @@
#
# Copyright (C) 2013-2016 MariaDB Corporation AB
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the COPYING-CMAKE-SCRIPTS file.
#
IF(MSVC)
SET(BFD_H_EXISTS 0 CACHE INTERNAL "")
SET(HAVE_ACCESS 1 CACHE INTERNAL "")
SET(HAVE_AIO_H CACHE INTERNAL "")
SET(HAVE_AIO_READ CACHE INTERNAL "")
SET(HAVE_ALARM CACHE INTERNAL "")
SET(HAVE_ALLOCA_H CACHE INTERNAL "")
SET(HAVE_ARPA_INET_H CACHE INTERNAL "")
SET(HAVE_ASM_MSR_H CACHE INTERNAL "")
SET(HAVE_BACKTRACE CACHE INTERNAL "")
SET(HAVE_BACKTRACE_SYMBOLS CACHE INTERNAL "")
SET(HAVE_BACKTRACE_SYMBOLS_FD CACHE INTERNAL "")
SET(HAVE_BFILL CACHE INTERNAL "")
SET(HAVE_BMOVE CACHE INTERNAL "")
SET(HAVE_BSD_SIGNALS CACHE INTERNAL "")
SET(HAVE_BSEARCH 1 CACHE INTERNAL "")
SET(HAVE_BSS_START CACHE INTERNAL "")
SET(HAVE_BZERO CACHE INTERNAL "")
SET(HAVE_CHOWN CACHE INTERNAL "")
SET(HAVE_CLOCK_GETTIME CACHE INTERNAL "")
SET(HAVE_COMPRESS CACHE INTERNAL "")
SET(HAVE_CRYPT CACHE INTERNAL "")
SET(HAVE_CRYPT_H CACHE INTERNAL "")
SET(HAVE_CUSERID CACHE INTERNAL "")
SET(HAVE_CXX_NEW 1 CACHE INTERNAL "")
SET(HAVE_DECL_MADVISE CACHE INTERNAL "")
SET(HAVE_DIRECTIO CACHE INTERNAL "")
SET(HAVE_DIRENT_H CACHE INTERNAL "")
SET(HAVE_DLERROR CACHE INTERNAL "")
SET(HAVE_DLFCN_H CACHE INTERNAL "")
SET(HAVE_DLOPEN CACHE INTERNAL "")
SET(HAVE_DOPRNT CACHE INTERNAL "")
SET(HAVE_EXECINFO_H CACHE INTERNAL "")
SET(HAVE_FCHMOD CACHE INTERNAL "")
SET(HAVE_FCNTL CACHE INTERNAL "")
SET(HAVE_FCNTL_H 1 CACHE INTERNAL "")
SET(HAVE_FCNTL_NONBLOCK CACHE INTERNAL "")
SET(HAVE_FCONVERT CACHE INTERNAL "")
SET(HAVE_FDATASYNC CACHE INTERNAL "")
SET(HAVE_DECL_FDATASYNC CACHE INTERNAL "")
SET(HAVE_FEDISABLEEXCEPT CACHE INTERNAL "")
SET(HAVE_FENV_H CACHE INTERNAL "")
SET(HAVE_FESETROUND CACHE INTERNAL "")
SET(HAVE_FGETLN CACHE INTERNAL "")
SET(HAVE_FINITE CACHE INTERNAL "")
SET(HAVE_FINITE_IN_MATH_H CACHE INTERNAL "")
SET(HAVE_FLOATINGPOINT_H CACHE INTERNAL "")
SET(HAVE_FLOAT_H 1 CACHE INTERNAL "")
SET(HAVE_FLOCKFILE CACHE INTERNAL "")
SET(HAVE_FNMATCH_H CACHE INTERNAL "")
SET(HAVE_FPSETMASK CACHE INTERNAL "")
SET(HAVE_FPU_CONTROL_H CACHE INTERNAL "")
SET(HAVE_FSEEKO CACHE INTERNAL "")
SET(HAVE_FSYNC CACHE INTERNAL "")
SET(HAVE_FTIME 1 CACHE INTERNAL "")
SET(HAVE_FTRUNCATE CACHE INTERNAL "")
SET(HAVE_GETADDRINFO 1 CACHE INTERNAL "")
SET(HAVE_GETCWD 1 CACHE INTERNAL "")
SET(HAVE_GETHOSTBYADDR_R CACHE INTERNAL "")
SET(HAVE_GETHRTIME CACHE INTERNAL "")
SET(HAVE_GETLINE CACHE INTERNAL "")
SET(HAVE_GETNAMEINFO CACHE INTERNAL "")
SET(HAVE_GETPAGESIZE CACHE INTERNAL "")
SET(HAVE_GETPASS CACHE INTERNAL "")
SET(HAVE_GETPASSPHRASE CACHE INTERNAL "")
SET(HAVE_GETPWNAM CACHE INTERNAL "")
SET(HAVE_GETPWUID CACHE INTERNAL "")
SET(HAVE_GETRLIMIT CACHE INTERNAL "")
SET(HAVE_GETRUSAGE CACHE INTERNAL "")
SET(HAVE_GETTIMEOFDAY CACHE INTERNAL "")
SET(HAVE_GETWD CACHE INTERNAL "")
SET(HAVE_GRP_H CACHE INTERNAL "")
SET(HAVE_IA64INTRIN_H CACHE INTERNAL "")
SET(HAVE_IEEEFP_H CACHE INTERNAL "")
SET(HAVE_INDEX CACHE INTERNAL "")
SET(HAVE_INITGROUPS CACHE INTERNAL "")
SET(HAVE_INTTYPES_H CACHE INTERNAL "")
SET(HAVE_IPPROTO_IPV6 CACHE INTERNAL "")
SET(HAVE_IPV6 TRUE CACHE INTERNAL "")
SET(HAVE_IPV6_V6ONLY 1 CACHE INTERNAL "")
SET(HAVE_ISINF CACHE INTERNAL "")
SET(HAVE_ISSETUGID CACHE INTERNAL "")
SET(HAVE_GETUID CACHE INTERNAL "")
SET(HAVE_GETEUID CACHE INTERNAL "")
SET(HAVE_GETGID CACHE INTERNAL "")
SET(HAVE_GETEGID CACHE INTERNAL "")
SET(HAVE_LANGINFO_H CACHE INTERNAL "")
SET(HAVE_LDIV 1 CACHE INTERNAL "")
SET(HAVE_LIMITS_H 1 CACHE INTERNAL "")
SET(HAVE_LOCALE_H 1 CACHE INTERNAL "")
SET(HAVE_LOG2 CACHE INTERNAL "")
SET(HAVE_LONGJMP 1 CACHE INTERNAL "")
SET(HAVE_LRAND48 CACHE INTERNAL "")
SET(HAVE_LSTAT CACHE INTERNAL "")
SET(HAVE_MADVISE CACHE INTERNAL "")
SET(HAVE_MALLINFO CACHE INTERNAL "")
SET(HAVE_MALLOC_H 1 CACHE INTERNAL "")
SET(HAVE_MEMALIGN CACHE INTERNAL "")
SET(HAVE_MEMCPY 1 CACHE INTERNAL "")
SET(HAVE_MEMMOVE 1 CACHE INTERNAL "")
SET(HAVE_MEMORY_H 1 CACHE INTERNAL "")
SET(HAVE_MKSTEMP CACHE INTERNAL "")
SET(HAVE_MLOCK CACHE INTERNAL "")
SET(HAVE_MLOCKALL CACHE INTERNAL "")
SET(HAVE_MMAP CACHE INTERNAL "")
SET(HAVE_MMAP64 CACHE INTERNAL "")
SET(HAVE_NETDB_H CACHE INTERNAL "")
SET(HAVE_NETINET_IN6_H CACHE INTERNAL "")
SET(HAVE_NETINET_IN_H CACHE INTERNAL "")
SET(HAVE_NL_LANGINFO CACHE INTERNAL "")
SET(HAVE_PASE_ENVIRONMENT CACHE INTERNAL "")
SET(HAVE_PATHS_H CACHE INTERNAL "")
SET(HAVE_PCLOSE CACHE INTERNAL "")
SET(HAVE_PERROR 1 CACHE INTERNAL "")
SET(HAVE_PEERCRED CACHE INTERNAL "")
SET(HAVE_PAM_APPL_H CACHE INTERNAL "")
SET(HAVE_POLL_H CACHE INTERNAL "")
SET(HAVE_POPEN CACHE INTERNAL "")
SET(HAVE_POLL CACHE INTERNAL "")
SET(HAVE_PORT_CREATE CACHE INTERNAL "")
SET(HAVE_PORT_H CACHE INTERNAL "")
SET(HAVE_POSIX_FALLOCATE CACHE INTERNAL "")
SET(HAVE_POSIX_SIGNALS CACHE INTERNAL "")
SET(HAVE_PREAD CACHE INTERNAL "")
SET(HAVE_PRINTSTACK CACHE INTERNAL "")
SET(HAVE_PTHREAD_ATTR_CREATE CACHE INTERNAL "")
SET(HAVE_PTHREAD_ATTR_GETSTACKSIZE CACHE INTERNAL "")
SET(HAVE_PTHREAD_ATTR_SETSCOPE CACHE INTERNAL "")
SET(HAVE_PTHREAD_ATTR_SETSTACKSIZE CACHE INTERNAL "")
SET(HAVE_PTHREAD_CONDATTR_CREATE CACHE INTERNAL "")
SET(HAVE_PTHREAD_CONDATTR_SETCLOCK CACHE INTERNAL "")
SET(HAVE_PTHREAD_INIT CACHE INTERNAL "")
SET(HAVE_PTHREAD_KEY_DELETE CACHE INTERNAL "")
SET(HAVE_PTHREAD_RWLOCK_RDLOCK CACHE INTERNAL "")
SET(HAVE_PTHREAD_SIGMASK CACHE INTERNAL "")
SET(HAVE_PTHREAD_THREADMASK CACHE INTERNAL "")
SET(HAVE_PTHREAD_YIELD_NP CACHE INTERNAL "")
SET(HAVE_PTHREAD_YIELD_ZERO_ARG CACHE INTERNAL "")
SET(HAVE_PUTENV 1 CACHE INTERNAL "")
SET(HAVE_PWD_H CACHE INTERNAL "")
SET(HAVE_RDTSCLL CACHE INTERNAL "")
SET(HAVE_READDIR_R CACHE INTERNAL "")
SET(HAVE_READLINK CACHE INTERNAL "")
SET(HAVE_READ_REAL_TIME CACHE INTERNAL "")
SET(HAVE_REALPATH CACHE INTERNAL "")
SET(HAVE_REGCOMP CACHE INTERNAL "")
SET(HAVE_RENAME 1 CACHE INTERNAL "")
SET(HAVE_RE_COMP CACHE INTERNAL "")
SET(HAVE_RINT CACHE INTERNAL "")
SET(HAVE_RWLOCK_INIT CACHE INTERNAL "")
SET(HAVE_SCHED_H CACHE INTERNAL "")
SET(HAVE_SCHED_YIELD CACHE INTERNAL "")
SET(HAVE_SELECT 1 CACHE INTERNAL "")
SET(HAVE_SELECT_H CACHE INTERNAL "")
SET(HAVE_SEMAPHORE_H CACHE INTERNAL "")
SET(HAVE_SETENV CACHE INTERNAL "")
SET(HAVE_SETFD CACHE INTERNAL "")
SET(HAVE_SETLOCALE 1 CACHE INTERNAL "")
SET(HAVE_SHMAT CACHE INTERNAL "")
SET(HAVE_SHMCTL CACHE INTERNAL "")
SET(HAVE_SHMDT CACHE INTERNAL "")
SET(HAVE_SHMGET CACHE INTERNAL "")
SET(HAVE_SIGACTION CACHE INTERNAL "")
SET(HAVE_SIGADDSET CACHE INTERNAL "")
SET(HAVE_SIGEMPTYSET CACHE INTERNAL "")
SET(HAVE_SIGHOLD CACHE INTERNAL "")
SET(HAVE_SIGINT 1 CACHE INTERNAL "")
SET(HAVE_SIGPIPE CACHE INTERNAL "")
SET(HAVE_SIGQUIT CACHE INTERNAL "")
SET(HAVE_SIGSET CACHE INTERNAL "")
SET(HAVE_SIGTERM 1 CACHE INTERNAL "")
SET(HAVE_SIGTHREADMASK CACHE INTERNAL "")
SET(HAVE_SIGWAIT CACHE INTERNAL "")
SET(HAVE_SIZEOF_BOOL FALSE CACHE INTERNAL "")
SET(HAVE_SIZEOF_CHAR TRUE CACHE INTERNAL "")
SET(SIZEOF_CHAR 1 CACHE INTERNAL "")
SET(HAVE_SIZEOF_CHARP TRUE CACHE INTERNAL "")
SET(SIZEOF_CHARP ${CMAKE_SIZEOF_VOID_P} CACHE INTERNAL "")
SET(HAVE_SIZEOF_IN6_ADDR TRUE CACHE INTERNAL "")
SET(HAVE_SIZEOF_INT TRUE CACHE INTERNAL "")
SET(SIZEOF_INT 4 CACHE INTERNAL "")
SET(HAVE_SIZEOF_INT16 FALSE CACHE INTERNAL "")
SET(HAVE_SIZEOF_INT32 FALSE CACHE INTERNAL "")
SET(HAVE_SIZEOF_INT64 FALSE CACHE INTERNAL "")
SET(HAVE_SIZEOF_INT8 FALSE CACHE INTERNAL "")
SET(HAVE_SIZEOF_LONG TRUE CACHE INTERNAL "")
SET(SIZEOF_LONG 4 CACHE INTERNAL "")
SET(HAVE_SIZEOF_LONG_LONG TRUE CACHE INTERNAL "")
SET(SIZEOF_LONG_LONG 8 CACHE INTERNAL "")
SET(HAVE_SIZEOF_MODE_T FALSE CACHE INTERNAL "")
SET(HAVE_SIZEOF_OFF_T TRUE CACHE INTERNAL "")
SET(SIZEOF_OFF_T 4 CACHE INTERNAL "")
SET(HAVE_SIZEOF_SHORT TRUE CACHE INTERNAL "")
SET(SIZEOF_SHORT 2 CACHE INTERNAL "")
SET(HAVE_SIZEOF_SIGSET_T FALSE CACHE INTERNAL "")
SET(HAVE_SIZEOF_SIZE_T TRUE CACHE INTERNAL "")
SET(SIZEOF_SIZE_T ${CMAKE_SIZEOF_VOID_P} CACHE INTERNAL "")
SET(HAVE_SIZEOF_SOCKADDR_IN6 TRUE CACHE INTERNAL "")
SET(HAVE_SIZEOF_SOCKLEN_T FALSE CACHE INTERNAL "")
SET(HAVE_SIZEOF_UCHAR FALSE CACHE INTERNAL "")
SET(HAVE_SIZEOF_UINT FALSE CACHE INTERNAL "")
SET(HAVE_SIZEOF_UINT16 FALSE CACHE INTERNAL "")
SET(HAVE_SIZEOF_UINT32 FALSE CACHE INTERNAL "")
SET(HAVE_SIZEOF_UINT64 FALSE CACHE INTERNAL "")
SET(HAVE_SIZEOF_UINT8 FALSE CACHE INTERNAL "")
SET(HAVE_SIZEOF_ULONG FALSE CACHE INTERNAL "")
SET(HAVE_SIZEOF_U_INT32_T FALSE CACHE INTERNAL "")
SET(HAVE_SIZE_OF_SSIZE_T FALSE CACHE INTERNAL "")
SET(HAVE_SLEEP CACHE INTERNAL "")
SET(HAVE_SOCKADDR_STORAGE_SS_FAMILY 1 CACHE INTERNAL "")
SET(HAVE_SOLARIS_STYLE_GETHOST CACHE INTERNAL "")
SET(STACK_DIRECTION -1 CACHE INTERNAL "")
SET(HAVE_STDARG_H 1 CACHE INTERNAL "")
SET(HAVE_STDDEF_H 1 CACHE INTERNAL "")
SET(HAVE_STDINT_H CACHE INTERNAL "")
SET(HAVE_STDLIB_H 1 CACHE INTERNAL "")
SET(HAVE_STPCPY CACHE INTERNAL "")
SET(HAVE_STRCASECMP CACHE INTERNAL "")
SET(HAVE_STRCOLL 1 CACHE INTERNAL "")
SET(HAVE_STRDUP 1 CACHE INTERNAL "")
SET(HAVE_STRERROR 1 CACHE INTERNAL "")
SET(HAVE_STRINGS_H CACHE INTERNAL "")
SET(HAVE_STRING_H 1 CACHE INTERNAL "")
SET(HAVE_STRLCAT CACHE INTERNAL "")
SET(HAVE_STRLCPY CACHE INTERNAL "")
SET(HAVE_STRNCASECMP CACHE INTERNAL "")
SET(HAVE_STRNDUP CACHE INTERNAL "")
IF(MSVC_VERSION GREATER 1310)
SET(HAVE_STRNLEN 1 CACHE INTERNAL "")
ENDIF()
SET(HAVE_STRPBRK 1 CACHE INTERNAL "")
SET(HAVE_STRSEP CACHE INTERNAL "")
SET(HAVE_STRSIGNAL CACHE INTERNAL "")
SET(HAVE_STRSTR 1 CACHE INTERNAL "")
SET(HAVE_STRTOK_R CACHE INTERNAL "")
SET(HAVE_STRTOL 1 CACHE INTERNAL "")
SET(HAVE_STRTOLL CACHE INTERNAL "")
SET(HAVE_STRTOUL 1 CACHE INTERNAL "")
SET(HAVE_STRTOULL CACHE INTERNAL "")
SET(HAVE_SVR3_SIGNALS CACHE INTERNAL "")
SET(HAVE_SYNCH_H CACHE INTERNAL "")
SET(HAVE_SYSENT_H CACHE INTERNAL "")
SET(HAVE_SYS_CDEFS_H CACHE INTERNAL "")
SET(HAVE_SYS_DIR_H CACHE INTERNAL "")
SET(HAVE_SYS_ERRLIST CACHE INTERNAL "")
SET(HAVE_SYS_FILE_H CACHE INTERNAL "")
SET(HAVE_SYS_FPU_H CACHE INTERNAL "")
SET(HAVE_SYS_IOCTL_H CACHE INTERNAL "")
SET(HAVE_SYS_IPC_H CACHE INTERNAL "")
SET(HAVE_SYS_MALLOC_H CACHE INTERNAL "")
SET(HAVE_SYS_MMAN_H CACHE INTERNAL "")
SET(HAVE_SYS_PARAM_H CACHE INTERNAL "")
SET(HAVE_SYS_PRCTL_H CACHE INTERNAL "")
SET(HAVE_SYS_PTEM_H CACHE INTERNAL "")
SET(HAVE_SYS_PTE_H CACHE INTERNAL "")
SET(HAVE_SYS_RESOURCE_H CACHE INTERNAL "")
SET(HAVE_SYS_SELECT_H CACHE INTERNAL "")
SET(HAVE_SYS_SHM_H CACHE INTERNAL "")
SET(HAVE_SYS_SOCKIO_H CACHE INTERNAL "")
SET(HAVE_SYS_SOCKET_H CACHE INTERNAL "")
SET(HAVE_SYS_STAT_H 1 CACHE INTERNAL "")
SET(HAVE_SYS_STREAM_H CACHE INTERNAL "")
SET(HAVE_SYS_TERMCAP_H CACHE INTERNAL "")
SET(HAVE_SYS_TIMEB_H 1 CACHE INTERNAL "")
SET(HAVE_SYS_TIMES_H CACHE INTERNAL "")
SET(HAVE_SYS_TIME_H CACHE INTERNAL "")
SET(HAVE_SYS_TYPES_H 1 CACHE INTERNAL "")
SET(HAVE_SYS_UN_H CACHE INTERNAL "")
SET(HAVE_SYS_UTIME_H 1 CACHE INTERNAL "")
SET(HAVE_SYS_VADVISE_H CACHE INTERNAL "")
SET(HAVE_SYS_WAIT_H CACHE INTERNAL "")
SET(HAVE_TCGETATTR CACHE INTERNAL "")
SET(HAVE_TELL 1 CACHE INTERNAL "")
SET(HAVE_TEMPNAM 1 CACHE INTERNAL "")
SET(HAVE_TERMCAP_H CACHE INTERNAL "")
SET(HAVE_TERMIOS_H CACHE INTERNAL "")
SET(HAVE_TERMIO_H CACHE INTERNAL "")
SET(HAVE_TERM_H CACHE INTERNAL "")
SET(HAVE_THR_SETCONCURRENCY CACHE INTERNAL "")
SET(HAVE_THR_YIELD CACHE INTERNAL "")
SET(HAVE_TIME 1 CACHE INTERNAL "")
SET(HAVE_TIMES CACHE INTERNAL "")
SET(HAVE_TIMESPEC_TS_SEC CACHE INTERNAL "")
SET(HAVE_TIME_H 1 CACHE INTERNAL "")
SET(HAVE_TZNAME 1 CACHE INTERNAL "")
SET(HAVE_UNISTD_H CACHE INTERNAL "")
SET(HAVE_UTIME_H CACHE INTERNAL "")
SET(HAVE_VALLOC CACHE INTERNAL "")
SET(HAVE_VARARGS_H 1 CACHE INTERNAL "")
SET(HAVE_VASPRINTF CACHE INTERNAL "")
SET(HAVE_VPRINTF 1 CACHE INTERNAL "")
IF(MSVC_VERSION GREATER 1310)
SET(HAVE_VSNPRINTF 1 CACHE INTERNAL "")
ENDIF()
SET(HAVE_WEAK_SYMBOL CACHE INTERNAL "")
SET(HAVE_WORDS_BIGENDIAN TRUE CACHE INTERNAL "")
SET(WORDS_BIGENDIAN CACHE INTERNAL "")
SET(HAVE__S_IFIFO 1 CACHE INTERNAL "")
SET(HAVE__S_IREAD 1 CACHE INTERNAL "")
SET(HAVE__finite 1 CACHE INTERNAL "")
SET(HAVE__pclose 1 CACHE INTERNAL "")
SET(HAVE__popen 1 CACHE INTERNAL "")
SET(HAVE__stricmp 1 CACHE INTERNAL "")
SET(HAVE__strnicmp 1 CACHE INTERNAL "")
SET(HAVE__strtoi64 1 CACHE INTERNAL "")
SET(HAVE__strtoui64 1 CACHE INTERNAL "")
IF(MSVC_VERSION GREATER 1310)
SET(HAVE_strtok_s 1 CACHE INTERNAL "")
ENDIF()
SET(STDC_HEADERS CACHE 1 INTERNAL "")
SET(STRUCT_DIRENT_HAS_D_INO CACHE INTERNAL "")
SET(STRUCT_DIRENT_HAS_D_INO CACHE INTERNAL "")
SET(STRUCT_DIRENT_HAS_D_NAMLEN CACHE INTERNAL "")
SET(TIME_WITH_SYS_TIME CACHE INTERNAL "")
SET(TIME_T_UNSIGNED 1 CACHE INTERNAL "")
SET(TIOCSTAT_IN_SYS_IOCTL CACHE INTERNAL "")
SET(HAVE_S_IROTH CACHE INTERNAL "")
SET(HAVE_S_IFIFO CACHE INTERNAL "")
SET(QSORT_TYPE_IS_VOID 1 CACHE INTERNAL "")
SET(SIGNAL_RETURN_TYPE_IS_VOID 1 CACHE INTERNAL "")
SET(C_HAS_inline CACHE INTERNAL "")
SET(C_HAS___inline 1 CACHE INTERNAL "")
SET(FIONREAD_IN_SYS_IOCTL CACHE INTERNAL "")
SET(FIONREAD_IN_SYS_FILIO CACHE INTERNAL "")
SET(GWINSZ_IN_SYS_IOCTL CACHE INTERNAL "")
SET(HAVE_CXXABI_H CACHE INTERNAL "")
SET(HAVE_NDIR_H CACHE INTERNAL "")
SET(HAVE_SYS_NDIR_H CACHE INTERNAL "")
SET(HAVE_SYS_NDIR_H CACHE INTERNAL "")
SET(HAVE_ASM_TERMBITS_H CACHE INTERNAL "")
SET(HAVE_TERMBITS_H CACHE INTERNAL "")
SET(HAVE_VIS_H CACHE INTERNAL "")
SET(HAVE_WCHAR_H 1 CACHE INTERNAL "")
SET(HAVE_WCTYPE_H 1 CACHE INTERNAL "")
SET(HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP CACHE INTERNAL "")
SET(HAVE_SOCKADDR_IN_SIN_LEN CACHE INTERNAL "")
SET(HAVE_SOCKADDR_IN6_SIN6_LEN CACHE INTERNAL "")
SET(HAVE_VALGRIND CACHE INTERNAL "")
SET(HAVE_EVENT_H CACHE INTERNAL "")
SET(HAVE_LINUX_UNISTD_H CACHE INTERNAL "")
SET(HAVE_SYS_UTSNAME_H CACHE INTERNAL "")
SET(HAVE_PTHREAD_ATTR_GETGUARDSIZE CACHE INTERNAL "")
SET(FIONREAD_IN_SYS_FILIO CACHE INTERNAL "")
SET(FIONREAD_IN_SYS_IOCTL CACHE INTERNAL "")
SET(GWINSZ_IN_SYS_IOCTL CACHE INTERNAL "")
SET(HAVE_ACCESS 1 CACHE INTERNAL "")
SET(HAVE_AIOWAIT CACHE INTERNAL "")
SET(HAVE_AIO_H CACHE INTERNAL "")
SET(HAVE_AIO_READ CACHE INTERNAL "")
SET(HAVE_ALARM CACHE INTERNAL "")
SET(HAVE_ALLOCA CACHE INTERNAL "")
SET(HAVE_ALLOCA_H CACHE INTERNAL "")
SET(HAVE_ARPA_INET_H CACHE INTERNAL "")
SET(HAVE_ASM_MSR_H CACHE INTERNAL "")
SET(HAVE_ASM_TERMBITS_H CACHE INTERNAL "")
SET(HAVE_BACKTRACE CACHE INTERNAL "")
SET(HAVE_BACKTRACE_SYMBOLS CACHE INTERNAL "")
SET(HAVE_BACKTRACE_SYMBOLS_FD CACHE INTERNAL "")
SET(HAVE_BCMP CACHE INTERNAL "")
SET(HAVE_BFILL CACHE INTERNAL "")
SET(HAVE_BMOVE CACHE INTERNAL "")
SET(HAVE_BSD_SIGNALS CACHE INTERNAL "")
SET(HAVE_BSEARCH CACHE INTERNAL "")
SET(HAVE_BSS_START CACHE INTERNAL "")
SET(HAVE_BZERO CACHE INTERNAL "")
SET(HAVE_CHOWN CACHE INTERNAL "")
SET(HAVE_CLOCK_GETTIME CACHE INTERNAL "")
SET(HAVE_COMPRESS CACHE INTERNAL "")
SET(HAVE_CRYPT CACHE INTERNAL "")
SET(HAVE_CRYPT_H CACHE INTERNAL "")
SET(HAVE_CUSERID CACHE INTERNAL "")
SET(HAVE_CXXABI_H CACHE INTERNAL "")
SET(HAVE_DECL_FDATASYNC CACHE INTERNAL "")
SET(HAVE_SIGNAL_H 1 CACHE INTERNAL "")
SET(HAVE_GETHOSTBYNAME_R CACHE INTERNAL "")
SET(HAVE_PTHREAD_ATTR_SETPRIO CACHE INTERNAL "")
SET(HAVE_PTHREAD_ATTR_SETSCHEDPARAM CACHE INTERNAL "")
SET(HAVE_PTHREAD_KILL CACHE INTERNAL "")
SET(HAVE_PTHREAD_SETPRIO_NP CACHE INTERNAL "")
SET(HAVE_PTHREAD_SETSCHEDPARAM CACHE INTERNAL "")
SET(HAVE_SETFILEPOINTER CACHE INTERNAL "")
SET(SIZEOF_U_INT32_T CACHE INTERNAL "")
SET(IS_VOID_SIGNAL 1 CACHE INTERNAL "")
SET(IS_VOID_QSORT 1 CACHE INTERNAL "")
ENDIF()

30
vendor/MDBC/cmake/export.cmake vendored Normal file
View File

@ -0,0 +1,30 @@
#
# Copyright (C) 2013-2016 MariaDB Corporation AB
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the COPYING-CMAKE-SCRIPTS file.
#
MACRO(CREATE_EXPORT_FILE op outfile version symbols alias_version)
IF(WIN32)
SET(EXPORT_CONTENT "EXPORTS\n")
FOREACH(exp_symbol ${symbols})
SET(EXPORT_CONTENT ${EXPORT_CONTENT} "${exp_symbol}\n")
ENDFOREACH()
ELSE()
SET(EXPORT_CONTENT "VERSION {\n${version} {\nglobal:\n")
FOREACH(exp_symbol ${symbols})
SET(EXPORT_CONTENT "${EXPORT_CONTENT} ${exp_symbol}\\;\n")
ENDFOREACH()
SET(EXPORT_CONTENT "${EXPORT_CONTENT}local:\n *\\;\n}\\;\n")
IF ("${alias_version}" STRGREATER "")
SET(EXPORT_CONTENT "${EXPORT_CONTENT}${alias_version} {\n}\\;\n}\\;\n")
FOREACH(exp_symbol ${symbols})
SET(EXPORT_CONTENT "${EXPORT_CONTENT}\"${exp_symbol}@${alias_version}\" = ${exp_symbol}\\;\n")
ENDFOREACH()
ELSE()
SET(EXPORT_CONTENT "${EXPORT_CONTENT}}\\;\n")
ENDIF()
ENDIF()
FILE(${op} ${CMAKE_CURRENT_BINARY_DIR}/${outfile} ${EXPORT_CONTENT})
ENDMACRO()

160
vendor/MDBC/cmake/install.cmake vendored Normal file
View File

@ -0,0 +1,160 @@
#
# Copyright (C) 2013-2016 MariaDB Corporation AB
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the COPYING-CMAKE-SCRIPTS file.
#
#
# This file contains settings for the following layouts:
#
# - RPM
# Built with default prefix=/usr
#
#
# The following va+riables are used and can be overwritten
#
# INSTALL_LAYOUT installation layout (DEFAULT = standard for tar.gz and zip packages
# RPM packages
#
# INSTALL_BINDIR location of binaries (mariadb_config)
# INSTALL_LIBDIR location of libraries
# INSTALL_PLUGINDIR location of plugins
# INSTALL_MANDIR location of manpages
IF(NOT INSTALL_LAYOUT)
SET(INSTALL_LAYOUT "DEFAULT")
ENDIF()
SET(INSTALL_LAYOUT ${INSTALL_LAYOUT} CACHE
STRING "Installation layout. Currently supported options are DEFAULT (tar.gz and zip), RPM and DEB")
# On Windows we only provide zip and .msi. Latter one uses a different packager.
IF(UNIX)
IF(INSTALL_LAYOUT MATCHES "RPM")
SET(libmariadb_prefix "/usr")
ELSEIF(INSTALL_LAYOUT MATCHES "DEFAULT|DEB")
SET(libmariadb_prefix ${CMAKE_INSTALL_PREFIX})
ENDIF()
ENDIF()
IF(CMAKE_DEFAULT_PREFIX_INITIALIZED_BY_DEFAULT)
SET(CMAKE_DEFAULT_PREFIX ${libmariadb_prefix} CACHE PATH "Installation prefix" FORCE)
ENDIF()
# check if the specified installation layout is valid
SET(VALID_INSTALL_LAYOUTS "DEFAULT" "RPM" "DEB")
LIST(FIND VALID_INSTALL_LAYOUTS "${INSTALL_LAYOUT}" layout_no)
IF(layout_no EQUAL -1)
MESSAGE(FATAL_ERROR "Invalid installation layout ${INSTALL_LAYOUT}. Please specify one of the following layouts: ${VALID_INSTALL_LAYOUTS}")
ENDIF()
#
# Todo: We don't generate man pages yet, will fix it
# later (webhelp to man transformation)
#
#
# DEFAULT layout
#
SET(INSTALL_BINDIR_DEFAULT "bin")
SET(INSTALL_LIBDIR_DEFAULT "lib/mariadb")
SET(INSTALL_PCDIR_DEFAULT "lib/pkgconfig")
SET(INSTALL_INCLUDEDIR_DEFAULT "include/mariadb")
SET(INSTALL_DOCDIR_DEFAULT "docs")
SET(INSTALL_MANDIR_DEFAULT "man")
IF(NOT IS_SUBPROJECT)
SET(INSTALL_PLUGINDIR_DEFAULT "lib/mariadb/plugin")
ELSE()
ENDIF()
SET(LIBMARIADB_STATIC_DEFAULT "mariadbclient")
#
# RPM layout
#
SET(INSTALL_BINDIR_RPM "bin")
IF((CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le" OR CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "s390x") AND CMAKE_SIZEOF_VOID_P EQUAL 8)
SET(INSTALL_LIBDIR_RPM "lib64/mariadb")
SET(INSTALL_PCDIR_RPM "lib64/pkgconfig")
SET(INSTALL_PLUGINDIR_RPM "lib64/mariadb/plugin")
ELSE()
SET(INSTALL_LIBDIR_RPM "lib/mariadb")
SET(INSTALL_PCDIR_RPM "lib/pkgconfig")
SET(INSTALL_PLUGINDIR_RPM "lib/mariadb/plugin")
ENDIF()
SET(INSTALL_INCLUDEDIR_RPM "include")
SET(INSTALL_DOCDIR_RPM "docs")
SET(INSTALL_MANDIR_RPM "share/man")
SET(LIBMARIADB_STATIC_RPM "mariadbclient")
#
# DEB layout
#
SET(INSTALL_BINDIR_DEB "bin")
SET(INSTALL_LIBDIR_DEB "lib/${CMAKE_LIBRARY_ARCHITECTURE}")
SET(INSTALL_PCDIR_DEB "lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig")
SET(INSTALL_PLUGINDIR_DEB "${INSTALL_LIBDIR_DEB}/libmariadb${CPACK_PACKAGE_VERSION_MAJOR}/plugin")
SET(INSTALL_INCLUDEDIR_DEB "include/mariadb")
SET(INSTALL_MANDIR_DEB "share/man")
SET(LIBMARIADB_STATIC_DEB "mariadb")
IF(INSTALL_LAYOUT MATCHES "DEB")
SET(INSTALL_PLUGINDIR_CLIENT ${INSTALL_PLUGINDIR_DEB})
ENDIF()
#
# Overwrite defaults
#
IF(INSTALL_LIBDIR)
SET(INSTALL_LIBDIR_${INSTALL_LAYOUT} ${INSTALL_LIBDIR})
ENDIF()
IF(INSTALL_PCDIR)
SET(INSTALL_PCDIR_${INSTALL_LAYOUT} ${INSTALL_PCDIR})
ENDIF()
IF(INSTALL_PLUGINDIR)
SET(INSTALL_PLUGINDIR_${INSTALL_LAYOUT} ${INSTALL_PLUGINDIR})
ENDIF()
# Extra INSTALL_PLUGINDIR_CLIENT that overrides any INSTALL_PLUGINDIR override
IF(INSTALL_PLUGINDIR_CLIENT)
SET(INSTALL_PLUGINDIR_${INSTALL_LAYOUT} ${INSTALL_PLUGINDIR_CLIENT})
ENDIF()
IF(INSTALL_INCLUDEDIR)
SET(INSTALL_INCLUDEDIR_${INSTALL_LAYOUT} ${INSTALL_INCLUDEDIR})
ENDIF()
IF(INSTALL_BINDIR)
SET(INSTALL_BINDIR_${INSTALL_LAYOUT} ${INSTALL_BINDIR})
ENDIF()
IF(INSTALL_MANDIR)
SET(INSTALL_MANDIR_${INSTALL_LAYOUT} ${INSTALL_MANDIR})
ENDIF()
IF(NOT INSTALL_PREFIXDIR)
SET(INSTALL_PREFIXDIR_${INSTALL_LAYOUT} ${libmariadb_prefix})
ELSE()
SET(INSTALL_PREFIXDIR_${INSTALL_LAYOUT} ${INSTALL_PREFIXDIR})
ENDIF()
IF(DEFINED INSTALL_SUFFIXDIR)
SET(INSTALL_SUFFIXDIR_${INSTALL_LAYOUT} ${INSTALL_SUFFIXDIR})
ENDIF()
FOREACH(dir "BIN" "LIB" "PC" "INCLUDE" "DOCS" "PLUGIN" "MAN")
SET(INSTALL_${dir}DIR ${INSTALL_${dir}DIR_${INSTALL_LAYOUT}})
MARK_AS_ADVANCED(INSTALL_${dir}DIR)
MESSAGE1(INSTALL_${dir}DIR "MariaDB Connector C: INSTALL_${dir}DIR=${INSTALL_${dir}DIR}")
ENDFOREACH()
SET(LIBMARIADB_STATIC_NAME ${LIBMARIADB_STATIC_${INSTALL_LAYOUT}})
MARK_AS_ADVANCED(LIBMARIADB_STATIC_NAME)
MESSAGE1(LIBMARIADB_STATIC_NAME "MariaDB Connector C: LIBMARIADB_STATIC_NAME ${LIBMARIADB_STATIC_NAME}")

20
vendor/MDBC/cmake/install_plugins.cmake vendored Normal file
View File

@ -0,0 +1,20 @@
#
# Copyright (C) 2013-2016 MariaDB Corporation AB
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the COPYING-CMAKE-SCRIPTS file.
#
# plugin installation
MACRO(INSTALL_PLUGIN name binary_dir)
#INSTALL(TARGETS ${name} COMPONENT ClientPlugins DESTINATION ${INSTALL_PLUGINDIR})
IF(MSVC)
INSTALL(FILES $<TARGET_PDB_FILE:${name}> COMPONENT Debuginfo
DESTINATION symbols CONFIGURATIONS Debug RelWithDebInfo)
ENDIF()
IF(WIN32)
FILE(APPEND ${CC_BINARY_DIR}/win/packaging/plugin.conf "<File Id=\"${name}.dll\" Name=\"${name}.dll\" DiskId=\"1\" Source=\"${binary_dir}/${CMAKE_BUILD_TYPE}/${name}.dll\"/>\n")
FILE(APPEND ${CC_BINARY_DIR}/win/packaging/plugin.conf "<File Id=\"${name}.pdb\" Name=\"${name}.pdb\" DiskId=\"1\" Source=\"${binary_dir}/${CMAKE_BUILD_TYPE}/${name}.pdb\"/>\n")
ENDIF()
ENDMACRO()

7
vendor/MDBC/cmake/libressl_version.c vendored Normal file
View File

@ -0,0 +1,7 @@
#include <openssl/opensslv.h>
#include <stdio.h>
int main()
{
printf("%s", LIBRESSL_VERSION_TEXT);
}

View File

@ -0,0 +1,18 @@
#
# Copyright (C) 2013-2016 MariaDB Corporation AB
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the COPYING-CMAKE-SCRIPTS file.
#
# toolchain file for building a 32bit version on a 64bit host
# Usage:
# cmake -DCMAKE_TOOLCHAIN_FILE=linux_86.toolchain.cmake
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR "i686")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32" CACHE STRING "c++ flags")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32" CACHE STRING "c flags")

13
vendor/MDBC/cmake/misc.cmake vendored Normal file
View File

@ -0,0 +1,13 @@
IF ("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_LESS "2.8.7")
FUNCTION(MESSAGE1 id out)
MESSAGE(STATUS "${out}")
ENDFUNCTION()
ELSE()
FUNCTION(MESSAGE1 id out)
STRING(MD5 hash "${out}")
IF(NOT __msg1_${id} STREQUAL "${hash}")
MESSAGE(STATUS "${out}")
ENDIF()
SET(__msg1_${id} ${hash} CACHE INTERNAL "")
ENDFUNCTION()
ENDIF()

94
vendor/MDBC/cmake/plugins.cmake vendored Normal file
View File

@ -0,0 +1,94 @@
#
# Copyright (C) 2013-2018 MariaDB Corporation AB
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the COPYING-CMAKE-SCRIPTS file.
#
# plugin configuration
include(${CC_SOURCE_DIR}/cmake/install_plugins.cmake)
include(${CC_SOURCE_DIR}/cmake/sign.cmake)
FUNCTION(REGISTER_PLUGIN)
SET(one_value_keywords TARGET DEFAULT TYPE)
SET(multi_value_keywords CONFIGURATIONS SOURCES LIBRARIES INCLUDES COMPILE_OPTIONS)
cmake_parse_arguments(CC_PLUGIN
"${options}"
"${one_value_keywords}"
"${multi_value_keywords}"
${ARGN})
# overwrite default if it was specified with cmake option
string(TOUPPER ${CC_PLUGIN_TARGET} cc_plugin)
if(NOT "${CLIENT_PLUGIN_${cc_plugin}}" STREQUAL "")
SET(CC_PLUGIN_DEFAULT ${CLIENT_PLUGIN_${cc_plugin}})
endif()
# use uppercase
string(TOUPPER ${CC_PLUGIN_TARGET} target_name)
string(TOUPPER "${CC_PLUGIN_CONFIGURATIONS}" CC_PLUGIN_CONFIGURATIONS)
if(NOT ${PLUGIN_${target_name}} STREQUAL "")
string(TOUPPER ${PLUGIN_${target_name}} PLUGIN_${target_name})
set(CC_PLUGIN_DEFAULT ${PLUGIN_${target_name}})
endif()
# check if default value is valid
string(TOUPPER ${CC_PLUGIN_DEFAULT} CC_PLUGIN_DEFAULT)
list(FIND CC_PLUGIN_CONFIGURATIONS ${CC_PLUGIN_DEFAULT} configuration_found)
if(${configuration_found} EQUAL -1)
message(FATAL_ERROR "Invalid plugin type ${CC_PLUGIN_DEFAULT}. Allowed plugin types are ${CC_PLUGIN_CONFIGURATIONS}")
endif()
if(NOT ${CC_PLUGIN_DEFAULT} STREQUAL "OFF")
set(PLUGIN_${CC_PLUGIN_TARGET}_TYPE ${CC_PLUGIN_TYPE})
if(${CC_PLUGIN_DEFAULT} STREQUAL "DYNAMIC")
set(PLUGINS_DYNAMIC ${PLUGINS_DYNAMIC} ${CC_PLUGIN_TARGET} PARENT_SCOPE)
if(WIN32)
set(target ${CC_PLUGIN_TARGET})
set(FILE_TYPE "VFT_DLL")
set(FILE_DESCRIPTION "MariaDB client plugin")
set(FILE_VERSION ${CPACK_PACKAGE_VERSION})
set(ORIGINAL_FILE_NAME "${target}.dll")
configure_file(${CC_SOURCE_DIR}/win/resource.rc.in
${CC_BINARY_DIR}/win/${target}.rc
@ONLY)
set(CC_PLUGIN_SOURCES ${CC_PLUGIN_SOURCES} ${CC_BINARY_DIR}/win/${target}.rc ${CC_SOURCE_DIR}/plugins/plugin.def)
endif()
add_library(${CC_PLUGIN_TARGET} MODULE ${CC_PLUGIN_SOURCES})
target_link_libraries(${CC_PLUGIN_TARGET} ${CC_PLUGIN_LIBRARIES})
set_target_properties(${CC_PLUGIN_TARGET} PROPERTIES PREFIX "")
set_target_properties(${CC_PLUGIN_TARGET}
PROPERTIES COMPILE_FLAGS
"-DPLUGIN_DYNAMIC=1 ${CC_PLUGIN_COMPILE_OPTIONS}")
if (NOT "${CC_PLUGIN_INCLUDES}" STREQUAL "")
if(CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories(${CC_PLUGIN_INCLUDES})
else()
target_include_directories(${CC_PLUGIN_TARGET} PRIVATE ${CC_PLUGIN_INCLUDES})
endif()
endif()
if (${CC_TARGET_COMPILE_OPTIONS})
target_compile_options(${CC_PLUGIN_TARGET} ${CC_TARGET_COMPILE_OPTIONS})
endif()
if(WIN32)
SIGN_TARGET(${target})
endif()
INSTALL_PLUGIN(${CC_PLUGIN_TARGET} ${CMAKE_CURRENT_BINARY_DIR})
elseif(${CC_PLUGIN_DEFAULT} STREQUAL "STATIC")
set(PLUGINS_STATIC ${PLUGINS_STATIC} ${CC_PLUGIN_TARGET} PARENT_SCOPE)
set(LIBMARIADB_PLUGIN_CFLAGS ${LIBMARIADB_PLUGIN_CFLAGS} ${CC_PLUGIN_COMPILE_OPTIONS} PARENT_SCOPE)
set(LIBMARIADB_PLUGIN_INCLUDES ${LIBMARIADB_PLUGIN_INCLUDES} ${CC_PLUGIN_INCLUDES} PARENT_SCOPE)
set(LIBMARIADB_PLUGIN_SOURCES ${LIBMARIADB_PLUGIN_SOURCES} ${CC_PLUGIN_SOURCES} PARENT_SCOPE)
set(LIBMARIADB_PLUGIN_LIBS ${LIBMARIADB_PLUGIN_LIBS} ${CC_PLUGIN_LIBRARIES} PARENT_SCOPE)
endif()
else()
set(PLUGINS_OFF ${PLUGINS_OFF} ${CC_PLUGIN_TARGET})
endif()
endfunction()

20
vendor/MDBC/cmake/sign.cmake vendored Normal file
View File

@ -0,0 +1,20 @@
#
# Copyright (C) 2013-2016 MariaDB Corporation AB
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the COPYING-CMAKE-SCRIPTS file.
#
IF(COMMAND SIGN_TARGET)
# Do not override server's SIGN_TARGET macro
RETURN()
ENDIF()
MACRO(SIGN_TARGET target)
IF(WITH_SIGNCODE)
IF(WIN32)
SET(target_file $<TARGET_FILE:${target}>)
ADD_CUSTOM_COMMAND(TARGET ${target} COMMAND signtool ARGS sign ${SIGN_OPTIONS} ${target_file})
ENDIF()
ENDIF()
ENDMACRO()

35
vendor/MDBC/cmake/symlink.cmake vendored Normal file
View File

@ -0,0 +1,35 @@
#
# Copyright (C) 2013-2016 MariaDB Corporation AB
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the COPYING-CMAKE-SCRIPTS file.
#
MACRO(create_symlink symlink_name target install_path)
# According to cmake documentation symlinks work on unix systems only
IF(UNIX)
# Get target components
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${symlink_name}
COMMAND ${CMAKE_COMMAND} ARGS -E remove -f ${symlink_name}
COMMAND ${CMAKE_COMMAND} ARGS -E create_symlink $<TARGET_FILE_NAME:${target}> ${symlink_name}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${target}
)
ADD_CUSTOM_TARGET(SYM_${symlink_name}
ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${symlink_name})
SET_TARGET_PROPERTIES(SYM_${symlink_name} PROPERTIES CLEAN_DIRECT_OUTPUT 1)
IF(CMAKE_GENERATOR MATCHES "Xcode")
# For Xcode, replace project config with install config
STRING(REPLACE "${CMAKE_CFG_INTDIR}"
"\${CMAKE_INSTALL_CONFIG_NAME}" output ${CMAKE_CURRENT_BINARY_DIR}/${symlink_name})
ENDIF()
# presumably this will be used for libmysql*.so symlinks
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${symlink_name} DESTINATION ${install_path}
COMPONENT Development)
ENDIF()
ENDMACRO()

44
vendor/MDBC/cmake/version_info.cmake vendored Normal file
View File

@ -0,0 +1,44 @@
#
# Copyright (C) 2013-2016 MariaDB Corporation AB
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the COPYING-CMAKE-SCRIPTS file.
#
FUNCTION(GET_FILE_VERSION FILE_NAME FILE_VERSION)
# if we build from a git repository, we calculate the file version:
# Patch number is number of commits for given file
IF(GIT_EXECUTABLE AND EXISTS ${CC_SOURCE_DIR}/.git)
EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} --git-dir=${CC_SOURCE_DIR}/.git --work-tree=${CC_SOURCE_DIR} rev-list HEAD --count -- ${FILE_NAME}
OUTPUT_VARIABLE FV)
STRING(REPLACE "\n" "" FV ${FV})
SET(${FILE_VERSION} ${FV} PARENT_SCOPE)
ELSE()
SET(${FILE_VERSION} 0)
ENDIF()
ENDFUNCTION()
MACRO(SET_VERSION_INFO)
SET(FILE_VERSION "0")
FOREACH(PROPERTY ${ARGN})
IF(${PROPERTY} MATCHES "TARGET:")
STRING(REGEX REPLACE "^[TARGET:\\s]" "" TARGET ${PROPERTY})
ELSEIF(${PROPERTY} MATCHES "FILE_TYPE:")
STRING(REGEX REPLACE "^[FILE_TYPE:\\s]" "" FILE_TYPE ${PROPERTY})
ELSEIF(${PROPERTY} MATCHES "ORIGINAL_FILE_NAME:")
STRING(REGEX REPLACE "^[ORIGINAL_FILE_NAME:\\s]" "" ORIGINAL_FILE_NAME ${PROPERTY})
ELSEIF(${PROPERTY} MATCHES "SOURCE_FILE:")
STRING(REGEX REPLACE "^[SOURCE_FILE:\\s]" "" SOURCE ${PROPERTY})
GET_FILE_VERSION(${SOURCE} FILE_VERSION)
ELSEIF(${PROPERTY} MATCHES "FILE_DESCRIPTION:")
STRING(REPLACE "FILE_DESCRIPTION:" "" FILE_DESCRIPTION ${PROPERTY})
ENDIF()
ENDFOREACH()
CONFIGURE_FILE(${CC_SOURCE_DIR}/win/resource.rc.in
${CC_BINARY_DIR}/win/${TARGET}.rc)
SET(${TARGET}_RC ${CC_BINARY_DIR}/win/${TARGET}.rc)
ENDMACRO()

41
vendor/MDBC/include/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,41 @@
SET(MARIADB_CLIENT_INCLUDES ${CC_SOURCE_DIR}/include/mariadb_com.h
${CC_SOURCE_DIR}/include/mysql.h
${CC_SOURCE_DIR}/include/mariadb_stmt.h
${CC_SOURCE_DIR}/include/ma_pvio.h
${CC_SOURCE_DIR}/include/ma_tls.h
${CC_BINARY_DIR}/include/mariadb_version.h
${CC_SOURCE_DIR}/include/ma_list.h
${CC_SOURCE_DIR}/include/errmsg.h
${CC_SOURCE_DIR}/include/mariadb_dyncol.h
${CC_SOURCE_DIR}/include/mariadb_ctype.h
${CC_SOURCE_DIR}/include/mariadb_rpl.h
)
IF(NOT IS_SUBPROJECT)
SET(MARIADB_CLIENT_INCLUDES ${MARIADB_CLIENT_INCLUDES}
${CC_SOURCE_DIR}/include/mysqld_error.h
)
ENDIF()
SET(MYSQL_ADDITIONAL_INCLUDES
${CC_SOURCE_DIR}/include/mysql/client_plugin.h
${CC_SOURCE_DIR}/include/mysql/plugin_auth_common.h
${CC_SOURCE_DIR}/include/mysql/plugin_auth.h
)
SET(MARIADB_ADDITIONAL_INCLUDES
${CC_SOURCE_DIR}/include/mariadb/ma_io.h
)
IF(WIN32)
SET(WIX_INCLUDES ${MARIADB_CLIENT_INCLUDES} ${MARIADB_ADDITIONAL_INCLUDES} ${MYSQL_ADDITIONAL_INCLUDES} PARENT_SCOPE)
ENDIF()
INSTALL(FILES
${MARIADB_CLIENT_INCLUDES}
DESTINATION ${INSTALL_INCLUDEDIR}
COMPONENT Development)
INSTALL(FILES
${MYSQL_ADDITIONAL_INCLUDES}
DESTINATION ${INSTALL_INCLUDEDIR}/mysql
COMPONENT Development)
INSTALL(FILES
${MARIADB_ADDITIONAL_INCLUDES}
DESTINATION ${INSTALL_INCLUDEDIR}/mariadb
COMPONENT Development)

107
vendor/MDBC/include/errmsg.h vendored Normal file
View File

@ -0,0 +1,107 @@
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
2012-2016 SkySQL AB, MariaDB Corporation 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
/* Error messages for mysql clients */
/* error messages for the demon is in share/language/errmsg.sys */
#ifndef _errmsg_h_
#define _errmsg_h_
#ifdef __cplusplus
extern "C" {
#endif
void init_client_errs(void);
extern const char *client_errors[]; /* Error messages */
extern const char *mariadb_client_errors[]; /* Error messages */
#ifdef __cplusplus
}
#endif
#define CR_MIN_ERROR 2000 /* For easier client code */
#define CR_MAX_ERROR 2999
#define CER_MIN_ERROR 5000
#define CER_MAX_ERROR 5999
#define CER(X) mariadb_client_errors[(X)-CER_MIN_ERROR]
#define ER(X) client_errors[(X)-CR_MIN_ERROR]
#define CLIENT_ERRMAP 2 /* Errormap used by ma_error() */
#define CR_UNKNOWN_ERROR 2000
#define CR_SOCKET_CREATE_ERROR 2001
#define CR_CONNECTION_ERROR 2002
#define CR_CONN_HOST_ERROR 2003 /* never sent to a client, message only */
#define CR_IPSOCK_ERROR 2004
#define CR_UNKNOWN_HOST 2005
#define CR_SERVER_GONE_ERROR 2006 /* disappeared _between_ queries */
#define CR_VERSION_ERROR 2007
#define CR_OUT_OF_MEMORY 2008
#define CR_WRONG_HOST_INFO 2009
#define CR_LOCALHOST_CONNECTION 2010
#define CR_TCP_CONNECTION 2011
#define CR_SERVER_HANDSHAKE_ERR 2012
#define CR_SERVER_LOST 2013 /* disappeared _during_ a query */
#define CR_COMMANDS_OUT_OF_SYNC 2014
#define CR_NAMEDPIPE_CONNECTION 2015
#define CR_NAMEDPIPEWAIT_ERROR 2016
#define CR_NAMEDPIPEOPEN_ERROR 2017
#define CR_NAMEDPIPESETSTATE_ERROR 2018
#define CR_CANT_READ_CHARSET 2019
#define CR_NET_PACKET_TOO_LARGE 2020
#define CR_SSL_CONNECTION_ERROR 2026
#define CR_MALFORMED_PACKET 2027
#define CR_NO_PREPARE_STMT 2030
#define CR_PARAMS_NOT_BOUND 2031
#define CR_INVALID_PARAMETER_NO 2034
#define CR_INVALID_BUFFER_USE 2035
#define CR_UNSUPPORTED_PARAM_TYPE 2036
#define CR_SHARED_MEMORY_CONNECTION 2037
#define CR_SHARED_MEMORY_CONNECT_ERROR 2038
#define CR_CONN_UNKNOWN_PROTOCOL 2047
#define CR_SECURE_AUTH 2049
#define CR_NO_DATA 2051
#define CR_NO_STMT_METADATA 2052
#define CR_NOT_IMPLEMENTED 2054
#define CR_SERVER_LOST_EXTENDED 2055 /* never sent to a client, message only */
#define CR_STMT_CLOSED 2056
#define CR_NEW_STMT_METADATA 2057
#define CR_ALREADY_CONNECTED 2058
#define CR_AUTH_PLUGIN_CANNOT_LOAD 2059
#define CR_DUPLICATE_CONNECTION_ATTR 2060
#define CR_AUTH_PLUGIN_ERR 2061
/* Always last, if you add new error codes please update the
value for CR_MYSQL_LAST_ERROR */
#define CR_MYSQL_LAST_ERROR CR_AUTH_PLUGIN_ERR
/*
* MariaDB Connector/C errors:
*/
#define CR_EVENT_CREATE_FAILED 5000
#define CR_BIND_ADDR_FAILED 5001
#define CR_ASYNC_NOT_SUPPORTED 5002
#define CR_FUNCTION_NOT_SUPPORTED 5003
#define CR_FILE_NOT_FOUND 5004
#define CR_FILE_READ 5005
#define CR_BULK_WITHOUT_PARAMETERS 5006
#define CR_INVALID_STMT 5007
#define CR_VERSION_MISMATCH 5008
/* Always last, if you add new error codes please update the
value for CR_MARIADB_LAST_ERROR */
#define CR_MARIADB_LAST_ERROR CR_VERSION_MISMATCH
#endif

122
vendor/MDBC/include/ma_common.h vendored Normal file
View File

@ -0,0 +1,122 @@
/* Copyright (C) 2013 by MontyProgram 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
/* defines for the libmariadb library */
#ifndef _ma_common_h
#define _ma_common_h
#include <mysql.h>
#include <ma_hashtbl.h>
enum enum_multi_status {
COM_MULTI_OFF= 0,
COM_MULTI_CANCEL,
COM_MULTI_ENABLED,
COM_MULTI_DISABLED,
COM_MULTI_END
};
typedef enum {
ALWAYS_ACCEPT, /* heuristics is disabled, use CLIENT_LOCAL_FILES */
WAIT_FOR_QUERY, /* heuristics is enabled, not sending files */
ACCEPT_FILE_REQUEST /* heuristics is enabled, ready to send a file */
} auto_local_infile_state;
typedef struct st_mariadb_db_driver
{
struct st_mariadb_client_plugin_DB *plugin;
char *name;
void *buffer;
} MARIADB_DB_DRIVER;
struct mysql_async_context;
struct st_mysql_options_extension {
char *plugin_dir;
char *default_auth;
char *ssl_crl;
char *ssl_crlpath;
char *server_public_key_path;
struct mysql_async_context *async_context;
MA_HASHTBL connect_attrs;
size_t connect_attrs_len;
void (*report_progress)(const MYSQL *mysql,
unsigned int stage,
unsigned int max_stage,
double progress,
const char *proc_info,
unsigned int proc_info_length);
MARIADB_DB_DRIVER *db_driver;
char *tls_fp; /* finger print of server certificate */
char *tls_fp_list; /* white list of finger prints */
char *tls_pw; /* password for encrypted certificates */
my_bool multi_command; /* indicates if client wants to send multiple
commands in one packet */
char *url; /* for connection handler we need to save URL for reconnect */
unsigned int tls_cipher_strength;
char *tls_version;
my_bool read_only;
char *connection_handler;
my_bool (*set_option)(MYSQL *mysql, const char *config_option, const char *config_value);
MA_HASHTBL userdata;
char *server_public_key;
char *proxy_header;
size_t proxy_header_len;
int (*io_wait)(my_socket handle, my_bool is_read, int timeout);
my_bool skip_read_response;
};
typedef struct st_connection_handler
{
struct st_ma_connection_plugin *plugin;
void *data;
my_bool active;
my_bool free_data;
} MA_CONNECTION_HANDLER;
struct st_mariadb_net_extension {
enum enum_multi_status multi_status;
int extended_errno;
};
struct st_mariadb_session_state
{
LIST *list,
*current;
};
struct st_mariadb_extension {
MA_CONNECTION_HANDLER *conn_hdlr;
struct st_mariadb_session_state session_state[SESSION_TRACK_TYPES];
unsigned long mariadb_client_flag; /* MariaDB specific client flags */
unsigned long mariadb_server_capabilities; /* MariaDB specific server capabilities */
my_bool auto_local_infile;
};
#define OPT_EXT_VAL(a,key) \
(((a)->options.extension && (a)->options.extension->key) ?\
(a)->options.extension->key : 0)
#endif
typedef struct st_mariadb_field_extension
{
MARIADB_CONST_STRING metadata[MARIADB_FIELD_ATTR_LAST+1]; /* 10.5 */
} MA_FIELD_EXTENSION;

145
vendor/MDBC/include/ma_config.h.in vendored Normal file
View File

@ -0,0 +1,145 @@
/*
* Include file constants (processed in LibmysqlIncludeFiles.txt 1
*/
#cmakedefine HAVE_OPENSSL_APPLINK_C 1
#cmakedefine HAVE_ALLOCA_H 1
#cmakedefine HAVE_BIGENDIAN 1
#cmakedefine HAVE_SETLOCALE 1
#cmakedefine HAVE_NL_LANGINFO 1
#cmakedefine HAVE_DLFCN_H 1
#cmakedefine HAVE_FCNTL_H 1
#cmakedefine HAVE_FLOAT_H 1
#cmakedefine HAVE_LIMITS_H 1
#cmakedefine HAVE_LINUX_LIMITS_H 1
#cmakedefine HAVE_PWD_H 1
#cmakedefine HAVE_SELECT_H 1
#cmakedefine HAVE_STDDEF_H 1
#cmakedefine HAVE_STDINT_H 1
#cmakedefine HAVE_STDLIB_H 1
#cmakedefine HAVE_STRING_H 1
#cmakedefine HAVE_SYS_IOCTL_H 1
#cmakedefine HAVE_SYS_SELECT_H 1
#cmakedefine HAVE_SYS_SOCKET_H 1
#cmakedefine HAVE_SYS_STREAM_H 1
#cmakedefine HAVE_SYS_STAT_H 1
#cmakedefine HAVE_SYS_SYSCTL_H 1
#cmakedefine HAVE_SYS_TYPES_H 1
#cmakedefine HAVE_SYS_UN_H 1
#cmakedefine HAVE_UNISTD_H 1
#cmakedefine HAVE_UCONTEXT_H 1
/*
* function definitions - processed in LibmysqlFunctions.txt
*/
#cmakedefine HAVE_DLERROR 1
#cmakedefine HAVE_DLOPEN 1
#cmakedefine HAVE_GETPWUID 1
#cmakedefine HAVE_MEMCPY 1
#cmakedefine HAVE_POLL 1
#cmakedefine HAVE_STRTOK_R 1
#cmakedefine HAVE_STRTOL 1
#cmakedefine HAVE_STRTOLL 1
#cmakedefine HAVE_STRTOUL 1
#cmakedefine HAVE_STRTOULL 1
#cmakedefine HAVE_TELL 1
#cmakedefine HAVE_THR_SETCONCURRENCY 1
#cmakedefine HAVE_THR_YIELD 1
#cmakedefine HAVE_VASPRINTF 1
#cmakedefine HAVE_VSNPRINTF 1
#cmakedefine HAVE_CUSERID 1
/*
* types and sizes
*/
#cmakedefine SIZEOF_CHARP @SIZEOF_CHARP@
#if defined(SIZEOF_CHARP)
# define HAVE_CHARP 1
#endif
#cmakedefine SIZEOF_INT @SIZEOF_INT@
#if defined(SIZEOF_INT)
# define HAVE_INT 1
#endif
#cmakedefine SIZEOF_LONG @SIZEOF_LONG@
#if defined(SIZEOF_LONG)
# define HAVE_LONG 1
#endif
#cmakedefine SIZEOF_LONG_LONG @SIZEOF_LONG_LONG@
#if defined(SIZEOF_LONG_LONG)
# define HAVE_LONG_LONG 1
#endif
#cmakedefine SIZEOF_SIZE_T @SIZEOF_SIZE_T@
#if defined(SIZEOF_SIZE_T)
# define HAVE_SIZE_T 1
#endif
#cmakedefine SIZEOF_UINT @SIZEOF_UINT@
#if defined(SIZEOF_UINT)
# define HAVE_UINT 1
#endif
#cmakedefine SIZEOF_ULONG @SIZEOF_ULONG@
#if defined(SIZEOF_ULONG)
# define HAVE_ULONG 1
#endif
#cmakedefine SIZEOF_INT8 @SIZEOF_INT8@
#if defined(SIZEOF_INT8)
# define HAVE_INT8 1
#endif
#cmakedefine SIZEOF_UINT8 @SIZEOF_UINT8@
#if defined(SIZEOF_UINT8)
# define HAVE_UINT8 1
#endif
#cmakedefine SIZEOF_INT16 @SIZEOF_INT16@
#if defined(SIZEOF_INT16)
# define HAVE_INT16 1
#endif
#cmakedefine SIZEOF_UINT16 @SIZEOF_UINT16@
#if defined(SIZEOF_UINT16)
# define HAVE_UINT16 1
#endif
#cmakedefine SIZEOF_INT32 @SIZEOF_INT32@
#if defined(SIZEOF_INT32)
# define HAVE_INT32 1
#endif
#cmakedefine SIZEOF_UINT32 @SIZEOF_UINT32@
#if defined(SIZEOF_UINT32)
# define HAVE_UINT32 1
#endif
#cmakedefine SIZEOF_INT64 @SIZEOF_INT64@
#if defined(SIZEOF_INT64)
# define HAVE_INT64 1
#endif
#cmakedefine SIZEOF_UINT64 @SIZEOF_UINT64@
#if defined(SIZEOF_UINT64)
# define HAVE_UINT64 1
#endif
#cmakedefine SIZEOF_SOCKLEN_T @SIZEOF_SOCKLEN_T@
#if defined(SIZEOF_SOCKLEN_T)
# define HAVE_SOCKLEN_T 1
#endif
#cmakedefine SOCKET_SIZE_TYPE @SOCKET_SIZE_TYPE@
#define LOCAL_INFILE_MODE_OFF 0
#define LOCAL_INFILE_MODE_ON 1
#define LOCAL_INFILE_MODE_AUTO 2
#define ENABLED_LOCAL_INFILE LOCAL_INFILE_MODE_@ENABLED_LOCAL_INFILE@
#define MARIADB_DEFAULT_CHARSET "@DEFAULT_CHARSET@"

236
vendor/MDBC/include/ma_context.h vendored Normal file
View File

@ -0,0 +1,236 @@
/*
Copyright 2011 Kristian Nielsen and Monty Program Ab
This file is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
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
Lesser General Public License for more details.
You should have received a copy of the GNU General Public License
along with this. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Simple API for spawning a co-routine, to be used for async libmysqlclient.
Idea is that by implementing this interface using whatever facilities are
available for given platform, we can use the same code for the generic
libmysqlclient-async code.
(This particular implementation uses Posix ucontext swapcontext().)
*/
#ifdef _WIN32
#define MY_CONTEXT_USE_WIN32_FIBERS 1
#elif defined(__GNUC__) && __GNUC__ >= 3 && defined(__x86_64__) && !defined(__ILP32__)
#define MY_CONTEXT_USE_X86_64_GCC_ASM
#elif defined(__GNUC__) && __GNUC__ >= 3 && defined(__i386__)
#define MY_CONTEXT_USE_I386_GCC_ASM
#elif defined(HAVE_UCONTEXT_H)
#define MY_CONTEXT_USE_UCONTEXT
#else
#define MY_CONTEXT_DISABLE
#endif
#ifdef MY_CONTEXT_USE_WIN32_FIBERS
struct my_context {
void (*user_func)(void *);
void *user_arg;
void *app_fiber;
void *lib_fiber;
int return_value;
#ifndef DBUG_OFF
void *dbug_state;
#endif
};
#endif
#ifdef MY_CONTEXT_USE_UCONTEXT
#if defined(__APPLE__) && !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE 600
#endif
#include <ucontext.h>
struct my_context {
void (*user_func)(void *);
void *user_data;
void *stack;
size_t stack_size;
ucontext_t base_context;
ucontext_t spawned_context;
int active;
#ifdef HAVE_VALGRIND
unsigned int valgrind_stack_id;
#endif
#ifndef DBUG_OFF
void *dbug_state;
#endif
};
#endif
#ifdef MY_CONTEXT_USE_X86_64_GCC_ASM
#include <stdint.h>
struct my_context {
uint64_t save[9];
void *stack_top;
void *stack_bot;
#ifdef HAVE_VALGRIND
unsigned int valgrind_stack_id;
#endif
#ifndef DBUG_OFF
void *dbug_state;
#endif
};
#endif
#ifdef MY_CONTEXT_USE_I386_GCC_ASM
#include <stdint.h>
struct my_context {
uint64_t save[7];
void *stack_top;
void *stack_bot;
#ifdef HAVE_VALGRIND
unsigned int valgrind_stack_id;
#endif
#ifndef DBUG_OFF
void *dbug_state;
#endif
};
#endif
#ifdef MY_CONTEXT_DISABLE
struct my_context {
int dummy;
};
#endif
/*
Initialize an asynchroneous context object.
Returns 0 on success, non-zero on failure.
*/
extern int my_context_init(struct my_context *c, size_t stack_size);
/* Free an asynchroneous context object, deallocating any resources used. */
extern void my_context_destroy(struct my_context *c);
/*
Spawn an asynchroneous context. The context will run the supplied user
function, passing the supplied user data pointer.
The context must have been initialised with my_context_init() prior to
this call.
The user function may call my_context_yield(), which will cause this
function to return 1. Then later my_context_continue() may be called, which
will resume the asynchroneous context by returning from the previous
my_context_yield() call.
When the user function returns, this function returns 0.
In case of error, -1 is returned.
*/
extern int my_context_spawn(struct my_context *c, void (*f)(void *), void *d);
/*
Suspend an asynchroneous context started with my_context_spawn.
When my_context_yield() is called, execution immediately returns from the
last my_context_spawn() or my_context_continue() call. Then when later
my_context_continue() is called, execution resumes by returning from this
my_context_yield() call.
Returns 0 if ok, -1 in case of error.
*/
extern int my_context_yield(struct my_context *c);
/*
Resume an asynchroneous context. The context was spawned by
my_context_spawn(), and later suspended inside my_context_yield().
The asynchroneous context may be repeatedly suspended with
my_context_yield() and resumed with my_context_continue().
Each time it is suspended, this function returns 1. When the originally
spawned user function returns, this function returns 0.
In case of error, -1 is returned.
*/
extern int my_context_continue(struct my_context *c);
struct st_ma_pvio;
struct mysql_async_context {
/*
This is set to the value that should be returned from foo_start() or
foo_cont() when a call is suspended.
*/
unsigned int events_to_wait_for;
/*
It is also set to the event(s) that triggered when a suspended call is
resumed, eg. whether we woke up due to connection completed or timeout
in mysql_real_connect_cont().
*/
unsigned int events_occured;
/*
This is set to the result of the whole asynchronous operation when it
completes. It uses a union, as different calls have different return
types.
*/
union {
void *r_ptr;
const void *r_const_ptr;
int r_int;
my_bool r_my_bool;
} ret_result;
/*
The timeout value (in millisecods), for suspended calls that need to wake
up on a timeout (eg. mysql_real_connect_start().
*/
unsigned int timeout_value;
/*
This flag is set when we are executing inside some asynchronous call
foo_start() or foo_cont(). It is used to decide whether to use the
synchronous or asynchronous version of calls that may block such as
recv().
Note that this flag is not set when a call is suspended, eg. after
returning from foo_start() and before re-entering foo_cont().
*/
my_bool active;
/*
This flag is set when an asynchronous operation is in progress, but
suspended. Ie. it is set when foo_start() or foo_cont() returns because
the operation needs to block, suspending the operation.
It is used to give an error (rather than crash) if the application
attempts to call some foo_cont() method when no suspended operation foo is
in progress.
*/
my_bool suspended;
/*
If non-NULL, this is a pointer to a callback hook that will be invoked with
the user data argument just before the context is suspended, and just after
it is resumed.
*/
struct st_ma_pvio *pvio;
void (*suspend_resume_hook)(my_bool suspend, void *user_data);
void *suspend_resume_hook_user_data;
/*
This is used to save the execution contexts so that we can suspend an
operation and switch back to the application context, to resume the
suspended context later when the application re-invokes us with
foo_cont().
*/
struct my_context async_context;
};

166
vendor/MDBC/include/ma_crypt.h vendored Normal file
View File

@ -0,0 +1,166 @@
/*
Copyright (C) 2018 MariaDB Corporation 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 <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
*/
#ifndef _ma_hash_h_
#define _ma_hash_h_
#include <stddef.h>
#include <stdarg.h>
/*! Hash algorithms */
#define MA_HASH_MD5 1
#define MA_HASH_SHA1 2
#define MA_HASH_SHA224 3
#define MA_HASH_SHA256 4
#define MA_HASH_SHA384 5
#define MA_HASH_SHA512 6
#define MA_HASH_RIPEMD160 7
/*! Hash digest sizes */
#define MA_MD5_HASH_SIZE 16
#define MA_SHA1_HASH_SIZE 20
#define MA_SHA224_HASH_SIZE 28
#define MA_SHA256_HASH_SIZE 32
#define MA_SHA384_HASH_SIZE 48
#define MA_SHA512_HASH_SIZE 64
#define MA_RIPEMD160_HASH_SIZE 20
#define MA_MAX_HASH_SIZE 64
/** \typedef MRL hash context */
#if defined(_WIN32)
#include <windows.h>
#include <bcrypt.h>
typedef struct {
char free_me;
BCRYPT_ALG_HANDLE hAlg;
BCRYPT_HASH_HANDLE hHash;
PBYTE hashObject;
DWORD digest_len;
} MA_HASH_CTX;
#elif defined(HAVE_OPENSSL)
typedef void MA_HASH_CTX;
#elif defined(HAVE_GNUTLS)
typedef struct {
void *ctx;
const struct nettle_hash *hash;
} MA_HASH_CTX;
#endif
/**
@brief acquire and initialize new hash context
@param[in] algorithm hash algorithm
@param[in] ctx pointer to a crypto context
@return hash context on success, NULL on error
*/
MA_HASH_CTX *ma_hash_new(unsigned int algorithm, MA_HASH_CTX *ctx);
/**
@brief release and deinitializes a hash context
@param[in] hash context
@return void
*/
void ma_hash_free(MA_HASH_CTX *ctx);
/**
@brief hashes len bytes of data into the hash context.
This function can be called several times on same context to
hash additional data.
@param[in] ctx hash context
@param[in] buffer data buffer
@param[in] len size of buffer
@return void
*/
void ma_hash_input(MA_HASH_CTX *ctx,
const unsigned char *buffer,
size_t len);
/**
@brief retrieves the hash value from hash context
@param[in] ctx hash context
@param[out] digest digest containing hash value
@return void
*/
void ma_hash_result(MA_HASH_CTX *ctx, unsigned char *digest);
/**
@brief returns digest size for a given hash algorithm
@param[in] hash algorithm
@returns digest size or 0 on error
*/
static inline size_t ma_hash_digest_size(unsigned int hash_alg)
{
switch(hash_alg) {
case MA_HASH_MD5:
return MA_MD5_HASH_SIZE;
case MA_HASH_SHA1:
return MA_SHA1_HASH_SIZE;
case MA_HASH_SHA224:
return MA_SHA224_HASH_SIZE;
case MA_HASH_SHA256:
return MA_SHA256_HASH_SIZE;
case MA_HASH_SHA384:
return MA_SHA384_HASH_SIZE;
case MA_HASH_SHA512:
return MA_SHA512_HASH_SIZE;
case MA_HASH_RIPEMD160:
return MA_RIPEMD160_HASH_SIZE;
default:
return 0;
}
}
/**
@brief function to compute hash from buffer.
@param[in] hash_alg hash algorithm
@param[in] buffer buffer
@param[in] buffer_leng length of buffer
@param[out] digest computed hash digest
@return void
*/
static inline void ma_hash(unsigned int algorithm,
const unsigned char *buffer,
size_t buffer_length,
unsigned char *digest)
{
MA_HASH_CTX *ctx= NULL;
#ifdef _WIN32
MA_HASH_CTX dctx;
ctx= &dctx;
#endif
ctx= ma_hash_new(algorithm, ctx);
ma_hash_input(ctx, buffer, buffer_length);
ma_hash_result(ctx, digest);
ma_hash_free(ctx);
}
#endif /* _ma_hash_h_ */

1094
vendor/MDBC/include/ma_global.h vendored Normal file

File diff suppressed because it is too large Load Diff

70
vendor/MDBC/include/ma_hashtbl.h vendored Normal file
View File

@ -0,0 +1,70 @@
/************************************************************************************
Copyright (C) 2000, 2012 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 <http://www.gnu.org/licenses>
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
*************************************************************************************/
#ifndef _ma_hashtbl_h
#define _ma_hashtbl_h
#ifdef __cplusplus
extern "C" {
#endif
typedef uchar *(*hash_get_key)(const uchar *,uint*,my_bool);
typedef void (*hash_free_key)(void *);
/* flags for hash_init */
#define MA_HASHTBL_CASE_INSENSITIVE 1
typedef struct st_hash_info {
uint next; /* index to next key */
uchar *data; /* data for current entry */
} MA_HASHTBL_LINK;
typedef struct st_hash {
uint key_offset,key_length; /* Length of key if const length */
uint records,blength,current_record;
uint flags;
DYNAMIC_ARRAY array; /* Place for hash_keys */
hash_get_key get_key;
void (*free)(void *);
uint (*calc_hashnr)(const uchar *key,uint length);
} MA_HASHTBL;
#define ma_hashtbl_init(A,B,C,D,E,F,G) _ma_hashtbl_init(A,B,C,D,E,F,G CALLER_INFO)
my_bool _ma_hashtbl_init(MA_HASHTBL *hash,uint default_array_elements, uint key_offset,
uint key_length, hash_get_key get_key,
void (*free_element)(void*), uint flags CALLER_INFO_PROTO);
void ma_hashtbl_free(MA_HASHTBL *tree);
uchar *ma_hashtbl_element(MA_HASHTBL *hash,uint idx);
void * ma_hashtbl_search(MA_HASHTBL *info,const uchar *key,uint length);
void * ma_hashtbl_next(MA_HASHTBL *info,const uchar *key,uint length);
my_bool ma_hashtbl_insert(MA_HASHTBL *info,const uchar *data);
my_bool ma_hashtbl_delete(MA_HASHTBL *hash,uchar *record);
my_bool ma_hashtbl_update(MA_HASHTBL *hash,uchar *record,uchar *old_key,uint old_key_length);
my_bool ma_hashtbl_check(MA_HASHTBL *hash); /* Only in debug library */
#define ma_hashtbl_clear(H) memset((char*) (H), 0,sizeof(*(H)))
#define ma_hashtbl_inited(H) ((H)->array.buffer != 0)
#ifdef __cplusplus
}
#endif
#endif

47
vendor/MDBC/include/ma_list.h vendored Normal file
View File

@ -0,0 +1,47 @@
/* 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
#ifndef _list_h_
#define _list_h_
#ifdef __cplusplus
extern "C" {
#endif
typedef struct st_list {
struct st_list *prev,*next;
void *data;
} LIST;
typedef int (*list_walk_action)(void *,void *);
extern LIST *list_add(LIST *root,LIST *element);
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 unsigned int list_length(LIST *list);
extern int list_walk(LIST *list,list_walk_action action,char * argument);
#define list_rest(a) ((a)->next)
#define list_push(a,b) (a)=list_cons((b),(a))
#define list_pop(A) do {LIST *old=(A); (A)=list_delete(old,old) ; ma_free((char *) old,MYF(MY_FAE)); } while(0)
#ifdef __cplusplus
}
#endif
#endif

60
vendor/MDBC/include/ma_priv.h vendored Normal file
View File

@ -0,0 +1,60 @@
/****************************************************************************
Copyright (C) 2020 MariaDB Corporation
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 <http://www.gnu.org/licenses>
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
*****************************************************************************/
#ifndef MA_PRIV_H
#define MA_PRIV_H
void free_rows(MYSQL_DATA *cur);
int ma_multi_command(MYSQL *mysql, enum enum_multi_status status);
MYSQL_FIELD * unpack_fields(const MYSQL *mysql, MYSQL_DATA *data,
MA_MEM_ROOT *alloc,uint fields,
my_bool default_value);
static inline my_bool ma_has_extended_type_info(const MYSQL *mysql)
{
return ((mysql->extension->mariadb_server_capabilities) &
(MARIADB_CLIENT_EXTENDED_METADATA >> 32)) != 0;
}
static inline uint ma_extended_type_info_rows(const MYSQL *mysql)
{
return ma_has_extended_type_info(mysql) ? 1 : 0;
}
static inline my_bool ma_supports_cache_metadata(const MYSQL *mysql)
{
return (mysql->extension->mariadb_server_capabilities &
(MARIADB_CLIENT_CACHE_METADATA >> 32)) != 0 ;
}
static inline uint ma_result_set_rows(const MYSQL *mysql)
{
return ma_has_extended_type_info(mysql) ? 9 : 8;
}
MA_FIELD_EXTENSION *ma_field_extension_deep_dup(MA_MEM_ROOT *memroot,
const MA_FIELD_EXTENSION *from);
MYSQL_FIELD *ma_duplicate_resultset_metadata(MYSQL_FIELD *fields, size_t count,
MA_MEM_ROOT *memroot);
#endif

34
vendor/MDBC/include/ma_pthread.h vendored Normal file
View File

@ -0,0 +1,34 @@
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
2016 MariaDB Corporation 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
/* Defines to make different thread packages compatible */
#ifndef _my_pthread_h
#define _my_pthread_h
#if defined(_WIN32)
#include <windows.h>
typedef CRITICAL_SECTION pthread_mutex_t;
#define pthread_mutex_init(A,B) InitializeCriticalSection(A)
#define pthread_mutex_lock(A) (EnterCriticalSection(A),0)
#define pthread_mutex_unlock(A) LeaveCriticalSection(A)
#define pthread_mutex_destroy(A) DeleteCriticalSection(A)
#define pthread_self() GetCurrentThreadId()
#endif /* defined(_WIN32) */
#endif /* _my_ptread_h */

139
vendor/MDBC/include/ma_pvio.h vendored Normal file
View File

@ -0,0 +1,139 @@
#ifndef _ma_pvio_h_
#define _ma_pvio_h_
#define cio_defined
#ifdef HAVE_TLS
#include <ma_tls.h>
#else
#define MARIADB_TLS void
#endif
/* CONC-492: Allow to buuld plugins outside of MariaDB Connector/C
source tree wnen ma_global.h was not included. */
#if !defined(_global_h) && !defined(MY_GLOBAL_INCLUDED)
typedef unsigned char uchar;
#endif
#define PVIO_SET_ERROR if (pvio->set_error) \
pvio->set_error
#define PVIO_READ_AHEAD_CACHE_SIZE 16384
#define PVIO_READ_AHEAD_CACHE_MIN_SIZE 2048
#define PVIO_EINTR_TRIES 2
struct st_ma_pvio_methods;
typedef struct st_ma_pvio_methods PVIO_METHODS;
#define IS_PVIO_ASYNC(a) \
((a)->mysql && (a)->mysql->options.extension && (a)->mysql->options.extension->async_context)
#define IS_PVIO_ASYNC_ACTIVE(a) \
(IS_PVIO_ASYNC(a)&& (a)->mysql->options.extension->async_context->active)
#define IS_MYSQL_ASYNC(a) \
((a)->options.extension && (a)->options.extension->async_context)
#define IS_MYSQL_ASYNC_ACTIVE(a) \
(IS_MYSQL_ASYNC(a)&& (a)->options.extension->async_context->active)
enum enum_pvio_timeout {
PVIO_CONNECT_TIMEOUT= 0,
PVIO_READ_TIMEOUT,
PVIO_WRITE_TIMEOUT
};
enum enum_pvio_io_event
{
VIO_IO_EVENT_READ,
VIO_IO_EVENT_WRITE,
VIO_IO_EVENT_CONNECT
};
enum enum_pvio_type {
PVIO_TYPE_UNIXSOCKET= 0,
PVIO_TYPE_SOCKET,
PVIO_TYPE_NAMEDPIPE,
PVIO_TYPE_SHAREDMEM,
};
enum enum_pvio_operation {
PVIO_READ= 0,
PVIO_WRITE=1
};
#define SHM_DEFAULT_NAME "MYSQL"
struct st_pvio_callback;
typedef struct st_pvio_callback {
void (*callback)(MYSQL *mysql, uchar *buffer, size_t size);
struct st_pvio_callback *next;
} PVIO_CALLBACK;
struct st_ma_pvio {
void *data;
/* read ahead cache */
uchar *cache;
uchar *cache_pos;
size_t cache_size;
enum enum_pvio_type type;
int timeout[3];
int ssl_type; /* todo: change to enum (ssl plugins) */
MARIADB_TLS *ctls;
MYSQL *mysql;
PVIO_METHODS *methods;
void (*set_error)(MYSQL *mysql, unsigned int error_nr, const char *sqlstate, const char *format, ...);
void (*callback)(MARIADB_PVIO *pvio, my_bool is_read, const uchar *buffer, size_t length);
};
typedef struct st_ma_pvio_cinfo
{
const char *host;
const char *unix_socket;
int port;
enum enum_pvio_type type;
MYSQL *mysql;
} MA_PVIO_CINFO;
struct st_ma_pvio_methods
{
my_bool (*set_timeout)(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout);
int (*get_timeout)(MARIADB_PVIO *pvio, enum enum_pvio_timeout type);
ssize_t (*read)(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
ssize_t (*async_read)(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
ssize_t (*write)(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
ssize_t (*async_write)(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
int (*wait_io_or_timeout)(MARIADB_PVIO *pvio, my_bool is_read, int timeout);
int (*blocking)(MARIADB_PVIO *pvio, my_bool value, my_bool *old_value);
my_bool (*connect)(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo);
my_bool (*close)(MARIADB_PVIO *pvio);
int (*fast_send)(MARIADB_PVIO *pvio);
int (*keepalive)(MARIADB_PVIO *pvio);
my_bool (*get_handle)(MARIADB_PVIO *pvio, void *handle);
my_bool (*is_blocking)(MARIADB_PVIO *pvio);
my_bool (*is_alive)(MARIADB_PVIO *pvio);
my_bool (*has_data)(MARIADB_PVIO *pvio, ssize_t *data_len);
int(*shutdown)(MARIADB_PVIO *pvio);
};
/* Function prototypes */
MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo);
void ma_pvio_close(MARIADB_PVIO *pvio);
ssize_t ma_pvio_cache_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
ssize_t ma_pvio_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
ssize_t ma_pvio_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
int ma_pvio_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type);
my_bool ma_pvio_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout);
int ma_pvio_fast_send(MARIADB_PVIO *pvio);
int ma_pvio_keepalive(MARIADB_PVIO *pvio);
my_socket ma_pvio_get_socket(MARIADB_PVIO *pvio);
my_bool ma_pvio_is_blocking(MARIADB_PVIO *pvio);
my_bool ma_pvio_blocking(MARIADB_PVIO *pvio, my_bool block, my_bool *previous_mode);
my_bool ma_pvio_is_blocking(MARIADB_PVIO *pvio);
int ma_pvio_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout);
my_bool ma_pvio_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo);
my_bool ma_pvio_is_alive(MARIADB_PVIO *pvio);
my_bool ma_pvio_get_handle(MARIADB_PVIO *pvio, void *handle);
my_bool ma_pvio_has_data(MARIADB_PVIO *pvio, ssize_t *length);
#endif /* _ma_pvio_h_ */

2
vendor/MDBC/include/ma_server_error.h vendored Normal file
View File

@ -0,0 +1,2 @@
/* This file exists for compatibility only */
#include "mysqld_error.h"

42
vendor/MDBC/include/ma_sha1.h vendored Normal file
View File

@ -0,0 +1,42 @@
/****************************************************************************
Copyright (C) 2012 Monty Program AB
2016 MariaDB Corporation 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 <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
*****************************************************************************/
/* This code came from the PHP project, initially written by
Stefan Esser */
#ifndef SHA1_H
#define SHA1_H
#define SHA1_MAX_LENGTH 20
#define SCRAMBLE_LENGTH 20
#define SCRAMBLE_LENGTH_323 8
/* SHA1 context. */
typedef struct {
uint32 state[5]; /* state (ABCD) */
uint32 count[2]; /* number of bits, modulo 2^64 (lsb first) */
unsigned char buffer[64]; /* input buffer */
} _MA_SHA1_CTX;
void ma_SHA1Init(_MA_SHA1_CTX *);
void ma_SHA1Update(_MA_SHA1_CTX *, const unsigned char *, size_t);
void ma_SHA1Final(unsigned char[20], _MA_SHA1_CTX *);
#endif

55
vendor/MDBC/include/ma_string.h vendored Normal file
View File

@ -0,0 +1,55 @@
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
2012 by MontyProgram 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
/* defines for the libmariadb library */
#ifndef _ma_string_h_
#define _ma_string_h_
#include <string.h>
typedef enum {
MY_GCVT_ARG_FLOAT,
MY_GCVT_ARG_DOUBLE
} my_gcvt_arg_type;
size_t ma_fcvt(double x, int precision, char *to, my_bool *error);
size_t ma_gcvt(double x, my_gcvt_arg_type type, int width, char *to,
my_bool *error);
char *ma_ll2str(long long val,char *dst, int radix);
#define MAX_ENV_SIZE 1024
static inline my_bool ma_check_env_str(const char *env)
{
unsigned int i;
if (!env)
return 1;
for (i=0; i < MAX_ENV_SIZE; i++)
{
if (env[i] == 0)
break;
}
if (i >= MAX_ENV_SIZE)
return 1;
return 0;
}
#endif

542
vendor/MDBC/include/ma_sys.h vendored Normal file
View File

@ -0,0 +1,542 @@
/* 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
#ifndef _my_sys_h
#define _my_sys_h
#ifdef __cplusplus
extern "C" {
#endif
#ifdef HAVE_AIOWAIT
#include <sys/asynch.h> /* Used by record-cache */
typedef struct my_aio_result {
aio_result_t result;
int pending;
} my_aio_result;
#endif
#ifndef _mariadb_ctype_h
#include <mariadb_ctype.h> /* for MARIADB_CHARSET_INFO */
#endif
#include <stdarg.h>
#define MYSYS_PROGRAM_USES_CURSES() \
do {\
ma_error_handler_hook = ma_message_curses;\
mysys_uses_curses=1;\
} while(0)
#define MYSYS_PROGRAM_DONT_USE_CURSES() \
do {\
ma_error_handler_hook = ma_message_no_curses; \
mysys_uses_curses=0; \
} while(0)
#define MY_INIT(name) \
do {\
ma_progname= name;\
ma_init();\
} while(0)
#define MAXMAPS (4) /* Number of error message maps */
#define ERRMOD (1000) /* Max number of errors in a map */
#define ERRMSGSIZE (SC_MAXWIDTH) /* Max length of a error message */
#define NRERRBUFFS (2) /* Buffers for parameters */
#define MY_FILE_ERROR ((uint) ~0)
/* General bitmaps for my_func's */
#define MY_FFNF 1 /* Fatal if file not found */
#define MY_FNABP 2 /* Fatal if not all bytes read/written */
#define MY_NABP 4 /* Error if not all bytes read/written */
#define MY_FAE 8 /* Fatal if any error */
#define MY_WME 16 /* Write message on error */
#define MY_WAIT_IF_FULL 32 /* Wait and try again if disk full error */
#define MY_RAID 64 /* Support for RAID (not the "Johnson&Johnson"-s one ;) */
#define MY_DONT_CHECK_FILESIZE 128 /* Option to init_io_cache() */
#define MY_LINK_WARNING 32 /* my_redel() gives warning if links */
#define MY_COPYTIME 64 /* my_redel() copies time */
#define MY_DELETE_OLD 256 /* my_create_with_symlink() */
#define MY_RESOLVE_LINK 128 /* my_realpath(); Only resolve links */
#define MY_HOLD_ORIGINAL_MODES 128 /* my_copy() holds to file modes */
#define MY_REDEL_MAKE_BACKUP 256
#define MY_SEEK_NOT_DONE 32 /* my_lock may have to do a seek */
#define MY_DONT_WAIT 64 /* my_lock() don't wait if can't lock */
#define MY_ZEROFILL 32 /* ma_malloc(), fill array with zero */
#define MY_ALLOW_ZERO_PTR 64 /* ma_realloc() ; zero ptr -> malloc */
#define MY_FREE_ON_ERROR 128 /* ma_realloc() ; Free old ptr on error */
#define MY_HOLD_ON_ERROR 256 /* ma_realloc() ; Return old ptr on error */
#define MY_THREADSAFE 128 /* pread/pwrite: Don't allow interrupts */
#define MY_DONT_OVERWRITE_FILE 1024 /* my_copy; Don't overwrite file */
#define MY_CHECK_ERROR 1 /* Params to ma_end; Check open-close */
#define MY_GIVE_INFO 2 /* Give time info about process*/
#define ME_HIGHBYTE 8 /* Shift for colours */
#define ME_NOCUR 1 /* Don't use curses message */
#define ME_OLDWIN 2 /* Use old window */
#define ME_BELL 4 /* Ring bell then printing message */
#define ME_HOLDTANG 8 /* Don't delete last keys */
#define ME_WAITTOT 16 /* Wait for errtime secs of for a action */
#define ME_WAITTANG 32 /* Wait for a user action */
#define ME_NOREFRESH 64 /* Don't refresh screen */
#define ME_NOINPUT 128 /* Don't use the input library */
#define ME_COLOUR1 ((1 << ME_HIGHBYTE)) /* Possibly error-colours */
#define ME_COLOUR2 ((2 << ME_HIGHBYTE))
#define ME_COLOUR3 ((3 << ME_HIGHBYTE))
/* My seek flags */
#define MY_SEEK_SET 0
#define MY_SEEK_CUR 1
#define MY_SEEK_END 2
/* My charsets_list flags */
#define MY_NO_SETS 0
#define MY_COMPILED_SETS 1 /* show compiled-in sets */
#define MY_CONFIG_SETS 2 /* sets that have a *.conf file */
#define MY_INDEX_SETS 4 /* all sets listed in the Index file */
#define MY_LOADED_SETS 8 /* the sets that are currently loaded */
/* Some constants */
#define MY_WAIT_FOR_USER_TO_FIX_PANIC 60 /* in seconds */
#define MY_WAIT_GIVE_USER_A_MESSAGE 10 /* Every 10 times of prev */
#define MIN_COMPRESS_LENGTH 50 /* Don't compress small bl. */
#define KEYCACHE_BLOCK_SIZE 1024
/* root_alloc flags */
#define MY_KEEP_PREALLOC 1
/* defines when allocating data */
#define my_checkmalloc() (0)
#undef TERMINATE
#define TERMINATE(A) {}
#define QUICK_SAFEMALLOC
#define NORMAL_SAFEMALLOC
#define ma_malloc_ci(SZ,FLAG) ma_malloc( SZ, FLAG )
#define CALLER_INFO_PROTO /* nothing */
#define CALLER_INFO /* nothing */
#define ORIG_CALLER_INFO /* nothing */
#ifdef HAVE_ALLOCA
#if defined(_AIX) && !defined(__GNUC__)
#pragma alloca
#endif /* _AIX */
#if defined(__GNUC__) && !defined(HAVE_ALLOCA_H)
#ifndef alloca
#define alloca __builtin_alloca
#endif
#endif /* GNUC */
#define my_alloca(SZ) alloca((size_t) (SZ))
#define my_afree(PTR) {}
#else
#define my_alloca(SZ) ma_malloc(SZ,MYF(0))
#define my_afree(PTR) ma_free(PTR)
#endif /* HAVE_ALLOCA */
#ifndef errno
#ifdef HAVE_ERRNO_AS_DEFINE
#include <errno.h> /* errno is a define */
#else
extern int errno; /* declare errno */
#endif
#endif
extern const char ** NEAR my_errmsg[];
extern char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE];
/* tbr
extern int (*ma_error_handler_hook)(uint my_err, const char *str,myf MyFlags);
extern int (*fatal_ma_error_handler_hook)(uint my_err, const char *str,
myf MyFlags);
*/
/* charsets */
/* tbr
extern uint get_charset_number(const char *cs_name);
extern const char *get_charset_name(uint cs_number);
extern my_bool set_default_charset(uint cs, myf flags);
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);
extern char *get_charsets_dir(char *buf);
*/
extern MARIADB_CHARSET_INFO *get_charset(uint cs_number, myf flags);
extern MARIADB_CHARSET_INFO *get_charset_by_name(const char *cs_name);
extern MARIADB_CHARSET_INFO *get_charset_by_nr(uint cs_number);
/* string functions */
char *ma_strmake(register char *dst, register const char *src, size_t length);
/* statistics */
#ifdef TBR
extern ulong _my_cache_w_requests,_my_cache_write,_my_cache_r_requests,
_my_cache_read;
extern ulong _my_blocks_used,_my_blocks_changed;
extern ulong ma_file_opened,ma_stream_opened, ma_tmp_file_created;
extern my_bool key_cache_inited;
/* Point to current ma_message() */
extern void (*my_sigtstp_cleanup)(void),
/* Executed before jump to shell */
(*my_sigtstp_restart)(void),
(*my_abort_hook)(int);
/* Executed when coming from shell */
extern int NEAR ma_umask, /* Default creation mask */
NEAR ma_umask_dir,
NEAR my_recived_signals, /* Signals we have got */
NEAR my_safe_to_handle_signal, /* Set when allowed to SIGTSTP */
NEAR ma_dont_interrupt; /* call remember_intr when set */
extern my_bool NEAR mysys_uses_curses, ma_use_symdir;
extern size_t lCurMemory,lMaxMemory; /* from safemalloc */
extern ulong ma_default_record_cache_size;
extern my_bool NEAR ma_disable_locking,NEAR ma_disable_async_io,
NEAR ma_disable_flush_key_blocks, NEAR ma_disable_symlinks;
extern char wild_many,wild_one,wild_prefix;
extern const char *charsets_dir;
extern char *defaults_extra_file;
typedef struct wild_file_pack /* Struct to hold info when selecting files */
{
uint wilds; /* How many wildcards */
uint not_pos; /* Start of not-theese-files */
my_string *wild; /* Pointer to wildcards */
} WF_PACK;
struct my_rnd_struct {
unsigned long seed1,seed2,max_value;
double max_value_dbl;
};
#endif
typedef struct st_typelib { /* Different types saved here */
uint count; /* How many types */
const char *name; /* Name of typelib */
const char **type_names;
} TYPELIB;
enum cache_type {READ_CACHE,WRITE_CACHE,READ_FIFO,READ_NET,WRITE_NET};
enum flush_type { FLUSH_KEEP, FLUSH_RELEASE, FLUSH_IGNORE_CHANGED,
FLUSH_FORCE_WRITE};
typedef struct st_record_cache /* Used when caching records */
{
File file;
int rc_seek,error,inited;
uint rc_length,read_length,reclength;
my_off_t rc_record_pos,end_of_file;
unsigned char *rc_buff,*rc_buff2,*rc_pos,*rc_end,*rc_request_pos;
#ifdef HAVE_AIOWAIT
int use_async_io;
my_aio_result aio_result;
#endif
enum cache_type type;
} RECORD_CACHE;
typedef struct st_dynamic_array {
char *buffer;
uint elements,max_element;
uint alloc_increment;
uint size_of_element;
} DYNAMIC_ARRAY;
typedef struct st_dynamic_string {
char *str;
size_t length,max_length,alloc_increment;
} DYNAMIC_STRING;
typedef struct st_io_cache /* Used when caching files */
{
my_off_t pos_in_file,end_of_file;
unsigned char *rc_pos,*rc_end,*buffer,*rc_request_pos;
int (*read_function)(struct st_io_cache *,unsigned char *,uint);
char *file_name; /* if used with 'open_cached_file' */
char *dir,*prefix;
File file;
int seek_not_done,error;
uint buffer_length,read_length;
myf myflags; /* Flags used to my_read/my_write */
enum cache_type type;
#ifdef HAVE_AIOWAIT
uint inited;
my_off_t aio_read_pos;
my_aio_result aio_result;
#endif
} IO_CACHE;
typedef int (*qsort2_cmp)(const void *, const void *, const void *);
/* defines for mf_iocache */
/* Test if buffer is inited */
#define my_b_clear(info) do{(info)->buffer= 0;} while (0)
#define my_b_inited(info) ((info)->buffer)
#define my_b_EOF INT_MIN
#define my_b_read(info,Buffer,Count) \
((info)->rc_pos + (Count) <= (info)->rc_end ?\
(memcpy((Buffer),(info)->rc_pos,(size_t) (Count)), \
((info)->rc_pos+=(Count)),0) :\
(*(info)->read_function)((info),(Buffer),(Count)))
#define my_b_get(info) \
((info)->rc_pos != (info)->rc_end ?\
((info)->rc_pos++, (int) (uchar) (info)->rc_pos[-1]) :\
_my_b_get(info))
#define my_b_write(info,Buffer,Count) \
((info)->rc_pos + (Count) <= (info)->rc_end ?\
(memcpy((info)->rc_pos,(Buffer),(size_t) (Count)), \
((info)->rc_pos+=(Count)),0) :\
_my_b_write((info),(Buffer),(Count)))
/* my_b_write_byte doesn't have any err-check */
#define my_b_write_byte(info,chr) \
(((info)->rc_pos < (info)->rc_end) ?\
((*(info)->rc_pos++)=(chr)) :\
(_my_b_write((info),0,0) , ((*(info)->rc_pos++)=(chr))))
#define my_b_fill_cache(info) \
(((info)->rc_end=(info)->rc_pos),(*(info)->read_function)((info),0,0))
#define my_b_tell(info) ((info)->pos_in_file + \
((info)->rc_pos - (info)->rc_request_pos))
#define my_b_bytes_in_cache(info) ((uint) ((info)->rc_end - (info)->rc_pos))
typedef struct st_changeable_var {
const char *name; /* Name of variable */
long *varptr; /* Pointer to variable */
long def_value, /* Default value */
min_value, /* Min allowed value */
max_value, /* Max allowed value */
sub_size, /* Subtract this from given value */
block_size; /* Value should be a mult. of this */
} CHANGEABLE_VAR;
/* structs for ma_alloc_root */
#ifndef ST_MA_USED_MEM_DEFINED
#define ST_MA_USED_MEM_DEFINED
typedef struct st_ma_used_mem { /* struct for once_alloc */
struct st_ma_used_mem *next; /* Next block in use */
size_t left; /* memory left in block */
size_t size; /* Size of block */
} MA_USED_MEM;
typedef struct st_ma_mem_root {
MA_USED_MEM *free;
MA_USED_MEM *used;
MA_USED_MEM *pre_alloc;
size_t min_malloc;
size_t block_size;
unsigned int block_num;
unsigned int first_block_usage;
void (*error_handler)(void);
} MA_MEM_ROOT;
#endif
/* Prototypes for mysys and my_func functions */
extern void * _mymalloc(size_t uSize,const char *sFile,
uint uLine, myf MyFlag);
extern void * _myrealloc(void * pPtr,size_t uSize,const char *sFile,
uint uLine, myf MyFlag);
extern void *ma_multi_malloc(myf MyFlags, ...);
extern void _myfree(void * pPtr,const char *sFile,uint uLine, myf MyFlag);
extern int _sanity(const char *sFile,unsigned int uLine);
#ifndef TERMINATE
extern void TERMINATE(FILE *file);
#endif
extern void ma_init_glob_errs(void);
extern FILE *my_fopen(const char *FileName,int Flags,myf MyFlags);
extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags);
extern int my_fclose(FILE *fd,myf MyFlags);
extern int my_chsize(File fd,my_off_t newlength,myf MyFlags);
extern int ma_error _VARARGS((int nr,myf MyFlags, ...));
extern int ma_printf_error _VARARGS((uint my_err, const char *format,
myf MyFlags, ...)
__attribute__ ((format (printf, 2, 4))));
extern int ma_vsnprintf( char *str, size_t n,
const char *format, va_list ap );
extern int ma_snprintf(char* to, size_t n, const char* fmt, ...);
extern int ma_message(uint my_err, const char *str,myf MyFlags);
extern int _mariadb_stderr_out(unsigned int error, const char *errmsg, myf MyFlags);
extern void ma_init(void);
extern void ma_end(int infoflag);
extern int my_redel(const char *from, const char *to, int MyFlags);
extern int my_copystat(const char *from, const char *to, int MyFlags);
extern my_string my_filename(File fd);
#ifndef THREAD
extern void dont_break(void);
extern void allow_break(void);
#else
#define dont_break()
#define allow_break()
#endif
extern void caseup(my_string str,uint length);
extern void casedn(my_string str,uint length);
extern void caseup_str(my_string str);
extern void casedn_str(my_string str);
extern void case_sort(my_string str,uint length);
extern uint ma_dirname_part(my_string to,const char *name);
extern uint ma_dirname_length(const char *name);
#define base_name(A) ((A)+dirname_length(A))
extern int test_if_hard_path(const char *dir_name);
extern char *ma_convert_dirname(my_string name);
extern void to_unix_path(my_string name);
extern my_string ma_fn_ext(const char *name);
extern my_string fn_same(my_string toname,const char *name,int flag);
extern my_string ma_fn_format(my_string to,const char *name,const char *dsk,
const char *form,int flag);
extern size_s ma_strlength(const char *str);
extern void ma_pack_dirname(my_string to,const char *from);
extern uint unma_pack_dirname(my_string to,const char *from);
extern uint ma_cleanup_dirname(my_string to,const char *from);
extern uint ma_system_filename(my_string to,const char *from);
extern my_string ma_unpack_filename(my_string to,const char *from);
extern my_string ma_intern_filename(my_string to,const char *from);
extern my_string directory_file_name(my_string dst, const char *src);
extern int pack_filename(my_string to, const char *name, size_s max_length);
extern my_string my_path(my_string to,const char *progname,
const char *own_pathname_part);
extern my_string my_load_path(my_string to, const char *path,
const char *own_path_prefix);
extern int wild_compare(const char *str,const char *wildstr);
extern my_string my_strcasestr(const char *src,const char *suffix);
extern int my_strcasecmp(const char *s,const char *t);
extern int my_strsortcmp(const char *s,const char *t);
extern int my_casecmp(const char *s,const char *t,uint length);
extern int my_sortcmp(const char *s,const char *t,uint length);
extern int my_sortncmp(const char *s,uint s_len, const char *t,uint t_len);
#ifdef TBR
extern WF_PACK *wf_comp(my_string str);
extern int wf_test(struct wild_file_pack *wf_pack,const char *name);
extern void wf_end(struct wild_file_pack *buffer);
extern size_s strip_sp(my_string str);
extern void get_date(my_string to,int timeflag,time_t use_time);
extern void soundex(my_string out_pntr, my_string in_pntr,pbool remove_garbage);
extern int init_record_cache(RECORD_CACHE *info,uint cachesize,File file,
uint reclength,enum cache_type type,
pbool use_async_io);
extern int read_cache_record(RECORD_CACHE *info,unsigned char *to);
extern int end_record_cache(RECORD_CACHE *info);
extern int write_cache_record(RECORD_CACHE *info,my_off_t filepos,
const unsigned char *record,uint length);
extern int flush_write_cache(RECORD_CACHE *info);
extern long my_clock(void);
extern sig_handler sigtstp_handler(int signal_number);
extern void handle_recived_signals(void);
extern int init_key_cache(ulong use_mem,ulong leave_this_much_mem);
extern unsigned char *key_cache_read(File file,my_off_t filepos,unsigned char* buff,uint length,
uint block_length,int return_buffer);
extern int key_cache_write(File file,my_off_t filepos,unsigned char* buff,uint length,
uint block_length,int force_write);
extern int flush_key_blocks(int file, enum flush_type type);
extern void end_key_cache(void);
extern sig_handler my_set_alarm_variable(int signo);
extern void my_string_ptr_sort(void *base,uint items,size_s size);
extern void radixsort_for_str_ptr(uchar* base[], uint number_of_elements,
size_s size_of_element,uchar *buffer[]);
extern qsort_t qsort2(void *base_ptr, size_t total_elems, size_t size,
qsort2_cmp cmp, void *cmp_argument);
extern qsort2_cmp get_ptr_compare(uint);
extern 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);
extern my_bool reinit_io_cache(IO_CACHE *info,enum cache_type type,
my_off_t seek_offset,pbool use_async_io,
pbool clear_cache);
extern int _my_b_read(IO_CACHE *info,unsigned char *Buffer,uint Count);
extern int _my_b_net_read(IO_CACHE *info,unsigned char *Buffer,uint Count);
extern int _my_b_get(IO_CACHE *info);
extern int _my_b_async_read(IO_CACHE *info,unsigned char *Buffer,uint Count);
extern int _my_b_write(IO_CACHE *info,const unsigned char *Buffer,uint Count);
extern int my_block_write(IO_CACHE *info, const unsigned char *Buffer,
uint Count, my_off_t pos);
extern int flush_io_cache(IO_CACHE *info);
extern int end_io_cache(IO_CACHE *info);
extern uint my_b_fill(IO_CACHE *info);
extern void my_b_seek(IO_CACHE *info,my_off_t pos);
extern uint my_b_gets(IO_CACHE *info, char *to, uint max_length);
extern uint my_b_printf(IO_CACHE *info, const char* fmt, ...);
extern uint my_b_vprintf(IO_CACHE *info, const char* fmt, va_list ap);
extern my_bool open_cached_file(IO_CACHE *cache,const char *dir,
const char *prefix, uint cache_size,
myf cache_myflags);
extern my_bool real_open_cached_file(IO_CACHE *cache);
extern void close_cached_file(IO_CACHE *cache);
File create_temp_file(char *to, const char *dir, const char *pfx,
int mode, myf MyFlags);
#define ma_init_dynamic_array(A,B,C,D) init_dynamic_array(A,B,C,D CALLER_INFO)
#endif
extern my_bool ma_init_dynamic_array(DYNAMIC_ARRAY *array,uint element_size,
uint init_alloc,uint alloc_increment CALLER_INFO_PROTO);
#define ma_init_dynamic_array_ci(A,B,C,D) ma_init_dynamic_array(A,B,C,D ORIG_CALLER_INFO)
extern my_bool ma_insert_dynamic(DYNAMIC_ARRAY *array,void * element);
extern unsigned char *ma_alloc_dynamic(DYNAMIC_ARRAY *array);
extern unsigned char *ma_pop_dynamic(DYNAMIC_ARRAY*);
extern my_bool ma_set_dynamic(DYNAMIC_ARRAY *array,void * element,uint array_index);
extern void ma_get_dynamic(DYNAMIC_ARRAY *array,void * element,uint array_index);
extern void ma_delete_dynamic(DYNAMIC_ARRAY *array);
extern void ma_delete_dynamic_element(DYNAMIC_ARRAY *array, uint array_index);
extern void ma_freeze_size(DYNAMIC_ARRAY *array);
#define dynamic_array_ptr(array,array_index) ((array)->buffer+(array_index)*(array)->size_of_element)
#define dynamic_element(array,array_index,type) ((type)((array)->buffer) +(array_index))
#define push_dynamic(A,B) ma_insert_dynamic(A,B)
extern int ma_find_type(my_string x,TYPELIB *typelib,uint full_name);
extern void ma_make_type(my_string to,uint nr,TYPELIB *typelib);
extern const char *ma_get_type(TYPELIB *typelib,uint nr);
extern my_bool ma_init_dynamic_string(DYNAMIC_STRING *str, const char *init_str,
size_t init_alloc, size_t alloc_increment);
extern my_bool ma_dynstr_append(DYNAMIC_STRING *str, const char *append);
extern my_bool ma_dynstr_append_quoted(DYNAMIC_STRING *str,
const char *append, size_t len,
char quote);
my_bool ma_dynstr_append_mem(DYNAMIC_STRING *str, const char *append,
size_t length);
extern my_bool ma_dynstr_set(DYNAMIC_STRING *str, const char *init_str);
extern my_bool ma_dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size);
extern void ma_dynstr_free(DYNAMIC_STRING *str);
void set_all_changeable_vars(CHANGEABLE_VAR *vars);
my_bool set_changeable_var(my_string str,CHANGEABLE_VAR *vars);
my_bool set_changeable_varval(const char *var, ulong val,
CHANGEABLE_VAR *vars);
#define ma_alloc_root_inited(A) ((A)->min_malloc != 0)
void ma_init_alloc_root(MA_MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size);
void *ma_alloc_root(MA_MEM_ROOT *mem_root, size_t Size);
void ma_free_root(MA_MEM_ROOT *root, myf MyFLAGS);
char *ma_strdup_root(MA_MEM_ROOT *root,const char *str);
char *ma_memdup_root(MA_MEM_ROOT *root,const char *str, size_t len);
void ma_free_defaults(char **argv);
void ma_print_defaults(const char *conf_file, const char **groups);
my_bool _mariadb_compress(unsigned char *, size_t *, size_t *);
my_bool _mariadb_uncompress(unsigned char *, size_t *, size_t *);
unsigned char *_mariadb_compress_alloc(const unsigned char *packet, size_t *len, size_t *complen);
ulong checksum(const unsigned char *mem, uint count);
#if defined(_MSC_VER) && !defined(_WIN32)
extern void sleep(int sec);
#endif
#ifdef __cplusplus
}
#endif
#endif /* _my_sys_h */

161
vendor/MDBC/include/ma_tls.h vendored Normal file
View File

@ -0,0 +1,161 @@
#ifndef _ma_tls_h_
#define _ma_tls_h_
enum enum_pvio_tls_type {
SSL_TYPE_DEFAULT=0,
#ifdef _WIN32
SSL_TYPE_SCHANNEL,
#endif
SSL_TYPE_OPENSSL,
SSL_TYPE_GNUTLS
};
#define PROTOCOL_SSLV3 0
#define PROTOCOL_TLS_1_0 1
#define PROTOCOL_TLS_1_1 2
#define PROTOCOL_TLS_1_2 3
#define PROTOCOL_TLS_1_3 4
#define PROTOCOL_UNKNOWN 5
#define PROTOCOL_MAX PROTOCOL_TLS_1_3
#define TLS_VERSION_LENGTH 64
extern char tls_library_version[TLS_VERSION_LENGTH];
typedef struct st_ma_pvio_tls {
void *data;
MARIADB_PVIO *pvio;
void *ssl;
} MARIADB_TLS;
/* Function prototypes */
/* ma_tls_start
initializes the ssl library
Parameter:
errmsg pointer to error message buffer
errmsg_len length of error message buffer
Returns:
0 success
1 if an error occurred
Notes:
On success the global variable ma_tls_initialized will be set to 1
*/
int ma_tls_start(char *errmsg, size_t errmsg_len);
/* ma_tls_end
unloads/deinitializes ssl library and unsets global variable
ma_tls_initialized
*/
void ma_tls_end(void);
/* ma_tls_init
creates a new SSL structure for a SSL connection and loads
client certificates
Parameters:
MYSQL a mysql structure
Returns:
void * a pointer to internal SSL structure
*/
void * ma_tls_init(MYSQL *mysql);
/* ma_tls_connect
performs SSL handshake
Parameters:
MARIADB_TLS MariaDB SSL container
Returns:
0 success
1 error
*/
my_bool ma_tls_connect(MARIADB_TLS *ctls);
/* ma_tls_read
reads up to length bytes from socket
Parameters:
ctls MariaDB SSL container
buffer read buffer
length buffer length
Returns:
0-n bytes read
-1 if an error occurred
*/
ssize_t ma_tls_read(MARIADB_TLS *ctls, const uchar* buffer, size_t length);
/* ma_tls_write
write buffer to socket
Parameters:
ctls MariaDB SSL container
buffer write buffer
length buffer length
Returns:
0-n bytes written
-1 if an error occurred
*/
ssize_t ma_tls_write(MARIADB_TLS *ctls, const uchar* buffer, size_t length);
/* ma_tls_close
closes SSL connection and frees SSL structure which was previously
created by ma_tls_init call
Parameters:
MARIADB_TLS MariaDB SSL container
Returns:
0 success
1 error
*/
my_bool ma_tls_close(MARIADB_TLS *ctls);
/* ma_tls_verify_server_cert
validation check of server certificate
Parameter:
MARIADB_TLS MariaDB SSL container
Returns:
ß success
1 error
*/
int ma_tls_verify_server_cert(MARIADB_TLS *ctls);
/* ma_tls_get_cipher
returns cipher for current ssl connection
Parameter:
MARIADB_TLS MariaDB SSL container
Returns:
cipher in use or
NULL on error
*/
const char *ma_tls_get_cipher(MARIADB_TLS *ssl);
/* ma_tls_get_finger_print
returns SHA1 finger print of server certificate
Parameter:
MARIADB_TLS MariaDB SSL container
fp buffer for fingerprint
fp_len buffer length
Returns:
actual size of finger print
*/
unsigned int ma_tls_get_finger_print(MARIADB_TLS *ctls, char *fp, unsigned int fp_len);
/* ma_tls_get_protocol_version
returns protocol version number in use
Parameter:
MARIADB_TLS MariaDB SSL container
Returns:
protocol number
*/
int ma_tls_get_protocol_version(MARIADB_TLS *ctls);
const char *ma_pvio_tls_get_protocol_version(MARIADB_TLS *ctls);
int ma_pvio_tls_get_protocol_version_id(MARIADB_TLS *ctls);
/* Function prototypes */
MARIADB_TLS *ma_pvio_tls_init(MYSQL *mysql);
my_bool ma_pvio_tls_connect(MARIADB_TLS *ctls);
ssize_t ma_pvio_tls_read(MARIADB_TLS *ctls, const uchar *buffer, size_t length);
ssize_t ma_pvio_tls_write(MARIADB_TLS *ctls, const uchar *buffer, size_t length);
my_bool ma_pvio_tls_close(MARIADB_TLS *ctls);
int ma_pvio_tls_verify_server_cert(MARIADB_TLS *ctls);
const char *ma_pvio_tls_cipher(MARIADB_TLS *ctls);
my_bool ma_pvio_tls_check_fp(MARIADB_TLS *ctls, const char *fp, const char *fp_list);
my_bool ma_pvio_start_ssl(MARIADB_PVIO *pvio);
void ma_pvio_tls_end();
#endif /* _ma_tls_h_ */

55
vendor/MDBC/include/mariadb/ma_io.h vendored Normal file
View File

@ -0,0 +1,55 @@
/* Copyright (C) 2015 MariaDB Corporation 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
#ifndef _ma_io_h_
#define _ma_io_h_
#ifdef HAVE_REMOTEIO
#include <curl/curl.h>
#endif
enum enum_file_type {
MA_FILE_NONE=0,
MA_FILE_LOCAL=1,
MA_FILE_REMOTE=2
};
typedef struct
{
enum enum_file_type type;
void *ptr;
} MA_FILE;
#ifdef HAVE_REMOTEIO
struct st_rio_methods {
MA_FILE *(*mopen)(const char *url, const char *mode);
int (*mclose)(MA_FILE *ptr);
int (*mfeof)(MA_FILE *file);
size_t (*mread)(void *ptr, size_t size, size_t nmemb, MA_FILE *file);
char * (*mgets)(char *ptr, size_t size, MA_FILE *file);
};
#endif
/* function prototypes */
MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql);
int ma_close(MA_FILE *file);
int ma_feof(MA_FILE *file);
size_t ma_read(void *ptr, size_t size, size_t nmemb, MA_FILE *file);
char *ma_gets(char *ptr, size_t size, MA_FILE *file);
#endif

37
vendor/MDBC/include/mariadb_async.h vendored Normal file
View File

@ -0,0 +1,37 @@
/* Copyright (C) 2012 MariaDB Services and Kristian Nielsen
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; version 2 of the License.
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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
/* Common definitions for MariaDB non-blocking client library. */
#ifndef MYSQL_ASYNC_H
#define MYSQL_ASYNC_H
extern int my_connect_async(MARIADB_PVIO *pvio,
const struct sockaddr *name, uint namelen,
int vio_timeout);
extern ssize_t my_recv_async(MARIADB_PVIO *pvio,
unsigned char *buf, size_t size, int timeout);
extern ssize_t my_send_async(MARIADB_PVIO *pvio,
const unsigned char *buf, size_t size,
int timeout);
extern my_bool my_io_wait_async(struct mysql_async_context *b,
enum enum_pvio_io_event event, int timeout);
#ifdef HAVE_TLS
extern ssize_t ma_tls_read_async(MARIADB_PVIO *pvio, const uchar *buf, size_t size);
extern ssize_t ma_tls_write_async(MARIADB_PVIO *pvio, const uchar *buf, size_t size);
#endif
#endif /* MYSQL_ASYNC_H */

469
vendor/MDBC/include/mariadb_com.h vendored Normal file
View File

@ -0,0 +1,469 @@
/************************************************************************************
Copyright (C) 2000, 2012 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 <http://www.gnu.org/licenses>
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
*************************************************************************************/
/*
** Common definition between mysql server & client
*/
#ifndef _mysql_com_h
#define _mysql_com_h
#define NAME_CHAR_LEN 64
#define NAME_LEN 256 /* Field/table name length */
#define HOSTNAME_LENGTH 60
#define SYSTEM_MB_MAX_CHAR_LENGTH 4
#define USERNAME_CHAR_LENGTH 128
#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(_WIN32) && !defined( _CUSTOMCONFIG_)
#define MARIADB_NAMEDPIPE "MySQL"
#define MYSQL_SERVICENAME "MySql"
#endif /* _WIN32 */
/* for use in mysql client tools only */
#define MYSQL_AUTODETECT_CHARSET_NAME "auto"
#define BINCMP_FLAG 131072
enum mysql_enum_shutdown_level
{
SHUTDOWN_DEFAULT = 0,
KILL_QUERY= 254,
KILL_CONNECTION= 255
};
enum enum_server_command
{
COM_SLEEP = 0,
COM_QUIT,
COM_INIT_DB,
COM_QUERY,
COM_FIELD_LIST,
COM_CREATE_DB,
COM_DROP_DB,
COM_REFRESH,
COM_SHUTDOWN,
COM_STATISTICS,
COM_PROCESS_INFO,
COM_CONNECT,
COM_PROCESS_KILL,
COM_DEBUG,
COM_PING,
COM_TIME = 15,
COM_DELAYED_INSERT,
COM_CHANGE_USER,
COM_BINLOG_DUMP,
COM_TABLE_DUMP,
COM_CONNECT_OUT = 20,
COM_REGISTER_SLAVE,
COM_STMT_PREPARE = 22,
COM_STMT_EXECUTE = 23,
COM_STMT_SEND_LONG_DATA = 24,
COM_STMT_CLOSE = 25,
COM_STMT_RESET = 26,
COM_SET_OPTION = 27,
COM_STMT_FETCH = 28,
COM_DAEMON= 29,
COM_UNSUPPORTED= 30,
COM_RESET_CONNECTION = 31,
COM_STMT_BULK_EXECUTE = 250,
COM_RESERVED_1 = 254, /* former COM_MULTI, now removed */
COM_END
};
#define NOT_NULL_FLAG 1 /* Field can't be NULL */
#define PRI_KEY_FLAG 2 /* Field is part of a primary key */
#define UNIQUE_KEY_FLAG 4 /* Field is part of a unique key */
#define MULTIPLE_KEY_FLAG 8 /* Field is part of a key */
#define BLOB_FLAG 16 /* Field is a blob */
#define UNSIGNED_FLAG 32 /* Field is unsigned */
#define ZEROFILL_FLAG 64 /* Field is zerofill */
#define BINARY_FLAG 128
/* The following are only sent to new clients */
#define ENUM_FLAG 256 /* field is an enum */
#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 */
#define UNIQUE_FLAG 65536 /* Intern: Used by sql_yacc */
#define REFRESH_GRANT 1 /* Refresh grant tables */
#define REFRESH_LOG 2 /* Start on new log file */
#define REFRESH_TABLES 4 /* close all tables */
#define REFRESH_HOSTS 8 /* Flush host cache */
#define REFRESH_STATUS 16 /* Flush status variables */
#define REFRESH_THREADS 32 /* Flush thread cache */
#define REFRESH_SLAVE 64 /* Reset master info and restart slave
thread */
#define REFRESH_MASTER 128 /* Remove all bin logs in the index
and truncate the index */
/* The following can't be set with mysql_refresh() */
#define REFRESH_READ_LOCK 16384 /* Lock tables for read */
#define REFRESH_FAST 32768 /* Intern flag */
#define CLIENT_MYSQL 1
#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */
#define CLIENT_LONG_FLAG 4 /* Get all column flags */
#define CLIENT_CONNECT_WITH_DB 8 /* One can specify db on connect */
#define CLIENT_NO_SCHEMA 16 /* Don't allow database.table.column */
#define CLIENT_COMPRESS 32 /* Can use compression protocol */
#define CLIENT_ODBC 64 /* Odbc client */
#define CLIENT_LOCAL_FILES 128 /* Can use LOAD DATA LOCAL */
#define CLIENT_IGNORE_SPACE 256 /* Ignore spaces before '(' */
#define CLIENT_INTERACTIVE 1024 /* This is an interactive client */
#define CLIENT_SSL 2048 /* Switch to SSL after handshake */
#define CLIENT_IGNORE_SIGPIPE 4096 /* IGNORE sigpipes */
#define CLIENT_TRANSACTIONS 8192 /* Client knows about transactions */
/* added in 4.x */
#define CLIENT_PROTOCOL_41 512
#define CLIENT_RESERVED 16384
#define CLIENT_SECURE_CONNECTION 32768
#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_CONNECT_ATTRS (1UL << 20)
#define CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA (1UL << 21)
#define CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS (1UL << 22)
#define CLIENT_SESSION_TRACKING (1UL << 23)
#define CLIENT_PROGRESS (1UL << 29) /* client supports progress indicator */
#define CLIENT_PROGRESS_OBSOLETE CLIENT_PROGRESS
#define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30)
#define CLIENT_REMEMBER_OPTIONS (1UL << 31)
/* MariaDB specific capabilities */
#define MARIADB_CLIENT_FLAGS 0xFFFFFFFF00000000ULL
#define MARIADB_CLIENT_PROGRESS (1ULL << 32)
#define MARIADB_CLIENT_RESERVED_1 (1ULL << 33) /* Former COM_MULTI, don't use */
#define MARIADB_CLIENT_STMT_BULK_OPERATIONS (1ULL << 34)
/* support of extended data type/format information, since 10.5.0 */
#define MARIADB_CLIENT_EXTENDED_METADATA (1ULL << 35)
/* Do not resend metadata for prepared statements, since 10.6*/
#define MARIADB_CLIENT_CACHE_METADATA (1ULL << 36)
#define IS_MARIADB_EXTENDED_SERVER(mysql)\
(!(mysql->server_capabilities & CLIENT_MYSQL))
#define MARIADB_CLIENT_SUPPORTED_FLAGS (MARIADB_CLIENT_PROGRESS |\
MARIADB_CLIENT_STMT_BULK_OPERATIONS|\
MARIADB_CLIENT_EXTENDED_METADATA|\
MARIADB_CLIENT_CACHE_METADATA)
#define CLIENT_SUPPORTED_FLAGS (CLIENT_MYSQL |\
CLIENT_FOUND_ROWS |\
CLIENT_LONG_FLAG |\
CLIENT_CONNECT_WITH_DB |\
CLIENT_NO_SCHEMA |\
CLIENT_COMPRESS |\
CLIENT_ODBC |\
CLIENT_LOCAL_FILES |\
CLIENT_IGNORE_SPACE |\
CLIENT_INTERACTIVE |\
CLIENT_SSL |\
CLIENT_IGNORE_SIGPIPE |\
CLIENT_TRANSACTIONS |\
CLIENT_PROTOCOL_41 |\
CLIENT_RESERVED |\
CLIENT_SECURE_CONNECTION |\
CLIENT_MULTI_STATEMENTS |\
CLIENT_MULTI_RESULTS |\
CLIENT_PROGRESS |\
CLIENT_SSL_VERIFY_SERVER_CERT |\
CLIENT_REMEMBER_OPTIONS |\
CLIENT_PLUGIN_AUTH |\
CLIENT_SESSION_TRACKING |\
CLIENT_CONNECT_ATTRS)
#define CLIENT_CAPABILITIES (CLIENT_MYSQL | \
CLIENT_LONG_FLAG |\
CLIENT_TRANSACTIONS |\
CLIENT_SECURE_CONNECTION |\
CLIENT_MULTI_RESULTS | \
CLIENT_PS_MULTI_RESULTS |\
CLIENT_PROTOCOL_41 |\
CLIENT_PLUGIN_AUTH |\
CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA | \
CLIENT_SESSION_TRACKING |\
CLIENT_CONNECT_ATTRS)
#define CLIENT_DEFAULT_FLAGS ((CLIENT_SUPPORTED_FLAGS & ~CLIENT_COMPRESS)\
& ~CLIENT_SSL)
#define SERVER_STATUS_IN_TRANS 1 /* Transaction has started */
#define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */
#define SERVER_MORE_RESULTS_EXIST 8
#define SERVER_QUERY_NO_GOOD_INDEX_USED 16
#define SERVER_QUERY_NO_INDEX_USED 32
#define SERVER_STATUS_CURSOR_EXISTS 64
#define SERVER_STATUS_LAST_ROW_SENT 128
#define SERVER_STATUS_DB_DROPPED 256
#define SERVER_STATUS_NO_BACKSLASH_ESCAPES 512
#define SERVER_STATUS_METADATA_CHANGED 1024
#define SERVER_QUERY_WAS_SLOW 2048
#define SERVER_PS_OUT_PARAMS 4096
#define SERVER_STATUS_IN_TRANS_READONLY 8192
#define SERVER_SESSION_STATE_CHANGED 16384
#define SERVER_STATUS_ANSI_QUOTES 32768
#define MYSQL_ERRMSG_SIZE 512
#define NET_READ_TIMEOUT 30 /* Timeout on read */
#define NET_WRITE_TIMEOUT 60 /* Timeout on write */
#define NET_WAIT_TIMEOUT (8*60*60) /* Wait for new query */
/* for server integration (mysqlbinlog) */
#define LIST_PROCESS_HOST_LEN 64
#define MYSQL50_TABLE_NAME_PREFIX "#mysql50#"
#define MYSQL50_TABLE_NAME_PREFIX_LENGTH (sizeof(MYSQL50_TABLE_NAME_PREFIX)-1)
#define SAFE_NAME_LEN (NAME_LEN + MYSQL50_TABLE_NAME_PREFIX_LENGTH)
struct st_ma_pvio;
typedef struct st_ma_pvio MARIADB_PVIO;
#define MAX_CHAR_WIDTH 255 /* Max length for a CHAR column */
#define MAX_BLOB_WIDTH 8192 /* Default width for blob */
/* the following defines were added for PHP's mysqli and pdo extensions:
see: CONC-56
*/
#define MAX_TINYINT_WIDTH 3
#define MAX_SMALLINT_WIDTH 5
#define MAX_MEDIUMINT_WIDTH 8
#define MAX_INT_WIDTH 10
#define MAX_BIGINT_WIDTH 20
struct st_ma_connection_plugin;
typedef struct st_net {
MARIADB_PVIO *pvio;
unsigned char *buff;
unsigned char *buff_end,*write_pos,*read_pos;
my_socket fd; /* For Perl DBI/dbd */
unsigned long remain_in_buf,length;
unsigned long buf_length, where_b;
unsigned long max_packet, max_packet_size;
unsigned int pkt_nr, compress_pkt_nr;
unsigned int write_timeout, read_timeout, retry_count;
int fcntl;
unsigned int *return_status;
unsigned char reading_or_writing;
char save_char;
char unused_1;
my_bool unused_2;
my_bool compress;
my_bool unused_3;
void *unused_4;
unsigned int last_errno;
unsigned char error;
my_bool unused_5;
my_bool unused_6;
char last_error[MYSQL_ERRMSG_SIZE];
char sqlstate[SQLSTATE_LENGTH+1];
struct st_mariadb_net_extension *extension;
} 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_session_state_type
{
SESSION_TRACK_SYSTEM_VARIABLES= 0,
SESSION_TRACK_SCHEMA,
SESSION_TRACK_STATE_CHANGE,
/* currently not supported by MariaDB Server */
SESSION_TRACK_GTIDS,
SESSION_TRACK_TRANSACTION_CHARACTERISTICS,
SESSION_TRACK_TRANSACTION_STATE /* make sure that SESSION_TRACK_END always points
to last element of enum !! */
};
#define SESSION_TRACK_BEGIN 0
#define SESSION_TRACK_END SESSION_TRACK_TRANSACTION_STATE
#define SESSION_TRACK_TYPES (SESSION_TRACK_END + 1)
/* SESSION_TRACK_TRANSACTION_TYPE was renamed to SESSION_TRACK_TRANSACTION_STATE
in 3e699a1738cdfb0a2c5b8eabfa8301b8d11cf711.
This is a workaround to prevent breaking of travis and buildbot tests.
TODO: Remove this after server fixes */
#define SESSION_TRACK_TRANSACTION_TYPE SESSION_TRACK_TRANSACTION_STATE
enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY,
MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP,
MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24,
MYSQL_TYPE_DATE, MYSQL_TYPE_TIME,
MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
MYSQL_TYPE_BIT,
/*
the following types are not used by client,
only for mysqlbinlog!!
*/
MYSQL_TYPE_TIMESTAMP2,
MYSQL_TYPE_DATETIME2,
MYSQL_TYPE_TIME2,
/* --------------------------------------------- */
MYSQL_TYPE_JSON=245,
MYSQL_TYPE_NEWDECIMAL=246,
MYSQL_TYPE_ENUM=247,
MYSQL_TYPE_SET=248,
MYSQL_TYPE_TINY_BLOB=249,
MYSQL_TYPE_MEDIUM_BLOB=250,
MYSQL_TYPE_LONG_BLOB=251,
MYSQL_TYPE_BLOB=252,
MYSQL_TYPE_VAR_STRING=253,
MYSQL_TYPE_STRING=254,
MYSQL_TYPE_GEOMETRY=255,
MAX_NO_FIELD_TYPES };
#define FIELD_TYPE_CHAR FIELD_TYPE_TINY /* For compatibility */
#define FIELD_TYPE_INTERVAL FIELD_TYPE_ENUM /* For compatibility */
#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;
#define net_new_transaction(net) ((net)->pkt_nr=0)
int ma_net_init(NET *net, MARIADB_PVIO *pvio);
void ma_net_end(NET *net);
void ma_net_clear(NET *net);
int ma_net_flush(NET *net);
int ma_net_write(NET *net,const unsigned char *packet, size_t len);
int ma_net_write_command(NET *net,unsigned char command,const char *packet,
size_t len, my_bool disable_flush);
int ma_net_real_write(NET *net,const char *packet, size_t len);
extern unsigned long ma_net_read(NET *net);
struct rand_struct {
unsigned long seed1,seed2,max_value;
double max_value_dbl;
};
/* The following is for user defined functions */
enum Item_result {STRING_RESULT,REAL_RESULT,INT_RESULT,ROW_RESULT,DECIMAL_RESULT};
typedef struct st_udf_args
{
unsigned int arg_count; /* Number of arguments */
enum Item_result *arg_type; /* Pointer to item_results */
char **args; /* Pointer to argument */
unsigned long *lengths; /* Length of string arguments */
char *maybe_null; /* Set to 1 for all maybe_null args */
} UDF_ARGS;
/* This holds information about the result */
typedef struct st_udf_init
{
my_bool maybe_null; /* 1 if function can return NULL */
unsigned int decimals; /* for real functions */
unsigned int max_length; /* For string functions */
char *ptr; /* free pointer for function data */
my_bool const_item; /* 0 if result is independent of arguments */
} UDF_INIT;
/* Connection types */
#define MARIADB_CONNECTION_UNIXSOCKET 0
#define MARIADB_CONNECTION_TCP 1
#define MARIADB_CONNECTION_NAMEDPIPE 2
#define MARIADB_CONNECTION_SHAREDMEM 3
/* Constants when using compression */
#define NET_HEADER_SIZE 4 /* standard header size */
#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" {
#endif
char *ma_scramble_323(char *to,const char *message,const char *password);
void ma_scramble_41(const unsigned char *buffer, const char *scramble, const char *password);
void ma_hash_password(unsigned long *result, const char *password, size_t len);
void ma_make_scrambled_password(char *to,const char *password);
/* Some other useful functions */
void mariadb_load_defaults(const char *conf_file, const char **groups,
int *argc, char ***argv);
my_bool ma_thread_init(void);
void ma_thread_end(void);
#ifdef __cplusplus
}
#endif
#define NULL_LENGTH ((unsigned long) ~0) /* For net_store_length */
#endif

76
vendor/MDBC/include/mariadb_ctype.h vendored Normal file
View File

@ -0,0 +1,76 @@
/* 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
/*
A better implementation of the UNIX ctype(3) library.
Notes: my_global.h should be included before ctype.h
*/
#ifndef _mariadb_ctype_h
#define _mariadb_ctype_h
#include <ctype.h>
#ifdef __cplusplus
extern "C" {
#endif
#define CHARSET_DIR "charsets/"
#define MY_CS_NAME_SIZE 32
#define MADB_DEFAULT_CHARSET_NAME "latin1"
#define MADB_DEFAULT_COLLATION_NAME "latin1_swedish_ci"
#define MADB_AUTODETECT_CHARSET_NAME "auto"
/* we use the mysqlnd implementation */
typedef struct ma_charset_info_st
{
unsigned int nr; /* so far only 1 byte for charset */
unsigned int state;
const char *csname;
const char *name;
const char *dir;
unsigned int codepage;
const char *encoding;
unsigned int char_minlen;
unsigned int char_maxlen;
unsigned int (*mb_charlen)(unsigned int c);
unsigned int (*mb_valid)(const char *start, const char *end);
} MARIADB_CHARSET_INFO;
extern const MARIADB_CHARSET_INFO mariadb_compiled_charsets[];
extern MARIADB_CHARSET_INFO *ma_default_charset_info;
extern MARIADB_CHARSET_INFO *ma_charset_bin;
extern MARIADB_CHARSET_INFO *ma_charset_latin1;
extern MARIADB_CHARSET_INFO *ma_charset_utf8_general_ci;
extern MARIADB_CHARSET_INFO *ma_charset_utf16le_general_ci;
MARIADB_CHARSET_INFO *find_compiled_charset(unsigned int cs_number);
MARIADB_CHARSET_INFO *find_compiled_charset_by_name(const char *name);
size_t mysql_cset_escape_quotes(const MARIADB_CHARSET_INFO *cset, char *newstr, const char *escapestr, size_t escapestr_len);
size_t mysql_cset_escape_slashes(const MARIADB_CHARSET_INFO *cset, char *newstr, const char *escapestr, size_t escapestr_len);
const char* madb_get_os_character_set(void);
#ifdef _WIN32
int madb_get_windows_cp(const char *charset);
#endif
#ifdef __cplusplus
}
#endif
#endif

259
vendor/MDBC/include/mariadb_dyncol.h vendored Normal file
View File

@ -0,0 +1,259 @@
/* Copyright (c) 2011, Monty Program Ab
Copyright (c) 2011, Oleksandr Byelkin
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 the following disclaimer in
the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND ANY
EXPRESS 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 <COPYRIGHT HOLDER> OR
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.
*/
#ifndef ma_dyncol_h
#define ma_dyncol_h
#ifdef __cplusplus
extern "C" {
#endif
#ifndef LIBMARIADB
#include <decimal.h>
#include <my_decimal_limits.h>
#endif
#include <mysql.h>
#ifndef longlong_defined
#if defined(HAVE_LONG_LONG) && SIZEOF_LONG != 8
typedef unsigned long long int ulonglong; /* ulong or unsigned long long */
typedef long long int longlong;
#else
typedef unsigned long ulonglong; /* ulong or unsigned long long */
typedef long longlong;
#endif
#define longlong_defined
#endif
#ifndef _my_sys_h
typedef struct st_dynamic_string
{
char *str;
size_t length,max_length,alloc_increment;
} DYNAMIC_STRING;
#endif
struct st_mysql_lex_string
{
char *str;
size_t length;
};
typedef struct st_mysql_lex_string MYSQL_LEX_STRING;
typedef struct st_mysql_lex_string LEX_STRING;
/*
Limits of implementation
*/
#define MAX_TOTAL_NAME_LENGTH 65535
#define MAX_NAME_LENGTH (MAX_TOTAL_NAME_LENGTH/4)
/* NO and OK is the same used just to show semantics */
#define ER_DYNCOL_NO ER_DYNCOL_OK
enum enum_dyncol_func_result
{
ER_DYNCOL_OK= 0,
ER_DYNCOL_YES= 1, /* For functions returning 0/1 */
ER_DYNCOL_FORMAT= -1, /* Wrong format of the encoded string */
ER_DYNCOL_LIMIT= -2, /* Some limit reached */
ER_DYNCOL_RESOURCE= -3, /* Out of resourses */
ER_DYNCOL_DATA= -4, /* Incorrect input data */
ER_DYNCOL_UNKNOWN_CHARSET= -5, /* Unknown character set */
ER_DYNCOL_TRUNCATED= 2 /* OK, but data was truncated */
};
typedef DYNAMIC_STRING DYNAMIC_COLUMN;
enum enum_dynamic_column_type
{
DYN_COL_NULL= 0,
DYN_COL_INT,
DYN_COL_UINT,
DYN_COL_DOUBLE,
DYN_COL_STRING,
DYN_COL_DECIMAL,
DYN_COL_DATETIME,
DYN_COL_DATE,
DYN_COL_TIME,
DYN_COL_DYNCOL
};
typedef enum enum_dynamic_column_type DYNAMIC_COLUMN_TYPE;
struct st_dynamic_column_value
{
DYNAMIC_COLUMN_TYPE type;
union
{
long long long_value;
unsigned long long ulong_value;
double double_value;
struct {
MYSQL_LEX_STRING value;
MARIADB_CHARSET_INFO *charset;
} string;
#ifndef LIBMARIADB
struct {
decimal_digit_t buffer[DECIMAL_BUFF_LENGTH];
decimal_t value;
} decimal;
#endif
MYSQL_TIME time_value;
} x;
};
typedef struct st_dynamic_column_value DYNAMIC_COLUMN_VALUE;
#ifdef MADYNCOL_DEPRECATED
enum enum_dyncol_func_result
dynamic_column_create(DYNAMIC_COLUMN *str,
uint column_nr, DYNAMIC_COLUMN_VALUE *value);
enum enum_dyncol_func_result
dynamic_column_create_many(DYNAMIC_COLUMN *str,
uint column_count,
uint *column_numbers,
DYNAMIC_COLUMN_VALUE *values);
enum enum_dyncol_func_result
dynamic_column_update(DYNAMIC_COLUMN *org, uint column_nr,
DYNAMIC_COLUMN_VALUE *value);
enum enum_dyncol_func_result
dynamic_column_update_many(DYNAMIC_COLUMN *str,
uint add_column_count,
uint *column_numbers,
DYNAMIC_COLUMN_VALUE *values);
enum enum_dyncol_func_result
dynamic_column_exists(DYNAMIC_COLUMN *org, uint column_nr);
enum enum_dyncol_func_result
dynamic_column_list(DYNAMIC_COLUMN *org, DYNAMIC_ARRAY *array_of_uint);
enum enum_dyncol_func_result
dynamic_column_get(DYNAMIC_COLUMN *org, uint column_nr,
DYNAMIC_COLUMN_VALUE *store_it_here);
#endif
/* new functions */
enum enum_dyncol_func_result
mariadb_dyncol_create_many_num(DYNAMIC_COLUMN *str,
uint column_count,
uint *column_numbers,
DYNAMIC_COLUMN_VALUE *values,
my_bool new_string);
enum enum_dyncol_func_result
mariadb_dyncol_create_many_named(DYNAMIC_COLUMN *str,
uint column_count,
MYSQL_LEX_STRING *column_keys,
DYNAMIC_COLUMN_VALUE *values,
my_bool new_string);
enum enum_dyncol_func_result
mariadb_dyncol_update_many_num(DYNAMIC_COLUMN *str,
uint add_column_count,
uint *column_keys,
DYNAMIC_COLUMN_VALUE *values);
enum enum_dyncol_func_result
mariadb_dyncol_update_many_named(DYNAMIC_COLUMN *str,
uint add_column_count,
MYSQL_LEX_STRING *column_keys,
DYNAMIC_COLUMN_VALUE *values);
enum enum_dyncol_func_result
mariadb_dyncol_exists_num(DYNAMIC_COLUMN *org, uint column_nr);
enum enum_dyncol_func_result
mariadb_dyncol_exists_named(DYNAMIC_COLUMN *str, MYSQL_LEX_STRING *name);
/* List of not NULL columns */
enum enum_dyncol_func_result
mariadb_dyncol_list_num(DYNAMIC_COLUMN *str, uint *count, uint **nums);
enum enum_dyncol_func_result
mariadb_dyncol_list_named(DYNAMIC_COLUMN *str, uint *count,
MYSQL_LEX_STRING **names);
/*
if the column do not exists it is NULL
*/
enum enum_dyncol_func_result
mariadb_dyncol_get_num(DYNAMIC_COLUMN *org, uint column_nr,
DYNAMIC_COLUMN_VALUE *store_it_here);
enum enum_dyncol_func_result
mariadb_dyncol_get_named(DYNAMIC_COLUMN *str, MYSQL_LEX_STRING *name,
DYNAMIC_COLUMN_VALUE *store_it_here);
my_bool mariadb_dyncol_has_names(DYNAMIC_COLUMN *str);
enum enum_dyncol_func_result
mariadb_dyncol_check(DYNAMIC_COLUMN *str);
enum enum_dyncol_func_result
mariadb_dyncol_json(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json);
void mariadb_dyncol_free(DYNAMIC_COLUMN *str);
#define mariadb_dyncol_init(A) memset((A), 0, sizeof(DYNAMIC_COLUMN))
#define dynamic_column_initialize(A) mariadb_dyncol_init((A))
#define dynamic_column_column_free(A) mariadb_dyncol_free((A))
/* conversion of values to 3 base types */
enum enum_dyncol_func_result
mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val,
MARIADB_CHARSET_INFO *cs, char quote);
enum enum_dyncol_func_result
mariadb_dyncol_val_long(longlong *ll, DYNAMIC_COLUMN_VALUE *val);
enum enum_dyncol_func_result
mariadb_dyncol_val_double(double *dbl, DYNAMIC_COLUMN_VALUE *val);
enum enum_dyncol_func_result
mariadb_dyncol_unpack(DYNAMIC_COLUMN *str,
uint *count,
MYSQL_LEX_STRING **names, DYNAMIC_COLUMN_VALUE **vals);
int mariadb_dyncol_column_cmp_named(const MYSQL_LEX_STRING *s1,
const MYSQL_LEX_STRING *s2);
enum enum_dyncol_func_result
mariadb_dyncol_column_count(DYNAMIC_COLUMN *str, uint *column_count);
#define mariadb_dyncol_value_init(V) \
do {\
(V)->type= DYN_COL_NULL;\
} while(0)
/*
Prepare value for using as decimal
*/
void mariadb_dyncol_prepare_decimal(DYNAMIC_COLUMN_VALUE *value);
#ifdef __cplusplus
}
#endif
#endif

305
vendor/MDBC/include/mariadb_rpl.h vendored Normal file
View File

@ -0,0 +1,305 @@
/* Copyright (C) 2018 MariaDB Corporation 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
#ifndef _mariadb_rpl_h_
#define _mariadb_rpl_h_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#define MARIADB_RPL_VERSION 0x0001
#define MARIADB_RPL_REQUIRED_VERSION 0x0001
/* Protocol flags */
#define MARIADB_RPL_BINLOG_DUMP_NON_BLOCK 1
#define MARIADB_RPL_BINLOG_SEND_ANNOTATE_ROWS 2
#define MARIADB_RPL_IGNORE_HEARTBEAT (1 << 17)
#define EVENT_HEADER_OFS 20
#define FL_GROUP_COMMIT_ID 2
#define FL_STMT_END 1
#define LOG_EVENT_ARTIFICIAL_F 0x20
/* Options */
enum mariadb_rpl_option {
MARIADB_RPL_FILENAME, /* Filename and length */
MARIADB_RPL_START, /* Start position */
MARIADB_RPL_SERVER_ID, /* Server ID */
MARIADB_RPL_FLAGS, /* Protocol flags */
MARIADB_RPL_GTID_CALLBACK, /* GTID callback function */
MARIADB_RPL_GTID_DATA, /* GTID data */
MARIADB_RPL_BUFFER
};
/* Event types: From MariaDB Server sql/log_event.h */
enum mariadb_rpl_event {
UNKNOWN_EVENT= 0,
START_EVENT_V3= 1,
QUERY_EVENT= 2,
STOP_EVENT= 3,
ROTATE_EVENT= 4,
INTVAR_EVENT= 5,
LOAD_EVENT= 6,
SLAVE_EVENT= 7,
CREATE_FILE_EVENT= 8,
APPEND_BLOCK_EVENT= 9,
EXEC_LOAD_EVENT= 10,
DELETE_FILE_EVENT= 11,
NEW_LOAD_EVENT= 12,
RAND_EVENT= 13,
USER_VAR_EVENT= 14,
FORMAT_DESCRIPTION_EVENT= 15,
XID_EVENT= 16,
BEGIN_LOAD_QUERY_EVENT= 17,
EXECUTE_LOAD_QUERY_EVENT= 18,
TABLE_MAP_EVENT = 19,
PRE_GA_WRITE_ROWS_EVENT = 20, /* deprecated */
PRE_GA_UPDATE_ROWS_EVENT = 21, /* deprecated */
PRE_GA_DELETE_ROWS_EVENT = 22, /* deprecated */
WRITE_ROWS_EVENT_V1 = 23,
UPDATE_ROWS_EVENT_V1 = 24,
DELETE_ROWS_EVENT_V1 = 25,
INCIDENT_EVENT= 26,
HEARTBEAT_LOG_EVENT= 27,
IGNORABLE_LOG_EVENT= 28,
ROWS_QUERY_LOG_EVENT= 29,
WRITE_ROWS_EVENT = 30,
UPDATE_ROWS_EVENT = 31,
DELETE_ROWS_EVENT = 32,
GTID_LOG_EVENT= 33,
ANONYMOUS_GTID_LOG_EVENT= 34,
PREVIOUS_GTIDS_LOG_EVENT= 35,
TRANSACTION_CONTEXT_EVENT= 36,
VIEW_CHANGE_EVENT= 37,
XA_PREPARE_LOG_EVENT= 38,
/*
Add new events here - right above this comment!
Existing events (except ENUM_END_EVENT) should never change their numbers
*/
/* New MySQL/Sun events are to be added right above this comment */
MYSQL_EVENTS_END,
MARIA_EVENTS_BEGIN= 160,
ANNOTATE_ROWS_EVENT= 160,
BINLOG_CHECKPOINT_EVENT= 161,
GTID_EVENT= 162,
GTID_LIST_EVENT= 163,
START_ENCRYPTION_EVENT= 164,
QUERY_COMPRESSED_EVENT = 165,
WRITE_ROWS_COMPRESSED_EVENT_V1 = 166,
UPDATE_ROWS_COMPRESSED_EVENT_V1 = 167,
DELETE_ROWS_COMPRESSED_EVENT_V1 = 168,
WRITE_ROWS_COMPRESSED_EVENT = 169,
UPDATE_ROWS_COMPRESSED_EVENT = 170,
DELETE_ROWS_COMPRESSED_EVENT = 171,
/* Add new MariaDB events here - right above this comment! */
ENUM_END_EVENT /* end marker */
};
typedef struct {
char *str;
size_t length;
} MARIADB_STRING;
enum mariadb_row_event_type {
WRITE_ROWS= 0,
UPDATE_ROWS= 1,
DELETE_ROWS= 2
};
/* Global transaction id */
typedef struct st_mariadb_gtid {
unsigned int domain_id;
unsigned int server_id;
unsigned long long sequence_nr;
} MARIADB_GTID;
/* Generic replication handle */
typedef struct st_mariadb_rpl {
unsigned int version;
MYSQL *mysql;
char *filename;
uint32_t filename_length;
unsigned char *buffer;
unsigned long buffer_size;
uint32_t server_id;
unsigned long start_position;
uint32_t flags;
uint8_t fd_header_len; /* header len from last format description event */
uint8_t use_checksum;
} MARIADB_RPL;
/* Event header */
struct st_mariadb_rpl_rotate_event {
unsigned long long position;
MARIADB_STRING filename;
};
struct st_mariadb_rpl_query_event {
uint32_t thread_id;
uint32_t seconds;
MARIADB_STRING database;
uint32_t errornr;
MARIADB_STRING status;
MARIADB_STRING statement;
};
struct st_mariadb_rpl_gtid_list_event {
uint32_t gtid_cnt;
MARIADB_GTID *gtid;
};
struct st_mariadb_rpl_format_description_event
{
uint16_t format;
char *server_version;
uint32_t timestamp;
uint8_t header_len;
};
struct st_mariadb_rpl_checkpoint_event {
MARIADB_STRING filename;
};
struct st_mariadb_rpl_xid_event {
uint64_t transaction_nr;
};
struct st_mariadb_rpl_gtid_event {
uint64_t sequence_nr;
uint32_t domain_id;
uint8_t flags;
uint64_t commit_id;
};
struct st_mariadb_rpl_annotate_rows_event {
MARIADB_STRING statement;
};
struct st_mariadb_rpl_table_map_event {
unsigned long long table_id;
MARIADB_STRING database;
MARIADB_STRING table;
unsigned int column_count;
MARIADB_STRING column_types;
MARIADB_STRING metadata;
char *null_indicator;
};
struct st_mariadb_rpl_rand_event {
unsigned long long first_seed;
unsigned long long second_seed;
};
struct st_mariadb_rpl_encryption_event {
char scheme;
unsigned int key_version;
char *nonce;
};
struct st_mariadb_rpl_intvar_event {
char type;
unsigned long long value;
};
struct st_mariadb_rpl_uservar_event {
MARIADB_STRING name;
uint8_t is_null;
uint8_t type;
uint32_t charset_nr;
MARIADB_STRING value;
uint8_t flags;
};
struct st_mariadb_rpl_rows_event {
enum mariadb_row_event_type type;
uint64_t table_id;
uint16_t flags;
uint32_t column_count;
char *column_bitmap;
char *column_update_bitmap;
size_t row_data_size;
void *row_data;
};
struct st_mariadb_rpl_heartbeat_event {
uint32_t timestamp;
uint32_t next_position;
uint8_t type;
uint16_t flags;
};
typedef struct st_mariadb_rpl_event
{
/* common header */
MA_MEM_ROOT memroot;
unsigned int checksum;
char ok;
enum mariadb_rpl_event event_type;
unsigned int timestamp;
unsigned int server_id;
unsigned int event_length;
unsigned int next_event_pos;
unsigned short flags;
/****************/
union {
struct st_mariadb_rpl_rotate_event rotate;
struct st_mariadb_rpl_query_event query;
struct st_mariadb_rpl_format_description_event format_description;
struct st_mariadb_rpl_gtid_list_event gtid_list;
struct st_mariadb_rpl_checkpoint_event checkpoint;
struct st_mariadb_rpl_xid_event xid;
struct st_mariadb_rpl_gtid_event gtid;
struct st_mariadb_rpl_annotate_rows_event annotate_rows;
struct st_mariadb_rpl_table_map_event table_map;
struct st_mariadb_rpl_rand_event rand;
struct st_mariadb_rpl_encryption_event encryption;
struct st_mariadb_rpl_intvar_event intvar;
struct st_mariadb_rpl_uservar_event uservar;
struct st_mariadb_rpl_rows_event rows;
struct st_mariadb_rpl_heartbeat_event heartbeat;
} event;
} MARIADB_RPL_EVENT;
#define mariadb_rpl_init(a) mariadb_rpl_init_ex((a), MARIADB_RPL_VERSION)
/* Function prototypes */
MARIADB_RPL * STDCALL mariadb_rpl_init_ex(MYSQL *mysql, unsigned int version);
int mariadb_rpl_optionsv(MARIADB_RPL *rpl, enum mariadb_rpl_option, ...);
int mariadb_rpl_get_optionsv(MARIADB_RPL *rpl, enum mariadb_rpl_option, ...);
int STDCALL mariadb_rpl_open(MARIADB_RPL *rpl);
void STDCALL mariadb_rpl_close(MARIADB_RPL *rpl);
MARIADB_RPL_EVENT * STDCALL mariadb_rpl_fetch(MARIADB_RPL *rpl, MARIADB_RPL_EVENT *event);
void STDCALL mariadb_free_rpl_event(MARIADB_RPL_EVENT *event);
#ifdef __cplusplus
}
#endif
#endif

298
vendor/MDBC/include/mariadb_stmt.h vendored Normal file
View File

@ -0,0 +1,298 @@
/************************************************************************
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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA
Part of this code includes code from PHP's mysqlnd extension
(written by Andrey Hristov, Georg Richter and Ulf Wendel), freely
available from http://www.php.net/software
*************************************************************************/
#define MYSQL_NO_DATA 100
#define MYSQL_DATA_TRUNCATED 101
#define MYSQL_DEFAULT_PREFETCH_ROWS (unsigned long) 1
/* Bind flags */
#define MADB_BIND_DUMMY 1
#define MARIADB_STMT_BULK_SUPPORTED(stmt)\
((stmt)->mysql && \
(!((stmt)->mysql->server_capabilities & CLIENT_MYSQL) &&\
((stmt)->mysql->extension->mariadb_server_capabilities & \
(MARIADB_CLIENT_STMT_BULK_OPERATIONS >> 32))))
#define SET_CLIENT_STMT_ERROR(a, b, c, d) \
do { \
(a)->last_errno= (b);\
strncpy((a)->sqlstate, (c), SQLSTATE_LENGTH);\
(a)->sqlstate[SQLSTATE_LENGTH]= 0;\
strncpy((a)->last_error, (d) ? (d) : ER((b)), MYSQL_ERRMSG_SIZE);\
(a)->last_error[MYSQL_ERRMSG_SIZE - 1]= 0;\
} while (0)
#define CLEAR_CLIENT_STMT_ERROR(a) \
do { \
(a)->last_errno= 0;\
strcpy((a)->sqlstate, "00000");\
(a)->last_error[0]= 0;\
} while (0)
#define MYSQL_PS_SKIP_RESULT_W_LEN -1
#define MYSQL_PS_SKIP_RESULT_STR -2
#define STMT_ID_LENGTH 4
typedef struct st_mysql_stmt MYSQL_STMT;
typedef MYSQL_RES* (*mysql_stmt_use_or_store_func)(MYSQL_STMT *);
enum enum_stmt_attr_type
{
STMT_ATTR_UPDATE_MAX_LENGTH,
STMT_ATTR_CURSOR_TYPE,
STMT_ATTR_PREFETCH_ROWS,
/* MariaDB only */
STMT_ATTR_PREBIND_PARAMS=200,
STMT_ATTR_ARRAY_SIZE,
STMT_ATTR_ROW_SIZE,
STMT_ATTR_STATE,
STMT_ATTR_CB_USER_DATA,
STMT_ATTR_CB_PARAM,
STMT_ATTR_CB_RESULT
};
enum enum_cursor_type
{
CURSOR_TYPE_NO_CURSOR= 0,
CURSOR_TYPE_READ_ONLY= 1,
CURSOR_TYPE_FOR_UPDATE= 2,
CURSOR_TYPE_SCROLLABLE= 4
};
enum enum_indicator_type
{
STMT_INDICATOR_NTS=-1,
STMT_INDICATOR_NONE=0,
STMT_INDICATOR_NULL=1,
STMT_INDICATOR_DEFAULT=2,
STMT_INDICATOR_IGNORE=3,
STMT_INDICATOR_IGNORE_ROW=4
};
/*
bulk PS flags
*/
#define STMT_BULK_FLAG_CLIENT_SEND_TYPES 128
#define STMT_BULK_FLAG_INSERT_ID_REQUEST 64
typedef enum mysql_stmt_state
{
MYSQL_STMT_INITTED = 0,
MYSQL_STMT_PREPARED,
MYSQL_STMT_EXECUTED,
MYSQL_STMT_WAITING_USE_OR_STORE,
MYSQL_STMT_USE_OR_STORE_CALLED,
MYSQL_STMT_USER_FETCHING, /* fetch_row_buff or fetch_row_unbuf */
MYSQL_STMT_FETCH_DONE
} enum_mysqlnd_stmt_state;
typedef struct st_mysql_bind
{
unsigned long *length; /* output length pointer */
my_bool *is_null; /* Pointer to null indicator */
void *buffer; /* buffer to get/put data */
/* set this if you want to track data truncations happened during fetch */
my_bool *error;
union {
unsigned char *row_ptr; /* for the current data position */
char *indicator; /* indicator variable */
} u;
void (*store_param_func)(NET *net, struct st_mysql_bind *param);
void (*fetch_result)(struct st_mysql_bind *, MYSQL_FIELD *,
unsigned char **row);
void (*skip_result)(struct st_mysql_bind *, MYSQL_FIELD *,
unsigned char **row);
/* output buffer length, must be set when fetching str/binary */
unsigned long buffer_length;
unsigned long offset; /* offset position for char/binary fetch */
unsigned long length_value; /* Used if length is 0 */
unsigned int flags; /* special flags, e.g. for dummy bind */
unsigned int pack_length; /* Internal length for packed data */
enum enum_field_types buffer_type; /* buffer type */
my_bool error_value; /* used if error is 0 */
my_bool is_unsigned; /* set if integer type is unsigned */
my_bool long_data_used; /* If used with mysql_send_long_data */
my_bool is_null_value; /* Used if is_null is 0 */
void *extension;
} MYSQL_BIND;
typedef struct st_mysqlnd_upsert_result
{
unsigned int warning_count;
unsigned int server_status;
unsigned long long affected_rows;
unsigned long long last_insert_id;
} mysql_upsert_status;
typedef struct st_mysql_cmd_buffer
{
unsigned char *buffer;
size_t length;
} MYSQL_CMD_BUFFER;
typedef struct st_mysql_error_info
{
unsigned int error_no;
char error[MYSQL_ERRMSG_SIZE+1];
char sqlstate[SQLSTATE_LENGTH + 1];
} mysql_error_info;
struct st_mysqlnd_stmt_methods
{
my_bool (*prepare)(const MYSQL_STMT * stmt, const char * const query, size_t query_len);
my_bool (*execute)(const MYSQL_STMT * stmt);
MYSQL_RES * (*use_result)(const MYSQL_STMT * stmt);
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 MYSQL_STMT * stmt, unsigned long long 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 */
my_bool (*fetch)(const MYSQL_STMT * stmt, my_bool * const fetched_anything);
my_bool (*bind_param)(const MYSQL_STMT * stmt, const MYSQL_BIND bind);
my_bool (*refresh_bind_param)(const MYSQL_STMT * stmt);
my_bool (*bind_result)(const MYSQL_STMT * stmt, const MYSQL_BIND *bind);
my_bool (*send_long_data)(const MYSQL_STMT * stmt, unsigned int param_num,
const char * const data, size_t length);
MYSQL_RES *(*get_parameter_metadata)(const MYSQL_STMT * stmt);
MYSQL_RES *(*get_result_metadata)(const MYSQL_STMT * stmt);
unsigned long long (*get_last_insert_id)(const MYSQL_STMT * stmt);
unsigned long long (*get_affected_rows)(const MYSQL_STMT * stmt);
unsigned long long (*get_num_rows)(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 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);
void (*set_error)(MYSQL_STMT *stmt, unsigned int error_nr, const char *sqlstate, const char *format, ...);
};
typedef int (*mysql_stmt_fetch_row_func)(MYSQL_STMT *stmt, unsigned char **row);
typedef void (*ps_result_callback)(void *data, unsigned int column, unsigned char **row);
typedef my_bool *(*ps_param_callback)(void *data, MYSQL_BIND *bind, unsigned int row_nr);
struct st_mysql_stmt
{
MA_MEM_ROOT mem_root;
MYSQL *mysql;
unsigned long stmt_id;
unsigned long flags;/* cursor is set here */
enum_mysqlnd_stmt_state state;
MYSQL_FIELD *fields;
unsigned int field_count;
unsigned int param_count;
unsigned char send_types_to_server;
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;
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;
LIST list;
my_bool cursor_exists;
void *extension;
mysql_stmt_fetch_row_func fetch_row_func;
unsigned int execute_count;/* count how many times the stmt was executed */
mysql_stmt_use_or_store_func default_rset_handler;
struct st_mysqlnd_stmt_methods *m;
unsigned int array_size;
size_t row_size;
unsigned int prebind_params;
void *user_data;
ps_result_callback result_callback;
ps_param_callback param_callback;
};
typedef void (*ps_field_fetch_func)(MYSQL_BIND *r_param, const MYSQL_FIELD * field, unsigned char **row);
typedef struct st_mysql_perm_bind {
ps_field_fetch_func func;
/* should be signed int */
int pack_len;
unsigned long max_len;
} MYSQL_PS_CONVERSION;
extern MYSQL_PS_CONVERSION mysql_ps_fetch_functions[MYSQL_TYPE_GEOMETRY + 1];
unsigned long ma_net_safe_read(MYSQL *mysql);
void mysql_init_ps_subsystem(void);
unsigned long net_field_length(unsigned char **packet);
int ma_simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg,
size_t length, my_bool skipp_check, void *opt_arg);
/*
* function prototypes
*/
MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql);
int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, unsigned long length);
int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt);
int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt);
int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind_arg, unsigned int column, unsigned long offset);
int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt);
unsigned long STDCALL mysql_stmt_param_count(MYSQL_STMT * stmt);
my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, const void *attr);
my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, void *attr);
my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
my_bool STDCALL mysql_stmt_close(MYSQL_STMT * stmt);
my_bool STDCALL mysql_stmt_reset(MYSQL_STMT * stmt);
my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt);
my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt, unsigned int param_number, const char *data, unsigned long length);
MYSQL_RES *STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt);
MYSQL_RES *STDCALL mysql_stmt_param_metadata(MYSQL_STMT *stmt);
unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT * stmt);
const char *STDCALL mysql_stmt_error(MYSQL_STMT * stmt);
const char *STDCALL mysql_stmt_sqlstate(MYSQL_STMT * stmt);
MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_seek(MYSQL_STMT *stmt, MYSQL_ROW_OFFSET offset);
MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_tell(MYSQL_STMT *stmt);
void STDCALL mysql_stmt_data_seek(MYSQL_STMT *stmt, unsigned long long offset);
unsigned long long STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt);
unsigned long long STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt);
unsigned long long STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt);
unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt);
int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt);
my_bool STDCALL mysql_stmt_more_results(MYSQL_STMT *stmt);
int STDCALL mariadb_stmt_execute_direct(MYSQL_STMT *stmt, const char *stmt_str, size_t length);
MYSQL_FIELD * STDCALL mariadb_stmt_fetch_fields(MYSQL_STMT *stmt);

View File

@ -0,0 +1,44 @@
/* 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 */
#ifndef _mariadb_version_h_
#define _mariadb_version_h_
#ifdef _CUSTOMCONFIG_
#include <custom_conf.h>
#else
#define PROTOCOL_VERSION @PROTOCOL_VERSION@
#define MARIADB_CLIENT_VERSION_STR "@MARIADB_CLIENT_VERSION@"
#define MARIADB_BASE_VERSION "@MARIADB_BASE_VERSION@"
#define MARIADB_VERSION_ID @MARIADB_VERSION_ID@
#define MARIADB_PORT @MARIADB_PORT@
#define MARIADB_UNIX_ADDR "@MARIADB_UNIX_ADDR@"
#ifndef MYSQL_UNIX_ADDR
#define MYSQL_UNIX_ADDR MARIADB_UNIX_ADDR
#endif
#ifndef MYSQL_PORT
#define MYSQL_PORT MARIADB_PORT
#endif
#define MYSQL_CONFIG_NAME "my"
#define MYSQL_VERSION_ID @MARIADB_VERSION_ID@
#define MYSQL_SERVER_VERSION "@MARIADB_CLIENT_VERSION@-MariaDB"
#define MARIADB_PACKAGE_VERSION "@CPACK_PACKAGE_VERSION@"
#define MARIADB_PACKAGE_VERSION_ID @MARIADB_PACKAGE_VERSION_ID@
#define MARIADB_SYSTEM_TYPE "@CMAKE_SYSTEM_NAME@"
#define MARIADB_MACHINE_TYPE "@CMAKE_SYSTEM_PROCESSOR@"
#define MARIADB_PLUGINDIR "@CMAKE_INSTALL_PREFIX@/@INSTALL_PLUGINDIR@"
/* mysqld compile time options */
#ifndef MYSQL_CHARSET
#define MYSQL_CHARSET "@default_charset@"
#endif
#endif
/* Source information */
#define CC_SOURCE_REVISION "@CC_SOURCE_REVISION@"
#endif /* _mariadb_version_h_ */

893
vendor/MDBC/include/mysql.h vendored Normal file
View File

@ -0,0 +1,893 @@
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
2012 by MontyProgram 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
/* defines for the libmariadb library */
#ifndef _mysql_h
#define _mysql_h
#ifdef __cplusplus
extern "C" {
#endif
#ifndef LIBMARIADB
#define LIBMARIADB
#endif
#ifndef MYSQL_CLIENT
#define MYSQL_CLIENT
#endif
#include <stdarg.h>
#if !defined (_global_h) && !defined (MY_GLOBAL_INCLUDED) /* If not standard header */
#include <sys/types.h>
typedef char my_bool;
typedef unsigned long long my_ulonglong;
#if !defined(_WIN32)
#define STDCALL
#else
#define STDCALL __stdcall
#endif
#ifndef my_socket_defined
#define my_socket_defined
#if defined(_WIN64)
#define my_socket unsigned long long
#elif defined(_WIN32)
#define my_socket unsigned int
#else
typedef int my_socket;
#endif
#endif
#endif
#include "mariadb_com.h"
#include "mariadb_version.h"
#include "ma_list.h"
#include "mariadb_ctype.h"
typedef struct st_ma_const_string
{
const char *str;
size_t length;
} MARIADB_CONST_STRING;
#ifndef ST_MA_USED_MEM_DEFINED
#define ST_MA_USED_MEM_DEFINED
typedef struct st_ma_used_mem { /* struct for once_alloc */
struct st_ma_used_mem *next; /* Next block in use */
size_t left; /* memory left in block */
size_t size; /* Size of block */
} MA_USED_MEM;
typedef struct st_ma_mem_root {
MA_USED_MEM *free;
MA_USED_MEM *used;
MA_USED_MEM *pre_alloc;
size_t min_malloc;
size_t block_size;
unsigned int block_num;
unsigned int first_block_usage;
void (*error_handler)(void);
} MA_MEM_ROOT;
#endif
extern unsigned int mysql_port;
extern char *mysql_unix_port;
extern unsigned int mariadb_deinitialize_ssl;
#define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG)
#define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG)
#define IS_BLOB(n) ((n) & BLOB_FLAG)
#define IS_NUM(t) (((t) <= MYSQL_TYPE_INT24 && (t) != MYSQL_TYPE_TIMESTAMP) || (t) == MYSQL_TYPE_YEAR || (t) == MYSQL_TYPE_NEWDECIMAL)
#define IS_NUM_FIELD(f) ((f)->flags & NUM_FLAG)
#define INTERNAL_NUM_FIELD(f) (((f)->type <= MYSQL_TYPE_INT24 && ((f)->type != MYSQL_TYPE_TIMESTAMP || (f)->length == 14 || (f)->length == 8)) || (f)->type == MYSQL_TYPE_YEAR || (f)->type == MYSQL_TYPE_NEWDECIMAL || (f)->type == MYSQL_TYPE_DECIMAL)
typedef struct st_mysql_field {
char *name; /* Name of column */
char *org_name; /* Name of original column (added after 3.23.58) */
char *table; /* Table of column if column was a field */
char *org_table; /* Name of original table (added after 3.23.58 */
char *db; /* table schema (added after 3.23.58) */
char *catalog; /* table catalog (added after 3.23.58) */
char *def; /* Default value (set by mysql_list_fields) */
unsigned long length; /* Width of column */
unsigned long max_length; /* Max width of selected set */
/* added after 3.23.58 */
unsigned int name_length;
unsigned int org_name_length;
unsigned int table_length;
unsigned int org_table_length;
unsigned int db_length;
unsigned int catalog_length;
unsigned int def_length;
/***********************/
unsigned int flags; /* Div flags */
unsigned int decimals; /* Number of decimals in field */
unsigned int charsetnr; /* char set number (added in 4.1) */
enum enum_field_types type; /* Type of field. Se mysql_com.h for types */
void *extension; /* added in 4.1 */
} MYSQL_FIELD;
typedef char **MYSQL_ROW; /* return data as array of strings */
typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */
#define SET_CLIENT_ERROR(a, b, c, d) \
do { \
(a)->net.last_errno= (b);\
strncpy((a)->net.sqlstate, (c), SQLSTATE_LENGTH);\
(a)->net.sqlstate[SQLSTATE_LENGTH]= 0;\
strncpy((a)->net.last_error, (d) ? (d) : ER((b)), MYSQL_ERRMSG_SIZE - 1);\
(a)->net.last_error[MYSQL_ERRMSG_SIZE - 1]= 0;\
} while(0)
/* For mysql_async.c */
#define set_mariadb_error(A,B,C) SET_CLIENT_ERROR((A),(B),(C),0)
extern const char *SQLSTATE_UNKNOWN;
#define unknown_sqlstate SQLSTATE_UNKNOWN
#define CLEAR_CLIENT_ERROR(a) \
do { \
(a)->net.last_errno= 0;\
strcpy((a)->net.sqlstate, "00000");\
(a)->net.last_error[0]= '\0';\
if ((a)->net.extension)\
(a)->net.extension->extended_errno= 0;\
} while (0)
#define MYSQL_COUNT_ERROR (~(unsigned long long) 0)
typedef struct st_mysql_rows {
struct st_mysql_rows *next; /* list of rows */
MYSQL_ROW data;
unsigned long length;
} MYSQL_ROWS;
typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; /* offset to current row */
typedef struct st_mysql_data {
MYSQL_ROWS *data;
void *embedded_info;
MA_MEM_ROOT alloc;
unsigned long long rows;
unsigned int fields;
void *extension;
} MYSQL_DATA;
enum mysql_option
{
MYSQL_OPT_CONNECT_TIMEOUT,
MYSQL_OPT_COMPRESS,
MYSQL_OPT_NAMED_PIPE,
MYSQL_INIT_COMMAND,
MYSQL_READ_DEFAULT_FILE,
MYSQL_READ_DEFAULT_GROUP,
MYSQL_SET_CHARSET_DIR,
MYSQL_SET_CHARSET_NAME,
MYSQL_OPT_LOCAL_INFILE,
MYSQL_OPT_PROTOCOL,
MYSQL_SHARED_MEMORY_BASE_NAME,
MYSQL_OPT_READ_TIMEOUT,
MYSQL_OPT_WRITE_TIMEOUT,
MYSQL_OPT_USE_RESULT,
MYSQL_OPT_USE_REMOTE_CONNECTION,
MYSQL_OPT_USE_EMBEDDED_CONNECTION,
MYSQL_OPT_GUESS_CONNECTION,
MYSQL_SET_CLIENT_IP,
MYSQL_SECURE_AUTH,
MYSQL_REPORT_DATA_TRUNCATION,
MYSQL_OPT_RECONNECT,
MYSQL_OPT_SSL_VERIFY_SERVER_CERT,
MYSQL_PLUGIN_DIR,
MYSQL_DEFAULT_AUTH,
MYSQL_OPT_BIND,
MYSQL_OPT_SSL_KEY,
MYSQL_OPT_SSL_CERT,
MYSQL_OPT_SSL_CA,
MYSQL_OPT_SSL_CAPATH,
MYSQL_OPT_SSL_CIPHER,
MYSQL_OPT_SSL_CRL,
MYSQL_OPT_SSL_CRLPATH,
/* Connection attribute options */
MYSQL_OPT_CONNECT_ATTR_RESET,
MYSQL_OPT_CONNECT_ATTR_ADD,
MYSQL_OPT_CONNECT_ATTR_DELETE,
MYSQL_SERVER_PUBLIC_KEY,
MYSQL_ENABLE_CLEARTEXT_PLUGIN,
MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS,
MYSQL_OPT_SSL_ENFORCE,
MYSQL_OPT_MAX_ALLOWED_PACKET,
MYSQL_OPT_NET_BUFFER_LENGTH,
MYSQL_OPT_TLS_VERSION,
/* MariaDB specific */
MYSQL_PROGRESS_CALLBACK=5999,
MYSQL_OPT_NONBLOCK,
/* MariaDB Connector/C specific */
MYSQL_DATABASE_DRIVER=7000,
MARIADB_OPT_SSL_FP, /* deprecated, use MARIADB_OPT_TLS_PEER_FP instead */
MARIADB_OPT_SSL_FP_LIST, /* deprecated, use MARIADB_OPT_TLS_PEER_FP_LIST instead */
MARIADB_OPT_TLS_PASSPHRASE, /* passphrase for encrypted certificates */
MARIADB_OPT_TLS_CIPHER_STRENGTH,
MARIADB_OPT_TLS_VERSION,
MARIADB_OPT_TLS_PEER_FP, /* single finger print for server certificate verification */
MARIADB_OPT_TLS_PEER_FP_LIST, /* finger print white list for server certificate verification */
MARIADB_OPT_CONNECTION_READ_ONLY,
MYSQL_OPT_CONNECT_ATTRS, /* for mysql_get_optionv */
MARIADB_OPT_USERDATA,
MARIADB_OPT_CONNECTION_HANDLER,
MARIADB_OPT_PORT,
MARIADB_OPT_UNIXSOCKET,
MARIADB_OPT_PASSWORD,
MARIADB_OPT_HOST,
MARIADB_OPT_USER,
MARIADB_OPT_SCHEMA,
MARIADB_OPT_DEBUG,
MARIADB_OPT_FOUND_ROWS,
MARIADB_OPT_MULTI_RESULTS,
MARIADB_OPT_MULTI_STATEMENTS,
MARIADB_OPT_INTERACTIVE,
MARIADB_OPT_PROXY_HEADER,
MARIADB_OPT_IO_WAIT,
MARIADB_OPT_SKIP_READ_RESPONSE
};
enum mariadb_value {
MARIADB_CHARSET_ID,
MARIADB_CHARSET_NAME,
MARIADB_CLIENT_ERRORS,
MARIADB_CLIENT_VERSION,
MARIADB_CLIENT_VERSION_ID,
MARIADB_CONNECTION_ASYNC_TIMEOUT,
MARIADB_CONNECTION_ASYNC_TIMEOUT_MS,
MARIADB_CONNECTION_MARIADB_CHARSET_INFO,
MARIADB_CONNECTION_ERROR,
MARIADB_CONNECTION_ERROR_ID,
MARIADB_CONNECTION_HOST,
MARIADB_CONNECTION_INFO,
MARIADB_CONNECTION_PORT,
MARIADB_CONNECTION_PROTOCOL_VERSION_ID,
MARIADB_CONNECTION_PVIO_TYPE,
MARIADB_CONNECTION_SCHEMA,
MARIADB_CONNECTION_SERVER_TYPE,
MARIADB_CONNECTION_SERVER_VERSION,
MARIADB_CONNECTION_SERVER_VERSION_ID,
MARIADB_CONNECTION_SOCKET,
MARIADB_CONNECTION_SQLSTATE,
MARIADB_CONNECTION_SSL_CIPHER,
MARIADB_TLS_LIBRARY,
MARIADB_CONNECTION_TLS_VERSION,
MARIADB_CONNECTION_TLS_VERSION_ID,
MARIADB_CONNECTION_TYPE,
MARIADB_CONNECTION_UNIX_SOCKET,
MARIADB_CONNECTION_USER,
MARIADB_MAX_ALLOWED_PACKET,
MARIADB_NET_BUFFER_LENGTH,
MARIADB_CONNECTION_SERVER_STATUS,
MARIADB_CONNECTION_SERVER_CAPABILITIES,
MARIADB_CONNECTION_EXTENDED_SERVER_CAPABILITIES,
MARIADB_CONNECTION_CLIENT_CAPABILITIES
};
enum mysql_status { MYSQL_STATUS_READY,
MYSQL_STATUS_GET_RESULT,
MYSQL_STATUS_USE_RESULT,
MYSQL_STATUS_QUERY_SENT,
MYSQL_STATUS_SENDING_LOAD_DATA,
MYSQL_STATUS_FETCHING_DATA,
MYSQL_STATUS_NEXT_RESULT_PENDING,
MYSQL_STATUS_QUIT_SENT, /* object is "destroyed" at this stage */
MYSQL_STATUS_STMT_RESULT
};
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_command;
char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name;
char *ssl_key; /* PEM key file */
char *ssl_cert; /* PEM cert file */
char *ssl_ca; /* PEM CA file */
char *ssl_capath; /* PEM directory of CA-s? */
char *ssl_cipher;
char *shared_memory_base_name;
unsigned long max_allowed_packet;
my_bool use_ssl; /* if to use SSL or not */
my_bool compress,named_pipe;
my_bool reconnect, unused_1, unused_2, unused_3;
enum mysql_option methods_to_use;
char *bind_address;
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;
};
typedef struct st_mysql {
NET net; /* Communication parameters */
void *unused_0;
char *host,*user,*passwd,*unix_socket,*server_version,*host_info;
char *info,*db;
const struct ma_charset_info_st *charset; /* character set */
MYSQL_FIELD *fields;
MA_MEM_ROOT field_alloc;
unsigned long long affected_rows;
unsigned long long insert_id; /* id if insert on table with NEXTNR */
unsigned long long extra_info; /* Used by mysqlshow */
unsigned long thread_id; /* Id for connection in server */
unsigned long packet_length;
unsigned int port;
unsigned long client_flag;
unsigned long server_capabilities;
unsigned int protocol_version;
unsigned int field_count;
unsigned int server_status;
unsigned int server_language;
unsigned int warning_count; /* warning count, added in 4.1 protocol */
struct st_mysql_options options;
enum mysql_status status;
my_bool free_me; /* If free in mysql_close */
my_bool unused_1;
char scramble_buff[20+ 1];
/* madded after 3.23.58 */
my_bool unused_2;
void *unused_3, *unused_4, *unused_5, *unused_6;
LIST *stmts;
const struct st_mariadb_methods *methods;
void *thd;
my_bool *unbuffered_fetch_owner;
char *info_buffer;
struct st_mariadb_extension *extension;
} MYSQL;
typedef struct st_mysql_res {
unsigned long long row_count;
unsigned int field_count, current_field;
MYSQL_FIELD *fields;
MYSQL_DATA *data;
MYSQL_ROWS *data_cursor;
MA_MEM_ROOT field_alloc;
MYSQL_ROW row; /* If unbuffered read */
MYSQL_ROW current_row; /* buffer to current row */
unsigned long *lengths; /* column lengths of current row */
MYSQL *handle; /* for unbuffered reads */
my_bool eof; /* Used my mysql_fetch_row */
my_bool is_ps;
} MYSQL_RES;
typedef struct
{
unsigned long *p_max_allowed_packet;
unsigned long *p_net_buffer_length;
void *extension;
} MYSQL_PARAMETERS;
enum mariadb_field_attr_t
{
MARIADB_FIELD_ATTR_DATA_TYPE_NAME= 0,
MARIADB_FIELD_ATTR_FORMAT_NAME= 1
};
#define MARIADB_FIELD_ATTR_LAST MARIADB_FIELD_ATTR_FORMAT_NAME
int STDCALL mariadb_field_attr(MARIADB_CONST_STRING *attr,
const MYSQL_FIELD *field,
enum mariadb_field_attr_t type);
#ifndef _mysql_time_h_
enum enum_mysql_timestamp_type
{
MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1,
MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2
};
typedef struct st_mysql_time
{
unsigned int year, month, day, hour, minute, second;
unsigned long second_part;
my_bool neg;
enum enum_mysql_timestamp_type time_type;
} MYSQL_TIME;
#define AUTO_SEC_PART_DIGITS 39
#endif
#define SEC_PART_DIGITS 6
#define MARIADB_INVALID_SOCKET -1
/* Asynchronous API constants */
#define MYSQL_WAIT_READ 1
#define MYSQL_WAIT_WRITE 2
#define MYSQL_WAIT_EXCEPT 4
#define MYSQL_WAIT_TIMEOUT 8
typedef struct character_set
{
unsigned int number; /* character set number */
unsigned int state; /* character set state */
const char *csname; /* character set name */
const char *name; /* collation name */
const char *comment; /* comment */
const char *dir; /* character set directory */
unsigned int mbminlen; /* min. length for multibyte strings */
unsigned int mbmaxlen; /* max. length for multibyte strings */
} MY_CHARSET_INFO;
/* Local infile support functions */
#define LOCAL_INFILE_ERROR_LEN 512
#include "mariadb_stmt.h"
#ifndef MYSQL_CLIENT_PLUGIN_HEADER
#define MYSQL_CLIENT_PLUGIN_HEADER \
int type; \
unsigned int interface_version; \
const char *name; \
const char *author; \
const char *desc; \
unsigned int version[3]; \
const char *license; \
void *mysql_api; \
int (*init)(char *, size_t, int, va_list); \
int (*deinit)(void); \
int (*options)(const char *option, const void *);
struct st_mysql_client_plugin
{
MYSQL_CLIENT_PLUGIN_HEADER
};
struct st_mysql_client_plugin *
mysql_load_plugin(struct st_mysql *mysql, const char *name, int type,
int argc, ...);
struct st_mysql_client_plugin * STDCALL
mysql_load_plugin_v(struct st_mysql *mysql, const char *name, int type,
int argc, va_list args);
struct st_mysql_client_plugin * STDCALL
mysql_client_find_plugin(struct st_mysql *mysql, const char *name, int type);
struct st_mysql_client_plugin * STDCALL
mysql_client_register_plugin(struct st_mysql *mysql,
struct st_mysql_client_plugin *plugin);
#endif
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 */
my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res);
unsigned int STDCALL mysql_num_fields(MYSQL_RES *res);
my_bool STDCALL mysql_eof(MYSQL_RES *res);
MYSQL_FIELD *STDCALL mysql_fetch_field_direct(MYSQL_RES *res,
unsigned int fieldnr);
MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res);
MYSQL_ROWS * STDCALL mysql_row_tell(MYSQL_RES *res);
unsigned int STDCALL mysql_field_tell(MYSQL_RES *res);
unsigned int STDCALL mysql_field_count(MYSQL *mysql);
my_bool STDCALL mysql_more_results(MYSQL *mysql);
int STDCALL mysql_next_result(MYSQL *mysql);
my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql);
my_bool STDCALL mysql_autocommit(MYSQL *mysql, my_bool mode);
my_bool STDCALL mysql_commit(MYSQL *mysql);
my_bool STDCALL mysql_rollback(MYSQL *mysql);
my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql);
unsigned int STDCALL mysql_errno(MYSQL *mysql);
const char * STDCALL mysql_error(MYSQL *mysql);
const char * STDCALL mysql_info(MYSQL *mysql);
unsigned long STDCALL mysql_thread_id(MYSQL *mysql);
const char * STDCALL mysql_character_set_name(MYSQL *mysql);
void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *cs);
int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname);
my_bool mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void *arg, ...);
my_bool STDCALL mariadb_get_info(MYSQL *mysql, enum mariadb_value value, void *arg);
MYSQL * STDCALL mysql_init(MYSQL *mysql);
int STDCALL mysql_ssl_set(MYSQL *mysql, const char *key,
const char *cert, const char *ca,
const char *capath, const char *cipher);
const char * STDCALL mysql_get_ssl_cipher(MYSQL *mysql);
my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
const char *passwd, const char *db);
MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
const char *user,
const char *passwd,
const char *db,
unsigned int port,
const char *unix_socket,
unsigned long clientflag);
void STDCALL mysql_close(MYSQL *sock);
int STDCALL mysql_select_db(MYSQL *mysql, const char *db);
int STDCALL mysql_query(MYSQL *mysql, const char *q);
int STDCALL mysql_send_query(MYSQL *mysql, const char *q,
unsigned long length);
my_bool STDCALL mysql_read_query_result(MYSQL *mysql);
int STDCALL mysql_real_query(MYSQL *mysql, const char *q,
unsigned long length);
int STDCALL mysql_shutdown(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level);
int STDCALL mysql_dump_debug_info(MYSQL *mysql);
int STDCALL mysql_refresh(MYSQL *mysql,
unsigned int refresh_options);
int STDCALL mysql_kill(MYSQL *mysql,unsigned long pid);
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_host_info(MYSQL *mysql);
unsigned int STDCALL mysql_get_proto_info(MYSQL *mysql);
MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild);
MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql,const char *wild);
MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table,
const char *wild);
MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql);
MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql);
MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql);
int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option,
const void *arg);
int STDCALL mysql_options4(MYSQL *mysql,enum mysql_option option,
const void *arg1, const void *arg2);
void STDCALL mysql_free_result(MYSQL_RES *result);
void STDCALL mysql_data_seek(MYSQL_RES *result,
unsigned long long offset);
MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result, MYSQL_ROW_OFFSET);
MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result,
MYSQL_FIELD_OFFSET offset);
MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result);
unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result);
MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *result);
unsigned long STDCALL mysql_escape_string(char *to,const char *from,
unsigned long from_length);
unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql,
char *to,const char *from,
unsigned long length);
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, 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);
my_bool STDCALL mariadb_connection(MYSQL *mysql);
const char * STDCALL mysql_get_server_name(MYSQL *mysql);
MARIADB_CHARSET_INFO * STDCALL mariadb_get_charset_by_name(const char *csname);
MARIADB_CHARSET_INFO * STDCALL mariadb_get_charset_by_nr(unsigned int csnr);
size_t STDCALL mariadb_convert_string(const char *from, size_t *from_len, MARIADB_CHARSET_INFO *from_cs,
char *to, size_t *to_len, MARIADB_CHARSET_INFO *to_cs, int *errorcode);
int mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...);
int mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...);
int STDCALL mysql_get_option(MYSQL *mysql, enum mysql_option option, void *arg);
unsigned long STDCALL mysql_hex_string(char *to, const char *from, unsigned long len);
my_socket STDCALL mysql_get_socket(MYSQL *mysql);
unsigned int STDCALL mysql_get_timeout_value(const MYSQL *mysql);
unsigned int STDCALL mysql_get_timeout_value_ms(const MYSQL *mysql);
my_bool STDCALL mariadb_reconnect(MYSQL *mysql);
int STDCALL mariadb_cancel(MYSQL *mysql);
void STDCALL mysql_debug(const char *debug);
unsigned long STDCALL mysql_net_read_packet(MYSQL *mysql);
unsigned long STDCALL mysql_net_field_length(unsigned char **packet);
my_bool STDCALL mysql_embedded(void);
MYSQL_PARAMETERS *STDCALL mysql_get_parameters(void);
/* Async API */
int STDCALL mysql_close_start(MYSQL *sock);
int STDCALL mysql_close_cont(MYSQL *sock, int status);
int STDCALL mysql_commit_start(my_bool *ret, MYSQL * mysql);
int STDCALL mysql_commit_cont(my_bool *ret, MYSQL * mysql, int status);
int STDCALL mysql_dump_debug_info_cont(int *ret, MYSQL *mysql, int ready_status);
int STDCALL mysql_dump_debug_info_start(int *ret, MYSQL *mysql);
int STDCALL mysql_rollback_start(my_bool *ret, MYSQL * mysql);
int STDCALL mysql_rollback_cont(my_bool *ret, MYSQL * mysql, int status);
int STDCALL mysql_autocommit_start(my_bool *ret, MYSQL * mysql,
my_bool auto_mode);
int STDCALL mysql_list_fields_cont(MYSQL_RES **ret, MYSQL *mysql, int ready_status);
int STDCALL mysql_list_fields_start(MYSQL_RES **ret, MYSQL *mysql, const char *table,
const char *wild);
int STDCALL mysql_autocommit_cont(my_bool *ret, MYSQL * mysql, int status);
int STDCALL mysql_next_result_start(int *ret, MYSQL *mysql);
int STDCALL mysql_next_result_cont(int *ret, MYSQL *mysql, int status);
int STDCALL mysql_select_db_start(int *ret, MYSQL *mysql, const char *db);
int STDCALL mysql_select_db_cont(int *ret, MYSQL *mysql, int ready_status);
int STDCALL mysql_stmt_warning_count(MYSQL_STMT *stmt);
int STDCALL mysql_stmt_next_result_start(int *ret, MYSQL_STMT *stmt);
int STDCALL mysql_stmt_next_result_cont(int *ret, MYSQL_STMT *stmt, int status);
int STDCALL mysql_set_character_set_start(int *ret, MYSQL *mysql,
const char *csname);
int STDCALL mysql_set_character_set_cont(int *ret, MYSQL *mysql,
int status);
int STDCALL mysql_change_user_start(my_bool *ret, MYSQL *mysql,
const char *user,
const char *passwd,
const char *db);
int STDCALL mysql_change_user_cont(my_bool *ret, MYSQL *mysql,
int status);
int STDCALL mysql_real_connect_start(MYSQL **ret, MYSQL *mysql,
const char *host,
const char *user,
const char *passwd,
const char *db,
unsigned int port,
const char *unix_socket,
unsigned long clientflag);
int STDCALL mysql_real_connect_cont(MYSQL **ret, MYSQL *mysql,
int status);
int STDCALL mysql_query_start(int *ret, MYSQL *mysql,
const char *q);
int STDCALL mysql_query_cont(int *ret, MYSQL *mysql,
int status);
int STDCALL mysql_send_query_start(int *ret, MYSQL *mysql,
const char *q,
unsigned long length);
int STDCALL mysql_send_query_cont(int *ret, MYSQL *mysql, int status);
int STDCALL mysql_real_query_start(int *ret, MYSQL *mysql,
const char *q,
unsigned long length);
int STDCALL mysql_real_query_cont(int *ret, MYSQL *mysql,
int status);
int STDCALL mysql_store_result_start(MYSQL_RES **ret, MYSQL *mysql);
int STDCALL mysql_store_result_cont(MYSQL_RES **ret, MYSQL *mysql,
int status);
int STDCALL mysql_shutdown_start(int *ret, MYSQL *mysql,
enum mysql_enum_shutdown_level
shutdown_level);
int STDCALL mysql_shutdown_cont(int *ret, MYSQL *mysql,
int status);
int STDCALL mysql_refresh_start(int *ret, MYSQL *mysql,
unsigned int refresh_options);
int STDCALL mysql_refresh_cont(int *ret, MYSQL *mysql, int status);
int STDCALL mysql_kill_start(int *ret, MYSQL *mysql,
unsigned long pid);
int STDCALL mysql_kill_cont(int *ret, MYSQL *mysql, int status);
int STDCALL mysql_set_server_option_start(int *ret, MYSQL *mysql,
enum enum_mysql_set_option
option);
int STDCALL mysql_set_server_option_cont(int *ret, MYSQL *mysql,
int status);
int STDCALL mysql_ping_start(int *ret, MYSQL *mysql);
int STDCALL mysql_ping_cont(int *ret, MYSQL *mysql, int status);
int STDCALL mysql_stat_start(const char **ret, MYSQL *mysql);
int STDCALL mysql_stat_cont(const char **ret, MYSQL *mysql,
int status);
int STDCALL mysql_free_result_start(MYSQL_RES *result);
int STDCALL mysql_free_result_cont(MYSQL_RES *result, int status);
int STDCALL mysql_fetch_row_start(MYSQL_ROW *ret,
MYSQL_RES *result);
int STDCALL mysql_fetch_row_cont(MYSQL_ROW *ret, MYSQL_RES *result,
int status);
int STDCALL mysql_read_query_result_start(my_bool *ret,
MYSQL *mysql);
int STDCALL mysql_read_query_result_cont(my_bool *ret,
MYSQL *mysql, int status);
int STDCALL mysql_reset_connection_start(int *ret, MYSQL *mysql);
int STDCALL mysql_reset_connection_cont(int *ret, MYSQL *mysql, int status);
int STDCALL mysql_session_track_get_next(MYSQL *mysql, enum enum_session_state_type type, const char **data, size_t *length);
int STDCALL mysql_session_track_get_first(MYSQL *mysql, enum enum_session_state_type type, const char **data, size_t *length);
int STDCALL mysql_stmt_prepare_start(int *ret, MYSQL_STMT *stmt,const char *query, unsigned long length);
int STDCALL mysql_stmt_prepare_cont(int *ret, MYSQL_STMT *stmt, int status);
int STDCALL mysql_stmt_execute_start(int *ret, MYSQL_STMT *stmt);
int STDCALL mysql_stmt_execute_cont(int *ret, MYSQL_STMT *stmt, int status);
int STDCALL mysql_stmt_fetch_start(int *ret, MYSQL_STMT *stmt);
int STDCALL mysql_stmt_fetch_cont(int *ret, MYSQL_STMT *stmt, int status);
int STDCALL mysql_stmt_store_result_start(int *ret, MYSQL_STMT *stmt);
int STDCALL mysql_stmt_store_result_cont(int *ret, MYSQL_STMT *stmt,int status);
int STDCALL mysql_stmt_close_start(my_bool *ret, MYSQL_STMT *stmt);
int STDCALL mysql_stmt_close_cont(my_bool *ret, MYSQL_STMT * stmt, int status);
int STDCALL mysql_stmt_reset_start(my_bool *ret, MYSQL_STMT * stmt);
int STDCALL mysql_stmt_reset_cont(my_bool *ret, MYSQL_STMT *stmt, int status);
int STDCALL mysql_stmt_free_result_start(my_bool *ret, MYSQL_STMT *stmt);
int STDCALL mysql_stmt_free_result_cont(my_bool *ret, MYSQL_STMT *stmt,
int status);
int STDCALL mysql_stmt_send_long_data_start(my_bool *ret, MYSQL_STMT *stmt,
unsigned int param_number,
const char *data,
unsigned long len);
int STDCALL mysql_stmt_send_long_data_cont(my_bool *ret, MYSQL_STMT *stmt,
int status);
int STDCALL mysql_reset_connection(MYSQL *mysql);
/* API function calls (used by dynamic plugins) */
struct st_mariadb_api {
unsigned long long (STDCALL *mysql_num_rows)(MYSQL_RES *res);
unsigned int (STDCALL *mysql_num_fields)(MYSQL_RES *res);
my_bool (STDCALL *mysql_eof)(MYSQL_RES *res);
MYSQL_FIELD *(STDCALL *mysql_fetch_field_direct)(MYSQL_RES *res, unsigned int fieldnr);
MYSQL_FIELD * (STDCALL *mysql_fetch_fields)(MYSQL_RES *res);
MYSQL_ROWS * (STDCALL *mysql_row_tell)(MYSQL_RES *res);
unsigned int (STDCALL *mysql_field_tell)(MYSQL_RES *res);
unsigned int (STDCALL *mysql_field_count)(MYSQL *mysql);
my_bool (STDCALL *mysql_more_results)(MYSQL *mysql);
int (STDCALL *mysql_next_result)(MYSQL *mysql);
unsigned long long (STDCALL *mysql_affected_rows)(MYSQL *mysql);
my_bool (STDCALL *mysql_autocommit)(MYSQL *mysql, my_bool mode);
my_bool (STDCALL *mysql_commit)(MYSQL *mysql);
my_bool (STDCALL *mysql_rollback)(MYSQL *mysql);
unsigned long long (STDCALL *mysql_insert_id)(MYSQL *mysql);
unsigned int (STDCALL *mysql_errno)(MYSQL *mysql);
const char * (STDCALL *mysql_error)(MYSQL *mysql);
const char * (STDCALL *mysql_info)(MYSQL *mysql);
unsigned long (STDCALL *mysql_thread_id)(MYSQL *mysql);
const char * (STDCALL *mysql_character_set_name)(MYSQL *mysql);
void (STDCALL *mysql_get_character_set_info)(MYSQL *mysql, MY_CHARSET_INFO *cs);
int (STDCALL *mysql_set_character_set)(MYSQL *mysql, const char *csname);
my_bool (*mariadb_get_infov)(MYSQL *mysql, enum mariadb_value value, void *arg, ...);
my_bool (STDCALL *mariadb_get_info)(MYSQL *mysql, enum mariadb_value value, void *arg);
MYSQL * (STDCALL *mysql_init)(MYSQL *mysql);
int (STDCALL *mysql_ssl_set)(MYSQL *mysql, const char *key, const char *cert, const char *ca, const char *capath, const char *cipher);
const char * (STDCALL *mysql_get_ssl_cipher)(MYSQL *mysql);
my_bool (STDCALL *mysql_change_user)(MYSQL *mysql, const char *user, const char *passwd, const char *db);
MYSQL * (STDCALL *mysql_real_connect)(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long clientflag);
void (STDCALL *mysql_close)(MYSQL *sock);
int (STDCALL *mysql_select_db)(MYSQL *mysql, const char *db);
int (STDCALL *mysql_query)(MYSQL *mysql, const char *q);
int (STDCALL *mysql_send_query)(MYSQL *mysql, const char *q, unsigned long length);
my_bool (STDCALL *mysql_read_query_result)(MYSQL *mysql);
int (STDCALL *mysql_real_query)(MYSQL *mysql, const char *q, unsigned long length);
int (STDCALL *mysql_shutdown)(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level);
int (STDCALL *mysql_dump_debug_info)(MYSQL *mysql);
int (STDCALL *mysql_refresh)(MYSQL *mysql, unsigned int refresh_options);
int (STDCALL *mysql_kill)(MYSQL *mysql,unsigned long pid);
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_host_info)(MYSQL *mysql);
unsigned int (STDCALL *mysql_get_proto_info)(MYSQL *mysql);
MYSQL_RES * (STDCALL *mysql_list_dbs)(MYSQL *mysql,const char *wild);
MYSQL_RES * (STDCALL *mysql_list_tables)(MYSQL *mysql,const char *wild);
MYSQL_RES * (STDCALL *mysql_list_fields)(MYSQL *mysql, const char *table, const char *wild);
MYSQL_RES * (STDCALL *mysql_list_processes)(MYSQL *mysql);
MYSQL_RES * (STDCALL *mysql_store_result)(MYSQL *mysql);
MYSQL_RES * (STDCALL *mysql_use_result)(MYSQL *mysql);
int (STDCALL *mysql_options)(MYSQL *mysql,enum mysql_option option, const void *arg);
void (STDCALL *mysql_free_result)(MYSQL_RES *result);
void (STDCALL *mysql_data_seek)(MYSQL_RES *result, unsigned long long offset);
MYSQL_ROW_OFFSET (STDCALL *mysql_row_seek)(MYSQL_RES *result, MYSQL_ROW_OFFSET);
MYSQL_FIELD_OFFSET (STDCALL *mysql_field_seek)(MYSQL_RES *result, MYSQL_FIELD_OFFSET offset);
MYSQL_ROW (STDCALL *mysql_fetch_row)(MYSQL_RES *result);
unsigned long * (STDCALL *mysql_fetch_lengths)(MYSQL_RES *result);
MYSQL_FIELD * (STDCALL *mysql_fetch_field)(MYSQL_RES *result);
unsigned long (STDCALL *mysql_escape_string)(char *to,const char *from, unsigned long from_length);
unsigned long (STDCALL *mysql_real_escape_string)(MYSQL *mysql, char *to,const char *from, unsigned long length);
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, 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);
my_bool (STDCALL *mariadb_connection)(MYSQL *mysql);
const char * (STDCALL *mysql_get_server_name)(MYSQL *mysql);
MARIADB_CHARSET_INFO * (STDCALL *mariadb_get_charset_by_name)(const char *csname);
MARIADB_CHARSET_INFO * (STDCALL *mariadb_get_charset_by_nr)(unsigned int csnr);
size_t (STDCALL *mariadb_convert_string)(const char *from, size_t *from_len, MARIADB_CHARSET_INFO *from_cs, char *to, size_t *to_len, MARIADB_CHARSET_INFO *to_cs, int *errorcode);
int (*mysql_optionsv)(MYSQL *mysql,enum mysql_option option, ...);
int (*mysql_get_optionv)(MYSQL *mysql, enum mysql_option option, void *arg, ...);
int (STDCALL *mysql_get_option)(MYSQL *mysql, enum mysql_option option, void *arg);
unsigned long (STDCALL *mysql_hex_string)(char *to, const char *from, unsigned long len);
my_socket (STDCALL *mysql_get_socket)(MYSQL *mysql);
unsigned int (STDCALL *mysql_get_timeout_value)(const MYSQL *mysql);
unsigned int (STDCALL *mysql_get_timeout_value_ms)(const MYSQL *mysql);
my_bool (STDCALL *mariadb_reconnect)(MYSQL *mysql);
MYSQL_STMT * (STDCALL *mysql_stmt_init)(MYSQL *mysql);
int (STDCALL *mysql_stmt_prepare)(MYSQL_STMT *stmt, const char *query, unsigned long length);
int (STDCALL *mysql_stmt_execute)(MYSQL_STMT *stmt);
int (STDCALL *mysql_stmt_fetch)(MYSQL_STMT *stmt);
int (STDCALL *mysql_stmt_fetch_column)(MYSQL_STMT *stmt, MYSQL_BIND *bind_arg, unsigned int column, unsigned long offset);
int (STDCALL *mysql_stmt_store_result)(MYSQL_STMT *stmt);
unsigned long (STDCALL *mysql_stmt_param_count)(MYSQL_STMT * stmt);
my_bool (STDCALL *mysql_stmt_attr_set)(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, const void *attr);
my_bool (STDCALL *mysql_stmt_attr_get)(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, void *attr);
my_bool (STDCALL *mysql_stmt_bind_param)(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
my_bool (STDCALL *mysql_stmt_bind_result)(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
my_bool (STDCALL *mysql_stmt_close)(MYSQL_STMT * stmt);
my_bool (STDCALL *mysql_stmt_reset)(MYSQL_STMT * stmt);
my_bool (STDCALL *mysql_stmt_free_result)(MYSQL_STMT *stmt);
my_bool (STDCALL *mysql_stmt_send_long_data)(MYSQL_STMT *stmt, unsigned int param_number, const char *data, unsigned long length);
MYSQL_RES *(STDCALL *mysql_stmt_result_metadata)(MYSQL_STMT *stmt);
MYSQL_RES *(STDCALL *mysql_stmt_param_metadata)(MYSQL_STMT *stmt);
unsigned int (STDCALL *mysql_stmt_errno)(MYSQL_STMT * stmt);
const char *(STDCALL *mysql_stmt_error)(MYSQL_STMT * stmt);
const char *(STDCALL *mysql_stmt_sqlstate)(MYSQL_STMT * stmt);
MYSQL_ROW_OFFSET (STDCALL *mysql_stmt_row_seek)(MYSQL_STMT *stmt, MYSQL_ROW_OFFSET offset);
MYSQL_ROW_OFFSET (STDCALL *mysql_stmt_row_tell)(MYSQL_STMT *stmt);
void (STDCALL *mysql_stmt_data_seek)(MYSQL_STMT *stmt, unsigned long long offset);
unsigned long long (STDCALL *mysql_stmt_num_rows)(MYSQL_STMT *stmt);
unsigned long long (STDCALL *mysql_stmt_affected_rows)(MYSQL_STMT *stmt);
unsigned long long (STDCALL *mysql_stmt_insert_id)(MYSQL_STMT *stmt);
unsigned int (STDCALL *mysql_stmt_field_count)(MYSQL_STMT *stmt);
int (STDCALL *mysql_stmt_next_result)(MYSQL_STMT *stmt);
my_bool (STDCALL *mysql_stmt_more_results)(MYSQL_STMT *stmt);
int (STDCALL *mariadb_stmt_execute_direct)(MYSQL_STMT *stmt, const char *stmtstr, size_t length);
int (STDCALL *mysql_reset_connection)(MYSQL *mysql);
};
/* these methods can be overwritten by db plugins */
struct st_mariadb_methods {
MYSQL *(*db_connect)(MYSQL *mysql, const char *host, const char *user, const char *passwd,
const char *db, unsigned int port, const char *unix_socket, unsigned long clientflag);
void (*db_close)(MYSQL *mysql);
int (*db_command)(MYSQL *mysql,enum enum_server_command command, const char *arg,
size_t length, my_bool skipp_check, void *opt_arg);
void (*db_skip_result)(MYSQL *mysql);
int (*db_read_query_result)(MYSQL *mysql);
MYSQL_DATA *(*db_read_rows)(MYSQL *mysql,MYSQL_FIELD *fields, unsigned int field_count);
int (*db_read_one_row)(MYSQL *mysql,unsigned int fields,MYSQL_ROW row, unsigned long *lengths);
/* prepared statements */
my_bool (*db_supported_buffer_type)(enum enum_field_types type);
my_bool (*db_read_prepare_response)(MYSQL_STMT *stmt);
int (*db_read_stmt_result)(MYSQL *mysql);
my_bool (*db_stmt_get_result_metadata)(MYSQL_STMT *stmt);
my_bool (*db_stmt_get_param_metadata)(MYSQL_STMT *stmt);
int (*db_stmt_read_all_rows)(MYSQL_STMT *stmt);
int (*db_stmt_fetch)(MYSQL_STMT *stmt, unsigned char **row);
int (*db_stmt_fetch_to_bind)(MYSQL_STMT *stmt, unsigned char *row);
void (*db_stmt_flush_unbuffered)(MYSQL_STMT *stmt);
void (*set_error)(MYSQL *mysql, unsigned int error_nr, const char *sqlstate, const char *format, ...);
void (*invalidate_stmts)(MYSQL *mysql, const char *function_name);
struct st_mariadb_api *api;
int (*db_read_execute_response)(MYSQL_STMT *stmt);
};
/* synonyms/aliases functions */
#define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
#define mysql_library_init mysql_server_init
#define mysql_library_end mysql_server_end
/* new api functions */
#define HAVE_MYSQL_REAL_CONNECT
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,244 @@
/* Copyright (C) 2010 - 2012 Sergei Golubchik and Monty Program Ab
2014 MariaDB Corporation 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 <http://www.gnu.org/licenses>
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 <stdarg.h>
#include <stdlib.h>
#endif
#ifndef PLUGINDIR
#define PLUGINDIR "lib/plugin"
#endif
#define plugin_declarations_sym "_mysql_client_plugin_declaration_"
/* known plugin types */
#define MYSQL_CLIENT_PLUGIN_RESERVED 0
#define MYSQL_CLIENT_PLUGIN_RESERVED2 1
#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN 2 /* authentication */
#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION 0x0100
#define MYSQL_CLIENT_MAX_PLUGINS 3
/* Connector/C specific plugin types */
#define MARIADB_CLIENT_REMOTEIO_PLUGIN 100 /* communication IO */
#define MARIADB_CLIENT_PVIO_PLUGIN 101
#define MARIADB_CLIENT_TRACE_PLUGIN 102
#define MARIADB_CLIENT_CONNECTION_PLUGIN 103
#define MARIADB_CLIENT_REMOTEIO_PLUGIN_INTERFACE_VERSION 0x0100
#define MARIADB_CLIENT_PVIO_PLUGIN_INTERFACE_VERSION 0x0100
#define MARIADB_CLIENT_TRACE_PLUGIN_INTERFACE_VERSION 0x0100
#define MARIADB_CLIENT_CONNECTION_PLUGIN_INTERFACE_VERSION 0x0100
#define MARIADB_CLIENT_MAX_PLUGINS 4
#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 */
#ifndef MYSQL_CLIENT_PLUGIN_HEADER
#define MYSQL_CLIENT_PLUGIN_HEADER \
int type; \
unsigned int interface_version; \
const char *name; \
const char *author; \
const char *desc; \
unsigned int version[3]; \
const char *license; \
void *mysql_api; \
int (*init)(char *, size_t, int, va_list); \
int (*deinit)(void); \
int (*options)(const char *option, const void *);
struct st_mysql_client_plugin
{
MYSQL_CLIENT_PLUGIN_HEADER
};
#endif
struct st_mysql;
/********* connection handler plugin specific declarations **********/
typedef struct st_ma_connection_plugin
{
MYSQL_CLIENT_PLUGIN_HEADER
/* functions */
MYSQL *(*connect)(MYSQL *mysql, const char *host,
const char *user, const char *passwd,
const char *db, unsigned int port,
const char *unix_socket, unsigned long clientflag);
void (*close)(MYSQL *mysql);
int (*set_optionsv)(MYSQL *mysql, unsigned int option, ...);
int (*set_connection)(MYSQL *mysql,enum enum_server_command command,
const char *arg,
size_t length, my_bool skipp_check, void *opt_arg);
my_bool (*reconnect)(MYSQL *mysql);
int (*reset)(MYSQL *mysql);
} MARIADB_CONNECTION_PLUGIN;
#define MARIADB_DB_DRIVER(a) ((a)->ext_db)
/******************* Communication IO plugin *****************/
#include <ma_pvio.h>
typedef struct st_mariadb_client_plugin_PVIO
{
MYSQL_CLIENT_PLUGIN_HEADER
struct st_ma_pvio_methods *methods;
} MARIADB_PVIO_PLUGIN;
/******** authentication plugin specific declarations *********/
#include <mysql/plugin_auth_common.h>
struct st_mysql_client_plugin_AUTHENTICATION
{
MYSQL_CLIENT_PLUGIN_HEADER
int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql);
};
/******** trace plugin *******/
struct st_mysql_client_plugin_TRACE
{
MYSQL_CLIENT_PLUGIN_HEADER
};
/**
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);
/********************** remote IO plugin **********************/
#ifdef HAVE_REMOTEIO
#include <mariadb/ma_io.h>
/* Remote IO plugin */
typedef struct st_mysql_client_plugin_REMOTEIO
{
MYSQL_CLIENT_PLUGIN_HEADER
struct st_rio_methods *methods;
} MARIADB_REMOTEIO_PLUGIN;
#endif
/******** 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 * STDCALL
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 * STDCALL
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 * STDCALL
mysql_client_register_plugin(struct st_mysql *mysql,
struct st_mysql_client_plugin *plugin);
extern struct st_mysql_client_plugin *mysql_client_builtins[];
#endif

107
vendor/MDBC/include/mysql/plugin_auth.h vendored Normal file
View File

@ -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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, 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 512
/**
return values of the plugin authenticate_user() method.
*/
/**
Authentication failed. Additionally, all other CR_xxx values
(libmariadb 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 libmariadb 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, libmariadb 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

View File

@ -0,0 +1,110 @@
/* 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
#ifndef MYSQL_PLUGIN_AUTH_COMMON_INCLUDED
/**
@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 512
/**
return values of the plugin authenticate_user() method.
*/
/**
Authentication failed. Additionally, all other CR_xxx values
(libmariadb 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 libmariadb 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, libmariadb 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;
#ifndef _WIN32
int socket; /**< it's set, if the protocol is SOCKET or TCP */
#else
SOCKET socket; /**< it's set, if the protocol is SOCKET or TCP */
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

1225
vendor/MDBC/include/mysqld_error.h vendored Normal file

File diff suppressed because it is too large Load Diff

470
vendor/MDBC/libmariadb/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,470 @@
INCLUDE_DIRECTORIES(${CC_SOURCE_DIR}/include
${CC_SOURCE_DIR}/libmariadb)
ADD_DEFINITIONS(-D HAVE_COMPRESS)
ADD_DEFINITIONS(-D LIBMARIADB)
ADD_DEFINITIONS(-D THREAD)
INCLUDE(${CC_SOURCE_DIR}/cmake/sign.cmake)
SET(MARIADB_LIB_SYMBOLS
mariadb_cancel
mariadb_connection
mariadb_convert_string
ma_pvio_register_callback
mariadb_get_charset_by_name
mariadb_stmt_execute_direct
mariadb_get_charset_by_nr
mariadb_get_info
mariadb_get_infov
mysql_get_timeout_value
mysql_get_timeout_value_ms
mysql_optionsv
mysql_ps_fetch_functions
mariadb_reconnect
mysql_stmt_warning_count
mariadb_stmt_fetch_fields
mariadb_rpl_open
mariadb_rpl_close
mariadb_rpl_fetch
mariadb_rpl_optionsv
mariadb_rpl_get_optionsv
mariadb_rpl_init_ex
mariadb_free_rpl_event
mariadb_field_attr
)
IF(WITH_SSL)
SET(MARIADB_LIB_SYMBOLS ${MARIADB_LIB_SYMBOLS} mariadb_deinitialize_ssl)
ENDIF()
SET(MYSQL_LIB_SYMBOLS
mysql_affected_rows
mysql_autocommit
mysql_change_user
mysql_character_set_name
mysql_client_find_plugin
mysql_client_register_plugin
mysql_close
mysql_commit
mysql_data_seek
mysql_debug
mysql_dump_debug_info
mysql_embedded
mysql_eof
mysql_errno
mysql_error
mysql_escape_string
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_character_set_info
mysql_get_charset_by_name
mysql_get_charset_by_nr
mysql_get_client_info
mysql_get_client_version
mysql_get_host_info
mysql_get_option
mysql_get_optionv
mysql_get_parameters
mysql_get_proto_info
mysql_get_server_info
mysql_get_server_name
mysql_get_server_version
mysql_get_socket
mysql_get_ssl_cipher
mysql_hex_string
mysql_info
mysql_init
mysql_insert_id
mysql_kill
mysql_list_dbs
mysql_list_fields
mysql_list_processes
mysql_list_tables
mysql_load_plugin
mysql_load_plugin_v
mysql_more_results
mysql_net_field_length
mysql_net_read_packet
mysql_next_result
mysql_num_fields
mysql_num_rows
mysql_options
mysql_options4
mysql_ping
mysql_query
mysql_read_query_result
mysql_real_connect
mysql_real_escape_string
mysql_real_query
mysql_refresh
mysql_reset_connection
mysql_rollback
mysql_row_seek
mysql_row_tell
mysql_select_db
mysql_send_query
mysql_server_end
mysql_server_init
mysql_session_track_get_next
mysql_session_track_get_first
mysql_set_character_set
mysql_set_local_infile_default
mysql_set_local_infile_handler
mysql_set_server_option
mysql_shutdown
mysql_sqlstate
mysql_ssl_set
mysql_stat
mysql_stmt_affected_rows
mysql_stmt_attr_get
mysql_stmt_attr_set
mysql_stmt_bind_param
mysql_stmt_bind_result
mysql_stmt_close
mysql_stmt_data_seek
mysql_stmt_errno
mysql_stmt_error
mysql_stmt_execute
mysql_stmt_fetch
mysql_stmt_fetch_column
mysql_stmt_field_count
mysql_stmt_free_result
mysql_stmt_init
mysql_stmt_insert_id
mysql_stmt_more_results
mysql_stmt_next_result
mysql_stmt_num_rows
mysql_stmt_param_count
mysql_stmt_param_metadata
mysql_stmt_prepare
mysql_stmt_reset
mysql_stmt_result_metadata
mysql_stmt_row_seek
mysql_stmt_row_tell
mysql_stmt_send_long_data
mysql_stmt_sqlstate
mysql_stmt_store_result
mysql_store_result
mysql_thread_end
mysql_thread_id
mysql_thread_init
mysql_thread_safe
mysql_use_result
mysql_warning_count)
# some gcc versions fail to compile asm parts of my_context.c,
# if build type is "Release" (see CONC-133), so we need to add -g flag
IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_BUILD_TYPE MATCHES "Release")
SET_SOURCE_FILES_PROPERTIES(my_context.c PROPERTIES COMPILE_FLAGS -g)
ENDIF()
SET(MARIADB_DYNCOL_SYMBOLS
mariadb_dyncol_check
mariadb_dyncol_column_cmp_named
mariadb_dyncol_column_count
mariadb_dyncol_create_many_named
mariadb_dyncol_create_many_num
mariadb_dyncol_exists_named
mariadb_dyncol_exists_num
mariadb_dyncol_free
mariadb_dyncol_get_named
mariadb_dyncol_get_num
mariadb_dyncol_has_names
mariadb_dyncol_json
mariadb_dyncol_list_named
mariadb_dyncol_list_num
mariadb_dyncol_unpack
mariadb_dyncol_update_many_named
mariadb_dyncol_update_many_num
mariadb_dyncol_val_double
mariadb_dyncol_val_long
mariadb_dyncol_val_str)
SET(MARIADB_NONBLOCK_SYMBOLS
mysql_autocommit_cont
mysql_autocommit_start
mysql_change_user_cont
mysql_change_user_start
mysql_close_cont
mysql_close_start
mysql_commit_cont
mysql_commit_start
mysql_dump_debug_info_cont
mysql_dump_debug_info_start
mysql_fetch_row_cont
mysql_fetch_row_start
mysql_free_result_cont
mysql_free_result_start
mysql_kill_cont
mysql_kill_start
mysql_list_fields_cont
mysql_list_fields_start
mysql_next_result_cont
mysql_next_result_start
mysql_ping_cont
mysql_ping_start
mysql_reset_connection_start
mysql_reset_connection_cont
mysql_query_cont
mysql_query_start
mysql_read_query_result_cont
mysql_read_query_result_start
mysql_real_connect_cont
mysql_real_connect_start
mysql_real_query_cont
mysql_real_query_start
mysql_refresh_cont
mysql_refresh_start
mysql_rollback_cont
mysql_rollback_start
mysql_select_db_cont
mysql_select_db_start
mysql_send_query_cont
mysql_send_query_start
mysql_set_character_set_cont
mysql_set_character_set_start
mysql_set_server_option_cont
mysql_set_server_option_start
mysql_shutdown_cont
mysql_shutdown_start
mysql_stat_cont
mysql_stat_start
mysql_stmt_close_cont
mysql_stmt_close_start
mysql_stmt_execute_cont
mysql_stmt_execute_start
mysql_stmt_fetch_cont
mysql_stmt_fetch_start
mysql_stmt_free_result_cont
mysql_stmt_free_result_start
mysql_stmt_next_result_cont
mysql_stmt_next_result_start
mysql_stmt_prepare_cont
mysql_stmt_prepare_start
mysql_stmt_reset_cont
mysql_stmt_reset_start
mysql_stmt_send_long_data_cont
mysql_stmt_send_long_data_start
mysql_stmt_store_result_cont
mysql_stmt_store_result_start
mysql_store_result_cont
mysql_store_result_start
)
# handle static plugins
SET(LIBMARIADB_SOURCES ${LIBMARIADB_PLUGIN_SOURCES})
SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${LIBMARIADB_PLUGIN_LIBS} ${INTERNAL_ZLIB_LIBRARY})
ADD_DEFINITIONS(${LIBMARIADB_PLUGIN_DEFS})
FOREACH(plugin ${PLUGINS_STATIC})
SET(EXTERNAL_PLUGINS "${EXTERNAL_PLUGINS} extern struct st_mysql_client_plugin ${plugin}_client_plugin;\n")
SET(BUILTIN_PLUGINS "${BUILTIN_PLUGINS} (struct st_mysql_client_plugin *)&${plugin}_client_plugin,\n")
ENDFOREACH()
CONFIGURE_FILE(${CC_SOURCE_DIR}/libmariadb/ma_client_plugin.c.in
${CC_BINARY_DIR}/libmariadb/ma_client_plugin.c)
SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES}
${CC_SOURCE_DIR}/plugins/auth/my_auth.c
ma_array.c
ma_charset.c
ma_hashtbl.c
ma_net.c
mariadb_charset.c
ma_time.c
ma_default.c
ma_errmsg.c
mariadb_lib.c
ma_list.c
ma_pvio.c
ma_tls.c
ma_alloc.c
ma_compress.c
ma_init.c
ma_password.c
ma_ll2str.c
ma_sha1.c
mariadb_stmt.c
ma_loaddata.c
ma_stmt_codec.c
ma_string.c
ma_dtoa.c
mariadb_rpl.c
${CC_BINARY_DIR}/libmariadb/ma_client_plugin.c
ma_io.c
${SSL_SOURCES}
)
IF(WIN32)
ADD_DEFINITIONS(-DSIZEOF_CHARP=${CMAKE_SIZEOF_VOID_P})
INCLUDE_DIRECTORIES(${CC_SOURCE_DIR}/win-iconv)
SET(LIBMARIADB_SOURCES
${LIBMARIADB_SOURCES}
${CC_SOURCE_DIR}/win-iconv/win_iconv.c
win32_errmsg.c
win32_errmsg.h)
ELSE()
IF(ICONV_INCLUDE_DIR)
INCLUDE_DIRECTORIES(BEFORE ${ICONV_INCLUDE_DIR})
ENDIF()
IF(NOT CMAKE_SYSTEM_NAME MATCHES AIX)
ADD_DEFINITIONS(-DLIBICONV_PLUG)
ENDIF()
ENDIF()
IF(ZLIB_FOUND AND WITH_EXTERNAL_ZLIB)
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
ELSE()
SET(ZLIB_SOURCES
../zlib/adler32.c
../zlib/compress.c
../zlib/crc32.c
../zlib/deflate.c
../zlib/gzclose.c
../zlib/gzlib.c
../zlib/gzread.c
../zlib/gzwrite.c
../zlib/infback.c
../zlib/inffast.c
../zlib/inflate.c
../zlib/inftrees.c
../zlib/trees.c
../zlib/uncompr.c
../zlib/zutil.c
)
SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} ${ZLIB_SOURCES})
INCLUDE_DIRECTORIES(${CC_SOURCE_DIR}/zlib)
ENDIF()
IF(WITH_DYNCOL)
MESSAGE1(WITH_DYNCOL "Dynamic column API support: ON")
SET(MARIADB_LIB_SYMBOLS ${MARIADB_LIB_SYMBOLS} ${MARIADB_DYNCOL_SYMBOLS})
SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} mariadb_dyncol.c)
ENDIF()
SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} mariadb_async.c ma_context.c)
SET(MARIADB_LIB_SYMBOLS ${MARIADB_LIB_SYMBOLS} ${MARIADB_NONBLOCK_SYMBOLS})
INCLUDE(${CC_SOURCE_DIR}/cmake/export.cmake)
IF(NOT WIN32)
CREATE_EXPORT_FILE(WRITE mariadbclient.def
"libmysqlclient_18"
"${MYSQL_LIB_SYMBOLS}"
"libmariadbclient_18")
CREATE_EXPORT_FILE(APPEND mariadbclient.def
"libmariadb_3"
"${MARIADB_LIB_SYMBOLS}"
"")
ELSE()
CREATE_EXPORT_FILE(WRITE mariadbclient.def
"libmariadb_3"
"${MARIADB_LIB_SYMBOLS};${MYSQL_LIB_SYMBOLS}"
"")
ENDIF()
IF(CMAKE_VERSION VERSION_GREATER 2.8.7)
# CREATE OBJECT LIBRARY
ADD_LIBRARY(mariadb_obj OBJECT ${LIBMARIADB_SOURCES})
IF(UNIX)
SET_TARGET_PROPERTIES(mariadb_obj PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}")
ENDIF()
SET (MARIADB_OBJECTS $<TARGET_OBJECTS:mariadb_obj>)
ELSE()
SET (MARIADB_OBJECTS ${LIBMARIADB_SOURCES})
ENDIF()
# Xcode doesn't support targets that have only object files,
# so let's add an empty file to keep Xcode happy
IF(CMAKE_GENERATOR MATCHES Xcode)
FILE(WRITE ${CC_BINARY_DIR}/libmariadb/empty.c "")
SET(EMPTY_FILE ${CC_BINARY_DIR}/libmariadb/empty.c)
ENDIF()
#* create file with list of functions */
FILE(WRITE ${CC_BINARY_DIR}/manpages.list "${MARIADB_LIB_SYMBOLS};${MYSQL_LIB_SYMBOLS}")
IF(WIN32)
SET_VERSION_INFO("TARGET:libmariadb"
"FILE_TYPE:VFT_DLL"
"SOURCE_FILE:libmariadb/libmariadb.c"
"ORIGINAL_FILE_NAME:libmariadb.dll"
"FILE_DESCRIPTION:Dynamic lib for client/server communication")
ENDIF()
ADD_LIBRARY(mariadbclient STATIC ${MARIADB_OBJECTS} ${EMPTY_FILE})
TARGET_LINK_LIBRARIES(mariadbclient ${SYSTEM_LIBS})
IF(UNIX)
ADD_LIBRARY(libmariadb SHARED ${libmariadb_RC} ${MARIADB_OBJECTS} ${EMPTY_FILE})
SET_TARGET_PROPERTIES(libmariadb PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}")
ELSE()
ADD_LIBRARY(libmariadb SHARED ${libmariadb_RC} ${MARIADB_OBJECTS} mariadbclient.def)
SET_TARGET_PROPERTIES(libmariadb PROPERTIES LINKER_LANGUAGE C)
ENDIF()
TARGET_LINK_LIBRARIES(libmariadb LINK_PRIVATE ${SYSTEM_LIBS})
SIGN_TARGET(libmariadb)
IF(CMAKE_SYSTEM_NAME MATCHES "Linux" OR
CMAKE_SYSTEM_NAME MATCHES "kFreeBSD" OR
CMAKE_SYSTEM_NAME MATCHES "GNU")
IF (NOT WITH_ASAN AND NOT WITH_TSAN AND NOT WITH_UBSAN AND NOT WITH_MSAN)
TARGET_LINK_LIBRARIES (libmariadb LINK_PRIVATE "-Wl,--no-undefined")
ENDIF()
SET_TARGET_PROPERTIES(libmariadb PROPERTIES LINK_FLAGS "${CC_BINARY_DIR}/libmariadb/mariadbclient.def")
ENDIF()
SET_TARGET_PROPERTIES(mariadbclient PROPERTIES IMPORTED_INTERFACE_LINK_LIBRARIES "${SYSTEM_LIBS}")
SET_TARGET_PROPERTIES(libmariadb PROPERTIES IMPORTED_INTERFACE_LINK_LIBRARIES "${SYSTEM_LIBS}")
SET_TARGET_PROPERTIES(libmariadb PROPERTIES PREFIX "")
#
# Installation
#
INCLUDE(${CC_SOURCE_DIR}/cmake/symlink.cmake)
# There are still several projects which don't make use
# of the config program. To make sure these programs can
# use mariadb client library we provide libmysql symlinks
IF(WITH_MYSQLCOMPAT)
create_symlink(libmysqlclient${CMAKE_SHARED_LIBRARY_SUFFIX} libmariadb ${INSTALL_LIBDIR})
create_symlink(libmysqlclient_r${CMAKE_SHARED_LIBRARY_SUFFIX} libmariadb ${INSTALL_LIBDIR})
IF(NOT CMAKE_SYSTEM_NAME MATCHES AIX)
create_symlink(libmysqlclient${CMAKE_STATIC_LIBRARY_SUFFIX} mariadbclient ${INSTALL_LIBDIR})
create_symlink(libmysqlclient_r${CMAKE_STATIC_LIBRARY_SUFFIX} mariadbclient ${INSTALL_LIBDIR})
ENDIF()
ENDIF()
SET_TARGET_PROPERTIES(libmariadb PROPERTIES VERSION
${CPACK_PACKAGE_VERSION_MAJOR}
SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR})
IF(NOT WIN32)
SET_TARGET_PROPERTIES(mariadbclient PROPERTIES OUTPUT_NAME "${LIBMARIADB_STATIC_NAME}")
ENDIF()
INSTALL(TARGETS mariadbclient
COMPONENT Development
DESTINATION ${INSTALL_LIBDIR})
INSTALL(TARGETS libmariadb
COMPONENT SharedLibraries
DESTINATION ${INSTALL_LIBDIR})
IF(MSVC)
# On Windows, install PDB
INSTALL(FILES $<TARGET_PDB_FILE:libmariadb> DESTINATION "${INSTALL_LIBDIR}"
CONFIGURATIONS Debug RelWithDebInfo
COMPONENT Development)
ENDIF()

33
vendor/MDBC/libmariadb/bmove_upp.c vendored Normal file
View File

@ -0,0 +1,33 @@
/* 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
/* File : bmove.c
Author : Michael widenius
Updated: 1987-03-20
Defines: bmove_upp()
bmove_upp(dst, src, len) moves exactly "len" bytes from the source
"src-len" to the destination "dst-len" counting downwards.
*/
#include <ma_global.h>
#include "ma_string.h"
void ma_bmove_upp(register char *dst, register const char *src, register size_t len)
{
while (len-- != 0) *--dst = *--src;
}

172
vendor/MDBC/libmariadb/get_password.c vendored Normal file
View File

@ -0,0 +1,172 @@
/************************************************************************************
Copyright (C) 2014 MariaDB Corporation 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 <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
*************************************************************************************/
#include <ma_global.h>
#include <ma_sys.h>
#include "mysql.h"
#include <ma_string.h>
#include <mariadb_ctype.h>
#include <stdio.h>
#include <memory.h>
#ifndef _WIN32
#include <termios.h>
#else
#include <conio.h>
#endif /* _WIN32 */
/* {{{ static char *get_password() */
/*
read password from device
SYNOPSIS
get_password
Hdl/file file handle
buffer input buffer
length buffer length
RETURN
buffer zero terminated input buffer
*/
#ifdef _WIN32
static char *get_password(HANDLE Hdl, char *buffer, DWORD length)
#else
static char *get_password(FILE *file, char *buffer, int length)
#endif
{
char inChar;
int CharsProcessed= 1;
#ifdef _WIN32
DWORD Offset= 0;
#else
int Offset= 0;
#endif
memset(buffer, 0, length);
do
{
#ifdef _WIN32
if (!ReadConsole(Hdl, &inChar, 1, (DWORD *)&CharsProcessed, NULL) ||
!CharsProcessed)
break;
#else
inChar= (char)fgetc(file);
#endif
switch(inChar) {
case '\b': /* backslash */
if (Offset)
{
/* cursor is always at the end */
Offset--;
buffer[Offset]= 0;
#ifdef _WIN32
_cputs("\b \b");
#endif
}
break;
case '\n':
case '\r':
break;
default:
buffer[Offset]= inChar;
if (Offset < length - 2)
Offset++;
#ifdef _WIN32
_cputs("*");
#endif
break;
}
} while (CharsProcessed && inChar != '\n' && inChar != '\r');
return buffer;
}
/* }}} */
/* {{{ static char* get_tty_password */
/*
reads password from tty/console
SYNOPSIS
get_tty_password()
buffer input buffer
length length of input buffer
DESCRIPTION
reads a password from console (Windows) or tty without echoing
it's characters. Input buffer must be allocated by calling function.
RETURNS
buffer pointer to input buffer
*/
char* get_tty_password(char *prompt, char *buffer, int length)
{
#ifdef _WIN32
DWORD SaveState;
HANDLE Hdl;
if (prompt)
fprintf(stderr, "%s", prompt);
if (!(Hdl= CreateFile("CONIN$",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING, 0, NULL)))
{
/* todo: provide a graphical dialog */
return buffer;
}
/* Save ConsoleMode and set ENABLE_PROCESSED_INPUT:
CTRL+C is processed by the system and is not placed in the input buffer */
GetConsoleMode(Hdl, &SaveState);
SetConsoleMode(Hdl, ENABLE_PROCESSED_INPUT);
buffer= get_password(Hdl, buffer, length);
SetConsoleMode(Hdl, SaveState);
CloseHandle(Hdl);
return buffer;
#else
struct termios term_old,
term_new;
FILE *readfrom;
if (prompt && isatty(fileno(stderr)))
fputs(prompt, stderr);
if (!(readfrom= fopen("/dev/tty", "r")))
readfrom= stdin;
/* try to disable echo */
tcgetattr(fileno(readfrom), &term_old);
term_new= term_old;
term_new.c_cc[VMIN] = 1;
term_new.c_cc[VTIME]= 0;
term_new.c_lflag&= ~(ECHO | ISIG | ICANON | ECHONL);
tcsetattr(fileno(readfrom), TCSADRAIN, &term_new);
buffer= get_password(readfrom, buffer, length);
if (isatty(fileno(readfrom)))
tcsetattr(fileno(readfrom), TCSADRAIN, &term_old);
fclose(readfrom);
return buffer;
#endif
}
/* }}} */

193
vendor/MDBC/libmariadb/ma_alloc.c vendored Normal file
View File

@ -0,0 +1,193 @@
/* 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
/* Routines to handle mallocing of results which will be freed the same time */
#include <ma_global.h>
#include <ma_sys.h>
#include <ma_string.h>
void ma_init_alloc_root(MA_MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size)
{
mem_root->free= mem_root->used= mem_root->pre_alloc= 0;
mem_root->min_malloc=32;
mem_root->block_size= (block_size-MALLOC_OVERHEAD-sizeof(MA_USED_MEM)+8);
mem_root->error_handler=0;
mem_root->block_num= 4;
mem_root->first_block_usage= 0;
#if !(defined(HAVE_purify) && defined(EXTRA_DEBUG))
if (pre_alloc_size)
{
if ((mem_root->free = mem_root->pre_alloc=
(MA_USED_MEM*) malloc(pre_alloc_size+ ALIGN_SIZE(sizeof(MA_USED_MEM)))))
{
mem_root->free->size=pre_alloc_size+ALIGN_SIZE(sizeof(MA_USED_MEM));
mem_root->free->left=pre_alloc_size;
mem_root->free->next=0;
}
}
#endif
}
void * ma_alloc_root(MA_MEM_ROOT *mem_root, size_t Size)
{
#if defined(HAVE_purify) && defined(EXTRA_DEBUG)
reg1 MA_USED_MEM *next;
Size+=ALIGN_SIZE(sizeof(MA_USED_MEM));
if (!(next = (MA_USED_MEM*) malloc(Size)))
{
if (mem_root->error_handler)
(*mem_root->error_handler)();
return((void *) 0); /* purecov: inspected */
}
next->next=mem_root->used;
mem_root->used=next;
return (void *) (((char*) next)+ALIGN_SIZE(sizeof(MA_USED_MEM)));
#else
size_t get_size;
void * point;
reg1 MA_USED_MEM *next= 0;
reg2 MA_USED_MEM **prev;
Size= ALIGN_SIZE(Size);
if ((*(prev= &mem_root->free)))
{
if ((*prev)->left < Size &&
mem_root->first_block_usage++ >= 16 &&
(*prev)->left < 4096)
{
next= *prev;
*prev= next->next;
next->next= mem_root->used;
mem_root->used= next;
mem_root->first_block_usage= 0;
}
for (next= *prev; next && next->left < Size; next= next->next)
prev= &next->next;
}
if (! next)
{ /* Time to alloc new block */
get_size= MAX(Size+ALIGN_SIZE(sizeof(MA_USED_MEM)),
(mem_root->block_size & ~1) * (mem_root->block_num >> 2));
if (!(next = (MA_USED_MEM*) malloc(get_size)))
{
if (mem_root->error_handler)
(*mem_root->error_handler)();
return((void *) 0); /* purecov: inspected */
}
mem_root->block_num++;
next->next= *prev;
next->size= get_size;
next->left= get_size-ALIGN_SIZE(sizeof(MA_USED_MEM));
*prev=next;
}
point= (void *) ((char*) next+ (next->size-next->left));
if ((next->left-= Size) < mem_root->min_malloc)
{ /* Full block */
*prev=next->next; /* Remove block from list */
next->next=mem_root->used;
mem_root->used=next;
mem_root->first_block_usage= 0;
}
return(point);
#endif
}
/* deallocate everything used by alloc_root */
void ma_free_root(MA_MEM_ROOT *root, myf MyFlags)
{
reg1 MA_USED_MEM *next,*old;
if (!root)
return; /* purecov: inspected */
if (!(MyFlags & MY_KEEP_PREALLOC))
root->pre_alloc=0;
for ( next=root->used; next ;)
{
old=next; next= next->next ;
if (old != root->pre_alloc)
free(old);
}
for (next= root->free ; next ; )
{
old=next; next= next->next ;
if (old != root->pre_alloc)
free(old);
}
root->used=root->free=0;
if (root->pre_alloc)
{
root->free=root->pre_alloc;
root->free->left=root->pre_alloc->size-ALIGN_SIZE(sizeof(MA_USED_MEM));
root->free->next=0;
}
}
char *ma_strdup_root(MA_MEM_ROOT *root,const char *str)
{
size_t len= strlen(str)+1;
char *pos;
if ((pos=ma_alloc_root(root,len)))
memcpy(pos,str,len);
return pos;
}
char *ma_memdup_root(MA_MEM_ROOT *root, const char *str, size_t len)
{
char *pos;
if ((pos= ma_alloc_root(root,len)))
memcpy(pos,str,len);
return pos;
}
void *ma_multi_malloc(myf myFlags, ...)
{
va_list args;
char **ptr,*start,*res;
size_t tot_length,length;
va_start(args,myFlags);
tot_length=0;
while ((ptr=va_arg(args, char **)))
{
length=va_arg(args, size_t);
tot_length+=ALIGN_SIZE(length);
}
va_end(args);
if (!(start=(char *)malloc(tot_length)))
return 0;
va_start(args,myFlags);
res=start;
while ((ptr=va_arg(args, char **)))
{
*ptr=res;
length=va_arg(args,size_t);
res+=ALIGN_SIZE(length);
}
va_end(args);
return start;
}

172
vendor/MDBC/libmariadb/ma_array.c vendored Normal file
View File

@ -0,0 +1,172 @@
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
2016 MariaDB Corporation 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
/* Handling of arrays that can grow dynamically. */
#undef SAFEMALLOC /* Problems with threads */
#include <ma_global.h>
#include <ma_sys.h>
#include "ma_string.h"
#include <memory.h>
/*
Initiate array and alloc space for init_alloc elements. Array is usable
even if space allocation failed
*/
my_bool ma_init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size,
uint init_alloc, uint alloc_increment CALLER_INFO_PROTO)
{
if (!alloc_increment)
{
alloc_increment=max((8192-MALLOC_OVERHEAD)/element_size,16);
if (init_alloc > 8 && alloc_increment > init_alloc * 2)
alloc_increment=init_alloc*2;
}
if (!init_alloc)
init_alloc=alloc_increment;
array->elements=0;
array->max_element=init_alloc;
array->alloc_increment=alloc_increment;
array->size_of_element=element_size;
if (!(array->buffer=(char*) malloc(element_size*init_alloc)))
{
array->max_element=0;
return(TRUE);
}
return(FALSE);
}
my_bool ma_insert_dynamic(DYNAMIC_ARRAY *array, void *element)
{
void *buffer;
if (array->elements == array->max_element)
{ /* Call only when necessary */
if (!(buffer=ma_alloc_dynamic(array)))
return TRUE;
}
else
{
buffer=array->buffer+(array->elements * array->size_of_element);
array->elements++;
}
memcpy(buffer,element,(size_t) array->size_of_element);
return FALSE;
}
/* Alloc room for one element */
unsigned char *ma_alloc_dynamic(DYNAMIC_ARRAY *array)
{
if (array->elements == array->max_element)
{
char *new_ptr;
if (!(new_ptr=(char*) realloc(array->buffer,(array->max_element+
array->alloc_increment)*
array->size_of_element)))
return 0;
array->buffer=new_ptr;
array->max_element+=array->alloc_increment;
}
return (unsigned char *)array->buffer+(array->elements++ * array->size_of_element);
}
/* remove last element from array and return it */
unsigned char *ma_pop_dynamic(DYNAMIC_ARRAY *array)
{
if (array->elements)
return (unsigned char *)array->buffer+(--array->elements * array->size_of_element);
return 0;
}
my_bool ma_set_dynamic(DYNAMIC_ARRAY *array, void * element, uint idx)
{
if (idx >= array->elements)
{
if (idx >= array->max_element)
{
uint size;
char *new_ptr;
size=(idx+array->alloc_increment)/array->alloc_increment;
size*= array->alloc_increment;
if (!(new_ptr=(char*) realloc(array->buffer,size*
array->size_of_element)))
return TRUE;
array->buffer=new_ptr;
array->max_element=size;
}
memset((array->buffer+array->elements*array->size_of_element), 0,
(idx - array->elements)*array->size_of_element);
array->elements=idx+1;
}
memcpy(array->buffer+(idx * array->size_of_element),element,
(size_t) array->size_of_element);
return FALSE;
}
void ma_get_dynamic(DYNAMIC_ARRAY *array, void * element, uint idx)
{
if (idx >= array->elements)
{
memset(element, 0, array->size_of_element);
return;
}
memcpy(element,array->buffer+idx*array->size_of_element,
(size_t) array->size_of_element);
}
void ma_delete_dynamic(DYNAMIC_ARRAY *array)
{
if (array->buffer)
{
free(array->buffer);
array->buffer=0;
array->elements=array->max_element=0;
}
}
void ma_delete_dynamic_element(DYNAMIC_ARRAY *array, uint idx)
{
char *ptr=array->buffer+array->size_of_element*idx;
array->elements--;
memmove(ptr,ptr+array->size_of_element,
(array->elements-idx)*array->size_of_element);
}
void ma_freeze_size(DYNAMIC_ARRAY *array)
{
uint elements=max(array->elements,1);
if (array->buffer && array->max_element != elements)
{
array->buffer=(char*) realloc(array->buffer,
elements*array->size_of_element);
array->max_element=elements;
}
}

1482
vendor/MDBC/libmariadb/ma_charset.c vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,508 @@
/* Copyright (C) 2010 - 2012 Sergei Golubchik and Monty Program Ab
2015-2016 MariaDB Corporation 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 <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA */
/**
@file
Support code for the client side (libmariadb) 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.
*/
/* Silence warnings about variable 'unused' being used. */
#define FORCE_INIT_OF_VARS 1
#include <ma_global.h>
#include <ma_sys.h>
#include <ma_common.h>
#include <ma_string.h>
#include <ma_pthread.h>
#include "errmsg.h"
#include <mysql/client_plugin.h>
#ifndef WIN32
#include <dlfcn.h>
#endif
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 MA_MEM_ROOT mem_root;
static uint valid_plugins[][2]= {
{MYSQL_CLIENT_AUTHENTICATION_PLUGIN, MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION},
{MARIADB_CLIENT_PVIO_PLUGIN, MARIADB_CLIENT_PVIO_PLUGIN_INTERFACE_VERSION},
{MARIADB_CLIENT_TRACE_PLUGIN, MARIADB_CLIENT_TRACE_PLUGIN_INTERFACE_VERSION},
{MARIADB_CLIENT_REMOTEIO_PLUGIN, MARIADB_CLIENT_REMOTEIO_PLUGIN_INTERFACE_VERSION},
{MARIADB_CLIENT_CONNECTION_PLUGIN, MARIADB_CLIENT_CONNECTION_PLUGIN_INTERFACE_VERSION},
{0, 0}
};
/*
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 + MARIADB_CLIENT_MAX_PLUGINS];
#ifdef THREAD
static pthread_mutex_t LOCK_load_client_plugin;
#endif
@EXTERNAL_PLUGINS@
struct st_mysql_client_plugin *mysql_client_builtins[]=
{
@BUILTIN_PLUGINS@
0
};
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;
}
static int get_plugin_nr(uint type)
{
uint i= 0;
for(; valid_plugins[i][1]; i++)
if (valid_plugins[i][0] == type)
return i;
return -1;
}
static const char *check_plugin_version(struct st_mysql_client_plugin *plugin, unsigned int version)
{
if (plugin->interface_version < version ||
(plugin->interface_version >> 8) > (version >> 8))
return "Incompatible client plugin interface";
return 0;
}
/**
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;
int plugin_nr= get_plugin_nr(type);
DBUG_ASSERT(initialized);
if (plugin_nr == -1)
return 0;
if (!name)
return plugin_list[plugin_nr]->plugin;
for (p= plugin_list[plugin_nr]; 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];
int plugin_nr;
DBUG_ASSERT(initialized);
plugin_int.plugin= plugin;
plugin_int.dlhandle= dlhandle;
if ((plugin_nr= get_plugin_nr(plugin->type)) == -1)
{
errmsg= "Unknown client plugin type";
goto err1;
}
if ((errmsg= check_plugin_version(plugin, valid_plugins[plugin_nr][1])))
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 *)
ma_memdup_root(&mem_root, (char *)&plugin_int, sizeof(plugin_int));
if (!p)
{
errmsg= "Out of memory";
goto err2;
}
p->next= plugin_list[plugin_nr];
plugin_list[plugin_nr]= p;
return plugin;
err2:
if (plugin->deinit)
plugin->deinit();
err1:
my_set_error(mysql, CR_AUTH_PLUGIN_CANNOT_LOAD, SQLSTATE_UNKNOWN,
ER(CR_AUTH_PLUGIN_CANNOT_LOAD), plugin->name, errmsg);
if (dlhandle)
(void)dlclose(dlhandle);
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");
if (ma_check_env_str(s))
return;
free_env= strdup(s);
plugs= s= free_env;
do {
if ((s= strchr(plugs, ';')))
*s= '\0';
mysql_load_plugin(mysql, plugs, -1, 0);
plugs= s + 1;
} while (s);
free(free_env);
}
/********** extern functions to be used by libmariadb *********************/
/**
Initializes the client plugin layer.
This function must be called before any other client plugin function.
@retval 0 successful
@retval != 0 error occurred
*/
int mysql_client_plugin_init()
{
MYSQL mysql;
struct st_mysql_client_plugin **builtin;
va_list unused;
LINT_INIT_STRUCT(unused);
if (initialized)
return 0;
memset(&mysql, 0, sizeof(mysql)); /* dummy mysql for set_mysql_extended_error */
pthread_mutex_init(&LOCK_load_client_plugin, NULL);
ma_init_alloc_root(&mem_root, 128, 128);
memset(&plugin_list, 0, 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);
}
memset(&plugin_list, 0, sizeof(plugin_list));
initialized= 0;
ma_free_root(&mem_root, MYF(0));
pthread_mutex_destroy(&LOCK_load_client_plugin);
}
/************* public facing functions, for client consumption *********/
/* see <mysql/client_plugin.h> for a full description */
struct st_mysql_client_plugin * STDCALL
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 <mysql/client_plugin.h> for a full description */
struct st_mysql_client_plugin * STDCALL
mysql_load_plugin_v(MYSQL *mysql, const char *name, int type,
int argc, va_list args)
{
const char *errmsg;
#ifdef _WIN32
char errbuf[1024];
#endif
char dlpath[FN_REFLEN+1];
void *sym, *dlhandle = NULL;
struct st_mysql_client_plugin *plugin;
char *env_plugin_dir= getenv("MARIADB_PLUGIN_DIR");
CLEAR_CLIENT_ERROR(mysql);
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 */
#ifndef WIN32
snprintf(dlpath, sizeof(dlpath) - 1, "%s/%s%s",
mysql->options.extension && mysql->options.extension->plugin_dir ?
mysql->options.extension->plugin_dir : (env_plugin_dir) ? env_plugin_dir :
MARIADB_PLUGINDIR, name, SO_EXT);
#else
{
char *p= (mysql->options.extension && mysql->options.extension->plugin_dir) ?
mysql->options.extension->plugin_dir : env_plugin_dir;
snprintf(dlpath, sizeof(dlpath), "%s%s%s%s", p ? p : "", p ? "\\" : "", name, SO_EXT);
}
#endif
if (strpbrk(name, "()[]!@#$%^&/*;.,'?\\"))
{
errmsg= "invalid plugin name";
goto err;
}
/* Open new dll handle */
if (!(dlhandle= dlopen((const char *)dlpath, RTLD_NOW)))
{
#ifdef _WIN32
char winmsg[255];
size_t len;
winmsg[0] = 0;
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
winmsg, 255, NULL);
len= strlen(winmsg);
while (len > 0 && (winmsg[len - 1] == '\n' || winmsg[len - 1] == '\r'))
len--;
if (len)
winmsg[len] = 0;
snprintf(errbuf, sizeof(errbuf), "%s Library path is '%s'", winmsg, dlpath);
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:
if (dlhandle)
dlclose(dlhandle);
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 <mysql/client_plugin.h> for a full description */
struct st_mysql_client_plugin * STDCALL
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 <mysql/client_plugin.h> for a full description */
struct st_mysql_client_plugin * STDCALL
mysql_client_find_plugin(MYSQL *mysql, const char *name, int type)
{
struct st_mysql_client_plugin *p;
int plugin_nr= get_plugin_nr(type);
if (is_not_initialized(mysql, name))
return NULL;
if (plugin_nr == -1)
{
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);
}

90
vendor/MDBC/libmariadb/ma_compress.c vendored Normal file
View File

@ -0,0 +1,90 @@
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
2016 MariaDB Corporation 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
/* Written by Sinisa Milivojevic <sinisa@coresinc.com> */
#include <ma_global.h>
#ifdef HAVE_COMPRESS
#include <ma_sys.h>
#include <ma_string.h>
#include <zlib.h>
/*
** This replaces the packet with a compressed packet
** Returns 1 on error
** *complen is 0 if the packet wasn't compressed
*/
my_bool _mariadb_compress(unsigned char *packet, size_t *len, size_t *complen)
{
if (*len < MIN_COMPRESS_LENGTH)
*complen=0;
else
{
unsigned char *compbuf=_mariadb_compress_alloc(packet,len,complen);
if (!compbuf)
return *complen ? 0 : 1;
memcpy(packet,compbuf,*len);
free(compbuf);
}
return 0;
}
unsigned char *_mariadb_compress_alloc(const unsigned char *packet, size_t *len, size_t *complen)
{
unsigned char *compbuf;
*complen = *len * 120 / 100 + 12;
if (!(compbuf = (unsigned char *) malloc(*complen)))
return 0; /* Not enough memory */
if (compress((Bytef*) compbuf,(ulong *) complen, (Bytef*) packet,
(uLong) *len ) != Z_OK)
{
free(compbuf);
return 0;
}
if (*complen >= *len)
{
*complen=0;
free(compbuf);
return 0;
}
swap(size_t,*len,*complen); /* *len is now packet length */
return compbuf;
}
my_bool _mariadb_uncompress (unsigned char *packet, size_t *len, size_t *complen)
{
if (*complen) /* If compressed */
{
unsigned char *compbuf = (unsigned char *) malloc (*complen);
if (!compbuf)
return 1; /* Not enough memory */
if (uncompress((Bytef*) compbuf, (uLongf *)complen, (Bytef*) packet, (uLongf)*len) != Z_OK)
{ /* Probably wrong packet */
free(compbuf);
return 1;
}
*len = *complen;
memcpy(packet,compbuf,*len);
free(compbuf);
}
else *complen= *len;
return 0;
}
#endif /* HAVE_COMPRESS */

726
vendor/MDBC/libmariadb/ma_context.c vendored Normal file
View File

@ -0,0 +1,726 @@
/*
Copyright 2011, 2012 Kristian Nielsen and Monty Program Ab
2016 MariaDB Corporation AB
This file is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
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
Lesser General Public License for more details.
You should have received a copy of the GNU General Public License
along with this. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Implementation of async context spawning using Posix ucontext and
swapcontext().
*/
#include "ma_global.h"
#include "ma_string.h"
#include "ma_context.h"
#ifdef HAVE_VALGRIND
#include <valgrind/valgrind.h>
#endif
#ifdef MY_CONTEXT_USE_UCONTEXT
/*
The makecontext() only allows to pass integers into the created context :-(
We want to pass pointers, so we do it this kinda hackish way.
Anyway, it should work everywhere, and at least it does not break strict
aliasing.
*/
union pass_void_ptr_as_2_int {
int a[2];
void *p;
};
/*
We use old-style function definition here, as this is passed to
makecontext(). And the type of the makecontext() argument does not match
the actual type (as the actual type can differ from call to call).
*/
static void
my_context_spawn_internal(i0, i1)
int i0, i1;
{
int err;
struct my_context *c;
union pass_void_ptr_as_2_int u;
u.a[0]= i0;
u.a[1]= i1;
c= (struct my_context *)u.p;
(*c->user_func)(c->user_data);
c->active= 0;
err= setcontext(&c->base_context);
fprintf(stderr, "Aieie, setcontext() failed: %d (errno=%d)\n", err, errno);
}
int
my_context_continue(struct my_context *c)
{
int err;
if (!c->active)
return 0;
err= swapcontext(&c->base_context, &c->spawned_context);
if (err)
{
fprintf(stderr, "Aieie, swapcontext() failed: %d (errno=%d)\n",
err, errno);
return -1;
}
return c->active;
}
int
my_context_spawn(struct my_context *c, void (*f)(void *), void *d)
{
int err;
union pass_void_ptr_as_2_int u;
err= getcontext(&c->spawned_context);
if (err)
return -1;
c->spawned_context.uc_stack.ss_sp= c->stack;
c->spawned_context.uc_stack.ss_size= c->stack_size;
c->spawned_context.uc_link= NULL;
c->user_func= f;
c->user_data= d;
c->active= 1;
u.p= c;
makecontext(&c->spawned_context, my_context_spawn_internal, 2,
u.a[0], u.a[1]);
return my_context_continue(c);
}
int
my_context_yield(struct my_context *c)
{
int err;
if (!c->active)
return -1;
err= swapcontext(&c->spawned_context, &c->base_context);
if (err)
return -1;
return 0;
}
int
my_context_init(struct my_context *c, size_t stack_size)
{
#if SIZEOF_CHARP > SIZEOF_INT*2
#error Error: Unable to store pointer in 2 ints on this architecture
#endif
memset(c, 0, sizeof(*c));
if (!(c->stack= malloc(stack_size)))
return -1; /* Out of memory */
c->stack_size= stack_size;
#ifdef HAVE_VALGRIND
c->valgrind_stack_id=
VALGRIND_STACK_REGISTER(c->stack, ((unsigned char *)(c->stack))+stack_size);
#endif
return 0;
}
void
my_context_destroy(struct my_context *c)
{
if (c->stack)
{
#ifdef HAVE_VALGRIND
VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id);
#endif
free(c->stack);
}
}
#endif /* MY_CONTEXT_USE_UCONTEXT */
#ifdef MY_CONTEXT_USE_X86_64_GCC_ASM
/*
GCC-amd64 implementation of my_context.
This is slightly optimized in the common case where we never yield
(eg. fetch next row and it is already fully received in buffer). In this
case we do not need to restore registers at return (though we still need to
save them as we cannot know if we will yield or not in advance).
*/
#include <stdint.h>
#include <stdlib.h>
/*
Layout of saved registers etc.
Since this is accessed through gcc inline assembler, it is simpler to just
use numbers than to try to define nice constants or structs.
0 0 %rsp
1 8 %rbp
2 16 %rbx
3 24 %r12
4 32 %r13
5 40 %r14
6 48 %r15
7 56 %rip for done
8 64 %rip for yield/continue
*/
int
my_context_spawn(struct my_context *c, void (*f)(void *), void *d)
{
int ret;
/*
There are 6 callee-save registers we need to save and restore when
suspending and continuing, plus stack pointer %rsp and instruction pointer
%rip.
However, if we never suspend, the user-supplied function will in any case
restore the 6 callee-save registers, so we can avoid restoring them in
this case.
*/
__asm__ __volatile__
(
"movq %%rsp, (%[save])\n\t"
"movq %[stack], %%rsp\n\t"
#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 4 && !defined(__INTEL_COMPILER)
/*
This emits a DWARF DW_CFA_undefined directive to make the return address
undefined. This indicates that this is the top of the stack frame, and
helps tools that use DWARF stack unwinding to obtain stack traces.
(I use numeric constant to avoid a dependency on libdwarf includes).
*/
".cfi_escape 0x07, 16\n\t"
#endif
"movq %%rbp, 8(%[save])\n\t"
"movq %%rbx, 16(%[save])\n\t"
"movq %%r12, 24(%[save])\n\t"
"movq %%r13, 32(%[save])\n\t"
"movq %%r14, 40(%[save])\n\t"
"movq %%r15, 48(%[save])\n\t"
"leaq 1f(%%rip), %%rax\n\t"
"leaq 2f(%%rip), %%rcx\n\t"
"movq %%rax, 56(%[save])\n\t"
"movq %%rcx, 64(%[save])\n\t"
/*
Constraint below puts the argument to the user function into %rdi, as
needed for the calling convention.
*/
"callq *%[f]\n\t"
"jmpq *56(%[save])\n"
/*
Come here when operation is done.
We do not need to restore callee-save registers, as the called function
will do this for us if needed.
*/
"1:\n\t"
"movq (%[save]), %%rsp\n\t"
"xorl %[ret], %[ret]\n\t"
"jmp 3f\n"
/* Come here when operation was suspended. */
"2:\n\t"
"movl $1, %[ret]\n"
"3:\n"
: [ret] "=a" (ret),
[f] "+S" (f),
/* Need this in %rdi to follow calling convention. */
[d] "+D" (d)
: [stack] "a" (c->stack_top),
/* Need this in callee-save register to preserve in function call. */
[save] "b" (&c->save[0])
: "rcx", "rdx", "r8", "r9", "r10", "r11", "memory", "cc"
);
return ret;
}
int
my_context_continue(struct my_context *c)
{
int ret;
__asm__ __volatile__
(
"movq (%[save]), %%rax\n\t"
"movq %%rsp, (%[save])\n\t"
"movq %%rax, %%rsp\n\t"
"movq 8(%[save]), %%rax\n\t"
"movq %%rbp, 8(%[save])\n\t"
"movq %%rax, %%rbp\n\t"
"movq 24(%[save]), %%rax\n\t"
"movq %%r12, 24(%[save])\n\t"
"movq %%rax, %%r12\n\t"
"movq 32(%[save]), %%rax\n\t"
"movq %%r13, 32(%[save])\n\t"
"movq %%rax, %%r13\n\t"
"movq 40(%[save]), %%rax\n\t"
"movq %%r14, 40(%[save])\n\t"
"movq %%rax, %%r14\n\t"
"movq 48(%[save]), %%rax\n\t"
"movq %%r15, 48(%[save])\n\t"
"movq %%rax, %%r15\n\t"
"leaq 1f(%%rip), %%rax\n\t"
"leaq 2f(%%rip), %%rcx\n\t"
"movq %%rax, 56(%[save])\n\t"
"movq 64(%[save]), %%rax\n\t"
"movq %%rcx, 64(%[save])\n\t"
"movq 16(%[save]), %%rcx\n\t"
"movq %%rbx, 16(%[save])\n\t"
"movq %%rcx, %%rbx\n\t"
"jmpq *%%rax\n"
/*
Come here when operation is done.
Be sure to use the same callee-save register for %[save] here and in
my_context_spawn(), so we preserve the value correctly at this point.
*/
"1:\n\t"
"movq (%[save]), %%rsp\n\t"
"movq 8(%[save]), %%rbp\n\t"
/* %rbx is preserved from my_context_spawn() in this case. */
"movq 24(%[save]), %%r12\n\t"
"movq 32(%[save]), %%r13\n\t"
"movq 40(%[save]), %%r14\n\t"
"movq 48(%[save]), %%r15\n\t"
"xorl %[ret], %[ret]\n\t"
"jmp 3f\n"
/* Come here when operation is suspended. */
"2:\n\t"
"movl $1, %[ret]\n"
"3:\n"
: [ret] "=a" (ret)
: /* Need this in callee-save register to preserve in function call. */
[save] "b" (&c->save[0])
: "rcx", "rdx", "rsi", "rdi", "r8", "r9", "r10", "r11", "memory", "cc"
);
return ret;
}
int
my_context_yield(struct my_context *c)
{
uint64_t *save= &c->save[0];
__asm__ __volatile__
(
"movq (%[save]), %%rax\n\t"
"movq %%rsp, (%[save])\n\t"
"movq %%rax, %%rsp\n\t"
"movq 8(%[save]), %%rax\n\t"
"movq %%rbp, 8(%[save])\n\t"
"movq %%rax, %%rbp\n\t"
"movq 16(%[save]), %%rax\n\t"
"movq %%rbx, 16(%[save])\n\t"
"movq %%rax, %%rbx\n\t"
"movq 24(%[save]), %%rax\n\t"
"movq %%r12, 24(%[save])\n\t"
"movq %%rax, %%r12\n\t"
"movq 32(%[save]), %%rax\n\t"
"movq %%r13, 32(%[save])\n\t"
"movq %%rax, %%r13\n\t"
"movq 40(%[save]), %%rax\n\t"
"movq %%r14, 40(%[save])\n\t"
"movq %%rax, %%r14\n\t"
"movq 48(%[save]), %%rax\n\t"
"movq %%r15, 48(%[save])\n\t"
"movq %%rax, %%r15\n\t"
"movq 64(%[save]), %%rax\n\t"
"leaq 1f(%%rip), %%rcx\n\t"
"movq %%rcx, 64(%[save])\n\t"
"jmpq *%%rax\n"
"1:\n"
: [save] "+D" (save)
:
: "rax", "rcx", "rdx", "rsi", "r8", "r9", "r10", "r11", "memory", "cc"
);
return 0;
}
int
my_context_init(struct my_context *c, size_t stack_size)
{
memset(c, 0, sizeof(*c));
if (!(c->stack_bot= malloc(stack_size)))
return -1; /* Out of memory */
/*
The x86_64 ABI specifies 16-byte stack alignment.
Also put two zero words at the top of the stack.
*/
c->stack_top= (void *)
(( ((intptr)c->stack_bot + stack_size) & ~(intptr)0xf) - 16);
memset(c->stack_top, 0, 16);
#ifdef HAVE_VALGRIND
c->valgrind_stack_id=
VALGRIND_STACK_REGISTER(c->stack_bot, c->stack_top);
#endif
return 0;
}
void
my_context_destroy(struct my_context *c)
{
if (c->stack_bot)
{
free(c->stack_bot);
#ifdef HAVE_VALGRIND
VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id);
#endif
}
}
#endif /* MY_CONTEXT_USE_X86_64_GCC_ASM */
#ifdef MY_CONTEXT_USE_I386_GCC_ASM
/*
GCC-i386 implementation of my_context.
This is slightly optimized in the common case where we never yield
(eg. fetch next row and it is already fully received in buffer). In this
case we do not need to restore registers at return (though we still need to
save them as we cannot know if we will yield or not in advance).
*/
#include <stdint.h>
#include <stdlib.h>
/*
Layout of saved registers etc.
Since this is accessed through gcc inline assembler, it is simpler to just
use numbers than to try to define nice constants or structs.
0 0 %esp
1 4 %ebp
2 8 %ebx
3 12 %esi
4 16 %edi
5 20 %eip for done
6 24 %eip for yield/continue
*/
int
my_context_spawn(struct my_context *c, void (*f)(void *), void *d)
{
int ret;
/*
There are 4 callee-save registers we need to save and restore when
suspending and continuing, plus stack pointer %esp and instruction pointer
%eip.
However, if we never suspend, the user-supplied function will in any case
restore the 4 callee-save registers, so we can avoid restoring them in
this case.
*/
__asm__ __volatile__
(
"movl %%esp, (%[save])\n\t"
"movl %[stack], %%esp\n\t"
#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 4 && !defined(__INTEL_COMPILER)
/*
This emits a DWARF DW_CFA_undefined directive to make the return address
undefined. This indicates that this is the top of the stack frame, and
helps tools that use DWARF stack unwinding to obtain stack traces.
(I use numeric constant to avoid a dependency on libdwarf includes).
*/
".cfi_escape 0x07, 8\n\t"
#endif
/* Push the parameter on the stack. */
"pushl %[d]\n\t"
"movl %%ebp, 4(%[save])\n\t"
"movl %%ebx, 8(%[save])\n\t"
"movl %%esi, 12(%[save])\n\t"
"movl %%edi, 16(%[save])\n\t"
/* Get label addresses in -fPIC-compatible way (no pc-relative on 32bit) */
"call 1f\n"
"1:\n\t"
"popl %%eax\n\t"
"addl $(2f-1b), %%eax\n\t"
"movl %%eax, 20(%[save])\n\t"
"addl $(3f-2f), %%eax\n\t"
"movl %%eax, 24(%[save])\n\t"
"call *%[f]\n\t"
"jmp *20(%[save])\n"
/*
Come here when operation is done.
We do not need to restore callee-save registers, as the called function
will do this for us if needed.
*/
"2:\n\t"
"movl (%[save]), %%esp\n\t"
"xorl %[ret], %[ret]\n\t"
"jmp 4f\n"
/* Come here when operation was suspended. */
"3:\n\t"
"movl $1, %[ret]\n"
"4:\n"
: [ret] "=a" (ret),
[f] "+c" (f),
[d] "+d" (d)
: [stack] "a" (c->stack_top),
/* Need this in callee-save register to preserve across function call. */
[save] "D" (&c->save[0])
: "memory", "cc"
);
return ret;
}
int
my_context_continue(struct my_context *c)
{
int ret;
__asm__ __volatile__
(
"movl (%[save]), %%eax\n\t"
"movl %%esp, (%[save])\n\t"
"movl %%eax, %%esp\n\t"
"movl 4(%[save]), %%eax\n\t"
"movl %%ebp, 4(%[save])\n\t"
"movl %%eax, %%ebp\n\t"
"movl 8(%[save]), %%eax\n\t"
"movl %%ebx, 8(%[save])\n\t"
"movl %%eax, %%ebx\n\t"
"movl 12(%[save]), %%eax\n\t"
"movl %%esi, 12(%[save])\n\t"
"movl %%eax, %%esi\n\t"
"movl 24(%[save]), %%eax\n\t"
"call 1f\n"
"1:\n\t"
"popl %%ecx\n\t"
"addl $(2f-1b), %%ecx\n\t"
"movl %%ecx, 20(%[save])\n\t"
"addl $(3f-2f), %%ecx\n\t"
"movl %%ecx, 24(%[save])\n\t"
/* Must restore %edi last as it is also our %[save] register. */
"movl 16(%[save]), %%ecx\n\t"
"movl %%edi, 16(%[save])\n\t"
"movl %%ecx, %%edi\n\t"
"jmp *%%eax\n"
/*
Come here when operation is done.
Be sure to use the same callee-save register for %[save] here and in
my_context_spawn(), so we preserve the value correctly at this point.
*/
"2:\n\t"
"movl (%[save]), %%esp\n\t"
"movl 4(%[save]), %%ebp\n\t"
"movl 8(%[save]), %%ebx\n\t"
"movl 12(%[save]), %%esi\n\t"
"movl 16(%[save]), %%edi\n\t"
"xorl %[ret], %[ret]\n\t"
"jmp 4f\n"
/* Come here when operation is suspended. */
"3:\n\t"
"movl $1, %[ret]\n"
"4:\n"
: [ret] "=a" (ret)
: /* Need this in callee-save register to preserve in function call. */
[save] "D" (&c->save[0])
: "ecx", "edx", "memory", "cc"
);
return ret;
}
int
my_context_yield(struct my_context *c)
{
uint64_t *save= &c->save[0];
__asm__ __volatile__
(
"movl (%[save]), %%eax\n\t"
"movl %%esp, (%[save])\n\t"
"movl %%eax, %%esp\n\t"
"movl 4(%[save]), %%eax\n\t"
"movl %%ebp, 4(%[save])\n\t"
"movl %%eax, %%ebp\n\t"
"movl 8(%[save]), %%eax\n\t"
"movl %%ebx, 8(%[save])\n\t"
"movl %%eax, %%ebx\n\t"
"movl 12(%[save]), %%eax\n\t"
"movl %%esi, 12(%[save])\n\t"
"movl %%eax, %%esi\n\t"
"movl 16(%[save]), %%eax\n\t"
"movl %%edi, 16(%[save])\n\t"
"movl %%eax, %%edi\n\t"
"movl 24(%[save]), %%eax\n\t"
"call 1f\n"
"1:\n\t"
"popl %%ecx\n\t"
"addl $(2f-1b), %%ecx\n\t"
"movl %%ecx, 24(%[save])\n\t"
"jmp *%%eax\n"
"2:\n"
: [save] "+d" (save)
:
: "eax", "ecx", "memory", "cc"
);
return 0;
}
int
my_context_init(struct my_context *c, size_t stack_size)
{
memset(c, 0, sizeof(*c));
if (!(c->stack_bot= malloc(stack_size)))
return -1; /* Out of memory */
c->stack_top= (void *)
(( ((intptr)c->stack_bot + stack_size) & ~(intptr)0xf) - 16);
memset(c->stack_top, 0, 16);
#ifdef HAVE_VALGRIND
c->valgrind_stack_id=
VALGRIND_STACK_REGISTER(c->stack_bot, c->stack_top);
#endif
return 0;
}
void
my_context_destroy(struct my_context *c)
{
if (c->stack_bot)
{
free(c->stack_bot);
#ifdef HAVE_VALGRIND
VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id);
#endif
}
}
#endif /* MY_CONTEXT_USE_I386_GCC_ASM */
#ifdef MY_CONTEXT_USE_WIN32_FIBERS
int
my_context_yield(struct my_context *c)
{
c->return_value= 1;
SwitchToFiber(c->app_fiber);
return 0;
}
static void WINAPI
my_context_trampoline(void *p)
{
struct my_context *c= (struct my_context *)p;
/*
Reuse the Fiber by looping infinitely, each time we are scheduled we
spawn the appropriate function and switch back when it is done.
This way we avoid the overhead of CreateFiber() for every asynchroneous
operation.
*/
for(;;)
{
(*(c->user_func))(c->user_arg);
c->return_value= 0;
SwitchToFiber(c->app_fiber);
}
}
int
my_context_init(struct my_context *c, size_t stack_size)
{
memset(c, 0, sizeof(*c));
c->lib_fiber= CreateFiber(stack_size, my_context_trampoline, c);
if (c->lib_fiber)
return 0;
return -1;
}
void
my_context_destroy(struct my_context *c)
{
if (c->lib_fiber)
{
DeleteFiber(c->lib_fiber);
c->lib_fiber= NULL;
}
}
int
my_context_spawn(struct my_context *c, void (*f)(void *), void *d)
{
c->user_func= f;
c->user_arg= d;
return my_context_continue(c);
}
int
my_context_continue(struct my_context *c)
{
void *current_fiber= IsThreadAFiber() ? GetCurrentFiber() : ConvertThreadToFiber(c);
c->app_fiber= current_fiber;
SwitchToFiber(c->lib_fiber);
return c->return_value;
}
#endif /* MY_CONTEXT_USE_WIN32_FIBERS */
#ifdef MY_CONTEXT_DISABLE
int
my_context_continue(struct my_context *c)
{
return -1;
}
int
my_context_spawn(struct my_context *c, void (*f)(void *), void *d)
{
return -1;
}
int
my_context_yield(struct my_context *c)
{
return -1;
}
int
my_context_init(struct my_context *c, size_t stack_size)
{
return -1; /* Out of memory */
}
void
my_context_destroy(struct my_context *c)
{
}
#endif

370
vendor/MDBC/libmariadb/ma_default.c vendored Normal file
View File

@ -0,0 +1,370 @@
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
2016 MariaDB Corporation 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
#include <ma_global.h>
#include <ma_sys.h>
#include "ma_string.h"
#include <ctype.h>
#include "mariadb_ctype.h"
#include <mysql.h>
#include <ma_common.h>
#include <mariadb/ma_io.h>
#ifdef _WIN32
#include <io.h>
#include "shlwapi.h"
static const char *ini_exts[]= {"ini", "cnf", 0};
#define R_OK 4
#else
#include <unistd.h>
static const char *ini_exts[]= {"cnf", 0};
#endif
char **configuration_dirs= NULL;
#define MAX_CONFIG_DIRS 6
my_bool _mariadb_read_options(MYSQL *mysql,
const char *config_dir,
const char *config_file,
const char *group,
unsigned int recursion);
static int add_cfg_dir(char **cfg_dirs, const char *directory)
{
int i;
for (i = 0; i < MAX_CONFIG_DIRS && cfg_dirs[i]; i++)
if (!strcmp(cfg_dirs[i], directory)) /* already present */
return 0;
if (i < MAX_CONFIG_DIRS) {
cfg_dirs[i]= strdup(directory);
return 0;
}
return 1;
}
void release_configuration_dirs()
{
if (configuration_dirs)
{
int i= 0;
while (configuration_dirs[i])
free(configuration_dirs[i++]);
free(configuration_dirs);
}
}
char **get_default_configuration_dirs()
{
#ifdef _WIN32
char dirname[FN_REFLEN];
#endif
char *env;
configuration_dirs= (char **)calloc(1, (MAX_CONFIG_DIRS + 1) * sizeof(char *));
if (!configuration_dirs)
goto end;
#ifdef _WIN32
/* On Windows operating systems configuration files are stored in
1. System Windows directory
2. System directory
3. Windows directory
4. C:\
*/
if (!GetSystemWindowsDirectory(dirname, FN_REFLEN) ||
add_cfg_dir(configuration_dirs, dirname))
goto error;
if (!GetWindowsDirectory(dirname, FN_REFLEN) ||
add_cfg_dir(configuration_dirs, dirname))
goto error;
if (add_cfg_dir(configuration_dirs, "C:"))
goto error;
if (GetModuleFileName(NULL, dirname, FN_REFLEN))
{
PathRemoveFileSpec(dirname);
if (add_cfg_dir(configuration_dirs, dirname))
goto error;
}
#else
/* on *nix platforms configuration files are stored in
1. SYSCONFDIR (if build happens inside server package, or
-DDEFAULT_SYSCONFDIR was specified
2. /etc
3. /etc/mysql
*/
#ifdef DEFAULT_SYSCONFDIR
if (add_cfg_dir(configuration_dirs, DEFAULT_SYSCONFDIR))
goto error;
#else
if (add_cfg_dir(configuration_dirs, "/etc"))
goto error;
if (add_cfg_dir(configuration_dirs, "/etc/mysql"))
goto error;
#endif
#endif
/* CONC-537: Read configuration files from MYSQL_HOME directory only if
MARIADB_HOME was not set */
if (!(env= getenv("MARIADB_HOME")))
env= getenv("MYSQL_HOME");
if (env && add_cfg_dir(configuration_dirs, env))
goto error;
end:
return configuration_dirs;
error:
return NULL;
}
extern my_bool _mariadb_set_conf_option(MYSQL *mysql, const char *config_option, const char *config_value);
static my_bool is_group(char *ptr, const char **groups)
{
while (*groups)
{
if (!strcmp(ptr, *groups))
return 1;
groups++;
}
return 0;
}
static my_bool _mariadb_read_options_from_file(MYSQL *mysql,
const char *config_file,
const char *group,
unsigned int recursion)
{
uint line=0;
my_bool read_values= 0, found_group= 0, is_escaped= 0, is_quoted= 0;
char buff[4096],*ptr,*end,*value, *key= 0, *optval;
MA_FILE *file= NULL;
my_bool rc= 1;
const char *groups[5]= {"client",
"client-server",
"client-mariadb",
group,
NULL};
my_bool (*set_option)(MYSQL *mysql, const char *config_option, const char *config_value);
/* if a plugin registered a hook we will call this hook, otherwise
* default (_mariadb_set_conf_option) will be called */
if (mysql->options.extension && mysql->options.extension->set_option)
set_option= mysql->options.extension->set_option;
else
set_option= _mariadb_set_conf_option;
if (!(file = ma_open(config_file, "r", NULL)))
goto err;
while (ma_gets(buff,sizeof(buff)-1,file))
{
line++;
key= 0;
/* Ignore comment and empty lines */
for (ptr=buff ; isspace(*ptr) ; ptr++ );
if (!is_escaped && (*ptr == '\"' || *ptr== '\''))
{
is_quoted= !is_quoted;
continue;
}
/* CONC- 327: !includedir and !include */
if (*ptr == '!')
{
char *val;
ptr++;
if (!(val= strchr(ptr, ' ')))
continue;
*val++= 0;
end= strchr(val, 0);
for ( ; isspace(end[-1]) ; end--) ; /* Remove end space */
*end= 0;
if (!strcmp(ptr, "includedir"))
_mariadb_read_options(mysql, (const char *)val, NULL, group, recursion + 1);
else if (!strcmp(ptr, "include"))
_mariadb_read_options(mysql, NULL, (const char *)val, group, recursion + 1);
continue;
}
if (*ptr == '#' || *ptr == ';' || !*ptr)
continue;
is_escaped= (*ptr == '\\');
if (*ptr == '[') /* Group name */
{
found_group=1;
if (!(end=(char *) strchr(++ptr,']')))
{
/* todo: set error */
goto err;
}
for ( ; isspace(end[-1]) ; end--) ; /* Remove end space */
end[0]=0;
read_values= is_group(ptr, groups);
continue;
}
if (!found_group)
{
/* todo: set error */
goto err;
}
if (!read_values)
continue;
if (!(end=value=strchr(ptr,'=')))
{
end=strchr(ptr, '\0'); /* Option without argument */
set_option(mysql, ptr, NULL);
}
if (!key)
key= ptr;
for ( ; isspace(end[-1]) ; end--) ;
*end= 0;
if (value)
{
/* Remove pre- and end space */
char *value_end;
*value= 0;
value++;
ptr= value;
for ( ; isspace(*value); value++) ;
value_end=strchr(value, '\0');
*value_end= 0;
optval= ptr;
for ( ; isspace(value_end[-1]) ; value_end--) ;
/* remove possible quotes */
if (*value == '\'' || *value == '\"')
{
value++;
if (value_end[-1] == '\'' || value_end[-1] == '\"')
value_end--;
}
if (value_end < value) /* Empty string */
value_end=value;
for ( ; value != value_end; value++)
{
if (*value == '\\' && value != value_end-1)
{
switch(*++value) {
case 'n':
*ptr++='\n';
break;
case 't':
*ptr++= '\t';
break;
case 'r':
*ptr++ = '\r';
break;
case 'b':
*ptr++ = '\b';
break;
case 's':
*ptr++= ' '; /* space */
break;
case '\"':
*ptr++= '\"';
break;
case '\'':
*ptr++= '\'';
break;
case '\\':
*ptr++= '\\';
break;
default: /* Unknown; Keep '\' */
*ptr++= '\\';
*ptr++= *value;
break;
}
}
else
*ptr++= *value;
}
*ptr=0;
set_option(mysql, key, optval);
key= optval= 0;
}
}
rc= 0;
err:
if (file)
ma_close(file);
return rc;
}
my_bool _mariadb_read_options(MYSQL *mysql,
const char *config_dir,
const char *config_file,
const char *group,
unsigned int recursion)
{
int i= 0,
exts,
errors= 0;
char filename[FN_REFLEN + 1];
unsigned int recursion_stop= 64;
#ifndef _WIN32
char *env;
#endif
if (recursion >= recursion_stop)
return 1;
if (config_file && config_file[0])
return _mariadb_read_options_from_file(mysql, config_file, group, recursion);
if (config_dir && config_dir[0])
{
for (exts= 0; ini_exts[exts]; exts++)
{
snprintf(filename, FN_REFLEN,
"%s%cmy.%s", config_dir, FN_LIBCHAR, ini_exts[exts]);
if (!access(filename, R_OK))
errors+= _mariadb_read_options_from_file(mysql, filename, group, recursion);
}
return errors;
}
for (i=0; i < MAX_CONFIG_DIRS && configuration_dirs[i]; i++)
{
for (exts= 0; ini_exts[exts]; exts++)
{
snprintf(filename, FN_REFLEN,
"%s%cmy.%s", configuration_dirs[i], FN_LIBCHAR, ini_exts[exts]);
if (!access(filename, R_OK))
errors+= _mariadb_read_options_from_file(mysql, filename, group, recursion);
}
}
#ifndef _WIN32
/* special case: .my.cnf in Home directory */
if ((env= getenv("HOME")))
{
for (exts= 0; ini_exts[exts]; exts++)
{
snprintf(filename, FN_REFLEN,
"%s%c.my.%s", env, FN_LIBCHAR, ini_exts[exts]);
if (!access(filename, R_OK))
errors+= _mariadb_read_options_from_file(mysql, filename, group, recursion);
}
}
#endif
return errors;
}

1924
vendor/MDBC/libmariadb/ma_dtoa.c vendored Normal file

File diff suppressed because it is too large Load Diff

116
vendor/MDBC/libmariadb/ma_errmsg.c vendored Normal file
View File

@ -0,0 +1,116 @@
/* 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
/* Error messages for clients */
/* error messages for the demon is in share/language/errmsg.sys */
#include <ma_global.h>
#include <ma_sys.h>
#include "errmsg.h"
#include <stdarg.h>
const char *SQLSTATE_UNKNOWN= "HY000";
const char *client_errors[]=
{
/* 2000 */ "Unknown error",
/* 2001 */ "Can't create UNIX socket (%d)",
/* 2002 */ "Can't connect to local server through socket '%-.64s' (%d)",
/* 2003 */ "Can't connect to server on '%-.64s' (%d)",
/* 2004 */ "Can't create TCP/IP socket (%d)",
/* 2005 */ "Unknown server host '%-.100s' (%d)",
/* 2006 */ "Server has gone away",
/* 2007 */ "Protocol mismatch. Server Version = %d Client Version = %d",
/* 2008 */ "Client run out of memory",
/* 2009 */ "Wrong host info",
/* 2010 */ "Localhost via UNIX socket",
/* 2011 */ "%-.64s via TCP/IP",
/* 2012 */ "Error in server handshake",
/* 2013 */ "Lost connection to server during query",
/* 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)",
/* 2018 */ "Can't set state of named pipe to host: %-.64s pipe: %-.32s (%lu)",
/* 2019 */ "Can't initialize character set %-.64s (path: %-.64s)",
/* 2020 */ "Got packet bigger than 'max_allowed_packet'",
/* 2021 */ "",
/* 2022 */ "",
/* 2023 */ "",
/* 2024 */ "",
/* 2025 */ "",
/* 2026 */ "SSL connection error: %-.100s",
/* 2027 */ "Received malformed packet",
/* 2028 */ "",
/* 2029 */ "",
/* 2030 */ "Statement is not prepared",
/* 2031 */ "No data supplied for parameters in prepared statement",
/* 2032 */ "Data truncated",
/* 2033 */ "",
/* 2034 */ "Invalid parameter number",
/* 2035 */ "Invalid buffer type: %d (parameter: %d)",
/* 2036 */ "Buffer type is not supported",
/* 2037 */ "Shared memory: %-.64s",
/* 2038 */ "Shared memory connection failed during %s. (%lu)",
/* 2039 */ "",
/* 2040 */ "",
/* 2041 */ "",
/* 2042 */ "",
/* 2043 */ "",
/* 2044 */ "",
/* 2045 */ "",
/* 2046 */ "",
/* 2047 */ "Wrong or unknown protocol",
/* 2048 */ "",
/* 2049 */ "Connection with old authentication protocol refused.",
/* 2050 */ "",
/* 2051 */ "",
/* 2052 */ "Prepared statement contains no metadata",
/* 2053 */ "",
/* 2054 */ "This feature is not implemented or disabled",
/* 2055 */ "Lost connection to server at '%s', system error: %d",
/* 2056 */ "Server closed statement due to a prior %s function call",
/* 2057 */ "The number of parameters in bound buffers differs from number of columns in resultset",
/* 2059 */ "Can't connect twice. Already connected",
/* 2058 */ "Plugin %s could not be loaded: %s",
/* 2059 */ "An attribute with same name already exists",
/* 2060 */ "Plugin doesn't support this function",
""
};
const char *mariadb_client_errors[] =
{
/* 5000 */ "Creating an event failed (Errorcode: %d)",
/* 5001 */ "Bind to local interface '-.%64s' failed (Errorcode: %d)",
/* 5002 */ "Connection type doesn't support asynchronous IO operations",
/* 5003 */ "Server doesn't support function '%s'",
/* 5004 */ "File '%s' not found (Errcode: %d)",
/* 5005 */ "Error reading file '%s' (Errcode: %d)",
/* 5006 */ "Bulk operation without parameters is not supported",
/* 5007 */ "Invalid statement handle",
/* 5008 */ "Unsupported version %d. Supported versions are in the range %d - %d",
""
};
const char ** NEAR my_errmsg[MAXMAPS]={0,0,0,0};
char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE];
void init_client_errs(void)
{
my_errmsg[CLIENT_ERRMAP] = &client_errors[0];
}

580
vendor/MDBC/libmariadb/ma_hashtbl.c vendored Normal file
View File

@ -0,0 +1,580 @@
/************************************************************************************
Copyright (C) 2000, 2012 MySQL AB & MySQL Finland AB & TCX DataKonsult AB,
Monty Program AB, 2016 MariaDB Corporation 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 <http://www.gnu.org/licenses>
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
*************************************************************************************/
/* The hash functions used for saving keys */
/* One of key_length or key_length_offset must be given */
/* Key length of 0 isn't allowed */
#include <ma_global.h>
#include <ma_sys.h>
#include <ma_string.h>
#include <mariadb_ctype.h>
#include "ma_hashtbl.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(MA_HASHTBL_LINK *array,uint pos,uint next_link,uint newlink);
static uint calc_hashnr(const uchar *key,uint length);
static uint calc_hashnr_caseup(const uchar *key,uint length);
static int hashcmp(MA_HASHTBL *hash,MA_HASHTBL_LINK *pos,const uchar *key,uint length);
my_bool _ma_hashtbl_init(MA_HASHTBL *hash,uint size,uint key_offset,uint key_length,
hash_get_key get_key,
void (*free_element)(void*),uint flags CALLER_INFO_PROTO)
{
hash->records=0;
if (ma_init_dynamic_array_ci(&hash->array,sizeof(MA_HASHTBL_LINK),size,0))
{
hash->free=0; /* Allow call to hash_free */
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 & MA_HASHTBL_CASE_INSENSITIVE)
hash->calc_hashnr=calc_hashnr_caseup;
else
hash->calc_hashnr=calc_hashnr;
return(0);
}
void ma_hashtbl_free(MA_HASHTBL *hash)
{
if (hash->free)
{
uint i,records;
MA_HASHTBL_LINK *data=dynamic_element(&hash->array,0,MA_HASHTBL_LINK*);
for (i=0,records=hash->records ; i < records ; i++)
(*hash->free)(data[i].data);
hash->free=0;
}
ma_delete_dynamic(&hash->array);
hash->records=0;
return;
}
/* some helper functions */
/*
This function is char* instead of uchar* as HPUX11 compiler can't
handle inline functions that are not defined as native types
*/
static inline char*
hash_key(MA_HASHTBL *hash,const uchar *record,uint *length,my_bool first)
{
if (hash->get_key)
return (char *)(*hash->get_key)(record,(uint *)length,first);
*length=hash->key_length;
return (char*) 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(MA_HASHTBL *hash,MA_HASHTBL_LINK *pos,uint buffmax,
uint maxlength)
{
uint length;
uchar *key= (uchar*) hash_key(hash,pos->data,&length,0);
return hash_mask((*hash->calc_hashnr)(key,length),buffmax,maxlength);
}
#ifndef NEW_MA_HASHTBL_FUNCTION
/* Calc hashvalue for a key */
static uint calc_hashnr(const uchar *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 independently */
static uint calc_hashnr_caseup(const uchar *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 uchar *key, uint len)
{
const uchar *end=key+len;
uint hash;
for (hash = 0; key < end; key++)
{
hash *= 16777619;
hash ^= (uint) *(uchar*) key;
}
return (hash);
}
uint calc_hashnr_caseup(const uchar *key, uint len)
{
const uchar *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 */
static inline
#endif
unsigned int rec_hashnr(MA_HASHTBL *hash,const uchar *record)
{
uint length;
uchar *key= (uchar*) 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 */
void* ma_hashtbl_search(MA_HASHTBL *hash,const uchar *key,uint length)
{
MA_HASHTBL_LINK *pos;
uint flag,idx;
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,MA_HASHTBL_LINK*);
if (!hashcmp(hash,pos,key,length))
{
hash->current_record= idx;
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;
return(0);
}
/* Get next record with identical key */
/* Can only be called if previous calls was hash_search */
void *ma_hashtbl_next(MA_HASHTBL *hash,const uchar *key,uint length)
{
MA_HASHTBL_LINK *pos;
uint idx;
if (hash->current_record != NO_RECORD)
{
MA_HASHTBL_LINK *data=dynamic_element(&hash->array,0,MA_HASHTBL_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(MA_HASHTBL_LINK *array,uint find,uint next_link,uint newlink)
{
MA_HASHTBL_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(MA_HASHTBL *hash,MA_HASHTBL_LINK *pos,const uchar *key,uint length)
{
uint rec_keylength;
uchar *rec_key= (uchar*) hash_key(hash,pos->data,&rec_keylength,1);
return (length && length != rec_keylength) ||
memcmp(rec_key,key,rec_keylength);
}
/* Write a hash-key to the hash-index */
my_bool ma_hashtbl_insert(MA_HASHTBL *info,const uchar *record)
{
int flag;
uint halfbuff,hash_nr,first_index,idx;
uchar *ptr_to_rec= NULL,*ptr_to_rec2= NULL;
MA_HASHTBL_LINK *data,*empty,*gpos= NULL,*gpos2 = NULL,*pos;
LINT_INIT(gpos); LINT_INIT(gpos2);
LINT_INIT(ptr_to_rec); LINT_INIT(ptr_to_rec2);
flag=0;
if (!(empty=(MA_HASHTBL_LINK*) ma_alloc_dynamic(&info->array)))
return(TRUE); /* No more memory */
info->current_record= NO_RECORD;
data=dynamic_element(&info->array,0,MA_HASHTBL_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=(uchar*) 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=(uchar*) record;
pos->next=(uint) (empty - data);
}
else
{
pos->data=(uchar*) 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 ma_hashtbl_delete(MA_HASHTBL *hash,uchar *record)
{
uint blength,pos2,pos_hashnr,lastpos_hashnr,idx,empty_index;
MA_HASHTBL_LINK *data,*lastpos,*gpos,*pos,*pos3,*empty;
if (!hash->records)
return(1);
blength=hash->blength;
data=dynamic_element(&hash->array,0,MA_HASHTBL_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)
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:
ma_pop_dynamic(&hash->array);
if (hash->free)
(*hash->free)((uchar*) record);
return(0);
}
/*
Update keys when record has changed.
This is much more efficient than using a delete & insert.
*/
my_bool ma_hashtbl_update(MA_HASHTBL *hash,uchar *record,uchar *old_key,uint old_key_length)
{
uint idx,new_index,new_pos_index,blength,records,empty;
MA_HASHTBL_LINK org_link,*data,*previous,*pos;
data=dynamic_element(&hash->array,0,MA_HASHTBL_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)
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)
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;
}
return(0);
}
uchar *ma_hashtbl_element(MA_HASHTBL *hash,uint idx)
{
if (idx < hash->records)
return dynamic_element(&hash->array,idx,MA_HASHTBL_LINK*)->data;
return 0;
}

87
vendor/MDBC/libmariadb/ma_init.c vendored Normal file
View File

@ -0,0 +1,87 @@
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
2016 MariaDB Corporation 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
#include <ma_global.h>
#include <ma_sys.h>
#include "mariadb_ctype.h"
#include <ma_string.h>
#include <mariadb_ctype.h>
#include <signal.h>
#ifdef _WIN32
#ifdef _MSC_VER
#include <locale.h>
#include <crtdbg.h>
#endif
static my_bool my_win_init(void);
#else
#define my_win_init()
#endif
my_bool ma_init_done=0;
/* Init ma_sys functions and ma_sys variabels */
void ma_init(void)
{
if (ma_init_done)
return;
ma_init_done=1;
{
#ifdef _WIN32
my_win_init();
#endif
return;
}
} /* ma_init */
void ma_end(int infoflag __attribute__((unused)))
{
#ifdef _WIN32
WSACleanup( );
#endif /* _WIN32 */
ma_init_done=0;
} /* ma_end */
#ifdef _WIN32
static my_bool my_win_init()
{
WORD VersionRequested;
int err;
WSADATA WsaData;
const unsigned int MajorVersion=2,
MinorVersion=2;
VersionRequested= MAKEWORD(MajorVersion, MinorVersion);
/* Load WinSock library */
if ((err= WSAStartup(VersionRequested, &WsaData)))
{
return 0;
}
/* make sure 2.2 or higher is supported */
if ((LOBYTE(WsaData.wVersion) * 10 + HIBYTE(WsaData.wVersion)) < 22)
{
WSACleanup();
return 1;
}
return 0;
}
#endif

224
vendor/MDBC/libmariadb/ma_io.c vendored Normal file
View File

@ -0,0 +1,224 @@
/*
Copyright (C) 2015 MariaDB Corporation 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA
*/
#include <ma_global.h>
#include <ma_sys.h>
#include <errmsg.h>
#include <mysql.h>
#include <mysql/client_plugin.h>
#include <mariadb/ma_io.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_REMOTEIO
struct st_mysql_client_plugin_REMOTEIO *rio_plugin= NULL;
#endif
/* {{{ ma_open */
MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql)
{
int CodePage= -1;
FILE *fp= NULL;
MA_FILE *ma_file= NULL;
if (!location || !location[0])
return NULL;
#ifdef HAVE_REMOTEIO
if (strstr(location, "://"))
goto remote;
#endif
#ifdef _WIN32
if (mysql && mysql->charset)
CodePage= madb_get_windows_cp(mysql->charset->csname);
#endif
if (CodePage == -1)
{
if (!(fp= fopen(location, mode)))
{
return NULL;
}
}
#ifdef _WIN32
/* See CONC-44: we need to support non ascii filenames too, so we convert
current character set to wchar_t and try to open the file via _wsopen */
else
{
wchar_t *w_filename= NULL;
wchar_t *w_mode= NULL;
int len;
DWORD Length;
len= MultiByteToWideChar(CodePage, 0, location, (int)strlen(location), NULL, 0);
if (!len)
return NULL;
if (!(w_filename= (wchar_t *)calloc(1, (len + 1) * sizeof(wchar_t))))
{
my_set_error(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0);
return NULL;
}
Length= len;
len= MultiByteToWideChar(CodePage, 0, location, (int)strlen(location), w_filename, (int)Length);
if (!len)
{
/* todo: error handling */
free(w_filename);
return NULL;
}
len= (int)strlen(mode);
if (!(w_mode= (wchar_t *)calloc(1, (len + 1) * sizeof(wchar_t))))
{
my_set_error(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0);
free(w_filename);
return NULL;
}
Length= len;
len= MultiByteToWideChar(CodePage, 0, mode, (int)strlen(mode), w_mode, (int)Length);
if (!len)
{
/* todo: error handling */
free(w_filename);
free(w_mode);
return NULL;
}
fp= _wfopen(w_filename, w_mode);
free(w_filename);
free(w_mode);
}
#endif
if (fp)
{
ma_file= (MA_FILE *)malloc(sizeof(MA_FILE));
if (!ma_file)
{
fclose(fp);
my_set_error(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0);
return NULL;
}
ma_file->type= MA_FILE_LOCAL;
ma_file->ptr= (void *)fp;
}
return ma_file;
#ifdef HAVE_REMOTEIO
remote:
/* check if plugin for remote io is available and try
* to open location */
{
MYSQL mysql;
if (rio_plugin ||(rio_plugin= (struct st_mysql_client_plugin_REMOTEIO *)
mysql_client_find_plugin(&mysql, NULL, MARIADB_CLIENT_REMOTEIO_PLUGIN)))
return rio_plugin->methods->mopen(location, mode);
return NULL;
}
#endif
}
/* }}} */
/* {{{ ma_close */
int ma_close(MA_FILE *file)
{
int rc;
if (!file)
return -1;
switch (file->type) {
case MA_FILE_LOCAL:
rc= fclose((FILE *)file->ptr);
free(file);
break;
#ifdef HAVE_REMOTEIO
case MA_FILE_REMOTE:
rc= rio_plugin->methods->mclose(file);
break;
#endif
default:
return -1;
}
return rc;
}
/* }}} */
/* {{{ ma_feof */
int ma_feof(MA_FILE *file)
{
if (!file)
return -1;
switch (file->type) {
case MA_FILE_LOCAL:
return feof((FILE *)file->ptr);
break;
#ifdef HAVE_REMOTEIO
case MA_FILE_REMOTE:
return rio_plugin->methods->mfeof(file);
break;
#endif
default:
return -1;
}
}
/* }}} */
/* {{{ ma_read */
size_t ma_read(void *ptr, size_t size, size_t nmemb, MA_FILE *file)
{
size_t s= 0;
if (!file)
return -1;
switch (file->type) {
case MA_FILE_LOCAL:
s= fread(ptr, size, nmemb, (FILE *)file->ptr);
return s;
break;
#ifdef HAVE_REMOTEIO
case MA_FILE_REMOTE:
return rio_plugin->methods->mread(ptr, size, nmemb, file);
break;
#endif
default:
return -1;
}
}
/* }}} */
/* {{{ ma_gets */
char *ma_gets(char *ptr, size_t size, MA_FILE *file)
{
if (!file)
return NULL;
switch (file->type) {
case MA_FILE_LOCAL:
return fgets(ptr, (int)size, (FILE *)file->ptr);
break;
#ifdef HAVE_REMOTEIO
case MA_FILE_REMOTE:
return rio_plugin->methods->mgets(ptr, size, file);
break;
#endif
default:
return NULL;
}
}
/* }}} */

114
vendor/MDBC/libmariadb/ma_list.c vendored Normal file
View File

@ -0,0 +1,114 @@
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
2016 MariaDB Corporation 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
/*
Code for handling dubble-linked lists in C
*/
#include <ma_global.h>
#include <ma_sys.h>
#include <ma_list.h>
/* Add a element to start of list */
LIST *list_add(LIST *root, LIST *element)
{
if (root)
{
if (root->prev) /* If add in mid of list */
root->prev->next= element;
element->prev=root->prev;
root->prev=element;
}
else
element->prev=0;
element->next=root;
return(element); /* New root */
}
LIST *list_delete(LIST *root, LIST *element)
{
if (element->prev)
element->prev->next=element->next;
else
root=element->next;
if (element->next)
element->next->prev=element->prev;
return root;
}
void list_free(LIST *root, unsigned int free_data)
{
LIST *next;
while (root)
{
next=root->next;
if (free_data)
free(root->data);
free(root);
root=next;
}
}
LIST *list_cons(void *data, LIST *list)
{
LIST *new_charset=(LIST*) malloc(sizeof(LIST));
if (!new_charset)
return 0;
new_charset->data=data;
return list_add(list,new_charset);
}
LIST *list_reverse(LIST *root)
{
LIST *last;
last=root;
while (root)
{
last=root;
root=root->next;
last->next=last->prev;
last->prev=root;
}
return last;
}
uint list_length(LIST *list)
{
uint count;
for (count=0 ; list ; list=list->next, count++) ;
return count;
}
int list_walk(LIST *list, list_walk_action action, gptr argument)
{
int error=0;
while (list)
{
if ((error = (*action)(list->data,argument)))
return error;
list= list_rest(list);
}
return 0;
}

70
vendor/MDBC/libmariadb/ma_ll2str.c vendored Normal file
View File

@ -0,0 +1,70 @@
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
2016,2018 MariaDB Corporation 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
#include <ma_global.h>
#include "ma_string.h"
#include <ctype.h>
static char NEAR _dig_vec[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char *ma_ll2str(long long val,char *dst,int radix)
{
char buffer[65];
register char *p;
long long_val;
if (radix < 0)
{
if (radix < -36 || radix > -2) return (char*) 0;
if (val < 0) {
*dst++ = '-';
val = 0ULL - val;
}
radix = -radix;
}
else
{
if (radix > 36 || radix < 2) return (char*) 0;
}
if (val == 0)
{
*dst++='0';
*dst='\0';
return dst;
}
p = &buffer[sizeof(buffer)-1];
*p = '\0';
while ((ulonglong) val > (ulonglong) LONG_MAX)
{
ulonglong quo=(ulonglong) val/(uint) radix;
uint rem= (uint) (val- quo* (uint) radix);
*--p = _dig_vec[rem];
val= quo;
}
long_val= (long) val;
while (long_val != 0)
{
long quo= long_val/radix;
*--p = _dig_vec[(uchar) (long_val - quo*radix)];
long_val= quo;
}
while ((*dst++ = *p++) != 0) ;
return dst-1;
}

265
vendor/MDBC/libmariadb/ma_loaddata.c vendored Normal file
View File

@ -0,0 +1,265 @@
/************************************************************************************
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 <http://www.gnu.org/licenses>
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 <georg@mysql.com> |
| Andrey Hristov <andrey@mysql.com> |
| Ulf Wendel <uwendel@mysql.com> |
+----------------------------------------------------------------------+
*/
#include "ma_global.h"
#include <ma_sys.h>
#include <ma_string.h>
#include "errmsg.h"
#include "mysql.h"
#include <mariadb/ma_io.h>
#include <string.h>
#ifdef _WIN32
#include <share.h>
#endif
#include <ma_common.h>
typedef struct st_mysql_infile_info
{
MA_FILE *fp;
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;
MYSQL *mysql= (MYSQL *)userdata;
info = (MYSQL_INFILE_INFO *)malloc(sizeof(MYSQL_INFILE_INFO));
if (!info) {
return(1);
}
memset(info, 0, sizeof(MYSQL_INFILE_INFO));
*ptr = info;
info->filename = filename;
info->fp= ma_open(filename, "rb", mysql);
if (!info->fp)
{
/* error handling is done via mysql_local_infile_error function, so we
need to copy error to info */
if (mysql_errno(mysql) && !info->error_no)
{
info->error_no= mysql_errno(mysql);
ma_strmake(info->error_msg, mysql_error(mysql), MYSQL_ERRMSG_SIZE);
}
else
{
info->error_no = errno;
snprintf((char *)info->error_msg, sizeof(info->error_msg),
CER(CR_FILE_NOT_FOUND), filename, info->error_no);
}
return(1);
}
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;
size_t count;
count= ma_read((void *)buf, 1, (size_t)buf_len, info->fp);
if (count == (size_t)-1)
{
info->error_no = errno;
snprintf((char *)info->error_msg, sizeof(info->error_msg),
CER(CR_FILE_READ), info->filename, info->error_no);
}
return((int)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;
if (info) {
ma_strmake(error_buf, info->error_msg, error_buf_len);
return(info->error_no);
}
ma_strmake(error_buf, "Unknown error", error_buf_len);
return(CR_UNKNOWN_ERROR);
}
/* }}} */
/* {{{ mysql_local_infile_end */
static
void mysql_local_infile_end(void *ptr)
{
MYSQL_INFILE_INFO *info = (MYSQL_INFILE_INFO *)ptr;
if (info)
{
if (info->fp)
ma_close(info->fp);
free(ptr);
}
return;
}
/* }}} */
/* {{{ mysql_local_infile_default */
void mysql_set_local_infile_default(MYSQL *conn)
{
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;
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)
{
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;
return;
}
/* }}} */
/* {{{ mysql_handle_local_infile */
my_bool mysql_handle_local_infile(MYSQL *conn, const char *filename, my_bool can_local_infile)
{
unsigned int buflen= 4096;
int bufread;
unsigned char *buf= NULL;
void *info= NULL;
my_bool result= 1;
/* 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)
{
conn->options.local_infile_userdata= conn;
mysql_set_local_infile_default(conn);
}
if (!(conn->options.client_flag & CLIENT_LOCAL_FILES) ||
!can_local_infile)
{
my_set_error(conn, CR_UNKNOWN_ERROR, SQLSTATE_UNKNOWN, "Load data local infile forbidden");
/* write empty packet to server */
ma_net_write(&conn->net, (unsigned char *)"", 0);
ma_net_flush(&conn->net);
goto infile_error;
}
/* allocate buffer for reading data */
buf = (uchar *)malloc(buflen);
/* 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);
ma_net_write(&conn->net, (unsigned char *)"", 0);
ma_net_flush(&conn->net);
goto infile_error;
}
/* read data */
while ((bufread= conn->options.local_infile_read(info, (char *)buf, buflen)) > 0)
{
if (ma_net_write(&conn->net, (unsigned char *)buf, bufread))
{
my_set_error(conn, CR_SERVER_LOST, SQLSTATE_UNKNOWN, NULL);
goto infile_error;
}
}
/* send empty packet for eof */
if (ma_net_write(&conn->net, (unsigned char *)"", 0) ||
ma_net_flush(&conn->net))
{
my_set_error(conn, CR_SERVER_LOST, SQLSTATE_UNKNOWN, NULL);
goto infile_error;
}
/* error during read occurred */
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);
free(buf);
return(result);
}
/* }}} */

591
vendor/MDBC/libmariadb/ma_net.c vendored Normal file
View File

@ -0,0 +1,591 @@
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
2012-2016 SkySQL AB, MariaDB Corporation 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
/* Write and read of logical packets to/from socket
** Writes are cached into net_buffer_length big packets.
** Read packets are reallocated dynamically when reading big packets.
** Each logical packet has the following pre-info:
** 3 byte length & 1 byte package-number.
*/
#include <ma_global.h>
#include <mysql.h>
#include <ma_pvio.h>
#include <ma_sys.h>
#include <ma_string.h>
#include "mysql.h"
#include "ma_server_error.h"
#include <signal.h>
#include <errno.h>
#include <sys/types.h>
#include <ma_pvio.h>
#include <ma_common.h>
#ifndef _WIN32
#include <poll.h>
#endif
#define MAX_PACKET_LENGTH (256L*256L*256L-1)
/* net_buffer_length and max_allowed_packet are defined in mysql.h
See bug conc-57
*/
#undef net_buffer_length
#undef max_allowed_packet
ulong max_allowed_packet=1024L * 1024L * 1024L;
ulong net_read_timeout= NET_READ_TIMEOUT;
ulong net_write_timeout= NET_WRITE_TIMEOUT;
ulong net_buffer_length= 8192; /* Default length. Enlarged if necessary */
#if !defined(_WIN32)
#include <sys/socket.h>
#else
#undef MYSQL_SERVER /* Win32 can't handle interrupts */
#endif
#if !defined(_WIN32) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__)
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#if !defined(alpha_linux_port)
#include <netinet/tcp.h>
#endif
#endif
/*
** Give error if a too big packet is found
** The server can change this with the -O switch, but because the client
** can't normally do this the client should have a bigger max-buffer.
*/
static int ma_net_write_buff(NET *net,const char *packet, size_t len);
/* Init with packet info */
int ma_net_init(NET *net, MARIADB_PVIO* pvio)
{
if (!(net->buff=(uchar*) malloc(net_buffer_length)))
return 1;
if (!net->extension)
return 1;
memset(net->buff, 0, net_buffer_length);
net->max_packet_size= MAX(net_buffer_length, max_allowed_packet);
net->buff_end=net->buff+(net->max_packet=net_buffer_length);
net->pvio = pvio;
net->error=0; net->return_status=0;
net->read_timeout=(uint) net_read_timeout; /* Timeout for read */
net->compress_pkt_nr= net->pkt_nr= 0;
net->write_pos=net->read_pos = net->buff;
net->last_error[0]= net->sqlstate[0] =0;
net->compress=0; net->reading_or_writing=0;
net->where_b = net->remain_in_buf=0;
net->last_errno=0;
if (pvio != 0) /* If real connection */
{
ma_pvio_get_handle(pvio, &net->fd);
ma_pvio_blocking(pvio, 1, 0);
ma_pvio_fast_send(pvio);
}
return 0;
}
void ma_net_end(NET *net)
{
free(net->buff);
net->buff=0;
}
/* Realloc the packet buffer */
static my_bool net_realloc(NET *net, size_t length)
{
uchar *buff;
size_t pkt_length;
if (length >= net->max_packet_size)
{
net->error=1;
net->last_errno=ER_NET_PACKET_TOO_LARGE;
return(1);
}
pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1);
/* reallocate buffer:
size= pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE */
if (!(buff=(uchar*) realloc(net->buff,
pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE)))
{
net->error=1;
return(1);
}
net->buff=net->write_pos=buff;
net->buff_end=buff+(net->max_packet=(unsigned long)pkt_length);
return(0);
}
/* Remove unwanted characters from connection */
void ma_net_clear(NET *net)
{
if (net->extension->multi_status > COM_MULTI_OFF)
return;
net->compress_pkt_nr= net->pkt_nr=0; /* Ready for new command */
net->write_pos=net->buff;
return;
}
/* Flush write_buffer if not empty. */
int ma_net_flush(NET *net)
{
int error=0;
/* don't flush if pipelined query is in progress */
if (net->extension->multi_status > COM_MULTI_OFF)
return 0;
if (net->buff != net->write_pos)
{
error=ma_net_real_write(net,(char*) net->buff,
(size_t) (net->write_pos - net->buff));
net->write_pos=net->buff;
}
if (net->compress)
net->pkt_nr= net->compress_pkt_nr;
return(error);
}
/*****************************************************************************
** Write something to server/client buffer
*****************************************************************************/
/*
** Write a logical packet with packet header
** Format: Packet length (3 bytes), packet number(1 byte)
** When compression is used a 3 byte compression length is added
** NOTE: If compression is used the original package is destroyed!
*/
int ma_net_write(NET *net, const uchar *packet, size_t len)
{
uchar buff[NET_HEADER_SIZE];
while (len >= MAX_PACKET_LENGTH)
{
const ulong max_len= MAX_PACKET_LENGTH;
int3store(buff,max_len);
buff[3]= (uchar)net->pkt_nr++;
if (ma_net_write_buff(net,(char*) buff,NET_HEADER_SIZE) ||
ma_net_write_buff(net, (char *)packet, max_len))
return 1;
packet+= max_len;
len-= max_len;
}
/* write last remaining packet, size can be zero */
int3store(buff, len);
buff[3]= (uchar)net->pkt_nr++;
if (ma_net_write_buff(net,(char*) buff,NET_HEADER_SIZE) ||
ma_net_write_buff(net, (char *)packet, len))
return 1;
return 0;
}
int ma_net_write_command(NET *net, uchar command,
const char *packet, size_t len,
my_bool disable_flush)
{
uchar buff[NET_HEADER_SIZE+1];
size_t buff_size= NET_HEADER_SIZE + 1;
size_t length= 1 + len; /* 1 extra byte for command */
int rc;
buff[NET_HEADER_SIZE]= 0;
buff[4]=command;
if (length >= MAX_PACKET_LENGTH)
{
len= MAX_PACKET_LENGTH - 1;
do
{
int3store(buff, MAX_PACKET_LENGTH);
buff[3]= (net->compress) ? 0 : (uchar) (net->pkt_nr++);
if (ma_net_write_buff(net, (char *)buff, buff_size) ||
ma_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++);
rc= test (ma_net_write_buff(net,(char *)buff, buff_size) ||
ma_net_write_buff(net,packet,len));
if (!rc && !disable_flush)
return test(ma_net_flush(net));
return rc;
}
static int ma_net_write_buff(NET *net,const char *packet, size_t len)
{
size_t left_length;
if (!len)
return 0;
if (net->max_packet > MAX_PACKET_LENGTH &&
net->compress)
left_length= (size_t)(MAX_PACKET_LENGTH - (net->write_pos - net->buff));
else
left_length=(size_t) (net->buff_end - net->write_pos);
if (len > left_length)
{
if (net->write_pos != net->buff)
{
memcpy((char*) net->write_pos,packet,left_length);
if (ma_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 (net->compress)
{
/* uncompressed length is stored in 3 bytes,so
packet can't be > 0xFFFFFF */
left_length= MAX_PACKET_LENGTH;
while (len > left_length)
{
if (ma_net_real_write(net, packet, left_length))
return 1;
packet+= left_length;
len-= left_length;
}
}
if (len > net->max_packet)
return(test(ma_net_real_write(net, packet, len)));
}
memcpy((char*) net->write_pos,packet,len);
net->write_pos+=len;
return 0;
}
unsigned char *mysql_net_store_length(unsigned char *packet, size_t length);
/* Read and write using timeouts */
int ma_net_real_write(NET *net, const char *packet, size_t len)
{
ssize_t length;
char *pos,*end;
if (net->error == 2)
return(-1); /* socket can't be used */
net->reading_or_writing=2;
#ifdef HAVE_COMPRESS
if (net->compress)
{
size_t complen;
uchar *b;
uint header_length=NET_HEADER_SIZE+COMP_HEADER_SIZE;
if (!(b=(uchar*) malloc(len + NET_HEADER_SIZE + COMP_HEADER_SIZE + 1)))
{
net->last_errno=ER_OUT_OF_RESOURCES;
net->error=2;
net->reading_or_writing=0;
return(1);
}
memcpy(b+header_length,packet,len);
if (_mariadb_compress((unsigned char*) b+header_length,&len,&complen))
{
complen=0;
}
int3store(&b[NET_HEADER_SIZE],complen);
int3store(b,len);
b[3]=(uchar) (net->compress_pkt_nr++);
len+= header_length;
packet= (char*) b;
}
#endif /* HAVE_COMPRESS */
pos=(char*) packet; end=pos+len;
while (pos != end)
{
if ((length=ma_pvio_write(net->pvio,(uchar *)pos,(size_t) (end-pos))) <= 0)
{
net->error=2; /* Close socket */
net->last_errno= ER_NET_ERROR_ON_WRITE;
net->reading_or_writing=0;
#ifdef HAVE_COMPRESS
if (net->compress)
free((char*) packet);
#endif
return(1);
}
pos+=length;
}
#ifdef HAVE_COMPRESS
if (net->compress)
free((char*) packet);
#endif
net->reading_or_writing=0;
return(((int) (pos != end)));
}
/*****************************************************************************
** Read something from server/clinet
*****************************************************************************/
static ulong ma_real_read(NET *net, size_t *complen)
{
uchar *pos;
ssize_t length;
uint i;
ulong len=packet_error;
size_t remain= (net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE :
NET_HEADER_SIZE);
*complen = 0;
net->reading_or_writing=1;
pos = net->buff + net->where_b; /* net->packet -4 */
for (i=0 ; i < 2 ; i++)
{
while (remain > 0)
{
/* First read is done with non blocking mode */
if ((length=ma_pvio_cache_read(net->pvio, pos,remain)) <= 0L)
{
len= packet_error;
net->error=2; /* Close socket */
goto end;
}
remain -= (ulong) length;
pos+= (ulong) length;
}
if (i == 0)
{ /* First parts is packet length */
ulong helping;
net->pkt_nr= net->buff[net->where_b + 3];
net->compress_pkt_nr= ++net->pkt_nr;
#ifdef HAVE_COMPRESS
if (net->compress)
{
/* complen is > 0 if package is really compressed */
*complen=uint3korr(&(net->buff[net->where_b + NET_HEADER_SIZE]));
}
#endif
len=uint3korr(net->buff+net->where_b);
if (!len)
goto end;
helping = max(len,(ulong)*complen) + net->where_b;
/* The necessary size of net->buff */
if (helping >= net->max_packet)
{
if (net_realloc(net, helping))
{
len= packet_error; /* Return error */
goto end;
}
}
pos=net->buff + net->where_b;
remain = len;
}
}
end:
net->reading_or_writing=0;
return(len);
}
ulong ma_net_read(NET *net)
{
size_t len,complen;
#ifdef HAVE_COMPRESS
if (!net->compress)
{
#endif
len = ma_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+= (unsigned long)len;
len= ma_real_read(net, &complen);
} 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 */
return (ulong)len;
#ifdef HAVE_COMPRESS
}
else
{
/*
compressed protocol:
--------------------------------------
packet_length 3
sequence_id 1
uncompressed_length 3
--------------------------------------
compressed data packet_length - 7
--------------------------------------
Another packet will follow if:
packet_length == MAX_PACKET_LENGTH
Last package will be identified by
- packet_length is zero (special case)
- packet_length < MAX_PACKET_LENGTH
*/
size_t packet_length,
buffer_length;
size_t current= 0, start= 0;
my_bool is_multi_packet= 0;
/* check if buffer is empty */
if (!net->remain_in_buf)
{
buffer_length= 0;
}
else
{
/* save position and restore \0 character */
buffer_length= net->buf_length;
current= net->buf_length - net->remain_in_buf;
start= current;
net->buff[net->buf_length - net->remain_in_buf]=net->save_char;
}
for (;;)
{
if (buffer_length - current >= 4)
{
uchar *pos= net->buff + current;
packet_length= uint3korr(pos);
/* check if we have last package (special case: zero length) */
if (!packet_length)
{
current+= 4; /* length + sequence_id,
no more data will follow */
break;
}
if (packet_length + 4 <= buffer_length - current)
{
if (!is_multi_packet)
{
current= current + packet_length + 4;
}
else
{
/* remove packet_header */
memmove(net->buff + current,
net->buff + current + 4,
buffer_length - current);
buffer_length-= 4;
current+= packet_length;
}
/* do we have last packet ? */
if (packet_length != MAX_PACKET_LENGTH)
{
is_multi_packet= 0;
break;
}
else
is_multi_packet= 1;
if (start)
{
memmove(net->buff, net->buff + start,
buffer_length - start);
/* decrease buflen*/
buffer_length-= start;
start= 0;
}
continue;
}
}
if (start)
{
memmove(net->buff, net->buff + start, buffer_length - start);
/* decrease buflen and current */
current -= start;
buffer_length-= start;
start= 0;
}
net->where_b=(unsigned long)buffer_length;
if ((packet_length = ma_real_read(net,(size_t *)&complen)) == packet_error)
return packet_error;
if (_mariadb_uncompress((unsigned char*) net->buff + net->where_b, &packet_length, &complen))
{
net->error=2; /* caller will close socket */
net->last_errno=ER_NET_UNCOMPRESS_ERROR;
break;
return packet_error;
}
buffer_length+= complen;
}
/* set values */
net->buf_length= (unsigned long)buffer_length;
net->remain_in_buf= (unsigned long)(buffer_length - current);
net->read_pos= net->buff + start + 4;
len= current - start - 4;
if (is_multi_packet)
len-= 4;
net->save_char= net->read_pos[len]; /* Must be saved */
net->read_pos[len]=0; /* Safeguard for mysql_use_result */
}
#endif
return (ulong)len;
}
int net_add_multi_command(NET *net, uchar command, const uchar *packet,
size_t length)
{
if (net->extension->multi_status == COM_MULTI_OFF)
{
return(1);
}
/* don't increase packet number */
net->compress_pkt_nr= net->pkt_nr= 0;
return ma_net_write_command(net, command, (const char *)packet, length, 1);
}

162
vendor/MDBC/libmariadb/ma_password.c vendored Normal file
View File

@ -0,0 +1,162 @@
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
2016,2018 MariaDB Corporation 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
/* password checking routines */
/*****************************************************************************
The main idea is that no password are sent between client & server on
connection and that no password are saved in mysql in a decodable form.
On connection a random string is generated and sent to the client.
The client generates a new string with a random generator inited with
the hash values from the password and the sent string.
This 'check' string is sent to the server where it is compared with
a string generated from the stored hash_value of the password and the
random string.
The password is saved (in user.password) by using the PASSWORD() function in
mysql.
Example:
update user set password=PASSWORD("hello") where user="test"
This saves a hashed number as a string in the password field.
*****************************************************************************/
#include <ma_global.h>
#include <ma_sys.h>
#include <ma_string.h>
#include <ma_sha1.h>
#include "mysql.h"
void ma_randominit(struct rand_struct *rand_st,ulong seed1, ulong seed2)
{ /* For mysql 3.21.# */
#ifdef HAVE_purify
memset((char*) rand_st, 0m sizeof(*rand_st)); /* Avoid UMC warnings */
#endif
rand_st->max_value= 0x3FFFFFFFL;
rand_st->max_value_dbl=(double) rand_st->max_value;
rand_st->seed1=seed1%rand_st->max_value ;
rand_st->seed2=seed2%rand_st->max_value;
}
double rnd(struct rand_struct *rand_st)
{
rand_st->seed1=(rand_st->seed1*3+rand_st->seed2) % rand_st->max_value;
rand_st->seed2=(rand_st->seed1+rand_st->seed2+33) % rand_st->max_value;
return (((double) rand_st->seed1)/rand_st->max_value_dbl);
}
void ma_hash_password(ulong *result, const char *password, size_t len)
{
register ulong nr=1345345333L, add=7, nr2=0x12345671L;
ulong tmp;
const char *password_end= password + len;
for (; password < password_end; password++)
{
if (*password == ' ' || *password == '\t')
continue; /* skip space in password */
tmp= (ulong) (uchar) *password;
nr^= (((nr & 63)+add)*tmp)+ (nr << 8);
nr2+=(nr2 << 8) ^ nr;
add+=tmp;
}
result[0]=nr & (((ulong) 1L << 31) -1L); /* Don't use sign bit (str2int) */;
result[1]=nr2 & (((ulong) 1L << 31) -1L);
return;
}
/*
* Generate 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 ma_scramble_41(const unsigned char *buffer, const char *scramble, const char *password)
{
_MA_SHA1_CTX context;
unsigned char sha1[SHA1_MAX_LENGTH];
unsigned char sha2[SHA1_MAX_LENGTH];
/* Phase 1: hash password */
ma_SHA1Init(&context);
ma_SHA1Update(&context, (unsigned char *)password, strlen((char *)password));
ma_SHA1Final(sha1, &context);
/* Phase 2: hash sha1 */
ma_SHA1Init(&context);
ma_SHA1Update(&context, (unsigned char*)sha1, SHA1_MAX_LENGTH);
ma_SHA1Final(sha2, &context);
/* Phase 3: hash scramble + sha2 */
ma_SHA1Init(&context);
ma_SHA1Update(&context, (unsigned char *)scramble, SCRAMBLE_LENGTH);
ma_SHA1Update(&context, (unsigned char*)sha2, SHA1_MAX_LENGTH);
ma_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 ma_make_scrambled_password(char *to,const char *password)
{
ulong hash_res[2];
ma_hash_password(hash_res,password, strlen(password));
sprintf(to,"%08lx%08lx",hash_res[0],hash_res[1]);
}
/*
* Generate a new message based on message and password
* The same thing is done in client and server and the results are checked.
*/
char *ma_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 extra, *to_start=to;
const char *end_scramble323= message + SCRAMBLE_LENGTH_323;
ma_hash_password(hash_pass,password, (uint) strlen(password));
/* Don't use strlen, could be > SCRAMBLE_LENGTH_323 ! */
ma_hash_password(hash_message, message, SCRAMBLE_LENGTH_323);
ma_randominit(&rand_st, hash_pass[0] ^ hash_message[0],
hash_pass[1] ^ hash_message[1]);
for (; message < end_scramble323; message++)
*to++= (char) (floor(rnd(&rand_st) * 31) + 64);
extra=(char) (floor(rnd(&rand_st) * 31));
while (to_start != to)
*(to_start++)^= extra;
}
*to= 0;
return to;
}

594
vendor/MDBC/libmariadb/ma_pvio.c vendored Normal file
View File

@ -0,0 +1,594 @@
/************************************************************************************
Copyright (C) 2015 MariaDB Corporation 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 <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
*************************************************************************************/
/* MariaDB Communication IO (PVIO) interface
PVIO is the interface for client server communication and replaces former vio
component of the client library.
PVIO support various protcols like sockets, pipes and shared memory, which are
implemented as plugins and can be extended therefore easily.
Interface function description:
ma_pvio_init allocates a new PVIO object which will be used
for the current connection
ma_pvio_close frees all resources of previously allocated PVIO object
and closes open connections
ma_pvio_read reads data from server
ma_pvio_write sends data to server
ma_pvio_set_timeout sets timeout for connection, read and write
ma_pvio_register_callback
register callback functions for read and write
*/
#include <ma_global.h>
#include <ma_sys.h>
#include <mysql.h>
#include <errmsg.h>
#include <mysql/client_plugin.h>
#include <string.h>
#include <ma_common.h>
#include <ma_pvio.h>
#include <mariadb_async.h>
#include <ma_context.h>
/* callback functions for read/write */
LIST *pvio_callback= NULL;
#define IS_BLOCKING_ERROR() \
IF_WIN(WSAGetLastError() != WSAEWOULDBLOCK, \
(errno != EAGAIN && errno != EINTR))
/* {{{ MARIADB_PVIO *ma_pvio_init */
MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo)
{
/* check connection type and load the required plugin.
* Currently we support the following pvio types:
* pvio_socket
* pvio_namedpipe
* pvio_sharedmed
*/
const char *pvio_plugins[] = {"pvio_socket", "pvio_npipe", "pvio_shmem"};
int type;
MARIADB_PVIO_PLUGIN *pvio_plugin;
MARIADB_PVIO *pvio= NULL;
switch (cinfo->type)
{
case PVIO_TYPE_UNIXSOCKET:
case PVIO_TYPE_SOCKET:
type= 0;
break;
#ifdef _WIN32
case PVIO_TYPE_NAMEDPIPE:
type= 1;
break;
case PVIO_TYPE_SHAREDMEM:
type= 2;
break;
#endif
default:
return NULL;
}
if (!(pvio_plugin= (MARIADB_PVIO_PLUGIN *)
mysql_client_find_plugin(cinfo->mysql,
pvio_plugins[type],
MARIADB_CLIENT_PVIO_PLUGIN)))
{
/* error already set in mysql_client_find_plugin */
return NULL;
}
/* coverity[var_deref_op] */
if (!(pvio= (MARIADB_PVIO *)calloc(1, sizeof(MARIADB_PVIO))))
{
my_set_error(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0);
return NULL;
}
/* register error routine and methods */
pvio->methods= pvio_plugin->methods;
pvio->set_error= my_set_error;
pvio->type= cinfo->type;
/* set timeout to connect timeout - after successful connect we will set
* correct values for read and write */
if (pvio->methods->set_timeout)
{
pvio->methods->set_timeout(pvio, PVIO_CONNECT_TIMEOUT, cinfo->mysql->options.connect_timeout);
pvio->methods->set_timeout(pvio, PVIO_READ_TIMEOUT, cinfo->mysql->options.connect_timeout);
pvio->methods->set_timeout(pvio, PVIO_WRITE_TIMEOUT, cinfo->mysql->options.connect_timeout);
}
if (!(pvio->cache= calloc(1, PVIO_READ_AHEAD_CACHE_SIZE)))
{
PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0);
free(pvio);
return NULL;
}
pvio->cache_size= 0;
pvio->cache_pos= pvio->cache;
return pvio;
}
/* }}} */
/* {{{ my_bool ma_pvio_is_alive */
my_bool ma_pvio_is_alive(MARIADB_PVIO *pvio)
{
if (!pvio)
return FALSE;
if (pvio->methods->is_alive)
return pvio->methods->is_alive(pvio);
return TRUE;
}
/* }}} */
/* {{{ int ma_pvio_fast_send */
int ma_pvio_fast_send(MARIADB_PVIO *pvio)
{
if (!pvio || !pvio->methods->fast_send)
return 1;
return pvio->methods->fast_send(pvio);
}
/* }}} */
/* {{{ int ma_pvio_keepalive */
int ma_pvio_keepalive(MARIADB_PVIO *pvio)
{
if (!pvio || !pvio->methods->keepalive)
return 1;
return pvio->methods->keepalive(pvio);
}
/* }}} */
/* {{{ my_bool ma_pvio_set_timeout */
my_bool ma_pvio_set_timeout(MARIADB_PVIO *pvio,
enum enum_pvio_timeout type,
int timeout)
{
if (!pvio)
return 1;
if (pvio->methods->set_timeout)
return pvio->methods->set_timeout(pvio, type, timeout);
return 1;
}
/* }}} */
/* {{{ size_t ma_pvio_read_async */
static size_t ma_pvio_read_async(MARIADB_PVIO *pvio, uchar *buffer, size_t length)
{
ssize_t res= 0;
struct mysql_async_context *b= pvio->mysql->options.extension->async_context;
int timeout= pvio->timeout[PVIO_READ_TIMEOUT];
if (!pvio->methods->async_read)
{
PVIO_SET_ERROR(pvio->mysql, CR_ASYNC_NOT_SUPPORTED, unknown_sqlstate, 0);
return -1;
}
for (;;)
{
if (pvio->methods->async_read)
res= pvio->methods->async_read(pvio, buffer, length);
if (res >= 0 || IS_BLOCKING_ERROR())
return res;
b->events_to_wait_for= MYSQL_WAIT_READ;
if (timeout >= 0)
{
b->events_to_wait_for|= MYSQL_WAIT_TIMEOUT;
b->timeout_value= timeout;
}
if (b->suspend_resume_hook)
(*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data);
my_context_yield(&b->async_context);
if (b->suspend_resume_hook)
(*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data);
if (b->events_occured & MYSQL_WAIT_TIMEOUT)
return -1;
}
}
/* }}} */
/* {{{ size_t ma_pvio_read */
ssize_t ma_pvio_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length)
{
ssize_t r= -1;
if (!pvio)
return -1;
if (IS_PVIO_ASYNC_ACTIVE(pvio))
{
r=
#if defined(HAVE_TLS) && !defined(HAVE_SCHANNEL)
(pvio->ctls) ? ma_tls_read_async(pvio, buffer, length) :
#endif
(ssize_t)ma_pvio_read_async(pvio, buffer, length);
goto end;
}
else
{
if (IS_PVIO_ASYNC(pvio))
{
/*
If switching from non-blocking to blocking API usage, set the socket
back to blocking mode.
*/
my_bool old_mode;
ma_pvio_blocking(pvio, TRUE, &old_mode);
}
}
/* secure connection */
#ifdef HAVE_TLS
if (pvio->ctls)
{
r= ma_pvio_tls_read(pvio->ctls, buffer, length);
goto end;
}
#endif
if (pvio->methods->read)
r= pvio->methods->read(pvio, buffer, length);
end:
if (pvio_callback)
{
void (*callback)(int mode, MYSQL *mysql, const uchar *buffer, size_t length);
LIST *p= pvio_callback;
while (p)
{
callback= p->data;
callback(0, pvio->mysql, buffer, r);
p= p->next;
}
}
return r;
}
/* }}} */
/* {{{ size_t ma_pvio_cache_read */
ssize_t ma_pvio_cache_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length)
{
ssize_t r;
if (!pvio)
return -1;
if (!pvio->cache)
return ma_pvio_read(pvio, buffer, length);
if (pvio->cache + pvio->cache_size > pvio->cache_pos)
{
ssize_t remaining = pvio->cache + pvio->cache_size - pvio->cache_pos;
assert(remaining > 0);
r= MIN((ssize_t)length, remaining);
memcpy(buffer, pvio->cache_pos, r);
pvio->cache_pos+= r;
}
else if (length >= PVIO_READ_AHEAD_CACHE_MIN_SIZE)
{
r= ma_pvio_read(pvio, buffer, length);
}
else
{
r= ma_pvio_read(pvio, pvio->cache, PVIO_READ_AHEAD_CACHE_SIZE);
if (r > 0)
{
if (length < (size_t)r)
{
pvio->cache_size= r;
pvio->cache_pos= pvio->cache + length;
r= length;
}
memcpy(buffer, pvio->cache, r);
}
}
return r;
}
/* }}} */
/* {{{ size_t ma_pvio_write_async */
static ssize_t ma_pvio_write_async(MARIADB_PVIO *pvio, const uchar *buffer, size_t length)
{
ssize_t res;
struct mysql_async_context *b= pvio->mysql->options.extension->async_context;
int timeout= pvio->timeout[PVIO_WRITE_TIMEOUT];
for (;;)
{
res= pvio->methods->async_write(pvio, buffer, length);
if (res >= 0 || IS_BLOCKING_ERROR())
return res;
b->events_to_wait_for= MYSQL_WAIT_WRITE;
if (timeout >= 0)
{
b->events_to_wait_for|= MYSQL_WAIT_TIMEOUT;
b->timeout_value= timeout;
}
if (b->suspend_resume_hook)
(*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data);
my_context_yield(&b->async_context);
if (b->suspend_resume_hook)
(*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data);
if (b->events_occured & MYSQL_WAIT_TIMEOUT)
return -1;
}
}
/* }}} */
/* {{{ size_t ma_pvio_write */
ssize_t ma_pvio_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length)
{
ssize_t r= 0;
if (!pvio)
return -1;
if (IS_PVIO_ASYNC_ACTIVE(pvio))
{
r=
#if defined(HAVE_TLS) && !defined(HAVE_SCHANNEL)
(pvio->ctls) ? ma_tls_write_async(pvio, buffer, length) :
#endif
ma_pvio_write_async(pvio, buffer, length);
goto end;
}
else
{
if (IS_PVIO_ASYNC(pvio))
{
/*
If switching from non-blocking to blocking API usage, set the socket
back to blocking mode.
*/
my_bool old_mode;
ma_pvio_blocking(pvio, TRUE, &old_mode);
}
}
/* secure connection */
#ifdef HAVE_TLS
if (pvio->ctls)
{
r= ma_pvio_tls_write(pvio->ctls, buffer, length);
goto end;
}
#endif
if (pvio->methods->write)
r= pvio->methods->write(pvio, buffer, length);
end:
if (pvio_callback)
{
void (*callback)(int mode, MYSQL *mysql, const uchar *buffer, size_t length);
LIST *p= pvio_callback;
while (p)
{
callback= p->data;
callback(1, pvio->mysql, buffer, r);
p= p->next;
}
}
return r;
}
/* }}} */
/* {{{ void ma_pvio_close */
void ma_pvio_close(MARIADB_PVIO *pvio)
{
/* free internal structures and close connection */
if (pvio)
{
#ifdef HAVE_TLS
if (pvio->ctls)
{
ma_pvio_tls_close(pvio->ctls);
free(pvio->ctls);
}
#endif
if (pvio && pvio->methods->close)
pvio->methods->close(pvio);
if (pvio->cache)
free(pvio->cache);
free(pvio);
}
}
/* }}} */
/* {{{ my_bool ma_pvio_get_handle */
my_bool ma_pvio_get_handle(MARIADB_PVIO *pvio, void *handle)
{
if (pvio && pvio->methods->get_handle)
return pvio->methods->get_handle(pvio, handle);
return 1;
}
/* }}} */
/* {{{ ma_pvio_wait_async */
static my_bool
ma_pvio_wait_async(struct mysql_async_context *b, enum enum_pvio_io_event event,
int timeout)
{
switch (event)
{
case VIO_IO_EVENT_READ:
b->events_to_wait_for = MYSQL_WAIT_READ;
break;
case VIO_IO_EVENT_WRITE:
b->events_to_wait_for = MYSQL_WAIT_WRITE;
break;
case VIO_IO_EVENT_CONNECT:
b->events_to_wait_for = MYSQL_WAIT_WRITE | IF_WIN(0, MYSQL_WAIT_EXCEPT);
break;
}
if (timeout >= 0)
{
b->events_to_wait_for |= MYSQL_WAIT_TIMEOUT;
b->timeout_value= timeout;
}
if (b->suspend_resume_hook)
(*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data);
my_context_yield(&b->async_context);
if (b->suspend_resume_hook)
(*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data);
return (b->events_occured & MYSQL_WAIT_TIMEOUT) ? 0 : 1;
}
/* }}} */
/* {{{ ma_pvio_wait_io_or_timeout */
int ma_pvio_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout)
{
if (pvio)
{
if (IS_PVIO_ASYNC_ACTIVE(pvio))
return ma_pvio_wait_async(pvio->mysql->options.extension->async_context,
(is_read) ? VIO_IO_EVENT_READ : VIO_IO_EVENT_WRITE,
timeout);
if (pvio && pvio->methods->wait_io_or_timeout)
return pvio->methods->wait_io_or_timeout(pvio, is_read, timeout);
}
return 1;
}
/* }}} */
/* {{{ my_bool ma_pvio_connect */
my_bool ma_pvio_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo)
{
if (pvio && pvio->methods->connect)
return pvio->methods->connect(pvio, cinfo);
return 1;
}
/* }}} */
/* {{{ my_bool ma_pvio_blocking */
my_bool ma_pvio_blocking(MARIADB_PVIO *pvio, my_bool block, my_bool *previous_mode)
{
if (pvio && pvio->methods->blocking)
return pvio->methods->blocking(pvio, block, previous_mode) != 0;
return 1;
}
/* }}} */
/* {{{ my_bool ma_pvio_is_blocking */
my_bool ma_pvio_is_blocking(MARIADB_PVIO *pvio)
{
if (pvio && pvio->methods->is_blocking)
return pvio->methods->is_blocking(pvio);
return 1;
}
/* }}} */
/* {{{ ma_pvio_has_data */
my_bool ma_pvio_has_data(MARIADB_PVIO *pvio, ssize_t *data_len)
{
/* check if we still have unread data in cache */
if (pvio && pvio->cache)
if (pvio->cache_pos > pvio->cache)
return test(pvio->cache_pos - pvio->cache);
if (pvio && pvio->methods->has_data)
return pvio->methods->has_data(pvio, data_len);
return 1;
}
/* }}} */
#ifdef HAVE_TLS
/* {{{ my_bool ma_pvio_start_ssl */
my_bool ma_pvio_start_ssl(MARIADB_PVIO *pvio)
{
if (!pvio || !pvio->mysql)
return 1;
CLEAR_CLIENT_ERROR(pvio->mysql);
if (!(pvio->ctls= ma_pvio_tls_init(pvio->mysql)))
{
return 1;
}
if (ma_pvio_tls_connect(pvio->ctls))
{
free(pvio->ctls);
pvio->ctls= NULL;
return 1;
}
/* default behaviour:
1. peer certificate verification
2. verify CN (requires option ssl_verify_check)
3. verrify finger print
*/
if ((pvio->mysql->client_flag & CLIENT_SSL_VERIFY_SERVER_CERT) &&
ma_pvio_tls_verify_server_cert(pvio->ctls))
return 1;
if (pvio->mysql->options.extension &&
((pvio->mysql->options.extension->tls_fp && pvio->mysql->options.extension->tls_fp[0]) ||
(pvio->mysql->options.extension->tls_fp_list && pvio->mysql->options.extension->tls_fp_list[0])))
{
if (ma_pvio_tls_check_fp(pvio->ctls,
pvio->mysql->options.extension->tls_fp,
pvio->mysql->options.extension->tls_fp_list))
return 1;
}
return 0;
}
/* }}} */
#endif
/* {{{ ma_pvio_register_callback */
int ma_pvio_register_callback(my_bool register_callback,
void (*callback_function)(int mode, MYSQL *mysql, const uchar *buffer, size_t length))
{
LIST *list;
if (!callback_function)
return 1;
/* plugin will unregister in it's deinit function */
if (register_callback)
{
list= (LIST *)malloc(sizeof(LIST));
list->data= (void *)callback_function;
pvio_callback= list_add(pvio_callback, list);
}
else /* unregister callback function */
{
LIST *p= pvio_callback;
while (p)
{
if (p->data == callback_function)
{
list_delete(pvio_callback, p);
break;
}
p= p->next;
}
}
return 0;
}
/* }}} */

326
vendor/MDBC/libmariadb/ma_sha1.c vendored Normal file
View File

@ -0,0 +1,326 @@
/****************************************************************************
Copyright (C) 2012 Monty Program AB
2016 MariaDB Corporation 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 <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
*****************************************************************************/
/* This code came from the PHP project, initially written by
Stefan Esser */
#include "ma_global.h"
#include "string.h"
/* This code is heavily based on the PHP md5 implementation */
#include "ma_sha1.h"
static void ma_SHA1Transform(uint32[5], const unsigned char[64]);
static void ma_SHA1Encode(unsigned char *, uint32 *, unsigned int);
static void ma_SHA1Decode(uint32 *, const unsigned char *, unsigned int);
static unsigned char PADDING[64] =
{
0x80, 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
};
/* F, G, H and I are basic SHA1 functions.
*/
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
#define G(x, y, z) ((x) ^ (y) ^ (z))
#define H(x, y, z) (((x) & (y)) | ((z) & ((x) | (y))))
#define I(x, y, z) ((x) ^ (y) ^ (z))
/* ROTATE_LEFT rotates x left n bits.
*/
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
/* W[i]
*/
#define W(i) ( tmp=x[(i-3)&15]^x[(i-8)&15]^x[(i-14)&15]^x[i&15], \
(x[i&15]=ROTATE_LEFT(tmp, 1)) )
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
*/
#define FF(a, b, c, d, e, w) { \
(e) += F ((b), (c), (d)) + (w) + (uint32)(0x5A827999); \
(e) += ROTATE_LEFT ((a), 5); \
(b) = ROTATE_LEFT((b), 30); \
}
#define GG(a, b, c, d, e, w) { \
(e) += G ((b), (c), (d)) + (w) + (uint32)(0x6ED9EBA1); \
(e) += ROTATE_LEFT ((a), 5); \
(b) = ROTATE_LEFT((b), 30); \
}
#define HH(a, b, c, d, e, w) { \
(e) += H ((b), (c), (d)) + (w) + (uint32)(0x8F1BBCDC); \
(e) += ROTATE_LEFT ((a), 5); \
(b) = ROTATE_LEFT((b), 30); \
}
#define II(a, b, c, d, e, w) { \
(e) += I ((b), (c), (d)) + (w) + (uint32)(0xCA62C1D6); \
(e) += ROTATE_LEFT ((a), 5); \
(b) = ROTATE_LEFT((b), 30); \
}
/* {{{ ma_SHA1Init
* SHA1 initialization. Begins an SHA1 operation, writing a new context.
*/
void ma_SHA1Init(_MA_SHA1_CTX * context)
{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
*/
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
context->state[4] = 0xc3d2e1f0;
}
/* }}} */
/* {{{ ma_SHA1Update
SHA1 block update operation. Continues an SHA1 message-digest
operation, processing another message block, and updating the
context.
*/
void ma_SHA1Update(_MA_SHA1_CTX * context, const unsigned char *input,
size_t inputLen)
{
unsigned int i, index, partLen;
/* Compute number of bytes mod 64 */
index = (unsigned int) ((context->count[0] >> 3) & 0x3F);
/* Update number of bits */
if ((context->count[0] += ((uint32) inputLen << 3))
< ((uint32) inputLen << 3))
context->count[1]++;
context->count[1] += ((uint32) inputLen >> 29);
partLen = 64 - index;
/* Transform as many times as possible.
*/
if (inputLen >= partLen) {
memcpy
((unsigned char*) & context->buffer[index], (unsigned char*) input, partLen);
ma_SHA1Transform(context->state, context->buffer);
for (i = partLen; i + 63 < inputLen; i += 64)
ma_SHA1Transform(context->state, &input[i]);
index = 0;
} else
i = 0;
/* Buffer remaining input */
memcpy
((unsigned char*) & context->buffer[index], (unsigned char*) & input[i],
inputLen - i);
}
/* }}} */
/* {{{ ma_SHA1Final
SHA1 finalization. Ends an SHA1 message-digest operation, writing the
the message digest and zeroizing the context.
*/
void ma_SHA1Final(unsigned char digest[20], _MA_SHA1_CTX * context)
{
unsigned char bits[8];
unsigned int index, padLen;
/* Save number of bits */
bits[7] = context->count[0] & 0xFF;
bits[6] = (context->count[0] >> 8) & 0xFF;
bits[5] = (context->count[0] >> 16) & 0xFF;
bits[4] = (context->count[0] >> 24) & 0xFF;
bits[3] = context->count[1] & 0xFF;
bits[2] = (context->count[1] >> 8) & 0xFF;
bits[1] = (context->count[1] >> 16) & 0xFF;
bits[0] = (context->count[1] >> 24) & 0xFF;
/* Pad out to 56 mod 64.
*/
index = (unsigned int) ((context->count[0] >> 3) & 0x3f);
padLen = (index < 56) ? (56 - index) : (120 - index);
ma_SHA1Update(context, PADDING, padLen);
/* Append length (before padding) */
ma_SHA1Update(context, bits, 8);
/* Store state in digest */
ma_SHA1Encode(digest, context->state, 20);
/* Zeroize sensitive information.
*/
memset((unsigned char*) context, 0, sizeof(*context));
}
/* }}} */
/* {{{ ma_SHA1Transform
* SHA1 basic transformation. Transforms state based on block.
*/
static void ma_SHA1Transform(uint32 state[5], const unsigned char block[64])
{
uint32 a = state[0], b = state[1], c = state[2];
uint32 d = state[3], e = state[4], x[16], tmp;
ma_SHA1Decode(x, block, 64);
/* Round 1 */
FF(a, b, c, d, e, x[0]); /* 1 */
FF(e, a, b, c, d, x[1]); /* 2 */
FF(d, e, a, b, c, x[2]); /* 3 */
FF(c, d, e, a, b, x[3]); /* 4 */
FF(b, c, d, e, a, x[4]); /* 5 */
FF(a, b, c, d, e, x[5]); /* 6 */
FF(e, a, b, c, d, x[6]); /* 7 */
FF(d, e, a, b, c, x[7]); /* 8 */
FF(c, d, e, a, b, x[8]); /* 9 */
FF(b, c, d, e, a, x[9]); /* 10 */
FF(a, b, c, d, e, x[10]); /* 11 */
FF(e, a, b, c, d, x[11]); /* 12 */
FF(d, e, a, b, c, x[12]); /* 13 */
FF(c, d, e, a, b, x[13]); /* 14 */
FF(b, c, d, e, a, x[14]); /* 15 */
FF(a, b, c, d, e, x[15]); /* 16 */
FF(e, a, b, c, d, W(16)); /* 17 */
FF(d, e, a, b, c, W(17)); /* 18 */
FF(c, d, e, a, b, W(18)); /* 19 */
FF(b, c, d, e, a, W(19)); /* 20 */
/* Round 2 */
GG(a, b, c, d, e, W(20)); /* 21 */
GG(e, a, b, c, d, W(21)); /* 22 */
GG(d, e, a, b, c, W(22)); /* 23 */
GG(c, d, e, a, b, W(23)); /* 24 */
GG(b, c, d, e, a, W(24)); /* 25 */
GG(a, b, c, d, e, W(25)); /* 26 */
GG(e, a, b, c, d, W(26)); /* 27 */
GG(d, e, a, b, c, W(27)); /* 28 */
GG(c, d, e, a, b, W(28)); /* 29 */
GG(b, c, d, e, a, W(29)); /* 30 */
GG(a, b, c, d, e, W(30)); /* 31 */
GG(e, a, b, c, d, W(31)); /* 32 */
GG(d, e, a, b, c, W(32)); /* 33 */
GG(c, d, e, a, b, W(33)); /* 34 */
GG(b, c, d, e, a, W(34)); /* 35 */
GG(a, b, c, d, e, W(35)); /* 36 */
GG(e, a, b, c, d, W(36)); /* 37 */
GG(d, e, a, b, c, W(37)); /* 38 */
GG(c, d, e, a, b, W(38)); /* 39 */
GG(b, c, d, e, a, W(39)); /* 40 */
/* Round 3 */
HH(a, b, c, d, e, W(40)); /* 41 */
HH(e, a, b, c, d, W(41)); /* 42 */
HH(d, e, a, b, c, W(42)); /* 43 */
HH(c, d, e, a, b, W(43)); /* 44 */
HH(b, c, d, e, a, W(44)); /* 45 */
HH(a, b, c, d, e, W(45)); /* 46 */
HH(e, a, b, c, d, W(46)); /* 47 */
HH(d, e, a, b, c, W(47)); /* 48 */
HH(c, d, e, a, b, W(48)); /* 49 */
HH(b, c, d, e, a, W(49)); /* 50 */
HH(a, b, c, d, e, W(50)); /* 51 */
HH(e, a, b, c, d, W(51)); /* 52 */
HH(d, e, a, b, c, W(52)); /* 53 */
HH(c, d, e, a, b, W(53)); /* 54 */
HH(b, c, d, e, a, W(54)); /* 55 */
HH(a, b, c, d, e, W(55)); /* 56 */
HH(e, a, b, c, d, W(56)); /* 57 */
HH(d, e, a, b, c, W(57)); /* 58 */
HH(c, d, e, a, b, W(58)); /* 59 */
HH(b, c, d, e, a, W(59)); /* 60 */
/* Round 4 */
II(a, b, c, d, e, W(60)); /* 61 */
II(e, a, b, c, d, W(61)); /* 62 */
II(d, e, a, b, c, W(62)); /* 63 */
II(c, d, e, a, b, W(63)); /* 64 */
II(b, c, d, e, a, W(64)); /* 65 */
II(a, b, c, d, e, W(65)); /* 66 */
II(e, a, b, c, d, W(66)); /* 67 */
II(d, e, a, b, c, W(67)); /* 68 */
II(c, d, e, a, b, W(68)); /* 69 */
II(b, c, d, e, a, W(69)); /* 70 */
II(a, b, c, d, e, W(70)); /* 71 */
II(e, a, b, c, d, W(71)); /* 72 */
II(d, e, a, b, c, W(72)); /* 73 */
II(c, d, e, a, b, W(73)); /* 74 */
II(b, c, d, e, a, W(74)); /* 75 */
II(a, b, c, d, e, W(75)); /* 76 */
II(e, a, b, c, d, W(76)); /* 77 */
II(d, e, a, b, c, W(77)); /* 78 */
II(c, d, e, a, b, W(78)); /* 79 */
II(b, c, d, e, a, W(79)); /* 80 */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
state[4] += e;
/* Zeroize sensitive information. */
memset((unsigned char*) x, 0, sizeof(x));
}
/* }}} */
/* {{{ ma_SHA1Encode
Encodes input (uint32) into output (unsigned char). Assumes len is
a multiple of 4.
*/
static void ma_SHA1Encode(unsigned char *output, uint32 *input, unsigned int len)
{
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4) {
output[j] = (unsigned char) ((input[i] >> 24) & 0xff);
output[j + 1] = (unsigned char) ((input[i] >> 16) & 0xff);
output[j + 2] = (unsigned char) ((input[i] >> 8) & 0xff);
output[j + 3] = (unsigned char) (input[i] & 0xff);
}
}
/* }}} */
/* {{{ ma_SHA1Decode
Decodes input (unsigned char) into output (uint32). Assumes len is
a multiple of 4.
*/
static void ma_SHA1Decode(uint32 *output, const unsigned char * input, unsigned int len)
{
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
output[i] = ((uint32) input[j + 3]) | (((uint32) input[j + 2]) << 8) |
(((uint32) input[j + 1]) << 16) | (((uint32) input[j]) << 24);
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: sw=4 ts=4 fdm=marker
* vim<600: sw=4 ts=4
*/

1362
vendor/MDBC/libmariadb/ma_stmt_codec.c vendored Normal file

File diff suppressed because it is too large Load Diff

163
vendor/MDBC/libmariadb/ma_string.c vendored Normal file
View File

@ -0,0 +1,163 @@
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
2016 MariaDB Corporation 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
/*
Code for handling strings which can grow dynamically.
Copyright Monty Program KB.
By monty.
*/
#include <ma_global.h>
#include <ma_sys.h>
#include <ma_string.h>
my_bool ma_init_dynamic_string(DYNAMIC_STRING *str, const char *init_str,
size_t init_alloc, size_t alloc_increment)
{
uint length;
if (!alloc_increment)
alloc_increment=128;
length=1;
if (init_str && (length= (uint) strlen(init_str)+1) < init_alloc)
init_alloc=((length+alloc_increment-1)/alloc_increment)*alloc_increment;
if (!init_alloc)
init_alloc=alloc_increment;
if (!(str->str=(char*) malloc(init_alloc)))
return(TRUE);
str->length=length-1;
if (init_str)
memcpy(str->str,init_str,length);
str->max_length=init_alloc;
str->alloc_increment=alloc_increment;
return(FALSE);
}
my_bool ma_dynstr_set(DYNAMIC_STRING *str, const char *init_str)
{
uint length;
if (init_str && (length= (uint) strlen(init_str)+1) > str->max_length)
{
str->max_length=((length+str->alloc_increment-1)/str->alloc_increment)*
str->alloc_increment;
if (!str->max_length)
str->max_length=str->alloc_increment;
if (!(str->str=(char*) realloc(str->str,str->max_length)))
return(TRUE);
}
if (init_str)
{
str->length=length-1;
memcpy(str->str,init_str,length);
}
else
str->length=0;
return(FALSE);
}
my_bool ma_dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size)
{
if (!additional_size) return(FALSE);
if (str->length + additional_size > str->max_length)
{
str->max_length=((str->length + additional_size+str->alloc_increment-1)/
str->alloc_increment)*str->alloc_increment;
if (!(str->str=(char*) realloc(str->str,str->max_length)))
return(TRUE);
}
return(FALSE);
}
my_bool ma_dynstr_append(DYNAMIC_STRING *str, const char *append)
{
return ma_dynstr_append_mem(str,append,strlen(append));
}
my_bool ma_dynstr_append_quoted(DYNAMIC_STRING *str,
const char *append, size_t len,
char quote)
{
size_t additional= str->alloc_increment;
size_t lim= additional;
uint i;
if (ma_dynstr_realloc(str, len + additional + 2))
return TRUE;
str->str[str->length++]= quote;
for (i= 0; i < len; i++)
{
register char c= append[i];
if (c == quote || c == '\\')
{
if (!lim)
{
if (ma_dynstr_realloc(str, additional))
return TRUE;
lim= additional;
}
lim--;
str->str[str->length++]= '\\';
}
str->str[str->length++]= c;
}
str->str[str->length++]= quote;
return FALSE;
}
my_bool ma_dynstr_append_mem(DYNAMIC_STRING *str, const char *append,
size_t length)
{
char *new_ptr;
if (str->length+length >= str->max_length)
{
size_t new_length=(str->length+length+str->alloc_increment)/
str->alloc_increment;
new_length*=str->alloc_increment;
if (!(new_ptr=(char*) realloc(str->str,new_length)))
return TRUE;
str->str=new_ptr;
str->max_length=new_length;
}
memcpy(str->str + str->length,append,length);
str->length+=length;
str->str[str->length]=0; /* Safety for C programs */
return FALSE;
}
void ma_dynstr_free(DYNAMIC_STRING *str)
{
if (str->str)
{
free(str->str);
str->str=0;
}
}
char *ma_strmake(register char *dst, register const char *src, size_t length)
{
while (length--)
if (! (*dst++ = *src++))
return dst-1;
*dst=0;
return dst;
}

65
vendor/MDBC/libmariadb/ma_time.c vendored Normal file
View File

@ -0,0 +1,65 @@
/****************************************************************************
Copyright (C) 2013 Monty Program AB
2016 MariaDB Corporation 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 <http://www.gnu.org/licenses>
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
*****************************************************************************/
#include <ma_global.h>
#include <mysql.h>
#include <stdio.h>
size_t mariadb_time_to_string(const MYSQL_TIME *tm, char *time_str, size_t len,
unsigned int digits)
{
size_t length;
if (!time_str || !len)
return 0;
if (digits == AUTO_SEC_PART_DIGITS)
digits= (tm->second_part) ? SEC_PART_DIGITS : 0;
switch(tm->time_type) {
case MYSQL_TIMESTAMP_DATE:
length= snprintf(time_str, len, "%04u-%02u-%02u", tm->year, tm->month, tm->day);
digits= 0;
break;
case MYSQL_TIMESTAMP_DATETIME:
length= snprintf(time_str, len, "%04u-%02u-%02u %02u:%02u:%02u",
tm->year, tm->month, tm->day, tm->hour, tm->minute, tm->second);
break;
case MYSQL_TIMESTAMP_TIME:
length= snprintf(time_str, len, "%s%02u:%02u:%02u",
(tm->neg ? "-" : ""), tm->hour, tm->minute, tm->second);
break;
default:
time_str[0]= '\0';
return 0;
break;
}
if (digits && (len < length))
{
char helper[16];
snprintf(helper, 16, ".%%0%du", digits);
length+= snprintf(time_str + length, len - length, helper, digits);
}
return length;
}

232
vendor/MDBC/libmariadb/ma_tls.c vendored Normal file
View File

@ -0,0 +1,232 @@
/************************************************************************************
Copyright (C) 2014 MariaDB Corporation 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 <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
*************************************************************************************/
/*
* this is the abstraction layer for communication via SSL.
* The following SSL libraries/variants are currently supported:
* - openssl
* - gnutls
* - schannel (windows only)
*
* Different SSL variants are implemented as plugins
* On Windows schannel is implemented as (standard)
* built-in plugin.
*/
#ifdef HAVE_TLS
#include <ma_global.h>
#include <ma_sys.h>
#include <ma_common.h>
#include <string.h>
#include <errmsg.h>
#include <ma_pvio.h>
#include <ma_tls.h>
#include <mysql/client_plugin.h>
#include <mariadb/ma_io.h>
#ifdef HAVE_NONBLOCK
#include <mariadb_async.h>
#include <ma_context.h>
#endif
/* Errors should be handled via pvio callback function */
my_bool ma_tls_initialized= FALSE;
unsigned int mariadb_deinitialize_ssl= 1;
const char *tls_protocol_version[]=
{"SSLv3", "TLSv1.0", "TLSv1.1", "TLSv1.2", "TLSv1.3", "Unknown"};
MARIADB_TLS *ma_pvio_tls_init(MYSQL *mysql)
{
MARIADB_TLS *ctls= NULL;
if (!ma_tls_initialized)
ma_tls_start(mysql->net.last_error, MYSQL_ERRMSG_SIZE);
if (!(ctls= (MARIADB_TLS *)calloc(1, sizeof(MARIADB_TLS))))
{
return NULL;
}
/* register error routine and methods */
ctls->pvio= mysql->net.pvio;
if (!(ctls->ssl= ma_tls_init(mysql)))
{
free(ctls);
ctls= NULL;
}
return ctls;
}
my_bool ma_pvio_tls_connect(MARIADB_TLS *ctls)
{
my_bool rc;
if ((rc= ma_tls_connect(ctls)))
ma_tls_close(ctls);
return rc;
}
ssize_t ma_pvio_tls_read(MARIADB_TLS *ctls, const uchar* buffer, size_t length)
{
return ma_tls_read(ctls, buffer, length);
}
ssize_t ma_pvio_tls_write(MARIADB_TLS *ctls, const uchar* buffer, size_t length)
{
return ma_tls_write(ctls, buffer, length);
}
my_bool ma_pvio_tls_close(MARIADB_TLS *ctls)
{
return ma_tls_close(ctls);
}
int ma_pvio_tls_verify_server_cert(MARIADB_TLS *ctls)
{
return ma_tls_verify_server_cert(ctls);
}
const char *ma_pvio_tls_cipher(MARIADB_TLS *ctls)
{
return ma_tls_get_cipher(ctls);
}
void ma_pvio_tls_end()
{
ma_tls_end();
}
int ma_pvio_tls_get_protocol_version_id(MARIADB_TLS *ctls)
{
return ma_tls_get_protocol_version(ctls);
}
const char *ma_pvio_tls_get_protocol_version(MARIADB_TLS *ctls)
{
int version;
version= ma_tls_get_protocol_version(ctls);
if (version < 0 || version > PROTOCOL_MAX)
return tls_protocol_version[PROTOCOL_UNKNOWN];
return tls_protocol_version[version];
}
static signed char ma_hex2int(char c)
{
if (c >= '0' && c <= '9')
return c - '0';
if (c >= 'A' && c <= 'F')
return 10 + c - 'A';
if (c >= 'a' && c <= 'f')
return 10 + c - 'a';
return -1;
}
static my_bool ma_pvio_tls_compare_fp(const char *cert_fp,
unsigned int cert_fp_len,
const char *fp, unsigned int fp_len)
{
char *p= (char *)fp,
*c;
/* check length */
if (cert_fp_len != 20)
return 1;
/* We support two formats:
2 digits hex numbers, separated by colons (length=59)
20 * 2 digits hex numbers without separators (length = 40)
*/
if (fp_len != (strchr(fp, ':') ? 59 : 40))
return 1;
for(c= (char *)cert_fp; c < cert_fp + cert_fp_len; c++)
{
signed char d1, d2;
if (*p == ':')
p++;
if (p - fp > (int)fp_len -1)
return 1;
if ((d1 = ma_hex2int(*p)) == - 1 ||
(d2 = ma_hex2int(*(p+1))) == -1 ||
(char)(d1 * 16 + d2) != *c)
return 1;
p+= 2;
}
return 0;
}
my_bool ma_pvio_tls_check_fp(MARIADB_TLS *ctls, const char *fp, const char *fp_list)
{
unsigned int cert_fp_len= 64;
char *cert_fp= NULL;
my_bool rc=1;
MYSQL *mysql= ctls->pvio->mysql;
cert_fp= (char *)malloc(cert_fp_len);
if ((cert_fp_len= ma_tls_get_finger_print(ctls, cert_fp, cert_fp_len)) < 1)
goto end;
if (fp)
rc= ma_pvio_tls_compare_fp(cert_fp, cert_fp_len, fp, (unsigned int)strlen(fp));
else if (fp_list)
{
MA_FILE *fp;
char buff[255];
if (!(fp = ma_open(fp_list, "r", mysql)))
goto end;
while (ma_gets(buff, sizeof(buff)-1, fp))
{
/* remove trailing new line character */
char *pos= strchr(buff, '\r');
if (!pos)
pos= strchr(buff, '\n');
if (pos)
*pos= '\0';
if (!ma_pvio_tls_compare_fp(cert_fp, cert_fp_len, buff, (unsigned int)strlen(buff)))
{
/* finger print is valid: close file and exit */
ma_close(fp);
rc= 0;
goto end;
}
}
/* No finger print matched - close file and return error */
ma_close(fp);
}
end:
if (cert_fp)
free(cert_fp);
if (rc)
{
my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
ER(CR_SSL_CONNECTION_ERROR),
"Fingerprint verification of server certificate failed");
}
return rc;
}
#endif /* HAVE_TLS */

1946
vendor/MDBC/libmariadb/mariadb_async.c vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,74 @@
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
2016 MariaDB Corporation 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., 51 Franklin Street, Fifth Floor, Boston,
MA 02111-1301, USA */
#include <ma_global.h>
#include <ma_sys.h>
// #include "mysys_err.h"
#include <mariadb_ctype.h>
#include <ma_string.h>
MARIADB_CHARSET_INFO *ma_default_charset_info; /* will be set in mysql_server_init */
MARIADB_CHARSET_INFO *ma_charset_bin= (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[32];
MARIADB_CHARSET_INFO *ma_charset_latin1= (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[5];
MARIADB_CHARSET_INFO *ma_charset_utf8_general_ci= (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[21];
MARIADB_CHARSET_INFO *ma_charset_utf16le_general_ci= (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[68];
MARIADB_CHARSET_INFO * STDCALL mysql_get_charset_by_nr(uint cs_number)
{
int i= 0;
while (mariadb_compiled_charsets[i].nr && cs_number != mariadb_compiled_charsets[i].nr)
i++;
return (mariadb_compiled_charsets[i].nr) ? (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[i] : NULL;
}
my_bool set_default_charset(uint cs, myf flags __attribute__((unused)))
{
MARIADB_CHARSET_INFO *new_charset;
new_charset = mysql_get_charset_by_nr(cs);
if (!new_charset)
{
return(TRUE); /* error */
}
ma_default_charset_info = new_charset;
return(FALSE);
}
MARIADB_CHARSET_INFO * STDCALL mysql_get_charset_by_name(const char *cs_name)
{
int i= 0;
while (mariadb_compiled_charsets[i].nr && strcmp(cs_name, mariadb_compiled_charsets[i].csname) != 0)
i++;
return (mariadb_compiled_charsets[i].nr) ? (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[i] : NULL;
}
my_bool set_default_charset_by_name(const char *cs_name, myf flags __attribute__((unused)))
{
MARIADB_CHARSET_INFO *new_charset;
new_charset = mysql_get_charset_by_name(cs_name);
if (!new_charset)
{
return(TRUE); /* error */
}
ma_default_charset_info = new_charset;
return(FALSE);
}

4368
vendor/MDBC/libmariadb/mariadb_dyncol.c vendored Normal file

File diff suppressed because it is too large Load Diff

4522
vendor/MDBC/libmariadb/mariadb_lib.c vendored Normal file

File diff suppressed because it is too large Load Diff

513
vendor/MDBC/libmariadb/mariadb_rpl.c vendored Normal file
View File

@ -0,0 +1,513 @@
/************************************************************************************
Copyright (C) 2018 MariaDB Corpoeation 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 <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
*************************************************************************************/
#include <ma_global.h>
#include <ma_sys.h>
#include <mysql.h>
#include <errmsg.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <zlib.h>
#include <mariadb_rpl.h>
static int rpl_alloc_string(MARIADB_RPL_EVENT *event,
MARIADB_STRING *s,
unsigned char *buffer,
size_t len)
{
if (!(s->str= ma_alloc_root(&event->memroot, len)))
return 1;
memcpy(s->str, buffer, len);
s->length= len;
return 0;
}
MARIADB_RPL * STDCALL mariadb_rpl_init_ex(MYSQL *mysql, unsigned int version)
{
MARIADB_RPL *rpl;
if (version < MARIADB_RPL_REQUIRED_VERSION ||
version > MARIADB_RPL_VERSION)
{
my_set_error(mysql, CR_VERSION_MISMATCH, SQLSTATE_UNKNOWN, 0, version,
MARIADB_RPL_VERSION, MARIADB_RPL_REQUIRED_VERSION);
return 0;
}
if (!mysql)
return NULL;
if (!(rpl= (MARIADB_RPL *)calloc(1, sizeof(MARIADB_RPL))))
{
SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0);
return 0;
}
rpl->version= version;
rpl->mysql= mysql;
return rpl;
}
void STDCALL mariadb_free_rpl_event(MARIADB_RPL_EVENT *event)
{
if (event)
{
ma_free_root(&event->memroot, MYF(0));
free(event);
}
}
int STDCALL mariadb_rpl_open(MARIADB_RPL *rpl)
{
unsigned char *ptr, *buf;
if (!rpl || !rpl->mysql)
return 1;
/* COM_BINLOG_DUMP:
Ofs Len Data
0 1 COM_BINLOG_DUMP
1 4 position
5 2 flags
7 4 server id
11 * filename
* = filename length
*/
ptr= buf=
#ifdef WIN32
(unsigned char *)_alloca(rpl->filename_length + 11);
#else
(unsigned char *)alloca(rpl->filename_length + 11);
#endif
int4store(ptr, (unsigned int)rpl->start_position);
ptr+= 4;
int2store(ptr, rpl->flags);
ptr+= 2;
int4store(ptr, rpl->server_id);
ptr+= 4;
memcpy(ptr, rpl->filename, rpl->filename_length);
ptr+= rpl->filename_length;
if (ma_simple_command(rpl->mysql, COM_BINLOG_DUMP, (const char *)buf, ptr - buf, 1, 0))
return 1;
return 0;
}
MARIADB_RPL_EVENT * STDCALL mariadb_rpl_fetch(MARIADB_RPL *rpl, MARIADB_RPL_EVENT *event)
{
unsigned char *ev;
size_t len;
MARIADB_RPL_EVENT *rpl_event= 0;
if (!rpl || !rpl->mysql)
return 0;
while (1) {
unsigned long pkt_len= ma_net_safe_read(rpl->mysql);
if (pkt_len == packet_error)
{
rpl->buffer_size= 0;
return 0;
}
/* EOF packet:
see https://mariadb.com/kb/en/library/eof_packet/
Packet length must be less than 9 bytes, EOF header
is 0xFE.
*/
if (pkt_len < 9 && rpl->mysql->net.read_pos[0] == 0xFE)
{
rpl->buffer_size= 0;
return 0;
}
/* if ignore heartbeat flag was set, we ignore this
record and continue to fetch next record.
The first byte is always status byte (0x00)
For event header description see
https://mariadb.com/kb/en/library/2-binlog-event-header/ */
if (rpl->flags & MARIADB_RPL_IGNORE_HEARTBEAT)
{
if (rpl->mysql->net.read_pos[1 + 4] == HEARTBEAT_LOG_EVENT)
continue;
}
rpl->buffer_size= pkt_len;
rpl->buffer= rpl->mysql->net.read_pos;
if (event)
{
MA_MEM_ROOT memroot= event->memroot;
rpl_event= event;
ma_free_root(&memroot, MYF(MY_KEEP_PREALLOC));
memset(rpl_event, 0, sizeof(MARIADB_RPL_EVENT));
rpl_event->memroot= memroot;
} else {
if (!(rpl_event = (MARIADB_RPL_EVENT *)malloc(sizeof(MARIADB_RPL_EVENT))))
goto mem_error;
memset(rpl_event, 0, sizeof(MARIADB_RPL_EVENT));
ma_init_alloc_root(&rpl_event->memroot, 8192, 0);
}
rpl_event->checksum= uint4korr(rpl->buffer + rpl->buffer_size - 4);
rpl_event->ok= rpl->buffer[0];
rpl_event->timestamp= uint4korr(rpl->buffer + 1);
rpl_event->event_type= (unsigned char)*(rpl->buffer + 5);
rpl_event->server_id= uint4korr(rpl->buffer + 6);
rpl_event->event_length= uint4korr(rpl->buffer + 10);
rpl_event->next_event_pos= uint4korr(rpl->buffer + 14);
rpl_event->flags= uint2korr(rpl->buffer + 18);
ev= rpl->buffer + EVENT_HEADER_OFS;
if (rpl->use_checksum)
{
rpl_event->checksum= *(ev + rpl_event->event_length - 4);
rpl_event->event_length-= 4;
}
switch(rpl_event->event_type) {
case HEARTBEAT_LOG_EVENT:
rpl_event->event.heartbeat.timestamp= uint4korr(ev);
ev+= 4;
rpl_event->event.heartbeat.next_position= uint4korr(ev);
ev+= 4;
rpl_event->event.heartbeat.type= (uint8_t)*ev;
ev+= 1;
rpl_event->event.heartbeat.flags= uint2korr(ev);
break;
case BINLOG_CHECKPOINT_EVENT:
len= uint4korr(ev);
ev+= 4;
if (rpl_alloc_string(rpl_event, &rpl_event->event.checkpoint.filename, ev, len))
goto mem_error;
break;
case FORMAT_DESCRIPTION_EVENT:
rpl_event->event.format_description.format = uint2korr(ev);
ev+= 2;
rpl_event->event.format_description.server_version = (char *)(ev);
ev+= 50;
rpl_event->event.format_description.timestamp= uint4korr(ev);
ev+= 4;
rpl->fd_header_len= rpl_event->event.format_description.header_len= (uint8_t)*ev;
ev= rpl->buffer + rpl->buffer_size - 5;
rpl->use_checksum= *ev;
break;
case QUERY_EVENT:
{
size_t db_len, status_len;
rpl_event->event.query.thread_id= uint4korr(ev);
ev+= 4;
rpl_event->event.query.seconds= uint4korr(ev);
ev+= 4;
db_len= *ev;
ev++;
rpl_event->event.query.errornr= uint2korr(ev);
ev+= 2;
status_len= uint2korr(ev);
ev+= 2;
if (rpl_alloc_string(rpl_event, &rpl_event->event.query.status, ev, status_len))
goto mem_error;
ev+= status_len;
if (rpl_alloc_string(rpl_event, &rpl_event->event.query.database, ev, db_len))
goto mem_error;
ev+= db_len + 1; /* zero terminated */
/* calculate statement size: buffer + buffer_size - current_ofs (ev) - crc_size */
len= (size_t)(rpl->buffer + rpl->buffer_size - ev - (rpl->use_checksum ? 4 : 0));
if (rpl_alloc_string(rpl_event, &rpl_event->event.query.statement, ev, len))
goto mem_error;
break;
}
case TABLE_MAP_EVENT:
rpl_event->event.table_map.table_id= uint6korr(ev);
ev+= 8;
len= *ev;
ev++;
if (rpl_alloc_string(rpl_event, &rpl_event->event.table_map.database, ev, len))
goto mem_error;
ev+= len + 1;
len= *ev;
ev++;
if (rpl_alloc_string(rpl_event, &rpl_event->event.table_map.table, ev, len))
goto mem_error;
ev+= len + 1;
rpl_event->event.table_map.column_count= mysql_net_field_length(&ev);
len= rpl_event->event.table_map.column_count;
if (rpl_alloc_string(rpl_event, &rpl_event->event.table_map.column_types, ev, len))
goto mem_error;
ev+= len;
len= mysql_net_field_length(&ev);
if (rpl_alloc_string(rpl_event, &rpl_event->event.table_map.metadata, ev, len))
goto mem_error;
break;
case RAND_EVENT:
rpl_event->event.rand.first_seed= uint8korr(ev);
ev+= 8;
rpl_event->event.rand.second_seed= uint8korr(ev);
break;
case INTVAR_EVENT:
rpl_event->event.intvar.type= *ev;
ev++;
rpl_event->event.intvar.value= uint8korr(ev);
break;
case USER_VAR_EVENT:
len= uint4korr(ev);
ev+= 4;
if (rpl_alloc_string(rpl_event, &rpl_event->event.uservar.name, ev, len))
goto mem_error;
ev+= len;
if (!(rpl_event->event.uservar.is_null= (uint8)*ev))
{
ev++;
rpl_event->event.uservar.type= *ev;
ev++;
rpl_event->event.uservar.charset_nr= uint4korr(ev);
ev+= 4;
len= uint4korr(ev);
ev+= 4;
if (rpl_alloc_string(rpl_event, &rpl_event->event.uservar.value, ev, len))
goto mem_error;
ev+= len;
if ((unsigned long)(ev - rpl->buffer) < rpl->buffer_size)
rpl_event->event.uservar.flags= *ev;
}
break;
case START_ENCRYPTION_EVENT:
rpl_event->event.encryption.scheme= *ev;
ev++;
rpl_event->event.encryption.key_version= uint4korr(ev);
ev+= 4;
rpl_event->event.encryption.nonce= (char *)ev;
break;
case ANNOTATE_ROWS_EVENT:
len= (uint32)(rpl->buffer + rpl->buffer_size - (unsigned char *)ev - (rpl->use_checksum ? 4 : 0));
if (rpl_alloc_string(rpl_event, &rpl_event->event.annotate_rows.statement, ev, len))
goto mem_error;
break;
case ROTATE_EVENT:
rpl_event->event.rotate.position= uint8korr(ev);
ev+= 8;
len= rpl_event->event_length - rpl->fd_header_len - 8;
if (rpl_alloc_string(rpl_event, &rpl_event->event.rotate.filename, ev, len))
goto mem_error;
break;
case XID_EVENT:
rpl_event->event.xid.transaction_nr= uint8korr(ev);
break;
case STOP_EVENT:
/* nothing to do here */
break;
case GTID_EVENT:
rpl_event->event.gtid.sequence_nr= uint8korr(ev);
ev+= 8;
rpl_event->event.gtid.domain_id= uint4korr(ev);
ev+= 4;
rpl_event->event.gtid.flags= *ev;
ev++;
if (rpl_event->event.gtid.flags & FL_GROUP_COMMIT_ID)
rpl_event->event.gtid.commit_id= uint8korr(ev);
break;
case GTID_LIST_EVENT:
{
uint32 i;
rpl_event->event.gtid_list.gtid_cnt= uint4korr(ev);
ev++;
if (!(rpl_event->event.gtid_list.gtid= (MARIADB_GTID *)ma_alloc_root(&rpl_event->memroot, sizeof(MARIADB_GTID) * rpl_event->event.gtid_list.gtid_cnt)))
goto mem_error;
for (i=0; i < rpl_event->event.gtid_list.gtid_cnt; i++)
{
rpl_event->event.gtid_list.gtid[i].domain_id= uint4korr(ev);
ev+= 4;
rpl_event->event.gtid_list.gtid[i].server_id= uint4korr(ev);
ev+= 4;
rpl_event->event.gtid_list.gtid[i].sequence_nr= uint8korr(ev);
ev+= 8;
}
break;
}
case WRITE_ROWS_EVENT_V1:
case UPDATE_ROWS_EVENT_V1:
case DELETE_ROWS_EVENT_V1:
rpl_event->event.rows.type= rpl_event->event_type - WRITE_ROWS_EVENT_V1;
if (rpl->fd_header_len == 6)
{
rpl_event->event.rows.table_id= uint4korr(ev);
ev+= 4;
} else {
rpl_event->event.rows.table_id= uint6korr(ev);
ev+= 6;
}
rpl_event->event.rows.flags= uint2korr(ev);
ev+= 2;
len= rpl_event->event.rows.column_count= mysql_net_field_length(&ev);
if (!len)
break;
if (!(rpl_event->event.rows.column_bitmap =
(char *)ma_alloc_root(&rpl_event->memroot, (len + 7) / 8)))
goto mem_error;
memcpy(rpl_event->event.rows.column_bitmap, ev, (len + 7) / 8);
ev+= (len + 7) / 8;
if (rpl_event->event_type == UPDATE_ROWS_EVENT_V1)
{
if (!(rpl_event->event.rows.column_update_bitmap =
(char *)ma_alloc_root(&rpl_event->memroot, (len + 7) / 8)))
goto mem_error;
memcpy(rpl_event->event.rows.column_update_bitmap, ev, (len + 7) / 8);
ev+= (len + 7) / 8;
}
len= (rpl->buffer + rpl_event->event_length + EVENT_HEADER_OFS - rpl->fd_header_len) - ev;
if ((rpl_event->event.rows.row_data_size= len))
{
if (!(rpl_event->event.rows.row_data =
(char *)ma_alloc_root(&rpl_event->memroot, rpl_event->event.rows.row_data_size)))
goto mem_error;
memcpy(rpl_event->event.rows.row_data, ev, rpl_event->event.rows.row_data_size);
}
break;
default:
free(rpl_event);
return NULL;
break;
}
return rpl_event;
}
mem_error:
free(rpl_event);
SET_CLIENT_ERROR(rpl->mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0);
return 0;
}
void STDCALL mariadb_rpl_close(MARIADB_RPL *rpl)
{
if (!rpl)
return;
if (rpl->filename)
free((void *)rpl->filename);
free(rpl);
return;
}
int mariadb_rpl_optionsv(MARIADB_RPL *rpl,
enum mariadb_rpl_option option,
...)
{
va_list ap;
int rc= 0;
if (!rpl)
return 1;
va_start(ap, option);
switch (option) {
case MARIADB_RPL_FILENAME:
{
char *arg1= va_arg(ap, char *);
rpl->filename_length= (uint32_t)va_arg(ap, size_t);
free((void *)rpl->filename);
rpl->filename= NULL;
if (rpl->filename_length)
{
rpl->filename= (char *)malloc(rpl->filename_length);
memcpy((void *)rpl->filename, arg1, rpl->filename_length);
}
else if (arg1)
{
rpl->filename= strdup((const char *)arg1);
rpl->filename_length= (uint32_t)strlen(rpl->filename);
}
break;
}
case MARIADB_RPL_SERVER_ID:
{
rpl->server_id= va_arg(ap, unsigned int);
break;
}
case MARIADB_RPL_FLAGS:
{
rpl->flags= va_arg(ap, unsigned int);
break;
}
case MARIADB_RPL_START:
{
rpl->start_position= va_arg(ap, unsigned long);
break;
}
default:
rc= -1;
goto end;
}
end:
va_end(ap);
return rc;
}
int mariadb_rpl_get_optionsv(MARIADB_RPL *rpl,
enum mariadb_rpl_option option,
...)
{
va_list ap;
if (!rpl)
return 1;
va_start(ap, option);
switch (option) {
case MARIADB_RPL_FILENAME:
{
const char **name= (const char **)va_arg(ap, char **);
size_t *len= (size_t*)va_arg(ap, size_t *);
*name= rpl->filename;
*len= rpl->filename_length;
break;
}
case MARIADB_RPL_SERVER_ID:
{
unsigned int *id= va_arg(ap, unsigned int *);
*id= rpl->server_id;
break;
}
case MARIADB_RPL_FLAGS:
{
unsigned int *flags= va_arg(ap, unsigned int *);
*flags= rpl->flags;
break;
}
case MARIADB_RPL_START:
{
unsigned long *start= va_arg(ap, unsigned long *);
*start= rpl->start_position;
break;
}
default:
va_end(ap);
return 1;
break;
}
va_end(ap);
return 0;
}

2515
vendor/MDBC/libmariadb/mariadb_stmt.c vendored Normal file

File diff suppressed because it is too large Load Diff

1463
vendor/MDBC/libmariadb/secure/gnutls.c vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,77 @@
/*
Copyright (C) 2018 MariaDB Corporation 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 <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
*/
#include <ma_crypt.h>
#include <gnutls/gnutls.h>
#include <gnutls/crypto.h>
static gnutls_digest_algorithm_t ma_hash_get_algorithm(unsigned int alg)
{
switch(alg)
{
case MA_HASH_MD5:
return GNUTLS_DIG_MD5;
case MA_HASH_SHA1:
return GNUTLS_DIG_SHA1;
case MA_HASH_SHA256:
return GNUTLS_DIG_SHA256;
case MA_HASH_SHA384:
return GNUTLS_DIG_SHA384;
case MA_HASH_SHA512:
return GNUTLS_DIG_SHA512;
case MA_HASH_RIPEMD160:
return GNUTLS_DIG_RMD160;
default:
return GNUTLS_DIG_UNKNOWN;
}
}
MA_HASH_CTX *ma_hash_new(unsigned int algorithm, MA_HASH_CTX *unused_ctx __attribute__((unused)))
{
gnutls_hash_hd_t ctx= NULL;
gnutls_digest_algorithm_t hash_alg= ma_hash_get_algorithm(algorithm);
/* unknown or unsupported hash algorithm */
if (hash_alg == GNUTLS_DIG_UNKNOWN)
return NULL;
if (gnutls_hash_init(&ctx, hash_alg) < 0)
return NULL;
return (MA_HASH_CTX *)ctx;
}
void ma_hash_free(MA_HASH_CTX *ctx)
{
if (ctx)
gnutls_hash_deinit((gnutls_hash_hd_t)ctx, NULL);
}
void ma_hash_input(MA_HASH_CTX *ctx,
const unsigned char *buffer,
size_t len)
{
gnutls_hash((gnutls_hash_hd_t)ctx, (const void *)buffer, len);
}
void ma_hash_result(MA_HASH_CTX *ctx, unsigned char *digest)
{
gnutls_hash_output((gnutls_hash_hd_t)ctx, digest);
}

View File

@ -0,0 +1,637 @@
/************************************************************************************
Copyright (C) 2014 MariaDB Corporation 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 <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
Author: Georg Richter
*************************************************************************************/
#include "ma_schannel.h"
#include "schannel_certs.h"
#include <assert.h>
#define SC_IO_BUFFER_SIZE 0x4000
#define MAX_SSL_ERR_LEN 100
#define SCHANNEL_PAYLOAD(A) ((A).cbMaximumMessage + (A).cbHeader + (A).cbTrailer)
void ma_schannel_set_win_error(MARIADB_PVIO *pvio, DWORD ErrorNo);
/* {{{ void ma_schannel_set_sec_error */
void ma_schannel_set_sec_error(MARIADB_PVIO* pvio, DWORD ErrorNo)
{
MYSQL* mysql = pvio->mysql;
if (ErrorNo != SEC_E_OK)
mysql->net.extension->extended_errno = ErrorNo;
if (ErrorNo == SEC_E_INTERNAL_ERROR && GetLastError())
{
ma_schannel_set_win_error(pvio, GetLastError());
return;
}
ma_schannel_set_win_error(pvio, ErrorNo);
}
/* }}} */
#include "win32_errmsg.h"
/* {{{ void ma_schnnel_set_win_error */
void ma_schannel_set_win_error(MARIADB_PVIO *pvio, DWORD ErrorNo)
{
char buffer[256];
ma_format_win32_error(buffer, sizeof(buffer), ErrorNo, "SSL connection error: ");
pvio->set_error(pvio->mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, buffer);
return;
}
/* }}} */
/* }}} */
/* {{{ SECURITY_STATUS ma_schannel_handshake_loop(MARIADB_PVIO *pvio, my_bool InitialRead, SecBuffer *pExtraData) */
/*
perform handshake loop
SYNOPSIS
ma_schannel_handshake_loop()
pvio Pointer to an Communication/IO structure
InitialRead TRUE if it's the very first read
ExtraData Pointer to an SecBuffer which contains extra data (sent by application)
*/
SECURITY_STATUS ma_schannel_handshake_loop(MARIADB_PVIO *pvio, my_bool InitialRead, SecBuffer *pExtraData)
{
SecBufferDesc OutBuffer, InBuffer;
SecBuffer InBuffers[2], OutBuffers;
DWORD dwSSPIFlags, dwSSPIOutFlags, cbData, cbIoBuffer;
TimeStamp tsExpiry;
SECURITY_STATUS rc;
PUCHAR IoBuffer;
BOOL fDoRead;
MARIADB_TLS *ctls= pvio->ctls;
SC_CTX *sctx= (SC_CTX *)ctls->ssl;
dwSSPIFlags = ISC_REQ_SEQUENCE_DETECT |
ISC_REQ_REPLAY_DETECT |
ISC_REQ_CONFIDENTIALITY |
ISC_RET_EXTENDED_ERROR |
ISC_REQ_ALLOCATE_MEMORY |
ISC_REQ_STREAM;
/* Allocate data buffer */
if (!(IoBuffer = LocalAlloc(LMEM_FIXED, SC_IO_BUFFER_SIZE)))
return SEC_E_INSUFFICIENT_MEMORY;
cbIoBuffer = 0;
fDoRead = InitialRead;
/* handshake loop: We will leave if handshake is finished
or an error occurs */
rc = SEC_I_CONTINUE_NEEDED;
while (rc == SEC_I_CONTINUE_NEEDED ||
rc == SEC_E_INCOMPLETE_MESSAGE ||
rc == SEC_I_INCOMPLETE_CREDENTIALS )
{
/* Read data */
if (rc == SEC_E_INCOMPLETE_MESSAGE ||
!cbIoBuffer)
{
if(fDoRead)
{
ssize_t nbytes = pvio->methods->read(pvio, IoBuffer + cbIoBuffer, (size_t)(SC_IO_BUFFER_SIZE - cbIoBuffer));
if (nbytes <= 0)
{
rc = SEC_E_INTERNAL_ERROR;
break;
}
cbData = (DWORD)nbytes;
cbIoBuffer += cbData;
}
else
fDoRead = TRUE;
}
/* input buffers
First buffer stores data received from server. leftover data
will be stored in second buffer with BufferType SECBUFFER_EXTRA */
InBuffers[0].pvBuffer = IoBuffer;
InBuffers[0].cbBuffer = cbIoBuffer;
InBuffers[0].BufferType = SECBUFFER_TOKEN;
InBuffers[1].pvBuffer = NULL;
InBuffers[1].cbBuffer = 0;
InBuffers[1].BufferType = SECBUFFER_EMPTY;
InBuffer.cBuffers = 2;
InBuffer.pBuffers = InBuffers;
InBuffer.ulVersion = SECBUFFER_VERSION;
/* output buffer */
OutBuffers.pvBuffer = NULL;
OutBuffers.BufferType= SECBUFFER_TOKEN;
OutBuffers.cbBuffer = 0;
OutBuffer.cBuffers = 1;
OutBuffer.pBuffers = &OutBuffers;
OutBuffer.ulVersion = SECBUFFER_VERSION;
rc = InitializeSecurityContextA(&sctx->CredHdl,
&sctx->hCtxt,
NULL,
dwSSPIFlags,
0,
SECURITY_NATIVE_DREP,
&InBuffer,
0,
NULL,
&OutBuffer,
&dwSSPIOutFlags,
&tsExpiry );
if (rc == SEC_E_OK ||
rc == SEC_I_CONTINUE_NEEDED ||
(FAILED(rc) && (dwSSPIOutFlags & ISC_RET_EXTENDED_ERROR)))
{
if(OutBuffers.cbBuffer && OutBuffers.pvBuffer)
{
ssize_t nbytes = pvio->methods->write(pvio, (uchar *)OutBuffers.pvBuffer, (size_t)OutBuffers.cbBuffer);
if(nbytes <= 0)
{
FreeContextBuffer(OutBuffers.pvBuffer);
DeleteSecurityContext(&sctx->hCtxt);
return SEC_E_INTERNAL_ERROR;
}
cbData= (DWORD)nbytes;
/* Free output context buffer */
FreeContextBuffer(OutBuffers.pvBuffer);
OutBuffers.pvBuffer = NULL;
}
}
/* check if we need to read more data */
switch (rc) {
case SEC_E_INCOMPLETE_MESSAGE:
/* we didn't receive all data, so just continue loop */
continue;
break;
case SEC_E_OK:
/* handshake completed, but we need to check if extra
data was sent (which contains encrypted application data) */
if (InBuffers[1].BufferType == SECBUFFER_EXTRA)
{
if (!(pExtraData->pvBuffer= LocalAlloc(0, InBuffers[1].cbBuffer)))
return SEC_E_INSUFFICIENT_MEMORY;
MoveMemory(pExtraData->pvBuffer, IoBuffer + (cbIoBuffer - InBuffers[1].cbBuffer), InBuffers[1].cbBuffer );
pExtraData->BufferType = SECBUFFER_TOKEN;
pExtraData->cbBuffer = InBuffers[1].cbBuffer;
}
else
{
pExtraData->BufferType= SECBUFFER_EMPTY;
pExtraData->pvBuffer= NULL;
pExtraData->cbBuffer= 0;
}
break;
case SEC_I_INCOMPLETE_CREDENTIALS:
/* Provided credentials didn't contain a valid client certificate.
We will try to connect anonymously, using current credentials */
fDoRead= FALSE;
rc= SEC_I_CONTINUE_NEEDED;
continue;
break;
default:
if (FAILED(rc))
{
goto loopend;
}
break;
}
if ( InBuffers[1].BufferType == SECBUFFER_EXTRA )
{
MoveMemory( IoBuffer, IoBuffer + (cbIoBuffer - InBuffers[1].cbBuffer), InBuffers[1].cbBuffer );
cbIoBuffer = InBuffers[1].cbBuffer;
}
else
cbIoBuffer = 0;
}
loopend:
if (FAILED(rc))
{
ma_schannel_set_sec_error(pvio, rc);
DeleteSecurityContext(&sctx->hCtxt);
}
LocalFree(IoBuffer);
return rc;
}
/* }}} */
/* {{{ SECURITY_STATUS ma_schannel_client_handshake(MARIADB_TLS *ctls) */
/*
performs client side handshake
SYNOPSIS
ma_schannel_client_handshake()
ctls Pointer to a MARIADB_TLS structure
DESCRIPTION
initiates a client/server handshake. This function can be used
by clients only
RETURN
SEC_E_OK on success
*/
SECURITY_STATUS ma_schannel_client_handshake(MARIADB_TLS *ctls)
{
MARIADB_PVIO *pvio;
SECURITY_STATUS sRet;
DWORD OutFlags;
DWORD r;
SC_CTX *sctx;
SecBuffer ExtraData;
DWORD SFlags= ISC_REQ_SEQUENCE_DETECT | ISC_REQ_REPLAY_DETECT |
ISC_REQ_CONFIDENTIALITY | ISC_RET_EXTENDED_ERROR |
ISC_REQ_USE_SUPPLIED_CREDS |
ISC_REQ_ALLOCATE_MEMORY | ISC_REQ_STREAM;
SecBufferDesc BufferOut;
SecBuffer BuffersOut;
if (!ctls || !ctls->pvio)
return 1;
pvio= ctls->pvio;
sctx= (SC_CTX *)ctls->ssl;
/* Initialie securifty context */
BuffersOut.BufferType= SECBUFFER_TOKEN;
BuffersOut.cbBuffer= 0;
BuffersOut.pvBuffer= NULL;
BufferOut.cBuffers= 1;
BufferOut.pBuffers= &BuffersOut;
BufferOut.ulVersion= SECBUFFER_VERSION;
sRet = InitializeSecurityContext(&sctx->CredHdl,
NULL,
pvio->mysql->host,
SFlags,
0,
SECURITY_NATIVE_DREP,
NULL,
0,
&sctx->hCtxt,
&BufferOut,
&OutFlags,
NULL);
if(sRet != SEC_I_CONTINUE_NEEDED)
{
ma_schannel_set_sec_error(pvio, sRet);
return sRet;
}
/* send client hello packaet */
if(BuffersOut.cbBuffer != 0 && BuffersOut.pvBuffer != NULL)
{
ssize_t nbytes = (DWORD)pvio->methods->write(pvio, (uchar *)BuffersOut.pvBuffer, (size_t)BuffersOut.cbBuffer);
if (nbytes <= 0)
{
sRet= SEC_E_INTERNAL_ERROR;
goto end;
}
r = (DWORD)nbytes;
}
sRet= ma_schannel_handshake_loop(pvio, TRUE, &ExtraData);
/* allocate IO-Buffer for write operations: After handshake
was successful, we are able now to calculate payload */
if ((sRet = QueryContextAttributes(&sctx->hCtxt, SECPKG_ATTR_STREAM_SIZES, &sctx->Sizes )))
goto end;
sctx->IoBufferSize= SCHANNEL_PAYLOAD(sctx->Sizes);
if (!(sctx->IoBuffer= (PUCHAR)LocalAlloc(0, sctx->IoBufferSize)))
{
sRet= SEC_E_INSUFFICIENT_MEMORY;
goto end;
}
return sRet;
end:
if (BuffersOut.pvBuffer)
FreeContextBuffer(BuffersOut.pvBuffer);
return sRet;
}
/* }}} */
/* {{{ SECURITY_STATUS ma_schannel_read_decrypt(MARIADB_PVIO *pvio, PCredHandle phCreds, CtxtHandle * phContext,
DWORD DecryptLength, uchar *ReadBuffer, DWORD ReadBufferSize) */
/*
Reads encrypted data from a SSL stream and decrypts it.
SYNOPSIS
ma_schannel_read
pvio pointer to Communication IO structure
phContext a context handle
DecryptLength size of decrypted buffer
ReadBuffer Buffer for decrypted data
ReadBufferSize size of ReadBuffer
DESCRIPTION
Reads decrypted data from a SSL stream and encrypts it.
RETURN
SEC_E_OK on success
SEC_E_* if an error occurred
*/
SECURITY_STATUS ma_schannel_read_decrypt(MARIADB_PVIO *pvio,
CtxtHandle * phContext,
DWORD *DecryptLength,
uchar *ReadBuffer,
DWORD ReadBufferSize)
{
ssize_t nbytes = 0;
DWORD dwOffset = 0;
SC_CTX *sctx;
SECURITY_STATUS sRet = 0;
SecBufferDesc Msg;
SecBuffer Buffers[4];
int i;
if (!pvio || !pvio->methods || !pvio->methods->read || !pvio->ctls || !DecryptLength)
return SEC_E_INTERNAL_ERROR;
sctx = (SC_CTX *)pvio->ctls->ssl;
*DecryptLength = 0;
if (sctx->dataBuf.cbBuffer)
{
/* Have unread decrypted data from the last time, copy. */
nbytes = MIN(ReadBufferSize, sctx->dataBuf.cbBuffer);
memcpy(ReadBuffer, sctx->dataBuf.pvBuffer, nbytes);
sctx->dataBuf.pvBuffer = (char *)(sctx->dataBuf.pvBuffer) + nbytes;
sctx->dataBuf.cbBuffer -= (DWORD)nbytes;
*DecryptLength = (DWORD)nbytes;
return SEC_E_OK;
}
while (1)
{
/* Check for any encrypted data returned by last DecryptMessage() in SECBUFFER_EXTRA buffer. */
if (sctx->extraBuf.cbBuffer)
{
memmove(sctx->IoBuffer, sctx->extraBuf.pvBuffer, sctx->extraBuf.cbBuffer);
dwOffset = sctx->extraBuf.cbBuffer;
sctx->extraBuf.cbBuffer = 0;
}
do {
assert(sctx->IoBufferSize > dwOffset);
if (dwOffset == 0 || sRet == SEC_E_INCOMPLETE_MESSAGE)
{
nbytes = pvio->methods->read(pvio, sctx->IoBuffer + dwOffset, (size_t)(sctx->IoBufferSize - dwOffset));
if (nbytes <= 0)
{
/* server closed connection, or an error */
// todo: error
return SEC_E_INVALID_HANDLE;
}
dwOffset += (DWORD)nbytes;
}
ZeroMemory(Buffers, sizeof(SecBuffer) * 4);
Buffers[0].pvBuffer = sctx->IoBuffer;
Buffers[0].cbBuffer = dwOffset;
Buffers[0].BufferType = SECBUFFER_DATA;
Buffers[1].BufferType = SECBUFFER_EMPTY;
Buffers[2].BufferType = SECBUFFER_EMPTY;
Buffers[3].BufferType = SECBUFFER_EMPTY;
Msg.ulVersion = SECBUFFER_VERSION; // Version number
Msg.cBuffers = 4;
Msg.pBuffers = Buffers;
sRet = DecryptMessage(phContext, &Msg, 0, NULL);
} while (sRet == SEC_E_INCOMPLETE_MESSAGE); /* Continue reading until full message arrives */
if (sRet != SEC_E_OK)
{
ma_schannel_set_sec_error(pvio, sRet);
return sRet;
}
sctx->extraBuf.cbBuffer = 0;
sctx->dataBuf.cbBuffer = 0;
for (i = 0; i < 4; i++)
{
if (Buffers[i].BufferType == SECBUFFER_DATA)
sctx->dataBuf = Buffers[i];
if (Buffers[i].BufferType == SECBUFFER_EXTRA)
sctx->extraBuf = Buffers[i];
}
if (sctx->dataBuf.cbBuffer)
{
assert(sctx->dataBuf.pvBuffer);
/*
Copy at most ReadBufferSize bytes to output.
Store the rest (if any) to be processed next time.
*/
nbytes = MIN(sctx->dataBuf.cbBuffer, ReadBufferSize);
memcpy((char *)ReadBuffer, sctx->dataBuf.pvBuffer, nbytes);
sctx->dataBuf.cbBuffer -= (unsigned long)nbytes;
sctx->dataBuf.pvBuffer = (char *)sctx->dataBuf.pvBuffer + nbytes;
*DecryptLength = (DWORD)nbytes;
return SEC_E_OK;
}
// No data buffer, loop
}
}
/* }}} */
#include "win32_errmsg.h"
my_bool ma_schannel_verify_certs(MARIADB_TLS *ctls, BOOL verify_server_name)
{
SECURITY_STATUS status;
MARIADB_PVIO *pvio= ctls->pvio;
MYSQL *mysql= pvio->mysql;
SC_CTX *sctx = (SC_CTX *)ctls->ssl;
const char *ca_file= mysql->options.ssl_ca;
const char* ca_path = mysql->options.ssl_capath;
const char *crl_file= mysql->options.extension ? mysql->options.extension->ssl_crl : NULL;
const char* crl_path = mysql->options.extension ? mysql->options.extension->ssl_crlpath : NULL;
PCCERT_CONTEXT pServerCert= NULL;
char errmsg[256];
HCERTSTORE store= NULL;
int ret= 0;
status = schannel_create_store(ca_file, ca_path, crl_file, crl_path, &store, errmsg, sizeof(errmsg));
if(status)
goto end;
status = QueryContextAttributesA(&sctx->hCtxt, SECPKG_ATTR_REMOTE_CERT_CONTEXT, (PVOID)&pServerCert);
if (status)
{
ma_format_win32_error(errmsg, sizeof(errmsg), GetLastError(),
"QueryContextAttributes(SECPKG_ATTR_REMOTE_CERT_CONTEXT) failed.");
goto end;
}
status = schannel_verify_server_certificate(
pServerCert,
store,
crl_file != 0 || crl_path != 0,
mysql->host,
verify_server_name,
errmsg, sizeof(errmsg));
if (status)
goto end;
ret= 1;
end:
if (!ret)
{
pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
"SSL connection error: %s", errmsg);
}
if (pServerCert)
CertFreeCertificateContext(pServerCert);
if(store)
schannel_free_store(store);
return ret;
}
/* {{{ size_t ma_schannel_write_encrypt(MARIADB_PVIO *pvio, PCredHandle phCreds, CtxtHandle * phContext) */
/*
Decrypts data and write to SSL stream
SYNOPSIS
ma_schannel_write_decrypt
pvio pointer to Communication IO structure
phContext a context handle
DecryptLength size of decrypted buffer
ReadBuffer Buffer for decrypted data
ReadBufferSize size of ReadBuffer
DESCRIPTION
Write encrypted data to SSL stream.
RETURN
SEC_E_OK on success
SEC_E_* if an error occurred
*/
ssize_t ma_schannel_write_encrypt(MARIADB_PVIO *pvio,
uchar *WriteBuffer,
size_t WriteBufferSize)
{
SECURITY_STATUS scRet;
SecBufferDesc Message;
SecBuffer Buffers[4];
DWORD cbMessage;
PBYTE pbMessage;
SC_CTX *sctx= (SC_CTX *)pvio->ctls->ssl;
size_t payload;
ssize_t nbytes;
DWORD write_size;
payload= MIN(WriteBufferSize, sctx->Sizes.cbMaximumMessage);
memcpy(&sctx->IoBuffer[sctx->Sizes.cbHeader], WriteBuffer, payload);
pbMessage = sctx->IoBuffer + sctx->Sizes.cbHeader;
cbMessage = (DWORD)payload;
Buffers[0].pvBuffer = sctx->IoBuffer;
Buffers[0].cbBuffer = sctx->Sizes.cbHeader;
Buffers[0].BufferType = SECBUFFER_STREAM_HEADER; // Type of the buffer
Buffers[1].pvBuffer = &sctx->IoBuffer[sctx->Sizes.cbHeader];
Buffers[1].cbBuffer = (DWORD)payload;
Buffers[1].BufferType = SECBUFFER_DATA;
Buffers[2].pvBuffer = &sctx->IoBuffer[sctx->Sizes.cbHeader] + payload;
Buffers[2].cbBuffer = sctx->Sizes.cbTrailer;
Buffers[2].BufferType = SECBUFFER_STREAM_TRAILER;
Buffers[3].pvBuffer = SECBUFFER_EMPTY; // Pointer to buffer 4
Buffers[3].cbBuffer = SECBUFFER_EMPTY; // length of buffer 4
Buffers[3].BufferType = SECBUFFER_EMPTY; // Type of the buffer 4
Message.ulVersion = SECBUFFER_VERSION;
Message.cBuffers = 4;
Message.pBuffers = Buffers;
if ((scRet = EncryptMessage(&sctx->hCtxt, 0, &Message, 0))!= SEC_E_OK)
return -1;
write_size = Buffers[0].cbBuffer + Buffers[1].cbBuffer + Buffers[2].cbBuffer;
nbytes = pvio->methods->write(pvio, sctx->IoBuffer, write_size);
return nbytes == write_size ? payload : -1;
}
/* }}} */
extern char *ssl_protocol_version[5];
/* {{{ ma_tls_get_protocol_version(MARIADB_TLS *ctls) */
int ma_tls_get_protocol_version(MARIADB_TLS *ctls)
{
SC_CTX *sctx;
SecPkgContext_ConnectionInfo ConnectionInfo;
if (!ctls->ssl)
return 1;
sctx= (SC_CTX *)ctls->ssl;
if (QueryContextAttributes(&sctx->hCtxt, SECPKG_ATTR_CONNECTION_INFO, &ConnectionInfo) != SEC_E_OK)
return -1;
switch(ConnectionInfo.dwProtocol)
{
case SP_PROT_SSL3_CLIENT:
return PROTOCOL_SSLV3;
case SP_PROT_TLS1_CLIENT:
return PROTOCOL_TLS_1_0;
case SP_PROT_TLS1_1_CLIENT:
return PROTOCOL_TLS_1_1;
case SP_PROT_TLS1_2_CLIENT:
return PROTOCOL_TLS_1_2;
default:
return -1;
}
}
/* }}} */

View File

@ -0,0 +1,87 @@
/************************************************************************************
Copyright (C) 2014 MariaDB Corporation 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 <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
Author: Georg Richter
*************************************************************************************/
#ifndef _ma_schannel_h_
#define _ma_schannel_h_
#define SECURITY_WIN32
#include <ma_global.h>
#include <ma_sys.h>
#include <ma_common.h>
#include <ma_pvio.h>
#include <errmsg.h>
#include <wincrypt.h>
#include <wintrust.h>
#include <security.h>
#include <schnlsp.h>
#undef SECURITY_WIN32
#include <windows.h>
#include <sspi.h>
#define SC_IO_BUFFER_SIZE 0x4000
#include <ma_pthread.h>
struct st_DER {
char* der_buffer;
DWORD der_length;
};
struct st_schannel {
CredHandle CredHdl;
PUCHAR IoBuffer;
DWORD IoBufferSize;
SecPkgContext_StreamSizes Sizes;
CtxtHandle hCtxt;
/* Cached data from the last read/decrypt call.*/
SecBuffer extraBuf; /* encrypted data read from server. */
SecBuffer dataBuf; /* decrypted but still unread data from server.*/
};
typedef struct st_schannel SC_CTX;
extern HCERTSTORE ca_CertStore, crl_CertStore;
extern my_bool ca_Check, crl_Check;
;
SECURITY_STATUS ma_schannel_client_handshake(MARIADB_TLS *ctls);
SECURITY_STATUS ma_schannel_handshake_loop(MARIADB_PVIO *pvio, my_bool InitialRead, SecBuffer *pExtraData);
my_bool ma_schannel_verify_certs(MARIADB_TLS *ctls, BOOL verify_server_name);
ssize_t ma_schannel_write_encrypt(MARIADB_PVIO *pvio,
uchar *WriteBuffer,
size_t WriteBufferSize);
SECURITY_STATUS ma_schannel_read_decrypt(MARIADB_PVIO *pvio,
CtxtHandle* phContext,
DWORD *DecryptLength,
uchar *ReadBuffer,
DWORD ReadBufferSize);
#endif /* _ma_schannel_h_ */

797
vendor/MDBC/libmariadb/secure/openssl.c vendored Normal file
View File

@ -0,0 +1,797 @@
/************************************************************************************
Copyright (C) 2012 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 <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
*************************************************************************************/
#include <ma_global.h>
#include <ma_sys.h>
#include <ma_common.h>
#include <ma_pvio.h>
#include <errmsg.h>
#include <string.h>
#include <mysql/client_plugin.h>
#include <string.h>
#include <openssl/ssl.h> /* SSL and SSL_CTX */
#include <openssl/err.h> /* error reporting */
#include <openssl/conf.h>
#include <openssl/md4.h>
#if defined(_WIN32) && !defined(_OPENSSL_Applink) && defined(HAVE_OPENSSL_APPLINK_C)
#include <openssl/applink.c>
#endif
#if OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined(LIBRESSL_VERSION_NUMBER)
#include <openssl/x509v3.h>
#define HAVE_OPENSSL_CHECK_HOST 1
#endif
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
#define HAVE_OPENSSL_1_1_API
#endif
#if OPENSSL_VERSION_NUMBER < 0x10000000L
#define SSL_OP_NO_TLSv1_1 0L
#define SSL_OP_NO_TLSv1_2 0L
#define CRYPTO_THREADID_set_callback CRYPTO_set_id_callback
#define CRYPTO_THREADID_get_callback CRYPTO_get_id_callback
#endif
#if defined(OPENSSL_USE_BIOMETHOD)
#undef OPENSSL_USE_BIOMETHOD
#endif
#ifndef HAVE_OPENSSL_DEFAULT
#include <memory.h>
#define ma_malloc(A,B) malloc((A))
#undef ma_free
#define ma_free(A) free((A))
#define ma_snprintf snprintf
#define ma_vsnprintf vsnprintf
#undef SAFE_MUTEX
#endif
#include <ma_pthread.h>
#include <mariadb_async.h>
#include <ma_context.h>
extern my_bool ma_tls_initialized;
extern unsigned int mariadb_deinitialize_ssl;
#define MAX_SSL_ERR_LEN 100
char tls_library_version[TLS_VERSION_LENGTH];
static pthread_mutex_t LOCK_openssl_config;
#ifndef HAVE_OPENSSL_1_1_API
static pthread_mutex_t *LOCK_crypto= NULL;
#endif
#if defined(OPENSSL_USE_BIOMETHOD)
static int ma_bio_read(BIO *h, char *buf, int size);
static int ma_bio_write(BIO *h, const char *buf, int size);
static BIO_METHOD ma_BIO_method;
#endif
static long ma_tls_version_options(const char *version)
{
long protocol_options,
disable_all_protocols;
protocol_options= disable_all_protocols=
SSL_OP_NO_SSLv2 |
SSL_OP_NO_SSLv3 |
SSL_OP_NO_TLSv1 |
SSL_OP_NO_TLSv1_1 |
SSL_OP_NO_TLSv1_2
#ifdef TLS1_3_VERSION
| SSL_OP_NO_TLSv1_3
#endif
;
if (!version)
return 0;
if (strstr(version, "TLSv1.0"))
protocol_options&= ~SSL_OP_NO_TLSv1;
if (strstr(version, "TLSv1.1"))
protocol_options&= ~SSL_OP_NO_TLSv1_1;
if (strstr(version, "TLSv1.2"))
protocol_options&= ~SSL_OP_NO_TLSv1_2;
#ifdef TLS1_3_VERSION
if (strstr(version, "TLSv1.3"))
protocol_options&= ~SSL_OP_NO_TLSv1_3;
#endif
if (protocol_options != disable_all_protocols)
return protocol_options;
return 0;
}
static void ma_tls_set_error(MYSQL *mysql)
{
ulong ssl_errno= ERR_get_error();
char ssl_error[MAX_SSL_ERR_LEN];
const char *ssl_error_reason;
MARIADB_PVIO *pvio= mysql->net.pvio;
if (!ssl_errno)
{
pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, "Unknown SSL error");
return;
}
if ((ssl_error_reason= ERR_reason_error_string(ssl_errno)))
{
pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
0, ssl_error_reason);
return;
}
snprintf(ssl_error, MAX_SSL_ERR_LEN, "SSL errno=%lu", ssl_errno);
pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, 0, ssl_error);
return;
}
#ifndef HAVE_OPENSSL_1_1_API
/*
thread safe callbacks for OpenSSL
Crypto call back functions will be
set during ssl_initialization
*/
#if OPENSSL_VERSION_NUMBER < 0x10000000L
static unsigned long my_cb_threadid(void)
{
/* cast pthread_t to unsigned long */
return (unsigned long) pthread_self();
}
#else
static void my_cb_threadid(CRYPTO_THREADID *id)
{
CRYPTO_THREADID_set_numeric(id, (unsigned long)pthread_self());
}
#endif
#endif
#ifndef HAVE_OPENSSL_1_1_API
static void my_cb_locking(int mode, int n,
const char *file __attribute__((unused)),
int line __attribute__((unused)))
{
if (mode & CRYPTO_LOCK)
pthread_mutex_lock(&LOCK_crypto[n]);
else
pthread_mutex_unlock(&LOCK_crypto[n]);
}
static int ssl_thread_init()
{
if (!CRYPTO_THREADID_get_callback()
#ifndef OPENSSL_NO_DEPRECATED
&& !CRYPTO_get_id_callback()
#endif
)
{
int i, max= CRYPTO_num_locks();
if (LOCK_crypto == NULL)
{
if (!(LOCK_crypto=
(pthread_mutex_t *)ma_malloc(sizeof(pthread_mutex_t) * max, MYF(0))))
return 1;
for (i=0; i < max; i++)
pthread_mutex_init(&LOCK_crypto[i], NULL);
}
CRYPTO_set_locking_callback(my_cb_locking);
CRYPTO_THREADID_set_callback(my_cb_threadid);
}
return 0;
}
#endif
#if defined(_WIN32) || !defined(DISABLE_SIGPIPE)
#define disable_sigpipe()
#else
#include <signal.h>
static void ma_sigpipe_handler()
{
}
static void disable_sigpipe()
{
struct sigaction old_handler, new_handler={NULL};
if (!sigaction (SIGPIPE, NULL, &old_handler) &&
!old_handler.sa_handler)
{
new_handler.sa_handler= ma_sigpipe_handler;
new_handler.sa_flags= 0;
if (!sigemptyset(&new_handler.sa_mask))
sigaction(SIGPIPE, &new_handler, NULL);
}
}
#endif
/*
Initializes SSL
SYNOPSIS
my_ssl_start
mysql connection handle
RETURN VALUES
0 success
1 error
*/
int ma_tls_start(char *errmsg __attribute__((unused)), size_t errmsg_len __attribute__((unused)))
{
int rc= 1;
char *p;
if (ma_tls_initialized)
return 0;
/* lock mutex to prevent multiple initialization */
pthread_mutex_init(&LOCK_openssl_config, NULL);
pthread_mutex_lock(&LOCK_openssl_config);
#ifdef HAVE_OPENSSL_1_1_API
if (!OPENSSL_init_ssl(OPENSSL_INIT_LOAD_CONFIG, NULL))
goto end;
#else
if (ssl_thread_init())
{
strncpy(errmsg, "Not enough memory", errmsg_len);
goto end;
}
SSL_library_init();
#if SSLEAY_VERSION_NUMBER >= 0x00907000L
OPENSSL_config(NULL);
#endif
#endif
#ifndef HAVE_OPENSSL_1_1_API
/* load errors */
SSL_load_error_strings();
/* digests and ciphers */
OpenSSL_add_all_algorithms();
#endif
disable_sigpipe();
#ifdef OPENSSL_USE_BIOMETHOD
memcpy(&ma_BIO_method, BIO_s_socket(), sizeof(BIO_METHOD));
ma_BIO_method.bread= ma_bio_read;
ma_BIO_method.bwrite= ma_bio_write;
#endif
snprintf(tls_library_version, TLS_VERSION_LENGTH - 1, "%s",
#if defined(LIBRESSL_VERSION_NUMBER) || !defined(HAVE_OPENSSL_1_1_API)
SSLeay_version(SSLEAY_VERSION));
#else
OpenSSL_version(OPENSSL_VERSION));
#endif
/* remove date from version */
if ((p= strstr(tls_library_version, " ")))
*p= 0;
rc= 0;
ma_tls_initialized= TRUE;
end:
pthread_mutex_unlock(&LOCK_openssl_config);
return rc;
}
/*
Release SSL and free resources
Will be automatically executed by
mysql_server_end() function
SYNOPSIS
my_ssl_end()
void
RETURN VALUES
void
*/
void ma_tls_end()
{
if (ma_tls_initialized)
{
pthread_mutex_lock(&LOCK_openssl_config);
#ifndef HAVE_OPENSSL_1_1_API
if (LOCK_crypto)
{
int i;
CRYPTO_set_locking_callback(NULL);
CRYPTO_THREADID_set_callback(NULL);
for (i=0; i < CRYPTO_num_locks(); i++)
pthread_mutex_destroy(&LOCK_crypto[i]);
ma_free((gptr)LOCK_crypto);
LOCK_crypto= NULL;
}
#endif
if (mariadb_deinitialize_ssl)
{
#ifndef HAVE_OPENSSL_1_1_API
ERR_remove_thread_state(NULL);
EVP_cleanup();
CRYPTO_cleanup_all_ex_data();
ERR_free_strings();
CONF_modules_free();
CONF_modules_unload(1);
#endif
}
ma_tls_initialized= FALSE;
pthread_mutex_unlock(&LOCK_openssl_config);
pthread_mutex_destroy(&LOCK_openssl_config);
}
return;
}
int ma_tls_get_password(char *buf, int size,
int rwflag __attribute__((unused)),
void *userdata)
{
memset(buf, 0, size);
if (userdata)
strncpy(buf, (char *)userdata, size);
return (int)strlen(buf);
}
static int ma_tls_set_certs(MYSQL *mysql, SSL_CTX *ctx)
{
char *certfile= mysql->options.ssl_cert,
*keyfile= mysql->options.ssl_key;
char *pw= (mysql->options.extension) ?
mysql->options.extension->tls_pw : NULL;
/* add cipher */
if ((mysql->options.ssl_cipher &&
mysql->options.ssl_cipher[0] != 0))
{
if(
#ifdef TLS1_3_VERSION
SSL_CTX_set_ciphersuites(ctx, mysql->options.ssl_cipher) == 0 &&
#endif
SSL_CTX_set_cipher_list(ctx, mysql->options.ssl_cipher) == 0)
goto error;
}
/* ca_file and ca_path */
if (!SSL_CTX_load_verify_locations(ctx,
mysql->options.ssl_ca,
mysql->options.ssl_capath))
{
if (mysql->options.ssl_ca || mysql->options.ssl_capath)
goto error;
if (SSL_CTX_set_default_verify_paths(ctx) == 0)
goto error;
}
if (mysql->options.extension &&
(mysql->options.extension->ssl_crl || mysql->options.extension->ssl_crlpath))
{
X509_STORE *certstore;
if ((certstore= SSL_CTX_get_cert_store(ctx)))
{
if (X509_STORE_load_locations(certstore, mysql->options.extension->ssl_crl,
mysql->options.extension->ssl_crlpath) == 0)
goto error;
if (X509_STORE_set_flags(certstore, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL) == 0)
goto error;
}
}
if (keyfile && !certfile)
certfile= keyfile;
if (certfile && !keyfile)
keyfile= certfile;
/* set cert */
if (certfile && certfile[0] != 0)
{
if (SSL_CTX_use_certificate_chain_file(ctx, certfile) != 1)
{
goto error;
}
}
if (keyfile && keyfile[0])
{
FILE *fp;
if ((fp= fopen(keyfile, "rb")))
{
EVP_PKEY *key= EVP_PKEY_new();
PEM_read_PrivateKey(fp, &key, NULL, pw);
fclose(fp);
if (SSL_CTX_use_PrivateKey(ctx, key) != 1)
{
unsigned long err= ERR_peek_error();
EVP_PKEY_free(key);
if (!(ERR_GET_LIB(err) == ERR_LIB_X509 &&
ERR_GET_REASON(err) == X509_R_CERT_ALREADY_IN_HASH_TABLE))
goto error;
}
EVP_PKEY_free(key);
} else {
my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
CER(CR_FILE_NOT_FOUND), keyfile);
return 1;
}
}
/* verify key */
if (certfile && SSL_CTX_check_private_key(ctx) != 1)
goto error;
SSL_CTX_set_verify(ctx, (mysql->options.ssl_ca || mysql->options.ssl_capath) ?
SSL_VERIFY_PEER : SSL_VERIFY_NONE, NULL);
return 0;
error:
ma_tls_set_error(mysql);
return 1;
}
void *ma_tls_init(MYSQL *mysql)
{
SSL *ssl= NULL;
SSL_CTX *ctx= NULL;
long default_options= SSL_OP_ALL |
SSL_OP_NO_SSLv2 |
SSL_OP_NO_SSLv3;
long options= 0;
pthread_mutex_lock(&LOCK_openssl_config);
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
if (!(ctx= SSL_CTX_new(TLS_client_method())))
#else
if (!(ctx= SSL_CTX_new(SSLv23_client_method())))
#endif
goto error;
if (mysql->options.extension)
options= ma_tls_version_options(mysql->options.extension->tls_version);
SSL_CTX_set_options(ctx, options ? options : default_options);
if (ma_tls_set_certs(mysql, ctx))
{
goto error;
}
if (!(ssl= SSL_new(ctx)))
goto error;
if (!SSL_set_app_data(ssl, mysql))
goto error;
pthread_mutex_unlock(&LOCK_openssl_config);
return (void *)ssl;
error:
pthread_mutex_unlock(&LOCK_openssl_config);
if (ctx)
SSL_CTX_free(ctx);
if (ssl)
SSL_free(ssl);
return NULL;
}
my_bool ma_tls_connect(MARIADB_TLS *ctls)
{
SSL *ssl = (SSL *)ctls->ssl;
my_bool blocking, try_connect= 1;
MYSQL *mysql;
MARIADB_PVIO *pvio;
int rc;
#ifdef OPENSSL_USE_BIOMETHOD
BIO_METHOD *bio_method= NULL;
BIO *bio;
#endif
mysql= (MYSQL *)SSL_get_app_data(ssl);
pvio= mysql->net.pvio;
/* Set socket to non blocking if not already set */
if (!(blocking= pvio->methods->is_blocking(pvio)))
pvio->methods->blocking(pvio, FALSE, 0);
SSL_clear(ssl);
#ifdef OPENSSL_USE_BIOMETHOD
bio= BIO_new(&ma_BIO_method);
bio->ptr= pvio;
SSL_set_bio(ssl, bio, bio);
BIO_set_fd(bio, mysql_get_socket(mysql), BIO_NOCLOSE);
#else
SSL_set_fd(ssl, (int)mysql_get_socket(mysql));
#endif
while (try_connect && (rc= SSL_connect(ssl)) == -1)
{
switch((SSL_get_error(ssl, rc))) {
case SSL_ERROR_WANT_READ:
if (pvio->methods->wait_io_or_timeout(pvio, TRUE, mysql->options.connect_timeout) < 1)
try_connect= 0;
break;
case SSL_ERROR_WANT_WRITE:
if (pvio->methods->wait_io_or_timeout(pvio, TRUE, mysql->options.connect_timeout) < 1)
try_connect= 0;
break;
default:
try_connect= 0;
}
}
/* In case handshake failed or if a root certificate (ca) was specified,
we need to check the result code of X509 verification. A detailed check
of the peer certificate (hostname checking will follow later) */
if (rc != 1 ||
(mysql->client_flag & CLIENT_SSL_VERIFY_SERVER_CERT) ||
(mysql->options.ssl_ca || mysql->options.ssl_capath))
{
long x509_err= SSL_get_verify_result(ssl);
if (x509_err != X509_V_OK)
{
my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
ER(CR_SSL_CONNECTION_ERROR), X509_verify_cert_error_string(x509_err));
/* restore blocking mode */
if (!blocking)
pvio->methods->blocking(pvio, FALSE, 0);
return 1;
} else if (rc != 1) {
ma_tls_set_error(mysql);
return 1;
}
}
pvio->ctls->ssl= ctls->ssl= (void *)ssl;
return 0;
}
static my_bool
ma_tls_async_check_result(int res, struct mysql_async_context *b, SSL *ssl)
{
int ssl_err;
b->events_to_wait_for= 0;
if (res >= 0)
return 1;
ssl_err= SSL_get_error(ssl, res);
if (ssl_err == SSL_ERROR_WANT_READ)
b->events_to_wait_for|= MYSQL_WAIT_READ;
else if (ssl_err == SSL_ERROR_WANT_WRITE)
b->events_to_wait_for|= MYSQL_WAIT_WRITE;
else
return 1;
if (b->suspend_resume_hook)
(*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data);
my_context_yield(&b->async_context);
if (b->suspend_resume_hook)
(*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data);
return 0;
}
ssize_t ma_tls_read_async(MARIADB_PVIO *pvio,
const unsigned char *buffer,
size_t length)
{
int res;
struct mysql_async_context *b= pvio->mysql->options.extension->async_context;
MARIADB_TLS *ctls= pvio->ctls;
for (;;)
{
res= SSL_read((SSL *)ctls->ssl, (void *)buffer, (int)length);
if (ma_tls_async_check_result(res, b, (SSL *)ctls->ssl))
return res;
}
}
ssize_t ma_tls_write_async(MARIADB_PVIO *pvio,
const unsigned char *buffer,
size_t length)
{
int res;
struct mysql_async_context *b= pvio->mysql->options.extension->async_context;
MARIADB_TLS *ctls= pvio->ctls;
for (;;)
{
res= SSL_write((SSL *)ctls->ssl, (void *)buffer, (int)length);
if (ma_tls_async_check_result(res, b, (SSL *)ctls->ssl))
return res;
}
}
ssize_t ma_tls_read(MARIADB_TLS *ctls, const uchar* buffer, size_t length)
{
int rc;
MARIADB_PVIO *pvio= ctls->pvio;
while ((rc= SSL_read((SSL *)ctls->ssl, (void *)buffer, (int)length)) < 0)
{
int error= SSL_get_error((SSL *)ctls->ssl, rc);
if (error != SSL_ERROR_WANT_READ)
return rc;
if (pvio->methods->wait_io_or_timeout(pvio, TRUE, pvio->mysql->options.read_timeout) < 1)
return rc;
}
return rc;
}
ssize_t ma_tls_write(MARIADB_TLS *ctls, const uchar* buffer, size_t length)
{
int rc;
MARIADB_PVIO *pvio= ctls->pvio;
while ((rc= SSL_write((SSL *)ctls->ssl, (void *)buffer, (int)length)) <= 0)
{
int error= SSL_get_error((SSL *)ctls->ssl, rc);
if (error != SSL_ERROR_WANT_WRITE)
return rc;
if (pvio->methods->wait_io_or_timeout(pvio, TRUE, pvio->mysql->options.write_timeout) < 1)
return rc;
}
return rc;
}
my_bool ma_tls_close(MARIADB_TLS *ctls)
{
int i, rc;
SSL *ssl;
SSL_CTX *ctx= NULL;
if (!ctls || !ctls->ssl)
return 1;
ssl= (SSL *)ctls->ssl;
ctx= SSL_get_SSL_CTX(ssl);
if (ctx)
SSL_CTX_free(ctx);
SSL_set_quiet_shutdown(ssl, 1);
/* 2 x pending + 2 * data = 4 */
for (i=0; i < 4; i++)
if ((rc= SSL_shutdown(ssl)))
break;
/* Since we transferred ownership of BIO to ssl, BIO will
automatically freed - no need for an explicit BIO_free_all */
SSL_free(ssl);
ctls->ssl= NULL;
return rc;
}
int ma_tls_verify_server_cert(MARIADB_TLS *ctls)
{
X509 *cert;
MYSQL *mysql;
SSL *ssl;
MARIADB_PVIO *pvio;
#if !defined(HAVE_OPENSSL_CHECK_HOST)
X509_NAME *x509sn;
int cn_pos;
X509_NAME_ENTRY *cn_entry;
ASN1_STRING *cn_asn1;
const char *cn_str;
#endif
if (!ctls || !ctls->ssl)
return 1;
ssl= (SSL *)ctls->ssl;
mysql= (MYSQL *)SSL_get_app_data(ssl);
pvio= mysql->net.pvio;
if (!mysql->host)
{
pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
ER(CR_SSL_CONNECTION_ERROR), "Invalid (empty) hostname");
return 1;
}
if (!(cert= SSL_get_peer_certificate(ssl)))
{
pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
ER(CR_SSL_CONNECTION_ERROR), "Unable to get server certificate");
return 1;
}
#ifdef HAVE_OPENSSL_CHECK_HOST
if (X509_check_host(cert, mysql->host, 0, 0, 0) != 1
&& X509_check_ip_asc(cert, mysql->host, 0) != 1)
goto error;
#else
x509sn= X509_get_subject_name(cert);
if ((cn_pos= X509_NAME_get_index_by_NID(x509sn, NID_commonName, -1)) < 0)
goto error;
if (!(cn_entry= X509_NAME_get_entry(x509sn, cn_pos)))
goto error;
if (!(cn_asn1 = X509_NAME_ENTRY_get_data(cn_entry)))
goto error;
cn_str = (char *)ASN1_STRING_data(cn_asn1);
/* Make sure there is no embedded \0 in the CN */
if ((size_t)ASN1_STRING_length(cn_asn1) != strlen(cn_str))
goto error;
if (strcmp(cn_str, mysql->host))
goto error;
#endif
X509_free(cert);
return 0;
error:
X509_free(cert);
pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
ER(CR_SSL_CONNECTION_ERROR), "Validation of SSL server certificate failed");
return 1;
}
const char *ma_tls_get_cipher(MARIADB_TLS *ctls)
{
if (!ctls || !ctls->ssl)
return NULL;
return SSL_get_cipher_name(ctls->ssl);
}
unsigned int ma_tls_get_finger_print(MARIADB_TLS *ctls, char *fp, unsigned int len)
{
X509 *cert= NULL;
MYSQL *mysql;
unsigned int fp_len;
if (!ctls || !ctls->ssl)
return 0;
mysql= SSL_get_app_data(ctls->ssl);
if (!(cert= SSL_get_peer_certificate(ctls->ssl)))
{
my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
ER(CR_SSL_CONNECTION_ERROR),
"Unable to get server certificate");
goto end;
}
if (len < EVP_MAX_MD_SIZE)
{
my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
ER(CR_SSL_CONNECTION_ERROR),
"Finger print buffer too small");
goto end;
}
if (!X509_digest(cert, EVP_sha1(), (unsigned char *)fp, &fp_len))
{
my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
ER(CR_SSL_CONNECTION_ERROR),
"invalid finger print of server certificate");
goto end;
}
X509_free(cert);
return (fp_len);
end:
X509_free(cert);
return 0;
}
int ma_tls_get_protocol_version(MARIADB_TLS *ctls)
{
if (!ctls || !ctls->ssl)
return -1;
return SSL_version(ctls->ssl) & 0xFF;
}

View File

@ -0,0 +1,88 @@
/*
Copyright (C) 2018 MariaDB Corporation 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 <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
*/
#include <ma_global.h>
#include <ma_crypt.h>
#include <openssl/evp.h>
static const EVP_MD *ma_hash_get_algorithm(unsigned int alg)
{
switch(alg)
{
case MA_HASH_MD5:
return EVP_md5();
case MA_HASH_SHA1:
return EVP_sha1();
case MA_HASH_SHA224:
return EVP_sha224();
case MA_HASH_SHA256:
return EVP_sha256();
case MA_HASH_SHA384:
return EVP_sha384();
case MA_HASH_SHA512:
return EVP_sha512();
case MA_HASH_RIPEMD160:
return EVP_ripemd160();
default:
return NULL;
}
}
MA_HASH_CTX *ma_hash_new(unsigned int algorithm, MA_HASH_CTX *unused __attribute__((unused)))
{
EVP_MD_CTX *ctx= NULL;
const EVP_MD *evp_md= ma_hash_get_algorithm(algorithm);
/* unknown or unsupported hash algorithm */
if (!evp_md)
return NULL;
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
if (!(ctx= EVP_MD_CTX_new()))
#else
if (!(ctx= EVP_MD_CTX_create()))
#endif
return NULL;
if (!EVP_DigestInit(ctx, evp_md))
{
ma_hash_free(ctx);
return NULL;
}
return ctx;
}
void ma_hash_free(MA_HASH_CTX *ctx)
{
if (ctx)
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
EVP_MD_CTX_free(ctx);
#else
EVP_MD_CTX_destroy(ctx);
#endif
}
void ma_hash_input(MA_HASH_CTX *ctx,
const unsigned char *buffer,
size_t len)
{
EVP_DigestUpdate(ctx, buffer, len);
}
void ma_hash_result(MA_HASH_CTX *ctx, unsigned char *digest)
{
EVP_DigestFinal_ex(ctx, digest, NULL);
}

562
vendor/MDBC/libmariadb/secure/schannel.c vendored Normal file
View File

@ -0,0 +1,562 @@
/************************************************************************************
Copyright (C) 2014 MariaDB Corporation 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 <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
*************************************************************************************/
#include "ma_schannel.h"
#include "schannel_certs.h"
#include <string.h>
extern my_bool ma_tls_initialized;
char tls_library_version[] = "Schannel";
#define PROT_SSL3 1
#define PROT_TLS1_0 2
#define PROT_TLS1_2 4
#define PROT_TLS1_3 8
static struct
{
DWORD cipher_id;
DWORD protocol;
const char *iana_name;
const char *openssl_name;
ALG_ID algs[4]; /* exchange, encryption, hash, signature */
}
cipher_map[] =
{
{
0x0002,
PROT_TLS1_0 | PROT_TLS1_2 | PROT_SSL3,
"TLS_RSA_WITH_NULL_SHA", "NULL-SHA",
{ CALG_RSA_KEYX, 0, CALG_SHA1, CALG_RSA_SIGN }
},
{
0x0004,
PROT_TLS1_0 | PROT_TLS1_2 | PROT_SSL3,
"TLS_RSA_WITH_RC4_128_MD5", "RC4-MD5",
{ CALG_RSA_KEYX, CALG_RC4, CALG_MD5, CALG_RSA_SIGN }
},
{
0x0005,
PROT_TLS1_0 | PROT_TLS1_2 | PROT_SSL3,
"TLS_RSA_WITH_RC4_128_SHA", "RC4-SHA",
{ CALG_RSA_KEYX, CALG_RC4, CALG_SHA1, CALG_RSA_SIGN }
},
{
0x000A,
PROT_SSL3,
"TLS_RSA_WITH_3DES_EDE_CBC_SHA", "DES-CBC3-SHA",
{CALG_RSA_KEYX, CALG_3DES, CALG_SHA1, CALG_DSS_SIGN}
},
{
0x0013,
PROT_TLS1_0 | PROT_TLS1_2 | PROT_SSL3,
"TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA", "EDH-DSS-DES-CBC3-SHA",
{ CALG_DH_EPHEM, CALG_3DES, CALG_SHA1, CALG_DSS_SIGN }
},
{
0x002F,
PROT_SSL3 | PROT_TLS1_0 | PROT_TLS1_2,
"TLS_RSA_WITH_AES_128_CBC_SHA", "AES128-SHA",
{ CALG_RSA_KEYX, CALG_AES_128, CALG_SHA, CALG_RSA_SIGN}
},
{
0x0032,
PROT_TLS1_0 | PROT_TLS1_2,
"TLS_DHE_DSS_WITH_AES_128_CBC_SHA", "DHE-DSS-AES128-SHA",
{ CALG_DH_EPHEM, CALG_AES_128, CALG_SHA1, CALG_RSA_SIGN }
},
{
0x0033,
PROT_TLS1_0 | PROT_TLS1_2,
"TLS_DHE_RSA_WITH_AES_128_CBC_SHA", "DHE-RSA-AES128-SHA",
{ CALG_DH_EPHEM, CALG_AES_128, CALG_SHA1, CALG_RSA_SIGN }
},
{
0x0035,
PROT_TLS1_0 | PROT_TLS1_2,
"TLS_RSA_WITH_AES_256_CBC_SHA", "AES256-SHA",
{ CALG_RSA_KEYX, CALG_AES_256, CALG_SHA1, CALG_RSA_SIGN }
},
{
0x0038,
PROT_TLS1_0 | PROT_TLS1_2,
"TLS_DHE_DSS_WITH_AES_256_CBC_SHA", "DHE-DSS-AES256-SHA",
{ CALG_DH_EPHEM, CALG_AES_256, CALG_SHA1, CALG_DSS_SIGN }
},
{
0x0039,
PROT_TLS1_0 | PROT_TLS1_2,
"TLS_DHE_RSA_WITH_AES_256_CBC_SHA", "DHE-RSA-AES256-SHA",
{ CALG_DH_EPHEM, CALG_AES_256, CALG_SHA1, CALG_RSA_SIGN }
},
{
0x003B,
PROT_TLS1_2,
"TLS_RSA_WITH_NULL_SHA256", "NULL-SHA256",
{ CALG_RSA_KEYX, 0, CALG_SHA_256, CALG_RSA_SIGN }
},
{
0x003C,
PROT_TLS1_2,
"TLS_RSA_WITH_AES_128_CBC_SHA256", "AES128-SHA256",
{ CALG_RSA_KEYX, CALG_AES_128, CALG_SHA_256, CALG_RSA_SIGN }
},
{
0x003D,
PROT_TLS1_2,
"TLS_RSA_WITH_AES_256_CBC_SHA256", "AES256-SHA256",
{ CALG_RSA_KEYX, CALG_AES_256, CALG_SHA_256, CALG_RSA_SIGN }
},
{
0x0040,
PROT_TLS1_2,
"TLS_DHE_DSS_WITH_AES_128_CBC_SHA256", "DHE-DSS-AES128-SHA256",
{ CALG_DH_EPHEM, CALG_AES_128, CALG_SHA_256, CALG_DSS_SIGN }
},
{
0x009C,
PROT_TLS1_2,
"TLS_RSA_WITH_AES_128_GCM_SHA256", "AES128-GCM-SHA256",
{ CALG_RSA_KEYX, CALG_AES_128, CALG_SHA_256, CALG_RSA_SIGN }
},
{
0x009D,
PROT_TLS1_2,
"TLS_RSA_WITH_AES_256_GCM_SHA384", "AES256-GCM-SHA384",
{ CALG_RSA_KEYX, CALG_AES_256, CALG_SHA_384, CALG_RSA_SIGN }
},
{
0x009E,
PROT_TLS1_2,
"TLS_DHE_RSA_WITH_AES_128_GCM_SHA256", "DHE-RSA-AES128-GCM-SHA256",
{ CALG_DH_EPHEM, CALG_AES_128, CALG_SHA_256, CALG_RSA_SIGN }
},
{
0x009F,
PROT_TLS1_2,
"TLS_DHE_RSA_WITH_AES_256_GCM_SHA384", "DHE-RSA-AES256-GCM-SHA384",
{ CALG_DH_EPHEM, CALG_AES_256, CALG_SHA_384, CALG_RSA_SIGN }
},
{
0xC027,
PROT_TLS1_2,
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", "ECDHE-RSA-AES128-SHA256",
{ CALG_ECDH, CALG_AES_128, CALG_SHA_256, CALG_RSA_SIGN }
},
{
0xC028,
PROT_TLS1_2,
"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384", "ECDHE-RSA-AES256-SHA384",
{ CALG_ECDH, CALG_AES_256, CALG_SHA_384, CALG_RSA_SIGN }
}
};
#define MAX_ALG_ID 50
extern void ma_schannel_set_sec_error(MARIADB_PVIO *pvio, DWORD ErrorNo);
/*
Initializes SSL and allocate global
context SSL_context
SYNOPSIS
ma_tls_start
RETURN VALUES
0 success
1 error
*/
int ma_tls_start(char *errmsg, size_t errmsg_len)
{
ma_tls_initialized = TRUE;
return 0;
}
/*
Release SSL and free resources
Will be automatically executed by
mysql_server_end() function
SYNOPSIS
ma_tls_end()
void
RETURN VALUES
void
*/
void ma_tls_end()
{
return;
}
/* {{{ static int ma_tls_set_client_certs(MARIADB_TLS *ctls) */
static int ma_tls_set_client_certs(MARIADB_TLS *ctls,const CERT_CONTEXT **cert_ctx)
{
MYSQL *mysql= ctls->pvio->mysql;
char *certfile= mysql->options.ssl_cert,
*keyfile= mysql->options.ssl_key;
MARIADB_PVIO *pvio= ctls->pvio;
char errmsg[256];
if (!certfile && keyfile)
certfile= keyfile;
if (!keyfile && certfile)
keyfile= certfile;
if (!certfile)
return 0;
*cert_ctx = schannel_create_cert_context(certfile, keyfile, errmsg, sizeof(errmsg));
if (!*cert_ctx)
{
pvio->set_error(pvio->mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, "SSL connection error: %s", errmsg);
return 1;
}
return 0;
}
/* }}} */
/* {{{ void *ma_tls_init(MARIADB_TLS *ctls, MYSQL *mysql) */
void *ma_tls_init(MYSQL *mysql)
{
SC_CTX *sctx = (SC_CTX *)LocalAlloc(LMEM_ZEROINIT, sizeof(SC_CTX));
if (sctx)
{
SecInvalidateHandle(&sctx->CredHdl);
SecInvalidateHandle(&sctx->hCtxt);
}
return sctx;
}
/* }}} */
/*
Maps between openssl suite names and schannel alg_ids.
Every suite has 4 algorithms (for exchange, encryption, hash and signing).
The input string is a set of suite names (openssl), separated
by ':'
The output is written into the array 'arr' of size 'arr_size'
The function returns number of elements written to the 'arr'.
*/
static struct _tls_version {
const char *tls_version;
DWORD protocol;
} tls_version[]= {
{"TLSv1.0", PROT_TLS1_0},
{"TLSv1.2", PROT_TLS1_2},
{"TLSv1.3", PROT_TLS1_3},
{"SSLv3", PROT_SSL3}
};
/* The following list was produced with OpenSSL 1.1.1j
by executing `openssl ciphers -V`. */
static struct {
DWORD dwCipherSuite;
const char *openssl_name;
} openssl_ciphers[] = {
{0x002F, "AES128-SHA"},
{0x0033, "DHE-RSA-AES128-SHA"},
{0x0035, "AES256-SHA"},
{0x0039, "DHE-RSA-AES256-SHA"},
{0x003C, "AES128-SHA256"},
{0x003D, "AES256-SHA256"},
{0x0067, "DHE-RSA-AES128-SHA256"},
{0x006B, "DHE-RSA-AES256-SHA256"},
{0x008C, "PSK-AES128-CBC-SHA"},
{0x008D, "PSK-AES256-CBC-SHA"},
{0x0090, "DHE-PSK-AES128-CBC-SHA"},
{0x0091, "DHE-PSK-AES256-CBC-SHA"},
{0x0094, "RSA-PSK-AES128-CBC-SHA"},
{0x0095, "RSA-PSK-AES256-CBC-SHA"},
{0x009C, "AES128-GCM-SHA256"},
{0x009D, "AES256-GCM-SHA384"},
{0x009E, "DHE-RSA-AES128-GCM-SHA256"},
{0x009F, "DHE-RSA-AES256-GCM-SHA384"},
{0x00A8, "PSK-AES128-GCM-SHA256"},
{0x00A9, "PSK-AES256-GCM-SHA384"},
{0x00AA, "DHE-PSK-AES128-GCM-SHA256"},
{0x00AB, "DHE-PSK-AES256-GCM-SHA384"},
{0x00AC, "RSA-PSK-AES128-GCM-SHA256"},
{0x00AD, "RSA-PSK-AES256-GCM-SHA384"},
{0x00AE, "PSK-AES128-CBC-SHA256"},
{0x00AF, "PSK-AES256-CBC-SHA384"},
{0x00B2, "DHE-PSK-AES128-CBC-SHA256"},
{0x00B3, "DHE-PSK-AES256-CBC-SHA384"},
{0x00B6, "RSA-PSK-AES128-CBC-SHA256"},
{0x00B7, "RSA-PSK-AES256-CBC-SHA384"},
{0x1301, "TLS_AES_128_GCM_SHA256"},
{0x1302, "TLS_AES_256_GCM_SHA384"},
{0x1303, "TLS_CHACHA20_POLY1305_SHA256"},
{0xC009, "ECDHE-ECDSA-AES128-SHA"},
{0xC00A, "ECDHE-ECDSA-AES256-SHA"},
{0xC013, "ECDHE-RSA-AES128-SHA"},
{0xC014, "ECDHE-RSA-AES256-SHA"},
{0xC01D, "SRP-AES-128-CBC-SHA"},
{0xC01E, "SRP-RSA-AES-128-CBC-SHA"},
{0xC020, "SRP-AES-256-CBC-SHA"},
{0xC021, "SRP-RSA-AES-256-CBC-SHA"},
{0xC023, "ECDHE-ECDSA-AES128-SHA256"},
{0xC024, "ECDHE-ECDSA-AES256-SHA384"},
{0xC027, "ECDHE-RSA-AES128-SHA256"},
{0xC028, "ECDHE-RSA-AES256-SHA384"},
{0xC02B, "ECDHE-ECDSA-AES128-GCM-SHA256"},
{0xC02C, "ECDHE-ECDSA-AES256-GCM-SHA384"},
{0xC02F, "ECDHE-RSA-AES128-GCM-SHA256"},
{0xC030, "ECDHE-RSA-AES256-GCM-SHA384"},
{0xC035, "ECDHE-PSK-AES128-CBC-SHA"},
{0xC036, "ECDHE-PSK-AES256-CBC-SHA"},
{0xC037, "ECDHE-PSK-AES128-CBC-SHA256"},
{0xC038, "ECDHE-PSK-AES256-CBC-SHA384"},
{0xCCA8, "ECDHE-RSA-CHACHA20-POLY1305"},
{0xCCA9, "ECDHE-ECDSA-CHACHA20-POLY1305"},
{0xCCAA, "DHE-RSA-CHACHA20-POLY1305"},
{0xCCAB, "PSK-CHACHA20-POLY1305"},
{0xCCAC, "ECDHE-PSK-CHACHA20-POLY1305"},
{0xCCAD, "DHE-PSK-CHACHA20-POLY1305"},
{0xCCAE, "RSA-PSK-CHACHA20-POLY1305"}
};
static size_t set_cipher(char * cipher_str, DWORD protocol, ALG_ID *arr , size_t arr_size)
{
char *token = strtok(cipher_str, ":");
size_t pos = 0;
while (token)
{
size_t i;
for(i = 0; i < sizeof(cipher_map)/sizeof(cipher_map[0]) ; i++)
{
if((pos + 4 < arr_size && strcmp(cipher_map[i].openssl_name, token) == 0) ||
(cipher_map[i].protocol <= protocol))
{
memcpy(arr + pos, cipher_map[i].algs, sizeof(ALG_ID)* 4);
pos += 4;
break;
}
}
token = strtok(NULL, ":");
}
return pos;
}
my_bool ma_tls_connect(MARIADB_TLS *ctls)
{
MYSQL *mysql;
SCHANNEL_CRED Cred = {0};
MARIADB_PVIO *pvio;
my_bool rc= 1;
SC_CTX *sctx;
SECURITY_STATUS sRet;
ALG_ID AlgId[MAX_ALG_ID];
size_t i;
DWORD protocol = 0;
int verify_certs;
const CERT_CONTEXT* cert_context = NULL;
if (!ctls)
return 1;
pvio= ctls->pvio;
sctx= (SC_CTX *)ctls->ssl;
if (!pvio || !sctx)
return 1;
mysql= pvio->mysql;
if (!mysql)
return 1;
/* Set cipher */
if (mysql->options.ssl_cipher)
{
/* check if a protocol was specified as a cipher:
* In this case don't allow cipher suites which belong to newer protocols
* Please note: There are no cipher suites for TLS1.1
*/
for (i = 0; i < sizeof(tls_version) / sizeof(tls_version[0]); i++)
{
if (!_stricmp(mysql->options.ssl_cipher, tls_version[i].tls_version))
protocol |= tls_version[i].protocol;
}
memset(AlgId, 0, sizeof(AlgId));
Cred.cSupportedAlgs = (DWORD)set_cipher(mysql->options.ssl_cipher, protocol, AlgId, MAX_ALG_ID);
if (Cred.cSupportedAlgs)
{
Cred.palgSupportedAlgs = AlgId;
}
else if (!protocol)
{
ma_schannel_set_sec_error(pvio, SEC_E_ALGORITHM_MISMATCH);
goto end;
}
}
Cred.dwVersion= SCHANNEL_CRED_VERSION;
Cred.dwFlags = SCH_CRED_NO_SERVERNAME_CHECK | SCH_CRED_NO_DEFAULT_CREDS | SCH_CRED_MANUAL_CRED_VALIDATION;
if (mysql->options.extension && mysql->options.extension->tls_version)
{
if (strstr(mysql->options.extension->tls_version, "TLSv1.0"))
Cred.grbitEnabledProtocols|= SP_PROT_TLS1_0_CLIENT;
if (strstr(mysql->options.extension->tls_version, "TLSv1.1"))
Cred.grbitEnabledProtocols|= SP_PROT_TLS1_1_CLIENT;
if (strstr(mysql->options.extension->tls_version, "TLSv1.2"))
Cred.grbitEnabledProtocols|= SP_PROT_TLS1_2_CLIENT;
}
if (!Cred.grbitEnabledProtocols)
Cred.grbitEnabledProtocols = SP_PROT_TLS1_0_CLIENT | SP_PROT_TLS1_1_CLIENT | SP_PROT_TLS1_2_CLIENT;
if (ma_tls_set_client_certs(ctls, &cert_context))
goto end;
if (cert_context)
{
Cred.cCreds = 1;
Cred.paCred = &cert_context;
}
sRet= AcquireCredentialsHandleA(NULL, UNISP_NAME_A, SECPKG_CRED_OUTBOUND,
NULL, &Cred, NULL, NULL, &sctx->CredHdl, NULL);
if (sRet)
{
ma_schannel_set_sec_error(pvio, sRet);
goto end;
}
if (ma_schannel_client_handshake(ctls) != SEC_E_OK)
goto end;
verify_certs = mysql->options.ssl_ca || mysql->options.ssl_capath ||
(mysql->client_flag & CLIENT_SSL_VERIFY_SERVER_CERT);
if (verify_certs)
{
if (!ma_schannel_verify_certs(ctls, (mysql->client_flag & CLIENT_SSL_VERIFY_SERVER_CERT)))
goto end;
}
rc = 0;
end:
if (cert_context)
schannel_free_cert_context(cert_context);
return rc;
}
ssize_t ma_tls_read(MARIADB_TLS *ctls, const uchar* buffer, size_t length)
{
SC_CTX *sctx= (SC_CTX *)ctls->ssl;
MARIADB_PVIO *pvio= ctls->pvio;
DWORD dlength= 0;
SECURITY_STATUS status = ma_schannel_read_decrypt(pvio, &sctx->hCtxt, &dlength, (uchar *)buffer, (DWORD)length);
if (status == SEC_I_CONTEXT_EXPIRED)
return 0; /* other side shut down the connection. */
if (status == SEC_I_RENEGOTIATE)
return -1; /* Do not handle renegotiate yet */
return (status == SEC_E_OK)? (ssize_t)dlength : -1;
}
ssize_t ma_tls_write(MARIADB_TLS *ctls, const uchar* buffer, size_t length)
{
MARIADB_PVIO *pvio= ctls->pvio;
ssize_t rc, wlength= 0;
ssize_t remain= length;
while (remain > 0)
{
if ((rc= ma_schannel_write_encrypt(pvio, (uchar *)buffer + wlength, remain)) <= 0)
return rc;
wlength+= rc;
remain-= rc;
}
return length;
}
/* {{{ my_bool ma_tls_close(MARIADB_PVIO *pvio) */
my_bool ma_tls_close(MARIADB_TLS *ctls)
{
SC_CTX *sctx= (SC_CTX *)ctls->ssl;
if (sctx)
{
LocalFree(sctx->IoBuffer);
if (SecIsValidHandle(&sctx->CredHdl))
FreeCredentialHandle(&sctx->CredHdl);
if (SecIsValidHandle(&sctx->hCtxt))
DeleteSecurityContext(&sctx->hCtxt);
}
LocalFree(sctx);
return 0;
}
/* }}} */
int ma_tls_verify_server_cert(MARIADB_TLS *ctls)
{
/* Done elsewhere */
return 0;
}
static const char *cipher_name(const SecPkgContext_CipherInfo *CipherInfo)
{
size_t i;
for(i = 0; i < sizeof(openssl_ciphers)/sizeof(openssl_ciphers[0]) ; i++)
{
if (CipherInfo->dwCipherSuite == openssl_ciphers[i].dwCipherSuite)
return openssl_ciphers[i].openssl_name;
}
return "";
};
const char *ma_tls_get_cipher(MARIADB_TLS *ctls)
{
SecPkgContext_CipherInfo CipherInfo = { SECPKGCONTEXT_CIPHERINFO_V1 };
SECURITY_STATUS sRet;
SC_CTX *sctx;
if (!ctls || !ctls->ssl)
return NULL;
sctx= (SC_CTX *)ctls->ssl;
sRet= QueryContextAttributesA(&sctx->hCtxt, SECPKG_ATTR_CIPHER_INFO, (PVOID)&CipherInfo);
if (sRet != SEC_E_OK)
return NULL;
return cipher_name(&CipherInfo);
}
unsigned int ma_tls_get_finger_print(MARIADB_TLS *ctls, char *fp, unsigned int len)
{
SC_CTX *sctx= (SC_CTX *)ctls->ssl;
PCCERT_CONTEXT pRemoteCertContext = NULL;
if (QueryContextAttributes(&sctx->hCtxt, SECPKG_ATTR_REMOTE_CERT_CONTEXT, (PVOID)&pRemoteCertContext) != SEC_E_OK)
return 0;
CertGetCertificateContextProperty(pRemoteCertContext, CERT_HASH_PROP_ID, fp, (DWORD *)&len);
CertFreeCertificateContext(pRemoteCertContext);
return len;
}

View File

@ -0,0 +1,854 @@
/************************************************************************************
Copyright (C) 2019 MariaDB
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 <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
*************************************************************************************/
/*
This module contain X509 certificate handling on Windows.
PEM parsing, loading client certificate and key, server certificate validation
*/
/*
CERT_CHAIN_ENGINE_CONFIG has additional members in Windows 8.1
To allow client to be work on pre-8.1 Windows, compile
with corresponding _WIN32_WINNT
*/
#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0601
#endif
#include <winsock2.h>
#include "schannel_certs.h"
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include <ws2tcpip.h>
#include <winhttp.h>
#include <assert.h>
#include "win32_errmsg.h"
/*
Return GetLastError(), or, if this unexpectedly gives success,
return ERROR_INTERNAL_ERROR.
Background - in several cases in this module we return GetLastError()
after an Windows function fails. However, we do not want the function to
return success, even if GetLastError() was suddenly 0.
*/
static DWORD get_last_error()
{
DWORD ret = GetLastError();
if (ret)
return ret;
// We generally expect last error to be set API fails.
// thus the debug assertion-
assert(0);
return ERROR_INTERNAL_ERROR;
}
#define FAIL(...) \
do{\
status = get_last_error();\
ma_format_win32_error(errmsg, errmsg_len, status, __VA_ARGS__);\
goto cleanup;\
} while (0)
/*
Load file into memory. Add null terminator at the end, so it will be a valid C string.
*/
static char* pem_file_to_string(const char* file, char* errmsg, size_t errmsg_len)
{
LARGE_INTEGER file_size;
size_t file_bufsize = 0;
size_t total_bytes_read = 0;
char* file_buffer = NULL;
SECURITY_STATUS status = SEC_E_OK;
HANDLE file_handle = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (file_handle == INVALID_HANDLE_VALUE)
{
FAIL("failed to open file '%s'", file);
}
if (!GetFileSizeEx(file_handle, &file_size))
{
FAIL("GetFileSizeEx failed on '%s'", file);
}
if (file_size.QuadPart > ULONG_MAX - 1)
{
SetLastError(SEC_E_INVALID_PARAMETER);
FAIL("file '%s' too large", file);
}
file_bufsize = (size_t)file_size.QuadPart;
file_buffer = (char*)LocalAlloc(0,file_bufsize + 1);
if (!file_buffer)
{
FAIL("LocalAlloc(0,%zu) failed", file_bufsize + 1);
}
while (total_bytes_read < file_bufsize)
{
DWORD bytes_to_read = (DWORD)(file_bufsize - total_bytes_read);
DWORD bytes_read = 0;
if (!ReadFile(file_handle, file_buffer + total_bytes_read,
bytes_to_read, &bytes_read, NULL))
{
FAIL("ReadFile() failed to read file '%s'", file);
}
if (bytes_read == 0)
{
/* Premature EOF -- adjust the bufsize to the new value */
file_bufsize = total_bytes_read;
}
else
{
total_bytes_read += bytes_read;
}
}
/* Null terminate the buffer */
file_buffer[file_bufsize] = '\0';
cleanup:
if (file_handle != INVALID_HANDLE_VALUE)
{
CloseHandle(file_handle);
}
if (status)
{
/* Some error happened. */
LocalFree(file_buffer);
file_buffer = NULL;
}
return file_buffer;
}
// Structure for parsing BEGIN/END sections inside pem.
typedef struct _pem_type_desc
{
const char* begin_tag;
size_t begin_tag_len;
const char* end_tag;
size_t end_tag_len;
} pem_type_desc;
#define BEGIN_TAG(x) "-----BEGIN " x "-----"
#define END_TAG(x) "\n-----END " x "-----"
#define PEM_SECTION(tag) {BEGIN_TAG(tag), sizeof(BEGIN_TAG(tag))-1, END_TAG(tag), sizeof(END_TAG(tag))-1}
typedef enum {
PEM_TYPE_CERTIFICATE = 0,
PEM_TYPE_X509_CRL,
PEM_TYPE_RSA_PRIVATE_KEY,
PEM_TYPE_PRIVATE_KEY
} PEM_TYPE;
static const pem_type_desc pem_sections[] = {
PEM_SECTION("CERTIFICATE"),
PEM_SECTION("X509 CRL"),
PEM_SECTION("RSA PRIVATE KEY"),
PEM_SECTION("PRIVATE KEY")
};
/*
Locate a substring in pem for given type,
e.g section between BEGIN CERTIFICATE and END CERTIFICATE
in PEMs base64 format, with header and footer.
output parameters 'begin' and 'end' are set upon return.
it is possible that functions returns 'begin' != NULL but
'end' = NULL. This is generally a format error, meaning that
the end tag was not found
*/
void pem_locate(char* pem_str,
PEM_TYPE type,
char** begin,
char** end)
{
*begin = NULL;
*end = NULL;
char c;
const pem_type_desc* desc = &pem_sections[type];
*begin = strstr(pem_str, desc->begin_tag);
if (!(*begin))
return;
// We expect newline after the
// begin tag, LF or CRLF
c = (*begin)[desc->begin_tag_len];
if (c != '\r' && c != '\n')
{
*begin = NULL;
return;
}
*end = strstr(*begin + desc->begin_tag_len + 1, desc->end_tag);
if (!*end)
return; // error, end marker not found
(*end) += desc->end_tag_len;
return;
}
/*
Add certificates, or CRLs from a PEM file to Wincrypt store
*/
static SECURITY_STATUS add_certs_to_store(
HCERTSTORE trust_store,
const char* file,
PEM_TYPE type,
char* errmsg,
size_t errmsg_len)
{
char* file_buffer = NULL;
char* cur = NULL;
SECURITY_STATUS status = SEC_E_OK;
CRL_CONTEXT* crl_context = NULL;
CERT_CONTEXT* cert_context = NULL;
char* begin;
char* end;
file_buffer = pem_file_to_string(file, errmsg, errmsg_len);
if (!file_buffer)
goto cleanup;
for (cur = file_buffer; ; cur = end)
{
pem_locate(cur, type, &begin, &end);
if (!begin)
break;
if (!end)
{
SetLastError(SEC_E_INVALID_PARAMETER);
FAIL("Invalid PEM file '%s', missing end marker corresponding to begin marker '%s' at offset %zu",
file, pem_sections[type].begin_tag, (size_t)(begin - file_buffer));
}
CERT_BLOB cert_blob;
void* context = NULL;
DWORD actual_content_type = 0;
cert_blob.pbData = (BYTE*)begin;
cert_blob.cbData = (DWORD)(end - begin);
if (!CryptQueryObject(
CERT_QUERY_OBJECT_BLOB, &cert_blob,
CERT_QUERY_CONTENT_FLAG_CERT | CERT_QUERY_CONTENT_FLAG_CRL,
CERT_QUERY_FORMAT_FLAG_ALL, 0, NULL, &actual_content_type,
NULL, NULL, NULL, (const void**)&context))
{
FAIL("failed to extract certificate from PEM file '%s'",file);
}
if (!context)
{
SetLastError(SEC_E_INTERNAL_ERROR);
FAIL("unexpected result from CryptQueryObject(),cert_context is NULL"
" after successful completion, file '%s'",
file);
}
if (actual_content_type == CERT_QUERY_CONTENT_CERT)
{
CERT_CONTEXT* cert_context = (CERT_CONTEXT*)context;
if (!CertAddCertificateContextToStore(
trust_store, cert_context,
CERT_STORE_ADD_ALWAYS, NULL))
{
FAIL("CertAddCertificateContextToStore failed");
}
}
else if (actual_content_type == CERT_QUERY_CONTENT_CRL)
{
CRL_CONTEXT* crl_context = (CRL_CONTEXT*)context;
if (!CertAddCRLContextToStore(
trust_store, crl_context,
CERT_STORE_ADD_ALWAYS, NULL))
{
FAIL("CertAddCRLContextToStore() failed");
}
}
}
cleanup:
LocalFree(file_buffer);
if (cert_context)
CertFreeCertificateContext(cert_context);
if (crl_context)
CertFreeCRLContext(crl_context);
return status;
}
/*
Add a directory to store, i.e try to load all files.
(extract certificates and add them to store)
@return 0 on success, error only if directory is invalid.
*/
SECURITY_STATUS add_dir_to_store(HCERTSTORE trust_store, const char* dir,
PEM_TYPE type, char* errmsg, size_t errmsg_len)
{
WIN32_FIND_DATAA ffd;
char path[MAX_PATH];
char pattern[MAX_PATH];
DWORD dwAttr;
HANDLE hFind = INVALID_HANDLE_VALUE;
SECURITY_STATUS status = SEC_E_OK;
if ((dwAttr = GetFileAttributes(dir)) == INVALID_FILE_ATTRIBUTES)
{
SetLastError(SEC_E_INVALID_PARAMETER);
FAIL("directory '%s' does not exist", dir);
}
if (!(dwAttr & FILE_ATTRIBUTE_DIRECTORY))
{
SetLastError(SEC_E_INVALID_PARAMETER);
FAIL("'%s' is not a directory", dir);
}
sprintf_s(pattern, sizeof(pattern), "%s\\*", dir);
hFind = FindFirstFile(pattern, &ffd);
if (hFind == INVALID_HANDLE_VALUE)
{
FAIL("FindFirstFile(%s) failed",pattern);
}
do
{
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
continue;
sprintf_s(path, sizeof(path), "%s\\%s", dir, ffd.cFileName);
// ignore error from add_certs_to_store(), not all file
// maybe PEM.
add_certs_to_store(trust_store, path, type, errmsg,
errmsg_len);
} while (FindNextFile(hFind, &ffd) != 0);
cleanup:
if (hFind != INVALID_HANDLE_VALUE)
FindClose(hFind);
return status;
}
/* Count certificates in store. */
static int count_certificates(HCERTSTORE store)
{
int num_certs = 0;
PCCERT_CONTEXT c = NULL;
while ((c = CertEnumCertificatesInStore(store, c)))
num_certs++;
return num_certs;
}
/**
Creates certificate store with user defined CA chain and/or CRL.
Loads PEM certificate from files or directories.
If only CRLFile/CRLPath is defined, the "system" store is duplicated,
and new CRLs are added to it.
If CAFile/CAPAth is defined, then new empty store is created, and CAs
(and CRLs, if defined), are added to it.
The function throws an error, if none of the files in CAFile/CAPath have a valid certificate.
It is also an error if CRLFile does not exist.
*/
SECURITY_STATUS schannel_create_store(
const char* CAFile,
const char* CAPath,
const char* CRLFile,
const char* CRLPath,
HCERTSTORE* out_store,
char* errmsg,
size_t errmsg_len)
{
HCERTSTORE store = NULL;
HCERTSTORE system_store = NULL;
int status = SEC_E_OK;
*out_store = NULL;
if (!CAFile && !CAPath && !CRLFile && !CRLPath)
{
/* Nothing to do, caller will use default store*/
*out_store = NULL;
return SEC_E_OK;
}
if (CAFile || CAPath)
{
/* Open the certificate store */
store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, (HCRYPTPROV)NULL,
CERT_STORE_CREATE_NEW_FLAG, NULL);
if (!store)
{
FAIL("CertOpenStore failed for memory store");
}
}
else if (CRLFile || CRLPath)
{
/* Only CRL was provided, copy system store, add revocation list to
* it. */
system_store =
CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, (HCRYPTPROV_LEGACY)NULL,
CERT_SYSTEM_STORE_CURRENT_USER, L"MY");
if (!system_store)
{
FAIL("CertOpenStore failed for system store");
}
store = CertDuplicateStore(system_store);
if (!store)
{
FAIL("CertDuplicateStore failed");
}
}
if (CAFile)
{
status = add_certs_to_store(store, CAFile,
PEM_TYPE_CERTIFICATE, errmsg, errmsg_len);
if (status)
goto cleanup;
}
if (CAPath)
{
status = add_dir_to_store(store, CAPath,
PEM_TYPE_CERTIFICATE, errmsg, errmsg_len);
if (status)
goto cleanup;
}
if ((CAFile || CAPath) && store && !count_certificates(store))
{
SetLastError(SEC_E_INVALID_PARAMETER);
FAIL("no valid certificates were found, CAFile='%s', CAPath='%s'",
CAFile ? CAFile : "<not set>", CAPath ? CAPath : "<not set>");
}
if (CRLFile)
{
status = add_certs_to_store(store, CRLFile, PEM_TYPE_X509_CRL,
errmsg, errmsg_len);
}
if (CRLPath)
{
status = add_dir_to_store(store, CRLPath, PEM_TYPE_X509_CRL,
errmsg, errmsg_len);
}
cleanup:
if (system_store)
CertCloseStore(system_store, 0);
if (status && store)
{
CertCloseStore(store, 0);
store = NULL;
}
*out_store = store;
return status;
}
/*
The main verification logic.
Taken almost completely from Windows 2003 Platform SDK 2003
(Samples\Security\SSPI\SSL\WebClient.c)
The only difference here is is usage of custom store
and chain engine.
*/
static SECURITY_STATUS VerifyServerCertificate(
PCCERT_CONTEXT pServerCert,
HCERTSTORE hStore,
LPWSTR pwszServerName,
DWORD dwRevocationCheckFlags,
DWORD dwVerifyFlags,
LPSTR errmsg,
size_t errmsg_len)
{
SSL_EXTRA_CERT_CHAIN_POLICY_PARA polExtra;
CERT_CHAIN_POLICY_PARA PolicyPara;
CERT_CHAIN_POLICY_STATUS PolicyStatus;
CERT_CHAIN_PARA ChainPara;
HCERTCHAINENGINE hChainEngine = NULL;
PCCERT_CHAIN_CONTEXT pChainContext = NULL;
LPSTR rgszUsages[] = { szOID_PKIX_KP_SERVER_AUTH,
szOID_SERVER_GATED_CRYPTO,
szOID_SGC_NETSCAPE };
DWORD cUsages = sizeof(rgszUsages) / sizeof(LPSTR);
SECURITY_STATUS status = SEC_E_OK;
if (pServerCert == NULL)
{
SetLastError(SEC_E_WRONG_PRINCIPAL);
FAIL("Invalid parameter pServerCert passed to VerifyServerCertificate");
}
ZeroMemory(&ChainPara, sizeof(ChainPara));
ChainPara.cbSize = sizeof(ChainPara);
ChainPara.RequestedUsage.dwType = USAGE_MATCH_TYPE_OR;
ChainPara.RequestedUsage.Usage.cUsageIdentifier = cUsages;
ChainPara.RequestedUsage.Usage.rgpszUsageIdentifier = rgszUsages;
if (hStore)
{
CERT_CHAIN_ENGINE_CONFIG EngineConfig = { 0 };
EngineConfig.cbSize = sizeof(EngineConfig);
EngineConfig.hExclusiveRoot = hStore;
if (!CertCreateCertificateChainEngine(&EngineConfig, &hChainEngine))
{
FAIL("CertCreateCertificateChainEngine failed");
}
}
if (!CertGetCertificateChain(
hChainEngine,
pServerCert,
NULL,
pServerCert->hCertStore,
&ChainPara,
dwRevocationCheckFlags,
NULL,
&pChainContext))
{
FAIL("CertGetCertificateChain failed");
goto cleanup;
}
// Validate certificate chain.
ZeroMemory(&polExtra, sizeof(SSL_EXTRA_CERT_CHAIN_POLICY_PARA));
polExtra.cbStruct = sizeof(SSL_EXTRA_CERT_CHAIN_POLICY_PARA);
polExtra.dwAuthType = AUTHTYPE_SERVER;
polExtra.fdwChecks = dwVerifyFlags;
polExtra.pwszServerName = pwszServerName;
memset(&PolicyPara, 0, sizeof(PolicyPara));
PolicyPara.cbSize = sizeof(PolicyPara);
PolicyPara.pvExtraPolicyPara = &polExtra;
memset(&PolicyStatus, 0, sizeof(PolicyStatus));
PolicyStatus.cbSize = sizeof(PolicyStatus);
if (!CertVerifyCertificateChainPolicy(
CERT_CHAIN_POLICY_SSL,
pChainContext,
&PolicyPara,
&PolicyStatus))
{
FAIL("CertVerifyCertificateChainPolicy failed");
}
if (PolicyStatus.dwError)
{
SetLastError(PolicyStatus.dwError);
FAIL("Server certificate validation failed");
}
cleanup:
if (hChainEngine)
{
CertFreeCertificateChainEngine(hChainEngine);
}
if (pChainContext)
{
CertFreeCertificateChain(pChainContext);
}
return status;
}
void schannel_free_store(HCERTSTORE store)
{
if (store)
CertCloseStore(store, 0);
}
/*
Verify server certificate against a wincrypt store
@return 0 - success, otherwise error occurred.
*/
SECURITY_STATUS schannel_verify_server_certificate(
const CERT_CONTEXT* cert,
HCERTSTORE store,
BOOL check_revocation,
const char* server_name,
BOOL check_server_name,
char* errmsg,
size_t errmsg_len)
{
SECURITY_STATUS status = SEC_E_OK;
wchar_t* wserver_name = NULL;
DWORD dwVerifyFlags;
DWORD dwRevocationFlags;
if (check_server_name)
{
int cchServerName = (int)strlen(server_name) + 1;
wserver_name = (wchar_t*)LocalAlloc(0,sizeof(wchar_t) * cchServerName);
if (!wserver_name)
{
FAIL("LocalAlloc() failed");
}
if (MultiByteToWideChar(CP_UTF8, 0, server_name, cchServerName, wserver_name, cchServerName) < 0)
{
FAIL("MultiByteToWideChar() failed");
}
}
dwVerifyFlags = 0;
dwRevocationFlags = 0;
if (check_revocation)
dwRevocationFlags |= CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT | CERT_CHAIN_REVOCATION_CHECK_CACHE_ONLY;
if (!check_server_name)
dwVerifyFlags |= SECURITY_FLAG_IGNORE_CERT_CN_INVALID;
status = VerifyServerCertificate(cert, store, wserver_name ? wserver_name : L"SERVER_NAME",
dwRevocationFlags, dwVerifyFlags, errmsg, errmsg_len);
cleanup:
LocalFree(wserver_name);
return status;
}
/* Attach private key (in PEM format) to client certificate */
static SECURITY_STATUS load_private_key(CERT_CONTEXT* cert, char* private_key_str, size_t len, char* errmsg, size_t errmsg_len)
{
DWORD derlen = (DWORD)len;
BYTE* derbuf = NULL;
DWORD keyblob_len = 0;
BYTE* keyblob = NULL;
HCRYPTPROV hProv = 0;
HCRYPTKEY hKey = 0;
CERT_KEY_CONTEXT cert_key_context = { 0 };
PCRYPT_PRIVATE_KEY_INFO pki = NULL;
DWORD pki_len = 0;
SECURITY_STATUS status = SEC_E_OK;
derbuf = LocalAlloc(0, derlen);
if (!derbuf)
{
FAIL("LocalAlloc failed");
}
if (!CryptStringToBinaryA(private_key_str, (DWORD)len, CRYPT_STRING_BASE64HEADER, derbuf, &derlen, NULL, NULL))
{
FAIL("Failed to convert BASE64 private key");
}
/*
To accommodate for both "BEGIN PRIVATE KEY" vs "BEGIN RSA PRIVATE KEY"
sections in PEM, we try to decode with PKCS_PRIVATE_KEY_INFO first,
and, if it fails, with PKCS_RSA_PRIVATE_KEY flag.
*/
if (CryptDecodeObjectEx(
X509_ASN_ENCODING,
PKCS_PRIVATE_KEY_INFO,
derbuf, derlen,
CRYPT_DECODE_ALLOC_FLAG,
NULL, &pki, &pki_len))
{
// convert private key info to RSA private key blob
if (!CryptDecodeObjectEx(
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
PKCS_RSA_PRIVATE_KEY,
pki->PrivateKey.pbData,
pki->PrivateKey.cbData,
CRYPT_DECODE_ALLOC_FLAG,
NULL, &keyblob, &keyblob_len))
{
FAIL("Failed to parse private key");
}
}
else if (!CryptDecodeObjectEx(
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
PKCS_RSA_PRIVATE_KEY,
derbuf, derlen,
CRYPT_DECODE_ALLOC_FLAG, NULL,
&keyblob, &keyblob_len))
{
FAIL("Failed to parse private key");
}
if (!CryptAcquireContext(&hProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
{
FAIL("CryptAcquireContext failed");
}
if (!CryptImportKey(hProv, keyblob, keyblob_len, 0, 0, (HCRYPTKEY*)&hKey))
{
FAIL("CryptImportKey failed");
}
cert_key_context.hCryptProv = hProv;
cert_key_context.dwKeySpec = AT_KEYEXCHANGE;
cert_key_context.cbSize = sizeof(cert_key_context);
/* assign private key to certificate context */
if (!CertSetCertificateContextProperty(cert, CERT_KEY_CONTEXT_PROP_ID,
CERT_STORE_NO_CRYPT_RELEASE_FLAG,
&cert_key_context))
{
FAIL("CertSetCertificateContextProperty failed");
}
cleanup:
LocalFree(derbuf);
LocalFree(keyblob);
LocalFree(pki);
if (hKey)
CryptDestroyKey(hKey);
if (status)
{
if (hProv)
CryptReleaseContext(hProv, 0);
}
return status;
}
/*
Given PEM strings for certificate and private key,
create a client certificate*
*/
static CERT_CONTEXT* create_client_certificate_mem(
char* cert_file_content,
char* key_file_content,
char* errmsg,
size_t errmsg_len)
{
CERT_CONTEXT* ctx = NULL;
char* begin;
char* end;
CERT_BLOB cert_blob;
DWORD actual_content_type = 0;
SECURITY_STATUS status = SEC_E_OK;
/* Parse certificate */
pem_locate(cert_file_content, PEM_TYPE_CERTIFICATE,
&begin, &end);
if (!begin || !end)
{
SetLastError(SEC_E_INVALID_PARAMETER);
FAIL("Client certificate not found in PEM file");
}
cert_blob.pbData = (BYTE*)begin;
cert_blob.cbData = (DWORD)(end - begin);
if (!CryptQueryObject(
CERT_QUERY_OBJECT_BLOB, &cert_blob,
CERT_QUERY_CONTENT_FLAG_CERT,
CERT_QUERY_FORMAT_FLAG_ALL, 0, NULL, &actual_content_type,
NULL, NULL, NULL, (const void**)&ctx))
{
FAIL("Can't parse client certficate");
}
/* Parse key */
PEM_TYPE types[] = { PEM_TYPE_RSA_PRIVATE_KEY, PEM_TYPE_PRIVATE_KEY };
for (int i = 0; i < sizeof(types) / sizeof(types[0]); i++)
{
pem_locate(key_file_content, types[i], &begin, &end);
if (begin && end)
{
/* Assign key to certificate.*/
status = load_private_key(ctx, begin, (end - begin), errmsg, errmsg_len);
goto cleanup;
}
}
if (!begin || !end)
{
SetLastError(SEC_E_INVALID_PARAMETER);
FAIL("Client private key not found in PEM");
}
cleanup:
if (status && ctx)
{
CertFreeCertificateContext(ctx);
ctx = NULL;
}
return ctx;
}
/* Given cert and key, as PEM file names, create a client certificate */
CERT_CONTEXT* schannel_create_cert_context(char* cert_file, char* key_file, char* errmsg, size_t errmsg_len)
{
CERT_CONTEXT* ctx = NULL;
char* key_file_content = NULL;
char* cert_file_content = NULL;
cert_file_content = pem_file_to_string(cert_file, errmsg, errmsg_len);
if (!cert_file_content)
goto cleanup;
if (cert_file == key_file)
{
key_file_content = cert_file_content;
}
else
{
key_file_content = pem_file_to_string(key_file, errmsg, errmsg_len);
if (!key_file_content)
goto cleanup;
}
ctx = create_client_certificate_mem(cert_file_content, key_file_content, errmsg, errmsg_len);
cleanup:
LocalFree(cert_file_content);
if (cert_file != key_file)
LocalFree(key_file_content);
return ctx;
}
/*
Free certificate, and all resources, created by schannel_create_cert_context()
*/
void schannel_free_cert_context(const CERT_CONTEXT* cert)
{
/* release provider handle which was acquires in load_private_key() */
CERT_KEY_CONTEXT cert_key_context = { 0 };
cert_key_context.cbSize = sizeof(cert_key_context);
DWORD cbData = sizeof(CERT_KEY_CONTEXT);
HCRYPTPROV hProv = 0;
if (CertGetCertificateContextProperty(cert, CERT_KEY_CONTEXT_PROP_ID, &cert_key_context, &cbData))
{
hProv = cert_key_context.hCryptProv;
}
CertFreeCertificateContext(cert);
if (hProv)
{
CryptReleaseContext(cert_key_context.hCryptProv, 0);
}
}

View File

@ -0,0 +1,53 @@
/************************************************************************************
Copyright (C) 2019 MariaDB Corporation 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 <http://www.gnu.org/licenses>
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
*************************************************************************************/
#pragma once
#include <windows.h>
#include <wincrypt.h>
extern SECURITY_STATUS schannel_create_store(
const char* CAFile,
const char* CAPath,
const char* CRLFile,
const char* CRLPath,
HCERTSTORE* store,
char* errmsg,
size_t errmsg_len
);
extern SECURITY_STATUS schannel_verify_server_certificate(
const CERT_CONTEXT* cert,
HCERTSTORE store,
BOOL check_revocation,
const char* server_name,
BOOL check_server_name,
char* errmsg,
size_t errmsg_len);
extern void schannel_free_store(HCERTSTORE store);
extern CERT_CONTEXT* schannel_create_cert_context(
char* cert_file,
char* key_file,
char* errmsg,
size_t errmsg_len);
extern void schannel_free_cert_context(const CERT_CONTEXT* cert);

Some files were not shown because too many files have changed in this diff Show More