1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-08 14:02:17 +03:00

Merge branch '10.3-server' into 3.0

This commit is contained in:
Sergei Golubchik
2018-11-07 00:18:48 +01:00
12 changed files with 117 additions and 136 deletions

1
.gitignore vendored
View File

@@ -87,6 +87,7 @@ unittest/libmariadb/t_aurora
unittest/libmariadb/t_conc173
unittest/libmariadb/thread
unittest/libmariadb/view
unittest/libmariadb/conc336
#VS files/directories
*.vcxproj

View File

@@ -151,7 +151,7 @@ ENDIF()
# various defines for generating include/mysql_version.h
INCLUDE(FindGit)
IF(GIT_EXECUTABLE)
IF(GIT_EXECUTABLE AND EXISTS ${CC_SOURCE_DIR}/.git)
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY ${CC_SOURCE_DIR}
@@ -399,7 +399,7 @@ ENDIF()
IF(WIN32 AND WITH_MSI AND CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
ADD_SUBDIRECTORY(win/packaging)
ENDIF()
MESSAGE("SYSTEM processor: ${CMAKE_SYSTEM_PROCESSOR}")
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")
@@ -417,15 +417,15 @@ ENDIF()
# Build source packages
IF(GIT_BUILD_SRCPKG)
# get branch name
EXECUTE_PROCESS(COMMAND git show-branch OUTPUT_VARIABLE git_branch)
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 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=zip --prefix=${CPACK_SOURCE_PACKAGE_FILE_NAME}/ --output=${CPACK_SOURCE_PACKAGE_FILE_NAME}.zip)
ELSE()
EXECUTE_PROCESS(COMMAND git archive ${GIT_BRANCH} --format=zip --prefix=${CPACK_SOURCE_PACKAGE_FILE_NAME}/ --output=${CPACK_SOURCE_PACKAGE_FILE_NAME}.zip)
EXECUTE_PROCESS(COMMAND git archive ${GIT_BRANCH} --format=tar --prefix=${CPACK_SOURCE_PACKAGE_FILE_NAME}/ --output=${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar)
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()

View File

@@ -22,10 +22,6 @@
# INSTALL_LIBDIR location of libraries
# INSTALL_PLUGINDIR location of plugins
IF(DEFINED INSTALL_BINDIR AND DEFINED INSTALL_LIBDIR AND DEFINED INSTALL_INCLUDEDIR AND DEFINED INSTALL_DOCDIR AND DEFINED INSTALL_PLUGINDIR)
RETURN()
ENDIF()
IF(NOT INSTALL_LAYOUT)
SET(INSTALL_LAYOUT "DEFAULT")
ENDIF()

View File

@@ -8,22 +8,28 @@
MACRO(create_symlink symlink_name target install_path)
# According to cmake documentation symlinks work on unix systems only
IF(UNIX)
# Set target components
SET(target_lib $<TARGET_FILE_DIR:${target}>/${symlink_name})
# Get target components
ADD_CUSTOM_COMMAND(
TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E remove -f ${target_lib}
COMMAND ${CMAKE_COMMAND} ARGS -E create_symlink $<TARGET_FILE_NAME:${target}> ${symlink_name})
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 ${target_path}/${symlink_name})
"\${CMAKE_INSTALL_CONFIG_NAME}" output ${CMAKE_CURRENT_BINARY_DIR}/${symlink_name})
ENDIF()
# presumably this will be used for libmysql*.so symlinks
INSTALL(FILES ${target_lib} DESTINATION ${install_path}
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${symlink_name} DESTINATION ${install_path}
COMPONENT SharedLibraries)
ENDIF()
ENDMACRO()

View File

@@ -9,8 +9,8 @@ FUNCTION(GET_FILE_VERSION FILE_NAME FILE_VERSION)
# if we build from a git repository, we calculate the file version:
# Patch number is numer of commits for given file
IF(EXISTS ${CC_SOURCE_DIR}/.git)
EXECUTE_PROCESS(COMMAND git --git-dir=${CC_SOURCE_DIR}/.git --work-tree=${CC_SOURCE_DIR} rev-list HEAD --count -- ${FILE_NAME}
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)

View File

