From 0bc7dc5e3cacf3f41e968fb80d357bcb9178218d Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Sat, 19 Sep 2015 13:02:30 +0200 Subject: [PATCH] Added build option WITH_REMOTEIO (default=off) --- CMakeLists.txt | 6 +++--- include/mariadb/ma_io.h | 3 +++ include/mysql/client_plugin.h | 11 ++++++++--- libmariadb/client_plugin.c | 2 ++ libmariadb/ma_io.c | 16 +++++++++++++++- plugins/io/CMakeLists.txt | 28 ++++++++++++++++------------ unittest/libmariadb/misc.c | 6 +++++- unittest/libmariadb/ps_bugs.c | 1 - 8 files changed, 52 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 11320a99..7da32fee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ ELSE() OPTION(WITH_SIGNCODE "digitally sign files" OFF) OPTION(WITH_RTC "enables run time checks for debug builds" OFF) ENDIF() +OPTION(WITH_REMOTEIO "enables remote io support (requires libcurl)" OFF) OPTION(WITH_EXTERNAL_ZLIB "Enables use of external zlib" OFF) ############### @@ -90,9 +91,8 @@ IF(NOT MYSQL_UNIX_ADDR) SET(MYSQL_UNIX_ADDR "/tmp/mysql.sock") ENDIF() -FIND_PACKAGE(CURL) -IF(CURL_FOUND) - ADD_DEFINITIONS(-DHAVE_CURL=1) +IF(WITH_REMOTEIO) + ADD_DEFINITIONS(-DHAVE_REMOTEIO) ENDIF() INCLUDE("${CMAKE_SOURCE_DIR}/cmake/install.cmake") diff --git a/include/mariadb/ma_io.h b/include/mariadb/ma_io.h index 0035f28a..b9881833 100644 --- a/include/mariadb/ma_io.h +++ b/include/mariadb/ma_io.h @@ -18,6 +18,7 @@ #ifndef _ma_io_h_ #define _ma_io_h_ + #ifdef HAVE_CURL #include #endif @@ -34,6 +35,7 @@ typedef struct void *ptr; } MA_FILE; +#ifdef HAVE_REMOTEIO struct st_rio_methods { MA_FILE *(*open)(const char *url, const char *mode); int (*close)(MA_FILE *ptr); @@ -41,6 +43,7 @@ struct st_rio_methods { size_t (*read)(void *ptr, size_t size, size_t nmemb, MA_FILE *file); char * (*gets)(char *ptr, size_t size, MA_FILE *file); }; +#endif /* function prototypes */ MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql); diff --git a/include/mysql/client_plugin.h b/include/mysql/client_plugin.h index f0e04637..1138df9c 100644 --- a/include/mysql/client_plugin.h +++ b/include/mysql/client_plugin.h @@ -40,13 +40,16 @@ #define MYSQL_CLIENT_reserved 1 #define MYSQL_CLIENT_AUTHENTICATION_PLUGIN 2 #define MYSQL_CLIENT_reserved22 3 -#define MYSQL_CLIENT_REMOTEIO_PLUGIN 4 - #define MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION 0x0100 #define MYSQL_CLIENT_DB_PLUGIN_INTERFACE_VERSION 0x0100 -#define MYSQL_CLIENT_REMOTEIO_PLUGIN_INTERFACE_VERSION 0x0100 +#ifdef HAVE_REMOTEIO +#define MYSQL_CLIENT_REMOTEIO_PLUGIN 4 #define MYSQL_CLIENT_MAX_PLUGINS 5 +#define MYSQL_CLIENT_REMOTEIO_PLUGIN_INTERFACE_VERSION 0x0100 +#else +#define MYSQL_CLIENT_MAX_PLUGINS 4 +#endif #define mysql_declare_client_plugin(X) \ struct st_mysql_client_plugin_ ## X \ @@ -113,6 +116,7 @@ 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 /* Remote IO plugin */ @@ -121,6 +125,7 @@ struct st_mysql_client_plugin_REMOTEIO MYSQL_CLIENT_PLUGIN_HEADER struct st_rio_methods *methods; }; +#endif /******** using plugins ************/ diff --git a/libmariadb/client_plugin.c b/libmariadb/client_plugin.c index e8a5ee2b..7b22ca9c 100644 --- a/libmariadb/client_plugin.c +++ b/libmariadb/client_plugin.c @@ -64,7 +64,9 @@ static uint plugin_version[MYSQL_CLIENT_MAX_PLUGINS]= 0, /* these two are taken by Connector/C */ MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION, 0, +#ifdef HAVE_REMOTEIO MYSQL_CLIENT_REMOTEIO_PLUGIN_INTERFACE_VERSION +#endif }; typedef struct st_mysql_client_plugin_AUTHENTICATION auth_plugin_t; diff --git a/libmariadb/ma_io.c b/libmariadb/ma_io.c index 15277818..83236382 100644 --- a/libmariadb/ma_io.c +++ b/libmariadb/ma_io.c @@ -23,10 +23,13 @@ #include #include #include +#include #include #include +#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) @@ -37,9 +40,10 @@ MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql) if (!location || !location[0]) return NULL; - +#ifdef HAVE_REMOTEIO if (strstr(location, "://")) goto remote; +#endif #ifdef _WIN32 if (mysql && mysql->charset) @@ -118,6 +122,7 @@ MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql) 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 */ @@ -128,6 +133,7 @@ remote: return rio_plugin->methods->open(location, mode); return NULL; } +#endif } /* }}} */ @@ -143,9 +149,11 @@ int ma_close(MA_FILE *file) rc= fclose((FILE *)file->ptr); my_free(file); break; +#ifdef HAVE_REMOTEIO case MA_FILE_REMOTE: rc= rio_plugin->methods->close(file); break; +#endif default: return -1; } @@ -163,9 +171,11 @@ int ma_feof(MA_FILE *file) case MA_FILE_LOCAL: return feof((FILE *)file->ptr); break; +#ifdef HAVE_REMOTEIO case MA_FILE_REMOTE: return rio_plugin->methods->feof(file); break; +#endif default: return -1; } @@ -184,9 +194,11 @@ size_t ma_read(void *ptr, size_t size, size_t nmemb, MA_FILE *file) s= fread(ptr, size, nmemb, (FILE *)file->ptr); return s; break; +#ifdef HAVE_REMOTEIO case MA_FILE_REMOTE: return rio_plugin->methods->read(ptr, size, nmemb, file); break; +#endif default: return -1; } @@ -203,9 +215,11 @@ char *ma_gets(char *ptr, size_t size, MA_FILE *file) case MA_FILE_LOCAL: return fgets(ptr, size, (FILE *)file->ptr); break; +#ifdef HAVE_REMOTEIO case MA_FILE_REMOTE: return rio_plugin->methods->gets(ptr, size, file); break; +#endif default: return NULL; } diff --git a/plugins/io/CMakeLists.txt b/plugins/io/CMakeLists.txt index d5aee9cf..ac63c0ea 100644 --- a/plugins/io/CMakeLists.txt +++ b/plugins/io/CMakeLists.txt @@ -1,17 +1,21 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) -IF(CURL_FOUND) - # remote file plugin - INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR}) - SET(REMOTE_IO_SOURCES remote_io.c) - ADD_LIBRARY(remote_io SHARED ${REMOTE_IO_SOURCES} ${CMAKE_SOURCE_DIR}/plugins/plugin.def) - TARGET_LINK_LIBRARIES(remote_io ${CURL_LIBRARIES}) +IF(WITH_REMOTEIO) + FIND_PACKAGE(CURL) + IF(CURL_FOUND) + ADD_DEFINITIONS(-DHAVE_CURL=1) + # remote file plugin + INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR}) + SET(REMOTE_IO_SOURCES remote_io.c) + ADD_LIBRARY(remote_io SHARED ${REMOTE_IO_SOURCES} ${CMAKE_SOURCE_DIR}/plugins/plugin.def) + TARGET_LINK_LIBRARIES(remote_io ${CURL_LIBRARIES}) - SET_TARGET_PROPERTIES(remote_io PROPERTIES PREFIX "") + SET_TARGET_PROPERTIES(remote_io PROPERTIES PREFIX "") - INSTALL(TARGETS - remote_io - RUNTIME DESTINATION "${PLUGIN_INSTALL_DIR}" - LIBRARY DESTINATION "${PLUGIN_INSTALL_DIR}" - ARCHIVE DESTINATION "${PLUGIN_INSTALL_DIR}") + INSTALL(TARGETS + remote_io + RUNTIME DESTINATION "${PLUGIN_INSTALL_DIR}" + LIBRARY DESTINATION "${PLUGIN_INSTALL_DIR}" + ARCHIVE DESTINATION "${PLUGIN_INSTALL_DIR}") + ENDIF() ENDIF() diff --git a/unittest/libmariadb/misc.c b/unittest/libmariadb/misc.c index 499547dd..d9ab5204 100644 --- a/unittest/libmariadb/misc.c +++ b/unittest/libmariadb/misc.c @@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include -void *remote_plugin; /* Bug#28075 "COM_DEBUG crashes mysqld" @@ -1003,6 +1002,8 @@ static int test_conc117(MYSQL *mysql) return OK; } +#ifdef HAVE_REMOTEIO +void *remote_plugin; static int test_remote1(MYSQL *mysql) { int rc; @@ -1048,10 +1049,13 @@ static int test_remote2(MYSQL *my) mysql_close(mysql); return OK; } +#endif struct my_tests_st my_tests[] = { +#ifdef HAVE_REMOTEIO {"test_remote1", test_remote1, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_remote2", test_remote2, TEST_CONNECTION_NEW, 0, NULL, NULL}, +#endif {"test_conc117", test_conc117, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc_114", test_conc_114, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_connect_attrs", test_connect_attrs, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, diff --git a/unittest/libmariadb/ps_bugs.c b/unittest/libmariadb/ps_bugs.c index a03c8174..d4d6fa0f 100644 --- a/unittest/libmariadb/ps_bugs.c +++ b/unittest/libmariadb/ps_bugs.c @@ -3871,7 +3871,6 @@ static int test_conc_5(MYSQL *mysql) static int test_conc141(MYSQL *mysql) { int rc; - MYSQL_RES *res; char *query= "CALL p_conc141"; MYSQL_STMT *stmt= mysql_stmt_init(mysql);