@@ -449,9 +449,7 @@ INSTALL(TARGETS libmariadb
IF(WIN32)
IF(${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
SET(PDB_LOCATION ${CC_BINARY_DIR}/libmariadb/RelWIthDebInfo/libmariadb.pdb)
INSTALL(FILES ${PDB_LOCATION} DESTINATION "${INSTALL_LIBDIR}"
# On Windows, install PDB
INSTALL(FILES $<TARGET_PDB_FILE:libmariadb> DESTINATION "${INSTALL_LIBDIR}"
COMPONENT Development)
ENDIF()
ENDIF()

View File

@@ -96,8 +96,8 @@ my_bool ma_dynstr_append_quoted(DYNAMIC_STRING *str,
const char *append, size_t len,
char quote)
{
uint additional= str->alloc_increment;
uint lim= additional;
size_t additional= str->alloc_increment;
size_t lim= additional;
uint i;
if (ma_dynstr_realloc(str, len + additional + 2))

View File

@@ -39,6 +39,13 @@
#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
#ifdef HAVE_TLS_SESSION_CACHE
#undef HAVE_TLS_SESSION_CACHE
#endif
@@ -436,7 +443,7 @@ int ma_tls_get_password(char *buf, int size,
memset(buf, 0, size);
if (userdata)
strncpy(buf, (char *)userdata, size);
return strlen(buf);
return (int)strlen(buf);
}
@@ -616,7 +623,7 @@ my_bool ma_tls_connect(MARIADB_TLS *ctls)
SSL_set_bio(ssl, bio, bio);
BIO_set_fd(bio, mysql_get_socket(mysql), BIO_NOCLOSE);
#else
SSL_set_fd(ssl, mysql_get_socket(mysql));
SSL_set_fd(ssl, (int)mysql_get_socket(mysql));
#endif
while (try_connect && (rc= SSL_connect(ssl)) == -1)
@@ -693,7 +700,7 @@ ssize_t ma_tls_read_async(MARIADB_PVIO *pvio,
for (;;)
{
res= SSL_read((SSL *)ctls->ssl, (void *)buffer, length);
res= SSL_read((SSL *)ctls->ssl, (void *)buffer, (int)length);
if (ma_tls_async_check_result(res, b, (SSL *)ctls->ssl))
return res;
}
@@ -709,7 +716,7 @@ ssize_t ma_tls_write_async(MARIADB_PVIO *pvio,
for (;;)
{
res= SSL_write((SSL *)ctls->ssl, (void *)buffer, length);
res= SSL_write((SSL *)ctls->ssl, (void *)buffer, (int)length);
if (ma_tls_async_check_result(res, b, (SSL *)ctls->ssl))
return res;
}
@@ -718,7 +725,7 @@ ssize_t ma_tls_write_async(MARIADB_PVIO *pvio,
ssize_t ma_tls_read(MARIADB_TLS *ctls, const uchar* buffer, size_t length)
{
ssize_t rc;
int rc;
MARIADB_PVIO *pvio= ctls->pvio;
while ((rc= SSL_read((SSL *)ctls->ssl, (void *)buffer, (int)length)) < 0)
@@ -734,7 +741,7 @@ ssize_t ma_tls_read(MARIADB_TLS *ctls, const uchar* buffer, size_t length)
ssize_t ma_tls_write(MARIADB_TLS *ctls, const uchar* buffer, size_t length)
{
ssize_t rc;
int rc;
MARIADB_PVIO *pvio= ctls->pvio;
while ((rc= SSL_write((SSL *)ctls->ssl, (void *)buffer, (int)length)) <= 0)

View File

@@ -39,7 +39,7 @@ IF(GSSAPI_SOURCES)
ENDIF()
IF(${WITH_SSL} STREQUAL "OPENSSL" OR ${WITH_SSL} STREQUAL "SCHANNEL")
IF(WIN32)
IF(WITH_SSL STREQUAL "SCHANNEL")
SET(SHA256_LIBS crypt32)
ELSE()
SET(SHA256_LIBS ${SSL_LIBRARIES})

View File

@@ -142,7 +142,7 @@ char *load_pub_key_file(const char *filename, int *pub_key_size)
if (bytes_read < (size_t)fsize)
goto end;
*pub_key_size= bytes_read;
*pub_key_size= (int)bytes_read;
error= 0;

View File

@@ -34,11 +34,8 @@
my_bool pvio_npipe_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout);
int pvio_npipe_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type);
ssize_t pvio_npipe_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
ssize_t pvio_npipe_async_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
ssize_t pvio_npipe_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
ssize_t pvio_npipe_async_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
int pvio_npipe_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout);
int pvio_npipe_blocking(MARIADB_PVIO *pvio, my_bool value, my_bool *old_value);
my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo);
my_bool pvio_npipe_close(MARIADB_PVIO *pvio);
int pvio_npipe_fast_send(MARIADB_PVIO *pvio);
@@ -55,8 +52,8 @@ struct st_ma_pvio_methods pvio_npipe_methods= {
NULL,
pvio_npipe_write,
NULL,
pvio_npipe_wait_io_or_timeout,
pvio_npipe_blocking,
NULL,
NULL,
pvio_npipe_connect,
pvio_npipe_close,
pvio_npipe_fast_send,
@@ -91,14 +88,22 @@ MARIADB_PVIO_PLUGIN _mysql_client_plugin_declaration_ =
struct st_pvio_npipe {
HANDLE pipe;
OVERLAPPED overlapped;
size_t rw_size;
MYSQL *mysql;
};
my_bool pvio_npipe_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout)
{
int timeout_ms;
if (!pvio)
return 1;
if (timeout > INT_MAX/1000)
timeout_ms= -1;
else if (timeout <=0)
timeout_ms= -1;
else
timeout_ms = timeout*100;
pvio->timeout[type]= (timeout > 0) ? timeout * 1000 : -1;
return 0;
}
@@ -110,103 +115,78 @@ int pvio_npipe_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type)
return pvio->timeout[type] / 1000;
}
static BOOL complete_io(HANDLE file, OVERLAPPED *ov, BOOL ret, DWORD timeout, DWORD *size)
{
if (ret)
timeout = 0; /* IO completed successfully, do not WaitForSingleObject */
else
{
assert(timeout);
if (GetLastError() != ERROR_IO_PENDING)
return FALSE;
}
if (timeout)
{
HANDLE wait_handle= ov->hEvent;
assert(wait_handle && (wait_handle != INVALID_HANDLE_VALUE));
DWORD wait_ret= WaitForSingleObject(wait_handle, timeout);
switch (wait_ret)
{
case WAIT_OBJECT_0:
break;
case WAIT_TIMEOUT:
CancelIoEx(file, ov);
SetLastError(ERROR_TIMEOUT);
return FALSE;
default:
/* WAIT_ABANDONED or WAIT_FAILED unexpected. */
assert(0);
return FALSE;
}
}
return GetOverlappedResult(file, ov, size, FALSE);
}
ssize_t pvio_npipe_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length)
{
DWORD dwRead= 0;
BOOL ret;
ssize_t r= -1;
struct st_pvio_npipe *cpipe= NULL;
DWORD size;
if (!pvio || !pvio->data)
return -1;
cpipe= (struct st_pvio_npipe *)pvio->data;
if (ReadFile(cpipe->pipe, (LPVOID)buffer, (DWORD)length, &dwRead, &cpipe->overlapped))
{
r= (ssize_t)dwRead;
goto end;
}
if (GetLastError() == ERROR_IO_PENDING)
{
if (!pvio_npipe_wait_io_or_timeout(pvio, 1, 0))
r= cpipe->rw_size;
}
end:
ret= ReadFile(cpipe->pipe, buffer, (DWORD)length, NULL, &cpipe->overlapped);
ret= complete_io(cpipe->pipe, &cpipe->overlapped, ret, pvio->timeout[PVIO_READ_TIMEOUT], &size);
r= ret? (ssize_t) size:-1;
return r;
}
ssize_t pvio_npipe_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length)
{
DWORD dwWrite= 0;
ssize_t r= -1;
struct st_pvio_npipe *cpipe= NULL;
BOOL ret;
DWORD size;
if (!pvio || !pvio->data)
return -1;
cpipe= (struct st_pvio_npipe *)pvio->data;
if (WriteFile(cpipe->pipe, buffer, (DWORD)length, &dwWrite, &cpipe->overlapped))
{
r= (ssize_t)dwWrite;
goto end;
}
if (GetLastError() == ERROR_IO_PENDING)
{
if (!pvio_npipe_wait_io_or_timeout(pvio, 0, 0))
r= cpipe->rw_size;
}
end:
ret= WriteFile(cpipe->pipe, buffer, (DWORD)length, NULL , &cpipe->overlapped);
ret= complete_io(cpipe->pipe, &cpipe->overlapped, ret, pvio->timeout[PVIO_WRITE_TIMEOUT], &size);
r= ret ? (ssize_t)size : -1;
return r;
}
int pvio_npipe_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout)
{
DWORD status;
int save_error;
struct st_pvio_npipe *cpipe= NULL;
cpipe= (struct st_pvio_npipe *)pvio->data;
if (!timeout)
timeout= (is_read) ? pvio->timeout[PVIO_READ_TIMEOUT] : pvio->timeout[PVIO_WRITE_TIMEOUT];
if (!timeout)
timeout= INFINITE;
status= WaitForSingleObject(cpipe->overlapped.hEvent, timeout);
if (status == WAIT_OBJECT_0)
{
if (GetOverlappedResult(cpipe->pipe, &cpipe->overlapped, (LPDWORD)&cpipe->rw_size, FALSE))
return 0;
}
/* For other status codes (WAIT_ABANDONED, WAIT_TIMEOUT and WAIT_FAILED)
we return error */
save_error= GetLastError();
CancelIo(cpipe->pipe);
SetLastError(save_error);
return -1;
}
int pvio_npipe_blocking(MARIADB_PVIO *pvio, my_bool block, my_bool *previous_mode)
{
/* not supported */
DWORD flags= 0;
struct st_pvio_npipe *cpipe= NULL;
cpipe= (struct st_pvio_npipe *)pvio->data;
if (previous_mode)
{
if (!GetNamedPipeHandleState(cpipe->pipe, &flags, NULL, NULL, NULL, NULL, 0))
return 1;
*previous_mode= flags & PIPE_NOWAIT ? 0 : 1;
}
flags= block ? PIPE_WAIT : PIPE_NOWAIT;
if (!SetNamedPipeHandleState(cpipe->pipe, &flags, NULL, NULL))
return 1;
return 0;
}
int pvio_npipe_keepalive(MARIADB_PVIO *pvio)
{
@@ -245,10 +225,10 @@ my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo)
if (cinfo->type == PVIO_TYPE_NAMEDPIPE)
{
my_bool has_timedout= 0;
char szPipeName[MAX_PATH];
DWORD dwMode;
ULONGLONG deadline;
LONGLONG wait_ms;
DWORD backoff= 0; /* Avoid busy wait if ERROR_PIPE_BUSY.*/
if ( ! cinfo->unix_socket || (cinfo->unix_socket)[0] == 0x00)
cinfo->unix_socket = MARIADB_NAMEDPIPE;
if (!cinfo->host || !strcmp(cinfo->host,LOCAL_HOST))
@@ -257,6 +237,7 @@ my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo)
szPipeName[MAX_PATH - 1]= 0;
snprintf(szPipeName, MAX_PATH - 1, "\\\\%s\\pipe\\%s", cinfo->host, cinfo->unix_socket);
deadline = GetTickCount64() + pvio->timeout[PVIO_CONNECT_TIMEOUT];
while (1)
{
if ((cpipe->pipe = CreateFile(szPipeName,
@@ -276,24 +257,23 @@ my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo)
goto end;
}
if (has_timedout || !WaitNamedPipe(szPipeName, pvio->timeout[PVIO_CONNECT_TIMEOUT]))
Sleep(backoff);
if (!backoff)
backoff = 1;
wait_ms = deadline - GetTickCount64();
if (wait_ms > INFINITE)
wait_ms = INFINITE;
if ((wait_ms <= 0) || !WaitNamedPipe(szPipeName, (DWORD)wait_ms))
{
pvio->set_error(pvio->mysql, CR_NAMEDPIPEWAIT_ERROR, "HY000", 0,
cinfo->host, cinfo->unix_socket, GetLastError());
cinfo->host, cinfo->unix_socket, ERROR_TIMEOUT);
goto end;
}
has_timedout= 1;
}
dwMode = PIPE_READMODE_BYTE | PIPE_WAIT;
if (!SetNamedPipeHandleState(cpipe->pipe, &dwMode, NULL, NULL))
{
pvio->set_error(pvio->mysql, CR_NAMEDPIPESETSTATE_ERROR, "HY000", 0,
cinfo->host, cinfo->unix_socket, (ulong) GetLastError());
goto end;
}
/* Register event handler for overlapped IO */
if (!(cpipe->overlapped.hEvent= CreateEvent(NULL, FALSE, FALSE, NULL)))
{
pvio->set_error(pvio->mysql, CR_EVENT_CREATE_FAILED, "HY000", 0,
@@ -348,14 +328,7 @@ my_bool pvio_npipe_get_handle(MARIADB_PVIO *pvio, void *handle)
my_bool pvio_npipe_is_blocking(MARIADB_PVIO *pvio)
{
DWORD flags= 0;
struct st_pvio_npipe *cpipe= NULL;
cpipe= (struct st_pvio_npipe *)pvio->data;
if (!GetNamedPipeHandleState(cpipe->pipe, &flags, NULL, NULL, NULL, NULL, 0))
return 1;
return (flags & PIPE_NOWAIT) ? 0 : 1;
return 1;
}
int pvio_npipe_shutdown(MARIADB_PVIO *pvio)

View File

@@ -1,6 +1,6 @@
#include "my_test.h"
#define MAX_COUNT 4000
#define MAX_COUNT 2000
int main(int argc, char *argv[]) {
@@ -25,7 +25,7 @@ int main(int argc, char *argv[]) {
return 1;
}
if (!mysql_real_connect(mysql, hostname, username, password, NULL, port, NULL, 0)) {
if (!mysql_real_connect(mysql, hostname, username, password, schema, port, socketname, 0)) {
diag("mysql_real_connect failed: %s", mysql_error(mysql));
return 1;
}