From 5fca34186f1cef71a25e0ec5833c0cee341f380b Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Fri, 20 Nov 2015 18:34:35 +0100 Subject: [PATCH 01/39] Initial implementation for MDEV-9117: 10.2 protocol changes - exchanging mariadb specific client/server capabilities during handshake --- include/mysql.h | 19 ++++++++++--------- include/mysql_com.h | 12 ++++++++++-- libmariadb/libmariadb.c | 15 ++++++++++++--- plugins/auth/my_auth.c | 13 ++++++++++++- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/include/mysql.h b/include/mysql.h index b61eb84f..d2a5c7e3 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -276,17 +276,18 @@ struct st_mysql_options { my_ulonglong 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,server_capabilities; /* changed from int to long in 4.1 protocol */ - 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 */ + unsigned int port; + unsigned long long client_flag; + unsigned long long server_capabilities; /* changed from long to longlong in 10.2 protocol */ + 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 reconnect; /* set to 1 if automatic reconnect */ + my_bool free_me; /* If free in mysql_close */ + my_bool reconnect; /* set to 1 if automatic reconnect */ char scramble_buff[20+ 1]; /* madded after 3.23.58 */ my_bool unused_1; diff --git a/include/mysql_com.h b/include/mysql_com.h index f1d4eb69..eba227fb 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -154,7 +154,15 @@ enum enum_server_command #define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30) #define CLIENT_REMEMBER_OPTIONS (1UL << 31) -#define CLIENT_SUPPORTED_FLAGS (CLIENT_LONG_PASSWORD | \ +/* MariaDB specific capabilities */ +#define MARIADB_CLIENT_FLAGS 0xFFFFFFFF00000000ULL +#define MARIADB_CLIENT_PROGRESS (1ULL << 32) +#define MARIADB_CLIENT_EXTENDED_PROTOCOL (1ULL << 63) + +#define MARIADB_CLIENT_SUPPORTED_FLAGS (MARIADB_CLIENT_PROGRESS |\ + MARIADB_CLIENT_EXTENDED_PROTOCOL) + +#define CLIENT_SUPPORTED_FLAGS (CLIENT_LONG_PASSWORD |\ CLIENT_FOUND_ROWS |\ CLIENT_LONG_FLAG |\ CLIENT_CONNECT_WITH_DB |\ @@ -178,7 +186,7 @@ enum enum_server_command CLIENT_PLUGIN_AUTH |\ CLIENT_CONNECT_ATTRS) -#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD |\ +#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | \ CLIENT_LONG_FLAG |\ CLIENT_TRANSACTIONS |\ CLIENT_SECURE_CONNECTION |\ diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index 1590df17..1a5e62b4 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -70,6 +70,7 @@ #include #define ASYNC_CONTEXT_DEFAULT_STACK_SIZE (4096*15) +#define MA_RPL_VERSION_HACK "5.5.5-" #undef max_allowed_packet #undef net_buffer_length @@ -1308,6 +1309,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, MA_PVIO_CINFO cinfo= {NULL, NULL, 0, -1, NULL}; MARIADB_PVIO *pvio= NULL; char *scramble_data; + my_bool is_maria= 0; const char *scramble_plugin; uint pkt_length, scramble_len, pkt_scramble_len= 0; NET *net= &mysql->net; @@ -1532,13 +1534,14 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, mysql->port=port; client_flag|=mysql->options.client_flag; - if (strncmp(end, "5.5.5-", 6) == 0) + if (strncmp(end, MA_RPL_VERSION_HACK, sizeof(MA_RPL_VERSION_HACK)) == 0) { - if (!(mysql->server_version= my_strdup(end + 6, 0))) + if (!(mysql->server_version= my_strdup(end + sizeof(MA_RPL_VERSION_HACK), 0))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); goto error; } + is_maria= 1; } else { @@ -1575,7 +1578,14 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, mysql->server_status= uint2korr(end + 3); mysql->server_capabilities|= uint2korr(end + 5) << 16; pkt_scramble_len= uint1korr(end + 7); + + /* check if MariaD2B specific capabilities are available */ + if (is_maria && !(mysql->server_capabilities & CLIENT_LONG_PASSWORD)) + { + mysql->server_capabilities|= (ulonglong) uint4korr(end + 14) << 32; + } } + /* pad 2 */ end+= 18; @@ -1605,7 +1615,6 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, } } - /* Set character set */ if (mysql->options.charset_name) mysql->charset= mysql_find_charset_name(mysql->options.charset_name); diff --git a/plugins/auth/my_auth.c b/plugins/auth/my_auth.c index 08505685..e1a8b95c 100644 --- a/plugins/auth/my_auth.c +++ b/plugins/auth/my_auth.c @@ -169,6 +169,12 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, if (mysql->client_flag & CLIENT_MULTI_STATEMENTS) mysql->client_flag|= CLIENT_MULTI_RESULTS; + /* if server supports extended MariaDB extended protocol, we will unset + CLIENT_LONG_PASSWORD and send extended client capabilities in last + four of 23 unused bytes */ + if (mysql->server_capabilities & MARIADB_CLIENT_EXTENDED_PROTOCOL) + mysql->client_flag &= ~CLIENT_LONG_PASSWORD; + #if defined(HAVE_SSL) && !defined(EMBEDDED_LIBRARY) if (mysql->options.ssl_key || mysql->options.ssl_cert || mysql->options.ssl_ca || mysql->options.ssl_capath || @@ -211,7 +217,12 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, int4store(buff,mysql->client_flag); int4store(buff+4, net->max_packet_size); buff[8]= (char) mysql->charset->nr; - bzero(buff+9, 32-9); + bzero(buff + 9, 32-9); + if (!(mysql->server_capabilities & MARIADB_CLIENT_EXTENDED_PROTOCOL)) + { + mysql->client_flag |= MARIADB_CLIENT_SUPPORTED_FLAGS; + int4store(buff + 28, mysql->client_flag << 32); + } end= buff+32; } else From 955bb8d6ff2c3faa3f0fabb621d58870c5a86469 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Fri, 20 Nov 2015 19:20:22 +0100 Subject: [PATCH 02/39] 10.2 protocol fixes: exclude trailing 0 when checking for RPL_HACK in version number. Shift extended client flags up instead of down --- libmariadb/libmariadb.c | 2 +- plugins/auth/my_auth.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index 1a5e62b4..9ab13e46 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -1534,7 +1534,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, mysql->port=port; client_flag|=mysql->options.client_flag; - if (strncmp(end, MA_RPL_VERSION_HACK, sizeof(MA_RPL_VERSION_HACK)) == 0) + if (strncmp(end, MA_RPL_VERSION_HACK, sizeof(MA_RPL_VERSION_HACK) - 1) == 0) { if (!(mysql->server_version= my_strdup(end + sizeof(MA_RPL_VERSION_HACK), 0))) { diff --git a/plugins/auth/my_auth.c b/plugins/auth/my_auth.c index e1a8b95c..bcb957cc 100644 --- a/plugins/auth/my_auth.c +++ b/plugins/auth/my_auth.c @@ -218,10 +218,10 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, int4store(buff+4, net->max_packet_size); buff[8]= (char) mysql->charset->nr; bzero(buff + 9, 32-9); - if (!(mysql->server_capabilities & MARIADB_CLIENT_EXTENDED_PROTOCOL)) + if (mysql->server_capabilities & MARIADB_CLIENT_EXTENDED_PROTOCOL) { mysql->client_flag |= MARIADB_CLIENT_SUPPORTED_FLAGS; - int4store(buff + 28, mysql->client_flag << 32); + int4store(buff + 28, mysql->client_flag >> 32); } end= buff+32; } From c8648cf4b29460738fd74d05e48c5a70db7a6039 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Thu, 17 Dec 2015 19:21:52 +0100 Subject: [PATCH 03/39] Initial implementation for COM_MULTI --- CMakeLists.txt | 7 +++ include/errmsg.h | 1 + include/ma_common.h | 2 + include/mysql.h | 1 + include/mysql_com.h | 7 ++- libmariadb/CMakeLists.txt | 1 + libmariadb/errmsg.c | 1 + libmariadb/libmariadb.c | 52 ++++++++++++++++-- libmariadb/net.c | 81 +++++++++++++++++++++++++---- plugins/auth/my_auth.c | 4 +- unittest/libmariadb/CMakeLists.txt | 2 +- unittest/libmariadb/features-10_2.c | 55 ++++++++++++++++++++ 12 files changed, 197 insertions(+), 17 deletions(-) create mode 100644 unittest/libmariadb/features-10_2.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 636de894..8d21bd6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,13 @@ IF(COMMAND CMAKE_POLICY) CMAKE_POLICY(SET CMP0003 NEW) ENDIF() +#Allow access to non existing targets +IF(CMAKE_VERSION VERSION_GREATER "2.9.9") + CMAKE_POLICY(SET CMP0026 OLD) + CMAKE_POLICY(SET CMP0042 OLD) + CMAKE_POLICY(SET CMP0045 OLD) +ENDIF() + SET(MARIADB_CONNECTOR_C_COPYRIGHT "2013-2015 MariaDB Corporation Ab") ### Options ### diff --git a/include/errmsg.h b/include/errmsg.h index ff795a7b..8a91519a 100644 --- a/include/errmsg.h +++ b/include/errmsg.h @@ -84,6 +84,7 @@ extern const char *mariadb_client_errors[]; /* Error messages */ #define CR_EVENT_CREATE_FAILED 5000 #define CR_BIND_ADDR_FAILED 5001 +#define CR_FUNCTION_NOT_SUPPORTED 5002 #define SQLSTATE_UNKNOWN "HY000" diff --git a/include/ma_common.h b/include/ma_common.h index 6a6a80a0..6d61f1f0 100644 --- a/include/ma_common.h +++ b/include/ma_common.h @@ -52,6 +52,8 @@ struct st_mysql_options_extension { char *ssl_fp; /* finger print of server certificate */ char *ssl_fp_list; /* white list of finger prints */ char *ssl_pw; /* password for encrypted certificates */ + my_bool multi_command; /* indicates if client wants to send multiple + commands in one packet */ }; #define OPT_HAS_EXT_VAL(a,key) \ diff --git a/include/mysql.h b/include/mysql.h index d2a5c7e3..b262af85 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -214,6 +214,7 @@ extern unsigned int mariadb_deinitialize_ssl; MARIADB_OPT_SSL_FP, /* single finger print for server certificate verification */ MARIADB_OPT_SSL_FP_LIST, /* finger print white list for server certificate verification */ MARIADB_OPT_SSL_PASSWORD, /* password for encrypted certificates */ + MARIADB_OPT_COM_MULTI, MARIADB_OPT_CONNECTION_READ_ONLY }; diff --git a/include/mysql_com.h b/include/mysql_com.h index eba227fb..045e4d72 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -87,6 +87,7 @@ enum enum_server_command COM_SET_OPTION = 27, COM_STMT_FETCH = 28, COM_DAEMON, + COM_MULTI = 255, COM_END }; @@ -156,11 +157,12 @@ enum enum_server_command /* MariaDB specific capabilities */ #define MARIADB_CLIENT_FLAGS 0xFFFFFFFF00000000ULL +#define MARIADB_CLIENT_COM_MULTI 1 #define MARIADB_CLIENT_PROGRESS (1ULL << 32) -#define MARIADB_CLIENT_EXTENDED_PROTOCOL (1ULL << 63) +#define MARIADB_CLIENT_EXTENDED_FLAGS (1ULL << 63) #define MARIADB_CLIENT_SUPPORTED_FLAGS (MARIADB_CLIENT_PROGRESS |\ - MARIADB_CLIENT_EXTENDED_PROTOCOL) + MARIADB_CLIENT_EXTENDED_FLAGS) #define CLIENT_SUPPORTED_FLAGS (CLIENT_LONG_PASSWORD |\ CLIENT_FOUND_ROWS |\ @@ -245,6 +247,7 @@ typedef struct st_net { MARIADB_PVIO *pvio; unsigned char *buff; unsigned char *buff_end,*write_pos,*read_pos; + unsigned char *mbuff, *mbuff_end, *mbuff_pos; my_socket fd; /* For Perl DBI/dbd */ unsigned long remain_in_buf,length; unsigned long buf_length, where_b; diff --git a/libmariadb/CMakeLists.txt b/libmariadb/CMakeLists.txt index ed0c041e..9de5f7d0 100644 --- a/libmariadb/CMakeLists.txt +++ b/libmariadb/CMakeLists.txt @@ -34,6 +34,7 @@ SET(EXPORT_SYMBOLS mariadb_dyncol_val_double mariadb_dyncol_val_long mariadb_dyncol_val_str + mariadb_flush_multi_command myodbc_remove_escape mysql_affected_rows mysql_autocommit diff --git a/libmariadb/errmsg.c b/libmariadb/errmsg.c index 8ae0fa04..d228d6b3 100644 --- a/libmariadb/errmsg.c +++ b/libmariadb/errmsg.c @@ -149,6 +149,7 @@ const char *mariadb_client_errors[] = { /* 5000 */ "Creating an event failed (Errorcode: %d)", /* 5001 */ "Bind to local interface '-.%64s' failed (Errorcode: %d)", + /* 5002 */ "Server doesn't support function '%s'", "" }; diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index 9ab13e46..d2409b35 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -88,6 +88,8 @@ extern const CHARSET_INFO * mysql_find_charset_nr(uint charsetnr); extern const CHARSET_INFO * mysql_find_charset_name(const char * const name); extern int run_plugin_auth(MYSQL *mysql, char *data, uint data_len, const char *data_plugin, const char *db); +extern int net_add_multi_command(NET *net, uchar command, const uchar *packet, + size_t length); extern LIST *pvio_callback; @@ -350,11 +352,21 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg, { NET *net= &mysql->net; int result= -1; + my_bool is_multi= 0; - DBUG_ENTER("mthd_my_send_command"); + if (OPT_HAS_EXT_VAL(mysql, multi_command)) + is_multi= mysql->options.extension->multi_command; + + DBUG_ENTER("mthd_my_send_cmd"); DBUG_PRINT("info", ("server_command: %d packet_size: %u", command, length)); + if (is_multi) + { + /* todo: error handling */ + DBUG_RETURN(net_add_multi_command(&mysql->net, command, arg, length)); + } + if (mysql->net.conn_hdlr && mysql->net.conn_hdlr->data) { result= mysql->net.conn_hdlr->plugin->set_connection(mysql, command, arg, length, skipp_check, opt_arg); @@ -661,7 +673,7 @@ enum option_val #define OPT_SET_EXTENDED_VALUE_INT(OPTS, KEY, VAL) \ CHECK_OPT_EXTENSION_SET(OPTS) \ -+ (OPTS)->extension->KEY= (VAL) + (OPTS)->extension->KEY= (VAL) static TYPELIB option_types={array_elements(default_options)-1, @@ -2106,15 +2118,22 @@ mysql_read_query_result(MYSQL *mysql) int STDCALL mysql_real_query(MYSQL *mysql, const char *query, size_t length) { + my_bool is_multi= 0; + DBUG_ENTER("mysql_real_query"); DBUG_PRINT("enter",("handle: %lx",mysql)); DBUG_PRINT("query",("Query = \"%.255s\" length=%u",query, length)); + if (OPT_HAS_EXT_VAL(mysql, multi_command)) + is_multi= mysql->options.extension->multi_command; + free_old_query(mysql); if (simple_command(mysql, COM_QUERY,query,length,1,0)) DBUG_RETURN(-1); - DBUG_RETURN(mysql->methods->db_read_query_result(mysql)); + if (!is_multi) + DBUG_RETURN(mysql->methods->db_read_query_result(mysql)); + DBUG_RETURN(0); } /************************************************************************** @@ -2891,6 +2910,15 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) DBUG_RETURN(mysql->net.conn_hdlr->plugin->options(mysql, MARIADB_OPT_CONNECTION_READ_ONLY, arg1)); else return -1; + case MARIADB_OPT_COM_MULTI: + if (&mysql->net.pvio && + (mysql->server_capabilities & MARIADB_CLIENT_EXTENDED_FLAGS)) + { + OPT_SET_EXTENDED_VALUE_INT(&mysql->options, multi_command, *(my_bool *)arg1); + } + else + DBUG_RETURN(-1); + break; default: va_end(ap); DBUG_RETURN(-1); @@ -3304,6 +3332,24 @@ mysql_get_socket(const MYSQL *mysql) return sock; } +int STDCALL mariadb_flush_multi_command(MYSQL *mysql) +{ + int is_multi= 0; + int rc; + + /* turn off multi_command option, so simple_command will + * stop to add commands to the queue and send packet + * to the server */ + mysql_options(mysql, MARIADB_OPT_COM_MULTI, &is_multi); + + rc= simple_command(mysql, COM_MULTI, mysql->net.mbuff, + mysql->net.mbuff_pos - mysql->net.mbuff, + 0, 0); + /* reset multi_buff */ + mysql->net.mbuff_pos= mysql->net.mbuff; + return rc; +} + /* * Default methods for a connection. These methods are * stored in mysql->methods and can be overwritten by diff --git a/libmariadb/net.c b/libmariadb/net.c index 8c657d2a..df75c8c0 100644 --- a/libmariadb/net.c +++ b/libmariadb/net.c @@ -107,7 +107,6 @@ extern pthread_mutex_t LOCK_bytes_sent , LOCK_bytes_received; ** can't normally do this the client should have a bigger max-buffer. */ -#define TEST_BLOCKING 8 static int net_write_buff(NET *net,const char *packet, size_t len); @@ -117,6 +116,10 @@ int my_net_init(NET *net, MARIADB_PVIO* pvio) { if (!(net->buff=(uchar*) my_malloc(net_buffer_length,MYF(MY_WME | MY_ZEROFILL)))) return 1; + + /* We don't allocate memory for multi buffer, since we don't know in advance if the server + * supports COM_MULTI comand. It will be allocated on demand in net_add_multi_command */ + max_allowed_packet= 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; @@ -141,13 +144,15 @@ int my_net_init(NET *net, MARIADB_PVIO* pvio) void net_end(NET *net) { - my_free((gptr) net->buff); + my_free(net->buff); + my_free(net->mbuff); net->buff=0; + net->mbuff= 0; } /* Realloc the packet buffer */ -static my_bool net_realloc(NET *net, size_t length) +static my_bool net_realloc(NET *net, my_bool is_multi, size_t length) { uchar *buff; size_t pkt_length; @@ -166,7 +171,7 @@ static my_bool net_realloc(NET *net, size_t length) pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1); /* reallocate buffer: size= pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE */ - if (!(buff=(uchar*) my_realloc((char*) net->buff, + if (!(buff=(uchar*) my_realloc(is_multi ? net->mbuff : net->buff, pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE, MYF(MY_WME)))) { @@ -174,8 +179,16 @@ static my_bool net_realloc(NET *net, size_t length) net->error=1; DBUG_RETURN(1); } - net->buff=net->write_pos=buff; - net->buff_end=buff+(net->max_packet=(unsigned long)pkt_length); + if (!is_multi) + { + net->buff=net->write_pos=buff; + net->buff_end=buff+(net->max_packet=(unsigned long)pkt_length); + } + else + { + net->mbuff=net->mbuff_pos=buff; + net->mbuff_end=buff+(net->max_packet=(unsigned long)pkt_length); + } DBUG_RETURN(0); } @@ -186,11 +199,13 @@ void net_clear(NET *net) DBUG_ENTER("net_clear"); net->compress_pkt_nr= net->pkt_nr=0; /* Ready for new command */ net->write_pos=net->buff; + if (net->mbuff) + net->mbuff_pos= net->mbuff; DBUG_VOID_RETURN; } - /* Flush write_buffer if not empty. */ +/* Flush write_buffer if not empty. */ int net_flush(NET *net) { @@ -327,6 +342,55 @@ net_write_buff(NET *net,const char *packet, size_t len) return 0; } +int net_add_multi_command(NET *net, uchar command, const uchar *packet, + size_t length) +{ + size_t left_length; + size_t required_length, current_length; + required_length= length + 1 + NET_HEADER_SIZE; + + /* We didn't allocate memory in my_net_init since it was to early to + * detect if the server supports COM_MULTI command */ + if (!net->mbuff) + { + size_t alloc_size= (required_length + IO_SIZE - 1) & ~(IO_SIZE - 1); + if (!(net->mbuff= (char *)my_malloc(alloc_size, MYF(MY_WME)))) + { + net->last_errno=ER_OUT_OF_RESOURCES; + net->error=2; + net->reading_or_writing=0; + return(1); + } + net->mbuff_pos= net->mbuff; + net->mbuff_end= net->mbuff + alloc_size; + } + + left_length= net->mbuff_end - net->mbuff_pos; + + /* check if our buffer is large enough */ + if (left_length < required_length) + { + current_length= net->mbuff_pos - net->mbuff; + if (net_realloc(net, 1, current_length + required_length)) + goto error; + } + int3store(net->mbuff_pos, length + 1); + net->mbuff_pos+= 3; + *net->mbuff_pos= command; + net->mbuff_pos++; + memcpy(net->mbuff_pos, packet, length); + net->mbuff_pos+= length; + return 0; + +error: + if (net->mbuff) + { + my_free(net->mbuff); + net->mbuff= net->mbuff_pos= net->mbuff_end= 0; + } + return 1; +} + /* Read and write using timeouts */ int @@ -391,7 +455,6 @@ net_real_write(NET *net,const char *packet,size_t len) DBUG_RETURN(((int) (pos != end))); } - /***************************************************************************** ** Read something from server/clinet *****************************************************************************/ @@ -460,7 +523,7 @@ my_real_read(NET *net, size_t *complen) /* The necessary size of net->buff */ if (helping >= net->max_packet) { - if (net_realloc(net,helping)) + if (net_realloc(net, 0, helping)) { len= packet_error; /* Return error */ goto end; diff --git a/plugins/auth/my_auth.c b/plugins/auth/my_auth.c index bcb957cc..039d5eb6 100644 --- a/plugins/auth/my_auth.c +++ b/plugins/auth/my_auth.c @@ -172,7 +172,7 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, /* if server supports extended MariaDB extended protocol, we will unset CLIENT_LONG_PASSWORD and send extended client capabilities in last four of 23 unused bytes */ - if (mysql->server_capabilities & MARIADB_CLIENT_EXTENDED_PROTOCOL) + if (mysql->server_capabilities & MARIADB_CLIENT_EXTENDED_FLAGS) mysql->client_flag &= ~CLIENT_LONG_PASSWORD; #if defined(HAVE_SSL) && !defined(EMBEDDED_LIBRARY) @@ -218,7 +218,7 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, int4store(buff+4, net->max_packet_size); buff[8]= (char) mysql->charset->nr; bzero(buff + 9, 32-9); - if (mysql->server_capabilities & MARIADB_CLIENT_EXTENDED_PROTOCOL) + if (mysql->server_capabilities & MARIADB_CLIENT_EXTENDED_FLAGS) { mysql->client_flag |= MARIADB_CLIENT_SUPPORTED_FLAGS; int4store(buff + 28, mysql->client_flag >> 32); diff --git a/unittest/libmariadb/CMakeLists.txt b/unittest/libmariadb/CMakeLists.txt index 4e8d2125..d8a8e695 100644 --- a/unittest/libmariadb/CMakeLists.txt +++ b/unittest/libmariadb/CMakeLists.txt @@ -21,7 +21,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/unittest/mytap) ADD_DEFINITIONS(-DLIBMARIADB) -SET(API_TESTS "async" "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs" +SET(API_TESTS "features-10_2" "async" "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs" "sp" "result" "connection" "misc" "ps_new" "sqlite3" "thread" "dyncol") # Get finger print from server certificate diff --git a/unittest/libmariadb/features-10_2.c b/unittest/libmariadb/features-10_2.c new file mode 100644 index 00000000..758b59fe --- /dev/null +++ b/unittest/libmariadb/features-10_2.c @@ -0,0 +1,55 @@ +/* +*/ + +#include "my_test.h" + +static int com_multi_1(MYSQL *mysql) +{ + int rc; + my_bool is_multi= 1; + + if (mysql_options(mysql, MARIADB_OPT_COM_MULTI, &is_multi)) + { + diag("COM_MULT not supported"); + return SKIP; + } + + rc= mysql_query(mysql, "SET @a:=1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SET @b:=2"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "select @a,@b"); + check_mysql_rc(rc, mysql); + + rc= mariadb_flush_multi_command(mysql); + check_mysql_rc(rc, mysql); + + /* question: how will result sets look like ? */ + diag("error: %s", mysql_error(mysql)); + + return OK; +} + +struct my_tests_st my_tests[] = { + {"com_multi_1", com_multi_1, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + + +int main(int argc, char **argv) +{ + + mysql_library_init(0,0,NULL); + + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + mysql_server_end(); + return(exit_status()); +} From a3bb1d2009d7c27c3b0962783a0e82a4234a89f8 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Tue, 29 Dec 2015 21:06:23 +0100 Subject: [PATCH 04/39] merge from 3.0.0 fixes --- CMakeLists.txt | 22 +- appveyor.yml | 29 + cmake/plugins.cmake | 13 +- include/errmsg.h | 3 +- include/ma_common.h | 5 +- include/ma_pvio.h | 3 +- include/ma_ssl.h | 17 + include/my_context.h | 1 - include/my_stmt.h | 1 + include/mysql.h | 170 ++++- include/mysql/client_plugin.h | 1 + include/mysql_com.h | 7 + libmariadb/CMakeLists.txt | 8 +- libmariadb/errmsg.c | 3 +- libmariadb/libmariadb.c | 871 ++++++++++++++++++---- libmariadb/ma_dyncol.c | 2 +- libmariadb/ma_pvio.c | 16 +- libmariadb/ma_ssl.c | 7 + libmariadb/my_static.c | 2 - libmariadb/my_static.h | 1 - libmariadb/my_stmt.c | 1 - libmariadb/mysql_async.c | 8 +- libmariadb/net.c | 8 +- libmariadb/secure/gnutls.c | 10 +- libmariadb/secure/ma_schannel.c | 77 +- libmariadb/secure/openssl.c | 96 ++- libmariadb/secure/schannel.c | 2 +- mariadb_config/libmariadb.pc.in | 19 + plugins/connection/CMakeLists.txt | 22 +- plugins/connection/aurora.c | 819 ++++++++++++++++++++ plugins/connection/replication.c | 74 +- plugins/pvio/pvio_npipe.c | 22 +- plugins/pvio/pvio_socket.c | 2 +- unittest/libmariadb/CMakeLists.txt | 27 +- unittest/libmariadb/async.c | 32 +- unittest/libmariadb/basic-t.c | 59 +- unittest/libmariadb/certs/create_certs.sh | 15 - unittest/libmariadb/certs/dummy.pem | 21 - unittest/libmariadb/charset.c | 2 +- unittest/libmariadb/connection.c | 103 ++- unittest/libmariadb/cursor.c | 8 +- unittest/libmariadb/logs.c | 2 +- unittest/libmariadb/misc.c | 67 +- unittest/libmariadb/my_test.h | 30 +- unittest/libmariadb/ps.c | 11 +- unittest/libmariadb/ps_bugs.c | 11 +- unittest/libmariadb/ssl.c.in | 78 +- unittest/libmariadb/t_aurora.c | 67 ++ win-iconv/win_iconv.c | 6 +- win/packaging/CMakeLists.txt | 6 +- 50 files changed, 2499 insertions(+), 388 deletions(-) create mode 100644 appveyor.yml create mode 100644 mariadb_config/libmariadb.pc.in create mode 100644 plugins/connection/aurora.c delete mode 100755 unittest/libmariadb/certs/create_certs.sh delete mode 100644 unittest/libmariadb/certs/dummy.pem create mode 100644 unittest/libmariadb/t_aurora.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d21bd6f..b8e45c18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,8 @@ # This is the LGPL libmariadb project. PROJECT(mariadb-connector-c C) +SET(PACKAGE_STATUS_SUFFIX "alpha") + SET(CPACK_PACKAGE_VERSION_MAJOR 3) SET(CPACK_PACKAGE_VERSION_MINOR 0) SET(CPACK_PACKAGE_VERSION_PATCH 0) @@ -154,6 +156,10 @@ IF(CMAKE_HAVE_PTHREAD_H) SET(CMAKE_REQUIRED_INCLUDES pthread.h) ENDIF() +IF(DBUG_OFF) + ADD_DEFINITIONS(-DDBUG_OFF=1) +ENDIF() + IF(WIN32) SET(HAVE_THREADS 1) ADD_DEFINITIONS(-DHAVE_DLOPEN) @@ -271,12 +277,16 @@ 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_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${system_name}-${CMAKE_SYSTEM_PROCESSOR}") SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING.LIB") SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README") INCLUDE(cmake/ConnectorName.cmake) -SET(CPACK_SOURCE_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-src") - +IF(NOT PACKAGE_STATUS_SUFFIX) + SET(CPACK_SOURCE_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-src") + SET(CPACK_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${system_name}-${CMAKE_SYSTEM_PROCESSOR}") +ELSE() + SET(CPACK_SOURCE_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${PACKAGE_STATUS_SUFFIX}-src") + SET(CPACK_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${PACKAGE_STATUS_SUFFIX}-${system_name}-${CMAKE_SYSTEM_PROCESSOR}") +ENDIF() # Build source packages IF(GIT_BUILD_SRCPKG) # get branch name @@ -285,10 +295,10 @@ IF(GIT_BUILD_SRCPKG) STRING(REGEX REPLACE "\\[|\\]" "" GIT_BRANCH ${git_branch}) MESSAGE(STATUS "${GIT_BRANCH}") IF(WIN32) - EXECUTE_PROCESS(COMMAND git archive ${GIT_BRANCH} --format=zip --output=${CPACK_SOURCE_PACKAGE_FILE_NAME}.zip) + EXECUTE_PROCESS(COMMAND git 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 --output=${CPACK_SOURCE_PACKAGE_FILE_NAME}.zip) - EXECUTE_PROCESS(COMMAND git archive ${GIT_BRANCH} --format=tar --output=${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar) + 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 gzip -9 -f ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar) ENDIF() ENDIF() diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..89566c92 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,29 @@ +version: 3.0.0.{build} +branches: + only: + - master +os: Visual Studio 2015 +configuration: RelWithDebInfo +platform: x64 +clone_folder: c:\projects\mariadb-connector-c +environment: + MYSQL_TEST_USER: root + MYSQL_TEST_HOST: 127.0.0.1 + MYSQL_TEST_PASSWD: Password12! +services: mysql56 +before_build: +- ps: >- + cd c:\projects\mariadb-connector-c + + echo running cmake + + cmake -G "Visual Studio 14 2015 Win64" -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 + + ctest -V diff --git a/cmake/plugins.cmake b/cmake/plugins.cmake index 47e15597..a68bd509 100644 --- a/cmake/plugins.cmake +++ b/cmake/plugins.cmake @@ -1,12 +1,16 @@ # plugin configuration MACRO(REGISTER_PLUGIN name source struct type target allow) + SET(PLUGIN_TYPE ${${name}}) + IF(NOT PLUGIN_TYPE STREQUAL "OFF") + SET(PLUGIN_TYPE ${type}) + ENDIF() IF(PLUGINS) LIST(REMOVE_ITEM PLUGINS ${name}) ENDIF() SET(${name}_PLUGIN_SOURCE ${source}) MARK_AS_ADVANCED(${name}_PLUGIN_SOURCE}) - SET(${name}_PLUGIN_TYPE ${type}) + SET(${name}_PLUGIN_TYPE ${PLUGIN_TYPE}) IF(NOT ${target} STREQUAL "") SET(${name}_PLUGIN_TARGET ${target}) ENDIF() @@ -40,7 +44,8 @@ ENDIF() REGISTER_PLUGIN("TRACE_EXAMPLE" "${CMAKE_SOURCE_DIR}/plugins/trace/trace_example.c" "trace_example_plugin" "DYNAMIC" "trace_example" 1) #Connection -REGISTER_PLUGIN("REPLICATION" "${CMAKE_SOURCE_DIR}/plugins/connection/replication.c" "connection_replication_plugin" "STATIC" "" 1) +REGISTER_PLUGIN("REPLICATION" "${CMAKE_SOURCE_DIR}/plugins/connection/replication.c" "connection_replication_plugin" "DYNAMIC" "" 1) +REGISTER_PLUGIN("AURORA" "${CMAKE_SOURCE_DIR}/plugins/connection/aurora.c" "connection_aurora_plugin" "DYNAMIC" "" 1) # Allow registration of additional plugins IF(PLUGIN_CONF_FILE) @@ -50,7 +55,7 @@ ENDIF() SET(LIBMARIADB_SOURCES "") -MESSAGE(STATUS "Plugin configuration") +MESSAGE(STATUS "Plugin configuration:") FOREACH(PLUGIN ${PLUGINS}) IF(WITH_${PLUGIN}_PLUGIN AND ${${PLUGIN}_PLUGIN_CHG} GREATER 0) SET(${PLUGIN}_PLUGIN_TYPE ${WITH_${PLUGIN}_PLUGIN}) @@ -72,6 +77,6 @@ ENDIF() LIST(REMOVE_DUPLICATES LIBMARIADB_SOURCES) CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/libmariadb/client_plugin.c.in - ${CMAKE_BINARY_DIR}/libmariadb/client_plugin.c) + ${CMAKE_BINARY_DIR}/libmariadb/client_plugin.c) MARK_AS_ADVANCED(LIBMARIADB_SOURCES) diff --git a/include/errmsg.h b/include/errmsg.h index 8a91519a..0af17b20 100644 --- a/include/errmsg.h +++ b/include/errmsg.h @@ -84,7 +84,8 @@ extern const char *mariadb_client_errors[]; /* Error messages */ #define CR_EVENT_CREATE_FAILED 5000 #define CR_BIND_ADDR_FAILED 5001 -#define CR_FUNCTION_NOT_SUPPORTED 5002 +#define CR_ASYNC_NOT_SUPPORTED 5002 +#define CR_FUNCTION_NOT_SUPPORTED 5003 #define SQLSTATE_UNKNOWN "HY000" diff --git a/include/ma_common.h b/include/ma_common.h index 6d61f1f0..ff5837f9 100644 --- a/include/ma_common.h +++ b/include/ma_common.h @@ -48,12 +48,15 @@ struct st_mysql_options_extension { double progress, const char *proc_info, unsigned int proc_info_length); - MARIADB_DB_DRIVER *db_driver; + MARIADB_DB_DRIVER *db_driver; char *ssl_fp; /* finger print of server certificate */ char *ssl_fp_list; /* white list of finger prints */ char *ssl_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 */ + my_bool read_only; + HASH userdata; }; #define OPT_HAS_EXT_VAL(a,key) \ diff --git a/include/ma_pvio.h b/include/ma_pvio.h index 0fada961..7ac4be94 100644 --- a/include/ma_pvio.h +++ b/include/ma_pvio.h @@ -50,7 +50,8 @@ enum enum_pvio_io_event enum enum_pvio_type { PVIO_TYPE_UNIXSOCKET= 0, PVIO_TYPE_SOCKET, - PVIO_TYPE_NAMEDPIPE + PVIO_TYPE_NAMEDPIPE, + PVIO_TYPE_SHAREDMEM, }; enum enum_pvio_operation { diff --git a/include/ma_ssl.h b/include/ma_ssl.h index ded44e3e..b994f08c 100644 --- a/include/ma_ssl.h +++ b/include/ma_ssl.h @@ -16,6 +16,11 @@ typedef struct st_ma_pvio_ssl { void *ssl; } MARIADB_SSL; +struct st_ssl_version { + unsigned int iversion; + char *cversion; +}; + /* Function prototypes */ /* ma_ssl_start @@ -124,6 +129,17 @@ const char *ma_ssl_get_cipher(MARIADB_SSL *ssl); */ unsigned int ma_ssl_get_finger_print(MARIADB_SSL *cssl, unsigned char *fp, unsigned int fp_len); +/* ma_ssl_get_protocol_version + returns protocol version in use + Parameter: + MARIADB_SSL MariaDB SSL container + version pointer to ssl version info + Returns: + 0 success + 1 error +*/ +my_bool ma_ssl_get_protocol_version(MARIADB_SSL *cssl, struct st_ssl_version *version); + /* Function prototypes */ MARIADB_SSL *ma_pvio_ssl_init(MYSQL *mysql); my_bool ma_pvio_ssl_connect(MARIADB_SSL *cssl); @@ -134,5 +150,6 @@ int ma_pvio_ssl_verify_server_cert(MARIADB_SSL *cssl); const char *ma_pvio_ssl_cipher(MARIADB_SSL *cssl); my_bool ma_pvio_ssl_check_fp(MARIADB_SSL *cssl, const char *fp, const char *fp_list); my_bool ma_pvio_start_ssl(MARIADB_PVIO *pvio); +my_bool ma_pvio_ssl_get_protocol_version(MARIADB_SSL *cssl, struct st_ssl_version *version); #endif /* _ma_ssl_h_ */ diff --git a/include/my_context.h b/include/my_context.h index 591a064a..b66482a4 100644 --- a/include/my_context.h +++ b/include/my_context.h @@ -112,7 +112,6 @@ struct my_context { }; #endif - /* Initialize an asynchroneous context object. Returns 0 on success, non-zero on failure. diff --git a/include/my_stmt.h b/include/my_stmt.h index 77046caf..0dfb1ba1 100644 --- a/include/my_stmt.h +++ b/include/my_stmt.h @@ -165,6 +165,7 @@ struct st_mysqlnd_stmt_methods 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); diff --git a/include/mysql.h b/include/mysql.h index b262af85..57d4da76 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -215,7 +215,38 @@ extern unsigned int mariadb_deinitialize_ssl; MARIADB_OPT_SSL_FP_LIST, /* finger print white list for server certificate verification */ MARIADB_OPT_SSL_PASSWORD, /* password for encrypted certificates */ MARIADB_OPT_COM_MULTI, - MARIADB_OPT_CONNECTION_READ_ONLY + MARIADB_OPT_CONNECTION_READ_ONLY, + MYSQL_OPT_CONNECT_ATTRS, /* for mysql_get_optionv */ + MARIADB_OPT_USERDATA + }; + + enum mariadb_value { + MARIADB_CHARSET_ID, + MARIADB_CHARSET_INFO, + MARIADB_CHARSET_NAME, + MARIADB_CLIENT_ERRORS, + MARIADB_CLIENT_VERSION, + MARIADB_CLIENT_VERSION_ID, + MARIADB_CONNECTION_ASYNC_TIMEOUT, + MARIADB_CONNECTION_ASYNC_TIMEOUT_MS, + 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_SSL_CIPHER, + MARIADB_CONNECTION_SSL_VERSION, + MARIADB_CONNECTION_SSL_VERSION_ID, + MARIADB_CONNECTION_TYPE, + MARIADB_CONNECTION_UNIX_SOCKET, + MARIADB_CONNECTION_USER, + MARIADB_MAX_ALLOWED_PACKET, + MARIADB_NET_BUFFER_LENGTH }; enum mysql_status { MYSQL_STATUS_READY, @@ -407,12 +438,13 @@ 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 STDCALL 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); -int STDCALL mysql_ssl_clear(MYSQL *mysql); MYSQL * STDCALL mysql_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd); my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, @@ -471,7 +503,6 @@ unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql, void STDCALL mysql_debug(const char *debug); #define mysql_debug_init(A) mysql_debug((A)); void STDCALL mysql_debug_end(void); -void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name); unsigned int STDCALL mysql_thread_safe(void); unsigned int STDCALL mysql_warning_count(MYSQL *mysql); const char * STDCALL mysql_sqlstate(MYSQL *mysql); @@ -485,16 +516,19 @@ 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); -CHARSET_INFO * STDCALL mysql_get_charset_by_name(const char *csname); -CHARSET_INFO * STDCALL mysql_get_charset_by_nr(unsigned int csnr); +CHARSET_INFO * STDCALL mariadb_get_charset_by_name(const char *csname); +CHARSET_INFO * STDCALL mariadb_get_charset_by_nr(unsigned int csnr); size_t STDCALL mariadb_convert_string(const char *from, size_t *from_len, CHARSET_INFO *from_cs, char *to, size_t *to_len, CHARSET_INFO *to_cs, int *errorcode); int STDCALL mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...); +int STDCALL mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...); +int STDCALL mysql_get_option(MYSQL *mysql, enum mysql_option option, void *arg); MYSQL_PARAMETERS *STDCALL mysql_get_parameters(void); unsigned long STDCALL mysql_hex_string(char *to, const char *from, size_t len); -my_socket STDCALL mysql_get_socket(const MYSQL *mysql); +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 mysql_reconnect(MYSQL *mysql); /* Async API */ int STDCALL mysql_close_start(MYSQL *sock); @@ -607,6 +641,128 @@ int STDCALL mysql_stmt_send_long_data_cont(my_bool *ret, MYSQL_STMT *stmt, int status); +/* API function calls (used by dynmic plugins) */ +struct st_mariadb_api { + 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); + char * (STDCALL *mysql_error)(MYSQL *mysql); + 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 (STDCALL *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); + MYSQL * (STDCALL *mysql_connect)(MYSQL *mysql, const char *host, const char *user, const char *passwd); + 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, size_t length); + my_bool (STDCALL *mysql_read_query_result)(MYSQL *mysql); + int (STDCALL *mysql_real_query)(MYSQL *mysql, const char *q, size_t length); + int (STDCALL *mysql_create_db)(MYSQL *mysql, const char *DB); + int (STDCALL *mysql_drop_db)(MYSQL *mysql, const char *DB); + 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, my_ulonglong 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); + void (STDCALL *mysql_debug)(const char *debug); + void (STDCALL *mysql_debug_end)(void); + 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); + CHARSET_INFO * (STDCALL *mariadb_get_charset_by_name)(const char *csname); + CHARSET_INFO * (STDCALL *mariadb_get_charset_by_nr)(unsigned int csnr); + size_t (STDCALL *mariadb_convert_string)(const char *from, size_t *from_len, CHARSET_INFO *from_cs, char *to, size_t *to_len, CHARSET_INFO *to_cs, int *errorcode); + int (STDCALL *mysql_optionsv)(MYSQL *mysql,enum mysql_option option, ...); + int (STDCALL *mysql_get_optionv)(MYSQL *mysql, enum mysql_option option, void *arg, ...); + int (STDCALL *mysql_get_option)(MYSQL *mysql, enum mysql_option option, void *arg); + MYSQL_PARAMETERS *(STDCALL *mysql_get_parameters)(void); + unsigned long (STDCALL *mysql_hex_string)(char *to, const char *from, size_t 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 *mysql_reconnect)(MYSQL *mysql); + MYSQL_STMT * (STDCALL *mysql_stmt_init)(MYSQL *mysql); + int (STDCALL *mysql_stmt_prepare)(MYSQL_STMT *stmt, const char *query, size_t 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, size_t 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, my_ulonglong offset); + my_ulonglong (STDCALL *mysql_stmt_num_rows)(MYSQL_STMT *stmt); + my_ulonglong (STDCALL *mysql_stmt_affected_rows)(MYSQL_STMT *stmt); + my_ulonglong (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); +}; /* these methods can be overwritten by db plugins */ struct st_mysql_methods { @@ -630,6 +786,8 @@ struct st_mysql_methods { 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; }; /* synonyms/aliases functions */ diff --git a/include/mysql/client_plugin.h b/include/mysql/client_plugin.h index f9c4199b..616de69e 100644 --- a/include/mysql/client_plugin.h +++ b/include/mysql/client_plugin.h @@ -95,6 +95,7 @@ typedef struct st_ma_connection_plugin int (*options)(MYSQL *mysql, enum mysql_option, void *arg); 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); } MARIADB_CONNECTION_PLUGIN; #define MARIADB_DB_DRIVER(a) ((a)->ext_db) diff --git a/include/mysql_com.h b/include/mysql_com.h index 045e4d72..84e39635 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -240,6 +240,7 @@ typedef struct st_connection_handler { struct st_ma_connection_plugin *plugin; void *data; + my_bool active; my_bool free_data; } MA_CONNECTION_HANDLER; @@ -375,6 +376,12 @@ typedef struct st_udf_init 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 */ diff --git a/libmariadb/CMakeLists.txt b/libmariadb/CMakeLists.txt index 9de5f7d0..92333cce 100644 --- a/libmariadb/CMakeLists.txt +++ b/libmariadb/CMakeLists.txt @@ -35,7 +35,10 @@ SET(EXPORT_SYMBOLS mariadb_dyncol_val_long mariadb_dyncol_val_str mariadb_flush_multi_command - myodbc_remove_escape + mariadb_get_charset_by_name + mariadb_get_charset_by_nr + mariadb_get_info + mariadb_get_infov mysql_affected_rows mysql_autocommit mysql_autocommit_cont @@ -80,6 +83,8 @@ SET(EXPORT_SYMBOLS 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 @@ -125,6 +130,7 @@ SET(EXPORT_SYMBOLS mysql_query mysql_query_cont mysql_query_start + mysql_reconnect mysql_read_query_result mysql_read_query_result_cont mysql_read_query_result_start diff --git a/libmariadb/errmsg.c b/libmariadb/errmsg.c index d228d6b3..936db98e 100644 --- a/libmariadb/errmsg.c +++ b/libmariadb/errmsg.c @@ -149,7 +149,8 @@ const char *mariadb_client_errors[] = { /* 5000 */ "Creating an event failed (Errorcode: %d)", /* 5001 */ "Bind to local interface '-.%64s' failed (Errorcode: %d)", - /* 5002 */ "Server doesn't support function '%s'", + /* 5002 */ "Connection type doesn't support asynchronous IO operations", + /* 5003 */ "Server doesn't support function '%s'", "" }; diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index d2409b35..3e5319f3 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -37,6 +37,7 @@ #include #include #include + #ifdef HAVE_PWD_H #include #endif @@ -66,6 +67,9 @@ #include #endif #include +#ifdef HAVE_SSL +#include +#endif #include #include @@ -127,11 +131,14 @@ struct st_mysql_methods MARIADB_DEFAULT_METHODS; #define native_password_plugin_name "mysql_native_password" +#define IS_CONNHDLR_ACTIVE(mysql)\ + ((mysql)->net.conn_hdlr && (mysql)->net.conn_hdlr->active) + static void end_server(MYSQL *mysql); static void mysql_close_memory(MYSQL *mysql); void read_user_name(char *name); static void append_wild(char *to,char *end,const char *wild); -static my_bool mysql_reconnect(MYSQL *mysql); +my_bool STDCALL mysql_reconnect(MYSQL *mysql); static int cli_report_progress(MYSQL *mysql, uchar *packet, uint length); extern int mysql_client_plugin_init(); @@ -164,7 +171,7 @@ void net_get_error(char *buf, size_t buf_len, else { *error_no= CR_UNKNOWN_ERROR; - memcpy(sqlstate, unknown_sqlstate, SQLSTATE_LENGTH); + memcpy(sqlstate, SQLSTATE_UNKNOWN, SQLSTATE_LENGTH); } } @@ -208,7 +215,7 @@ restart: if (cli_report_progress(mysql, (uchar *)pos, (uint) (len-1))) { /* Wrong packet */ - my_set_error(mysql, CR_MALFORMED_PACKET, unknown_sqlstate, 0); + my_set_error(mysql, CR_MALFORMED_PACKET, SQLSTATE_UNKNOWN, 0); return (packet_error); } goto restart; @@ -367,13 +374,6 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg, DBUG_RETURN(net_add_multi_command(&mysql->net, command, arg, length)); } - if (mysql->net.conn_hdlr && mysql->net.conn_hdlr->data) - { - result= mysql->net.conn_hdlr->plugin->set_connection(mysql, command, arg, length, skipp_check, opt_arg); - if (result== -1) - DBUG_RETURN(result); - } - if (mysql->net.pvio == 0) { /* Do reconnect if possible */ if (mysql_reconnect(mysql)) @@ -385,10 +385,17 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg, if (mysql->status != MYSQL_STATUS_READY || mysql->server_status & SERVER_MORE_RESULTS_EXIST) { - SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate, 0); + SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); goto end; } + if (IS_CONNHDLR_ACTIVE(mysql)) + { + result= mysql->net.conn_hdlr->plugin->set_connection(mysql, command, arg, length, skipp_check, opt_arg); + if (result== -1) + DBUG_RETURN(result); + } + CLEAR_CLIENT_ERROR(mysql); mysql->info=0; @@ -397,13 +404,6 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg, if (!arg) arg=""; - /* check if connection kills itself */ - if (command == COM_PROCESS_KILL) - { - unsigned long thread_id= uint4korr(arg); - if (thread_id == mysql->thread_id) - skipp_check= 1; - } if (net_write_command(net,(uchar) command,arg, length ? length : (ulong) strlen(arg))) { @@ -532,7 +532,7 @@ append_wild(char *to, char *end, const char *wild) /************************************************************************** ** Init debugging if MYSQL_DEBUG environment variable is found **************************************************************************/ -void STDCALL mysql_debug_end() +void STDCALL mysql_debug_end(void) { #ifndef DBUG_OFF DEBUGGER_OFF; @@ -1014,7 +1014,7 @@ MYSQL_DATA *mthd_my_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, if (!(result=(MYSQL_DATA*) my_malloc(sizeof(MYSQL_DATA), MYF(MY_WME | MY_ZEROFILL)))) { - SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(0); } init_alloc_root(&result->alloc,8192,0); /* Assume rowlength < 8192 */ @@ -1033,7 +1033,7 @@ MYSQL_DATA *mthd_my_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, (fields+1)*sizeof(char *)+fields+pkt_len)))) { free_rows(result); - SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(0); } *prev_ptr=cur; @@ -1052,7 +1052,7 @@ MYSQL_DATA *mthd_my_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, if (len > (ulong) (end_to - to)) { free_rows(result); - SET_CLIENT_ERROR(mysql, CR_UNKNOWN_ERROR, unknown_sqlstate, 0); + SET_CLIENT_ERROR(mysql, CR_UNKNOWN_ERROR, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(0); } memcpy(to,(char*) cp,len); to[len]=0; @@ -1158,6 +1158,7 @@ mysql_init(MYSQL *mysql) bzero((char*) (mysql),sizeof(*(mysql))); mysql->options.connect_timeout=CONNECT_TIMEOUT; mysql->charset= default_charset_info; + mysql->methods= &MARIADB_DEFAULT_METHODS; strmov(mysql->net.sqlstate, "00000"); mysql->net.last_error[0]= mysql->net.last_errno= 0; @@ -1244,15 +1245,13 @@ uchar *ma_send_connect_attr(MYSQL *mysql, uchar *buffer) size_t len; uchar *p= hash_element(&mysql->options.extension->connect_attrs, i); - len= *(size_t *)p; + len= strlen((char *)p); buffer= mysql_net_store_length(buffer, len); - p+= sizeof(size_t); memcpy(buffer, p, len); - buffer+= len; - p+= len; - len= *(size_t *)p; + buffer+= (len); + p+= (len + 1); + len= strlen(p); buffer= mysql_net_store_length(buffer, len); - p+= sizeof(size_t); memcpy(buffer, p, len); buffer+= len; } @@ -1304,9 +1303,38 @@ mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, uint port, const char *unix_socket,unsigned long client_flag) { + char *end; + if (!mysql->methods) mysql->methods= &MARIADB_DEFAULT_METHODS; + if (host && (end= strstr(host, "://"))) + { + MARIADB_CONNECTION_PLUGIN *plugin; + char plugin_name[64]; + + bzero(plugin_name, 64); + strncpy(plugin_name, host, MIN(end - host, 63)); + end+= 3; + + if (!(plugin= (MARIADB_CONNECTION_PLUGIN *)mysql_client_find_plugin(mysql, plugin_name, MARIADB_CLIENT_CONNECTION_PLUGIN))) + return NULL; + + if (!(mysql->net.conn_hdlr= (MA_CONNECTION_HANDLER *)my_malloc(sizeof(MA_CONNECTION_HANDLER), MYF(MY_ZEROFILL)))) + { + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return NULL; + } + + /* save URL for reconnect */ + OPT_SET_EXTENDED_VALUE_STR(&mysql->options, url, host); + + mysql->net.conn_hdlr->plugin= plugin; + + if (plugin && plugin->connect) + return plugin->connect(mysql, end, user, passwd, db, port, unix_socket, client_flag); + } + return mysql->methods->db_connect(mysql, host, user, passwd, db, port, unix_socket, client_flag); } @@ -1334,32 +1362,6 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, if (!mysql->methods) mysql->methods= &MARIADB_DEFAULT_METHODS; - /* special case: - * If hostname contains "://", e.g. "repl://localhost", we need to process connection - * by connection plugin - */ - if (host && (end= strstr(host, "://"))) - { - MARIADB_CONNECTION_PLUGIN *plugin; - char plugin_name[64]; - - bzero(plugin_name, 64); - strncpy(plugin_name, host, MIN(end - host, 63)); - end+= 3; - if (!(plugin= (MARIADB_CONNECTION_PLUGIN *)mysql_client_find_plugin(mysql, plugin_name, MARIADB_CLIENT_CONNECTION_PLUGIN))) - DBUG_RETURN(NULL); - - if (!(mysql->net.conn_hdlr= (MA_CONNECTION_HANDLER *)my_malloc(sizeof(MA_CONNECTION_HANDLER), MYF(MY_ZEROFILL)))) - { - SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(NULL); - } - - mysql->net.conn_hdlr->plugin= plugin; - - if (plugin->connect) - return plugin->connect(mysql, end, user, passwd, db, port, unix_socket, client_flag); - } ma_set_connect_attrs(mysql); @@ -1534,7 +1536,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, !(mysql->user=my_strdup(user,MYF(0))) || !(mysql->passwd=my_strdup(passwd,MYF(0)))) { - SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto error; } strmov(mysql->host_info,host_info); @@ -1550,7 +1552,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, { if (!(mysql->server_version= my_strdup(end + sizeof(MA_RPL_VERSION_HACK), 0))) { - SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto error; } is_maria= 1; @@ -1559,7 +1561,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, { if (!(mysql->server_version= my_strdup(end, MYF(0)))) { - SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto error; } } @@ -1622,7 +1624,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, mysql->server_capabilities&= ~CLIENT_SECURE_CONNECTION; if (mysql->options.secure_auth) { - SET_CLIENT_ERROR(mysql, CR_SECURE_AUTH, unknown_sqlstate, 0); + SET_CLIENT_ERROR(mysql, CR_SECURE_AUTH, SQLSTATE_UNKNOWN, 0); goto error; } } @@ -1658,7 +1660,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, { if (mysql_select_db(mysql, db)) { - my_set_error(mysql, CR_SERVER_LOST, unknown_sqlstate, + my_set_error(mysql, CR_SERVER_LOST, SQLSTATE_UNKNOWN, ER(CR_SERVER_LOST_EXTENDED), "Setting intital database", errno); @@ -1680,7 +1682,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, mysql->reconnect= 0; for (;begin < end; begin++) - { + { if (mysql_real_query(mysql, *begin, (unsigned long)strlen(*begin))) goto error; @@ -1736,14 +1738,22 @@ my_suspend_hook(my_bool suspend, void *data) } -static my_bool mysql_reconnect(MYSQL *mysql) +my_bool STDCALL mysql_reconnect(MYSQL *mysql) { MYSQL tmp_mysql; struct my_hook_data hook_data; struct mysql_async_context *ctxt= NULL; + LIST *li_stmt= mysql->stmts; DBUG_ENTER("mysql_reconnect"); + /* check if connection handler is active */ + if (IS_CONNHDLR_ACTIVE(mysql)) + { + if (mysql->net.conn_hdlr->plugin && mysql->net.conn_hdlr->plugin->connect) + DBUG_RETURN(mysql->net.conn_hdlr->plugin->reconnect(mysql)); + } + if (!mysql->reconnect || (mysql->server_status & SERVER_STATUS_IN_TRANS) || !mysql->host_info) { @@ -1755,6 +1765,13 @@ static my_bool mysql_reconnect(MYSQL *mysql) mysql_init(&tmp_mysql); tmp_mysql.options=mysql->options; + if (mysql->net.conn_hdlr) + { + tmp_mysql.net.conn_hdlr= mysql->net.conn_hdlr; + mysql->net.conn_hdlr= 0; + } + + /* don't reread options from configuration files */ tmp_mysql.options.my_cnf_group= tmp_mysql.options.my_cnf_file= NULL; @@ -1783,6 +1800,17 @@ static my_bool mysql_reconnect(MYSQL *mysql) DBUG_RETURN(1); } + for (;li_stmt;li_stmt= li_stmt->next) + { + MYSQL_STMT *stmt= (MYSQL_STMT *)li_stmt->data; + + if (stmt->state != MYSQL_STMT_INITTED) + { + stmt->state= MYSQL_STMT_INITTED; + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + } + } + tmp_mysql.reconnect= mysql->reconnect; tmp_mysql.free_me= mysql->free_me; tmp_mysql.stmts= mysql->stmts; @@ -1799,8 +1827,7 @@ static my_bool mysql_reconnect(MYSQL *mysql) DBUG_RETURN(0); } - -static void ma_invalidate_stmts(MYSQL *mysql, const char *function_name) +void ma_invalidate_stmts(MYSQL *mysql, const char *function_name) { if (mysql->stmts) { @@ -1863,7 +1890,7 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, if (db && !(mysql->db= my_strdup(db,MYF(MY_WME)))) { - SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); rc= 1; } } else @@ -1944,8 +1971,11 @@ static void mysql_close_options(MYSQL *mysql) my_free(mysql->options.extension->ssl_fp); my_free(mysql->options.extension->ssl_fp_list); my_free(mysql->options.extension->ssl_pw); + my_free(mysql->options.extension->url); if(hash_inited(&mysql->options.extension->connect_attrs)) hash_free(&mysql->options.extension->connect_attrs); + if (hash_inited(&mysql->options.extension->userdata)) + hash_free(&mysql->options.extension->userdata); if ((ctxt = mysql->options.extension->async_context) != 0) { my_context_destroy(&ctxt->async_context); @@ -2006,7 +2036,8 @@ mysql_close(MYSQL *mysql) DBUG_ENTER("mysql_close"); if (mysql) /* Some simple safety */ { - if (mysql->net.conn_hdlr && mysql->net.conn_hdlr->data) + + if (IS_CONNHDLR_ACTIVE(mysql)) { void *p= (void *)mysql->net.conn_hdlr; mysql->net.conn_hdlr->plugin->close(mysql); @@ -2019,6 +2050,7 @@ mysql_close(MYSQL *mysql) /* reset the connection in all active statements */ ma_invalidate_stmts(mysql, "mysql_close()"); + mysql_close_memory(mysql); mysql_close_options(mysql); mysql->host_info=mysql->user=mysql->passwd=mysql->db=0; @@ -2069,7 +2101,9 @@ int mthd_my_read_query_result(MYSQL *mysql) DBUG_ENTER("mthd_my_read_query_result"); if (!mysql || (length = net_safe_read(mysql)) == packet_error) + { DBUG_RETURN(1); + } free_old_query(mysql); /* Free old result */ get_info: pos=(uchar*) mysql->net.read_pos; @@ -2151,7 +2185,7 @@ mysql_store_result(MYSQL *mysql) DBUG_RETURN(0); if (mysql->status != MYSQL_STATUS_GET_RESULT) { - SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate, 0); + SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(0); } mysql->status=MYSQL_STATUS_READY; /* server is ready */ @@ -2159,7 +2193,7 @@ mysql_store_result(MYSQL *mysql) sizeof(ulong)*mysql->field_count, MYF(MY_WME | MY_ZEROFILL)))) { - SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(0); } result->eof=1; /* Marker for buffered */ @@ -2201,7 +2235,7 @@ mysql_use_result(MYSQL *mysql) DBUG_RETURN(0); if (mysql->status != MYSQL_STATUS_GET_RESULT) { - SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate, 0); + SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(0); } if (!(result=(MYSQL_RES*) my_malloc(sizeof(*result)+ @@ -2518,13 +2552,12 @@ mysql_stat(MYSQL *mysql) mysql->net.read_pos[mysql->packet_length]=0; /* End of stat string */ if (!mysql->net.read_pos[0]) { - SET_CLIENT_ERROR(mysql, CR_WRONG_HOST_INFO , unknown_sqlstate, 0); + SET_CLIENT_ERROR(mysql, CR_WRONG_HOST_INFO , SQLSTATE_UNKNOWN, 0); return mysql->net.last_error; } DBUG_RETURN((char*) mysql->net.read_pos); } - int STDCALL mysql_ping(MYSQL *mysql) { @@ -2538,16 +2571,15 @@ mysql_ping(MYSQL *mysql) return rc; } - char * STDCALL mysql_get_server_info(MYSQL *mysql) { return((char*) mysql->server_version); } -unsigned long STDCALL mysql_get_server_version(MYSQL *mysql) +static size_t mariadb_server_version_id(MYSQL *mysql) { - long major, minor, patch; + size_t major, minor, patch; char *p; if (!(p = mysql->server_version)) { @@ -2560,7 +2592,12 @@ unsigned long STDCALL mysql_get_server_version(MYSQL *mysql) p += 1; /* consume the dot */ patch = strtol(p, &p, 10); - return (unsigned long)(major * 10000L + (unsigned long)(minor * 100L + patch)); + return (major * 10000L + (unsigned long)(minor * 100L + patch)); +} + +unsigned long STDCALL mysql_get_server_version(MYSQL *mysql) +{ + return (unsigned long)mariadb_server_version_id(mysql); } @@ -2595,21 +2632,17 @@ static size_t get_store_length(size_t length) return 9; } -uchar *ma_get_hash_key(const uchar *hash_entry, +uchar *ma_get_hash_keyval(const uchar *hash_entry, unsigned int *length, my_bool not_used __attribute__((unused))) { /* Hash entry has the following format: - Offset: 0 key length - sizeof(size_t) key - key_length + - sizeof(size_t) value length - value + Offset: 0 key (\0 terminated) + key_length + 1 value (\0 terminated) */ uchar *p= (uchar *)hash_entry; - size_t len=*((size_t*)p); - p+= sizeof(size_t); - *length= (uint)len; + size_t len= strlen(p); + *length= (unsigned int)len; return p; } @@ -2747,7 +2780,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) if (!(ctxt= (struct mysql_async_context *) my_malloc(sizeof(*ctxt), MYF(MY_ZEROFILL)))) { - SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto end; } stacksize= 0; @@ -2765,7 +2798,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) my_malloc(sizeof(struct st_mysql_options_extension), MYF(MY_WME | MY_ZEROFILL)))) { - SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto end; } mysql->options.extension->async_context= ctxt; @@ -2807,19 +2840,19 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) break; case MYSQL_OPT_CONNECT_ATTR_DELETE: { - uchar *p; + uchar *h; CHECK_OPT_EXTENSION_SET(&mysql->options); if (hash_inited(&mysql->options.extension->connect_attrs) && - (p= (uchar *)hash_search(&mysql->options.extension->connect_attrs, (uchar *)arg1, + (h= (uchar *)hash_search(&mysql->options.extension->connect_attrs, (uchar *)arg1, arg1 ? (uint)strlen((char *)arg1) : 0))) { - size_t key_len= *(size_t *)p; - mysql->options.extension->connect_attrs_len-= key_len; - mysql->options.extension->connect_attrs_len-= get_store_length(key_len); - key_len= *(size_t *)(p + sizeof(size_t) + key_len); - mysql->options.extension->connect_attrs_len-= key_len; - mysql->options.extension->connect_attrs_len-= get_store_length(key_len); - hash_delete(&mysql->options.extension->connect_attrs, p); + uchar *p= h; + size_t key_len= strlen(p); + mysql->options.extension->connect_attrs_len-= key_len + get_store_length(key_len); + p+= key_len + 1; + key_len= strlen(p); + mysql->options.extension->connect_attrs_len-= key_len + get_store_length(key_len); + hash_delete(&mysql->options.extension->connect_attrs, h); } } @@ -2832,6 +2865,42 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) mysql->options.extension->connect_attrs_len= 0; } break; + case MARIADB_OPT_USERDATA: + { + void *data= va_arg(ap, void *); + uchar *buffer, *p; + char *key= (char *)arg1; + + if (!key || !data) + { + SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); + goto end; + } + + CHECK_OPT_EXTENSION_SET(&mysql->options); + if (!hash_inited(&mysql->options.extension->userdata)) + { + if (_hash_init(&mysql->options.extension->userdata, + 0, 0, 0, ma_get_hash_keyval, ma_hash_free, 0) || + !(buffer= (uchar *)my_malloc(strlen(key) + 1 + sizeof(void *), MYF(MY_ZEROFILL)))) + { + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + goto end; + } + } + p= buffer; + strcpy(p, key); + p+= strlen(key) + 1; + memcpy(p, &data, sizeof(void *)); + + if (hash_insert(&mysql->options.extension->userdata, buffer)) + { + my_free(buffer); + SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); + goto end; + } + } + break; case MYSQL_OPT_CONNECT_ATTR_ADD: { uchar *buffer; @@ -2841,48 +2910,49 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) size_t storage_len= key_len + value_len + get_store_length(key_len) + get_store_length(value_len); + + /* since we store terminating zero character in hash, we need + * to increase lengths */ + key_len++; + value_len++; CHECK_OPT_EXTENSION_SET(&mysql->options); if (!key_len || storage_len + mysql->options.extension->connect_attrs_len > 0xFFFF) { - SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, unknown_sqlstate, 0); + SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); goto end; } if (!hash_inited(&mysql->options.extension->connect_attrs)) { if (_hash_init(&mysql->options.extension->connect_attrs, - 0, 0, 0, ma_get_hash_key, ma_hash_free, 0)) + 0, 0, 0, ma_get_hash_keyval, ma_hash_free, 0)) { - SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto end; } } - if ((buffer= (uchar *)my_malloc(2 * sizeof(size_t) + key_len + value_len, + if ((buffer= (uchar *)my_malloc(key_len + value_len, MYF(MY_WME | MY_ZEROFILL)))) { uchar *p= buffer; - *((size_t *)p)= key_len; - p+= sizeof(size_t); - memcpy(p, arg1, key_len); - p+= key_len; - *((size_t *)p)= value_len; - p+= sizeof(size_t); + strcpy(p, arg1); + p+= (strlen(arg1) + 1); if (arg2) - memcpy(p, arg2, value_len); + strcpy(p, arg2); if (hash_insert(&mysql->options.extension->connect_attrs, buffer)) { my_free(buffer); - SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, unknown_sqlstate, 0); + SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); goto end; } mysql->options.extension->connect_attrs_len+= storage_len; } else { - SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto end; } } @@ -2905,11 +2975,6 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) case MARIADB_OPT_SSL_PASSWORD: OPT_SET_EXTENDED_VALUE_STR(&mysql->options, ssl_pw, (char *)arg1); break; - case MARIADB_OPT_CONNECTION_READ_ONLY: - if (mysql->net.conn_hdlr) - DBUG_RETURN(mysql->net.conn_hdlr->plugin->options(mysql, MARIADB_OPT_CONNECTION_READ_ONLY, arg1)); - else - return -1; case MARIADB_OPT_COM_MULTI: if (&mysql->net.pvio && (mysql->server_capabilities & MARIADB_CLIENT_EXTENDED_FLAGS)) @@ -2919,6 +2984,9 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) else DBUG_RETURN(-1); break; + case MARIADB_OPT_CONNECTION_READ_ONLY: + OPT_SET_EXTENDED_VALUE_INT(&mysql->options, read_only, *(my_bool *)arg1); + break; default: va_end(ap); DBUG_RETURN(-1); @@ -2930,6 +2998,200 @@ end: DBUG_RETURN(1); } +int STDCALL +mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...) +{ + va_list ap; + + DBUG_ENTER("mariadb_get_optionv"); + DBUG_PRINT("enter",("option: %d",(int) option)); + + va_start(ap, arg); + + switch(option) { + case MYSQL_OPT_CONNECT_TIMEOUT: + *((uint *)arg)= mysql->options.connect_timeout; + break; + case MYSQL_OPT_COMPRESS: + *((my_bool *)arg)= mysql->options.compress; + break; + case MYSQL_OPT_NAMED_PIPE: + *((my_bool *)arg)= mysql->options.named_pipe; + break; + case MYSQL_OPT_LOCAL_INFILE: /* Allow LOAD DATA LOCAL ?*/ + *((uint *)arg)= test(mysql->options.client_flag & CLIENT_LOCAL_FILES); + break; + case MYSQL_INIT_COMMAND: + /* mysql_get_optionsv(mysql, MYSQL_INIT_COMMAND, commands, elements) */ + { + unsigned int *elements; + if (arg) + *((char **)arg)= mysql->options.init_command ? mysql->options.init_command->buffer : NULL; + if ((elements= va_arg(ap, unsigned int *))) + *elements= mysql->options.init_command ? mysql->options.init_command->elements : 0; + } + break; + case MYSQL_READ_DEFAULT_FILE: + *((char **)arg)= mysql->options.my_cnf_file; + break; + case MYSQL_READ_DEFAULT_GROUP: + *((char **)arg)= mysql->options.my_cnf_group; + break; + case MYSQL_SET_CHARSET_DIR: + /* not supported in this version. Since all character sets + are internally available, we don't throw an error */ + *((char **)arg)= NULL; + break; + case MYSQL_SET_CHARSET_NAME: + *((char **)arg)= mysql->options.charset_name; + break; + case MYSQL_OPT_RECONNECT: + *((uint *)arg)= mysql->reconnect; + break; + case MYSQL_OPT_PROTOCOL: + *((uint *)arg)= mysql->options.protocol; + break; + case MYSQL_OPT_READ_TIMEOUT: + *((uint *)arg)= mysql->options.read_timeout; + break; + case MYSQL_OPT_WRITE_TIMEOUT: + *((uint *)arg)= mysql->options.write_timeout; + break; + case MYSQL_REPORT_DATA_TRUNCATION: + *((uint *)arg)= mysql->options.report_data_truncation; + break; + case MYSQL_PROGRESS_CALLBACK: + *((void (**)(const MYSQL *, uint, uint, double, const char *, uint))arg)= + mysql->options.extension ? mysql->options.extension->report_progress : NULL; + break; + case MYSQL_PLUGIN_DIR: + *((char **)arg)= mysql->options.extension ? mysql->options.extension->plugin_dir : NULL; + break; + case MYSQL_DEFAULT_AUTH: + *((char **)arg)= mysql->options.extension ? mysql->options.extension->default_auth : NULL; + break; + case MYSQL_OPT_NONBLOCK: + *((my_bool *)arg)= test(mysql->options.extension && mysql->options.extension->async_context); + break; + case MYSQL_OPT_SSL_VERIFY_SERVER_CERT: + *((my_bool *)arg)= test(mysql->options.client_flag & CLIENT_SSL_VERIFY_SERVER_CERT); + break; + case MYSQL_OPT_SSL_KEY: + *((char **)arg)= mysql->options.ssl_key; + break; + case MYSQL_OPT_SSL_CERT: + *((char **)arg)= mysql->options.ssl_cert; + break; + case MYSQL_OPT_SSL_CA: + *((char **)arg)= mysql->options.ssl_ca; + break; + case MYSQL_OPT_SSL_CAPATH: + *((char **)arg)= mysql->options.ssl_capath; + break; + case MYSQL_OPT_SSL_CIPHER: + *((char **)arg)= mysql->options.ssl_cipher; + break; + case MYSQL_OPT_SSL_CRL: + *((char **)arg)= mysql->options.extension ? mysql->options.ssl_cipher : NULL; + break; + case MYSQL_OPT_SSL_CRLPATH: + *((char **)arg)= mysql->options.extension ? mysql->options.extension->ssl_crlpath : NULL; + break; + case MYSQL_OPT_CONNECT_ATTRS: + /* mysql_get_optionsv(mysql, MYSQL_OPT_CONNECT_ATTRS, keys, vals, elements) */ + { + int i, *elements; + char **key= NULL; + void *arg1; + char **val= NULL; + + if (arg) + key= *(char ***)arg; + + arg1= va_arg(ap, char **); + if (arg1) + val= *(char ***)arg1; + + if (!(elements= va_arg(ap, unsigned int *))) + goto error; + + if (!elements) + goto error; + + *elements= 0; + + if (!mysql->options.extension || + !hash_inited(&mysql->options.extension->connect_attrs)) + break; + + *elements= mysql->options.extension->connect_attrs.records; + + if (val || key) + { + for (i=0; i < *elements; i++) + { + uchar *p= hash_element(&mysql->options.extension->connect_attrs, i); + if (key) + key[i]= p; + p+= strlen(p) + 1; + if (val) + val[i]= p; + } + } + } + break; + case MYSQL_SECURE_AUTH: + *((my_bool *)arg)= mysql->options.secure_auth; + break; + case MYSQL_OPT_BIND: + *((char **)arg)= mysql->options.bind_address; + break; + case MARIADB_OPT_SSL_FP: + *((char **)arg)= mysql->options.extension ? mysql->options.extension->ssl_fp : NULL; + break; + case MARIADB_OPT_SSL_FP_LIST: + *((char **)arg)= mysql->options.extension ? mysql->options.extension->ssl_fp_list : NULL; + break; + case MARIADB_OPT_SSL_PASSWORD: + *((char **)arg)= mysql->options.extension ? mysql->options.extension->ssl_pw : NULL; + break; + /* todo + case MARIADB_OPT_CONNECTION_READ_ONLY: + break; + */ + case MARIADB_OPT_USERDATA: + /* nysql_get_optionv(mysql, MARIADB_OPT_USERDATA, key, value) */ + { + uchar *p; + void *data= va_arg(ap, void *); + char *key= (char *)arg; + if (key && data && mysql->options.extension && hash_inited(&mysql->options.extension->userdata) && + (p= (uchar *)hash_search(&mysql->options.extension->userdata, (uchar *)key, + (uint)strlen((char *)key)))) + { + p+= strlen(key) + 1; + *((void **)data)= *((void **)p); + break; + } + if (data) + *((void **)data)= NULL; + } + break; + default: + va_end(ap); + DBUG_RETURN(-1); + } + va_end(ap); + DBUG_RETURN(0); +error: + va_end(ap); + DBUG_RETURN(-1); +} + +int STDCALL mysql_get_option(MYSQL *mysql, enum mysql_option option, void *arg) +{ + return mysql_get_optionv(mysql, option, arg); +} int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg) @@ -2937,7 +3199,6 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg) return mysql_optionsv(mysql, option, arg); } - /**************************************************************************** ** Functions to get information from the MySQL structure ** These are functions to make shared libraries more usable. @@ -3044,7 +3305,7 @@ int STDCALL mysql_next_result(MYSQL *mysql) /* make sure communication is not blocking */ if (mysql->status != MYSQL_STATUS_READY) { - SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate, 0); + SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); } @@ -3106,35 +3367,9 @@ mysql_real_escape_string(MYSQL *mysql, char *to,const char *from, return (ulong)mysql_cset_escape_slashes(mysql->charset, to, from, length); } -void STDCALL -myodbc_remove_escape(MYSQL *mysql,char *name) +static void mariadb_get_charset_info(MYSQL *mysql, MY_CHARSET_INFO *cs) { - char *to; - my_bool use_mb_flag= (mysql->charset->char_maxlen > 1); - char *end= 0; - if (use_mb_flag) - for (end=name; *end ; end++) ; - - for (to=name ; *name ; name++) - { - int l; - if (use_mb_flag && (l = mysql->charset->mb_valid(name , end))) - { - while (l--) - *to++ = *name++; - name--; - continue; - } - if (*name == '\\' && name[1]) - name++; - *to++= *name; - } - *to=0; -} - -void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *cs) -{ - DBUG_ENTER("mysql_get_character_set_info"); + DBUG_ENTER("mariadb_get_charset_info"); if (!cs) DBUG_VOID_RETURN; @@ -3151,6 +3386,11 @@ void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *cs) DBUG_VOID_RETURN; } +void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *cs) +{ + mariadb_get_charset_info(mysql, cs); +} + int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname) { const CHARSET_INFO *cs; @@ -3247,7 +3487,7 @@ void STDCALL mysql_server_end() my_init_done= 0; } -my_bool STDCALL mysql_thread_init() +my_bool STDCALL mysql_thread_init(void) { #ifdef THREAD return my_thread_init(); @@ -3255,7 +3495,7 @@ my_bool STDCALL mysql_thread_init() return 0; } -void STDCALL mysql_thread_end() +void STDCALL mysql_thread_end(void) { #ifdef THREAD my_thread_end(); @@ -3312,8 +3552,7 @@ mysql_get_parameters(void) return &mariadb_internal_parameters; } -my_socket STDCALL -mysql_get_socket(const MYSQL *mysql) +static my_socket mariadb_get_socket(MYSQL *mysql) { my_socket sock= INVALID_SOCKET; if (mysql->net.pvio) @@ -3350,6 +3589,339 @@ int STDCALL mariadb_flush_multi_command(MYSQL *mysql) return rc; } +my_socket STDCALL +mysql_get_socket(MYSQL *mysql) +{ + return mariadb_get_socket(mysql); +} + +CHARSET_INFO * STDCALL mariadb_get_charset_by_name(const char *csname) +{ + return (CHARSET_INFO *)mysql_find_charset_name(csname); +} + +CHARSET_INFO * STDCALL mariadb_get_charset_by_nr(unsigned int csnr) +{ + return (CHARSET_INFO *)mysql_find_charset_nr(csnr); +} + +my_bool STDCALL mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void *arg, ...) +{ + va_list ap; + + DBUG_ENTER("mariadb_get_valuev"); + DBUG_PRINT("enter",("value: %d",(int) value)); + + va_start(ap, arg); + + switch(value) { + case MARIADB_MAX_ALLOWED_PACKET: + *((size_t *)arg)= (size_t)max_allowed_packet; + break; + case MARIADB_NET_BUFFER_LENGTH: + *((size_t *)arg)= (size_t)net_buffer_length; + break; + case MARIADB_CONNECTION_SSL_VERSION: + #ifdef HAVE_SSL + if (mysql && mysql->net.pvio && mysql->net.pvio->cssl) + { + struct st_ssl_version version; + if (!ma_pvio_ssl_get_protocol_version(mysql->net.pvio->cssl, &version)) + *((char **)arg)= version.cversion; + } + else + #endif + goto error; + break; + case MARIADB_CONNECTION_SSL_VERSION_ID: + #ifdef HAVE_SSL + if (mysql && mysql->net.pvio && mysql->net.pvio->cssl) + { + struct st_ssl_version version; + if (!ma_pvio_ssl_get_protocol_version(mysql->net.pvio->cssl, &version)) + *((unsigned int *)arg)= version.iversion; + } + else + #endif + goto error; + break; + case MARIADB_CLIENT_VERSION: + *((char **)arg)= MYSQL_CLIENT_VERSION; + break; + case MARIADB_CLIENT_VERSION_ID: + *((size_t *)arg)= MYSQL_VERSION_ID; + break; + case MARIADB_CONNECTION_SERVER_VERSION: + if (mysql) + *((char **)arg)= mysql->server_version; + else + goto error; + break; + case MARIADB_CONNECTION_SERVER_TYPE: + if (mysql) + *((char **)arg)= mariadb_connection(mysql) ? "MariaDB" : "MySQL"; + else + goto error; + break; + case MARIADB_CONNECTION_SERVER_VERSION_ID: + if (mysql) + *((size_t *)arg)= mariadb_server_version_id(mysql); + else + goto error; + break; + case MARIADB_CONNECTION_PROTOCOL_VERSION_ID: + if (mysql) + *((unsigned int *)arg)= mysql->protocol_version; + else + goto error; + break; + case MARIADB_CHARSET_INFO: + if (mysql) + mariadb_get_charset_info(mysql, (MY_CHARSET_INFO *)arg); + else + goto error; + break; + case MARIADB_CONNECTION_SOCKET: + if (mysql) + *((my_socket *)arg)= mariadb_get_socket(mysql); + else + goto error; + break; + case MARIADB_CONNECTION_TYPE: + if (mysql && mysql->net.pvio) + *((int *)arg)= (int)mysql->net.pvio->type; + else + goto error; + break; + case MARIADB_CONNECTION_ASYNC_TIMEOUT_MS: + if (mysql && mysql->options.extension && mysql->options.extension->async_context) + *((unsigned int *)arg)= mysql->options.extension->async_context->timeout_value; + else + goto error; + break; + case MARIADB_CONNECTION_ASYNC_TIMEOUT: + if (mysql && mysql->options.extension && mysql->options.extension->async_context) + { + unsigned int timeout= mysql->options.extension->async_context->timeout_value; + if (timeout > UINT_MAX - 999) + *((unsigned int *)arg)= (timeout - 1)/1000 + 1; + else + *((unsigned int *)arg)= (timeout+999)/1000; + } + else + goto error; + break; + case MARIADB_CHARSET_NAME: + { + char *name; + name= va_arg(ap, char *); + if (name) + *((CHARSET_INFO **)arg)= (CHARSET_INFO *)mysql_find_charset_name(name); + else + goto error; + } + break; + case MARIADB_CHARSET_ID: + { + unsigned int nr; + nr= va_arg(ap, unsigned int); + *((CHARSET_INFO **)arg)= (CHARSET_INFO *)mysql_find_charset_nr(nr); + } + break; + case MARIADB_CONNECTION_SSL_CIPHER: + #ifdef HAVE_SSL + if (mysql && mysql->net.pvio && mysql->net.pvio->cssl) + *((char **)arg)= (char *)ma_pvio_ssl_cipher(mysql->net.pvio->cssl); + else + #endif + goto error; + break; + case MARIADB_CLIENT_ERRORS: + *((char ***)arg)= (char **)client_errors; + break; + case MARIADB_CONNECTION_INFO: + if (mysql) + *((char **)arg)= (char *)mysql->info; + else + goto error; + break; + case MARIADB_CONNECTION_PVIO_TYPE: + if (mysql && !mysql->net.pvio) + *((unsigned int *)arg)= (unsigned int)mysql->net.pvio->type; + else + goto error; + break; + case MARIADB_CONNECTION_SCHEMA: + if (mysql) + *((char **)arg)= mysql->db; + else + goto error; + break; + case MARIADB_CONNECTION_USER: + if (mysql) + *((char **)arg)= mysql->user; + else + goto error; + break; + case MARIADB_CONNECTION_PORT: + if (mysql) + *((unsigned int *)arg)= mysql->port; + else + goto error; + break; + case MARIADB_CONNECTION_UNIX_SOCKET: + if (mysql) + *((char **)arg)= mysql->unix_socket; + else + goto error; + break; + case MARIADB_CONNECTION_HOST: + if (mysql) + *((char **)arg)= mysql->host; + else + goto error; + break; + default: + va_end(ap); + DBUG_RETURN(-1); + } + va_end(ap); + DBUG_RETURN(0); +error: + va_end(ap); + DBUG_RETURN(-1); +} + +my_bool STDCALL mariadb_get_info(MYSQL *mysql, enum mariadb_value value, void *arg) +{ + return mariadb_get_infov(mysql, value, arg); +} + +#undef STDCALL +/* API functions for usage in dynamic plugins */ +struct st_mariadb_api MARIADB_API= +{ + mysql_num_rows, + mysql_num_fields, + mysql_eof, + mysql_fetch_field_direct, + mysql_fetch_fields, + mysql_row_tell, + mysql_field_tell, + mysql_field_count, + mysql_more_results, + mysql_next_result, + mysql_affected_rows, + mysql_autocommit, + mysql_commit, + mysql_rollback, + mysql_insert_id, + mysql_errno, + mysql_error, + mysql_info, + mysql_thread_id, + mysql_character_set_name, + mysql_get_character_set_info, + mysql_set_character_set, + mariadb_get_infov, + mariadb_get_info, + mysql_init, + mysql_ssl_set, + mysql_get_ssl_cipher, + mysql_connect, + mysql_change_user, + mysql_real_connect, + mysql_close, + mysql_select_db, + mysql_query, + mysql_send_query, + mysql_read_query_result, + mysql_real_query, + mysql_create_db, + mysql_drop_db, + mysql_shutdown, + mysql_dump_debug_info, + mysql_refresh, + mysql_kill, + mysql_ping, + mysql_stat, + mysql_get_server_info, + mysql_get_server_version, + mysql_get_host_info, + mysql_get_proto_info, + mysql_list_dbs, + mysql_list_tables, + mysql_list_fields, + mysql_list_processes, + mysql_store_result, + mysql_use_result, + mysql_options, + mysql_free_result, + mysql_data_seek, + mysql_row_seek, + mysql_field_seek, + mysql_fetch_row, + mysql_fetch_lengths, + mysql_fetch_field, + mysql_escape_string, + mysql_real_escape_string, + mysql_debug, + mysql_debug_end, + mysql_thread_safe, + mysql_warning_count, + mysql_sqlstate, + mysql_server_init, + mysql_server_end, + mysql_thread_end, + mysql_thread_init, + mysql_set_server_option, + mysql_get_client_info, + mysql_get_client_version, + mariadb_connection, + mysql_get_server_name, + mariadb_get_charset_by_name, + mariadb_get_charset_by_nr, + mariadb_convert_string, + mysql_optionsv, + mysql_get_optionv, + mysql_get_option, + mysql_get_parameters, + mysql_hex_string, + mysql_get_socket, + mysql_get_timeout_value, + mysql_get_timeout_value_ms, + mysql_reconnect, + mysql_stmt_init, + mysql_stmt_prepare, + mysql_stmt_execute, + mysql_stmt_fetch, + mysql_stmt_fetch_column, + mysql_stmt_store_result, + mysql_stmt_param_count, + mysql_stmt_attr_set, + mysql_stmt_attr_get, + mysql_stmt_bind_param, + mysql_stmt_bind_result, + mysql_stmt_close, + mysql_stmt_reset, + mysql_stmt_free_result, + mysql_stmt_send_long_data, + mysql_stmt_result_metadata, + mysql_stmt_param_metadata, + mysql_stmt_errno, + mysql_stmt_error, + mysql_stmt_sqlstate, + mysql_stmt_row_seek, + mysql_stmt_row_tell, + mysql_stmt_data_seek, + mysql_stmt_num_rows, + mysql_stmt_affected_rows, + mysql_stmt_insert_id, + mysql_stmt_field_count, + mysql_stmt_next_result, + mysql_stmt_more_results +}; + /* * Default methods for a connection. These methods are * stored in mysql->methods and can be overwritten by @@ -3387,5 +3959,10 @@ struct st_mysql_methods MARIADB_DEFAULT_METHODS = { /* store values in bind buffer */ mthd_stmt_fetch_to_bind, /* skip unbuffered stmt result */ - mthd_stmt_flush_unbuffered + mthd_stmt_flush_unbuffered, + /* set error */ + my_set_error, + /* invalidate statements */ + ma_invalidate_stmts, + &MARIADB_API }; diff --git a/libmariadb/ma_dyncol.c b/libmariadb/ma_dyncol.c index c7c3b66d..aa8391b6 100644 --- a/libmariadb/ma_dyncol.c +++ b/libmariadb/ma_dyncol.c @@ -1114,7 +1114,7 @@ dynamic_column_string_read(DYNAMIC_COLUMN_VALUE *store_it_here, #ifndef LIBMARIADB store_it_here->x.string.charset= get_charset_by_nr(charset_nr); #else - store_it_here->x.string.charset= mysql_get_charset_by_nr(charset_nr); + store_it_here->x.string.charset= mariadb_get_charset_by_nr(charset_nr); #endif if (store_it_here->x.string.charset == NULL) return ER_DYNCOL_UNKNOWN_CHARSET; diff --git a/libmariadb/ma_pvio.c b/libmariadb/ma_pvio.c index 2f9d2744..054ef45d 100644 --- a/libmariadb/ma_pvio.c +++ b/libmariadb/ma_pvio.c @@ -71,7 +71,7 @@ MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo) * pvio_socket * pvio_namedpipe */ - char *pvio_plugins[] = {"pvio_socket", "pvio_npipe"}; + char *pvio_plugins[] = {"pvio_socket", "pvio_npipe", "pvio_shmem"}; int type; MARIADB_PVIO_PLUGIN *pvio_plugin; MARIADB_PVIO *pvio= NULL; @@ -86,6 +86,9 @@ MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo) case PVIO_TYPE_NAMEDPIPE: type= 1; break; + case PVIO_TYPE_SHAREDMEM: + type= 2; + break; #endif default: return NULL; @@ -96,7 +99,6 @@ MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo) pvio_plugins[type], MARIADB_CLIENT_PVIO_PLUGIN))) { - /* error handling */ return NULL; } @@ -111,6 +113,7 @@ MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo) /* register error routine and methods */ pvio->methods= pvio_plugin->methods; pvio->set_error= my_set_error; + pvio->type= cinfo->type; /* set tineouts */ if (pvio->methods->set_timeout) @@ -180,9 +183,14 @@ static size_t ma_pvio_read_async(MARIADB_PVIO *pvio, uchar *buffer, size_t lengt 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 (;;) { - /* todo: async */ if (pvio->methods->async_read) res= pvio->methods->async_read(pvio, buffer, length); if (res >= 0 || IS_BLOCKING_ERROR()) @@ -482,7 +490,7 @@ my_bool ma_pvio_has_data(MARIADB_PVIO *pvio, ssize_t *data_len) /* check if we still have unread data in cache */ if (pvio->cache) if (pvio->cache_pos > pvio->cache) - return 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; diff --git a/libmariadb/ma_ssl.c b/libmariadb/ma_ssl.c index 3ea613e3..2ea474a8 100644 --- a/libmariadb/ma_ssl.c +++ b/libmariadb/ma_ssl.c @@ -51,6 +51,8 @@ my_bool ma_ssl_initialized= FALSE; unsigned int mariadb_deinitialize_ssl= 1; +char *ssl_protocol_version[5]= {"unknown", "SSL3", "TLS1.0", "TLS1.1", "TLS1.2"}; + MARIADB_SSL *ma_pvio_ssl_init(MYSQL *mysql) { MARIADB_SSL *cssl= NULL; @@ -104,6 +106,11 @@ const char *ma_pvio_ssl_cipher(MARIADB_SSL *cssl) return ma_ssl_get_cipher(cssl); } +my_bool ma_pvio_ssl_get_protocol_version(MARIADB_SSL *cssl, struct st_ssl_version *version) +{ + return ma_ssl_get_protocol_version(cssl, version); +} + static my_bool ma_pvio_ssl_compare_fp(char *fp1, unsigned int fp1_len, char *fp2, unsigned int fp2_len) { diff --git a/libmariadb/my_static.c b/libmariadb/my_static.c index 61d25574..9a892996 100644 --- a/libmariadb/my_static.c +++ b/libmariadb/my_static.c @@ -73,8 +73,6 @@ uint sf_malloc_prehunc=0, /* If you have problem with core- */ size_t lCurMemory = 0L; /* Current memory usage */ size_t lMaxMemory = 0L; /* Maximum memory usage */ uint cNewCount = 0; /* Number of times NEW() was called */ -unsigned char *sf_min_adress= (unsigned char*) ~(unsigned long) 0L, - *sf_max_adress= (unsigned char*) 0L; /* Root of the linked list of remembers */ struct remember *pRememberRoot = NULL; diff --git a/libmariadb/my_static.h b/libmariadb/my_static.h index a30b462d..8a6be025 100644 --- a/libmariadb/my_static.h +++ b/libmariadb/my_static.h @@ -61,7 +61,6 @@ extern uint my_once_extra; extern int _my_tempnam_used; #endif -extern unsigned char *sf_min_adress,*sf_max_adress; extern uint cNewCount; extern struct remember *pRememberRoot; diff --git a/libmariadb/my_stmt.c b/libmariadb/my_stmt.c index 7f0355b5..58a5c951 100644 --- a/libmariadb/my_stmt.c +++ b/libmariadb/my_stmt.c @@ -416,7 +416,6 @@ int store_param(MYSQL_STMT *stmt, int column, unsigned char **p) { DBUG_ENTER("store_param"); DBUG_PRINT("info", ("column: %d type: %d", column, stmt->params[column].buffer_type)); - printf("type: %d\n", column, stmt->params[column].buffer_type); switch (stmt->params[column].buffer_type) { case MYSQL_TYPE_TINY: int1store(*p, *(uchar *)stmt->params[column].buffer); diff --git a/libmariadb/mysql_async.c b/libmariadb/mysql_async.c index 4a86ab90..f7dfc998 100644 --- a/libmariadb/mysql_async.c +++ b/libmariadb/mysql_async.c @@ -394,7 +394,7 @@ MK_ASYNC_CONT_BODY( struct mysql_real_query_params { MYSQL *mysql; const char *stmt_str; - unsigned long length; + size_t length; }; static void mysql_real_query_start_internal(void *d) @@ -578,7 +578,7 @@ MK_ASYNC_CONT_BODY( struct mysql_send_query_params { MYSQL *mysql; const char *q; - unsigned long length; + size_t length; }; static void mysql_send_query_start_internal(void *d) @@ -1311,7 +1311,7 @@ MK_ASYNC_CONT_BODY( struct mysql_stmt_prepare_params { MYSQL_STMT *stmt; const char *query; - unsigned long length; + size_t length; }; static void mysql_stmt_prepare_start_internal(void *d) @@ -1614,7 +1614,7 @@ struct mysql_stmt_send_long_data_params { MYSQL_STMT *stmt; unsigned int param_number; const char *data; - unsigned long length; + size_t length; }; static void mysql_stmt_send_long_data_start_internal(void *d) diff --git a/libmariadb/net.c b/libmariadb/net.c index df75c8c0..9788906a 100644 --- a/libmariadb/net.c +++ b/libmariadb/net.c @@ -193,10 +193,11 @@ static my_bool net_realloc(NET *net, my_bool is_multi, size_t length) } /* Remove unwanted characters from connection */ - void net_clear(NET *net) { + size_t len; DBUG_ENTER("net_clear"); + ma_pvio_has_data(net->pvio, &len); net->compress_pkt_nr= net->pkt_nr=0; /* Ready for new command */ net->write_pos=net->buff; if (net->mbuff) @@ -204,13 +205,12 @@ void net_clear(NET *net) DBUG_VOID_RETURN; } - /* Flush write_buffer if not empty. */ - int net_flush(NET *net) { int error=0; DBUG_ENTER("net_flush"); + if (net->buff != net->write_pos) { error=net_real_write(net,(char*) net->buff, @@ -222,12 +222,10 @@ int net_flush(NET *net) DBUG_RETURN(error); } - /***************************************************************************** ** Write something to server/client buffer *****************************************************************************/ - /* ** Write a logical packet with packet header ** Format: Packet length (3 bytes), packet number(1 byte) diff --git a/libmariadb/secure/gnutls.c b/libmariadb/secure/gnutls.c index cfa89006..5b955e1b 100644 --- a/libmariadb/secure/gnutls.c +++ b/libmariadb/secure/gnutls.c @@ -423,5 +423,13 @@ unsigned int ma_ssl_get_finger_print(MARIADB_SSL *cssl, unsigned char *fp, unsig } } -#endif /* HAVE_GNUTLS */ +my_bool ma_ssl_get_protocol_version(MARIADB_SSL *cssl, struct st_ssl_version *version) +{ + if (!cssl || !cssl->ssl) + return 1; + version->iversion= gnutls_protocol_get_version(cssl->ssl); + version->cversion= (char *)gnutls_protocol_get_name(version->iversion); + return 0; +} +#endif /* HAVE_GNUTLS */ diff --git a/libmariadb/secure/ma_schannel.c b/libmariadb/secure/ma_schannel.c index 065a9ab7..063ce361 100644 --- a/libmariadb/secure/ma_schannel.c +++ b/libmariadb/secure/ma_schannel.c @@ -338,7 +338,7 @@ my_bool ma_schannel_load_private_key(MARIADB_PVIO *pvio, CERT_CONTEXT *ctx, char goto end; } /* ... and import the private key */ - if (!CryptImportKey(crypt_prov, priv_key, priv_key_len, NULL, 0, (HCRYPTKEY *)&crypt_key)) + if (!CryptImportKey(crypt_prov, priv_key, priv_key_len, 0, 0, (HCRYPTKEY *)&crypt_key)) { ma_schannel_set_win_error(pvio); goto end; @@ -427,7 +427,7 @@ SECURITY_STATUS ma_schannel_handshake_loop(MARIADB_PVIO *pvio, my_bool InitialRe { if(fDoRead) { - cbData = pvio->methods->read(pvio, IoBuffer + cbIoBuffer, (size_t)(SC_IO_BUFFER_SIZE - cbIoBuffer)); + cbData = (DWORD)pvio->methods->read(pvio, IoBuffer + cbIoBuffer, (size_t)(SC_IO_BUFFER_SIZE - cbIoBuffer)); if (cbData == SOCKET_ERROR || cbData == 0) { rc = SEC_E_INTERNAL_ERROR; @@ -486,7 +486,7 @@ SECURITY_STATUS ma_schannel_handshake_loop(MARIADB_PVIO *pvio, my_bool InitialRe { if(OutBuffers[0].cbBuffer && OutBuffers[0].pvBuffer) { - cbData= pvio->methods->write(pvio, (uchar *)OutBuffers[0].pvBuffer, (size_t)OutBuffers[0].cbBuffer); + cbData= (DWORD)pvio->methods->write(pvio, (uchar *)OutBuffers[0].pvBuffer, (size_t)OutBuffers[0].cbBuffer); if(cbData == SOCKET_ERROR || cbData == 0) { FreeContextBuffer(OutBuffers[0].pvBuffer); @@ -626,18 +626,10 @@ SECURITY_STATUS ma_schannel_client_handshake(MARIADB_SSL *cssl) return sRet; } - /* Allocate IO-Buffer */ - sctx->IoBufferSize= 2 * net_buffer_length; - if (!(sctx->IoBuffer= (PUCHAR)LocalAlloc(LMEM_ZEROINIT, sctx->IoBufferSize))) - { - sRet= SEC_E_INSUFFICIENT_MEMORY; - goto end; - } - /* send client hello packaet */ if(BuffersOut[0].cbBuffer != 0 && BuffersOut[0].pvBuffer != NULL) { - r= pvio->methods->write(pvio, (uchar *)BuffersOut[0].pvBuffer, (size_t)BuffersOut[0].cbBuffer); + r= (DWORD)pvio->methods->write(pvio, (uchar *)BuffersOut[0].pvBuffer, (size_t)BuffersOut[0].cbBuffer); if (r <= 0) { sRet= SEC_E_INTERNAL_ERROR; @@ -646,11 +638,17 @@ SECURITY_STATUS ma_schannel_client_handshake(MARIADB_SSL *cssl) } sRet= ma_schannel_handshake_loop(pvio, TRUE, &ExtraData); - /* Reallocate IO-Buffer for write operations: After handshake + /* allocate IO-Buffer for write operations: After handshake was successfull, we are able now to calculate payload */ - QueryContextAttributes( &sctx->ctxt, SECPKG_ATTR_STREAM_SIZES, &sctx->Sizes ); + if ((sRet = QueryContextAttributes(&sctx->ctxt, SECPKG_ATTR_STREAM_SIZES, &sctx->Sizes ))) + goto end; + sctx->IoBufferSize= SCHANNEL_PAYLOAD(sctx->Sizes); - sctx->IoBuffer= LocalReAlloc(sctx->IoBuffer, sctx->IoBufferSize, LMEM_ZEROINIT); + if (!(sctx->IoBuffer= (PUCHAR)LocalAlloc(0, sctx->IoBufferSize))) + { + sRet= SEC_E_INSUFFICIENT_MEMORY; + goto end; + } return sRet; end: @@ -697,7 +695,6 @@ SECURITY_STATUS ma_schannel_read_decrypt(MARIADB_PVIO *pvio, SECURITY_STATUS sRet= 0; SecBufferDesc Msg; SecBuffer Buffers[4], - ExtraBuffer, *pData, *pExtra; int i; @@ -711,18 +708,18 @@ SECURITY_STATUS ma_schannel_read_decrypt(MARIADB_PVIO *pvio, { if (!dwBytesRead || sRet == SEC_E_INCOMPLETE_MESSAGE) { - dwBytesRead= pvio->methods->read(pvio, sctx->IoBuffer + dwOffset, (size_t)(sctx->IoBufferSize - dwOffset)); + dwBytesRead= (DWORD)pvio->methods->read(pvio, sctx->IoBuffer + dwOffset, (size_t)(sctx->IoBufferSize - dwOffset)); if (dwBytesRead == 0) { /* server closed connection */ // todo: error - return NULL; + return SEC_E_INVALID_HANDLE; } if (dwBytesRead < 0) { /* socket error */ // todo: error - return NULL; + return SEC_E_INVALID_HANDLE; } dwOffset+= dwBytesRead; } @@ -777,6 +774,7 @@ SECURITY_STATUS ma_schannel_read_decrypt(MARIADB_PVIO *pvio, dwOffset= 0; } } +/* }}} */ my_bool ma_schannel_verify_certs(SC_CTX *sctx, DWORD dwCertFlags) { @@ -863,7 +861,7 @@ size_t ma_schannel_write_encrypt(MARIADB_PVIO *pvio, SECURITY_STATUS scRet; SecBufferDesc Message; SecBuffer Buffers[4]; - DWORD cbMessage, cbData; + DWORD cbMessage; PBYTE pbMessage; SC_CTX *sctx= (SC_CTX *)pvio->cssl->ssl; size_t payload; @@ -898,8 +896,45 @@ size_t ma_schannel_write_encrypt(MARIADB_PVIO *pvio, return -1; if (pvio->methods->write(pvio, sctx->IoBuffer, Buffers[0].cbBuffer + Buffers[1].cbBuffer + Buffers[2].cbBuffer)) - return payload; + return payload; return 0; } /* }}} */ +extern char *ssl_protocol_version[5]; + +/* {{{ ma_ssl_get_protocol_version(MARIADB_SSL *cssl, struct st_ssl_version *version) */ +my_bool ma_ssl_get_protocol_version(MARIADB_SSL *cssl, struct st_ssl_version *version) +{ + SC_CTX *sctx; + SecPkgContext_ConnectionInfo ConnectionInfo; + if (!cssl->ssl) + return 1; + + sctx= (SC_CTX *)cssl->ssl; + + if (QueryContextAttributes(&sctx->ctxt, SECPKG_ATTR_CONNECTION_INFO, &ConnectionInfo) != SEC_E_OK) + return 1; + + switch(ConnectionInfo.dwProtocol) + { + case SP_PROT_SSL3_CLIENT: + version->iversion= 1; + break; + case SP_PROT_TLS1_CLIENT: + version->iversion= 2; + break; + case SP_PROT_TLS1_1_CLIENT: + version->iversion= 3; + break; + case SP_PROT_TLS1_2_CLIENT: + version->iversion= 4; + break; + default: + version->iversion= 0; + break; + } + version->cversion= ssl_protocol_version[version->iversion]; + return 0; +} +/* }}} */ diff --git a/libmariadb/secure/openssl.c b/libmariadb/secure/openssl.c index 37256efc..e659a1a1 100644 --- a/libmariadb/secure/openssl.c +++ b/libmariadb/secure/openssl.c @@ -177,8 +177,11 @@ int ma_ssl_start(char *errmsg, size_t errmsg_len) SSL_load_error_strings(); /* digests and ciphers */ OpenSSL_add_all_algorithms(); - - if (!(SSL_context= SSL_CTX_new(TLSv1_client_method()))) +#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) + if (!(SSL_context= SSL_CTX_new(TLS_client_method()))) +#else + if (!(SSL_context= SSL_CTX_new(SSLv23_client_method()))) +#endif { ma_ssl_get_error(errmsg, errmsg_len); goto end; @@ -464,9 +467,13 @@ int ma_ssl_verify_server_cert(MARIADB_SSL *cssl) { X509 *cert; MYSQL *mysql; - MARIADB_PVIO *pvio; + X509_NAME *x509sn; + int cn_pos; + X509_NAME_ENTRY *cn_entry; + ASN1_STRING *cn_asn1; + const char *cn_str; SSL *ssl; - char *p1, *p2, buf[256]; + MARIADB_PVIO *pvio; if (!cssl || !cssl->ssl) return 1; @@ -477,33 +484,46 @@ int ma_ssl_verify_server_cert(MARIADB_SSL *cssl) if (!mysql->host) { - pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, 0, - "Invalid (empty) hostname"); + 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, 0, - "Unable to get server certificate"); + pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, + ER(CR_SSL_CONNECTION_ERROR), "Unable to get server certificate"); return 1; } - X509_NAME_oneline(X509_get_subject_name(cert), buf, 256); + 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; + X509_free(cert); - /* Extract the server name from buffer: - Format: ....CN=/hostname/.... */ - if ((p1= strstr(buf, "/CN="))) - { - p1+= 4; - if ((p2= strchr(p1, '/'))) - *p2= 0; - if (!strcmp(mysql->host, p1)) - return(0); - } - pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, 0, - "Validation of SSL server certificate failed"); + 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; } @@ -552,3 +572,37 @@ unsigned int ma_ssl_get_finger_print(MARIADB_SSL *cssl, unsigned char *fp, unsig } return (fp_len); } + + +extern char *ssl_protocol_version[5]; + +my_bool ma_ssl_get_protocol_version(MARIADB_SSL *cssl, struct st_ssl_version *version) +{ + SSL *ssl; + + if (!cssl || !cssl->ssl) + return 1; + + ssl = (SSL *)cssl->ssl; + switch(ssl->version) + { + case SSL3_VERSION: + version->iversion= 1; + break; + case TLS1_VERSION: + version->iversion= 2; + break; + case TLS1_1_VERSION: + version->iversion= 3; + break; + case TLS1_2_VERSION: + version->iversion= 4; + break; + default: + version->iversion= 0; + break; + } + version->cversion= ssl_protocol_version[version->iversion]; + return 0; +} + diff --git a/libmariadb/secure/schannel.c b/libmariadb/secure/schannel.c index cc0fd4e2..3f84c17f 100644 --- a/libmariadb/secure/schannel.c +++ b/libmariadb/secure/schannel.c @@ -284,7 +284,7 @@ my_bool ma_ssl_connect(MARIADB_SSL *cssl) Cred.cCreds = 1; Cred.paCred = &sctx->client_cert_ctx; } - Cred.grbitEnabledProtocols= SP_PROT_TLS1; + Cred.grbitEnabledProtocols= SP_PROT_TLS1_1PLUS; if ((sRet= AcquireCredentialsHandleA(NULL, UNISP_NAME_A, SECPKG_CRED_OUTBOUND, NULL, &Cred, NULL, NULL, &sctx->CredHdl, NULL)) != SEC_E_OK) diff --git a/mariadb_config/libmariadb.pc.in b/mariadb_config/libmariadb.pc.in new file mode 100644 index 00000000..e9161554 --- /dev/null +++ b/mariadb_config/libmariadb.pc.in @@ -0,0 +1,19 @@ +# +# pkg_config.pc.in +# +# pkg_config configuration file +# For a detailled description of options, please visit +# Dan Nicholson’s Guide to pkg-config (http://www.freedesktop.org/wiki/Software/pkg-config/) +# + +includedir=@PREFIX_INSTALL_DIR@/@INCLUDE_INSTALL_DIR@/@SUFFIX_INSTALL_DIR@ +libdir=@PREFIX_INSTALL_DIR@/@INCLUDE_INSTALL_DIR@/@SUFFIX_INSTALL_DIR@ +prefix=@PREFIX_INSTALL_DIR@ + +Name: libmariadb +Version: @LIBMARIADB_VERSION@ +Description: MariaDB Connector/C dynamic library +Cflags: -I@PREFIX_INSTALL_DIR@/@INCLUDE_INSTALL_DIR@/@SUFFIX_INSTALL_DIR@ @CMAKE_C_FLAGS@ +Libs: -L@PREFIX_INSTALL_DIR@/@LIB_INSTALL_DIR@/@SUFFIX_INSTALL_DIR@ -lmariadb @extra_dynamic_LDFLAGS@ + + diff --git a/plugins/connection/CMakeLists.txt b/plugins/connection/CMakeLists.txt index f5d7cc19..4ccdd611 100644 --- a/plugins/connection/CMakeLists.txt +++ b/plugins/connection/CMakeLists.txt @@ -13,10 +13,30 @@ IF(REPLICATION_PLUGIN_TYPE MATCHES "DYNAMIC") "FILE_DESCRIPTION:Connection plugin for master/slave environment") ENDIF() ADD_DEFINITIONS(-DHAVE_REPLICATION_DYNAMIC=1) - ADD_LIBRARY(replication SHARED replication.c ${EXPORT_FILE}) + ADD_LIBRARY(replication SHARED ${replication_RC} replication.c ${EXPORT_FILE}) + IF(WIN32) + TARGET_LINK_LIBRARIES(replication libmariadb) + ENDIF() SET(INSTALL_LIBS replication) ENDIF() +IF(REPLICATION_PLUGIN_TYPE MATCHES "DYNAMIC") + IF(WIN32) + SET_VERSION_INFO("TARGET:aurora" + "FILE_TYPE:VFT_DLL" + "SOURCE_FILE:plugins/connection/aurora.c" + "ORIGINAL_FILE_NAME:aurora.dll" + "FILE_DESCRIPTION:Connection plugin for Amazon AWS Aurora") + ENDIF() + ADD_DEFINITIONS(-DHAVE_AURORA_DYNAMIC=1) + ADD_LIBRARY(aurora SHARED ${aurora_RC} aurora.c ${EXPORT_FILE}) + IF(WIN32) + TARGET_LINK_LIBRARIES(aurora libmariadb) + ENDIF() + SET(INSTALL_LIBS ${INSTALL_LIBS} aurora) +ENDIF() + + IF(INSTALL_LIBS) INSTALL(TARGETS ${INSTALL_LIBS} diff --git a/plugins/connection/aurora.c b/plugins/connection/aurora.c new file mode 100644 index 00000000..524f4364 --- /dev/null +++ b/plugins/connection/aurora.c @@ -0,0 +1,819 @@ +/************************************************************************************ + 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 + 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 + *************************************************************************************/ + +/* MariaDB Connection plugin for Aurora failover */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef WIN32 +#include +#endif + +/* function prototypes */ +int aurora_init(char *errormsg, size_t errormsg_size, + int unused __attribute__((unused)), + va_list unused1 __attribute__((unused))); + +MYSQL *aurora_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 aurora_close(MYSQL *mysql); +int aurora_command(MYSQL *mysql,enum enum_server_command command, const char *arg, + size_t length, my_bool skipp_check, void *opt_arg); +int aurora_set_options(MYSQL *msql, enum mysql_option option, void *arg); +my_bool aurora_reconnect(MYSQL *mysql); + +#define AURORA_MAX_INSTANCES 16 + +#define AURORA_UNKNOWN -1 +#define AURORA_PRIMARY 0 +#define AURORA_REPLICA 1 +#define AURORA_UNAVAILABLE 2 + +#define ENABLE_AURORA(mysql)\ + (mysql)->net.conn_hdlr->active= 1; +#define DISABLE_AURORA(mysql)\ + (mysql)->net.conn_hdlr->active= 0; + +#ifndef HAVE_AURORA_DYNAMIC +MARIADB_CONNECTION_PLUGIN connection_aurora_plugin = +#else +MARIADB_CONNECTION_PLUGIN _mysql_client_plugin_declaration_ = +#endif +{ + MARIADB_CLIENT_CONNECTION_PLUGIN, + MARIADB_CLIENT_CONNECTION_PLUGIN_INTERFACE_VERSION, + "aurora", + "Georg Richter", + "MariaDB connection plugin for Aurora failover", + {1, 0, 0}, + "LGPL", + aurora_init, + NULL, + aurora_connect, + aurora_close, + aurora_set_options, + aurora_command, + aurora_reconnect +}; + +struct st_mariadb_api *mariadb_api= NULL; + +typedef struct st_aurora_instance { + char *host; + int port; + time_t blacklisted; + int type; +} AURORA_INSTANCE; + +typedef struct st_conn_aurora { + MARIADB_PVIO *pvio[2]; + MYSQL *mysql[2]; + my_bool active[2]; + char *url; + unsigned int num_instances; + AURORA_INSTANCE instance[AURORA_MAX_INSTANCES]; + char *username, *password, *database; + unsigned int port; + unsigned long client_flag; + unsigned int last_instance_type; /* Primary or Replica */ + char primary_id[100]; +} AURORA; + +#define AURORA_BLACKLIST_TIMEOUT 150 + +#define AURORA_IS_BLACKLISTED(a, i) \ + ((time(NULL) - (a)->instance[(i)].blacklisted) < AURORA_BLACKLIST_TIMEOUT) + +/* {{{ my_bool aurora_swutch_connection */ +my_bool aurora_switch_connection(MYSQL *mysql, AURORA *aurora, int type) +{ + switch (type) + { + case AURORA_REPLICA: + if (aurora->mysql[AURORA_REPLICA]) + { + mysql->net.pvio= aurora->pvio[AURORA_REPLICA]; + aurora->pvio[AURORA_REPLICA]->mysql= mysql; + mysql->thread_id= aurora->mysql[AURORA_REPLICA]->thread_id; + aurora->last_instance_type= AURORA_REPLICA; + } + break; + case AURORA_PRIMARY: + if (aurora->mysql[AURORA_PRIMARY]) + { + if (aurora->mysql[AURORA_REPLICA]) + aurora->mysql[AURORA_REPLICA]->net.pvio->mysql= aurora->mysql[AURORA_REPLICA]; + mysql->net.pvio= aurora->pvio[AURORA_PRIMARY]; + mysql->thread_id= aurora->mysql[AURORA_PRIMARY]->thread_id; + aurora->last_instance_type= AURORA_PRIMARY; + } + break; + default: + return 1; + } + return 0; +} +/* }}} */ + +/* {{{ int aurora_init + * + * plugin initialization function + */ +int aurora_init(char *errormsg, size_t errormsg_size, + int unused __attribute__((unused)), + va_list unused1 __attribute__((unused))) +{ + /* random generator initialization */ +#ifndef WIN32 + struct timeval tp; + gettimeofday(&tp,NULL); + srand(tp.tv_usec / 1000 + tp.tv_sec * 1000); +#else + srand(GetTickCount()); +#endif + return 0; +} +/* }}} */ + +/* {{{ void aurora_close_memory */ +void aurora_close_memory(AURORA *aurora) +{ + free(aurora->url); + free(aurora->username); + free(aurora->password); + free(aurora->database); + free(aurora); +} +/* }}} */ + +/* {{{ my_bool aurora_parse_url + * + * parse url + * Url has the following format: + * instance1:port, instance2:port, .., instanceN:port + * + */ +my_bool aurora_parse_url(const char *url, AURORA *aurora) +{ + char *p, *c; + unsigned int i; + + if (!url || url[0] == 0) + return 1; + + bzero(aurora->instance, (AURORA_MAX_INSTANCES + 1) * sizeof(char *)); + bzero(&aurora->port, (AURORA_MAX_INSTANCES + 1) * sizeof(int)); + + if (aurora->url) + free(aurora->url); + + aurora->url= strdup(url); + c= aurora->url; + + /* get instances */ + while((c)) + { + if (p= strchr(c, ',')) + { + *p= '\0'; + p++; + } + if (*c) + { + aurora->instance[aurora->num_instances].host= c; + aurora->num_instances++; + } + c= p; + } + + if (!aurora->num_instances) + return 0; + + /* check ports */ + for (i=0; i < aurora->num_instances && aurora->instance[i].host; i++) + { + aurora->instance[i].type= AURORA_UNKNOWN; + + /* We need to be aware of IPv6 addresses: According to RFC3986 sect. 3.2.2 + hostnames have to be enclosed in square brackets if a port is given */ + if (aurora->instance[i].host[0]== '[' && + strchr(aurora->instance[i].host, ':') && + (p= strchr(aurora->instance[i].host,']'))) + { + /* ignore first square bracket */ + memmove(aurora->instance[i].host, + aurora->instance[i].host+1, + strlen(aurora->instance[i].host) - 1); + p= strchr(aurora->instance[i].host,']'); + *p= 0; + p++; + } + else + p= aurora->instance[i].host; + if (p && (p= strchr(p, ':'))) + { + *p= '\0'; + p++; + aurora->instance[i].port= atoi(p); + } + } + return 0; +} +/* }}} */ + +/* {{{ int aurora_get_instance_type + * + * RETURNS: + * + * AURORA_PRIMARY + * AURORA_REPLICA + * -1 on error + */ +int aurora_get_instance_type(MYSQL *mysql) +{ + int rc; + char *query= "select variable_value from information_schema.global_variables where variable_name='INNODB_READ_ONLY' AND variable_value='OFF'"; + + if (!mariadb_api->mysql_query(mysql, query)) + { + MYSQL_RES *res= mysql_store_result(mysql); + rc= mysql_num_rows(res) ? AURORA_PRIMARY : AURORA_REPLICA; + mysql_free_result(res); + return rc; + } + return -1; +} +/* }}} */ + +/* {{{ my_bool aurora_get_primary_id + * + * try to find primary instance from slave by retrieving + * primary_id information_schema.replica_host_status information + * + * If the function succeeds, primary_id will be copied into + * aurora->primary_id + * + * Returns: + * 1 on success + * 0 if an error occured or primary_id couldn't be + * found + */ +my_bool aurora_get_primary_id(MYSQL *mysql, AURORA *aurora) +{ + my_bool rc= 0; + + if (!mariadb_api->mysql_query(mysql, "select server_id from information_schema.replica_host_status " + "where session_id = 'MASTER_SESSION_ID'")) + { + MYSQL_RES *res; + MYSQL_ROW row; + + if ((res= mysql_store_result(mysql))) + { + if ((row= mysql_fetch_row(res))) + { + if (row[0]) + { + strcpy(aurora->primary_id, row[0]); + rc= 1; + } + } + mysql_free_result(res); + } + } + return rc; +} +/* }}} */ + +/* {{{ unsigned int aurora_get_valid_instances + * + * returns the number of instances which are + * not blacklisted or don't have a type assigned. + */ +static unsigned int aurora_get_valid_instances(AURORA *aurora, AURORA_INSTANCE **instances) +{ + unsigned int i, valid_instances= 0; + + memset(instances, 0, sizeof(AURORA_INSTANCE *) * AURORA_MAX_INSTANCES); + + for (i=0; i < aurora->num_instances; i++) + { + if (aurora->instance[i].type != AURORA_UNAVAILABLE) + { + if (aurora->instance[i].type == AURORA_PRIMARY && aurora->active[AURORA_PRIMARY]) + continue; + instances[valid_instances]= &aurora->instance[i]; + valid_instances++; + } + } + return valid_instances; +} +/* }}} */ + +/* {{{ void aurora_refresh_blacklist() */ +void aurora_refresh_blacklist(AURORA *aurora) +{ + unsigned int i; + for (i=0; i < aurora->num_instances; i++) + { + if (aurora->instance[i].blacklisted && + !(AURORA_IS_BLACKLISTED(aurora, i))) + { + aurora->instance[i].blacklisted= 0; + aurora->instance[i].type= AURORA_UNKNOWN; + } + } +} +/* }}} */ + +/* {{{ MYSQL *aurora_connect_instance() */ +MYSQL *aurora_connect_instance(AURORA *aurora, AURORA_INSTANCE *instance, MYSQL *mysql) +{ + if (!mysql->methods->db_connect(mysql, + instance->host, + aurora->username, + aurora->password, + aurora->database, + instance->port ? instance->port : aurora->port, + NULL, + aurora->client_flag)) + { + /* connection not available */ + instance->blacklisted= time(NULL); + instance->type= AURORA_UNAVAILABLE; + return NULL; + } + + /* check if we are slave or master */ + switch (aurora_get_instance_type(mysql)) + { + case AURORA_PRIMARY: + instance->type= AURORA_PRIMARY; + return mysql; + break; + case AURORA_REPLICA: + instance->type= AURORA_REPLICA; + break; + default: + instance->type= AURORA_UNAVAILABLE; + instance->blacklisted= time(NULL); + return NULL; + } + if (!aurora->primary_id[0]) + aurora_get_primary_id(mysql, aurora); + return mysql; +} +/* }}} */ + +/* {{{ void aurora_copy_mysql() */ +void aurora_copy_mysql(MYSQL *from, MYSQL *to) +{ + /* invalidate statements */ + to->methods->invalidate_stmts(to, "aurora connect/reconnect"); + + from->free_me= to->free_me; + from->reconnect= to->reconnect; + from->net.conn_hdlr= to->net.conn_hdlr; + from->stmts= to->stmts; + to->stmts= NULL; + + memset(&to->options, 0, sizeof(to->options)); + to->free_me= 0; + to->net.conn_hdlr= 0; + mariadb_api->mysql_close(to); + *to= *from; + to->net.pvio= from->net.pvio; + to->net.pvio->mysql= to; + from->net.pvio= NULL; +} +/* }}} */ + +/* {{{ my_bool aurora_find_replica() */ +my_bool aurora_find_replica(AURORA *aurora) +{ + int valid_instances; + my_bool replica_found= 0; + AURORA_INSTANCE *instance[AURORA_MAX_INSTANCES]; + MYSQL mysql; + + if (aurora->num_instances < 2) + return 0; + + mariadb_api->mysql_init(&mysql); + mysql.options= aurora->mysql[AURORA_PRIMARY]->options; + + /* don't execute init_command on slave */ + mysql.net.conn_hdlr= aurora->mysql[AURORA_PRIMARY]->net.conn_hdlr; + + valid_instances= aurora_get_valid_instances(aurora, instance); + + while (valid_instances && !replica_found) + { + int random_pick= rand() % valid_instances; + if ((aurora_connect_instance(aurora, instance[random_pick], &mysql))) + { + switch (instance[random_pick]->type) { + case AURORA_REPLICA: + if (!aurora->mysql[AURORA_REPLICA]) + { + aurora->mysql[AURORA_REPLICA]= mysql_init(NULL); + } + aurora_copy_mysql(&mysql, aurora->mysql[AURORA_REPLICA]); + aurora->active[AURORA_REPLICA]= 1; + return 1; + break; + case AURORA_PRIMARY: + aurora_copy_mysql(&mysql, aurora->mysql[AURORA_PRIMARY]); + aurora->pvio[AURORA_PRIMARY]= aurora->mysql[AURORA_PRIMARY]->net.pvio; + aurora->active[AURORA_PRIMARY]= 1; + continue; + break; + default: + mysql_close(&mysql); + return 0; + break; + } + } + valid_instances= aurora_get_valid_instances(aurora, instance); + } + return 0; +} +/* }}} */ + +/* {{{ AURORA_INSTANCE aurora_get_primary_id_instance() */ +AURORA_INSTANCE *aurora_get_primary_id_instance(AURORA *aurora) +{ + unsigned int i; + + if (!aurora->primary_id[0]) + return 0; + + for (i=0; i < aurora->num_instances; i++) + { + if (!strncmp(aurora->instance[i].host, aurora->primary_id, strlen(aurora->primary_id))) + return &aurora->instance[i]; + } + return NULL; +} +/* }}} */ + +/* {{{ my_bool aurora_find_primary() */ +my_bool aurora_find_primary(AURORA *aurora) +{ + unsigned int i; + AURORA_INSTANCE *instance= NULL; + MYSQL mysql; + my_bool check_primary= 1; + + if (!aurora->num_instances) + return 0; + + mariadb_api->mysql_init(&mysql); + mysql.options= aurora->mysql[AURORA_PRIMARY]->options; + mysql.net.conn_hdlr= aurora->mysql[AURORA_PRIMARY]->net.conn_hdlr; + + for (i=0; i < aurora->num_instances; i++) + { + if (check_primary && aurora->primary_id[0]) + { + if ((instance= aurora_get_primary_id_instance(aurora)) && + aurora_connect_instance(aurora, instance, &mysql) && + instance->type == AURORA_PRIMARY) + { + aurora_copy_mysql(&mysql, aurora->mysql[AURORA_PRIMARY]); + aurora->active[AURORA_PRIMARY]= 1; + return 1; + } + /* primary id connect failed, don't try again */ + aurora->primary_id[0]= 0; + check_primary= 0; + } + if (aurora->instance[i].type != AURORA_UNAVAILABLE) + { + if (aurora_connect_instance(aurora, &aurora->instance[i], &mysql) + && aurora->instance[i].type == AURORA_PRIMARY) + { + aurora_copy_mysql(&mysql, aurora->mysql[AURORA_PRIMARY]); + aurora->active[AURORA_PRIMARY]= 1; + return 1; + } + } + } + return 0; +} +/* }}} */ + +/* {{{ void aurora_close_replica() */ +void aurora_close_replica(MYSQL *mysql, AURORA *aurora) +{ + if (aurora->mysql[AURORA_REPLICA]) + { + aurora->mysql[AURORA_REPLICA]->net.pvio->mysql= aurora->mysql[AURORA_REPLICA]; + aurora->mysql[AURORA_REPLICA]->net.conn_hdlr= 0; + mariadb_api->mysql_close(aurora->mysql[AURORA_REPLICA]); + aurora->pvio[AURORA_REPLICA]= 0; + aurora->mysql[AURORA_REPLICA]= NULL; + } +} +/* }}} */ + +/* {{{ MYSQL *aurora_connect */ +MYSQL *aurora_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, + const char *db, unsigned int port, const char *unix_socket, unsigned long client_flag) +{ + AURORA *aurora= NULL; + MA_CONNECTION_HANDLER *hdlr= mysql->net.conn_hdlr; + my_bool is_reconnect= 0; + + if (!mariadb_api) + mariadb_api= mysql->methods->api; + + mariadb_api->mariadb_get_info(mysql, MARIADB_CLIENT_ERRORS, &client_errors); + + if ((aurora= (AURORA *)hdlr->data)) + { + aurora_refresh_blacklist(aurora); + if (aurora->mysql[aurora->last_instance_type]->net.pvio) + { + SET_CLIENT_ERROR(mysql, CR_ALREADY_CONNECTED, SQLSTATE_UNKNOWN, 0); + return NULL; + } + is_reconnect= 1; + } + else + { + if (!(aurora= (AURORA *)calloc(1, sizeof(AURORA)))) + { + mysql->methods->set_error(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return NULL; + } + + mysql->net.conn_hdlr->data= (void *)aurora; + + aurora->mysql[AURORA_PRIMARY]= mysql; + + if (aurora_parse_url(host, aurora)) + { + goto error; + } + + if (user) + aurora->username= strdup(user); + if (passwd) + aurora->password= strdup(passwd); + if (db) + aurora->database= strdup(db); + aurora->port= port; + aurora->client_flag= client_flag; + aurora->pvio[AURORA_PRIMARY]= aurora->pvio[AURORA_REPLICA]= NULL; + hdlr->data= aurora; + } + + + /* In case of reconnect, close broken connection first */ + if (is_reconnect) + { + DISABLE_AURORA(mysql); + switch (aurora->last_instance_type) { + case AURORA_REPLICA: + aurora_close_replica(mysql, aurora); + aurora->pvio[AURORA_REPLICA]= NULL; + break; + case AURORA_PRIMARY: + /* pvio will be closed in mysql_reconnect() */ + aurora->pvio[AURORA_PRIMARY]= NULL; + aurora->primary_id[0]= 0; + break; + } + aurora->active[aurora->last_instance_type]= 0; + } + + if (!aurora->active[AURORA_REPLICA]) + { + if (aurora_find_replica(aurora)) + { + aurora->pvio[AURORA_REPLICA]= aurora->mysql[AURORA_REPLICA]->net.pvio; + aurora->mysql[AURORA_REPLICA]->net.conn_hdlr= mysql->net.conn_hdlr; + } + else + aurora->pvio[AURORA_REPLICA]= NULL; + } + + if (!aurora->active[AURORA_PRIMARY]) + { + if (aurora_find_primary(aurora)) + { + aurora->active[AURORA_PRIMARY]= 1; + aurora->pvio[AURORA_PRIMARY]= aurora->mysql[AURORA_PRIMARY]->net.pvio; + } + } + + aurora_switch_connection(mysql, aurora, AURORA_PRIMARY); + ENABLE_AURORA(mysql); + return mysql; +error: + aurora_close_memory(aurora); + return NULL; +} +/* }}} */ + +/* {{{ my_bool aurora_reconnect */ +my_bool aurora_reconnect(MYSQL *mysql) +{ + AURORA *aurora; + MA_CONNECTION_HANDLER *hdlr= mysql->net.conn_hdlr; + my_bool rc= 1; + + aurora= (AURORA *)hdlr->data; + + DISABLE_AURORA(mysql); + switch (aurora->last_instance_type) + { + case AURORA_REPLICA: + if (!(rc= mariadb_api->mysql_reconnect(aurora->mysql[aurora->last_instance_type]))) + aurora_switch_connection(mysql, aurora, AURORA_REPLICA); + break; + case AURORA_PRIMARY: + if (!(rc= mysql_reconnect(aurora->mysql[aurora->last_instance_type]))) + aurora_switch_connection(mysql, aurora, AURORA_PRIMARY); + break; + default: + /* todo: error message */ + break; + } + ENABLE_AURORA(mysql); + return rc; +} +/* }}} */ + +/* {{{ void aurora_close */ +void aurora_close(MYSQL *mysql) +{ + MA_CONNECTION_HANDLER *hdlr= mysql->net.conn_hdlr; + AURORA *aurora= (AURORA *)hdlr->data; + + aurora_switch_connection(mysql, aurora, AURORA_PRIMARY); + + /* if the connection is not active yet, just return */ + if (!aurora->active[1]) + return; + + if (aurora->mysql[AURORA_REPLICA]) + { + /* we got options from primary, so don't free it twice */ + memset(&aurora->mysql[AURORA_REPLICA]->options, 0, sizeof(mysql->options)); + /* connection handler wull be freed in mariadb_api->mysql_close() */ + aurora->mysql[AURORA_REPLICA]->net.conn_hdlr= 0; + + mysql_close(aurora->mysql[AURORA_REPLICA]); + } + + if (aurora->mysql[AURORA_PRIMARY]) + { + /* connection handler wull be freed in mysql_close() */ + aurora->mysql[AURORA_PRIMARY]->net.conn_hdlr= 0; + + aurora->mysql[AURORA_PRIMARY]->net.pvio= aurora->pvio[AURORA_PRIMARY]; + + mysql_close(aurora->mysql[AURORA_PRIMARY]); + } + + + +/* + if (aurora->mysql[AURORA_PRIMARY]) + { + aurora->mysql[AURORA_PRIMARY]->net.pvio= aurora->pvio[AURORA_PRIMARY]; + aurora->mysql[AURORA_PRIMARY]->net.conn_hdlr= 0; + mysql_close(aurora->mysql[AURORA_PRIMARY]); + } +*/ + /* free masrwe information */ + aurora_close_memory(aurora); +} +/* }}} */ + +/* {{{ my_bool is_replica_command */ +my_bool is_replica_command(const char *buffer, size_t buffer_len) +{ + const char *buffer_end= buffer + buffer_len; + + for (; buffer < buffer_end; ++buffer) + { + char c; + if (isalpha(c=*buffer)) + { + if (tolower(c) == 's') + return 1; + return 0; + } + } + return 0; +} +/* }}} */ + +/* {{{ my_bool is_replica_stmt */ +my_bool is_replica_stmt(MYSQL *mysql, const char *buffer) +{ + unsigned long stmt_id= uint4korr(buffer); + LIST *stmt_list= mysql->stmts; + + for (; stmt_list; stmt_list= stmt_list->next) + { + MYSQL_STMT *stmt= (MYSQL_STMT *)stmt_list->data; + if (stmt->stmt_id == stmt_id) + return 1; + } + return 0; +} +/* }}} */ + +/* {{{ int aurora_command */ +int aurora_command(MYSQL *mysql,enum enum_server_command command, const char *arg, + size_t length, my_bool skipp_check, void *opt_arg) +{ + AURORA *aurora= (AURORA *)mysql->net.conn_hdlr->data; + + /* if we don't have slave or slave became unavailable root traffic to master */ + if (!aurora->mysql[AURORA_REPLICA] || !OPT_HAS_EXT_VAL(mysql, read_only)) + { + if (command != COM_INIT_DB) + { + aurora_switch_connection(mysql, aurora, AURORA_PRIMARY); + return 0; + } + } + + switch(command) { + case COM_INIT_DB: + /* we need to change default database on primary and replica */ + if (aurora->mysql[AURORA_REPLICA] && aurora->last_instance_type != AURORA_REPLICA) + { + aurora_switch_connection(mysql, aurora, AURORA_REPLICA); + DISABLE_AURORA(mysql); + mariadb_api->mysql_select_db(aurora->mysql[AURORA_REPLICA], arg); + ENABLE_AURORA(mysql); + aurora_switch_connection(mysql, aurora, AURORA_PRIMARY); + } + break; + case COM_QUERY: + case COM_STMT_PREPARE: + if (aurora->mysql[AURORA_REPLICA] && aurora->last_instance_type != AURORA_REPLICA) + aurora_switch_connection(mysql, aurora, AURORA_REPLICA); + break; + case COM_STMT_EXECUTE: + case COM_STMT_FETCH: + if (aurora->pvio[AURORA_REPLICA]->mysql->stmts && is_replica_stmt(aurora->pvio[AURORA_REPLICA]->mysql, arg)) + { + if (aurora->last_instance_type != AURORA_REPLICA) + aurora_switch_connection(mysql, aurora, AURORA_REPLICA); + } + else + { + if (aurora->last_instance_type != AURORA_PRIMARY) + aurora_switch_connection(mysql, aurora, AURORA_PRIMARY); + } + + default: + aurora_switch_connection(mysql, aurora, AURORA_PRIMARY); + break; + } + return 0; +} +/* }}} */ + +/* {{{ int aurora_set_options() */ +int aurora_set_options(MYSQL *mysql, enum mysql_option option, void *arg) +{ + switch(option) { + default: + return -1; + } +} +/* }}} */ diff --git a/plugins/connection/replication.c b/plugins/connection/replication.c index cf5320ec..9b4d1865 100644 --- a/plugins/connection/replication.c +++ b/plugins/connection/replication.c @@ -42,16 +42,11 @@ int repl_command(MYSQL *mysql,enum enum_server_command command, const char *arg, size_t length, my_bool skipp_check, void *opt_arg); int repl_set_options(MYSQL *msql, enum mysql_option option, void *arg); -#ifdef HAVE_REPLICATION_DYNAMIC - -#undef my_free -#define my_malloc(a,b) malloc(a) -#define my_free(a) free(a) -#endif - #define MARIADB_MASTER 0 #define MARIADB_SLAVE 1 +struct st_mariadb_api *mariadb_api= NULL; + #ifndef HAVE_REPLICATION_DYNAMIC MARIADB_CONNECTION_PLUGIN connection_replication_plugin = #else @@ -70,7 +65,8 @@ MARIADB_CONNECTION_PLUGIN _mysql_client_plugin_declaration_ = repl_connect, repl_close, repl_set_options, - repl_command + repl_command, + NULL }; typedef struct st_conn_repl { @@ -81,10 +77,20 @@ typedef struct st_conn_repl { char *url; char *host[2]; int port[2]; + unsigned int current_type; } REPL_DATA; -#define SET_SLAVE(mysql, data) mysql->net.pvio= data->pvio[MARIADB_SLAVE] -#define SET_MASTER(mysql, data) mysql->net.pvio= data->pvio[MARIADB_MASTER] +#define SET_SLAVE(mysql, data)\ +{\ + mysql->net.pvio= data->pvio[MARIADB_SLAVE]; \ + data->current_type= MARIADB_SLAVE;\ +} + +#define SET_MASTER(mysql, data)\ +{\ + mysql->net.pvio= data->pvio[MARIADB_MASTER];\ + data->current_type= MARIADB_MASTER;\ +} /* parse url @@ -108,10 +114,8 @@ my_bool repl_parse_url(const char *url, REPL_DATA *data) memset(data->host, 0, 2 * sizeof(char *)); memset(data->port, 0, 2 * sizeof(int)); - if (data->url) - my_free(data->url); - - data->url= my_strdup(url, MYF(0)); + if (!data->url) + data->url= strdup(url); data->host[MARIADB_MASTER]= p= data->url; /* get slaves */ @@ -150,10 +154,11 @@ my_bool repl_parse_url(const char *url, REPL_DATA *data) { /* We need to be aware of IPv6 addresses: According to RFC3986 sect. 3.2.2 hostnames have to be enclosed in square brackets if a port is given */ - if (data->host[i][0]= '[' && strchr(data->host[i], ':') && (p= strchr(data->host[i],']'))) + if (data->host[i][0]== '[' && strchr(data->host[i], ':') && (p= strchr(data->host[i],']'))) { /* ignore first square bracket */ - data->host[i]++; + memmove(data->host[i], data->host[i]+1, strlen(data->host[i]) - 1); + p= strchr(data->host[i],']'); *p= 0; p++; } @@ -176,12 +181,21 @@ MYSQL *repl_connect(MYSQL *mysql, const char *host, const char *user, const char REPL_DATA *data= NULL; MA_CONNECTION_HANDLER *hdlr= mysql->net.conn_hdlr; + if (!mariadb_api) + mariadb_api= mysql->methods->api; + + if ((data= (REPL_DATA *)hdlr->data)) + { + data->pvio[MARIADB_MASTER]->methods->close(data->pvio[MARIADB_MASTER]); + data->pvio[MARIADB_MASTER]= 0; + repl_close(mysql); + } + if (!(data= calloc(1, sizeof(REPL_DATA)))) { mysql->methods->set_error(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); return NULL; } - memset(data->pvio, 0, 2 * sizeof(MARIADB_PVIO *)); if (repl_parse_url(host, data)) @@ -194,17 +208,18 @@ MYSQL *repl_connect(MYSQL *mysql, const char *host, const char *user, const char data->pvio[MARIADB_MASTER]= mysql->net.pvio; hdlr->data= data; + SET_MASTER(mysql, data); /* to allow immediate access without connection delay, we will start * connecting to slave(s) in background */ /* if slave connection will fail, we will not return error but use master instead */ - if (!(data->slave_mysql= mysql_init(NULL)) || + if (!(data->slave_mysql= mariadb_api->mysql_init(NULL)) || !(mysql->methods->db_connect(data->slave_mysql, data->host[MARIADB_SLAVE], user, passwd, db, data->port[MARIADB_SLAVE] ? data->port[MARIADB_SLAVE] : port, unix_socket, clientflag))) { if (data->slave_mysql) - mysql_close(data->slave_mysql); + mariadb_api->mysql_close(data->slave_mysql); data->pvio[MARIADB_SLAVE]= NULL; } else @@ -217,8 +232,8 @@ error: if (data) { if (data->url) - my_free(data->url); - my_free(data); + free(data->url); + free(data); } return NULL; } @@ -236,16 +251,15 @@ void repl_close(MYSQL *mysql) { /* restore mysql */ data->pvio[MARIADB_SLAVE]->mysql= data->slave_mysql; - mysql_close(data->slave_mysql); + mariadb_api->mysql_close(data->slave_mysql); data->pvio[MARIADB_SLAVE]= NULL; data->slave_mysql= NULL; } /* free masrwe information and close connection */ - my_free(data->url); - my_free(data); + free(data->url); + free(data); mysql->net.conn_hdlr->data= NULL; - mysql_close(mysql); } static my_bool is_slave_command(const char *buffer, size_t buffer_len) @@ -295,20 +309,20 @@ int repl_command(MYSQL *mysql,enum enum_server_command command, const char *arg, case COM_QUERY: case COM_STMT_PREPARE: if (is_slave_command(arg, length)) - SET_SLAVE(mysql, data); + SET_SLAVE(mysql, data) else - SET_MASTER(mysql,data); + SET_MASTER(mysql,data) break; case COM_STMT_EXECUTE: case COM_STMT_FETCH: if (data->pvio[MARIADB_SLAVE]->mysql->stmts && is_slave_stmt(data->pvio[MARIADB_SLAVE]->mysql, arg)) - SET_SLAVE(mysql, data); + SET_SLAVE(mysql, data) else - SET_MASTER(mysql,data); + SET_MASTER(mysql,data) break; default: - SET_MASTER(mysql,data); + SET_MASTER(mysql,data) break; } return 0; diff --git a/plugins/pvio/pvio_npipe.c b/plugins/pvio/pvio_npipe.c index 95b11a0b..623f6ba9 100644 --- a/plugins/pvio/pvio_npipe.c +++ b/plugins/pvio/pvio_npipe.c @@ -34,7 +34,9 @@ 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); size_t pvio_npipe_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length); +size_t pvio_npipe_async_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length); size_t pvio_npipe_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length); +size_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); my_bool 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); @@ -118,10 +120,10 @@ size_t pvio_npipe_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length) goto end; } if (GetLastError() == ERROR_IO_PENDING) - r= pvio_npipe_wait_io_or_timeout(pvio, 1, 0); - - if (!r) - r= cpipe->rw_size; + { + if (!pvio_npipe_wait_io_or_timeout(pvio, 1, 0)) + r= cpipe->rw_size; + } end: return r; } @@ -143,10 +145,10 @@ size_t pvio_npipe_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length) goto end; } if (GetLastError() == ERROR_IO_PENDING) - r= pvio_npipe_wait_io_or_timeout(pvio, 1, 0); - - if (!r) - r= cpipe->rw_size; + { + if (!pvio_npipe_wait_io_or_timeout(pvio, 1, 0)) + r= cpipe->rw_size; + } end: return r; } @@ -216,7 +218,7 @@ my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) if (!pvio || !cinfo) return 1; - if (!(cpipe= (struct st_pvio_npipe *)LocalAlloc(sizeof(struct st_pvio_npipe), 0))) + if (!(cpipe= (struct st_pvio_npipe *)LocalAlloc(LMEM_ZEROINIT, sizeof(struct st_pvio_npipe)))) { PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0, ""); return 1; @@ -249,7 +251,7 @@ my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) 0, /* no sharing */ NULL, /* default security attributes */ OPEN_EXISTING, - 0, /* default attributes */ + FILE_FLAG_OVERLAPPED, NULL)) != INVALID_HANDLE_VALUE) break; diff --git a/plugins/pvio/pvio_socket.c b/plugins/pvio/pvio_socket.c index 01df4775..809a6b97 100644 --- a/plugins/pvio/pvio_socket.c +++ b/plugins/pvio/pvio_socket.c @@ -948,7 +948,7 @@ my_bool pvio_socket_is_alive(MARIADB_PVIO *pvio) my_bool pvio_socket_has_data(MARIADB_PVIO *pvio, ssize_t *data_len) { struct st_pvio_socket *csock= NULL; - char tmp_buf[1024]; + char tmp_buf; ssize_t len; my_bool mode; diff --git a/unittest/libmariadb/CMakeLists.txt b/unittest/libmariadb/CMakeLists.txt index d8a8e695..7d1c0be4 100644 --- a/unittest/libmariadb/CMakeLists.txt +++ b/unittest/libmariadb/CMakeLists.txt @@ -21,7 +21,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/unittest/mytap) ADD_DEFINITIONS(-DLIBMARIADB) -SET(API_TESTS "features-10_2" "async" "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs" +SET(API_TESTS "t_aurora" "async" "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs" "sp" "result" "connection" "misc" "ps_new" "sqlite3" "thread" "dyncol") # Get finger print from server certificate @@ -31,18 +31,15 @@ IF(WITH_SSL) IF(EXISTS "${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs/server-cert.pem") MESSAGE(STATUS "certificates already exist") ELSE() - MESSAGE(STATUS "cerating certificates") - EXECUTE_PROCESS(COMMAND openssl req -x509 -newkey rsa:1024 -keyout server-key-enc.pem -out server-cert.pem -subj "/DC=com/DC=example/CN=server" -passout pass:qwerty - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs) - EXECUTE_PROCESS(COMMAND openssl rsa -in server-key-enc.pem -out server-key.pem -passin pass:qwerty -passout pass: - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs) - EXECUTE_PROCESS(COMMAND openssl req -x509 -newkey rsa:1024 -keyout client-key-enc.pem -out client-cert.pem -subj "/DC=com/DC=example/CN=client" -passout pass:qwerty - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs) - EXECUTE_PROCESS(COMMAND openssl rsa -in client-key-enc.pem -out client-key.pem -passin pass:qwerty -passout pass: - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs) - FILE(READ ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs/server-cert.pem F1) - FILE(READ ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs/client-cert.pem F2) - FILE(WRITE ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs/ca-cert.pem ${F1} ${F2}) + MESSAGE(STATUS "creating certificates") + IF(WIN32) + EXECUTE_PROCESS(COMMAND create_certs.bat + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs + OUTPUT_FILE x.1 ERROR_FILE x.2) + ELSE() + EXECUTE_PROCESS(COMMAND ./create_certs.sh + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs) + ENDIF() ENDIF() EXECUTE_PROCESS(COMMAND openssl x509 -in server-cert.pem -sha1 -fingerprint -noout @@ -60,8 +57,8 @@ IF(WITH_SSL) ENDIF() FOREACH(API_TEST ${API_TESTS}) - ADD_EXECUTABLE(${API_TEST} ${API_TEST}.c) - TARGET_LINK_LIBRARIES(${API_TEST} mytap mariadbclient ) + ADD_EXECUTABLE(${API_TEST} ${API_TEST}.c ${CMAKE_SOURCE_DIR}/libmariadb/getopt.c) + TARGET_LINK_LIBRARIES(${API_TEST} mytap libmariadb) ADD_TEST(${API_TEST} ${EXECUTABLE_OUTPUT_PATH}/${API_TEST}) SET_TESTS_PROPERTIES(${API_TEST} PROPERTIES TIMEOUT 120) ENDFOREACH(API_TEST) diff --git a/unittest/libmariadb/async.c b/unittest/libmariadb/async.c index a0c3381b..c9f6c49b 100644 --- a/unittest/libmariadb/async.c +++ b/unittest/libmariadb/async.c @@ -30,6 +30,20 @@ #define SL(s) (s), sizeof(s) +my_bool skip_async= 0; + +static int test_async(MYSQL *mysql) +{ + int type; + mariadb_get_info(mysql, MARIADB_CONNECTION_PVIO_TYPE, &type); + if (type > MARIADB_CONNECTION_TCP) + { + skip_async= 1; + diag("Asnyc IO not supported"); + } + return OK; +} + static int wait_for_mysql(MYSQL *mysql, int status) { @@ -126,6 +140,9 @@ static int async1(MYSQL *my) uint default_timeout; int i; + if (skip_async) + return SKIP; + for (i=0; i < 100; i++) { @@ -196,7 +213,12 @@ static int test_conc131(MYSQL *my) { int rc; /* this test needs to run under valgrind */ - MYSQL *mysql=mysql_init(NULL); + MYSQL *mysql; + + if (skip_async) + return SKIP; + + mysql= mysql_init(NULL); rc= mysql_options(mysql, MYSQL_OPT_NONBLOCK, 0); check_mysql_rc(rc, mysql); mysql_close(mysql); @@ -205,13 +227,19 @@ static int test_conc131(MYSQL *my) static int test_conc129(MYSQL *my) { - MYSQL *mysql= mysql_init(NULL); + MYSQL *mysql; + + if (skip_async) + return SKIP; + + mysql= mysql_init(NULL); FAIL_IF(mysql_close_start(mysql), "No error expected"); return OK; } struct my_tests_st my_tests[] = { + {"test_async", test_async, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"async1", async1, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc131", test_conc131, TEST_CONNECTION_NONE, 0, NULL, NULL}, {"test_conc129", test_conc129, TEST_CONNECTION_NONE, 0, NULL, NULL}, diff --git a/unittest/libmariadb/basic-t.c b/unittest/libmariadb/basic-t.c index 4e535852..02dcc294 100644 --- a/unittest/libmariadb/basic-t.c +++ b/unittest/libmariadb/basic-t.c @@ -55,13 +55,17 @@ static int test_conc75(MYSQL *my) { ulong thread_id= mysql_thread_id(mysql); /* force reconnect */ + mysql->reconnect= 1; + diag("killing connection"); mysql_kill(my, thread_id); - sleep(1); + sleep(2); + mysql_ping(mysql); rc= mysql_query(mysql, "load data local infile './nonexistingfile.csv' into table a (`a`)"); FAIL_IF(!test(mysql->options.client_flag | CLIENT_LOCAL_FILES), "client_flags not correct"); + diag("thread1: %d %d", thread_id, mysql_thread_id(mysql)); FAIL_IF(thread_id == mysql_thread_id(mysql), "new thread id expected"); - diag("cs: %s", mysql->charset->csname); - FAIL_IF(strcmp(mysql->charset->csname, "utf8"), "wrong character set"); + //diag("cs: %s", mysql->charset->csname); + //FAIL_IF(strcmp(mysql->charset->csname, "utf8"), "wrong character set"); } mysql_close(mysql); return OK; @@ -76,7 +80,12 @@ static int test_conc74(MYSQL *my) mysql= mysql_init(NULL); - mysql_real_connect(mysql, hostname, username, password, schema, port, socketname, 0| CLIENT_MULTI_RESULTS | CLIENT_REMEMBER_OPTIONS); + if (!mysql_real_connect(mysql, hostname, username, password, schema, port, socketname, 0| CLIENT_MULTI_RESULTS | CLIENT_REMEMBER_OPTIONS)) + { + diag("Error: %s", mysql_error(mysql)); + mysql_close(mysql); + return FAIL; + } rc= mysql_query(mysql, "DROP TABLE IF EXISTS a"); check_mysql_rc(rc, mysql); @@ -128,7 +137,11 @@ static int test_conc70(MYSQL *my) int rc; MYSQL_RES *res; MYSQL_ROW row; - MYSQL *mysql= mysql_init(NULL); + MYSQL *mysql; + + SKIP_CONNECTION_HANDLER; + + mysql= mysql_init(NULL); rc= mysql_query(my, "SET @a:=@@max_allowed_packet"); check_mysql_rc(rc, my); @@ -148,6 +161,14 @@ static int test_conc70(MYSQL *my) rc= mysql_query(mysql, "INSERT INTO t1 VALUES (REPEAT('A', 1024 * 1024 * 20))"); check_mysql_rc(rc, mysql); + if (mysql_warning_count(mysql)) + { + diag("server doesn't accept package size"); + return SKIP; + } + + sleep(20); + rc= mysql_query(mysql, "SELECT a FROM t1"); check_mysql_rc(rc, mysql); @@ -175,7 +196,11 @@ static int test_conc68(MYSQL *my) int rc; MYSQL_RES *res; MYSQL_ROW row; - MYSQL *mysql= mysql_init(NULL); + MYSQL *mysql; + + SKIP_CONNECTION_HANDLER; + + mysql= mysql_init(NULL); rc= mysql_query(my, "SET @a:=@@max_allowed_packet"); check_mysql_rc(rc, my); @@ -193,6 +218,11 @@ static int test_conc68(MYSQL *my) rc= mysql_query(mysql, "INSERT INTO t1 VALUES (REPEAT('A', 1024 * 1024 * 20))"); check_mysql_rc(rc, mysql); + if (mysql_warning_count(mysql)) + { + diag("server doesn't accept package size"); + return SKIP; + } rc= mysql_query(mysql, "SELECT a FROM t1"); check_mysql_rc(rc, mysql); @@ -427,7 +457,7 @@ static int test_mysql_insert_id(MYSQL *mysql) FAIL_UNLESS(res == 400, ""); /* table with auto_increment column */ - rc= mysql_query(mysql, "create table t2 (f1 int not null primary key auto_increment, f2 varchar(255))"); + rc= mysql_query(mysql, "create table t2 (f1 int not null primary key auto_increment, f2 varchar(255)) engine=MyISAM"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "insert into t2 values (1,'a')"); check_mysql_rc(rc, mysql); @@ -504,12 +534,13 @@ static int test_mysql_insert_id(MYSQL *mysql) according to the manual, this might be 20 or 300, but it looks like auto_increment column takes priority over last_insert_id(). */ + diag("res: %d", res); FAIL_UNLESS(res == 20, ""); /* If first autogenerated number fails and 2nd works: */ rc= mysql_query(mysql, "drop table t2"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "create table t2 (f1 int not null primary key " - "auto_increment, f2 varchar(255), unique (f2))"); + "auto_increment, f2 varchar(255), unique (f2)) engine=MyISAM"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "insert into t2 values (null,'e')"); res= mysql_insert_id(mysql); @@ -618,12 +649,9 @@ static int bug_conc1(MYSQL *mysql) { mysql_real_connect(mysql, hostname, username, password, schema, port, socketname, 0); + diag("errno: %d", mysql_errno(mysql)); FAIL_IF(mysql_errno(mysql) != CR_ALREADY_CONNECTED, "Expected errno=CR_ALREADY_CONNECTED"); - FAIL_IF(strcmp(mysql_error(mysql), ER(CR_ALREADY_CONNECTED)) != 0, - "Wrong error message"); - FAIL_IF(strcmp(ER(CR_ALREADY_CONNECTED), "Can't connect twice. Already connected") != 0, - "wrong error message"); return OK; } @@ -668,11 +696,14 @@ static int test_reconnect_maxpackage(MYSQL *my) { int rc; ulong max_packet= 0; - MYSQL *mysql= mysql_init(NULL); + MYSQL *mysql; MYSQL_RES *res; MYSQL_ROW row; char *query; + SKIP_CONNECTION_HANDLER; + mysql= mysql_init(NULL); + FAIL_IF(!mysql_real_connect(mysql, hostname, username, password, schema, port, socketname, CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS), mysql_error(mysql)); @@ -770,6 +801,8 @@ int main(int argc, char **argv) get_envvars(); + diag("user: %s", username); + run_tests(my_tests); return(exit_status()); diff --git a/unittest/libmariadb/certs/create_certs.sh b/unittest/libmariadb/certs/create_certs.sh deleted file mode 100755 index 47ea98e8..00000000 --- a/unittest/libmariadb/certs/create_certs.sh +++ /dev/null @@ -1,15 +0,0 @@ -openssl req -x509 -newkey rsa:1024 \ --keyout server-key-enc.pem -out server-cert.pem \ --subj '/DC=com/DC=example/CN=server' -passout pass:qwerty - -openssl rsa -in server-key-enc.pem -out server-key.pem \ --passin pass:qwerty -passout pass: - -openssl req -x509 -newkey rsa:1024 \ --keyout client-key-enc.pem -out client-cert.pem \ --subj '/DC=com/DC=example/CN=client' -passout pass:qwerty - -openssl rsa -in client-key-enc.pem -out client-key.pem \ --passin pass:qwerty -passout pass: - -cat server-cert.pem client-cert.pem > ca-cert.pem diff --git a/unittest/libmariadb/certs/dummy.pem b/unittest/libmariadb/certs/dummy.pem deleted file mode 100644 index 1fc34aa1..00000000 --- a/unittest/libmariadb/certs/dummy.pem +++ /dev/null @@ -1,21 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDXTCCAkWgAwIBAgIJAL4tmDe5DR0sMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV -BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX -aWRnaXRzIFB0eSBMdGQwHhcNMTUwMzEwMjAyMDI4WhcNMTYwMzA5MjAyMDI4WjBF -MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50 -ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB -CgKCAQEApV9UfWmeXYdexOEn+adOm6FdJUhKMrjTiycwETmDXRVpY4wl+LNGsANp -ohSRovDjFiFO+Ti0bUhpf552oE23wYw+P6f0UY0KkV/PgSght1Ezfffe0BaEjI0X -tA5zdNmxzL3OUWJVcg+I4UE3rbYFHUgymu72P0IRXjmJv1tToNxUxbTBLxU/KAlq -Uy49upB3q3/IPOdP9UzAZDHnRv1gjwUzNgumfcc5d5lSsGpwLDYCQs4I539fCkBD -MfU2BN/qpmPhb/nm5ZUdFUFYGN+XxVPVpJLmeWVRwMSQR2LN5CkqnK9e2Q/QaJ53 -G3AAng+fpfEGPpjQdFWuhFjQozOD0wIDAQABo1AwTjAdBgNVHQ4EFgQUyg6WfzL2 -JhhjKm1Ex28s4Y3vNGQwHwYDVR0jBBgwFoAUyg6WfzL2JhhjKm1Ex28s4Y3vNGQw -DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOCAQEAIrj/bHiRf8UJIfv8hyZ1 -dXEqvqjxUMXtJ/QhhCQs42p9pHv+mPTkeXh0K18Oj6k/Vp4J1/0mp/kqiQUHt9yO -/3pJPc+JordTjlVLgb95cfBIs4yiPT9biGaA7j0Dh9EcDBOCT4v56Z9BLqGMfBUK -YeZ7ZecWmZCZOYk/X+CPB30GxLy5Wm9D50qEUXXBPZ9Bie6FYaQYOFlQlqxYuLX0 -NVqLDvX6zz6FMsgqoyDJ1BMuMsjPDUUUrwGY+R3YqiqkPRbDkr8zvzpqiYvjTZi0 -LTJO7GRfwzfhkeEPL/hl/TYdB1GZHixMrAKx1HGKHAa0sgWTWxQGYhfclH8DI7AR -Tw== ------END CERTIFICATE----- diff --git a/unittest/libmariadb/charset.c b/unittest/libmariadb/charset.c index b5cdbf89..0226bc18 100644 --- a/unittest/libmariadb/charset.c +++ b/unittest/libmariadb/charset.c @@ -679,7 +679,7 @@ static int test_utf16_utf32_noboms(MYSQL *mysql) for (i= 0; i < sizeof(csname)/sizeof(char*); ++i) { - csinfo[i]= mysql_find_charset_name(csname[i]); + csinfo[i]= mariadb_get_charset_by_name(csname[i]); if (csinfo[i] == NULL) { diff --git a/unittest/libmariadb/connection.c b/unittest/libmariadb/connection.c index 11452977..0ce22450 100644 --- a/unittest/libmariadb/connection.c +++ b/unittest/libmariadb/connection.c @@ -32,6 +32,7 @@ static int test_conc66(MYSQL *my) MYSQL *mysql= mysql_init(NULL); int rc; FILE *fp; + char query[1024]; if (!(fp= fopen("./my.cnf", "w"))) return FAIL; @@ -47,7 +48,8 @@ static int test_conc66(MYSQL *my) rc= mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "./my.cnf"); check_mysql_rc(rc, mysql); - rc= mysql_query(my, "GRANT ALL ON test.* TO 'conc66'@'localhost' IDENTIFIED BY 'test\";#test'"); + sprintf(query, "GRANT ALL ON %s.* TO 'conc66'@'%s' IDENTIFIED BY 'test\";#test'", schema, hostname); + rc= mysql_query(my, query); check_mysql_rc(rc, my); rc= mysql_query(my, "FLUSH PRIVILEGES"); check_mysql_rc(rc, my); @@ -57,7 +59,8 @@ static int test_conc66(MYSQL *my) diag("Error: %s", mysql_error(mysql)); return FAIL; } - rc= mysql_query(my, "DROP USER conc66@localhost"); + sprintf(query, "DROP user conc66@%s", hostname); + rc= mysql_query(my, query); check_mysql_rc(rc, my); mysql_close(mysql); @@ -561,6 +564,8 @@ static int test_reconnect(MYSQL *mysql) mysql_kill(mysql, mysql_thread_id(mysql1)); sleep(4); + mysql_ping(mysql1); + rc= mysql_query(mysql1, "SELECT 1 FROM DUAL LIMIT 0"); check_mysql_rc(rc, mysql1); diag("Thread_id after kill: %lu", mysql_thread_id(mysql1)); @@ -649,6 +654,8 @@ static int test_conc118(MYSQL *mysql) rc= mysql_kill(mysql, mysql_thread_id(mysql)); sleep(2); + mysql_ping(mysql); + rc= mysql_query(mysql, "SET @a:=1"); check_mysql_rc(rc, mysql); @@ -657,12 +664,7 @@ static int test_conc118(MYSQL *mysql) rc= mysql_kill(mysql, mysql_thread_id(mysql)); sleep(2); - mysql->host= "foo"; - - rc= mysql_query(mysql, "SET @a:=1"); - FAIL_IF(!rc, "error expected"); - - mysql->host= hostname; + mysql_ping(mysql); rc= mysql_query(mysql, "SET @a:=1"); check_mysql_rc(rc, mysql); @@ -740,7 +742,92 @@ static int test_bind_address(MYSQL *my) return OK; } +static int test_get_options(MYSQL *my) +{ + MYSQL *mysql= mysql_init(NULL); + int options_int[]= {MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_LOCAL_INFILE, + MYSQL_OPT_RECONNECT, MYSQL_OPT_PROTOCOL, MYSQL_OPT_READ_TIMEOUT, MYSQL_OPT_WRITE_TIMEOUT, 0}; + my_bool options_bool[]= {MYSQL_OPT_COMPRESS, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_SECURE_AUTH, +#ifdef _WIN32 + MYSQL_OPT_NAMED_PIPE, +#endif + 0}; + int options_char[]= {MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP, MYSQL_SET_CHARSET_NAME, + MYSQL_OPT_SSL_KEY, MYSQL_OPT_SSL_CA, MYSQL_OPT_SSL_CERT, MYSQL_OPT_SSL_CAPATH, + MYSQL_OPT_SSL_CIPHER, MYSQL_OPT_BIND, MARIADB_OPT_SSL_FP, MARIADB_OPT_SSL_FP_LIST, + MARIADB_OPT_SSL_PASSWORD, 0}; + + char *init_command[3]= {"SET @a:=1", "SET @b:=2", "SET @c:=3"}; + int elements= 0; + char **command; + + + int intval[2]= {1, 0}; + my_bool boolval[2]= {1, 0}; + char *char1= "test", *char2; + int i; + MYSQL *userdata; + char *attr_key[] = {"foo1", "foo2", "foo3"}; + char *attr_val[] = {"bar1", "bar2", "bar3"}; + char **key, **val; + + for (i=0; options_int[i]; i++) + { + mysql_options(mysql, options_int[i], &intval[0]); + intval[1]= 0; + mysql_get_optionv(mysql, options_int[i], &intval[1]); + FAIL_IF(intval[0] != intval[1], "mysql_get_optionv (int) failed"); + } + for (i=0; options_bool[i]; i++) + { + mysql_options(mysql, options_bool[i], &boolval[0]); + intval[1]= 0; + mysql_get_optionv(mysql, options_bool[i], &boolval[1]); + FAIL_IF(boolval[0] != boolval[1], "mysql_get_optionv (my_bool) failed"); + } + for (i=0; options_char[i]; i++) + { + mysql_options(mysql, options_char[i], char1); + char2= NULL; + mysql_get_optionv(mysql, options_char[i], (void *)&char2); + FAIL_IF(strcmp(char1, char2), "mysql_get_optionv (char) failed"); + } + + for (i=0; i < 3; i++) + mysql_options(mysql, MYSQL_INIT_COMMAND, init_command[i]); + + mysql_get_optionv(mysql, MYSQL_INIT_COMMAND, &command, &elements); + FAIL_IF(elements != 3, "expected 3 elements"); + for (i=0; i < 3; i++) + FAIL_IF(strcmp(init_command[i], command[i]), "wrong init command"); + for (i=0; i < 3; i++) + mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, attr_key[i], attr_val[i]); + + mysql_get_optionv(mysql, MYSQL_OPT_CONNECT_ATTRS, NULL, NULL, &elements); + FAIL_IF(elements != 3, "expected 3 connection attributes"); + + key= (char **)malloc(sizeof(char *) * elements); + val= (char **)malloc(sizeof(char *) * elements); + + mysql_get_optionv(mysql, MYSQL_OPT_CONNECT_ATTRS, &key, &val, &elements); + for (i=0; i < elements; i++) + { + diag("%s => %s", key[i], val[i]); + } + + free(key); + free(val); + + mysql_optionsv(mysql, MARIADB_OPT_USERDATA, "my_app", (void *)mysql); + mysql_get_optionv(mysql, MARIADB_OPT_USERDATA, "my_app", &userdata); + + FAIL_IF(mysql != userdata, "wrong userdata"); + mysql_close(mysql); + return OK; +} + struct my_tests_st my_tests[] = { + {"test_get_options", test_get_options, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_wrong_bind_address", test_wrong_bind_address, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_bind_address", test_bind_address, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc118", test_conc118, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, diff --git a/unittest/libmariadb/cursor.c b/unittest/libmariadb/cursor.c index 97a75bc2..97bafd2e 100644 --- a/unittest/libmariadb/cursor.c +++ b/unittest/libmariadb/cursor.c @@ -59,12 +59,12 @@ MYSQL_STMT *open_cursor(MYSQL *mysql, const char *query) fetch buffers. */ -int stmt_fetch_init(MYSQL *mysql, Stmt_fetch *fetch, unsigned stmt_no_arg, +int stmt_fetch_init(MYSQL *mysql, Stmt_fetch *fetch, unsigned int stmt_no_arg, const char *query_arg) { unsigned long type= CURSOR_TYPE_READ_ONLY; int rc; - unsigned i; + unsigned int i; MYSQL_RES *metadata; /* Save query and statement number for error messages */ @@ -180,7 +180,7 @@ int fetch_n(MYSQL *mysql, const char **query_list, unsigned query_count, for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch) { - if (stmt_fetch_init(mysql, fetch, fetch - fetch_array, + if (stmt_fetch_init(mysql, fetch, (unsigned int)(fetch - fetch_array), query_list[fetch - fetch_array])) return FAIL; } @@ -322,7 +322,7 @@ static int test_bug21206(MYSQL *mysql) for (fetch= fetch_array; fetch < fetch_array + cursor_count; ++fetch) { - if ((retcode= stmt_fetch_init(mysql, fetch, fetch - fetch_array, query))) + if ((retcode= stmt_fetch_init(mysql, fetch, (unsigned int)(fetch - fetch_array), query))) break; } diff --git a/unittest/libmariadb/logs.c b/unittest/libmariadb/logs.c index 534feeb2..38dfd8a7 100644 --- a/unittest/libmariadb/logs.c +++ b/unittest/libmariadb/logs.c @@ -89,7 +89,7 @@ static int test_logs(MYSQL *mysql) my_bind[1].buffer_type= MYSQL_TYPE_STRING; my_bind[1].buffer= (void *)&data; my_bind[1].buffer_length= 255; - my_bind[1].length= &length; + my_bind[1].length= (unsigned long *)&length; id= 9876; strcpy((char *)data, "MySQL - Open Source Database"); diff --git a/unittest/libmariadb/misc.c b/unittest/libmariadb/misc.c index ede78ace..1dd9f478 100644 --- a/unittest/libmariadb/misc.c +++ b/unittest/libmariadb/misc.c @@ -266,7 +266,7 @@ static int test_frm_bug(MYSQL *mysql) sprintf(test_frm, "%s/%s/test_frm_bug.frm", data_dir, schema); - if (!(test_file= my_fopen(test_frm, (int) (O_RDWR | O_CREAT), MYF(MY_WME)))) + if (!(test_file= fopen(test_frm, "rw"))) { mysql_stmt_close(stmt); diag("Can't write to file %s -> SKIP", test_frm); @@ -294,7 +294,7 @@ static int test_frm_bug(MYSQL *mysql) mysql_free_result(result); mysql_stmt_close(stmt); - my_fclose(test_file, MYF(0)); + fclose(test_file); mysql_query(mysql, "drop table if exists test_frm_bug"); return OK; } @@ -1021,11 +1021,74 @@ static int test_remote2(MYSQL *my) } #endif +static int test_get_info(MYSQL *mysql) +{ + size_t sval; + unsigned int ival; + char *cval; + int rc; + MY_CHARSET_INFO cs; + CHARSET_INFO *ci; + char **errors; + + rc= mariadb_get_infov(mysql, MARIADB_MAX_ALLOWED_PACKET, &sval); + FAIL_IF(rc, "mysql_get_info failed"); + diag("max_allowed_packet: %d", sval); + rc= mariadb_get_infov(mysql, MARIADB_NET_BUFFER_LENGTH, &sval); + FAIL_IF(rc, "mysql_get_info failed"); + diag("net_buffer_length: %d", sval); + rc= mariadb_get_infov(mysql, MARIADB_CLIENT_VERSION_ID, &sval); + FAIL_IF(rc, "mysql_get_info failed"); + diag("client_version_id: %d", sval); + rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_VERSION_ID, &sval); + FAIL_IF(rc, "mysql_get_info failed"); + diag("server_version_id: %d", sval); + rc= mariadb_get_infov(mysql, MARIADB_CHARSET_INFO, &cs); + FAIL_IF(rc, "mysql_get_info failed"); + diag("charset name: %s", cs.csname); + rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_PVIO_TYPE, &ival); + FAIL_IF(rc, "mysql_get_info failed"); + diag("connection type: %d", ival); + rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_PROTOCOL_VERSION_ID, &ival); + FAIL_IF(rc, "mysql_get_info failed"); + diag("protocol_version: %d", ival); + rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_TYPE, &cval); + FAIL_IF(rc, "mysql_get_info failed"); + diag("server_type: %s", cval); + rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_VERSION, &cval); + FAIL_IF(rc, "mysql_get_info failed"); + diag("server_version: %s", cval); + rc= mariadb_get_infov(mysql, MARIADB_CLIENT_VERSION, &cval); + FAIL_IF(rc, "mysql_get_info failed"); + diag("client_version: %s", cval); + rc= mariadb_get_infov(mysql, MARIADB_CHARSET_NAME, &ci, "utf8"); + FAIL_IF(rc, "mysql_get_info failed"); + diag("charset_name: %s", ci->csname); + diag("charset_nr: %d", ci->nr); + rc= mariadb_get_infov(mysql, MARIADB_CHARSET_ID, &ci, 63); + FAIL_IF(rc, "mysql_get_info failed"); + diag("charset_name: %s", ci->csname); + rc= mariadb_get_infov(mysql, MARIADB_CLIENT_ERRORS, &errors); + FAIL_IF(rc, "mysql_get_info failed"); + diag("error[0]: %s", errors[0]); + rc= mysql_query(mysql, "DROP TABLE IF exists t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE t1 (a int)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1),(2)"); + check_mysql_rc(rc, mysql); + rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_INFO, &cval); + FAIL_IF(rc, "mysql_get_info failed"); + diag("mariadb_info: %s", cval); + return OK; +} + 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_get_info", test_get_info, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"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/my_test.h b/unittest/libmariadb/my_test.h index e862ced1..e0db2beb 100644 --- a/unittest/libmariadb/my_test.h +++ b/unittest/libmariadb/my_test.h @@ -82,6 +82,13 @@ if (!(expr))\ return FAIL;\ } +#define SKIP_CONNECTION_HANDLER \ + if (hostname && strstr(hostname, "://"))\ + {\ + diag("Test skipped (connection handler)");\ + return SKIP;\ + } + /* connection options */ #define TEST_CONNECTION_DEFAULT 1 /* default connection */ #define TEST_CONNECTION_NONE 2 /* tests creates own connection */ @@ -104,7 +111,7 @@ struct my_tests_st char *skipmsg; }; -static char *schema = "test_c"; +static char *schema = 0; static char *hostname = 0; static char *password = 0; static unsigned int port = 0; @@ -368,18 +375,19 @@ int check_variable(MYSQL *mysql, char *variable, char *value) MYSQL *test_connect(struct my_tests_st *test) { MYSQL *mysql; char query[255]; - int i= 1; + int i= 0; + int timeout= 10; + int truncation_report= 1; if (!(mysql = mysql_init(NULL))) { diag("%s", "mysql_init failed - exiting"); return(NULL); } - mysql_options(mysql, MYSQL_REPORT_DATA_TRUNCATION, &i); - mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&i); + mysql_options(mysql, MYSQL_REPORT_DATA_TRUNCATION, &truncation_report); + mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, &timeout); /* option handling */ if (test && test->options) { - int i=0; while (test->options[i].option) { @@ -403,6 +411,8 @@ MYSQL *test_connect(struct my_tests_st *test) { /* change database or create if it doesn't exist */ if (mysql_select_db(mysql, schema)) { + diag("Error number: %d", mysql_errno(mysql)); + if(mysql_errno(mysql) == 1049) { sprintf(query, "CREATE DATABASE %s", schema); if (mysql_query(mysql, query)) { @@ -425,11 +435,6 @@ static int reset_connection(MYSQL *mysql) { rc= mysql_change_user(mysql, username, password, schema); check_mysql_rc(rc, mysql); - if (mysql_get_server_version(mysql) < 50400) - rc= mysql_query(mysql, "SET table_type='MyISAM'"); - else - rc= mysql_query(mysql, "SET storage_engine='MyISAM'"); - check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "SET sql_mode=''"); check_mysql_rc(rc, mysql); @@ -452,6 +457,8 @@ void get_envvars() { password= envvar; if (!schema && (envvar= getenv("MYSQL_TEST_DB"))) schema= envvar; + if (!schema) + schema= "testc"; if (!port && (envvar= getenv("MYSQL_TEST_PORT"))) port= atoi(envvar); if (!socketname && (envvar= getenv("MYSQL_TEST_SOCKET"))) @@ -470,7 +477,8 @@ void run_tests(struct my_tests_st *test) { if ((mysql_default= test_connect(NULL))) { diag("Testing against MySQL Server %s", mysql_get_server_info(mysql_default)); - diag("Host %s", mysql_get_host_info(mysql_default)); + diag("Host: %s", mysql_get_host_info(mysql_default)); + diag("Client library: %s", mysql_get_client_info()); } else { diff --git a/unittest/libmariadb/ps.c b/unittest/libmariadb/ps.c index 1c96baca..add7a493 100644 --- a/unittest/libmariadb/ps.c +++ b/unittest/libmariadb/ps.c @@ -64,7 +64,10 @@ static int test_conc83(MYSQL *my) /* 1. Status is inited, so prepare should work */ rc= mysql_kill(mysql, mysql_thread_id(mysql)); - sleep(2); + sleep(5); + + rc= mysql_ping(mysql); + check_mysql_rc(rc, mysql); rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_stmt_rc(rc, stmt); @@ -1383,7 +1386,7 @@ static int test_long_data_str1(MYSQL *mysql) my_bind[0].buffer= data; /* string data */ my_bind[0].buffer_length= sizeof(data); - my_bind[0].length= &length1; + my_bind[0].length= (unsigned long *)&length1; my_bind[0].buffer_type= MYSQL_TYPE_STRING; length1= 0; @@ -1482,7 +1485,7 @@ static int test_long_data_str1(MYSQL *mysql) my_bind[0].buffer_type= MYSQL_TYPE_BLOB; my_bind[0].buffer= (void *) &data; /* this buffer won't be altered */ my_bind[0].buffer_length= 16; - my_bind[0].length= &blob_length; + my_bind[0].length= (unsigned long *)&blob_length; my_bind[0].error= &my_bind[0].error_value; rc= mysql_stmt_bind_result(stmt, my_bind); data[16]= 0; @@ -1498,7 +1501,7 @@ static int test_long_data_str1(MYSQL *mysql) my_bind[1].buffer_type= MYSQL_TYPE_BLOB; my_bind[1].buffer= (void *) &data; /* this buffer won't be altered */ my_bind[1].buffer_length= sizeof(data); - my_bind[1].length= &blob_length; + my_bind[1].length= (unsigned long *)&blob_length; memset(data, '\0', sizeof(data)); mysql_stmt_fetch_column(stmt, my_bind+1, 0, 0); FAIL_UNLESS(strlen(data) == max_blob_length, "strlen(data) != max_blob_length"); diff --git a/unittest/libmariadb/ps_bugs.c b/unittest/libmariadb/ps_bugs.c index bd072646..e5204ea4 100644 --- a/unittest/libmariadb/ps_bugs.c +++ b/unittest/libmariadb/ps_bugs.c @@ -528,9 +528,8 @@ static int test_bug12744(MYSQL *mysql) rc= mysql_options(mysql, MYSQL_OPT_RECONNECT, "1"); check_mysql_rc(rc, mysql); rc= mysql_kill(mysql, mysql_thread_id(mysql)); - check_mysql_rc(rc, mysql); - sleep(2); + sleep(4); rc= mysql_ping(mysql); check_mysql_rc(rc, mysql); @@ -644,7 +643,7 @@ static int test_bug1500(MYSQL *mysql) data= "Grave"; my_bind[0].buffer_type= MYSQL_TYPE_STRING; my_bind[0].buffer= (void *) data; - my_bind[0].buffer_length= strlen(data); + my_bind[0].buffer_length= (unsigned long)strlen(data); rc= mysql_stmt_bind_param(stmt, my_bind); check_stmt_rc(rc, stmt); @@ -2652,7 +2651,7 @@ static int test_bug5194(MYSQL *mysql) for (i= 1; i < COLUMN_COUNT; ++i) strcat(param_str, "?, "); strcat(param_str, "?)"); - param_str_length= strlen(param_str); + param_str_length= (int)strlen(param_str); /* setup bind array */ memset(my_bind, '\0', MAX_PARAM_COUNT * sizeof(MYSQL_BIND)); @@ -3230,7 +3229,7 @@ static int test_mem_overun(MYSQL *mysql) sprintf(field, "c%d int, ", i); strcat(buffer, field); } - length= strlen(buffer); + length= (int)strlen(buffer); buffer[length-2]= ')'; buffer[--length]= '\0'; @@ -3242,7 +3241,7 @@ static int test_mem_overun(MYSQL *mysql) { strcat(buffer, "1, "); } - length= strlen(buffer); + length= (int)strlen(buffer); buffer[length-2]= ')'; buffer[--length]= '\0'; diff --git a/unittest/libmariadb/ssl.c.in b/unittest/libmariadb/ssl.c.in index b6e51965..6982e41b 100644 --- a/unittest/libmariadb/ssl.c.in +++ b/unittest/libmariadb/ssl.c.in @@ -51,12 +51,20 @@ static int check_cipher(MYSQL *mysql) char *cipher= (char *)mysql_get_ssl_cipher(mysql); if (!cipher) return 1; + diag("cipher: %s", cipher); + #ifdef HAVE_GNUTLS - return strcmp(cipher, "AES-128-GCM"); -#endif -#ifdef HAVE_OPENSSL - return strcmp(cipher, "DHE-RSA-AES256-SHA"); + { + return strcmp(cipher, "AES-128-GCM"); + } +#elif HAVE_OPENSSL + if (!strcmp(cipher, "DHE-RSA-AES256-SHA") || + !strcmp(cipher, "DHE-RSA-AES256-GCM-SHA384")) + return 0; +#elif HAVE_SCHANNEL + return strcmp(cipher, "CALG_AES_256"); #endif + return 1; } static int create_ssl_user(const char *ssluser, my_bool is_X509) @@ -105,6 +113,14 @@ static int test_ssl(MYSQL *mysql) } mysql_free_result(res); +#ifdef HAVE_GNUTLS + diag("SSL library: GNUTLS"); +#elif HAVE_OPENSSL + diag("SSL library: OPENSSL"); +#elif HAVE_SCHANNEL + diag("SSL library: SCHANNEL"); +#endif + sslhost[0]= 0; if (!skip_ssl) @@ -127,6 +143,9 @@ static int test_ssl(MYSQL *mysql) static int test_ssl_cipher(MYSQL *unused) { MYSQL *my; + MYSQL_RES *res; + MYSQL_ROW row; + int rc; if (check_skip_ssl()) return SKIP; @@ -139,6 +158,14 @@ static int test_ssl_cipher(MYSQL *unused) FAIL_IF(!mysql_real_connect(my, hostname, ssluser, sslpw, schema, port, socketname, 0), mysql_error(my)); + rc= mysql_query(my, "SHOW session status like 'Ssl_version'"); + check_mysql_rc(rc, my); + res= mysql_store_result(my); + row= mysql_fetch_row(res); + diag("%s: %s", row[0], row[1]); + diag("cipher: %s", mysql_get_ssl_cipher(my)); + mysql_free_result(res); + FAIL_IF(check_cipher(my) != 0, "Invalid cipher"); mysql_close(my); return OK; @@ -268,6 +295,7 @@ DWORD WINAPI ssl_thread(void *dummy) mysql_close(mysql); mysql_thread_end(); pthread_exit(0); + return; } static int test_ssl_threads(MYSQL *mysql) @@ -291,6 +319,7 @@ static int test_ssl_threads(MYSQL *mysql) check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "INSERT into ssltest VALUES (0)"); check_mysql_rc(rc, mysql); + pthread_mutex_init(&LOCK_test, NULL); pthread_mutex_init(&LOCK_test, NULL); @@ -478,7 +507,7 @@ static int test_conc50_3(MYSQL *my) mysql_ssl_set(mysql, NULL, NULL, "@CMAKE_SOURCE_DIR@/unittest/libmariadb/certs/ca-cert.pem", NULL, NULL); - mysql_real_connect(mysql, hostname, "ssltest", NULL, schema, + mysql_real_connect(mysql, hostname, ssluser, sslpw, schema, port, socketname, 0); diag("Error: %s<", mysql_error(mysql)); FAIL_IF(mysql_errno(mysql), "No error expected"); @@ -640,12 +669,16 @@ static int test_conc_102(MYSQL *mysql) DWORD threads[50]; #endif + if (check_skip_ssl()) + return SKIP; + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t_conc102"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "CREATE TABLE t_conc102 ( a int)"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "INSERT INTO t_conc102 VALUES (0)"); check_mysql_rc(rc, mysql); + pthread_mutex_init(&LOCK_test, NULL); for (i=0; i < 50; i++) { @@ -665,6 +698,7 @@ static int test_conc_102(MYSQL *mysql) WaitForSingleObject(hthreads[i], INFINITE); #endif } + pthread_mutex_destroy(&LOCK_test); rc= mysql_query(mysql, "SELECT a FROM t_conc102"); check_mysql_rc(rc, mysql); res= mysql_store_result(mysql); @@ -699,10 +733,10 @@ static int test_ssl_fp(MYSQL *unused) FAIL_IF(check_cipher(my) != 0, "Invalid cipher"); - mysql_query(my, "SET @a:=1"); + rc= mysql_query(my, "SET @a:=1"); check_mysql_rc(rc, my); - mysql_query(my, "SELECT @a"); + rc= mysql_query(my, "SELECT @a"); check_mysql_rc(rc, my); if ((res= mysql_store_result(my))) @@ -738,7 +772,33 @@ static int test_ssl_fp_list(MYSQL *unused) return OK; } +static int test_ssl_version(MYSQL *mysql) +{ + unsigned int iversion; + char *version; + MYSQL *my; + if (check_skip_ssl()) + return SKIP; + + my= mysql_init(NULL); + FAIL_IF(!my, "mysql_init() failed"); + + mysql_ssl_set(my,0, 0, "@CMAKE_SOURCE_DIR@/unittest/libmariadb/certs/ca-cert.pem", 0, 0); + FAIL_IF(!mysql_real_connect(my, hostname, ssluser, sslpw, schema, + port, socketname, 0), mysql_error(my)); + + diag("cipher: %s", mysql_get_ssl_cipher(my)); + mariadb_get_infov(my, MARIADB_CONNECTION_SSL_VERSION_ID, &iversion); + diag("protocol: %d", iversion); + mariadb_get_infov(my, MARIADB_CONNECTION_SSL_VERSION, &version); + diag("protocol: %s", version); + + mysql_close(my); + + return OK; +} + struct my_tests_st my_tests[] = { {"test_ssl", test_ssl, TEST_CONNECTION_NEW, 0, NULL, NULL}, @@ -757,9 +817,11 @@ struct my_tests_st my_tests[] = { {"test_ssl_cipher", test_ssl_cipher, TEST_CONNECTION_NONE, 0, NULL, NULL}, {"test_multi_ssl_connections", test_multi_ssl_connections, TEST_CONNECTION_NONE, 0, NULL, NULL}, {"test_conc_102", test_conc_102, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_ssl_version", test_ssl_version, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_ssl_threads", test_ssl_threads, TEST_CONNECTION_NEW, 0, NULL, NULL}, +#ifndef HAVE_SCHANNEL {"test_password_protected", test_password_protected, TEST_CONNECTION_NEW, 0, NULL, NULL}, - +#endif {NULL, NULL, 0, 0, NULL, NULL} }; diff --git a/unittest/libmariadb/t_aurora.c b/unittest/libmariadb/t_aurora.c new file mode 100644 index 00000000..d9c89c45 --- /dev/null +++ b/unittest/libmariadb/t_aurora.c @@ -0,0 +1,67 @@ +/* +*/ + +#include "my_test.h" + +static int aurora1(MYSQL *mysql) +{ + int rc; + my_bool read_only= 1; + char *primary, *replica; + MYSQL_RES *res; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a int, b varchar(20))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1, 'foo'), (2, 'bar')"); + check_mysql_rc(rc, mysql); + + primary= mysql->host; + diag("primary: %s", primary); + + mysql_options(mysql, MARIADB_OPT_CONNECTION_READ_ONLY, &read_only); + + /* ensure, that this is a replica, so INSERT should fail */ + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (3, 'error')"); + if (rc) + diag("Expected error: %s", mysql_error(mysql)); + + rc= mysql_query(mysql, "SELECT a, b FROM t1"); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(mysql); + + diag("Num_rows: %d", mysql_num_rows(res)); + mysql_free_result(res); + + replica= mysql->host; + diag("replica: %s", replica); + diag("db: %s", mysql->db); + + return OK; +} + +struct my_tests_st my_tests[] = { + {"aurora1", aurora1, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + + +int main(int argc, char **argv) +{ + + mysql_library_init(0,0,NULL); + + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + mysql_server_end(); + return(exit_status()); +} diff --git a/win-iconv/win_iconv.c b/win-iconv/win_iconv.c index 6699c022..d1740fe1 100644 --- a/win-iconv/win_iconv.c +++ b/win-iconv/win_iconv.c @@ -789,7 +789,7 @@ win_iconv(iconv_t _cd, const char **inbuf, size_t *inbytesleft, char **outbuf, s if (outbuf != NULL && *outbuf != NULL && cd->to.flush != NULL) { tomode = cd->to.mode; - outsize = cd->to.flush(&cd->to, (uchar *)*outbuf, *outbytesleft); + outsize = cd->to.flush(&cd->to, (uchar *)*outbuf, (int)*outbytesleft); if (outsize == -1) { if ((cd->to.flags & FLAG_IGNORE) && errno != E2BIG) @@ -816,7 +816,7 @@ win_iconv(iconv_t _cd, const char **inbuf, size_t *inbytesleft, char **outbuf, s tomode = cd->to.mode; wsize = MB_CHAR_MAX; - insize = cd->from.mbtowc(&cd->from, (const uchar *)*inbuf, *inbytesleft, wbuf, &wsize); + insize = cd->from.mbtowc(&cd->from, (const uchar *)*inbuf, (int)*inbytesleft, wbuf, &wsize); if (insize == -1) { if (cd->to.flags & FLAG_IGNORE) @@ -867,7 +867,7 @@ win_iconv(iconv_t _cd, const char **inbuf, size_t *inbytesleft, char **outbuf, s } } - outsize = cd->to.wctomb(&cd->to, wbuf, wsize, (uchar *)*outbuf, *outbytesleft); + outsize = cd->to.wctomb(&cd->to, wbuf, wsize, (uchar *)*outbuf, (int)*outbytesleft); if (outsize == -1) { if ((cd->to.flags & FLAG_IGNORE) && errno != E2BIG) diff --git a/win/packaging/CMakeLists.txt b/win/packaging/CMakeLists.txt index ec1ba8b3..6decef34 100644 --- a/win/packaging/CMakeLists.txt +++ b/win/packaging/CMakeLists.txt @@ -57,7 +57,11 @@ IF(NOT WIX_DIR) SET(WIX_DIR $ENV{WIX}/bin) ENDIF() -SET(MSI_PACKAGE "mariadb-connector-c-${PRODUCT_VERSION}-${PLATFORM}.msi") +IF(NOT PACKAGE_STATUS_SUFFIX) + SET(MSI_PACKAGE "mariadb-connector-c-${PRODUCT_VERSION}-${PLATFORM}.msi") +ELSE() + SET(MSI_PACKAGE "mariadb-connector-c-${PRODUCT_VERSION}-${PACKAGE_STATUS_SUFFIX}-${PLATFORM}.msi") +ENDIF() IF(WITH_SIGNCODE) IF(EXISTS "/tools/sign.bat") From 45729a2d2549afc7ee4f646144487469e588a5c2 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Tue, 5 Jan 2016 16:46:45 +0100 Subject: [PATCH 05/39] Fix building. --- include/mysql.h | 1 + unittest/libmariadb/CMakeLists.txt | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/mysql.h b/include/mysql.h index 57d4da76..a8d01693 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -438,6 +438,7 @@ 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); +int STDCALL mariadb_flush_multi_command(MYSQL *mysql); my_bool STDCALL 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); diff --git a/unittest/libmariadb/CMakeLists.txt b/unittest/libmariadb/CMakeLists.txt index 7d1c0be4..8c30c728 100644 --- a/unittest/libmariadb/CMakeLists.txt +++ b/unittest/libmariadb/CMakeLists.txt @@ -21,8 +21,10 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/unittest/mytap) ADD_DEFINITIONS(-DLIBMARIADB) -SET(API_TESTS "t_aurora" "async" "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs" - "sp" "result" "connection" "misc" "ps_new" "sqlite3" "thread" "dyncol") +SET(API_TESTS "t_aurora" "async" "basic-t" "fetch" "charset" "logs" + "cursor" "errors" "view" "ps" "ps_bugs" + "sp" "result" "connection" "misc" "ps_new" "sqlite3" "thread" + "dyncol" "features-10_2") # Get finger print from server certificate IF(WITH_SSL) From b6e1e364048e8b03b27ca3159836c625f8c438ac Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Tue, 5 Jan 2016 16:48:37 +0100 Subject: [PATCH 06/39] Georg's changes to make mariadb_flush_multi_command working (reading result of multi-command). --- libmariadb/libmariadb.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index 3e5319f3..ed76d7b4 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -3576,16 +3576,20 @@ int STDCALL mariadb_flush_multi_command(MYSQL *mysql) int is_multi= 0; int rc; - /* turn off multi_command option, so simple_command will + /* turn off multi_command option, so simple_command will * stop to add commands to the queue and send packet * to the server */ mysql_options(mysql, MARIADB_OPT_COM_MULTI, &is_multi); - + rc= simple_command(mysql, COM_MULTI, mysql->net.mbuff, mysql->net.mbuff_pos - mysql->net.mbuff, - 0, 0); + 1, 0); /* reset multi_buff */ mysql->net.mbuff_pos= mysql->net.mbuff; + + if (!rc) + rc= mysql->methods->db_read_query_result(mysql); + return rc; } From 0518bd6b419bbf3d63c0eef485c1da4c50085542 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Tue, 5 Jan 2016 20:41:37 +0100 Subject: [PATCH 07/39] Very simple test of COM_MULTI --- unittest/libmariadb/features-10_2.c | 45 ++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/unittest/libmariadb/features-10_2.c b/unittest/libmariadb/features-10_2.c index 758b59fe..501cefe8 100644 --- a/unittest/libmariadb/features-10_2.c +++ b/unittest/libmariadb/features-10_2.c @@ -6,25 +6,56 @@ static int com_multi_1(MYSQL *mysql) { int rc; + MYSQL_RES *res; my_bool is_multi= 1; + /* TEST a simple query before COM_MULTI */ + + rc= mysql_query(mysql, "select 1"); + check_mysql_rc(rc, mysql); + FAIL_UNLESS(res, "1 simple query no result"); + res= mysql_store_result(mysql); + + mysql_free_result(res); + + /* TEST COM_MULTI */ + if (mysql_options(mysql, MARIADB_OPT_COM_MULTI, &is_multi)) { diag("COM_MULT not supported"); return SKIP; } - rc= mysql_query(mysql, "SET @a:=1"); - check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "select 1"); - rc= mysql_query(mysql, "SET @b:=2"); - check_mysql_rc(rc, mysql); - - rc= mysql_query(mysql, "select @a,@b"); - check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "select 2"); rc= mariadb_flush_multi_command(mysql); check_mysql_rc(rc, mysql); + /* 1 SELECT result */ + res= mysql_store_result(mysql); + FAIL_UNLESS(res, "1 of 2 simple query in batch no result"); + mysql_free_result(res); + /* 2 SELECT result */ + rc= mysql_next_result(mysql); + FAIL_UNLESS(rc == 0, "no second result in the batch"); + res= mysql_store_result(mysql); + FAIL_UNLESS(res, "2 of 2 simple query in batch no result"); + mysql_free_result(res); + /* WHOLE batch result (OK) */ + rc= mysql_next_result(mysql); + res= mysql_store_result(mysql); + FAIL_UNLESS(res == NULL, "rows instead of batch OK"); + rc= mysql_next_result(mysql); + FAIL_UNLESS(rc == -1, "more then 2 results"); + + /* TEST a simple query after COM_MULTI */ + + rc= mysql_query(mysql, "select 1"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + FAIL_UNLESS(res, "2 simple query no result"); + mysql_free_result(res); /* question: how will result sets look like ? */ diag("error: %s", mysql_error(mysql)); From 0c7fabc0b1843efef1896930804ade606801a44a Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Fri, 8 Jan 2016 13:08:47 +0100 Subject: [PATCH 08/39] More control over results in the unittest. --- unittest/libmariadb/features-10_2.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/unittest/libmariadb/features-10_2.c b/unittest/libmariadb/features-10_2.c index 501cefe8..f0708686 100644 --- a/unittest/libmariadb/features-10_2.c +++ b/unittest/libmariadb/features-10_2.c @@ -35,12 +35,18 @@ static int com_multi_1(MYSQL *mysql) /* 1 SELECT result */ res= mysql_store_result(mysql); FAIL_UNLESS(res, "1 of 2 simple query in batch no result"); + FAIL_UNLESS(res->field_count == 1 && res->row_count == 1 && + strcmp(res->fields[0].name, "1") == 0, + "1 of 2 simple query in batch wrong result"); mysql_free_result(res); /* 2 SELECT result */ rc= mysql_next_result(mysql); FAIL_UNLESS(rc == 0, "no second result in the batch"); res= mysql_store_result(mysql); FAIL_UNLESS(res, "2 of 2 simple query in batch no result"); + FAIL_UNLESS(res->field_count == 1 && res->row_count == 1 && + strcmp(res->fields[0].name, "2") == 0, + "1 of 2 simple query in batch wrong result"); mysql_free_result(res); /* WHOLE batch result (OK) */ rc= mysql_next_result(mysql); From 623663775c88c669f3dcf3f86cd545017c6ecae0 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Wed, 13 Jan 2016 19:37:46 +0100 Subject: [PATCH 09/39] MDEV-9058 post-review fix --- include/mysql_com.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mysql_com.h b/include/mysql_com.h index 84e39635..5e71809f 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -87,7 +87,7 @@ enum enum_server_command COM_SET_OPTION = 27, COM_STMT_FETCH = 28, COM_DAEMON, - COM_MULTI = 255, + COM_MULTI = 254, COM_END }; From 25e610c965df9c80b17e2a33ee47f25de5dc618e Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Wed, 27 Jan 2016 18:19:35 +0100 Subject: [PATCH 10/39] Removed deprecated API functions: - mysql_close - mysql_create_db - mysql_drop_db - mysql_get_parameters Fixed build error when SSL is disabled max_allowed_packet and net_buffer size needs to be retrieved via mysql_get_option now (instead of mariadb_get_info) --- include/ma_pvio.h | 2 ++ include/mysql.h | 23 +++----------- libmariadb/libmariadb.c | 69 ++++++++++------------------------------- 3 files changed, 22 insertions(+), 72 deletions(-) diff --git a/include/ma_pvio.h b/include/ma_pvio.h index 4d1a5a45..6984bb7b 100644 --- a/include/ma_pvio.h +++ b/include/ma_pvio.h @@ -4,6 +4,8 @@ #ifdef HAVE_SSL #include +#else +#define MARIADB_SSL void #endif #define PVIO_SET_ERROR if (pvio->set_error) \ diff --git a/include/mysql.h b/include/mysql.h index 6ffd7a96..c74653d0 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -205,6 +205,10 @@ extern unsigned int mariadb_deinitialize_ssl; 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, /* MariaDB specific */ MYSQL_PROGRESS_CALLBACK=5999, @@ -389,16 +393,6 @@ typedef struct character_set unsigned int mbmaxlen; /* max. length for multibyte strings */ } MY_CHARSET_INFO; -typedef struct -{ - unsigned long *p_max_allowed_packet; - unsigned long *p_net_buffer_length; - void *extension; -} MYSQL_PARAMETERS; - -#define net_buffer_length (*mysql_get_parameters()->p_net_buffer_length) -#define max_allowed_packet (*mysql_get_parameters()->p_max_allowed_packet) - /* Local infile support functions */ #define LOCAL_INFILE_ERROR_LEN 512 @@ -450,8 +444,6 @@ 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); -MYSQL * STDCALL mysql_connect(MYSQL *mysql, const char *host, - const char *user, const char *passwd); 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, @@ -469,8 +461,6 @@ int STDCALL mysql_send_query(MYSQL *mysql, const char *q, my_bool STDCALL mysql_read_query_result(MYSQL *mysql); int STDCALL mysql_real_query(MYSQL *mysql, const char *q, size_t length); -int STDCALL mysql_create_db(MYSQL *mysql, const char *DB); -int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB); 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, @@ -528,7 +518,6 @@ size_t STDCALL mariadb_convert_string(const char *from, size_t *from_len, CHARSE int STDCALL mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...); int STDCALL mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...); int STDCALL mysql_get_option(MYSQL *mysql, enum mysql_option option, void *arg); -MYSQL_PARAMETERS *STDCALL mysql_get_parameters(void); unsigned long STDCALL mysql_hex_string(char *to, const char *from, size_t len); my_socket STDCALL mysql_get_socket(MYSQL *mysql); unsigned int STDCALL mysql_get_timeout_value(const MYSQL *mysql); @@ -675,7 +664,6 @@ struct st_mariadb_api { 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); - MYSQL * (STDCALL *mysql_connect)(MYSQL *mysql, const char *host, const char *user, const char *passwd); 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); @@ -684,8 +672,6 @@ struct st_mariadb_api { int (STDCALL *mysql_send_query)(MYSQL *mysql, const char *q, size_t length); my_bool (STDCALL *mysql_read_query_result)(MYSQL *mysql); int (STDCALL *mysql_real_query)(MYSQL *mysql, const char *q, size_t length); - int (STDCALL *mysql_create_db)(MYSQL *mysql, const char *DB); - int (STDCALL *mysql_drop_db)(MYSQL *mysql, const char *DB); 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); @@ -732,7 +718,6 @@ struct st_mariadb_api { int (STDCALL *mysql_optionsv)(MYSQL *mysql,enum mysql_option option, ...); int (STDCALL *mysql_get_optionv)(MYSQL *mysql, enum mysql_option option, void *arg, ...); int (STDCALL *mysql_get_option)(MYSQL *mysql, enum mysql_option option, void *arg); - MYSQL_PARAMETERS *(STDCALL *mysql_get_parameters)(void); unsigned long (STDCALL *mysql_hex_string)(char *to, const char *from, size_t len); my_socket (STDCALL *mysql_get_socket)(MYSQL *mysql); unsigned int (STDCALL *mysql_get_timeout_value)(const MYSQL *mysql); diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index 28760e4f..f2cff1b8 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -80,8 +80,6 @@ #undef net_buffer_length extern ulong max_allowed_packet; /* net.c */ extern ulong net_buffer_length; /* net.c */ -static MYSQL_PARAMETERS mariadb_internal_parameters= -{&max_allowed_packet, &net_buffer_length, 0}; static my_bool mysql_client_init=0; static void mysql_close_options(MYSQL *mysql); @@ -1212,28 +1210,6 @@ mysql_get_ssl_cipher(MYSQL *mysql) ** NB! Errors are not reported until you do mysql_real_connect. **************************************************************************/ -/************************************************************************** -** Connect to sql server -** If host == 0 then use localhost -**************************************************************************/ - -MYSQL * STDCALL -mysql_connect(MYSQL *mysql,const char *host, - const char *user, const char *passwd) -{ - MYSQL *res; - mysql=mysql_init(mysql); /* Make it thread safe */ - { - DBUG_ENTER("mysql_connect"); - if (!(res=mysql_real_connect(mysql,host,user,passwd,NullS,0,NullS,0))) - { - if (mysql->free_me) - my_free(mysql); - } - DBUG_RETURN(res); - } -} - uchar *ma_send_connect_attr(MYSQL *mysql, uchar *buffer) { if (mysql->server_capabilities & CLIENT_CONNECT_ATTRS) @@ -2509,24 +2485,6 @@ mysql_list_processes(MYSQL *mysql) DBUG_RETURN(mysql_store_result(mysql)); } - -int STDCALL -mysql_create_db(MYSQL *mysql, const char *db) -{ - DBUG_ENTER("mysql_createdb"); - DBUG_PRINT("enter",("db: %s",db)); - DBUG_RETURN(simple_command(mysql, COM_CREATE_DB,db, (uint) strlen(db),0,0)); -} - - -int STDCALL -mysql_drop_db(MYSQL *mysql, const char *db) -{ - DBUG_ENTER("mysql_drop_db"); - DBUG_PRINT("enter",("db: %s",db)); - DBUG_RETURN(simple_command(mysql, COM_DROP_DB,db,(uint) strlen(db),0,0)); -} - /* In 5.0 this version became an additional parameter shutdown_level */ int STDCALL mysql_shutdown(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level) @@ -2820,7 +2778,15 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) if (mysql->net.pvio) mysql->net.pvio->async_context= ctxt; break; - + case MYSQL_OPT_MAX_ALLOWED_PACKET: + if (mysql) + mysql->options.max_allowed_packet= (*(size_t *)arg1); + else + max_allowed_packet= (*(size_t *)arg1); + break; + case MYSQL_OPT_NET_BUFFER_LENGTH: + net_buffer_length= (*(size_t *)arg1); + break; case MYSQL_OPT_SSL_VERIFY_SERVER_CERT: if (*(my_bool *)arg1) mysql->options.client_flag |= CLIENT_SSL_VERIFY_SERVER_CERT; @@ -3172,6 +3138,13 @@ mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...) } } break; + case MYSQL_OPT_MAX_ALLOWED_PACKET: + *((unsigned long *)arg)= (mysql) ? mysql->options.max_allowed_packet : + max_allowed_packet; + break; + case MYSQL_OPT_NET_BUFFER_LENGTH: + *((unsigned long *)arg)= net_buffer_length; + break; case MYSQL_SECURE_AUTH: *((my_bool *)arg)= mysql->options.secure_auth; break; @@ -3583,12 +3556,6 @@ mysql_get_server_name(MYSQL *mysql) return mariadb_connection(mysql) ? "MariaDB" : "MySQL"; } -MYSQL_PARAMETERS *STDCALL -mysql_get_parameters(void) -{ - return &mariadb_internal_parameters; -} - static my_socket mariadb_get_socket(MYSQL *mysql) { my_socket sock= INVALID_SOCKET; @@ -3897,7 +3864,6 @@ struct st_mariadb_api MARIADB_API= mysql_init, mysql_ssl_set, mysql_get_ssl_cipher, - mysql_connect, mysql_change_user, mysql_real_connect, mysql_close, @@ -3906,8 +3872,6 @@ struct st_mariadb_api MARIADB_API= mysql_send_query, mysql_read_query_result, mysql_real_query, - mysql_create_db, - mysql_drop_db, mysql_shutdown, mysql_dump_debug_info, mysql_refresh, @@ -3954,7 +3918,6 @@ struct st_mariadb_api MARIADB_API= mysql_optionsv, mysql_get_optionv, mysql_get_option, - mysql_get_parameters, mysql_hex_string, mysql_get_socket, mysql_get_timeout_value, From 8845fcb7ce778329e650d555bb9a71d41bfa6d75 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Thu, 28 Jan 2016 16:58:30 +0100 Subject: [PATCH 11/39] First implementation of mariadb_stmt_execute_direct --- include/my_stmt.h | 1 + include/mysql.h | 9 +- include/mysql_com.h | 12 +- libmariadb/CMakeLists.txt | 1 + libmariadb/libmariadb.c | 91 ++++++--- libmariadb/my_stmt.c | 295 +++++++++++++++++++++------- plugins/auth/my_auth.c | 8 +- unittest/libmariadb/CMakeLists.txt | 2 +- unittest/libmariadb/features-10_2.c | 95 ++++++++- unittest/libmariadb/my_test.h | 2 + unittest/libmariadb/ps.c | 1 + 11 files changed, 392 insertions(+), 125 deletions(-) diff --git a/include/my_stmt.h b/include/my_stmt.h index 0dfb1ba1..e58e3524 100644 --- a/include/my_stmt.h +++ b/include/my_stmt.h @@ -253,3 +253,4 @@ my_ulonglong 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); diff --git a/include/mysql.h b/include/mysql.h index c74653d0..78e7911e 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -165,6 +165,12 @@ extern unsigned int mariadb_deinitialize_ssl; MEM_ROOT alloc; } MYSQL_DATA; + enum mariadb_com_multi { + MARIADB_COM_MULTI_END, + MARIADB_COM_MULTI_BEGIN, + MARIADB_COM_MULTI_CANCEL + }; + enum mysql_option { MYSQL_OPT_CONNECT_TIMEOUT, @@ -637,7 +643,7 @@ int STDCALL mysql_stmt_send_long_data_cont(my_bool *ret, MYSQL_STMT *stmt, /* API function calls (used by dynmic plugins) */ struct st_mariadb_api { - my_ulonglong (STDCALL *mysql_num_rows)(MYSQL_RES *res); + 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); @@ -752,6 +758,7 @@ struct st_mariadb_api { 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); }; /* these methods can be overwritten by db plugins */ diff --git a/include/mysql_com.h b/include/mysql_com.h index 5e71809f..cfd520d5 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -129,7 +129,7 @@ enum enum_server_command #define REFRESH_READ_LOCK 16384 /* Lock tables for read */ #define REFRESH_FAST 32768 /* Intern flag */ -#define CLIENT_LONG_PASSWORD 1 /* new more secure passwords */ +#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 */ @@ -157,14 +157,14 @@ enum enum_server_command /* MariaDB specific capabilities */ #define MARIADB_CLIENT_FLAGS 0xFFFFFFFF00000000ULL -#define MARIADB_CLIENT_COM_MULTI 1 #define MARIADB_CLIENT_PROGRESS (1ULL << 32) -#define MARIADB_CLIENT_EXTENDED_FLAGS (1ULL << 63) +#define MARIADB_CLIENT_COM_MULTI (1ULL << 33) +//#define MARIADB_CLIENT_EXTENDED_FLAGS (1ULL << 63) #define MARIADB_CLIENT_SUPPORTED_FLAGS (MARIADB_CLIENT_PROGRESS |\ - MARIADB_CLIENT_EXTENDED_FLAGS) + MARIADB_CLIENT_COM_MULTI) -#define CLIENT_SUPPORTED_FLAGS (CLIENT_LONG_PASSWORD |\ +#define CLIENT_SUPPORTED_FLAGS (CLIENT_MYSQL |\ CLIENT_FOUND_ROWS |\ CLIENT_LONG_FLAG |\ CLIENT_CONNECT_WITH_DB |\ @@ -188,7 +188,7 @@ enum enum_server_command CLIENT_PLUGIN_AUTH |\ CLIENT_CONNECT_ATTRS) -#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | \ +#define CLIENT_CAPABILITIES (CLIENT_MYSQL | \ CLIENT_LONG_FLAG |\ CLIENT_TRANSACTIONS |\ CLIENT_SECURE_CONNECTION |\ diff --git a/libmariadb/CMakeLists.txt b/libmariadb/CMakeLists.txt index 26767358..c8da08eb 100644 --- a/libmariadb/CMakeLists.txt +++ b/libmariadb/CMakeLists.txt @@ -35,6 +35,7 @@ SET(EXPORT_SYMBOLS mariadb_dyncol_val_long mariadb_dyncol_val_str mariadb_get_charset_by_name + mariadb_stmt_execute_direct mariadb_get_charset_by_nr mariadb_get_info mariadb_get_infov diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index f2cff1b8..2ace684d 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -361,16 +361,16 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg, { NET *net= &mysql->net; int result= -1; - my_bool is_multi= 0; + enum mariadb_com_multi multi= MARIADB_COM_MULTI_END; if (OPT_HAS_EXT_VAL(mysql, multi_command)) - is_multi= mysql->options.extension->multi_command; + multi= mysql->options.extension->multi_command; DBUG_ENTER("mthd_my_send_cmd"); DBUG_PRINT("info", ("server_command: %d packet_size: %u", command, length)); - if (is_multi) + if (multi == MARIADB_COM_MULTI_BEGIN) { /* todo: error handling */ DBUG_RETURN(net_add_multi_command(&mysql->net, command, arg, length)); @@ -1546,7 +1546,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, if (strncmp(end, MA_RPL_VERSION_HACK, sizeof(MA_RPL_VERSION_HACK) - 1) == 0) { - if (!(mysql->server_version= my_strdup(end + sizeof(MA_RPL_VERSION_HACK), 0))) + if (!(mysql->server_version= my_strdup(end + sizeof(MA_RPL_VERSION_HACK) - 1, 0))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto error; @@ -1586,11 +1586,11 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, { mysql->server_language= uint1korr(end + 2); mysql->server_status= uint2korr(end + 3); - mysql->server_capabilities|= uint2korr(end + 5) << 16; + mysql->server_capabilities|= (unsigned int)(uint2korr(end + 5) << 16); pkt_scramble_len= uint1korr(end + 7); /* check if MariaD2B specific capabilities are available */ - if (is_maria && !(mysql->server_capabilities & CLIENT_LONG_PASSWORD)) + if (is_maria && !(mysql->server_capabilities & CLIENT_MYSQL)) { mysql->server_capabilities|= (ulonglong) uint4korr(end + 14) << 32; } @@ -2630,6 +2630,24 @@ void ma_hash_free(void *p) my_free(p); } +int mariadb_flush_multi_command(MYSQL *mysql) +{ + int rc; + size_t length= mysql->net.mbuff_pos - mysql->net.mbuff; + + rc= simple_command(mysql, COM_MULTI, mysql->net.mbuff, + length, 1, 0); + /* reset multi_buff */ + mysql->net.mbuff_pos= mysql->net.mbuff; + + if (!rc) + if (mysql->net.mbuff && length > 3 && + (mysql->net.mbuff[3] == COM_STMT_PREPARE || mysql->net.mbuff[3] == COM_STMT_EXECUTE)) + return rc; + else + return mysql->methods->db_read_query_result(mysql); + return rc; +} int STDCALL mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) @@ -2975,8 +2993,33 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) break; case MARIADB_OPT_COM_MULTI: if (&mysql->net.pvio && - (mysql->server_capabilities & MARIADB_CLIENT_EXTENDED_FLAGS)) + !(mysql->server_capabilities & CLIENT_MYSQL)) { + enum mariadb_com_multi type= *(enum mariadb_com_multi *)arg1; + switch (type) + { + case MARIADB_COM_MULTI_BEGIN: + OPT_SET_EXTENDED_VALUE_INT(&mysql->options, multi_command, type); + break; + case MARIADB_COM_MULTI_CANCEL: + if (!mysql->options.extension || + mysql->options.extension->multi_command != MARIADB_COM_MULTI_BEGIN) + DBUG_RETURN(-1); + /* reset multi_buff */ + mysql->net.mbuff_pos= mysql->net.mbuff; + OPT_SET_EXTENDED_VALUE_INT(&mysql->options, multi_command, MARIADB_COM_MULTI_END); + break; + case MARIADB_COM_MULTI_END: + if (!mysql->options.extension || + mysql->options.extension->multi_command != MARIADB_COM_MULTI_BEGIN) + DBUG_RETURN(-1); + OPT_SET_EXTENDED_VALUE_INT(&mysql->options, multi_command, MARIADB_COM_MULTI_END); + if (mariadb_flush_multi_command(mysql)) + DBUG_RETURN(-1); + break; + default: + DBUG_RETURN(-1); + } OPT_SET_EXTENDED_VALUE_INT(&mysql->options, multi_command, *(my_bool *)arg1); } else @@ -3071,6 +3114,15 @@ mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...) case MYSQL_OPT_NONBLOCK: *((my_bool *)arg)= test(mysql->options.extension && mysql->options.extension->async_context); break; + case MARIADB_OPT_COM_MULTI: + if (!(mysql->server_capabilities & CLIENT_MYSQL)) + { + *((enum mariadb_com_multi *)arg)= mysql->options.extension ? + mysql->options.extension->multi_command : 0; + } + else + DBUG_RETURN(-1); + break; case MYSQL_OPT_SSL_VERIFY_SERVER_CERT: *((my_bool *)arg)= test(mysql->options.client_flag & CLIENT_SSL_VERIFY_SERVER_CERT); break; @@ -3575,28 +3627,6 @@ static my_socket mariadb_get_socket(MYSQL *mysql) return sock; } -int mariadb_flush_multi_command(MYSQL *mysql) -{ - int is_multi= 0; - int rc; - - /* turn off multi_command option, so simple_command will - * stop to add commands to the queue and send packet - * to the server */ - mysql_options(mysql, MARIADB_OPT_COM_MULTI, &is_multi); - - rc= simple_command(mysql, COM_MULTI, mysql->net.mbuff, - mysql->net.mbuff_pos - mysql->net.mbuff, - 1, 0); - /* reset multi_buff */ - mysql->net.mbuff_pos= mysql->net.mbuff; - - if (!rc) - rc= mysql->methods->db_read_query_result(mysql); - - return rc; -} - my_socket STDCALL mysql_get_socket(MYSQL *mysql) { @@ -3951,7 +3981,8 @@ struct st_mariadb_api MARIADB_API= mysql_stmt_insert_id, mysql_stmt_field_count, mysql_stmt_next_result, - mysql_stmt_more_results + mysql_stmt_more_results, + mariadb_stmt_execute_direct }; /* diff --git a/libmariadb/my_stmt.c b/libmariadb/my_stmt.c index 4894ceb2..4b97469d 100644 --- a/libmariadb/my_stmt.c +++ b/libmariadb/my_stmt.c @@ -113,7 +113,7 @@ my_bool mthd_supported_buffer_type(enum enum_field_types type) } static my_bool madb_reset_stmt(MYSQL_STMT *stmt, unsigned int flags); - +static my_bool mysql_stmt_internal_reset(MYSQL_STMT *stmt, my_bool is_close); static int stmt_unbuffered_eof(MYSQL_STMT *stmt, uchar **row) { return MYSQL_NO_DATA; @@ -281,7 +281,7 @@ static int stmt_cursor_fetch(MYSQL_STMT *stmt, uchar **row) int4store(buf, stmt->stmt_id); int4store(buf + STMT_ID_LENGTH, stmt->prefetch_rows); - if (simple_command(stmt->mysql, COM_STMT_FETCH, (char *)buf, sizeof(buf), 1, stmt)) + if (stmt->mysql->methods->db_command(stmt->mysql, COM_STMT_FETCH, (char *)buf, sizeof(buf), 1, stmt)) DBUG_RETURN(1); /* free previously allocated buffer */ @@ -774,9 +774,40 @@ my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type a my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bind) { + MYSQL *mysql= stmt->mysql; DBUG_ENTER("mysql_stmt_bind_param"); - if (stmt->state < MYSQL_STMT_PREPARED) { + if (!mysql) + { + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + DBUG_RETURN(1); + } + + /* for mariadb_stmt_execute_direct we need to bind parameters in advance: + client has to pass a bind array, where last parameter needs to be set + to buffer type MAX_NO_FIELD_TYPES */ + if (stmt->state < MYSQL_STMT_PREPARED && + !(mysql->server_capabilities & CLIENT_MYSQL)) + { + if (!stmt->params) + { + int param_count; + for(param_count= 0; + bind[param_count].buffer_type != MAX_NO_FIELD_TYPES; + param_count++); + stmt->param_count= param_count; + if (stmt->param_count) + { + if (!(stmt->params= (MYSQL_BIND *)alloc_root(&stmt->mem_root, stmt->param_count * sizeof(MYSQL_BIND)))) + { + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + DBUG_RETURN(1); + } + } + memset(stmt->params, '\0', stmt->param_count * sizeof(MYSQL_BIND)); + } + } + else if (stmt->state < MYSQL_STMT_PREPARED) { SET_CLIENT_STMT_ERROR(stmt, CR_NO_PREPARE_STMT, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); } @@ -947,7 +978,7 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) DBUG_RETURN(0); } -my_bool net_stmt_close(MYSQL_STMT *stmt, my_bool remove) +static my_bool net_stmt_close(MYSQL_STMT *stmt, my_bool remove) { char stmt_id[STMT_ID_LENGTH]; MEM_ROOT *fields_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_alloc_root; @@ -974,7 +1005,8 @@ my_bool net_stmt_close(MYSQL_STMT *stmt, my_bool remove) if (stmt->state > MYSQL_STMT_INITTED) { int4store(stmt_id, stmt->stmt_id); - if (simple_command(stmt->mysql,COM_STMT_CLOSE, stmt_id, sizeof(stmt_id), 1, stmt)) + if (stmt->mysql->methods->db_command(stmt->mysql,COM_STMT_CLOSE, stmt_id, + sizeof(stmt_id), 1, stmt)) { SET_CLIENT_STMT_ERROR(stmt, stmt->mysql->net.last_errno, stmt->mysql->net.sqlstate, stmt->mysql->net.last_error); return 1; @@ -989,7 +1021,8 @@ my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt) DBUG_ENTER("mysql_stmt_close"); if (stmt && stmt->mysql && stmt->mysql->net.pvio) - mysql_stmt_reset(stmt); + mysql_stmt_internal_reset(stmt, 1); + net_stmt_close(stmt, 1); my_free(stmt->extension); @@ -1142,6 +1175,7 @@ MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql) /* fill mysql's stmt list */ stmt->list.data= stmt; stmt->mysql= mysql; + stmt->stmt_id= -1; mysql->stmts= list_add(mysql->stmts, &stmt->list); @@ -1226,9 +1260,7 @@ int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, size_t lengt MYSQL *mysql= stmt->mysql; int rc= 1; DBUG_ENTER("mysql_stmt_prepare"); - - if (length == -1) - length= strlen(query); + enum mariadb_com_multi multi= MARIADB_COM_MULTI_END; if (!stmt->mysql) { @@ -1236,6 +1268,11 @@ int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, size_t lengt DBUG_RETURN(1); } + if (length == -1) + length= strlen(query); + + mysql_get_optionv(mysql, MARIADB_OPT_COM_MULTI, &multi); + /* clear flags */ CLEAR_CLIENT_STMT_ERROR(stmt); CLEAR_CLIENT_ERROR(stmt->mysql); @@ -1259,14 +1296,18 @@ int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, size_t lengt stmt->field_count= 0; int4store(stmt_id, stmt->stmt_id); - if (simple_command(mysql, COM_STMT_CLOSE, stmt_id, sizeof(stmt_id), 1, stmt)) + if (mysql->methods->db_command(mysql, COM_STMT_CLOSE, stmt_id, + sizeof(stmt_id), 1, stmt)) goto fail; } - if (simple_command(mysql, COM_STMT_PREPARE, query, length, 1, stmt)) + if (mysql->methods->db_command(mysql, COM_STMT_PREPARE, query, length, 1, stmt)) goto fail; - if (stmt->mysql->methods->db_read_prepare_response && - stmt->mysql->methods->db_read_prepare_response(stmt)) + if (multi == MARIADB_COM_MULTI_BEGIN) + return 0; + + if (mysql->methods->db_read_prepare_response && + mysql->methods->db_read_prepare_response(stmt)) goto fail; /* metadata not supported yet */ @@ -1346,7 +1387,8 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) int4store(buff, stmt->stmt_id); int4store(buff + STMT_ID_LENGTH, (int)~0); - if (simple_command(stmt->mysql, COM_STMT_FETCH, buff, sizeof(buff), 1, stmt)) + if (stmt->mysql->methods->db_command(stmt->mysql, COM_STMT_FETCH, + buff, sizeof(buff), 1, stmt)) DBUG_RETURN(1); /* todo: cursor */ } @@ -1442,63 +1484,17 @@ static int madb_alloc_stmt_fields(MYSQL_STMT *stmt) DBUG_RETURN(0); } - -int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) +int stmt_read_execute_response(MYSQL_STMT *stmt) { MYSQL *mysql= stmt->mysql; - char *request; - int ret; - size_t request_len= 0; + DBUG_ENTER("stmt_read_execute_response"); - DBUG_ENTER("mysql_stmt_execute"); - - if (!stmt->mysql) - { - SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + if (!mysql) DBUG_RETURN(1); - } - - if (stmt->state < MYSQL_STMT_PREPARED) - { - SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); - } - - if (stmt->param_count && !stmt->bind_param_done) - { - SET_CLIENT_STMT_ERROR(stmt, CR_PARAMS_NOT_BOUND, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); - } - - if (stmt->state == MYSQL_STMT_WAITING_USE_OR_STORE) - { - stmt->default_rset_handler = _mysql_stmt_use_result; - stmt->default_rset_handler(stmt); - } - if (stmt->state > MYSQL_STMT_WAITING_USE_OR_STORE && stmt->state < MYSQL_STMT_FETCH_DONE && !stmt->result.data) - { - mysql->methods->db_stmt_flush_unbuffered(stmt); - stmt->state= MYSQL_STMT_PREPARED; - stmt->mysql->status= MYSQL_STATUS_READY; - } - - /* clear data, in case mysql_stmt_store_result was called */ - if (stmt->result.data) - { - free_root(&stmt->result.alloc, MYF(MY_KEEP_PREALLOC)); - stmt->result_cursor= stmt->result.data= 0; - stmt->result.rows= 0; - } - request= (char *)mysql_stmt_execute_generate_request(stmt, &request_len); - DBUG_PRINT("info",("request_len=%ld", request_len)); - - ret= test(simple_command(mysql, COM_STMT_EXECUTE, request, request_len, 1, stmt) || - (mysql && mysql->methods->db_read_stmt_result && mysql->methods->db_read_stmt_result(mysql))); - if (request) - my_free(request); + int ret= test((mysql->methods->db_read_stmt_result && + mysql->methods->db_read_stmt_result(mysql))); /* if a reconnect occured, our connection handle is invalid */ if (!stmt->mysql) DBUG_RETURN(1); @@ -1615,6 +1611,78 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) DBUG_RETURN(0); } +int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) +{ + MYSQL *mysql= stmt->mysql; + char *request; + int ret; + size_t request_len= 0; + enum mariadb_com_multi multi= MARIADB_COM_MULTI_END; + + DBUG_ENTER("mysql_stmt_execute"); + + if (!stmt->mysql) + { + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + DBUG_RETURN(1); + } + + mysql_get_optionv(mysql, MARIADB_OPT_COM_MULTI, &multi); + + if (stmt->state < MYSQL_STMT_PREPARED) + { + SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + DBUG_RETURN(1); + } + + if (stmt->param_count && !stmt->bind_param_done) + { + SET_CLIENT_STMT_ERROR(stmt, CR_PARAMS_NOT_BOUND, SQLSTATE_UNKNOWN, 0); + DBUG_RETURN(1); + } + + if (stmt->state == MYSQL_STMT_WAITING_USE_OR_STORE) + { + stmt->default_rset_handler = _mysql_stmt_use_result; + stmt->default_rset_handler(stmt); + } + if (stmt->state > MYSQL_STMT_WAITING_USE_OR_STORE && stmt->state < MYSQL_STMT_FETCH_DONE && !stmt->result.data) + { + mysql->methods->db_stmt_flush_unbuffered(stmt); + stmt->state= MYSQL_STMT_PREPARED; + stmt->mysql->status= MYSQL_STATUS_READY; + } + + /* clear data, in case mysql_stmt_store_result was called */ + if (stmt->result.data) + { + free_root(&stmt->result.alloc, MYF(MY_KEEP_PREALLOC)); + stmt->result_cursor= stmt->result.data= 0; + stmt->result.rows= 0; + } + request= (char *)mysql_stmt_execute_generate_request(stmt, &request_len); + DBUG_PRINT("info",("request_len=%ld", request_len)); + + ret= stmt->mysql->methods->db_command(mysql, COM_STMT_EXECUTE, request, + request_len, 1, stmt); + + if (request) + my_free(request); + + if (ret) + { + SET_CLIENT_STMT_ERROR(stmt, mysql->net.last_errno, mysql->net.sqlstate, + mysql->net.last_error); + DBUG_RETURN(1); + } + + if (multi == MARIADB_COM_MULTI_BEGIN) + DBUG_RETURN(0); + + DBUG_RETURN(stmt_read_execute_response(stmt)); +} + static my_bool madb_reset_stmt(MYSQL_STMT *stmt, unsigned int flags) { MYSQL *mysql= stmt->mysql; @@ -1670,11 +1738,13 @@ static my_bool madb_reset_stmt(MYSQL_STMT *stmt, unsigned int flags) if (flags & MADB_RESET_SERVER) { /* reset statement on server side */ - if (stmt->mysql && stmt->mysql->status == MYSQL_STATUS_READY) + if (stmt->mysql && stmt->mysql->status == MYSQL_STATUS_READY && + stmt->mysql->net.pvio) { unsigned char cmd_buf[STMT_ID_LENGTH]; int4store(cmd_buf, stmt->stmt_id); - if ((ret= simple_command(mysql,COM_STMT_RESET, (char *)cmd_buf, sizeof(cmd_buf), 0, stmt))) + if ((ret= stmt->mysql->methods->db_command(mysql,COM_STMT_RESET, (char *)cmd_buf, + sizeof(cmd_buf), 0, stmt))) { SET_CLIENT_STMT_ERROR(stmt, mysql->net.last_errno, mysql->net.sqlstate, mysql->net.last_error); @@ -1698,13 +1768,13 @@ static my_bool madb_reset_stmt(MYSQL_STMT *stmt, unsigned int flags) DBUG_RETURN(ret); } -my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt) +static my_bool mysql_stmt_internal_reset(MYSQL_STMT *stmt, my_bool is_close) { MYSQL *mysql= stmt->mysql; my_bool ret= 1; unsigned int flags= MADB_RESET_LONGDATA | MADB_RESET_BUFFER | MADB_RESET_ERROR; - DBUG_ENTER("mysql_stmt_reset"); + DBUG_ENTER("mysql_stmt_internal_reset"); if (!mysql) { @@ -1739,7 +1809,9 @@ my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt) stmt->mysql->status= MYSQL_STATUS_READY; } } - ret= madb_reset_stmt(stmt, MADB_RESET_SERVER); + if (!stmt->execute_count) + if (!is_close) + ret= madb_reset_stmt(stmt, MADB_RESET_SERVER); } stmt->state= MYSQL_STMT_PREPARED; stmt->upsert_status.affected_rows= mysql->affected_rows; @@ -1770,7 +1842,13 @@ MYSQL_RES * STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt) res->eof= 1; res->fields= stmt->fields; res->field_count= stmt->field_count; - DBUG_RETURN(res);} + DBUG_RETURN(res); +} + +my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt) +{ + return mysql_stmt_internal_reset(stmt, 0); +} const char * STDCALL mysql_stmt_sqlstate(MYSQL_STMT *stmt) { @@ -1828,7 +1906,8 @@ my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number, int2store(cmd_buff + STMT_ID_LENGTH, param_number); memcpy(cmd_buff + STMT_ID_LENGTH + 2, data, length); stmt->params[param_number].long_data_used= 1; - ret= simple_command(stmt->mysql, COM_STMT_SEND_LONG_DATA, (char *)cmd_buff, packet_len, 1, stmt); + ret= stmt->mysql->methods->db_command(stmt->mysql, COM_STMT_SEND_LONG_DATA, + (char *)cmd_buff, packet_len, 1, stmt); my_free(cmd_buff); DBUG_RETURN(ret); } @@ -1915,3 +1994,75 @@ int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt) DBUG_RETURN(rc); } + +int STDCALL mariadb_stmt_execute_direct(MYSQL_STMT *stmt, + const char *stmt_str, + size_t length) +{ + enum mariadb_com_multi multi= MARIADB_COM_MULTI_BEGIN; + MYSQL *mysql= stmt->mysql; + + if (!mysql) + { + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + goto fail; + } + + if (mysql_optionsv(mysql, MARIADB_OPT_COM_MULTI, &multi)) + goto fail; + + if (length == -1) + length= strlen(stmt_str); + + if (mysql_stmt_prepare(stmt, stmt_str, length)) + goto fail; + + stmt->state= MYSQL_STMT_PREPARED; + + if (mysql_stmt_execute(stmt)) + goto fail; + + multi= MARIADB_COM_MULTI_END; + if (mysql_optionsv(mysql, MARIADB_OPT_COM_MULTI, &multi)) + goto fail; + + /* read prepare response */ + if (mysql->methods->db_read_prepare_response && + mysql->methods->db_read_prepare_response(stmt)) + goto fail; + + /* metadata not supported yet */ + + if (stmt->param_count && + stmt->mysql->methods->db_stmt_get_param_metadata(stmt)) + { + goto fail; + } + + /* allocated bind buffer for parameters */ + if (stmt->field_count && + stmt->mysql->methods->db_stmt_get_result_metadata(stmt)) + { + goto fail; + } + + /* allocated bind buffer for result */ + if (stmt->field_count) + { + MEM_ROOT *fields_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_alloc_root; + if (!(stmt->bind= (MYSQL_BIND *)alloc_root(fields_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) + { + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + goto fail; + } + } + stmt->state = MYSQL_STMT_PREPARED; + + /* read execute response packet */ + return stmt_read_execute_response(stmt); +fail: + stmt->state= MYSQL_STMT_INITTED; + SET_CLIENT_STMT_ERROR(stmt, mysql->net.last_errno, mysql->net.sqlstate, + mysql->net.last_error); + return 1; +} diff --git a/plugins/auth/my_auth.c b/plugins/auth/my_auth.c index 039d5eb6..ab797f85 100644 --- a/plugins/auth/my_auth.c +++ b/plugins/auth/my_auth.c @@ -169,12 +169,6 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, if (mysql->client_flag & CLIENT_MULTI_STATEMENTS) mysql->client_flag|= CLIENT_MULTI_RESULTS; - /* if server supports extended MariaDB extended protocol, we will unset - CLIENT_LONG_PASSWORD and send extended client capabilities in last - four of 23 unused bytes */ - if (mysql->server_capabilities & MARIADB_CLIENT_EXTENDED_FLAGS) - mysql->client_flag &= ~CLIENT_LONG_PASSWORD; - #if defined(HAVE_SSL) && !defined(EMBEDDED_LIBRARY) if (mysql->options.ssl_key || mysql->options.ssl_cert || mysql->options.ssl_ca || mysql->options.ssl_capath || @@ -218,7 +212,7 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, int4store(buff+4, net->max_packet_size); buff[8]= (char) mysql->charset->nr; bzero(buff + 9, 32-9); - if (mysql->server_capabilities & MARIADB_CLIENT_EXTENDED_FLAGS) + if (!(mysql->server_capabilities & CLIENT_MYSQL)) { mysql->client_flag |= MARIADB_CLIENT_SUPPORTED_FLAGS; int4store(buff + 28, mysql->client_flag >> 32); diff --git a/unittest/libmariadb/CMakeLists.txt b/unittest/libmariadb/CMakeLists.txt index 90e5a1b7..0d3703b1 100644 --- a/unittest/libmariadb/CMakeLists.txt +++ b/unittest/libmariadb/CMakeLists.txt @@ -22,7 +22,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ADD_DEFINITIONS(-DLIBMARIADB) SET(API_TESTS "async" "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs" - "sp" "result" "connection" "misc" "ps_new" "sqlite3" "thread" "dyncol" "features-10_2") + "sp" "result" "connection" "misc" "ps_new" "sqlite3" "thread" "dyncol" "features-10_2" ) #exclude following tests from ctests, since we need to run them maually with different credentials SET(MANUAL_TESTS "t_aurora") diff --git a/unittest/libmariadb/features-10_2.c b/unittest/libmariadb/features-10_2.c index f0708686..39007346 100644 --- a/unittest/libmariadb/features-10_2.c +++ b/unittest/libmariadb/features-10_2.c @@ -3,26 +3,30 @@ #include "my_test.h" +my_bool have_com_multi= 1; + static int com_multi_1(MYSQL *mysql) { int rc; MYSQL_RES *res; - my_bool is_multi= 1; + enum mariadb_com_multi status; /* TEST a simple query before COM_MULTI */ rc= mysql_query(mysql, "select 1"); check_mysql_rc(rc, mysql); - FAIL_UNLESS(res, "1 simple query no result"); res= mysql_store_result(mysql); + FAIL_UNLESS(res, "1 simple query no result"); mysql_free_result(res); /* TEST COM_MULTI */ - if (mysql_options(mysql, MARIADB_OPT_COM_MULTI, &is_multi)) + status= MARIADB_COM_MULTI_BEGIN; + if (mysql_options(mysql, MARIADB_OPT_COM_MULTI, &status)) { diag("COM_MULT not supported"); + have_com_multi= 0; return SKIP; } @@ -30,7 +34,8 @@ static int com_multi_1(MYSQL *mysql) rc= mysql_query(mysql, "select 2"); - rc= mariadb_flush_multi_command(mysql); + status= MARIADB_COM_MULTI_END; + rc= mysql_options(mysql, MARIADB_OPT_COM_MULTI, &status); check_mysql_rc(rc, mysql); /* 1 SELECT result */ res= mysql_store_result(mysql); @@ -48,10 +53,6 @@ static int com_multi_1(MYSQL *mysql) strcmp(res->fields[0].name, "2") == 0, "1 of 2 simple query in batch wrong result"); mysql_free_result(res); - /* WHOLE batch result (OK) */ - rc= mysql_next_result(mysql); - res= mysql_store_result(mysql); - FAIL_UNLESS(res == NULL, "rows instead of batch OK"); rc= mysql_next_result(mysql); FAIL_UNLESS(rc == -1, "more then 2 results"); @@ -69,8 +70,86 @@ static int com_multi_1(MYSQL *mysql) return OK; } +static int com_multi_ps1(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + int rc; + + if (!have_com_multi) + return SKIP; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE t1 (a int, b varchar(20))"); + + rc= mysql_stmt_prepare(stmt, "INSERT INTO t1 values (2, 'execute_direct')", -1); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + diag("affected_rows: %d", mysql_stmt_affected_rows(stmt)); + diag("stmt_id: %d", stmt->stmt_id); + mysql_stmt_close(stmt); + + stmt= mysql_stmt_init(mysql); + rc= mariadb_stmt_execute_direct(stmt, "INSERT INTO t1 values (2, 'execute_direct')", -1); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_affected_rows(stmt) != 1, "expected affected_rows= 1"); + FAIL_IF(stmt->stmt_id < 1, "expected statement id > 0"); + + rc= mysql_stmt_close(stmt); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int com_multi_ps2(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND bind[3]; + int intval= 3, rc; + int i; + char *varval= "com_multi_ps2"; + + + if (!have_com_multi) + return SKIP; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE t1 (a int, b varchar(20))"); + + memset(&bind, 0, sizeof(MYSQL_BIND) * 3); + bind[0].buffer_type= MYSQL_TYPE_SHORT; + bind[0].buffer= &intval; + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= varval; + bind[1].buffer_length= strlen(varval); + bind[2].buffer_type= MAX_NO_FIELD_TYPES; + + for (i=0; i < 2; i++) + { + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mariadb_stmt_execute_direct(stmt, "INSERT INTO t1 VALUES (1,'foo')", -1); + check_stmt_rc(rc, stmt); + FAIL_IF(mysql_stmt_affected_rows(stmt) != 1, "expected affected_rows= 1"); + FAIL_IF(stmt->stmt_id < 1, "expected statement id > 0"); + + rc= mysql_stmt_close(stmt); + check_mysql_rc(rc, mysql); + } + + return OK; +} + struct my_tests_st my_tests[] = { {"com_multi_1", com_multi_1, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"com_multi_ps1", com_multi_ps1, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"com_multi_ps2", com_multi_ps2, TEST_CONNECTION_NEW, 0, NULL, NULL}, {NULL, NULL, 0, 0, NULL, NULL} }; diff --git a/unittest/libmariadb/my_test.h b/unittest/libmariadb/my_test.h index 2897b3a7..2c7d744b 100644 --- a/unittest/libmariadb/my_test.h +++ b/unittest/libmariadb/my_test.h @@ -189,6 +189,8 @@ int do_verify_prepare_field(MYSQL_RES *result, FAIL_UNLESS(strcmp(field->table, table) == 0, "field->table differs"); if (org_table) FAIL_UNLESS(strcmp(field->org_table, org_table) == 0, "field->org_table differs"); + if (strcmp(field->db,db)) + diag("%s / %s", field->db, db); FAIL_UNLESS(strcmp(field->db, db) == 0, "field->db differs"); /* Character set should be taken into account for multibyte encodings, such diff --git a/unittest/libmariadb/ps.c b/unittest/libmariadb/ps.c index 3eb74bb9..6385fe35 100644 --- a/unittest/libmariadb/ps.c +++ b/unittest/libmariadb/ps.c @@ -830,6 +830,7 @@ static int test_prepare_alter(MYSQL *mysql) FAIL_IF(!(mysql_real_connect(mysql_new, hostname, username, password, schema, port, socketname, 0)), "mysql_real_connect failed"); rc= mysql_query(mysql_new, "ALTER TABLE test_prep_alter change id id_new varchar(20)"); + diag("Error: %d %s", mysql_errno(mysql_new), mysql_error(mysql_new)); check_mysql_rc(rc, mysql_new); mysql_close(mysql_new); From a7e31ad54f3208824fa144046c9e639031df4d56 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Thu, 28 Jan 2016 19:55:43 +0100 Subject: [PATCH 12/39] Do not set CMAKE_INSTALL_PREFIX to empty string on Windows --- CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b5e9a16f..29fc3a24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -300,9 +300,6 @@ IF(CLIENT_DOCS) DESTINATION ${DOCS_INSTALL_DIR_${INSTALL_LAYOUT}}) ENDIF() -IF(MSVC) - SET(CMAKE_INSTALL_PREFIX "") -ENDIF() IF(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") ADD_SUBDIRECTORY(win/packaging) From ccb8798f09a8b3b4648474b95bdf2e30b89d75a5 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Tue, 2 Feb 2016 10:11:15 +0100 Subject: [PATCH 13/39] Added mysql_options4 (was #define before) --- cmake/plugins.cmake | 2 +- include/mysql.h | 5 ++--- libmariadb/CMakeLists.txt | 3 +-- libmariadb/libmariadb.c | 5 +++++ 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cmake/plugins.cmake b/cmake/plugins.cmake index 2068b1e3..6d5d0c0f 100644 --- a/cmake/plugins.cmake +++ b/cmake/plugins.cmake @@ -50,7 +50,7 @@ IF(CURL_FOUND) IF(WIN32) REGISTER_PLUGIN("REMOTEIO" "${CMAKE_SOURCE_DIR}/plugins/io/remote_io.c" "remote_io_plugin" "DYNAMIC" "remote_io" 1) ELSE() - REGISTER_PLUGIN("REMOTEIO" "${CMAKE_SOURCE_DIR}/plugins/io/remote_io.c" "remote_io_plugin" "STATIC" "remote_io" 1) + REGISTER_PLUGIN("REMOTEIO" "${CMAKE_SOURCE_DIR}/plugins/io/remote_io.c" "remote_io_plugin" "DYNAMIC" "remote_io" 1) ENDIF() ENDIF() diff --git a/include/mysql.h b/include/mysql.h index 78e7911e..270567f5 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -126,9 +126,6 @@ extern unsigned int mariadb_deinitialize_ssl; typedef unsigned long long my_ulonglong; #endif -/* mysql compatibility macro */ -#define mysql_options4(A,B,C,D) mysql_optionsv((A),(B),(C),(D)) - #define SET_CLIENT_ERROR(a, b, c, d) \ { \ (a)->net.last_errno= (b);\ @@ -487,6 +484,8 @@ 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, my_ulonglong offset); diff --git a/libmariadb/CMakeLists.txt b/libmariadb/CMakeLists.txt index a0df989d..8dbc61f1 100644 --- a/libmariadb/CMakeLists.txt +++ b/libmariadb/CMakeLists.txt @@ -121,6 +121,7 @@ SET(EXPORT_SYMBOLS mysql_num_fields mysql_num_rows mysql_options + mysql_options4 mysql_optionsv mysql_ping mysql_ping_cont @@ -305,10 +306,8 @@ my_malloc.c my_messnc.c my_net.c my_once.c -my_open.c my_port.c my_pthread.c -my_read.c my_realloc.c my_seek.c my_static.c diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index 2ace684d..49f136a3 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -3258,6 +3258,11 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg) return mysql_optionsv(mysql, option, arg); } +int STDCALL +mysql_options4(MYSQL *mysql,enum mysql_option option, const void *arg1, const void *arg2) +{ + return mysql_optionsv(mysql, option, arg1, arg2); +} /**************************************************************************** ** Functions to get information from the MySQL structure ** These are functions to make shared libraries more usable. From c5ca735dd3aba9f1de2c6435392d0dad21589a4f Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Tue, 2 Feb 2016 12:12:04 +0100 Subject: [PATCH 14/39] Renamed prefixes for 10.2 integration --- client/ma_plugin_info.c | 12 +- include/errmsg.h | 2 +- include/m_ctype.h | 10 +- include/m_string.h | 2 +- include/my_alarm.h | 12 +- include/my_list.h | 2 +- include/my_pthread.h | 16 +- include/my_sys.h | 160 +++++++------- include/mysql_com.h | 6 +- include/mysys_err.h | 4 +- libmariadb/array.c | 28 +-- libmariadb/charset.c | 14 +- libmariadb/client_plugin.c.in | 10 +- libmariadb/dbug.c | 8 +- libmariadb/default.c | 38 ++-- libmariadb/errors.c | 12 +- libmariadb/hash.c | 8 +- libmariadb/libmariadb.c | 322 ++++++++++++++--------------- libmariadb/list.c | 6 +- libmariadb/llstr.c | 6 +- libmariadb/ma_dyncol.c | 48 ++--- libmariadb/ma_io.c | 20 +- libmariadb/ma_pvio.c | 12 +- libmariadb/ma_ssl.c | 4 +- libmariadb/mf_format.c | 4 +- libmariadb/mf_pack.c | 78 +++---- libmariadb/mf_path.c | 8 +- libmariadb/mulalloc.c | 2 +- libmariadb/my_alloc.c | 28 +-- libmariadb/my_charset.c | 4 +- libmariadb/my_compress.c | 14 +- libmariadb/my_div.c | 4 +- libmariadb/my_error.c | 18 +- libmariadb/my_fopen.c | 34 +-- libmariadb/my_fstream.c | 8 +- libmariadb/my_getwd.c | 34 +-- libmariadb/my_init.c | 46 ++--- libmariadb/my_lib.c | 26 +-- libmariadb/my_loaddata.c | 10 +- libmariadb/my_malloc.c | 28 +-- libmariadb/my_messnc.c | 8 +- libmariadb/my_once.c | 14 +- libmariadb/my_open.c | 28 +-- libmariadb/my_read.c | 4 +- libmariadb/my_realloc.c | 16 +- libmariadb/my_static.c | 52 ++--- libmariadb/my_static.h | 12 +- libmariadb/my_stmt.c | 128 ++++++------ libmariadb/my_symlink.c | 6 +- libmariadb/my_thr_init.c | 48 ++--- libmariadb/my_vsnprintf.c | 8 +- libmariadb/my_write.c | 4 +- libmariadb/net.c | 16 +- libmariadb/secure/gnutls.c | 4 +- libmariadb/secure/ma_schannel.h | 4 +- libmariadb/secure/openssl.c | 16 +- libmariadb/string.c | 10 +- libmariadb/typelib.c | 16 +- mariadb_config/mariadb_config.c.in | 4 +- plugins/auth/my_auth.c | 2 +- plugins/pvio/pvio_socket.c | 8 +- unittest/mytap/tap.c | 2 +- 62 files changed, 759 insertions(+), 759 deletions(-) diff --git a/client/ma_plugin_info.c b/client/ma_plugin_info.c index f273bed9..11ea9888 100644 --- a/client/ma_plugin_info.c +++ b/client/ma_plugin_info.c @@ -56,16 +56,16 @@ static struct st_plugin_type plugin_types[]= static void version() { - printf("%s Version %s\n", my_progname, CLIENT_PLUGIN_INFO_VERSION); + printf("%s Version %s\n", ma_progname, CLIENT_PLUGIN_INFO_VERSION); } static void usage(void) { int i=0; - printf("%s Version %s\n", my_progname, CLIENT_PLUGIN_INFO_VERSION); + 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", my_progname); + printf("Usage: %s [OPTIONS] [plugin_name]\n", ma_progname); while (long_options[i].name) { printf(" --%-12s -%s\n", long_options[i].name, values[i]); @@ -73,7 +73,7 @@ static void usage(void) } } -static char *get_type_name(int type) +static char *ma_get_type_name(int type) { int i=0; while (plugin_types[i].type) @@ -88,7 +88,7 @@ static char *get_type_name(int type) static void show_plugin_info(struct st_mysql_client_plugin *plugin, my_bool builtin) { printf("Name: %s\n", plugin->name); - printf("Type: %s\n", get_type_name(plugin->type)); + 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); @@ -164,7 +164,7 @@ int main(int argc, char *argv[]) { int option_index= 0; int c; - my_progname= argv[0]; + ma_progname= argv[0]; mysql_server_init(0, NULL, NULL); diff --git a/include/errmsg.h b/include/errmsg.h index 0af17b20..6f1318dc 100644 --- a/include/errmsg.h +++ b/include/errmsg.h @@ -37,7 +37,7 @@ extern const char *mariadb_client_errors[]; /* Error messages */ #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 my_error() */ +#define CLIENT_ERRMAP 2 /* Errormap used by ma_error() */ #define CR_UNKNOWN_ERROR 2000 #define CR_SOCKET_CREATE_ERROR 2001 diff --git a/include/m_ctype.h b/include/m_ctype.h index f25f1104..d9f48ce7 100644 --- a/include/m_ctype.h +++ b/include/m_ctype.h @@ -52,11 +52,11 @@ typedef struct charset_info_st } CHARSET_INFO; extern const CHARSET_INFO compiled_charsets[]; -extern CHARSET_INFO *default_charset_info; -extern CHARSET_INFO *my_charset_bin; -extern CHARSET_INFO *my_charset_latin1; -extern CHARSET_INFO *my_charset_utf8_general_ci; -extern CHARSET_INFO *my_charset_utf16le_general_ci; +extern CHARSET_INFO *ma_default_charset_info; +extern CHARSET_INFO *ma_charset_bin; +extern CHARSET_INFO *ma_charset_latin1; +extern CHARSET_INFO *ma_charset_utf8_general_ci; +extern CHARSET_INFO *ma_charset_utf16le_general_ci; CHARSET_INFO *find_compiled_charset(unsigned int cs_number); CHARSET_INFO *find_compiled_charset_by_name(const char *name); diff --git a/include/m_string.h b/include/m_string.h index 7d102127..197a8e33 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -195,7 +195,7 @@ extern char *my_itoa(int val,char *dst,int radix); extern char *my_ltoa(long val,char *dst,int radix); #endif -extern char *llstr(longlong value,char *buff); +extern char *ma_llstr(longlong value,char *buff); #ifndef HAVE_STRTOUL extern long strtol(const char *str, char **ptr, int base); extern ulong strtoul(const char *str, char **ptr, int base); diff --git a/include/my_alarm.h b/include/my_alarm.h index b6c5ca6a..ab8424a8 100644 --- a/include/my_alarm.h +++ b/include/my_alarm.h @@ -25,26 +25,26 @@ extern "C" { #endif -extern int volatile my_have_got_alarm; -extern ulong my_time_to_wait_for_lock; +extern int volatile ma_have_got_alarm; +extern ulong ma_time_to_wait_for_lock; #if defined(HAVE_ALARM) && !defined(NO_ALARM_LOOP) #include #define ALARM_VARIABLES uint alarm_old=0; \ sig_return alarm_signal=0 -#define ALARM_INIT my_have_got_alarm=0 ; \ +#define ALARM_INIT ma_have_got_alarm=0 ; \ alarm_old=(uint) alarm(MY_HOW_OFTEN_TO_ALARM); \ alarm_signal=signal(SIGALRM,my_set_alarm_variable); #define ALARM_END VOID(signal(SIGALRM,alarm_signal)); \ VOID(alarm(alarm_old)); -#define ALARM_TEST my_have_got_alarm +#define ALARM_TEST ma_have_got_alarm #ifdef DONT_REMEMBER_SIGNAL #define ALARM_REINIT VOID(alarm(MY_HOW_OFTEN_TO_ALARM)); \ VOID(signal(SIGALRM,my_set_alarm_variable));\ - my_have_got_alarm=0; + ma_have_got_alarm=0; #else #define ALARM_REINIT VOID(alarm((uint) MY_HOW_OFTEN_TO_ALARM)); \ - my_have_got_alarm=0; + ma_have_got_alarm=0; #endif /* DONT_REMEMBER_SIGNAL */ #else #define ALARM_VARIABLES long alarm_pos=0,alarm_end_pos=MY_HOW_OFTEN_TO_WRITE-1 diff --git a/include/my_list.h b/include/my_list.h index a5621367..d733decc 100644 --- a/include/my_list.h +++ b/include/my_list.h @@ -39,7 +39,7 @@ extern int list_walk(LIST *list,list_walk_action action,gptr argument); #define rest(a) ((a)->next) #define list_push(a,b) (a)=list_cons((b),(a)) -#define list_pop(A) {LIST *old=(A); (A)=list_delete(old,old) ; my_free((gptr) old,MYF(MY_FAE)); } +#define list_pop(A) {LIST *old=(A); (A)=list_delete(old,old) ; ma_free((gptr) old,MYF(MY_FAE)); } #ifdef __cplusplus } diff --git a/include/my_pthread.h b/include/my_pthread.h index 1d4f894c..65f8d30e 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -516,11 +516,11 @@ extern pthread_mutexattr_t my_errchk_mutexattr; #define MY_INIT_MUTEX_ERRCHK &my_errchk_mutexattr #endif -extern my_bool my_thread_global_init(void); -extern void my_thread_global_end(void); -extern my_bool my_thread_init(void); -extern void my_thread_end(void); -extern const char *my_thread_name(void); +extern my_bool ma_thread_global_init(void); +extern void ma_thread_global_end(void); +extern my_bool ma_thread_init(void); +extern void ma_thread_end(void); +extern const char *ma_thread_name(void); extern long my_thread_id(void); extern int pthread_no_free(void *); extern int pthread_dummy(int); @@ -534,7 +534,7 @@ extern int pthread_dummy(int); #define DEFAULT_THREAD_STACK (64*1024) #endif -struct st_my_thread_var +struct st_ma_thread_var { int thr_errno; pthread_cond_t suspend; @@ -552,9 +552,9 @@ struct st_my_thread_var my_bool initialized; }; -extern struct st_my_thread_var *_my_thread_var(void) __attribute__ ((const)); +extern struct st_ma_thread_var *_ma_thread_var(void) __attribute__ ((const)); extern void **my_thread_var_dbug(); -#define my_thread_var (_my_thread_var()) +#define my_thread_var (_ma_thread_var()) #define my_errno my_thread_var->thr_errno /* statistics_xxx functions are for not essential statistic */ diff --git a/include/my_sys.h b/include/my_sys.h index dabaa12e..26755cc4 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -41,9 +41,9 @@ extern int NEAR my_errno; /* Last error in mysys */ #include -#define MYSYS_PROGRAM_USES_CURSES() { error_handler_hook = my_message_curses; mysys_uses_curses=1; } -#define MYSYS_PROGRAM_DONT_USE_CURSES() { error_handler_hook = my_message_no_curses; mysys_uses_curses=0;} -#define MY_INIT(name); { my_progname= name; my_init(); } +#define MYSYS_PROGRAM_USES_CURSES() { ma_error_handler_hook = ma_message_curses; mysys_uses_curses=1; } +#define MYSYS_PROGRAM_DONT_USE_CURSES() { ma_error_handler_hook = ma_message_no_curses; mysys_uses_curses=0;} +#define MY_INIT(name); { ma_progname= name; ma_init(); } #define MAXMAPS (4) /* Number of error message maps */ #define ERRMOD (1000) /* Max number of errors in a map */ @@ -68,14 +68,14 @@ extern int NEAR my_errno; /* Last error in mysys */ #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 /* my_malloc(), fill array with zero */ -#define MY_ALLOW_ZERO_PTR 64 /* my_realloc() ; zero ptr -> malloc */ -#define MY_FREE_ON_ERROR 128 /* my_realloc() ; Free old ptr on error */ -#define MY_HOLD_ON_ERROR 256 /* my_realloc() ; Return old ptr on error */ +#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 my_end; Check open-close */ +#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 */ @@ -119,14 +119,14 @@ extern int NEAR my_errno; /* Last error in mysys */ #define TERMINATE(A) {} #define QUICK_SAFEMALLOC #define NORMAL_SAFEMALLOC -extern gptr my_malloc(size_t Size,myf MyFlags); -#define my_malloc_ci(SZ,FLAG) my_malloc( SZ, FLAG ) -extern gptr my_realloc(gptr oldpoint, size_t Size,myf MyFlags); +extern gptr ma_malloc(size_t Size,myf MyFlags); +#define ma_malloc_ci(SZ,FLAG) ma_malloc( SZ, FLAG ) +extern gptr ma_realloc(gptr oldpoint, size_t Size,myf MyFlags); extern void my_no_flags_free(void *ptr); -extern gptr my_memdup(const unsigned char *from, size_t length,myf MyFlags); -extern my_string my_strdup(const char *from,myf MyFlags); -extern my_string my_strndup(const char *from, size_t length, myf MyFlags); -#define my_free(PTR) my_no_flags_free(PTR) +extern gptr ma_memdup(const unsigned char *from, size_t length,myf MyFlags); +extern my_string ma_strdup(const char *from,myf MyFlags); +extern my_string ma_strndup(const char *from, size_t length, myf MyFlags); +#define ma_free(PTR) my_no_flags_free(PTR) #define CALLER_INFO_PROTO /* nothing */ #define CALLER_INFO /* nothing */ #define ORIG_CALLER_INFO /* nothing */ @@ -143,8 +143,8 @@ extern my_string my_strndup(const char *from, size_t length, myf MyFlags); #define my_alloca(SZ) alloca((size_t) (SZ)) #define my_afree(PTR) {} #else -#define my_alloca(SZ) my_malloc(SZ,MYF(0)) -#define my_afree(PTR) my_free(PTR) +#define my_alloca(SZ) ma_malloc(SZ,MYF(0)) +#define my_afree(PTR) ma_free(PTR) #endif /* HAVE_ALLOCA */ #ifdef MSDOS @@ -172,11 +172,11 @@ extern int errno; /* declare errno */ #endif extern const char ** NEAR my_errmsg[]; extern char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE]; -extern char *home_dir; /* Home directory for user */ -extern char *my_progname; /* program-name (printed in errors) */ -extern char NEAR curr_dir[]; /* Current directory for user */ -extern int (*error_handler_hook)(uint my_err, const char *str,myf MyFlags); -extern int (*fatal_error_handler_hook)(uint my_err, const char *str, +extern char *ma_ma_ma_home_dir; /* Home directory for user */ +extern char *ma_progname; /* program-name (printed in errors) */ +extern char NEAR ma_cur_dir[]; /* Current directory for user */ +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 */ @@ -188,7 +188,7 @@ extern CHARSET_INFO *get_charset_by_name(const char *cs_name); extern CHARSET_INFO *get_charset_by_nr(uint cs_number); extern my_bool set_default_charset_by_name(const char *cs_name, myf flags); extern void free_charsets(void); -extern char *list_charsets(myf want_flags); /* my_free() this string... */ +extern char *list_charsets(myf want_flags); /* ma_free() this string... */ extern char *get_charsets_dir(char *buf); @@ -196,26 +196,26 @@ extern char *get_charsets_dir(char *buf); 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 my_file_opened,my_stream_opened, my_tmp_file_created; +extern ulong ma_file_opened,ma_stream_opened, ma_tmp_file_created; extern my_bool key_cache_inited; - /* Point to current my_message() */ + /* 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 comming from shell */ -extern int NEAR my_umask, /* Default creation mask */ - NEAR my_umask_dir, +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 my_dont_interrupt; /* call remember_intr when set */ -extern my_bool NEAR mysys_uses_curses, my_use_symdir; + 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 my_default_record_cache_size; -extern my_bool NEAR my_disable_locking,NEAR my_disable_async_io, - NEAR my_disable_flush_key_blocks, NEAR my_disable_symlinks; +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; @@ -259,14 +259,14 @@ typedef struct st_record_cache /* Used when cacheing records */ enum file_type { UNOPEN = 0, FILE_BY_OPEN, FILE_BY_CREATE, STREAM_BY_FOPEN, STREAM_BY_FDOPEN, FILE_BY_MKSTEMP }; -extern struct my_file_info +extern struct ma_file_info { my_string name; enum file_type type; #if defined(THREAD) && !defined(HAVE_PREAD) pthread_mutex_t mutex; #endif -} my_file_info[MY_NFILE]; +} ma_file_info[MY_NFILE]; typedef struct st_dynamic_array { @@ -352,7 +352,7 @@ typedef struct st_changeable_var { } CHANGEABLE_VAR; -/* structs for alloc_root */ +/* structs for ma_alloc_root */ #ifndef ST_USED_MEM_DEFINED #define ST_USED_MEM_DEFINED @@ -423,30 +423,30 @@ extern gptr _myrealloc(gptr pPtr,size_t uSize,const char *sFile, extern gptr my_multi_malloc _VARARGS((myf MyFlags, ...)); extern void _myfree(gptr pPtr,const char *sFile,uint uLine, myf MyFlag); extern int _sanity(const char *sFile,unsigned int uLine); -extern gptr _my_memdup(const unsigned char *from, size_t length, +extern gptr _ma_memdup(const unsigned char *from, size_t length, const char *sFile, uint uLine,myf MyFlag); -extern my_string _my_strdup(const char *from, const char *sFile, uint uLine, +extern my_string _ma_strdup(const char *from, const char *sFile, uint uLine, myf MyFlag); #ifndef TERMINATE extern void TERMINATE(FILE *file); #endif -extern void init_glob_errs(void); +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 my_error _VARARGS((int nr,myf MyFlags, ...)); -extern int my_printf_error _VARARGS((uint my_err, const char *format, +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 my_vsnprintf( char *str, size_t n, +extern int ma_vsnprintf( char *str, size_t n, const char *format, va_list ap ); -extern int my_snprintf(char* to, size_t n, const char* fmt, ...); -extern int my_message(uint my_err, const char *str,myf MyFlags); -extern int my_message_no_curses(uint my_err, const char *str,myf MyFlags); -extern int my_message_curses(uint my_err, const char *str,myf MyFlags); -extern void my_init(void); -extern void my_end(int infoflag); +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 ma_message_no_curses(uint my_err, const char *str,myf MyFlags); +extern int ma_message_curses(uint my_err, const char *str,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); @@ -476,12 +476,12 @@ extern my_string fn_same(my_string toname,const char *name,int flag); extern my_string fn_format(my_string to,const char *name,const char *dsk, const char *form,int flag); extern size_s strlength(const char *str); -extern void pack_dirname(my_string to,const char *from); -extern uint unpack_dirname(my_string to,const char *from); -extern uint cleanup_dirname(my_string to,const char *from); -extern uint system_filename(my_string to,const char *from); -extern my_string unpack_filename(my_string to,const char *from); -extern my_string intern_filename(my_string to,const char *from); +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, @@ -553,25 +553,25 @@ 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 my_init_dynamic_array(A,B,C,D) init_dynamic_array(A,B,C,D CALLER_INFO) -#define my_init_dynamic_array_ci(A,B,C,D) init_dynamic_array(A,B,C,D ORIG_CALLER_INFO) +#define ma_init_dynamic_array(A,B,C,D) init_dynamic_array(A,B,C,D CALLER_INFO) +#define ma_init_dynamic_array_ci(A,B,C,D) init_dynamic_array(A,B,C,D ORIG_CALLER_INFO) extern my_bool init_dynamic_array(DYNAMIC_ARRAY *array,uint element_size, uint init_alloc,uint alloc_increment CALLER_INFO_PROTO); -extern my_bool insert_dynamic(DYNAMIC_ARRAY *array,gptr element); -extern unsigned char *alloc_dynamic(DYNAMIC_ARRAY *array); -extern unsigned char *pop_dynamic(DYNAMIC_ARRAY*); -extern my_bool set_dynamic(DYNAMIC_ARRAY *array,gptr element,uint array_index); -extern void get_dynamic(DYNAMIC_ARRAY *array,gptr element,uint array_index); -extern void delete_dynamic(DYNAMIC_ARRAY *array); -extern void delete_dynamic_element(DYNAMIC_ARRAY *array, uint array_index); -extern void freeze_size(DYNAMIC_ARRAY *array); +extern my_bool ma_insert_dynamic(DYNAMIC_ARRAY *array,gptr 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,gptr element,uint array_index); +extern void ma_get_dynamic(DYNAMIC_ARRAY *array,gptr 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) insert_dynamic(A,B) +#define push_dynamic(A,B) ma_insert_dynamic(A,B) -extern int find_type(my_string x,TYPELIB *typelib,uint full_name); -extern void make_type(my_string to,uint nr,TYPELIB *typelib); -extern const char *get_type(TYPELIB *typelib,uint nr); +extern 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 init_dynamic_string(DYNAMIC_STRING *str, const char *init_str, size_t init_alloc, size_t alloc_increment); extern my_bool dynstr_append(DYNAMIC_STRING *str, const char *append); @@ -585,22 +585,22 @@ my_bool set_changeable_var(my_string str,CHANGEABLE_VAR *vars); my_bool set_changeable_varval(const char *var, ulong val, CHANGEABLE_VAR *vars); #ifdef HAVE_MLOCK -extern unsigned char *my_malloc_lock(size_t length,myf flags); -extern void my_free_lock(unsigned char *ptr,myf flags); +extern unsigned char *ma_malloc_lock(size_t length,myf flags); +extern void ma_free_lock(unsigned char *ptr,myf flags); #else -#define my_malloc_lock(A,B) my_malloc((A),(B)) -#define my_free_lock(A,B) my_free((A),(B)) +#define ma_malloc_lock(A,B) ma_malloc((A),(B)) +#define ma_free_lock(A,B) ma_free((A),(B)) #endif -#define alloc_root_inited(A) ((A)->min_malloc != 0) -void init_alloc_root(MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size); -gptr alloc_root(MEM_ROOT *mem_root, size_t Size); -void free_root(MEM_ROOT *root, myf MyFLAGS); -char *strdup_root(MEM_ROOT *root,const char *str); -char *memdup_root(MEM_ROOT *root,const char *str, size_t len); -void load_defaults(const char *conf_file, const char **groups, +#define ma_alloc_root_inited(A) ((A)->min_malloc != 0) +void ma_init_ma_alloc_root(MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size); +gptr ma_alloc_root(MEM_ROOT *mem_root, size_t Size); +void ma_free_root(MEM_ROOT *root, myf MyFLAGS); +char *ma_strdup_root(MEM_ROOT *root,const char *str); +char *ma_memdup_root(MEM_ROOT *root,const char *str, size_t len); +void mariadb_load_defaults(const char *conf_file, const char **groups, int *argc, char ***argv); -void free_defaults(char **argv); -void print_defaults(const char *conf_file, const char **groups); +void ma_free_defaults(char **argv); +void ma_print_defaults(const char *conf_file, const char **groups); my_bool my_compress(unsigned char *, size_t *, size_t *); my_bool my_uncompress(unsigned char *, size_t *, size_t *); unsigned char *my_compress_alloc(const unsigned char *packet, size_t *len, size_t *complen); diff --git a/include/mysql_com.h b/include/mysql_com.h index cfd520d5..121b8b88 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -408,10 +408,10 @@ void hash_password(unsigned long *result, const char *password, size_t len); /* Some other useful functions */ -void load_defaults(const char *conf_file, const char **groups, +void mariadb_load_defaults(const char *conf_file, const char **groups, int *argc, char ***argv); -my_bool my_thread_init(void); -void my_thread_end(void); +my_bool ma_thread_init(void); +void ma_thread_end(void); #ifdef __cplusplus } diff --git a/include/mysys_err.h b/include/mysys_err.h index 6ac5e2cc..ede23088 100644 --- a/include/mysys_err.h +++ b/include/mysys_err.h @@ -23,9 +23,9 @@ extern "C" { #define GLOB 0 /* Error maps */ #define GLOBERRS EE_LASTERROR - EE_FIRSTERROR + 1 /* Max number of error messages in map's */ -#define EE(X) globerrs[ (X) - EE_FIRSTERROR ] /* Defines to add error to right map */ +#define EE(X) ma_globerrs[ (X) - EE_FIRSTERROR ] /* Defines to add error to right map */ -extern const char * NEAR globerrs[]; /* my_error_messages is here */ +extern const char * NEAR ma_globerrs[]; /* ma_error_messages is here */ /* Error message numbers in global map diff --git a/libmariadb/array.c b/libmariadb/array.c index d52a58c8..14521b34 100644 --- a/libmariadb/array.c +++ b/libmariadb/array.c @@ -44,7 +44,7 @@ my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size, array->max_element=init_alloc; array->alloc_increment=alloc_increment; array->size_of_element=element_size; - if (!(array->buffer=(char*) my_malloc_ci(element_size*init_alloc,MYF(MY_WME)))) + if (!(array->buffer=(char*) ma_malloc_ci(element_size*init_alloc,MYF(MY_WME)))) { array->max_element=0; DBUG_RETURN(TRUE); @@ -53,12 +53,12 @@ my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size, } -my_bool insert_dynamic(DYNAMIC_ARRAY *array, gptr element) +my_bool ma_insert_dynamic(DYNAMIC_ARRAY *array, gptr element) { gptr buffer; if (array->elements == array->max_element) { /* Call only when nessesary */ - if (!(buffer=alloc_dynamic(array))) + if (!(buffer=ma_alloc_dynamic(array))) return TRUE; } else @@ -73,12 +73,12 @@ my_bool insert_dynamic(DYNAMIC_ARRAY *array, gptr element) /* Alloc room for one element */ -unsigned char *alloc_dynamic(DYNAMIC_ARRAY *array) +unsigned char *ma_alloc_dynamic(DYNAMIC_ARRAY *array) { if (array->elements == array->max_element) { char *new_ptr; - if (!(new_ptr=(char*) my_realloc(array->buffer,(array->max_element+ + if (!(new_ptr=(char*) ma_realloc(array->buffer,(array->max_element+ array->alloc_increment)* array->size_of_element, MYF(MY_WME | MY_ALLOW_ZERO_PTR)))) @@ -92,7 +92,7 @@ unsigned char *alloc_dynamic(DYNAMIC_ARRAY *array) /* remove last element from array and return it */ -unsigned char *pop_dynamic(DYNAMIC_ARRAY *array) +unsigned char *ma_pop_dynamic(DYNAMIC_ARRAY *array) { if (array->elements) return array->buffer+(--array->elements * array->size_of_element); @@ -100,7 +100,7 @@ unsigned char *pop_dynamic(DYNAMIC_ARRAY *array) } -my_bool set_dynamic(DYNAMIC_ARRAY *array, gptr element, uint idx) +my_bool ma_set_dynamic(DYNAMIC_ARRAY *array, gptr element, uint idx) { if (idx >= array->elements) { @@ -110,7 +110,7 @@ my_bool set_dynamic(DYNAMIC_ARRAY *array, gptr element, uint idx) char *new_ptr; size=(idx+array->alloc_increment)/array->alloc_increment; size*= array->alloc_increment; - if (!(new_ptr=(char*) my_realloc(array->buffer,size* + if (!(new_ptr=(char*) ma_realloc(array->buffer,size* array->size_of_element, MYF(MY_WME | MY_ALLOW_ZERO_PTR)))) return TRUE; @@ -127,7 +127,7 @@ my_bool set_dynamic(DYNAMIC_ARRAY *array, gptr element, uint idx) } -void get_dynamic(DYNAMIC_ARRAY *array, gptr element, uint idx) +void ma_get_dynamic(DYNAMIC_ARRAY *array, gptr element, uint idx) { if (idx >= array->elements) { @@ -141,18 +141,18 @@ void get_dynamic(DYNAMIC_ARRAY *array, gptr element, uint idx) } -void delete_dynamic(DYNAMIC_ARRAY *array) +void ma_delete_dynamic(DYNAMIC_ARRAY *array) { if (array->buffer) { - my_free(array->buffer); + ma_free(array->buffer); array->buffer=0; array->elements=array->max_element=0; } } -void delete_dynamic_element(DYNAMIC_ARRAY *array, uint idx) +void ma_delete_dynamic_element(DYNAMIC_ARRAY *array, uint idx) { char *ptr=array->buffer+array->size_of_element*idx; array->elements--; @@ -161,13 +161,13 @@ void delete_dynamic_element(DYNAMIC_ARRAY *array, uint idx) } -void freeze_size(DYNAMIC_ARRAY *array) +void ma_freeze_size(DYNAMIC_ARRAY *array) { uint elements=max(array->elements,1); if (array->buffer && array->max_element != elements) { - array->buffer=(char*) my_realloc(array->buffer, + array->buffer=(char*) ma_realloc(array->buffer, elements*array->size_of_element, MYF(MY_WME)); array->max_element=elements; diff --git a/libmariadb/charset.c b/libmariadb/charset.c index 9d8a4224..72e2da96 100644 --- a/libmariadb/charset.c +++ b/libmariadb/charset.c @@ -21,11 +21,11 @@ #include #include -CHARSET_INFO *default_charset_info = (CHARSET_INFO *)&compiled_charsets[5]; -CHARSET_INFO *my_charset_bin= (CHARSET_INFO *)&compiled_charsets[32]; -CHARSET_INFO *my_charset_latin1= (CHARSET_INFO *)&compiled_charsets[5]; -CHARSET_INFO *my_charset_utf8_general_ci= (CHARSET_INFO *)&compiled_charsets[21]; -CHARSET_INFO *my_charset_utf16le_general_ci= (CHARSET_INFO *)&compiled_charsets[68]; +CHARSET_INFO *ma_default_charset_info = (CHARSET_INFO *)&compiled_charsets[5]; +CHARSET_INFO *ma_charset_bin= (CHARSET_INFO *)&compiled_charsets[32]; +CHARSET_INFO *ma_charset_latin1= (CHARSET_INFO *)&compiled_charsets[5]; +CHARSET_INFO *ma_charset_utf8_general_ci= (CHARSET_INFO *)&compiled_charsets[21]; +CHARSET_INFO *ma_charset_utf16le_general_ci= (CHARSET_INFO *)&compiled_charsets[68]; CHARSET_INFO * STDCALL mysql_get_charset_by_nr(uint cs_number) { @@ -48,7 +48,7 @@ my_bool set_default_charset(uint cs, myf flags) DBUG_PRINT("error",("Couldn't set default character set")); DBUG_RETURN(TRUE); /* error */ } - default_charset_info = new_charset; + ma_default_charset_info = new_charset; DBUG_RETURN(FALSE); } @@ -74,6 +74,6 @@ my_bool set_default_charset_by_name(const char *cs_name, myf flags) DBUG_RETURN(TRUE); /* error */ } - default_charset_info = new_charset; + ma_default_charset_info = new_charset; DBUG_RETURN(FALSE); } diff --git a/libmariadb/client_plugin.c.in b/libmariadb/client_plugin.c.in index 0e2d5952..6d0a8c67 100644 --- a/libmariadb/client_plugin.c.in +++ b/libmariadb/client_plugin.c.in @@ -197,7 +197,7 @@ add_plugin(MYSQL *mysql, struct st_mysql_client_plugin *plugin, void *dlhandle, } p= (struct st_client_plugin_int *) - memdup_root(&mem_root, (char *)&plugin_int, sizeof(plugin_int)); + ma_memdup_root(&mem_root, (char *)&plugin_int, sizeof(plugin_int)); if (!p) { @@ -250,7 +250,7 @@ static void load_env_plugins(MYSQL *mysql) if (!s) return; - free_env= plugs= my_strdup(s, MYF(MY_WME)); + free_env= plugs= ma_strdup(s, MYF(MY_WME)); do { if ((s= strchr(plugs, ';'))) @@ -259,7 +259,7 @@ static void load_env_plugins(MYSQL *mysql) plugs= s + 1; } while (s); - my_free(free_env); + ma_free(free_env); } /********** extern functions to be used by libmariadb *********************/ @@ -286,7 +286,7 @@ int mysql_client_plugin_init() bzero(&mysql, sizeof(mysql)); /* dummy mysql for set_mysql_extended_error */ pthread_mutex_init(&LOCK_load_client_plugin, MY_MUTEX_INIT_SLOW); - init_alloc_root(&mem_root, 128, 128); + ma_init_ma_alloc_root(&mem_root, 128, 128); bzero(&plugin_list, sizeof(plugin_list)); @@ -329,7 +329,7 @@ void mysql_client_plugin_deinit() bzero(&plugin_list, sizeof(plugin_list)); initialized= 0; - free_root(&mem_root, MYF(0)); + ma_free_root(&mem_root, MYF(0)); pthread_mutex_destroy(&LOCK_load_client_plugin); } diff --git a/libmariadb/dbug.c b/libmariadb/dbug.c index 5e848c44..df15301f 100644 --- a/libmariadb/dbug.c +++ b/libmariadb/dbug.c @@ -101,7 +101,7 @@ #include #endif -extern int my_snprintf(char* to, size_t n, const char* fmt, ...); +extern int ma_snprintf(char* to, size_t n, const char* fmt, ...); char _dig_vec_upper[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; @@ -283,7 +283,7 @@ typedef struct _db_code_state_ { /* The test below is so we could call functions with DBUG_ENTER before - my_thread_init(). + ma_thread_init(). */ #define get_code_state_if_not_set_or_return if (!cs && !((cs=code_state()))) return #define get_code_state_or_return if (!((cs=code_state()))) return @@ -1290,7 +1290,7 @@ void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_) if (cs->framep != _stack_frame_) { char buf[512]; - my_snprintf(buf, sizeof(buf), ERR_MISSING_RETURN, cs->func); + ma_snprintf(buf, sizeof(buf), ERR_MISSING_RETURN, cs->func); DbugExit(buf); } @@ -1957,7 +1957,7 @@ static void DoPrefix(CODE_STATE *cs, uint _line_) cs->lineno++; if (cs->stack->flags & PID_ON) { - (void) fprintf(cs->stack->out_file, "%-7s: ", my_thread_name()); + (void) fprintf(cs->stack->out_file, "%-7s: ", ma_thread_name()); } if (cs->stack->flags & NUMBER_ON) (void) fprintf(cs->stack->out_file, "%5d: ", cs->lineno); diff --git a/libmariadb/default.c b/libmariadb/default.c index 20fa4cf3..7571bdbc 100644 --- a/libmariadb/default.c +++ b/libmariadb/default.c @@ -21,7 +21,7 @@ ** On Windows defaults will also search in the Windows directory for a file ** called 'group'.ini ** As long as the program uses the last argument for conflicting -** options one only have to add a call to "load_defaults" to enable +** options one only have to add a call to "mariadb_load_defaults" to enable ** use of default values. ** pre- and end 'blank space' are removed from options and values. The ** following escape sequences are recognized in values: \b \t \n \r \\ @@ -75,24 +75,24 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args,MEM_ROOT *alloc, const char *ext, TYPELIB *group); -void load_defaults(const char *conf_file, const char **groups, +void mariadb_load_defaults(const char *conf_file, const char **groups, int *argc, char ***argv) { DYNAMIC_ARRAY args; const char **dirs, *forced_default_file; TYPELIB group; - my_bool found_print_defaults=0; + my_bool found_ma_print_defaults=0; uint args_used=0; MEM_ROOT alloc; char *ptr,**res; - DBUG_ENTER("load_defaults"); + DBUG_ENTER("mariadb_load_defaults"); - init_alloc_root(&alloc,128,0); + ma_init_ma_alloc_root(&alloc,128,0); if (*argc >= 2 && !strcmp(argv[0][1],"--no-defaults")) { /* remove the --no-defaults argument and return only the other arguments */ uint i; - if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+ + if (!(ptr=(char*) ma_alloc_root(&alloc,sizeof(alloc)+ (*argc + 1)*sizeof(char*)))) goto err; res= (char**) (ptr+sizeof(alloc)); @@ -127,7 +127,7 @@ void load_defaults(const char *conf_file, const char **groups, for (; *groups ; groups++) group.count++; - if (my_init_dynamic_array(&args, sizeof(char*),*argc, 32)) + if (ma_init_dynamic_array(&args, sizeof(char*),*argc, 32)) goto err; if (forced_default_file) { @@ -169,7 +169,7 @@ void load_defaults(const char *conf_file, const char **groups, goto err; } } - if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+ + if (!(ptr=(char*) ma_alloc_root(&alloc,sizeof(alloc)+ (args.elements + *argc +1) *sizeof(char*)))) goto err; res= (char**) (ptr+sizeof(alloc)); @@ -184,7 +184,7 @@ void load_defaults(const char *conf_file, const char **groups, /* Check if we wan't to see the new argument list */ if (*argc >= 2 && !strcmp(argv[0][1],"--print-defaults")) { - found_print_defaults=1; + found_ma_print_defaults=1; --*argc; ++*argv; /* skipp argument */ } @@ -195,8 +195,8 @@ void load_defaults(const char *conf_file, const char **groups, (*argc)+=args.elements; *argv= (char**) res; *(MEM_ROOT*) ptr= alloc; /* Save alloc root for free */ - delete_dynamic(&args); - if (found_print_defaults) + ma_delete_dynamic(&args); + if (found_ma_print_defaults) { int i; printf("%s would have been started with the following arguments:\n", @@ -214,11 +214,11 @@ void load_defaults(const char *conf_file, const char **groups, } -void free_defaults(char **argv) +void ma_free_defaults(char **argv) { MEM_ROOT ptr; memcpy_fixed((char*) &ptr,(char *) argv - sizeof(ptr), sizeof(ptr)); - free_root(&ptr,MYF(0)); + ma_free_root(&ptr,MYF(0)); } @@ -294,7 +294,7 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, } for ( ; isspace(end[-1]) ; end--) ; /* Remove end space */ end[0]=0; - read_values=find_type(ptr,group,3) > 0; + read_values=ma_find_type(ptr,group,3) > 0; continue; } if (!found_group) @@ -311,10 +311,10 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, for ( ; isspace(end[-1]) ; end--) ; if (!value) { - if (!(tmp=alloc_root(alloc,(uint) (end-ptr)+3))) + if (!(tmp=ma_alloc_root(alloc,(uint) (end-ptr)+3))) goto err; strmake(strmov(tmp,"--"),ptr,(uint) (end-ptr)); - if (insert_dynamic(args,(gptr) &tmp)) + if (ma_insert_dynamic(args,(gptr) &tmp)) goto err; } else @@ -333,10 +333,10 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, } if (value_end < value) /* Empty string */ value_end=value; - if (!(tmp=alloc_root(alloc,(uint) (end-ptr)+3 + + if (!(tmp=ma_alloc_root(alloc,(uint) (end-ptr)+3 + (uint) (value_end-value)+1))) goto err; - if (insert_dynamic(args,(gptr) &tmp)) + if (ma_insert_dynamic(args,(gptr) &tmp)) goto err; ptr=strnmov(strmov(tmp,"--"),ptr,(uint) (end-ptr)); *ptr++= '='; @@ -390,7 +390,7 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, } -void print_defaults(const char *conf_file, const char **groups) +void ma_print_defaults(const char *conf_file, const char **groups) { #ifdef _WIN32 bool have_ext=fn_ext(conf_file)[0] != 0; diff --git a/libmariadb/errors.c b/libmariadb/errors.c index 393f628b..7a68d3b6 100644 --- a/libmariadb/errors.c +++ b/libmariadb/errors.c @@ -20,7 +20,7 @@ #ifndef SHARED_LIBRARY -const char * NEAR globerrs[GLOBERRS]= +const char * NEAR ma_globerrs[GLOBERRS]= { "Can't create/write to file '%s' (Errcode: %d)", "Error reading file '%s' (Errcode: %d)", @@ -55,16 +55,16 @@ const char * NEAR globerrs[GLOBERRS]= "Can't change mode for file '%s' to 0x%lx (Error: %d)" }; -void init_glob_errs(void) +void ma_init_glob_errs(void) { - my_errmsg[GLOB] = & globerrs[0]; -} /* init_glob_errs */ + my_errmsg[GLOB] = & ma_globerrs[0]; +} /* ma_init_glob_errs */ #else -void init_glob_errs() +void ma_init_glob_errs() { - my_errmsg[GLOB] = & globerrs[0]; + my_errmsg[GLOB] = & ma_globerrs[0]; EE(EE_FILENOTFOUND) = "File '%s' not found (Errcode: %d)"; EE(EE_CANTCREATEFILE) = "Can't create/write to file '%s' (Errcode: %d)"; diff --git a/libmariadb/hash.c b/libmariadb/hash.c index 8436ef91..31bd7a89 100644 --- a/libmariadb/hash.c +++ b/libmariadb/hash.c @@ -51,7 +51,7 @@ my_bool _hash_init(HASH *hash,uint size,uint key_offset,uint key_length, DBUG_PRINT("enter",("hash: %lx size: %d",hash,size)); hash->records=0; - if (my_init_dynamic_array_ci(&hash->array,sizeof(HASH_LINK),size,0)) + if (ma_init_dynamic_array_ci(&hash->array,sizeof(HASH_LINK),size,0)) { hash->free=0; /* Allow call to hash_free */ DBUG_RETURN(TRUE); @@ -82,7 +82,7 @@ void hash_free(HASH *hash) (*hash->free)(data[i].data); hash->free=0; } - delete_dynamic(&hash->array); + ma_delete_dynamic(&hash->array); hash->records=0; DBUG_VOID_RETURN; } @@ -303,7 +303,7 @@ my_bool hash_insert(HASH *info,const uchar *record) LINT_INIT(ptr_to_rec); LINT_INIT(ptr_to_rec2); flag=0; - if (!(empty=(HASH_LINK*) alloc_dynamic(&info->array))) + if (!(empty=(HASH_LINK*) ma_alloc_dynamic(&info->array))) return(TRUE); /* No more memory */ info->current_record= NO_RECORD; @@ -503,7 +503,7 @@ my_bool hash_delete(HASH *hash,uchar *record) pos->next=empty_index; exit: - VOID(pop_dynamic(&hash->array)); + VOID(ma_pop_dynamic(&hash->array)); if (hash->free) (*hash->free)((uchar*) record); DBUG_RETURN(0); diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index 49f136a3..5a39c9a1 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -83,7 +83,7 @@ extern ulong net_buffer_length; /* net.c */ static my_bool mysql_client_init=0; static void mysql_close_options(MYSQL *mysql); -extern my_bool my_init_done; +extern my_bool ma_init_done; extern my_bool mysql_ps_subsystem_initialized; extern my_bool mysql_handle_local_infile(MYSQL *mysql, const char *filename); extern const CHARSET_INFO * mysql_find_charset_nr(uint charsetnr); @@ -350,8 +350,8 @@ void free_rows(MYSQL_DATA *cur) { if (cur) { - free_root(&cur->alloc,MYF(0)); - my_free(cur); + ma_free_root(&cur->alloc,MYF(0)); + ma_free(cur); } } @@ -446,8 +446,8 @@ static void free_old_query(MYSQL *mysql) { DBUG_ENTER("free_old_query"); if (mysql->fields) - free_root(&mysql->field_alloc,MYF(0)); - init_alloc_root(&mysql->field_alloc,8192,0); /* Assume rowlength < 8192 */ + ma_free_root(&mysql->field_alloc,MYF(0)); + ma_init_ma_alloc_root(&mysql->field_alloc,8192,0); /* Assume rowlength < 8192 */ mysql->fields=0; mysql->field_count=0; /* For API */ DBUG_VOID_RETURN; @@ -621,10 +621,10 @@ mysql_free_result(MYSQL_RES *result) } free_rows(result->data); if (result->fields) - free_root(&result->field_alloc,MYF(0)); + ma_free_root(&result->field_alloc,MYF(0)); if (result->row) - my_free(result->row); - my_free(result); + ma_free(result->row); + ma_free(result); } DBUG_VOID_RETURN; } @@ -665,13 +665,13 @@ enum option_val #define CHECK_OPT_EXTENSION_SET(OPTS)\ if (!(OPTS)->extension) \ (OPTS)->extension= (struct st_mysql_options_extension *) \ - my_malloc(sizeof(struct st_mysql_options_extension), \ + ma_malloc(sizeof(struct st_mysql_options_extension), \ MYF(MY_WME | MY_ZEROFILL)); \ #define OPT_SET_EXTENDED_VALUE_STR(OPTS, KEY, VAL) \ CHECK_OPT_EXTENSION_SET(OPTS) \ - my_free((gptr)(OPTS)->extension->KEY);\ - (OPTS)->extension->KEY= my_strdup((char *)(VAL), MYF(MY_WME)) + ma_free((gptr)(OPTS)->extension->KEY);\ + (OPTS)->extension->KEY= ma_strdup((char *)(VAL), MYF(MY_WME)) #define OPT_SET_EXTENDED_VALUE_INT(OPTS, KEY, VAL) \ CHECK_OPT_EXTENSION_SET(OPTS) \ @@ -682,23 +682,23 @@ static TYPELIB option_types={array_elements(default_options)-1, "options",default_options}; const char *protocol_names[]= {"TCP", "SOCKED", "PIPE", "MEMORY", NULL}; -static TYPELIB protocol_types= {array_elements(protocol_names)-1, - "protocol names", - protocol_names}; +TYPELIB sql_protocol_typelib= {array_elements(protocol_names)-1, + "protocol names", + protocol_names}; static void options_add_initcommand(struct st_mysql_options *options, const char *init_cmd) { - char *insert= my_strdup(init_cmd, MYF(MY_WME)); + char *insert= ma_strdup(init_cmd, MYF(MY_WME)); if (!options->init_command) { - options->init_command= (DYNAMIC_ARRAY*)my_malloc(sizeof(DYNAMIC_ARRAY), + options->init_command= (DYNAMIC_ARRAY*)ma_malloc(sizeof(DYNAMIC_ARRAY), MYF(MY_WME)); - my_init_dynamic_array(options->init_command, sizeof(char*), 5, 5); + ma_init_dynamic_array(options->init_command, sizeof(char*), 5, 5); } - if (insert_dynamic(options->init_command, (gptr)&insert)) - my_free(insert); + if (ma_insert_dynamic(options->init_command, (gptr)&insert)) + ma_free(insert); } @@ -714,7 +714,7 @@ static void mysql_read_default_options(struct st_mysql_options *options, argc=1; argv=argv_buff; argv_buff[0]= (char*) "client"; groups[0]= (char*) "client"; groups[1]= (char*) group; groups[2]=0; - load_defaults(filename, groups, &argc, &argv); + mariadb_load_defaults(filename, groups, &argc, &argv); if (argc != 1) /* If some default option */ { char **option=argv; @@ -733,7 +733,7 @@ static void mysql_read_default_options(struct st_mysql_options *options, /* Change all '_' in variable name to '-' */ for (end= *option ; *(end= strcend(end,'_')) ; ) *end= '-'; - switch (find_type(*option+2,&option_types,2)) { + switch (ma_find_type(*option+2,&option_types,2)) { case OPT_port: if (opt_arg) options->port=atoi(opt_arg); @@ -741,8 +741,8 @@ static void mysql_read_default_options(struct st_mysql_options *options, case OPT_socket: if (opt_arg) { - my_free(options->unix_socket); - options->unix_socket=my_strdup(opt_arg,MYF(MY_WME)); + ma_free(options->unix_socket); + options->unix_socket=ma_strdup(opt_arg,MYF(MY_WME)); } break; case OPT_compress: @@ -751,8 +751,8 @@ static void mysql_read_default_options(struct st_mysql_options *options, case OPT_password: if (opt_arg) { - my_free(options->password); - options->password=my_strdup(opt_arg,MYF(MY_WME)); + ma_free(options->password); + options->password=ma_strdup(opt_arg,MYF(MY_WME)); } break; case OPT_pipe: @@ -766,8 +766,8 @@ static void mysql_read_default_options(struct st_mysql_options *options, case OPT_user: if (opt_arg) { - my_free(options->user); - options->user=my_strdup(opt_arg,MYF(MY_WME)); + ma_free(options->user); + options->user=ma_strdup(opt_arg,MYF(MY_WME)); } break; case OPT_init_command: @@ -777,15 +777,15 @@ static void mysql_read_default_options(struct st_mysql_options *options, case OPT_host: if (opt_arg) { - my_free(options->host); - options->host=my_strdup(opt_arg,MYF(MY_WME)); + ma_free(options->host); + options->host=ma_strdup(opt_arg,MYF(MY_WME)); } break; case OPT_database: if (opt_arg) { - my_free(options->db); - options->db=my_strdup(opt_arg,MYF(MY_WME)); + ma_free(options->db); + options->db=ma_strdup(opt_arg,MYF(MY_WME)); } break; case OPT_debug: @@ -796,20 +796,20 @@ static void mysql_read_default_options(struct st_mysql_options *options, break; #ifdef HAVE_SSL case OPT_ssl_key: - my_free(options->ssl_key); - options->ssl_key = my_strdup(opt_arg, MYF(MY_WME)); + ma_free(options->ssl_key); + options->ssl_key = ma_strdup(opt_arg, MYF(MY_WME)); break; case OPT_ssl_cert: - my_free(options->ssl_cert); - options->ssl_cert = my_strdup(opt_arg, MYF(MY_WME)); + ma_free(options->ssl_cert); + options->ssl_cert = ma_strdup(opt_arg, MYF(MY_WME)); break; case OPT_ssl_ca: - my_free(options->ssl_ca); - options->ssl_ca = my_strdup(opt_arg, MYF(MY_WME)); + ma_free(options->ssl_ca); + options->ssl_ca = ma_strdup(opt_arg, MYF(MY_WME)); break; case OPT_ssl_capath: - my_free(options->ssl_capath); - options->ssl_capath = my_strdup(opt_arg, MYF(MY_WME)); + ma_free(options->ssl_capath); + options->ssl_capath = ma_strdup(opt_arg, MYF(MY_WME)); break; case OPT_ssl_cipher: break; @@ -833,12 +833,12 @@ static void mysql_read_default_options(struct st_mysql_options *options, break; #endif /* HAVE_SSL */ case OPT_charset_dir: - my_free(options->charset_dir); - options->charset_dir = my_strdup(opt_arg, MYF(MY_WME)); + ma_free(options->charset_dir); + options->charset_dir = ma_strdup(opt_arg, MYF(MY_WME)); break; case OPT_charset_name: - my_free(options->charset_name); - options->charset_name = my_strdup(opt_arg, MYF(MY_WME)); + ma_free(options->charset_name); + options->charset_name = ma_strdup(opt_arg, MYF(MY_WME)); break; case OPT_interactive_timeout: options->client_flag|= CLIENT_INTERACTIVE; @@ -857,7 +857,7 @@ static void mysql_read_default_options(struct st_mysql_options *options, options->max_allowed_packet= atoi(opt_arg); break; case OPT_protocol: - options->protocol= find_type(opt_arg, &protocol_types, 0); + options->protocol= ma_find_type(opt_arg, &sql_protocol_typelib, 0); #ifndef _WIN32 if (options->protocol < 0 || options->protocol > 1) #else @@ -899,8 +899,8 @@ static void mysql_read_default_options(struct st_mysql_options *options, OPT_SET_EXTENDED_VALUE_STR(options, default_auth, opt_arg); break; case OPT_bind_address: - my_free(options->bind_address); - options->bind_address= my_strdup(opt_arg, MYF(MY_WME)); + ma_free(options->bind_address); + options->bind_address= ma_strdup(opt_arg, MYF(MY_WME)); break; default: DBUG_PRINT("warning",("unknown option: %s",option[0])); @@ -908,7 +908,7 @@ static void mysql_read_default_options(struct st_mysql_options *options, } } } - free_defaults(argv); + ma_free_defaults(argv); DBUG_VOID_RETURN; } @@ -942,7 +942,7 @@ unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, unsigned int i, field_count= sizeof(rset_field_offsets)/sizeof(size_t)/2; DBUG_ENTER("unpack_fields"); - field=result=(MYSQL_FIELD*) alloc_root(alloc,sizeof(MYSQL_FIELD)*fields); + field=result=(MYSQL_FIELD*) ma_alloc_root(alloc,sizeof(MYSQL_FIELD)*fields); if (!result) DBUG_RETURN(0); @@ -952,12 +952,12 @@ unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, { switch(row->data[i][0]) { case 0: - *(char **)(((char *)field) + rset_field_offsets[i*2])= strdup_root(alloc, ""); + *(char **)(((char *)field) + rset_field_offsets[i*2])= ma_strdup_root(alloc, ""); *(unsigned int *)(((char *)field) + rset_field_offsets[i*2+1])= 0; break; default: *(char **)(((char *)field) + rset_field_offsets[i*2])= - strdup_root(alloc, (char *)row->data[i]); + ma_strdup_root(alloc, (char *)row->data[i]); *(unsigned int *)(((char *)field) + rset_field_offsets[i*2+1])= (uint)(row->data[i+1] - row->data[i] - 1); break; @@ -985,7 +985,7 @@ unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, if (default_value && row->data[7]) { - field->def=strdup_root(alloc,(char*) row->data[7]); + field->def=ma_strdup_root(alloc,(char*) row->data[7]); } else field->def=0; @@ -1013,13 +1013,13 @@ MYSQL_DATA *mthd_my_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, if ((pkt_len= net_safe_read(mysql)) == packet_error) DBUG_RETURN(0); - if (!(result=(MYSQL_DATA*) my_malloc(sizeof(MYSQL_DATA), + if (!(result=(MYSQL_DATA*) ma_malloc(sizeof(MYSQL_DATA), MYF(MY_WME | MY_ZEROFILL)))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(0); } - init_alloc_root(&result->alloc,8192,0); /* Assume rowlength < 8192 */ + ma_init_ma_alloc_root(&result->alloc,8192,0); /* Assume rowlength < 8192 */ result->alloc.min_malloc=sizeof(MYSQL_ROWS); prev_ptr= &result->data; result->rows=0; @@ -1028,10 +1028,10 @@ MYSQL_DATA *mthd_my_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, while (*(cp=net->read_pos) != 254 || pkt_len >= 8) { result->rows++; - if (!(cur= (MYSQL_ROWS*) alloc_root(&result->alloc, + if (!(cur= (MYSQL_ROWS*) ma_alloc_root(&result->alloc, sizeof(MYSQL_ROWS))) || !(cur->data= ((MYSQL_ROW) - alloc_root(&result->alloc, + ma_alloc_root(&result->alloc, (fields+1)*sizeof(char *)+fields+pkt_len)))) { free_rows(result); @@ -1151,7 +1151,7 @@ mysql_init(MYSQL *mysql) return NULL; if (!mysql) { - if (!(mysql=(MYSQL*) my_malloc(sizeof(*mysql),MYF(MY_WME | MY_ZEROFILL)))) + if (!(mysql=(MYSQL*) ma_malloc(sizeof(*mysql),MYF(MY_WME | MY_ZEROFILL)))) return 0; mysql->free_me=1; mysql->net.pvio= 0; @@ -1159,7 +1159,7 @@ mysql_init(MYSQL *mysql) else bzero((char*) (mysql),sizeof(*(mysql))); mysql->options.connect_timeout=CONNECT_TIMEOUT; - mysql->charset= default_charset_info; + mysql->charset= ma_default_charset_info; mysql->methods= &MARIADB_DEFAULT_METHODS; strmov(mysql->net.sqlstate, "00000"); mysql->net.last_error[0]= mysql->net.last_errno= 0; @@ -1308,7 +1308,7 @@ mysql_real_connect(MYSQL *mysql, const char *host, const char *user, if (!(plugin= (MARIADB_CONNECTION_PLUGIN *)mysql_client_find_plugin(mysql, plugin_name, MARIADB_CLIENT_CONNECTION_PLUGIN))) return NULL; - if (!(mysql->net.conn_hdlr= (MA_CONNECTION_HANDLER *)my_malloc(sizeof(MA_CONNECTION_HANDLER), MYF(MY_ZEROFILL)))) + if (!(mysql->net.conn_hdlr= (MA_CONNECTION_HANDLER *)ma_malloc(sizeof(MA_CONNECTION_HANDLER), MYF(MY_ZEROFILL)))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); return NULL; @@ -1324,7 +1324,7 @@ mysql_real_connect(MYSQL *mysql, const char *host, const char *user, MYSQL *my= plugin->connect(mysql, end, user, passwd, db, port, unix_socket, client_flag); if (!my) { - my_free(mysql->net.conn_hdlr); + ma_free(mysql->net.conn_hdlr); mysql->net.conn_hdlr= NULL; } return my; @@ -1374,8 +1374,8 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, (mysql->options.my_cnf_file ? mysql->options.my_cnf_file : "my"), mysql->options.my_cnf_group); - my_free(mysql->options.my_cnf_file); - my_free(mysql->options.my_cnf_group); + ma_free(mysql->options.my_cnf_file); + ma_free(mysql->options.my_cnf_group); mysql->options.my_cnf_file=mysql->options.my_cnf_group=0; } @@ -1529,8 +1529,8 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, (uint) strlen(cinfo.unix_socket)+1 : (uint) 1, &mysql->server_version, (uint) (end - (char*) net->read_pos), NullS) || - !(mysql->user=my_strdup(user,MYF(0))) || - !(mysql->passwd=my_strdup(passwd,MYF(0)))) + !(mysql->user=ma_strdup(user,MYF(0))) || + !(mysql->passwd=ma_strdup(passwd,MYF(0)))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto error; @@ -1546,7 +1546,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, if (strncmp(end, MA_RPL_VERSION_HACK, sizeof(MA_RPL_VERSION_HACK) - 1) == 0) { - if (!(mysql->server_version= my_strdup(end + sizeof(MA_RPL_VERSION_HACK) - 1, 0))) + if (!(mysql->server_version= ma_strdup(end + sizeof(MA_RPL_VERSION_HACK) - 1, 0))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto error; @@ -1555,7 +1555,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, } else { - if (!(mysql->server_version= my_strdup(end, MYF(0)))) + if (!(mysql->server_version= ma_strdup(end, MYF(0)))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto error; @@ -1631,7 +1631,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, else if (mysql->server_language) mysql->charset= mysql_find_charset_nr(mysql->server_language); else - mysql->charset=default_charset_info; + mysql->charset=ma_default_charset_info; if (!mysql->charset) { @@ -1865,10 +1865,10 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, else if (mysql->server_language) mysql->charset=mysql_find_charset_nr(mysql->server_language); else - mysql->charset=default_charset_info; + mysql->charset=ma_default_charset_info; - mysql->user= my_strdup(user ? user : "", MYF(MY_WME)); - mysql->passwd= my_strdup(passwd ? passwd : "", MYF(MY_WME)); + mysql->user= ma_strdup(user ? user : "", MYF(MY_WME)); + mysql->passwd= ma_strdup(passwd ? passwd : "", MYF(MY_WME)); /* db will be set in run_plugin_auth */ mysql->db= 0; @@ -1879,20 +1879,20 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, if (rc==0) { - my_free(s_user); - my_free(s_passwd); - my_free(s_db); + ma_free(s_user); + ma_free(s_passwd); + ma_free(s_db); - if (db && !(mysql->db= my_strdup(db,MYF(MY_WME)))) + if (db && !(mysql->db= ma_strdup(db,MYF(MY_WME)))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); rc= 1; } } else { - my_free(mysql->user); - my_free(mysql->passwd); - my_free(mysql->db); + ma_free(mysql->user); + ma_free(mysql->passwd); + ma_free(mysql->db); mysql->user= s_user; mysql->passwd= s_passwd; @@ -1916,8 +1916,8 @@ mysql_select_db(MYSQL *mysql, const char *db) if ((error=simple_command(mysql, COM_INIT_DB,db,(uint) strlen(db),0,0))) DBUG_RETURN(error); - my_free(mysql->db); - mysql->db=my_strdup(db,MYF(MY_WME)); + ma_free(mysql->db); + mysql->db=ma_strdup(db,MYF(MY_WME)); DBUG_RETURN(0); } @@ -1935,39 +1935,39 @@ static void mysql_close_options(MYSQL *mysql) char **end= begin + mysql->options.init_command->elements; for (;begin < end; begin++) - my_free(*begin); - delete_dynamic(mysql->options.init_command); - my_free(mysql->options.init_command); + ma_free(*begin); + ma_delete_dynamic(mysql->options.init_command); + ma_free(mysql->options.init_command); } - my_free(mysql->options.user); - my_free(mysql->options.host); - my_free(mysql->options.password); - my_free(mysql->options.unix_socket); - my_free(mysql->options.db); - my_free(mysql->options.my_cnf_file); - my_free(mysql->options.my_cnf_group); - my_free(mysql->options.charset_dir); - my_free(mysql->options.charset_name); - my_free(mysql->options.bind_address); - my_free(mysql->options.ssl_key); - my_free(mysql->options.ssl_cert); - my_free(mysql->options.ssl_ca); - my_free(mysql->options.ssl_capath); - my_free(mysql->options.ssl_cipher); + ma_free(mysql->options.user); + ma_free(mysql->options.host); + ma_free(mysql->options.password); + ma_free(mysql->options.unix_socket); + ma_free(mysql->options.db); + ma_free(mysql->options.my_cnf_file); + ma_free(mysql->options.my_cnf_group); + ma_free(mysql->options.charset_dir); + ma_free(mysql->options.charset_name); + ma_free(mysql->options.bind_address); + ma_free(mysql->options.ssl_key); + ma_free(mysql->options.ssl_cert); + ma_free(mysql->options.ssl_ca); + ma_free(mysql->options.ssl_capath); + ma_free(mysql->options.ssl_cipher); if (mysql->options.extension) { struct mysql_async_context *ctxt; - my_free(mysql->options.extension->plugin_dir); - my_free(mysql->options.extension->default_auth); - my_free(mysql->options.extension->db_driver); - my_free(mysql->options.extension->ssl_crl); - my_free(mysql->options.extension->ssl_crlpath); - my_free(mysql->options.extension->ssl_fp); - my_free(mysql->options.extension->ssl_fp_list); - my_free(mysql->options.extension->ssl_pw); - my_free(mysql->options.extension->url); - my_free(mysql->options.extension->connection_handler); + ma_free(mysql->options.extension->plugin_dir); + ma_free(mysql->options.extension->default_auth); + ma_free(mysql->options.extension->db_driver); + ma_free(mysql->options.extension->ssl_crl); + ma_free(mysql->options.extension->ssl_crlpath); + ma_free(mysql->options.extension->ssl_fp); + ma_free(mysql->options.extension->ssl_fp_list); + ma_free(mysql->options.extension->ssl_pw); + ma_free(mysql->options.extension->url); + ma_free(mysql->options.extension->connection_handler); if(hash_inited(&mysql->options.extension->connect_attrs)) hash_free(&mysql->options.extension->connect_attrs); if (hash_inited(&mysql->options.extension->userdata)) @@ -1975,22 +1975,22 @@ static void mysql_close_options(MYSQL *mysql) if ((ctxt = mysql->options.extension->async_context) != 0) { my_context_destroy(&ctxt->async_context); - my_free(ctxt); + ma_free(ctxt); } } - my_free(mysql->options.extension); + ma_free(mysql->options.extension); /* clear all pointer */ memset(&mysql->options, 0, sizeof(mysql->options)); } static void mysql_close_memory(MYSQL *mysql) { - my_free(mysql->host_info); - my_free(mysql->user); - my_free(mysql->passwd); - my_free(mysql->db); - my_free(mysql->server_version); + ma_free(mysql->host_info); + ma_free(mysql->user); + ma_free(mysql->passwd); + ma_free(mysql->db); + ma_free(mysql->server_version); mysql->host_info= mysql->server_version=mysql->user=mysql->passwd=mysql->db=0; } @@ -2007,7 +2007,7 @@ void my_set_error(MYSQL *mysql, mysql->net.last_errno= error_nr; strncpy(mysql->net.sqlstate, sqlstate, SQLSTATE_LENGTH); va_start(ap, format); - my_vsnprintf(mysql->net.last_error, MYSQL_ERRMSG_SIZE, + ma_vsnprintf(mysql->net.last_error, MYSQL_ERRMSG_SIZE, format ? format : ER(error_nr), ap); DBUG_PRINT("info", ("error(%d) %s", error_nr, mysql->net.last_error)); va_end(ap); @@ -2037,7 +2037,7 @@ mysql_close(MYSQL *mysql) { MA_CONNECTION_HANDLER *p= mysql->net.conn_hdlr; p->plugin->close(mysql); - my_free(p); + ma_free(p); } if (mysql->methods) @@ -2054,11 +2054,11 @@ mysql_close(MYSQL *mysql) bzero((char*) &mysql->options,sizeof(mysql->options)); if (mysql->extension) - my_free(mysql->extension); + ma_free(mysql->extension); mysql->net.pvio= 0; if (mysql->free_me) - my_free(mysql); + ma_free(mysql); } DBUG_VOID_RETURN; } @@ -2186,7 +2186,7 @@ mysql_store_result(MYSQL *mysql) DBUG_RETURN(0); } mysql->status=MYSQL_STATUS_READY; /* server is ready */ - if (!(result=(MYSQL_RES*) my_malloc(sizeof(MYSQL_RES)+ + if (!(result=(MYSQL_RES*) ma_malloc(sizeof(MYSQL_RES)+ sizeof(ulong)*mysql->field_count, MYF(MY_WME | MY_ZEROFILL)))) { @@ -2197,7 +2197,7 @@ mysql_store_result(MYSQL *mysql) result->lengths=(ulong*) (result+1); if (!(result->data=mysql->methods->db_read_rows(mysql,mysql->fields,mysql->field_count))) { - my_free(result); + ma_free(result); DBUG_RETURN(0); } mysql->affected_rows= result->row_count= result->data->rows; @@ -2235,15 +2235,15 @@ mysql_use_result(MYSQL *mysql) SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(0); } - if (!(result=(MYSQL_RES*) my_malloc(sizeof(*result)+ + if (!(result=(MYSQL_RES*) ma_malloc(sizeof(*result)+ sizeof(ulong)*mysql->field_count, MYF(MY_WME | MY_ZEROFILL)))) DBUG_RETURN(0); result->lengths=(ulong*) (result+1); if (!(result->row=(MYSQL_ROW) - my_malloc(sizeof(result->row[0])*(mysql->field_count+1), MYF(MY_WME)))) + ma_malloc(sizeof(result->row[0])*(mysql->field_count+1), MYF(MY_WME)))) { /* Ptrs: to one row */ - my_free(result); + ma_free(result); DBUG_RETURN(0); } result->fields= mysql->fields; @@ -2441,7 +2441,7 @@ mysql_list_fields(MYSQL *mysql, const char *table, const char *wild) DBUG_RETURN(NULL); free_old_query(mysql); - if (!(result = (MYSQL_RES *) my_malloc(sizeof(MYSQL_RES), + if (!(result = (MYSQL_RES *) ma_malloc(sizeof(MYSQL_RES), MYF(MY_WME | MY_ZEROFILL)))) { free_rows(query); @@ -2627,7 +2627,7 @@ uchar *ma_get_hash_keyval(const uchar *hash_entry, void ma_hash_free(void *p) { - my_free(p); + ma_free(p); } int mariadb_flush_multi_command(MYSQL *mysql) @@ -2685,20 +2685,20 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) options_add_initcommand(&mysql->options, (char *)arg1); break; case MYSQL_READ_DEFAULT_FILE: - my_free(mysql->options.my_cnf_file); - mysql->options.my_cnf_file=my_strdup((char *)arg1,MYF(MY_WME)); + ma_free(mysql->options.my_cnf_file); + mysql->options.my_cnf_file=ma_strdup((char *)arg1,MYF(MY_WME)); break; case MYSQL_READ_DEFAULT_GROUP: - my_free(mysql->options.my_cnf_group); - mysql->options.my_cnf_group=my_strdup((char *)arg1,MYF(MY_WME)); + ma_free(mysql->options.my_cnf_group); + mysql->options.my_cnf_group=ma_strdup((char *)arg1,MYF(MY_WME)); break; case MYSQL_SET_CHARSET_DIR: /* not supported in this version. Since all character sets are internally available, we don't throw an error */ break; case MYSQL_SET_CHARSET_NAME: - my_free(mysql->options.charset_name); - mysql->options.charset_name=my_strdup((char *)arg1,MYF(MY_WME)); + ma_free(mysql->options.charset_name); + mysql->options.charset_name=ma_strdup((char *)arg1,MYF(MY_WME)); break; case MYSQL_OPT_RECONNECT: mysql->options.reconnect= *(uint *)arg1; @@ -2718,7 +2718,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) case MYSQL_PROGRESS_CALLBACK: if (!mysql->options.extension) mysql->options.extension= (struct st_mysql_options_extension *) - my_malloc(sizeof(struct st_mysql_options_extension), + ma_malloc(sizeof(struct st_mysql_options_extension), MYF(MY_WME | MY_ZEROFILL)); if (mysql->options.extension) mysql->options.extension->report_progress= @@ -2739,11 +2739,11 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) break; if (!mysql->options.extension) mysql->options.extension= (struct st_mysql_options_extension *) - my_malloc(sizeof(struct st_mysql_options_extension), + ma_malloc(sizeof(struct st_mysql_options_extension), MYF(MY_WME | MY_ZEROFILL)); if (!mysql->options.extension->db_driver) mysql->options.extension->db_driver= (MARIADB_DB_DRIVER *) - my_malloc(sizeof(MARIADB_DB_DRIVER), MYF(MY_WME | MY_ZEROFILL)); + ma_malloc(sizeof(MARIADB_DB_DRIVER), MYF(MY_WME | MY_ZEROFILL)); if (mysql->options.extension && mysql->options.extension->db_driver) { @@ -2766,10 +2766,10 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) if (ctxt->suspended) goto end; my_context_destroy(&ctxt->async_context); - my_free(ctxt); + ma_free(ctxt); } if (!(ctxt= (struct mysql_async_context *) - my_malloc(sizeof(*ctxt), MYF(MY_ZEROFILL)))) + ma_malloc(sizeof(*ctxt), MYF(MY_ZEROFILL)))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto end; @@ -2781,12 +2781,12 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) stacksize= ASYNC_CONTEXT_DEFAULT_STACK_SIZE; if (my_context_init(&ctxt->async_context, stacksize)) { - my_free(ctxt); + ma_free(ctxt); goto end; } if (!mysql->options.extension) if(!(mysql->options.extension= (struct st_mysql_options_extension *) - my_malloc(sizeof(struct st_mysql_options_extension), + ma_malloc(sizeof(struct st_mysql_options_extension), MYF(MY_WME | MY_ZEROFILL)))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); @@ -2812,24 +2812,24 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) mysql->options.client_flag &= ~CLIENT_SSL_VERIFY_SERVER_CERT; break; case MYSQL_OPT_SSL_KEY: - my_free(mysql->options.ssl_key); - mysql->options.ssl_key=my_strdup((char *)arg1,MYF(MY_WME | MY_ALLOW_ZERO_PTR)); + ma_free(mysql->options.ssl_key); + mysql->options.ssl_key=ma_strdup((char *)arg1,MYF(MY_WME | MY_ALLOW_ZERO_PTR)); break; case MYSQL_OPT_SSL_CERT: - my_free(mysql->options.ssl_cert); - mysql->options.ssl_cert=my_strdup((char *)arg1,MYF(MY_WME | MY_ALLOW_ZERO_PTR)); + ma_free(mysql->options.ssl_cert); + mysql->options.ssl_cert=ma_strdup((char *)arg1,MYF(MY_WME | MY_ALLOW_ZERO_PTR)); break; case MYSQL_OPT_SSL_CA: - my_free(mysql->options.ssl_ca); - mysql->options.ssl_ca=my_strdup((char *)arg1,MYF(MY_WME | MY_ALLOW_ZERO_PTR)); + ma_free(mysql->options.ssl_ca); + mysql->options.ssl_ca=ma_strdup((char *)arg1,MYF(MY_WME | MY_ALLOW_ZERO_PTR)); break; case MYSQL_OPT_SSL_CAPATH: - my_free(mysql->options.ssl_capath); - mysql->options.ssl_capath=my_strdup((char *)arg1,MYF(MY_WME | MY_ALLOW_ZERO_PTR)); + ma_free(mysql->options.ssl_capath); + mysql->options.ssl_capath=ma_strdup((char *)arg1,MYF(MY_WME | MY_ALLOW_ZERO_PTR)); break; case MYSQL_OPT_SSL_CIPHER: - my_free(mysql->options.ssl_cipher); - mysql->options.ssl_cipher=my_strdup((char *)arg1,MYF(MY_WME | MY_ALLOW_ZERO_PTR)); + ma_free(mysql->options.ssl_cipher); + mysql->options.ssl_cipher=ma_strdup((char *)arg1,MYF(MY_WME | MY_ALLOW_ZERO_PTR)); break; case MYSQL_OPT_SSL_CRL: OPT_SET_EXTENDED_VALUE_STR(&mysql->options, ssl_crl, (char *)arg1); @@ -2898,7 +2898,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) break; } - if (!(buffer= (uchar *)my_malloc(strlen(key) + 1 + sizeof(void *), MYF(MY_ZEROFILL)))) + if (!(buffer= (uchar *)ma_malloc(strlen(key) + 1 + sizeof(void *), MYF(MY_ZEROFILL)))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto end; @@ -2911,7 +2911,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) if (hash_insert(&mysql->options.extension->userdata, buffer)) { - my_free(buffer); + ma_free(buffer); SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); goto end; } @@ -2949,7 +2949,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) goto end; } } - if ((buffer= (uchar *)my_malloc(key_len + value_len, + if ((buffer= (uchar *)ma_malloc(key_len + value_len, MYF(MY_WME | MY_ZEROFILL)))) { uchar *p= buffer; @@ -2960,7 +2960,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) if (hash_insert(&mysql->options.extension->connect_attrs, buffer)) { - my_free(buffer); + ma_free(buffer); SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); goto end; } @@ -2979,8 +2979,8 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) mysql->options.secure_auth= *(my_bool *)arg1; break; case MYSQL_OPT_BIND: - my_free(mysql->options.bind_address); - mysql->options.bind_address= my_strdup(arg1, MYF(MY_WME)); + ma_free(mysql->options.bind_address); + mysql->options.bind_address= ma_strdup(arg1, MYF(MY_WME)); break; case MARIADB_OPT_SSL_FP: OPT_SET_EXTENDED_VALUE_STR(&mysql->options, ssl_fp, (char *)arg1); @@ -3418,7 +3418,7 @@ uint STDCALL mysql_thread_safe(void) ulong STDCALL mysql_escape_string(char *to,const char *from, ulong length) { - return (ulong)mysql_cset_escape_slashes(default_charset_info, to, from, length); + return (ulong)mysql_cset_escape_slashes(ma_default_charset_info, to, from, length); } ulong STDCALL @@ -3467,7 +3467,7 @@ int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname) { char buff[64]; - my_snprintf(buff, 63, "SET NAMES %s", cs->csname); + ma_snprintf(buff, 63, "SET NAMES %s", cs->csname); if (!mysql_real_query(mysql, buff, (uint)strlen(buff))) { mysql->charset= cs; @@ -3500,7 +3500,7 @@ int STDCALL mysql_server_init(int argc __attribute__((unused)), if (!mysql_client_init) { mysql_client_init=1; - my_init(); /* Will init threads */ + ma_init(); /* Will init threads */ init_client_errs(); if (mysql_client_plugin_init()) return 1; @@ -3545,19 +3545,19 @@ void STDCALL mysql_server_end(void) mysql_client_plugin_deinit(); list_free(pvio_callback, 0); - if (my_init_done) - my_end(0); + if (ma_init_done) + ma_end(0); #ifdef HAVE_SSL ma_pvio_ssl_end(); #endif mysql_client_init= 0; - my_init_done= 0; + ma_init_done= 0; } my_bool STDCALL mysql_thread_init(void) { #ifdef THREAD - return my_thread_init(); + return ma_thread_init(); #endif return 0; } @@ -3565,7 +3565,7 @@ my_bool STDCALL mysql_thread_init(void) void STDCALL mysql_thread_end(void) { #ifdef THREAD - my_thread_end(); + ma_thread_end(); #endif } diff --git a/libmariadb/list.c b/libmariadb/list.c index 204acd33..50ad0b43 100644 --- a/libmariadb/list.c +++ b/libmariadb/list.c @@ -63,8 +63,8 @@ void list_free(LIST *root, unsigned int free_data) { next=root->next; if (free_data) - my_free(root->data); - my_free(root); + ma_free(root->data); + ma_free(root); root=next; } } @@ -72,7 +72,7 @@ void list_free(LIST *root, unsigned int free_data) LIST *list_cons(void *data, LIST *list) { - LIST *new_charset=(LIST*) my_malloc(sizeof(LIST),MYF(MY_FAE)); + LIST *new_charset=(LIST*) ma_malloc(sizeof(LIST),MYF(MY_FAE)); if (!new_charset) return 0; new_charset->data=data; diff --git a/libmariadb/llstr.c b/libmariadb/llstr.c index 3e935c69..1a90f2af 100644 --- a/libmariadb/llstr.c +++ b/libmariadb/llstr.c @@ -16,9 +16,9 @@ MA 02111-1307, USA */ /* - Defines: llstr(); + Defines: ma_llstr(); - llstr(value, buff); + ma_llstr(value, buff); This function saves a longlong value in a buffer and returns the pointer to the buffer. This is useful when trying to portable print longlong @@ -29,7 +29,7 @@ #include #include "m_string.h" -char *llstr(longlong value,char *buff) +char *ma_llstr(longlong value,char *buff) { longlong2str(value,buff,-10); return buff; diff --git a/libmariadb/ma_dyncol.c b/libmariadb/ma_dyncol.c index aa8391b6..e8b1668e 100644 --- a/libmariadb/ma_dyncol.c +++ b/libmariadb/ma_dyncol.c @@ -1139,7 +1139,7 @@ static enum enum_dyncol_func_result dynamic_column_dyncol_read(DYNAMIC_COLUMN_VALUE *store_it_here, uchar *data, size_t length) { - store_it_here->x.string.charset= my_charset_bin; + store_it_here->x.string.charset= ma_charset_bin; store_it_here->x.string.value.length= length; store_it_here->x.string.value.str= (char*) data; return ER_DYNCOL_OK; @@ -2440,7 +2440,7 @@ dynamic_column_list(DYNAMIC_COLUMN *str, DYNAMIC_ARRAY *array_of_uint) str->length) return ER_DYNCOL_FORMAT; - if (my_init_dynamic_array(array_of_uint, sizeof(uint), header.column_count, 0)) + if (ma_init_dynamic_array(array_of_uint, sizeof(uint), header.column_count, 0)) return ER_DYNCOL_RESOURCE; for (i= 0, read= header.header; @@ -2449,7 +2449,7 @@ dynamic_column_list(DYNAMIC_COLUMN *str, DYNAMIC_ARRAY *array_of_uint) { uint nm= uint2korr(read); /* Insert can't never fail as it's pre-allocated above */ - (void) insert_dynamic(array_of_uint, (uchar *)&nm); + (void) ma_insert_dynamic(array_of_uint, (uchar *)&nm); } return ER_DYNCOL_OK; } @@ -2484,7 +2484,7 @@ mariadb_dyncol_list_num(DYNAMIC_COLUMN *str, uint *count, uint **nums) str->length) return ER_DYNCOL_FORMAT; - if (!((*nums)= (uint *)my_malloc(sizeof(uint) * header.column_count, MYF(0)))) + if (!((*nums)= (uint *)ma_malloc(sizeof(uint) * header.column_count, MYF(0)))) return ER_DYNCOL_RESOURCE; for (i= 0, read= header.header; @@ -2532,10 +2532,10 @@ mariadb_dyncol_list_named(DYNAMIC_COLUMN *str, uint *count, LEX_STRING **names) return ER_DYNCOL_FORMAT; if (header.format == dyncol_fmt_num) - *names= (LEX_STRING *)my_malloc(sizeof(LEX_STRING) * header.column_count + + *names= (LEX_STRING *)ma_malloc(sizeof(LEX_STRING) * header.column_count + DYNCOL_NUM_CHAR * header.column_count, MYF(0)); else - *names= (LEX_STRING *)my_malloc(sizeof(LEX_STRING) * header.column_count + + *names= (LEX_STRING *)ma_malloc(sizeof(LEX_STRING) * header.column_count + header.nmpool_size + header.column_count, MYF(0)); if (!(*names)) return ER_DYNCOL_RESOURCE; @@ -3349,7 +3349,7 @@ dynamic_column_update_many_fmt(DYNAMIC_COLUMN *str, if (IN_PLACE_PLAN > add_column_count) plan= in_place_plan; else if (!(alloc_plan= plan= - (PLAN *)my_malloc(sizeof(PLAN) * (add_column_count + 1), MYF(0)))) + (PLAN *)ma_malloc(sizeof(PLAN) * (add_column_count + 1), MYF(0)))) return ER_DYNCOL_RESOURCE; not_null= add_column_count; @@ -3606,13 +3606,13 @@ dynamic_column_update_many_fmt(DYNAMIC_COLUMN *str, &header, &new_header, convert); end: - my_free(alloc_plan); + ma_free(alloc_plan); return rc; create_new_string: /* There is no columns from before, so let's just add the new ones */ rc= ER_DYNCOL_OK; - my_free(alloc_plan); + ma_free(alloc_plan); if (not_null != 0) rc= dynamic_column_create_many_internal_fmt(str, add_column_count, (uint*)column_keys, values, @@ -3884,9 +3884,9 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, if (!conv) { #ifndef LIBMARIADB - uint dummy_errors; + uint dumma_errors; #else - int dummy_errors; + int dumma_errors; #endif if (!quote) { @@ -3897,24 +3897,24 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, cs, from, (uint32)len, val->x.string.charset, - &dummy_errors); + &dumma_errors); #else mariadb_convert_string(from, &len, val->x.string.charset, - str->str, (size_t *)&bufflen, cs, &dummy_errors); + str->str, (size_t *)&bufflen, cs, &dumma_errors); #endif return ER_DYNCOL_OK; } - if ((alloc= (char *)my_malloc(bufflen, MYF(0)))) + if ((alloc= (char *)ma_malloc(bufflen, MYF(0)))) { len= #ifndef LIBMARIADB copy_and_convert_extended(alloc, bufflen, cs, from, (uint32)len, val->x.string.charset, - &dummy_errors); + &dumma_errors); #else mariadb_convert_string(from, &len, val->x.string.charset, - alloc, (size_t *)&bufflen, cs, &dummy_errors); + alloc, (size_t *)&bufflen, cs, &dumma_errors); #endif from= alloc; } @@ -3927,7 +3927,7 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, if (quote) rc= dynstr_append_mem(str, "e, 1); if (alloc) - my_free(alloc); + ma_free(alloc); if (rc) return ER_DYNCOL_RESOURCE; break; @@ -4195,7 +4195,7 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json, if (dynstr_realloc(json, DYNCOL_NUM_CHAR + 3)) goto err; json->str[json->length++]= '"'; - json->length+= (my_snprintf(json->str + json->length, + json->length+= (ma_snprintf(json->str + json->length, DYNCOL_NUM_CHAR, "%u", nm)); } else @@ -4231,7 +4231,7 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json, else { if ((rc= mariadb_dyncol_val_str(json, &val, - my_charset_utf8_general_ci, '"')) < 0) + ma_charset_utf8_general_ci, '"')) < 0) goto err; } } @@ -4291,16 +4291,16 @@ mariadb_dyncol_unpack(DYNAMIC_COLUMN *str, str->length) return ER_DYNCOL_FORMAT; - *vals= (DYNAMIC_COLUMN_VALUE *)my_malloc(sizeof(DYNAMIC_COLUMN_VALUE)* header.column_count, MYF(0)); + *vals= (DYNAMIC_COLUMN_VALUE *)ma_malloc(sizeof(DYNAMIC_COLUMN_VALUE)* header.column_count, MYF(0)); if (header.format == dyncol_fmt_num) { - *names= (LEX_STRING *)my_malloc(sizeof(LEX_STRING) * header.column_count + + *names= (LEX_STRING *)ma_malloc(sizeof(LEX_STRING) * header.column_count + DYNCOL_NUM_CHAR * header.column_count, MYF(0)); nm= (char *)(names + sizeof(LEX_STRING) * header.column_count); } else { - *names= (LEX_STRING *)my_malloc(sizeof(LEX_STRING) * header.column_count, MYF(0)); + *names= (LEX_STRING *)ma_malloc(sizeof(LEX_STRING) * header.column_count, MYF(0)); nm= 0; } if (!(*vals) || !(*names)) @@ -4352,12 +4352,12 @@ mariadb_dyncol_unpack(DYNAMIC_COLUMN *str, err: if (*vals) { - my_free(*vals); + ma_free(*vals); *vals= 0; } if (*names) { - my_free(*names); + ma_free(*names); *names= 0; } return rc; diff --git a/libmariadb/ma_io.c b/libmariadb/ma_io.c index c66d00a0..c2fca04a 100644 --- a/libmariadb/ma_io.c +++ b/libmariadb/ma_io.c @@ -74,7 +74,7 @@ MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql) len= MultiByteToWideChar(CodePage, 0, location, (int)strlen(location), NULL, 0); if (!len) return NULL; - if (!(w_filename= (wchar_t *)my_malloc((len + 1) * sizeof(wchar_t), MYF(MY_ZEROFILL)))) + if (!(w_filename= (wchar_t *)ma_malloc((len + 1) * sizeof(wchar_t), MYF(MY_ZEROFILL)))) { my_set_error(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); return NULL; @@ -84,14 +84,14 @@ MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql) if (!len) { /* todo: error handling */ - my_free(w_filename); + ma_free(w_filename); return NULL; } len= (int)strlen(mode); - if (!(w_mode= (wchar_t *)my_malloc((len + 1) * sizeof(wchar_t), MYF(MY_ZEROFILL)))) + if (!(w_mode= (wchar_t *)ma_malloc((len + 1) * sizeof(wchar_t), MYF(MY_ZEROFILL)))) { my_set_error(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - my_free(w_filename); + ma_free(w_filename); return NULL; } Length= len; @@ -99,20 +99,20 @@ MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql) if (!len) { /* todo: error handling */ - my_free(w_filename); - my_free(w_mode); + ma_free(w_filename); + ma_free(w_mode); return NULL; } fp= _wfopen(w_filename, w_mode); my_errno= GetLastError(); - my_free(w_filename); - my_free(w_mode); + ma_free(w_filename); + ma_free(w_mode); } #endif if (fp) { - ma_file= (MA_FILE *)my_malloc(sizeof(MA_FILE), MYF(0)); + ma_file= (MA_FILE *)ma_malloc(sizeof(MA_FILE), MYF(0)); if (!ma_file) { my_set_error(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); @@ -147,7 +147,7 @@ int ma_close(MA_FILE *file) switch (file->type) { case MA_FILE_LOCAL: rc= fclose((FILE *)file->ptr); - my_free(file); + ma_free(file); break; #ifdef HAVE_REMOTEIO case MA_FILE_REMOTE: diff --git a/libmariadb/ma_pvio.c b/libmariadb/ma_pvio.c index 7d012c66..255d5eca 100644 --- a/libmariadb/ma_pvio.c +++ b/libmariadb/ma_pvio.c @@ -104,7 +104,7 @@ MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo) } - if (!(pvio= (MARIADB_PVIO *)my_malloc(sizeof(MARIADB_PVIO), + if (!(pvio= (MARIADB_PVIO *)ma_malloc(sizeof(MARIADB_PVIO), MYF(MY_WME | MY_ZEROFILL)))) { PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); @@ -124,7 +124,7 @@ MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo) pvio->methods->set_timeout(pvio, PVIO_WRITE_TIMEOUT, cinfo->mysql->options.write_timeout); } - if (!(pvio->cache= my_malloc(PVIO_READ_AHEAD_CACHE_SIZE, MYF(MY_ZEROFILL)))) + if (!(pvio->cache= ma_malloc(PVIO_READ_AHEAD_CACHE_SIZE, MYF(MY_ZEROFILL)))) { PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); return NULL; @@ -386,19 +386,19 @@ void ma_pvio_close(MARIADB_PVIO *pvio) if (pvio && pvio->cssl) { ma_pvio_ssl_close(pvio->cssl); - my_free((gptr)pvio->cssl); + ma_free((gptr)pvio->cssl); } #endif if (pvio && pvio->methods->close) pvio->methods->close(pvio); if (pvio->cache) - my_free((gptr)pvio->cache); + ma_free((gptr)pvio->cache); if (pvio->fp) my_fclose(pvio->fp, MYF(0)); - my_free((gptr)pvio); + ma_free((gptr)pvio); } /* }}} */ @@ -511,7 +511,7 @@ my_bool ma_pvio_start_ssl(MARIADB_PVIO *pvio) } if (ma_pvio_ssl_connect(pvio->cssl)) { - my_free(pvio->cssl); + ma_free(pvio->cssl); pvio->cssl= NULL; return 1; } diff --git a/libmariadb/ma_ssl.c b/libmariadb/ma_ssl.c index 529979ea..65651934 100644 --- a/libmariadb/ma_ssl.c +++ b/libmariadb/ma_ssl.c @@ -60,7 +60,7 @@ MARIADB_SSL *ma_pvio_ssl_init(MYSQL *mysql) if (!ma_ssl_initialized) ma_ssl_start(mysql->net.last_error, MYSQL_ERRMSG_SIZE); - if (!(cssl= (MARIADB_SSL *)my_malloc(sizeof(MARIADB_SSL), + if (!(cssl= (MARIADB_SSL *)ma_malloc(sizeof(MARIADB_SSL), MYF(MY_WME | MY_ZEROFILL)))) { return NULL; @@ -70,7 +70,7 @@ MARIADB_SSL *ma_pvio_ssl_init(MYSQL *mysql) cssl->pvio= mysql->net.pvio; if (!(cssl->ssl= ma_ssl_init(mysql))) { - my_free(cssl); + ma_free(cssl); cssl= NULL; } return cssl; diff --git a/libmariadb/mf_format.c b/libmariadb/mf_format.c index 7dac46cf..f356facf 100644 --- a/libmariadb/mf_format.c +++ b/libmariadb/mf_format.c @@ -62,9 +62,9 @@ my_string fn_format(my_string to, const char *name, const char *dsk, convert_dirname(dev); /* Fix to this OS */ } if (flag & 8) - pack_dirname(dev,dev); /* Put in ./.. and ~/.. */ + ma_pack_dirname(dev,dev); /* Put in ./.. and ~/.. */ if (flag & 4) - (void) unpack_dirname(dev,dev); /* Replace ~/.. with dir */ + (void) unma_pack_dirname(dev,dev); /* Replace ~/.. with dir */ if ((pos=(char*)strchr(name,FN_EXTCHAR)) != NullS) { if ((flag & 2) == 0) /* Skall vi byta extension ? */ diff --git a/libmariadb/mf_pack.c b/libmariadb/mf_pack.c index 68be4aa2..eb5484bc 100644 --- a/libmariadb/mf_pack.c +++ b/libmariadb/mf_pack.c @@ -32,15 +32,15 @@ static my_string NEAR_F expand_tilde(my_string *path); /* from is a dirname (from dirname() ?) ending with FN_LIBCHAR */ /* to may be == from */ -void pack_dirname(my_string to, const char *from) +void ma_pack_dirname(my_string to, const char *from) { int cwd_err; uint d_length,length,buff_length= 0; my_string start; char buff[FN_REFLEN]; - DBUG_ENTER("pack_dirname"); + DBUG_ENTER("ma_pack_dirname"); - (void) intern_filename(to,from); /* Change to intern name */ + (void) ma_intern_filename(to,from); /* Change to intern name */ #ifdef FN_DEVCHAR if ((start=strrchr(to,FN_DEVCHAR)) != 0) /* Skipp device part */ @@ -62,18 +62,18 @@ void pack_dirname(my_string to, const char *from) } } - if ((d_length= cleanup_dirname(to,to)) != 0) + if ((d_length= ma_cleanup_dirname(to,to)) != 0) { length=0; - if (home_dir) + if (ma_ma_ma_home_dir) { - length= (uint) strlen(home_dir); - if (home_dir[length-1] == FN_LIBCHAR) + length= (uint) strlen(ma_ma_ma_home_dir); + if (ma_ma_ma_home_dir[length-1] == FN_LIBCHAR) length--; /* Don't test last '/' */ } if (length > 1 && length < d_length) { /* test if /xx/yy -> ~/yy */ - if (bcmp(to,home_dir,length) == 0 && to[length] == FN_LIBCHAR) + if (bcmp(to,ma_ma_ma_home_dir,length) == 0 && to[length] == FN_LIBCHAR) { to[0]=FN_HOMELIB; /* Filename begins with ~ */ (void) strmov_overlapp(to+1,to+length); @@ -83,7 +83,7 @@ void pack_dirname(my_string to, const char *from) { /* Test if cwd is ~/... */ if (length > 1 && length < buff_length) { - if (bcmp(buff,home_dir,length) == 0 && buff[length] == FN_LIBCHAR) + if (bcmp(buff,ma_ma_ma_home_dir,length) == 0 && buff[length] == FN_LIBCHAR) { buff[0]=FN_HOMELIB; (void) strmov_overlapp(buff+1,buff+length); @@ -105,17 +105,17 @@ void pack_dirname(my_string to, const char *from) } DBUG_PRINT("exit",("to: '%s'",to)); DBUG_VOID_RETURN; -} /* pack_dirname */ +} /* ma_pack_dirname */ /* remove unwanted chars from dirname */ /* if "/../" removes prev dir; "/~/" removes all before ~ */ /* "//" is same as "/", except on Win32 at start of a file */ /* "/./" is removed */ - /* Unpacks home_dir if "~/.." used */ + /* Unpacks ma_ma_ma_home_dir if "~/.." used */ /* Unpacks current dir if if "./.." used */ -uint cleanup_dirname(register my_string to, const char *from) +uint ma_cleanup_dirname(register my_string to, const char *from) /* to may be == from */ { @@ -125,7 +125,7 @@ uint cleanup_dirname(register my_string to, const char *from) reg4 my_string start; char parent[5], /* for "FN_PARENTDIR" */ buff[FN_REFLEN+1],*end_parentdir; - DBUG_ENTER("cleanup_dirname"); + DBUG_ENTER("ma_cleanup_dirname"); DBUG_PRINT("enter",("from: '%s'",from)); start=buff; @@ -154,23 +154,23 @@ uint cleanup_dirname(register my_string to, const char *from) pos--; if (*pos == FN_HOMELIB && (pos == start || pos[-1] == FN_LIBCHAR)) { - if (!home_dir) + if (!ma_ma_ma_home_dir) { pos+=length+1; /* Don't unpack ~/.. */ continue; } - pos=strmov(buff,home_dir)-1; /* Unpacks ~/.. */ + pos=strmov(buff,ma_ma_ma_home_dir)-1; /* Unpacks ~/.. */ if (*pos == FN_LIBCHAR) pos--; /* home ended with '/' */ } if (*pos == FN_CURLIB && (pos == start || pos[-1] == FN_LIBCHAR)) { - if (my_getwd(curr_dir,FN_REFLEN,MYF(0))) + if (my_getwd(ma_cur_dir,FN_REFLEN,MYF(0))) { pos+=length+1; /* Don't unpack ./.. */ continue; } - pos=strmov(buff,curr_dir)-1; /* Unpacks ./.. */ + pos=strmov(buff,ma_cur_dir)-1; /* Unpacks ./.. */ if (*pos == FN_LIBCHAR) pos--; /* home ended with '/' */ } @@ -208,7 +208,7 @@ uint cleanup_dirname(register my_string to, const char *from) (void) strmov(to,buff); DBUG_PRINT("exit",("to: '%s'",to)); DBUG_RETURN((uint) (pos-buff)); -} /* cleanup_dirname */ +} /* ma_cleanup_dirname */ /* @@ -220,7 +220,7 @@ uint cleanup_dirname(register my_string to, const char *from) */ -my_bool my_use_symdir=0; /* Set this if you want to use symdirs */ +my_bool ma_use_symdir=0; /* Set this if you want to use symdirs */ #ifdef USE_SYMDIR void symdirget(char *dir) @@ -257,18 +257,18 @@ void symdirget(char *dir) /* Unpacks dirname to name that can be used by open... */ /* Make that last char of to is '/' if from not empty and from doesn't end in FN_DEVCHAR */ - /* Uses cleanup_dirname and changes ~/.. to home_dir/.. */ + /* Uses ma_cleanup_dirname and changes ~/.. to ma_ma_ma_home_dir/.. */ /* Returns length of new directory */ -uint unpack_dirname(my_string to, const char *from) +uint unma_pack_dirname(my_string to, const char *from) /* to may be == from */ { uint length,h_length; char buff[FN_REFLEN+1+4],*suffix,*tilde_expansion; - DBUG_ENTER("unpack_dirname"); + DBUG_ENTER("unma_pack_dirname"); - (void) intern_filename(buff,from); /* Change to intern name */ + (void) ma_intern_filename(buff,from); /* Change to intern name */ length= (uint) strlen(buff); /* Fix that '/' is last */ if (length && #ifdef FN_DEVCHAR @@ -280,7 +280,7 @@ uint unpack_dirname(my_string to, const char *from) buff[length+1]= '\0'; } - length=cleanup_dirname(buff,buff); + length=ma_cleanup_dirname(buff,buff); if (buff[0] == FN_HOMELIB) { suffix=buff+1; tilde_expansion=expand_tilde(&suffix); @@ -300,11 +300,11 @@ uint unpack_dirname(my_string to, const char *from) } } #ifdef USE_SYMDIR - if (my_use_symdir) + if (ma_use_symdir) symdirget(buff); #endif - DBUG_RETURN(system_filename(to,buff)); /* Fix for open */ -} /* unpack_dirname */ + DBUG_RETURN(ma_system_filename(to,buff)); /* Fix for open */ +} /* unma_pack_dirname */ /* Expand tilde to home or user-directory */ @@ -313,7 +313,7 @@ uint unpack_dirname(my_string to, const char *from) static my_string NEAR_F expand_tilde(my_string *path) { if (path[0][0] == FN_LIBCHAR) - return home_dir; /* ~/ expanded to home */ + return ma_ma_ma_home_dir; /* ~/ expanded to home */ #ifdef HAVE_GETPWNAM { char *str,save; @@ -339,30 +339,30 @@ static my_string NEAR_F expand_tilde(my_string *path) /* to may be == from */ /* Returns to */ -my_string unpack_filename(my_string to, const char *from) +my_string ma_unpack_filename(my_string to, const char *from) { uint length,n_length; char buff[FN_REFLEN]; - DBUG_ENTER("unpack_filename"); + DBUG_ENTER("ma_unpack_filename"); length=dirname_part(buff,from); /* copy & convert dirname */ - n_length=unpack_dirname(buff,buff); + n_length=unma_pack_dirname(buff,buff); if (n_length+strlen(from+length) < FN_REFLEN) { (void) strmov(buff+n_length,from+length); - (void) system_filename(to,buff); /* Fix to usably filename */ + (void) ma_system_filename(to,buff); /* Fix to usably filename */ } else - (void) system_filename(to,from); /* Fix to usably filename */ + (void) ma_system_filename(to,from); /* Fix to usably filename */ DBUG_RETURN(to); -} /* unpack_filename */ +} /* ma_unpack_filename */ /* Convert filename (unix standard) to system standard */ /* Used before system command's like open(), create() .. */ /* Returns to */ -uint system_filename(my_string to, const char *from) +uint ma_system_filename(my_string to, const char *from) { #ifndef FN_C_BEFORE_DIR return (uint) (strmake(to,from,FN_REFLEN-1)-to); @@ -378,7 +378,7 @@ uint system_filename(my_string to, const char *from) int libchar_found,length; my_string to_pos,from_pos,pos; char buff[FN_REFLEN]; - DBUG_ENTER("system_filename"); + DBUG_ENTER("ma_system_filename"); libchar_found=0; (void) strmov(buff,from); /* If to == from */ @@ -426,12 +426,12 @@ uint system_filename(my_string to, const char *from) DBUG_PRINT("exit",("name: '%s'",to)); DBUG_RETURN((uint) length); #endif -} /* system_filename */ +} /* ma_system_filename */ /* Fix a filename to intern (UNIX format) */ -my_string intern_filename(my_string to, const char *from) +my_string ma_intern_filename(my_string to, const char *from) { #ifndef VMS { @@ -529,4 +529,4 @@ my_string intern_filename(my_string to, const char *from) (void) strmov(to_pos,from_pos); return (to); #endif /* VMS */ -} /* intern_filename */ +} /* ma_intern_filename */ diff --git a/libmariadb/mf_path.c b/libmariadb/mf_path.c index c53157de..a4ea1473 100644 --- a/libmariadb/mf_path.c +++ b/libmariadb/mf_path.c @@ -42,11 +42,11 @@ my_string my_path(my_string to, const char *progname, find_file_in_path(to,progname) || ((prog=getenv("_")) != 0 && dirname_part(to,prog)))) { - VOID(intern_filename(to,to)); + VOID(ma_intern_filename(to,to)); if (!test_if_hard_path(to)) { - if (!my_getwd(curr_dir,FN_REFLEN,MYF(0))) - bchange(to,0,curr_dir, (uint) strlen(curr_dir), (uint) strlen(to)+1); + if (!my_getwd(ma_cur_dir,FN_REFLEN,MYF(0))) + bchange(to,0,ma_cur_dir, (uint) strlen(ma_cur_dir), (uint) strlen(to)+1); } } else @@ -60,7 +60,7 @@ my_string my_path(my_string to, const char *progname, end= (char*) "/my/"; #endif } - VOID(intern_filename(to,end)); + VOID(ma_intern_filename(to,end)); to=strend(to); if (to != start && to[-1] != FN_LIBCHAR) *to++ = FN_LIBCHAR; diff --git a/libmariadb/mulalloc.c b/libmariadb/mulalloc.c index 8a7ee312..01d9ab88 100644 --- a/libmariadb/mulalloc.c +++ b/libmariadb/mulalloc.c @@ -37,7 +37,7 @@ gptr my_multi_malloc(myf myFlags, ...) } va_end(args); - if (!(start=(char *) my_malloc(tot_length,myFlags))) + if (!(start=(char *) ma_malloc(tot_length,myFlags))) DBUG_RETURN(0); /* purecov: inspected */ va_start(args,myFlags); diff --git a/libmariadb/my_alloc.c b/libmariadb/my_alloc.c index 1434b912..b0486afe 100644 --- a/libmariadb/my_alloc.c +++ b/libmariadb/my_alloc.c @@ -21,7 +21,7 @@ #include #include -void init_alloc_root(MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size) +void ma_init_ma_alloc_root(MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size) { mem_root->free=mem_root->used=0; mem_root->min_malloc=32; @@ -31,7 +31,7 @@ void init_alloc_root(MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_siz if (pre_alloc_size) { if ((mem_root->free = mem_root->pre_alloc= - (USED_MEM*) my_malloc(pre_alloc_size+ ALIGN_SIZE(sizeof(USED_MEM)), + (USED_MEM*) ma_malloc(pre_alloc_size+ ALIGN_SIZE(sizeof(USED_MEM)), MYF(0)))) { mem_root->free->size=pre_alloc_size+ALIGN_SIZE(sizeof(USED_MEM)); @@ -42,13 +42,13 @@ void init_alloc_root(MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_siz #endif } -gptr alloc_root(MEM_ROOT *mem_root, size_t Size) +gptr ma_alloc_root(MEM_ROOT *mem_root, size_t Size) { #if defined(HAVE_purify) && defined(EXTRA_DEBUG) reg1 USED_MEM *next; Size+=ALIGN_SIZE(sizeof(USED_MEM)); - if (!(next = (USED_MEM*) my_malloc(Size,MYF(MY_WME)))) + if (!(next = (USED_MEM*) ma_malloc(Size,MYF(MY_WME)))) { if (mem_root->error_handler) (*mem_root->error_handler)(); @@ -78,7 +78,7 @@ gptr alloc_root(MEM_ROOT *mem_root, size_t Size) if (max_left*4 < mem_root->block_size && get_size < mem_root->block_size) get_size=mem_root->block_size; /* Normal alloc */ - if (!(next = (USED_MEM*) my_malloc(get_size,MYF(MY_WME | MY_ZEROFILL)))) + if (!(next = (USED_MEM*) ma_malloc(get_size,MYF(MY_WME | MY_ZEROFILL)))) { if (mem_root->error_handler) (*mem_root->error_handler)(); @@ -100,12 +100,12 @@ gptr alloc_root(MEM_ROOT *mem_root, size_t Size) #endif } - /* deallocate everything used by alloc_root */ + /* deallocate everything used by ma_alloc_root */ -void free_root(MEM_ROOT *root, myf MyFlags) +void ma_free_root(MEM_ROOT *root, myf MyFlags) { reg1 USED_MEM *next,*old; - DBUG_ENTER("free_root"); + DBUG_ENTER("ma_free_root"); if (!root) DBUG_VOID_RETURN; /* purecov: inspected */ @@ -116,13 +116,13 @@ void free_root(MEM_ROOT *root, myf MyFlags) { old=next; next= next->next ; if (old != root->pre_alloc) - my_free(old); + ma_free(old); } for (next= root->free ; next ; ) { old=next; next= next->next ; if (old != root->pre_alloc) - my_free(old); + ma_free(old); } root->used=root->free=0; if (root->pre_alloc) @@ -135,21 +135,21 @@ void free_root(MEM_ROOT *root, myf MyFlags) } -char *strdup_root(MEM_ROOT *root,const char *str) +char *ma_strdup_root(MEM_ROOT *root,const char *str) { size_t len= strlen(str)+1; char *pos; - if ((pos=alloc_root(root,len))) + if ((pos=ma_alloc_root(root,len))) memcpy(pos,str,len); pos[len]= 0; return pos; } -char *memdup_root(MEM_ROOT *root, const char *str, size_t len) +char *ma_memdup_root(MEM_ROOT *root, const char *str, size_t len) { char *pos; - if ((pos=alloc_root(root,len))) + if ((pos=ma_alloc_root(root,len))) memcpy(pos,str,len); return pos; } diff --git a/libmariadb/my_charset.c b/libmariadb/my_charset.c index b38ddf21..325af139 100644 --- a/libmariadb/my_charset.c +++ b/libmariadb/my_charset.c @@ -55,7 +55,7 @@ #include -extern int my_snprintf(char* to, size_t n, const char* fmt, ...); +extern int ma_snprintf(char* to, size_t n, const char* fmt, ...); /* +----------------------------------------------------------------------+ | PHP Version 5 | @@ -1086,7 +1086,7 @@ char *madb_get_os_character_set() char *p= NULL; #ifdef _WIN32 char codepage[FN_REFLEN]; - my_snprintf(codepage, FN_REFLEN, "%u", GetConsoleWindow() ? + ma_snprintf(codepage, FN_REFLEN, "%u", GetConsoleWindow() ? GetConsoleCP() : GetACP()); p= codepage; #elif defined(HAVE_NL_LANGINFO) && defined(HAVE_SETLOCALE) diff --git a/libmariadb/my_compress.c b/libmariadb/my_compress.c index c9498842..27bdaa52 100644 --- a/libmariadb/my_compress.c +++ b/libmariadb/my_compress.c @@ -39,7 +39,7 @@ my_bool my_compress(unsigned char *packet, size_t *len, size_t *complen) if (!compbuf) return *complen ? 0 : 1; memcpy(packet,compbuf,*len); - my_free(compbuf); + ma_free(compbuf); } return 0; } @@ -49,18 +49,18 @@ unsigned char *my_compress_alloc(const unsigned char *packet, size_t *len, size_ { unsigned char *compbuf; *complen = *len * 120 / 100 + 12; - if (!(compbuf = (unsigned char *) my_malloc(*complen,MYF(MY_WME)))) + if (!(compbuf = (unsigned char *) ma_malloc(*complen,MYF(MY_WME)))) return 0; /* Not enough memory */ if (compress((Bytef*) compbuf,(ulong *) complen, (Bytef*) packet, (uLong) *len ) != Z_OK) { - my_free(compbuf); + ma_free(compbuf); return 0; } if (*complen >= *len) { *complen=0; - my_free(compbuf); + ma_free(compbuf); return 0; } swap(size_t,*len,*complen); /* *len is now packet length */ @@ -71,17 +71,17 @@ my_bool my_uncompress (unsigned char *packet, size_t *len, size_t *complen) { if (*complen) /* If compressed */ { - unsigned char *compbuf = (unsigned char *) my_malloc (*complen,MYF(MY_WME)); + unsigned char *compbuf = (unsigned char *) ma_malloc (*complen,MYF(MY_WME)); if (!compbuf) return 1; /* Not enough memory */ if (uncompress((Bytef*) compbuf, (uLongf *)complen, (Bytef*) packet, (uLongf)*len) != Z_OK) { /* Probably wrong packet */ - my_free (compbuf); + ma_free (compbuf); return 1; } *len = *complen; memcpy(packet,compbuf,*len); - my_free(compbuf); + ma_free(compbuf); } else *complen= *len; return 0; diff --git a/libmariadb/my_div.c b/libmariadb/my_div.c index 24794679..537c2d45 100644 --- a/libmariadb/my_div.c +++ b/libmariadb/my_div.c @@ -22,9 +22,9 @@ my_string my_filename(File fd) DBUG_ENTER("my_filename"); if (fd >= MY_NFILE) DBUG_RETURN((char*) "UNKNOWN"); - if (fd >= 0 && my_file_info[fd].type != UNOPEN) + if (fd >= 0 && ma_file_info[fd].type != UNOPEN) { - DBUG_RETURN(my_file_info[fd].name); + DBUG_RETURN(ma_file_info[fd].name); } else DBUG_RETURN((char*) "UNOPENED"); /* Debug message */ diff --git a/libmariadb/my_error.c b/libmariadb/my_error.c index 9778206a..e5b2c2da 100644 --- a/libmariadb/my_error.c +++ b/libmariadb/my_error.c @@ -29,7 +29,7 @@ char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE]; /* Error message to user */ /*VARARGS2*/ -int my_error(int nr,myf MyFlags, ...) +int ma_error(int nr,myf MyFlags, ...) { va_list ap; uint olen, plen; @@ -37,13 +37,13 @@ int my_error(int nr,myf MyFlags, ...) reg2 char *endpos; char * par; char ebuff[ERRMSGSIZE+20]; - DBUG_ENTER("my_error"); + DBUG_ENTER("ma_error"); va_start(ap,MyFlags); DBUG_PRINT("my", ("nr: %d MyFlags: %d errno: %d", nr, MyFlags, errno)); if (nr / ERRMOD == GLOB && my_errmsg[GLOB] == 0) - init_glob_errs(); + ma_init_glob_errs(); olen=(uint) strlen(tpos=my_errmsg[nr / ERRMOD][nr % ERRMOD - EE_FIRSTERROR]); endpos=ebuff; @@ -100,12 +100,12 @@ int my_error(int nr,myf MyFlags, ...) } *endpos='\0'; /* End of errmessage */ va_end(ap); - DBUG_RETURN((*error_handler_hook)(nr, ebuff, MyFlags)); + DBUG_RETURN((*ma_error_handler_hook)(nr, ebuff, MyFlags)); } /* Error as printf */ -int my_printf_error (uint error, const char *format, myf MyFlags, ...) +int ma_printf_error (uint error, const char *format, myf MyFlags, ...) { va_list args; char ebuff[ERRMSGSIZE+20]; @@ -113,12 +113,12 @@ int my_printf_error (uint error, const char *format, myf MyFlags, ...) va_start(args,MyFlags); (void) vsprintf (ebuff,format,args); va_end(args); - return (*error_handler_hook)(error, ebuff, MyFlags); + return (*ma_error_handler_hook)(error, ebuff, MyFlags); } - /* Give message using error_handler_hook */ + /* Give message using ma_error_handler_hook */ -int my_message(uint error, const char *str, register myf MyFlags) +int ma_message(uint error, const char *str, register myf MyFlags) { - return (*error_handler_hook)(error, str, MyFlags); + return (*ma_error_handler_hook)(error, str, MyFlags); } diff --git a/libmariadb/my_fopen.c b/libmariadb/my_fopen.c index 5c0fb40d..4727f8fa 100644 --- a/libmariadb/my_fopen.c +++ b/libmariadb/my_fopen.c @@ -49,15 +49,15 @@ FILE *my_fopen(const char *FileName, int Flags, myf MyFlags) */ if ((uint) fileno(fd) >= MY_NFILE) { - thread_safe_increment(my_stream_opened,&THR_LOCK_open); + thread_safe_increment(ma_stream_opened,&THR_LOCK_open); DBUG_RETURN(fd); /* safeguard */ } pthread_mutex_lock(&THR_LOCK_open); - if ((my_file_info[fileno(fd)].name = (char*) - my_strdup(FileName,MyFlags))) + if ((ma_file_info[fileno(fd)].name = (char*) + ma_strdup(FileName,MyFlags))) { - my_stream_opened++; - my_file_info[fileno(fd)].type = STREAM_BY_FOPEN; + ma_stream_opened++; + ma_file_info[fileno(fd)].type = STREAM_BY_FOPEN; pthread_mutex_unlock(&THR_LOCK_open); DBUG_PRINT("exit",("stream: %lx",fd)); DBUG_RETURN(fd); @@ -70,7 +70,7 @@ FILE *my_fopen(const char *FileName, int Flags, myf MyFlags) my_errno=errno; DBUG_PRINT("error",("Got error %d on open",my_errno)); if (MyFlags & (MY_FFNF | MY_FAE | MY_WME)) - my_error((Flags & O_RDONLY) || (Flags == O_RDONLY ) ? EE_FILENOTFOUND : + ma_error((Flags & O_RDONLY) || (Flags == O_RDONLY ) ? EE_FILENOTFOUND : EE_CANTCREATEFILE, MYF(ME_BELL+ME_WAITTANG), FileName,my_errno); DBUG_RETURN((FILE*) 0); @@ -91,15 +91,15 @@ int my_fclose(FILE *fd, myf MyFlags) { my_errno=errno; if (MyFlags & (MY_FAE | MY_WME)) - my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG), + ma_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG), my_filename(file),errno); } else - my_stream_opened--; - if ((uint) file < MY_NFILE && my_file_info[file].type != UNOPEN) + ma_stream_opened--; + if ((uint) file < MY_NFILE && ma_file_info[file].type != UNOPEN) { - my_file_info[file].type = UNOPEN; - my_free(my_file_info[file].name); + ma_file_info[file].type = UNOPEN; + ma_free(ma_file_info[file].name); } pthread_mutex_unlock(&THR_LOCK_open); DBUG_RETURN(err); @@ -122,23 +122,23 @@ FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags) { my_errno=errno; if (MyFlags & (MY_FAE | MY_WME)) - my_error(EE_CANT_OPEN_STREAM, MYF(ME_BELL+ME_WAITTANG),errno); + ma_error(EE_CANT_OPEN_STREAM, MYF(ME_BELL+ME_WAITTANG),errno); } else { pthread_mutex_lock(&THR_LOCK_open); - my_stream_opened++; + ma_stream_opened++; if (Filedes < MY_NFILE) { - if (my_file_info[Filedes].type != UNOPEN) + if (ma_file_info[Filedes].type != UNOPEN) { - my_file_opened--; /* File is opened with my_open ! */ + ma_file_opened--; /* File is opened with my_open ! */ } else { - my_file_info[Filedes].name= my_strdup(name,MyFlags); + ma_file_info[Filedes].name= ma_strdup(name,MyFlags); } - my_file_info[Filedes].type = STREAM_BY_FDOPEN; + ma_file_info[Filedes].type = STREAM_BY_FDOPEN; } pthread_mutex_unlock(&THR_LOCK_open); } diff --git a/libmariadb/my_fstream.c b/libmariadb/my_fstream.c index 39a15b10..0d297924 100644 --- a/libmariadb/my_fstream.c +++ b/libmariadb/my_fstream.c @@ -50,11 +50,11 @@ uint my_fread(FILE *stream, unsigned char *Buffer, uint Count, myf MyFlags) if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) { if (ferror(stream)) - my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG), + ma_error(EE_READ, MYF(ME_BELL+ME_WAITTANG), my_filename(fileno(stream)),errno); else if (MyFlags & (MY_NABP | MY_FNABP)) - my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), + ma_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), my_filename(fileno(stream)),errno); } my_errno=errno ? errno : -1; @@ -118,7 +118,7 @@ uint my_fwrite(FILE *stream, const unsigned char *Buffer, uint Count, myf MyFlag if (errno == ENOSPC && (MyFlags & MY_WAIT_IF_FULL)) { if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE)) - my_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH)); + ma_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH)); sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC); VOID(my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0))); continue; @@ -128,7 +128,7 @@ uint my_fwrite(FILE *stream, const unsigned char *Buffer, uint Count, myf MyFlag { if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) { - my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG), + ma_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG), my_filename(fileno(stream)),errno); } writenbytes=(uint) -1; /* Return that we got error */ diff --git a/libmariadb/my_getwd.c b/libmariadb/my_getwd.c index 6e32b9c1..1cefdec2 100644 --- a/libmariadb/my_getwd.c +++ b/libmariadb/my_getwd.c @@ -15,7 +15,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ -/* my_setwd() and my_getwd() works with intern_filenames !! */ +/* my_setwd() and my_getwd() works with ma_intern_filenames !! */ #include "mysys_priv.h" #include @@ -40,7 +40,7 @@ /* Gets current working directory in buff. Directory is allways ended with FN_LIBCHAR */ /* One must pass a buffer to my_getwd. One can allways use - curr_dir[] */ + ma_cur_dir[] */ int my_getwd(my_string buf, uint size, myf MyFlags) { @@ -49,8 +49,8 @@ int my_getwd(my_string buf, uint size, myf MyFlags) DBUG_PRINT("my",("buf: %lx size: %d MyFlags %d", buf,size,MyFlags)); #if ! defined(MSDOS) - if (curr_dir[0]) /* Current pos is saved here */ - VOID(strmake(buf,&curr_dir[0],size-1)); + if (ma_cur_dir[0]) /* Current pos is saved here */ + VOID(strmake(buf,&ma_cur_dir[0],size-1)); else #endif { @@ -62,7 +62,7 @@ int my_getwd(my_string buf, uint size, myf MyFlags) #endif { my_errno=errno; - my_error(EE_GETWD,MYF(ME_BELL+ME_WAITTANG),errno); + ma_error(EE_GETWD,MYF(ME_BELL+ME_WAITTANG),errno); return(-1); } #elif defined(HAVE_GETWD) @@ -75,10 +75,10 @@ int my_getwd(my_string buf, uint size, myf MyFlags) if (!getcwd(buf,size-2,1) && MyFlags & MY_WME) { my_errno=errno; - my_error(EE_GETWD,MYF(ME_BELL+ME_WAITTANG),errno); + ma_error(EE_GETWD,MYF(ME_BELL+ME_WAITTANG),errno); return(-1); } - intern_filename(buf,buf); + ma_intern_filename(buf,buf); #else #error "No way to get current directory" #endif @@ -87,7 +87,7 @@ int my_getwd(my_string buf, uint size, myf MyFlags) pos[0]= FN_LIBCHAR; pos[1]=0; } - (void) strmake(&curr_dir[0],buf,(size_s) (FN_REFLEN-1)); + (void) strmake(&ma_cur_dir[0],buf,(size_s) (FN_REFLEN-1)); } DBUG_RETURN(0); } /* my_getwd */ @@ -129,7 +129,7 @@ int my_setwd(const char *dir, myf MyFlags) { *pos='\0'; /* Dir is now only drive */ my_errno=errno; - my_error(EE_SETWD,MYF(ME_BELL+ME_WAITTANG),dir,ENOENT); + ma_error(EE_SETWD,MYF(ME_BELL+ME_WAITTANG),dir,ENOENT); DBUG_RETURN(-1); } dir=pos; /* drive changed, change now path */ @@ -151,7 +151,7 @@ int my_setwd(const char *dir, myf MyFlags) pos[0]=FN_LIBCHAR; /* Mark as directory */ pos[1]=0; } - system_filename(buff,buff); /* Change to VMS format */ + ma_system_filename(buff,buff); /* Change to VMS format */ dir=buff; } #endif /* VMS */ @@ -163,22 +163,22 @@ int my_setwd(const char *dir, myf MyFlags) { my_errno=errno; if (MyFlags & MY_WME) - my_error(EE_SETWD,MYF(ME_BELL+ME_WAITTANG),start,errno); + ma_error(EE_SETWD,MYF(ME_BELL+ME_WAITTANG),start,errno); } else { if (test_if_hard_path(start)) { /* Hard pathname */ - pos=strmake(&curr_dir[0],start,(size_s) FN_REFLEN-1); + pos=strmake(&ma_cur_dir[0],start,(size_s) FN_REFLEN-1); if (pos[-1] != FN_LIBCHAR) { - length=(uint) (pos-(char*) curr_dir); - curr_dir[length]=FN_LIBCHAR; /* must end with '/' */ - curr_dir[length+1]='\0'; + length=(uint) (pos-(char*) ma_cur_dir); + ma_cur_dir[length]=FN_LIBCHAR; /* must end with '/' */ + ma_cur_dir[length+1]='\0'; } } else - curr_dir[0]='\0'; /* Don't save name */ + ma_cur_dir[0]='\0'; /* Don't save name */ } DBUG_RETURN(res); } /* my_setwd */ @@ -191,7 +191,7 @@ int my_setwd(const char *dir, myf MyFlags) int test_if_hard_path(register const char *dir_name) { if (dir_name[0] == FN_HOMELIB && dir_name[1] == FN_LIBCHAR) - return (home_dir != NullS && test_if_hard_path(home_dir)); + return (ma_ma_ma_home_dir != NullS && test_if_hard_path(ma_ma_ma_home_dir)); if (dir_name[0] == FN_LIBCHAR) return (TRUE); #ifdef FN_DEVCHAR diff --git a/libmariadb/my_init.c b/libmariadb/my_init.c index 391f5290..bb096159 100644 --- a/libmariadb/my_init.c +++ b/libmariadb/my_init.c @@ -43,7 +43,7 @@ static my_bool win32_init_tcp_ip(); #define my_win_init() #endif -my_bool my_init_done=0; +my_bool ma_init_done=0; @@ -61,17 +61,17 @@ static ulong atoi_octal(const char *str) /* Init my_sys functions and my_sys variabels */ -void my_init(void) +void ma_init(void) { my_string str; - if (my_init_done) + if (ma_init_done) return; - my_init_done=1; + ma_init_done=1; #ifdef THREAD #if defined(HAVE_PTHREAD_INIT) pthread_init(); /* Must be called before DBUG_ENTER */ #endif - my_thread_global_init(); + ma_thread_global_init(); #ifndef _WIN32 sigfillset(&my_signals); /* signals blocked by mf_brkhant */ #endif @@ -80,46 +80,46 @@ void my_init(void) (void) isatty(0); /* Go around connect() bug in UW7 */ #endif { - DBUG_ENTER("my_init"); - DBUG_PROCESS(my_progname ? my_progname : (char*) "unknown"); - if (!home_dir) + DBUG_ENTER("ma_init"); + DBUG_PROCESS(ma_progname ? ma_progname : (char*) "unknown"); + if (!ma_ma_ma_home_dir) { /* Don't initialize twice */ - if ((home_dir=getenv("HOME")) != 0) - home_dir=intern_filename(home_dir_buff,home_dir); + if ((ma_ma_ma_home_dir=getenv("HOME")) != 0) + ma_ma_ma_home_dir=ma_intern_filename(ma_ma_ma_ma_ma_ma_home_dir_buff,ma_ma_ma_home_dir); #ifndef VMS /* Default creation of new files */ if ((str=getenv("UMASK")) != 0) - my_umask=(int) (atoi_octal(str) | 0600); + ma_umask=(int) (atoi_octal(str) | 0600); /* Default creation of new dir's */ if ((str=getenv("UMASK_DIR")) != 0) - my_umask_dir=(int) (atoi_octal(str) | 0700); + ma_umask_dir=(int) (atoi_octal(str) | 0700); #endif #ifdef VMS init_ctype(); /* Stupid linker don't link _ctype.c */ #endif - DBUG_PRINT("exit",("home: '%s'",home_dir)); + DBUG_PRINT("exit",("home: '%s'",ma_ma_ma_home_dir)); } #ifdef _WIN32 my_win_init(); #endif DBUG_VOID_RETURN; } -} /* my_init */ +} /* ma_init */ /* End my_sys */ -void my_end(int infoflag) +void ma_end(int infoflag) { FILE *info_file; if (!(info_file=DBUG_FILE)) info_file=stderr; if (infoflag & MY_CHECK_ERROR || info_file != stderr) { /* Test if some file is left open */ - if (my_file_opened | my_stream_opened) + if (ma_file_opened | ma_stream_opened) { - sprintf(errbuff[0],EE(EE_OPEN_WARNING),my_file_opened,my_stream_opened); - (void) my_message_no_curses(EE_OPEN_WARNING,errbuff[0],ME_BELL); + sprintf(errbuff[0],EE(EE_OPEN_WARNING),ma_file_opened,ma_stream_opened); + (void) ma_message_no_curses(EE_OPEN_WARNING,errbuff[0],ME_BELL); DBUG_PRINT("error",("%s",errbuff[0])); } } @@ -164,16 +164,16 @@ Voluntary context switches %ld, Involuntary context switches %ld\n", pthread_mutex_destroy(&THR_LOCK_malloc); pthread_mutex_destroy(&THR_LOCK_open); pthread_mutex_destroy(&THR_LOCK_net); - DBUG_END(); /* Must be done before my_thread_end */ - my_thread_end(); - my_thread_global_end(); + DBUG_END(); /* Must be done before ma_thread_end */ + ma_thread_end(); + ma_thread_global_end(); #endif #ifdef _WIN32 if (have_tcpip); WSACleanup( ); #endif /* _WIN32 */ - my_init_done=0; -} /* my_end */ + ma_init_done=0; +} /* ma_end */ #ifdef _WIN32 diff --git a/libmariadb/my_lib.c b/libmariadb/my_lib.c index b0092c4b..0d86218c 100644 --- a/libmariadb/my_lib.c +++ b/libmariadb/my_lib.c @@ -75,7 +75,7 @@ void my_dirend(MY_DIR *buffer) { DBUG_ENTER("my_dirend"); if (buffer) - my_free(buffer); + ma_free(buffer); DBUG_VOID_RETURN; } /* my_dirend */ @@ -112,7 +112,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags) dirp = opendir(directory_file_name(tmp_path,(my_string) path)); size = STARTSIZE; - if (dirp == NULL || ! (buffer = (char *) my_malloc(size, MyFlags))) + if (dirp == NULL || ! (buffer = (char *) ma_malloc(size, MyFlags))) goto error; fcnt = 0; @@ -146,7 +146,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags) if (eof) break; size += STARTSIZE; obuffer = buffer; - if (!(buffer = (char *) my_realloc((gptr) buffer, size, + if (!(buffer = (char *) ma_realloc((gptr) buffer, size, MyFlags | MY_FREE_ON_ERROR))) goto error; /* No memory */ length= (uint) (sizeof(struct fileinfo ) * firstfcnt); @@ -184,7 +184,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags) if (dirp) (void) closedir(dirp); if (MyFlags & (MY_FAE+MY_WME)) - my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,my_errno); + ma_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,my_errno); DBUG_RETURN((MY_DIR *) NULL); } /* my_dir */ @@ -392,7 +392,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags) size = STARTSIZE; firstfcnt = maxfcnt = (size - sizeof(MY_DIR)) / (sizeof(struct fileinfo) + FN_LEN); - if ((buffer = (char *) my_malloc(size, MyFlags)) == 0) + if ((buffer = (char *) ma_malloc(size, MyFlags)) == 0) goto error; fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR)); tempptr = (char *) (fnames + maxfcnt); @@ -435,7 +435,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags) if (eof) break; size += STARTSIZE; obuffer = buffer; - if (!(buffer = (char *) my_realloc((gptr) buffer, size, + if (!(buffer = (char *) ma_realloc((gptr) buffer, size, MyFlags | MY_FREE_ON_ERROR))) goto error; length= sizeof(struct fileinfo ) * firstfcnt; @@ -469,7 +469,7 @@ error: _findclose(handle); #endif if (MyFlags & MY_FAE+MY_WME) - my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,errno); + ma_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,errno); DBUG_RETURN((MY_DIR *) NULL); } /* my_dir */ @@ -514,7 +514,7 @@ MY_DIR *my_dir(const char* path, myf MyFlags) size = STARTSIZE; firstfcnt = maxfcnt = (size - sizeof(MY_DIR)) / (sizeof(struct fileinfo) + FN_LEN); - if ((buffer = (char *) my_malloc(size, MyFlags)) == 0) + if ((buffer = (char *) ma_malloc(size, MyFlags)) == 0) goto error; fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR)); tempptr = (char *) (fnames + maxfcnt); @@ -543,7 +543,7 @@ MY_DIR *my_dir(const char* path, myf MyFlags) if (eof) break; size += STARTSIZE; obuffer = buffer; - if (!(buffer = (char *) my_realloc((gptr) buffer, size, + if (!(buffer = (char *) ma_realloc((gptr) buffer, size, MyFlags | MY_FREE_ON_ERROR))) goto error; length= sizeof(struct fileinfo ) * firstfcnt; @@ -569,7 +569,7 @@ MY_DIR *my_dir(const char* path, myf MyFlags) error: if (MyFlags & MY_FAE+MY_WME) - my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,errno); + ma_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,errno); DBUG_RETURN((MY_DIR *) NULL); } /* my_dir */ @@ -595,18 +595,18 @@ MY_STAT *my_stat(const char *path, MY_STAT *stat_area, myf my_flags) (unsigned char *) stat_area, my_flags)); if ((m_used= (stat_area == NULL))) - if (!(stat_area = (MY_STAT *) my_malloc(sizeof(MY_STAT), my_flags))) + if (!(stat_area = (MY_STAT *) ma_malloc(sizeof(MY_STAT), my_flags))) goto error; if ( ! stat((my_string) path, (struct stat *) stat_area) ) DBUG_RETURN(stat_area); my_errno=errno; if (m_used) /* Free if new area */ - my_free(stat_area); + ma_free(stat_area); error: if (my_flags & (MY_FAE+MY_WME)) { - my_error(EE_STAT, MYF(ME_BELL+ME_WAITTANG),path,my_errno); + ma_error(EE_STAT, MYF(ME_BELL+ME_WAITTANG),path,my_errno); DBUG_RETURN((MY_STAT *) NULL); } DBUG_RETURN((MY_STAT *) NULL); diff --git a/libmariadb/my_loaddata.c b/libmariadb/my_loaddata.c index e36c086a..574c995e 100644 --- a/libmariadb/my_loaddata.c +++ b/libmariadb/my_loaddata.c @@ -68,7 +68,7 @@ int mysql_local_infile_init(void **ptr, const char *filename, void *userdata) MYSQL *mysql= (MYSQL *)userdata; DBUG_ENTER("mysql_local_infile_init"); - info = (MYSQL_INFILE_INFO *)my_malloc(sizeof(MYSQL_INFILE_INFO), MYF(MY_ZEROFILL)); + info = (MYSQL_INFILE_INFO *)ma_malloc(sizeof(MYSQL_INFILE_INFO), MYF(MY_ZEROFILL)); if (!info) { DBUG_RETURN(1); } @@ -90,7 +90,7 @@ int mysql_local_infile_init(void **ptr, const char *filename, void *userdata) else { info->error_no = my_errno; - my_snprintf((char *)info->error_msg, sizeof(info->error_msg), + ma_snprintf((char *)info->error_msg, sizeof(info->error_msg), EE(EE_FILENOTFOUND), filename, info->error_no); } DBUG_RETURN(1); @@ -153,7 +153,7 @@ void mysql_local_infile_end(void *ptr) { if (info->fp) ma_close(info->fp); - my_free(ptr); + ma_free(ptr); } DBUG_VOID_RETURN; } @@ -218,7 +218,7 @@ my_bool mysql_handle_local_infile(MYSQL *conn, const char *filename) } /* allocate buffer for reading data */ - buf = (uchar *)my_malloc(buflen, MYF(0)); + buf = (uchar *)ma_malloc(buflen, MYF(0)); /* init handler: allocate read buffer and open file */ if (conn->options.local_infile_init(&info, filename, @@ -264,7 +264,7 @@ my_bool mysql_handle_local_infile(MYSQL *conn, const char *filename) infile_error: conn->options.local_infile_end(info); - my_free(buf); + ma_free(buf); DBUG_RETURN(result); } /* }}} */ diff --git a/libmariadb/my_malloc.c b/libmariadb/my_malloc.c index 665d767c..8a077333 100644 --- a/libmariadb/my_malloc.c +++ b/libmariadb/my_malloc.c @@ -25,10 +25,10 @@ /* My memory allocator */ -gptr my_malloc(size_t Size, myf MyFlags) +gptr ma_malloc(size_t Size, myf MyFlags) { gptr point; - DBUG_ENTER("my_malloc"); + DBUG_ENTER("ma_malloc"); DBUG_PRINT("my",("Size: %u MyFlags: %d",Size, MyFlags)); if (!Size) @@ -37,9 +37,9 @@ gptr my_malloc(size_t Size, myf MyFlags) { my_errno=errno; if (MyFlags & MY_FAE) - error_handler_hook=fatal_error_handler_hook; + ma_error_handler_hook=fatal_ma_error_handler_hook; if (MyFlags & (MY_FAE+MY_WME)) - my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG),Size); + ma_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG),Size); if (MyFlags & MY_FAE) exit(1); } @@ -47,34 +47,34 @@ gptr my_malloc(size_t Size, myf MyFlags) bzero(point,Size); DBUG_PRINT("exit",("ptr: %lx",point)); DBUG_RETURN(point); -} /* my_malloc */ +} /* ma_malloc */ - /* Free memory allocated with my_malloc */ + /* Free memory allocated with ma_malloc */ /*ARGSUSED*/ void my_no_flags_free(void *ptr) { - DBUG_ENTER("my_free"); + DBUG_ENTER("ma_free"); DBUG_PRINT("my",("ptr: %lx",ptr)); if (ptr) free(ptr); DBUG_VOID_RETURN; -} /* my_free */ +} /* ma_free */ /* malloc and copy */ -gptr my_memdup(const unsigned char *from, size_t length, myf MyFlags) +gptr ma_memdup(const unsigned char *from, size_t length, myf MyFlags) { gptr ptr; - if ((ptr=my_malloc(length,MyFlags)) != 0) + if ((ptr=ma_malloc(length,MyFlags)) != 0) memcpy((unsigned char*) ptr, (unsigned char*) from,(size_t) length); return(ptr); } -my_string my_strdup(const char *from, myf MyFlags) +my_string ma_strdup(const char *from, myf MyFlags) { gptr ptr; uint length; @@ -83,16 +83,16 @@ my_string my_strdup(const char *from, myf MyFlags) return NULL; length=(uint) strlen(from)+1; - if ((ptr=my_malloc(length,MyFlags)) != 0) + if ((ptr=ma_malloc(length,MyFlags)) != 0) memcpy((unsigned char*) ptr, (unsigned char*) from,(size_t) length); return((my_string) ptr); } -my_string my_strndup(const char *src, size_t length, myf MyFlags) +my_string ma_strndup(const char *src, size_t length, myf MyFlags) { gptr ptr; - if ((ptr= my_malloc(length+1, MyFlags))) { + if ((ptr= ma_malloc(length+1, MyFlags))) { memcpy(ptr, src, length); ptr[length] = 0; } diff --git a/libmariadb/my_messnc.c b/libmariadb/my_messnc.c index 0dd3be5b..b81160d4 100644 --- a/libmariadb/my_messnc.c +++ b/libmariadb/my_messnc.c @@ -17,17 +17,17 @@ #include "mysys_priv.h" -int my_message_no_curses(uint error __attribute__((unused)), +int ma_message_no_curses(uint error __attribute__((unused)), const char *str, myf MyFlags) { - DBUG_ENTER("my_message_no_curses"); + DBUG_ENTER("ma_message_no_curses"); DBUG_PRINT("enter",("message: %s",str)); (void) fflush(stdout); if (MyFlags & ME_BELL) (void) fputc('\007',stderr); /* Bell */ - if (my_progname) + if (ma_progname) { - (void)fputs(my_progname,stderr); (void)fputs(": ",stderr); + (void)fputs(ma_progname,stderr); (void)fputs(": ",stderr); } (void)fputs(str,stderr); (void)fputc('\n',stderr); diff --git a/libmariadb/my_once.c b/libmariadb/my_once.c index 15ce18e1..f074ad1f 100644 --- a/libmariadb/my_once.c +++ b/libmariadb/my_once.c @@ -36,9 +36,9 @@ gptr my_once_alloc(unsigned int Size, myf MyFlags) reg2 USED_MEM **prev; Size= ALIGN_SIZE(Size); - prev= &my_once_root_block; + prev= &ma_once_root_block; max_left=0; - for (next=my_once_root_block ; next && next->left < Size ; next= next->next) + for (next=ma_once_root_block ; next && next->left < Size ; next= next->next) { if (next->left > max_left) max_left=next->left; @@ -47,14 +47,14 @@ gptr my_once_alloc(unsigned int Size, myf MyFlags) if (! next) { /* Time to alloc new block */ get_size= Size+ALIGN_SIZE(sizeof(USED_MEM)); - if (max_left*4 < my_once_extra && get_size < my_once_extra) - get_size=my_once_extra; /* Normal alloc */ + if (max_left*4 < ma_once_extra && get_size < ma_once_extra) + get_size=ma_once_extra; /* Normal alloc */ if ((next = (USED_MEM*) malloc(get_size)) == 0) { my_errno=errno; if (MyFlags & (MY_FAE+MY_WME)) - my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG),get_size); + ma_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG),get_size); return((gptr) 0); } DBUG_PRINT("test",("my_once_malloc %u byte malloced",get_size)); @@ -77,12 +77,12 @@ void my_once_free(void) reg1 USED_MEM *next,*old; DBUG_ENTER("my_once_free"); - for (next=my_once_root_block ; next ; ) + for (next=ma_once_root_block ; next ; ) { old=next; next= next->next ; free((gptr) old); } - my_once_root_block=0; + ma_once_root_block=0; DBUG_VOID_RETURN; } /* my_once_free */ diff --git a/libmariadb/my_open.c b/libmariadb/my_open.c index 6fc8ee45..31a59d59 100644 --- a/libmariadb/my_open.c +++ b/libmariadb/my_open.c @@ -43,7 +43,7 @@ File my_open(const char *FileName, int Flags, myf MyFlags) fd = open((my_string) FileName, Flags | O_BINARY, MY_S_IREAD | MY_S_IWRITE); #elif !defined(NO_OPEN_3) - fd = open(FileName, Flags, my_umask); /* Normal unix */ + fd = open(FileName, Flags, ma_umask); /* Normal unix */ #else fd = open((my_string) FileName, Flags); #endif @@ -66,17 +66,17 @@ int my_close(File fd, myf MyFlags) DBUG_PRINT("error",("Got error %d on close",err)); my_errno=errno; if (MyFlags & (MY_FAE | MY_WME)) - my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG),my_filename(fd),errno); + ma_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG),my_filename(fd),errno); } - if ((uint) fd < MY_NFILE && my_file_info[fd].type != UNOPEN) + if ((uint) fd < MY_NFILE && ma_file_info[fd].type != UNOPEN) { - my_free(my_file_info[fd].name); + ma_free(ma_file_info[fd].name); #if defined(THREAD) && !defined(HAVE_PREAD) - pthread_mutex_destroy(&my_file_info[fd].mutex); + pthread_mutex_destroy(&ma_file_info[fd].mutex); #endif - my_file_info[fd].type = UNOPEN; + ma_file_info[fd].type = UNOPEN; } - my_file_opened--; + ma_file_opened--; pthread_mutex_unlock(&THR_LOCK_open); DBUG_RETURN(err); } /* my_close */ @@ -93,20 +93,20 @@ File my_register_filename(File fd, const char *FileName, enum file_type (void) my_close(fd,MyFlags); my_errno=EMFILE; if (MyFlags & (MY_FFNF | MY_FAE | MY_WME)) - my_error(EE_OUT_OF_FILERESOURCES, MYF(ME_BELL+ME_WAITTANG), + ma_error(EE_OUT_OF_FILERESOURCES, MYF(ME_BELL+ME_WAITTANG), FileName, my_errno); return(-1); #endif - thread_safe_increment(my_file_opened,&THR_LOCK_open); + thread_safe_increment(ma_file_opened,&THR_LOCK_open); return(fd); /* safeguard */ } pthread_mutex_lock(&THR_LOCK_open); - if ((my_file_info[fd].name = (char*) my_strdup(FileName,MyFlags))) + if ((ma_file_info[fd].name = (char*) ma_strdup(FileName,MyFlags))) { - my_file_opened++; - my_file_info[fd].type = type_of_file; + ma_file_opened++; + ma_file_info[fd].type = type_of_file; #if defined(THREAD) && !defined(HAVE_PREAD) - pthread_mutex_init(&my_file_info[fd].mutex,MY_MUTEX_INIT_FAST); + pthread_mutex_init(&ma_file_info[fd].mutex,MY_MUTEX_INIT_FAST); #endif pthread_mutex_unlock(&THR_LOCK_open); DBUG_PRINT("exit",("fd: %d",fd)); @@ -120,7 +120,7 @@ File my_register_filename(File fd, const char *FileName, enum file_type my_errno=errno; DBUG_PRINT("error",("Got error %d on open",my_errno)); if (MyFlags & (MY_FFNF | MY_FAE | MY_WME)) - my_error(error_message_number, MYF(ME_BELL+ME_WAITTANG), + ma_error(error_message_number, MYF(ME_BELL+ME_WAITTANG), FileName, my_errno); return(fd); } diff --git a/libmariadb/my_read.c b/libmariadb/my_read.c index 4e4999af..68a72584 100644 --- a/libmariadb/my_read.c +++ b/libmariadb/my_read.c @@ -48,10 +48,10 @@ uint my_read(File Filedes, unsigned char *Buffer, uint Count, myf MyFlags) if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) { if ((int) readbytes == -1) - my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG), + ma_error(EE_READ, MYF(ME_BELL+ME_WAITTANG), my_filename(Filedes),my_errno); else if (MyFlags & (MY_NABP | MY_FNABP)) - my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), + ma_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), my_filename(Filedes),my_errno); } if ((int) readbytes == -1 || (MyFlags & (MY_FNABP | MY_NABP))) diff --git a/libmariadb/my_realloc.c b/libmariadb/my_realloc.c index 49107a05..8ca285ae 100644 --- a/libmariadb/my_realloc.c +++ b/libmariadb/my_realloc.c @@ -24,24 +24,24 @@ /* My memory re allocator */ -gptr my_realloc(gptr oldpoint, size_t Size, myf MyFlags) +gptr ma_realloc(gptr oldpoint, size_t Size, myf MyFlags) { gptr point; - DBUG_ENTER("my_realloc"); + DBUG_ENTER("ma_realloc"); DBUG_PRINT("my",("ptr: %lx Size: %u MyFlags: %d",oldpoint, Size, MyFlags)); if (!oldpoint && (MyFlags & MY_ALLOW_ZERO_PTR)) - DBUG_RETURN(my_malloc(Size,MyFlags)); + DBUG_RETURN(ma_malloc(Size,MyFlags)); #ifdef USE_HALLOC if (!(point = malloc(Size))) { if (MyFlags & MY_FREE_ON_ERROR) - my_free(oldpoint); + ma_free(oldpoint); if (MyFlags & MY_HOLD_ON_ERROR) DBUG_RETURN(oldpoint); my_errno=errno; if (MyFlags & MY_FAE+MY_WME) - my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG),Size); + ma_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG),Size); } else { @@ -52,14 +52,14 @@ gptr my_realloc(gptr oldpoint, size_t Size, myf MyFlags) if ((point = (char*)realloc(oldpoint,Size)) == NULL) { if (MyFlags & MY_FREE_ON_ERROR) - my_free(oldpoint); + ma_free(oldpoint); if (MyFlags & MY_HOLD_ON_ERROR) DBUG_RETURN(oldpoint); my_errno=errno; if (MyFlags & (MY_FAE+MY_WME)) - my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG), Size); + ma_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG), Size); } #endif DBUG_PRINT("exit",("ptr: %lx",point)); DBUG_RETURN(point); -} /* my_realloc */ +} /* ma_realloc */ diff --git a/libmariadb/my_static.c b/libmariadb/my_static.c index 9a892996..d24ab174 100644 --- a/libmariadb/my_static.c +++ b/libmariadb/my_static.c @@ -26,21 +26,21 @@ #include "my_alarm.h" #endif - /* from my_init */ -my_string home_dir=0,my_progname=0; -char NEAR curr_dir[FN_REFLEN]= {0}, - NEAR home_dir_buff[FN_REFLEN]= {0}; -ulong my_stream_opened=0,my_file_opened=0, my_tmp_file_created=0; -int NEAR my_umask=0664, NEAR my_umask_dir=0777; + /* from ma_init */ +my_string ma_ma_ma_home_dir=0,ma_progname=0; +char NEAR ma_cur_dir[FN_REFLEN]= {0}, + NEAR ma_ma_ma_ma_ma_ma_home_dir_buff[FN_REFLEN]= {0}; +ulong ma_stream_opened=0,ma_file_opened=0, ma_tmp_file_created=0; +int NEAR ma_umask=0664, NEAR ma_umask_dir=0777; #ifndef THREAD int NEAR my_errno=0; #endif -struct my_file_info my_file_info[MY_NFILE]= {{0,UNOPEN}}; +struct ma_file_info ma_file_info[MY_NFILE]= {{0,UNOPEN}}; /* From mf_brkhant */ -int NEAR my_dont_interrupt=0; -volatile int _my_signals=0; -struct st_remember _my_sig_remember[MAX_SIGNALS]={{0,0}}; +int NEAR ma_dont_interrupt=0; +volatile int _ma_signals=0; +struct st_remember _ma_sig_remember[MAX_SIGNALS]={{0,0}}; #ifdef THREAD sigset_t my_signals; /* signals blocked by mf_brkhant */ #endif @@ -49,16 +49,16 @@ sigset_t my_signals; /* signals blocked by mf_brkhant */ my_bool key_cache_inited=0; /* from mf_reccache.c */ -ulong my_default_record_cache_size=RECORD_CACHE_SIZE; +ulong ma_default_record_cache_size=RECORD_CACHE_SIZE; /* from soundex.c */ /* ABCDEFGHIJKLMNOPQRSTUVWXYZ */ /* :::::::::::::::::::::::::: */ -const char *soundex_map= "01230120022455012623010202"; +const char *ma_soundex_map= "01230120022455012623010202"; - /* from my_malloc */ -USED_MEM* my_once_root_block=0; /* pointer to first block */ -uint my_once_extra=ONCE_ALLOC_INIT; /* Memory to alloc / block */ + /* from ma_malloc */ +USED_MEM* ma_once_root_block=0; /* pointer to first block */ +uint ma_once_extra=ONCE_ALLOC_INIT; /* Memory to alloc / block */ /* from my_tempnam */ #if !defined(HAVE_TEMPNAM) || defined(HPUX11) @@ -78,22 +78,22 @@ uint cNewCount = 0; /* Number of times NEW() was called */ struct remember *pRememberRoot = NULL; /* from my_alarm */ -int volatile my_have_got_alarm=0; /* declare variable to reset */ -ulong my_time_to_wait_for_lock=2; /* In seconds */ +int volatile ma_have_got_alarm=0; /* declare variable to reset */ +ulong ma_time_to_wait_for_lock=2; /* In seconds */ /* from errors.c */ #ifdef SHARED_LIBRARY -char * NEAR globerrs[GLOBERRS]; /* my_error_messages is here */ +char * NEAR ma_globerrs[GLOBERRS]; /* ma_error_messages is here */ #endif void (*my_abort_hook)(int) = (void(*)(int)) exit; -int (*error_handler_hook)(uint error,const char *str,myf MyFlags)= - my_message_no_curses; -int (*fatal_error_handler_hook)(uint error,const char *str,myf MyFlags)= - my_message_no_curses; +int (*ma_error_handler_hook)(uint error,const char *str,myf MyFlags)= + ma_message_no_curses; +int (*fatal_ma_error_handler_hook)(uint error,const char *str,myf MyFlags)= + ma_message_no_curses; /* How to disable options */ -my_bool NEAR my_disable_locking=0; -my_bool NEAR my_disable_async_io=0; -my_bool NEAR my_disable_flush_key_blocks=0; -my_bool NEAR my_disable_symlinks=0; +my_bool NEAR ma_disable_locking=0; +my_bool NEAR ma_disable_async_io=0; +my_bool NEAR ma_disable_flush_key_blocks=0; +my_bool NEAR ma_disable_symlinks=0; my_bool NEAR mysys_uses_curses=0; diff --git a/libmariadb/my_static.h b/libmariadb/my_static.h index 8a6be025..5f163df5 100644 --- a/libmariadb/my_static.h +++ b/libmariadb/my_static.h @@ -47,15 +47,15 @@ struct remember { char aData[1]; }; -extern char NEAR curr_dir[FN_REFLEN],NEAR home_dir_buff[FN_REFLEN]; +extern char NEAR ma_cur_dir[FN_REFLEN],NEAR ma_ma_ma_ma_ma_ma_home_dir_buff[FN_REFLEN]; -extern volatile int _my_signals; -extern struct st_remember _my_sig_remember[MAX_SIGNALS]; +extern volatile int _ma_signals; +extern struct st_remember _ma_sig_remember[MAX_SIGNALS]; -extern const char *soundex_map; +extern const char *ma_soundex_map; -extern USED_MEM* my_once_root_block; -extern uint my_once_extra; +extern USED_MEM* ma_once_root_block; +extern uint ma_once_extra; #if !defined(HAVE_TEMPNAM) || defined(HPUX11) extern int _my_tempnam_used; diff --git a/libmariadb/my_stmt.c b/libmariadb/my_stmt.c index 4b97469d..1a8cfc28 100644 --- a/libmariadb/my_stmt.c +++ b/libmariadb/my_stmt.c @@ -71,7 +71,7 @@ typedef struct { - MEM_ROOT fields_alloc_root; + MEM_ROOT fields_ma_alloc_root; } MADB_STMT_EXTENSION; static my_bool is_not_null= 0; @@ -178,7 +178,7 @@ int mthd_stmt_read_all_rows(MYSQL_STMT *stmt) if (packet_len > 7 || p[0] != 254) { /* allocate space for rows */ - if (!(current= (MYSQL_ROWS *)alloc_root(&result->alloc, sizeof(MYSQL_ROWS) + packet_len))) + if (!(current= (MYSQL_ROWS *)ma_alloc_root(&result->alloc, sizeof(MYSQL_ROWS) + packet_len))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); @@ -285,7 +285,7 @@ static int stmt_cursor_fetch(MYSQL_STMT *stmt, uchar **row) DBUG_RETURN(1); /* free previously allocated buffer */ - free_root(&result->alloc, MYF(MY_KEEP_PREALLOC)); + ma_free_root(&result->alloc, MYF(MY_KEEP_PREALLOC)); result->data= 0; result->rows= 0; @@ -574,7 +574,7 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req DBUG_ENTER("mysql_stmt_execute_generate_request"); /* preallocate length bytes */ - if (!(start= p= (uchar *)my_malloc(length, MYF(MY_WME | MY_ZEROFILL)))) + if (!(start= p= (uchar *)ma_malloc(length, MYF(MY_WME | MY_ZEROFILL)))) goto mem_error; int4store(p, stmt->stmt_id); @@ -597,7 +597,7 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req { size_t offset= p - start; length+= offset + null_count + 20; - if (!(start= (uchar *)my_realloc((gptr)start, length, MYF(MY_WME | MY_ZEROFILL)))) + if (!(start= (uchar *)ma_realloc((gptr)start, length, MYF(MY_WME | MY_ZEROFILL)))) goto mem_error; p= start + offset; } @@ -621,7 +621,7 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req { size_t offset= p - start; length= offset + stmt->param_count * 2 + 20; - if (!(start= (uchar *)my_realloc((gptr)start, length, MYF(MY_WME | MY_ZEROFILL)))) + if (!(start= (uchar *)ma_realloc((gptr)start, length, MYF(MY_WME | MY_ZEROFILL)))) goto mem_error; p= start + offset; } @@ -676,7 +676,7 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req { size_t offset= p - start; length= offset + data_size + 20; - if (!(start= (uchar *)my_realloc((gptr)start, length, MYF(MY_WME | MY_ZEROFILL)))) + if (!(start= (uchar *)ma_realloc((gptr)start, length, MYF(MY_WME | MY_ZEROFILL)))) goto mem_error; p= start + offset; } @@ -702,7 +702,7 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req mem_error: SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - my_free(start); + ma_free(start); *request_len= 0; DBUG_RETURN(NULL); } @@ -798,7 +798,7 @@ my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bind) stmt->param_count= param_count; if (stmt->param_count) { - if (!(stmt->params= (MYSQL_BIND *)alloc_root(&stmt->mem_root, stmt->param_count * sizeof(MYSQL_BIND)))) + if (!(stmt->params= (MYSQL_BIND *)ma_alloc_root(&stmt->mem_root, stmt->param_count * sizeof(MYSQL_BIND)))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); @@ -913,10 +913,10 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) if (stmt->field_count && !stmt->bind) { - MEM_ROOT *fields_alloc_root= - &((MADB_STMT_EXTENSION *)stmt->extension)->fields_alloc_root; -// free_root(fields_alloc_root, MYF(0)); - if (!(stmt->bind= (MYSQL_BIND *)alloc_root(fields_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) + MEM_ROOT *fields_ma_alloc_root= + &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; +// ma_free_root(fields_ma_alloc_root, MYF(0)); + if (!(stmt->bind= (MYSQL_BIND *)ma_alloc_root(fields_ma_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); @@ -981,12 +981,12 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) static my_bool net_stmt_close(MYSQL_STMT *stmt, my_bool remove) { char stmt_id[STMT_ID_LENGTH]; - MEM_ROOT *fields_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_alloc_root; + MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; /* clear memory */ - free_root(&stmt->result.alloc, MYF(0)); /* allocated in mysql_stmt_store_result */ - free_root(&stmt->mem_root,MYF(0)); - free_root(fields_alloc_root, MYF(0)); + ma_free_root(&stmt->result.alloc, MYF(0)); /* allocated in mysql_stmt_store_result */ + ma_free_root(&stmt->mem_root,MYF(0)); + ma_free_root(fields_ma_alloc_root, MYF(0)); if (stmt->mysql) { @@ -1025,8 +1025,8 @@ my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt) net_stmt_close(stmt, 1); - my_free(stmt->extension); - my_free(stmt); + ma_free(stmt->extension); + ma_free(stmt); DBUG_RETURN(0); } @@ -1162,11 +1162,11 @@ MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql) MYSQL_STMT *stmt; DBUG_ENTER("mysql_stmt_init"); - if (!(stmt= (MYSQL_STMT *)my_malloc(sizeof(MYSQL_STMT), MYF(MY_WME | MY_ZEROFILL))) || - !(stmt->extension= (MADB_STMT_EXTENSION *)my_malloc(sizeof(MADB_STMT_EXTENSION), + if (!(stmt= (MYSQL_STMT *)ma_malloc(sizeof(MYSQL_STMT), MYF(MY_WME | MY_ZEROFILL))) || + !(stmt->extension= (MADB_STMT_EXTENSION *)ma_malloc(sizeof(MADB_STMT_EXTENSION), MYF(MY_WME | MY_ZEROFILL)))) { - my_free(stmt); + ma_free(stmt); SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(NULL); } @@ -1187,9 +1187,9 @@ MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql) /* set default */ stmt->prefetch_rows= 1; - init_alloc_root(&stmt->mem_root, 2048, 0); - init_alloc_root(&stmt->result.alloc, 4096, 0); - init_alloc_root(&((MADB_STMT_EXTENSION *)stmt->extension)->fields_alloc_root, 2048, 0); + ma_init_ma_alloc_root(&stmt->mem_root, 2048, 0); + ma_init_ma_alloc_root(&stmt->result.alloc, 4096, 0); + ma_init_ma_alloc_root(&((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root, 2048, 0); DBUG_RETURN(stmt); } @@ -1243,12 +1243,12 @@ my_bool mthd_stmt_get_param_metadata(MYSQL_STMT *stmt) my_bool mthd_stmt_get_result_metadata(MYSQL_STMT *stmt) { MYSQL_DATA *result; - MEM_ROOT *fields_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_alloc_root; + MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; DBUG_ENTER("stmt_read_result_metadata"); if (!(result= stmt->mysql->methods->db_read_rows(stmt->mysql, (MYSQL_FIELD *)0, 7))) DBUG_RETURN(1); - if (!(stmt->fields= unpack_fields(result,fields_alloc_root, + if (!(stmt->fields= unpack_fields(result,fields_ma_alloc_root, stmt->field_count, 0, stmt->mysql->server_capabilities & CLIENT_LONG_FLAG))) DBUG_RETURN(1); @@ -1289,8 +1289,8 @@ int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, size_t lengt if (mysql_stmt_reset(stmt)) goto fail; - free_root(&stmt->mem_root, MYF(MY_KEEP_PREALLOC)); - free_root(&((MADB_STMT_EXTENSION *)stmt->extension)->fields_alloc_root, MYF(0)); + ma_free_root(&stmt->mem_root, MYF(MY_KEEP_PREALLOC)); + ma_free_root(&((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root, MYF(0)); stmt->param_count= 0; stmt->field_count= 0; @@ -1326,7 +1326,7 @@ int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, size_t lengt } if (stmt->param_count) { - if (!(stmt->params= (MYSQL_BIND *)alloc_root(&stmt->mem_root, stmt->param_count * sizeof(MYSQL_BIND)))) + if (!(stmt->params= (MYSQL_BIND *)ma_alloc_root(&stmt->mem_root, stmt->param_count * sizeof(MYSQL_BIND)))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto fail; @@ -1336,8 +1336,8 @@ int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, size_t lengt /* allocated bind buffer for result */ if (stmt->field_count) { - MEM_ROOT *fields_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_alloc_root; - if (!(stmt->bind= (MYSQL_BIND *)alloc_root(fields_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) + MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; + if (!(stmt->bind= (MYSQL_BIND *)ma_alloc_root(fields_ma_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto fail; @@ -1402,7 +1402,7 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) if (stmt->mysql->methods->db_stmt_read_all_rows(stmt)) { /* error during read - reset stmt->data */ - free_root(&stmt->result.alloc, 0); + ma_free_root(&stmt->result.alloc, 0); stmt->result.data= NULL; stmt->result.rows= 0; stmt->mysql->status= MYSQL_STATUS_READY; @@ -1436,14 +1436,14 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) static int madb_alloc_stmt_fields(MYSQL_STMT *stmt) { uint i; - MEM_ROOT *fields_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_alloc_root; + MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; DBUG_ENTER("madb_alloc_stmt_fields"); if (stmt->mysql->field_count) { - free_root(fields_alloc_root, MYF(0)); - if (!(stmt->fields= (MYSQL_FIELD *)alloc_root(fields_alloc_root, + ma_free_root(fields_ma_alloc_root, MYF(0)); + if (!(stmt->fields= (MYSQL_FIELD *)ma_alloc_root(fields_ma_alloc_root, sizeof(MYSQL_FIELD) * stmt->mysql->field_count))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); @@ -1454,18 +1454,18 @@ static int madb_alloc_stmt_fields(MYSQL_STMT *stmt) for (i=0; i < stmt->field_count; i++) { if (stmt->mysql->fields[i].db) - stmt->fields[i].db= strdup_root(fields_alloc_root, stmt->mysql->fields[i].db); + stmt->fields[i].db= ma_strdup_root(fields_ma_alloc_root, stmt->mysql->fields[i].db); if (stmt->mysql->fields[i].table) - stmt->fields[i].table= strdup_root(fields_alloc_root, stmt->mysql->fields[i].table); + stmt->fields[i].table= ma_strdup_root(fields_ma_alloc_root, stmt->mysql->fields[i].table); if (stmt->mysql->fields[i].org_table) - stmt->fields[i].org_table= strdup_root(fields_alloc_root, stmt->mysql->fields[i].org_table); + stmt->fields[i].org_table= ma_strdup_root(fields_ma_alloc_root, stmt->mysql->fields[i].org_table); if (stmt->mysql->fields[i].name) - stmt->fields[i].name= strdup_root(fields_alloc_root, stmt->mysql->fields[i].name); + stmt->fields[i].name= ma_strdup_root(fields_ma_alloc_root, stmt->mysql->fields[i].name); if (stmt->mysql->fields[i].org_name) - stmt->fields[i].org_name= strdup_root(fields_alloc_root, stmt->mysql->fields[i].org_name); + stmt->fields[i].org_name= ma_strdup_root(fields_ma_alloc_root, stmt->mysql->fields[i].org_name); if (stmt->mysql->fields[i].catalog) - stmt->fields[i].catalog= strdup_root(fields_alloc_root, stmt->mysql->fields[i].catalog); - stmt->fields[i].def= stmt->mysql->fields[i].def ? strdup_root(fields_alloc_root, stmt->mysql->fields[i].def) : NULL; + stmt->fields[i].catalog= ma_strdup_root(fields_ma_alloc_root, stmt->mysql->fields[i].catalog); + stmt->fields[i].def= stmt->mysql->fields[i].def ? ma_strdup_root(fields_ma_alloc_root, stmt->mysql->fields[i].def) : NULL; stmt->fields[i].type= stmt->mysql->fields[i].type; stmt->fields[i].length= stmt->mysql->fields[i].length; stmt->fields[i].flags= stmt->mysql->fields[i].flags; @@ -1473,7 +1473,7 @@ static int madb_alloc_stmt_fields(MYSQL_STMT *stmt) stmt->fields[i].charsetnr= stmt->mysql->fields[i].charsetnr; stmt->fields[i].max_length= stmt->mysql->fields[i].max_length; } - if (!(stmt->bind= (MYSQL_BIND *)alloc_root(fields_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) + if (!(stmt->bind= (MYSQL_BIND *)ma_alloc_root(fields_ma_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(1); @@ -1526,14 +1526,14 @@ int stmt_read_execute_response(MYSQL_STMT *stmt) if (!stmt->field_count || mysql->server_status & SERVER_MORE_RESULTS_EXIST) /* fix for ps_bug: test_misc */ { - MEM_ROOT *fields_alloc_root= - &((MADB_STMT_EXTENSION *)stmt->extension)->fields_alloc_root; + MEM_ROOT *fields_ma_alloc_root= + &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; uint i; - free_root(fields_alloc_root, MYF(0)); - if (!(stmt->bind= (MYSQL_BIND *)alloc_root(fields_alloc_root, + ma_free_root(fields_ma_alloc_root, MYF(0)); + if (!(stmt->bind= (MYSQL_BIND *)ma_alloc_root(fields_ma_alloc_root, sizeof(MYSQL_BIND) * mysql->field_count)) || - !(stmt->fields= (MYSQL_FIELD *)alloc_root(fields_alloc_root, + !(stmt->fields= (MYSQL_FIELD *)ma_alloc_root(fields_ma_alloc_root, sizeof(MYSQL_FIELD) * mysql->field_count))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); @@ -1544,18 +1544,18 @@ int stmt_read_execute_response(MYSQL_STMT *stmt) for (i=0; i < stmt->field_count; i++) { if (mysql->fields[i].db) - stmt->fields[i].db= strdup_root(fields_alloc_root, mysql->fields[i].db); + stmt->fields[i].db= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].db); if (mysql->fields[i].table) - stmt->fields[i].table= strdup_root(fields_alloc_root, mysql->fields[i].table); + stmt->fields[i].table= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].table); if (mysql->fields[i].org_table) - stmt->fields[i].org_table= strdup_root(fields_alloc_root, mysql->fields[i].org_table); + stmt->fields[i].org_table= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].org_table); if (mysql->fields[i].name) - stmt->fields[i].name= strdup_root(fields_alloc_root, mysql->fields[i].name); + stmt->fields[i].name= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].name); if (mysql->fields[i].org_name) - stmt->fields[i].org_name= strdup_root(fields_alloc_root, mysql->fields[i].org_name); + stmt->fields[i].org_name= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].org_name); if (mysql->fields[i].catalog) - stmt->fields[i].catalog= strdup_root(fields_alloc_root, mysql->fields[i].catalog); - stmt->fields[i].def= mysql->fields[i].def ? strdup_root(fields_alloc_root, mysql->fields[i].def) : NULL; + stmt->fields[i].catalog= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].catalog); + stmt->fields[i].def= mysql->fields[i].def ? ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].def) : NULL; } } @@ -1657,7 +1657,7 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) /* clear data, in case mysql_stmt_store_result was called */ if (stmt->result.data) { - free_root(&stmt->result.alloc, MYF(MY_KEEP_PREALLOC)); + ma_free_root(&stmt->result.alloc, MYF(MY_KEEP_PREALLOC)); stmt->result_cursor= stmt->result.data= 0; stmt->result.rows= 0; } @@ -1668,7 +1668,7 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) request_len, 1, stmt); if (request) - my_free(request); + ma_free(request); if (ret) { @@ -1710,7 +1710,7 @@ static my_bool madb_reset_stmt(MYSQL_STMT *stmt, unsigned int flags) if (flags & MADB_RESET_STORED && stmt->result_cursor) { - free_root(&stmt->result.alloc, MYF(MY_KEEP_PREALLOC)); + ma_free_root(&stmt->result.alloc, MYF(MY_KEEP_PREALLOC)); stmt->result.data= NULL; stmt->result.rows= 0; stmt->result_cursor= NULL; @@ -1833,7 +1833,7 @@ MYSQL_RES * STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt) DBUG_RETURN(NULL); /* aloocate result set structutr and copy stmt information */ - if (!(res= (MYSQL_RES *)my_malloc(sizeof(MYSQL_RES), MYF(MY_WME | MY_ZEROFILL)))) + if (!(res= (MYSQL_RES *)ma_malloc(sizeof(MYSQL_RES), MYF(MY_WME | MY_ZEROFILL)))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(NULL); @@ -1901,14 +1901,14 @@ my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number, { int ret; size_t packet_len; - uchar *cmd_buff= (uchar *)my_malloc(packet_len= STMT_ID_LENGTH + 2 + length, MYF(MY_WME | MY_ZEROFILL)); + uchar *cmd_buff= (uchar *)ma_malloc(packet_len= STMT_ID_LENGTH + 2 + length, MYF(MY_WME | MY_ZEROFILL)); int4store(cmd_buff, stmt->stmt_id); int2store(cmd_buff + STMT_ID_LENGTH, param_number); memcpy(cmd_buff + STMT_ID_LENGTH + 2, data, length); stmt->params[param_number].long_data_used= 1; ret= stmt->mysql->methods->db_command(stmt->mysql, COM_STMT_SEND_LONG_DATA, (char *)cmd_buff, packet_len, 1, stmt); - my_free(cmd_buff); + ma_free(cmd_buff); DBUG_RETURN(ret); } DBUG_RETURN(0); @@ -2049,8 +2049,8 @@ int STDCALL mariadb_stmt_execute_direct(MYSQL_STMT *stmt, /* allocated bind buffer for result */ if (stmt->field_count) { - MEM_ROOT *fields_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_alloc_root; - if (!(stmt->bind= (MYSQL_BIND *)alloc_root(fields_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) + MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; + if (!(stmt->bind= (MYSQL_BIND *)ma_alloc_root(fields_ma_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto fail; diff --git a/libmariadb/my_symlink.c b/libmariadb/my_symlink.c index 65d165fc..a4853474 100644 --- a/libmariadb/my_symlink.c +++ b/libmariadb/my_symlink.c @@ -53,7 +53,7 @@ int my_readlink(char *to, const char *filename, myf MyFlags) else { if (MyFlags & MY_WME) - my_error(EE_CANT_READLINK, MYF(0), filename, errno); + ma_error(EE_CANT_READLINK, MYF(0), filename, errno); result= -1; } } @@ -80,7 +80,7 @@ int my_symlink(const char *content, const char *linkname, myf MyFlags) result= -1; my_errno=errno; if (MyFlags & MY_WME) - my_error(EE_CANT_SYMLINK, MYF(0), linkname, content, errno); + ma_error(EE_CANT_SYMLINK, MYF(0), linkname, content, errno); } DBUG_RETURN(result); #endif /* HAVE_READLINK */ @@ -123,7 +123,7 @@ int my_realpath(char *to, const char *filename, myf MyFlags) /* Realpath didn't work; Use original name */ my_errno=errno; if (MyFlags & MY_WME) - my_error(EE_REALPATH, MYF(0), filename, my_errno); + ma_error(EE_REALPATH, MYF(0), filename, my_errno); if (to != filename) strmov(to,filename); result= -1; diff --git a/libmariadb/my_thr_init.c b/libmariadb/my_thr_init.c index 23625693..bef301dc 100644 --- a/libmariadb/my_thr_init.c +++ b/libmariadb/my_thr_init.c @@ -26,9 +26,9 @@ #ifdef THREAD #ifdef USE_TLS -pthread_key(struct st_my_thread_var*, THR_KEY_mysys); +pthread_key(struct st_ma_thread_var*, THR_KEY_mysys); #else -pthread_key(struct st_my_thread_var, THR_KEY_mysys); +pthread_key(struct st_ma_thread_var, THR_KEY_mysys); #endif /* USE_TLS */ pthread_mutex_t THR_LOCK_malloc,THR_LOCK_open, THR_LOCK_lock, THR_LOCK_net, THR_LOCK_mysys; @@ -50,7 +50,7 @@ my_bool THR_KEY_mysys_initialized= FALSE; the function my_thread_global_free must be called from somewhere before final exit of the library */ -my_bool my_thread_global_init(void) +my_bool ma_thread_global_init(void) { if (pthread_key_create(&THR_KEY_mysys,free)) { @@ -80,10 +80,10 @@ my_bool my_thread_global_init(void) #ifndef HAVE_LOCALTIME_R pthread_mutex_init(&LOCK_localtime_r,MY_MUTEX_INIT_SLOW); #endif - return my_thread_init(); + return ma_thread_init(); } -void my_thread_global_end(void) +void ma_thread_global_end(void) { #if defined(USE_TLS) (void) TlsFree(THR_KEY_mysys); @@ -108,19 +108,19 @@ static long thread_id=0; the pthread_self thread specific variable is initialized. */ -my_bool my_thread_init(void) +my_bool ma_thread_init(void) { - struct st_my_thread_var *tmp; - if (my_pthread_getspecific(struct st_my_thread_var *,THR_KEY_mysys)) + struct st_ma_thread_var *tmp; + if (my_pthread_getspecific(struct st_ma_thread_var *,THR_KEY_mysys)) { - DBUG_PRINT("info", ("my_thread_init was already called. Thread id: %lu", + DBUG_PRINT("info", ("ma_thread_init was already called. Thread id: %lu", pthread_self())); return 0; /* Safequard */ } /* We must have many calloc() here because these are freed on pthread_exit */ - if (!(tmp=(struct st_my_thread_var *) - calloc(1,sizeof(struct st_my_thread_var)))) + if (!(tmp=(struct st_ma_thread_var *) + calloc(1,sizeof(struct st_ma_thread_var)))) { return 1; } @@ -140,10 +140,10 @@ my_bool my_thread_init(void) return 0; } -void my_thread_end(void) +void ma_thread_end(void) { - struct st_my_thread_var *tmp= - my_pthread_getspecific(struct st_my_thread_var *, THR_KEY_mysys); + struct st_ma_thread_var *tmp= + my_pthread_getspecific(struct st_ma_thread_var *, THR_KEY_mysys); if (tmp && tmp->initialized) { @@ -173,15 +173,15 @@ void my_thread_end(void) pthread_setspecific(THR_KEY_mysys,0); } -struct st_my_thread_var *_my_thread_var(void) +struct st_ma_thread_var *_ma_thread_var(void) { - struct st_my_thread_var *tmp= - my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys); + struct st_ma_thread_var *tmp= + my_pthread_getspecific(struct st_ma_thread_var*,THR_KEY_mysys); #if defined(USE_TLS) if (!tmp) { - my_thread_init(); - tmp=my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys); + ma_thread_init(); + tmp=my_pthread_getspecific(struct st_ma_thread_var*,THR_KEY_mysys); } #endif return tmp; @@ -205,17 +205,17 @@ long my_thread_id() } #ifdef DBUG_OFF -const char *my_thread_name(void) +const char *ma_thread_name(void) { return "no_name"; } #else -const char *my_thread_name(void) +const char *ma_thread_name(void) { char name_buff[100]; - struct st_my_thread_var *tmp=my_thread_var; + struct st_ma_thread_var *tmp=my_thread_var; if (!tmp->name[0]) { long id=my_thread_id(); @@ -227,7 +227,7 @@ const char *my_thread_name(void) extern void **my_thread_var_dbug() { - struct st_my_thread_var *tmp; + struct st_ma_thread_var *tmp; /* Instead of enforcing DBUG_ASSERT(THR_KEY_mysys_initialized) here, which causes any DBUG_ENTER and related traces to fail when @@ -237,7 +237,7 @@ extern void **my_thread_var_dbug() */ if (! THR_KEY_mysys_initialized) return NULL; - tmp= _my_thread_var(); + tmp= _ma_thread_var(); return tmp && tmp->initialized ? (void **)&tmp->dbug : 0; } #endif /* DBUG_OFF */ diff --git a/libmariadb/my_vsnprintf.c b/libmariadb/my_vsnprintf.c index 9bc33e28..df67204c 100644 --- a/libmariadb/my_vsnprintf.c +++ b/libmariadb/my_vsnprintf.c @@ -22,18 +22,18 @@ #include -int my_snprintf(char* to, size_t n, const char* fmt, ...) +int ma_snprintf(char* to, size_t n, const char* fmt, ...) { int result; va_list args; va_start(args,fmt); - result= my_vsnprintf(to, n, fmt, args); + result= ma_vsnprintf(to, n, fmt, args); va_end(args); return result; } -int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap) +int ma_vsnprintf(char *to, size_t n, const char* fmt, va_list ap) { char *start=to, *end=to+n-1; for (; *fmt ; fmt++) @@ -92,7 +92,7 @@ static void my_printf(const char * fmt, ...) int n; va_list ar; va_start(ar, fmt); - n = my_vsnprintf(buf, sizeof(buf),fmt, ar); + n = ma_vsnprintf(buf, sizeof(buf),fmt, ar); printf(buf); printf("n=%d, strlen=%d\n", n, strlen(buf)); va_end(ar); diff --git a/libmariadb/my_write.c b/libmariadb/my_write.c index 9a271d44..34b82a54 100644 --- a/libmariadb/my_write.c +++ b/libmariadb/my_write.c @@ -53,7 +53,7 @@ uint my_write(int Filedes, const unsigned char *Buffer, uint Count, myf MyFlags) (uint) writenbytes != (uint) -1) { if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE)) - my_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH), + ma_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH), my_filename(Filedes)); VOID(sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC)); continue; @@ -76,7 +76,7 @@ uint my_write(int Filedes, const unsigned char *Buffer, uint Count, myf MyFlags) { if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) { - my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG), + ma_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG), my_filename(Filedes),my_errno); } DBUG_RETURN(MY_FILE_ERROR); /* Error on read */ diff --git a/libmariadb/net.c b/libmariadb/net.c index 49b5ac1f..7e0161d4 100644 --- a/libmariadb/net.c +++ b/libmariadb/net.c @@ -114,7 +114,7 @@ static int net_write_buff(NET *net,const char *packet, size_t len); int my_net_init(NET *net, MARIADB_PVIO* pvio) { - if (!(net->buff=(uchar*) my_malloc(net_buffer_length,MYF(MY_WME | MY_ZEROFILL)))) + if (!(net->buff=(uchar*) ma_malloc(net_buffer_length,MYF(MY_WME | MY_ZEROFILL)))) return 1; /* We don't allocate memory for multi buffer, since we don't know in advance if the server @@ -144,8 +144,8 @@ int my_net_init(NET *net, MARIADB_PVIO* pvio) void net_end(NET *net) { - my_free(net->buff); - my_free(net->mbuff); + ma_free(net->buff); + ma_free(net->mbuff); net->buff=0; net->mbuff= 0; } @@ -171,7 +171,7 @@ static my_bool net_realloc(NET *net, my_bool is_multi, size_t length) pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1); /* reallocate buffer: size= pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE */ - if (!(buff=(uchar*) my_realloc(is_multi ? net->mbuff : net->buff, + if (!(buff=(uchar*) ma_realloc(is_multi ? net->mbuff : net->buff, pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE, MYF(MY_WME)))) { @@ -353,7 +353,7 @@ int net_add_multi_command(NET *net, uchar command, const uchar *packet, if (!net->mbuff) { size_t alloc_size= (required_length + IO_SIZE - 1) & ~(IO_SIZE - 1); - if (!(net->mbuff= (char *)my_malloc(alloc_size, MYF(MY_WME)))) + if (!(net->mbuff= (char *)ma_malloc(alloc_size, MYF(MY_WME)))) { net->last_errno=ER_OUT_OF_RESOURCES; net->error=2; @@ -384,7 +384,7 @@ int net_add_multi_command(NET *net, uchar command, const uchar *packet, error: if (net->mbuff) { - my_free(net->mbuff); + ma_free(net->mbuff); net->mbuff= net->mbuff_pos= net->mbuff_end= 0; } return 1; @@ -409,7 +409,7 @@ net_real_write(NET *net,const char *packet,size_t len) size_t complen; uchar *b; uint header_length=NET_HEADER_SIZE+COMP_HEADER_SIZE; - if (!(b=(uchar*) my_malloc(len + NET_HEADER_SIZE + COMP_HEADER_SIZE + 1, + if (!(b=(uchar*) ma_malloc(len + NET_HEADER_SIZE + COMP_HEADER_SIZE + 1, MYF(MY_WME)))) { net->last_errno=ER_OUT_OF_RESOURCES; @@ -448,7 +448,7 @@ net_real_write(NET *net,const char *packet,size_t len) } #ifdef HAVE_COMPRESS if (net->compress) - my_free((char*) packet); + ma_free((char*) packet); #endif net->reading_or_writing=0; DBUG_RETURN(((int) (pos != end))); diff --git a/libmariadb/secure/gnutls.c b/libmariadb/secure/gnutls.c index 534c2592..15bfe97e 100644 --- a/libmariadb/secure/gnutls.c +++ b/libmariadb/secure/gnutls.c @@ -58,7 +58,7 @@ static void ma_ssl_set_error(MYSQL *mysql, int ssl_errno) ssl_error_reason); return; } - my_snprintf(ssl_error, MAX_SSL_ERR_LEN, "SSL errno=%lu", ssl_errno, mysql->charset); + ma_snprintf(ssl_error, MAX_SSL_ERR_LEN, "SSL errno=%lu", ssl_errno, mysql->charset); pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, ssl_error); } @@ -187,7 +187,7 @@ static int ma_ssl_set_certs(MYSQL *mysql) error: if (cipher) - my_free(cipher); + ma_free(cipher); return ssl_error; } diff --git a/libmariadb/secure/ma_schannel.h b/libmariadb/secure/ma_schannel.h index 614a274b..94ac0941 100644 --- a/libmariadb/secure/ma_schannel.h +++ b/libmariadb/secure/ma_schannel.h @@ -47,8 +47,8 @@ typedef void VOID; #ifndef HAVE_SCHANNEL_DEFAULT -#define my_snprintf snprintf -#define my_vsnprintf vsnprintf +#define ma_snprintf snprintf +#define ma_vsnprintf vsnprintf #undef SAFE_MUTEX #endif #include diff --git a/libmariadb/secure/openssl.c b/libmariadb/secure/openssl.c index f8a844dd..75609b26 100644 --- a/libmariadb/secure/openssl.c +++ b/libmariadb/secure/openssl.c @@ -31,11 +31,11 @@ #ifndef HAVE_OPENSSL_DEFAULT #include -#define my_malloc(A,B) malloc((A)) -#undef my_free -#define my_free(A) free((A)) -#define my_snprintf snprintf -#define my_vsnprintf vsnprintf +#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 @@ -126,7 +126,7 @@ static int ssl_thread_init() if (LOCK_crypto == NULL) { if (!(LOCK_crypto= - (pthread_mutex_t *)my_malloc(sizeof(pthread_mutex_t) * max, MYF(0)))) + (pthread_mutex_t *)ma_malloc(sizeof(pthread_mutex_t) * max, MYF(0)))) return 1; for (i=0; i < max; i++) @@ -219,7 +219,7 @@ void ma_ssl_end() for (i=0; i < CRYPTO_num_locks(); i++) pthread_mutex_destroy(&LOCK_crypto[i]); - my_free((gptr)LOCK_crypto); + ma_free((gptr)LOCK_crypto); LOCK_crypto= NULL; if (SSL_context) @@ -572,7 +572,7 @@ unsigned int ma_ssl_get_finger_print(MARIADB_SSL *cssl, unsigned char *fp, unsig fp_len= len; if (!X509_digest(cert, digest, fp, &fp_len)) { - my_free(fp); + ma_free(fp); my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, ER(CR_SSL_CONNECTION_ERROR), "invalid finger print of server certificate"); diff --git a/libmariadb/string.c b/libmariadb/string.c index aba0ba83..daf3dab8 100644 --- a/libmariadb/string.c +++ b/libmariadb/string.c @@ -38,7 +38,7 @@ my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str, if (!init_alloc) init_alloc=alloc_increment; - if (!(str->str=(char*) my_malloc(init_alloc,MYF(MY_WME)))) + if (!(str->str=(char*) ma_malloc(init_alloc,MYF(MY_WME)))) DBUG_RETURN(TRUE); str->length=length-1; if (init_str) @@ -60,7 +60,7 @@ my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str) str->alloc_increment; if (!str->max_length) str->max_length=str->alloc_increment; - if (!(str->str=(char*) my_realloc(str->str,str->max_length,MYF(MY_WME)))) + if (!(str->str=(char*) ma_realloc(str->str,str->max_length,MYF(MY_WME)))) DBUG_RETURN(TRUE); } if (init_str) @@ -83,7 +83,7 @@ my_bool dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size) { str->max_length=((str->length + additional_size+str->alloc_increment-1)/ str->alloc_increment)*str->alloc_increment; - if (!(str->str=(char*) my_realloc(str->str,str->max_length,MYF(MY_WME)))) + if (!(str->str=(char*) ma_realloc(str->str,str->max_length,MYF(MY_WME)))) DBUG_RETURN(TRUE); } DBUG_RETURN(FALSE); @@ -105,7 +105,7 @@ my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append, size_t new_length=(str->length+length+str->alloc_increment)/ str->alloc_increment; new_length*=str->alloc_increment; - if (!(new_ptr=(char*) my_realloc(str->str,new_length,MYF(MY_WME)))) + if (!(new_ptr=(char*) ma_realloc(str->str,new_length,MYF(MY_WME)))) return TRUE; str->str=new_ptr; str->max_length=new_length; @@ -121,7 +121,7 @@ void dynstr_free(DYNAMIC_STRING *str) { if (str->str) { - my_free(str->str); + ma_free(str->str); str->str=0; } } diff --git a/libmariadb/typelib.c b/libmariadb/typelib.c index 7e1fb623..72297dcb 100644 --- a/libmariadb/typelib.c +++ b/libmariadb/typelib.c @@ -31,12 +31,12 @@ ** If & 4 allow #number# as type ****************************************************************************/ -int find_type(my_string x, TYPELIB *typelib, uint full_name) +int ma_find_type(my_string x, TYPELIB *typelib, uint full_name) { int find,pos,findpos= 0; reg1 my_string i; reg2 const char *j; - DBUG_ENTER("find_type"); + DBUG_ENTER("ma_find_type"); DBUG_PRINT("enter",("x: '%s' lib: %lx",x,typelib)); if (!typelib->count) @@ -78,27 +78,27 @@ int find_type(my_string x, TYPELIB *typelib, uint full_name) if (!(full_name & 2)) (void) strmov(x,typelib->type_names[findpos]); DBUG_RETURN(findpos+1); -} /* find_type */ +} /* ma_find_type */ /* Get name of type nr 'nr' */ /* Warning first type is 1, 0 = empty field */ -void make_type(register my_string to, register uint nr, register TYPELIB *typelib) +void ma_make_type(register my_string to, register uint nr, register TYPELIB *typelib) { - DBUG_ENTER("make_type"); + DBUG_ENTER("ma_make_type"); if (!nr) to[0]=0; else - (void) strmov(to,get_type(typelib,nr-1)); + (void) strmov(to,ma_get_type(typelib,nr-1)); DBUG_VOID_RETURN; -} /* make_type */ +} /* ma_make_type */ /* Get type */ /* Warning first type is 0 */ -const char *get_type(TYPELIB *typelib, uint nr) +const char *ma_get_type(TYPELIB *typelib, uint nr) { if (nr < (uint) typelib->count && typelib->type_names) return(typelib->type_names[nr]); diff --git a/mariadb_config/mariadb_config.c.in b/mariadb_config/mariadb_config.c.in index b4aa74c6..15f26618 100644 --- a/mariadb_config/mariadb_config.c.in +++ b/mariadb_config/mariadb_config.c.in @@ -44,7 +44,7 @@ void usage(void) int i=0; puts("Copyright 2011-2015 MariaDB Corporation AB"); puts("Get compiler flags for using the MariaDB Connector/C."); - printf("Usage: %s [OPTIONS]\n", my_progname); + printf("Usage: %s [OPTIONS]\n", ma_progname); while (long_options[i].name) { if (values[i]) @@ -57,7 +57,7 @@ void usage(void) int main(int argc, char **argv) { int c; - my_progname= argv[0]; + ma_progname= argv[0]; if (argc <= 1) { diff --git a/plugins/auth/my_auth.c b/plugins/auth/my_auth.c index ab797f85..053167c5 100644 --- a/plugins/auth/my_auth.c +++ b/plugins/auth/my_auth.c @@ -293,7 +293,7 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, if (mpvio->db && (mysql->server_capabilities & CLIENT_CONNECT_WITH_DB)) { end= strmake(end, mpvio->db, NAME_LEN) + 1; - mysql->db= my_strdup(mpvio->db, MYF(MY_WME)); + mysql->db= ma_strdup(mpvio->db, MYF(MY_WME)); } if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH) diff --git a/plugins/pvio/pvio_socket.c b/plugins/pvio/pvio_socket.c index 841acfcb..a2b36f49 100644 --- a/plugins/pvio/pvio_socket.c +++ b/plugins/pvio/pvio_socket.c @@ -687,7 +687,7 @@ my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) if (!pvio || !cinfo) return 1; - if (!(csock= (struct st_pvio_socket *)my_malloc(sizeof(struct st_pvio_socket), + if (!(csock= (struct st_pvio_socket *)ma_malloc(sizeof(struct st_pvio_socket), MYF(MY_WME | MY_ZEROFILL)))) { PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0, ""); @@ -734,7 +734,7 @@ my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) int rc= 0; bzero(&server_port, NI_MAXSERV); - my_snprintf(server_port, NI_MAXSERV, "%d", cinfo->port); + ma_snprintf(server_port, NI_MAXSERV, "%d", cinfo->port); /* set hints for getaddrinfo */ bzero(&hints, sizeof(hints)); @@ -838,7 +838,7 @@ my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) error: if (pvio->data) { - my_free((gptr)pvio->data); + ma_free((gptr)pvio->data); pvio->data= NULL; } return 1; @@ -862,7 +862,7 @@ my_bool pvio_socket_close(MARIADB_PVIO *pvio) r= closesocket(csock->socket); csock->socket= -1; } - my_free((gptr)pvio->data); + ma_free((gptr)pvio->data); pvio->data= NULL; } return r; diff --git a/unittest/mytap/tap.c b/unittest/mytap/tap.c index 5cdbfeb4..06233349 100644 --- a/unittest/mytap/tap.c +++ b/unittest/mytap/tap.c @@ -30,7 +30,7 @@ /* Visual Studio 2003 does not know vsnprintf but knows _vsnprintf. We don't put this #define in config-win.h because we prefer - my_vsnprintf everywhere instead, except when linking with libmysys + ma_vsnprintf everywhere instead, except when linking with libmysys is not desirable - the case here. */ #if defined(_MSC_VER) && ( _MSC_VER == 1310 ) From e794883554a37b92a24b4fc9601c56d3b0234211 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 2 Feb 2016 12:38:06 +0100 Subject: [PATCH 15/39] fix export symbols --- libmariadb/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmariadb/CMakeLists.txt b/libmariadb/CMakeLists.txt index 8dbc61f1..0ace3363 100644 --- a/libmariadb/CMakeLists.txt +++ b/libmariadb/CMakeLists.txt @@ -10,7 +10,7 @@ ADD_DEFINITIONS(-D THREAD) INCLUDE(${CMAKE_SOURCE_DIR}/cmake/sign.cmake) SET(EXPORT_SYMBOLS - load_defaults + mariadb_load_defaults ma_pvio_register_callback mariadb_connection mariadb_convert_string From 49a0a894383b109caf220a21e2ad3de262962bdc Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Tue, 2 Feb 2016 12:41:53 +0100 Subject: [PATCH 16/39] 1) added missing export function mariadb_load_defaults 2) added option WITH_UNITEST=ON/OFF to disable build of unittests --- CMakeLists.txt | 7 +++++-- libmariadb/CMakeLists.txt | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f9ca0946..ca25fc6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ ELSE() OPTION(WITH_RTC "enables run time checks for debug builds" OFF) ENDIF() +OPTION(WITH_UNITTEST "build test suite" ON) OPTION(WITH_EXTERNAL_ZLIB "Enables use of external zlib" OFF) ############### IF(WITH_SIGNCODE) @@ -290,8 +291,10 @@ ENDIF() ADD_SUBDIRECTORY(client) IF(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/unittest) - ADD_SUBDIRECTORY(unittest/mytap) - ADD_SUBDIRECTORY(unittest/libmariadb) + IF(WITH_UNITTEST STREQUAL "ON") + ADD_SUBDIRECTORY(unittest/mytap) + ADD_SUBDIRECTORY(unittest/libmariadb) + ENDIF() ENDIF() IF(CLIENT_DOCS) diff --git a/libmariadb/CMakeLists.txt b/libmariadb/CMakeLists.txt index 8dbc61f1..0ace3363 100644 --- a/libmariadb/CMakeLists.txt +++ b/libmariadb/CMakeLists.txt @@ -10,7 +10,7 @@ ADD_DEFINITIONS(-D THREAD) INCLUDE(${CMAKE_SOURCE_DIR}/cmake/sign.cmake) SET(EXPORT_SYMBOLS - load_defaults + mariadb_load_defaults ma_pvio_register_callback mariadb_connection mariadb_convert_string From ab67ef2e8598a7d58b3e7a11daa044daea82ae66 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 2 Feb 2016 14:08:20 +0100 Subject: [PATCH 17/39] fix compilation with gcc 4.8 --- plugins/auth/gssapi_errmsg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/auth/gssapi_errmsg.c b/plugins/auth/gssapi_errmsg.c index 8ea4cab5..6731fbe1 100644 --- a/plugins/auth/gssapi_errmsg.c +++ b/plugins/auth/gssapi_errmsg.c @@ -38,8 +38,8 @@ void gssapi_errmsg(OM_uint32 major, OM_uint32 minor, char *buf, size_t size) char *p= buf; char *end= buf + size - 1; int types[] = {GSS_C_GSS_CODE,GSS_C_MECH_CODE}; - - for(int i= 0; i < 2;i++) + int i; + for(i= 0; i < 2;i++) { message_context= 0; status_code= types[i] == GSS_C_GSS_CODE?major:minor; From ecf92d33069bfb7c7bfbe94d1d1f011d5d532a8f Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Tue, 2 Feb 2016 17:10:56 +0100 Subject: [PATCH 18/39] removed obsolete have_tcpip stuff --- include/my_sys.h | 3 -- libmariadb/libmariadb.c | 3 +- libmariadb/my_init.c | 88 +++++++++-------------------------------- 3 files changed, 20 insertions(+), 74 deletions(-) diff --git a/include/my_sys.h b/include/my_sys.h index 26755cc4..d6d505a1 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -609,9 +609,6 @@ ulong checksum(const unsigned char *mem, uint count); #if defined(_MSC_VER) && !defined(_WIN32) extern void sleep(int sec); #endif -#ifdef _WIN32 -extern my_bool have_tcpip; /* Is set if tcpip is used */ -#endif #ifdef __cplusplus } diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index 5a39c9a1..dd9f31ec 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -1430,8 +1430,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, if ((unix_socket || (!host && is_NT()) || (host && strcmp(host,LOCAL_HOST_NAMEDPIPE) == 0) || - mysql->options.named_pipe || - !have_tcpip) && + mysql->options.named_pipe) && mysql->options.protocol != MYSQL_PROTOCOL_TCP) { cinfo.type= PVIO_TYPE_NAMEDPIPE; diff --git a/libmariadb/my_init.c b/libmariadb/my_init.c index bb096159..75a50f7f 100644 --- a/libmariadb/my_init.c +++ b/libmariadb/my_init.c @@ -36,9 +36,7 @@ #include #endif my_bool have_tcpip=0; -static void my_win_init(void); -static my_bool win32_have_tcpip(void); -static my_bool win32_init_tcp_ip(); +static my_bool my_win_init(void); #else #define my_win_init() #endif @@ -169,10 +167,9 @@ Voluntary context switches %ld, Involuntary context switches %ld\n", ma_thread_global_end(); #endif #ifdef _WIN32 - if (have_tcpip); - WSACleanup( ); + WSACleanup( ); #endif /* _WIN32 */ - ma_init_done=0; + ma_init_done=0; } /* ma_end */ #ifdef _WIN32 @@ -201,73 +198,26 @@ void setEnvString(char *ret, const char *name, const char *value) DBUG_VOID_RETURN ; } -static void my_win_init(void) +static my_bool my_win_init() { - DBUG_ENTER("my_win_init"); - win32_init_tcp_ip(); - DBUG_VOID_RETURN ; -} - - -/*------------------------------------------------------------------ -** Name: CheckForTcpip| Desc: checks if tcpip has been installed on system -** According to Microsoft Developers documentation the first registry -** entry should be enough to check if TCP/IP is installed, but as expected -** this doesn't work on all Win32 machines :( -------------------------------------------------------------------*/ - -#define TCPIPKEY "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters" -#define WINSOCK2KEY "SYSTEM\\CurrentControlSet\\Services\\Winsock2\\Parameters" -#define WINSOCKKEY "SYSTEM\\CurrentControlSet\\Services\\Winsock\\Parameters" - -static my_bool win32_have_tcpip(void) -{ - HKEY hTcpipRegKey; - if (RegOpenKeyEx ( HKEY_LOCAL_MACHINE, TCPIPKEY, 0, KEY_READ, - &hTcpipRegKey) != ERROR_SUCCESS) + 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))) { - if (RegOpenKeyEx ( HKEY_LOCAL_MACHINE, WINSOCK2KEY, 0, KEY_READ, - &hTcpipRegKey) != ERROR_SUCCESS) - { - if (RegOpenKeyEx ( HKEY_LOCAL_MACHINE, WINSOCKKEY, 0, KEY_READ, - &hTcpipRegKey) != ERROR_SUCCESS) - if (!getenv("HAVE_TCPIP") || have_tcpip) /* Provide a workaround */ - return (FALSE); - } + return 0; } - RegCloseKey ( hTcpipRegKey); - return (TRUE); -} - -static my_bool win32_init_tcp_ip() -{ - if (win32_have_tcpip()) + /* make sure 2.2 or higher is supported */ + if ((LOBYTE(WsaData.wVersion) * 10 + HIBYTE(WsaData.wVersion)) < 22) { - WORD wVersionRequested = MAKEWORD( 2, 0 ); - WSADATA wsaData; - /* Be a good citizen: maybe another lib has already initialised - sockets, so dont clobber them unless necessary */ - if (WSAStartup( wVersionRequested, &wsaData )) - { - /* Load failed, maybe because of previously loaded - incompatible version; try again */ - WSACleanup( ); - if (!WSAStartup( wVersionRequested, &wsaData )) - have_tcpip=1; - } - else - { - if (wsaData.wVersion != wVersionRequested) - { - /* Version is no good, try again */ - WSACleanup( ); - if (!WSAStartup( wVersionRequested, &wsaData )) - have_tcpip=1; - } - else - have_tcpip=1; - } + WSACleanup(); + return 1; } - return(0); + return 0; } #endif + From e138995b87d24cb82cbe0745bfa5b49963acd538 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Tue, 2 Feb 2016 20:09:42 +0100 Subject: [PATCH 19/39] more fixes for 10.2 integration --- include/CMakeLists.txt | 53 +++++++++----------------- include/ma_dyncol.h | 4 +- include/{m_ctype.h => mariadb_ctype.h} | 28 +++++++------- include/my_stmt.h | 2 +- include/my_sys.h | 40 +++++++++---------- include/mysql.h | 49 ++++++++++++------------ include/mysql_com.h | 4 ++ include/mysql_priv.h | 2 +- libmariadb/CMakeLists.txt | 7 ---- libmariadb/charset.c | 28 +++++++------- libmariadb/client_plugin.c.in | 2 +- libmariadb/default.c | 14 +++---- libmariadb/get_password.c | 2 +- libmariadb/hash.c | 2 +- libmariadb/libmariadb.c | 26 ++++++------- libmariadb/ma_dyncol.c | 12 +++--- libmariadb/my_alloc.c | 38 +++++++++--------- libmariadb/my_charset.c | 20 +++++----- libmariadb/my_error.c | 2 +- libmariadb/my_getwd.c | 2 +- libmariadb/my_init.c | 6 +-- libmariadb/my_once.c | 12 +++--- libmariadb/my_static.c | 2 +- libmariadb/my_static.h | 2 +- libmariadb/my_stmt.c | 18 ++++----- libmariadb/my_stmt_codec.c | 2 +- libmariadb/my_vsnprintf.c | 2 +- libmariadb/str2int.c | 2 +- libmariadb/strto.c | 2 +- libmariadb/strtoll.c | 2 +- libmariadb/typelib.c | 2 +- unittest/libmariadb/charset.c | 4 +- unittest/libmariadb/dyncol.c | 6 +-- unittest/libmariadb/misc.c | 4 +- unittest/libmariadb/my_test.h | 2 +- 35 files changed, 192 insertions(+), 213 deletions(-) rename include/{m_ctype.h => mariadb_ctype.h} (66%) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 47e7f7b2..d2823e4d 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,37 +1,18 @@ -SET(MARIADB_CLIENT_INCLUDES config-win.h - dbug.h - errmsg.h - getopt.h - hash.h - ma_common.h - ma_pvio.h - ma_ssl.h - m_ctype.h - m_string.h - ma_dyncol.h - my_alarm.h - my_base.h - my_config.h.in - my_dir.h - my_global.h - my_list.h - my_net.h - my_no_pthread.h - my_pthread.h - my_stmt.h - my_sys.h - mysql.h - mysql_com.h - mysql_io.h - mysql_mm.h - mysql_priv.h - mysql_version.h - mysql_wireprotocol.h - mysqld_error.h - mysys_err.h - sha1.h - thr_alarm.h - mysql/client_plugin.h - mysql/plugin_auth_common.h - mysql/plugin_auth.h +SET(MARIADB_CLIENT_INCLUDES + ${CMAKE_SOURCE_DIR}/include/mysql_com.h + ${CMAKE_SOURCE_DIR}/include/mysql.h + ${CMAKE_SOURCE_DIR}/include/my_stmt.h + ${CMAKE_SOURCE_DIR}/include/mysql_version.h + ${CMAKE_SOURCE_DIR}/include/my_list.h + ${CMAKE_SOURCE_DIR}/include/mariadb_ctype.h) +SET(MARIADB_ADDITIONAL_INCLUDES PARENT_SCOPE) +INSTALL(FILES + ${CMAKE_BINARY_DIR}/include/mysql_version.h + ${MARIADB_CLIENT_INCLUDES} + DESTINATION ${INCLUDE_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}) +INSTALL(FILES + ${CMAKE_SOURCE_DIR}/include/mysql/client_plugin.h + ${CMAKE_SOURCE_DIR}/include/mysql/plugin_auth_common.h + ${CMAKE_SOURCE_DIR}/include/mysql/plugin_auth.h + DESTINATION ${INCLUDE_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}/mysql) diff --git a/include/ma_dyncol.h b/include/ma_dyncol.h index 3b5c8ae3..f2c13aa3 100644 --- a/include/ma_dyncol.h +++ b/include/ma_dyncol.h @@ -115,7 +115,7 @@ struct st_dynamic_column_value double double_value; struct { MYSQL_LEX_STRING value; - CHARSET_INFO *charset; + MARIADB_CHARSET_INFO *charset; } string; #ifndef LIBMARIADB struct { @@ -225,7 +225,7 @@ void mariadb_dyncol_free(DYNAMIC_COLUMN *str); /* conversion of values to 3 base types */ enum enum_dyncol_func_result mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, - CHARSET_INFO *cs, my_bool quote); + MARIADB_CHARSET_INFO *cs, my_bool quote); enum enum_dyncol_func_result mariadb_dyncol_val_long(longlong *ll, DYNAMIC_COLUMN_VALUE *val); enum enum_dyncol_func_result diff --git a/include/m_ctype.h b/include/mariadb_ctype.h similarity index 66% rename from include/m_ctype.h rename to include/mariadb_ctype.h index d9f48ce7..727f5823 100644 --- a/include/m_ctype.h +++ b/include/mariadb_ctype.h @@ -20,8 +20,8 @@ Notes: my_global.h should be included before ctype.h */ -#ifndef _m_ctype_h -#define _m_ctype_h +#ifndef _mariadb_ctype_h +#define _mariadb_ctype_h #include @@ -36,7 +36,7 @@ extern "C" { #define MADB_DEFAULT_COLLATION_NAME "latin1_swedish_ci" /* we use the mysqlnd implementation */ -typedef struct charset_info_st +typedef struct ma_charset_info_st { unsigned int nr; /* so far only 1 byte for charset */ unsigned int state; @@ -49,20 +49,20 @@ typedef struct charset_info_st unsigned int char_maxlen; unsigned int (*mb_charlen)(unsigned int c); unsigned int (*mb_valid)(const char *start, const char *end); -} CHARSET_INFO; +} MARIADB_CHARSET_INFO; -extern const CHARSET_INFO compiled_charsets[]; -extern CHARSET_INFO *ma_default_charset_info; -extern CHARSET_INFO *ma_charset_bin; -extern CHARSET_INFO *ma_charset_latin1; -extern CHARSET_INFO *ma_charset_utf8_general_ci; -extern CHARSET_INFO *ma_charset_utf16le_general_ci; +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; -CHARSET_INFO *find_compiled_charset(unsigned int cs_number); -CHARSET_INFO *find_compiled_charset_by_name(const char *name); +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 CHARSET_INFO *cset, char *newstr, const char *escapestr, size_t escapestr_len); -size_t mysql_cset_escape_slashes(const CHARSET_INFO *cset, char *newstr, const char *escapestr, size_t escapestr_len); +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); char* madb_get_os_character_set(void); #ifdef _WIN32 int madb_get_windows_cp(const char *charset); diff --git a/include/my_stmt.h b/include/my_stmt.h index e58e3524..4cf2863c 100644 --- a/include/my_stmt.h +++ b/include/my_stmt.h @@ -172,7 +172,7 @@ typedef int (*mysql_stmt_fetch_row_func)(MYSQL_STMT *stmt, unsigned char **row) struct st_mysql_stmt { - MEM_ROOT mem_root; + MA_MEM_ROOT mem_root; MYSQL *mysql; unsigned long stmt_id; unsigned long flags;/* cursor is set here */ diff --git a/include/my_sys.h b/include/my_sys.h index 26755cc4..d4560942 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -35,8 +35,8 @@ extern int NEAR my_errno; /* Last error in mysys */ #include #endif -#ifndef _m_ctype_h -#include /* for CHARSET_INFO */ +#ifndef _mariadb_ctype_h +#include /* for MARIADB_CHARSET_INFO */ #endif #include @@ -182,10 +182,10 @@ extern int (*fatal_ma_error_handler_hook)(uint my_err, const char *str, /* charsets */ extern uint get_charset_number(const char *cs_name); extern const char *get_charset_name(uint cs_number); -extern CHARSET_INFO *get_charset(uint cs_number, myf flags); +extern MARIADB_CHARSET_INFO *get_charset(uint cs_number, myf flags); extern my_bool set_default_charset(uint cs, myf flags); -extern CHARSET_INFO *get_charset_by_name(const char *cs_name); -extern CHARSET_INFO *get_charset_by_nr(uint cs_number); +extern MARIADB_CHARSET_INFO *get_charset_by_name(const char *cs_name); +extern MARIADB_CHARSET_INFO *get_charset_by_nr(uint cs_number); extern my_bool set_default_charset_by_name(const char *cs_name, myf flags); extern void free_charsets(void); extern char *list_charsets(myf want_flags); /* ma_free() this string... */ @@ -354,24 +354,24 @@ typedef struct st_changeable_var { /* structs for ma_alloc_root */ -#ifndef ST_USED_MEM_DEFINED -#define ST_USED_MEM_DEFINED -typedef struct st_used_mem { /* struct for once_alloc */ - struct st_used_mem *next; /* Next block in use */ +#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 */ -} USED_MEM; +} MA_USED_MEM; -typedef struct st_mem_root { - USED_MEM *free; - USED_MEM *used; - USED_MEM *pre_alloc; +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); -} MEM_ROOT; +} MA_MEM_ROOT; #endif /* Prototypes for mysys and my_func functions */ @@ -592,11 +592,11 @@ extern void ma_free_lock(unsigned char *ptr,myf flags); #define ma_free_lock(A,B) ma_free((A),(B)) #endif #define ma_alloc_root_inited(A) ((A)->min_malloc != 0) -void ma_init_ma_alloc_root(MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size); -gptr ma_alloc_root(MEM_ROOT *mem_root, size_t Size); -void ma_free_root(MEM_ROOT *root, myf MyFLAGS); -char *ma_strdup_root(MEM_ROOT *root,const char *str); -char *ma_memdup_root(MEM_ROOT *root,const char *str, size_t len); +void ma_init_ma_alloc_root(MA_MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size); +gptr 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 mariadb_load_defaults(const char *conf_file, const char **groups, int *argc, char ***argv); void ma_free_defaults(char **argv); diff --git a/include/mysql.h b/include/mysql.h index 270567f5..a90bbd54 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -56,26 +56,26 @@ typedef int my_socket; #include "mysql_com.h" #include "mysql_version.h" #include "my_list.h" -#include "m_ctype.h" +#include "mariadb_ctype.h" -#ifndef ST_USED_MEM_DEFINED -#define ST_USED_MEM_DEFINED - typedef struct st_used_mem { /* struct for once_alloc */ - struct st_used_mem *next; /* Next block in use */ +#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 */ - } USED_MEM; + } MA_USED_MEM; - typedef struct st_mem_root { - USED_MEM *free; - USED_MEM *used; - USED_MEM *pre_alloc; + 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); - } MEM_ROOT; + } MA_MEM_ROOT; #endif extern unsigned int mysql_port; @@ -159,7 +159,7 @@ extern unsigned int mariadb_deinitialize_ssl; my_ulonglong rows; unsigned int fields; MYSQL_ROWS *data; - MEM_ROOT alloc; + MA_MEM_ROOT alloc; } MYSQL_DATA; enum mariadb_com_multi { @@ -236,7 +236,7 @@ extern unsigned int mariadb_deinitialize_ssl; MARIADB_CLIENT_VERSION_ID, MARIADB_CONNECTION_ASYNC_TIMEOUT, MARIADB_CONNECTION_ASYNC_TIMEOUT_MS, - MARIADB_CONNECTION_CHARSET_INFO, + MARIADB_CONNECTION_MARIADB_CHARSET_INFO, MARIADB_CONNECTION_ERROR, MARIADB_CONNECTION_ERROR_ID, MARIADB_CONNECTION_HOST, @@ -312,9 +312,9 @@ struct st_mysql_options { void *unused_0; char *host,*user,*passwd,*unix_socket,*server_version,*host_info; char *info,*db; - const struct charset_info_st *charset; /* character set */ + const struct ma_charset_info_st *charset; /* character set */ MYSQL_FIELD *fields; - MEM_ROOT field_alloc; + MA_MEM_ROOT field_alloc; my_ulonglong affected_rows; my_ulonglong insert_id; /* id if insert on table with NEXTNR */ my_ulonglong extra_info; /* Used by mysqlshow */ @@ -350,7 +350,7 @@ typedef struct st_mysql_res { MYSQL_FIELD *fields; MYSQL_DATA *data; MYSQL_ROWS *data_cursor; - MEM_ROOT field_alloc; + 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 */ @@ -359,13 +359,13 @@ typedef struct st_mysql_res { my_bool is_ps; } MYSQL_RES; +#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; @@ -373,6 +373,7 @@ typedef struct st_mysql_time my_bool neg; enum enum_mysql_timestamp_type time_type; } MYSQL_TIME; +#endif #define AUTO_SEC_PART_DIGITS 31 #define SEC_PART_DIGITS 6 @@ -516,10 +517,10 @@ 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); -CHARSET_INFO * STDCALL mariadb_get_charset_by_name(const char *csname); -CHARSET_INFO * STDCALL mariadb_get_charset_by_nr(unsigned int csnr); -size_t STDCALL mariadb_convert_string(const char *from, size_t *from_len, CHARSET_INFO *from_cs, - char *to, size_t *to_len, CHARSET_INFO *to_cs, int *errorcode); +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 STDCALL mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...); int STDCALL mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...); int STDCALL mysql_get_option(MYSQL *mysql, enum mysql_option option, void *arg); @@ -717,9 +718,9 @@ struct st_mariadb_api { unsigned long (STDCALL *mysql_get_client_version)(void); my_bool (STDCALL *mariadb_connection)(MYSQL *mysql); const char * (STDCALL *mysql_get_server_name)(MYSQL *mysql); - CHARSET_INFO * (STDCALL *mariadb_get_charset_by_name)(const char *csname); - CHARSET_INFO * (STDCALL *mariadb_get_charset_by_nr)(unsigned int csnr); - size_t (STDCALL *mariadb_convert_string)(const char *from, size_t *from_len, CHARSET_INFO *from_cs, char *to, size_t *to_len, CHARSET_INFO *to_cs, int *errorcode); + 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 (STDCALL *mysql_optionsv)(MYSQL *mysql,enum mysql_option option, ...); int (STDCALL *mysql_get_optionv)(MYSQL *mysql, enum mysql_option option, void *arg, ...); int (STDCALL *mysql_get_option)(MYSQL *mysql, enum mysql_option option, void *arg); diff --git a/include/mysql_com.h b/include/mysql_com.h index 121b8b88..0cbc7817 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -48,6 +48,10 @@ #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, diff --git a/include/mysql_priv.h b/include/mysql_priv.h index f0198139..b2a32364 100644 --- a/include/mysql_priv.h +++ b/include/mysql_priv.h @@ -1,4 +1,4 @@ /* internal functions */ MYSQL_DATA *read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, uint fields); void free_rows(MYSQL_DATA *cur); -MYSQL_FIELD * unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, my_bool default_value, my_bool long_flag_protocol); +MYSQL_FIELD * unpack_fields(MYSQL_DATA *data,MA_MEM_ROOT *alloc,uint fields, my_bool default_value, my_bool long_flag_protocol); diff --git a/libmariadb/CMakeLists.txt b/libmariadb/CMakeLists.txt index 0ace3363..02f6cfd0 100644 --- a/libmariadb/CMakeLists.txt +++ b/libmariadb/CMakeLists.txt @@ -445,11 +445,4 @@ INSTALL(TARGETS LIBRARY DESTINATION "${LIB_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}" ARCHIVE DESTINATION "${LIB_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}") -INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ - DESTINATION ${INCLUDE_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}) -INSTALL(FILES - ${CMAKE_BINARY_DIR}/include/my_config.h - ${CMAKE_BINARY_DIR}/include/mysql_version.h - DESTINATION ${INCLUDE_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}) - diff --git a/libmariadb/charset.c b/libmariadb/charset.c index 72e2da96..73a5e399 100644 --- a/libmariadb/charset.c +++ b/libmariadb/charset.c @@ -17,29 +17,29 @@ #include "mysys_priv.h" #include "mysys_err.h" -#include +#include #include #include -CHARSET_INFO *ma_default_charset_info = (CHARSET_INFO *)&compiled_charsets[5]; -CHARSET_INFO *ma_charset_bin= (CHARSET_INFO *)&compiled_charsets[32]; -CHARSET_INFO *ma_charset_latin1= (CHARSET_INFO *)&compiled_charsets[5]; -CHARSET_INFO *ma_charset_utf8_general_ci= (CHARSET_INFO *)&compiled_charsets[21]; -CHARSET_INFO *ma_charset_utf16le_general_ci= (CHARSET_INFO *)&compiled_charsets[68]; +MARIADB_CHARSET_INFO *ma_default_charset_info = (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[5]; +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]; -CHARSET_INFO * STDCALL mysql_get_charset_by_nr(uint cs_number) +MARIADB_CHARSET_INFO * STDCALL mysql_get_charset_by_nr(uint cs_number) { int i= 0; - while (compiled_charsets[i].nr && cs_number != compiled_charsets[i].nr) + while (mariadb_compiled_charsets[i].nr && cs_number != mariadb_compiled_charsets[i].nr) i++; - return (compiled_charsets[i].nr) ? (CHARSET_INFO *)&compiled_charsets[i] : NULL; + return (mariadb_compiled_charsets[i].nr) ? (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[i] : NULL; } my_bool set_default_charset(uint cs, myf flags) { - CHARSET_INFO *new_charset; + MARIADB_CHARSET_INFO *new_charset; DBUG_ENTER("set_default_charset"); DBUG_PRINT("enter",("character set: %d",(int) cs)); new_charset = mysql_get_charset_by_nr(cs); @@ -52,19 +52,19 @@ my_bool set_default_charset(uint cs, myf flags) DBUG_RETURN(FALSE); } -CHARSET_INFO * STDCALL mysql_get_charset_by_name(const char *cs_name) +MARIADB_CHARSET_INFO * STDCALL mysql_get_charset_by_name(const char *cs_name) { int i= 0; - while (compiled_charsets[i].nr && strcmp(cs_name, compiled_charsets[i].csname) != 0) + while (mariadb_compiled_charsets[i].nr && strcmp(cs_name, mariadb_compiled_charsets[i].csname) != 0) i++; - return (compiled_charsets[i].nr) ? (CHARSET_INFO *)&compiled_charsets[i] : NULL; + 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) { - CHARSET_INFO *new_charset; + MARIADB_CHARSET_INFO *new_charset; DBUG_ENTER("set_default_charset_by_name"); DBUG_PRINT("enter",("character set: %s", cs_name)); new_charset = mysql_get_charset_by_name(cs_name); diff --git a/libmariadb/client_plugin.c.in b/libmariadb/client_plugin.c.in index 6d0a8c67..6ae48243 100644 --- a/libmariadb/client_plugin.c.in +++ b/libmariadb/client_plugin.c.in @@ -54,7 +54,7 @@ struct st_client_plugin_int { }; static my_bool initialized= 0; -static MEM_ROOT mem_root; +static MA_MEM_ROOT mem_root; static uint valid_plugins[][2]= { {MYSQL_CLIENT_AUTHENTICATION_PLUGIN, MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION}, diff --git a/libmariadb/default.c b/libmariadb/default.c index 7571bdbc..573bb126 100644 --- a/libmariadb/default.c +++ b/libmariadb/default.c @@ -39,7 +39,7 @@ #include "mysys_priv.h" #include "m_string.h" #include -#include "m_ctype.h" +#include "mariadb_ctype.h" #include #include #include @@ -70,7 +70,7 @@ NullS, #define windows_ext ".ini" #endif -static my_bool search_default_file(DYNAMIC_ARRAY *args,MEM_ROOT *alloc, +static my_bool search_default_file(DYNAMIC_ARRAY *args,MA_MEM_ROOT *alloc, const char *dir, const char *config_file, const char *ext, TYPELIB *group); @@ -83,7 +83,7 @@ void mariadb_load_defaults(const char *conf_file, const char **groups, TYPELIB group; my_bool found_ma_print_defaults=0; uint args_used=0; - MEM_ROOT alloc; + MA_MEM_ROOT alloc; char *ptr,**res; DBUG_ENTER("mariadb_load_defaults"); @@ -101,7 +101,7 @@ void mariadb_load_defaults(const char *conf_file, const char **groups, res[i-1]=argv[0][i]; (*argc)--; *argv=res; - *(MEM_ROOT*) ptr= alloc; /* Save alloc root for free */ + *(MA_MEM_ROOT*) ptr= alloc; /* Save alloc root for free */ DBUG_VOID_RETURN; } @@ -194,7 +194,7 @@ void mariadb_load_defaults(const char *conf_file, const char **groups, (*argc)+=args.elements; *argv= (char**) res; - *(MEM_ROOT*) ptr= alloc; /* Save alloc root for free */ + *(MA_MEM_ROOT*) ptr= alloc; /* Save alloc root for free */ ma_delete_dynamic(&args); if (found_ma_print_defaults) { @@ -216,13 +216,13 @@ void mariadb_load_defaults(const char *conf_file, const char **groups, void ma_free_defaults(char **argv) { - MEM_ROOT ptr; + MA_MEM_ROOT ptr; memcpy_fixed((char*) &ptr,(char *) argv - sizeof(ptr), sizeof(ptr)); ma_free_root(&ptr,MYF(0)); } -static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, +static my_bool search_default_file(DYNAMIC_ARRAY *args, MA_MEM_ROOT *alloc, const char *dir, const char *config_file, const char *ext, TYPELIB *group) { diff --git a/libmariadb/get_password.c b/libmariadb/get_password.c index 2eafb7a8..287c412a 100644 --- a/libmariadb/get_password.c +++ b/libmariadb/get_password.c @@ -20,7 +20,7 @@ #include #include "mysql.h" #include -#include +#include #include #include diff --git a/libmariadb/hash.c b/libmariadb/hash.c index 31bd7a89..0f5bdf01 100644 --- a/libmariadb/hash.c +++ b/libmariadb/hash.c @@ -27,7 +27,7 @@ #include "mysys_priv.h" #include -#include +#include #include "hash.h" #define NO_RECORD ((uint) -1) diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index 5a39c9a1..35e366c6 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include "my_context.h" #include "mysql.h" @@ -86,8 +86,8 @@ static void mysql_close_options(MYSQL *mysql); extern my_bool ma_init_done; extern my_bool mysql_ps_subsystem_initialized; extern my_bool mysql_handle_local_infile(MYSQL *mysql, const char *filename); -extern const CHARSET_INFO * mysql_find_charset_nr(uint charsetnr); -extern const CHARSET_INFO * mysql_find_charset_name(const char * const name); +extern const MARIADB_CHARSET_INFO * mysql_find_charset_nr(uint charsetnr); +extern const MARIADB_CHARSET_INFO * mysql_find_charset_name(const char * const name); extern int run_plugin_auth(MYSQL *mysql, char *data, uint data_len, const char *data_plugin, const char *db); extern int net_add_multi_command(NET *net, uchar command, const uchar *packet, @@ -933,7 +933,7 @@ static size_t rset_field_offsets[]= { }; MYSQL_FIELD * -unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, +unpack_fields(MYSQL_DATA *data,MA_MEM_ROOT *alloc,uint fields, my_bool default_value, my_bool long_flag_protocol) { MYSQL_ROWS *row; @@ -1845,7 +1845,7 @@ void ma_invalidate_stmts(MYSQL *mysql, const char *function_name) my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, const char *passwd, const char *db) { - const CHARSET_INFO *s_cs= mysql->charset; + const MARIADB_CHARSET_INFO *s_cs= mysql->charset; char *s_user= mysql->user, *s_passwd= mysql->passwd, *s_db= mysql->db; @@ -3457,7 +3457,7 @@ void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *cs) int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname) { - const CHARSET_INFO *cs; + const MARIADB_CHARSET_INFO *cs; DBUG_ENTER("mysql_set_character_set"); if (!csname) @@ -3638,14 +3638,14 @@ mysql_get_socket(MYSQL *mysql) return mariadb_get_socket(mysql); } -CHARSET_INFO * STDCALL mariadb_get_charset_by_name(const char *csname) +MARIADB_CHARSET_INFO * STDCALL mariadb_get_charset_by_name(const char *csname) { - return (CHARSET_INFO *)mysql_find_charset_name(csname); + return (MARIADB_CHARSET_INFO *)mysql_find_charset_name(csname); } -CHARSET_INFO * STDCALL mariadb_get_charset_by_nr(unsigned int csnr) +MARIADB_CHARSET_INFO * STDCALL mariadb_get_charset_by_nr(unsigned int csnr) { - return (CHARSET_INFO *)mysql_find_charset_nr(csnr); + return (MARIADB_CHARSET_INFO *)mysql_find_charset_nr(csnr); } my_bool STDCALL mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void *arg, ...) @@ -3746,7 +3746,7 @@ my_bool STDCALL mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void * else goto error; break; - case MARIADB_CONNECTION_CHARSET_INFO: + case MARIADB_CONNECTION_MARIADB_CHARSET_INFO: if (mysql) mariadb_get_charset_info(mysql, (MY_CHARSET_INFO *)arg); else @@ -3787,7 +3787,7 @@ my_bool STDCALL mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void * char *name; name= va_arg(ap, char *); if (name) - *((CHARSET_INFO **)arg)= (CHARSET_INFO *)mysql_find_charset_name(name); + *((MARIADB_CHARSET_INFO **)arg)= (MARIADB_CHARSET_INFO *)mysql_find_charset_name(name); else goto error; } @@ -3796,7 +3796,7 @@ my_bool STDCALL mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void * { unsigned int nr; nr= va_arg(ap, unsigned int); - *((CHARSET_INFO **)arg)= (CHARSET_INFO *)mysql_find_charset_nr(nr); + *((MARIADB_CHARSET_INFO **)arg)= (MARIADB_CHARSET_INFO *)mysql_find_charset_nr(nr); } break; case MARIADB_CONNECTION_SSL_CIPHER: diff --git a/libmariadb/ma_dyncol.c b/libmariadb/ma_dyncol.c index e8b1668e..5e168503 100644 --- a/libmariadb/ma_dyncol.c +++ b/libmariadb/ma_dyncol.c @@ -71,15 +71,15 @@ #ifndef LIBMARIADB -uint32 copy_and_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs, +uint32 copy_and_convert(char *to, uint32 to_length, MARIADB_CHARSET_INFO *to_cs, const char *from, uint32 from_length, - CHARSET_INFO *from_cs, uint *errors); + MARIADB_CHARSET_INFO *from_cs, uint *errors); #else size_t mariadb_time_to_string(const MYSQL_TIME *tm, char *time_str, size_t len, unsigned int digits); -size_t STDCALL mariadb_convert_string(const char *from, size_t *from_len, CHARSET_INFO *from_cs, - char *to, size_t *to_len, CHARSET_INFO *to_cs, int *errorcode); +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); #endif /* Flag byte bits @@ -1062,7 +1062,7 @@ dynamic_column_double_read(DYNAMIC_COLUMN_VALUE *store_it_here, static enum enum_dyncol_func_result dynamic_column_string_store(DYNAMIC_COLUMN *str, LEX_STRING *string, - CHARSET_INFO *charset) + MARIADB_CHARSET_INFO *charset) { enum enum_dyncol_func_result rc; #ifdef LIBMARIADB @@ -3841,7 +3841,7 @@ end: enum enum_dyncol_func_result mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, - CHARSET_INFO *cs, char quote) + MARIADB_CHARSET_INFO *cs, char quote) { char buff[40]; size_t len; diff --git a/libmariadb/my_alloc.c b/libmariadb/my_alloc.c index b0486afe..96ea05b0 100644 --- a/libmariadb/my_alloc.c +++ b/libmariadb/my_alloc.c @@ -21,20 +21,20 @@ #include #include -void ma_init_ma_alloc_root(MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size) +void ma_init_ma_alloc_root(MA_MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size) { mem_root->free=mem_root->used=0; mem_root->min_malloc=32; - mem_root->block_size=block_size-MALLOC_OVERHEAD-sizeof(USED_MEM)-8; + mem_root->block_size=block_size-MALLOC_OVERHEAD-sizeof(MA_USED_MEM)-8; mem_root->error_handler=0; #if !(defined(HAVE_purify) && defined(EXTRA_DEBUG)) if (pre_alloc_size) { if ((mem_root->free = mem_root->pre_alloc= - (USED_MEM*) ma_malloc(pre_alloc_size+ ALIGN_SIZE(sizeof(USED_MEM)), + (MA_USED_MEM*) ma_malloc(pre_alloc_size+ ALIGN_SIZE(sizeof(MA_USED_MEM)), MYF(0)))) { - mem_root->free->size=pre_alloc_size+ALIGN_SIZE(sizeof(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; } @@ -42,13 +42,13 @@ void ma_init_ma_alloc_root(MEM_ROOT *mem_root, size_t block_size, size_t pre_all #endif } -gptr ma_alloc_root(MEM_ROOT *mem_root, size_t Size) +gptr ma_alloc_root(MA_MEM_ROOT *mem_root, size_t Size) { #if defined(HAVE_purify) && defined(EXTRA_DEBUG) - reg1 USED_MEM *next; - Size+=ALIGN_SIZE(sizeof(USED_MEM)); + reg1 MA_USED_MEM *next; + Size+=ALIGN_SIZE(sizeof(MA_USED_MEM)); - if (!(next = (USED_MEM*) ma_malloc(Size,MYF(MY_WME)))) + if (!(next = (MA_USED_MEM*) ma_malloc(Size,MYF(MY_WME)))) { if (mem_root->error_handler) (*mem_root->error_handler)(); @@ -56,12 +56,12 @@ gptr ma_alloc_root(MEM_ROOT *mem_root, size_t Size) } next->next=mem_root->used; mem_root->used=next; - return (gptr) (((char*) next)+ALIGN_SIZE(sizeof(USED_MEM))); + return (gptr) (((char*) next)+ALIGN_SIZE(sizeof(MA_USED_MEM))); #else size_t get_size,max_left; gptr point; - reg1 USED_MEM *next; - reg2 USED_MEM **prev; + reg1 MA_USED_MEM *next; + reg2 MA_USED_MEM **prev; Size= ALIGN_SIZE(Size); prev= &mem_root->free; @@ -74,11 +74,11 @@ gptr ma_alloc_root(MEM_ROOT *mem_root, size_t Size) } if (! next) { /* Time to alloc new block */ - get_size= Size+ALIGN_SIZE(sizeof(USED_MEM)); + get_size= Size+ALIGN_SIZE(sizeof(MA_USED_MEM)); if (max_left*4 < mem_root->block_size && get_size < mem_root->block_size) get_size=mem_root->block_size; /* Normal alloc */ - if (!(next = (USED_MEM*) ma_malloc(get_size,MYF(MY_WME | MY_ZEROFILL)))) + if (!(next = (MA_USED_MEM*) ma_malloc(get_size,MYF(MY_WME | MY_ZEROFILL)))) { if (mem_root->error_handler) (*mem_root->error_handler)(); @@ -86,7 +86,7 @@ gptr ma_alloc_root(MEM_ROOT *mem_root, size_t Size) } next->next= *prev; next->size= get_size; - next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM)); + next->left= get_size-ALIGN_SIZE(sizeof(MA_USED_MEM)); *prev=next; } point= (gptr) ((char*) next+ (next->size-next->left)); @@ -102,9 +102,9 @@ gptr ma_alloc_root(MEM_ROOT *mem_root, size_t Size) /* deallocate everything used by ma_alloc_root */ -void ma_free_root(MEM_ROOT *root, myf MyFlags) +void ma_free_root(MA_MEM_ROOT *root, myf MyFlags) { - reg1 USED_MEM *next,*old; + reg1 MA_USED_MEM *next,*old; DBUG_ENTER("ma_free_root"); if (!root) @@ -128,14 +128,14 @@ void ma_free_root(MEM_ROOT *root, myf MyFlags) if (root->pre_alloc) { root->free=root->pre_alloc; - root->free->left=root->pre_alloc->size-ALIGN_SIZE(sizeof(USED_MEM)); + root->free->left=root->pre_alloc->size-ALIGN_SIZE(sizeof(MA_USED_MEM)); root->free->next=0; } DBUG_VOID_RETURN; } -char *ma_strdup_root(MEM_ROOT *root,const char *str) +char *ma_strdup_root(MA_MEM_ROOT *root,const char *str) { size_t len= strlen(str)+1; char *pos; @@ -146,7 +146,7 @@ char *ma_strdup_root(MEM_ROOT *root,const char *str) } -char *ma_memdup_root(MEM_ROOT *root, const char *str, size_t len) +char *ma_memdup_root(MA_MEM_ROOT *root, const char *str, size_t len) { char *pos; if ((pos=ma_alloc_root(root,len))) diff --git a/libmariadb/my_charset.c b/libmariadb/my_charset.c index 325af139..36776fc7 100644 --- a/libmariadb/my_charset.c +++ b/libmariadb/my_charset.c @@ -50,7 +50,7 @@ #include #endif #include -#include +#include #include #include @@ -494,7 +494,7 @@ mysql_mbcharlen_utf32(unsigned int utf32 __attribute((unused))) #define UTF8_MB3 "utf8" /* {{{ mysql_charsets */ -const CHARSET_INFO compiled_charsets[] = +const MARIADB_CHARSET_INFO mariadb_compiled_charsets[] = { { 1, 1, "big5","big5_chinese_ci", "", 950, "BIG5", 1, 2, mysql_mbcharlen_big5, check_mb_big5}, { 3, 1, "dec8", "dec8_swedisch_ci", "", 0, "DEC", 1, 1, NULL, NULL}, @@ -668,9 +668,9 @@ const CHARSET_INFO compiled_charsets[] = /* {{{ mysql_find_charset_nr */ -const CHARSET_INFO * mysql_find_charset_nr(unsigned int charsetnr) +const MARIADB_CHARSET_INFO * mysql_find_charset_nr(unsigned int charsetnr) { - const CHARSET_INFO * c = compiled_charsets; + const MARIADB_CHARSET_INFO * c = mariadb_compiled_charsets; DBUG_ENTER("mysql_find_charset_nr"); do { @@ -686,9 +686,9 @@ const CHARSET_INFO * mysql_find_charset_nr(unsigned int charsetnr) /* {{{ mysql_find_charset_name */ -CHARSET_INFO * mysql_find_charset_name(const char *name) +MARIADB_CHARSET_INFO * mysql_find_charset_name(const char *name) { - CHARSET_INFO *c = (CHARSET_INFO *)compiled_charsets; + MARIADB_CHARSET_INFO *c = (MARIADB_CHARSET_INFO *)mariadb_compiled_charsets; DBUG_ENTER("mysql_find_charset_name"); do { @@ -704,7 +704,7 @@ CHARSET_INFO * mysql_find_charset_name(const char *name) /* {{{ mysql_cset_escape_quotes */ -size_t mysql_cset_escape_quotes(const CHARSET_INFO *cset, char *newstr, +size_t mysql_cset_escape_quotes(const MARIADB_CHARSET_INFO *cset, char *newstr, const char * escapestr, size_t escapestr_len ) { const char *newstr_s = newstr; @@ -758,7 +758,7 @@ size_t mysql_cset_escape_quotes(const CHARSET_INFO *cset, char *newstr, /* {{{ mysql_cset_escape_slashes */ -size_t mysql_cset_escape_slashes(const CHARSET_INFO * cset, char *newstr, +size_t mysql_cset_escape_slashes(const MARIADB_CHARSET_INFO * cset, char *newstr, const char * escapestr, size_t escapestr_len ) { const char *newstr_s = newstr; @@ -1164,8 +1164,8 @@ static void map_charset_name(const char *cs_name, my_bool target_cs, char *buffe @return -1 in case of error, bytes used in the "to" buffer, otherwise */ -size_t STDCALL mariadb_convert_string(const char *from, size_t *from_len, CHARSET_INFO *from_cs, - char *to, size_t *to_len, CHARSET_INFO *to_cs, int *errorcode) +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) { iconv_t conv= 0; size_t rc= -1; diff --git a/libmariadb/my_error.c b/libmariadb/my_error.c index e5b2c2da..15cd8e62 100644 --- a/libmariadb/my_error.c +++ b/libmariadb/my_error.c @@ -19,7 +19,7 @@ #include "mysys_err.h" #include #include -#include +#include /* Define some external variables for error handling */ diff --git a/libmariadb/my_getwd.c b/libmariadb/my_getwd.c index 1cefdec2..59afcece 100644 --- a/libmariadb/my_getwd.c +++ b/libmariadb/my_getwd.c @@ -24,7 +24,7 @@ #include #endif #if defined(MSDOS) || defined(_WIN32) -#include +#include #include #include #endif diff --git a/libmariadb/my_init.c b/libmariadb/my_init.c index bb096159..76ab8a65 100644 --- a/libmariadb/my_init.c +++ b/libmariadb/my_init.c @@ -18,9 +18,9 @@ #include "mysys_priv.h" #include "my_static.h" #include "mysys_err.h" -#include "m_ctype.h" +#include "mariadb_ctype.h" #include -#include +#include #ifdef HAVE_GETRUSAGE #include /* extern int getrusage(int, struct rusage *); */ @@ -28,7 +28,7 @@ #include #ifdef VMS #include -#include +#include #endif #ifdef _WIN32 #ifdef _MSC_VER diff --git a/libmariadb/my_once.c b/libmariadb/my_once.c index f074ad1f..51a476a7 100644 --- a/libmariadb/my_once.c +++ b/libmariadb/my_once.c @@ -32,8 +32,8 @@ gptr my_once_alloc(unsigned int Size, myf MyFlags) { size_t get_size,max_left; gptr point; - reg1 USED_MEM *next; - reg2 USED_MEM **prev; + reg1 MA_USED_MEM *next; + reg2 MA_USED_MEM **prev; Size= ALIGN_SIZE(Size); prev= &ma_once_root_block; @@ -46,11 +46,11 @@ gptr my_once_alloc(unsigned int Size, myf MyFlags) } if (! next) { /* Time to alloc new block */ - get_size= Size+ALIGN_SIZE(sizeof(USED_MEM)); + get_size= Size+ALIGN_SIZE(sizeof(MA_USED_MEM)); if (max_left*4 < ma_once_extra && get_size < ma_once_extra) get_size=ma_once_extra; /* Normal alloc */ - if ((next = (USED_MEM*) malloc(get_size)) == 0) + if ((next = (MA_USED_MEM*) malloc(get_size)) == 0) { my_errno=errno; if (MyFlags & (MY_FAE+MY_WME)) @@ -60,7 +60,7 @@ gptr my_once_alloc(unsigned int Size, myf MyFlags) DBUG_PRINT("test",("my_once_malloc %u byte malloced",get_size)); next->next= 0; next->size= get_size; - next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM)); + next->left= get_size-ALIGN_SIZE(sizeof(MA_USED_MEM)); *prev=next; } point= (gptr) ((char*) next+ (next->size-next->left)); @@ -74,7 +74,7 @@ gptr my_once_alloc(unsigned int Size, myf MyFlags) void my_once_free(void) { - reg1 USED_MEM *next,*old; + reg1 MA_USED_MEM *next,*old; DBUG_ENTER("my_once_free"); for (next=ma_once_root_block ; next ; ) diff --git a/libmariadb/my_static.c b/libmariadb/my_static.c index d24ab174..9020df27 100644 --- a/libmariadb/my_static.c +++ b/libmariadb/my_static.c @@ -57,7 +57,7 @@ ulong ma_default_record_cache_size=RECORD_CACHE_SIZE; const char *ma_soundex_map= "01230120022455012623010202"; /* from ma_malloc */ -USED_MEM* ma_once_root_block=0; /* pointer to first block */ +MA_USED_MEM* ma_once_root_block=0; /* pointer to first block */ uint ma_once_extra=ONCE_ALLOC_INIT; /* Memory to alloc / block */ /* from my_tempnam */ diff --git a/libmariadb/my_static.h b/libmariadb/my_static.h index 5f163df5..344b0030 100644 --- a/libmariadb/my_static.h +++ b/libmariadb/my_static.h @@ -54,7 +54,7 @@ extern struct st_remember _ma_sig_remember[MAX_SIGNALS]; extern const char *ma_soundex_map; -extern USED_MEM* ma_once_root_block; +extern MA_USED_MEM* ma_once_root_block; extern uint ma_once_extra; #if !defined(HAVE_TEMPNAM) || defined(HPUX11) diff --git a/libmariadb/my_stmt.c b/libmariadb/my_stmt.c index 1a8cfc28..b109415c 100644 --- a/libmariadb/my_stmt.c +++ b/libmariadb/my_stmt.c @@ -47,7 +47,7 @@ #include #include #include -#include +#include #include "mysql.h" #include "mysql_priv.h" #include "mysql_version.h" @@ -71,7 +71,7 @@ typedef struct { - MEM_ROOT fields_ma_alloc_root; + MA_MEM_ROOT fields_ma_alloc_root; } MADB_STMT_EXTENSION; static my_bool is_not_null= 0; @@ -913,7 +913,7 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) if (stmt->field_count && !stmt->bind) { - MEM_ROOT *fields_ma_alloc_root= + MA_MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; // ma_free_root(fields_ma_alloc_root, MYF(0)); if (!(stmt->bind= (MYSQL_BIND *)ma_alloc_root(fields_ma_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) @@ -981,7 +981,7 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) static my_bool net_stmt_close(MYSQL_STMT *stmt, my_bool remove) { char stmt_id[STMT_ID_LENGTH]; - MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; + MA_MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; /* clear memory */ ma_free_root(&stmt->result.alloc, MYF(0)); /* allocated in mysql_stmt_store_result */ @@ -1243,7 +1243,7 @@ my_bool mthd_stmt_get_param_metadata(MYSQL_STMT *stmt) my_bool mthd_stmt_get_result_metadata(MYSQL_STMT *stmt) { MYSQL_DATA *result; - MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; + MA_MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; DBUG_ENTER("stmt_read_result_metadata"); if (!(result= stmt->mysql->methods->db_read_rows(stmt->mysql, (MYSQL_FIELD *)0, 7))) @@ -1336,7 +1336,7 @@ int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, size_t lengt /* allocated bind buffer for result */ if (stmt->field_count) { - MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; + MA_MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; if (!(stmt->bind= (MYSQL_BIND *)ma_alloc_root(fields_ma_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); @@ -1436,7 +1436,7 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) static int madb_alloc_stmt_fields(MYSQL_STMT *stmt) { uint i; - MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; + MA_MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; DBUG_ENTER("madb_alloc_stmt_fields"); @@ -1526,7 +1526,7 @@ int stmt_read_execute_response(MYSQL_STMT *stmt) if (!stmt->field_count || mysql->server_status & SERVER_MORE_RESULTS_EXIST) /* fix for ps_bug: test_misc */ { - MEM_ROOT *fields_ma_alloc_root= + MA_MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; uint i; @@ -2049,7 +2049,7 @@ int STDCALL mariadb_stmt_execute_direct(MYSQL_STMT *stmt, /* allocated bind buffer for result */ if (stmt->field_count) { - MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; + MA_MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; if (!(stmt->bind= (MYSQL_BIND *)ma_alloc_root(fields_ma_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); diff --git a/libmariadb/my_stmt_codec.c b/libmariadb/my_stmt_codec.c index 0261195c..09f39443 100644 --- a/libmariadb/my_stmt_codec.c +++ b/libmariadb/my_stmt_codec.c @@ -47,7 +47,7 @@ #include #include #include -#include +#include #include "mysql.h" #define MYSQL_SILENT diff --git a/libmariadb/my_vsnprintf.c b/libmariadb/my_vsnprintf.c index df67204c..754e6099 100644 --- a/libmariadb/my_vsnprintf.c +++ b/libmariadb/my_vsnprintf.c @@ -19,7 +19,7 @@ #include "mysys_err.h" #include #include -#include +#include int ma_snprintf(char* to, size_t n, const char* fmt, ...) diff --git a/libmariadb/str2int.c b/libmariadb/str2int.c index 7f42b028..012e6ecb 100644 --- a/libmariadb/str2int.c +++ b/libmariadb/str2int.c @@ -41,7 +41,7 @@ #include #include "m_string.h" -#include "m_ctype.h" +#include "mariadb_ctype.h" #include "my_sys.h" /* defines errno */ #include diff --git a/libmariadb/strto.c b/libmariadb/strto.c index 097fc012..aed398b8 100644 --- a/libmariadb/strto.c +++ b/libmariadb/strto.c @@ -39,7 +39,7 @@ #define strtoll glob_strtoll /* Fix for True64 */ #include "m_string.h" -#include "m_ctype.h" +#include "mariadb_ctype.h" #include "my_sys.h" /* defines errno */ #include diff --git a/libmariadb/strtoll.c b/libmariadb/strtoll.c index ba72a83f..360126ce 100644 --- a/libmariadb/strtoll.c +++ b/libmariadb/strtoll.c @@ -25,7 +25,7 @@ #define strtoll glob_strtoll /* Fix for True64 */ #include "m_string.h" -#include "m_ctype.h" +#include "mariadb_ctype.h" #include "my_sys.h" /* defines errno */ #include diff --git a/libmariadb/typelib.c b/libmariadb/typelib.c index 72297dcb..aa087a23 100644 --- a/libmariadb/typelib.c +++ b/libmariadb/typelib.c @@ -19,7 +19,7 @@ #include "mysys_priv.h" #include -#include +#include /*************************************************************************** ** Search after a fieldtype. Endspace in x is not compared. diff --git a/unittest/libmariadb/charset.c b/unittest/libmariadb/charset.c index 0226bc18..f84bcc49 100644 --- a/unittest/libmariadb/charset.c +++ b/unittest/libmariadb/charset.c @@ -658,12 +658,12 @@ static int test_bug_54100(MYSQL *mysql) /* We need this internal function for the test */ -CHARSET_INFO * mysql_find_charset_name(const char *name); +MARIADB_CHARSET_INFO * mysql_find_charset_name(const char *name); static int test_utf16_utf32_noboms(MYSQL *mysql) { char *csname[]= {"utf16", "utf16le", "utf32", "utf8"}; - CHARSET_INFO *csinfo[sizeof(csname)/sizeof(char*)]; + MARIADB_CHARSET_INFO *csinfo[sizeof(csname)/sizeof(char*)]; const int UTF8= sizeof(csname)/sizeof(char*) - 1; diff --git a/unittest/libmariadb/dyncol.c b/unittest/libmariadb/dyncol.c index 6d39fea3..185b034d 100644 --- a/unittest/libmariadb/dyncol.c +++ b/unittest/libmariadb/dyncol.c @@ -39,7 +39,7 @@ static int create_dyncol_named(MYSQL *mysql) vals[i].type= DYN_COL_STRING; vals[i].x.string.value.str= strval[i]; vals[i].x.string.value.length= strlen(strval[i]); - vals[i].x.string.charset= (CHARSET_INFO *)mysql->charset; + vals[i].x.string.charset= (MARIADB_CHARSET_INFO *)mysql->charset; diag("%s", keys3[i].str); } @@ -132,7 +132,7 @@ static int create_dyncol_num(MYSQL *mysql) vals[i].type= DYN_COL_STRING; vals[i].x.string.value.str= strval[i]; vals[i].x.string.value.length= strlen(strval[i]); - vals[i].x.string.charset= (CHARSET_INFO *)mysql->charset; + vals[i].x.string.charset= (MARIADB_CHARSET_INFO *)mysql->charset; } FAIL_IF(mariadb_dyncol_create_many_num(&dyncol, column_count, keys1, vals, 1) <0, "Error (keys1)"); @@ -176,7 +176,7 @@ static int mdev_x1(MYSQL *mysql) vals[i].type= DYN_COL_STRING; vals[i].x.string.value.str= strval[i]; vals[i].x.string.value.length= strlen(strval[i]); - vals[i].x.string.charset= (CHARSET_INFO *)mysql->charset; + vals[i].x.string.charset= (MARIADB_CHARSET_INFO *)mysql->charset; } mariadb_dyncol_init(&dynstr); diff --git a/unittest/libmariadb/misc.c b/unittest/libmariadb/misc.c index dd156fe8..993141de 100644 --- a/unittest/libmariadb/misc.c +++ b/unittest/libmariadb/misc.c @@ -1030,7 +1030,7 @@ static int test_get_info(MYSQL *mysql) char *cval; int rc; MY_CHARSET_INFO cs; - CHARSET_INFO *ci; + MARIADB_CHARSET_INFO *ci; char **errors; rc= mariadb_get_infov(mysql, MARIADB_MAX_ALLOWED_PACKET, &sval); @@ -1045,7 +1045,7 @@ static int test_get_info(MYSQL *mysql) rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_VERSION_ID, &sval); FAIL_IF(rc, "mysql_get_info failed"); diag("server_version_id: %d", sval); - rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_CHARSET_INFO, &cs); + rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_MARIADB_CHARSET_INFO, &cs); FAIL_IF(rc, "mysql_get_info failed"); diag("charset name: %s", cs.csname); rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_PVIO_TYPE, &ival); diff --git a/unittest/libmariadb/my_test.h b/unittest/libmariadb/my_test.h index 2c7d744b..b8816a17 100644 --- a/unittest/libmariadb/my_test.h +++ b/unittest/libmariadb/my_test.h @@ -165,7 +165,7 @@ int do_verify_prepare_field(MYSQL_RES *result, const char *file, int line) { MYSQL_FIELD *field; -/* CHARSET_INFO *cs; */ +/* MARIADB_CHARSET_INFO *cs; */ FAIL_IF(!(field= mysql_fetch_field_direct(result, no)), "FAILED to get result"); /* cs= mysql_find_charset_nr(field->charsetnr); From 9e4bd29447d3cf7b13760711a03feb5d180ad7c1 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Wed, 3 Feb 2016 09:14:01 +0100 Subject: [PATCH 20/39] More fixes and renames for 10.2 integration --- CMakeLists.txt | 1 - include/mysql.h | 6 +++--- include/mysql_com.h | 2 +- libmariadb/libmariadb.c | 4 ++-- libmariadb/mysql_async.c | 14 +++++++------- libmariadb/net.c | 2 +- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ca25fc6f..7c0e79ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,6 @@ IF(WITH_SIGNCODE) MARK_AS_ADVANCED(SIGN_OPTIONS) ENDIF() - IF(WITH_RTC) SET(RTC_OPTIONS "/RTC1 /RTCc") ENDIF() diff --git a/include/mysql.h b/include/mysql.h index a90bbd54..851e2069 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -134,7 +134,7 @@ extern unsigned int mariadb_deinitialize_ssl; } /* For mysql_async.c */ -#define set_mysql_error(A,B,C) SET_CLIENT_ERROR((A),(B),(C),0) +#define set_mariadb_error(A,B,C) SET_CLIENT_ERROR((A),(B),(C),0) #define unknown_sqlstate SQLSTATE_UNKNOWN #define CLEAR_CLIENT_ERROR(a) \ @@ -337,7 +337,7 @@ struct st_mysql_options { my_bool unused_2; void *unused_3, *unused_4, *unused_5, *unused_6; LIST *stmts; - const struct st_mysql_methods *methods; + const struct st_mariadb_methods *methods; void *thd; my_bool *unbuffered_fetch_owner; char *info_buffer; @@ -762,7 +762,7 @@ struct st_mariadb_api { }; /* these methods can be overwritten by db plugins */ -struct st_mysql_methods { +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); diff --git a/include/mysql_com.h b/include/mysql_com.h index 0cbc7817..704c19fc 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -345,7 +345,7 @@ int my_net_init(NET *net, MARIADB_PVIO *pvio); void net_end(NET *net); void net_clear(NET *net); int net_flush(NET *net); -int my_net_write(NET *net,const char *packet, size_t len); +int my_net_write(NET *net,const unsigned char *packet, size_t len); int net_write_command(NET *net,unsigned char command,const char *packet, size_t len); int net_real_write(NET *net,const char *packet, size_t len); diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index 0cc65506..f44cd4a7 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -119,7 +119,7 @@ my_string mysql_unix_port=0; #define CONNECT_TIMEOUT 0 #endif -struct st_mysql_methods MARIADB_DEFAULT_METHODS; +struct st_mariadb_methods MARIADB_DEFAULT_METHODS; #if defined(MSDOS) || defined(_WIN32) // socket_errno is defined in my_global.h for all platforms @@ -3994,7 +3994,7 @@ struct st_mariadb_api MARIADB_API= * stored in mysql->methods and can be overwritten by * a plugin, e.g. for using another database */ -struct st_mysql_methods MARIADB_DEFAULT_METHODS = { +struct st_mariadb_methods MARIADB_DEFAULT_METHODS = { /* open a connection */ mthd_my_real_connect, /* close connection */ diff --git a/libmariadb/mysql_async.c b/libmariadb/mysql_async.c index f7dfc998..3729e79c 100644 --- a/libmariadb/mysql_async.c +++ b/libmariadb/mysql_async.c @@ -250,7 +250,7 @@ mysql_get_timeout_value_ms(const MYSQL *mysql) } \ if (res < 0) \ { \ - set_mysql_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ + set_mariadb_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ *ret= err_val; \ } \ else \ @@ -263,7 +263,7 @@ mysql_get_timeout_value_ms(const MYSQL *mysql) (mysql_val)->options.extension->async_context; \ if (!b->suspended) \ { \ - set_mysql_error((mysql_val), CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); \ + set_mariadb_error((mysql_val), CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); \ *ret= err_val; \ return 0; \ } \ @@ -277,7 +277,7 @@ mysql_get_timeout_value_ms(const MYSQL *mysql) b->suspended= 0; \ if (res < 0) \ { \ - set_mysql_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ + set_mariadb_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ *ret= err_val; \ } \ else \ @@ -311,7 +311,7 @@ mysql_get_timeout_value_ms(const MYSQL *mysql) return b->events_to_wait_for; \ } \ if (res < 0) \ - set_mysql_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ + set_mariadb_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ return 0; #define MK_ASYNC_CONT_BODY_VOID_RETURN(mysql_val) \ @@ -320,7 +320,7 @@ mysql_get_timeout_value_ms(const MYSQL *mysql) (mysql_val)->options.extension->async_context; \ if (!b->suspended) \ { \ - set_mysql_error((mysql_val), CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); \ + set_mariadb_error((mysql_val), CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); \ return 0; \ } \ \ @@ -332,7 +332,7 @@ mysql_get_timeout_value_ms(const MYSQL *mysql) return b->events_to_wait_for; /* (Still) suspended */ \ b->suspended= 0; \ if (res < 0) \ - set_mysql_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ + set_mariadb_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ return 0; @@ -432,7 +432,7 @@ mysql_real_query_start(int *ret, MYSQL *mysql, const char *stmt_str, size_t leng } if (res < 0) { - set_mysql_error((mysql), CR_OUT_OF_MEMORY, unknown_sqlstate); + set_mariadb_error((mysql), CR_OUT_OF_MEMORY, unknown_sqlstate); *ret= 1; } else diff --git a/libmariadb/net.c b/libmariadb/net.c index 7e0161d4..4511f9ec 100644 --- a/libmariadb/net.c +++ b/libmariadb/net.c @@ -235,7 +235,7 @@ int net_flush(NET *net) */ int -my_net_write(NET *net, const char *packet, size_t len) +my_net_write(NET *net, const uchar *packet, size_t len) { uchar buff[NET_HEADER_SIZE]; while (len >= MAX_PACKET_LENGTH) From 79d0b2946b5fa9059baf046b0c98a9a037379713 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Wed, 3 Feb 2016 11:53:39 +0100 Subject: [PATCH 21/39] More 10.2 fixes for integration --- include/my_stmt.h | 2 +- include/mysql_com.h | 18 ++++++++++++++++-- libmariadb/CMakeLists.txt | 2 ++ libmariadb/libmariadb.c | 32 ++++++++++++++++---------------- libmariadb/my_thr_init.c | 8 ++------ plugins/auth/my_auth.c | 2 +- 6 files changed, 38 insertions(+), 26 deletions(-) diff --git a/include/my_stmt.h b/include/my_stmt.h index 4cf2863c..cfe4d8d9 100644 --- a/include/my_stmt.h +++ b/include/my_stmt.h @@ -219,7 +219,7 @@ extern MYSQL_PS_CONVERSION mysql_ps_fetch_functions[MYSQL_TYPE_GEOMETRY + 1]; unsigned long net_safe_read(MYSQL *mysql); void mysql_init_ps_subsystem(void); unsigned long net_field_length(unsigned char **packet); -int simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, +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 diff --git a/include/mysql_com.h b/include/mysql_com.h index 704c19fc..15e0043c 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -223,6 +223,12 @@ enum enum_server_command #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; @@ -295,6 +301,14 @@ enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY, 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_NEWDECIMAL=246, MYSQL_TYPE_ENUM=247, MYSQL_TYPE_SET=248, @@ -349,7 +363,7 @@ int my_net_write(NET *net,const unsigned char *packet, size_t len); int net_write_command(NET *net,unsigned char command,const char *packet, size_t len); int net_real_write(NET *net,const char *packet, size_t len); -unsigned long my_net_read(NET *net); +extern unsigned long my_net_read(NET *net); struct rand_struct { unsigned long seed1,seed2,max_value; @@ -358,7 +372,7 @@ struct rand_struct { /* The following is for user defined functions */ -enum Item_result {STRING_RESULT,REAL_RESULT,INT_RESULT}; +enum Item_result {STRING_RESULT,REAL_RESULT,INT_RESULT,ROW_RESULT,DECIMAL_RESULT}; typedef struct st_udf_args { diff --git a/libmariadb/CMakeLists.txt b/libmariadb/CMakeLists.txt index 02f6cfd0..4a98e29d 100644 --- a/libmariadb/CMakeLists.txt +++ b/libmariadb/CMakeLists.txt @@ -415,6 +415,8 @@ IF(CMAKE_SYSTEM_NAME MATCHES "Linux") TARGET_LINK_LIBRARIES (mariadbclient "-Wl,--version-script=${EXPORT_FILE}") ENDIF() +SET_TARGET_PROPERTIES(mariadbclient PROPERTIES INTERFACE_LINK_LIBRARIES "${SYSTEM_LIBS}") + SET_TARGET_PROPERTIES(libmariadb PROPERTIES PREFIX "") SET_TARGET_PROPERTIES(libmariadb PROPERTIES VERSION diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index f44cd4a7..5e3fe709 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -436,7 +436,7 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg, } int -simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, +ma_simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, size_t length, my_bool skipp_check, void *opt_arg) { return mysql->methods->db_command(mysql, command, arg, length, skipp_check, opt_arg); @@ -1913,7 +1913,7 @@ mysql_select_db(MYSQL *mysql, const char *db) DBUG_ENTER("mysql_select_db"); DBUG_PRINT("enter",("db: '%s'",db)); - if ((error=simple_command(mysql, COM_INIT_DB,db,(uint) strlen(db),0,0))) + if ((error=ma_simple_command(mysql, COM_INIT_DB,db,(uint) strlen(db),0,0))) DBUG_RETURN(error); ma_free(mysql->db); mysql->db=ma_strdup(db,MYF(MY_WME)); @@ -2021,7 +2021,7 @@ void mysql_close_slow_part(MYSQL *mysql) mysql->status=MYSQL_STATUS_READY; /* Force command */ mysql->options.reconnect=0; if (mysql->net.pvio && mysql->net.buff) - simple_command(mysql, COM_QUIT,NullS,0,1,0); + ma_simple_command(mysql, COM_QUIT,NullS,0,1,0); end_server(mysql); } } @@ -2083,7 +2083,7 @@ mysql_query(MYSQL *mysql, const char *query) int STDCALL mysql_send_query(MYSQL* mysql, const char* query, size_t length) { - return simple_command(mysql, COM_QUERY, query, length, 1,0); + return ma_simple_command(mysql, COM_QUERY, query, length, 1,0); } int mthd_my_read_query_result(MYSQL *mysql) @@ -2159,7 +2159,7 @@ mysql_real_query(MYSQL *mysql, const char *query, size_t length) free_old_query(mysql); - if (simple_command(mysql, COM_QUERY,query,length,1,0)) + if (ma_simple_command(mysql, COM_QUERY,query,length,1,0)) DBUG_RETURN(-1); if (!is_multi) DBUG_RETURN(mysql->methods->db_read_query_result(mysql)); @@ -2435,7 +2435,7 @@ mysql_list_fields(MYSQL *mysql, const char *table, const char *wild) LINT_INIT(query); end=strmake(strmake(buff, table,128)+1,wild ? wild : "",128); - if (simple_command(mysql, COM_FIELD_LIST,buff,(uint) (end-buff),1,0) || + if (ma_simple_command(mysql, COM_FIELD_LIST,buff,(uint) (end-buff),1,0) || !(query = mysql->methods->db_read_rows(mysql,(MYSQL_FIELD*) 0,8))) DBUG_RETURN(NULL); @@ -2468,7 +2468,7 @@ mysql_list_processes(MYSQL *mysql) DBUG_ENTER("mysql_list_processes"); LINT_INIT(fields); - if (simple_command(mysql, COM_PROCESS_INFO,0,0,0,0)) + if (ma_simple_command(mysql, COM_PROCESS_INFO,0,0,0,0)) DBUG_RETURN(0); free_old_query(mysql); pos=(uchar*) mysql->net.read_pos; @@ -2491,7 +2491,7 @@ mysql_shutdown(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level) uchar s_level[2]; DBUG_ENTER("mysql_shutdown"); s_level[0]= (uchar)shutdown_level; - DBUG_RETURN(simple_command(mysql, COM_SHUTDOWN, (char *)s_level, 1, 0, 0)); + DBUG_RETURN(ma_simple_command(mysql, COM_SHUTDOWN, (char *)s_level, 1, 0, 0)); } int STDCALL @@ -2500,7 +2500,7 @@ mysql_refresh(MYSQL *mysql,uint options) uchar bits[1]; DBUG_ENTER("mysql_refresh"); bits[0]= (uchar) options; - DBUG_RETURN(simple_command(mysql, COM_REFRESH,(char*) bits,1,0,0)); + DBUG_RETURN(ma_simple_command(mysql, COM_REFRESH,(char*) bits,1,0,0)); } int STDCALL @@ -2510,7 +2510,7 @@ mysql_kill(MYSQL *mysql,ulong pid) DBUG_ENTER("mysql_kill"); int4store(buff,pid); /* if we kill our own thread, reading the response packet will fail */ - DBUG_RETURN(simple_command(mysql, COM_PROCESS_KILL,buff,4,0,0)); + DBUG_RETURN(ma_simple_command(mysql, COM_PROCESS_KILL,buff,4,0,0)); } @@ -2518,14 +2518,14 @@ int STDCALL mysql_dump_debug_info(MYSQL *mysql) { DBUG_ENTER("mysql_dump_debug_info"); - DBUG_RETURN(simple_command(mysql, COM_DEBUG,0,0,0,0)); + DBUG_RETURN(ma_simple_command(mysql, COM_DEBUG,0,0,0,0)); } char * STDCALL mysql_stat(MYSQL *mysql) { DBUG_ENTER("mysql_stat"); - if (simple_command(mysql, COM_STATISTICS,0,0,0,0)) + if (ma_simple_command(mysql, COM_STATISTICS,0,0,0,0)) return mysql->net.last_error; mysql->net.read_pos[mysql->packet_length]=0; /* End of stat string */ if (!mysql->net.read_pos[0]) @@ -2541,11 +2541,11 @@ mysql_ping(MYSQL *mysql) { int rc; DBUG_ENTER("mysql_ping"); - rc= simple_command(mysql, COM_PING,0,0,0,0); + rc= ma_simple_command(mysql, COM_PING,0,0,0,0); /* if connection was terminated and reconnect is true, try again */ if (rc!=0 && mysql->options.reconnect) - rc= simple_command(mysql, COM_PING,0,0,0,0); + rc= ma_simple_command(mysql, COM_PING,0,0,0,0); return rc; } @@ -2634,7 +2634,7 @@ int mariadb_flush_multi_command(MYSQL *mysql) int rc; size_t length= mysql->net.mbuff_pos - mysql->net.mbuff; - rc= simple_command(mysql, COM_MULTI, mysql->net.mbuff, + rc= ma_simple_command(mysql, COM_MULTI, mysql->net.mbuff, length, 1, 0); /* reset multi_buff */ mysql->net.mbuff_pos= mysql->net.mbuff; @@ -3574,7 +3574,7 @@ int STDCALL mysql_set_server_option(MYSQL *mysql, char buffer[2]; DBUG_ENTER("mysql_set_server_option"); int2store(buffer, (uint)option); - DBUG_RETURN(simple_command(mysql, COM_SET_OPTION, buffer, sizeof(buffer), 0, 0)); + DBUG_RETURN(ma_simple_command(mysql, COM_SET_OPTION, buffer, sizeof(buffer), 0, 0)); } ulong STDCALL mysql_get_client_version(void) diff --git a/libmariadb/my_thr_init.c b/libmariadb/my_thr_init.c index bef301dc..12bb0b48 100644 --- a/libmariadb/my_thr_init.c +++ b/libmariadb/my_thr_init.c @@ -147,12 +147,8 @@ void ma_thread_end(void) if (tmp && tmp->initialized) { -#ifdef HAVE_OPENSSL -#if OPENSSL_VERSION_NUMBER >= 0x10000001L - ERR_remove_thread_state(NULL); -#else - ERR_remove_state(0); -#endif +#ifdef HAVE_NSSL + ma_ssl_end(); #endif #if !defined(DBUG_OFF) if (tmp->dbug) diff --git a/plugins/auth/my_auth.c b/plugins/auth/my_auth.c index 053167c5..2753284e 100644 --- a/plugins/auth/my_auth.c +++ b/plugins/auth/my_auth.c @@ -141,7 +141,7 @@ static int send_change_user_packet(MCPVIO_EXT *mpvio, end= ma_send_connect_attr(mysql, end); - res= simple_command(mysql, COM_CHANGE_USER, + res= ma_simple_command(mysql, COM_CHANGE_USER, buff, (ulong)(end-buff), 1, NULL); error: From ad58fa7868419e0213a45b530c3bd70df6778b22 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Thu, 4 Feb 2016 13:11:44 +0100 Subject: [PATCH 22/39] More cleanup for 10.2 integration --- CMakeLists.txt | 2 + client/ma_plugin_info.c | 6 +- include/m_string.h | 10 +- include/my_sys.h | 11 - libmariadb/CMakeLists.txt | 13 -- libmariadb/array.c | 22 +- libmariadb/client_plugin.c.in | 10 +- libmariadb/dbug.c | 3 +- libmariadb/default.c | 20 +- libmariadb/libmariadb.c | 380 ++++++++++++++-------------------- libmariadb/list.c | 6 +- libmariadb/ma_dyncol.c | 32 +-- libmariadb/ma_io.c | 20 +- libmariadb/ma_pvio.c | 14 +- libmariadb/ma_ssl.c | 5 +- libmariadb/mf_dirname.c | 2 +- libmariadb/mf_format.c | 8 +- libmariadb/mf_loadpath.c | 4 +- libmariadb/mf_pack.c | 8 +- libmariadb/mf_path.c | 5 +- libmariadb/mulalloc.c | 53 ----- libmariadb/my_alloc.c | 11 +- libmariadb/my_compress.c | 14 +- libmariadb/my_fopen.c | 7 +- libmariadb/my_getwd.c | 10 +- libmariadb/my_init.c | 2 +- libmariadb/my_lib.c | 21 +- libmariadb/my_loaddata.c | 8 +- libmariadb/my_malloc.c | 101 --------- libmariadb/my_messnc.c | 5 +- libmariadb/my_net.c | 2 +- libmariadb/my_open.c | 2 +- libmariadb/my_realloc.c | 65 ------ libmariadb/my_stmt.c | 35 ++-- libmariadb/my_stmt_codec.c | 9 +- libmariadb/my_symlink.c | 8 +- libmariadb/my_thr_init.c | 2 +- libmariadb/net.c | 20 +- libmariadb/strcend.c | 48 ----- libmariadb/strend.c | 50 ----- libmariadb/strfill.c | 36 ---- libmariadb/string.c | 10 +- libmariadb/strinstr.c | 50 ----- libmariadb/strmake.c | 54 ----- libmariadb/strmov.c | 59 ------ libmariadb/strnlen.c | 36 ---- libmariadb/strnmov.c | 36 ---- libmariadb/strxmov.c | 50 ----- libmariadb/strxnmov.c | 48 ----- plugins/auth/my_auth.c | 24 +-- plugins/pvio/pvio_socket.c | 7 +- 51 files changed, 346 insertions(+), 1118 deletions(-) delete mode 100644 libmariadb/mulalloc.c delete mode 100644 libmariadb/my_malloc.c delete mode 100644 libmariadb/my_realloc.c delete mode 100644 libmariadb/strcend.c delete mode 100644 libmariadb/strend.c delete mode 100644 libmariadb/strfill.c delete mode 100644 libmariadb/strinstr.c delete mode 100644 libmariadb/strmake.c delete mode 100644 libmariadb/strmov.c delete mode 100644 libmariadb/strnlen.c delete mode 100644 libmariadb/strnmov.c delete mode 100644 libmariadb/strxmov.c delete mode 100644 libmariadb/strxnmov.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c0e79ba..8abe14fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,8 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8 FATAL_ERROR) ENDIF() IF(COMMAND CMAKE_POLICY) CMAKE_POLICY(SET CMP0003 NEW) + CMAKE_POLICY(SET CMP0022 NEW) + CMAKE_POLICY(SET CMP0023 NEW) ENDIF() #Allow access to non existing targets diff --git a/client/ma_plugin_info.c b/client/ma_plugin_info.c index 11ea9888..5edc5228 100644 --- a/client/ma_plugin_info.c +++ b/client/ma_plugin_info.c @@ -115,8 +115,10 @@ static void show_file(char *filename) char *has_so_ext= strstr(filename, SO_EXT); if (!strchr(filename, FN_LIBCHAR)) - strxnmov(dlpath, sizeof(dlpath) - 1, - (env_plugin_dir) ? env_plugin_dir : PLUGINDIR, "/", filename, has_so_ext ? "" : SO_EXT, NullS); + 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))) diff --git a/include/m_string.h b/include/m_string.h index 197a8e33..39e23798 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -88,6 +88,10 @@ extern "C" { #if defined(HAVE_STPCPY) && !defined(HAVE_mit_thread) #define strmov(A,B) stpcpy((A),(B)) +#define strnmov(A,B,C) stpncpy((A),(B),(C)) +#else +#define strmov(A,B) (strcpy((A),(B)) + strlen((B)); +#define strnmov(A,B,C) (strncpy((A),(B),(C)) + strlen((B)); #endif extern char NEAR _dig_vec[]; /* Declared in int2str() */ @@ -139,7 +143,7 @@ extern void bmove_upp(char *dst,const char *src, size_t len); extern void bchange(char *dst, size_t old_len, const char *src, size_t new_len, size_t tot_len); extern void strappend(char *s,size_t len,pchar fill); -extern char *strend(const char *s); +#define strend(s) strchr((s),'\0') extern char *strcend(const char *, char); extern char *strfield(char *src,int fields,int chars,int blanks, int tabch); @@ -152,10 +156,6 @@ extern char *strmake(char *dst,const char *src, size_t length); extern char *strmake_overlapp(char *dst,const char *src, size_t length); #endif -#ifndef strmov -extern char *strmov(char *dst,const char *src); -#endif -extern char *strnmov(char *dst,const char *src,uint n); extern char *strsuff(const char *src,const char *suffix); extern char *strcont(const char *src,const char *set); extern char *strxcat _VARARGS((char *dst,const char *src, ...)); diff --git a/include/my_sys.h b/include/my_sys.h index e77626df..1b4eb35e 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -119,14 +119,7 @@ extern int NEAR my_errno; /* Last error in mysys */ #define TERMINATE(A) {} #define QUICK_SAFEMALLOC #define NORMAL_SAFEMALLOC -extern gptr ma_malloc(size_t Size,myf MyFlags); #define ma_malloc_ci(SZ,FLAG) ma_malloc( SZ, FLAG ) -extern gptr ma_realloc(gptr oldpoint, size_t Size,myf MyFlags); -extern void my_no_flags_free(void *ptr); -extern gptr ma_memdup(const unsigned char *from, size_t length,myf MyFlags); -extern my_string ma_strdup(const char *from,myf MyFlags); -extern my_string ma_strndup(const char *from, size_t length, myf MyFlags); -#define ma_free(PTR) my_no_flags_free(PTR) #define CALLER_INFO_PROTO /* nothing */ #define CALLER_INFO /* nothing */ #define ORIG_CALLER_INFO /* nothing */ @@ -423,10 +416,6 @@ extern gptr _myrealloc(gptr pPtr,size_t uSize,const char *sFile, extern gptr my_multi_malloc _VARARGS((myf MyFlags, ...)); extern void _myfree(gptr pPtr,const char *sFile,uint uLine, myf MyFlag); extern int _sanity(const char *sFile,unsigned int uLine); -extern gptr _ma_memdup(const unsigned char *from, size_t length, - const char *sFile, uint uLine,myf MyFlag); -extern my_string _ma_strdup(const char *from, const char *sFile, uint uLine, - myf MyFlag); #ifndef TERMINATE extern void TERMINATE(FILE *file); #endif diff --git a/libmariadb/CMakeLists.txt b/libmariadb/CMakeLists.txt index 4a98e29d..020ec597 100644 --- a/libmariadb/CMakeLists.txt +++ b/libmariadb/CMakeLists.txt @@ -291,7 +291,6 @@ mf_pack.c mf_path.c mf_unixpath.c mf_wcomp.c -mulalloc.c my_alloc.c my_compress.c my_context.c @@ -302,13 +301,11 @@ my_fstream.c my_getwd.c my_init.c my_lib.c -my_malloc.c my_messnc.c my_net.c my_once.c my_port.c my_pthread.c -my_realloc.c my_seek.c my_static.c my_symlink.c @@ -317,19 +314,9 @@ my_write.c mysql_async.c password.c str2int.c -strcend.c -strcont.c -strend.c -strfill.c string.c -strinstr.c -strmake.c -strmov.c -strnmov.c strtoll.c strtoull.c -strxmov.c -strxnmov.c thr_mutex.c typelib.c sha1.c diff --git a/libmariadb/array.c b/libmariadb/array.c index 14521b34..659bec62 100644 --- a/libmariadb/array.c +++ b/libmariadb/array.c @@ -21,6 +21,7 @@ #include "mysys_priv.h" #include "m_string.h" +#include /* Initiate array and alloc space for init_alloc elements. Array is usable @@ -44,7 +45,7 @@ my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size, array->max_element=init_alloc; array->alloc_increment=alloc_increment; array->size_of_element=element_size; - if (!(array->buffer=(char*) ma_malloc_ci(element_size*init_alloc,MYF(MY_WME)))) + if (!(array->buffer=(char*) malloc(element_size*init_alloc))) { array->max_element=0; DBUG_RETURN(TRUE); @@ -78,10 +79,9 @@ unsigned char *ma_alloc_dynamic(DYNAMIC_ARRAY *array) if (array->elements == array->max_element) { char *new_ptr; - if (!(new_ptr=(char*) ma_realloc(array->buffer,(array->max_element+ - array->alloc_increment)* - array->size_of_element, - MYF(MY_WME | MY_ALLOW_ZERO_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; @@ -110,9 +110,8 @@ my_bool ma_set_dynamic(DYNAMIC_ARRAY *array, gptr element, uint idx) char *new_ptr; size=(idx+array->alloc_increment)/array->alloc_increment; size*= array->alloc_increment; - if (!(new_ptr=(char*) ma_realloc(array->buffer,size* - array->size_of_element, - MYF(MY_WME | MY_ALLOW_ZERO_PTR)))) + if (!(new_ptr=(char*) realloc(array->buffer,size* + array->size_of_element))) return TRUE; array->buffer=new_ptr; array->max_element=size; @@ -145,7 +144,7 @@ void ma_delete_dynamic(DYNAMIC_ARRAY *array) { if (array->buffer) { - ma_free(array->buffer); + free(array->buffer); array->buffer=0; array->elements=array->max_element=0; } @@ -167,9 +166,8 @@ void ma_freeze_size(DYNAMIC_ARRAY *array) if (array->buffer && array->max_element != elements) { - array->buffer=(char*) ma_realloc(array->buffer, - elements*array->size_of_element, - MYF(MY_WME)); + array->buffer=(char*) realloc(array->buffer, + elements*array->size_of_element); array->max_element=elements; } } diff --git a/libmariadb/client_plugin.c.in b/libmariadb/client_plugin.c.in index 6ae48243..bef791f4 100644 --- a/libmariadb/client_plugin.c.in +++ b/libmariadb/client_plugin.c.in @@ -250,16 +250,16 @@ static void load_env_plugins(MYSQL *mysql) if (!s) return; - free_env= plugs= ma_strdup(s, MYF(MY_WME)); + free_env= plugs= strdup(s); do { - if ((s= strchr(plugs, ';'))) + if (s= strchr(plugs, ';')) *s= '\0'; mysql_load_plugin(mysql, plugs, -1, 0); plugs= s + 1; } while (s); - ma_free(free_env); + free(free_env); } /********** extern functions to be used by libmariadb *********************/ @@ -391,11 +391,11 @@ mysql_load_plugin_v(MYSQL *mysql, const char *name, int type, } /* Compile dll path */ - strxnmov(dlpath, sizeof(dlpath) - 1, + 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 : PLUGINDIR, "/", - name, SO_EXT, NullS); + name, SO_EXT); /* Open new dll handle */ if (!(dlhandle= dlopen((const char *)dlpath, RTLD_NOW))) diff --git a/libmariadb/dbug.c b/libmariadb/dbug.c index df15301f..27040d87 100644 --- a/libmariadb/dbug.c +++ b/libmariadb/dbug.c @@ -99,6 +99,7 @@ #include #else #include +#include #endif extern int ma_snprintf(char* to, size_t n, const char* fmt, ...); @@ -2032,7 +2033,7 @@ static void DBUGOpenFile(CODE_STATE *cs, cs->stack->name[len]=0; } else - strmov(cs->stack->name,name); + strcpy(cs->stack->name,name); name=cs->stack->name; if (strcmp(name, "-") == 0) { diff --git a/libmariadb/default.c b/libmariadb/default.c index 573bb126..b538e41a 100644 --- a/libmariadb/default.c +++ b/libmariadb/default.c @@ -237,15 +237,15 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MA_MEM_ROOT *alloc, return 0; /* Ignore wrong paths */ if (dir) { - strmov(name,dir); + strcpy(name,dir); convert_dirname(name); if (dir[0] == FN_HOMELIB) /* Add . to filenames in home */ strcat(name,"."); - strxmov(strend(name),config_file,ext,NullS); + strcat(strcat(name, config_file), ext); } else { - strmov(name,config_file); + strcpy(name,config_file); } fn_format(name,name,"","",4); #if !defined(_WIN32) && !defined(OS2) @@ -261,7 +261,7 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MA_MEM_ROOT *alloc, } } #endif - if (!(file = ma_open(fn_format(name,name,"","",4),"r", NULL))) + if (!(file = ma_open(name,"r", NULL))) return 0; } else { @@ -307,13 +307,13 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MA_MEM_ROOT *alloc, if (!read_values) continue; if (!(end=value=strchr(ptr,'='))) - end=strend(ptr); /* Option without argument */ + end=strchr(ptr, '\0'); /* Option without argument */ for ( ; isspace(end[-1]) ; end--) ; if (!value) { if (!(tmp=ma_alloc_root(alloc,(uint) (end-ptr)+3))) goto err; - strmake(strmov(tmp,"--"),ptr,(uint) (end-ptr)); + strncpy(strmov(tmp,"--"),ptr,(uint) (end-ptr)); if (ma_insert_dynamic(args,(gptr) &tmp)) goto err; } @@ -322,7 +322,7 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MA_MEM_ROOT *alloc, /* Remove pre- and end space */ char *value_end; for (value++ ; isspace(*value); value++) ; - value_end=strend(value); + value_end=strchr(value, '\0'); for ( ; isspace(value_end[-1]) ; value_end--) ; /* remove possible quotes */ if (*value == '\'' || *value == '\"') @@ -414,15 +414,15 @@ void ma_print_defaults(const char *conf_file, const char **groups) for (dirs=default_directories ; *dirs; dirs++) { if (**dirs) - strmov(name,*dirs); + strcpy(name,*dirs); else if (defaults_extra_file) - strmov(name,defaults_extra_file); + strcpy(name,defaults_extra_file); else continue; convert_dirname(name); if (name[0] == FN_HOMELIB) /* Add . to filenames in home */ strcat(name,"."); - strxmov(strend(name),conf_file,default_ext," ",NullS); + strcat(strcat(strcat(name, conf_file), default_ext), " "); fputs(name,stdout); } puts(""); diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index 5e3fe709..14113fa1 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -225,15 +225,15 @@ restart: net->last_errno= last_errno; if (pos[0]== '#') { - strmake(net->sqlstate, pos+1, SQLSTATE_LENGTH); + strncpy(net->sqlstate, pos+1, SQLSTATE_LENGTH); pos+= SQLSTATE_LENGTH + 1; } else { - strmov(net->sqlstate, SQLSTATE_UNKNOWN); + strcpy(net->sqlstate, SQLSTATE_UNKNOWN); } - (void) strmake(net->last_error,(char*) pos, - min(len,sizeof(net->last_error)-1)); + strncpy(net->last_error,(char*) pos, + min(len,sizeof(net->last_error)-1)); } else { @@ -351,7 +351,7 @@ void free_rows(MYSQL_DATA *cur) if (cur) { ma_free_root(&cur->alloc,MYF(0)); - ma_free(cur); + free(cur); } } @@ -477,11 +477,11 @@ void read_user_name(char *name) !(str=getenv("LOGIN"))) str="UNKNOWN_USER"; } - (void) strmake(name,str,USERNAME_LENGTH); + strncpy(name,str,USERNAME_LENGTH); #elif HAVE_CUSERID (void) cuserid(name); #else - strmov(name,"UNKNOWN_USER"); + strncpy(name,"UNKNOWN_USER", USERNAME_LENGTH); #endif } DBUG_VOID_RETURN; @@ -492,7 +492,7 @@ void read_user_name(char *name) void read_user_name(char *name) { char *str=getenv("USERNAME"); /* ODBC will send user variable */ - strmake(name,str ? str : "ODBC", USERNAME_LENGTH); + strncpy(name,str ? str : "ODBC", USERNAME_LENGTH); } #endif @@ -564,7 +564,7 @@ mysql_debug(const char *debug __attribute__((unused))) #else { char buff[80]; - strmov(strmov(buff,"libmariadb: "),env); + strcpy(strmov(buff,"libmariadb: "),env); MessageBox((HWND) 0,"Debugging variable MYSQL_DEBUG used",buff,MB_OK); } #endif @@ -623,8 +623,8 @@ mysql_free_result(MYSQL_RES *result) if (result->fields) ma_free_root(&result->field_alloc,MYF(0)); if (result->row) - ma_free(result->row); - ma_free(result); + free(result->row); + free(result); } DBUG_VOID_RETURN; } @@ -665,18 +665,27 @@ enum option_val #define CHECK_OPT_EXTENSION_SET(OPTS)\ if (!(OPTS)->extension) \ (OPTS)->extension= (struct st_mysql_options_extension *) \ - ma_malloc(sizeof(struct st_mysql_options_extension), \ - MYF(MY_WME | MY_ZEROFILL)); \ + calloc(1, sizeof(struct st_mysql_options_extension)); -#define OPT_SET_EXTENDED_VALUE_STR(OPTS, KEY, VAL) \ - CHECK_OPT_EXTENSION_SET(OPTS) \ - ma_free((gptr)(OPTS)->extension->KEY);\ - (OPTS)->extension->KEY= ma_strdup((char *)(VAL), MYF(MY_WME)) +#define OPT_SET_EXTENDED_VALUE_STR(OPTS, KEY, VAL) \ + CHECK_OPT_EXTENSION_SET(OPTS) \ + free((gptr)(OPTS)->extension->KEY); \ + if((VAL)) \ + (OPTS)->extension->KEY= strdup((char *)(VAL)); \ + else \ + (OPTS)->extension->KEY= NULL #define OPT_SET_EXTENDED_VALUE_INT(OPTS, KEY, VAL) \ CHECK_OPT_EXTENSION_SET(OPTS) \ (OPTS)->extension->KEY= (VAL) +#define OPT_SET_VALUE_STR(OPTS, KEY, VAL) \ + free((OPTS)->KEY); \ + if((VAL)) \ + (OPTS)->KEY= strdup((char *)(VAL)); \ + else \ + (OPTS)->KEY= NULL + static TYPELIB option_types={array_elements(default_options)-1, "options",default_options}; @@ -689,16 +698,15 @@ TYPELIB sql_protocol_typelib= {array_elements(protocol_names)-1, static void options_add_initcommand(struct st_mysql_options *options, const char *init_cmd) { - char *insert= ma_strdup(init_cmd, MYF(MY_WME)); + char *insert= strdup(init_cmd); if (!options->init_command) { - options->init_command= (DYNAMIC_ARRAY*)ma_malloc(sizeof(DYNAMIC_ARRAY), - MYF(MY_WME)); + options->init_command= (DYNAMIC_ARRAY*)malloc(sizeof(DYNAMIC_ARRAY)); ma_init_dynamic_array(options->init_command, sizeof(char*), 5, 5); } if (ma_insert_dynamic(options->init_command, (gptr)&insert)) - ma_free(insert); + free(insert); } @@ -723,37 +731,32 @@ static void mysql_read_default_options(struct st_mysql_options *options, /* DBUG_PRINT("info",("option: %s",option[0])); */ if (option[0][0] == '-' && option[0][1] == '-') { - char *end=strcend(*option,'='); - char *opt_arg=0; - if (*end) - { - opt_arg=end+1; - *end=0; /* Remove '=' */ - } - /* Change all '_' in variable name to '-' */ - for (end= *option ; *(end= strcend(end,'_')) ; ) - *end= '-'; - switch (ma_find_type(*option+2,&option_types,2)) { + char *end= strchr(*option, '='); + char *opt_arg=0; + + if (!end) + end= strchr(*option, '\0'); + if (*end) + { + opt_arg=end+1; + *end=0; /* Remove '=' */ + } + /* Change all '_' in variable name to '-' */ + for (end= *option ; (end= strchr(end,'_')) ; ) + *end= '-'; + switch (ma_find_type(*option+2,&option_types,2)) { case OPT_port: if (opt_arg) - options->port=atoi(opt_arg); + options->port=atoi(opt_arg); break; case OPT_socket: - if (opt_arg) - { - ma_free(options->unix_socket); - options->unix_socket=ma_strdup(opt_arg,MYF(MY_WME)); - } + OPT_SET_VALUE_STR(options, unix_socket, opt_arg); break; case OPT_compress: options->compress=1; break; case OPT_password: - if (opt_arg) - { - ma_free(options->password); - options->password=ma_strdup(opt_arg,MYF(MY_WME)); - } + OPT_SET_VALUE_STR(options, password, opt_arg); break; case OPT_pipe: options->named_pipe=1; /* Force named pipe */ @@ -764,29 +767,17 @@ static void mysql_read_default_options(struct st_mysql_options *options, options->connect_timeout=atoi(opt_arg); break; case OPT_user: - if (opt_arg) - { - ma_free(options->user); - options->user=ma_strdup(opt_arg,MYF(MY_WME)); - } + OPT_SET_VALUE_STR(options, user, opt_arg); break; case OPT_init_command: if (opt_arg) options_add_initcommand(options, opt_arg); break; case OPT_host: - if (opt_arg) - { - ma_free(options->host); - options->host=ma_strdup(opt_arg,MYF(MY_WME)); - } + OPT_SET_VALUE_STR(options, host, opt_arg); break; case OPT_database: - if (opt_arg) - { - ma_free(options->db); - options->db=ma_strdup(opt_arg,MYF(MY_WME)); - } + OPT_SET_VALUE_STR(options, db, opt_arg); break; case OPT_debug: mysql_debug(opt_arg ? opt_arg : "d:t:o,/tmp/client.trace"); @@ -796,22 +787,19 @@ static void mysql_read_default_options(struct st_mysql_options *options, break; #ifdef HAVE_SSL case OPT_ssl_key: - ma_free(options->ssl_key); - options->ssl_key = ma_strdup(opt_arg, MYF(MY_WME)); + OPT_SET_VALUE_STR(options, ssl_key, opt_arg); break; case OPT_ssl_cert: - ma_free(options->ssl_cert); - options->ssl_cert = ma_strdup(opt_arg, MYF(MY_WME)); + OPT_SET_VALUE_STR(options, ssl_cert, opt_arg); break; case OPT_ssl_ca: - ma_free(options->ssl_ca); - options->ssl_ca = ma_strdup(opt_arg, MYF(MY_WME)); + OPT_SET_VALUE_STR(options, ssl_ca, opt_arg); break; case OPT_ssl_capath: - ma_free(options->ssl_capath); - options->ssl_capath = ma_strdup(opt_arg, MYF(MY_WME)); + OPT_SET_VALUE_STR(options, ssl_capath, opt_arg); break; case OPT_ssl_cipher: + OPT_SET_VALUE_STR(options, ssl_cipher, opt_arg); break; case OPT_ssl_fp: OPT_SET_EXTENDED_VALUE_STR(options, ssl_fp, opt_arg); @@ -830,15 +818,14 @@ static void mysql_read_default_options(struct st_mysql_options *options, case OPT_ssl_cipher: case OPT_ssl_fp: case OPT_ssl_fp_list: + case OPT_ssl_pw: break; #endif /* HAVE_SSL */ case OPT_charset_dir: - ma_free(options->charset_dir); - options->charset_dir = ma_strdup(opt_arg, MYF(MY_WME)); + OPT_SET_VALUE_STR(options, charset_dir, opt_arg); break; case OPT_charset_name: - ma_free(options->charset_name); - options->charset_name = ma_strdup(opt_arg, MYF(MY_WME)); + OPT_SET_VALUE_STR(options, charset_name, opt_arg); break; case OPT_interactive_timeout: options->client_flag|= CLIENT_INTERACTIVE; @@ -868,7 +855,7 @@ static void mysql_read_default_options(struct st_mysql_options *options, } break; case OPT_shared_memory_base_name: - /* todo */ + OPT_SET_VALUE_STR(options, shared_memory_base_name, opt_arg); break; case OPT_multi_results: options->client_flag|= CLIENT_MULTI_RESULTS; @@ -899,8 +886,7 @@ static void mysql_read_default_options(struct st_mysql_options *options, OPT_SET_EXTENDED_VALUE_STR(options, default_auth, opt_arg); break; case OPT_bind_address: - ma_free(options->bind_address); - options->bind_address= ma_strdup(opt_arg, MYF(MY_WME)); + OPT_SET_VALUE_STR(options, bind_address, opt_arg); break; default: DBUG_PRINT("warning",("unknown option: %s",option[0])); @@ -1013,8 +999,7 @@ MYSQL_DATA *mthd_my_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, if ((pkt_len= net_safe_read(mysql)) == packet_error) DBUG_RETURN(0); - if (!(result=(MYSQL_DATA*) ma_malloc(sizeof(MYSQL_DATA), - MYF(MY_WME | MY_ZEROFILL)))) + if (!(result=(MYSQL_DATA*) calloc(1, sizeof(MYSQL_DATA)))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(0); @@ -1124,7 +1109,7 @@ int mthd_my_read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths) if (len > (ulong) (end_pos - pos)) { mysql->net.last_errno=CR_UNKNOWN_ERROR; - strmov(mysql->net.last_error,ER(mysql->net.last_errno)); + strcpy(mysql->net.last_error,ER(mysql->net.last_errno)); return -1; } row[field] = (char*) pos; @@ -1151,7 +1136,7 @@ mysql_init(MYSQL *mysql) return NULL; if (!mysql) { - if (!(mysql=(MYSQL*) ma_malloc(sizeof(*mysql),MYF(MY_WME | MY_ZEROFILL)))) + if (!(mysql=(MYSQL*) calloc(1, sizeof(MYSQL)))) return 0; mysql->free_me=1; mysql->net.pvio= 0; @@ -1161,7 +1146,7 @@ mysql_init(MYSQL *mysql) mysql->options.connect_timeout=CONNECT_TIMEOUT; mysql->charset= ma_default_charset_info; mysql->methods= &MARIADB_DEFAULT_METHODS; - strmov(mysql->net.sqlstate, "00000"); + strcpy(mysql->net.sqlstate, "00000"); mysql->net.last_error[0]= mysql->net.last_errno= 0; /* @@ -1308,7 +1293,7 @@ mysql_real_connect(MYSQL *mysql, const char *host, const char *user, if (!(plugin= (MARIADB_CONNECTION_PLUGIN *)mysql_client_find_plugin(mysql, plugin_name, MARIADB_CLIENT_CONNECTION_PLUGIN))) return NULL; - if (!(mysql->net.conn_hdlr= (MA_CONNECTION_HANDLER *)ma_malloc(sizeof(MA_CONNECTION_HANDLER), MYF(MY_ZEROFILL)))) + if (!(mysql->net.conn_hdlr= (MA_CONNECTION_HANDLER *)calloc(1, sizeof(MA_CONNECTION_HANDLER)))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); return NULL; @@ -1324,7 +1309,7 @@ mysql_real_connect(MYSQL *mysql, const char *host, const char *user, MYSQL *my= plugin->connect(mysql, end, user, passwd, db, port, unix_socket, client_flag); if (!my) { - ma_free(mysql->net.conn_hdlr); + free(mysql->net.conn_hdlr); mysql->net.conn_hdlr= NULL; } return my; @@ -1374,8 +1359,8 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, (mysql->options.my_cnf_file ? mysql->options.my_cnf_file : "my"), mysql->options.my_cnf_group); - ma_free(mysql->options.my_cnf_file); - ma_free(mysql->options.my_cnf_group); + free(mysql->options.my_cnf_file); + free(mysql->options.my_cnf_group); mysql->options.my_cnf_file=mysql->options.my_cnf_group=0; } @@ -1464,7 +1449,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, goto error; ma_pvio_keepalive(net->pvio); - strmov(mysql->net.sqlstate, "00000"); + strcpy(mysql->net.sqlstate, "00000"); /* Get version info */ mysql->protocol_version= PROTOCOL_VERSION; /* Assume this */ @@ -1521,23 +1506,20 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, if (!user) user=""; if (!passwd) passwd=""; - if (!my_multi_malloc(MYF(0), - &mysql->host_info, (uint) strlen(host_info)+1, - &mysql->host, (uint) strlen(cinfo.host)+1, - &mysql->unix_socket, cinfo.unix_socket ? - (uint) strlen(cinfo.unix_socket)+1 : (uint) 1, - &mysql->server_version, (uint) (end - (char*) net->read_pos), - NullS) || - !(mysql->user=ma_strdup(user,MYF(0))) || - !(mysql->passwd=ma_strdup(passwd,MYF(0)))) + if (!(mysql->host_info= strdup(host_info ? host_info : "")) || + !(mysql->host= strdup(cinfo.host ? cinfo.host : "")) || + !(mysql->unix_socket= strdup(cinfo.unix_socket ? cinfo.unix_socket : "")) || + !(mysql->server_version = malloc((size_t)(end - (char*) net->read_pos))) || + !(mysql->user=strdup(user)) || + !(mysql->passwd=strdup(passwd))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto error; } - strmov(mysql->host_info,host_info); - strmov(mysql->host, cinfo.host); + strcpy(mysql->host_info,host_info); + strcpy(mysql->host, cinfo.host); if (cinfo.unix_socket) - strmov(mysql->unix_socket, cinfo.unix_socket); + strcpy(mysql->unix_socket, cinfo.unix_socket); else mysql->unix_socket=0; mysql->port=port; @@ -1545,7 +1527,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, if (strncmp(end, MA_RPL_VERSION_HACK, sizeof(MA_RPL_VERSION_HACK) - 1) == 0) { - if (!(mysql->server_version= ma_strdup(end + sizeof(MA_RPL_VERSION_HACK) - 1, 0))) + if (!(mysql->server_version= strdup(end + sizeof(MA_RPL_VERSION_HACK) - 1))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto error; @@ -1554,7 +1536,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, } else { - if (!(mysql->server_version= ma_strdup(end, MYF(0)))) + if (!(mysql->server_version= strdup(end))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto error; @@ -1691,7 +1673,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, mysql->options.reconnect= save_reconnect; } - strmov(mysql->net.sqlstate, "00000"); + strcpy(mysql->net.sqlstate, "00000"); DBUG_PRINT("exit",("Mysql handler: %lx",mysql)); DBUG_RETURN(mysql); @@ -1866,8 +1848,8 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, else mysql->charset=ma_default_charset_info; - mysql->user= ma_strdup(user ? user : "", MYF(MY_WME)); - mysql->passwd= ma_strdup(passwd ? passwd : "", MYF(MY_WME)); + mysql->user= strdup(user ? user : ""); + mysql->passwd= strdup(passwd ? passwd : ""); /* db will be set in run_plugin_auth */ mysql->db= 0; @@ -1878,20 +1860,20 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, if (rc==0) { - ma_free(s_user); - ma_free(s_passwd); - ma_free(s_db); + free(s_user); + free(s_passwd); + free(s_db); - if (db && !(mysql->db= ma_strdup(db,MYF(MY_WME)))) + if (db && !(mysql->db= strdup(db))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); rc= 1; } } else { - ma_free(mysql->user); - ma_free(mysql->passwd); - ma_free(mysql->db); + free(mysql->user); + free(mysql->passwd); + free(mysql->db); mysql->user= s_user; mysql->passwd= s_passwd; @@ -1915,8 +1897,8 @@ mysql_select_db(MYSQL *mysql, const char *db) if ((error=ma_simple_command(mysql, COM_INIT_DB,db,(uint) strlen(db),0,0))) DBUG_RETURN(error); - ma_free(mysql->db); - mysql->db=ma_strdup(db,MYF(MY_WME)); + free(mysql->db); + mysql->db=strdup(db); DBUG_RETURN(0); } @@ -1934,39 +1916,39 @@ static void mysql_close_options(MYSQL *mysql) char **end= begin + mysql->options.init_command->elements; for (;begin < end; begin++) - ma_free(*begin); + free(*begin); ma_delete_dynamic(mysql->options.init_command); - ma_free(mysql->options.init_command); + free(mysql->options.init_command); } - ma_free(mysql->options.user); - ma_free(mysql->options.host); - ma_free(mysql->options.password); - ma_free(mysql->options.unix_socket); - ma_free(mysql->options.db); - ma_free(mysql->options.my_cnf_file); - ma_free(mysql->options.my_cnf_group); - ma_free(mysql->options.charset_dir); - ma_free(mysql->options.charset_name); - ma_free(mysql->options.bind_address); - ma_free(mysql->options.ssl_key); - ma_free(mysql->options.ssl_cert); - ma_free(mysql->options.ssl_ca); - ma_free(mysql->options.ssl_capath); - ma_free(mysql->options.ssl_cipher); + free(mysql->options.user); + free(mysql->options.host); + free(mysql->options.password); + free(mysql->options.unix_socket); + free(mysql->options.db); + free(mysql->options.my_cnf_file); + free(mysql->options.my_cnf_group); + free(mysql->options.charset_dir); + free(mysql->options.charset_name); + free(mysql->options.bind_address); + free(mysql->options.ssl_key); + free(mysql->options.ssl_cert); + free(mysql->options.ssl_ca); + free(mysql->options.ssl_capath); + free(mysql->options.ssl_cipher); if (mysql->options.extension) { struct mysql_async_context *ctxt; - ma_free(mysql->options.extension->plugin_dir); - ma_free(mysql->options.extension->default_auth); - ma_free(mysql->options.extension->db_driver); - ma_free(mysql->options.extension->ssl_crl); - ma_free(mysql->options.extension->ssl_crlpath); - ma_free(mysql->options.extension->ssl_fp); - ma_free(mysql->options.extension->ssl_fp_list); - ma_free(mysql->options.extension->ssl_pw); - ma_free(mysql->options.extension->url); - ma_free(mysql->options.extension->connection_handler); + free(mysql->options.extension->plugin_dir); + free(mysql->options.extension->default_auth); + free(mysql->options.extension->db_driver); + free(mysql->options.extension->ssl_crl); + free(mysql->options.extension->ssl_crlpath); + free(mysql->options.extension->ssl_fp); + free(mysql->options.extension->ssl_fp_list); + free(mysql->options.extension->ssl_pw); + free(mysql->options.extension->url); + free(mysql->options.extension->connection_handler); if(hash_inited(&mysql->options.extension->connect_attrs)) hash_free(&mysql->options.extension->connect_attrs); if (hash_inited(&mysql->options.extension->userdata)) @@ -1974,22 +1956,22 @@ static void mysql_close_options(MYSQL *mysql) if ((ctxt = mysql->options.extension->async_context) != 0) { my_context_destroy(&ctxt->async_context); - ma_free(ctxt); + free(ctxt); } } - ma_free(mysql->options.extension); + free(mysql->options.extension); /* clear all pointer */ memset(&mysql->options, 0, sizeof(mysql->options)); } static void mysql_close_memory(MYSQL *mysql) { - ma_free(mysql->host_info); - ma_free(mysql->user); - ma_free(mysql->passwd); - ma_free(mysql->db); - ma_free(mysql->server_version); + free(mysql->host_info); + free(mysql->user); + free(mysql->passwd); + free(mysql->db); + free(mysql->server_version); mysql->host_info= mysql->server_version=mysql->user=mysql->passwd=mysql->db=0; } @@ -2036,7 +2018,7 @@ mysql_close(MYSQL *mysql) { MA_CONNECTION_HANDLER *p= mysql->net.conn_hdlr; p->plugin->close(mysql); - ma_free(p); + free(p); } if (mysql->methods) @@ -2053,11 +2035,11 @@ mysql_close(MYSQL *mysql) bzero((char*) &mysql->options,sizeof(mysql->options)); if (mysql->extension) - ma_free(mysql->extension); + free(mysql->extension); mysql->net.pvio= 0; if (mysql->free_me) - ma_free(mysql); + free(mysql); } DBUG_VOID_RETURN; } @@ -2185,9 +2167,8 @@ mysql_store_result(MYSQL *mysql) DBUG_RETURN(0); } mysql->status=MYSQL_STATUS_READY; /* server is ready */ - if (!(result=(MYSQL_RES*) ma_malloc(sizeof(MYSQL_RES)+ - sizeof(ulong)*mysql->field_count, - MYF(MY_WME | MY_ZEROFILL)))) + if (!(result=(MYSQL_RES*) calloc(1, sizeof(MYSQL_RES)+ + sizeof(ulong)*mysql->field_count))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(0); @@ -2196,7 +2177,7 @@ mysql_store_result(MYSQL *mysql) result->lengths=(ulong*) (result+1); if (!(result->data=mysql->methods->db_read_rows(mysql,mysql->fields,mysql->field_count))) { - ma_free(result); + free(result); DBUG_RETURN(0); } mysql->affected_rows= result->row_count= result->data->rows; @@ -2234,15 +2215,14 @@ mysql_use_result(MYSQL *mysql) SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(0); } - if (!(result=(MYSQL_RES*) ma_malloc(sizeof(*result)+ - sizeof(ulong)*mysql->field_count, - MYF(MY_WME | MY_ZEROFILL)))) + if (!(result=(MYSQL_RES*) calloc(1, sizeof(*result)+ + sizeof(ulong)*mysql->field_count))) DBUG_RETURN(0); result->lengths=(ulong*) (result+1); if (!(result->row=(MYSQL_ROW) - ma_malloc(sizeof(result->row[0])*(mysql->field_count+1), MYF(MY_WME)))) + malloc(sizeof(result->row[0])*(mysql->field_count+1)))) { /* Ptrs: to one row */ - ma_free(result); + free(result); DBUG_RETURN(0); } result->fields= mysql->fields; @@ -2428,20 +2408,21 @@ mysql_list_fields(MYSQL *mysql, const char *table, const char *wild) { MYSQL_RES *result; MYSQL_DATA *query; - char buff[257],*end; + char buff[128]; + int length= 0; DBUG_ENTER("mysql_list_fields"); DBUG_PRINT("enter",("table: '%s' wild: '%s'",table,wild ? wild : "")); LINT_INIT(query); - end=strmake(strmake(buff, table,128)+1,wild ? wild : "",128); - if (ma_simple_command(mysql, COM_FIELD_LIST,buff,(uint) (end-buff),1,0) || + length= snprintf(buff, 128, "%s%c%s", table, '\0', wild ? wild : ""); + + if (ma_simple_command(mysql, COM_FIELD_LIST,buff,length,1,0) || !(query = mysql->methods->db_read_rows(mysql,(MYSQL_FIELD*) 0,8))) DBUG_RETURN(NULL); free_old_query(mysql); - if (!(result = (MYSQL_RES *) ma_malloc(sizeof(MYSQL_RES), - MYF(MY_WME | MY_ZEROFILL)))) + if (!(result = (MYSQL_RES *) calloc(1, sizeof(MYSQL_RES)))) { free_rows(query); DBUG_RETURN(NULL); @@ -2626,7 +2607,7 @@ uchar *ma_get_hash_keyval(const uchar *hash_entry, void ma_hash_free(void *p) { - ma_free(p); + free(p); } int mariadb_flush_multi_command(MYSQL *mysql) @@ -2684,20 +2665,17 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) options_add_initcommand(&mysql->options, (char *)arg1); break; case MYSQL_READ_DEFAULT_FILE: - ma_free(mysql->options.my_cnf_file); - mysql->options.my_cnf_file=ma_strdup((char *)arg1,MYF(MY_WME)); + OPT_SET_VALUE_STR(&mysql->options, my_cnf_file, (char *)arg1); break; case MYSQL_READ_DEFAULT_GROUP: - ma_free(mysql->options.my_cnf_group); - mysql->options.my_cnf_group=ma_strdup((char *)arg1,MYF(MY_WME)); + OPT_SET_VALUE_STR(&mysql->options, my_cnf_group, (char *)arg1); break; case MYSQL_SET_CHARSET_DIR: /* not supported in this version. Since all character sets are internally available, we don't throw an error */ break; case MYSQL_SET_CHARSET_NAME: - ma_free(mysql->options.charset_name); - mysql->options.charset_name=ma_strdup((char *)arg1,MYF(MY_WME)); + OPT_SET_VALUE_STR(&mysql->options, charset_name, (char *)arg1); break; case MYSQL_OPT_RECONNECT: mysql->options.reconnect= *(uint *)arg1; @@ -2715,10 +2693,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) mysql->options.report_data_truncation= *(my_bool *)arg1; break; case MYSQL_PROGRESS_CALLBACK: - if (!mysql->options.extension) - mysql->options.extension= (struct st_mysql_options_extension *) - ma_malloc(sizeof(struct st_mysql_options_extension), - MYF(MY_WME | MY_ZEROFILL)); + CHECK_OPT_EXTENSION_SET(&mysql->options); if (mysql->options.extension) mysql->options.extension->report_progress= (void (*)(const MYSQL *, uint, uint, double, const char *, uint)) arg1; @@ -2729,32 +2704,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) case MYSQL_DEFAULT_AUTH: OPT_SET_EXTENDED_VALUE_STR(&mysql->options, default_auth, (char *)arg1); break; - /* - case MYSQL_DATABASE_DRIVER: - { - MARIADB_DB_PLUGIN *db_plugin; - if (!(db_plugin= (MARIADB_DB_PLUGIN *)mysql_client_find_plugin(mysql, (char *)arg1, - MYSQL_CLIENT_DB_PLUGIN))) - break; - if (!mysql->options.extension) - mysql->options.extension= (struct st_mysql_options_extension *) - ma_malloc(sizeof(struct st_mysql_options_extension), - MYF(MY_WME | MY_ZEROFILL)); - if (!mysql->options.extension->db_driver) - mysql->options.extension->db_driver= (MARIADB_DB_DRIVER *) - ma_malloc(sizeof(MARIADB_DB_DRIVER), MYF(MY_WME | MY_ZEROFILL)); - if (mysql->options.extension && - mysql->options.extension->db_driver) - { - mysql->options.extension->db_driver->plugin = db_plugin; - mysql->options.extension->db_driver->buffer= NULL; - mysql->options.extension->db_driver->name= (char *)db_plugin->name; - mysql->methods= db_plugin->methods; - } - } - break; - */ - case MYSQL_OPT_NONBLOCK: + case MYSQL_OPT_NONBLOCK: if (mysql->options.extension && (ctxt = mysql->options.extension->async_context) != 0) { @@ -2765,10 +2715,10 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) if (ctxt->suspended) goto end; my_context_destroy(&ctxt->async_context); - ma_free(ctxt); + free(ctxt); } if (!(ctxt= (struct mysql_async_context *) - ma_malloc(sizeof(*ctxt), MYF(MY_ZEROFILL)))) + calloc(1, sizeof(*ctxt)))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto end; @@ -2780,13 +2730,12 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) stacksize= ASYNC_CONTEXT_DEFAULT_STACK_SIZE; if (my_context_init(&ctxt->async_context, stacksize)) { - ma_free(ctxt); + free(ctxt); goto end; } if (!mysql->options.extension) if(!(mysql->options.extension= (struct st_mysql_options_extension *) - ma_malloc(sizeof(struct st_mysql_options_extension), - MYF(MY_WME | MY_ZEROFILL)))) + calloc(1, sizeof(struct st_mysql_options_extension)))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto end; @@ -2811,24 +2760,19 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) mysql->options.client_flag &= ~CLIENT_SSL_VERIFY_SERVER_CERT; break; case MYSQL_OPT_SSL_KEY: - ma_free(mysql->options.ssl_key); - mysql->options.ssl_key=ma_strdup((char *)arg1,MYF(MY_WME | MY_ALLOW_ZERO_PTR)); + OPT_SET_VALUE_STR(&mysql->options, ssl_key, (char *)arg1); break; case MYSQL_OPT_SSL_CERT: - ma_free(mysql->options.ssl_cert); - mysql->options.ssl_cert=ma_strdup((char *)arg1,MYF(MY_WME | MY_ALLOW_ZERO_PTR)); + OPT_SET_VALUE_STR(&mysql->options, ssl_cert, (char *)arg1); break; case MYSQL_OPT_SSL_CA: - ma_free(mysql->options.ssl_ca); - mysql->options.ssl_ca=ma_strdup((char *)arg1,MYF(MY_WME | MY_ALLOW_ZERO_PTR)); + OPT_SET_VALUE_STR(&mysql->options, ssl_ca, (char *)arg1); break; case MYSQL_OPT_SSL_CAPATH: - ma_free(mysql->options.ssl_capath); - mysql->options.ssl_capath=ma_strdup((char *)arg1,MYF(MY_WME | MY_ALLOW_ZERO_PTR)); + OPT_SET_VALUE_STR(&mysql->options, ssl_capath, (char *)arg1); break; case MYSQL_OPT_SSL_CIPHER: - ma_free(mysql->options.ssl_cipher); - mysql->options.ssl_cipher=ma_strdup((char *)arg1,MYF(MY_WME | MY_ALLOW_ZERO_PTR)); + OPT_SET_VALUE_STR(&mysql->options, ssl_cipher, (char *)arg1); break; case MYSQL_OPT_SSL_CRL: OPT_SET_EXTENDED_VALUE_STR(&mysql->options, ssl_crl, (char *)arg1); @@ -2897,7 +2841,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) break; } - if (!(buffer= (uchar *)ma_malloc(strlen(key) + 1 + sizeof(void *), MYF(MY_ZEROFILL)))) + if (!(buffer= (uchar *)malloc(strlen(key) + 1 + sizeof(void *)))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto end; @@ -2910,7 +2854,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) if (hash_insert(&mysql->options.extension->userdata, buffer)) { - ma_free(buffer); + free(buffer); SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); goto end; } @@ -2948,8 +2892,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) goto end; } } - if ((buffer= (uchar *)ma_malloc(key_len + value_len, - MYF(MY_WME | MY_ZEROFILL)))) + if ((buffer= (uchar *)malloc(key_len + value_len))) { uchar *p= buffer; strcpy(p, arg1); @@ -2959,7 +2902,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) if (hash_insert(&mysql->options.extension->connect_attrs, buffer)) { - ma_free(buffer); + free(buffer); SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); goto end; } @@ -2978,8 +2921,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) mysql->options.secure_auth= *(my_bool *)arg1; break; case MYSQL_OPT_BIND: - ma_free(mysql->options.bind_address); - mysql->options.bind_address= ma_strdup(arg1, MYF(MY_WME)); + OPT_SET_VALUE_STR(&mysql->options, bind_address, arg1); break; case MARIADB_OPT_SSL_FP: OPT_SET_EXTENDED_VALUE_STR(&mysql->options, ssl_fp, (char *)arg1); diff --git a/libmariadb/list.c b/libmariadb/list.c index 50ad0b43..49772b3c 100644 --- a/libmariadb/list.c +++ b/libmariadb/list.c @@ -63,8 +63,8 @@ void list_free(LIST *root, unsigned int free_data) { next=root->next; if (free_data) - ma_free(root->data); - ma_free(root); + free(root->data); + free(root); root=next; } } @@ -72,7 +72,7 @@ void list_free(LIST *root, unsigned int free_data) LIST *list_cons(void *data, LIST *list) { - LIST *new_charset=(LIST*) ma_malloc(sizeof(LIST),MYF(MY_FAE)); + LIST *new_charset=(LIST*) malloc(sizeof(LIST)); if (!new_charset) return 0; new_charset->data=data; diff --git a/libmariadb/ma_dyncol.c b/libmariadb/ma_dyncol.c index 5e168503..25fff7eb 100644 --- a/libmariadb/ma_dyncol.c +++ b/libmariadb/ma_dyncol.c @@ -2484,7 +2484,7 @@ mariadb_dyncol_list_num(DYNAMIC_COLUMN *str, uint *count, uint **nums) str->length) return ER_DYNCOL_FORMAT; - if (!((*nums)= (uint *)ma_malloc(sizeof(uint) * header.column_count, MYF(0)))) + if (!((*nums)= (uint *)malloc(sizeof(uint) * header.column_count))) return ER_DYNCOL_RESOURCE; for (i= 0, read= header.header; @@ -2532,11 +2532,11 @@ mariadb_dyncol_list_named(DYNAMIC_COLUMN *str, uint *count, LEX_STRING **names) return ER_DYNCOL_FORMAT; if (header.format == dyncol_fmt_num) - *names= (LEX_STRING *)ma_malloc(sizeof(LEX_STRING) * header.column_count + - DYNCOL_NUM_CHAR * header.column_count, MYF(0)); + *names= (LEX_STRING *)malloc(sizeof(LEX_STRING) * header.column_count + + DYNCOL_NUM_CHAR * header.column_count); else - *names= (LEX_STRING *)ma_malloc(sizeof(LEX_STRING) * header.column_count + - header.nmpool_size + header.column_count, MYF(0)); + *names= (LEX_STRING *)malloc(sizeof(LEX_STRING) * header.column_count + + header.nmpool_size + header.column_count); if (!(*names)) return ER_DYNCOL_RESOURCE; pool= ((char *)(*names)) + sizeof(LEX_STRING) * header.column_count; @@ -3349,7 +3349,7 @@ dynamic_column_update_many_fmt(DYNAMIC_COLUMN *str, if (IN_PLACE_PLAN > add_column_count) plan= in_place_plan; else if (!(alloc_plan= plan= - (PLAN *)ma_malloc(sizeof(PLAN) * (add_column_count + 1), MYF(0)))) + (PLAN *)malloc(sizeof(PLAN) * (add_column_count + 1)))) return ER_DYNCOL_RESOURCE; not_null= add_column_count; @@ -3606,13 +3606,13 @@ dynamic_column_update_many_fmt(DYNAMIC_COLUMN *str, &header, &new_header, convert); end: - ma_free(alloc_plan); + free(alloc_plan); return rc; create_new_string: /* There is no columns from before, so let's just add the new ones */ rc= ER_DYNCOL_OK; - ma_free(alloc_plan); + free(alloc_plan); if (not_null != 0) rc= dynamic_column_create_many_internal_fmt(str, add_column_count, (uint*)column_keys, values, @@ -3904,7 +3904,7 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, #endif return ER_DYNCOL_OK; } - if ((alloc= (char *)ma_malloc(bufflen, MYF(0)))) + if ((alloc= (char *)malloc(bufflen))) { len= #ifndef LIBMARIADB @@ -3927,7 +3927,7 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, if (quote) rc= dynstr_append_mem(str, "e, 1); if (alloc) - ma_free(alloc); + free(alloc); if (rc) return ER_DYNCOL_RESOURCE; break; @@ -4291,16 +4291,16 @@ mariadb_dyncol_unpack(DYNAMIC_COLUMN *str, str->length) return ER_DYNCOL_FORMAT; - *vals= (DYNAMIC_COLUMN_VALUE *)ma_malloc(sizeof(DYNAMIC_COLUMN_VALUE)* header.column_count, MYF(0)); + *vals= (DYNAMIC_COLUMN_VALUE *)malloc(sizeof(DYNAMIC_COLUMN_VALUE)* header.column_count); if (header.format == dyncol_fmt_num) { - *names= (LEX_STRING *)ma_malloc(sizeof(LEX_STRING) * header.column_count + - DYNCOL_NUM_CHAR * header.column_count, MYF(0)); + *names= (LEX_STRING *)malloc(sizeof(LEX_STRING) * header.column_count + + DYNCOL_NUM_CHAR * header.column_count); nm= (char *)(names + sizeof(LEX_STRING) * header.column_count); } else { - *names= (LEX_STRING *)ma_malloc(sizeof(LEX_STRING) * header.column_count, MYF(0)); + *names= (LEX_STRING *)malloc(sizeof(LEX_STRING) * header.column_count); nm= 0; } if (!(*vals) || !(*names)) @@ -4352,12 +4352,12 @@ mariadb_dyncol_unpack(DYNAMIC_COLUMN *str, err: if (*vals) { - ma_free(*vals); + free(*vals); *vals= 0; } if (*names) { - ma_free(*names); + free(*names); *names= 0; } return rc; diff --git a/libmariadb/ma_io.c b/libmariadb/ma_io.c index c2fca04a..5aacec81 100644 --- a/libmariadb/ma_io.c +++ b/libmariadb/ma_io.c @@ -74,7 +74,7 @@ MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql) len= MultiByteToWideChar(CodePage, 0, location, (int)strlen(location), NULL, 0); if (!len) return NULL; - if (!(w_filename= (wchar_t *)ma_malloc((len + 1) * sizeof(wchar_t), MYF(MY_ZEROFILL)))) + 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; @@ -84,14 +84,14 @@ MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql) if (!len) { /* todo: error handling */ - ma_free(w_filename); + free(w_filename); return NULL; } len= (int)strlen(mode); - if (!(w_mode= (wchar_t *)ma_malloc((len + 1) * sizeof(wchar_t), MYF(MY_ZEROFILL)))) + if (!(w_mode= (wchar_t *)calloc(1, (len + 1) * sizeof(wchar_t)))) { my_set_error(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - ma_free(w_filename); + free(w_filename); return NULL; } Length= len; @@ -99,20 +99,20 @@ MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql) if (!len) { /* todo: error handling */ - ma_free(w_filename); - ma_free(w_mode); + free(w_filename); + free(w_mode); return NULL; } fp= _wfopen(w_filename, w_mode); my_errno= GetLastError(); - ma_free(w_filename); - ma_free(w_mode); + free(w_filename); + free(w_mode); } #endif if (fp) { - ma_file= (MA_FILE *)ma_malloc(sizeof(MA_FILE), MYF(0)); + ma_file= (MA_FILE *)malloc(sizeof(MA_FILE)); if (!ma_file) { my_set_error(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); @@ -147,7 +147,7 @@ int ma_close(MA_FILE *file) switch (file->type) { case MA_FILE_LOCAL: rc= fclose((FILE *)file->ptr); - ma_free(file); + free(file); break; #ifdef HAVE_REMOTEIO case MA_FILE_REMOTE: diff --git a/libmariadb/ma_pvio.c b/libmariadb/ma_pvio.c index 255d5eca..19c6713d 100644 --- a/libmariadb/ma_pvio.c +++ b/libmariadb/ma_pvio.c @@ -104,8 +104,7 @@ MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo) } - if (!(pvio= (MARIADB_PVIO *)ma_malloc(sizeof(MARIADB_PVIO), - MYF(MY_WME | MY_ZEROFILL)))) + if (!(pvio= (MARIADB_PVIO *)calloc(1, sizeof(MARIADB_PVIO)))) { PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); return NULL; @@ -124,9 +123,10 @@ MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo) pvio->methods->set_timeout(pvio, PVIO_WRITE_TIMEOUT, cinfo->mysql->options.write_timeout); } - if (!(pvio->cache= ma_malloc(PVIO_READ_AHEAD_CACHE_SIZE, MYF(MY_ZEROFILL)))) + 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; @@ -386,19 +386,19 @@ void ma_pvio_close(MARIADB_PVIO *pvio) if (pvio && pvio->cssl) { ma_pvio_ssl_close(pvio->cssl); - ma_free((gptr)pvio->cssl); + free((gptr)pvio->cssl); } #endif if (pvio && pvio->methods->close) pvio->methods->close(pvio); if (pvio->cache) - ma_free((gptr)pvio->cache); + free((gptr)pvio->cache); if (pvio->fp) my_fclose(pvio->fp, MYF(0)); - ma_free((gptr)pvio); + free((gptr)pvio); } /* }}} */ @@ -511,7 +511,7 @@ my_bool ma_pvio_start_ssl(MARIADB_PVIO *pvio) } if (ma_pvio_ssl_connect(pvio->cssl)) { - ma_free(pvio->cssl); + free(pvio->cssl); pvio->cssl= NULL; return 1; } diff --git a/libmariadb/ma_ssl.c b/libmariadb/ma_ssl.c index 65651934..2bf54fe0 100644 --- a/libmariadb/ma_ssl.c +++ b/libmariadb/ma_ssl.c @@ -60,8 +60,7 @@ MARIADB_SSL *ma_pvio_ssl_init(MYSQL *mysql) if (!ma_ssl_initialized) ma_ssl_start(mysql->net.last_error, MYSQL_ERRMSG_SIZE); - if (!(cssl= (MARIADB_SSL *)ma_malloc(sizeof(MARIADB_SSL), - MYF(MY_WME | MY_ZEROFILL)))) + if (!(cssl= (MARIADB_SSL *)calloc(1, sizeof(MARIADB_SSL)))) { return NULL; } @@ -70,7 +69,7 @@ MARIADB_SSL *ma_pvio_ssl_init(MYSQL *mysql) cssl->pvio= mysql->net.pvio; if (!(cssl->ssl= ma_ssl_init(mysql))) { - ma_free(cssl); + free(cssl); cssl= NULL; } return cssl; diff --git a/libmariadb/mf_dirname.c b/libmariadb/mf_dirname.c index f163735c..d32f06e2 100644 --- a/libmariadb/mf_dirname.c +++ b/libmariadb/mf_dirname.c @@ -50,7 +50,7 @@ uint dirname_part(my_string to, const char *name) DBUG_PRINT("enter",("'%s'",name)); length=dirname_length(name); - (void) strmake(to,(char*) name,min(length,FN_REFLEN-2)); + strncpy(to,(char*) name,min(length,FN_REFLEN-2)); convert_dirname(to); /* Convert chars */ DBUG_RETURN(length); } /* dirname */ diff --git a/libmariadb/mf_format.c b/libmariadb/mf_format.c index f356facf..d4ac008f 100644 --- a/libmariadb/mf_format.c +++ b/libmariadb/mf_format.c @@ -57,7 +57,7 @@ my_string fn_format(my_string to, const char *name, const char *dsk, name+=(length=dirname_part(dev,(startpos=(my_string) name))); if (length == 0 || flag & 1) { - (void) strmake(dev,dsk, sizeof(dev) - 2); + strncpy(dev,dsk, sizeof(dev) - 2); /* Use given directory */ convert_dirname(dev); /* Fix to this OS */ } @@ -91,7 +91,7 @@ my_string fn_format(my_string to, const char *name, const char *dsk, return 0; tmp_length=strlength(startpos); DBUG_PRINT("error",("dev: '%s' ext: '%s' length: %d",dev,ext,length)); - (void) strmake(to,startpos,min(tmp_length,FN_REFLEN-1)); + strncpy(to,startpos,min(tmp_length,FN_REFLEN-1)); } else { @@ -100,7 +100,7 @@ my_string fn_format(my_string to, const char *name, const char *dsk, bmove(buff,(char*) name,length); /* Save name for last copy */ name=buff; } - pos=strmake(strmov(to,dev),name,length); + pos=strncpy(strmov(to,dev),name,length) + strlen(to); #ifdef FN_UPPER_CASE caseup_str(to); #endif @@ -117,7 +117,7 @@ my_string fn_format(my_string to, const char *name, const char *dsk, if (flag & 32 || (!lstat(to,&stat_buff) && S_ISLNK(stat_buff.st_mode))) { if (realpath(to,buff)) - strmake(to,buff,FN_REFLEN-1); + strncpy(to,buff,FN_REFLEN-1); } } #endif diff --git a/libmariadb/mf_loadpath.c b/libmariadb/mf_loadpath.c index 641528b8..35bf54be 100644 --- a/libmariadb/mf_loadpath.c +++ b/libmariadb/mf_loadpath.c @@ -47,8 +47,8 @@ my_string my_load_path(my_string to, const char *path, VOID(strmov(buff,path)); } else - VOID(strxmov(buff,own_path_prefix,path,NullS)); - strmov(to,buff); + strcat(strcat(buff, own_path_prefix), path); + strcpy(to,buff); DBUG_PRINT("exit",("to: %s",to)); DBUG_RETURN(to); } /* my_load_path */ diff --git a/libmariadb/mf_pack.c b/libmariadb/mf_pack.c index eb5484bc..6632e707 100644 --- a/libmariadb/mf_pack.c +++ b/libmariadb/mf_pack.c @@ -231,7 +231,7 @@ void symdirget(char *dir) { FILE *fp; char temp= *(--pos); /* May be "/" or "\" */ - strmov(pos,".sym"); + strcpy(pos,".sym"); fp = my_fopen(dir, O_RDONLY,MYF(0)); *pos++=temp; *pos=0; /* Restore old filename */ if (fp) @@ -246,7 +246,7 @@ void symdirget(char *dir) if (pos == buff || pos[-1] != FN_LIBCHAR) *pos++=FN_LIBCHAR; - strmake(dir,buff, (uint) (pos-buff)); + strncpy(dir,buff, (uint) (pos-buff)); } my_fclose(fp,MYF(0)); } @@ -365,7 +365,7 @@ my_string ma_unpack_filename(my_string to, const char *from) uint ma_system_filename(my_string to, const char *from) { #ifndef FN_C_BEFORE_DIR - return (uint) (strmake(to,from,FN_REFLEN-1)-to); + return (uint) strlen(strncpy(to,from,FN_REFLEN-1)); #else /* VMS */ /* change 'dev:lib/xxx' to 'dev:[lib]xxx' */ @@ -439,7 +439,7 @@ my_string ma_intern_filename(my_string to, const char *from) char buff[FN_REFLEN]; if (from == to) { /* Dirname may destroy from */ - strmov(buff,from); + strcpy(buff,from); from=buff; } length=dirname_part(to,from); /* Copy dirname & fix chars */ diff --git a/libmariadb/mf_path.c b/libmariadb/mf_path.c index a4ea1473..7a8379f7 100644 --- a/libmariadb/mf_path.c +++ b/libmariadb/mf_path.c @@ -99,7 +99,8 @@ static char *find_file_in_path(char *to, const char *name) { if (path != pos) { - strxmov(strnmov(to,path,(uint) (pos-path)),dir,name,ext,NullS); + sprintf(to, "%s%s%s%s%s", path, pos - path, dir, name, ext); +// strxmov(strnmov(to,path,(uint) (pos-path)),dir,name,ext,NullS); if (!access(to,F_OK)) { to[(uint) (pos-path)+1]=0; /* Return path only */ @@ -109,7 +110,7 @@ static char *find_file_in_path(char *to, const char *name) } #ifdef _WIN32 to[0]=FN_CURLIB; - strxmov(to+1,dir,name,ext,NullS); + sprintf(to +1, "%s%s%s", dir, name, ext); if (!access(to,F_OK)) /* Test in current dir */ { to[2]=0; /* Leave ".\" */ diff --git a/libmariadb/mulalloc.c b/libmariadb/mulalloc.c deleted file mode 100644 index 01d9ab88..00000000 --- a/libmariadb/mulalloc.c +++ /dev/null @@ -1,53 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - - /* Malloc many pointers at the same time */ - /* format myFlags,ptr,length,ptr,length ... until null ptr */ - -#include "mysys_priv.h" -#include - -gptr my_multi_malloc(myf myFlags, ...) -{ - va_list args; - char **ptr,*start,*res; - uint tot_length,length; - DBUG_ENTER("my_multi_malloc"); - - va_start(args,myFlags); - tot_length=0; - while ((ptr=va_arg(args, char **))) - { - length=va_arg(args,uint); - tot_length+=ALIGN_SIZE(length); - } - va_end(args); - - if (!(start=(char *) ma_malloc(tot_length,myFlags))) - DBUG_RETURN(0); /* purecov: inspected */ - - va_start(args,myFlags); - res=start; - while ((ptr=va_arg(args, char **))) - { - *ptr=res; - length=va_arg(args,uint); - res+=ALIGN_SIZE(length); - } - va_end(args); - DBUG_RETURN((gptr) start); -} diff --git a/libmariadb/my_alloc.c b/libmariadb/my_alloc.c index 96ea05b0..2616e3e7 100644 --- a/libmariadb/my_alloc.c +++ b/libmariadb/my_alloc.c @@ -31,8 +31,7 @@ void ma_init_ma_alloc_root(MA_MEM_ROOT *mem_root, size_t block_size, size_t pre_ if (pre_alloc_size) { if ((mem_root->free = mem_root->pre_alloc= - (MA_USED_MEM*) ma_malloc(pre_alloc_size+ ALIGN_SIZE(sizeof(MA_USED_MEM)), - MYF(0)))) + (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; @@ -48,7 +47,7 @@ gptr ma_alloc_root(MA_MEM_ROOT *mem_root, size_t Size) reg1 MA_USED_MEM *next; Size+=ALIGN_SIZE(sizeof(MA_USED_MEM)); - if (!(next = (MA_USED_MEM*) ma_malloc(Size,MYF(MY_WME)))) + if (!(next = (MA_USED_MEM*) malloc(Size))) { if (mem_root->error_handler) (*mem_root->error_handler)(); @@ -78,7 +77,7 @@ gptr ma_alloc_root(MA_MEM_ROOT *mem_root, size_t Size) if (max_left*4 < mem_root->block_size && get_size < mem_root->block_size) get_size=mem_root->block_size; /* Normal alloc */ - if (!(next = (MA_USED_MEM*) ma_malloc(get_size,MYF(MY_WME | MY_ZEROFILL)))) + if (!(next = (MA_USED_MEM*) calloc(1, get_size))) { if (mem_root->error_handler) (*mem_root->error_handler)(); @@ -116,13 +115,13 @@ void ma_free_root(MA_MEM_ROOT *root, myf MyFlags) { old=next; next= next->next ; if (old != root->pre_alloc) - ma_free(old); + free(old); } for (next= root->free ; next ; ) { old=next; next= next->next ; if (old != root->pre_alloc) - ma_free(old); + free(old); } root->used=root->free=0; if (root->pre_alloc) diff --git a/libmariadb/my_compress.c b/libmariadb/my_compress.c index 27bdaa52..72df4cdf 100644 --- a/libmariadb/my_compress.c +++ b/libmariadb/my_compress.c @@ -39,7 +39,7 @@ my_bool my_compress(unsigned char *packet, size_t *len, size_t *complen) if (!compbuf) return *complen ? 0 : 1; memcpy(packet,compbuf,*len); - ma_free(compbuf); + free(compbuf); } return 0; } @@ -49,18 +49,18 @@ unsigned char *my_compress_alloc(const unsigned char *packet, size_t *len, size_ { unsigned char *compbuf; *complen = *len * 120 / 100 + 12; - if (!(compbuf = (unsigned char *) ma_malloc(*complen,MYF(MY_WME)))) + if (!(compbuf = (unsigned char *) malloc(*complen))) return 0; /* Not enough memory */ if (compress((Bytef*) compbuf,(ulong *) complen, (Bytef*) packet, (uLong) *len ) != Z_OK) { - ma_free(compbuf); + free(compbuf); return 0; } if (*complen >= *len) { *complen=0; - ma_free(compbuf); + free(compbuf); return 0; } swap(size_t,*len,*complen); /* *len is now packet length */ @@ -71,17 +71,17 @@ my_bool my_uncompress (unsigned char *packet, size_t *len, size_t *complen) { if (*complen) /* If compressed */ { - unsigned char *compbuf = (unsigned char *) ma_malloc (*complen,MYF(MY_WME)); + 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 */ - ma_free (compbuf); + free(compbuf); return 1; } *len = *complen; memcpy(packet,compbuf,*len); - ma_free(compbuf); + free(compbuf); } else *complen= *len; return 0; diff --git a/libmariadb/my_fopen.c b/libmariadb/my_fopen.c index 4727f8fa..9a3ff822 100644 --- a/libmariadb/my_fopen.c +++ b/libmariadb/my_fopen.c @@ -19,6 +19,7 @@ #include "my_static.h" #include #include "mysys_err.h" +#include static void make_ftype(my_string to,int flag); @@ -54,7 +55,7 @@ FILE *my_fopen(const char *FileName, int Flags, myf MyFlags) } pthread_mutex_lock(&THR_LOCK_open); if ((ma_file_info[fileno(fd)].name = (char*) - ma_strdup(FileName,MyFlags))) + strdup(FileName))) { ma_stream_opened++; ma_file_info[fileno(fd)].type = STREAM_BY_FOPEN; @@ -99,7 +100,7 @@ int my_fclose(FILE *fd, myf MyFlags) if ((uint) file < MY_NFILE && ma_file_info[file].type != UNOPEN) { ma_file_info[file].type = UNOPEN; - ma_free(ma_file_info[file].name); + free(ma_file_info[file].name); } pthread_mutex_unlock(&THR_LOCK_open); DBUG_RETURN(err); @@ -136,7 +137,7 @@ FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags) } else { - ma_file_info[Filedes].name= ma_strdup(name,MyFlags); + ma_file_info[Filedes].name= strdup(name); } ma_file_info[Filedes].type = STREAM_BY_FDOPEN; } diff --git a/libmariadb/my_getwd.c b/libmariadb/my_getwd.c index 59afcece..602d13de 100644 --- a/libmariadb/my_getwd.c +++ b/libmariadb/my_getwd.c @@ -50,7 +50,7 @@ int my_getwd(my_string buf, uint size, myf MyFlags) #if ! defined(MSDOS) if (ma_cur_dir[0]) /* Current pos is saved here */ - VOID(strmake(buf,&ma_cur_dir[0],size-1)); + strncpy(buf,&ma_cur_dir[0],size-1); else #endif { @@ -69,7 +69,7 @@ int my_getwd(my_string buf, uint size, myf MyFlags) { char pathname[MAXPATHLEN]; getwd(pathname); - strmake(buf,pathname,size-1); + strncpy(buf,pathname,size-1); } #elif defined(VMS) if (!getcwd(buf,size-2,1) && MyFlags & MY_WME) @@ -87,7 +87,7 @@ int my_getwd(my_string buf, uint size, myf MyFlags) pos[0]= FN_LIBCHAR; pos[1]=0; } - (void) strmake(&ma_cur_dir[0],buf,(size_s) (FN_REFLEN-1)); + strncpy(&ma_cur_dir[0],buf,(size_s) (FN_REFLEN-1)); } DBUG_RETURN(0); } /* my_getwd */ @@ -137,7 +137,7 @@ int my_setwd(const char *dir, myf MyFlags) #endif if (*((pos=strend(dir)-1)) == FN_LIBCHAR && pos != dir) { - strmov(buff,dir)[-1]=0; /* Remove last '/' */ + strncpy(buff, dir, strlen(dir) - 1); /* Remove last '/' */ dir=buff; } #endif /* MSDOS*/ @@ -169,7 +169,7 @@ int my_setwd(const char *dir, myf MyFlags) { if (test_if_hard_path(start)) { /* Hard pathname */ - pos=strmake(&ma_cur_dir[0],start,(size_s) FN_REFLEN-1); + pos=strncpy(&ma_cur_dir[0],start,(size_s) FN_REFLEN-1) + strlen(&ma_cur_dir[0]); if (pos[-1] != FN_LIBCHAR) { length=(uint) (pos-(char*) ma_cur_dir); diff --git a/libmariadb/my_init.c b/libmariadb/my_init.c index 2cbd6f04..e9437ef3 100644 --- a/libmariadb/my_init.c +++ b/libmariadb/my_init.c @@ -194,7 +194,7 @@ Voluntary context switches %ld, Involuntary context switches %ld\n", void setEnvString(char *ret, const char *name, const char *value) { DBUG_ENTER("setEnvString"); - strxmov(ret, name,"=",value,NullS); + sprintf(ret, "%s=%S", name, value); DBUG_VOID_RETURN ; } diff --git a/libmariadb/my_lib.c b/libmariadb/my_lib.c index 0d86218c..4327f79f 100644 --- a/libmariadb/my_lib.c +++ b/libmariadb/my_lib.c @@ -75,7 +75,7 @@ void my_dirend(MY_DIR *buffer) { DBUG_ENTER("my_dirend"); if (buffer) - ma_free(buffer); + free(buffer); DBUG_VOID_RETURN; } /* my_dirend */ @@ -112,7 +112,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags) dirp = opendir(directory_file_name(tmp_path,(my_string) path)); size = STARTSIZE; - if (dirp == NULL || ! (buffer = (char *) ma_malloc(size, MyFlags))) + if (dirp == NULL || ! (buffer = (char *) malloc(size))) goto error; fcnt = 0; @@ -146,8 +146,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags) if (eof) break; size += STARTSIZE; obuffer = buffer; - if (!(buffer = (char *) ma_realloc((gptr) buffer, size, - MyFlags | MY_FREE_ON_ERROR))) + if (!(buffer = (char *) realloc((gptr) buffer, size))) goto error; /* No memory */ length= (uint) (sizeof(struct fileinfo ) * firstfcnt); diff= PTR_BYTE_DIFF(buffer , obuffer) + (int) length; @@ -392,7 +391,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags) size = STARTSIZE; firstfcnt = maxfcnt = (size - sizeof(MY_DIR)) / (sizeof(struct fileinfo) + FN_LEN); - if ((buffer = (char *) ma_malloc(size, MyFlags)) == 0) + if ((buffer = (char *) malloc(size) == 0) goto error; fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR)); tempptr = (char *) (fnames + maxfcnt); @@ -435,8 +434,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags) if (eof) break; size += STARTSIZE; obuffer = buffer; - if (!(buffer = (char *) ma_realloc((gptr) buffer, size, - MyFlags | MY_FREE_ON_ERROR))) + if (!(buffer = (char *) realloc((gptr) buffer, size))) goto error; length= sizeof(struct fileinfo ) * firstfcnt; diff= PTR_BYTE_DIFF(buffer , obuffer) +length; @@ -514,7 +512,7 @@ MY_DIR *my_dir(const char* path, myf MyFlags) size = STARTSIZE; firstfcnt = maxfcnt = (size - sizeof(MY_DIR)) / (sizeof(struct fileinfo) + FN_LEN); - if ((buffer = (char *) ma_malloc(size, MyFlags)) == 0) + if ((buffer = (char *) malloc(size) == 0) goto error; fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR)); tempptr = (char *) (fnames + maxfcnt); @@ -543,8 +541,7 @@ MY_DIR *my_dir(const char* path, myf MyFlags) if (eof) break; size += STARTSIZE; obuffer = buffer; - if (!(buffer = (char *) ma_realloc((gptr) buffer, size, - MyFlags | MY_FREE_ON_ERROR))) + if (!(buffer = (char *) realloc((gptr) buffer, size))) goto error; length= sizeof(struct fileinfo ) * firstfcnt; diff= PTR_BYTE_DIFF(buffer , obuffer) +length; @@ -595,13 +592,13 @@ MY_STAT *my_stat(const char *path, MY_STAT *stat_area, myf my_flags) (unsigned char *) stat_area, my_flags)); if ((m_used= (stat_area == NULL))) - if (!(stat_area = (MY_STAT *) ma_malloc(sizeof(MY_STAT), my_flags))) + if (!(stat_area = (MY_STAT *) malloc(sizeof(MY_STAT)))) goto error; if ( ! stat((my_string) path, (struct stat *) stat_area) ) DBUG_RETURN(stat_area); my_errno=errno; if (m_used) /* Free if new area */ - ma_free(stat_area); + free(stat_area); error: if (my_flags & (MY_FAE+MY_WME)) diff --git a/libmariadb/my_loaddata.c b/libmariadb/my_loaddata.c index 574c995e..89f18459 100644 --- a/libmariadb/my_loaddata.c +++ b/libmariadb/my_loaddata.c @@ -68,7 +68,7 @@ int mysql_local_infile_init(void **ptr, const char *filename, void *userdata) MYSQL *mysql= (MYSQL *)userdata; DBUG_ENTER("mysql_local_infile_init"); - info = (MYSQL_INFILE_INFO *)ma_malloc(sizeof(MYSQL_INFILE_INFO), MYF(MY_ZEROFILL)); + info = (MYSQL_INFILE_INFO *)calloc(1, sizeof(MYSQL_INFILE_INFO)); if (!info) { DBUG_RETURN(1); } @@ -153,7 +153,7 @@ void mysql_local_infile_end(void *ptr) { if (info->fp) ma_close(info->fp); - ma_free(ptr); + free(ptr); } DBUG_VOID_RETURN; } @@ -218,7 +218,7 @@ my_bool mysql_handle_local_infile(MYSQL *conn, const char *filename) } /* allocate buffer for reading data */ - buf = (uchar *)ma_malloc(buflen, MYF(0)); + buf = (uchar *)malloc(buflen); /* init handler: allocate read buffer and open file */ if (conn->options.local_infile_init(&info, filename, @@ -264,7 +264,7 @@ my_bool mysql_handle_local_infile(MYSQL *conn, const char *filename) infile_error: conn->options.local_infile_end(info); - ma_free(buf); + free(buf); DBUG_RETURN(result); } /* }}} */ diff --git a/libmariadb/my_malloc.c b/libmariadb/my_malloc.c deleted file mode 100644 index 8a077333..00000000 --- a/libmariadb/my_malloc.c +++ /dev/null @@ -1,101 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#ifdef SAFEMALLOC /* We don't need SAFEMALLOC here */ -#undef SAFEMALLOC -#endif - -#include "mysys_priv.h" -#include "mysys_err.h" -#include - - /* My memory allocator */ - -gptr ma_malloc(size_t Size, myf MyFlags) -{ - gptr point; - DBUG_ENTER("ma_malloc"); - DBUG_PRINT("my",("Size: %u MyFlags: %d",Size, MyFlags)); - - if (!Size) - Size=1; /* Safety */ - if ((point = (char*)malloc(Size)) == NULL) - { - my_errno=errno; - if (MyFlags & MY_FAE) - ma_error_handler_hook=fatal_ma_error_handler_hook; - if (MyFlags & (MY_FAE+MY_WME)) - ma_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG),Size); - if (MyFlags & MY_FAE) - exit(1); - } - else if (MyFlags & MY_ZEROFILL) - bzero(point,Size); - DBUG_PRINT("exit",("ptr: %lx",point)); - DBUG_RETURN(point); -} /* ma_malloc */ - - - /* Free memory allocated with ma_malloc */ - /*ARGSUSED*/ - -void my_no_flags_free(void *ptr) -{ - DBUG_ENTER("ma_free"); - DBUG_PRINT("my",("ptr: %lx",ptr)); - if (ptr) - free(ptr); - DBUG_VOID_RETURN; -} /* ma_free */ - - - /* malloc and copy */ - -gptr ma_memdup(const unsigned char *from, size_t length, myf MyFlags) -{ - gptr ptr; - if ((ptr=ma_malloc(length,MyFlags)) != 0) - memcpy((unsigned char*) ptr, (unsigned char*) from,(size_t) length); - return(ptr); -} - - -my_string ma_strdup(const char *from, myf MyFlags) -{ - gptr ptr; - uint length; - - if ((MyFlags & MY_ALLOW_ZERO_PTR) && !from) - return NULL; - - length=(uint) strlen(from)+1; - if ((ptr=ma_malloc(length,MyFlags)) != 0) - memcpy((unsigned char*) ptr, (unsigned char*) from,(size_t) length); - return((my_string) ptr); -} - -my_string ma_strndup(const char *src, size_t length, myf MyFlags) -{ - gptr ptr; - - if ((ptr= ma_malloc(length+1, MyFlags))) { - memcpy(ptr, src, length); - ptr[length] = 0; - } - return ptr; -} -/* }}} */ diff --git a/libmariadb/my_messnc.c b/libmariadb/my_messnc.c index b81160d4..b3088670 100644 --- a/libmariadb/my_messnc.c +++ b/libmariadb/my_messnc.c @@ -16,9 +16,8 @@ MA 02111-1307, USA */ #include "mysys_priv.h" - -int ma_message_no_curses(uint error __attribute__((unused)), - const char *str, myf MyFlags) +int ma_message_no_curses(uint error __attribute__((unused)), + const char *str, myf MyFlags) { DBUG_ENTER("ma_message_no_curses"); DBUG_PRINT("enter",("message: %s",str)); diff --git a/libmariadb/my_net.c b/libmariadb/my_net.c index 2e6fa03b..b865c491 100644 --- a/libmariadb/my_net.c +++ b/libmariadb/my_net.c @@ -39,6 +39,6 @@ void my_inet_ntoa(struct in_addr in, char *buf) char *ptr; pthread_mutex_lock(&THR_LOCK_net); ptr=inet_ntoa(in); - strmov(buf,ptr); + strcpy(buf,ptr); pthread_mutex_unlock(&THR_LOCK_net); } diff --git a/libmariadb/my_open.c b/libmariadb/my_open.c index 31a59d59..50bf6341 100644 --- a/libmariadb/my_open.c +++ b/libmariadb/my_open.c @@ -101,7 +101,7 @@ File my_register_filename(File fd, const char *FileName, enum file_type return(fd); /* safeguard */ } pthread_mutex_lock(&THR_LOCK_open); - if ((ma_file_info[fd].name = (char*) ma_strdup(FileName,MyFlags))) + if ((ma_file_info[fd].name = (char*) strdup(FileName))) { ma_file_opened++; ma_file_info[fd].type = type_of_file; diff --git a/libmariadb/my_realloc.c b/libmariadb/my_realloc.c deleted file mode 100644 index 8ca285ae..00000000 --- a/libmariadb/my_realloc.c +++ /dev/null @@ -1,65 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#ifdef SAFEMALLOC /* We don't need SAFEMALLOC here */ -#undef SAFEMALLOC -#endif - -#include "mysys_priv.h" -#include "mysys_err.h" - - /* My memory re allocator */ - -gptr ma_realloc(gptr oldpoint, size_t Size, myf MyFlags) -{ - gptr point; - DBUG_ENTER("ma_realloc"); - DBUG_PRINT("my",("ptr: %lx Size: %u MyFlags: %d",oldpoint, Size, MyFlags)); - - if (!oldpoint && (MyFlags & MY_ALLOW_ZERO_PTR)) - DBUG_RETURN(ma_malloc(Size,MyFlags)); -#ifdef USE_HALLOC - if (!(point = malloc(Size))) - { - if (MyFlags & MY_FREE_ON_ERROR) - ma_free(oldpoint); - if (MyFlags & MY_HOLD_ON_ERROR) - DBUG_RETURN(oldpoint); - my_errno=errno; - if (MyFlags & MY_FAE+MY_WME) - ma_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG),Size); - } - else - { - memcpy(point,oldpoint,Size); - free(oldpoint); - } -#else - if ((point = (char*)realloc(oldpoint,Size)) == NULL) - { - if (MyFlags & MY_FREE_ON_ERROR) - ma_free(oldpoint); - if (MyFlags & MY_HOLD_ON_ERROR) - DBUG_RETURN(oldpoint); - my_errno=errno; - if (MyFlags & (MY_FAE+MY_WME)) - ma_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG), Size); - } -#endif - DBUG_PRINT("exit",("ptr: %lx",point)); - DBUG_RETURN(point); -} /* ma_realloc */ diff --git a/libmariadb/my_stmt.c b/libmariadb/my_stmt.c index b109415c..fe01f600 100644 --- a/libmariadb/my_stmt.c +++ b/libmariadb/my_stmt.c @@ -574,7 +574,8 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req DBUG_ENTER("mysql_stmt_execute_generate_request"); /* preallocate length bytes */ - if (!(start= p= (uchar *)ma_malloc(length, MYF(MY_WME | MY_ZEROFILL)))) + /* check: gr */ + if (!(start= p= (uchar *)malloc(length))) goto mem_error; int4store(p, stmt->stmt_id); @@ -597,7 +598,7 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req { size_t offset= p - start; length+= offset + null_count + 20; - if (!(start= (uchar *)ma_realloc((gptr)start, length, MYF(MY_WME | MY_ZEROFILL)))) + if (!(start= (uchar *)realloc((gptr)start, length))) goto mem_error; p= start + offset; } @@ -621,7 +622,7 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req { size_t offset= p - start; length= offset + stmt->param_count * 2 + 20; - if (!(start= (uchar *)ma_realloc((gptr)start, length, MYF(MY_WME | MY_ZEROFILL)))) + if (!(start= (uchar *)realloc((gptr)start, length))) goto mem_error; p= start + offset; } @@ -676,7 +677,7 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req { size_t offset= p - start; length= offset + data_size + 20; - if (!(start= (uchar *)ma_realloc((gptr)start, length, MYF(MY_WME | MY_ZEROFILL)))) + if (!(start= (uchar *)realloc((gptr)start, length))) goto mem_error; p= start + offset; } @@ -702,7 +703,7 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req mem_error: SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - ma_free(start); + free(start); *request_len= 0; DBUG_RETURN(NULL); } @@ -915,7 +916,6 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) { MA_MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; -// ma_free_root(fields_ma_alloc_root, MYF(0)); if (!(stmt->bind= (MYSQL_BIND *)ma_alloc_root(fields_ma_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); @@ -1025,8 +1025,8 @@ my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt) net_stmt_close(stmt, 1); - ma_free(stmt->extension); - ma_free(stmt); + free(stmt->extension); + free(stmt); DBUG_RETURN(0); } @@ -1159,14 +1159,13 @@ my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt) MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql) { - MYSQL_STMT *stmt; + MYSQL_STMT *stmt= NULL; DBUG_ENTER("mysql_stmt_init"); - if (!(stmt= (MYSQL_STMT *)ma_malloc(sizeof(MYSQL_STMT), MYF(MY_WME | MY_ZEROFILL))) || - !(stmt->extension= (MADB_STMT_EXTENSION *)ma_malloc(sizeof(MADB_STMT_EXTENSION), - MYF(MY_WME | MY_ZEROFILL)))) + if (!(stmt= (MYSQL_STMT *)calloc(1, sizeof(MYSQL_STMT))) || + !(stmt->extension= (MADB_STMT_EXTENSION *)calloc(1, sizeof(MADB_STMT_EXTENSION)))) { - ma_free(stmt); + free(stmt); SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(NULL); } @@ -1668,7 +1667,7 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) request_len, 1, stmt); if (request) - ma_free(request); + free(request); if (ret) { @@ -1833,7 +1832,7 @@ MYSQL_RES * STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt) DBUG_RETURN(NULL); /* aloocate result set structutr and copy stmt information */ - if (!(res= (MYSQL_RES *)ma_malloc(sizeof(MYSQL_RES), MYF(MY_WME | MY_ZEROFILL)))) + if (!(res= (MYSQL_RES *)calloc(1, sizeof(MYSQL_RES)))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); DBUG_RETURN(NULL); @@ -1900,15 +1899,15 @@ my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number, if (length || !stmt->params[param_number].long_data_used) { int ret; - size_t packet_len; - uchar *cmd_buff= (uchar *)ma_malloc(packet_len= STMT_ID_LENGTH + 2 + length, MYF(MY_WME | MY_ZEROFILL)); + size_t packet_len= STMT_ID_LENGTH + 2 + length; + uchar *cmd_buff= (uchar *)calloc(1, packet_len); int4store(cmd_buff, stmt->stmt_id); int2store(cmd_buff + STMT_ID_LENGTH, param_number); memcpy(cmd_buff + STMT_ID_LENGTH + 2, data, length); stmt->params[param_number].long_data_used= 1; ret= stmt->mysql->methods->db_command(stmt->mysql, COM_STMT_SEND_LONG_DATA, (char *)cmd_buff, packet_len, 1, stmt); - ma_free(cmd_buff); + free(cmd_buff); DBUG_RETURN(ret); } DBUG_RETURN(0); diff --git a/libmariadb/my_stmt_codec.c b/libmariadb/my_stmt_codec.c index 09f39443..66fe7b85 100644 --- a/libmariadb/my_stmt_codec.c +++ b/libmariadb/my_stmt_codec.c @@ -569,8 +569,8 @@ static void convert_from_float(MYSQL_BIND *r_param, const MYSQL_FIELD *field, do { #define MAX_DOUBLE_STRING_REP_LENGTH 300 char buff[MAX_DOUBLE_STRING_REP_LENGTH]; - char *end; size_t length; + char *end; length= MIN(MAX_DOUBLE_STRING_REP_LENGTH - 1, r_param->buffer_length); @@ -585,9 +585,10 @@ static void convert_from_float(MYSQL_BIND *r_param, const MYSQL_FIELD *field, do length= strlen(buff); } - /* remove possible trailing blanks */ - if ((end= strcend(buff, ' '))) - *end= 0; + /* remove trailing blanks */ + end= strchr(buff, '\0') - 1; + while (end > buff && *end == ' ') + *end--= '\0'; /* check if ZEROFILL flag is active */ if (field->flags & ZEROFILL_FLAG) diff --git a/libmariadb/my_symlink.c b/libmariadb/my_symlink.c index a4853474..b26ef197 100644 --- a/libmariadb/my_symlink.c +++ b/libmariadb/my_symlink.c @@ -35,7 +35,7 @@ int my_readlink(char *to, const char *filename, myf MyFlags) { #ifndef HAVE_READLINK - strmov(to,filename); + strcpy(to,filename); return 1; #else int result=0; @@ -48,7 +48,7 @@ int my_readlink(char *to, const char *filename, myf MyFlags) if ((my_errno=errno) == EINVAL) { result= 1; - strmov(to,filename); + strcpy(to,filename); } else { @@ -117,7 +117,7 @@ int my_realpath(char *to, const char *filename, myf MyFlags) { char *ptr; if ((ptr=realpath(filename,buff))) - strmake(to,ptr,FN_REFLEN-1); + strncpy(to,ptr,FN_REFLEN-1); else { /* Realpath didn't work; Use original name */ @@ -132,7 +132,7 @@ int my_realpath(char *to, const char *filename, myf MyFlags) DBUG_RETURN(result); #else if (to != filename) - strmov(to,filename); + strcpy(to,filename); return 0; #endif } diff --git a/libmariadb/my_thr_init.c b/libmariadb/my_thr_init.c index 12bb0b48..4408ed1b 100644 --- a/libmariadb/my_thr_init.c +++ b/libmariadb/my_thr_init.c @@ -216,7 +216,7 @@ const char *ma_thread_name(void) { long id=my_thread_id(); sprintf(name_buff,"T@%ld", id); - strmake(tmp->name,name_buff,THREAD_NAME_SIZE); + strncpy(tmp->name,name_buff,THREAD_NAME_SIZE); } return tmp->name; } diff --git a/libmariadb/net.c b/libmariadb/net.c index 4511f9ec..ef1a4fb6 100644 --- a/libmariadb/net.c +++ b/libmariadb/net.c @@ -114,7 +114,7 @@ static int net_write_buff(NET *net,const char *packet, size_t len); int my_net_init(NET *net, MARIADB_PVIO* pvio) { - if (!(net->buff=(uchar*) ma_malloc(net_buffer_length,MYF(MY_WME | MY_ZEROFILL)))) + if (!(net->buff=(uchar*) calloc(1, net_buffer_length))) return 1; /* We don't allocate memory for multi buffer, since we don't know in advance if the server @@ -144,8 +144,8 @@ int my_net_init(NET *net, MARIADB_PVIO* pvio) void net_end(NET *net) { - ma_free(net->buff); - ma_free(net->mbuff); + free(net->buff); + free(net->mbuff); net->buff=0; net->mbuff= 0; } @@ -171,9 +171,8 @@ static my_bool net_realloc(NET *net, my_bool is_multi, size_t length) pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1); /* reallocate buffer: size= pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE */ - if (!(buff=(uchar*) ma_realloc(is_multi ? net->mbuff : net->buff, - pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE, - MYF(MY_WME)))) + if (!(buff=(uchar*) realloc(is_multi ? net->mbuff : net->buff, + pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE))) { DBUG_PRINT("info", ("Out of memory")); net->error=1; @@ -353,7 +352,7 @@ int net_add_multi_command(NET *net, uchar command, const uchar *packet, if (!net->mbuff) { size_t alloc_size= (required_length + IO_SIZE - 1) & ~(IO_SIZE - 1); - if (!(net->mbuff= (char *)ma_malloc(alloc_size, MYF(MY_WME)))) + if (!(net->mbuff= (char *)malloc(alloc_size))) { net->last_errno=ER_OUT_OF_RESOURCES; net->error=2; @@ -384,7 +383,7 @@ int net_add_multi_command(NET *net, uchar command, const uchar *packet, error: if (net->mbuff) { - ma_free(net->mbuff); + free(net->mbuff); net->mbuff= net->mbuff_pos= net->mbuff_end= 0; } return 1; @@ -409,8 +408,7 @@ net_real_write(NET *net,const char *packet,size_t len) size_t complen; uchar *b; uint header_length=NET_HEADER_SIZE+COMP_HEADER_SIZE; - if (!(b=(uchar*) ma_malloc(len + NET_HEADER_SIZE + COMP_HEADER_SIZE + 1, - MYF(MY_WME)))) + if (!(b=(uchar*) malloc(len + NET_HEADER_SIZE + COMP_HEADER_SIZE + 1))) { net->last_errno=ER_OUT_OF_RESOURCES; net->error=2; @@ -448,7 +446,7 @@ net_real_write(NET *net,const char *packet,size_t len) } #ifdef HAVE_COMPRESS if (net->compress) - ma_free((char*) packet); + free((char*) packet); #endif net->reading_or_writing=0; DBUG_RETURN(((int) (pos != end))); diff --git a/libmariadb/strcend.c b/libmariadb/strcend.c deleted file mode 100644 index 0b7e9acf..00000000 --- a/libmariadb/strcend.c +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : strcend.c - Author : Michael Widenius: ifdef MC68000 - Updated: 20 April 1984 - Defines: strcend() - - strcend(s, c) returns a pointer to the first place in s where c - occurs, or a pointer to the end-null of s if c does not occur in s. -*/ - -#include -#include "m_string.h" - -/** - \fn char *strcend - \brief returns a pointer to the first occurence of specified stopchar - \param str char * - \param stopchar char - - returns a poimter to the first occurence of stopchar or to null char, - if stopchar wasn't found. -*/ -char *strcend(register const char *str, register char stopchar) -{ - for (;;) - { - if (*str == stopchar) - return (char*) str; - if (!*str++) - return (char*) str-1; - } -} diff --git a/libmariadb/strend.c b/libmariadb/strend.c deleted file mode 100644 index 0e9c0333..00000000 --- a/libmariadb/strend.c +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright (C) 2002 MySQL AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : strend.c - Author : Richard A. O'Keefe. - Updated: 23 April 1984 - Defines: strend() - - strend(s) returns a character pointer to the NUL which ends s. That - is, strend(s)-s == strlen(s). This is useful for adding things at - the end of strings. It is redundant, because strchr(s,'\0') could - be used instead, but this is clearer and faster. - Beware: the asm version works only if strlen(s) < 65535. -*/ - -#include -#include "m_string.h" - -#if VaxAsm - -char *strend(s) -const char *s; -{ - asm("locc $0,$65535,*4(ap)"); - asm("movl r1,r0"); -} - -#else /* ~VaxAsm */ - -char *strend(register const char *s) -{ - while (*s++); - return (char*) (s-1); -} - -#endif /* VaxAsm */ diff --git a/libmariadb/strfill.c b/libmariadb/strfill.c deleted file mode 100644 index 0559f171..00000000 --- a/libmariadb/strfill.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : strfill.c - Author : Monty - Updated: 1987.04.16 - Defines: strfill() - - strfill(dest, len, fill) makes a string of fill-characters. The result - string is of length == len. The des+len character is allways set to NULL. - strfill() returns pointer to dest+len; -*/ - -#include -#include "m_string.h" - -my_string strfill(my_string s, size_t len, pchar fill) -{ - while (len--) *s++ = fill; - *(s) = '\0'; - return(s); -} /* strfill */ diff --git a/libmariadb/string.c b/libmariadb/string.c index daf3dab8..4d152d91 100644 --- a/libmariadb/string.c +++ b/libmariadb/string.c @@ -38,7 +38,7 @@ my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str, if (!init_alloc) init_alloc=alloc_increment; - if (!(str->str=(char*) ma_malloc(init_alloc,MYF(MY_WME)))) + if (!(str->str=(char*) malloc(init_alloc))) DBUG_RETURN(TRUE); str->length=length-1; if (init_str) @@ -60,7 +60,7 @@ my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str) str->alloc_increment; if (!str->max_length) str->max_length=str->alloc_increment; - if (!(str->str=(char*) ma_realloc(str->str,str->max_length,MYF(MY_WME)))) + if (!(str->str=(char*) realloc(str->str,str->max_length))) DBUG_RETURN(TRUE); } if (init_str) @@ -83,7 +83,7 @@ my_bool dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size) { str->max_length=((str->length + additional_size+str->alloc_increment-1)/ str->alloc_increment)*str->alloc_increment; - if (!(str->str=(char*) ma_realloc(str->str,str->max_length,MYF(MY_WME)))) + if (!(str->str=(char*) realloc(str->str,str->max_length))) DBUG_RETURN(TRUE); } DBUG_RETURN(FALSE); @@ -105,7 +105,7 @@ my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append, size_t new_length=(str->length+length+str->alloc_increment)/ str->alloc_increment; new_length*=str->alloc_increment; - if (!(new_ptr=(char*) ma_realloc(str->str,new_length,MYF(MY_WME)))) + if (!(new_ptr=(char*) realloc(str->str,new_length))) return TRUE; str->str=new_ptr; str->max_length=new_length; @@ -121,7 +121,7 @@ void dynstr_free(DYNAMIC_STRING *str) { if (str->str) { - ma_free(str->str); + free(str->str); str->str=0; } } diff --git a/libmariadb/strinstr.c b/libmariadb/strinstr.c deleted file mode 100644 index 8ebd6afb..00000000 --- a/libmariadb/strinstr.c +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : strinstr.c - Author : Monty & David - Updated: 1986.12.08 - Defines: strinstr() - - strinstr(src, pat) looks for an instance of pat in src. pat is not a - regex(3) pattern, it is a literal string which must be matched exactly. - The result 0 if the pattern was not found else it is the start char of - the pattern counted from the beginning of the string, where the first - char is 1. -*/ - -#include -#include "m_string.h" - -uint strinstr(reg1 const char *str,reg4 const char *search) -{ - reg2 my_string i,j; - my_string start = (my_string) str; - - skipp: - while (*str != '\0') - { - if (*str++ == *search) - { - i=(my_string) str; j= (my_string) search+1; - while (*j) - if (*i++ != *j++) goto skipp; - return ((uint) (str - start)); - } - } - return (0); -} diff --git a/libmariadb/strmake.c b/libmariadb/strmake.c deleted file mode 100644 index c7820947..00000000 --- a/libmariadb/strmake.c +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : strmake.c - Author : Michael Widenius - Updated: 20 Jul 1984 - Defines: strmake() - - strmake(dst,src,length) moves length characters, or until end, of src to - dst and appends a closing NUL to dst. - Note that is strlen(src) >= length then dst[length] will be set to \0 - strmake() returns pointer to closing null -*/ - -#include -#include "m_string.h" - -#ifdef BAD_STRING_COMPILER - -char *strmake(char *dst,const char *src, size_t length) -{ - reg1 char *res; - - if ((res=memccpy(dst,src,0,length))) - return res-1; - dst[length]=0; - return dst+length; -} - -#define strmake strmake_overlapp /* Use orginal for overlapping str */ -#endif - -char *strmake(register char *dst, register const char *src, size_t length) -{ - while (length--) - if (! (*dst++ = *src++)) - return dst-1; - *dst=0; - return dst; -} diff --git a/libmariadb/strmov.c b/libmariadb/strmov.c deleted file mode 100644 index 5502c40b..00000000 --- a/libmariadb/strmov.c +++ /dev/null @@ -1,59 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - strmov(dst, src) moves all the characters of src (including the - closing NUL) to dst, and returns a pointer to the new closing NUL in - dst. The similar UNIX routine strcpy returns the old value of dst, - which I have never found useful. strmov(strmov(dst,a),b) moves a//b - into dst, which seems useful. -*/ - -#include -#include "m_string.h" - -#ifdef BAD_STRING_COMPILER -#undef strmov -#define strmov strmov_overlapp -#endif - -#ifndef strmov - -#if !defined(MC68000) && !defined(DS90) - -char *strmov(register char *dst, register const char *src) -{ - while ((*dst++ = *src++)) ; - return dst-1; -} - -#else - -char *strmov(dst, src) - char *dst, *src; -{ - asm(" movl 4(a7),a1 "); - asm(" movl 8(a7),a0 "); - asm(".L4: movb (a0)+,(a1)+ "); - asm(" jne .L4 "); - asm(" movl a1,d0 "); - asm(" subql #1,d0 "); -} - -#endif - -#endif /* strmov */ diff --git a/libmariadb/strnlen.c b/libmariadb/strnlen.c deleted file mode 100644 index b630edec..00000000 --- a/libmariadb/strnlen.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : strnlen.c - Author : Michael Widenius - Updated: 20 April 1984 - Defines: strnlen. - strnlen(s, len) returns the length of s or len if s is longer than len. -*/ - -#include -#include "m_string.h" - -#ifndef HAVE_STRNLEN - -uint strnlen(register const char *s, register uint maxlen) -{ - const char *end= (const char *)memchr(s, '\0', maxlen); - return end ? (uint) (end - s) : maxlen; -} - -#endif diff --git a/libmariadb/strnmov.c b/libmariadb/strnmov.c deleted file mode 100644 index 5b3e3b3b..00000000 --- a/libmariadb/strnmov.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - strnmov(dst,src,length) moves length characters, or until end, of src to - dst and appends a closing NUL to dst if src is shorter than length. - The result is a pointer to the first NUL in dst, or is dst+n if dst was - truncated. -*/ - -#include -#include "m_string.h" - -char *strnmov(register char *dst, register const char *src, uint n) -{ - while (n-- != 0) { - if (!(*dst++ = *src++)) { - return (char*) dst-1; - } - } - return dst; -} diff --git a/libmariadb/strxmov.c b/libmariadb/strxmov.c deleted file mode 100644 index fe1e88c1..00000000 --- a/libmariadb/strxmov.c +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright (C) 2002 MySQL AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : strxmov.c - Author : Richard A. O'Keefe. - Updated: 25 may 1984 - Defines: strxmov() - - strxmov(dst, src1, ..., srcn, NullS) - moves the concatenation of src1,...,srcn to dst, terminates it - with a NUL character, and returns a pointer to the terminating NUL. - It is just like strmov except that it concatenates multiple sources. - Beware: the last argument should be the null character pointer. - Take VERY great care not to omit it! Also be careful to use NullS - and NOT to use 0, as on some machines 0 is not the same size as a - character pointer, or not the same bit pattern as NullS. -*/ - -#include -#include "m_string.h" -#include - -char *strxmov(char *dst,const char *src, ...) -{ - va_list pvar; - - va_start(pvar,src); - while (src != NullS) { - while ((*dst++ = *src++)) ; - dst--; - src = va_arg(pvar, char *); - } - va_end(pvar); - *dst = 0; /* there might have been no sources! */ - return dst; -} diff --git a/libmariadb/strxnmov.c b/libmariadb/strxnmov.c deleted file mode 100644 index d5167f69..00000000 --- a/libmariadb/strxnmov.c +++ /dev/null @@ -1,48 +0,0 @@ -/* File : strxnmov.c - Author : Richard A. O'Keefe. - Updated: 2 June 1984 - Defines: strxnmov() - - strxnmov(dst, len, src1, ..., srcn, NullS) - moves the first len characters of the concatenation of src1,...,srcn - to dst. If there aren't that many characters, a NUL character will - be added to the end of dst to terminate it properly. This gives the - same effect as calling strxcpy(buff, src1, ..., srcn, NullS) with a - large enough buffer, and then calling strnmov(dst, buff, len). - It is just like strnmov except that it concatenates multiple sources. - Beware: the last argument should be the null character pointer. - Take VERY great care not to omit it! Also be careful to use NullS - and NOT to use 0, as on some machines 0 is not the same size as a - character pointer, or not the same bit pattern as NullS. - - Note: strxnmov is like strnmov in that it moves up to len - characters; dst will be padded on the right with one NUL characters if - needed. -*/ - -#include -#include "m_string.h" -#include - -char *strxnmov(char *dst, size_t len, const char *src, ...) -{ - va_list pvar; - char *end_of_dst=dst+len; - - va_start(pvar,src); - while (src != NullS) - { - do - { - if (dst == end_of_dst) - goto end; - } - while ((*dst++ = *src++)); - dst--; - src = va_arg(pvar, char *); - } - *dst=0; -end: - va_end(pvar); - return dst; -} diff --git a/plugins/auth/my_auth.c b/plugins/auth/my_auth.c index 2753284e..640d705b 100644 --- a/plugins/auth/my_auth.c +++ b/plugins/auth/my_auth.c @@ -102,9 +102,9 @@ static int send_change_user_packet(MCPVIO_EXT *mpvio, size_t conn_attr_len= (mysql->options.extension) ? mysql->options.extension->connect_attrs_len : 0; - buff= my_alloca(USERNAME_LENGTH+1 + data_len+1 + NAME_LEN+1 + 2 + NAME_LEN+1 + 9 + conn_attr_len); + buff= malloc(USERNAME_LENGTH+1 + data_len+1 + NAME_LEN+1 + 2 + NAME_LEN+1 + 9 + conn_attr_len); - end= strmake(buff, mysql->user, USERNAME_LENGTH) + 1; + end= strncpy(buff, mysql->user, USERNAME_LENGTH) + strlen(buff) + 1; if (!data_len) *end++= 0; @@ -128,7 +128,7 @@ static int send_change_user_packet(MCPVIO_EXT *mpvio, memcpy(end, data, data_len); end+= data_len; } - end= strmake(end, mpvio->db ? mpvio->db : "", NAME_LEN) + 1; + end= strncpy(end, mpvio->db ? mpvio->db : "", NAME_LEN) + strlen(end) + 1; if (mysql->server_capabilities & CLIENT_PROTOCOL_41) { @@ -137,7 +137,7 @@ static int send_change_user_packet(MCPVIO_EXT *mpvio, } if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH) - end= strmake(end, mpvio->plugin->name, NAME_LEN) + 1; + end= strncpy(end, mpvio->plugin->name, NAME_LEN) + strlen(end) + 1; end= ma_send_connect_attr(mysql, end); @@ -145,7 +145,7 @@ static int send_change_user_packet(MCPVIO_EXT *mpvio, buff, (ulong)(end-buff), 1, NULL); error: - my_afree(buff); + free(buff); return res; } @@ -161,7 +161,7 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, mysql->options.extension->connect_attrs_len : 0; /* see end= buff+32 below, fixed size of the packet is 32 bytes */ - buff= my_alloca(33 + USERNAME_LENGTH + data_len + NAME_LEN + NAME_LEN + conn_attr_len + 9); + buff= malloc(33 + USERNAME_LENGTH + data_len + NAME_LEN + NAME_LEN + conn_attr_len + 9); mysql->client_flag|= mysql->options.client_flag; mysql->client_flag|= CLIENT_CAPABILITIES; @@ -264,7 +264,7 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, /* This needs to be changed as it's not useful with big packets */ if (mysql->user[0]) - strmake(end, mysql->user, USERNAME_LENGTH); + strncpy(end, mysql->user, USERNAME_LENGTH); else read_user_name(end); @@ -292,12 +292,12 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, /* Add database if needed */ if (mpvio->db && (mysql->server_capabilities & CLIENT_CONNECT_WITH_DB)) { - end= strmake(end, mpvio->db, NAME_LEN) + 1; - mysql->db= ma_strdup(mpvio->db, MYF(MY_WME)); + end= strncpy(end, mpvio->db, NAME_LEN) + strlen(end) + 1; + mysql->db= strdup(mpvio->db); } if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH) - end= strmake(end, mpvio->plugin->name, NAME_LEN) + 1; + end= strncpy(end, mpvio->plugin->name, NAME_LEN) + strlen(end) + 1; end= ma_send_connect_attr(mysql, end); @@ -310,11 +310,11 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, errno); goto error; } - my_afree(buff); + free(buff); return 0; error: - my_afree(buff); + free(buff); return 1; } diff --git a/plugins/pvio/pvio_socket.c b/plugins/pvio/pvio_socket.c index a2b36f49..849193ec 100644 --- a/plugins/pvio/pvio_socket.c +++ b/plugins/pvio/pvio_socket.c @@ -687,8 +687,7 @@ my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) if (!pvio || !cinfo) return 1; - if (!(csock= (struct st_pvio_socket *)ma_malloc(sizeof(struct st_pvio_socket), - MYF(MY_WME | MY_ZEROFILL)))) + if (!(csock= (struct st_pvio_socket *)calloc(1, sizeof(struct st_pvio_socket)))) { PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0, ""); return 1; @@ -838,7 +837,7 @@ my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) error: if (pvio->data) { - ma_free((gptr)pvio->data); + free((gptr)pvio->data); pvio->data= NULL; } return 1; @@ -862,7 +861,7 @@ my_bool pvio_socket_close(MARIADB_PVIO *pvio) r= closesocket(csock->socket); csock->socket= -1; } - ma_free((gptr)pvio->data); + free((gptr)pvio->data); pvio->data= NULL; } return r; From 5cd3d2d0c988d4ece1705088fa45402391936af7 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Thu, 4 Feb 2016 13:43:48 +0100 Subject: [PATCH 23/39] moved ma_error to errmsg.c and removed my_error.c --- libmariadb/CMakeLists.txt | 2 +- libmariadb/errmsg.c | 21 +++++++ libmariadb/my_error.c | 124 -------------------------------------- 3 files changed, 22 insertions(+), 125 deletions(-) delete mode 100644 libmariadb/my_error.c diff --git a/libmariadb/CMakeLists.txt b/libmariadb/CMakeLists.txt index 020ec597..35862b6b 100644 --- a/libmariadb/CMakeLists.txt +++ b/libmariadb/CMakeLists.txt @@ -295,7 +295,7 @@ my_alloc.c my_compress.c my_context.c my_div.c -my_error.c +#my_error.c my_fopen.c my_fstream.c my_getwd.c diff --git a/libmariadb/errmsg.c b/libmariadb/errmsg.c index 936db98e..171ee04a 100644 --- a/libmariadb/errmsg.c +++ b/libmariadb/errmsg.c @@ -154,7 +154,28 @@ const char *mariadb_client_errors[] = "" }; +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]; } + +int ma_error(int nr,myf myFlags, ...) +{ + va_list args; + const char *errormsg; + char buffer[ERRMSGSIZE]; + + va_start(args, myFlags); + + if (!(errormsg= ER(nr))) + snprintf(buffer, ERRMSGSIZE, "Unknown error: %d", nr); + else + vsnprintf(buffer, ERRMSGSIZE, errormsg, args); + + va_end(args); + + return (*ma_error_handler_hook)(nr, buffer, myFlags); +} diff --git a/libmariadb/my_error.c b/libmariadb/my_error.c deleted file mode 100644 index 15cd8e62..00000000 --- a/libmariadb/my_error.c +++ /dev/null @@ -1,124 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include "mysys_err.h" -#include -#include -#include - -/* Define some external variables for error handling */ - -const char ** NEAR my_errmsg[MAXMAPS]={0,0,0,0}; -char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE]; - -/* Error message to user */ -/*VARARGS2*/ - -int ma_error(int nr,myf MyFlags, ...) -{ - va_list ap; - uint olen, plen; - reg1 const char *tpos; - reg2 char *endpos; - char * par; - char ebuff[ERRMSGSIZE+20]; - DBUG_ENTER("ma_error"); - - va_start(ap,MyFlags); - DBUG_PRINT("my", ("nr: %d MyFlags: %d errno: %d", nr, MyFlags, errno)); - - if (nr / ERRMOD == GLOB && my_errmsg[GLOB] == 0) - ma_init_glob_errs(); - - olen=(uint) strlen(tpos=my_errmsg[nr / ERRMOD][nr % ERRMOD - EE_FIRSTERROR]); - endpos=ebuff; - - while (*tpos) - { - if (tpos[0] != '%') - { - *endpos++= *tpos++; /* Copy ordinary char */ - olen++; - continue; - } - if (*++tpos == '%') /* test if %% */ - { - olen--; - } - else - { - /* Skipp if max size is used (to be compatible with printf) */ - while (isdigit(*tpos) || *tpos == '.' || *tpos == '-') - tpos++; - if (*tpos == 'l') /* Skipp 'l' argument */ - tpos++; - if (*tpos == 's') /* String parameter */ - { - par = va_arg(ap, char *); - plen = (uint) strlen(par); - if (olen + plen < ERRMSGSIZE+2) /* Replace if possible */ - { - endpos=strmov(endpos,par); - tpos++; - olen+=plen-2; - continue; - } - } - else if (*tpos == 'd' || *tpos == 'u') /* Integer parameter */ - { - register int iarg; - iarg = va_arg(ap, int); - if (*tpos == 'd') - plen= (uint) (int2str((long) iarg,endpos, -10) - endpos); - else - plen= (uint) (int2str((long) (uint) iarg,endpos,10)- endpos); - if (olen + plen < ERRMSGSIZE+2) /* Replace parameter if possible */ - { - endpos+=plen; - tpos++; - olen+=plen-2; - continue; - } - } - } - *endpos++='%'; /* % used as % or unknown code */ - } - *endpos='\0'; /* End of errmessage */ - va_end(ap); - DBUG_RETURN((*ma_error_handler_hook)(nr, ebuff, MyFlags)); -} - - /* Error as printf */ - -int ma_printf_error (uint error, const char *format, myf MyFlags, ...) -{ - va_list args; - char ebuff[ERRMSGSIZE+20]; - - va_start(args,MyFlags); - (void) vsprintf (ebuff,format,args); - va_end(args); - return (*ma_error_handler_hook)(error, ebuff, MyFlags); -} - - /* Give message using ma_error_handler_hook */ - -int ma_message(uint error, const char *str, register myf MyFlags) -{ - return (*ma_error_handler_hook)(error, str, MyFlags); -} From 88015678c9a7c3da84cc7ecac7f4a7682a5b5688 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Thu, 4 Feb 2016 14:22:27 +0100 Subject: [PATCH 24/39] removed my_vsnprintf removed llstr.c renamed int2string function with prefix ma_ --- include/m_string.h | 14 ++--- libmariadb/CMakeLists.txt | 2 - libmariadb/int2str.c | 8 +-- libmariadb/libmariadb.c | 6 +- libmariadb/llstr.c | 36 ----------- libmariadb/longlong2str.c | 9 +-- libmariadb/ma_dyncol.c | 6 +- libmariadb/my_loaddata.c | 2 +- libmariadb/my_vsnprintf.c | 119 ------------------------------------- libmariadb/secure/gnutls.c | 2 +- plugins/pvio/pvio_socket.c | 2 +- 11 files changed, 25 insertions(+), 181 deletions(-) delete mode 100644 libmariadb/llstr.c delete mode 100644 libmariadb/my_vsnprintf.c diff --git a/include/m_string.h b/include/m_string.h index 39e23798..77edd38b 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -201,13 +201,13 @@ extern long strtol(const char *str, char **ptr, int base); extern ulong strtoul(const char *str, char **ptr, int base); #endif -extern char *int2str(long val,char *dst,int radix); -extern char *int10_to_str(long val,char *dst,int radix); -extern char *str2int(const char *src,int radix,long lower,long upper, +extern char *ma_int2str(long val,char *dst,int radix); +extern char *ma_int10_to_str(long val,char *dst,int radix); +extern char *ma_str2int(const char *src,int radix,long lower,long upper, long *val); #if SIZEOF_LONG == SIZEOF_LONG_LONG -#define longlong2str(A,B,C) int2str((A),(B),(C)) -#define longlong10_to_str(A,B,C) int10_to_str((A),(B),(C)) +#define ma_longlong2str(A,B,C) ma_int2str((A),(B),(C)) +#define ma_longlong10_to_str(A,B,C) ma_int10_to_str((A),(B),(C)) #define strtoll(A,B,C) strtol((A),(B),(C)) #define strtoull(A,B,C) strtoul((A),(B),(C)) #ifndef HAVE_STRTOULL @@ -215,8 +215,8 @@ extern char *str2int(const char *src,int radix,long lower,long upper, #endif #else #ifdef HAVE_LONG_LONG -extern char *longlong2str(longlong val,char *dst,int radix); -extern char *longlong10_to_str(longlong val,char *dst,int radix); +extern char *ma_longlong2str(longlong val,char *dst,int radix); +extern char *ma_longlong10_to_str(longlong val,char *dst,int radix); #if (!defined(HAVE_STRTOULL) || defined(HAVE_mit_thread)) || defined(NO_STRTOLL_PROTO) extern longlong strtoll(const char *str, char **ptr, int base); extern ulonglong strtoull(const char *str, char **ptr, int base); diff --git a/libmariadb/CMakeLists.txt b/libmariadb/CMakeLists.txt index 35862b6b..1ac08e8d 100644 --- a/libmariadb/CMakeLists.txt +++ b/libmariadb/CMakeLists.txt @@ -271,7 +271,6 @@ ma_time.c dbug.c default.c errmsg.c -my_vsnprintf.c errors.c getopt1.c getopt.c @@ -279,7 +278,6 @@ int2str.c is_prefix.c libmariadb.c list.c -llstr.c longlong2str.c ma_pvio.c ma_ssl.c diff --git a/libmariadb/int2str.c b/libmariadb/int2str.c index 17bcb3fc..d7dd38d1 100644 --- a/libmariadb/int2str.c +++ b/libmariadb/int2str.c @@ -46,7 +46,7 @@ char NEAR _dig_vec[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -char *int2str(register long int val, register char *dst, register int radix) +char *ma_int2str(register long int val, register char *dst, register int radix) { char buffer[65]; register char *p; @@ -104,7 +104,7 @@ char *int2str(register long int val, register char *dst, register int radix) radix 10 / -10 */ -char *int10_to_str(long int val, char *dst, int radix) +char *ma_int10_to_str(long int val, char *dst, int radix) { char buffer[65]; register char *p; @@ -140,13 +140,13 @@ char *int10_to_str(long int val, char *dst, int radix) char *my_itoa(int val, char *dst, int radix) { - VOID(int2str((long) val,dst,(radix == 10 ? -10 : radix))); + VOID(ma_int2str((long) val,dst,(radix == 10 ? -10 : radix))); return dst; } char *my_ltoa(long int val, char *dst, int radix) { - VOID(int2str((long) val,dst,(radix == 10 ? -10 : radix))); + VOID(ma_int2str((long) val,dst,(radix == 10 ? -10 : radix))); return dst; } diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index 14113fa1..6f5244d1 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -1988,8 +1988,8 @@ void my_set_error(MYSQL *mysql, mysql->net.last_errno= error_nr; strncpy(mysql->net.sqlstate, sqlstate, SQLSTATE_LENGTH); va_start(ap, format); - ma_vsnprintf(mysql->net.last_error, MYSQL_ERRMSG_SIZE, - format ? format : ER(error_nr), ap); + vsnprintf(mysql->net.last_error, MYSQL_ERRMSG_SIZE, + format ? format : ER(error_nr), ap); DBUG_PRINT("info", ("error(%d) %s", error_nr, mysql->net.last_error)); va_end(ap); DBUG_VOID_RETURN; @@ -3408,7 +3408,7 @@ int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname) { char buff[64]; - ma_snprintf(buff, 63, "SET NAMES %s", cs->csname); + snprintf(buff, 63, "SET NAMES %s", cs->csname); if (!mysql_real_query(mysql, buff, (uint)strlen(buff))) { mysql->charset= cs; diff --git a/libmariadb/llstr.c b/libmariadb/llstr.c deleted file mode 100644 index 1a90f2af..00000000 --- a/libmariadb/llstr.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - Defines: ma_llstr(); - - ma_llstr(value, buff); - - This function saves a longlong value in a buffer and returns the pointer to - the buffer. This is useful when trying to portable print longlong - variables with printf() as there is no usable printf() standard one can use. -*/ - - -#include -#include "m_string.h" - -char *ma_llstr(longlong value,char *buff) -{ - longlong2str(value,buff,-10); - return buff; -} diff --git a/libmariadb/longlong2str.c b/libmariadb/longlong2str.c index fe4d419a..26b949a6 100644 --- a/libmariadb/longlong2str.c +++ b/libmariadb/longlong2str.c @@ -1,4 +1,5 @@ /* 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 @@ -16,9 +17,9 @@ MA 02111-1307, USA */ /* - Defines: longlong2str(); + Defines: ma_longlong2str(); - longlong2str(dst, radix, val) + ma_longlong2str(dst, radix, val) converts the (longlong) integer "val" to character form and moves it to the destination string "dst" followed by a terminating NUL. The result is normally a pointer to this NUL character, but if the radix @@ -42,7 +43,7 @@ #include #include "m_string.h" -#if defined(HAVE_LONG_LONG) && !defined(longlong2str) && !defined(HAVE_LONGLONG2STR) +#if defined(HAVE_LONG_LONG) && !defined(ma_longlong2str) && !defined(HAVE_LONGLONG2STR) extern char NEAR _dig_vec[]; @@ -50,7 +51,7 @@ extern char NEAR _dig_vec[]; This assumes that longlong multiplication is faster than longlong division. */ -char *longlong2str(longlong val,char *dst,int radix) +char *ma_longlong2str(longlong val,char *dst,int radix) { char buffer[65]; register char *p; diff --git a/libmariadb/ma_dyncol.c b/libmariadb/ma_dyncol.c index 25fff7eb..b95ed47c 100644 --- a/libmariadb/ma_dyncol.c +++ b/libmariadb/ma_dyncol.c @@ -2551,7 +2551,7 @@ mariadb_dyncol_list_named(DYNAMIC_COLUMN *str, uint *count, LEX_STRING **names) (*names)[i].str= pool; pool+= DYNCOL_NUM_CHAR; (*names)[i].length= - longlong2str(nm, (*names)[i].str, 10) - (*names)[i].str; + ma_longlong2str(nm, (*names)[i].str, 10) - (*names)[i].str; } else { @@ -4195,8 +4195,8 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json, if (dynstr_realloc(json, DYNCOL_NUM_CHAR + 3)) goto err; json->str[json->length++]= '"'; - json->length+= (ma_snprintf(json->str + json->length, - DYNCOL_NUM_CHAR, "%u", nm)); + json->length+= snprintf(json->str + json->length, + DYNCOL_NUM_CHAR, "%u", nm); } else { diff --git a/libmariadb/my_loaddata.c b/libmariadb/my_loaddata.c index 89f18459..747d5cba 100644 --- a/libmariadb/my_loaddata.c +++ b/libmariadb/my_loaddata.c @@ -90,7 +90,7 @@ int mysql_local_infile_init(void **ptr, const char *filename, void *userdata) else { info->error_no = my_errno; - ma_snprintf((char *)info->error_msg, sizeof(info->error_msg), + snprintf((char *)info->error_msg, sizeof(info->error_msg), EE(EE_FILENOTFOUND), filename, info->error_no); } DBUG_RETURN(1); diff --git a/libmariadb/my_vsnprintf.c b/libmariadb/my_vsnprintf.c deleted file mode 100644 index 754e6099..00000000 --- a/libmariadb/my_vsnprintf.c +++ /dev/null @@ -1,119 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include "mysys_err.h" -#include -#include -#include - - -int ma_snprintf(char* to, size_t n, const char* fmt, ...) -{ - int result; - va_list args; - va_start(args,fmt); - result= ma_vsnprintf(to, n, fmt, args); - va_end(args); - return result; -} - - -int ma_vsnprintf(char *to, size_t n, const char* fmt, va_list ap) -{ - char *start=to, *end=to+n-1; - for (; *fmt ; fmt++) - { - if (fmt[0] != '%') - { - if (to == end) /* End of buffer */ - break; - *to++= *fmt; /* Copy ordinary char */ - continue; - } - /* Skipp if max size is used (to be compatible with printf) */ - fmt++; - while (isdigit(*fmt) || *fmt == '.' || *fmt == '-') - fmt++; - if (*fmt == 'l') - fmt++; - if (*fmt == 's') /* String parameter */ - { - reg2 char *par = va_arg(ap, char *); - uint plen; - if (!par) par = (char*)"(null)"; - plen = (uint) strlen(par); - if ((uint) (end-to) > plen) /* Replace if possible */ - { - to=strmov(to,par); - continue; - } - } - else if (*fmt == 'd' || *fmt == 'u') /* Integer parameter */ - { - register int iarg; - if ((uint) (end-to) < 16) - break; - iarg = va_arg(ap, int); - if (*fmt == 'd') - to=int10_to_str((long) iarg,to, -10); - else - to=int10_to_str((long) (uint) iarg,to,10); - continue; - } - /* We come here on '%%', unknown code or too long parameter */ - if (to == end) - break; - *to++='%'; /* % used as % or unknown code */ - } - *to='\0'; /* End of errmessage */ - return (uint) (to - start); -} - - -#ifdef MAIN -static void my_printf(const char * fmt, ...) -{ - char buf[32]; - int n; - va_list ar; - va_start(ar, fmt); - n = ma_vsnprintf(buf, sizeof(buf),fmt, ar); - printf(buf); - printf("n=%d, strlen=%d\n", n, strlen(buf)); - va_end(ar); -} - - -int main() -{ - - my_printf("Hello\n"); - my_printf("Hello int, %d\n", 1); - my_printf("Hello string '%s'\n", "I am a string"); - my_printf("Hello hack hack hack hack hack hack hack %d\n", 1); - my_printf("Hello %d hack %d\n", 1, 4); - my_printf("Hello %d hack hack hack hack hack %d\n", 1, 4); - my_printf("Hello '%s' hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n", "hack"); - my_printf("Hello hhhhhhhhhhhhhh %d sssssssssssssss\n", 1); - my_printf("Hello %u\n", 1); - my_printf("conn %ld to: '%-.64s' user: '%-.32s' host:\ - `%-.64s' (%-.64s)", 1, 0,0,0,0); - return 0; -} -#endif - diff --git a/libmariadb/secure/gnutls.c b/libmariadb/secure/gnutls.c index 15bfe97e..30865f09 100644 --- a/libmariadb/secure/gnutls.c +++ b/libmariadb/secure/gnutls.c @@ -58,7 +58,7 @@ static void ma_ssl_set_error(MYSQL *mysql, int ssl_errno) ssl_error_reason); return; } - ma_snprintf(ssl_error, MAX_SSL_ERR_LEN, "SSL errno=%lu", ssl_errno, mysql->charset); + snprintf(ssl_error, MAX_SSL_ERR_LEN, "SSL errno=%lu", ssl_errno, mysql->charset); pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, ssl_error); } diff --git a/plugins/pvio/pvio_socket.c b/plugins/pvio/pvio_socket.c index 849193ec..5ce73a11 100644 --- a/plugins/pvio/pvio_socket.c +++ b/plugins/pvio/pvio_socket.c @@ -733,7 +733,7 @@ my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) int rc= 0; bzero(&server_port, NI_MAXSERV); - ma_snprintf(server_port, NI_MAXSERV, "%d", cinfo->port); + snprintf(server_port, NI_MAXSERV, "%d", cinfo->port); /* set hints for getaddrinfo */ bzero(&hints, sizeof(hints)); From 3c03d3b7d8961ff0e9d5e68d2f0871b6730e46c9 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Thu, 4 Feb 2016 16:53:51 +0100 Subject: [PATCH 25/39] Added prototypes for mysql_dump_debug_info_cont/start to mysql.h --- include/mysql.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/mysql.h b/include/mysql.h index 851e2069..b3dc4406 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -535,6 +535,8 @@ 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, From 485af023d55204e6e441ddc10d5b1794604f46e3 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Thu, 4 Feb 2016 20:30:17 +0100 Subject: [PATCH 26/39] More fixes for 10.2 integration --- include/mariadb_ctype.h | 1 + include/my_sys.h | 6 +++--- libmariadb/dbug.c | 4 ++-- libmariadb/default.c | 8 ++++---- libmariadb/libmariadb.c | 16 ++++++++++++++-- libmariadb/mf_dirname.c | 12 ++++++------ libmariadb/mf_fn_ext.c | 2 +- libmariadb/mf_format.c | 4 ++-- libmariadb/mf_pack.c | 6 +++--- libmariadb/mf_path.c | 4 ++-- 10 files changed, 38 insertions(+), 25 deletions(-) diff --git a/include/mariadb_ctype.h b/include/mariadb_ctype.h index 727f5823..e5d38f3d 100644 --- a/include/mariadb_ctype.h +++ b/include/mariadb_ctype.h @@ -34,6 +34,7 @@ extern "C" { #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 diff --git a/include/my_sys.h b/include/my_sys.h index 1b4eb35e..c99a630a 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -454,11 +454,11 @@ 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 dirname_part(my_string to,const char *name); -extern uint dirname_length(const char *name); +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 *convert_dirname(my_string name); +extern char *ma_convert_dirname(my_string name); extern void to_unix_path(my_string name); extern my_string fn_ext(const char *name); extern my_string fn_same(my_string toname,const char *name,int flag); diff --git a/libmariadb/dbug.c b/libmariadb/dbug.c index 27040d87..7bb65c54 100644 --- a/libmariadb/dbug.c +++ b/libmariadb/dbug.c @@ -104,9 +104,9 @@ extern int ma_snprintf(char* to, size_t n, const char* fmt, ...); -char _dig_vec_upper[] = +static const char _dig_vec_upper[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -char _dig_vec_lower[] = +static const char _dig_vec_lower[] = "0123456789abcdefghijklmnopqrstuvwxyz"; #ifndef DBUG_OFF diff --git a/libmariadb/default.c b/libmariadb/default.c index b538e41a..b3e3044d 100644 --- a/libmariadb/default.c +++ b/libmariadb/default.c @@ -135,7 +135,7 @@ void mariadb_load_defaults(const char *conf_file, const char **groups, &group)) goto err; } - else if (dirname_length(conf_file)) + else if (ma_dirname_length(conf_file)) { if (search_default_file(&args, &alloc, NullS, conf_file, default_ext, &group)) @@ -238,7 +238,7 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MA_MEM_ROOT *alloc, if (dir) { strcpy(name,dir); - convert_dirname(name); + ma_convert_dirname(name); if (dir[0] == FN_HOMELIB) /* Add . to filenames in home */ strcat(name,"."); strcat(strcat(name, config_file), ext); @@ -399,7 +399,7 @@ void ma_print_defaults(const char *conf_file, const char **groups) const char **dirs; puts("\nDefault options are read from the following files in the given order:"); - if (dirname_length(conf_file)) + if (ma_dirname_length(conf_file)) fputs(conf_file,stdout); else { @@ -419,7 +419,7 @@ void ma_print_defaults(const char *conf_file, const char **groups) strcpy(name,defaults_extra_file); else continue; - convert_dirname(name); + ma_convert_dirname(name); if (name[0] == FN_HOMELIB) /* Add . to filenames in home */ strcat(name,"."); strcat(strcat(strcat(name, conf_file), default_ext), " "); diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index 6f5244d1..a1b59d03 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -879,7 +879,7 @@ static void mysql_read_default_options(struct st_mysql_options *options, if (strlen(opt_arg) >= FN_REFLEN) opt_arg[FN_REFLEN]= 0; if (!my_realpath(directory, opt_arg, 0)) - OPT_SET_EXTENDED_VALUE_STR(options, plugin_dir, convert_dirname(directory)); + OPT_SET_EXTENDED_VALUE_STR(options, plugin_dir, ma_convert_dirname(directory)); } break; case OPT_default_auth: @@ -1608,7 +1608,19 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, /* Set character set */ if (mysql->options.charset_name) - mysql->charset= mysql_find_charset_name(mysql->options.charset_name); + { + if (!strcmp(mysql->options.charset_name, MADB_AUTODETECT_CHARSET_NAME)) + { + char *csname= madb_get_os_character_set(); + if (csname) + { + if (mysql->charset= mysql_find_charset_name(csname)) + mysql_options(mysql, MYSQL_SET_CHARSET_NAME, csname); + } + } + else + mysql->charset= mysql_find_charset_name(mysql->options.charset_name); + } else if (mysql->server_language) mysql->charset= mysql_find_charset_nr(mysql->server_language); else diff --git a/libmariadb/mf_dirname.c b/libmariadb/mf_dirname.c index d32f06e2..c5ebe64e 100644 --- a/libmariadb/mf_dirname.c +++ b/libmariadb/mf_dirname.c @@ -20,7 +20,7 @@ /* Functions definied in this file */ -uint dirname_length(const char *name) +uint ma_dirname_length(const char *name) { register my_string pos,gpos; #ifdef FN_DEVCHAR @@ -43,15 +43,15 @@ uint dirname_length(const char *name) /* Gives directory part of filename. Directory ends with '/' */ /* Returns length of directory part */ -uint dirname_part(my_string to, const char *name) +uint ma_dirname_part(my_string to, const char *name) { uint length; - DBUG_ENTER("dirname_part"); + DBUG_ENTER("ma_dirname_part"); DBUG_PRINT("enter",("'%s'",name)); - length=dirname_length(name); + length=ma_dirname_length(name); strncpy(to,(char*) name,min(length,FN_REFLEN-2)); - convert_dirname(to); /* Convert chars */ + ma_convert_dirname(to); /* Convert chars */ DBUG_RETURN(length); } /* dirname */ @@ -66,7 +66,7 @@ uint dirname_part(my_string to, const char *name) #define FN_DEVCHAR '\0' /* For easier code */ #endif -char *convert_dirname(my_string to) +char *ma_convert_dirname(my_string to) { reg1 char *pos; #if FN_LIBCHAR != '/' diff --git a/libmariadb/mf_fn_ext.c b/libmariadb/mf_fn_ext.c index 6a9b9d18..8690cf8c 100644 --- a/libmariadb/mf_fn_ext.c +++ b/libmariadb/mf_fn_ext.c @@ -35,7 +35,7 @@ my_string fn_ext(const char *name) #if defined(FN_DEVCHAR) || defined(FN_C_AFTER_DIR) { char buff[FN_REFLEN]; - gpos=(my_string) name+dirname_part(buff,(char*) name); + gpos=(my_string) name + ma_dirname_part(buff,(char*) name); } #else if (!(gpos=strrchr(name,FNLIBCHAR))) diff --git a/libmariadb/mf_format.c b/libmariadb/mf_format.c index d4ac008f..f0c54900 100644 --- a/libmariadb/mf_format.c +++ b/libmariadb/mf_format.c @@ -54,12 +54,12 @@ my_string fn_format(my_string to, const char *name, const char *dsk, name,dsk,form,flag)); /* Kopiera & skippa enheten */ - name+=(length=dirname_part(dev,(startpos=(my_string) name))); + name+=(length=ma_dirname_part(dev,(startpos=(my_string) name))); if (length == 0 || flag & 1) { strncpy(dev,dsk, sizeof(dev) - 2); /* Use given directory */ - convert_dirname(dev); /* Fix to this OS */ + ma_convert_dirname(dev); /* Fix to this OS */ } if (flag & 8) ma_pack_dirname(dev,dev); /* Put in ./.. and ~/.. */ diff --git a/libmariadb/mf_pack.c b/libmariadb/mf_pack.c index 6632e707..f8067ec2 100644 --- a/libmariadb/mf_pack.c +++ b/libmariadb/mf_pack.c @@ -345,7 +345,7 @@ my_string ma_unpack_filename(my_string to, const char *from) char buff[FN_REFLEN]; DBUG_ENTER("ma_unpack_filename"); - length=dirname_part(buff,from); /* copy & convert dirname */ + length=ma_dirname_part(buff,from); /* copy & convert dirname */ n_length=unma_pack_dirname(buff,buff); if (n_length+strlen(from+length) < FN_REFLEN) { @@ -435,14 +435,14 @@ my_string ma_intern_filename(my_string to, const char *from) { #ifndef VMS { - uint length; + uint length= 0; char buff[FN_REFLEN]; if (from == to) { /* Dirname may destroy from */ strcpy(buff,from); from=buff; } - length=dirname_part(to,from); /* Copy dirname & fix chars */ + length=ma_dirname_part(to,from); /* Copy dirname & fix chars */ (void) strcat(to,from+length); return (to); } diff --git a/libmariadb/mf_path.c b/libmariadb/mf_path.c index 7a8379f7..1c4f38c3 100644 --- a/libmariadb/mf_path.c +++ b/libmariadb/mf_path.c @@ -38,9 +38,9 @@ my_string my_path(my_string to, const char *progname, DBUG_ENTER("my_path"); start=to; /* Return this */ - if (progname && (dirname_part(to, progname) || + if (progname && (ma_dirname_part(to, progname) || find_file_in_path(to,progname) || - ((prog=getenv("_")) != 0 && dirname_part(to,prog)))) + ((prog=getenv("_")) != 0 && ma_dirname_part(to,prog)))) { VOID(ma_intern_filename(to,to)); if (!test_if_hard_path(to)) From bd3c6dd27c49f38131a7048421e5622836573153 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Fri, 5 Feb 2016 06:53:56 +0100 Subject: [PATCH 27/39] Fixed memory leak in mysql_real_connect Prefixed more functions (fn_format, strlength) --- include/my_sys.h | 4 ++-- libmariadb/default.c | 2 +- libmariadb/libmariadb.c | 10 ++-------- libmariadb/mf_format.c | 18 +++++++++--------- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/include/my_sys.h b/include/my_sys.h index c99a630a..5784468c 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -462,9 +462,9 @@ extern char *ma_convert_dirname(my_string name); extern void to_unix_path(my_string name); extern my_string fn_ext(const char *name); extern my_string fn_same(my_string toname,const char *name,int flag); -extern my_string fn_format(my_string to,const char *name,const char *dsk, +extern my_string ma_fn_format(my_string to,const char *name,const char *dsk, const char *form,int flag); -extern size_s strlength(const char *str); +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); diff --git a/libmariadb/default.c b/libmariadb/default.c index b3e3044d..77566dfd 100644 --- a/libmariadb/default.c +++ b/libmariadb/default.c @@ -247,7 +247,7 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MA_MEM_ROOT *alloc, { strcpy(name,config_file); } - fn_format(name,name,"","",4); + ma_fn_format(name,name,"","",4); #if !defined(_WIN32) && !defined(OS2) { MY_STAT stat_info; diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index a1b59d03..5c654d25 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -1508,8 +1508,6 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, if (!(mysql->host_info= strdup(host_info ? host_info : "")) || !(mysql->host= strdup(cinfo.host ? cinfo.host : "")) || - !(mysql->unix_socket= strdup(cinfo.unix_socket ? cinfo.unix_socket : "")) || - !(mysql->server_version = malloc((size_t)(end - (char*) net->read_pos))) || !(mysql->user=strdup(user)) || !(mysql->passwd=strdup(passwd))) { @@ -1519,7 +1517,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, strcpy(mysql->host_info,host_info); strcpy(mysql->host, cinfo.host); if (cinfo.unix_socket) - strcpy(mysql->unix_socket, cinfo.unix_socket); + mysql->unix_socket= strdup(cinfo.unix_socket); else mysql->unix_socket=0; mysql->port=port; @@ -1527,11 +1525,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, if (strncmp(end, MA_RPL_VERSION_HACK, sizeof(MA_RPL_VERSION_HACK) - 1) == 0) { - if (!(mysql->server_version= strdup(end + sizeof(MA_RPL_VERSION_HACK) - 1))) - { - SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - goto error; - } + mysql->server_version= strdup(end + sizeof(MA_RPL_VERSION_HACK) - 1); is_maria= 1; } else diff --git a/libmariadb/mf_format.c b/libmariadb/mf_format.c index f0c54900..7feb4aab 100644 --- a/libmariadb/mf_format.c +++ b/libmariadb/mf_format.c @@ -43,10 +43,10 @@ #endif #endif -my_string fn_format(my_string to, const char *name, const char *dsk, +my_string ma_fn_format(my_string to, const char *name, const char *dsk, const char *form, int flag) { - reg1 uint length; + reg1 uint length= 0; char dev[FN_REFLEN], buff[BUFF_LEN], *pos, *startpos; const char *ext; DBUG_ENTER("fn_format"); @@ -69,7 +69,7 @@ my_string fn_format(my_string to, const char *name, const char *dsk, { if ((flag & 2) == 0) /* Skall vi byta extension ? */ { - length=strlength(name); /* Old extension */ + length=ma_strlength(name); /* Old extension */ ext = ""; } else @@ -80,7 +80,7 @@ my_string fn_format(my_string to, const char *name, const char *dsk, } else { - length=strlength(name); /* Har ingen ext- tag nya */ + length=ma_strlength(name); /* Har ingen ext- tag nya */ ext=form; } @@ -89,7 +89,7 @@ my_string fn_format(my_string to, const char *name, const char *dsk, uint tmp_length; if (flag & 64) return 0; - tmp_length=strlength(startpos); + tmp_length=ma_strlength(startpos); DBUG_PRINT("error",("dev: '%s' ext: '%s' length: %d",dev,ext,length)); strncpy(to,startpos,min(tmp_length,FN_REFLEN-1)); } @@ -126,15 +126,15 @@ my_string fn_format(my_string to, const char *name, const char *dsk, /* - strlength(const string str) + ma_strlength(const string str) Return length of string with end-space:s not counted. */ -size_s strlength(const char *str) +size_s ma_strlength(const char *str) { reg1 my_string pos; reg2 my_string found; - DBUG_ENTER("strlength"); + DBUG_ENTER("ma_strlength"); pos=found=(char*) str; @@ -153,4 +153,4 @@ size_s strlength(const char *str) while (*++pos == ' ') {}; } DBUG_RETURN((size_s) (found-(char*) str)); -} /* strlength */ +} /* ma_strlength */ From 26b56d92e31898fd4b8906f25d13ff26a7be3a05 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 5 Feb 2016 07:52:24 +0100 Subject: [PATCH 28/39] Windows fixes for 10.2 integration --- include/m_string.h | 4 ++-- include/my_pthread.h | 2 +- libmariadb/dbug.c | 8 +++----- libmariadb/mf_path.c | 3 +-- libmariadb/my_charset.c | 9 +++------ libmariadb/my_init.c | 11 +++++------ libmariadb/my_lib.c | 3 ++- libmariadb/my_thr_init.c | 2 +- libmariadb/str2int.c | 8 ++++---- 9 files changed, 22 insertions(+), 28 deletions(-) diff --git a/include/m_string.h b/include/m_string.h index 77edd38b..9f7ba624 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -90,8 +90,8 @@ extern "C" { #define strmov(A,B) stpcpy((A),(B)) #define strnmov(A,B,C) stpncpy((A),(B),(C)) #else -#define strmov(A,B) (strcpy((A),(B)) + strlen((B)); -#define strnmov(A,B,C) (strncpy((A),(B),(C)) + strlen((B)); +#define strmov(A,B) (strcpy((A),(B)) + strlen((B))) +#define strnmov(A,B,C) (strncpy((A),(B),(C)) + strlen((B))) #endif extern char NEAR _dig_vec[]; /* Declared in int2str() */ diff --git a/include/my_pthread.h b/include/my_pthread.h index 65f8d30e..7601f38b 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -553,7 +553,7 @@ struct st_ma_thread_var }; extern struct st_ma_thread_var *_ma_thread_var(void) __attribute__ ((const)); -extern void **my_thread_var_dbug(); +extern void **ma_thread_var_dbug(); #define my_thread_var (_ma_thread_var()) #define my_errno my_thread_var->thr_errno diff --git a/libmariadb/dbug.c b/libmariadb/dbug.c index 7bb65c54..e1366515 100644 --- a/libmariadb/dbug.c +++ b/libmariadb/dbug.c @@ -102,8 +102,6 @@ #include #endif -extern int ma_snprintf(char* to, size_t n, const char* fmt, ...); - static const char _dig_vec_upper[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; static const char _dig_vec_lower[] = @@ -391,7 +389,7 @@ static CODE_STATE *code_state(void) init_settings.flags=OPEN_APPEND; } - if (!(cs_ptr= (CODE_STATE**) my_thread_var_dbug())) + if (!(cs_ptr= (CODE_STATE**) ma_thread_var_dbug())) return 0; /* Thread not initialised */ if (!(cs= *cs_ptr)) { @@ -1051,7 +1049,7 @@ void _db_pop_() } while (0) #define int_to_buf(i) do { \ char b[50]; \ - int10_to_str((i), b, 10); \ + ma_int10_to_str((i), b, 10); \ str_to_buf(b); \ } while (0) #define colon_to_buf do { \ @@ -1291,7 +1289,7 @@ void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_) if (cs->framep != _stack_frame_) { char buf[512]; - ma_snprintf(buf, sizeof(buf), ERR_MISSING_RETURN, cs->func); + snprintf(buf, sizeof(buf), ERR_MISSING_RETURN, cs->func); DbugExit(buf); } diff --git a/libmariadb/mf_path.c b/libmariadb/mf_path.c index 1c4f38c3..bbc8993d 100644 --- a/libmariadb/mf_path.c +++ b/libmariadb/mf_path.c @@ -99,8 +99,7 @@ static char *find_file_in_path(char *to, const char *name) { if (path != pos) { - sprintf(to, "%s%s%s%s%s", path, pos - path, dir, name, ext); -// strxmov(strnmov(to,path,(uint) (pos-path)),dir,name,ext,NullS); + snprintf(to, pos - path, "%s%s%s%s", path, dir, name, ext); if (!access(to,F_OK)) { to[(uint) (pos-path)+1]=0; /* Return path only */ diff --git a/libmariadb/my_charset.c b/libmariadb/my_charset.c index 36776fc7..73c50aea 100644 --- a/libmariadb/my_charset.c +++ b/libmariadb/my_charset.c @@ -55,7 +55,6 @@ #include -extern int ma_snprintf(char* to, size_t n, const char* fmt, ...); /* +----------------------------------------------------------------------+ | PHP Version 5 | @@ -1086,8 +1085,8 @@ char *madb_get_os_character_set() char *p= NULL; #ifdef _WIN32 char codepage[FN_REFLEN]; - ma_snprintf(codepage, FN_REFLEN, "%u", GetConsoleWindow() ? - GetConsoleCP() : GetACP()); + snprintf(codepage, FN_REFLEN, "%u", GetConsoleWindow() ? + GetConsoleCP() : GetACP()); p= codepage; #elif defined(HAVE_NL_LANGINFO) && defined(HAVE_SETLOCALE) if (setlocale(LC_CTYPE, "") && (p= nl_langinfo(CODESET))); @@ -1135,9 +1134,7 @@ static void map_charset_name(const char *cs_name, my_bool target_cs, char *buffe if (sscanf(cs_name, "UTF%2[0-9]%2[LBE]", digits, endianness)) { /* We should have at least digits. Endianness we write either default(BE), or what we found in the string */ - ptr= strnmov(ptr, "UTF-", (uint)buff_len); - ptr= strnmov(ptr, digits, (uint)(buff_len - (ptr - buffer))); - ptr= strnmov(ptr, endianness, (uint)(buff_len - (ptr - buffer))); + snprintf(ptr, buff_len, "UTF-%s%s", digits, endianness); } else { diff --git a/libmariadb/my_init.c b/libmariadb/my_init.c index e9437ef3..24a1e6ef 100644 --- a/libmariadb/my_init.c +++ b/libmariadb/my_init.c @@ -35,7 +35,6 @@ #include #include #endif -my_bool have_tcpip=0; static my_bool my_win_init(void); #else #define my_win_init() @@ -50,14 +49,14 @@ static ulong atoi_octal(const char *str) long int tmp; while (*str && isspace(*str)) str++; - str2int(str, - (*str == '0' ? 8 : 10), /* Octalt or decimalt */ - 0, INT_MAX, &tmp); + ma_str2int(str, + (*str == '0' ? 8 : 10), /* Octalt or decimalt */ + 0, INT_MAX, &tmp); return (ulong) tmp; } - /* Init my_sys functions and my_sys variabels */ +/* Init my_sys functions and my_sys variabels */ void ma_init(void) { @@ -194,7 +193,7 @@ Voluntary context switches %ld, Involuntary context switches %ld\n", void setEnvString(char *ret, const char *name, const char *value) { DBUG_ENTER("setEnvString"); - sprintf(ret, "%s=%S", name, value); + sprintf(ret, "%s=%s", name, value); DBUG_VOID_RETURN ; } diff --git a/libmariadb/my_lib.c b/libmariadb/my_lib.c index 4327f79f..a858dc3b 100644 --- a/libmariadb/my_lib.c +++ b/libmariadb/my_lib.c @@ -23,6 +23,7 @@ #include #include /* Structs used by my_dir,includes sys/types */ #include "mysys_err.h" +#include #if defined(HAVE_DIRENT_H) # include # define NAMLEN(dirent) strlen((dirent)->d_name) @@ -391,7 +392,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags) size = STARTSIZE; firstfcnt = maxfcnt = (size - sizeof(MY_DIR)) / (sizeof(struct fileinfo) + FN_LEN); - if ((buffer = (char *) malloc(size) == 0) + if (!(buffer = (char *)malloc(size))) goto error; fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR)); tempptr = (char *) (fnames + maxfcnt); diff --git a/libmariadb/my_thr_init.c b/libmariadb/my_thr_init.c index 4408ed1b..f4c442d7 100644 --- a/libmariadb/my_thr_init.c +++ b/libmariadb/my_thr_init.c @@ -221,7 +221,7 @@ const char *ma_thread_name(void) return tmp->name; } -extern void **my_thread_var_dbug() +extern void **ma_thread_var_dbug() { struct st_ma_thread_var *tmp; /* diff --git a/libmariadb/str2int.c b/libmariadb/str2int.c index 012e6ecb..22c71b2f 100644 --- a/libmariadb/str2int.c +++ b/libmariadb/str2int.c @@ -16,7 +16,7 @@ MA 02111-1307, USA */ /* - str2int(src, radix, lower, upper, &val) + ma_str2int(src, radix, lower, upper, &val) converts the string pointed to by src to an integer and stores it in val. It skips leading spaces and tabs (but not newlines, formfeeds, backspaces), then it accepts an optional sign and a sequence of digits @@ -50,7 +50,7 @@ X >= 'a' && X <= 'z' ? X-'a'+10 :\ '\177') -char *str2int(register const char *src, register int radix, long int lower, long int upper, long int *val) +char *ma_str2int(register const char *src, register int radix, long int lower, long int upper, long int *val) { int sign; /* is number negative (+1) or positive (-1) */ int n; /* number of digits yet to be converted */ @@ -187,7 +187,7 @@ char *str2int(register const char *src, register int radix, long int lower, long int atoi(const char *src) { long val; - str2int(src, 10, (long) INT_MIN, (long) INT_MAX, &val); + ma_str2int(src, 10, (long) INT_MIN, (long) INT_MAX, &val); return (int) val; } @@ -195,7 +195,7 @@ int atoi(const char *src) long atol(const char *src) { long val; - str2int(src, 10, LONG_MIN, LONG_MAX, &val); + ma_str2int(src, 10, LONG_MIN, LONG_MAX, &val); return val; } From f0b15617d7f39605f313ea12dc04f9d5ee06aec2 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Fri, 5 Feb 2016 09:54:22 +0100 Subject: [PATCH 29/39] More windows fixes for 10.2 integration --- include/my_sys.h | 2 +- libmariadb/CMakeLists.txt | 2 -- libmariadb/default.c | 2 +- libmariadb/longlong2str.c | 4 ++-- libmariadb/mf_fn_ext.c | 6 +++--- libmariadb/mf_path.c | 2 +- libmariadb/my_pthread.c | 8 ++++---- libmariadb/my_stmt_codec.c | 2 +- 8 files changed, 13 insertions(+), 15 deletions(-) diff --git a/include/my_sys.h b/include/my_sys.h index 5784468c..45d029e0 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -460,7 +460,7 @@ extern uint ma_dirname_length(const char *name); 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 fn_ext(const char *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); diff --git a/libmariadb/CMakeLists.txt b/libmariadb/CMakeLists.txt index 1ac08e8d..59d77d7d 100644 --- a/libmariadb/CMakeLists.txt +++ b/libmariadb/CMakeLists.txt @@ -303,7 +303,6 @@ my_messnc.c my_net.c my_once.c my_port.c -my_pthread.c my_seek.c my_static.c my_symlink.c @@ -315,7 +314,6 @@ str2int.c string.c strtoll.c strtoull.c -thr_mutex.c typelib.c sha1.c my_stmt.c diff --git a/libmariadb/default.c b/libmariadb/default.c index 77566dfd..bdeafa00 100644 --- a/libmariadb/default.c +++ b/libmariadb/default.c @@ -393,7 +393,7 @@ static my_bool search_default_file(DYNAMIC_ARRAY *args, MA_MEM_ROOT *alloc, void ma_print_defaults(const char *conf_file, const char **groups) { #ifdef _WIN32 - bool have_ext=fn_ext(conf_file)[0] != 0; + bool have_ext=ma_fn_ext(conf_file)[0] != 0; #endif char name[FN_REFLEN]; const char **dirs; diff --git a/libmariadb/longlong2str.c b/libmariadb/longlong2str.c index 26b949a6..95e4a155 100644 --- a/libmariadb/longlong2str.c +++ b/libmariadb/longlong2str.c @@ -99,8 +99,8 @@ char *ma_longlong2str(longlong val,char *dst,int radix) #endif -#ifndef longlong10_to_str -char *longlong10_to_str(longlong val,char *dst,int radix) +#ifndef ma_longlong10_to_str +char *ma_longlong10_to_str(longlong val,char *dst,int radix) { char buffer[65]; register char *p; diff --git a/libmariadb/mf_fn_ext.c b/libmariadb/mf_fn_ext.c index 8690cf8c..abb98291 100644 --- a/libmariadb/mf_fn_ext.c +++ b/libmariadb/mf_fn_ext.c @@ -26,10 +26,10 @@ NULL of the filename */ -my_string fn_ext(const char *name) +my_string ma_fn_ext(const char *name) { register my_string pos,gpos; - DBUG_ENTER("fn_ext"); + DBUG_ENTER("ma_fn_ext"); DBUG_PRINT("mfunkt",("name: '%s'",name)); #if defined(FN_DEVCHAR) || defined(FN_C_AFTER_DIR) @@ -43,4 +43,4 @@ my_string fn_ext(const char *name) #endif pos=strrchr(gpos,FN_EXTCHAR); DBUG_RETURN (pos ? pos : strend(gpos)); -} /* fn_ext */ +} /* ma_fn_ext */ diff --git a/libmariadb/mf_path.c b/libmariadb/mf_path.c index bbc8993d..8f7fc0b9 100644 --- a/libmariadb/mf_path.c +++ b/libmariadb/mf_path.c @@ -91,7 +91,7 @@ static char *find_file_in_path(char *to, const char *name) return NullS; dir[0]=FN_LIBCHAR; dir[1]=0; #ifdef PROGRAM_EXTENSION - if (!fn_ext(name)[0]) + if (!ma_fn_ext(name)[0]) ext=PROGRAM_EXTENSION; #endif diff --git a/libmariadb/my_pthread.c b/libmariadb/my_pthread.c index 37d4e58e..1c8ada56 100644 --- a/libmariadb/my_pthread.c +++ b/libmariadb/my_pthread.c @@ -29,7 +29,7 @@ #ifdef _WIN32 int -pthread_cond_init (pthread_cond_t *cv, const pthread_condattr_t *attr) +ma_pthread_cond_init (pthread_cond_t *cv, const pthread_condattr_t *attr) { DBUG_ENTER("pthread_cond_init"); /* Initialize the count to 0 */ @@ -45,9 +45,9 @@ pthread_cond_init (pthread_cond_t *cv, const pthread_condattr_t *attr) DBUG_RETURN(0); } -int pthread_cond_timedwait(pthread_cond_t *cond, - pthread_mutex_t *mutex, - struct timespec *abstime) +int ma_pthread_cond_timedwait(pthread_cond_t *cond, + pthread_mutex_t *mutex, + struct timespec *abstime) { int result= 0; return result == WAIT_TIMEOUT ? ETIMEDOUT : 0; diff --git a/libmariadb/my_stmt_codec.c b/libmariadb/my_stmt_codec.c index 66fe7b85..5397561a 100644 --- a/libmariadb/my_stmt_codec.c +++ b/libmariadb/my_stmt_codec.c @@ -363,7 +363,7 @@ static void convert_from_long(MYSQL_BIND *r_param, const MYSQL_FIELD *field, lon char *endptr; uint len; - endptr= longlong10_to_str(val, buffer, is_unsigned ? 10 : -10); + endptr= ma_longlong10_to_str(val, buffer, is_unsigned ? 10 : -10); len= (uint)(endptr - buffer); /* check if field flag is zerofill */ From 0c3c789628c1d25044689d6ce7f15c50f966e2dd Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Fri, 5 Feb 2016 12:19:45 +0100 Subject: [PATCH 30/39] More 10.2 windows fixes --- include/my_pthread.h | 4 ++- include/my_sys.h | 12 ++++---- libmariadb/CMakeLists.txt | 1 - libmariadb/ma_dyncol.c | 58 +++++++++++++++++++-------------------- libmariadb/my_thr_init.c | 4 +-- libmariadb/string.c | 22 +++++++-------- 6 files changed, 51 insertions(+), 50 deletions(-) diff --git a/include/my_pthread.h b/include/my_pthread.h index 7601f38b..b20f1172 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -260,8 +260,10 @@ extern int my_pthread_mutex_init(pthread_mutex_t *mp, const pthread_mutexattr_t *attr); #endif /* SAFE_MUTEX */ #define pthread_cond_init(a,b) my_pthread_cond_init((a),(b)) -extern int my_pthread_cond_init(pthread_cond_t *mp, +/* + extern int my_pthread_cond_init(pthread_cond_t *mp, const pthread_condattr_t *attr); + */ #endif /* HAVE_NONPOSIX_PTHREAD_MUTEX_INIT */ #if defined(HAVE_SIGTHREADMASK) && !defined(HAVE_PTHREAD_SIGMASK) diff --git a/include/my_sys.h b/include/my_sys.h index 45d029e0..a421a0f4 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -561,14 +561,14 @@ extern void ma_freeze_size(DYNAMIC_ARRAY *array); 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 init_dynamic_string(DYNAMIC_STRING *str, const char *init_str, +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 dynstr_append(DYNAMIC_STRING *str, const char *append); -my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append, +extern my_bool ma_dynstr_append(DYNAMIC_STRING *str, const char *append); +my_bool ma_dynstr_append_mem(DYNAMIC_STRING *str, const char *append, size_t length); -extern my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str); -extern my_bool dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size); -extern void dynstr_free(DYNAMIC_STRING *str); +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, diff --git a/libmariadb/CMakeLists.txt b/libmariadb/CMakeLists.txt index 59d77d7d..859137ff 100644 --- a/libmariadb/CMakeLists.txt +++ b/libmariadb/CMakeLists.txt @@ -293,7 +293,6 @@ my_alloc.c my_compress.c my_context.c my_div.c -#my_error.c my_fopen.c my_fstream.c my_getwd.c diff --git a/libmariadb/ma_dyncol.c b/libmariadb/ma_dyncol.c index b95ed47c..b6f63bf1 100644 --- a/libmariadb/ma_dyncol.c +++ b/libmariadb/ma_dyncol.c @@ -705,7 +705,7 @@ static my_bool dynamic_column_init_named(DYNAMIC_COLUMN *str, size_t size) - First \0 is flags - other 2 \0 is number of fields */ - if (init_dynamic_string(str, NULL, size, DYNCOL_SYZERESERVE)) + if (ma_init_dynamic_string(str, NULL, size, DYNCOL_SYZERESERVE)) return TRUE; return FALSE; } @@ -749,7 +749,7 @@ static size_t dynamic_column_var_uint_bytes(ulonglong val) static enum enum_dyncol_func_result dynamic_column_var_uint_store(DYNAMIC_COLUMN *str, ulonglong val) { - if (dynstr_realloc(str, 10)) /* max what we can use */ + if (ma_dynstr_realloc(str, 10)) /* max what we can use */ return ER_DYNCOL_RESOURCE; do @@ -829,7 +829,7 @@ static size_t dynamic_column_uint_bytes(ulonglong val) static enum enum_dyncol_func_result dynamic_column_uint_store(DYNAMIC_COLUMN *str, ulonglong val) { - if (dynstr_realloc(str, 8)) /* max what we can use */ + if (ma_dynstr_realloc(str, 8)) /* max what we can use */ return ER_DYNCOL_RESOURCE; for (; val; val>>= 8) @@ -1022,7 +1022,7 @@ dynamic_column_value_len(DYNAMIC_COLUMN_VALUE *value, static enum enum_dyncol_func_result dynamic_column_double_store(DYNAMIC_COLUMN *str, double val) { - if (dynstr_realloc(str, 8)) + if (ma_dynstr_realloc(str, 8)) return ER_DYNCOL_RESOURCE; float8store(str->str + str->length, val); str->length+= 8; @@ -1071,7 +1071,7 @@ dynamic_column_string_store(DYNAMIC_COLUMN *str, LEX_STRING *string, if ((rc= dynamic_column_var_uint_store(str, charset->number))) #endif return rc; - if (dynstr_append_mem(str, string->str, string->length)) + if (ma_dynstr_append_mem(str, string->str, string->length)) return ER_DYNCOL_RESOURCE; return ER_DYNCOL_OK; } @@ -1088,7 +1088,7 @@ dynamic_column_string_store(DYNAMIC_COLUMN *str, LEX_STRING *string, static enum enum_dyncol_func_result dynamic_column_dyncol_store(DYNAMIC_COLUMN *str, LEX_STRING *string) { - if (dynstr_append_mem(str, string->str, string->length)) + if (ma_dynstr_append_mem(str, string->str, string->length)) return ER_DYNCOL_RESOURCE; return ER_DYNCOL_OK; } @@ -1166,7 +1166,7 @@ dynamic_column_decimal_store(DYNAMIC_COLUMN *str, return ER_DYNCOL_OK; bin_size= decimal_bin_size(precision, value->frac); - if (dynstr_realloc(str, bin_size + 20)) + if (ma_dynstr_realloc(str, bin_size + 20)) return ER_DYNCOL_RESOURCE; /* The following can't fail as memory is already allocated */ @@ -1321,7 +1321,7 @@ dynamic_column_time_store(DYNAMIC_COLUMN *str, MYSQL_TIME *value, enum enum_dyncol_format format) { uchar *buf; - if (dynstr_realloc(str, 6)) + if (ma_dynstr_realloc(str, 6)) return ER_DYNCOL_RESOURCE; buf= ((uchar *)str->str) + str->length; @@ -1464,7 +1464,7 @@ static enum enum_dyncol_func_result dynamic_column_date_store(DYNAMIC_COLUMN *str, MYSQL_TIME *value) { uchar *buf; - if (dynstr_realloc(str, 3)) + if (ma_dynstr_realloc(str, 3)) return ER_DYNCOL_RESOURCE; buf= ((uchar *)str->str) + str->length; @@ -1668,7 +1668,7 @@ dynamic_new_column_store(DYNAMIC_COLUMN *str, else { str->length= 0; - if (dynstr_realloc(str, + if (ma_dynstr_realloc(str, fmt->fixed_hdr + hdr->header_size + hdr->nmpool_size + @@ -3848,21 +3848,21 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, switch (val->type) { case DYN_COL_INT: len= snprintf(buff, sizeof(buff), "%lld", val->x.long_value); - if (dynstr_append_mem(str, buff, len)) + if (ma_dynstr_append_mem(str, buff, len)) return ER_DYNCOL_RESOURCE; break; case DYN_COL_UINT: len= snprintf(buff, sizeof(buff), "%llu", val->x.ulong_value); - if (dynstr_append_mem(str, buff, len)) + if (ma_dynstr_append_mem(str, buff, len)) return ER_DYNCOL_RESOURCE; break; case DYN_COL_DOUBLE: len= snprintf(buff, sizeof(buff), "%g", val->x.double_value); - if (dynstr_realloc(str, len + (quote ? 2 : 0))) + if (ma_dynstr_realloc(str, len + (quote ? 2 : 0))) return ER_DYNCOL_RESOURCE; if (quote) str->str[str->length++]= quote; - dynstr_append_mem(str, buff, len); + ma_dynstr_append_mem(str, buff, len); if (quote) str->str[str->length++]= quote; break; @@ -3877,7 +3877,7 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, my_bool rc; len= val->x.string.value.length; bufflen= (ulong)(len * (conv ? cs->char_maxlen : 1)); - if (dynstr_realloc(str, bufflen)) + if (ma_dynstr_realloc(str, bufflen)) return ER_DYNCOL_RESOURCE; // guaranty UTF-8 string for value @@ -3922,10 +3922,10 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, return ER_DYNCOL_RESOURCE; } if (quote) - rc= dynstr_append_mem(str, "e, 1); - rc= dynstr_append_mem(str, from, len); + rc= ma_dynstr_append_mem(str, "e, 1); + rc= ma_dynstr_append_mem(str, from, len); if (quote) - rc= dynstr_append_mem(str, "e, 1); + rc= ma_dynstr_append_mem(str, "e, 1); if (alloc) free(alloc); if (rc) @@ -3939,7 +3939,7 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, decimal2string(&val->x.decimal.value, buff, &len, 0, val->x.decimal.value.frac, '0'); - if (dynstr_append_mem(str, buff, len)) + if (ma_dynstr_append_mem(str, buff, len)) return ER_DYNCOL_RESOURCE; break; } @@ -3952,16 +3952,16 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, #else len= mariadb_time_to_string(&val->x.time_value, buff, 39, AUTO_SEC_PART_DIGITS); #endif - if (dynstr_realloc(str, len + (quote ? 2 : 0))) + if (ma_dynstr_realloc(str, len + (quote ? 2 : 0))) return ER_DYNCOL_RESOURCE; if (quote) str->str[str->length++]= '"'; - dynstr_append_mem(str, buff, len); + ma_dynstr_append_mem(str, buff, len); if (quote) str->str[str->length++]= '"'; break; case DYN_COL_NULL: - if (dynstr_append_mem(str, "null", 4)) + if (ma_dynstr_append_mem(str, "null", 4)) return ER_DYNCOL_RESOURCE; break; default: @@ -4165,14 +4165,14 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json, rc= ER_DYNCOL_RESOURCE; - if (dynstr_append_mem(json, "{", 1)) + if (ma_dynstr_append_mem(json, "{", 1)) goto err; for (i= 0, header.entry= header.header; i < header.column_count; i++, header.entry+= header.entry_size) { DYNAMIC_COLUMN_VALUE val; - if (i != 0 && dynstr_append_mem(json, ",", 1)) + if (i != 0 && ma_dynstr_append_mem(json, ",", 1)) goto err; header.length= hdr_interval_length(&header, header.entry + header.entry_size); @@ -4192,7 +4192,7 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json, if (header.format == dyncol_fmt_num) { uint nm= uint2korr(header.entry); - if (dynstr_realloc(json, DYNCOL_NUM_CHAR + 3)) + if (ma_dynstr_realloc(json, DYNCOL_NUM_CHAR + 3)) goto err; json->str[json->length++]= '"'; json->length+= snprintf(json->str + json->length, @@ -4206,7 +4206,7 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json, rc= ER_DYNCOL_FORMAT; goto err; } - if (dynstr_realloc(json, name.length + 3)) + if (ma_dynstr_realloc(json, name.length + 3)) goto err; json->str[json->length++]= '"'; memcpy(json->str + json->length, name.str, name.length); @@ -4235,7 +4235,7 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json, goto err; } } - if (dynstr_append_mem(json, "}", 1)) + if (ma_dynstr_append_mem(json, "}", 1)) { rc= ER_DYNCOL_RESOURCE; goto err; @@ -4251,7 +4251,7 @@ enum enum_dyncol_func_result mariadb_dyncol_json(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json) { - if (init_dynamic_string(json, NULL, str->length * 2, 100)) + if (ma_init_dynamic_string(json, NULL, str->length * 2, 100)) return ER_DYNCOL_RESOURCE; return mariadb_dyncol_json_internal(str, json, 1); @@ -4397,5 +4397,5 @@ mariadb_dyncol_column_count(DYNAMIC_COLUMN *str, uint *column_count) */ void mariadb_dyncol_free(DYNAMIC_COLUMN *str) { - dynstr_free(str); + ma_dynstr_free(str); } diff --git a/libmariadb/my_thr_init.c b/libmariadb/my_thr_init.c index f4c442d7..bd9a2f30 100644 --- a/libmariadb/my_thr_init.c +++ b/libmariadb/my_thr_init.c @@ -132,7 +132,7 @@ my_bool ma_thread_init(void) } pthread_mutex_init(&tmp->mutex,MY_MUTEX_INIT_FAST); - pthread_cond_init(&tmp->suspend, NULL); +// pthread_cond_init(&tmp->suspend, NULL); pthread_mutex_lock(&THR_LOCK_lock); tmp->id= ++thread_id; pthread_mutex_unlock(&THR_LOCK_lock); @@ -159,7 +159,7 @@ void ma_thread_end(void) } #endif #if !defined(__bsdi__) || defined(HAVE_mit_thread) /* bsdi dumps core here */ - pthread_cond_destroy(&tmp->suspend); +// pthread_cond_destroy(&tmp->suspend); #endif pthread_mutex_destroy(&tmp->mutex); free(tmp); diff --git a/libmariadb/string.c b/libmariadb/string.c index 4d152d91..ade0af50 100644 --- a/libmariadb/string.c +++ b/libmariadb/string.c @@ -24,11 +24,12 @@ #include "mysys_priv.h" #include -my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str, +my_bool ma_init_dynamic_string(DYNAMIC_STRING *str, const char *init_str, + size_t init_alloc, size_t alloc_increment) { uint length; - DBUG_ENTER("init_dynamic_string"); + DBUG_ENTER("ma_init_dynamic_string"); if (!alloc_increment) alloc_increment=128; @@ -48,11 +49,10 @@ my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str, DBUG_RETURN(FALSE); } - -my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str) +my_bool ma_dynstr_set(DYNAMIC_STRING *str, const char *init_str) { uint length; - DBUG_ENTER("dynstr_set"); + DBUG_ENTER("ma_dynstr_set"); if (init_str && (length= (uint) strlen(init_str)+1) > str->max_length) { @@ -74,9 +74,9 @@ my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str) } -my_bool dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size) +my_bool ma_dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size) { - DBUG_ENTER("dynstr_realloc"); + DBUG_ENTER("ma_dynstr_realloc"); if (!additional_size) DBUG_RETURN(FALSE); if (str->length + additional_size > str->max_length) @@ -90,13 +90,13 @@ my_bool dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size) } -my_bool dynstr_append(DYNAMIC_STRING *str, const char *append) +my_bool ma_dynstr_append(DYNAMIC_STRING *str, const char *append) { - return dynstr_append_mem(str,append,strlen(append)); + return ma_dynstr_append_mem(str,append,strlen(append)); } -my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append, +my_bool ma_dynstr_append_mem(DYNAMIC_STRING *str, const char *append, size_t length) { char *new_ptr; @@ -117,7 +117,7 @@ my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append, } -void dynstr_free(DYNAMIC_STRING *str) +void ma_dynstr_free(DYNAMIC_STRING *str) { if (str->str) { From f3577bab9454f6fa2c4e153e701fa6d9e0e55ad8 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Fri, 5 Feb 2016 16:31:49 +0100 Subject: [PATCH 31/39] Disable dbug by default (to enable it specify cmake option -DWITH_DBUG=ON) minor fixes for 10.2 integration (windows) --- CMakeLists.txt | 5 +++++ libmariadb/CMakeLists.txt | 4 +++- libmariadb/libmariadb.c | 7 ++----- libmariadb/secure/schannel.c | 8 ++++---- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8abe14fb..0bd7998f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,6 +116,11 @@ IF(NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE "Relwithdebinfo") ENDIF() +OPTION(WITH_DBUG "enables use of DBUG library" OFF) +IF(NOT WITH_DBUG) + ADD_DEFINITIONS(-DDBUG_OFF=1) +ENDIF() + # various defines for generating include/mysql_version.h SET(PROTOCOL_VERSION 10) # we adapted new password option from PHP's mysqlnd ! diff --git a/libmariadb/CMakeLists.txt b/libmariadb/CMakeLists.txt index 859137ff..4c3caacd 100644 --- a/libmariadb/CMakeLists.txt +++ b/libmariadb/CMakeLists.txt @@ -268,7 +268,6 @@ hash.c net.c charset.c ma_time.c -dbug.c default.c errmsg.c errors.c @@ -322,6 +321,9 @@ ${CMAKE_BINARY_DIR}/libmariadb/client_plugin.c ma_io.c ${SSL_SOURCES} ) +IF(WITH_DBUG) + SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} dbug.c) +ENDIF() IF(WIN32) diff --git a/libmariadb/libmariadb.c b/libmariadb/libmariadb.c index 5c654d25..1b3da149 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -1412,11 +1412,8 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, #endif #else /* named pipe */ - if ((unix_socket || - (!host && is_NT()) || - (host && strcmp(host,LOCAL_HOST_NAMEDPIPE) == 0) || - mysql->options.named_pipe) && - mysql->options.protocol != MYSQL_PROTOCOL_TCP) + if (mysql->options.protocol == MYSQL_PROTOCOL_PIPE || + (host && strcmp(host,LOCAL_HOST_NAMEDPIPE) == 0)) { cinfo.type= PVIO_TYPE_NAMEDPIPE; sprintf(host_info=buff,ER(CR_NAMEDPIPE_CONNECTION),cinfo.host); diff --git a/libmariadb/secure/schannel.c b/libmariadb/secure/schannel.c index 1f27dd44..fd01c391 100644 --- a/libmariadb/secure/schannel.c +++ b/libmariadb/secure/schannel.c @@ -133,14 +133,14 @@ int ma_ssl_start(char *errmsg, size_t errmsg_len) */ void ma_ssl_end() { - pthread_mutex_lock(&LOCK_schannel_config); if (ma_ssl_initialized) { - + pthread_mutex_lock(&LOCK_schannel_config); ma_ssl_initialized= FALSE; + pthread_mutex_unlock(&LOCK_schannel_config); + pthread_mutex_destroy(&LOCK_schannel_config); } - pthread_mutex_unlock(&LOCK_schannel_config); - pthread_mutex_destroy(&LOCK_schannel_config); + return; } From 4ca933bb817efd90076d5bde968761047ac7e4cf Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Mon, 8 Feb 2016 18:43:02 +0100 Subject: [PATCH 32/39] Global cleanup: removed global locks removed dead code and files removed dbug --- CMakeLists.txt | 23 +- client/ma_plugin_info.c | 2 +- cmake/export.cmake | 16 + cmake/plugins.cmake | 4 +- include/CMakeLists.txt | 3 +- include/dbug.h | 151 - include/m_string.h | 230 -- include/ma_common.h | 3 +- include/{my_config.h.in => ma_config.h.in} | 0 include/{config-win.h => ma_config_win.h} | 0 include/{my_context.h => ma_context.h} | 0 include/{errmsg.h => ma_errmsg.h} | 12 +- include/{my_global.h => ma_global.h} | 9 +- include/{hash.h => ma_hash.h} | 6 +- include/{my_list.h => ma_list.h} | 0 include/ma_pvio.h | 8 +- include/{mysqld_error.h => ma_server_error.h} | 0 include/{sha1.h => ma_sha1.h} | 9 +- libmariadb/strtoull.c => include/ma_string.h | 18 +- include/{my_sys.h => ma_sys.h} | 85 +- include/{mysql_async.h => mariadb_async.h} | 0 include/{mysql_com.h => mariadb_com.h} | 0 include/{ma_dyncol.h => mariadb_dyncol.h} | 0 include/{my_stmt.h => mariadb_stmt.h} | 0 ...ysql_version.h.in => mariadb_version.h.in} | 0 include/my_alarm.h | 60 - include/my_base.h | 287 -- include/my_dir.h | 100 - include/my_net.h | 48 - include/my_no_pthread.h | 32 - include/my_pthread.h | 592 ---- include/mysql.h | 27 +- include/mysql_io.h | 31 - include/mysql_mm.h | 44 - include/mysql_priv.h | 4 - include/mysql_wireprotocol.h | 295 -- include/mysys_err.h | 69 - include/thr_alarm.h | 112 - libmariadb/CMakeLists.txt | 320 +-- libmariadb/bchange.c | 39 - libmariadb/bmove.c | 80 - libmariadb/bmove_upp.c | 24 +- libmariadb/dbug.c | 2455 ----------------- libmariadb/default.c | 442 --- libmariadb/errors.c | 96 - libmariadb/get_password.c | 6 +- libmariadb/getopt1.c | 170 -- libmariadb/int2str.c | 153 - libmariadb/is_prefix.c | 34 - libmariadb/longlong2str.c | 144 - libmariadb/{my_alloc.c => ma_alloc.c} | 11 +- libmariadb/{array.c => ma_array.c} | 21 +- libmariadb/{my_charset.c => ma_charset.c} | 37 +- ...ient_plugin.c.in => ma_client_plugin.c.in} | 21 +- libmariadb/{my_compress.c => ma_compress.c} | 15 +- libmariadb/{my_context.c => ma_context.c} | 46 +- libmariadb/ma_default.c | 224 ++ libmariadb/{errmsg.c => ma_errmsg.c} | 27 +- libmariadb/{hash.c => ma_hash.c} | 93 +- libmariadb/ma_init.c | 115 + libmariadb/ma_io.c | 13 +- libmariadb/{list.c => ma_list.c} | 12 +- libmariadb/ma_ll2str.c | 75 + libmariadb/{my_loaddata.c => ma_loaddata.c} | 49 +- libmariadb/{net.c => ma_net.c} | 61 +- libmariadb/{password.c => ma_password.c} | 33 +- libmariadb/ma_pvio.c | 38 +- libmariadb/ma_sha1.c | 326 +++ libmariadb/ma_ssl.c | 15 +- .../{my_stmt_codec.c => ma_stmt_codec.c} | 28 +- libmariadb/{string.c => ma_string.c} | 28 +- libmariadb/ma_time.c | 4 +- libmariadb/{mysql_async.c => mariadb_async.c} | 32 +- libmariadb/{charset.c => mariadb_charset.c} | 23 +- libmariadb/{ma_dyncol.c => mariadb_dyncol.c} | 85 +- libmariadb/{libmariadb.c => mariadb_lib.c} | 823 +++--- libmariadb/{my_stmt.c => mariadb_stmt.c} | 284 +- libmariadb/mf_dirname.c | 100 - libmariadb/mf_fn_ext.c | 46 - libmariadb/mf_format.c | 156 -- libmariadb/mf_loadpath.c | 54 - libmariadb/mf_pack.c | 532 ---- libmariadb/mf_path.c | 120 - libmariadb/mf_unixpath.c | 33 - libmariadb/mf_wcomp.c | 68 - libmariadb/my_div.c | 31 - libmariadb/my_fopen.c | 179 -- libmariadb/my_fstream.c | 171 -- libmariadb/my_getwd.c | 202 -- libmariadb/my_init.c | 222 -- libmariadb/my_lib.c | 612 ---- libmariadb/my_messnc.c | 35 - libmariadb/my_net.c | 44 - libmariadb/my_once.c | 88 - libmariadb/my_open.c | 126 - libmariadb/my_port.c | 40 - libmariadb/my_pthread.c | 555 ---- libmariadb/my_read.c | 66 - libmariadb/my_seek.c | 58 - libmariadb/my_static.c | 99 - libmariadb/my_static.h | 69 - libmariadb/my_symlink.c | 138 - libmariadb/my_thr_init.c | 241 -- libmariadb/my_write.c | 90 - libmariadb/mysys_priv.h | 32 - libmariadb/secure/gnutls.c | 10 +- libmariadb/secure/ma_schannel.h | 13 +- libmariadb/secure/openssl.c | 12 +- libmariadb/sha1.c | 325 --- libmariadb/str2int.c | 202 -- libmariadb/strcont.c | 46 - libmariadb/strto.c | 209 -- libmariadb/strtoll.c | 198 -- libmariadb/thr_mutex.c | 231 -- libmariadb/typelib.c | 106 - mariadb_config/mariadb_config.c.in | 10 +- plugins/auth/auth_gssapi_client.c | 4 +- plugins/auth/dialog.c | 2 +- plugins/auth/gssapi_client.c | 2 +- plugins/auth/mariadb_cleartext.c | 2 +- plugins/auth/my_auth.c | 19 +- plugins/auth/old_password.c | 4 +- plugins/auth/sspi_client.c | 2 +- plugins/connection/aurora.c | 12 +- plugins/connection/replication.c | 12 +- plugins/io/remote_io.c | 4 +- plugins/pvio/pvio_npipe.c | 10 +- plugins/pvio/pvio_shmem.c | 8 +- plugins/pvio/pvio_socket.c | 40 +- plugins/trace/trace_example.c | 2 +- unittest/libmariadb/CMakeLists.txt | 58 +- unittest/libmariadb/charset.c | 2 +- unittest/libmariadb/connection.c | 8 +- unittest/libmariadb/dyncol.c | 2 +- {libmariadb => unittest/libmariadb}/getopt.c | 10 +- unittest/libmariadb/ma_getopt.c | 742 +++++ .../libmariadb/ma_getopt.h | 0 unittest/libmariadb/misc.c | 28 + unittest/libmariadb/my_test.h | 8 +- unittest/libmariadb/ssl.c.in | 2 +- unittest/libmariadb/thread.c | 1 + unittest/mytap/tap.c | 2 +- unittest/mytap/tap.h | 2 +- 143 files changed, 2562 insertions(+), 12777 deletions(-) create mode 100644 cmake/export.cmake delete mode 100644 include/dbug.h delete mode 100644 include/m_string.h rename include/{my_config.h.in => ma_config.h.in} (100%) rename include/{config-win.h => ma_config_win.h} (100%) rename include/{my_context.h => ma_context.h} (100%) rename include/{errmsg.h => ma_errmsg.h} (93%) rename include/{my_global.h => ma_global.h} (99%) rename include/{hash.h => ma_hash.h} (96%) rename include/{my_list.h => ma_list.h} (100%) rename include/{mysqld_error.h => ma_server_error.h} (100%) rename include/{sha1.h => ma_sha1.h} (86%) rename libmariadb/strtoull.c => include/ma_string.h (80%) rename include/{my_sys.h => ma_sys.h} (86%) rename include/{mysql_async.h => mariadb_async.h} (100%) rename include/{mysql_com.h => mariadb_com.h} (100%) rename include/{ma_dyncol.h => mariadb_dyncol.h} (100%) rename include/{my_stmt.h => mariadb_stmt.h} (100%) rename include/{mysql_version.h.in => mariadb_version.h.in} (100%) delete mode 100644 include/my_alarm.h delete mode 100644 include/my_base.h delete mode 100644 include/my_dir.h delete mode 100644 include/my_net.h delete mode 100644 include/my_no_pthread.h delete mode 100644 include/my_pthread.h delete mode 100644 include/mysql_io.h delete mode 100644 include/mysql_mm.h delete mode 100644 include/mysql_priv.h delete mode 100644 include/mysql_wireprotocol.h delete mode 100644 include/mysys_err.h delete mode 100644 include/thr_alarm.h delete mode 100644 libmariadb/bchange.c delete mode 100644 libmariadb/bmove.c delete mode 100644 libmariadb/dbug.c delete mode 100644 libmariadb/default.c delete mode 100644 libmariadb/errors.c delete mode 100644 libmariadb/getopt1.c delete mode 100644 libmariadb/int2str.c delete mode 100644 libmariadb/is_prefix.c delete mode 100644 libmariadb/longlong2str.c rename libmariadb/{my_alloc.c => ma_alloc.c} (96%) rename libmariadb/{array.c => ma_array.c} (89%) rename libmariadb/{my_charset.c => ma_charset.c} (98%) rename libmariadb/{client_plugin.c.in => ma_client_plugin.c.in} (97%) rename libmariadb/{my_compress.c => ma_compress.c} (83%) rename libmariadb/{my_context.c => ma_context.c} (94%) create mode 100644 libmariadb/ma_default.c rename libmariadb/{errmsg.c => ma_errmsg.c} (93%) rename libmariadb/{hash.c => ma_hash.c} (88%) create mode 100644 libmariadb/ma_init.c rename libmariadb/{list.c => ma_list.c} (92%) create mode 100644 libmariadb/ma_ll2str.c rename libmariadb/{my_loaddata.c => ma_loaddata.c} (90%) rename libmariadb/{net.c => ma_net.c} (92%) rename libmariadb/{password.c => ma_password.c} (90%) create mode 100644 libmariadb/ma_sha1.c rename libmariadb/{my_stmt_codec.c => ma_stmt_codec.c} (97%) rename libmariadb/{string.c => ma_string.c} (90%) rename libmariadb/{mysql_async.c => mariadb_async.c} (98%) rename libmariadb/{charset.c => mariadb_charset.c} (82%) rename libmariadb/{ma_dyncol.c => mariadb_dyncol.c} (97%) rename libmariadb/{libmariadb.c => mariadb_lib.c} (85%) rename libmariadb/{my_stmt.c => mariadb_stmt.c} (92%) delete mode 100644 libmariadb/mf_dirname.c delete mode 100644 libmariadb/mf_fn_ext.c delete mode 100644 libmariadb/mf_format.c delete mode 100644 libmariadb/mf_loadpath.c delete mode 100644 libmariadb/mf_pack.c delete mode 100644 libmariadb/mf_path.c delete mode 100644 libmariadb/mf_unixpath.c delete mode 100644 libmariadb/mf_wcomp.c delete mode 100644 libmariadb/my_div.c delete mode 100644 libmariadb/my_fopen.c delete mode 100644 libmariadb/my_fstream.c delete mode 100644 libmariadb/my_getwd.c delete mode 100644 libmariadb/my_init.c delete mode 100644 libmariadb/my_lib.c delete mode 100644 libmariadb/my_messnc.c delete mode 100644 libmariadb/my_net.c delete mode 100644 libmariadb/my_once.c delete mode 100644 libmariadb/my_open.c delete mode 100644 libmariadb/my_port.c delete mode 100644 libmariadb/my_pthread.c delete mode 100644 libmariadb/my_read.c delete mode 100644 libmariadb/my_seek.c delete mode 100644 libmariadb/my_static.c delete mode 100644 libmariadb/my_static.h delete mode 100644 libmariadb/my_symlink.c delete mode 100644 libmariadb/my_thr_init.c delete mode 100644 libmariadb/my_write.c delete mode 100644 libmariadb/mysys_priv.h delete mode 100644 libmariadb/sha1.c delete mode 100644 libmariadb/str2int.c delete mode 100644 libmariadb/strcont.c delete mode 100644 libmariadb/strto.c delete mode 100644 libmariadb/strtoll.c delete mode 100644 libmariadb/thr_mutex.c delete mode 100644 libmariadb/typelib.c rename {libmariadb => unittest/libmariadb}/getopt.c (99%) create mode 100644 unittest/libmariadb/ma_getopt.c rename include/getopt.h => unittest/libmariadb/ma_getopt.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bd7998f..ac816cdf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,8 @@ ELSE() ENDIF() OPTION(WITH_UNITTEST "build test suite" ON) +OPTION(WITH_DYNCOL "Enables support of dynamic coluumns" ON) +OPTION(WITH_NONBLOCK "Enables support for non blocking operations" ON) OPTION(WITH_EXTERNAL_ZLIB "Enables use of external zlib" OFF) ############### IF(WITH_SIGNCODE) @@ -113,12 +115,7 @@ ENDIF() # If the build type isn't specified, set to Relwithdebinfo as default. IF(NOT CMAKE_BUILD_TYPE) - SET(CMAKE_BUILD_TYPE "Relwithdebinfo") -ENDIF() - -OPTION(WITH_DBUG "enables use of DBUG library" OFF) -IF(NOT WITH_DBUG) - ADD_DEFINITIONS(-DDBUG_OFF=1) + SET(CMAKE_BUILD_TYPE "RelWithDebInfo") ENDIF() # various defines for generating include/mysql_version.h @@ -243,14 +240,10 @@ IF(NOT WIN32) INCLUDE(${CMAKE_SOURCE_DIR}/cmake/FindIconv.cmake) ENDIF() -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/mysql_version.h.in - ${CMAKE_CURRENT_BINARY_DIR}/include/mysql_version.h) -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/my_config.h.in - ${CMAKE_CURRENT_BINARY_DIR}/include/my_config.h) -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/mysql_version.h.in - ${CMAKE_CURRENT_SOURCE_DIR}/include/mysql_version.h) -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/my_config.h.in - ${CMAKE_CURRENT_SOURCE_DIR}/include/my_config.h) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/ma_config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/include/ma_config.h) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/mariadb_version.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/include/mariadb_version.h) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/include) @@ -294,8 +287,6 @@ IF(NOT WIN32) ADD_SUBDIRECTORY(mariadb_config) ENDIF() -ADD_SUBDIRECTORY(client) - IF(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/unittest) IF(WITH_UNITTEST STREQUAL "ON") ADD_SUBDIRECTORY(unittest/mytap) diff --git a/client/ma_plugin_info.c b/client/ma_plugin_info.c index 5edc5228..b015ba7f 100644 --- a/client/ma_plugin_info.c +++ b/client/ma_plugin_info.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #define CLIENT_PLUGIN_INFO_VERSION "1.0.0" diff --git a/cmake/export.cmake b/cmake/export.cmake new file mode 100644 index 00000000..595b259f --- /dev/null +++ b/cmake/export.cmake @@ -0,0 +1,16 @@ +MACRO(CREATE_EXPORT_FILE targetname directory symbols) + SET(EXPORT_FILE "${directory}/${targetname}.def") + IF(WIN32) + SET(EXPORT_CONTENT "EXPORTS\n") + FOREACH(exp_symbol ${symbols}) + SET(EXPORT_CONTENT ${EXPORT_CONTENT} "${exp_symbol}\n") + ENDFOREACH() + ELSE() + SET(EXPORT_CONTENT "{\nglobal:\n") + FOREACH(exp_symbol ${symbols}) + SET(EXPORT_CONTENT "${EXPORT_CONTENT} ${exp_symbol}\\;\n") + ENDFOREACH() + SET(EXPORT_CONTENT "${EXPORT_CONTENT}local:\n *\\;\n}\\;") + ENDIF() + FILE(WRITE ${EXPORT_FILE} ${EXPORT_CONTENT}) +ENDMACRO() diff --git a/cmake/plugins.cmake b/cmake/plugins.cmake index 6d5d0c0f..81418d98 100644 --- a/cmake/plugins.cmake +++ b/cmake/plugins.cmake @@ -90,7 +90,7 @@ ENDIF() # since some files contain multiple plugins, remove duplicates from source files LIST(REMOVE_DUPLICATES LIBMARIADB_SOURCES) -CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/libmariadb/client_plugin.c.in - ${CMAKE_BINARY_DIR}/libmariadb/client_plugin.c) +CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/libmariadb/ma_client_plugin.c.in + ${CMAKE_BINARY_DIR}/libmariadb/ma_client_plugin.c) MARK_AS_ADVANCED(LIBMARIADB_SOURCES) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index d2823e4d..55c7b8ca 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -2,8 +2,9 @@ SET(MARIADB_CLIENT_INCLUDES ${CMAKE_SOURCE_DIR}/include/mysql_com.h ${CMAKE_SOURCE_DIR}/include/mysql.h ${CMAKE_SOURCE_DIR}/include/my_stmt.h - ${CMAKE_SOURCE_DIR}/include/mysql_version.h + ${CMAKE_SOURCE_DIR}/include/mariadb_version.h ${CMAKE_SOURCE_DIR}/include/my_list.h + ${CMAKE_SOURCE_DIR}/include/mariadb_dyncol.h ${CMAKE_SOURCE_DIR}/include/mariadb_ctype.h) SET(MARIADB_ADDITIONAL_INCLUDES PARENT_SCOPE) diff --git a/include/dbug.h b/include/dbug.h deleted file mode 100644 index b7b17e32..00000000 --- a/include/dbug.h +++ /dev/null @@ -1,151 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#ifndef _dbug_h -#define _dbug_h -#ifdef __cplusplus -extern "C" { -#endif - -/* unsupported macros (used by async) */ -#define DBUG_SWAP_CODE_STATE(a) {} -#define DBUG_FREE_CODE_STATE(a) {} - -#if !defined(DBUG_OFF) && !defined(_lint) - -struct _db_stack_frame_ { - const char *func; /* function name of the previous stack frame */ - const char *file; /* filename of the function of previous frame */ - uint level; /* this nesting level, highest bit enables tracing */ - struct _db_stack_frame_ *prev; /* pointer to the previous frame */ -}; - -struct _db_code_state_; -extern my_bool _dbug_on_; -extern my_bool _db_keyword_(struct _db_code_state_ *, const char *, int); -extern int _db_explain_(struct _db_code_state_ *cs, char *buf, size_t len); -extern int _db_explain_init_(char *buf, size_t len); -extern int _db_is_pushed_(void); -extern void _db_setjmp_(void); -extern void _db_longjmp_(void); -extern void _db_process_(const char *name); -extern void _db_push_(const char *control); -extern void _db_pop_(void); -extern void _db_set_(const char *control); -extern void _db_set_init_(const char *control); -extern void _db_enter_(const char *_func_, const char *_file_, uint _line_, - struct _db_stack_frame_ *_stack_frame_); -extern void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_); -extern void _db_pargs_(uint _line_,const char *keyword); -extern void _db_doprnt_ _VARARGS((const char *format,...)); -extern void _db_dump_(uint _line_,const char *keyword, - const unsigned char *memory, size_t length); -extern void _db_end_(void); -extern void _db_lock_file_(void); -extern void _db_unlock_file_(void); -extern FILE *_db_fp_(void); -extern void _db_flush_(); -extern const char* _db_get_func_(void); -/* -#define DBUG_ENTER(a) struct _db_stack_frame_ _db_stack_frame_; \ - _db_enter_ (a,__FILE__,__LINE__,&_db_stack_frame_) -#define DBUG_LEAVE \ - (_db_return_ (__LINE__, &_db_func_, &_db_file_, &_db_level_)) -#define DBUG_RETURN(a1) do {DBUG_LEAVE; return(a1);} while(0) -#define DBUG_VOID_RETURN {DBUG_LEAVE; return;} -#define DBUG_END() _db_end_ () -#define DBUG_EXECUTE(keyword,a1) \ - {if (_db_on_) {if (_db_keyword_ (keyword)) { a1 }}} -#define DBUG_PRINT(keyword,arglist) \ - {if (_db_on_) {_db_pargs_(__LINE__,keyword); _db_doprnt_ arglist;}} -#define DBUG_PUSH(a1) _db_push_ (a1) -#define DBUG_POP() _db_pop_ () -#define DBUG_PROCESS(a1) (_db_process_ = a1) -#define DBUG_FILE (_db_fp_) -#define DBUG_SETJMP(a1) (_db_setjmp_ (), setjmp (a1)) -#define DBUG_LONGJMP(a1,a2) (_db_longjmp_ (), longjmp (a1, a2)) -#define DBUG_DUMP(keyword,a1,a2)\ - {if (_db_on_) {_db_dump_(__LINE__,keyword,a1,a2);}} -#define DBUG_IN_USE (_db_fp_ && _db_fp_ != stderr) -#define DEBUGGER_OFF _no_db_=1;_db_on_=0; -#define DEBUGGER_ON _no_db_=0 -#define DBUG_LOCK_FILE { _db_lock_file(); } -#define DBUG_UNLOCK_FILE { _db_unlock_file(); } -#define DBUG_ASSERT(A) assert(A) */ -#define DBUG_ENTER(a) struct _db_stack_frame_ _db_stack_frame_; \ - _db_enter_ (a,__FILE__,__LINE__,&_db_stack_frame_) -#define DBUG_LEAVE _db_return_ (__LINE__, &_db_stack_frame_) -#define DBUG_RETURN(a1) do {DBUG_LEAVE; return(a1);} while(0) -#define DBUG_VOID_RETURN do {DBUG_LEAVE; return;} while(0) -#define DBUG_EXECUTE(keyword,a1) \ - do {if (_db_keyword_(0, (keyword), 0)) { a1 }} while(0) -#define DBUG_EXECUTE_IF(keyword,a1) \ - do {if (_db_keyword_(0, (keyword), 1)) { a1 }} while(0) -#define DBUG_EVALUATE(keyword,a1,a2) \ - (_db_keyword_(0,(keyword), 0) ? (a1) : (a2)) -#define DBUG_EVALUATE_IF(keyword,a1,a2) \ - (_db_keyword_(0,(keyword), 1) ? (a1) : (a2)) -#define DBUG_PRINT(keyword,arglist) \ - do {_db_pargs_(__LINE__,keyword); _db_doprnt_ arglist;} while(0) -#define DBUG_PUSH(a1) _db_push_ (a1) -#define DBUG_POP() _db_pop_ () -#define DBUG_SET(a1) _db_set_ (a1) -#define DBUG_SET_INITIAL(a1) _db_set_init_ (a1) -#define DBUG_PROCESS(a1) _db_process_(a1) -#define DBUG_FILE _db_fp_() -#define DBUG_SETJMP(a1) (_db_setjmp_ (), setjmp (a1)) -#define DBUG_LONGJMP(a1,a2) (_db_longjmp_ (), longjmp (a1, a2)) -#define DBUG_DUMP(keyword,a1,a2) _db_dump_(__LINE__,keyword,a1,a2) -#define DBUG_END() _db_end_ () -#define DBUG_LOCK_FILE _db_lock_file_() -#define DBUG_UNLOCK_FILE _db_unlock_file_() -#define DBUG_ASSERT(A) assert(A) -#define DBUG_EXPLAIN(buf,len) _db_explain_(0, (buf),(len)) -#define DBUG_EXPLAIN_INITIAL(buf,len) _db_explain_init_((buf),(len)) -#define DEBUGGER_OFF do { _dbug_on_= 0; } while(0) -#define DEBUGGER_ON do { _dbug_on_= 1; } while(0) -#ifndef _WIN32 -#define DBUG_ABORT() (_db_flush_(), abort()) -#else -#define DBUG_ABORT() (_db_flush_(), exit(3)) -#endif - -#else /* No debugger */ -#define DBUG_ENTER(a1) -#define DBUG_END() {} -#define DBUG_RETURN(a1) return(a1) -#define DBUG_VOID_RETURN return -#define DBUG_EXECUTE(keyword,a1) {} -#define DBUG_PRINT(keyword,arglist) {} -#define DBUG_PUSH(a1) {} -#define DBUG_POP() {} -#define DBUG_PROCESS(a1) {} -#define DBUG_FILE (stderr) -#define DBUG_SETJMP setjmp -#define DBUG_LONGJMP longjmp -#define DBUG_DUMP(keyword,a1,a2) {} -#define DBUG_IN_USE 0 -#define DEBUGGER_OFF -#define DEBUGGER_ON -#define DBUG_LOCK_FILE -#define DBUG_UNLOCK_FILE -#define DBUG_ASSERT(A) {} -#endif -#ifdef __cplusplus -} -#endif -#endif diff --git a/include/m_string.h b/include/m_string.h deleted file mode 100644 index 9f7ba624..00000000 --- a/include/m_string.h +++ /dev/null @@ -1,230 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* There may be prolems include all of theese. Try to test in - configure with ones are needed? */ - -/* This is needed for the definitions of strchr... on solaris */ - -#ifndef _m_string_h -#define _m_string_h -#ifndef __USE_GNU -#define __USE_GNU /* We want to use stpcpy */ -#endif -#if defined(HAVE_STRINGS_H) -#include -#endif -#if defined(HAVE_STRING_H) -#include -#endif - -/* Correct some things for UNIXWARE7 */ -#ifdef HAVE_UNIXWARE7_THREADS -#undef HAVE_STRINGS_H -#undef HAVE_MEMORY_H -#define HAVE_MEMCPY -#ifndef HAVE_MEMMOVE -#define HAVE_MEMMOVE -#endif -#undef HAVE_BCMP -#undef bcopy -#undef bcmp -#undef bzero -#endif /* HAVE_UNIXWARE7_THREADS */ -#ifdef _AIX -#undef HAVE_BCMP -#endif - -/* This is needed for the definitions of bzero... on solaris */ -#if defined(HAVE_STRINGS_H) && !defined(HAVE_mit_thread) -#include -#endif - -/* This is needed for the definitions of memcpy... on solaris */ -#if defined(HAVE_MEMORY_H) && !defined(__cplusplus) -#include -#endif - -#if !defined(HAVE_MEMCPY) && !defined(HAVE_MEMMOVE) -# define memcpy(d, s, n) bcopy ((s), (d), (n)) -# define memset(A,C,B) bfill((A),(B),(C)) -# define memmove(d, s, n) bmove ((d), (s), (n)) -#elif defined(HAVE_MEMMOVE) -# define bmove(d, s, n) memmove((d), (s), (n)) -#else -# define memmove(d, s, n) bmove((d), (s), (n)) /* our bmove */ -#endif - -/* Unixware 7 */ -#if !defined(HAVE_BFILL) -# define bfill(A,B,C) memset((A),(C),(B)) -# define bmove_allign(A,B,C) memcpy((A),(B),(C)) -#endif - -#if !defined(HAVE_BCMP) -# define bcopy(s, d, n) memcpy((d), (s), (n)) -# define bcmp(A,B,C) memcmp((A),(B),(C)) -# define bzero(A,B) memset((A),0,(B)) -# define bmove_allign(A,B,C) memcpy((A),(B),(C)) -#endif - -#if defined(__cplusplus) -extern "C" { -#endif - -#if defined(HAVE_STPCPY) && !defined(HAVE_mit_thread) -#define strmov(A,B) stpcpy((A),(B)) -#define strnmov(A,B,C) stpncpy((A),(B),(C)) -#else -#define strmov(A,B) (strcpy((A),(B)) + strlen((B))) -#define strnmov(A,B,C) (strncpy((A),(B),(C)) + strlen((B))) -#endif - -extern char NEAR _dig_vec[]; /* Declared in int2str() */ - -#ifdef BAD_STRING_COMPILER -#define strmov(A,B) (memccpy(A,B,0,INT_MAX)-1) -#else -#define strmov_overlapp(A,B) strmov(A,B) -#define strmake_overlapp(A,B,C) strmake(A,B,C) -#endif - -#ifdef BAD_MEMCPY /* Problem with gcc on Alpha */ -#define memcpy_fixed(A,B,C) bmove((A),(B),(C)) -#else -#define memcpy_fixed(A,B,C) memcpy((A),(B),(C)) -#endif - -#if (!defined(USE_BMOVE512) || defined(HAVE_purify)) && !defined(bmove512) -#define bmove512(A,B,C) memcpy(A,B,C) -#endif - - /* Prototypes for string functions */ - -#if !defined(bfill) && !defined(HAVE_BFILL) -extern void bfill(gptr dst, size_t len, pchar fill); -#endif - -#if !defined(bzero) && !defined(HAVE_BZERO) -extern void bzero(gptr dst, size_t len); -#endif - -#if !defined(bcmp) && !defined(HAVE_BCMP) -extern int bcmp(const char *s1,const char *s2, size_t len); -#ifdef HAVE_purify -extern int my_bcmp(const char *s1,const char *s2, size_t len); -#define bcmp(A,B,C) my_bcmp((A),(B),(C)) -#endif -#endif - -#ifndef bmove512 -extern void bmove512(gptr dst,const gptr src, size_t len); -#endif - -#if !defined(HAVE_BMOVE) && !defined(bmove) -extern void bmove(char *dst, const char *src, size_t len); -#endif - -extern void bmove_upp(char *dst,const char *src, size_t len); -extern void bchange(char *dst, size_t old_len, const char *src, - size_t new_len, size_t tot_len); -extern void strappend(char *s,size_t len,pchar fill); -#define strend(s) strchr((s),'\0') -extern char *strcend(const char *, char); -extern char *strfield(char *src,int fields,int chars,int blanks, - int tabch); -extern char *strfill(my_string s, size_t len, pchar fill); -extern uint strinstr(const char *str,const char *search); -extern uint r_strinstr(reg1 my_string str,int from, reg4 my_string search); -extern char *strkey(char *dst,char *head,char *tail,char *flags); -extern char *strmake(char *dst,const char *src, size_t length); -#ifndef strmake_overlapp -extern char *strmake_overlapp(char *dst,const char *src, size_t length); -#endif - -extern char *strsuff(const char *src,const char *suffix); -extern char *strcont(const char *src,const char *set); -extern char *strxcat _VARARGS((char *dst,const char *src, ...)); -extern char *strxmov _VARARGS((char *dst,const char *src, ...)); -extern char *strxcpy _VARARGS((char *dst,const char *src, ...)); -extern char *strxncat _VARARGS((char *dst, size_t len, const char *src, ...)); -extern char *strxnmov _VARARGS((char *dst, size_t len, const char *src, ...)); -extern char *strxncpy _VARARGS((char *dst, size_t len, const char *src, ...)); - -/* Prototypes of normal stringfunctions (with may ours) */ - -#ifdef WANT_STRING_PROTOTYPES -extern char *strcat(char *, const char *); -extern char *strchr(const char *, pchar); -extern char *strrchr(const char *, pchar); -extern char *strcpy(char *, const char *); -extern int strcmp(const char *, const char *); -#ifndef __GNUC__ -extern size_t strlen(const char *); -#endif -#endif - -#if !defined(__cplusplus) -#ifndef HAVE_STRPBRK -extern char *strpbrk(const char *, const char *); -#endif -#ifndef HAVE_STRSTR -extern char *strstr(const char *, const char *); -#endif -#endif -extern int is_prefix(const char *, const char *); - -/* Conversion rutins */ - -#ifdef USE_MY_ITOA -extern char *my_itoa(int val,char *dst,int radix); -extern char *my_ltoa(long val,char *dst,int radix); -#endif - -extern char *ma_llstr(longlong value,char *buff); -#ifndef HAVE_STRTOUL -extern long strtol(const char *str, char **ptr, int base); -extern ulong strtoul(const char *str, char **ptr, int base); -#endif - -extern char *ma_int2str(long val,char *dst,int radix); -extern char *ma_int10_to_str(long val,char *dst,int radix); -extern char *ma_str2int(const char *src,int radix,long lower,long upper, - long *val); -#if SIZEOF_LONG == SIZEOF_LONG_LONG -#define ma_longlong2str(A,B,C) ma_int2str((A),(B),(C)) -#define ma_longlong10_to_str(A,B,C) ma_int10_to_str((A),(B),(C)) -#define strtoll(A,B,C) strtol((A),(B),(C)) -#define strtoull(A,B,C) strtoul((A),(B),(C)) -#ifndef HAVE_STRTOULL -#define HAVE_STRTOULL -#endif -#else -#ifdef HAVE_LONG_LONG -extern char *ma_longlong2str(longlong val,char *dst,int radix); -extern char *ma_longlong10_to_str(longlong val,char *dst,int radix); -#if (!defined(HAVE_STRTOULL) || defined(HAVE_mit_thread)) || defined(NO_STRTOLL_PROTO) -extern longlong strtoll(const char *str, char **ptr, int base); -extern ulonglong strtoull(const char *str, char **ptr, int base); -#endif -#endif -#endif - -#if defined(__cplusplus) -} -#endif -#endif diff --git a/include/ma_common.h b/include/ma_common.h index a34ac47f..4a0fca91 100644 --- a/include/ma_common.h +++ b/include/ma_common.h @@ -21,7 +21,7 @@ #define _ma_common_h #include -#include +#include typedef struct st_mariadb_db_driver @@ -57,6 +57,7 @@ struct st_mysql_options_extension { char *url; /* for connection handler we need to save URL for reconnect */ my_bool read_only; char *connection_handler; + my_bool (*set_option)(MYSQL *mysql, const char *config_option, const char *config_value); HASH userdata; }; diff --git a/include/my_config.h.in b/include/ma_config.h.in similarity index 100% rename from include/my_config.h.in rename to include/ma_config.h.in diff --git a/include/config-win.h b/include/ma_config_win.h similarity index 100% rename from include/config-win.h rename to include/ma_config_win.h diff --git a/include/my_context.h b/include/ma_context.h similarity index 100% rename from include/my_context.h rename to include/ma_context.h diff --git a/include/errmsg.h b/include/ma_errmsg.h similarity index 93% rename from include/errmsg.h rename to include/ma_errmsg.h index 6f1318dc..18397bca 100644 --- a/include/errmsg.h +++ b/include/ma_errmsg.h @@ -1,4 +1,5 @@ /* 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 @@ -17,8 +18,8 @@ /* Error messages for mysql clients */ /* error messages for the demon is in share/language/errmsg.sys */ -#ifndef _errmsg_h_ -#define _errmsg_h_ +#ifndef _ma_errmsg_h_ +#define _ma_errmsg_h_ #ifdef __cplusplus extern "C" { @@ -31,6 +32,7 @@ extern const char *mariadb_client_errors[]; /* Error messages */ #endif + #define CR_MIN_ERROR 2000 /* For easier client code */ #define CR_MAX_ERROR 2999 #define CER_MIN_ERROR 5000 @@ -70,7 +72,6 @@ extern const char *mariadb_client_errors[]; /* Error messages */ #define CR_SHARED_MEMORY_CONNECTION 2037 #define CR_SHARED_MEMORY_CONNECT_ERROR 2038 - #define CR_SECURE_AUTH 2049 #define CR_NO_DATA 2051 #define CR_NO_STMT_METADATA 2052 @@ -82,10 +83,15 @@ extern const char *mariadb_client_errors[]; /* Error messages */ #define CR_ALREADY_CONNECTED 2059 #define CR_PLUGIN_FUNCTION_NOT_SUPPORTED 2060 +/* + * 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 SQLSTATE_UNKNOWN "HY000" diff --git a/include/my_global.h b/include/ma_global.h similarity index 99% rename from include/my_global.h rename to include/ma_global.h index 7ec47051..0b21400f 100644 --- a/include/my_global.h +++ b/include/ma_global.h @@ -23,9 +23,9 @@ #ifdef _WIN32 -#include +#include #else -#include +#include #if defined(__cplusplus) && defined(inline) #undef inline /* fix configure problem */ #endif @@ -257,7 +257,7 @@ int __void__; #if defined(_lint) || defined(FORCE_INIT_OF_VARS) #define LINT_INIT(var) var=0 /* No uninitialize-warning */ -#define LINT_INIT_STRUCT(var) bzero(&var, sizeof(var)) /* No uninitialize-warning */ +#define LINT_INIT_STRUCT(var) memset(&var, 0, sizeof(var)) /* No uninitialize-warning */ #else #define LINT_INIT(var) #define LINT_INIT_STRUCT(var) @@ -1064,11 +1064,12 @@ do { doubleget_union _tmp; \ #define SO_EXT ".so" #endif -#include #ifndef DBUG_OFF #define dbug_assert(A) assert(A) +#define DBUG_ASSERT(A) assert(A) #else #define dbug_assert(A) +#define DBUG_ASSERT(A) #endif #ifdef HAVE_DLOPEN diff --git a/include/hash.h b/include/ma_hash.h similarity index 96% rename from include/hash.h rename to include/ma_hash.h index 35e24c32..198d4d0a 100644 --- a/include/hash.h +++ b/include/ma_hash.h @@ -21,8 +21,8 @@ is freely available from http://www.php.net *************************************************************************************/ -#ifndef _hash_h -#define _hash_h +#ifndef _ma_hash_h +#define _ma_hash_h #ifdef __cplusplus extern "C" { #endif @@ -61,7 +61,7 @@ my_bool hash_delete(HASH *hash,uchar *record); my_bool hash_update(HASH *hash,uchar *record,uchar *old_key,uint old_key_length); my_bool hash_check(HASH *hash); /* Only in debug library */ -#define hash_clear(H) bzero((char*) (H),sizeof(*(H))) +#define hash_clear(H) memset((char*) (H), 0,sizeof(*(H))) #define hash_inited(H) ((H)->array.buffer != 0) #ifdef __cplusplus diff --git a/include/my_list.h b/include/ma_list.h similarity index 100% rename from include/my_list.h rename to include/ma_list.h diff --git a/include/ma_pvio.h b/include/ma_pvio.h index 6984bb7b..4848bebf 100644 --- a/include/ma_pvio.h +++ b/include/ma_pvio.h @@ -18,6 +18,7 @@ struct st_ma_pvio_methods; typedef struct st_ma_pvio_methods PVIO_METHODS; +#ifdef HAVE_NONBLOCK #define IS_PVIO_ASYNC(a) \ ((a)->mysql && (a)->mysql->options.extension && (a)->mysql->options.extension->async_context) @@ -29,6 +30,12 @@ typedef struct st_ma_pvio_methods PVIO_METHODS; #define IS_MYSQL_ASYNC_ACTIVE(a) \ (IS_MYSQL_ASYNC(a)&& (a)->options.extension->async_context->active) +#else +#define IS_PVIO_ASYNC(a) (0) +#define IS_PVIO_ASYNC_ACTIVE(a) (0) +#define IS_MYSQL_ASYNC(a) (0) +#define IS_MYSQL_ASYNC_ACTIVE(a) (0) +#endif enum enum_pvio_timeout { PVIO_CONNECT_TIMEOUT= 0, @@ -75,7 +82,6 @@ struct st_ma_pvio { MYSQL *mysql; struct mysql_async_context *async_context; /* For non-blocking API */ PVIO_METHODS *methods; - FILE *fp; 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 char *buffer, size_t length); }; diff --git a/include/mysqld_error.h b/include/ma_server_error.h similarity index 100% rename from include/mysqld_error.h rename to include/ma_server_error.h diff --git a/include/sha1.h b/include/ma_sha1.h similarity index 86% rename from include/sha1.h rename to include/ma_sha1.h index 6113d791..2748f114 100644 --- a/include/sha1.h +++ b/include/ma_sha1.h @@ -1,5 +1,6 @@ /**************************************************************************** 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 @@ -32,10 +33,10 @@ typedef struct { uint32 state[5]; /* state (ABCD) */ uint32 count[2]; /* number of bits, modulo 2^64 (lsb first) */ unsigned char buffer[64]; /* input buffer */ -} MYSQL_SHA1_CTX; +} _MA_SHA1_CTX; -void MYSQL_SHA1Init(MYSQL_SHA1_CTX *); -void MYSQL_SHA1Update(MYSQL_SHA1_CTX *, const unsigned char *, size_t); -void MYSQL_SHA1Final(unsigned char[20], MYSQL_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 diff --git a/libmariadb/strtoull.c b/include/ma_string.h similarity index 80% rename from libmariadb/strtoull.c rename to include/ma_string.h index 104885e7..cae0fedb 100644 --- a/libmariadb/strtoull.c +++ b/include/ma_string.h @@ -1,5 +1,6 @@ /* 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 @@ -15,12 +16,13 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ -/* This is defines strtoull() */ +/* defines for the libmariadb library */ + +#ifndef _ma_string_h_ +#define _ma_string_h_ + +#include + +char *ma_ll2str(long long val,char *dst, int radix); -#include -#include -#if !defined(HAVE_STRTOULL) && defined(HAVE_LONG_LONG) -#define USE_UNSIGNED -#define USE_LONGLONG -#include "strto.c" #endif diff --git a/include/my_sys.h b/include/ma_sys.h similarity index 86% rename from include/my_sys.h rename to include/ma_sys.h index a421a0f4..6608eded 100644 --- a/include/my_sys.h +++ b/include/ma_sys.h @@ -29,12 +29,6 @@ typedef struct my_aio_result { } my_aio_result; #endif -#ifndef THREAD -extern int NEAR my_errno; /* Last error in mysys */ -#else -#include -#endif - #ifndef _mariadb_ctype_h #include /* for MARIADB_CHARSET_INFO */ #endif @@ -165,27 +159,29 @@ extern int errno; /* declare errno */ #endif extern const char ** NEAR my_errmsg[]; extern char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE]; -extern char *ma_ma_ma_home_dir; /* Home directory for user */ -extern char *ma_progname; /* program-name (printed in errors) */ -extern char NEAR ma_cur_dir[]; /* Current directory for user */ +/* 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 MARIADB_CHARSET_INFO *get_charset(uint cs_number, myf flags); extern my_bool set_default_charset(uint cs, 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); 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); /* ma_free() this string... */ +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); /* 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; @@ -212,7 +208,6 @@ extern my_bool NEAR ma_disable_locking,NEAR ma_disable_async_io, 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 */ @@ -225,6 +220,7 @@ struct my_rnd_struct { double max_value_dbl; }; +#endif typedef struct st_typelib { /* Different types saved here */ uint count; /* How many types */ const char *name; /* Name of typelib */ @@ -249,6 +245,7 @@ typedef struct st_record_cache /* Used when cacheing records */ enum cache_type type; } RECORD_CACHE; +/* enum file_type { UNOPEN = 0, FILE_BY_OPEN, FILE_BY_CREATE, STREAM_BY_FOPEN, STREAM_BY_FDOPEN, FILE_BY_MKSTEMP }; @@ -260,7 +257,7 @@ extern struct ma_file_info pthread_mutex_t mutex; #endif } ma_file_info[MY_NFILE]; - +*/ typedef struct st_dynamic_array { char *buffer; @@ -369,46 +366,6 @@ typedef struct st_ma_mem_root { /* Prototypes for mysys and my_func functions */ -extern int my_copy(const char *from,const char *to,myf MyFlags); -extern int my_append(const char *from,const char *to,myf MyFlags); -extern int my_delete(const char *name,myf MyFlags); -extern int my_getwd(my_string buf,uint size,myf MyFlags); -extern int my_setwd(const char *dir,myf MyFlags); -extern int my_lock(File fd,int op,my_off_t start, my_off_t length,myf MyFlags); -extern gptr my_once_alloc(uint Size,myf MyFlags); -extern void my_once_free(void); -extern my_string my_tempnam(const char *dir,const char *pfx,myf MyFlags); -extern File my_open(const char *FileName,int Flags,myf MyFlags); -extern File my_register_filename(File fd, const char *FileName, - enum file_type type_of_file, - uint error_message_number, myf MyFlags); -extern File my_create(const char *FileName,int CreateFlags, - int AccsesFlags, myf MyFlags); -extern int my_close(File Filedes,myf MyFlags); -extern int my_mkdir(const char *dir, int Flags, myf MyFlags); -extern int my_readlink(char *to, const char *filename, myf MyFlags); -extern int my_realpath(char *to, const char *filename, myf MyFlags); -extern File my_create_with_symlink(const char *linkname, const char *filename, - int createflags, int access_flags, - myf MyFlags); -extern int my_delete_with_symlink(const char *name, myf MyFlags); -extern int my_rename_with_symlink(const char *from,const char *to,myf MyFlags); -extern int my_symlink(const char *content, const char *linkname, myf MyFlags); -extern uint my_read(File Filedes,unsigned char *Buffer,uint Count,myf MyFlags); -extern uint my_pread(File Filedes,unsigned char *Buffer,uint Count,my_off_t offset, - myf MyFlags); -extern int my_rename(const char *from,const char *to,myf MyFlags); -extern my_off_t my_seek(File fd,my_off_t pos,int whence,myf MyFlags); -extern my_off_t my_tell(File fd,myf MyFlags); -extern uint my_write(File Filedes,const unsigned char *Buffer,uint Count, - myf MyFlags); -extern uint my_pwrite(File Filedes,const unsigned char *Buffer,uint Count, - my_off_t offset,myf MyFlags); -extern uint my_fread(FILE *stream,unsigned char *Buffer,uint Count,myf MyFlags); -extern uint my_fwrite(FILE *stream,const unsigned char *Buffer,uint Count, - myf MyFlags); -extern my_off_t my_fseek(FILE *stream,my_off_t pos,int whence,myf MyFlags); -extern my_off_t my_ftell(FILE *stream,myf MyFlags); extern gptr _mymalloc(size_t uSize,const char *sFile, uint uLine, myf MyFlag); extern gptr _myrealloc(gptr pPtr,size_t uSize,const char *sFile, @@ -432,8 +389,8 @@ 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 ma_message_no_curses(uint my_err, const char *str,myf MyFlags); -extern int ma_message_curses(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); @@ -484,6 +441,7 @@ 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); @@ -543,9 +501,10 @@ 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) -#define ma_init_dynamic_array_ci(A,B,C,D) init_dynamic_array(A,B,C,D ORIG_CALLER_INFO) -extern my_bool init_dynamic_array(DYNAMIC_ARRAY *array,uint element_size, +#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,gptr element); extern unsigned char *ma_alloc_dynamic(DYNAMIC_ARRAY *array); extern unsigned char *ma_pop_dynamic(DYNAMIC_ARRAY*); @@ -586,13 +545,11 @@ gptr 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 mariadb_load_defaults(const char *conf_file, const char **groups, - int *argc, char ***argv); void ma_free_defaults(char **argv); void ma_print_defaults(const char *conf_file, const char **groups); -my_bool my_compress(unsigned char *, size_t *, size_t *); -my_bool my_uncompress(unsigned char *, size_t *, size_t *); -unsigned char *my_compress_alloc(const unsigned char *packet, size_t *len, size_t *complen); +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) diff --git a/include/mysql_async.h b/include/mariadb_async.h similarity index 100% rename from include/mysql_async.h rename to include/mariadb_async.h diff --git a/include/mysql_com.h b/include/mariadb_com.h similarity index 100% rename from include/mysql_com.h rename to include/mariadb_com.h diff --git a/include/ma_dyncol.h b/include/mariadb_dyncol.h similarity index 100% rename from include/ma_dyncol.h rename to include/mariadb_dyncol.h diff --git a/include/my_stmt.h b/include/mariadb_stmt.h similarity index 100% rename from include/my_stmt.h rename to include/mariadb_stmt.h diff --git a/include/mysql_version.h.in b/include/mariadb_version.h.in similarity index 100% rename from include/mysql_version.h.in rename to include/mariadb_version.h.in diff --git a/include/my_alarm.h b/include/my_alarm.h deleted file mode 100644 index ab8424a8..00000000 --- a/include/my_alarm.h +++ /dev/null @@ -1,60 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - File to include when we want to use alarm or a loop_counter to display - some information when a program is running -*/ -#ifndef _my_alarm_h -#define _my_alarm_h -#ifdef __cplusplus -extern "C" { -#endif - -extern int volatile ma_have_got_alarm; -extern ulong ma_time_to_wait_for_lock; - -#if defined(HAVE_ALARM) && !defined(NO_ALARM_LOOP) -#include -#define ALARM_VARIABLES uint alarm_old=0; \ - sig_return alarm_signal=0 -#define ALARM_INIT ma_have_got_alarm=0 ; \ - alarm_old=(uint) alarm(MY_HOW_OFTEN_TO_ALARM); \ - alarm_signal=signal(SIGALRM,my_set_alarm_variable); -#define ALARM_END VOID(signal(SIGALRM,alarm_signal)); \ - VOID(alarm(alarm_old)); -#define ALARM_TEST ma_have_got_alarm -#ifdef DONT_REMEMBER_SIGNAL -#define ALARM_REINIT VOID(alarm(MY_HOW_OFTEN_TO_ALARM)); \ - VOID(signal(SIGALRM,my_set_alarm_variable));\ - ma_have_got_alarm=0; -#else -#define ALARM_REINIT VOID(alarm((uint) MY_HOW_OFTEN_TO_ALARM)); \ - ma_have_got_alarm=0; -#endif /* DONT_REMEMBER_SIGNAL */ -#else -#define ALARM_VARIABLES long alarm_pos=0,alarm_end_pos=MY_HOW_OFTEN_TO_WRITE-1 -#define ALARM_INIT -#define ALARM_END -#define ALARM_TEST (alarm_pos++ >= alarm_end_pos) -#define ALARM_REINIT alarm_end_pos+=MY_HOW_OFTEN_TO_WRITE -#endif /* HAVE_ALARM */ - -#ifdef __cplusplus -} -#endif -#endif diff --git a/include/my_base.h b/include/my_base.h deleted file mode 100644 index 6275adab..00000000 --- a/include/my_base.h +++ /dev/null @@ -1,287 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* This file includes constants used with all databases */ -/* Author: Michael Widenius */ - -#ifndef _my_base_h -#define _my_base_h - -#ifndef stdin /* Included first in handler */ -#define USES_TYPES /* my_dir with sys/types is included */ -#define CHSIZE_USED -#include -#include /* This includes types */ -#include -#include -#include -#ifdef MSDOS -#include /* Neaded for sopen() */ -#endif -#if !defined(USE_MY_FUNC) && !defined(THREAD) -#include /* For faster code, after test */ -#endif /* USE_MY_FUNC */ -#endif /* stdin */ -#include - -/* The following is bits in the flag parameter to ha_open() */ - -#define HA_OPEN_ABORT_IF_LOCKED 0 /* default */ -#define HA_OPEN_WAIT_IF_LOCKED 1 -#define HA_OPEN_IGNORE_IF_LOCKED 2 -#define HA_OPEN_TMP_TABLE 4 /* Table is a temp table */ -#define HA_OPEN_DELAY_KEY_WRITE 8 /* Don't update index */ -#define HA_OPEN_ABORT_IF_CRASHED 16 -#define HA_OPEN_FOR_REPAIR 32 /* open even if crashed */ - - /* The following is parameter to ha_rkey() how to use key */ - -enum ha_rkey_function { - HA_READ_KEY_EXACT, /* Find first record else error */ - HA_READ_KEY_OR_NEXT, /* Record or next record */ - HA_READ_KEY_OR_PREV, /* Record or previous */ - HA_READ_AFTER_KEY, /* Find next rec. after key-record */ - HA_READ_BEFORE_KEY, /* Find next rec. before key-record */ - HA_READ_PREFIX, /* Key which as same prefix */ - HA_READ_PREFIX_LAST /* Last key with the same prefix */ -}; - - /* The following is parameter to ha_extra() */ - -enum ha_extra_function { - HA_EXTRA_NORMAL=0, /* Optimize for space (def) */ - HA_EXTRA_QUICK=1, /* Optimize for speed */ - HA_EXTRA_RESET=2, /* Reset database to after open */ - HA_EXTRA_CACHE=3, /* Cash record in HA_rrnd() */ - HA_EXTRA_NO_CACHE=4, /* End cacheing of records (def) */ - HA_EXTRA_NO_READCHECK=5, /* No readcheck on update */ - HA_EXTRA_READCHECK=6, /* Use readcheck (def) */ - HA_EXTRA_KEYREAD=7, /* Read only key to database */ - HA_EXTRA_NO_KEYREAD=8, /* Normal read of records (def) */ - HA_EXTRA_NO_USER_CHANGE=9, /* No user is allowed to write */ - HA_EXTRA_KEY_CACHE=10, - HA_EXTRA_NO_KEY_CACHE=11, - HA_EXTRA_WAIT_LOCK=12, /* Wait until file is avalably (def) */ - HA_EXTRA_NO_WAIT_LOCK=13, /* If file is locked, return quickly */ - HA_EXTRA_WRITE_CACHE=14, /* Use write cache in ha_write() */ - HA_EXTRA_FLUSH_CACHE=15, /* flush write_record_cache */ - HA_EXTRA_NO_KEYS=16, /* Remove all update of keys */ - HA_EXTRA_KEYREAD_CHANGE_POS=17, /* Keyread, but change pos */ - /* xxxxchk -r must be used */ - HA_EXTRA_REMEMBER_POS=18, /* Remember pos for next/prev */ - HA_EXTRA_RESTORE_POS=19, - HA_EXTRA_REINIT_CACHE=20, /* init cache from current record */ - HA_EXTRA_FORCE_REOPEN=21, /* Datafile have changed on disk */ - HA_EXTRA_FLUSH, /* Flush tables to disk */ - HA_EXTRA_NO_ROWS, /* Don't write rows */ - HA_EXTRA_RESET_STATE, /* Reset positions */ - HA_EXTRA_IGNORE_DUP_KEY, /* Dup keys don't rollback everything*/ - HA_EXTRA_NO_IGNORE_DUP_KEY, - HA_EXTRA_DONT_USE_CURSOR_TO_UPDATE /* Cursor will not be used for update */ -}; - - /* The following is parameter to ha_panic() */ - -enum ha_panic_function { - HA_PANIC_CLOSE, /* Close all databases */ - HA_PANIC_WRITE, /* Unlock and write status */ - HA_PANIC_READ /* Lock and read keyinfo */ -}; - - /* The following is parameter to ha_create(); keytypes */ - -enum ha_base_keytype { - HA_KEYTYPE_END=0, - HA_KEYTYPE_TEXT=1, /* Key is sorted as letters */ - HA_KEYTYPE_BINARY=2, /* Key is sorted as unsigned chars */ - HA_KEYTYPE_SHORT_INT=3, - HA_KEYTYPE_LONG_INT=4, - HA_KEYTYPE_FLOAT=5, - HA_KEYTYPE_DOUBLE=6, - HA_KEYTYPE_NUM=7, /* Not packed num with pre-space */ - HA_KEYTYPE_USHORT_INT=8, - HA_KEYTYPE_ULONG_INT=9, - HA_KEYTYPE_LONGLONG=10, - HA_KEYTYPE_ULONGLONG=11, - HA_KEYTYPE_INT24=12, - HA_KEYTYPE_UINT24=13, - HA_KEYTYPE_INT8=14, - HA_KEYTYPE_VARTEXT=15, /* Key is sorted as letters */ - HA_KEYTYPE_VARBINARY=16 /* Key is sorted as unsigned chars */ -}; - -#define HA_MAX_KEYTYPE 31 /* Must be log2-1 */ - - /* These flags kan be OR:ed to key-flag */ - -#define HA_NOSAME 1 /* Set if not dupplicated records */ -#define HA_PACK_KEY 2 /* Pack string key to previous key */ -#define HA_AUTO_KEY 16 -#define HA_BINARY_PACK_KEY 32 /* Packing of all keys to prev key */ -#define HA_FULLTEXT 128 /* SerG: for full-text search */ -#define HA_UNIQUE_CHECK 256 /* Check the key for uniqueness */ - - /* Automatic bits in key-flag */ - -#define HA_SPACE_PACK_USED 4 /* Test for if SPACE_PACK used */ -#define HA_VAR_LENGTH_KEY 8 -#define HA_NULL_PART_KEY 64 -#ifndef ISAM_LIBRARY -#define HA_SORT_ALLOWS_SAME 512 /* Intern bit when sorting records */ -#else -/* poor old NISAM has 8-bit flags :-( */ -#define HA_SORT_ALLOWS_SAME 128 /* Intern bit when sorting records */ -#endif - - /* These flags can be order to key-seg-flag */ - -#define HA_SPACE_PACK 1 /* Pack space in key-seg */ -#define HA_PART_KEY 4 /* Used by MySQL for part-key-cols */ -#define HA_VAR_LENGTH 8 -#define HA_NULL_PART 16 -#define HA_BLOB_PART 32 -#define HA_SWAP_KEY 64 -#define HA_REVERSE_SORT 128 /* Sort key in reverse order */ - - /* optionbits for database */ -#define HA_OPTION_PACK_RECORD 1 -#define HA_OPTION_PACK_KEYS 2 -#define HA_OPTION_COMPRESS_RECORD 4 -#define HA_OPTION_LONG_BLOB_PTR 8 /* new ISAM format */ -#define HA_OPTION_TMP_TABLE 16 -#define HA_OPTION_CHECKSUM 32 -#define HA_OPTION_DELAY_KEY_WRITE 64 -#define HA_OPTION_NO_PACK_KEYS 128 /* Reserved for MySQL */ -#define HA_OPTION_TEMP_COMPRESS_RECORD ((uint) 16384) /* set by isamchk */ -#define HA_OPTION_READ_ONLY_DATA ((uint) 32768) /* Set by isamchk */ - - /* Bits in flag to create() */ - -#define HA_DONT_TOUCH_DATA 1 /* Don't empty datafile (isamchk) */ -#define HA_PACK_RECORD 2 /* Request packed record format */ -#define HA_CREATE_TMP_TABLE 4 -#define HA_CREATE_CHECKSUM 8 -#define HA_CREATE_DELAY_KEY_WRITE 64 - - /* Bits in flag to _status */ - -#define HA_STATUS_POS 1 /* Return position */ -#define HA_STATUS_NO_LOCK 2 /* Don't use external lock */ -#define HA_STATUS_TIME 4 /* Return update time */ -#define HA_STATUS_CONST 8 /* Return constants values */ -#define HA_STATUS_VARIABLE 16 -#define HA_STATUS_ERRKEY 32 -#define HA_STATUS_AUTO 64 - - /* Errorcodes given by functions */ - -#define HA_ERR_KEY_NOT_FOUND 120 /* Didn't find key on read or update */ -#define HA_ERR_FOUND_DUPP_KEY 121 /* Dupplicate key on write */ -#define HA_ERR_RECORD_CHANGED 123 /* Uppdate with is recoverable */ -#define HA_ERR_WRONG_INDEX 124 /* Wrong index given to function */ -#define HA_ERR_CRASHED 126 /* Indexfile is crashed */ -#define HA_ERR_WRONG_IN_RECORD 127 /* Record-file is crashed */ -#define HA_ERR_OUT_OF_MEM 128 /* Record-file is crashed */ -#define HA_ERR_WRONG_COMMAND 131 /* Command not supported */ -#define HA_ERR_OLD_FILE 132 /* old databasfile */ -#define HA_ERR_NO_ACTIVE_RECORD 133 /* No record read in update() */ -#define HA_ERR_RECORD_DELETED 134 /* Intern error-code */ -#define HA_ERR_RECORD_FILE_FULL 135 /* No more room in file */ -#define HA_ERR_INDEX_FILE_FULL 136 /* No more room in file */ -#define HA_ERR_END_OF_FILE 137 /* end in next/prev/first/last */ -#define HA_ERR_UNSUPPORTED 138 /* unsupported extension used */ -#define HA_ERR_TO_BIG_ROW 139 /* Too big row */ -#define HA_WRONG_CREATE_OPTION 140 /* Wrong create option */ -#define HA_ERR_FOUND_DUPP_UNIQUE 141 /* Dupplicate unique on write */ -#define HA_ERR_UNKNOWN_CHARSET 142 /* Can't open charset */ -#define HA_ERR_WRONG_TABLE_DEF 143 -#define HA_ERR_CRASHED_ON_REPAIR 144 /* Last (automatic?) repair failed */ -#define HA_ERR_CRASHED_ON_USAGE 145 /* Table must be repaired */ -#define HA_ERR_LOCK_WAIT_TIMEOUT 146 -#define HA_ERR_LOCK_TABLE_FULL 147 -#define HA_ERR_READ_ONLY_TRANSACTION 148 /* Updates not allowed */ -#define HA_ERR_LOCK_DEADLOCK 149 -#define HA_ERR_CANNOT_ADD_FOREIGN 150 /* Cannot add a foreign key constr. */ -#define HA_ERR_NO_REFERENCED_ROW 151 /* Cannot add a child row */ -#define HA_ERR_ROW_IS_REFERENCED 152 /* Cannot delete a parent row */ - - /* Other constants */ - -#define HA_NAMELEN 64 /* Max length of saved filename */ - - /* Intern constants in databases */ - - /* bits in _search */ -#define SEARCH_FIND 1 -#define SEARCH_NO_FIND 2 -#define SEARCH_SAME 4 -#define SEARCH_BIGGER 8 -#define SEARCH_SMALLER 16 -#define SEARCH_SAVE_BUFF 32 -#define SEARCH_UPDATE 64 -#define SEARCH_PREFIX 128 -#define SEARCH_LAST 256 - - /* bits in opt_flag */ -#define QUICK_USED 1 -#define READ_CACHE_USED 2 -#define READ_CHECK_USED 4 -#define KEY_READ_USED 8 -#define WRITE_CACHE_USED 16 -#define OPT_NO_ROWS 32 - - /* bits in update */ -#define HA_STATE_CHANGED 1 /* Database has changed */ -#define HA_STATE_AKTIV 2 /* Has a current record */ -#define HA_STATE_WRITTEN 4 /* Record is written */ -#define HA_STATE_DELETED 8 -#define HA_STATE_NEXT_FOUND 16 /* Next found record (record before) */ -#define HA_STATE_PREV_FOUND 32 /* Prev found record (record after) */ -#define HA_STATE_NO_KEY 64 /* Last read didn't find record */ -#define HA_STATE_KEY_CHANGED 128 -#define HA_STATE_WRITE_AT_END 256 /* set in _ps_find_writepos */ -#define HA_STATE_BUFF_SAVED 512 /* If current keybuff is info->buff */ -#define HA_STATE_ROW_CHANGED 1024 /* To invalide ROW cache */ -#define HA_STATE_EXTEND_BLOCK 2048 - -enum en_fieldtype { - FIELD_LAST=-1,FIELD_NORMAL,FIELD_SKIPP_ENDSPACE,FIELD_SKIPP_PRESPACE, - FIELD_SKIPP_ZERO,FIELD_BLOB,FIELD_CONSTANT,FIELD_INTERVALL,FIELD_ZERO, - FIELD_VARCHAR,FIELD_CHECK -}; - -enum data_file_type { - STATIC_RECORD,DYNAMIC_RECORD,COMPRESSED_RECORD -}; - -/* For number of records */ -#ifdef BIG_TABLES -typedef my_off_t ha_rows; -#else -typedef ulong ha_rows; -#endif - -#define HA_POS_ERROR (~ (ha_rows) 0) -#define HA_OFFSET_ERROR (~ (my_off_t) 0) - -#if SYSTEM_SIZEOF_OFF_T == 4 -#define MAX_FILE_SIZE INT_MAX32 -#else -#define MAX_FILE_SIZE LONGLONG_MAX -#endif - -#endif /* _my_base_h */ diff --git a/include/my_dir.h b/include/my_dir.h deleted file mode 100644 index 1961ca79..00000000 --- a/include/my_dir.h +++ /dev/null @@ -1,100 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#ifndef _my_dir_h -#define _my_dir_h -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef MY_DIR_H -#define MY_DIR_H - -#include - - /* Defines for my_dir and my_stat */ - -#define MY_S_IFMT S_IFMT /* type of file */ -#define MY_S_IFDIR S_IFDIR /* directory */ -#define MY_S_IFCHR S_IFCHR /* character special */ -#define MY_S_IFBLK S_IFBLK /* block special */ -#define MY_S_IFREG S_IFREG /* regular */ -#define MY_S_IFIFO S_IFIFO /* fifo */ -#define MY_S_ISUID S_ISUID /* set user id on execution */ -#define MY_S_ISGID S_ISGID /* set group id on execution */ -#define MY_S_ISVTX S_ISVTX /* save swapped text even after use */ -#define MY_S_IREAD S_IREAD /* read permission, owner */ -#define MY_S_IWRITE S_IWRITE /* write permission, owner */ -#define MY_S_IEXEC S_IEXEC /* execute/search permission, owner */ - -#define MY_S_ISDIR(m) (((m) & MY_S_IFMT) == MY_S_IFDIR) -#define MY_S_ISCHR(m) (((m) & MY_S_IFMT) == MY_S_IFCHR) -#define MY_S_ISBLK(m) (((m) & MY_S_IFMT) == MY_S_IFBLK) -#define MY_S_ISREG(m) (((m) & MY_S_IFMT) == MY_S_IFREG) -#define MY_S_ISFIFO(m) (((m) & MY_S_IFMT) == MY_S_IFIFO) - -#define MY_DONT_SORT 512 /* my_lib; Don't sort files */ -#define MY_WANT_STAT 1024 /* my_lib; stat files */ - - /* typedefs for my_dir & my_stat */ - -#ifdef USE_MY_STAT_STRUCT - -typedef struct my_stat -{ - dev_t st_dev; /* major & minor device numbers */ - ino_t st_ino; /* inode number */ - ushort st_mode; /* file permissons (& suid sgid .. bits) */ - short st_nlink; /* number of links to file */ - ushort st_uid; /* user id */ - ushort st_gid; /* group id */ - dev_t st_rdev; /* more major & minor device numbers (???) */ - off_t st_size; /* size of file */ - time_t st_atime; /* time for last read */ - time_t st_mtime; /* time for last contens modify */ - time_t st_ctime; /* time for last inode or contents modify */ -} MY_STAT; - -#else - -#define MY_STAT struct stat /* Orginal struct have what we need */ - -#endif /* USE_MY_STAT_STRUCT */ - -typedef struct fileinfo /* Struct returned from my_dir & my_stat */ -{ - char *name; - MY_STAT mystat; -} FILEINFO; - -typedef struct st_my_dir /* Struct returned from my_dir */ -{ - struct fileinfo *dir_entry; - uint number_off_files; -} MY_DIR; - -extern MY_DIR *my_dir(const char *path,myf MyFlags); -extern void my_dirend(MY_DIR *buffer); -extern MY_STAT *my_stat(const char *path, MY_STAT *stat_area, myf my_flags); -extern int my_fstat(int filenr, MY_STAT *stat_area, myf MyFlags); - -#endif /* MY_DIR_H */ - -#ifdef __cplusplus -} -#endif -#endif diff --git a/include/my_net.h b/include/my_net.h deleted file mode 100644 index 3c4cb8b1..00000000 --- a/include/my_net.h +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* thread safe version of some common functions */ - -/* for thread safe my_inet_ntoa */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if !defined(MSDOS) && !defined(_WIN32) && !defined(__BEOS__) -#ifdef HAVE_SYS_SOCKET_H -#include -#endif -#ifdef HAVE_NETINET_IN_H -#include -#endif -#ifdef HAVE_ARPA_INET_H -#include -#endif -#endif /* !defined(MSDOS) && !defined(_WIN32) */ - - -/* On SCO you get a link error when refering to h_errno */ -#ifdef SCO -#undef h_errno -#define h_errno errno -#endif - -void my_inet_ntoa(struct in_addr in, char *buf); - -#ifdef __cplusplus -} -#endif diff --git a/include/my_no_pthread.h b/include/my_no_pthread.h deleted file mode 100644 index 328086ec..00000000 --- a/include/my_no_pthread.h +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - This undefs some pthread mutex locks when one isn't using threads - to make thread safe code, that should also work in single thread - environment, easier to use. -*/ - -#if !defined(_my_no_pthread_h) && !defined(THREAD) -#define _my_no_pthread_h - -#define pthread_mutex_init(A,B) -#define pthread_mutex_lock(A) -#define pthread_mutex_unlock(A) -#define pthread_mutex_destroy(A) - -#endif diff --git a/include/my_pthread.h b/include/my_pthread.h deleted file mode 100644 index b20f1172..00000000 --- a/include/my_pthread.h +++ /dev/null @@ -1,592 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* Defines to make different thread packages compatible */ - -#ifndef _my_pthread_h -#define _my_pthread_h - -#include -#ifndef ETIME -#define ETIME ETIMEDOUT /* For FreeBSD */ -#endif - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if defined(_WIN32) - -typedef CRITICAL_SECTION pthread_mutex_t; - -typedef HANDLE pthread_t; -typedef struct thread_attr { - DWORD dwStackSize ; - DWORD dwCreatingFlag ; - int priority ; -} pthread_attr_t ; - -typedef struct { int dummy; } pthread_condattr_t; - -/* Implementation of posix conditions */ - -typedef struct st_pthread_link { - DWORD thread_id; - struct st_pthread_link *next; -} pthread_link; - -typedef struct { - uint32 waiting; - - enum { - SIGNAL = 0, - BROADCAST = 1, - MAX_EVENTS = 2 - } EVENTS; - HANDLE events[MAX_EVENTS]; - CRITICAL_SECTION waiters_count_lock; -} pthread_cond_t; - -#ifndef _TIMESPEC_DEFINED -#if (!defined(_MSC_VER) || _MSC_VER < 1900) -struct timespec { /* For pthread_cond_timedwait() */ - time_t tv_sec; - long tv_nsec; -}; -#endif -#endif - -typedef int pthread_mutexattr_t; -#define pthread_self() GetCurrentThreadId() - -#define pthread_handler_decl(A,B) void * __cdecl A(void *B) -typedef void * (__cdecl *pthread_handler)(void *); - -void win_pthread_init(void); - -int pthread_create(pthread_t *,pthread_attr_t *,pthread_handler,void *); -int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr); -int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex); -int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, - struct timespec *abstime); -int pthread_cond_signal(pthread_cond_t *cond); -int pthread_cond_broadcast(pthread_cond_t *cond); -int pthread_cond_destroy(pthread_cond_t *cond); -int pthread_attr_init(pthread_attr_t *connect_att); -int pthread_attr_setstacksize(pthread_attr_t *connect_att,DWORD stack); -int pthread_attr_setprio(pthread_attr_t *connect_att,int priority); -int pthread_attr_destroy(pthread_attr_t *connect_att); -struct tm *localtime_r(const time_t *timep,struct tm *tmp); - -void pthread_exit(void *a); /* was #define pthread_exit(A) ExitThread(A)*/ - -#ifndef OS2 -#define getpid() GetCurrentThreadId() -#endif - -#define HAVE_LOCALTIME_R 1 -#define _REENTRANT 1 -#define HAVE_PTHREAD_ATTR_SETSTACKSIZE 1 - -#undef SAFE_MUTEX /* This will cause conflicts */ -#define pthread_key(T,V) DWORD V -#define pthread_key_create(A,B) ((*A=TlsAlloc())==0xFFFFFFFF) -#define pthread_getspecific(A) (TlsGetValue(A)) -#define my_pthread_getspecific(T,A) ((T) TlsGetValue(A)) -#define my_pthread_getspecific_ptr(T,V) ((T) TlsGetValue(V)) -#define my_pthread_setspecific_ptr(T,V) (!TlsSetValue((T),(V))) -#define pthread_setspecific(A,B) (!TlsSetValue((A),(B))) - - -#define pthread_equal(A,B) ((A) == (B)) - -#define pthread_mutex_init(A,B) InitializeCriticalSection(A) -#define pthread_mutex_lock(A) (EnterCriticalSection(A),0) -#define pthread_mutex_trylock(A) (WaitForSingleObject((A), 0) == WAIT_TIMEOUT) -#define pthread_mutex_unlock(A) LeaveCriticalSection(A) -#define pthread_mutex_destroy(A) DeleteCriticalSection(A) -#define my_pthread_setprio(A,B) SetThreadPriority(GetCurrentThread(), (B)) -#define pthread_kill(A,B) pthread_dummy(0) - - -/* Dummy defines for easier code */ -#define pthread_attr_setdetachstate(A,B) pthread_dummy(0) -#define my_pthread_attr_setprio(A,B) pthread_attr_setprio(A,B) -#define pthread_attr_setscope(A,B) -#define pthread_detach_this_thread() -#define pthread_condattr_init(A) -#define pthread_condattr_destroy(A) - -/*Irena: compiler does not like this: */ -/*#define my_pthread_getprio(pthread_t thread_id) pthread_dummy(0) */ -#define my_pthread_getprio(thread_id) pthread_dummy(0) - -#elif defined(HAVE_UNIXWARE7_THREADS) - -#include -#include - -#ifndef _REENTRANT -#define _REENTRANT -#endif - -#define HAVE_NONPOSIX_SIGWAIT -#define pthread_t thread_t -#define pthread_cond_t cond_t -#define pthread_mutex_t mutex_t -#define pthread_key_t thread_key_t -typedef int pthread_attr_t; /* Needed by Unixware 7.0.0 */ - -#define pthread_key_create(A,B) thr_keycreate((A),(B)) - -#define pthread_handler_decl(A,B) void *A(void *B) -#define pthread_key(T,V) pthread_key_t V - -void * my_pthread_getspecific_imp(pthread_key_t key); -#define my_pthread_getspecific(A,B) ((A) my_pthread_getspecific_imp(B)) -#define my_pthread_getspecific_ptr(T,V) my_pthread_getspecific(T,V) - -#define pthread_setspecific(A,B) thr_setspecific(A,B) -#define my_pthread_setspecific_ptr(T,V) pthread_setspecific(T,V) - -#define pthread_create(A,B,C,D) thr_create(NULL,65536L,(C),(D),THR_DETACHED,(A)) -#define pthread_cond_init(a,b) cond_init((a),USYNC_THREAD,NULL) -#define pthread_cond_destroy(a) cond_destroy(a) -#define pthread_cond_signal(a) cond_signal(a) -#define pthread_cond_wait(a,b) cond_wait((a),(b)) -#define pthread_cond_timedwait(a,b,c) cond_timedwait((a),(b),(c)) -#define pthread_cond_broadcast(a) cond_broadcast(a) - -#define pthread_mutex_init(a,b) mutex_init((a),USYNC_THREAD,NULL) -#define pthread_mutex_lock(a) mutex_lock(a) -#define pthread_mutex_unlock(a) mutex_unlock(a) -#define pthread_mutex_destroy(a) mutex_destroy(a) - -#define pthread_self() thr_self() -#define pthread_exit(A) thr_exit(A) -#define pthread_equal(A,B) (((A) == (B)) ? 1 : 0) -#define pthread_kill(A,B) thr_kill((A),(B)) -#define HAVE_PTHREAD_KILL - -#define pthread_sigmask(A,B,C) thr_sigsetmask((A),(B),(C)) - -extern int my_sigwait(const sigset_t *set,int *sig); - -#define pthread_detach_this_thread() pthread_dummy(0) - -#define pthread_attr_init(A) pthread_dummy(0) -#define pthread_attr_destroy(A) pthread_dummy(0) -#define pthread_attr_setscope(A,B) pthread_dummy(0) -#define pthread_attr_setdetachstate(A,B) pthread_dummy(0) -#define my_pthread_setprio(A,B) pthread_dummy (0) -#define my_pthread_getprio(A) pthread_dummy (0) -#define my_pthread_attr_setprio(A,B) pthread_dummy(0) - -#else /* Normal threads */ - -#ifdef HAVE_rts_threads -#define sigwait org_sigwait -#include -#undef sigwait -#endif -#undef _REENTRANT /* Fix if _REENTRANT is in pthread.h */ -#include -#ifndef _REENTRANT -#define _REENTRANT -#endif -#ifdef HAVE_THR_SETCONCURRENCY -#include /* Probably solaris */ -#endif -#ifdef HAVE_SCHED_H -#include -#endif -#ifdef HAVE_SYNCH_H -#include -#endif -#if defined(__EMX__) && (!defined(EMX_PTHREAD_REV) || (EMX_PTHREAD_REV < 2)) -#error Requires at least rev 2 of EMX pthreads library. -#endif - -extern int my_pthread_getprio(pthread_t thread_id); - -#define pthread_key(T,V) pthread_key_t V -#define my_pthread_getspecific_ptr(T,V) my_pthread_getspecific(T,(V)) -#define my_pthread_setspecific_ptr(T,V) pthread_setspecific(T,(void*) (V)) -#define pthread_detach_this_thread() -#define pthread_handler_decl(A,B) void *A(void *B) -typedef void *(* pthread_handler)(void *); - -/* Test first for RTS or FSU threads */ - -#if defined(PTHREAD_SCOPE_GLOBAL) && !defined(PTHREAD_SCOPE_SYSTEM) -#define HAVE_rts_threads -extern int my_pthread_create_detached; -#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C)) -#define PTHREAD_CREATE_DETACHED &my_pthread_create_detached -#define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_GLOBAL -#define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_LOCAL -#define USE_ALARM_THREAD -#endif /* defined(PTHREAD_SCOPE_GLOBAL) && !defined(PTHREAD_SCOPE_SYSTEM) */ - -#if defined(HAVE_UNIXWARE7_POSIX) -#undef HAVE_NONPOSIX_SIGWAIT -#define HAVE_NONPOSIX_SIGWAIT /* sigwait takes only 1 argument */ -#endif - -#ifndef HAVE_NONPOSIX_SIGWAIT -#define my_sigwait(A,B) sigwait((A),(B)) -#else -int my_sigwait(const sigset_t *set,int *sig); -#endif - -#ifdef HAVE_NONPOSIX_PTHREAD_MUTEX_INIT -#ifndef SAFE_MUTEX -#define pthread_mutex_init(a,b) my_pthread_mutex_init((a),(b)) -extern int my_pthread_mutex_init(pthread_mutex_t *mp, - const pthread_mutexattr_t *attr); -#endif /* SAFE_MUTEX */ -#define pthread_cond_init(a,b) my_pthread_cond_init((a),(b)) -/* - extern int my_pthread_cond_init(pthread_cond_t *mp, - const pthread_condattr_t *attr); - */ -#endif /* HAVE_NONPOSIX_PTHREAD_MUTEX_INIT */ - -#if defined(HAVE_SIGTHREADMASK) && !defined(HAVE_PTHREAD_SIGMASK) -#define pthread_sigmask(A,B,C) sigthreadmask((A),(B),(C)) -#endif - -#if !defined(HAVE_SIGWAIT) && !defined(HAVE_mit_thread) && !defined(HAVE_rts_threads) && !defined(sigwait) && !defined(alpha_linux_port) && !defined(HAVE_NONPOSIX_SIGWAIT) && !defined(HAVE_DEC_3_2_THREADS) && !defined(_AIX) -int sigwait(sigset_t *setp, int *sigp); /* Use our implemention */ -#endif -#if !defined(HAVE_SIGSET) && !defined(my_sigset) -#define my_sigset(A,B) do { struct sigaction s; sigset_t set; \ - sigemptyset(&set); \ - s.sa_handler = (B); \ - s.sa_mask = set; \ - s.sa_flags = 0; \ - sigaction((A), &s, (struct sigaction *) NULL); \ - } while (0) -#elif !defined(my_sigset) - #define my_sigset(A,B) signal((A),(B)) -#endif - -#ifndef my_pthread_setprio -#if defined(HAVE_PTHREAD_SETPRIO_NP) /* FSU threads */ -#define my_pthread_setprio(A,B) pthread_setprio_np((A),(B)) -#elif defined(HAVE_PTHREAD_SETPRIO) -#define my_pthread_setprio(A,B) pthread_setprio((A),(B)) -#else -extern void my_pthread_setprio(pthread_t thread_id,int prior); -#endif -#endif - -#ifndef my_pthread_attr_setprio -#ifdef HAVE_PTHREAD_ATTR_SETPRIO -#define my_pthread_attr_setprio(A,B) pthread_attr_setprio((A),(B)) -#else -extern void my_pthread_attr_setprio(pthread_attr_t *attr, int priority); -#endif -#endif - -#if !defined(HAVE_PTHREAD_ATTR_SETSCOPE) || defined(HAVE_DEC_3_2_THREADS) -#define pthread_attr_setscope(A,B) -#undef HAVE_GETHOSTBYADDR_R /* No definition */ -#endif - -#if defined(HAVE_BROKEN_PTHREAD_COND_TIMEDWAIT) && !defined(SAFE_MUTEX) -extern int my_pthread_cond_timedwait(pthread_cond_t *cond, - pthread_mutex_t *mutex, - struct timespec *abstime); -#define pthread_cond_timedwait(A,B,C) my_pthread_cond_timedwait((A),(B),(C)) -#endif - -#if !defined( HAVE_NONPOSIX_PTHREAD_GETSPECIFIC) -#define my_pthread_getspecific(A,B) ((A) pthread_getspecific(B)) -#else -#define my_pthread_getspecific(A,B) ((A) my_pthread_getspecific_imp(B)) -void *my_pthread_getspecific_imp(pthread_key_t key); -#endif - -#ifndef HAVE_LOCALTIME_R -struct tm *localtime_r(const time_t *clock, struct tm *res); -#endif - -#ifdef HAVE_PTHREAD_CONDATTR_CREATE -/* DCE threads on HPUX 10.20 */ -#define pthread_condattr_init pthread_condattr_create -#define pthread_condattr_destroy pthread_condattr_delete -#endif - -#ifdef HAVE_CTHREADS_WRAPPER /* For MacOSX */ -#define pthread_cond_destroy(A) pthread_dummy(0) -#define pthread_mutex_destroy(A) pthread_dummy(0) -#define pthread_attr_delete(A) pthread_dummy(0) -#define pthread_condattr_delete(A) pthread_dummy(0) -#define pthread_attr_setstacksize(A,B) pthread_dummy(0) -#define pthread_equal(A,B) ((A) == (B)) -#define pthread_cond_timedwait(a,b,c) pthread_cond_wait((a),(b)) -#define pthread_attr_init(A) pthread_attr_create(A) -#define pthread_attr_destroy(A) pthread_attr_delete(A) -#define pthread_attr_setdetachstate(A,B) pthread_dummy(0) -#define pthread_create(A,B,C,D) pthread_create((A),*(B),(C),(D)) -#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C)) -#define pthread_kill(A,B) pthread_dummy(0) -#undef pthread_detach_this_thread -#define pthread_detach_this_thread() { pthread_t tmp=pthread_self() ; pthread_detach(&tmp); } -#endif - -#ifdef HAVE_DARWIN_THREADS -#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C)) -#define pthread_kill(A,B) pthread_dummy(0) -#define pthread_condattr_init(A) pthread_dummy(0) -#define pthread_condattr_destroy(A) pthread_dummy(0) -#define pthread_signal(A,B) pthread_dummy(0) -#undef pthread_detach_this_thread -#define pthread_detach_this_thread() { pthread_t tmp=pthread_self() ; pthread_detach(tmp); } -#undef sigset -#define sigset(A,B) pthread_signal((A),(void (*)(int)) (B)) -#endif - -#if ((defined(HAVE_PTHREAD_ATTR_CREATE) && !defined(HAVE_SIGWAIT)) || defined(HAVE_DEC_3_2_THREADS)) && !defined(HAVE_CTHREADS_WRAPPER) -/* This is set on AIX_3_2 and Siemens unix (and DEC OSF/1 3.2 too) */ -#define pthread_key_create(A,B) \ - pthread_keycreate(A,(B) ?\ - (pthread_destructor_t) (B) :\ - (pthread_destructor_t) pthread_dummy) -#define pthread_attr_init(A) pthread_attr_create(A) -#define pthread_attr_destroy(A) pthread_attr_delete(A) -#define pthread_attr_setdetachstate(A,B) pthread_dummy(0) -#define pthread_create(A,B,C,D) pthread_create((A),*(B),(C),(D)) -#ifndef pthread_sigmask -#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C)) -#endif -#define pthread_kill(A,B) pthread_dummy(0) -#undef pthread_detach_this_thread -#define pthread_detach_this_thread() { pthread_t tmp=pthread_self() ; pthread_detach(&tmp); } -+#elif !defined(HAVE_PTHREAD_KILL) /* HAVE_PTHREAD_ATTR_CREATE && !HAVE_SIGWAIT */ -#define HAVE_PTHREAD_KILL -#endif - -#endif /* defined(_WIN32) */ - -#if defined(HPUX) && !defined(DONT_REMAP_PTHREAD_FUNCTIONS) -#undef pthread_cond_timedwait -#define pthread_cond_timedwait(a,b,c) my_pthread_cond_timedwait((a),(b),(c)) -int my_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, - struct timespec *abstime); -#endif - -#if defined(HAVE_POSIX1003_4a_MUTEX) && !defined(DONT_REMAP_PTHREAD_FUNCTIONS) -#undef pthread_mutex_trylock -#define pthread_mutex_trylock(a) my_pthread_mutex_trylock((a)) -int my_pthread_mutex_trylock(pthread_mutex_t *mutex); -#endif - - /* safe_mutex adds checking to mutex for easier debugging */ - -typedef struct st_safe_mutex_t -{ - pthread_mutex_t global,mutex; - char *file; - uint line,count; - pthread_t thread; -} safe_mutex_t; - -int safe_mutex_init(safe_mutex_t *mp, const pthread_mutexattr_t *attr); -int safe_mutex_lock(safe_mutex_t *mp,const char *file, uint line); -int safe_mutex_unlock(safe_mutex_t *mp,const char *file, uint line); -int safe_mutex_destroy(safe_mutex_t *mp,const char *file, uint line); -int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp,const char *file, - uint line); -int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp, - struct timespec *abstime, const char *file, uint line); - - /* Wrappers if safe mutex is actually used */ -#ifdef SAFE_MUTEX -#undef pthread_mutex_init -#undef pthread_mutex_lock -#undef pthread_mutex_unlock -#undef pthread_mutex_destroy -#undef pthread_mutex_wait -#undef pthread_mutex_timedwait -#undef pthread_mutex_t -#undef pthread_cond_wait -#undef pthread_cond_timedwait -#undef pthread_mutex_trylock -#define pthread_mutex_init(A,B) safe_mutex_init((A),(B)) -#define pthread_mutex_lock(A) safe_mutex_lock((A),__FILE__,__LINE__) -#define pthread_mutex_unlock(A) safe_mutex_unlock((A),__FILE__,__LINE__) -#define pthread_mutex_destroy(A) safe_mutex_destroy((A),__FILE__,__LINE__) -#define pthread_cond_wait(A,B) safe_cond_wait((A),(B),__FILE__,__LINE__) -#define pthread_cond_timedwait(A,B,C) safe_cond_timedwait((A),(B),(C),__FILE__,__LINE__) -#define pthread_mutex_trylock(A) pthread_mutex_lock(A) -#define pthread_mutex_t safe_mutex_t -#define safe_mutex_assert_owner(mp) DBUG_ASSERT((mp)->count > 0 && pthread_equal(pthread_self(),(mp)->thread)) -#else -#define safe_mutex_assert_owner(mp) -#endif /* SAFE_MUTEX */ - - /* READ-WRITE thread locking */ - -#if defined(USE_MUTEX_INSTEAD_OF_RW_LOCKS) -/* use these defs for simple mutex locking */ -#define rw_lock_t pthread_mutex_t -#define my_rwlock_init(A,B) pthread_mutex_init((A),(B)) -#define rw_rdlock(A) pthread_mutex_lock((A)) -#define rw_wrlock(A) pthread_mutex_lock((A)) -#define rw_tryrdlock(A) pthread_mutex_trylock((A)) -#define rw_trywrlock(A) pthread_mutex_trylock((A)) -#define rw_unlock(A) pthread_mutex_unlock((A)) -#define rwlock_destroy(A) pthread_mutex_destroy((A)) -#elif defined(HAVE_PTHREAD_RWLOCK_RDLOCK) -#define rw_lock_t pthread_rwlock_t -#define my_rwlock_init(A,B) pthread_rwlock_init((A),(B)) -#define rw_rdlock(A) pthread_rwlock_rdlock(A) -#define rw_wrlock(A) pthread_rwlock_wrlock(A) -#define rw_tryrdlock(A) pthread_rwlock_tryrdlock((A)) -#define rw_trywrlock(A) pthread_rwlock_trywrlock((A)) -#define rw_unlock(A) pthread_rwlock_unlock(A) -#define rwlock_destroy(A) pthread_rwlock_destroy(A) -#elif defined(HAVE_RWLOCK_INIT) -#ifdef HAVE_RWLOCK_T /* For example Solaris 2.6-> */ -#define rw_lock_t rwlock_t -#endif -#define my_rwlock_init(A,B) rwlock_init((A),USYNC_THREAD,0) -#else -/* Use our own version of read/write locks */ -typedef struct _my_rw_lock_t { - pthread_mutex_t lock; /* lock for structure */ - pthread_cond_t readers; /* waiting readers */ - pthread_cond_t writers; /* waiting writers */ - int state; /* -1:writer,0:free,>0:readers */ - int waiters; /* number of waiting writers */ -} my_rw_lock_t; - -#define rw_lock_t my_rw_lock_t -#define rw_rdlock(A) my_rw_rdlock((A)) -#define rw_wrlock(A) my_rw_wrlock((A)) -#define rw_tryrdlock(A) my_rw_tryrdlock((A)) -#define rw_trywrlock(A) my_rw_trywrlock((A)) -#define rw_unlock(A) my_rw_unlock((A)) -#define rwlock_destroy(A) my_rwlock_destroy((A)) - -extern int my_rwlock_init(my_rw_lock_t *, void *); -extern int my_rwlock_destroy(my_rw_lock_t *); -extern int my_rw_rdlock(my_rw_lock_t *); -extern int my_rw_wrlock(my_rw_lock_t *); -extern int my_rw_unlock(my_rw_lock_t *); -extern int my_rw_tryrdlock(my_rw_lock_t *); -extern int my_rw_trywrlock(my_rw_lock_t *); -#endif /* USE_MUTEX_INSTEAD_OF_RW_LOCKS */ - -#define GETHOSTBYADDR_BUFF_SIZE 2048 - -#ifndef HAVE_THR_SETCONCURRENCY -#define thr_setconcurrency(A) pthread_dummy(0) -#endif -#if !defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE) && ! defined(pthread_attr_setstacksize) -#define pthread_attr_setstacksize(A,B) pthread_dummy(0) -#endif - -/* Define mutex types */ -#define MY_MUTEX_INIT_SLOW NULL -#define MY_MUTEX_INIT_FAST NULL -#define MY_MUTEX_INIT_ERRCHK NULL -#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP -extern pthread_mutexattr_t my_fast_mutexattr; -#undef MY_MUTEX_INIT_FAST -#define MY_MUTEX_INIT_FAST &my_fast_mutexattr -#endif -#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP -extern pthread_mutexattr_t my_errchk_mutexattr; -#undef MY_INIT_MUTEX_ERRCHK -#define MY_INIT_MUTEX_ERRCHK &my_errchk_mutexattr -#endif - -extern my_bool ma_thread_global_init(void); -extern void ma_thread_global_end(void); -extern my_bool ma_thread_init(void); -extern void ma_thread_end(void); -extern const char *ma_thread_name(void); -extern long my_thread_id(void); -extern int pthread_no_free(void *); -extern int pthread_dummy(int); - -/* All thread specific variables are in the following struct */ - -#define THREAD_NAME_SIZE 10 -#if defined(__ia64__) -#define DEFAULT_THREAD_STACK (128*1024) -#else -#define DEFAULT_THREAD_STACK (64*1024) -#endif - -struct st_ma_thread_var -{ - int thr_errno; - pthread_cond_t suspend; - pthread_mutex_t mutex; - pthread_mutex_t * volatile current_mutex; - pthread_cond_t * volatile current_cond; - pthread_t pthread_self; - long id; - int cmp_length; - int volatile abort; -#ifndef DBUG_OFF - gptr dbug; - char name[THREAD_NAME_SIZE+1]; -#endif - my_bool initialized; -}; - -extern struct st_ma_thread_var *_ma_thread_var(void) __attribute__ ((const)); -extern void **ma_thread_var_dbug(); -#define my_thread_var (_ma_thread_var()) -#define my_errno my_thread_var->thr_errno - - /* statistics_xxx functions are for not essential statistic */ - -#ifndef thread_safe_increment -#ifdef HAVE_ATOMIC_ADD -#define thread_safe_increment(V,L) atomic_add(1,(atomic_t*) &V); -#define thread_safe_add(V,C,L) atomic_add((C),(atomic_t*) &V); -#define thread_safe_sub(V,C,L) atomic_sub((C),(atomic_t*) &V); -#define statistic_increment(V,L) thread_safe_increment((V),(L)) -#define statistic_add(V,C,L) thread_safe_add((V),(C),(L)) -#else -#define thread_safe_increment(V,L) \ - pthread_mutex_lock((L)); (V)++; pthread_mutex_unlock((L)); -#define thread_safe_add(V,C,L) \ - pthread_mutex_lock((L)); (V)+=(C); pthread_mutex_unlock((L)); -#define thread_safe_sub(V,C,L) \ - pthread_mutex_lock((L)); (V)-=(C); pthread_mutex_unlock((L)); -#ifdef SAFE_STATISTICS -#define statistic_increment(V,L) thread_safe_increment((V),(L)) -#define statistic_add(V,C,L) thread_safe_add((V),(C),(L)) -#else -#define statistic_increment(V,L) (V)++ -#define statistic_add(V,C,L) (V)+=(C) -#endif /* SAFE_STATISTICS */ -#endif /* HAVE_ATOMIC_ADD */ -#endif /* thread_safe_increment */ - -#ifdef __cplusplus -} -#endif - -#endif /* _my_ptread_h */ diff --git a/include/mysql.h b/include/mysql.h index b3dc4406..de1a19e0 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -53,9 +53,9 @@ typedef int my_socket; #endif #endif #endif -#include "mysql_com.h" -#include "mysql_version.h" -#include "my_list.h" +#include "mariadb_com.h" +#include "mariadb_version.h" +#include "ma_list.h" #include "mariadb_ctype.h" #ifndef ST_MA_USED_MEM_DEFINED @@ -225,6 +225,17 @@ extern unsigned int mariadb_deinitialize_ssl; 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_COM_MULTI, }; @@ -400,7 +411,7 @@ typedef struct character_set /* Local infile support functions */ #define LOCAL_INFILE_ERROR_LEN 512 -#include "my_stmt.h" +#include "mariadb_stmt.h" void STDCALL mysql_set_local_infile_handler(MYSQL *mysql, int (*local_infile_init)(void **, const char *, void *), @@ -501,9 +512,6 @@ unsigned long STDCALL mysql_escape_string(char *to,const char *from, unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql, char *to,const char *from, unsigned long length); -void STDCALL mysql_debug(const char *debug); -#define mysql_debug_init(A) mysql_debug((A)); -void STDCALL mysql_debug_end(void); unsigned int STDCALL mysql_thread_safe(void); unsigned int STDCALL mysql_warning_count(MYSQL *mysql); const char * STDCALL mysql_sqlstate(MYSQL *mysql); @@ -531,6 +539,7 @@ unsigned int STDCALL mysql_get_timeout_value_ms(const MYSQL *mysql); my_bool STDCALL mysql_reconnect(MYSQL *mysql); /* Async API */ +#ifdef HAVE_NONBLOCK 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); @@ -641,7 +650,7 @@ int STDCALL mysql_stmt_send_long_data_start(my_bool *ret, MYSQL_STMT *stmt, size_t len); int STDCALL mysql_stmt_send_long_data_cont(my_bool *ret, MYSQL_STMT *stmt, int status); - +#endif /* API function calls (used by dynmic plugins) */ struct st_mariadb_api { @@ -706,8 +715,6 @@ struct st_mariadb_api { 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); - void (STDCALL *mysql_debug)(const char *debug); - void (STDCALL *mysql_debug_end)(void); unsigned int (STDCALL *mysql_thread_safe)(void); unsigned int (STDCALL *mysql_warning_count)(MYSQL *mysql); const char * (STDCALL *mysql_sqlstate)(MYSQL *mysql); diff --git a/include/mysql_io.h b/include/mysql_io.h deleted file mode 100644 index 6cc3ad63..00000000 --- a/include/mysql_io.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 6 | - +----------------------------------------------------------------------+ - | Copyright (c) 2006-2007 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: | - +----------------------------------------------------------------------+ -*/ - -#ifndef MYSQL_IO_H -#define MYSQL_IO_H - -#ifdef _WIN32 -void mysql_io_win_init(void); -#endif - -MYSQL_STREAM * mysql_io_open(const char *name, size_t namelen); -size_t mysql_io_read(MYSQL_STREAM *stream, char *buf, size_t size); -size_t mysql_io_write(MYSQL_STREAM *stream, const char *buf, size_t count); -void mysql_io_close(MYSQL_STREAM *stream); - -#endif /* MYSQLND_IO_H */ diff --git a/include/mysql_mm.h b/include/mysql_mm.h deleted file mode 100644 index 78d1f874..00000000 --- a/include/mysql_mm.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 6 | - +----------------------------------------------------------------------+ - | Copyright (c) 2006-2007 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Georg Richter | - | Andrey Hristov | - | Ulf Wendel | - +----------------------------------------------------------------------+ -*/ - -#ifndef MYSQLND_MM_H -#define MYSQLND_MM_H -#include - - -char * mnd_strndup(const char *s, size_t length); -char * mnd_strdup(const char *src); - - -#define mnd_malloc(size) malloc((size)) -#define mnd_calloc(nmemb, size) calloc((nmemb), (size)) -#define mnd_realloc(ptr, new_size) realloc((ptr), (new_size)) -#define mnd_free(ptr) free((ptr)) - -#endif /* MYSQLND_MM_H */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/include/mysql_priv.h b/include/mysql_priv.h deleted file mode 100644 index b2a32364..00000000 --- a/include/mysql_priv.h +++ /dev/null @@ -1,4 +0,0 @@ -/* internal functions */ -MYSQL_DATA *read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, uint fields); -void free_rows(MYSQL_DATA *cur); -MYSQL_FIELD * unpack_fields(MYSQL_DATA *data,MA_MEM_ROOT *alloc,uint fields, my_bool default_value, my_bool long_flag_protocol); diff --git a/include/mysql_wireprotocol.h b/include/mysql_wireprotocol.h deleted file mode 100644 index 3417d454..00000000 --- a/include/mysql_wireprotocol.h +++ /dev/null @@ -1,295 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 6 | - +----------------------------------------------------------------------+ - | Copyright (c) 2006-2007 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Georg Richter | - | Andrey Hristov | - | Ulf Wendel | - +----------------------------------------------------------------------+ -*/ - -/* $Id: mysql_wireprotocol.h,v 1.4.2.2 2007/10/05 21:23:56 andrey Exp $ */ - -#ifndef MYSQL_WIREPROTOCOL_H -#define MYSQL_WIREPROTOCOL_H - -#define MYSQL_HEADER_SIZE 4 - -#define MYSQL_NULL_LENGTH (unsigned long) ~0 - -typedef unsigned char mysql_1b; -typedef unsigned short mysql_2b; -typedef unsigned int mysql_4b; - -/* Used in mysql_debug.c */ -extern char * mysql_read_header_name; -extern char * mysql_read_body_name; - - -/* Packet handling */ -#define PACKET_INIT(packet, enum_type, c_type) \ - { \ - packet = (c_type) my_mcalloc( packet_methods[enum_type].struct_size, MYF(MY_WME | MY_ZEROFILL)); \ - ((c_type) (packet))->header.m = &packet_methods[enum_type]; \ - } -#define PACKET_WRITE(packet, conn) ((packet)->header.m->write_to_net((packet), (conn))) -#define PACKET_READ(packet, conn) ((packet)->header.m->read_from_net((packet), (conn))) -#define PACKET_FREE(packet) ((packet)->header.m->free_mem((packet), FALSE)) - -#define PACKET_INIT_ALLOCA(packet, enum_type) \ - { \ - memset(&(packet), 0, packet_methods[enum_type].struct_size); \ - (packet).header.m = &packet_methods[enum_type]; \ - } -#define PACKET_WRITE_ALLOCA(packet, conn) PACKET_WRITE(&(packet), (conn)) -#define PACKET_READ_ALLOCA(packet, conn) PACKET_READ(&(packet), (conn)) -#define PACKET_FREE_ALLOCA(packet) (packet.header.m->free_mem(&(packet), TRUE)) - -/* Enums */ -enum php_mysql_packet_type -{ - PROT_GREET_PACKET= 0, - PROT_AUTH_PACKET, - PROT_OK_PACKET, - PROT_EOF_PACKET, - PROT_CMD_PACKET, - PROT_RSET_HEADER_PACKET, - PROT_RSET_FLD_PACKET, - PROT_ROW_PACKET, - PROT_STATS_PACKET, - PROT_PREPARE_RESP_PACKET, - PROT_CHG_USER_PACKET, - PROT_LAST, /* should always be last */ -}; - - -extern const char * const mysql_command_to_text[MYSQL_COM_END]; - -/* Low-level extraction functionality */ -typedef struct st_mysql_packet_methods { - size_t struct_size; - my_bool (*read_from_net)(void *packet, MYSQL *conn); - size_t (*write_to_net)(void *packet, MYSQL *conn); - void (*free_mem)(void *packet, my_bool alloca); -} mysql_packet_methods; - -extern mysql_packet_methods packet_methods[]; - - -typedef struct st_mysql_packet_header { - size_t size; - uchar packet_no; - mysql_packet_methods *m; -} mysql_packet_header; - -/* Server greets the client */ -typedef struct st_php_mysql_packet_greet { - mysql_packet_header header; - mysql_1b protocol_version; - char *server_version; - mysql_4b thread_id; - uchar scramble_buf[SCRAMBLE_LENGTH]; - /* 1 byte pad */ - mysql_2b server_capabilities; - mysql_1b charset_no; - mysql_2b server_status; - /* 13 byte pad*/ - my_bool pre41; - /* If error packet, we use these */ - char error[MYSQL_ERRMSG_SIZE+1]; - char sqlstate[SQLSTATE_LENGTH + 1]; - unsigned int error_no; -} php_mysql_packet_greet; - - -/* Client authenticates */ -typedef struct st_php_mysql_packet_auth { - mysql_packet_header header; - mysql_4b client_flags; - uint32 max_packet_size; - mysql_1b charset_no; - /* 23 byte pad */ - const char *user; - /* 8 byte scramble */ - const char *db; - /* 12 byte scramble */ - - /* Here the packet ends. This is user supplied data */ - const char *password; - /* +1 for \0 because of scramble() */ - unsigned char *server_scramble_buf; - size_t db_len; -} php_mysql_packet_auth; - -/* OK packet */ -typedef struct st_php_mysql_packet_ok { - mysql_packet_header header; - mysql_1b field_count; /* always 0x0 */ - my_ulonglong affected_rows; - my_ulonglong last_insert_id; - mysql_2b server_status; - mysql_2b warning_count; - char *message; - size_t message_len; - /* If error packet, we use these */ - char error[MYSQL_ERRMSG_SIZE+1]; - char sqlstate[SQLSTATE_LENGTH + 1]; - unsigned int error_no; -} php_mysql_packet_ok; - - -/* Command packet */ -typedef struct st_php_mysql_packet_command { - mysql_packet_header header; - enum enum_server_command command; - const char *argument; - size_t arg_len; -} php_mysql_packet_command; - - -/* EOF packet */ -typedef struct st_php_mysql_packet_eof { - mysql_packet_header header; - mysql_1b field_count; /* 0xFE */ - mysql_2b warning_count; - mysql_2b server_status; - /* If error packet, we use these */ - char error[MYSQL_ERRMSG_SIZE+1]; - char sqlstate[SQLSTATE_LENGTH + 1]; - unsigned int error_no; -} php_mysql_packet_eof; -/* EOF packet */ - - -/* Result Set header*/ -typedef struct st_php_mysql_packet_rset_header { - mysql_packet_header header; - /* - 0x00 => ok - ~0 => LOAD DATA LOCAL - error_no != 0 => error - others => result set -> Read res_field packets up to field_count - */ - unsigned long field_count; - /* - These are filled if no SELECT query. For SELECT warning_count - and server status are in the last row packet, the EOF packet. - */ - mysql_2b warning_count; - mysql_2b server_status; - my_ulonglong affected_rows; - my_ulonglong last_insert_id; - /* This is for both LOAD DATA or info, when no result set */ - char *info_or_local_file; - size_t info_or_local_file_len; - /* If error packet, we use these */ - mysql_error_info error_info; -} php_mysql_packet_rset_header; - - -/* Result set field packet */ -typedef struct st_php_mysql_packet_res_field { - mysql_packet_header header; - MYSQL_FIELD *metadata; - /* For table definitions, empty for result sets */ - my_bool skip_parsing; - my_bool stupid_list_fields_eof; -} php_mysql_packet_res_field; - - -/* Row packet */ -struct st_php_mysql_packet_row { - mysql_packet_header header; - uchar **fields; /* ??? */ - mysql_4b field_count; - my_bool eof; - /* - These are, of course, only for SELECT in the EOF packet, - which is detected by this packet - */ - mysql_2b warning_count; - mysql_2b server_status; - - uchar *row_buffer; - - my_bool skip_extraction; - my_bool binary_protocol; - MYSQL_FIELD *fields_metadata; - /* We need this to alloc bigger bufs in non-PS mode */ - unsigned int bit_fields_count; - size_t bit_fields_total_len; /* trailing \0 not counted */ - - /* If error packet, we use these */ - mysql_error_info error_info; -}; -typedef struct st_php_mysql_packet_row php_mysql_packet_row; - -/* Statistics packet */ -typedef struct st_php_mysql_packet_stats { - mysql_packet_header header; - char *message; - /* message_len is not part of the packet*/ - size_t message_len; -} php_mysql_packet_stats; - - -/* COM_PREPARE response packet */ -typedef struct st_php_mysql_packet_prepare_response { - mysql_packet_header header; - /* also known as field_count 0x00=OK , 0xFF=error */ - unsigned char error_code; - unsigned long stmt_id; - unsigned int field_count; - unsigned int param_count; - unsigned int warning_count; - - /* present in case of error */ - mysql_error_info error_info; -} php_mysql_packet_prepare_response; - - -/* Statistics packet */ -typedef struct st_php_mysql_packet_chg_user_resp { - mysql_packet_header header; - mysql_4b field_count; - - /* message_len is not part of the packet*/ - mysql_2b server_capabilities; - /* If error packet, we use these */ - mysql_error_info error_info; -} php_mysql_packet_chg_user_resp; - - -size_t mysql_stream_write(MYSQL *conn, const char * buf, size_t count); -size_t mysql_stream_write_w_header(MYSQL *conn, const char * buf, size_t count); - -#ifdef MYSQL_DO_WIRE_CHECK_BEFORE_COMMAND -size_t php_mysql_consume_uneaten_data(const MYSQL *conn, enum php_mysql_server_command cmd); -#endif - - -unsigned long php_mysql_net_field_length(uchar **packet); -uchar * php_mysql_net_store_length(uchar *packet, my_ulonglong length); - -extern char * const mysql_empty_string; - -#endif /* MYSQL_WIREPROTOCOL_H */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/include/mysys_err.h b/include/mysys_err.h deleted file mode 100644 index ede23088..00000000 --- a/include/mysys_err.h +++ /dev/null @@ -1,69 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#ifndef _mysys_err_h -#define _mysys_err_h -#ifdef __cplusplus -extern "C" { -#endif - -#define GLOB 0 /* Error maps */ -#define GLOBERRS EE_LASTERROR - EE_FIRSTERROR + 1 /* Max number of error messages in map's */ -#define EE(X) ma_globerrs[ (X) - EE_FIRSTERROR ] /* Defines to add error to right map */ - -extern const char * NEAR ma_globerrs[]; /* ma_error_messages is here */ - -/* Error message numbers in global map - -*/ -#define EE_FIRSTERROR 1 -#define EE_CANTCREATEFILE 1 -#define EE_READ 2 -#define EE_WRITE 3 -#define EE_BADCLOSE 4 -#define EE_OUTOFMEMORY 5 -#define EE_DELETE 6 -#define EE_LINK 7 -#define EE_EOFERR 9 -#define EE_CANTLOCK 10 -#define EE_CANTUNLOCK 11 -#define EE_DIR 12 -#define EE_STAT 13 -#define EE_CANT_CHSIZE 14 -#define EE_CANT_OPEN_STREAM 15 -#define EE_GETWD 16 -#define EE_SETWD 17 -#define EE_LINK_WARNING 18 -#define EE_OPEN_WARNING 19 -#define EE_DISK_FULL 20 -#define EE_CANT_MKDIR 21 -#define EE_UNKNOWN_CHARSET 22 -#define EE_OUT_OF_FILERESOURCES 23 -#define EE_CANT_READLINK 24 -#define EE_CANT_SYMLINK 25 -#define EE_REALPATH 26 -#define EE_SYNC 27 -#define EE_UNKNOWN_COLLATION 28 -#define EE_FILENOTFOUND 29 -#define EE_FILE_NOT_CLOSED 30 -#define EE_CANT_CHMOD 31 -#define EE_LASTERROR 31 - -#ifdef __cplusplus -} -#endif -#endif diff --git a/include/thr_alarm.h b/include/thr_alarm.h deleted file mode 100644 index c14deb0c..00000000 --- a/include/thr_alarm.h +++ /dev/null @@ -1,112 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* Prototypes when using thr_alarm library functions */ - -#ifndef _thr_alarm_h -#define _thr_alarm_h -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef USE_ALARM_THREAD -#define USE_ONE_SIGNAL_HAND /* One must call process_alarm */ -#endif -#ifdef HAVE_LINUXTHREADS -#define THR_CLIENT_ALARM SIGALRM -#else -#define THR_CLIENT_ALARM SIGUSR1 -#endif -#ifdef HAVE_rts_threads -#undef USE_ONE_SIGNAL_HAND -#define USE_ALARM_THREAD -#define THR_SERVER_ALARM SIGUSR1 -#else -#define THR_SERVER_ALARM SIGALRM -#endif - -#if defined(DONT_USE_THR_ALARM) - -#define USE_ALARM_THREAD -#undef USE_ONE_SIGNAL_HAND - -typedef struct st_thr_alarm_entry -{ - uint crono; -} thr_alarm_entry; - -#define thr_alarm_init(A) (A)->crono=0 -#define thr_alarm_in_use(A) (A)->crono -#define init_thr_alarm(A) -#define thr_alarm_kill(A) -#define end_thr_alarm() -#define thr_alarm(A,B) (((A)->crono=1)-1) -#define thr_got_alarm(A) (A)->crono -#define thr_end_alarm(A) - -#else -#if defined(_WIN32) -typedef struct st_thr_alarm_entry -{ - rf_SetTimer crono; -} thr_alarm_entry; - -#elif defined(__EMX__) || defined(OS2) - -typedef struct st_thr_alarm_entry -{ - uint crono; - uint event; -} thr_alarm_entry; - -#else /* System with posix threads */ - -typedef int thr_alarm_entry; - -#define thr_got_alarm(thr_alarm) (**(thr_alarm)) - -#endif /* _WIN32 */ - -typedef thr_alarm_entry* thr_alarm_t; - -typedef struct st_alarm { - ulong expire_time; - thr_alarm_entry alarmed; /* set when alarm is due */ - pthread_t thread; - my_bool malloced; -} ALARM; - -#define thr_alarm_init(A) (*(A))=0 -#define thr_alarm_in_use(A) (*(A)!= 0) -void init_thr_alarm(uint max_alarm); -bool thr_alarm(thr_alarm_t *alarmed, uint sec, ALARM *buff); -void thr_alarm_kill(pthread_t thread_id); -void thr_end_alarm(thr_alarm_t *alarmed); -void end_thr_alarm(void); -sig_handler process_alarm(int); -#ifndef thr_got_alarm -bool thr_got_alarm(thr_alarm_t *alrm); -#endif - - -#endif /* DONT_USE_THR_ALARM */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* _thr_alarm_h */ - diff --git a/libmariadb/CMakeLists.txt b/libmariadb/CMakeLists.txt index 4c3caacd..09e5e28e 100644 --- a/libmariadb/CMakeLists.txt +++ b/libmariadb/CMakeLists.txt @@ -9,31 +9,10 @@ ADD_DEFINITIONS(-D THREAD) INCLUDE(${CMAKE_SOURCE_DIR}/cmake/sign.cmake) -SET(EXPORT_SYMBOLS - mariadb_load_defaults - ma_pvio_register_callback +SET(MARIADB_LIB_SYMBOLS mariadb_connection mariadb_convert_string - 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 + ma_pvio_register_callback mariadb_get_charset_by_name mariadb_stmt_execute_direct mariadb_get_charset_by_nr @@ -41,25 +20,14 @@ SET(EXPORT_SYMBOLS mariadb_get_infov mysql_affected_rows mysql_autocommit - mysql_autocommit_cont - mysql_autocommit_start mysql_change_user - mysql_change_user_cont - mysql_change_user_start mysql_character_set_name mysql_client_find_plugin mysql_client_register_plugin mysql_close - mysql_close_cont - mysql_close_start mysql_commit - mysql_commit_cont - mysql_commit_start mysql_data_seek - mysql_debug mysql_dump_debug_info - mysql_dump_debug_info_cont - mysql_dump_debug_info_start mysql_eof mysql_errno mysql_error @@ -69,14 +37,10 @@ SET(EXPORT_SYMBOLS mysql_fetch_fields mysql_fetch_lengths mysql_fetch_row - mysql_fetch_row_cont - mysql_fetch_row_start mysql_field_count mysql_field_seek mysql_field_tell mysql_free_result - mysql_free_result_cont - mysql_free_result_start mysql_get_character_set_info mysql_get_charset_by_name mysql_get_charset_by_nr @@ -98,131 +62,73 @@ SET(EXPORT_SYMBOLS mysql_init mysql_insert_id mysql_kill - mysql_kill_cont - mysql_kill_start mysql_list_dbs - mysql_list_dbs_cont - mysql_list_dbs_start mysql_list_fields - mysql_list_fields_cont - mysql_list_fields_start mysql_list_processes - mysql_list_processes_cont - mysql_list_processes_start mysql_list_tables - mysql_list_tables_cont - mysql_list_tables_start mysql_load_plugin mysql_load_plugin_v mysql_more_results mysql_next_result - mysql_next_result_cont - mysql_next_result_start mysql_num_fields mysql_num_rows mysql_options mysql_options4 mysql_optionsv mysql_ping - mysql_ping_cont - mysql_ping_start mysql_ps_fetch_functions mysql_query - mysql_query_cont - mysql_query_start mysql_reconnect mysql_read_query_result - mysql_read_query_result_cont - mysql_read_query_result_start mysql_real_connect - mysql_real_connect_cont - mysql_real_connect_start mysql_real_escape_string mysql_real_query - mysql_real_query_cont - mysql_real_query_start mysql_refresh - mysql_refresh_cont - mysql_refresh_start mysql_rollback - mysql_rollback_cont - mysql_rollback_start mysql_row_seek mysql_row_tell mysql_select_db - mysql_select_db_cont - mysql_select_db_start mysql_send_query - mysql_send_query_cont - mysql_send_query_start mysql_server_end mysql_server_init mysql_set_character_set - mysql_set_character_set_cont - mysql_set_character_set_start mysql_set_local_infile_default mysql_set_local_infile_handler mysql_set_server_option - mysql_set_server_option_cont - mysql_set_server_option_start mysql_shutdown - mysql_shutdown_cont - mysql_shutdown_start mysql_sqlstate mysql_ssl_set mysql_stat - mysql_stat_cont - mysql_stat_start 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_close_cont - mysql_stmt_close_start mysql_stmt_data_seek mysql_stmt_errno mysql_stmt_error mysql_stmt_execute - mysql_stmt_execute_cont - mysql_stmt_execute_start mysql_stmt_fetch mysql_stmt_fetch_column - mysql_stmt_fetch_cont - mysql_stmt_fetch_start mysql_stmt_field_count mysql_stmt_free_result - mysql_stmt_free_result_cont - mysql_stmt_free_result_start mysql_stmt_init mysql_stmt_insert_id mysql_stmt_more_results mysql_stmt_next_result - mysql_stmt_next_result_cont - mysql_stmt_next_result_start mysql_stmt_num_rows mysql_stmt_param_count mysql_stmt_param_metadata mysql_stmt_prepare - mysql_stmt_prepare_cont - mysql_stmt_prepare_start mysql_stmt_reset - mysql_stmt_reset_cont - mysql_stmt_reset_start mysql_stmt_result_metadata mysql_stmt_row_seek mysql_stmt_row_tell mysql_stmt_send_long_data - mysql_stmt_send_long_data_cont - mysql_stmt_send_long_data_start mysql_stmt_sqlstate mysql_stmt_store_result - mysql_stmt_store_result_cont - mysql_stmt_store_result_start mysql_store_result - mysql_store_result_cont - mysql_store_result_start mysql_thread_end mysql_thread_id mysql_thread_init @@ -230,101 +136,136 @@ SET(EXPORT_SYMBOLS mysql_use_result mysql_warning_count) IF(WITH_SSL) - SET(EXPORTS ${EXPORTS} mariadb_deinitialize_ssl) + SET(MARIADB_LIB_SYMBOLS ${MARIADB_LIB_SYMBOLS} mariadb_deinitialize_ssl) ENDIF() # 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) +IF(WITH_NONBLOCK) + IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_BUILD_TYPE MATCHES "Release") + SET_SOURCE_FILES_PROPERTIES(my_context.c PROPERTIES COMPILE_FLAGS -g) + ENDIF() ENDIF() -IF(WIN32) - SET(EXPORT_CONTENT "EXPORTS\n") - FOREACH(SYMBOL ${EXPORT_SYMBOLS}) - SET(EXPORT_CONTENT "${EXPORT_CONTENT} ${SYMBOL}\n") - ENDFOREACH() - SET(EXPORT_FILE "${CMAKE_BINARY_DIR}/libmariadb/exports.def") - SET(EXPORT_LINK ${EXPORT_FILE}) -ELSE() - SET(EXPORT_CONTENT "{\nglobal:\n") - FOREACH(SYMBOL ${EXPORT_SYMBOLS}) - SET(EXPORT_CONTENT "${EXPORT_CONTENT} ${SYMBOL}\\;\n") - ENDFOREACH() - SET(EXPORT_FILE "${CMAKE_BINARY_DIR}/libmariadb/exports.txt") - SET(EXPORT_CONTENT "${EXPORT_CONTENT}local:\n *\\;\n}\\;") -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_get_timeout_value + mysql_get_timeout_value_ms + mysql_kill_cont + mysql_kill_start + mysql_next_result_cont + mysql_next_result_start + mysql_ping_cont + mysql_ping_start + 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 +) -FILE(WRITE ${EXPORT_FILE} ${EXPORT_CONTENT}) SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} -array.c -ma_dyncol.c -bchange.c -bmove.c -bmove_upp.c -my_charset.c -hash.c -net.c -charset.c +ma_array.c +ma_charset.c +ma_hash.c +ma_net.c +mariadb_charset.c ma_time.c -default.c -errmsg.c -errors.c -getopt1.c -getopt.c -int2str.c -is_prefix.c -libmariadb.c -list.c -longlong2str.c +ma_default.c +ma_errmsg.c +mariadb_lib.c +ma_list.c ma_pvio.c ma_ssl.c -mf_dirname.c -mf_fn_ext.c -mf_format.c -mf_loadpath.c -mf_pack.c -mf_path.c -mf_unixpath.c -mf_wcomp.c -my_alloc.c -my_compress.c -my_context.c -my_div.c -my_fopen.c -my_fstream.c -my_getwd.c -my_init.c -my_lib.c -my_messnc.c -my_net.c -my_once.c -my_port.c -my_seek.c -my_static.c -my_symlink.c -my_thr_init.c -my_write.c -mysql_async.c -password.c -str2int.c -string.c -strtoll.c -strtoull.c -typelib.c -sha1.c -my_stmt.c -my_loaddata.c -my_stmt_codec.c -${CMAKE_BINARY_DIR}/libmariadb/client_plugin.c +ma_alloc.c +ma_compress.c +ma_init.c +ma_password.c +ma_string.c +ma_ll2str.c +ma_sha1.c +mariadb_stmt.c +ma_loaddata.c +ma_stmt_codec.c +${CMAKE_BINARY_DIR}/libmariadb/ma_client_plugin.c ma_io.c ${SSL_SOURCES} ) -IF(WITH_DBUG) - SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} dbug.c) -ENDIF() - IF(WIN32) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/win-iconv) @@ -357,6 +298,23 @@ SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} ${ZLIB_SOURCES}) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/zlib) ENDIF() +IF(WITH_DYNCOL) + SET(MARIADB_LIB_SYMBOLS ${MARIADB_LIB_SYMBOLS} ${MARIADB_DYNCOL_SYMBOLS}) + SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} mariadb_dyncol.c) +ENDIF() + +IF(WITH_NONBLOCK) + SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} mariadb_async.c ma_context.c) + SET(MARIADB_LIB_SYMBOLS ${MARIADB_LIB_SYMBOLS} ${MARIADB_NONBLOCK_SYMBOLS}) + ADD_DEFINITIONS(-DHAVE_NONBLOCK) +ENDIF() + +INCLUDE(${CMAKE_SOURCE_DIR}/cmake/export.cmake) +CREATE_EXPORT_FILE(mariadbclient + ${CMAKE_CURRENT_BINARY_DIR} + "${MARIADB_LIB_SYMBOLS}") + + # CREATE OBJECT LIBRARY ADD_LIBRARY(mariadb_obj OBJECT ${LIBMARIADB_SOURCES}) IF(UNIX) @@ -383,9 +341,9 @@ IF(WIN32) "FILE_DESCRIPTION:Static lib for client/server communication") ENDIF() -ADD_LIBRARY(mariadbclient STATIC ${ariadbclient_RC} $ ${EMPTY_FILE} ${EXPORT_LINK}) +ADD_LIBRARY(mariadbclient STATIC ${mariadbclient_RC} $ ${EMPTY_FILE} mariadbclient.def) TARGET_LINK_LIBRARIES(mariadbclient ${SYSTEM_LIBS}) -ADD_LIBRARY(libmariadb SHARED ${libmariadb_RC} $ ${EMPTY_FILE} ${EXPORT_LINK}) +ADD_LIBRARY(libmariadb SHARED ${libmariadb_RC} $ ${EMPTY_FILE} mariadbclient.def) TARGET_LINK_LIBRARIES(libmariadb ${SYSTEM_LIBS}) IF(UNIX) SET_TARGET_PROPERTIES(libmariadb PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}") @@ -394,9 +352,9 @@ SIGN_TARGET(libmariadb) IF(CMAKE_SYSTEM_NAME MATCHES "Linux") TARGET_LINK_LIBRARIES (libmariadb "-Wl,--no-undefined") - TARGET_LINK_LIBRARIES (libmariadb "-Wl,--version-script=${EXPORT_FILE}") + TARGET_LINK_LIBRARIES (libmariadb "-Wl,--version-script=${CMAKE_BINARY_DIR}/libmariadb/mariadbclient.def") TARGET_LINK_LIBRARIES (mariadbclient "-Wl,--no-undefined") - TARGET_LINK_LIBRARIES (mariadbclient "-Wl,--version-script=${EXPORT_FILE}") + TARGET_LINK_LIBRARIES (mariadbclient "-Wl,--version-script=${CMAKE_BINARY_DIR}/libmariadb/mariadbclient.def") ENDIF() SET_TARGET_PROPERTIES(mariadbclient PROPERTIES INTERFACE_LINK_LIBRARIES "${SYSTEM_LIBS}") @@ -426,7 +384,7 @@ ENDIF() INSTALL(TARGETS - libmariadb mariadbclient + libmariadb mariadbclient RUNTIME DESTINATION "${LIB_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}" LIBRARY DESTINATION "${LIB_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}" ARCHIVE DESTINATION "${LIB_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}") diff --git a/libmariadb/bchange.c b/libmariadb/bchange.c deleted file mode 100644 index f71bcf53..00000000 --- a/libmariadb/bchange.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : bchange.c - Author : Michael widenius - Updated: 1987-03-20 - Defines: bchange() - - bchange(dst, old_length, src, new_length, tot_length) - replaces old_length characters at dst to new_length characters from - src in a buffer with tot_length bytes. -*/ - -#include -#include "m_string.h" - -void bchange(register char *dst, size_t old_length, register const char *src, size_t new_length, size_t tot_length) -{ - size_t rest=tot_length-old_length; - if (old_length < new_length) - bmove_upp(dst+rest+new_length,dst+tot_length,rest); - else - bmove(dst+new_length,dst+old_length,rest); - memcpy(dst,src,new_length); -} diff --git a/libmariadb/bmove.c b/libmariadb/bmove.c deleted file mode 100644 index 09fe067a..00000000 --- a/libmariadb/bmove.c +++ /dev/null @@ -1,80 +0,0 @@ -/* Copyright (C) 2002 MySQL AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : bmove.c - Author : Richard A. O'Keefe. - Michael Widenius; ifdef MC68000 - Updated: 23 April 1984 - Defines: bmove() - - bmove(dst, src, len) moves exactly "len" bytes from the source "src" - to the destination "dst". It does not check for NUL characters as - strncpy() and strnmov() do. Thus if your C compiler doesn't support - structure assignment, you can simulate it with - bmove(&to, &from, sizeof from); - The standard 4.2bsd routine for this purpose is bcopy. But as bcopy - has its first two arguments the other way around you may find this a - bit easier to get right. - No value is returned. - - Note: the "b" routines are there to exploit certain VAX order codes, - but the MOVC3 instruction will only move 65535 characters. The asm - code is presented for your interest and amusement. -*/ - -#include -#include "m_string.h" - -#if !defined(HAVE_BMOVE) && !defined(bmove) - -#if VaxAsm - -void bmove(dst, src, len) - char *dst, *src; - uint len; - { - asm("movc3 12(ap),*8(ap),*4(ap)"); - } - -#else -#if defined(MC68000) && defined(DS90) - -void bmove(dst, src, len) -char *dst,*src; -uint len; /* 0 <= len <= 65535 */ -{ -asm(" movl 12(a7),d0 "); -asm(" subql #1,d0 "); -asm(" blt .L5 "); -asm(" movl 4(a7),a1 "); -asm(" movl 8(a7),a0 "); -asm(".L4: movb (a0)+,(a1)+ "); -asm(" dbf d0,.L4 "); -asm(".L5: "); -} -#else - -void bmove(dst, src, len) -register char *dst; -register const char *src; -register uint len; -{ - while (len-- != 0) *dst++ = *src++; -} -#endif -#endif -#endif diff --git a/libmariadb/bmove_upp.c b/libmariadb/bmove_upp.c index 92df08ec..ee7798bc 100644 --- a/libmariadb/bmove_upp.c +++ b/libmariadb/bmove_upp.c @@ -24,28 +24,10 @@ "src-len" to the destination "dst-len" counting downwards. */ -#include -#include "m_string.h" +#include +#include "ma_string.h" -#if defined(MC68000) && defined(DS90) - -/* 0 <= len <= 65535 */ -void bmove_upp(byte *dst, const byte *src, size_t len) -{ -asm(" movl 12(a7),d0 "); -asm(" subql #1,d0 "); -asm(" blt .L5 "); -asm(" movl 4(a7),a1 "); -asm(" movl 8(a7),a0 "); -asm(".L4: movb -(a0),-(a1) "); -asm(" dbf d0,.L4 "); -asm(".L5: "); -} -#else - -void bmove_upp(register char *dst, register const char *src, register size_t len) +void ma_bmove_upp(register char *dst, register const char *src, register size_t len) { while (len-- != 0) *--dst = *--src; } - -#endif diff --git a/libmariadb/dbug.c b/libmariadb/dbug.c deleted file mode 100644 index e1366515..00000000 --- a/libmariadb/dbug.c +++ /dev/null @@ -1,2455 +0,0 @@ -/****************************************************************************** - * * - * N O T I C E * - * * - * Copyright Abandoned, 1987, Fred Fish * - * * - * * - * This previously copyrighted work has been placed into the public * - * domain by the author and may be freely used for any purpose, * - * private or commercial. * - * * - * Because of the number of inquiries I was receiving about the use * - * of this product in commercially developed works I have decided to * - * simply make it public domain to further its unrestricted use. I * - * specifically would be most happy to see this material become a * - * part of the standard Unix distributions by AT&T and the Berkeley * - * Computer Science Research Group, and a standard part of the GNU * - * system from the Free Software Foundation. * - * * - * I would appreciate it, as a courtesy, if this notice is left in * - * all copies and derivative works. Thank you. * - * * - * The author makes no warranty of any kind with respect to this * - * product and explicitly disclaims any implied warranties of mer- * - * chantability or fitness for any particular purpose. * - * * - ****************************************************************************** - */ - -/* - * FILE - * - * dbug.c runtime support routines for dbug package - * - * SCCS - * - * @(#)dbug.c 1.25 7/25/89 - * - * DESCRIPTION - * - * These are the runtime support routines for the dbug package. - * The dbug package has two main components; the user include - * file containing various macro definitions, and the runtime - * support routines which are called from the macro expansions. - * - * Externally visible functions in the runtime support module - * use the naming convention pattern "_db_xx...xx_", thus - * they are unlikely to collide with user defined function names. - * - * AUTHOR(S) - * - * Fred Fish (base code) - * Enhanced Software Technologies, Tempe, AZ - * asuvax!mcdphx!estinc!fnf - * - * Binayak Banerjee (profiling enhancements) - * seismo!bpa!sjuvax!bbanerje - * - * Michael Widenius: - * DBUG_DUMP - To dump a block of memory. - * PUSH_FLAG "O" - To be used insted of "o" if we - * want flushing after each write - * PUSH_FLAG "A" - as 'O', but we will append to the out file instead - * of creating a new one. - * Check of malloc on entry/exit (option "S") - * - * Sergei Golubchik: - * DBUG_EXECUTE_IF - * incremental mode (-#+t:-d,info ...) - * DBUG_SET, _db_explain_ - * thread-local settings - * negative lists (-#-d,info => everything but "info") - * - * function/ syntax - * (the logic is - think of a call stack as of a path. - * "function" means only this function, "function/" means the hierarchy. - * in the future, filters like function1/function2 could be supported. - * following this logic glob(7) wildcards are supported.) - * - */ - -/* - We can't have SAFE_MUTEX defined here as this will cause recursion - in pthread_mutex_lock -*/ - -#undef SAFE_MUTEX -#include -#include -#include - -#ifdef HAVE_FNMATCH_H -#include -#else -#define fnmatch(A,B,C) strcmp(A,B) -#endif - -#if defined(_WIN32) -#include -#else -#include -#include -#endif - -static const char _dig_vec_upper[] = - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -static const char _dig_vec_lower[] = - "0123456789abcdefghijklmnopqrstuvwxyz"; - -#ifndef DBUG_OFF - - -/* - * Manifest constants which may be "tuned" if desired. - */ - -#define PRINTBUF 1024 /* Print buffer size */ -#define INDENT 2 /* Indentation per trace level */ -#define MAXDEPTH 200 /* Maximum trace depth default */ - -/* - * The following flags are used to determine which - * capabilities the user has enabled with the settings - * push macro. - * - * TRACE_ON is also used in _db_stack_frame_->level - * (until we add flags to _db_stack_frame_, increasing it by 4 bytes) - */ - -#define DEBUG_ON (1 << 1) /* Debug enabled */ -#define FILE_ON (1 << 2) /* File name print enabled */ -#define LINE_ON (1 << 3) /* Line number print enabled */ -#define DEPTH_ON (1 << 4) /* Function nest level print enabled */ -#define PROCESS_ON (1 << 5) /* Process name print enabled */ -#define NUMBER_ON (1 << 6) /* Number each line of output */ -#define PROFILE_ON (1 << 7) /* Print out profiling code */ -#define PID_ON (1 << 8) /* Identify each line with process id */ -#define TIMESTAMP_ON (1 << 9) /* timestamp every line of output */ -#define FLUSH_ON_WRITE (1 << 10) /* Flush on every write */ -#define OPEN_APPEND (1 << 11) /* Open for append */ -#define TRACE_ON ((uint)1 << 31) /* Trace enabled. MUST be the highest bit!*/ - -#define TRACING (cs->stack->flags & TRACE_ON) -#define DEBUGGING (cs->stack->flags & DEBUG_ON) -#define PROFILING (cs->stack->flags & PROFILE_ON) - -/* - * Typedefs to make things more obvious. - */ - -#define BOOLEAN my_bool - -/* - * Make it easy to change storage classes if necessary. - */ - -#define IMPORT extern /* Names defined externally */ -#define EXPORT /* Allocated here, available globally */ - -/* - * The default file for profiling. Could also add another flag - * (G?) which allowed the user to specify this. - * - * If the automatic variables get allocated on the stack in - * reverse order from their declarations, then define AUTOS_REVERSE to 1. - * This is used by the code that keeps track of stack usage. For - * forward allocation, the difference in the dbug frame pointers - * represents stack used by the callee function. For reverse allocation, - * the difference represents stack used by the caller function. - * - */ - -#define PROF_FILE "dbugmon.out" -#define PROF_EFMT "E\t%ld\t%s\n" -#define PROF_SFMT "S\t%lx\t%lx\t%s\n" -#define PROF_XFMT "X\t%ld\t%s\n" - -#ifdef M_I386 /* predefined by xenix 386 compiler */ -#define AUTOS_REVERSE 1 -#else -#define AUTOS_REVERSE 0 -#endif - -/* - * Externally supplied functions. - */ - -#ifndef HAVE_PERROR -static void perror(); /* Fake system/library error print routine */ -#endif - -/* - * The user may specify a list of functions to trace or - * debug. These lists are kept in a linear linked list, - * a very simple implementation. - */ - -struct link { - struct link *next_link; /* Pointer to the next link */ - char flags; - char str[1]; /* Pointer to link's contents */ -}; - -/* flags for struct link and return flags of InList */ -#define SUBDIR 1 /* this MUST be 1 */ -#define INCLUDE 2 -#define EXCLUDE 4 -/* this is not a struct link flag, but only a return flags of InList */ -#define MATCHED 65536 -#define NOT_MATCHED 0 - -/* - * Debugging settings can be pushed or popped off of a - * stack which is implemented as a linked list. Note - * that the head of the list is the current settings and the - * stack is pushed by adding a new settings to the head of the - * list or popped by removing the first link. - * - * Note: if out_file is NULL, the other fields are not initialized at all! - */ - -struct settings { - uint flags; /* Current settings flags */ - uint maxdepth; /* Current maximum trace depth */ - uint delay; /* Delay after each output line */ - uint sub_level; /* Sub this from code_state->level */ - FILE *out_file; /* Current output stream */ - FILE *prof_file; /* Current profiling stream */ - char name[FN_REFLEN]; /* Name of output file */ - struct link *functions; /* List of functions */ - struct link *p_functions; /* List of profiled functions */ - struct link *keywords; /* List of debug keywords */ - struct link *processes; /* List of process names */ - struct settings *next; /* Next settings in the list */ -}; - -#define is_shared(S, V) ((S)->next && (S)->next->V == (S)->V) - -/* - * Local variables not seen by user. - */ - - -static BOOLEAN init_done= FALSE; /* Set to TRUE when initialization done */ -/** - Global debugging settings. - This structure shared between all threads, - and is the last element in each thread @c CODE_STATE::stack chain. - Protected by @c THR_LOCK_init_settings. -*/ -static struct settings init_settings; -static const char *db_process= 0;/* Pointer to process name; argv[0] */ -my_bool _dbug_on_= TRUE; /* FALSE if no debugging at all */ - -typedef struct _db_code_state_ { - const char *process; /* Pointer to process name; usually argv[0] */ - const char *func; /* Name of current user function */ - const char *file; /* Name of current user file */ - struct _db_stack_frame_ *framep; /* Pointer to current frame */ - struct settings *stack; /* debugging settings */ - const char *jmpfunc; /* Remember current function for setjmp */ - const char *jmpfile; /* Remember current file for setjmp */ - int lineno; /* Current debugger output line number */ - uint level; /* Current function nesting level */ - int jmplevel; /* Remember nesting level at setjmp() */ - -/* - * The following variables are used to hold the state information - * between the call to _db_pargs_() and _db_doprnt_(), during - * expansion of the DBUG_PRINT macro. This is the only macro - * that currently uses these variables. - * - * These variables are currently used only by _db_pargs_() and - * _db_doprnt_(). - */ - - uint u_line; /* User source code line number */ - int locked; /* If locked with _db_lock_file_ */ - const char *u_keyword; /* Keyword for current macro */ - uint m_read_lock_count; -} CODE_STATE; - -/* - The test below is so we could call functions with DBUG_ENTER before - ma_thread_init(). -*/ -#define get_code_state_if_not_set_or_return if (!cs && !((cs=code_state()))) return -#define get_code_state_or_return if (!((cs=code_state()))) return - - /* Handling lists */ -#define ListAdd(A,B,C) ListAddDel(A,B,C,INCLUDE) -#define ListDel(A,B,C) ListAddDel(A,B,C,EXCLUDE) -static struct link *ListAddDel(struct link *, const char *, const char *, int); -static struct link *ListCopy(struct link *); -static int InList(struct link *linkp,const char *cp); -static uint ListFlags(struct link *linkp); -static void FreeList(struct link *linkp); - - /* OpenClose debug output stream */ -static void DBUGOpenFile(CODE_STATE *,const char *, const char *, int); -static void DBUGCloseFile(CODE_STATE *cs, FILE *fp); - /* Push current debug settings */ -static void PushState(CODE_STATE *cs); - /* Free memory associated with debug state. */ -static void FreeState (CODE_STATE *cs, struct settings *state, int free_state); - /* Test for tracing enabled */ -static int DoTrace(CODE_STATE *cs); -/* - return values of DoTrace. - Can also be used as bitmask: ret & DO_TRACE -*/ -#define DO_TRACE 1 -#define DONT_TRACE 2 -#define ENABLE_TRACE 3 -#define DISABLE_TRACE 4 - - /* Test to see if file is writable */ -#if defined(HAVE_ACCESS) -static BOOLEAN Writable(const char *pathname); -#endif - -static void DoPrefix(CODE_STATE *cs, uint line); - -static char *DbugMalloc(size_t size); -static const char *BaseName(const char *pathname); -static void Indent(CODE_STATE *cs, int indent); -static void DbugFlush(CODE_STATE *); -static void DbugExit(const char *why); -static const char *DbugStrTok(const char *s); - -/* - * Miscellaneous printf format strings. - */ - -#define ERR_MISSING_RETURN "missing DBUG_RETURN or DBUG_VOID_RETURN macro in function \"%s\"\n" -#define ERR_MISSING_UNLOCK "missing DBUG_UNLOCK_FILE macro in function \"%s\"\n" -#define ERR_OPEN "%s: can't open debug output stream \"%s\": " -#define ERR_CLOSE "%s: can't close debug file: " -#define ERR_ABORT "%s: debugger aborting because %s\n" - -/* - * Macros and defines for testing file accessibility under UNIX and MSDOS. - */ - -#undef EXISTS -#if !defined(HAVE_ACCESS) -#define EXISTS(pathname) (FALSE) /* Assume no existance */ -#define Writable(name) (TRUE) -#else -#define EXISTS(pathname) (access(pathname, F_OK) == 0) -#define WRITABLE(pathname) (access(pathname, W_OK) == 0) -#endif - - -/* -** Macros to allow dbugging with threads -*/ - -#include -static pthread_mutex_t THR_LOCK_dbug; - -/** - A mutex protecting flushing of gcov data, see _db_flush_gcov_(). - We don't re-use THR_LOCK_dbug, because that would disallow: - DBUG_LOCK_FILE; ..... DBUG_SUICIDE(); .... DBUG_UNLOCK_FILE; -*/ -static pthread_mutex_t THR_LOCK_gcov; -static pthread_mutex_t THR_LOCK_init_settings; - -static CODE_STATE *code_state(void) -{ - CODE_STATE *cs, **cs_ptr; - - /* - _dbug_on_ is reset if we don't plan to use any debug commands at all and - we want to run on maximum speed - */ - if (!_dbug_on_) - return 0; - - if (!init_done) - { - init_done=TRUE; - pthread_mutex_init(&THR_LOCK_dbug, NULL); - pthread_mutex_init(&THR_LOCK_gcov, NULL); - pthread_mutex_init(&THR_LOCK_init_settings, NULL); - memset(&init_settings, 0, sizeof(init_settings)); - init_settings.out_file=stderr; - init_settings.flags=OPEN_APPEND; - } - - if (!(cs_ptr= (CODE_STATE**) ma_thread_var_dbug())) - return 0; /* Thread not initialised */ - if (!(cs= *cs_ptr)) - { - cs=(CODE_STATE*) DbugMalloc(sizeof(*cs)); - memset(cs, 0, sizeof(*cs)); - cs->process= db_process ? db_process : "dbug"; - cs->func="?func"; - cs->file="?file"; - cs->stack=&init_settings; - cs->m_read_lock_count= 0; - *cs_ptr= cs; - } - return cs; -} - -/** - Lock the stack debugging settings. - Only the shared (global) settings are locked if necessary, - per thread settings are local and safe to use. - This lock is re entrant. - @sa unlock_stack -*/ -static void read_lock_stack(CODE_STATE *cs) -{ - if (cs->stack == &init_settings) - { - if (++(cs->m_read_lock_count) == 1) - pthread_mutex_lock(&THR_LOCK_init_settings); - } -} - -/** - Unlock the stack debugging settings. - @sa read_lock_stack -*/ -static void unlock_stack(CODE_STATE *cs) -{ - if (cs->stack == &init_settings) - { - if (--(cs->m_read_lock_count) == 0) - pthread_mutex_unlock(&THR_LOCK_init_settings); - } -} - -/* - * Translate some calls among different systems. - */ - -#ifdef HAVE_SLEEP -/* sleep() wants seconds */ -#define Delay(A) sleep(((uint) A)/10) -#else -#define Delay(A) (0) -#endif - -/* - * FUNCTION - * - * _db_process_ give the name to the current process/thread - * - * SYNOPSIS - * - * VOID _process_(name) - * char *name; - * - */ - -void _db_process_(const char *name) -{ - CODE_STATE *cs; - - if (!db_process) - db_process= name; - - get_code_state_or_return; - cs->process= name; -} - -/* - * FUNCTION - * - * DbugParse parse control string and set current debugger settings - * - * DESCRIPTION - * - * Given pointer to a debug control string in "control", - * parses the control string, and sets - * up a current debug settings. - * - * The debug control string is a sequence of colon separated fields - * as follows: - * - * [+]::...: - * - * Each field consists of a mandatory flag character followed by - * an optional "," and comma separated list of modifiers: - * - * [sign]flag[,modifier,modifier,...,modifier] - * - * See the manual for the list of supported signs, flags, and modifiers - * - * For convenience, any leading "-#" is stripped off. - * - * RETURN - * 1 - a list of functions ("f" flag) was possibly changed - * 0 - a list of functions was not changed - */ - -int DbugParse(CODE_STATE *cs, const char *control) -{ - const char *end; - int rel, f_used=0; - struct settings *stack; - - /* - Make sure we are not changing settings while inside a - DBUG_LOCK_FILE - DBUG_UNLOCK_FILE - section, that is a mis use, that would cause changing - DBUG_FILE while the caller prints to it. - */ - assert(! cs->locked); - - stack= cs->stack; - - /* - When parsing the global init_settings itself, - make sure to block every other thread using dbug functions. - */ - assert(cs->m_read_lock_count == 0); - if (stack == &init_settings) - pthread_mutex_lock(&THR_LOCK_init_settings); - - if (control[0] == '-' && control[1] == '#') - control+=2; - - rel= control[0] == '+' || control[0] == '-'; - if ((!rel || (!stack->out_file && !stack->next))) - { - /* Free memory associated with the state before resetting its members */ - FreeState(cs, stack, 0); - stack->flags= 0; - stack->delay= 0; - stack->maxdepth= 0; - stack->sub_level= 0; - stack->out_file= stderr; - stack->prof_file= NULL; - stack->functions= NULL; - stack->p_functions= NULL; - stack->keywords= NULL; - stack->processes= NULL; - } - else if (!stack->out_file) - { - stack->flags= stack->next->flags; - stack->delay= stack->next->delay; - stack->maxdepth= stack->next->maxdepth; - stack->sub_level= stack->next->sub_level; - strcpy(stack->name, stack->next->name); - stack->prof_file= stack->next->prof_file; - if (stack->next == &init_settings) - { - assert(stack != &init_settings); - pthread_mutex_lock(&THR_LOCK_init_settings); - - /* - Never share with the global parent - it can change under your feet. - - Reset out_file to stderr to prevent sharing of trace files between - global and session settings. - */ - stack->out_file= stderr; - stack->functions= ListCopy(init_settings.functions); - stack->p_functions= ListCopy(init_settings.p_functions); - stack->keywords= ListCopy(init_settings.keywords); - stack->processes= ListCopy(init_settings.processes); - - pthread_mutex_unlock(&THR_LOCK_init_settings); - } - else - { - stack->out_file= stack->next->out_file; - stack->functions= stack->next->functions; - stack->p_functions= stack->next->p_functions; - stack->keywords= stack->next->keywords; - stack->processes= stack->next->processes; - } - } - - end= DbugStrTok(control); - while (control < end) - { - int c, sign= (*control == '+') ? 1 : (*control == '-') ? -1 : 0; - if (sign) control++; - c= *control++; - if (*control == ',') control++; - /* XXX when adding new cases here, don't forget _db_explain_ ! */ - switch (c) { - case 'd': - if (sign < 0 && control == end) - { - if (!is_shared(stack, keywords)) - FreeList(stack->keywords); - stack->keywords=NULL; - stack->flags &= ~DEBUG_ON; - break; - } - if (rel && is_shared(stack, keywords)) - stack->keywords= ListCopy(stack->keywords); - if (sign < 0) - { - if (DEBUGGING) - stack->keywords= ListDel(stack->keywords, control, end); - break; - } - stack->keywords= ListAdd(stack->keywords, control, end); - stack->flags |= DEBUG_ON; - break; - case 'D': - stack->delay= atoi(control); - break; - case 'f': - f_used= 1; - if (sign < 0 && control == end) - { - if (!is_shared(stack,functions)) - FreeList(stack->functions); - stack->functions=NULL; - break; - } - if (rel && is_shared(stack,functions)) - stack->functions= ListCopy(stack->functions); - if (sign < 0) - stack->functions= ListDel(stack->functions, control, end); - else - stack->functions= ListAdd(stack->functions, control, end); - break; - case 'F': - if (sign < 0) - stack->flags &= ~FILE_ON; - else - stack->flags |= FILE_ON; - break; - case 'i': - if (sign < 0) - stack->flags &= ~PID_ON; - else - stack->flags |= PID_ON; - break; - case 'L': - if (sign < 0) - stack->flags &= ~LINE_ON; - else - stack->flags |= LINE_ON; - break; - case 'n': - if (sign < 0) - stack->flags &= ~DEPTH_ON; - else - stack->flags |= DEPTH_ON; - break; - case 'N': - if (sign < 0) - stack->flags &= ~NUMBER_ON; - else - stack->flags |= NUMBER_ON; - break; - case 'A': - case 'O': - stack->flags |= FLUSH_ON_WRITE; - /* fall through */ - case 'a': - case 'o': - /* In case we already have an open file. */ - if (!is_shared(stack, out_file)) - DBUGCloseFile(cs, stack->out_file); - if (sign < 0) - { - stack->flags &= ~FLUSH_ON_WRITE; - stack->out_file= stderr; - break; - } - if (c == 'a' || c == 'A') - stack->flags |= OPEN_APPEND; - else - stack->flags &= ~OPEN_APPEND; - if (control != end) - DBUGOpenFile(cs, control, end, stack->flags & OPEN_APPEND); - else - DBUGOpenFile(cs, "-",0,0); - break; - case 'p': - if (sign < 0 && control == end) - { - if (!is_shared(stack,processes)) - FreeList(stack->processes); - stack->processes=NULL; - break; - } - if (rel && is_shared(stack, processes)) - stack->processes= ListCopy(stack->processes); - if (sign < 0) - stack->processes= ListDel(stack->processes, control, end); - else - stack->processes= ListAdd(stack->processes, control, end); - break; - case 'P': - if (sign < 0) - stack->flags &= ~PROCESS_ON; - else - stack->flags |= PROCESS_ON; - break; - case 'r': - stack->sub_level= cs->level; - break; - case 't': - if (sign < 0) - { - if (control != end) - stack->maxdepth-= atoi(control); - else - stack->maxdepth= 0; - } - else - { - if (control != end) - stack->maxdepth+= atoi(control); - else - stack->maxdepth= MAXDEPTH; - } - if (stack->maxdepth > 0) - stack->flags |= TRACE_ON; - else - stack->flags &= ~TRACE_ON; - break; - case 'T': - if (sign < 0) - stack->flags &= ~TIMESTAMP_ON; - else - stack->flags |= TIMESTAMP_ON; - break; - } - if (!*end) - break; - control=end+1; - end= DbugStrTok(control); - } - - if (stack->next == &init_settings) - { - /* - Enforce nothing is shared with the global init_settings - */ - assert((stack->functions == NULL) || (stack->functions != init_settings.functions)); - assert((stack->p_functions == NULL) || (stack->p_functions != init_settings.p_functions)); - assert((stack->keywords == NULL) || (stack->keywords != init_settings.keywords)); - assert((stack->processes == NULL) || (stack->processes != init_settings.processes)); - } - - if (stack == &init_settings) - pthread_mutex_unlock(&THR_LOCK_init_settings); - - return !rel || f_used; -} - -#define framep_trace_flag(cs, frp) (frp ? \ - frp->level & TRACE_ON : \ - (ListFlags(cs->stack->functions) & INCLUDE) ? \ - 0 : (uint)TRACE_ON) - -void FixTraceFlags_helper(CODE_STATE *cs, const char *func, - struct _db_stack_frame_ *framep) -{ - if (framep->prev) - FixTraceFlags_helper(cs, framep->func, framep->prev); - - cs->func= func; - cs->level= framep->level & ~TRACE_ON; - framep->level= cs->level | framep_trace_flag(cs, framep->prev); - /* - we don't set cs->framep correctly, even though DoTrace uses it. - It's ok, because cs->framep may only affect DO_TRACE/DONT_TRACE return - values, but we ignore them here anyway - */ - switch(DoTrace(cs)) { - case ENABLE_TRACE: - framep->level|= TRACE_ON; - break; - case DISABLE_TRACE: - framep->level&= ~TRACE_ON; - break; - } -} - -#define fflags(cs) cs->stack->out_file ? ListFlags(cs->stack->functions) : TRACE_ON; - -void FixTraceFlags(uint old_fflags, CODE_STATE *cs) -{ - const char *func; - uint new_fflags, traceon, level; - struct _db_stack_frame_ *framep; - - /* - first (a.k.a. safety) check: - if we haven't started tracing yet, no call stack at all - we're safe. - */ - framep=cs->framep; - if (framep == 0) - return; - - /* - Ok, the tracing has started, call stack isn't empty. - - second check: does the new list have a SUBDIR rule ? - */ - new_fflags=fflags(cs); - if (new_fflags & SUBDIR) - goto yuck; - - /* - Ok, new list doesn't use SUBDIR. - - third check: we do NOT need to re-scan if - neither old nor new lists used SUBDIR flag and if a default behavior - (whether an unlisted function is traced) hasn't changed. - Default behavior depends on whether there're INCLUDE elements in the list. - */ - if (!(old_fflags & SUBDIR) && !((new_fflags^old_fflags) & INCLUDE)) - return; - - /* - Ok, old list may've used SUBDIR, or defaults could've changed. - - fourth check: are we inside a currently active SUBDIR rule ? - go up the call stack, if TRACE_ON flag ever changes its value - we are. - */ - for (traceon=framep->level; framep; framep=framep->prev) - if ((traceon ^ framep->level) & TRACE_ON) - goto yuck; - - /* - Ok, TRACE_ON flag doesn't change in the call stack. - - fifth check: but is the top-most value equal to a default one ? - */ - if (((traceon & TRACE_ON) != 0) == ((new_fflags & INCLUDE) == 0)) - return; - -yuck: - /* - Yuck! function list was changed, and one of the currently active rules - was possibly affected. For example, a tracing could've been enabled or - disabled for a function somewhere up the call stack. - To react correctly, we must go up the call stack all the way to - the top and re-match rules to set TRACE_ON bit correctly. - - We must traverse the stack forwards, not backwards. - That's what a recursive helper is doing. - It'll destroy two CODE_STATE fields, save them now. - */ - func= cs->func; - level= cs->level; - FixTraceFlags_helper(cs, func, cs->framep); - /* now we only need to restore CODE_STATE fields, and we're done */ - cs->func= func; - cs->level= level; -} - -/* - * FUNCTION - * - * _db_set_ set current debugger settings - * - * SYNOPSIS - * - * VOID _db_set_(control) - * char *control; - * - * DESCRIPTION - * - * Given pointer to a debug control string in "control", - * parses the control string, and sets up a current debug - * settings. Pushes a new debug settings if the current is - * set to the initial debugger settings. - * - */ - -void _db_set_(const char *control) -{ - CODE_STATE *cs; - uint old_fflags; - get_code_state_or_return; - - read_lock_stack(cs); - old_fflags=fflags(cs); - unlock_stack(cs); - - if (cs->stack == &init_settings) - PushState(cs); - - if (DbugParse(cs, control)) - { - read_lock_stack(cs); - FixTraceFlags(old_fflags, cs); - unlock_stack(cs); - } -} - -/* - * FUNCTION - * - * _db_push_ push current debugger settings and set up new one - * - * SYNOPSIS - * - * VOID _db_push_(control) - * char *control; - * - * DESCRIPTION - * - * Given pointer to a debug control string in "control", pushes - * the current debug settings, parses the control string, and sets - * up a new debug settings with DbugParse() - * - */ - -void _db_push_(const char *control) -{ - CODE_STATE *cs; - uint old_fflags; - get_code_state_or_return; - - read_lock_stack(cs); - old_fflags=fflags(cs); - unlock_stack(cs); - - PushState(cs); - - if (DbugParse(cs, control)) - { - read_lock_stack(cs); - FixTraceFlags(old_fflags, cs); - unlock_stack(cs); - } -} - - -/** - Returns TRUE if session-local settings have been set. -*/ - -int _db_is_pushed_() -{ - CODE_STATE *cs= NULL; - get_code_state_or_return FALSE; - return (cs->stack != &init_settings); -} - -/* - * FUNCTION - * - * _db_set_init_ set initial debugger settings - * - * SYNOPSIS - * - * VOID _db_set_init_(control) - * char *control; - * - * DESCRIPTION - * see _db_set_ - * - */ - -void _db_set_init_(const char *control) -{ - CODE_STATE tmp_cs; - memset(&tmp_cs, 0, sizeof(tmp_cs)); - tmp_cs.stack= &init_settings; - tmp_cs.process= db_process ? db_process : "dbug"; - DbugParse(&tmp_cs, control); -} - -/* - * FUNCTION - * - * _db_pop_ pop the debug stack - * - * DESCRIPTION - * - * Pops the debug stack, returning the debug settings to its - * condition prior to the most recent _db_push_ invocation. - * Note that the pop will fail if it would remove the last - * valid settings from the stack. This prevents user errors - * in the push/pop sequence from screwing up the debugger. - * Maybe there should be some kind of warning printed if the - * user tries to pop too many states. - * - */ - -void _db_pop_() -{ - struct settings *discard; - uint old_fflags; - CODE_STATE *cs; - - get_code_state_or_return; - - discard= cs->stack; - if (discard != &init_settings) - { - read_lock_stack(cs); - old_fflags=fflags(cs); - unlock_stack(cs); - - cs->stack= discard->next; - FreeState(cs, discard, 1); - - read_lock_stack(cs); - FixTraceFlags(old_fflags, cs); - unlock_stack(cs); - } -} - -/* - * FUNCTION - * - * _db_explain_ generates 'control' string for the current settings - * - * RETURN - * 0 - ok - * 1 - buffer too short, output truncated - * - */ - -/* helper macros */ -#define char_to_buf(C) do { \ - *buf++=(C); \ - if (buf >= end) goto overflow; \ - } while (0) -#define str_to_buf(S) do { \ - char_to_buf(','); \ - buf=strnmov(buf, (S), len+1); \ - if (buf >= end) goto overflow; \ - } while (0) -#define list_to_buf(l, f) do { \ - struct link *listp=(l); \ - while (listp) \ - { \ - if (listp->flags & (f)) \ - { \ - str_to_buf(listp->str); \ - if (listp->flags & SUBDIR) \ - char_to_buf('/'); \ - } \ - listp=listp->next_link; \ - } \ - } while (0) -#define int_to_buf(i) do { \ - char b[50]; \ - ma_int10_to_str((i), b, 10); \ - str_to_buf(b); \ - } while (0) -#define colon_to_buf do { \ - if (buf != start) char_to_buf(':'); \ - } while(0) -#define op_int_to_buf(C, val, def) do { \ - if ((val) != (def)) \ - { \ - colon_to_buf; \ - char_to_buf((C)); \ - int_to_buf(val); \ - } \ - } while (0) -#define op_intf_to_buf(C, val, def, cond) do { \ - if ((cond)) \ - { \ - colon_to_buf; \ - char_to_buf((C)); \ - if ((val) != (def)) int_to_buf(val); \ - } \ - } while (0) -#define op_str_to_buf(C, val, cond) do { \ - if ((cond)) \ - { \ - char *s=(val); \ - colon_to_buf; \ - char_to_buf((C)); \ - if (*s) str_to_buf(s); \ - } \ - } while (0) -#define op_list_to_buf(C, val, cond) do { \ - if ((cond)) \ - { \ - int f=ListFlags(val); \ - colon_to_buf; \ - char_to_buf((C)); \ - if (f & INCLUDE) \ - list_to_buf(val, INCLUDE); \ - if (f & EXCLUDE) \ - { \ - colon_to_buf; \ - char_to_buf('-'); \ - char_to_buf((C)); \ - list_to_buf(val, EXCLUDE); \ - } \ - } \ - } while (0) -#define op_bool_to_buf(C, cond) do { \ - if ((cond)) \ - { \ - colon_to_buf; \ - char_to_buf((C)); \ - } \ - } while (0) - -int _db_explain_ (CODE_STATE *cs, char *buf, size_t len) -{ - char *start=buf, *end=buf+len-4; - - get_code_state_if_not_set_or_return *buf=0; - - read_lock_stack(cs); - - op_list_to_buf('d', cs->stack->keywords, DEBUGGING); - op_int_to_buf ('D', cs->stack->delay, 0); - op_list_to_buf('f', cs->stack->functions, cs->stack->functions); - op_bool_to_buf('F', cs->stack->flags & FILE_ON); - op_bool_to_buf('i', cs->stack->flags & PID_ON); - op_list_to_buf('g', cs->stack->p_functions, PROFILING); - op_bool_to_buf('L', cs->stack->flags & LINE_ON); - op_bool_to_buf('n', cs->stack->flags & DEPTH_ON); - op_bool_to_buf('N', cs->stack->flags & NUMBER_ON); - op_str_to_buf( - ((cs->stack->flags & FLUSH_ON_WRITE ? 0 : 32) | - (cs->stack->flags & OPEN_APPEND ? 'A' : 'O')), - cs->stack->name, cs->stack->out_file != stderr); - op_list_to_buf('p', cs->stack->processes, cs->stack->processes); - op_bool_to_buf('P', cs->stack->flags & PROCESS_ON); - op_bool_to_buf('r', cs->stack->sub_level != 0); - op_intf_to_buf('t', cs->stack->maxdepth, MAXDEPTH, TRACING); - op_bool_to_buf('T', cs->stack->flags & TIMESTAMP_ON); - - unlock_stack(cs); - - *buf= '\0'; - return 0; - -overflow: - *end++= '.'; - *end++= '.'; - *end++= '.'; - *end= '\0'; - - unlock_stack(cs); - return 1; -} - -#undef char_to_buf -#undef str_to_buf -#undef list_to_buf -#undef int_to_buf -#undef colon_to_buf -#undef op_int_to_buf -#undef op_intf_to_buf -#undef op_str_to_buf -#undef op_list_to_buf -#undef op_bool_to_buf - -/* - * FUNCTION - * - * _db_explain_init_ explain initial debugger settings - * - * DESCRIPTION - * see _db_explain_ - */ - -int _db_explain_init_(char *buf, size_t len) -{ - CODE_STATE cs; - memset(&cs, 0, sizeof(cs)); - cs.stack=&init_settings; - return _db_explain_(&cs, buf, len); -} - -/* - * FUNCTION - * - * _db_enter_ process entry point to user function - * - * SYNOPSIS - * - * VOID _db_enter_(_func_, _file_, _line_, _stack_frame_) - * char *_func_; points to current function name - * char *_file_; points to current file name - * int _line_; called from source line number - * struct _db_stack_frame_ allocated on the caller's stack - * - * DESCRIPTION - * - * Called at the beginning of each user function to tell - * the debugger that a new function has been entered. - * Note that the pointers to the previous user function - * name and previous user file name are stored on the - * caller's stack (this is why the ENTER macro must be - * the first "executable" code in a function, since it - * allocates these storage locations). The previous nesting - * level is also stored on the callers stack for internal - * self consistency checks. - * - * Also prints a trace line if tracing is enabled and - * increments the current function nesting depth. - * - * Note that this mechanism allows the debugger to know - * what the current user function is at all times, without - * maintaining an internal stack for the function names. - * - */ - -void _db_enter_(const char *_func_, const char *_file_, - uint _line_, struct _db_stack_frame_ *_stack_frame_) -{ - int save_errno; - CODE_STATE *cs; - if (!((cs=code_state()))) - { - _stack_frame_->level= 0; /* Set to avoid valgrind warnings if dbug is enabled later */ - _stack_frame_->prev= 0; - return; - } - save_errno= errno; - - read_lock_stack(cs); - - _stack_frame_->func= cs->func; - _stack_frame_->file= cs->file; - cs->func= _func_; - cs->file= _file_; - _stack_frame_->prev= cs->framep; - _stack_frame_->level= ++cs->level | framep_trace_flag(cs, cs->framep); - cs->framep= _stack_frame_; - - switch (DoTrace(cs)) { - case ENABLE_TRACE: - cs->framep->level|= TRACE_ON; - if (!TRACING) break; - /* fall through */ - case DO_TRACE: - if (TRACING) - { - if (!cs->locked) - pthread_mutex_lock(&THR_LOCK_dbug); - DoPrefix(cs, _line_); - Indent(cs, cs->level); - (void) fprintf(cs->stack->out_file, ">%s\n", cs->func); - DbugFlush(cs); /* This does a unlock */ - } - break; - case DISABLE_TRACE: - cs->framep->level&= ~TRACE_ON; - /* fall through */ - case DONT_TRACE: - break; - } - errno=save_errno; - - unlock_stack(cs); -} - -/* - * FUNCTION - * - * _db_return_ process exit from user function - * - * SYNOPSIS - * - * VOID _db_return_(_line_, _stack_frame_) - * int _line_; current source line number - * struct _db_stack_frame_ allocated on the caller's stack - * - * DESCRIPTION - * - * Called just before user function executes an explicit or implicit - * return. Prints a trace line if trace is enabled, decrements - * the current nesting level, and restores the current function and - * file names from the defunct function's stack. - * - */ - -void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_) -{ - int save_errno=errno; - uint _slevel_= _stack_frame_->level & ~TRACE_ON; - CODE_STATE *cs; - get_code_state_or_return; - - if (cs->framep != _stack_frame_) - { - char buf[512]; - snprintf(buf, sizeof(buf), ERR_MISSING_RETURN, cs->func); - DbugExit(buf); - } - - read_lock_stack(cs); - - if (DoTrace(cs) & DO_TRACE) - { - if (TRACING) - { - if (!cs->locked) - pthread_mutex_lock(&THR_LOCK_dbug); - DoPrefix(cs, _line_); - Indent(cs, cs->level); - (void) fprintf(cs->stack->out_file, "<%s %u\n", cs->func, _line_); - DbugFlush(cs); - } - } - /* - Check to not set level < 0. This can happen if DBUG was disabled when - function was entered and enabled in function. - */ - cs->level= _slevel_ != 0 ? _slevel_ - 1 : 0; - cs->func= _stack_frame_->func; - cs->file= _stack_frame_->file; - if (cs->framep != NULL) - cs->framep= cs->framep->prev; - errno=save_errno; - - unlock_stack(cs); -} - - -/* - * FUNCTION - * - * _db_pargs_ log arguments for subsequent use by _db_doprnt_() - * - * SYNOPSIS - * - * VOID _db_pargs_(_line_, keyword) - * int _line_; - * char *keyword; - * - * DESCRIPTION - * - * The new universal printing macro DBUG_PRINT, which replaces - * all forms of the DBUG_N macros, needs two calls to runtime - * support routines. The first, this function, remembers arguments - * that are used by the subsequent call to _db_doprnt_(). - * - */ - -void _db_pargs_(uint _line_, const char *keyword) -{ - CODE_STATE *cs; - get_code_state_or_return; - cs->u_line= _line_; - cs->u_keyword= keyword; -} - - -/* - * FUNCTION - * - * _db_doprnt_ handle print of debug lines - * - * SYNOPSIS - * - * VOID _db_doprnt_(format, va_alist) - * char *format; - * va_dcl; - * - * DESCRIPTION - * - * When invoked via one of the DBUG macros, tests the current keyword - * set by calling _db_pargs_() to see if that macro has been selected - * for processing via the debugger control string, and if so, handles - * printing of the arguments via the format string. The line number - * of the DBUG macro in the source is found in u_line. - * - * Note that the format string SHOULD NOT include a terminating - * newline, this is supplied automatically. - * - */ - -#include - -void _db_doprnt_(const char *format,...) -{ - va_list args; - CODE_STATE *cs; - get_code_state_or_return; - - /* Dirty read, for DBUG_PRINT() performance. */ - if (! DEBUGGING) - return; - - va_start(args,format); - read_lock_stack(cs); - - if (_db_keyword_(cs, cs->u_keyword, 0)) - { - int save_errno=errno; - if (!cs->locked) - pthread_mutex_lock(&THR_LOCK_dbug); - DoPrefix(cs, cs->u_line); - if (TRACING) - Indent(cs, cs->level + 1); - else - (void) fprintf(cs->stack->out_file, "%s: ", cs->func); - (void) fprintf(cs->stack->out_file, "%s: ", cs->u_keyword); - (void) vfprintf(cs->stack->out_file, format, args); - DbugFlush(cs); - errno=save_errno; - } - unlock_stack(cs); - va_end(args); -} - -/* - * FUNCTION - * - * _db_dump_ dump a string in hex - * - * SYNOPSIS - * - * void _db_dump_(_line_,keyword,memory,length) - * int _line_; current source line number - * char *keyword; - * char *memory; Memory to print - * int length; Bytes to print - * - * DESCRIPTION - * Dump N characters in a binary array. - * Is used to examine corrupted memory or arrays. - */ - -void _db_dump_(uint _line_, const char *keyword, - const unsigned char *memory, size_t length) -{ - int pos; - CODE_STATE *cs; - get_code_state_or_return; - - /* Dirty read, for DBUG_DUMP() performance. */ - if (! DEBUGGING) - return; - - read_lock_stack(cs); - - if (_db_keyword_(cs, keyword, 0)) - { - if (!cs->locked) - pthread_mutex_lock(&THR_LOCK_dbug); - DoPrefix(cs, _line_); - if (TRACING) - { - Indent(cs, cs->level + 1); - pos= MIN(MAX(cs->level-cs->stack->sub_level,0)*INDENT,80); - } - else - { - fprintf(cs->stack->out_file, "%s: ", cs->func); - } - (void) fprintf(cs->stack->out_file, "%s: Memory: 0x%lx Bytes: (%ld)\n", - keyword, (ulong) memory, (long) length); - - pos=0; - while (length-- > 0) - { - uint tmp= *((unsigned char*) memory++); - if ((pos+=3) >= 80) - { - fputc('\n',cs->stack->out_file); - pos=3; - } - fputc(_dig_vec_upper[((tmp >> 4) & 15)], cs->stack->out_file); - fputc(_dig_vec_upper[tmp & 15], cs->stack->out_file); - fputc(' ',cs->stack->out_file); - } - (void) fputc('\n',cs->stack->out_file); - DbugFlush(cs); - } - - unlock_stack(cs); -} - - -/* - * FUNCTION - * - * ListAddDel modify the list according to debug control string - * - * DESCRIPTION - * - * Given pointer to a comma separated list of strings in "cltp", - * parses the list, and modifies "listp", returning a pointer - * to the new list. - * - * The mode of operation is defined by "todo" parameter. - * - * If it is INCLUDE, elements (strings from "cltp") are added to the - * list, they will have INCLUDE flag set. If the list already contains - * the string in question, new element is not added, but a flag of - * the existing element is adjusted (INCLUDE bit is set, EXCLUDE bit - * is removed). - * - * If it is EXCLUDE, elements are added to the list with the EXCLUDE - * flag set. If the list already contains the string in question, - * it is removed, new element is not added. - */ - -static struct link *ListAddDel(struct link *head, const char *ctlp, - const char *end, int todo) -{ - const char *start; - struct link **cur; - size_t len; - int subdir; - - ctlp--; -next: - while (++ctlp < end) - { - start= ctlp; - subdir=0; - while (ctlp < end && *ctlp != ',') - ctlp++; - len=ctlp-start; - if (start[len-1] == '/') - { - len--; - subdir=SUBDIR; - } - if (len == 0) continue; - for (cur=&head; *cur; cur=&((*cur)->next_link)) - { - if (!strncmp((*cur)->str, start, len)) - { - if ((*cur)->flags & todo) /* same action ? */ - (*cur)->flags|= subdir; /* just merge the SUBDIR flag */ - else if (todo == EXCLUDE) - { - struct link *delme=*cur; - *cur=(*cur)->next_link; - free((void*) delme); - } - else - { - (*cur)->flags&=~(EXCLUDE | SUBDIR); - (*cur)->flags|=INCLUDE | subdir; - } - goto next; - } - } - *cur= (struct link *) DbugMalloc(sizeof(struct link)+len); - memcpy((*cur)->str, start, len); - (*cur)->str[len]=0; - (*cur)->flags=todo | subdir; - (*cur)->next_link=0; - } - return head; -} - -/* - * FUNCTION - * - * ListCopy make a copy of the list - * - * SYNOPSIS - * - * static struct link *ListCopy(orig) - * struct link *orig; - * - * DESCRIPTION - * - * Given pointer to list, which contains a copy of every element from - * the original list. - * - * the orig pointer can be NULL - * - * Note that since each link is added at the head of the list, - * the final list will be in "reverse order", which is not - * significant for our usage here. - * - */ - -static struct link *ListCopy(struct link *orig) -{ - struct link *new_malloc; - struct link *head; - size_t len; - - head= NULL; - while (orig != NULL) - { - len= strlen(orig->str); - new_malloc= (struct link *) DbugMalloc(sizeof(struct link)+len); - memcpy(new_malloc->str, orig->str, len); - new_malloc->str[len]= 0; - new_malloc->flags=orig->flags; - new_malloc->next_link= head; - head= new_malloc; - orig= orig->next_link; - } - return head; -} - -/* - * FUNCTION - * - * InList test a given string for member of a given list - * - * DESCRIPTION - * - * Tests the string pointed to by "cp" to determine if it is in - * the list pointed to by "linkp". Linkp points to the first - * link in the list. If linkp is NULL or contains only EXCLUDE - * elements then the string is treated as if it is in the list. - * This may seem rather strange at first but leads to the desired - * operation if no list is given. The net effect is that all - * strings will be accepted when there is no list, and when there - * is a list, only those strings in the list will be accepted. - * - * RETURN - * combination of SUBDIR, INCLUDE, EXCLUDE, MATCHED flags - * - */ - -static int InList(struct link *linkp, const char *cp) -{ - int result; - - for (result=MATCHED; linkp != NULL; linkp= linkp->next_link) - { - if (!fnmatch(linkp->str, cp, 0)) - return linkp->flags; - if (!(linkp->flags & EXCLUDE)) - result=NOT_MATCHED; - if (linkp->flags & SUBDIR) - result|=SUBDIR; - } - return result; -} - -/* - * FUNCTION - * - * ListFlags returns aggregated list flags (ORed over all elements) - * - */ - -static uint ListFlags(struct link *linkp) -{ - uint f; - for (f=0; linkp != NULL; linkp= linkp->next_link) - f|= linkp->flags; - return f; -} - -/* - * FUNCTION - * - * PushState push current settings onto stack and set up new one - * - * SYNOPSIS - * - * static VOID PushState() - * - * DESCRIPTION - * - * Pushes the current settings on the settings stack, and creates - * a new settings. The new settings is NOT initialized - * - * The settings stack is a linked list of settings, with the new - * settings added at the head. This allows the stack to grow - * to the limits of memory if necessary. - * - */ - -static void PushState(CODE_STATE *cs) -{ - struct settings *new_malloc; - - new_malloc= (struct settings *) DbugMalloc(sizeof(struct settings)); - memset(new_malloc, 0, sizeof(struct settings)); - new_malloc->next= cs->stack; - cs->stack= new_malloc; -} - -/* - * FUNCTION - * - * FreeState Free memory associated with a struct state. - * - * SYNOPSIS - * - * static void FreeState (state) - * struct state *state; - * int free_state; - * - * DESCRIPTION - * - * Deallocates the memory allocated for various information in a - * state. If free_state is set, also free 'state' - * - */ -static void FreeState(CODE_STATE *cs, struct settings *state, int free_state) -{ - if (!is_shared(state, keywords)) - FreeList(state->keywords); - if (!is_shared(state, functions)) - FreeList(state->functions); - if (!is_shared(state, processes)) - FreeList(state->processes); - if (!is_shared(state, p_functions)) - FreeList(state->p_functions); - - if (!is_shared(state, out_file)) - DBUGCloseFile(cs, state->out_file); - else - (void) fflush(state->out_file); - - if (!is_shared(state, prof_file)) - DBUGCloseFile(cs, state->prof_file); - else - (void) fflush(state->prof_file); - - if (free_state) - free((void*) state); -} - - -/* - * FUNCTION - * - * _db_end_ End debugging, freeing state stack memory. - * - * SYNOPSIS - * - * static VOID _db_end_ () - * - * DESCRIPTION - * - * Ends debugging, de-allocating the memory allocated to the - * state stack. - * - * To be called at the very end of the program. - * - */ -void _db_end_() -{ - struct settings *discard; - static struct settings tmp; - CODE_STATE *cs; - /* - Set _dbug_on_ to be able to do full reset even when DEBUGGER_OFF was - called after dbug was initialized - */ - _dbug_on_= 1; - get_code_state_or_return; - - /* - The caller may have missed a DBUG_UNLOCK_FILE, - we are breaking this lock to enforce DBUG_END can proceed. - */ - if (cs->locked) - { - fprintf(stderr, ERR_MISSING_UNLOCK, "(unknown)"); - cs->locked= 0; - pthread_mutex_unlock(&THR_LOCK_dbug); - } - - while ((discard= cs->stack)) - { - if (discard == &init_settings) - break; - cs->stack= discard->next; - FreeState(cs, discard, 1); - } - - pthread_mutex_lock(&THR_LOCK_init_settings); - tmp= init_settings; - init_settings.flags= OPEN_APPEND; - init_settings.out_file= stderr; - init_settings.prof_file= stderr; - init_settings.maxdepth= 0; - init_settings.delay= 0; - init_settings.sub_level= 0; - init_settings.functions= 0; - init_settings.p_functions= 0; - init_settings.keywords= 0; - init_settings.processes= 0; - pthread_mutex_unlock(&THR_LOCK_init_settings); - FreeState(cs, &tmp, 0); -} - - -/* - * FUNCTION - * - * DoTrace check to see if tracing is current enabled - * - * DESCRIPTION - * - * Checks to see if dbug in this function is enabled based on - * whether the maximum trace depth has been reached, the current - * function is selected, and the current process is selected. - * - */ - -static int DoTrace(CODE_STATE *cs) -{ - if ((cs->stack->maxdepth == 0 || cs->level <= cs->stack->maxdepth) && - InList(cs->stack->processes, cs->process) & (MATCHED|INCLUDE)) - switch(InList(cs->stack->functions, cs->func)) { - case INCLUDE|SUBDIR: return ENABLE_TRACE; - case INCLUDE: return DO_TRACE; - case MATCHED|SUBDIR: - case NOT_MATCHED|SUBDIR: - case MATCHED: return (framep_trace_flag(cs, cs->framep)) ? - DO_TRACE : DONT_TRACE; - case EXCLUDE: - case NOT_MATCHED: return DONT_TRACE; - case EXCLUDE|SUBDIR: return DISABLE_TRACE; - } - return DONT_TRACE; -} - -FILE *_db_fp_(void) -{ - CODE_STATE *cs; - get_code_state_or_return NULL; - return cs->stack->out_file; -} - -/* - * FUNCTION - * - * _db_keyword_ test keyword for member of keyword list - * - * DESCRIPTION - * - * Test a keyword to determine if it is in the currently active - * keyword list. If strict=0, a keyword is accepted - * if the list is null, otherwise it must match one of the list - * members. When debugging is not on, no keywords are accepted. - * After the maximum trace level is exceeded, no keywords are - * accepted (this behavior subject to change). Additionally, - * the current function and process must be accepted based on - * their respective lists. - * - * Returns TRUE if keyword accepted, FALSE otherwise. - * - */ - -BOOLEAN _db_keyword_(CODE_STATE *cs, const char *keyword, int strict) -{ - BOOLEAN result; - get_code_state_if_not_set_or_return FALSE; - - /* Dirty read, for DBUG_EXECUTE(), DBUG_EXECUTE_IF() ... performance. */ - if (! DEBUGGING) - return FALSE; - - read_lock_stack(cs); - - strict=strict ? INCLUDE : INCLUDE|MATCHED; - result= DoTrace(cs) & DO_TRACE && - InList(cs->stack->keywords, keyword) & strict; - - unlock_stack(cs); - - return result; -} - -/* - * FUNCTION - * - * Indent indent a line to the given indentation level - * - * SYNOPSIS - * - * static VOID Indent(indent) - * int indent; - * - * DESCRIPTION - * - * Indent a line to the given level. Note that this is - * a simple minded but portable implementation. - * There are better ways. - * - * Also, the indent must be scaled by the compile time option - * of character positions per nesting level. - * - */ - -static void Indent(CODE_STATE *cs, int indent) -{ - int count; - - indent= MAX(indent-1-cs->stack->sub_level,0)*INDENT; - for (count= 0; count < indent ; count++) - { - if ((count % INDENT) == 0) - fputc('|',cs->stack->out_file); - else - fputc(' ',cs->stack->out_file); - } -} - - -/* - * FUNCTION - * - * FreeList free all memory associated with a linked list - * - * SYNOPSIS - * - * static VOID FreeList(linkp) - * struct link *linkp; - * - * DESCRIPTION - * - * Given pointer to the head of a linked list, frees all - * memory held by the list and the members of the list. - * - */ - -static void FreeList(struct link *linkp) -{ - struct link *old; - - while (linkp != NULL) - { - old= linkp; - linkp= linkp->next_link; - free((void*) old); - } -} - - -/* - * FUNCTION - * - * DoPrefix print debugger line prefix prior to indentation - * - * SYNOPSIS - * - * static VOID DoPrefix(_line_) - * int _line_; - * - * DESCRIPTION - * - * Print prefix common to all debugger output lines, prior to - * doing indentation if necessary. Print such information as - * current process name, current source file name and line number, - * and current function nesting depth. - * - */ - -static void DoPrefix(CODE_STATE *cs, uint _line_) -{ - cs->lineno++; - if (cs->stack->flags & PID_ON) - { - (void) fprintf(cs->stack->out_file, "%-7s: ", ma_thread_name()); - } - if (cs->stack->flags & NUMBER_ON) - (void) fprintf(cs->stack->out_file, "%5d: ", cs->lineno); - if (cs->stack->flags & TIMESTAMP_ON) - { -#ifdef _WIN32 - /* FIXME This doesn't give microseconds as in Unix case, and the resolution is - in system ticks, 10 ms intervals. See my_getsystime.c for high res */ - SYSTEMTIME loc_t; - GetLocalTime(&loc_t); - (void) fprintf (cs->stack->out_file, - /* "%04d-%02d-%02d " */ - "%02d:%02d:%02d.%06d ", - /*tm_p->tm_year + 1900, tm_p->tm_mon + 1, tm_p->tm_mday,*/ - loc_t.wHour, loc_t.wMinute, loc_t.wSecond, loc_t.wMilliseconds); -#else - struct timeval tv; - struct tm *tm_p; - if (gettimeofday(&tv, NULL) != -1) - { - if ((tm_p= localtime((const time_t *)&tv.tv_sec))) - { - (void) fprintf (cs->stack->out_file, - /* "%04d-%02d-%02d " */ - "%02d:%02d:%02d.%06d ", - /*tm_p->tm_year + 1900, tm_p->tm_mon + 1, tm_p->tm_mday,*/ - tm_p->tm_hour, tm_p->tm_min, tm_p->tm_sec, - (int) (tv.tv_usec)); - } - } -#endif - } - if (cs->stack->flags & PROCESS_ON) - (void) fprintf(cs->stack->out_file, "%s: ", cs->process); - if (cs->stack->flags & FILE_ON) - (void) fprintf(cs->stack->out_file, "%14s: ", BaseName(cs->file)); - if (cs->stack->flags & LINE_ON) - (void) fprintf(cs->stack->out_file, "%5d: ", _line_); - if (cs->stack->flags & DEPTH_ON) - (void) fprintf(cs->stack->out_file, "%4d: ", cs->level); -} - - -/* - * FUNCTION - * - * DBUGOpenFile open new output stream for debugger output - * - * SYNOPSIS - * - * static VOID DBUGOpenFile(name) - * char *name; - * - * DESCRIPTION - * - * Given name of a new file (or "-" for stdout) opens the file - * and sets the output stream to the new file. - * - */ - -static void DBUGOpenFile(CODE_STATE *cs, - const char *name,const char *end,int append) -{ - FILE *fp; - - if (name != NULL) - { - if (end) - { - size_t len=end-name; - memcpy(cs->stack->name, name, len); - cs->stack->name[len]=0; - } - else - strcpy(cs->stack->name,name); - name=cs->stack->name; - if (strcmp(name, "-") == 0) - { - cs->stack->out_file= stdout; - cs->stack->flags |= FLUSH_ON_WRITE; - cs->stack->name[0]=0; - } - else - { - if (!Writable(name)) - { - (void) fprintf(stderr, ERR_OPEN, cs->process, name); - perror(""); - fflush(stderr); - } - else - { -#ifdef _WIN32 - if (fopen_s(&fp, name, append ? "a+" : "w")) -#else - if (!(fp= fopen(name, append ? "a+" : "w"))) -#endif - { - (void) fprintf(stderr, ERR_OPEN, cs->process, name); - perror(""); - fflush(stderr); - } - else - { - cs->stack->out_file= fp; - } - } - } - } -} - -/* - * FUNCTION - * - * DBUGCloseFile close the debug output stream - * - * SYNOPSIS - * - * static VOID DBUGCloseFile(fp) - * FILE *fp; - * - * DESCRIPTION - * - * Closes the debug output stream unless it is standard output - * or standard error. - * - */ - -static void DBUGCloseFile(CODE_STATE *cs, FILE *fp) -{ - if (fp != NULL && fp != stderr && fp != stdout && fclose(fp) == EOF) - { - pthread_mutex_lock(&THR_LOCK_dbug); - (void) fprintf(cs->stack->out_file, ERR_CLOSE, cs->process); - perror(""); - DbugFlush(cs); - } -} - - -/* - * FUNCTION - * - * DbugExit print error message and exit - * - * SYNOPSIS - * - * static VOID DbugExit(why) - * char *why; - * - * DESCRIPTION - * - * Prints error message using current process name, the reason for - * aborting (typically out of memory), and exits with status 1. - * This should probably be changed to use a status code - * defined in the user's debugger include file. - * - */ - -static void DbugExit(const char *why) -{ - CODE_STATE *cs=code_state(); - (void) fprintf(stderr, ERR_ABORT, cs ? cs->process : "(null)", why); - (void) fflush(stderr); - DBUG_ABORT(); -} - - -/* - * FUNCTION - * - * DbugMalloc allocate memory for debugger runtime support - * - * SYNOPSIS - * - * static long *DbugMalloc(size) - * int size; - * - * DESCRIPTION - * - * Allocate more memory for debugger runtime support functions. - * Failure to to allocate the requested number of bytes is - * immediately fatal to the current process. This may be - * rather unfriendly behavior. It might be better to simply - * print a warning message, freeze the current debugger cs, - * and continue execution. - * - */ - -static char *DbugMalloc(size_t size) -{ - char *new_malloc; - - if (!(new_malloc= (char*) malloc(size))) - DbugExit("out of memory"); - return new_malloc; -} - - -/* - * strtok lookalike - splits on ':', magically handles ::, :\ and :/ - */ - -static const char *DbugStrTok(const char *s) -{ - while (s[0] && (s[0] != ':' || - (s[1] == '\\' || s[1] == '/' || (s[1] == ':' && s++)))) - s++; - return s; -} - - -/* - * FUNCTION - * - * BaseName strip leading pathname components from name - * - * SYNOPSIS - * - * static char *BaseName(pathname) - * char *pathname; - * - * DESCRIPTION - * - * Given pointer to a complete pathname, locates the base file - * name at the end of the pathname and returns a pointer to - * it. - * - */ - -static const char *BaseName(const char *pathname) -{ - const char *base; - - base= strrchr(pathname, FN_LIBCHAR); - if (base++ == NullS) - base= pathname; - return base; -} - - -/* - * FUNCTION - * - * Writable test to see if a pathname is writable/creatable - * - * SYNOPSIS - * - * static BOOLEAN Writable(pathname) - * char *pathname; - * - * DESCRIPTION - * - * Because the debugger might be linked in with a program that - * runs with the set-uid-bit (suid) set, we have to be careful - * about opening a user named file for debug output. This consists - * of checking the file for write access with the real user id, - * or checking the directory where the file will be created. - * - * Returns TRUE if the user would normally be allowed write or - * create access to the named file. Returns FALSE otherwise. - * - */ - - -#ifndef Writable - -static BOOLEAN Writable(const char *pathname) -{ - BOOLEAN granted; - char *lastslash; - - granted= FALSE; - if (EXISTS(pathname)) - { - if (WRITABLE(pathname)) - granted= TRUE; - } - else - { - lastslash= strrchr(pathname, '/'); - if (lastslash != NULL) - *lastslash= '\0'; - else - pathname= "."; - if (WRITABLE(pathname)) - granted= TRUE; - if (lastslash != NULL) - *lastslash= '/'; - } - return granted; -} -#endif - - -/* - * FUNCTION - * - * _db_setjmp_ save debugger environment - * - * SYNOPSIS - * - * VOID _db_setjmp_() - * - * DESCRIPTION - * - * Invoked as part of the user's DBUG_SETJMP macro to save - * the debugger environment in parallel with saving the user's - * environment. - * - */ - -#ifdef HAVE_LONGJMP - -EXPORT void _db_setjmp_() -{ - CODE_STATE *cs; - get_code_state_or_return; - - cs->jmplevel= cs->level; - cs->jmpfunc= cs->func; - cs->jmpfile= cs->file; -} - -/* - * FUNCTION - * - * _db_longjmp_ restore previously saved debugger environment - * - * SYNOPSIS - * - * VOID _db_longjmp_() - * - * DESCRIPTION - * - * Invoked as part of the user's DBUG_LONGJMP macro to restore - * the debugger environment in parallel with restoring the user's - * previously saved environment. - * - */ - -EXPORT void _db_longjmp_() -{ - CODE_STATE *cs; - get_code_state_or_return; - - cs->level= cs->jmplevel; - if (cs->jmpfunc) - cs->func= cs->jmpfunc; - if (cs->jmpfile) - cs->file= cs->jmpfile; -} -#endif - -/* - * FUNCTION - * - * perror perror simulation for systems that don't have it - * - * SYNOPSIS - * - * static VOID perror(s) - * char *s; - * - * DESCRIPTION - * - * Perror produces a message on the standard error stream which - * provides more information about the library or system error - * just encountered. The argument string s is printed, followed - * by a ':', a blank, and then a message and a newline. - * - * An undocumented feature of the unix perror is that if the string - * 's' is a null string (NOT a NULL pointer!), then the ':' and - * blank are not printed. - * - * This version just complains about an "unknown system error". - * - */ - -#ifndef HAVE_PERROR -static void perror(s) -char *s; -{ - if (s && *s != '\0') - (void) fprintf(stderr, "%s: ", s); - (void) fprintf(stderr, "\n"); -} -#endif /* HAVE_PERROR */ - - - /* flush dbug-stream, free mutex lock & wait delay */ - /* This is because some systems (MSDOS!!) dosn't flush fileheader */ - /* and dbug-file isn't readable after a system crash !! */ - -static void DbugFlush(CODE_STATE *cs) -{ - if (cs->stack->flags & FLUSH_ON_WRITE) - { - (void) fflush(cs->stack->out_file); - if (cs->stack->delay) - (void) Delay(cs->stack->delay); - } - if (!cs->locked) - pthread_mutex_unlock(&THR_LOCK_dbug); -} /* DbugFlush */ - - -/* For debugging */ - -void _db_flush_() -{ - CODE_STATE *cs= NULL; - get_code_state_or_return; - (void) fflush(cs->stack->out_file); -} - - -#ifndef _WIN32 - -#ifdef HAVE_GCOV -extern void __gcov_flush(); -#endif - -void _db_flush_gcov_() -{ -#ifdef HAVE_GCOV - // Gcov will assert() if we try to flush in parallel. - pthread_mutex_lock(&THR_LOCK_gcov); - __gcov_flush(); - pthread_mutex_unlock(&THR_LOCK_gcov); -#endif -} - -void _db_suicide_() -{ - int retval; - sigset_t new_mask; - sigfillset(&new_mask); - -#ifdef HAVE_GCOV - fprintf(stderr, "Flushing gcov data\n"); - fflush(stderr); - _db_flush_gcov_(); -#endif - - fprintf(stderr, "SIGKILL myself\n"); - fflush(stderr); - - retval= kill(getpid(), SIGKILL); - assert(retval == 0); - retval= sigsuspend(&new_mask); - fprintf(stderr, "sigsuspend returned %d errno %d \n", retval, errno); - assert(FALSE); /* With full signal mask, we should never return here. */ -} -#endif /* ! _WIN32 */ - - -void _db_lock_file_() -{ - CODE_STATE *cs; - get_code_state_or_return; - pthread_mutex_lock(&THR_LOCK_dbug); - cs->locked=1; -} - -void _db_unlock_file_() -{ - CODE_STATE *cs; - get_code_state_or_return; - cs->locked=0; - pthread_mutex_unlock(&THR_LOCK_dbug); -} - -const char* _db_get_func_(void) -{ - CODE_STATE *cs; - get_code_state_or_return NULL; - return cs->func; -} - - -#else - -/* - * Dummy function, workaround for MySQL bug#14420 related - * build failure on a platform where linking with an empty - * archive fails. - * - * This block can be removed as soon as a fix for bug#14420 - * is implemented. - */ -int i_am_a_dummy_function() { - return 0; -} - -#endif diff --git a/libmariadb/default.c b/libmariadb/default.c deleted file mode 100644 index bdeafa00..00000000 --- a/libmariadb/default.c +++ /dev/null @@ -1,442 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/**************************************************************************** -** Add all options from files named "group".cnf from the default_directories -** before the command line arguments. -** On Windows defaults will also search in the Windows directory for a file -** called 'group'.ini -** As long as the program uses the last argument for conflicting -** options one only have to add a call to "mariadb_load_defaults" to enable -** use of default values. -** pre- and end 'blank space' are removed from options and values. The -** following escape sequences are recognized in values: \b \t \n \r \\ -** -** The following arguments are handled automaticly; If used, they must be -** first argument on the command line! -** --no-defaults ; no options are read. -** --defaults-file=full-path-to-default-file ; Only this file will be read. -** --defaults-extra-file=full-path-to-default-file ; Read this file before ~/ -** --print-defaults ; Print the modified command line and exit -****************************************************************************/ - -#undef SAFEMALLOC /* safe_malloc is not yet initailized */ - -#include "mysys_priv.h" -#include "m_string.h" -#include -#include "mariadb_ctype.h" -#include -#include -#include - -char *defaults_extra_file=0; - -/* Which directories are searched for options (and in which order) */ - -const char *default_directories[]= { -#ifdef _WIN32 -"C:/", -#else -"/etc/", -#endif -#ifdef DATADIR -DATADIR, -#endif -"", /* Place for defaults_extra_dir */ -#ifndef _WIN32 -"~/", -#endif -NullS, -}; - -#define default_ext ".cnf" /* extension for config file */ -#ifdef _WIN32 -#include -#define windows_ext ".ini" -#endif - -static my_bool search_default_file(DYNAMIC_ARRAY *args,MA_MEM_ROOT *alloc, - const char *dir, const char *config_file, - const char *ext, TYPELIB *group); - - -void mariadb_load_defaults(const char *conf_file, const char **groups, - int *argc, char ***argv) -{ - DYNAMIC_ARRAY args; - const char **dirs, *forced_default_file; - TYPELIB group; - my_bool found_ma_print_defaults=0; - uint args_used=0; - MA_MEM_ROOT alloc; - char *ptr,**res; - DBUG_ENTER("mariadb_load_defaults"); - - ma_init_ma_alloc_root(&alloc,128,0); - if (*argc >= 2 && !strcmp(argv[0][1],"--no-defaults")) - { - /* remove the --no-defaults argument and return only the other arguments */ - uint i; - if (!(ptr=(char*) ma_alloc_root(&alloc,sizeof(alloc)+ - (*argc + 1)*sizeof(char*)))) - goto err; - res= (char**) (ptr+sizeof(alloc)); - res[0]= **argv; /* Copy program name */ - for (i=2 ; i < (uint) *argc ; i++) - res[i-1]=argv[0][i]; - (*argc)--; - *argv=res; - *(MA_MEM_ROOT*) ptr= alloc; /* Save alloc root for free */ - DBUG_VOID_RETURN; - } - - /* Check if we want to force the use a specific default file */ - forced_default_file=0; - if (*argc >= 2) - { - if (is_prefix(argv[0][1],"--defaults-file=")) - { - forced_default_file=strchr(argv[0][1],'=')+1; - args_used++; - } - else if (is_prefix(argv[0][1],"--defaults-extra-file=")) - { - defaults_extra_file=strchr(argv[0][1],'=')+1; - args_used++; - } - } - - group.count=0; - group.name= "defaults"; - group.type_names= groups; - for (; *groups ; groups++) - group.count++; - - if (ma_init_dynamic_array(&args, sizeof(char*),*argc, 32)) - goto err; - if (forced_default_file) - { - if (search_default_file(&args, &alloc, "", forced_default_file, "", - &group)) - goto err; - } - else if (ma_dirname_length(conf_file)) - { - if (search_default_file(&args, &alloc, NullS, conf_file, default_ext, - &group)) - goto err; - } - else - { -#ifdef _WIN32 - char system_dir[FN_REFLEN]; - GetWindowsDirectory(system_dir,sizeof(system_dir)); - if (search_default_file(&args, &alloc, system_dir, conf_file, windows_ext, - &group)) - goto err; -#endif -#if defined(__EMX__) || defined(OS2) - if (getenv("ETC") && - search_default_file(&args, &alloc, getenv("ETC"), conf_file, - default_ext, &group)) - goto err; -#endif - for (dirs=default_directories ; *dirs; dirs++) - { - int error=0; - if (**dirs) - error=search_default_file(&args, &alloc, *dirs, conf_file, - default_ext, &group); - else if (defaults_extra_file) - error=search_default_file(&args, &alloc, NullS, defaults_extra_file, - default_ext, &group); - if (error) - goto err; - } - } - if (!(ptr=(char*) ma_alloc_root(&alloc,sizeof(alloc)+ - (args.elements + *argc +1) *sizeof(char*)))) - goto err; - res= (char**) (ptr+sizeof(alloc)); - - /* copy name + found arguments + command line arguments to new array */ - res[0]=argv[0][0]; - memcpy((gptr) (res+1), args.buffer, args.elements*sizeof(char*)); - /* Skipp --defaults-file and --defaults-extra-file */ - (*argc)-= args_used; - (*argv)+= args_used; - - /* Check if we wan't to see the new argument list */ - if (*argc >= 2 && !strcmp(argv[0][1],"--print-defaults")) - { - found_ma_print_defaults=1; - --*argc; ++*argv; /* skipp argument */ - } - - memcpy((gptr) (res+1+args.elements), (char*) ((*argv)+1), - (*argc-1)*sizeof(char*)); - res[args.elements+ *argc]=0; /* last null */ - - (*argc)+=args.elements; - *argv= (char**) res; - *(MA_MEM_ROOT*) ptr= alloc; /* Save alloc root for free */ - ma_delete_dynamic(&args); - if (found_ma_print_defaults) - { - int i; - printf("%s would have been started with the following arguments:\n", - **argv); - for (i=1 ; i < *argc ; i++) - printf("%s ", (*argv)[i]); - puts(""); - exit(1); - } - DBUG_VOID_RETURN; - - err: - fprintf(stderr,"Program aborted\n"); - exit(1); -} - - -void ma_free_defaults(char **argv) -{ - MA_MEM_ROOT ptr; - memcpy_fixed((char*) &ptr,(char *) argv - sizeof(ptr), sizeof(ptr)); - ma_free_root(&ptr,MYF(0)); -} - - -static my_bool search_default_file(DYNAMIC_ARRAY *args, MA_MEM_ROOT *alloc, - const char *dir, const char *config_file, - const char *ext, TYPELIB *group) -{ - char name[FN_REFLEN+10],buff[4096],*ptr,*end,*value,*tmp; - MA_FILE *file; - uint line=0; - my_bool read_values= 0, found_group= 0, is_escaped= 0, is_quoted= 0; - - if (!strstr(config_file, "://")) - { - if ((dir ? strlen(dir) : 0 )+strlen(config_file) >= FN_REFLEN-3) - return 0; /* Ignore wrong paths */ - if (dir) - { - strcpy(name,dir); - ma_convert_dirname(name); - if (dir[0] == FN_HOMELIB) /* Add . to filenames in home */ - strcat(name,"."); - strcat(strcat(name, config_file), ext); - } - else - { - strcpy(name,config_file); - } - ma_fn_format(name,name,"","",4); -#if !defined(_WIN32) && !defined(OS2) - { - MY_STAT stat_info; - if (!my_stat(name,&stat_info,MYF(0))) - return 0; - if (stat_info.st_mode & S_IWOTH) /* ignore world-writeable files */ - { - fprintf(stderr, "warning: World-writeable config file %s is ignored\n", - name); - return 0; - } - } -#endif - if (!(file = ma_open(name,"r", NULL))) - return 0; - } - else { - if (!(file = ma_open(config_file, "r", NULL))) - return 0; - } - - while (ma_gets(buff,sizeof(buff)-1,file)) - { - line++; - /* Ignore comment and empty lines */ - for (ptr=buff ; isspace(*ptr) ; ptr++ ); - if (!is_escaped && (*ptr == '\"' || *ptr== '\'')) - { - is_quoted= !is_quoted; - continue; - } - if (*ptr == '#' || *ptr == ';' || !*ptr) - continue; - is_escaped= (*ptr == '\\'); - if (*ptr == '[') /* Group name */ - { - found_group=1; - if (!(end=(char *) strchr(++ptr,']'))) - { - fprintf(stderr, - "error: Wrong group definition in config file: %s at line %d\n", - name,line); - goto err; - } - for ( ; isspace(end[-1]) ; end--) ; /* Remove end space */ - end[0]=0; - read_values=ma_find_type(ptr,group,3) > 0; - continue; - } - if (!found_group) - { - fprintf(stderr, - "error: Found option without preceding group in config file: %s at line: %d\n", - name,line); - goto err; - } - if (!read_values) - continue; - if (!(end=value=strchr(ptr,'='))) - end=strchr(ptr, '\0'); /* Option without argument */ - for ( ; isspace(end[-1]) ; end--) ; - if (!value) - { - if (!(tmp=ma_alloc_root(alloc,(uint) (end-ptr)+3))) - goto err; - strncpy(strmov(tmp,"--"),ptr,(uint) (end-ptr)); - if (ma_insert_dynamic(args,(gptr) &tmp)) - goto err; - } - else - { - /* Remove pre- and end space */ - char *value_end; - for (value++ ; isspace(*value); value++) ; - value_end=strchr(value, '\0'); - 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; - if (!(tmp=ma_alloc_root(alloc,(uint) (end-ptr)+3 + - (uint) (value_end-value)+1))) - goto err; - if (ma_insert_dynamic(args,(gptr) &tmp)) - goto err; - ptr=strnmov(strmov(tmp,"--"),ptr,(uint) (end-ptr)); - *ptr++= '='; - 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; - } - } - ma_close(file); - return(0); - - err: - ma_close(file); - return 1; -} - - -void ma_print_defaults(const char *conf_file, const char **groups) -{ -#ifdef _WIN32 - bool have_ext=ma_fn_ext(conf_file)[0] != 0; -#endif - char name[FN_REFLEN]; - const char **dirs; - puts("\nDefault options are read from the following files in the given order:"); - - if (ma_dirname_length(conf_file)) - fputs(conf_file,stdout); - else - { -#ifdef _WIN32 - GetWindowsDirectory(name,sizeof(name)); - printf("%s\\%s%s ",name,conf_file,have_ext ? "" : windows_ext); -#endif -#if defined(__EMX__) || defined(OS2) - if (getenv("ETC")) - printf("%s\\%s%s ", getenv("ETC"), conf_file, default_ext); -#endif - for (dirs=default_directories ; *dirs; dirs++) - { - if (**dirs) - strcpy(name,*dirs); - else if (defaults_extra_file) - strcpy(name,defaults_extra_file); - else - continue; - ma_convert_dirname(name); - if (name[0] == FN_HOMELIB) /* Add . to filenames in home */ - strcat(name,"."); - strcat(strcat(strcat(name, conf_file), default_ext), " "); - fputs(name,stdout); - } - puts(""); - } - fputs("The following groups are read:",stdout); - for ( ; *groups ; groups++) - { - fputc(' ',stdout); - fputs(*groups,stdout); - } - puts("\nThe following options may be given as the first argument:\n\ ---print-defaults Print the program argument list and exit\n\ ---no-defaults Don't read default options from any options file\n\ ---defaults-file=# Only read default options from the given file #\n\ ---defaults-extra-file=# Read this file after the global files are read"); -} - diff --git a/libmariadb/errors.c b/libmariadb/errors.c deleted file mode 100644 index 7a68d3b6..00000000 --- a/libmariadb/errors.c +++ /dev/null @@ -1,96 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include "mysys_err.h" - -#ifndef SHARED_LIBRARY - -const char * NEAR ma_globerrs[GLOBERRS]= -{ - "Can't create/write to file '%s' (Errcode: %d)", - "Error reading file '%s' (Errcode: %d)", - "Error writing file '%s' (Errcode: %d)", - "Error on close of '%s' (Errcode: %d)", - "Out of memory (Needed %u bytes)", - "Error on delete of '%s' (Errcode: %d)", - "Error on rename of '%s' to '%s' (Errcode: %d)", - "", - "Unexpected eof found when reading file '%s' (Errcode: %d)", - "Can't lock file (Errcode: %d)", - "Can't unlock file (Errcode: %d)", - "Can't read dir of '%s' (Errcode: %d)", - "Can't get stat of '%s' (Errcode: %d)", - "Can't change size of file (Errcode: %d)", - "Can't open stream from handle (Errcode: %d)", - "Can't get working dirctory (Errcode: %d)", - "Can't change dir to '%s' (Errcode: %d)", - "Warning: '%s' had %d links", - "Warning: %d files and %d streams is left open\n", - "Disk is full writing '%s' (Errcode: %d). Waiting for someone to free space... (Expect up to %d secs delay for server to continue after freeing disk space)", - "Can't create directory '%s' (Errcode: %d)", - "Character set '%s' is not a compiled character set and is not specified in the '%s' file", - "Out of resources when opening file '%s' (Errcode: %d)", - "Can't read value for symlink '%s' (Error %d)", - "Can't create symlink '%s' pointing at '%s' (Error %d)", - "Error on realpath() on '%s' (Error %d)", - "Can't sync file '%s' to disk (Errcode: %d)", - "Collation '%s' is not a compiled collation and is not specified in the '%s' file", - "File '%s' not found (Errcode: %d)", - "File '%s' (fileno: %d) was not closed", - "Can't change mode for file '%s' to 0x%lx (Error: %d)" -}; - -void ma_init_glob_errs(void) -{ - my_errmsg[GLOB] = & ma_globerrs[0]; -} /* ma_init_glob_errs */ - -#else - -void ma_init_glob_errs() -{ - my_errmsg[GLOB] = & ma_globerrs[0]; - - EE(EE_FILENOTFOUND) = "File '%s' not found (Errcode: %d)"; - EE(EE_CANTCREATEFILE) = "Can't create/write to file '%s' (Errcode: %d)"; - EE(EE_READ) = "Error reading file '%s' (Errcode: %d)"; - EE(EE_WRITE) = "Error writing file '%s' (Errcode: %d)"; - EE(EE_BADCLOSE) = "Error on close of '%'s (Errcode: %d)"; - EE(EE_OUTOFMEMORY) = "Out of memory (Needed %u bytes)"; - EE(EE_DELETE) = "Error on delete of '%s' (Errcode: %d)"; - EE(EE_LINK) = "Error on rename of '%s' to '%s' (Errcode: %d)"; - EE(EE_EOFERR) = "Unexpected eof found when reading file '%s' (Errcode: %d)"; - EE(EE_CANTLOCK) = "Can't lock file (Errcode: %d)"; - EE(EE_CANTUNLOCK) = "Can't unlock file (Errcode: %d)"; - EE(EE_DIR) = "Can't read dir of '%s' (Errcode: %d)"; - EE(EE_STAT) = "Can't get stat of '%s' (Errcode: %d)"; - EE(EE_CANT_CHSIZE) = "Can't change size of file (Errcode: %d)"; - EE(EE_CANT_OPEN_STREAM)= "Can't open stream from handle (Errcode: %d)"; - EE(EE_GETWD) = "Can't get working dirctory (Errcode: %d)"; - EE(EE_SETWD) = "Can't change dir to '%s' (Errcode: %d)"; - EE(EE_LINK_WARNING) = "Warning: '%s' had %d links"; - EE(EE_OPEN_WARNING) = "%d files and %d streams is left open\n"; - EE(EE_DISK_FULL) = "Disk is full writing '%s'. Waiting for someone to free space..."; - EE(EE_CANT_MKDIR) ="Can't create directory '%s' (Errcode: %d)"; - EE(EE_UNKNOWN_CHARSET)= "Character set is not a compiled character set and is not specified in the %s file"; - EE(EE_OUT_OF_FILERESOURCES)="Out of resources when opening file '%s' (Errcode: %d)"; - EE(EE_CANT_READLINK)="Can't read value for symlink '%s' (Error %d)"; - EE(EE_CANT_SYMLINK)="Can't create symlink '%s' pointing at '%s' (Error %d)"; - EE(EE_REALPATH)="Error on realpath() on '%s' (Error %d)"; -} -#endif diff --git a/libmariadb/get_password.c b/libmariadb/get_password.c index 287c412a..230a38de 100644 --- a/libmariadb/get_password.c +++ b/libmariadb/get_password.c @@ -16,10 +16,10 @@ or write to the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor, Boston, MA 02110, USA *************************************************************************************/ -#include -#include +#include +#include #include "mysql.h" -#include +#include #include #include #include diff --git a/libmariadb/getopt1.c b/libmariadb/getopt1.c deleted file mode 100644 index d89f7bcc..00000000 --- a/libmariadb/getopt1.c +++ /dev/null @@ -1,170 +0,0 @@ -/* getopt_long and getopt_long_only entry points for GNU getopt. - Copyright (C) 1987, 88, 89, 90, 91, 92, 1993, 1994 - Free Software Foundation, Inc. - -This file is part of the GNU C Library. Its master source is NOT part of -the C library, however. The master source lives in /gd/gnu/lib. - -The GNU C 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. - -The GNU C 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 the GNU C Library; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include "getopt.h" - -#if (!defined (__STDC__) || !__STDC__) && !defined(MSDOS) && !defined(OS2) -/* This is a separate conditional since some stdc systems - reject `defined (const)'. */ -#ifndef const -#define const -#endif -#endif - -#include - -/* Comment out all this code if we are using the GNU C Library, and are not - actually compiling the library itself. This code is part of the GNU C - Library, but also included in many other GNU distributions. Compiling - and linking in this code is a waste when using the GNU C library - (especially if it is a shared library). Rather than having every GNU - program understand `configure --with-gnu-libc' and omit the object files, - it is simpler to just do this in the source for each such file. */ - -#if defined (_LIBC) || !defined (__GNU_LIBRARY__) - -#ifndef _WIN32 -#include -#endif /* _WIN32 */ - -#ifndef NULL -#define NULL 0 -#endif - -int -getopt_long (int argc, char *const *argv, const char *options, const struct option *long_options, int *opt_index) -{ - return _getopt_internal (argc, argv, options, long_options, opt_index, 0); -} - -/* Like getopt_long, but '-' as well as '--' can indicate a long option. - If an option that starts with '-' (not '--') doesn't match a long option, - but does match a short option, it is parsed as a short option - instead. */ - -int -getopt_long_only (int argc, char *const *argv, const char *options, const struct option *long_options, int *opt_index) -{ - return _getopt_internal (argc, argv, options, long_options, opt_index, 1); -} - - -#endif /* _LIBC or not __GNU_LIBRARY__. */ - -#ifdef TEST - -#include - -int -main (argc, argv) - int argc; - char **argv; -{ - int c; - int digit_optind = 0; - - while (1) - { - int this_option_optind = optind ? optind : 1; - int option_index = 0; - static struct option long_options[] = - { - {"add", 1, 0, 0}, - {"append", 0, 0, 0}, - {"delete", 1, 0, 0}, - {"verbose", 0, 0, 0}, - {"create", 0, 0, 0}, - {"file", 1, 0, 0}, - {0, 0, 0, 0} - }; - - c = getopt_long (argc, argv, "abc:d:0123456789", - long_options, &option_index); - if (c == EOF) - break; - - switch (c) - { - case 0: - printf ("option %s", long_options[option_index].name); - if (optarg) - printf (" with arg %s", optarg); - printf ("\n"); - break; - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", optarg); - break; - - case 'd': - printf ("option d with value `%s'\n", optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } - } - - if (optind < argc) - { - printf ("non-option ARGV-elements: "); - while (optind < argc) - printf ("%s ", argv[optind++]); - printf ("\n"); - } - - exit (0); -} - -#endif /* TEST */ diff --git a/libmariadb/int2str.c b/libmariadb/int2str.c deleted file mode 100644 index d7dd38d1..00000000 --- a/libmariadb/int2str.c +++ /dev/null @@ -1,153 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - Defines: int2str(), itoa(), ltoa() - - int2str(dst, radix, val) - converts the (long) integer "val" to character form and moves it to - the destination string "dst" followed by a terminating NUL. The - result is normally a pointer to this NUL character, but if the radix - is dud the result will be NullS and nothing will be changed. - - If radix is -2..-36, val is taken to be SIGNED. - If radix is 2.. 36, val is taken to be UNSIGNED. - That is, val is signed if and only if radix is. You will normally - use radix -10 only through itoa and ltoa, for radix 2, 8, or 16 - unsigned is what you generally want. - - _dig_vec is public just in case someone has a use for it. - The definitions of itoa and ltoa are actually macros in m_string.h, - but this is where the code is. - - Note: The standard itoa() returns a pointer to the argument, when int2str - returns the pointer to the end-null. - itoa assumes that 10 -base numbers are allways signed and other arn't. -*/ - -#include -#include "m_string.h" - -char NEAR _dig_vec[] = - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - - -char *ma_int2str(register long int val, register char *dst, register int radix) -{ - char buffer[65]; - register char *p; - long int new_val; - - if (radix < 0) { - if (radix < -36 || radix > -2) return NullS; - if (val < 0) { - *dst++ = '-'; - val = -val; - } - radix = -radix; - } else { - if (radix > 36 || radix < 2) return NullS; - } - /* The slightly contorted code which follows is due to the - fact that few machines directly support unsigned long / and %. - Certainly the VAX C compiler generates a subroutine call. In - the interests of efficiency (hollow laugh) I let this happen - for the first digit only; after that "val" will be in range so - that signed integer division will do. Sorry 'bout that. - CHECK THE CODE PRODUCED BY YOUR C COMPILER. The first % and / - should be unsigned, the second % and / signed, but C compilers - tend to be extraordinarily sensitive to minor details of style. - This works on a VAX, that's all I claim for it. - */ - p = &buffer[sizeof(buffer)-1]; - *p = '\0'; - new_val=(ulong) val / (ulong) radix; - *--p = _dig_vec[(uchar) ((ulong) val- (ulong) new_val*(ulong) radix)]; - val = new_val; -#ifdef HAVE_LDIV - while (val != 0) - { - ldiv_t res; - res=ldiv(val,radix); - *--p = _dig_vec[res.rem]; - val= res.quot; - } -#else - while (val != 0) - { - new_val=val/radix; - *--p = _dig_vec[(uchar) (val-new_val*radix)]; - val= new_val; - } -#endif - while ((*dst++ = *p++) != 0) ; - return dst-1; -} - - -/* - This is a faster version of the above optimized for the normal case of - radix 10 / -10 -*/ - -char *ma_int10_to_str(long int val, char *dst, int radix) -{ - char buffer[65]; - register char *p; - long int new_val; - unsigned long int uval= (unsigned long int)val; - - if (radix < 0 && val < 0) /* -10 */ - { - *dst++ = '-'; - uval = (unsigned long int)0-uval; - } - - p = &buffer[sizeof(buffer)-1]; - *p = '\0'; - new_val= (long)(uval / 10); - *--p = '0'+ (char)(uval - (unsigned long)new_val * 10); - val = new_val; - - while (val != 0) - { - new_val=val/10; - *--p = '0' + (char) (val-new_val*10); - val= new_val; - } - while ((*dst++ = *p++) != 0) ; - return dst-1; -} - - -#ifdef USE_MY_ITOA - - /* Change to less general itoa interface */ - -char *my_itoa(int val, char *dst, int radix) -{ - VOID(ma_int2str((long) val,dst,(radix == 10 ? -10 : radix))); - return dst; -} - -char *my_ltoa(long int val, char *dst, int radix) -{ - VOID(ma_int2str((long) val,dst,(radix == 10 ? -10 : radix))); - return dst; -} - -#endif diff --git a/libmariadb/is_prefix.c b/libmariadb/is_prefix.c deleted file mode 100644 index 5fb29f87..00000000 --- a/libmariadb/is_prefix.c +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : is_prefix.c - Author : Michael Widenius - Defines: is_prefix() - - is_prefix(s, t) returns 1 if s starts with t. - A empty t is allways a prefix. -*/ - -#include -#include "m_string.h" - -int is_prefix(register const char *s, register const char *t) -{ - while (*t) - if (*s++ != *t++) return 0; - return 1; /* WRONG */ -} diff --git a/libmariadb/longlong2str.c b/libmariadb/longlong2str.c deleted file mode 100644 index 95e4a155..00000000 --- a/libmariadb/longlong2str.c +++ /dev/null @@ -1,144 +0,0 @@ -/* 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., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - Defines: ma_longlong2str(); - - ma_longlong2str(dst, radix, val) - converts the (longlong) integer "val" to character form and moves it to - the destination string "dst" followed by a terminating NUL. The - result is normally a pointer to this NUL character, but if the radix - is dud the result will be NullS and nothing will be changed. - - If radix is -2..-36, val is taken to be SIGNED. - If radix is 2.. 36, val is taken to be UNSIGNED. - That is, val is signed if and only if radix is. You will normally - use radix -10 only through itoa and ltoa, for radix 2, 8, or 16 - unsigned is what you generally want. - - _dig_vec is public just in case someone has a use for it. - The definitions of itoa and ltoa are actually macros in m_string.h, - but this is where the code is. - - Note: The standard itoa() returns a pointer to the argument, when int2str - returns the pointer to the end-null. - itoa assumes that 10 -base numbers are allways signed and other arn't. -*/ - -#include -#include "m_string.h" - -#if defined(HAVE_LONG_LONG) && !defined(ma_longlong2str) && !defined(HAVE_LONGLONG2STR) - -extern char NEAR _dig_vec[]; - -/* - This assumes that longlong multiplication is faster than longlong division. -*/ - -char *ma_longlong2str(longlong 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 = -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; -} - -#endif - -#ifndef ma_longlong10_to_str -char *ma_longlong10_to_str(longlong val,char *dst,int radix) -{ - char buffer[65]; - register char *p; - long long_val; - - if (radix < 0) - { - if (val < 0) - { - *dst++ = '-'; - val = -val; - } - } - - 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) 10; - uint rem= (uint) (val- quo* (uint) 10); - *--p = _dig_vec[rem]; - val= quo; - } - long_val= (long) val; - while (long_val != 0) - { - long quo= long_val/10; - *--p = _dig_vec[(uchar) (long_val - quo*10)]; - long_val= quo; - } - while ((*dst++ = *p++) != 0) ; - return dst-1; -} -#endif diff --git a/libmariadb/my_alloc.c b/libmariadb/ma_alloc.c similarity index 96% rename from libmariadb/my_alloc.c rename to libmariadb/ma_alloc.c index 2616e3e7..b516179d 100644 --- a/libmariadb/my_alloc.c +++ b/libmariadb/ma_alloc.c @@ -17,9 +17,9 @@ /* Routines to handle mallocing of results which will be freed the same time */ -#include -#include -#include +#include +#include +#include void ma_init_ma_alloc_root(MA_MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size) { @@ -104,10 +104,9 @@ gptr ma_alloc_root(MA_MEM_ROOT *mem_root, size_t Size) void ma_free_root(MA_MEM_ROOT *root, myf MyFlags) { reg1 MA_USED_MEM *next,*old; - DBUG_ENTER("ma_free_root"); if (!root) - DBUG_VOID_RETURN; /* purecov: inspected */ + return; /* purecov: inspected */ if (!(MyFlags & MY_KEEP_PREALLOC)) root->pre_alloc=0; @@ -130,7 +129,7 @@ void ma_free_root(MA_MEM_ROOT *root, myf MyFlags) root->free->left=root->pre_alloc->size-ALIGN_SIZE(sizeof(MA_USED_MEM)); root->free->next=0; } - DBUG_VOID_RETURN; + return; } diff --git a/libmariadb/array.c b/libmariadb/ma_array.c similarity index 89% rename from libmariadb/array.c rename to libmariadb/ma_array.c index 659bec62..56cbbfdd 100644 --- a/libmariadb/array.c +++ b/libmariadb/ma_array.c @@ -1,4 +1,5 @@ /* 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 @@ -19,8 +20,9 @@ #undef SAFEMALLOC /* Problems with threads */ -#include "mysys_priv.h" -#include "m_string.h" +#include +#include +#include "ma_string.h" #include /* @@ -28,10 +30,9 @@ even if space allocation failed */ -my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size, - uint init_alloc, uint alloc_increment CALLER_INFO_PROTO) +my_bool ma_init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size, + uint init_alloc, uint alloc_increment CALLER_INFO_PROTO) { - DBUG_ENTER("init_dynamic_array"); if (!alloc_increment) { alloc_increment=max((8192-MALLOC_OVERHEAD)/element_size,16); @@ -48,9 +49,9 @@ my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size, if (!(array->buffer=(char*) malloc(element_size*init_alloc))) { array->max_element=0; - DBUG_RETURN(TRUE); + return(TRUE); } - DBUG_RETURN(FALSE); + return(FALSE); } @@ -116,7 +117,7 @@ my_bool ma_set_dynamic(DYNAMIC_ARRAY *array, gptr element, uint idx) array->buffer=new_ptr; array->max_element=size; } - bzero((gptr) (array->buffer+array->elements*array->size_of_element), + memset((array->buffer+array->elements*array->size_of_element), 0, (idx - array->elements)*array->size_of_element); array->elements=idx+1; } @@ -130,9 +131,7 @@ void ma_get_dynamic(DYNAMIC_ARRAY *array, gptr element, uint idx) { if (idx >= array->elements) { - DBUG_PRINT("warning",("To big array idx: %d, array size is %d", - idx,array->elements)); - bzero(element,array->size_of_element); + memset(element, 0, array->size_of_element); return; } memcpy(element,array->buffer+idx*array->size_of_element, diff --git a/libmariadb/my_charset.c b/libmariadb/ma_charset.c similarity index 98% rename from libmariadb/my_charset.c rename to libmariadb/ma_charset.c index 73c50aea..d57cc83b 100644 --- a/libmariadb/my_charset.c +++ b/libmariadb/ma_charset.c @@ -49,9 +49,9 @@ #else #include #endif -#include +#include #include -#include +#include #include @@ -670,16 +670,14 @@ const MARIADB_CHARSET_INFO mariadb_compiled_charsets[] = const MARIADB_CHARSET_INFO * mysql_find_charset_nr(unsigned int charsetnr) { const MARIADB_CHARSET_INFO * c = mariadb_compiled_charsets; - DBUG_ENTER("mysql_find_charset_nr"); do { if (c->nr == charsetnr) { - DBUG_PRINT("info", ("found character set %d %s", c->nr, c->csname)); - DBUG_RETURN(c); + return(c); } ++c; } while (c[0].nr != 0); - DBUG_RETURN(NULL); + return(NULL); } /* }}} */ @@ -688,16 +686,14 @@ const MARIADB_CHARSET_INFO * mysql_find_charset_nr(unsigned int charsetnr) MARIADB_CHARSET_INFO * mysql_find_charset_name(const char *name) { MARIADB_CHARSET_INFO *c = (MARIADB_CHARSET_INFO *)mariadb_compiled_charsets; - DBUG_ENTER("mysql_find_charset_name"); do { if (!strcasecmp(c->csname, name)) { - DBUG_PRINT("info", ("found character set %d %s", c->nr, c->csname)); - DBUG_RETURN(c); + return(c); } ++c; } while (c[0].nr != 0); - DBUG_RETURN(NULL); + return(NULL); } /* }}} */ @@ -711,8 +707,6 @@ size_t mysql_cset_escape_quotes(const MARIADB_CHARSET_INFO *cset, char *newstr, const char *end = escapestr + escapestr_len; my_bool escape_overflow = FALSE; - DBUG_ENTER("mysql_cset_escape_quotes"); - for (;escapestr < end; escapestr++) { unsigned int len = 0; /* check unicode characters */ @@ -749,9 +743,9 @@ size_t mysql_cset_escape_quotes(const MARIADB_CHARSET_INFO *cset, char *newstr, *newstr = '\0'; if (escape_overflow) { - DBUG_RETURN((size_t)~0); + return((size_t)~0); } - DBUG_RETURN((size_t)(newstr - newstr_s)); + return((size_t)(newstr - newstr_s)); } /* }}} */ @@ -765,9 +759,6 @@ size_t mysql_cset_escape_slashes(const MARIADB_CHARSET_INFO * cset, char *newstr const char *end = escapestr + escapestr_len; my_bool escape_overflow = FALSE; - DBUG_ENTER("mysql_cset_escape_slashes"); - DBUG_PRINT("info", ("charset=%s", cset->name)); - for (;escapestr < end; escapestr++) { char esc = '\0'; unsigned int len = 0; @@ -829,9 +820,9 @@ size_t mysql_cset_escape_slashes(const MARIADB_CHARSET_INFO * cset, char *newstr *newstr = '\0'; if (escape_overflow) { - DBUG_RETURN((size_t)~0); + return((size_t)~0); } - DBUG_RETURN((size_t)(newstr - newstr_s)); + return((size_t)(newstr - newstr_s)); } /* }}} */ @@ -1129,22 +1120,22 @@ int madb_get_windows_cp(const char *charset) */ static void map_charset_name(const char *cs_name, my_bool target_cs, char *buffer, size_t buff_len) { - char *ptr= buffer, digits[3], endianness[3]= "BE"; + char digits[3], endianness[3]= "BE"; if (sscanf(cs_name, "UTF%2[0-9]%2[LBE]", digits, endianness)) { /* We should have at least digits. Endianness we write either default(BE), or what we found in the string */ - snprintf(ptr, buff_len, "UTF-%s%s", digits, endianness); + snprintf(buffer, buff_len, "UTF-%s%s", digits, endianness); } else { /* Not our client - copy as is*/ - ptr= strnmov(ptr, cs_name, (uint)buff_len); + strncpy(buffer, cs_name, buff_len); } if (target_cs) { - strnmov(ptr, "//TRANSLIT", (uint)(buff_len - (ptr - buffer))); + strncat(buffer, "//TRANSLIT", buff_len); } } /* }}} */ diff --git a/libmariadb/client_plugin.c.in b/libmariadb/ma_client_plugin.c.in similarity index 97% rename from libmariadb/client_plugin.c.in rename to libmariadb/ma_client_plugin.c.in index bef791f4..12522cc4 100644 --- a/libmariadb/client_plugin.c.in +++ b/libmariadb/ma_client_plugin.c.in @@ -1,4 +1,5 @@ /* 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 @@ -34,17 +35,13 @@ #define FORCE_INIT_OF_VARS 1 #endif -#include -#include +#include +#include #include -#include -#ifdef THREAD -#include -#else -#include -#endif +#include +#include -#include "errmsg.h" +#include "ma_errmsg.h" #include struct st_client_plugin_int { @@ -283,12 +280,12 @@ int mysql_client_plugin_init() if (initialized) return 0; - bzero(&mysql, sizeof(mysql)); /* dummy mysql for set_mysql_extended_error */ + memset(&mysql, 0, sizeof(mysql)); /* dummy mysql for set_mysql_extended_error */ pthread_mutex_init(&LOCK_load_client_plugin, MY_MUTEX_INIT_SLOW); ma_init_ma_alloc_root(&mem_root, 128, 128); - bzero(&plugin_list, sizeof(plugin_list)); + memset(&plugin_list, 0, sizeof(plugin_list)); initialized= 1; @@ -327,7 +324,7 @@ void mysql_client_plugin_deinit() (void)dlclose(p->dlhandle); } - bzero(&plugin_list, sizeof(plugin_list)); + memset(&plugin_list, 0, sizeof(plugin_list)); initialized= 0; ma_free_root(&mem_root, MYF(0)); pthread_mutex_destroy(&LOCK_load_client_plugin); diff --git a/libmariadb/my_compress.c b/libmariadb/ma_compress.c similarity index 83% rename from libmariadb/my_compress.c rename to libmariadb/ma_compress.c index 72df4cdf..c040af87 100644 --- a/libmariadb/my_compress.c +++ b/libmariadb/ma_compress.c @@ -1,4 +1,5 @@ /* 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 @@ -17,10 +18,10 @@ /* Written by Sinisa Milivojevic */ -#include +#include #ifdef HAVE_COMPRESS -#include -#include +#include +#include #include /* @@ -29,13 +30,13 @@ ** *complen is 0 if the packet wasn't compressed */ -my_bool my_compress(unsigned char *packet, size_t *len, size_t *complen) +my_bool _mariadb_compress(unsigned char *packet, size_t *len, size_t *complen) { if (*len < MIN_COMPRESS_LENGTH) *complen=0; else { - unsigned char *compbuf=my_compress_alloc(packet,len,complen); + unsigned char *compbuf=_mariadb_compress_alloc(packet,len,complen); if (!compbuf) return *complen ? 0 : 1; memcpy(packet,compbuf,*len); @@ -45,7 +46,7 @@ my_bool my_compress(unsigned char *packet, size_t *len, size_t *complen) } -unsigned char *my_compress_alloc(const unsigned char *packet, size_t *len, size_t *complen) +unsigned char *_mariadb_compress_alloc(const unsigned char *packet, size_t *len, size_t *complen) { unsigned char *compbuf; *complen = *len * 120 / 100 + 12; @@ -67,7 +68,7 @@ unsigned char *my_compress_alloc(const unsigned char *packet, size_t *len, size_ return compbuf; } -my_bool my_uncompress (unsigned char *packet, size_t *len, size_t *complen) +my_bool _mariadb_uncompress (unsigned char *packet, size_t *len, size_t *complen) { if (*complen) /* If compressed */ { diff --git a/libmariadb/my_context.c b/libmariadb/ma_context.c similarity index 94% rename from libmariadb/my_context.c rename to libmariadb/ma_context.c index 0fda2a73..5012c4e1 100644 --- a/libmariadb/my_context.c +++ b/libmariadb/ma_context.c @@ -1,5 +1,6 @@ /* 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 @@ -20,10 +21,9 @@ swapcontext(). */ -#include "my_global.h" -#include "mysys_priv.h" -#include "m_string.h" -#include "my_context.h" +#include "ma_global.h" +#include "ma_string.h" +#include "ma_context.h" #ifdef HAVE_VALGRIND #include @@ -73,9 +73,7 @@ my_context_continue(struct my_context *c) if (!c->active) return 0; - DBUG_SWAP_CODE_STATE(&c->dbug_state); err= swapcontext(&c->base_context, &c->spawned_context); - DBUG_SWAP_CODE_STATE(&c->dbug_state); if (err) { fprintf(stderr, "Aieie, swapcontext() failed: %d (errno=%d)\n", @@ -130,7 +128,7 @@ 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 - bzero(c, sizeof(*c)); + memset(c, 0, sizeof(*c)); if (!(c->stack= malloc(stack_size))) return -1; /* Out of memory */ c->stack_size= stack_size; @@ -151,7 +149,6 @@ my_context_destroy(struct my_context *c) #endif free(c->stack); } - DBUG_FREE_CODE_STATE(&c->dbug_state); } #endif /* MY_CONTEXT_USE_UCONTEXT */ @@ -191,8 +188,6 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d) { int ret; - DBUG_SWAP_CODE_STATE(&c->dbug_state); - /* There are 6 callee-save registers we need to save and restore when suspending and continuing, plus stack pointer %rsp and instruction pointer @@ -254,8 +249,6 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d) : "rcx", "rdx", "r8", "r9", "r10", "r11", "memory", "cc" ); - DBUG_SWAP_CODE_STATE(&c->dbug_state); - return ret; } @@ -264,8 +257,6 @@ my_context_continue(struct my_context *c) { int ret; - DBUG_SWAP_CODE_STATE(&c->dbug_state); - __asm__ __volatile__ ( "movq (%[save]), %%rax\n\t" @@ -323,8 +314,6 @@ my_context_continue(struct my_context *c) : "rcx", "rdx", "rsi", "rdi", "r8", "r9", "r10", "r11", "memory", "cc" ); - DBUG_SWAP_CODE_STATE(&c->dbug_state); - return ret; } @@ -372,7 +361,7 @@ my_context_yield(struct my_context *c) int my_context_init(struct my_context *c, size_t stack_size) { - bzero(c, sizeof(*c)); + memset(c, 0, sizeof(*c)); if (!(c->stack_bot= malloc(stack_size))) return -1; /* Out of memory */ @@ -382,7 +371,7 @@ my_context_init(struct my_context *c, size_t stack_size) */ c->stack_top= (void *) (( ((intptr)c->stack_bot + stack_size) & ~(intptr)0xf) - 16); - bzero(c->stack_top, 16); + memset(c->stack_top, 0, 16); #ifdef HAVE_VALGRIND c->valgrind_stack_id= @@ -401,7 +390,6 @@ my_context_destroy(struct my_context *c) VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id); #endif } - DBUG_FREE_CODE_STATE(&c->dbug_state); } #endif /* MY_CONTEXT_USE_X86_64_GCC_ASM */ @@ -439,8 +427,6 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d) { int ret; - DBUG_SWAP_CODE_STATE(&c->dbug_state); - /* There are 4 callee-save registers we need to save and restore when suspending and continuing, plus stack pointer %esp and instruction pointer @@ -501,8 +487,6 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d) : "memory", "cc" ); - DBUG_SWAP_CODE_STATE(&c->dbug_state); - return ret; } @@ -511,8 +495,6 @@ my_context_continue(struct my_context *c) { int ret; - DBUG_SWAP_CODE_STATE(&c->dbug_state); - __asm__ __volatile__ ( "movl (%[save]), %%eax\n\t" @@ -566,8 +548,6 @@ my_context_continue(struct my_context *c) : "ecx", "edx", "memory", "cc" ); - DBUG_SWAP_CODE_STATE(&c->dbug_state); - return ret; } @@ -613,12 +593,12 @@ my_context_yield(struct my_context *c) int my_context_init(struct my_context *c, size_t stack_size) { - bzero(c, sizeof(*c)); + 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); - bzero(c->stack_top, 16); + memset(c->stack_top, 0, 16); #ifdef HAVE_VALGRIND c->valgrind_stack_id= @@ -637,7 +617,6 @@ my_context_destroy(struct my_context *c) VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id); #endif } - DBUG_FREE_CODE_STATE(&c->dbug_state); } #endif /* MY_CONTEXT_USE_I386_GCC_ASM */ @@ -675,7 +654,7 @@ my_context_trampoline(void *p) int my_context_init(struct my_context *c, size_t stack_size) { - bzero(c, sizeof(*c)); + memset(c, 0, sizeof(*c)); c->lib_fiber= CreateFiber(stack_size, my_context_trampoline, c); if (c->lib_fiber) return 0; @@ -685,7 +664,6 @@ my_context_init(struct my_context *c, size_t stack_size) void my_context_destroy(struct my_context *c) { - DBUG_FREE_CODE_STATE(&c->dbug_state); if (c->lib_fiber) { DeleteFiber(c->lib_fiber); @@ -708,18 +686,14 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d) if (current_fiber == NULL || current_fiber == (void *)0x1e00) current_fiber= ConvertThreadToFiber(c); c->app_fiber= current_fiber; - DBUG_SWAP_CODE_STATE(&c->dbug_state); SwitchToFiber(c->lib_fiber); - DBUG_SWAP_CODE_STATE(&c->dbug_state); return c->return_value; } int my_context_continue(struct my_context *c) { - DBUG_SWAP_CODE_STATE(&c->dbug_state); SwitchToFiber(c->lib_fiber); - DBUG_SWAP_CODE_STATE(&c->dbug_state); return c->return_value; } diff --git a/libmariadb/ma_default.c b/libmariadb/ma_default.c new file mode 100644 index 00000000..7d6931a0 --- /dev/null +++ b/libmariadb/ma_default.c @@ -0,0 +1,224 @@ +/* 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., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +#include +#include +#include "ma_string.h" +#include +#include "mariadb_ctype.h" +#include +#include +#include + +#ifdef _WIN32 +#include +static const char *ini_exts[]= {"ini", "cnf", 0}; +static const char *ini_dirs[]= {"C:", ".", 0}; +static const char *ini_env_dirs[]= {"WINDOWS", "HOMEPATH", 0}; +#define R_OK 4 +#else +#include +static const char *ini_exts[]= {"cnf", 0}; +static const char *ini_dirs[]= {"/etc", "/etc/mysql", ".", 0}; +static const char *ini_env_dirs[]= {"HOME", "SYSCONFDIR", 0}; +#endif + +extern my_bool _mariadb_set_conf_option(MYSQL *mysql, const char *config_option, const char *config_value); + +char *_mariadb_get_default_file(char *filename, size_t length) +{ + int dirs; int exts; + + for (dirs= 0; ini_dirs[dirs]; dirs++) + { + for (exts= 0; ini_exts[exts]; exts++) + { + snprintf(filename, length, + "%s%cmy.%s", ini_dirs[dirs], FN_LIBCHAR, ini_exts[exts]); + if (!access(filename, R_OK)) + return filename; + } + } + for (dirs= 0; ini_env_dirs[dirs]; dirs++) + { + for (exts= 0; ini_exts[exts]; exts++) + { + char *env= getenv(ini_env_dirs[dirs]); + snprintf(filename, length, + "%s%cmy.%s", env, FN_LIBCHAR, ini_exts[exts]); + if (!access(filename, R_OK)) + return filename; + } + } + return NULL; +} + +my_bool _mariadb_read_options(MYSQL *mysql, const char *config_file, + const char *group) +{ + char buff[4096],*ptr,*end,*value, *key= 0, *optval; + MA_FILE *file= NULL; + char *filename; + uint line=0; + my_bool rc= 1; + my_bool read_values= 0, found_group= 0, is_escaped= 0, is_quoted= 0; + 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 (config_file) + filename= strdup(config_file); + else + { + filename= (char *)malloc(FN_REFLEN + 10); + if (!_mariadb_get_default_file(filename, FN_REFLEN + 10)) + { + free(filename); + goto err; + } + } + + if (!(file = ma_open(filename, "r", NULL))) + return 1; + + 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; + } + 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= test(strcmp(ptr, group) == 0); + 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--) ; + + if (!value) + { + if (!key) + key= ptr; + } + else + { + /* Remove pre- and end space */ + char *value_end; + *value= 0; + value++; + ptr= value; + for ( ; isspace(*value); value++) ; + optval= value; + value_end=strchr(value, '\0'); + 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: + free(filename); + if (file) + ma_close(file); + return rc; +} + + diff --git a/libmariadb/errmsg.c b/libmariadb/ma_errmsg.c similarity index 93% rename from libmariadb/errmsg.c rename to libmariadb/ma_errmsg.c index 171ee04a..d79da00e 100644 --- a/libmariadb/errmsg.c +++ b/libmariadb/ma_errmsg.c @@ -18,9 +18,9 @@ /* Error messages for MySQL clients */ /* error messages for the demon is in share/language/errmsg.sys */ -#include -#include -#include "errmsg.h" +#include +#include +#include "ma_errmsg.h" #include #ifdef GERMAN @@ -106,7 +106,7 @@ const char *client_errors[]= /* 2023 */ "", /* 2024 */ "", /* 2025 */ "", -/* 2026 */ "SSL connection error: %100s", +/* 2026 */ "SSL connection error: %-.100s", /* 2027 */ "received malformed packet", /* 2028 */ "", /* 2029 */ "", @@ -151,6 +151,8 @@ const char *mariadb_client_errors[] = /* 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)", "" }; @@ -162,20 +164,3 @@ void init_client_errs(void) my_errmsg[CLIENT_ERRMAP] = &client_errors[0]; } -int ma_error(int nr,myf myFlags, ...) -{ - va_list args; - const char *errormsg; - char buffer[ERRMSGSIZE]; - - va_start(args, myFlags); - - if (!(errormsg= ER(nr))) - snprintf(buffer, ERRMSGSIZE, "Unknown error: %d", nr); - else - vsnprintf(buffer, ERRMSGSIZE, errormsg, args); - - va_end(args); - - return (*ma_error_handler_hook)(nr, buffer, myFlags); -} diff --git a/libmariadb/hash.c b/libmariadb/ma_hash.c similarity index 88% rename from libmariadb/hash.c rename to libmariadb/ma_hash.c index 0f5bdf01..8b00d077 100644 --- a/libmariadb/hash.c +++ b/libmariadb/ma_hash.c @@ -1,6 +1,6 @@ /************************************************************************************ Copyright (C) 2000, 2012 MySQL AB & MySQL Finland AB & TCX DataKonsult AB, - Monty Program 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 @@ -25,10 +25,11 @@ /* One of key_length or key_length_offset must be given */ /* Key length of 0 isn't allowed */ -#include "mysys_priv.h" -#include +#include +#include +#include #include -#include "hash.h" +#include "ma_hash.h" #define NO_RECORD ((uint) -1) #define LOWFIND 1 @@ -47,14 +48,11 @@ my_bool _hash_init(HASH *hash,uint size,uint key_offset,uint key_length, hash_get_key get_key, void (*free_element)(void*),uint flags CALLER_INFO_PROTO) { - DBUG_ENTER("hash_init"); - DBUG_PRINT("enter",("hash: %lx size: %d",hash,size)); - hash->records=0; if (ma_init_dynamic_array_ci(&hash->array,sizeof(HASH_LINK),size,0)) { hash->free=0; /* Allow call to hash_free */ - DBUG_RETURN(TRUE); + return(TRUE); } hash->key_offset=key_offset; hash->key_length=key_length; @@ -67,13 +65,12 @@ my_bool _hash_init(HASH *hash,uint size,uint key_offset,uint key_length, hash->calc_hashnr=calc_hashnr_caseup; else hash->calc_hashnr=calc_hashnr; - DBUG_RETURN(0); + return(0); } void hash_free(HASH *hash) { - DBUG_ENTER("hash_free"); if (hash->free) { uint i,records; @@ -84,7 +81,7 @@ void hash_free(HASH *hash) } ma_delete_dynamic(&hash->array); hash->records=0; - DBUG_VOID_RETURN; + return; } /* some helper functions */ @@ -209,7 +206,6 @@ gptr hash_search(HASH *hash,const uchar *key,uint length) { HASH_LINK *pos; uint flag,idx; - DBUG_ENTER("hash_search"); flag=1; if (hash->records) @@ -222,9 +218,8 @@ gptr hash_search(HASH *hash,const uchar *key,uint length) pos= dynamic_element(&hash->array,idx,HASH_LINK*); if (!hashcmp(hash,pos,key,length)) { - DBUG_PRINT("exit",("found key at %d",idx)); hash->current_record= idx; - DBUG_RETURN (pos->data); + return (pos->data); } if (flag) { @@ -236,7 +231,7 @@ gptr hash_search(HASH *hash,const uchar *key,uint length) while ((idx=pos->next) != NO_RECORD); } hash->current_record= NO_RECORD; - DBUG_RETURN(0); + return(0); } /* Get next record with identical key */ @@ -430,9 +425,8 @@ my_bool hash_delete(HASH *hash,uchar *record) { uint blength,pos2,pos_hashnr,lastpos_hashnr,idx,empty_index; HASH_LINK *data,*lastpos,*gpos,*pos,*pos3,*empty; - DBUG_ENTER("hash_delete"); if (!hash->records) - DBUG_RETURN(1); + return(1); blength=hash->blength; data=dynamic_element(&hash->array,0,HASH_LINK*); @@ -444,7 +438,7 @@ my_bool hash_delete(HASH *hash,uchar *record) { gpos=pos; if (pos->next == NO_RECORD) - DBUG_RETURN(1); /* Key not found */ + return(1); /* Key not found */ pos=data+pos->next; } @@ -506,7 +500,7 @@ exit: VOID(ma_pop_dynamic(&hash->array)); if (hash->free) (*hash->free)((uchar*) record); - DBUG_RETURN(0); + return(0); } /* @@ -518,7 +512,6 @@ my_bool hash_update(HASH *hash,uchar *record,uchar *old_key,uint old_key_length) { uint idx,new_index,new_pos_index,blength,records,empty; HASH_LINK org_link,*data,*previous,*pos; - DBUG_ENTER("hash_update"); data=dynamic_element(&hash->array,0,HASH_LINK*); blength=hash->blength; records=hash->records; @@ -531,7 +524,7 @@ my_bool hash_update(HASH *hash,uchar *record,uchar *old_key,uint old_key_length) blength,records); new_index=hash_mask(rec_hashnr(hash,record),blength,records); if (idx == new_index) - DBUG_RETURN(0); /* Nothing to do (No record check) */ + return(0); /* Nothing to do (No record check) */ previous=0; for (;;) { @@ -540,7 +533,7 @@ my_bool hash_update(HASH *hash,uchar *record,uchar *old_key,uint old_key_length) break; previous=pos; if ((idx=pos->next) == NO_RECORD) - DBUG_RETURN(1); /* Not found in links */ + return(1); /* Not found in links */ } hash->current_record= NO_RECORD; org_link= *pos; @@ -575,7 +568,7 @@ my_bool hash_update(HASH *hash,uchar *record,uchar *old_key,uint old_key_length) data[empty]=org_link; data[new_index].next=empty; } - DBUG_RETURN(0); + return(0); } @@ -587,58 +580,4 @@ uchar *hash_element(HASH *hash,uint idx) } -#ifndef DBUG_OFF -my_bool hash_check(HASH *hash) -{ - int error; - uint i,rec_link,found,max_links,seek,links,idx; - uint records,blength; - HASH_LINK *data,*hash_info; - - records=hash->records; blength=hash->blength; - data=dynamic_element(&hash->array,0,HASH_LINK*); - error=0; - - for (i=found=max_links=seek=0 ; i < records ; i++) - { - if (hash_rec_mask(hash,data+i,blength,records) == i) - { - found++; seek++; links=1; - for (idx=data[i].next ; - idx != NO_RECORD && found < records + 1; - idx=hash_info->next) - { - if (idx >= records) - { - DBUG_PRINT("error", - ("Found pointer outside array to %d from link starting at %d", - idx,i)); - error=1; - } - hash_info=data+idx; - seek+= ++links; - if ((rec_link=hash_rec_mask(hash,hash_info,blength,records)) != i) - { - DBUG_PRINT("error", - ("Record in wrong link at %d: Start %d Record: %lx Record-link %d", idx,i,hash_info->data,rec_link)); - error=1; - } - else - found++; - } - if (links > max_links) max_links=links; - } - } - if (found != records) - { - DBUG_PRINT("error",("Found %ld of %ld records")); - error=1; - } - if (records) - DBUG_PRINT("info", - ("records: %ld seeks: %d max links: %d hitrate: %.2f", - records,seek,max_links,(float) seek / (float) records)); - return error; -} -#endif diff --git a/libmariadb/ma_init.c b/libmariadb/ma_init.c new file mode 100644 index 00000000..1e254b20 --- /dev/null +++ b/libmariadb/ma_init.c @@ -0,0 +1,115 @@ +/* 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., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +#include +#include +#include "mariadb_ctype.h" +#include +#include +#ifdef HAVE_GETRUSAGE +#include +/* extern int getrusage(int, struct rusage *); */ +#endif +#include +#ifdef _WIN32 +#ifdef _MSC_VER +#include +#include +#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) +{ +#ifdef _WIN32 + WSACleanup( ); +#endif /* _WIN32 */ + ma_init_done=0; +} /* ma_end */ + +#ifdef _WIN32 + +/* + This code is specially for running MySQL, but it should work in + other cases too. + + Inizializzazione delle variabili d'ambiente per Win a 32 bit. + + Vengono inserite nelle variabili d'ambiente (utilizzando cosi' + le funzioni getenv e putenv) i valori presenti nelle chiavi + del file di registro: + + HKEY_LOCAL_MACHINE\software\MySQL + + Se la kiave non esiste nonn inserisce nessun valore +*/ + +/* Crea la stringa d'ambiente */ + +void setEnvString(char *ret, const char *name, const char *value) +{ + sprintf(ret, "%s=%s", name, value); + return ; +} + +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 + diff --git a/libmariadb/ma_io.c b/libmariadb/ma_io.c index 5aacec81..c9e1509a 100644 --- a/libmariadb/ma_io.c +++ b/libmariadb/ma_io.c @@ -17,10 +17,9 @@ MA 02111-1307, USA */ -#include -#include -#include -#include +#include +#include +#include #include #include #include @@ -53,11 +52,6 @@ MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql) { if (!(fp= fopen(location, mode))) { -#ifdef _WIN32 - my_errno= GetLastError(); -#else - my_errno= errno; -#endif return NULL; } } @@ -104,7 +98,6 @@ MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql) return NULL; } fp= _wfopen(w_filename, w_mode); - my_errno= GetLastError(); free(w_filename); free(w_mode); } diff --git a/libmariadb/list.c b/libmariadb/ma_list.c similarity index 92% rename from libmariadb/list.c rename to libmariadb/ma_list.c index 49772b3c..4e14c945 100644 --- a/libmariadb/list.c +++ b/libmariadb/ma_list.c @@ -1,4 +1,5 @@ /* 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 @@ -19,17 +20,14 @@ Code for handling dubble-linked lists in C */ -#include "mysys_priv.h" -#include - - +#include +#include +#include /* Add a element to start of list */ LIST *list_add(LIST *root, LIST *element) { - DBUG_ENTER("list_add"); - DBUG_PRINT("enter",("root: %lx element: %lx", root, element)); if (root) { if (root->prev) /* If add in mid of list */ @@ -40,7 +38,7 @@ LIST *list_add(LIST *root, LIST *element) else element->prev=0; element->next=root; - DBUG_RETURN(element); /* New root */ + return(element); /* New root */ } diff --git a/libmariadb/ma_ll2str.c b/libmariadb/ma_ll2str.c new file mode 100644 index 00000000..36987767 --- /dev/null +++ b/libmariadb/ma_ll2str.c @@ -0,0 +1,75 @@ +/* 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., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +#include +#include "ma_string.h" +#include + +char NEAR _dig_vec[] = + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + +#define char_val(X) (X >= '0' && X <= '9' ? X-'0' :\ + X >= 'A' && X <= 'Z' ? X-'A'+10 :\ + X >= 'a' && X <= 'z' ? X-'a'+10 :\ + '\177') + +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 = -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; +} diff --git a/libmariadb/my_loaddata.c b/libmariadb/ma_loaddata.c similarity index 90% rename from libmariadb/my_loaddata.c rename to libmariadb/ma_loaddata.c index 747d5cba..2bc51eca 100644 --- a/libmariadb/my_loaddata.c +++ b/libmariadb/ma_loaddata.c @@ -40,11 +40,10 @@ +----------------------------------------------------------------------+ */ -#include "my_global.h" -#include -#include -#include -#include "errmsg.h" +#include "ma_global.h" +#include +#include +#include "ma_errmsg.h" #include "mysql.h" #include #include @@ -66,11 +65,10 @@ int mysql_local_infile_init(void **ptr, const char *filename, void *userdata) { MYSQL_INFILE_INFO *info; MYSQL *mysql= (MYSQL *)userdata; - DBUG_ENTER("mysql_local_infile_init"); info = (MYSQL_INFILE_INFO *)calloc(1, sizeof(MYSQL_INFILE_INFO)); if (!info) { - DBUG_RETURN(1); + return(1); } *ptr = info; @@ -89,14 +87,14 @@ int mysql_local_infile_init(void **ptr, const char *filename, void *userdata) } else { - info->error_no = my_errno; + info->error_no = errno; snprintf((char *)info->error_msg, sizeof(info->error_msg), - EE(EE_FILENOTFOUND), filename, info->error_no); + CER(CR_FILE_NOT_FOUND), filename, info->error_no); } - DBUG_RETURN(1); + return(1); } - DBUG_RETURN(0); + return(0); } /* }}} */ @@ -108,16 +106,15 @@ int mysql_local_infile_read(void *ptr, char * buf, unsigned int buf_len) MYSQL_INFILE_INFO *info = (MYSQL_INFILE_INFO *)ptr; size_t count; - DBUG_ENTER("mysql_local_infile_read"); - count= ma_read((void *)buf, 1, (size_t)buf_len, info->fp); if (count < 0) { - strcpy(info->error_msg, "Error reading file"); - info->error_no = EE_READ; + info->error_no = errno; + snprintf((char *)info->error_msg, sizeof(info->error_msg), + CER(CR_FILE_READ), info->filename, info->error_no); } - DBUG_RETURN((int)count); + return((int)count); } /* }}} */ @@ -128,15 +125,13 @@ int mysql_local_infile_error(void *ptr, char *error_buf, unsigned int error_buf_ { MYSQL_INFILE_INFO *info = (MYSQL_INFILE_INFO *)ptr; - DBUG_ENTER("mysql_local_infile_error"); - if (info) { strncpy(error_buf, info->error_msg, error_buf_len); - DBUG_RETURN(info->error_no); + return(info->error_no); } strncpy(error_buf, "Unknown error", error_buf_len); - DBUG_RETURN(CR_UNKNOWN_ERROR); + return(CR_UNKNOWN_ERROR); } /* }}} */ @@ -147,15 +142,13 @@ void mysql_local_infile_end(void *ptr) { MYSQL_INFILE_INFO *info = (MYSQL_INFILE_INFO *)ptr; - DBUG_ENTER("mysql_local_infile_end"); - if (info) { if (info->fp) ma_close(info->fp); free(ptr); } - DBUG_VOID_RETURN; + return; } /* }}} */ @@ -163,12 +156,11 @@ void mysql_local_infile_end(void *ptr) /* {{{ mysql_local_infile_default */ void mysql_set_local_infile_default(MYSQL *conn) { - DBUG_ENTER("mysql_local_infile_default"); conn->options.local_infile_init = mysql_local_infile_init; conn->options.local_infile_read = mysql_local_infile_read; conn->options.local_infile_error = mysql_local_infile_error; conn->options.local_infile_end = mysql_local_infile_end; - DBUG_VOID_RETURN; + return; } /* }}} */ @@ -180,13 +172,12 @@ void STDCALL mysql_set_local_infile_handler(MYSQL *conn, int (*local_infile_error)(void *, char *, uint), void *userdata) { - DBUG_ENTER("mysql_set_local_infile_handler"); conn->options.local_infile_init= local_infile_init; conn->options.local_infile_read= local_infile_read; conn->options.local_infile_end= local_infile_end; conn->options.local_infile_error= local_infile_error; conn->options.local_infile_userdata = userdata; - DBUG_VOID_RETURN; + return; } /* }}} */ @@ -199,8 +190,6 @@ my_bool mysql_handle_local_infile(MYSQL *conn, const char *filename) void *info= NULL; my_bool result= 1; - DBUG_ENTER("mysql_handle_local_infile"); - /* 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) @@ -265,7 +254,7 @@ my_bool mysql_handle_local_infile(MYSQL *conn, const char *filename) infile_error: conn->options.local_infile_end(info); free(buf); - DBUG_RETURN(result); + return(result); } /* }}} */ diff --git a/libmariadb/net.c b/libmariadb/ma_net.c similarity index 92% rename from libmariadb/net.c rename to libmariadb/ma_net.c index ef1a4fb6..7be79a23 100644 --- a/libmariadb/net.c +++ b/libmariadb/ma_net.c @@ -1,5 +1,5 @@ /* 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 @@ -23,13 +23,13 @@ */ -#include +#include #include #include -#include -#include +#include +#include #include "mysql.h" -#include "mysqld_error.h" +#include "ma_server_error.h" #include #include #include @@ -64,19 +64,6 @@ ulong net_buffer_length= 8192; /* Default length. Enlarged if necessary */ #include #endif #endif -#include "mysqld_error.h" -#ifdef MYSQL_SERVER -#include "my_pthread.h" -#include "thr_alarm.h" -void sql_print_error(const char *format,...); -#define RETRY_COUNT mysqld_net_retry_count -extern ulong mysqld_net_retry_count; -#else - -#ifdef OS2 /* avoid name conflict */ -#define thr_alarm_t thr_alarm_t_net -#define ALARM ALARM_net -#endif typedef my_bool thr_alarm_t; typedef my_bool ALARM; @@ -91,7 +78,6 @@ static inline int local_thr_alarm(my_bool *A,int B __attribute__((unused)),ALARM } #define thr_got_alarm(A) 0 #define RETRY_COUNT 1 -#endif #ifdef MYSQL_SERVER extern ulong bytes_sent, bytes_received; @@ -157,16 +143,11 @@ static my_bool net_realloc(NET *net, my_bool is_multi, size_t length) uchar *buff; size_t pkt_length; - DBUG_ENTER("net_realloc"); - DBUG_PRINT("info", ("length: %lu max_allowed_packet: %lu", - (ulong)length, max_allowed_packet)); - if (length >= net->max_packet_size) { - DBUG_PRINT("error",("Packet too large (%lu)", length)); net->error=1; net->last_errno=ER_NET_PACKET_TOO_LARGE; - DBUG_RETURN(1); + return(1); } pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1); /* reallocate buffer: @@ -174,9 +155,8 @@ static my_bool net_realloc(NET *net, my_bool is_multi, size_t length) if (!(buff=(uchar*) realloc(is_multi ? net->mbuff : net->buff, pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE))) { - DBUG_PRINT("info", ("Out of memory")); net->error=1; - DBUG_RETURN(1); + return(1); } if (!is_multi) { @@ -188,28 +168,26 @@ static my_bool net_realloc(NET *net, my_bool is_multi, size_t length) net->mbuff=net->mbuff_pos=buff; net->mbuff_end=buff+(net->max_packet=(unsigned long)pkt_length); } - DBUG_RETURN(0); + return(0); } /* Remove unwanted characters from connection */ void net_clear(NET *net) { // size_t len; - DBUG_ENTER("net_clear"); /* if (net->pvio) ma_pvio_has_data(net->pvio, &len); */ net->compress_pkt_nr= net->pkt_nr=0; /* Ready for new command */ net->write_pos=net->buff; if (net->mbuff) net->mbuff_pos= net->mbuff; - DBUG_VOID_RETURN; + return; } /* Flush write_buffer if not empty. */ int net_flush(NET *net) { int error=0; - DBUG_ENTER("net_flush"); if (net->buff != net->write_pos) { @@ -219,7 +197,7 @@ int net_flush(NET *net) } if (net->compress) net->pkt_nr= net->compress_pkt_nr; - DBUG_RETURN(error); + return(error); } /***************************************************************************** @@ -396,10 +374,9 @@ net_real_write(NET *net,const char *packet,size_t len) { size_t length; char *pos,*end; - DBUG_ENTER("net_real_write"); if (net->error == 2) - DBUG_RETURN(-1); /* socket can't be used */ + return(-1); /* socket can't be used */ net->reading_or_writing=2; #ifdef HAVE_COMPRESS @@ -413,14 +390,12 @@ net_real_write(NET *net,const char *packet,size_t len) net->last_errno=ER_OUT_OF_RESOURCES; net->error=2; net->reading_or_writing=0; - DBUG_RETURN(1); + return(1); } memcpy(b+header_length,packet,len); - if (my_compress((unsigned char*) b+header_length,&len,&complen)) + if (_mariadb_compress((unsigned char*) b+header_length,&len,&complen)) { - DBUG_PRINT("warning", - ("Compression error; Continuing without compression")); complen=0; } int3store(&b[NET_HEADER_SIZE],complen); @@ -439,7 +414,7 @@ net_real_write(NET *net,const char *packet,size_t len) net->error=2; /* Close socket */ net->last_errno= ER_NET_ERROR_ON_WRITE; net->reading_or_writing=0; - DBUG_RETURN(1); + return(1); } pos+=length; statistic_add(bytes_sent,length,&LOCK_bytes_sent); @@ -449,7 +424,7 @@ net_real_write(NET *net,const char *packet,size_t len) free((char*) packet); #endif net->reading_or_writing=0; - DBUG_RETURN(((int) (pos != end))); + return(((int) (pos != end))); } /***************************************************************************** @@ -491,10 +466,6 @@ my_real_read(NET *net, size_t *complen) { if (net->buff[net->where_b] != (uchar) 255) { - DBUG_PRINT("error", - ("Packets out of order (Found: %d, expected %d)", - (int) net->buff[net->where_b + 3], - (uint) (uchar) net->pkt_nr)); #ifdef EXTRA_DEBUG fprintf(stderr,"Packets out of order (Found: %d, expected %d)\n", (int) net->buff[net->where_b + 3], @@ -667,7 +638,7 @@ ulong my_net_read(NET *net) if ((packet_length = my_real_read(net,(size_t *)&complen)) == packet_error) return packet_error; - if (my_uncompress((unsigned char*) net->buff + net->where_b, &packet_length, &complen)) + if (_mariadb_uncompress((unsigned char*) net->buff + net->where_b, &packet_length, &complen)) { len= packet_error; net->error=2; /* caller will close socket */ diff --git a/libmariadb/password.c b/libmariadb/ma_password.c similarity index 90% rename from libmariadb/password.c rename to libmariadb/ma_password.c index ce0a6af7..6a494fad 100644 --- a/libmariadb/password.c +++ b/libmariadb/ma_password.c @@ -1,4 +1,5 @@ /* 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 @@ -35,17 +36,17 @@ This saves a hashed number as a string in the password field. *****************************************************************************/ -#include -#include -#include -#include +#include +#include +#include +#include #include "mysql.h" void randominit(struct rand_struct *rand_st,ulong seed1, ulong seed2) { /* For mysql 3.21.# */ #ifdef HAVE_purify - bzero((char*) rand_st,sizeof(*rand_st)); /* Avoid UMC varnings */ + memset((char*) rand_st, 0m sizeof(*rand_st)); /* Avoid UMC varnings */ #endif rand_st->max_value= 0x3FFFFFFFL; rand_st->max_value_dbl=(double) rand_st->max_value; @@ -114,26 +115,26 @@ void my_crypt(unsigned char *buffer, const unsigned char *s1, const unsigned cha void my_scramble_41(const unsigned char *buffer, const char *scramble, const char *password) { - MYSQL_SHA1_CTX context; + _MA_SHA1_CTX context; unsigned char sha1[SHA1_MAX_LENGTH]; unsigned char sha2[SHA1_MAX_LENGTH]; /* Phase 1: hash password */ - MYSQL_SHA1Init(&context); - MYSQL_SHA1Update(&context, (unsigned char *)password, strlen((char *)password)); - MYSQL_SHA1Final(sha1, &context); + ma_SHA1Init(&context); + ma_SHA1Update(&context, (unsigned char *)password, strlen((char *)password)); + ma_SHA1Final(sha1, &context); /* Phase 2: hash sha1 */ - MYSQL_SHA1Init(&context); - MYSQL_SHA1Update(&context, (unsigned char*)sha1, SHA1_MAX_LENGTH); - MYSQL_SHA1Final(sha2, &context); + ma_SHA1Init(&context); + ma_SHA1Update(&context, (unsigned char*)sha1, SHA1_MAX_LENGTH); + ma_SHA1Final(sha2, &context); /* Phase 3: hash scramble + sha2 */ - MYSQL_SHA1Init(&context); - MYSQL_SHA1Update(&context, (unsigned char *)scramble, SCRAMBLE_LENGTH); - MYSQL_SHA1Update(&context, (unsigned char*)sha2, SHA1_MAX_LENGTH); - MYSQL_SHA1Final((unsigned char *)buffer, &context); + 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); diff --git a/libmariadb/ma_pvio.c b/libmariadb/ma_pvio.c index 19c6713d..af53303d 100644 --- a/libmariadb/ma_pvio.c +++ b/libmariadb/ma_pvio.c @@ -43,18 +43,18 @@ register callback functions for read and write */ -#include -#include +#include +#include #include -#include +#include #include #include #include #include -#include -#include - -extern pthread_mutex_t THR_LOCK_lock; +#ifdef HAVE_NONBLOCK +#include +#include +#endif /* callback functions for read/write */ LIST *pvio_callback= NULL; @@ -177,6 +177,7 @@ my_bool ma_pvio_set_timeout(MARIADB_PVIO *pvio, } /* }}} */ +#ifdef HAVE_NONBLOCK /* {{{ size_t ma_pvio_read_async */ static size_t ma_pvio_read_async(MARIADB_PVIO *pvio, uchar *buffer, size_t length) { @@ -212,6 +213,7 @@ static size_t ma_pvio_read_async(MARIADB_PVIO *pvio, uchar *buffer, size_t lengt } } /* }}} */ +#endif /* {{{ size_t ma_pvio_read */ size_t ma_pvio_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length) @@ -219,13 +221,14 @@ size_t ma_pvio_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length) size_t r= -1; if (!pvio) return -1; - +#ifdef HAVE_NONBLOCK if (IS_PVIO_ASYNC_ACTIVE(pvio)) { r= ma_pvio_read_async(pvio, buffer, length); goto end; } else +#endif { if (IS_PVIO_ASYNC(pvio)) { @@ -303,6 +306,7 @@ size_t ma_pvio_cache_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length) } /* }}} */ +#ifdef HAVE_NONBLOCK /* {{{ size_t ma_pvio_write_async */ static size_t ma_pvio_write_async(MARIADB_PVIO *pvio, const uchar *buffer, size_t length) { @@ -332,6 +336,7 @@ static size_t ma_pvio_write_async(MARIADB_PVIO *pvio, const uchar *buffer, size_ } } /* }}} */ +#endif /* {{{ size_t ma_pvio_write */ size_t ma_pvio_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length) @@ -350,13 +355,14 @@ size_t ma_pvio_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length) } else #endif -// printf("No ssl (write): %x\n", pvio->cssl); +#ifdef HAVE_NONBLOCK if (IS_PVIO_ASYNC_ACTIVE(pvio)) { r= ma_pvio_write_async(pvio, buffer, length); goto end; } else +#endif { if (IS_PVIO_ASYNC(pvio)) { @@ -386,19 +392,16 @@ void ma_pvio_close(MARIADB_PVIO *pvio) if (pvio && pvio->cssl) { ma_pvio_ssl_close(pvio->cssl); - free((gptr)pvio->cssl); + free(pvio->cssl); } #endif if (pvio && pvio->methods->close) pvio->methods->close(pvio); if (pvio->cache) - free((gptr)pvio->cache); + free(pvio->cache); - if (pvio->fp) - my_fclose(pvio->fp, MYF(0)); - - free((gptr)pvio); + free(pvio); } /* }}} */ @@ -411,6 +414,7 @@ my_bool ma_pvio_get_handle(MARIADB_PVIO *pvio, void *handle) } /* }}} */ +#ifdef HAVE_NONBLOCK /* {{{ ma_pvio_wait_async */ static my_bool ma_pvio_wait_async(struct mysql_async_context *b, enum enum_pvio_io_event event, @@ -442,15 +446,17 @@ ma_pvio_wait_async(struct mysql_async_context *b, enum enum_pvio_io_event event, return (b->events_occured & MYSQL_WAIT_TIMEOUT) ? 0 : 1; } /* }}} */ +#endif /* {{{ ma_pvio_wait_io_or_timeout */ int ma_pvio_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout) { +#ifdef HAVE_NONBLOCK 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); - +#endif if (pvio && pvio->methods->wait_io_or_timeout) return pvio->methods->wait_io_or_timeout(pvio, is_read, timeout); diff --git a/libmariadb/ma_sha1.c b/libmariadb/ma_sha1.c new file mode 100644 index 00000000..04c5760e --- /dev/null +++ b/libmariadb/ma_sha1.c @@ -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 + 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 + */ diff --git a/libmariadb/ma_ssl.c b/libmariadb/ma_ssl.c index 2bf54fe0..33e1da78 100644 --- a/libmariadb/ma_ssl.c +++ b/libmariadb/ma_ssl.c @@ -32,20 +32,19 @@ #ifdef HAVE_SSL -#include -#include +#include +#include #include #include -//#include -#include +#include #include #include #include -/* -#include -#include -*/ +#ifdef HAVE_NONBLOCK +#include +#include +#endif /* Errors should be handled via pvio callback function */ my_bool ma_ssl_initialized= FALSE; diff --git a/libmariadb/my_stmt_codec.c b/libmariadb/ma_stmt_codec.c similarity index 97% rename from libmariadb/my_stmt_codec.c rename to libmariadb/ma_stmt_codec.c index 5397561a..20f2a0f9 100644 --- a/libmariadb/my_stmt_codec.c +++ b/libmariadb/ma_stmt_codec.c @@ -43,10 +43,9 @@ +----------------------------------------------------------------------+ */ -#include "my_global.h" -#include -#include -#include +#include "ma_global.h" +#include +#include #include #include "mysql.h" @@ -222,7 +221,7 @@ my_bool str_to_TIME(const char *str, size_t length, MYSQL_TIME *tm) } -static void convert_from_string(MYSQL_BIND *r_param, char *buffer, size_t len) +static void convert_froma_string(MYSQL_BIND *r_param, char *buffer, size_t len) { int error= 0; switch (r_param->buffer_type) @@ -363,12 +362,12 @@ static void convert_from_long(MYSQL_BIND *r_param, const MYSQL_FIELD *field, lon char *endptr; uint len; - endptr= ma_longlong10_to_str(val, buffer, is_unsigned ? 10 : -10); + endptr= ma_ll2str(val, buffer, is_unsigned ? 10 : -10); len= (uint)(endptr - buffer); /* check if field flag is zerofill */ - convert_from_string(r_param, buffer, len); + convert_froma_string(r_param, buffer, len); } break; } @@ -493,6 +492,11 @@ void ps_fetch_int64(MYSQL_BIND *r_param, const MYSQL_FIELD * const field, } /* }}} */ +void ma_bmove_upp(register char *dst, register const char *src, register size_t len) +{ + while (len-- != 0) *--dst = *--src; +} + static void convert_from_float(MYSQL_BIND *r_param, const MYSQL_FIELD *field, double val, int size) { double check_trunc_val= (val > 0) ? floor(val) : -floor(-val); @@ -596,10 +600,10 @@ static void convert_from_float(MYSQL_BIND *r_param, const MYSQL_FIELD *field, do /* enough space available ? */ if (field->length < length || field->length > MAX_DOUBLE_STRING_REP_LENGTH - 1) break; - bmove_upp(buff + field->length, buff + length, length); - bfill((char*) buff, field->length - length, '0'); + ma_bmove_upp(buff + field->length, buff + length, length); + memset((char*) buff, 0, field->length - length); } - convert_from_string(r_param, buff, strlen(buff)); + convert_froma_string(r_param, buff, strlen(buff)); } break; } @@ -782,7 +786,7 @@ void ps_fetch_datetime(MYSQL_BIND *r_param, const MYSQL_FIELD * field, length= 0; break; } - convert_from_string(r_param, dtbuffer, length); + convert_froma_string(r_param, dtbuffer, length); break; } } @@ -801,7 +805,7 @@ void ps_fetch_string(MYSQL_BIND *r_param, const MYSQL_FIELD *field, */ ulong field_length= net_field_length(row); - convert_from_string(r_param, (char *)*row, field_length); + convert_froma_string(r_param, (char *)*row, field_length); (*row) += field_length; } /* }}} */ diff --git a/libmariadb/string.c b/libmariadb/ma_string.c similarity index 90% rename from libmariadb/string.c rename to libmariadb/ma_string.c index ade0af50..18c9bef7 100644 --- a/libmariadb/string.c +++ b/libmariadb/ma_string.c @@ -1,5 +1,6 @@ /* 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 @@ -21,15 +22,15 @@ By monty. */ -#include "mysys_priv.h" -#include +#include +#include +#include my_bool ma_init_dynamic_string(DYNAMIC_STRING *str, const char *init_str, size_t init_alloc, size_t alloc_increment) { uint length; - DBUG_ENTER("ma_init_dynamic_string"); if (!alloc_increment) alloc_increment=128; @@ -40,19 +41,18 @@ my_bool ma_init_dynamic_string(DYNAMIC_STRING *str, const char *init_str, init_alloc=alloc_increment; if (!(str->str=(char*) malloc(init_alloc))) - DBUG_RETURN(TRUE); + 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; - DBUG_RETURN(FALSE); + return(FALSE); } my_bool ma_dynstr_set(DYNAMIC_STRING *str, const char *init_str) { uint length; - DBUG_ENTER("ma_dynstr_set"); if (init_str && (length= (uint) strlen(init_str)+1) > str->max_length) { @@ -61,7 +61,7 @@ my_bool ma_dynstr_set(DYNAMIC_STRING *str, const char *init_str) if (!str->max_length) str->max_length=str->alloc_increment; if (!(str->str=(char*) realloc(str->str,str->max_length))) - DBUG_RETURN(TRUE); + return(TRUE); } if (init_str) { @@ -70,23 +70,21 @@ my_bool ma_dynstr_set(DYNAMIC_STRING *str, const char *init_str) } else str->length=0; - DBUG_RETURN(FALSE); + return(FALSE); } my_bool ma_dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size) { - DBUG_ENTER("ma_dynstr_realloc"); - - if (!additional_size) DBUG_RETURN(FALSE); + 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))) - DBUG_RETURN(TRUE); + return(TRUE); } - DBUG_RETURN(FALSE); + return(FALSE); } @@ -125,3 +123,5 @@ void ma_dynstr_free(DYNAMIC_STRING *str) str->str=0; } } + + diff --git a/libmariadb/ma_time.c b/libmariadb/ma_time.c index 0b755064..5b4087b0 100644 --- a/libmariadb/ma_time.c +++ b/libmariadb/ma_time.c @@ -1,5 +1,6 @@ /**************************************************************************** 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 @@ -19,8 +20,7 @@ Part of this code includes code from the PHP project which is freely available from http://www.php.net *****************************************************************************/ -#include "mysys_priv.h" -#include +#include #include #include diff --git a/libmariadb/mysql_async.c b/libmariadb/mariadb_async.c similarity index 98% rename from libmariadb/mysql_async.c rename to libmariadb/mariadb_async.c index 3729e79c..922658ea 100644 --- a/libmariadb/mysql_async.c +++ b/libmariadb/mariadb_async.c @@ -19,19 +19,18 @@ MySQL non-blocking client library functions. */ -#include "my_global.h" -#include "my_sys.h" +#include "ma_global.h" +#include "ma_sys.h" #include "mysql.h" -#include "errmsg.h" +#include "ma_errmsg.h" #ifndef LIBMARIADB #include "sql_common.h" #else -#include "mysql_com.h" #include "ma_common.h" #endif -#include "my_context.h" +#include "ma_context.h" #include "ma_pvio.h" -#include "mysql_async.h" +#include "mariadb_async.h" #include @@ -186,29 +185,8 @@ my_ssl_write_async(struct mysql_async_context *b, SSL *ssl, } #endif /* HAVE_OPENSSL */ -/* - Legacy support of the MariaDB 5.5 version, where timeouts where only in - seconds resolution. Applications that use this will be asked to set a timeout - at the nearest higher whole-seconds value. -*/ -unsigned int STDCALL -mysql_get_timeout_value(const MYSQL *mysql) -{ - unsigned int timeout= mysql->options.extension->async_context->timeout_value; - /* Avoid overflow. */ - if (timeout > UINT_MAX - 999) - return (timeout - 1)/1000 + 1; - else - return (timeout+999)/1000; -} -unsigned int STDCALL -mysql_get_timeout_value_ms(const MYSQL *mysql) -{ - return mysql->options.extension->async_context->timeout_value; -} - /* Now create non-blocking definitions for all the calls that may block. diff --git a/libmariadb/charset.c b/libmariadb/mariadb_charset.c similarity index 82% rename from libmariadb/charset.c rename to libmariadb/mariadb_charset.c index 73a5e399..e78f6777 100644 --- a/libmariadb/charset.c +++ b/libmariadb/mariadb_charset.c @@ -1,4 +1,5 @@ /* 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 @@ -15,11 +16,11 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ -#include "mysys_priv.h" -#include "mysys_err.h" +#include +#include +// #include "mysys_err.h" #include -#include -#include +#include MARIADB_CHARSET_INFO *ma_default_charset_info = (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[5]; MARIADB_CHARSET_INFO *ma_charset_bin= (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[32]; @@ -40,16 +41,13 @@ MARIADB_CHARSET_INFO * STDCALL mysql_get_charset_by_nr(uint cs_number) my_bool set_default_charset(uint cs, myf flags) { MARIADB_CHARSET_INFO *new_charset; - DBUG_ENTER("set_default_charset"); - DBUG_PRINT("enter",("character set: %d",(int) cs)); new_charset = mysql_get_charset_by_nr(cs); if (!new_charset) { - DBUG_PRINT("error",("Couldn't set default character set")); - DBUG_RETURN(TRUE); /* error */ + return(TRUE); /* error */ } ma_default_charset_info = new_charset; - DBUG_RETURN(FALSE); + return(FALSE); } MARIADB_CHARSET_INFO * STDCALL mysql_get_charset_by_name(const char *cs_name) @@ -65,15 +63,12 @@ MARIADB_CHARSET_INFO * STDCALL mysql_get_charset_by_name(const char *cs_name) my_bool set_default_charset_by_name(const char *cs_name, myf flags) { MARIADB_CHARSET_INFO *new_charset; - DBUG_ENTER("set_default_charset_by_name"); - DBUG_PRINT("enter",("character set: %s", cs_name)); new_charset = mysql_get_charset_by_name(cs_name); if (!new_charset) { - DBUG_PRINT("error",("Couldn't set default character set")); - DBUG_RETURN(TRUE); /* error */ + return(TRUE); /* error */ } ma_default_charset_info = new_charset; - DBUG_RETURN(FALSE); + return(FALSE); } diff --git a/libmariadb/ma_dyncol.c b/libmariadb/mariadb_dyncol.c similarity index 97% rename from libmariadb/ma_dyncol.c rename to libmariadb/mariadb_dyncol.c index b6f63bf1..9f06d29a 100644 --- a/libmariadb/ma_dyncol.c +++ b/libmariadb/mariadb_dyncol.c @@ -61,11 +61,11 @@ */ #include -#include "mysys_priv.h" -#include -#include -#include -#include +#include +#include +#include +#include +#include #include @@ -1679,7 +1679,7 @@ dynamic_new_column_store(DYNAMIC_COLUMN *str, if (!column_count) return ER_DYNCOL_OK; - bzero(str->str, fmt->fixed_hdr); + memset(str->str, 0, fmt->fixed_hdr); str->length= fmt->fixed_hdr; /* sort columns for the header */ @@ -1813,13 +1813,13 @@ dynamic_column_create_many_internal_fmt(DYNAMIC_COLUMN *str, { DYN_HEADER header; enum enum_dyncol_func_result rc; - bzero(&header, sizeof(header)); + memset(&header, 0, sizeof(header)); header.format= (string_keys ? 1 : 0); if (new_str) { /* to make dynstr_free() working in case of errors */ - bzero(str, sizeof(DYNAMIC_COLUMN)); + memset(str, 0, sizeof(DYNAMIC_COLUMN)); } if ((rc= calc_var_sizes(&header, column_count, column_keys, values)) < 0) @@ -1849,8 +1849,7 @@ dynamic_column_create_many(DYNAMIC_COLUMN *str, uint *column_numbers, DYNAMIC_COLUMN_VALUE *values) { - DBUG_ENTER("dynamic_column_create_many"); - DBUG_RETURN(dynamic_column_create_many_internal_fmt(str, column_count, + return(dynamic_column_create_many_internal_fmt(str, column_count, column_numbers, values, TRUE, FALSE)); } @@ -1874,8 +1873,7 @@ mariadb_dyncol_create_many_num(DYNAMIC_COLUMN *str, DYNAMIC_COLUMN_VALUE *values, my_bool new_string) { - DBUG_ENTER("mariadb_dyncol_create_many"); - DBUG_RETURN(dynamic_column_create_many_internal_fmt(str, column_count, + return(dynamic_column_create_many_internal_fmt(str, column_count, column_numbers, values, new_string, FALSE)); } @@ -1899,8 +1897,7 @@ mariadb_dyncol_create_many_named(DYNAMIC_COLUMN *str, DYNAMIC_COLUMN_VALUE *values, my_bool new_string) { - DBUG_ENTER("mariadb_dyncol_create_many_named"); - DBUG_RETURN(dynamic_column_create_many_internal_fmt(str, column_count, + return(dynamic_column_create_many_internal_fmt(str, column_count, column_keys, values, new_string, TRUE)); } @@ -1919,8 +1916,7 @@ enum enum_dyncol_func_result dynamic_column_create(DYNAMIC_COLUMN *str, uint column_nr, DYNAMIC_COLUMN_VALUE *value) { - DBUG_ENTER("dynamic_column_create"); - DBUG_RETURN(dynamic_column_create_many(str, 1, &column_nr, value)); + return(dynamic_column_create_many(str, 1, &column_nr, value)); } @@ -2319,7 +2315,7 @@ dynamic_column_get_internal(DYNAMIC_COLUMN *str, { DYN_HEADER header; enum enum_dyncol_func_result rc= ER_DYNCOL_FORMAT; - bzero(&header, sizeof(header)); + memset(&header, 0, sizeof(header)); if (str->length == 0) goto null; @@ -2392,7 +2388,7 @@ dynamic_column_exists_internal(DYNAMIC_COLUMN *str, uint num_key, { DYN_HEADER header; enum enum_dyncol_func_result rc; - bzero(&header, sizeof(header)); + memset(&header, 0, sizeof(header)); if (str->length == 0) return ER_DYNCOL_NO; /* no columns */ @@ -2426,7 +2422,7 @@ dynamic_column_list(DYNAMIC_COLUMN *str, DYNAMIC_ARRAY *array_of_uint) uint i; enum enum_dyncol_func_result rc; - bzero(array_of_uint, sizeof(*array_of_uint)); /* In case of errors */ + memset(array_of_uint, 0, sizeof(*array_of_uint)); /* In case of errors */ if (str->length == 0) return ER_DYNCOL_OK; /* no columns */ @@ -2551,7 +2547,7 @@ mariadb_dyncol_list_named(DYNAMIC_COLUMN *str, uint *count, LEX_STRING **names) (*names)[i].str= pool; pool+= DYNCOL_NUM_CHAR; (*names)[i].length= - ma_longlong2str(nm, (*names)[i].str, 10) - (*names)[i].str; + ma_ll2str(nm, (*names)[i].str, 10) - (*names)[i].str; } else { @@ -2738,7 +2734,7 @@ dynamic_column_update_copy(DYNAMIC_COLUMN *str, PLAN *plan, { return ER_DYNCOL_RESOURCE; } - bzero(tmp.str, new_fmt->fixed_hdr); + memset(tmp.str, 0, new_fmt->fixed_hdr); (*new_fmt->set_fixed_hdr)(&tmp, new_hdr); /* Adjust tmp to contain whole the future header */ tmp.length= new_fmt->fixed_hdr + new_hdr->header_size + new_hdr->nmpool_size; @@ -3337,8 +3333,8 @@ dynamic_column_update_many_fmt(DYNAMIC_COLUMN *str, if (add_column_count == 0) return ER_DYNCOL_OK; - bzero(&header, sizeof(header)); - bzero(&new_header, sizeof(new_header)); + memset(&header, 0, sizeof(header)); + memset(&new_header, 0, sizeof(new_header)); new_header.format= (string_keys ? dyncol_fmt_str : dyncol_fmt_num); new_fmt= fmt_data + new_header.format; @@ -3654,20 +3650,16 @@ mariadb_dyncol_check(DYNAMIC_COLUMN *str) void *key, *prev_key; enum enum_dynamic_column_type type= DYN_COL_NULL, prev_type= DYN_COL_NULL; - DBUG_ENTER("dynamic_column_check"); - if (str->length == 0) { - DBUG_PRINT("info", ("empty string is OK")); - DBUG_RETURN(ER_DYNCOL_OK); + return(ER_DYNCOL_OK); } - bzero(&header, sizeof(header)); + memset(&header, 0, sizeof(header)); /* Check that header is OK */ if (read_fixed_header(&header, str)) { - DBUG_PRINT("info", ("Reading fixed string header failed")); goto end; } fmt= fmt_data + header.format; @@ -3677,12 +3669,6 @@ mariadb_dyncol_check(DYNAMIC_COLUMN *str) /* headers are out of string length (no space for data and part of headers) */ if (fmt->fixed_hdr + header.header_size + header.nmpool_size > str->length) { - DBUG_PRINT("info", ("Fixed header: %u Header size: %u " - "Name pool size: %u but Strig length: %u", - (uint)fmt->fixed_hdr, - (uint)header.header_size, - (uint)header.nmpool_size, - (uint)str->length)); goto end; } header.header= (uchar*)str->str + fmt->fixed_hdr; @@ -3716,12 +3702,6 @@ mariadb_dyncol_check(DYNAMIC_COLUMN *str) DBUG_ASSERT(header.format == dyncol_fmt_str); if (read_name(&header, header.entry, &name)) { - DBUG_PRINT("info", ("Reading name failed: Field order: %u" - " Name offset: %u" - " Name pool size: %u", - (uint) i, - uint2korr(header.entry), - (uint)header.nmpool_size)); goto end; } name_offset= name.str - (char *)header.nmpool; @@ -3734,11 +3714,6 @@ mariadb_dyncol_check(DYNAMIC_COLUMN *str) DBUG_ASSERT(type != DYN_COL_NULL); if (data_offset > header.data_size) { - DBUG_PRINT("info", ("Field order: %u Data offset: %u" - " > Data pool size: %u", - (uint)i, - (uint)data_offset, - (uint)header.data_size)); goto end; } if (prev_type != DYN_COL_NULL) @@ -3746,26 +3721,14 @@ mariadb_dyncol_check(DYNAMIC_COLUMN *str) /* It is not first entry */ if (prev_data_offset >= data_offset) { - DBUG_PRINT("info", ("Field order: %u Previous data offset: %u" - " >= Current data offset: %u", - (uint)i, - (uint)prev_data_offset, - (uint)data_offset)); goto end; } if (prev_name_offset > name_offset) { - DBUG_PRINT("info", ("Field order: %u Previous name offset: %u" - " > Current name offset: %u", - (uint)i, - (uint)prev_data_offset, - (uint)data_offset)); goto end; } if ((*fmt->column_sort)(&prev_key, &key) >= 0) { - DBUG_PRINT("info", ("Field order: %u Previous key >= Current key", - (uint)i)); goto end; } } @@ -3828,15 +3791,13 @@ mariadb_dyncol_check(DYNAMIC_COLUMN *str) if (rc != ER_DYNCOL_OK) { DBUG_ASSERT(rc < 0); - DBUG_PRINT("info", ("Field order: %u Can't read data: %i", - (uint)i, (int) rc)); goto end; } } rc= ER_DYNCOL_OK; end: - DBUG_RETURN(rc); + return(rc); } enum enum_dyncol_func_result @@ -4218,7 +4179,7 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json, { /* here we use it only for read so can cheat a bit */ DYNAMIC_COLUMN dc; - bzero(&dc, sizeof(dc)); + memset(&dc, 0, sizeof(dc)); dc.str= val.x.string.value.str; dc.length= val.x.string.value.length; if (mariadb_dyncol_json_internal(&dc, json, lvl + 1) < 0) diff --git a/libmariadb/libmariadb.c b/libmariadb/mariadb_lib.c similarity index 85% rename from libmariadb/libmariadb.c rename to libmariadb/mariadb_lib.c index 1b3da149..058a6dd8 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/mariadb_lib.c @@ -21,19 +21,20 @@ is freely available from http://www.php.net *************************************************************************************/ -#include +#include -#include -#include -#include +#include +#include #include #include -#include "my_context.h" +#ifdef HAVE_NONBLOCK +#include "ma_context.h" +#endif #include "mysql.h" -#include "mysql_version.h" -#include "mysqld_error.h" +#include "mariadb_version.h" +#include "ma_server_error.h" #include -#include "errmsg.h" +#include "ma_errmsg.h" #include #include #include @@ -56,13 +57,10 @@ #ifdef HAVE_SYS_UN_H # include #endif -#if defined(THREAD) && !defined(_WIN32) -#include /* because of signal() */ -#endif #ifndef INADDR_NONE #define INADDR_NONE -1 #endif -#include +#include #ifndef _WIN32 #include #endif @@ -70,7 +68,6 @@ #ifdef HAVE_SSL #include #endif -#include #include #define ASYNC_CONTEXT_DEFAULT_STACK_SIZE (4096*15) @@ -104,11 +101,16 @@ extern int mthd_stmt_fetch_row(MYSQL_STMT *stmt, unsigned char **row); extern int mthd_stmt_fetch_to_bind(MYSQL_STMT *stmt, unsigned char *row); extern int mthd_stmt_read_all_rows(MYSQL_STMT *stmt); extern void mthd_stmt_flush_unbuffered(MYSQL_STMT *stmt); +extern my_bool _mariadb_read_options(MYSQL *mysql, const char *config_file, + char *group); extern unsigned char *mysql_net_store_length(unsigned char *packet, size_t length); + +#ifdef HAVE_NONBLOCK extern void my_context_install_suspend_resume_hook(struct mysql_async_context *b, void (*hook)(my_bool, void *), void *user_data); +#endif uint mysql_port=0; my_string mysql_unix_port=0; @@ -122,7 +124,7 @@ my_string mysql_unix_port=0; struct st_mariadb_methods MARIADB_DEFAULT_METHODS; #if defined(MSDOS) || defined(_WIN32) -// socket_errno is defined in my_global.h for all platforms +// socket_errno is defined in ma_global.h for all platforms #define perror(A) #else #include @@ -139,7 +141,6 @@ struct st_mariadb_methods MARIADB_DEFAULT_METHODS; static void end_server(MYSQL *mysql); static void mysql_close_memory(MYSQL *mysql); void read_user_name(char *name); -static void append_wild(char *to,char *end,const char *wild); my_bool STDCALL mysql_reconnect(MYSQL *mysql); static int cli_report_progress(MYSQL *mysql, uchar *packet, uint length); @@ -242,8 +243,6 @@ restart: mysql->server_status&= ~SERVER_MORE_RESULTS_EXIST; - DBUG_PRINT("error",("Got error: %d (%s)", net->last_errno, - net->last_error)); return(packet_error); } return len; @@ -366,22 +365,17 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg, if (OPT_HAS_EXT_VAL(mysql, multi_command)) multi= mysql->options.extension->multi_command; - DBUG_ENTER("mthd_my_send_cmd"); - - DBUG_PRINT("info", ("server_command: %d packet_size: %u", command, length)); - if (multi == MARIADB_COM_MULTI_BEGIN) { /* todo: error handling */ - DBUG_RETURN(net_add_multi_command(&mysql->net, command, arg, length)); + return(net_add_multi_command(&mysql->net, command, arg, length)); } if (mysql->net.pvio == 0) { /* Do reconnect if possible */ if (mysql_reconnect(mysql)) { - DBUG_PRINT("info", ("reconnect failed")); - DBUG_RETURN(1); + return(1); } } if (mysql->status != MYSQL_STATUS_READY || @@ -395,7 +389,7 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg, { result= mysql->net.conn_hdlr->plugin->set_connection(mysql, command, arg, length, skipp_check, opt_arg); if (result== -1) - DBUG_RETURN(result); + return(result); } CLEAR_CLIENT_ERROR(mysql); @@ -409,7 +403,6 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg, if (net_write_command(net,(uchar) command,arg, length ? length : (ulong) strlen(arg))) { - DBUG_PRINT("error",("Can't send command to server. Error: %d",socket_errno)); if (net->last_errno == ER_NET_PACKET_TOO_LARGE) { my_set_error(mysql, CR_NET_PACKET_TOO_LARGE, SQLSTATE_UNKNOWN, 0); @@ -429,10 +422,9 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg, if (!skipp_check) { result= ((mysql->packet_length=net_safe_read(mysql)) == packet_error ? 1 : 0); - DBUG_PRINT("info", ("packet_length=%llu", mysql->packet_length)); } end: - DBUG_RETURN(result); + return(result); } int @@ -444,13 +436,12 @@ ma_simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg static void free_old_query(MYSQL *mysql) { - DBUG_ENTER("free_old_query"); if (mysql->fields) ma_free_root(&mysql->field_alloc,MYF(0)); ma_init_ma_alloc_root(&mysql->field_alloc,8192,0); /* Assume rowlength < 8192 */ mysql->fields=0; mysql->field_count=0; /* For API */ - DBUG_VOID_RETURN; + return; } #if defined(HAVE_GETPWUID) && defined(NO_GETPWUID_DECL) @@ -461,9 +452,8 @@ char* getlogin(void); #if !defined(MSDOS) && ! defined(VMS) && !defined(_WIN32) && !defined(OS2) void read_user_name(char *name) { - DBUG_ENTER("read_user_name"); if (geteuid() == 0) - (void) strmov(name,"root"); /* allow use of surun */ + strcpy(name,"root"); /* allow use of surun */ else { #ifdef HAVE_GETPWUID @@ -484,7 +474,7 @@ void read_user_name(char *name) strncpy(name,"UNKNOWN_USER", USERNAME_LENGTH); #endif } - DBUG_VOID_RETURN; + return; } #else /* If MSDOS || VMS */ @@ -505,74 +495,6 @@ static my_bool is_NT(void) } #endif -/* -** Expand wildcard to a sql string -*/ - -static void -append_wild(char *to, char *end, const char *wild) -{ - end-=5; /* Some extra */ - if (wild && wild[0]) - { - to=strmov(to," like '"); - while (*wild && to < end) - { - if (*wild == '\\' || *wild == '\'') - *to++='\\'; - *to++= *wild++; - } - if (*wild) /* Too small buffer */ - *to++='%'; /* Nicer this way */ - to[0]='\''; - to[1]=0; - } -} - - - -/************************************************************************** -** Init debugging if MYSQL_DEBUG environment variable is found -**************************************************************************/ -void STDCALL mysql_debug_end(void) -{ -#ifndef DBUG_OFF - DEBUGGER_OFF; - DBUG_POP(); -#endif -} - -void STDCALL -mysql_debug(const char *debug __attribute__((unused))) -{ -#ifndef DBUG_OFF - char *env; - if (debug) - { - DEBUGGER_ON; - DBUG_PUSH(debug); - } - else if ((env = getenv("MYSQL_DEBUG"))) - { - DEBUGGER_ON; - DBUG_PUSH(env); -#if !defined(_WINVER) && !defined(WINVER) - puts("\n-------------------------------------------------------"); - puts("MYSQL_DEBUG found. libmariadb started with the following:"); - puts(env); - puts("-------------------------------------------------------\n"); -#else - { - char buff[80]; - strcpy(strmov(buff,"libmariadb: "),env); - MessageBox((HWND) 0,"Debugging variable MYSQL_DEBUG used",buff,MB_OK); - } -#endif - } -#endif -} - - /************************************************************************** ** Shut down connection **************************************************************************/ @@ -580,8 +502,6 @@ mysql_debug(const char *debug __attribute__((unused))) static void end_server(MYSQL *mysql) { - DBUG_ENTER("end_server"); - /* if net->error 2 and reconnect is activated, we need to inforn connection handler */ if (mysql->net.pvio != 0) @@ -591,27 +511,24 @@ end_server(MYSQL *mysql) } net_end(&mysql->net); free_old_query(mysql); - DBUG_VOID_RETURN; + return; } void mthd_my_skip_result(MYSQL *mysql) { ulong pkt_len; - DBUG_ENTER("madb_skip_result"); do { pkt_len= net_safe_read(mysql); if (pkt_len == packet_error) break; } while (pkt_len > 8 || mysql->net.read_pos[0] != 254); - DBUG_VOID_RETURN; + return; } void STDCALL mysql_free_result(MYSQL_RES *result) { - DBUG_ENTER("mysql_free_result"); - DBUG_PRINT("enter",("mysql_res: %lx",result)); if (result) { if (result->handle && result->handle->status == MYSQL_STATUS_USE_RESULT) @@ -626,40 +543,70 @@ mysql_free_result(MYSQL_RES *result) free(result->row); free(result); } - DBUG_VOID_RETURN; + return; } /**************************************************************************** ** Get options from my.cnf ****************************************************************************/ - -static const char *default_options[]= -{ - "port","socket","compress","password","pipe", "timeout", "user", - "init-command", "host", "database", "debug", "return-found-rows", - "ssl-key" ,"ssl-cert" ,"ssl-ca" ,"ssl-capath", - "character-sets-dir", "default-character-set", "interactive-timeout", - "connect-timeout", "local-infile", "disable-local-infile", - "ssl-cipher", "max-allowed-packet", "protocol", "shared-memory-base-name", - "multi-results", "multi-statements", "multi-queries", "secure-auth", - "report-data-truncation", "plugin-dir", "default-auth", "database-type", - "ssl-fp", "ssl-fp-list", "ssl_password", "bind-address", - NULL +enum enum_option_type { + MARIADB_OPTION_NONE, + MARIADB_OPTION_BOOL, + MARIADB_OPTION_INT, + MARIADB_OPTION_SIZET, + MARIADB_OPTION_STR, }; -enum option_val +struct st_default_options { + enum mysql_option option; + enum enum_option_type type; + char *conf_key; +}; + +struct st_default_options mariadb_defaults[] = { - OPT_port=1, OPT_socket, OPT_compress, OPT_password, OPT_pipe, - OPT_timeout, OPT_user, OPT_init_command, OPT_host, OPT_database, - OPT_debug, OPT_return_found_rows, OPT_ssl_key, OPT_ssl_cert, - OPT_ssl_ca, OPT_ssl_capath, OPT_charset_dir, - OPT_charset_name, OPT_interactive_timeout, - OPT_connect_timeout, OPT_local_infile, OPT_disable_local_infile, - OPT_ssl_cipher, OPT_max_allowed_packet, OPT_protocol, OPT_shared_memory_base_name, - OPT_multi_results, OPT_multi_statements, OPT_multi_queries, OPT_secure_auth, - OPT_report_data_truncation, OPT_plugin_dir, OPT_default_auth, OPT_db_type, - OPT_ssl_fp, OPT_ssl_fp_list, OPT_ssl_pw, OPT_bind_address + {MARIADB_OPT_PORT, MARIADB_OPTION_INT,"port"}, + {MARIADB_OPT_UNIXSOCKET, MARIADB_OPTION_STR, "socket"}, + {MYSQL_OPT_COMPRESS, MARIADB_OPTION_BOOL, "compress"}, + {MARIADB_OPT_PASSWORD, MARIADB_OPTION_STR, "password"}, + {MYSQL_OPT_NAMED_PIPE, MARIADB_OPTION_BOOL, "pipe"}, + {MYSQL_OPT_CONNECT_TIMEOUT, MARIADB_OPTION_INT, "timeout"}, + {MARIADB_OPT_USER, MARIADB_OPTION_STR, "user"}, + {MYSQL_INIT_COMMAND, MARIADB_OPTION_STR, "init-command"}, + {MARIADB_OPT_HOST, MARIADB_OPTION_STR, "host"}, + {MARIADB_OPT_SCHEMA, MARIADB_OPTION_STR, "database"}, + {MARIADB_OPT_DEBUG, MARIADB_OPTION_STR, "debug"}, + {MARIADB_OPT_FOUND_ROWS, MARIADB_OPTION_NONE, "return-found-rows"}, + {MYSQL_OPT_SSL_KEY, MARIADB_OPTION_STR, "ssl-key"}, + {MYSQL_OPT_SSL_CERT, MARIADB_OPTION_STR,"ssl-cert"}, + {MYSQL_OPT_SSL_CA, MARIADB_OPTION_STR,"ssl-ca"}, + {MYSQL_OPT_SSL_CAPATH, MARIADB_OPTION_STR,"ssl-capath"}, + {MYSQL_SET_CHARSET_DIR, MARIADB_OPTION_STR, "character-sets-dir"}, + {MYSQL_SET_CHARSET_NAME, MARIADB_OPTION_STR, "default-character-set"}, + {MARIADB_OPT_INTERACTIVE, MARIADB_OPTION_NONE, "interactive-timeout"}, + {MYSQL_OPT_CONNECT_TIMEOUT, MARIADB_OPTION_INT, "connect-timeout"}, + {MYSQL_OPT_LOCAL_INFILE, MARIADB_OPTION_BOOL, "local-infile"}, + {0, 0 ,"disable-local-infile",}, + {MYSQL_OPT_SSL_CIPHER, MARIADB_OPTION_STR, "ssl-cipher"}, + {MYSQL_OPT_MAX_ALLOWED_PACKET, MARIADB_OPTION_SIZET, "max-allowed-packet"}, + {MYSQL_OPT_NET_BUFFER_LENGTH, MARIADB_OPTION_SIZET, "net-buffer-length"}, + {MYSQL_OPT_PROTOCOL, MARIADB_OPTION_INT, "protocol"}, + {MYSQL_SHARED_MEMORY_BASE_NAME, MARIADB_OPTION_STR,"shared-memory-base-name"}, + {MARIADB_OPT_MULTI_RESULTS, MARIADB_OPTION_NONE, "multi-results"}, + {MARIADB_OPT_MULTI_STATEMENTS, MARIADB_OPTION_STR, "multi-statements"}, + {MARIADB_OPT_MULTI_STATEMENTS, MARIADB_OPTION_STR, "multi-queries"}, + {MYSQL_SECURE_AUTH, MARIADB_OPTION_BOOL, "secure-auth"}, + {MYSQL_REPORT_DATA_TRUNCATION, MARIADB_OPTION_BOOL, "report-data-truncation"}, + {MYSQL_OPT_RECONNECT, MARIADB_OPTION_BOOL, "reconnect"}, + {MYSQL_PLUGIN_DIR, MARIADB_OPTION_STR, "plugin-dir"}, + {MYSQL_DEFAULT_AUTH, MARIADB_OPTION_STR, "default-auth"}, + {MARIADB_OPT_SSL_FP, MARIADB_OPTION_STR, "ssl-fp"}, + {MARIADB_OPT_SSL_FP_LIST, MARIADB_OPTION_STR, "ssl-fp-list"}, + {MARIADB_OPT_SSL_FP_LIST, MARIADB_OPTION_STR, "ssl-fplist"}, + {MARIADB_OPT_SSL_PASSPHRASE, MARIADB_OPTION_STR, "ssl_passphrase"}, + {MYSQL_OPT_BIND, MARIADB_OPTION_STR, "bind-address"}, + {0, 0, NULL} }; #define CHECK_OPT_EXTENSION_SET(OPTS)\ @@ -686,14 +633,8 @@ enum option_val else \ (OPTS)->KEY= NULL - -static TYPELIB option_types={array_elements(default_options)-1, - "options",default_options}; - -const char *protocol_names[]= {"TCP", "SOCKED", "PIPE", "MEMORY", NULL}; -TYPELIB sql_protocol_typelib= {array_elements(protocol_names)-1, - "protocol names", - protocol_names}; +#define OPT_SET_VALUE_INT(OPTS, KEY, VAL) \ + (OPTS)->KEY= (VAL) static void options_add_initcommand(struct st_mysql_options *options, const char *init_cmd) @@ -708,197 +649,55 @@ static void options_add_initcommand(struct st_mysql_options *options, if (ma_insert_dynamic(options->init_command, (gptr)&insert)) free(insert); } - - -static void mysql_read_default_options(struct st_mysql_options *options, - const char *filename,const char *group) +my_bool _mariadb_set_conf_option(MYSQL *mysql, const char *config_option, const char *config_value) { - int argc; - char *argv_buff[1],**argv; - const char *groups[3]; - DBUG_ENTER("mysql_read_default_options"); - DBUG_PRINT("enter",("file: %s group: %s",filename,group ? group :"NULL")); - - argc=1; argv=argv_buff; argv_buff[0]= (char*) "client"; - groups[0]= (char*) "client"; groups[1]= (char*) group; groups[2]=0; - - mariadb_load_defaults(filename, groups, &argc, &argv); - if (argc != 1) /* If some default option */ + if (config_option) { - char **option=argv; - while (*++option) - { - /* DBUG_PRINT("info",("option: %s",option[0])); */ - if (option[0][0] == '-' && option[0][1] == '-') - { - char *end= strchr(*option, '='); - char *opt_arg=0; + int i; - if (!end) - end= strchr(*option, '\0'); - if (*end) - { - opt_arg=end+1; - *end=0; /* Remove '=' */ - } - /* Change all '_' in variable name to '-' */ - for (end= *option ; (end= strchr(end,'_')) ; ) - *end= '-'; - switch (ma_find_type(*option+2,&option_types,2)) { - case OPT_port: - if (opt_arg) - options->port=atoi(opt_arg); - break; - case OPT_socket: - OPT_SET_VALUE_STR(options, unix_socket, opt_arg); - break; - case OPT_compress: - options->compress=1; - break; - case OPT_password: - OPT_SET_VALUE_STR(options, password, opt_arg); - break; - case OPT_pipe: - options->named_pipe=1; /* Force named pipe */ - break; - case OPT_connect_timeout: - case OPT_timeout: - if (opt_arg) - options->connect_timeout=atoi(opt_arg); - break; - case OPT_user: - OPT_SET_VALUE_STR(options, user, opt_arg); - break; - case OPT_init_command: - if (opt_arg) - options_add_initcommand(options, opt_arg); - break; - case OPT_host: - OPT_SET_VALUE_STR(options, host, opt_arg); - break; - case OPT_database: - OPT_SET_VALUE_STR(options, db, opt_arg); - break; - case OPT_debug: - mysql_debug(opt_arg ? opt_arg : "d:t:o,/tmp/client.trace"); - break; - case OPT_return_found_rows: - options->client_flag|=CLIENT_FOUND_ROWS; - break; -#ifdef HAVE_SSL - case OPT_ssl_key: - OPT_SET_VALUE_STR(options, ssl_key, opt_arg); - break; - case OPT_ssl_cert: - OPT_SET_VALUE_STR(options, ssl_cert, opt_arg); - break; - case OPT_ssl_ca: - OPT_SET_VALUE_STR(options, ssl_ca, opt_arg); - break; - case OPT_ssl_capath: - OPT_SET_VALUE_STR(options, ssl_capath, opt_arg); - break; - case OPT_ssl_cipher: - OPT_SET_VALUE_STR(options, ssl_cipher, opt_arg); - break; - case OPT_ssl_fp: - OPT_SET_EXTENDED_VALUE_STR(options, ssl_fp, opt_arg); - break; - case OPT_ssl_fp_list: - OPT_SET_EXTENDED_VALUE_STR(options, ssl_fp_list, opt_arg); - break; - case OPT_ssl_pw: - OPT_SET_EXTENDED_VALUE_STR(options, ssl_pw, opt_arg); - break; -#else - case OPT_ssl_key: - case OPT_ssl_cert: - case OPT_ssl_ca: - case OPT_ssl_capath: - case OPT_ssl_cipher: - case OPT_ssl_fp: - case OPT_ssl_fp_list: - case OPT_ssl_pw: - break; -#endif /* HAVE_SSL */ - case OPT_charset_dir: - OPT_SET_VALUE_STR(options, charset_dir, opt_arg); - break; - case OPT_charset_name: - OPT_SET_VALUE_STR(options, charset_name, opt_arg); - break; - case OPT_interactive_timeout: - options->client_flag|= CLIENT_INTERACTIVE; - break; - case OPT_local_infile: - if (!opt_arg || atoi(opt_arg) != 0) - options->client_flag|= CLIENT_LOCAL_FILES; - else - options->client_flag&= ~CLIENT_LOCAL_FILES; - break; - case OPT_disable_local_infile: - options->client_flag&= CLIENT_LOCAL_FILES; - break; - case OPT_max_allowed_packet: - if(opt_arg) - options->max_allowed_packet= atoi(opt_arg); - break; - case OPT_protocol: - options->protocol= ma_find_type(opt_arg, &sql_protocol_typelib, 0); -#ifndef _WIN32 - if (options->protocol < 0 || options->protocol > 1) -#else - if (options->protocol < 0) -#endif + for (i=0; mariadb_defaults[i].conf_key; i++) + { + if (!strcmp(mariadb_defaults[i].conf_key, config_option)) + { + int rc; + void *option_val= NULL; + switch (mariadb_defaults[i].type) { + case MARIADB_OPTION_BOOL: { - fprintf(stderr, "Unknown or unsupported protocol %s", opt_arg); + my_bool val= 0; + if (config_value) + val= atoi(config_value); + option_val= &val; + break; } - break; - case OPT_shared_memory_base_name: - OPT_SET_VALUE_STR(options, shared_memory_base_name, opt_arg); - break; - case OPT_multi_results: - options->client_flag|= CLIENT_MULTI_RESULTS; - break; - case OPT_multi_statements: - case OPT_multi_queries: - options->client_flag|= CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS; - break; - case OPT_report_data_truncation: - if (opt_arg) - options->report_data_truncation= atoi(opt_arg); - else - options->report_data_truncation= 1; - break; - case OPT_secure_auth: - options->secure_auth= 1; - break; - case OPT_plugin_dir: + case MARIADB_OPTION_INT: { - char directory[FN_REFLEN]; - if (strlen(opt_arg) >= FN_REFLEN) - opt_arg[FN_REFLEN]= 0; - if (!my_realpath(directory, opt_arg, 0)) - OPT_SET_EXTENDED_VALUE_STR(options, plugin_dir, ma_convert_dirname(directory)); + int val= 0; + if (config_value) + val= atoi(config_value); + option_val= &val; + break; + } + case MARIADB_OPTION_SIZET: + { + size_t val= 0; + if (config_value) + val= strtol(config_value, NULL, 10); + option_val= &val; + break; } - break; - case OPT_default_auth: - OPT_SET_EXTENDED_VALUE_STR(options, default_auth, opt_arg); - break; - case OPT_bind_address: - OPT_SET_VALUE_STR(options, bind_address, opt_arg); - break; default: - DBUG_PRINT("warning",("unknown option: %s",option[0])); + option_val= (void *)config_value; } + rc= mysql_optionsv(mysql, mariadb_defaults[i].option, option_val); + return(test(rc)); } } } - ma_free_defaults(argv); - DBUG_VOID_RETURN; + /* unknown key */ + return 1; } - /*************************************************************************** ** Change field rows to field structs ***************************************************************************/ @@ -927,10 +726,9 @@ unpack_fields(MYSQL_DATA *data,MA_MEM_ROOT *alloc,uint fields, char *p; unsigned int i, field_count= sizeof(rset_field_offsets)/sizeof(size_t)/2; - DBUG_ENTER("unpack_fields"); field=result=(MYSQL_FIELD*) ma_alloc_root(alloc,sizeof(MYSQL_FIELD)*fields); if (!result) - DBUG_RETURN(0); + return(0); for (row=data->data; row ; row = row->next,field++) { @@ -978,7 +776,7 @@ unpack_fields(MYSQL_DATA *data,MA_MEM_ROOT *alloc,uint fields, field->max_length= 0; } free_rows(data); /* Free old data */ - DBUG_RETURN(result); + return(result); } @@ -995,14 +793,13 @@ MYSQL_DATA *mthd_my_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, MYSQL_DATA *result; MYSQL_ROWS **prev_ptr,*cur; NET *net = &mysql->net; - DBUG_ENTER("madb_read_rows"); if ((pkt_len= net_safe_read(mysql)) == packet_error) - DBUG_RETURN(0); + return(0); if (!(result=(MYSQL_DATA*) calloc(1, sizeof(MYSQL_DATA)))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(0); + return(0); } ma_init_ma_alloc_root(&result->alloc,8192,0); /* Assume rowlength < 8192 */ result->alloc.min_malloc=sizeof(MYSQL_ROWS); @@ -1021,7 +818,7 @@ MYSQL_DATA *mthd_my_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, { free_rows(result); SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(0); + return(0); } *prev_ptr=cur; prev_ptr= &cur->next; @@ -1040,7 +837,7 @@ MYSQL_DATA *mthd_my_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, { free_rows(result); SET_CLIENT_ERROR(mysql, CR_UNKNOWN_ERROR, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(0); + return(0); } memcpy(to,(char*) cp,len); to[len]=0; to+=len+1; @@ -1056,7 +853,7 @@ MYSQL_DATA *mthd_my_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, if ((pkt_len=net_safe_read(mysql)) == packet_error) { free_rows(result); - DBUG_RETURN(0); + return(0); } } *prev_ptr=0; /* last pointer is null */ @@ -1068,8 +865,7 @@ MYSQL_DATA *mthd_my_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, cp+= 2; mysql->server_status= uint2korr(cp); } - DBUG_PRINT("exit",("Got %d rows",result->rows)); - DBUG_RETURN(result); + return(result); } @@ -1142,7 +938,7 @@ mysql_init(MYSQL *mysql) mysql->net.pvio= 0; } else - bzero((char*) (mysql),sizeof(*(mysql))); + memset((char*) (mysql), 0, sizeof(*(mysql))); mysql->options.connect_timeout=CONNECT_TIMEOUT; mysql->charset= ma_default_charset_info; mysql->methods= &MARIADB_DEFAULT_METHODS; @@ -1283,7 +1079,7 @@ mysql_real_connect(MYSQL *mysql, const char *host, const char *user, if (!connection_handler || !connection_handler[0]) { - bzero(plugin_name, 64); + memset(plugin_name, 0, 64); strncpy(plugin_name, host, MIN(end - host, 63)); end+= 3; } @@ -1334,12 +1130,6 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, const char *scramble_plugin; uint pkt_length, scramble_len, pkt_scramble_len= 0; NET *net= &mysql->net; - DBUG_ENTER("mysql_real_connect"); - - DBUG_PRINT("enter",("host: %s db: %s user: %s", - host ? host : "(Null)", - db ? db : "(Null)", - user ? user : "(Null)")); if (!mysql->methods) mysql->methods= &MARIADB_DEFAULT_METHODS; @@ -1349,16 +1139,16 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, if (net->pvio) /* check if we are already connected */ { SET_CLIENT_ERROR(mysql, CR_ALREADY_CONNECTED, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(NULL); + return(NULL); } /* use default options */ if (mysql->options.my_cnf_file || mysql->options.my_cnf_group) { - mysql_read_default_options(&mysql->options, - (mysql->options.my_cnf_file ? - mysql->options.my_cnf_file : "my"), - mysql->options.my_cnf_group); + _mariadb_read_options(mysql, + (mysql->options.my_cnf_file ? + mysql->options.my_cnf_file : NULL), + mysql->options.my_cnf_group); free(mysql->options.my_cnf_file); free(mysql->options.my_cnf_group); mysql->options.my_cnf_file=mysql->options.my_cnf_group=0; @@ -1489,9 +1279,6 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, goto error; } - DBUG_DUMP("packet",net->read_pos,10); - DBUG_PRINT("info",("mysql protocol version %d, server=%d", - PROTOCOL_VERSION, mysql->protocol_version)); if (mysql->protocol_version < PROTOCOL_VERSION) { net->last_errno= CR_VERSION_ERROR; @@ -1648,10 +1435,6 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, } } - DBUG_PRINT("info",("Server version = '%s' capabilities: %ld status: %d client_flag: %d", - mysql->server_version,mysql->server_capabilities, - mysql->server_status, client_flag)); - if (mysql->options.init_command) { char **begin= (char **)mysql->options.init_command->buffer; @@ -1678,20 +1461,16 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, strcpy(mysql->net.sqlstate, "00000"); - DBUG_PRINT("exit",("Mysql handler: %lx",mysql)); - DBUG_RETURN(mysql); + return(mysql); error: - DBUG_PRINT("error",("message: %u (%s)",net->last_errno,net->last_error)); - { - /* Free alloced memory */ - end_server(mysql); - /* only free the allocated memory, user needs to call mysql_close */ - mysql_close_memory(mysql); - if (!(((ulong) client_flag) & CLIENT_REMEMBER_OPTIONS)) - mysql_close_options(mysql); - } - DBUG_RETURN(0); + /* Free alloced memory */ + end_server(mysql); + /* only free the allocated memory, user needs to call mysql_close */ + mysql_close_memory(mysql); + if (!(((ulong) client_flag) & CLIENT_REMEMBER_OPTIONS)) + mysql_close_options(mysql); + return(0); } struct my_hook_data { @@ -1704,6 +1483,7 @@ struct my_hook_data { Callback hook to make the new VIO accessible via the old MYSQL to calling application when suspending a non-blocking call during automatic reconnect. */ +#ifdef HAVE_NONBLOCK static void my_suspend_hook(my_bool suspend, void *data) { @@ -1716,22 +1496,22 @@ my_suspend_hook(my_bool suspend, void *data) else hook_data->orig_mysql->net.pvio= hook_data->orig_pvio; } - +#endif my_bool STDCALL mysql_reconnect(MYSQL *mysql) { MYSQL tmp_mysql; +#ifdef HAVE_NONBLOCK struct my_hook_data hook_data; struct mysql_async_context *ctxt= NULL; +#endif LIST *li_stmt= mysql->stmts; - DBUG_ENTER("mysql_reconnect"); - /* check if connection handler is active */ if (IS_CONNHDLR_ACTIVE(mysql)) { if (mysql->net.conn_hdlr->plugin && mysql->net.conn_hdlr->plugin->reconnect) - DBUG_RETURN(mysql->net.conn_hdlr->plugin->reconnect(mysql)); + return(mysql->net.conn_hdlr->plugin->reconnect(mysql)); } if (!mysql->options.reconnect || @@ -1740,7 +1520,7 @@ my_bool STDCALL mysql_reconnect(MYSQL *mysql) /* Allow reconnect next time */ mysql->server_status&= ~SERVER_STATUS_IN_TRANS; my_set_error(mysql, CR_SERVER_GONE_ERROR, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } mysql_init(&tmp_mysql); @@ -1755,7 +1535,7 @@ my_bool STDCALL mysql_reconnect(MYSQL *mysql) /* don't reread options from configuration files */ tmp_mysql.options.my_cnf_group= tmp_mysql.options.my_cnf_file= NULL; - +#ifdef HAVE_NONBLOCK if (IS_MYSQL_ASYNC_ACTIVE(mysql)) { hook_data.orig_mysql= mysql; @@ -1763,21 +1543,24 @@ my_bool STDCALL mysql_reconnect(MYSQL *mysql) hook_data.orig_pvio= mysql->net.pvio; my_context_install_suspend_resume_hook(ctxt, my_suspend_hook, &hook_data); } +#endif if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd, mysql->db, mysql->port, mysql->unix_socket, mysql->client_flag | CLIENT_REMEMBER_OPTIONS) || mysql_set_character_set(&tmp_mysql, mysql->charset->csname)) { +#ifdef HAVE_NONBLOCK if (ctxt) my_context_install_suspend_resume_hook(ctxt, NULL, NULL); +#endif /* don't free options (CONC-118) */ memset(&tmp_mysql.options, 0, sizeof(struct st_mysql_options)); my_set_error(mysql, tmp_mysql.net.last_errno, tmp_mysql.net.sqlstate, tmp_mysql.net.last_error); mysql_close(&tmp_mysql); - DBUG_RETURN(1); + return(1); } for (;li_stmt;li_stmt= li_stmt->next) @@ -1803,7 +1586,7 @@ my_bool STDCALL mysql_reconnect(MYSQL *mysql) mysql->net.pvio->mysql= mysql; net_clear(&mysql->net); mysql->affected_rows= ~(my_ulonglong) 0; - DBUG_RETURN(0); + return(0); } void ma_invalidate_stmts(MYSQL *mysql, const char *function_name) @@ -1822,6 +1605,37 @@ void ma_invalidate_stmts(MYSQL *mysql, const char *function_name) } } +/* + Legacy support of the MariaDB 5.5 version, where timeouts where only in + seconds resolution. Applications that use this will be asked to set a timeout + at the nearest higher whole-seconds value. +*/ +unsigned int STDCALL +mysql_get_timeout_value(const MYSQL *mysql) +{ +#ifdef HAVE_NONBLOCK + unsigned int timeout= mysql->options.extension->async_context->timeout_value; + /* Avoid overflow. */ + if (timeout > UINT_MAX - 999) + return (timeout - 1)/1000 + 1; + else + return (timeout+999)/1000; +#else + return 0; +#endif +} + + +unsigned int STDCALL +mysql_get_timeout_value_ms(const MYSQL *mysql) +{ +#ifdef HAVE_NONBLOCK + return mysql->options.extension->async_context->timeout_value; +#else + return 0; +#endif +} + /************************************************************************** ** Change user and database **************************************************************************/ @@ -1835,8 +1649,6 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, *s_db= mysql->db; int rc; - DBUG_ENTER("mysql_change_user"); - if (!user) user=""; if (!passwd) @@ -1883,7 +1695,7 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, mysql->db= s_db; mysql->charset= s_cs; } - DBUG_RETURN(rc); + return(rc); } @@ -1895,14 +1707,12 @@ int STDCALL mysql_select_db(MYSQL *mysql, const char *db) { int error; - DBUG_ENTER("mysql_select_db"); - DBUG_PRINT("enter",("db: '%s'",db)); if ((error=ma_simple_command(mysql, COM_INIT_DB,db,(uint) strlen(db),0,0))) - DBUG_RETURN(error); + return(error); free(mysql->db); mysql->db=strdup(db); - DBUG_RETURN(0); + return(0); } @@ -1941,7 +1751,14 @@ static void mysql_close_options(MYSQL *mysql) if (mysql->options.extension) { +#ifdef HAVE_NONBLOCK struct mysql_async_context *ctxt; + if ((ctxt = mysql->options.extension->async_context) != 0) + { + my_context_destroy(&ctxt->async_context); + free(ctxt); + } +#endif free(mysql->options.extension->plugin_dir); free(mysql->options.extension->default_auth); free(mysql->options.extension->db_driver); @@ -1956,11 +1773,6 @@ static void mysql_close_options(MYSQL *mysql) hash_free(&mysql->options.extension->connect_attrs); if (hash_inited(&mysql->options.extension->userdata)) hash_free(&mysql->options.extension->userdata); - if ((ctxt = mysql->options.extension->async_context) != 0) - { - my_context_destroy(&ctxt->async_context); - free(ctxt); - } } free(mysql->options.extension); @@ -1986,16 +1798,13 @@ void my_set_error(MYSQL *mysql, { va_list ap; - DBUG_ENTER("my_set_error"); - mysql->net.last_errno= error_nr; strncpy(mysql->net.sqlstate, sqlstate, SQLSTATE_LENGTH); va_start(ap, format); vsnprintf(mysql->net.last_error, MYSQL_ERRMSG_SIZE, format ? format : ER(error_nr), ap); - DBUG_PRINT("info", ("error(%d) %s", error_nr, mysql->net.last_error)); va_end(ap); - DBUG_VOID_RETURN; + return; } void mysql_close_slow_part(MYSQL *mysql) @@ -2014,7 +1823,6 @@ void mysql_close_slow_part(MYSQL *mysql) void STDCALL mysql_close(MYSQL *mysql) { - DBUG_ENTER("mysql_close"); if (mysql) /* Some simple safety */ { if (mysql->net.conn_hdlr) @@ -2035,7 +1843,7 @@ mysql_close(MYSQL *mysql) mysql->host_info=mysql->user=mysql->passwd=mysql->db=0; /* Clear pointers for better safety */ - bzero((char*) &mysql->options,sizeof(mysql->options)); + memset((char*) &mysql->options, 0, sizeof(mysql->options)); if (mysql->extension) free(mysql->extension); @@ -2044,7 +1852,7 @@ mysql_close(MYSQL *mysql) if (mysql->free_me) free(mysql); } - DBUG_VOID_RETURN; + return; } @@ -2077,11 +1885,10 @@ int mthd_my_read_query_result(MYSQL *mysql) ulong field_count; MYSQL_DATA *fields; ulong length; - DBUG_ENTER("mthd_my_read_query_result"); if (!mysql || (length = net_safe_read(mysql)) == packet_error) { - DBUG_RETURN(1); + return(1); } free_old_query(mysql); /* Free old result */ get_info: @@ -2096,14 +1903,14 @@ get_info: pos+=2; if (pos < mysql->net.read_pos+length && net_field_length(&pos)) mysql->info=(char*) pos; - DBUG_RETURN(0); + return(0); } if (field_count == NULL_LENGTH) /* LOAD DATA LOCAL INFILE */ { int error=mysql_handle_local_infile(mysql, (char *)pos); if ((length=net_safe_read(mysql)) == packet_error || error) - DBUG_RETURN(-1); + return(-1); goto get_info; /* Get info packet */ } if (!(mysql->server_status & SERVER_STATUS_AUTOCOMMIT)) @@ -2111,15 +1918,15 @@ get_info: mysql->extra_info= net_field_length_ll(&pos); /* Maybe number of rec */ if (!(fields=mysql->methods->db_read_rows(mysql,(MYSQL_FIELD*) 0,8))) - DBUG_RETURN(-1); + return(-1); if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc, (uint) field_count,1, (my_bool) test(mysql->server_capabilities & CLIENT_LONG_FLAG)))) - DBUG_RETURN(-1); + return(-1); mysql->status=MYSQL_STATUS_GET_RESULT; mysql->field_count=field_count; - DBUG_RETURN(0); + return(0); } my_bool STDCALL @@ -2133,10 +1940,6 @@ mysql_real_query(MYSQL *mysql, const char *query, size_t length) { my_bool is_multi= 0; - DBUG_ENTER("mysql_real_query"); - DBUG_PRINT("enter",("handle: %lx",mysql)); - DBUG_PRINT("query",("Query = \"%.255s\" length=%u",query, length)); - if (OPT_HAS_EXT_VAL(mysql, multi_command)) is_multi= mysql->options.extension->multi_command; if (length == -1) @@ -2145,10 +1948,10 @@ mysql_real_query(MYSQL *mysql, const char *query, size_t length) free_old_query(mysql); if (ma_simple_command(mysql, COM_QUERY,query,length,1,0)) - DBUG_RETURN(-1); + return(-1); if (!is_multi) - DBUG_RETURN(mysql->methods->db_read_query_result(mysql)); - DBUG_RETURN(0); + return(mysql->methods->db_read_query_result(mysql)); + return(0); } /************************************************************************** @@ -2160,28 +1963,27 @@ MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql) { MYSQL_RES *result; - DBUG_ENTER("mysql_store_result"); if (!mysql->fields) - DBUG_RETURN(0); + return(0); if (mysql->status != MYSQL_STATUS_GET_RESULT) { SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(0); + return(0); } mysql->status=MYSQL_STATUS_READY; /* server is ready */ if (!(result=(MYSQL_RES*) calloc(1, sizeof(MYSQL_RES)+ sizeof(ulong)*mysql->field_count))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(0); + return(0); } result->eof=1; /* Marker for buffered */ result->lengths=(ulong*) (result+1); if (!(result->data=mysql->methods->db_read_rows(mysql,mysql->fields,mysql->field_count))) { free(result); - DBUG_RETURN(0); + return(0); } mysql->affected_rows= result->row_count= result->data->rows; result->data_cursor= result->data->data; @@ -2191,7 +1993,7 @@ mysql_store_result(MYSQL *mysql) result->current_field=0; result->current_row=0; /* Must do a fetch first */ mysql->fields=0; /* fields is now in result */ - DBUG_RETURN(result); /* Data fetched */ + return(result); /* Data fetched */ } @@ -2209,24 +2011,23 @@ MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql) { MYSQL_RES *result; - DBUG_ENTER("mysql_use_result"); if (!mysql->fields) - DBUG_RETURN(0); + return(0); if (mysql->status != MYSQL_STATUS_GET_RESULT) { SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(0); + return(0); } if (!(result=(MYSQL_RES*) calloc(1, sizeof(*result)+ sizeof(ulong)*mysql->field_count))) - DBUG_RETURN(0); + return(0); result->lengths=(ulong*) (result+1); if (!(result->row=(MYSQL_ROW) malloc(sizeof(result->row[0])*(mysql->field_count+1)))) { /* Ptrs: to one row */ free(result); - DBUG_RETURN(0); + return(0); } result->fields= mysql->fields; result->field_alloc= mysql->field_alloc; @@ -2236,7 +2037,7 @@ mysql_use_result(MYSQL *mysql) result->current_row= 0; mysql->fields=0; /* fields is now in result */ mysql->status=MYSQL_STATUS_USE_RESULT; - DBUG_RETURN(result); /* Data is read to be fetched */ + return(result); /* Data is read to be fetched */ } /************************************************************************** @@ -2256,7 +2057,6 @@ mysql_fetch_field(MYSQL_RES *result) MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *res) { - DBUG_ENTER("mysql_fetch_row"); if (!res) return 0; if (!res->data) @@ -2266,26 +2066,24 @@ mysql_fetch_row(MYSQL_RES *res) if (!(res->handle->methods->db_read_one_row(res->handle,res->field_count,res->row, res->lengths))) { res->row_count++; - DBUG_RETURN(res->current_row=res->row); + return(res->current_row=res->row); } - DBUG_PRINT("info",("end of data")); res->eof=1; res->handle->status=MYSQL_STATUS_READY; /* Don't clear handle in mysql_free_results */ res->handle=0; } - DBUG_RETURN((MYSQL_ROW) NULL); + return((MYSQL_ROW) NULL); } { MYSQL_ROW tmp; if (!res->data_cursor) { - DBUG_PRINT("info",("end of data")); - DBUG_RETURN(res->current_row=(MYSQL_ROW) NULL); + return(res->current_row=(MYSQL_ROW) NULL); } tmp = res->data_cursor->data; res->data_cursor = res->data_cursor->next; - DBUG_RETURN(res->current_row=tmp); + return(res->current_row=tmp); } } @@ -2333,7 +2131,6 @@ void STDCALL mysql_data_seek(MYSQL_RES *result, my_ulonglong row) { MYSQL_ROWS *tmp=0; - DBUG_PRINT("info",("mysql_data_seek(%ld)",(long) row)); if (result->data) for (tmp=result->data->data; row-- && tmp ; tmp = tmp->next) ; result->current_row=0; @@ -2372,12 +2169,10 @@ MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql, const char *wild) { char buff[255]; - DBUG_ENTER("mysql_list_dbs"); - - append_wild(strmov(buff,"show databases"),buff+sizeof(buff),wild); + snprintf(buff, 255, "SHOW DATABASES LIKE '%s'", wild ? wild : "%"); if (mysql_query(mysql,buff)) - DBUG_RETURN(0); - DBUG_RETURN (mysql_store_result(mysql)); + return(0); + return (mysql_store_result(mysql)); } @@ -2390,12 +2185,11 @@ MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql, const char *wild) { char buff[255]; - DBUG_ENTER("mysql_list_tables"); - append_wild(strmov(buff,"show tables"),buff+sizeof(buff),wild); + snprintf(buff, 255, "SHOW TABLES LIKE '%s'", wild ? wild : "%"); if (mysql_query(mysql,buff)) - DBUG_RETURN(0); - DBUG_RETURN (mysql_store_result(mysql)); + return(0); + return (mysql_store_result(mysql)); } @@ -2411,10 +2205,8 @@ mysql_list_fields(MYSQL *mysql, const char *table, const char *wild) { MYSQL_RES *result; MYSQL_DATA *query; - char buff[128]; + char buff[255]; int length= 0; - DBUG_ENTER("mysql_list_fields"); - DBUG_PRINT("enter",("table: '%s' wild: '%s'",table,wild ? wild : "")); LINT_INIT(query); @@ -2422,13 +2214,13 @@ mysql_list_fields(MYSQL *mysql, const char *table, const char *wild) if (ma_simple_command(mysql, COM_FIELD_LIST,buff,length,1,0) || !(query = mysql->methods->db_read_rows(mysql,(MYSQL_FIELD*) 0,8))) - DBUG_RETURN(NULL); + return(NULL); free_old_query(mysql); if (!(result = (MYSQL_RES *) calloc(1, sizeof(MYSQL_RES)))) { free_rows(query); - DBUG_RETURN(NULL); + return(NULL); } result->field_alloc=mysql->field_alloc; mysql->fields=0; @@ -2438,7 +2230,7 @@ mysql_list_fields(MYSQL *mysql, const char *table, const char *wild) (my_bool) test(mysql->server_capabilities & CLIENT_LONG_FLAG)); result->eof=1; - DBUG_RETURN(result); + return(result); } /* List all running processes (threads) in server */ @@ -2449,23 +2241,22 @@ mysql_list_processes(MYSQL *mysql) MYSQL_DATA *fields; uint field_count; uchar *pos; - DBUG_ENTER("mysql_list_processes"); LINT_INIT(fields); if (ma_simple_command(mysql, COM_PROCESS_INFO,0,0,0,0)) - DBUG_RETURN(0); + return(0); free_old_query(mysql); pos=(uchar*) mysql->net.read_pos; field_count=(uint) net_field_length(&pos); if (!(fields = mysql->methods->db_read_rows(mysql,(MYSQL_FIELD*) 0,5))) - DBUG_RETURN(NULL); + return(NULL); if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc,field_count,0, (my_bool) test(mysql->server_capabilities & CLIENT_LONG_FLAG)))) - DBUG_RETURN(0); + return(0); mysql->status=MYSQL_STATUS_GET_RESULT; mysql->field_count=field_count; - DBUG_RETURN(mysql_store_result(mysql)); + return(mysql_store_result(mysql)); } /* In 5.0 this version became an additional parameter shutdown_level */ @@ -2473,42 +2264,37 @@ int STDCALL mysql_shutdown(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level) { uchar s_level[2]; - DBUG_ENTER("mysql_shutdown"); s_level[0]= (uchar)shutdown_level; - DBUG_RETURN(ma_simple_command(mysql, COM_SHUTDOWN, (char *)s_level, 1, 0, 0)); + return(ma_simple_command(mysql, COM_SHUTDOWN, (char *)s_level, 1, 0, 0)); } int STDCALL mysql_refresh(MYSQL *mysql,uint options) { uchar bits[1]; - DBUG_ENTER("mysql_refresh"); bits[0]= (uchar) options; - DBUG_RETURN(ma_simple_command(mysql, COM_REFRESH,(char*) bits,1,0,0)); + return(ma_simple_command(mysql, COM_REFRESH,(char*) bits,1,0,0)); } int STDCALL mysql_kill(MYSQL *mysql,ulong pid) { char buff[12]; - DBUG_ENTER("mysql_kill"); int4store(buff,pid); /* if we kill our own thread, reading the response packet will fail */ - DBUG_RETURN(ma_simple_command(mysql, COM_PROCESS_KILL,buff,4,0,0)); + return(ma_simple_command(mysql, COM_PROCESS_KILL,buff,4,0,0)); } int STDCALL mysql_dump_debug_info(MYSQL *mysql) { - DBUG_ENTER("mysql_dump_debug_info"); - DBUG_RETURN(ma_simple_command(mysql, COM_DEBUG,0,0,0,0)); + return(ma_simple_command(mysql, COM_DEBUG,0,0,0,0)); } char * STDCALL mysql_stat(MYSQL *mysql) { - DBUG_ENTER("mysql_stat"); if (ma_simple_command(mysql, COM_STATISTICS,0,0,0,0)) return mysql->net.last_error; mysql->net.read_pos[mysql->packet_length]=0; /* End of stat string */ @@ -2517,14 +2303,13 @@ mysql_stat(MYSQL *mysql) SET_CLIENT_ERROR(mysql, CR_WRONG_HOST_INFO , SQLSTATE_UNKNOWN, 0); return mysql->net.last_error; } - DBUG_RETURN((char*) mysql->net.read_pos); + return((char*) mysql->net.read_pos); } int STDCALL mysql_ping(MYSQL *mysql) { int rc; - DBUG_ENTER("mysql_ping"); rc= ma_simple_command(mysql, COM_PING,0,0,0,0); /* if connection was terminated and reconnect is true, try again */ @@ -2637,11 +2422,10 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) { va_list ap; void *arg1; +#ifdef HAVE_NONBLOCK + size_t stacksize; struct mysql_async_context *ctxt; - size_t stacksize; - - DBUG_ENTER("mysql_option"); - DBUG_PRINT("enter",("option: %d",(int) option)); +#endif va_start(ap, option); @@ -2659,7 +2443,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) mysql->options.named_pipe=1; /* Force named pipe */ break; case MYSQL_OPT_LOCAL_INFILE: /* Allow LOAD DATA LOCAL ?*/ - if (!arg1 || test(*(uint*) arg1)) + if (!arg1 || test(*(my_bool*) arg1)) mysql->options.client_flag|= CLIENT_LOCAL_FILES; else mysql->options.client_flag&= ~CLIENT_LOCAL_FILES; @@ -2674,8 +2458,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) OPT_SET_VALUE_STR(&mysql->options, my_cnf_group, (char *)arg1); break; case MYSQL_SET_CHARSET_DIR: - /* not supported in this version. Since all character sets - are internally available, we don't throw an error */ + OPT_SET_VALUE_STR(&mysql->options, charset_dir, arg1); break; case MYSQL_SET_CHARSET_NAME: OPT_SET_VALUE_STR(&mysql->options, charset_name, (char *)arg1); @@ -2708,6 +2491,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) OPT_SET_EXTENDED_VALUE_STR(&mysql->options, default_auth, (char *)arg1); break; case MYSQL_OPT_NONBLOCK: +#ifdef HAVE_NONBLOCK if (mysql->options.extension && (ctxt = mysql->options.extension->async_context) != 0) { @@ -2746,6 +2530,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) mysql->options.extension->async_context= ctxt; if (mysql->net.pvio) mysql->net.pvio->async_context= ctxt; +#endif break; case MYSQL_OPT_MAX_ALLOWED_PACKET: if (mysql) @@ -2813,6 +2598,38 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) case MARIADB_OPT_CONNECTION_HANDLER: OPT_SET_EXTENDED_VALUE_STR(&mysql->options, connection_handler, (char *)arg1); break; + case MARIADB_OPT_PORT: + OPT_SET_VALUE_INT(&mysql->options, port, *((uint *)arg1)); + break; + case MARIADB_OPT_UNIXSOCKET: + OPT_SET_VALUE_STR(&mysql->options, unix_socket, arg1); + break; + case MARIADB_OPT_USER: + OPT_SET_VALUE_STR(&mysql->options, user, arg1); + break; + case MARIADB_OPT_HOST: + OPT_SET_VALUE_STR(&mysql->options, host, arg1); + break; + case MARIADB_OPT_SCHEMA: + OPT_SET_VALUE_STR(&mysql->options, db, arg1); + break; + case MARIADB_OPT_DEBUG: + break; + case MARIADB_OPT_FOUND_ROWS: + mysql->options.client_flag|= CLIENT_FOUND_ROWS; + break; + case MARIADB_OPT_INTERACTIVE: + mysql->options.client_flag|= CLIENT_INTERACTIVE; + break; + case MARIADB_OPT_MULTI_RESULTS: + mysql->options.client_flag|= CLIENT_MULTI_RESULTS; + break; + case MARIADB_OPT_MULTI_STATEMENTS: + mysql->options.client_flag|= CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS; + break; + case MARIADB_OPT_PASSWORD: + OPT_SET_VALUE_STR(&mysql->options, password, arg1); + break; case MARIADB_OPT_USERDATA: { void *data= va_arg(ap, void *); @@ -2948,7 +2765,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) case MARIADB_COM_MULTI_CANCEL: if (!mysql->options.extension || mysql->options.extension->multi_command != MARIADB_COM_MULTI_BEGIN) - DBUG_RETURN(-1); + return(-1); /* reset multi_buff */ mysql->net.mbuff_pos= mysql->net.mbuff; OPT_SET_EXTENDED_VALUE_INT(&mysql->options, multi_command, MARIADB_COM_MULTI_END); @@ -2956,31 +2773,31 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) case MARIADB_COM_MULTI_END: if (!mysql->options.extension || mysql->options.extension->multi_command != MARIADB_COM_MULTI_BEGIN) - DBUG_RETURN(-1); + return(-1); OPT_SET_EXTENDED_VALUE_INT(&mysql->options, multi_command, MARIADB_COM_MULTI_END); if (mariadb_flush_multi_command(mysql)) - DBUG_RETURN(-1); + return(-1); break; default: - DBUG_RETURN(-1); + return(-1); } OPT_SET_EXTENDED_VALUE_INT(&mysql->options, multi_command, *(my_bool *)arg1); } else - DBUG_RETURN(-1); + return(-1); break; case MARIADB_OPT_CONNECTION_READ_ONLY: OPT_SET_EXTENDED_VALUE_INT(&mysql->options, read_only, *(my_bool *)arg1); break; default: va_end(ap); - DBUG_RETURN(-1); + return(-1); } va_end(ap); - DBUG_RETURN(0); + return(0); end: va_end(ap); - DBUG_RETURN(1); + return(1); } int STDCALL @@ -2988,9 +2805,6 @@ mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...) { va_list ap; - DBUG_ENTER("mariadb_get_optionv"); - DBUG_PRINT("enter",("option: %d",(int) option)); - va_start(ap, arg); switch(option) { @@ -3065,7 +2879,7 @@ mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...) mysql->options.extension->multi_command : 0; } else - DBUG_RETURN(-1); + return(-1); break; case MYSQL_OPT_SSL_VERIFY_SERVER_CERT: *((my_bool *)arg)= test(mysql->options.client_flag & CLIENT_SSL_VERIFY_SERVER_CERT); @@ -3182,13 +2996,13 @@ mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...) break; default: va_end(ap); - DBUG_RETURN(-1); + return(-1); } va_end(ap); - DBUG_RETURN(0); + return(0); error: va_end(ap); - DBUG_RETURN(-1); + return(-1); } int STDCALL mysql_get_option(MYSQL *mysql, enum mysql_option option, void *arg) @@ -3263,21 +3077,18 @@ my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql) my_bool STDCALL mysql_autocommit(MYSQL *mysql, my_bool mode) { - DBUG_ENTER("mysql_autocommit"); - DBUG_RETURN((my_bool) mysql_real_query(mysql, (mode) ? "SET autocommit=1" : + return((my_bool) mysql_real_query(mysql, (mode) ? "SET autocommit=1" : "SET autocommit=0", 16)); } my_bool STDCALL mysql_commit(MYSQL *mysql) { - DBUG_ENTER("mysql_commit"); - DBUG_RETURN((my_bool)mysql_real_query(mysql, "COMMIT", sizeof("COMMIT"))); + return((my_bool)mysql_real_query(mysql, "COMMIT", sizeof("COMMIT"))); } my_bool STDCALL mysql_rollback(MYSQL *mysql) { - DBUG_ENTER("mysql_rollback"); - DBUG_RETURN((my_bool)mysql_real_query(mysql, "ROLLBACK", sizeof("ROLLBACK"))); + return((my_bool)mysql_real_query(mysql, "ROLLBACK", sizeof("ROLLBACK"))); } my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql) @@ -3302,19 +3113,17 @@ char *STDCALL mysql_info(MYSQL *mysql) my_bool STDCALL mysql_more_results(MYSQL *mysql) { - DBUG_ENTER("mysql_more_results"); - DBUG_RETURN(test(mysql->server_status & SERVER_MORE_RESULTS_EXIST)); + return(test(mysql->server_status & SERVER_MORE_RESULTS_EXIST)); } int STDCALL mysql_next_result(MYSQL *mysql) { - DBUG_ENTER("mysql_next_result"); /* make sure communication is not blocking */ if (mysql->status != MYSQL_STATUS_READY) { SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } /* clear error, and mysql status variables */ @@ -3323,10 +3132,10 @@ int STDCALL mysql_next_result(MYSQL *mysql) if (mysql->server_status & SERVER_MORE_RESULTS_EXIST) { - DBUG_RETURN(mysql->methods->db_read_query_result(mysql)); + return(mysql->methods->db_read_query_result(mysql)); } - DBUG_RETURN(-1); + return(-1); } ulong STDCALL mysql_thread_id(MYSQL *mysql) @@ -3377,10 +3186,8 @@ mysql_real_escape_string(MYSQL *mysql, char *to,const char *from, static void mariadb_get_charset_info(MYSQL *mysql, MY_CHARSET_INFO *cs) { - DBUG_ENTER("mariadb_get_charset_info"); - if (!cs) - DBUG_VOID_RETURN; + return; cs->number= mysql->charset->nr; cs->csname= mysql->charset->csname; @@ -3391,7 +3198,7 @@ static void mariadb_get_charset_info(MYSQL *mysql, MY_CHARSET_INFO *cs) cs->mbminlen= mysql->charset->char_minlen; cs->mbmaxlen= mysql->charset->char_maxlen; - DBUG_VOID_RETURN; + return; } void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *cs) @@ -3402,7 +3209,6 @@ void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *cs) int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname) { const MARIADB_CHARSET_INFO *cs; - DBUG_ENTER("mysql_set_character_set"); if (!csname) goto error; @@ -3415,14 +3221,14 @@ int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname) if (!mysql_real_query(mysql, buff, (uint)strlen(buff))) { mysql->charset= cs; - DBUG_RETURN(0); + return(0); } } error: my_set_error(mysql, CR_CANT_READ_CHARSET, SQLSTATE_UNKNOWN, 0, csname, "compiled_in"); - DBUG_RETURN(mysql->net.last_errno); + return(mysql->net.last_errno); } unsigned int STDCALL mysql_warning_count(MYSQL *mysql) @@ -3470,7 +3276,6 @@ int STDCALL mysql_server_init(int argc __attribute__((unused)), if ((env = getenv("MYSQL_UNIX_PORT"))) mysql_unix_port = env; } - mysql_debug(NullS); } #ifdef THREAD else @@ -3500,26 +3305,19 @@ void STDCALL mysql_server_end(void) my_bool STDCALL mysql_thread_init(void) { -#ifdef THREAD - return ma_thread_init(); -#endif return 0; } void STDCALL mysql_thread_end(void) { - #ifdef THREAD - ma_thread_end(); - #endif } int STDCALL mysql_set_server_option(MYSQL *mysql, enum enum_mysql_set_option option) { char buffer[2]; - DBUG_ENTER("mysql_set_server_option"); int2store(buffer, (uint)option); - DBUG_RETURN(ma_simple_command(mysql, COM_SET_OPTION, buffer, sizeof(buffer), 0, 0)); + return(ma_simple_command(mysql, COM_SET_OPTION, buffer, sizeof(buffer), 0, 0)); } ulong STDCALL mysql_get_client_version(void) @@ -3567,12 +3365,14 @@ static my_socket mariadb_get_socket(MYSQL *mysql) /* if an asynchronous connect is in progress, we need to obtain pvio handle from async_context until the connection was successfully established. - */ + */ +#ifdef HAVE_NONBLOCK else if (mysql->options.extension && mysql->options.extension->async_context && mysql->options.extension->async_context->pvio) { ma_pvio_get_handle(mysql->options.extension->async_context->pvio, &sock); } +#endif return sock; } @@ -3596,9 +3396,6 @@ my_bool STDCALL mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void * { va_list ap; - DBUG_ENTER("mariadb_get_valuev"); - DBUG_PRINT("enter",("value: %d",(int) value)); - va_start(ap, arg); switch(value) { @@ -3709,12 +3506,15 @@ my_bool STDCALL mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void * goto error; break; case MARIADB_CONNECTION_ASYNC_TIMEOUT_MS: +#ifdef HAVE_NONBLOCK if (mysql && mysql->options.extension && mysql->options.extension->async_context) *((unsigned int *)arg)= mysql->options.extension->async_context->timeout_value; else +#endif goto error; break; case MARIADB_CONNECTION_ASYNC_TIMEOUT: +#ifdef HAVE_NONBLOCK if (mysql && mysql->options.extension && mysql->options.extension->async_context) { unsigned int timeout= mysql->options.extension->async_context->timeout_value; @@ -3724,6 +3524,7 @@ my_bool STDCALL mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void * *((unsigned int *)arg)= (timeout+999)/1000; } else +#endif goto error; break; case MARIADB_CHARSET_NAME: @@ -3798,13 +3599,13 @@ my_bool STDCALL mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void * break; default: va_end(ap); - DBUG_RETURN(-1); + return(-1); } va_end(ap); - DBUG_RETURN(0); + return(0); error: va_end(ap); - DBUG_RETURN(-1); + return(-1); } my_bool STDCALL mariadb_get_info(MYSQL *mysql, enum mariadb_value value, void *arg) @@ -3877,8 +3678,6 @@ struct st_mariadb_api MARIADB_API= mysql_fetch_field, mysql_escape_string, mysql_real_escape_string, - mysql_debug, - mysql_debug_end, mysql_thread_safe, mysql_warning_count, mysql_sqlstate, diff --git a/libmariadb/my_stmt.c b/libmariadb/mariadb_stmt.c similarity index 92% rename from libmariadb/my_stmt.c rename to libmariadb/mariadb_stmt.c index fe01f600..9347b651 100644 --- a/libmariadb/my_stmt.c +++ b/libmariadb/mariadb_stmt.c @@ -43,16 +43,12 @@ +----------------------------------------------------------------------+ */ -#include "my_global.h" -#include -#include -#include +#include "ma_global.h" +#include +#include #include #include "mysql.h" -#include "mysql_priv.h" -#include "mysql_version.h" -#include "mysqld_error.h" -#include "errmsg.h" +#include "ma_errmsg.h" #include #include #include @@ -74,6 +70,10 @@ typedef struct MA_MEM_ROOT fields_ma_alloc_root; } MADB_STMT_EXTENSION; +MYSQL_DATA *read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, uint fields); +void free_rows(MYSQL_DATA *cur); +MYSQL_FIELD * unpack_fields(MYSQL_DATA *data,MA_MEM_ROOT *alloc,uint fields, my_bool default_value, my_bool long_flag_protocol); + static my_bool is_not_null= 0; static my_bool is_null= 1; @@ -123,27 +123,24 @@ static int stmt_unbuffered_fetch(MYSQL_STMT *stmt, uchar **row) { ulong pkt_len; - DBUG_ENTER("stmt_unbuffered_fetch"); - pkt_len= net_safe_read(stmt->mysql); - DBUG_PRINT("info",("packet_length= %ld",pkt_len)); if (pkt_len == packet_error) { stmt->fetch_row_func= stmt_unbuffered_eof; - DBUG_RETURN(1); + return(1); } if (stmt->mysql->net.read_pos[0] == 254) { *row = NULL; stmt->fetch_row_func= stmt_unbuffered_eof; - DBUG_RETURN(MYSQL_NO_DATA); + return(MYSQL_NO_DATA); } else *row = stmt->mysql->net.read_pos; stmt->result.rows++; - DBUG_RETURN(0); + return(0); } static int stmt_buffered_fetch(MYSQL_STMT *stmt, uchar **row) @@ -168,8 +165,6 @@ int mthd_stmt_read_all_rows(MYSQL_STMT *stmt) ulong packet_len; unsigned char *p; - DBUG_ENTER("stmt_read_all_rows"); - pprevious= &result->data; while ((packet_len = net_safe_read(stmt->mysql)) != packet_error) @@ -181,7 +176,7 @@ int mthd_stmt_read_all_rows(MYSQL_STMT *stmt) if (!(current= (MYSQL_ROWS *)ma_alloc_root(&result->alloc, sizeof(MYSQL_ROWS) + packet_len))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } current->data= (MYSQL_ROW)(current + 1); *pprevious= current; @@ -249,13 +244,13 @@ int mthd_stmt_read_all_rows(MYSQL_STMT *stmt) p+=2; stmt->mysql->server_status= uint2korr(p); stmt->result_cursor= result->data; - DBUG_RETURN(0); + return(0); } } stmt->result_cursor= 0; SET_CLIENT_STMT_ERROR(stmt, stmt->mysql->net.last_errno, stmt->mysql->net.sqlstate, stmt->mysql->net.last_error); - DBUG_RETURN(1); + return(1); } static int stmt_cursor_fetch(MYSQL_STMT *stmt, uchar **row) @@ -263,17 +258,15 @@ static int stmt_cursor_fetch(MYSQL_STMT *stmt, uchar **row) uchar buf[STMT_ID_LENGTH + 4]; MYSQL_DATA *result= &stmt->result; - DBUG_ENTER("stmt_cursor_fetch"); - if (stmt->state < MYSQL_STMT_USE_OR_STORE_CALLED) { SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } /* do we have some prefetched rows available ? */ if (stmt->result_cursor) - DBUG_RETURN(stmt_buffered_fetch(stmt, row)); + return(stmt_buffered_fetch(stmt, row)); if (stmt->mysql->server_status & SERVER_STATUS_LAST_ROW_SENT) stmt->mysql->server_status&= ~SERVER_STATUS_LAST_ROW_SENT; else @@ -282,7 +275,7 @@ static int stmt_cursor_fetch(MYSQL_STMT *stmt, uchar **row) int4store(buf + STMT_ID_LENGTH, stmt->prefetch_rows); if (stmt->mysql->methods->db_command(stmt->mysql, COM_STMT_FETCH, (char *)buf, sizeof(buf), 1, stmt)) - DBUG_RETURN(1); + return(1); /* free previously allocated buffer */ ma_free_root(&result->alloc, MYF(MY_KEEP_PREALLOC)); @@ -290,13 +283,13 @@ static int stmt_cursor_fetch(MYSQL_STMT *stmt, uchar **row) result->rows= 0; if (stmt->mysql->methods->db_stmt_read_all_rows(stmt)) - DBUG_RETURN(1); + return(1); - DBUG_RETURN(stmt_buffered_fetch(stmt, row)); + return(stmt_buffered_fetch(stmt, row)); } /* no more cursor data available */ *row= NULL; - DBUG_RETURN(MYSQL_NO_DATA); + return(MYSQL_NO_DATA); } void mthd_stmt_flush_unbuffered(MYSQL_STMT *stmt) @@ -313,10 +306,8 @@ int mthd_stmt_fetch_to_bind(MYSQL_STMT *stmt, unsigned char *row) size_t truncations= 0; unsigned char *null_ptr, bit_offset= 4; - DBUG_ENTER("stmt_fetch_to_bind"); - if (!stmt->bind_result_done) /* nothing to do */ - DBUG_RETURN(0); + return(0); row++; /* skip status byte */ null_ptr= row; @@ -360,22 +351,20 @@ int mthd_stmt_fetch_to_bind(MYSQL_STMT *stmt, unsigned char *row) null_ptr++; } } - DBUG_RETURN((truncations) ? MYSQL_DATA_TRUNCATED : 0); + return((truncations) ? MYSQL_DATA_TRUNCATED : 0); } MYSQL_RES *_mysql_stmt_use_result(MYSQL_STMT *stmt) { MYSQL *mysql= stmt->mysql; - DBUG_ENTER("mysql_stmt_use_result"); - if (!stmt->field_count || (!stmt->cursor_exists && mysql->status != MYSQL_STATUS_GET_RESULT) || (stmt->cursor_exists && mysql->status != MYSQL_STATUS_READY) || (stmt->state != MYSQL_STMT_WAITING_USE_OR_STORE)) { SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(NULL); + return(NULL); } CLEAR_CLIENT_STMT_ERROR(stmt); @@ -386,7 +375,7 @@ MYSQL_RES *_mysql_stmt_use_result(MYSQL_STMT *stmt) else stmt->fetch_row_func= stmt_cursor_fetch; - DBUG_RETURN(NULL); + return(NULL); } unsigned char *mysql_net_store_length(unsigned char *packet, size_t length) @@ -414,8 +403,6 @@ unsigned char *mysql_net_store_length(unsigned char *packet, size_t length) int store_param(MYSQL_STMT *stmt, int column, unsigned char **p) { - DBUG_ENTER("store_param"); - DBUG_PRINT("info", ("column: %d type: %d", column, stmt->params[column].buffer_type)); switch (stmt->params[column].buffer_type) { case MYSQL_TYPE_TINY: int1store(*p, *(uchar *)stmt->params[column].buffer); @@ -530,7 +517,6 @@ int store_param(MYSQL_STMT *stmt, int column, unsigned char **p) ulong len= (ulong)*stmt->params[column].length; /* to is after p. The latter hasn't been moved */ uchar *to = mysql_net_store_length(*p, len); - DBUG_PRINT("info", ("len=x%x", len)); if (len) memcpy(to, stmt->params[column].buffer, len); (*p) = to + len; @@ -540,9 +526,9 @@ int store_param(MYSQL_STMT *stmt, int column, unsigned char **p) default: /* unsupported parameter type */ SET_CLIENT_STMT_ERROR(stmt, CR_UNSUPPORTED_PARAM_TYPE, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } - DBUG_RETURN(0); + return(0); } /* {{{ mysqlnd_stmt_execute_generate_request */ @@ -571,8 +557,6 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req uchar *start= NULL, *p; - DBUG_ENTER("mysql_stmt_execute_generate_request"); - /* preallocate length bytes */ /* check: gr */ if (!(start= p= (uchar *)malloc(length))) @@ -690,7 +674,6 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req if (!stmt->params[i].buffer || *stmt->params[i].is_null || stmt->params[i].buffer_type == MYSQL_TYPE_NULL) { (start + null_byte_offset)[i/8] |= (unsigned char) (1 << (i & 7)); } else { - DBUG_PRINT("info", ("storing parameter %d at offset %d", i, p - start)); store_param(stmt, i, &p); } } @@ -698,14 +681,14 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req } stmt->send_types_to_server= 0; *request_len = (size_t)(p - start); - DBUG_RETURN(start); + return(start); mem_error: SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); free(start); *request_len= 0; - DBUG_RETURN(NULL); + return(NULL); } /* }}} */ @@ -726,8 +709,6 @@ my_ulonglong STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt) my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, void *value) { - DBUG_ENTER("mysql_stmt_attr_get"); - switch (attr_type) { case STMT_ATTR_UPDATE_MAX_LENGTH: *(my_bool *)value= stmt->update_max_length; @@ -739,15 +720,13 @@ my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt, enum enum_stmt_attr_type a *(unsigned long *)value= stmt->prefetch_rows; break; default: - DBUG_RETURN(1); + return(1); } - DBUG_RETURN(0); + return(0); } my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, const void *value) { - DBUG_ENTER("mysql_stmt_attr_get"); - switch (attr_type) { case STMT_ATTR_UPDATE_MAX_LENGTH: stmt->update_max_length= *(my_bool *)value; @@ -756,7 +735,7 @@ my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type a if (*(ulong *)value > (unsigned long) CURSOR_TYPE_READ_ONLY) { SET_CLIENT_STMT_ERROR(stmt, CR_NOT_IMPLEMENTED, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } stmt->flags = *(ulong *)value; break; @@ -768,20 +747,19 @@ my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type a break; default: SET_CLIENT_STMT_ERROR(stmt, CR_NOT_IMPLEMENTED, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } - DBUG_RETURN(0); + return(0); } my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bind) { MYSQL *mysql= stmt->mysql; - DBUG_ENTER("mysql_stmt_bind_param"); if (!mysql) { SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } /* for mariadb_stmt_execute_direct we need to bind parameters in advance: @@ -802,7 +780,7 @@ my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bind) if (!(stmt->params= (MYSQL_BIND *)ma_alloc_root(&stmt->mem_root, stmt->param_count * sizeof(MYSQL_BIND)))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } } memset(stmt->params, '\0', stmt->param_count * sizeof(MYSQL_BIND)); @@ -810,7 +788,7 @@ my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bind) } else if (stmt->state < MYSQL_STMT_PREPARED) { SET_CLIENT_STMT_ERROR(stmt, CR_NO_PREPARE_STMT, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (stmt->param_count && bind) @@ -826,7 +804,7 @@ my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bind) !stmt->mysql->methods->db_supported_buffer_type(stmt->params[i].buffer_type)) { SET_CLIENT_STMT_ERROR(stmt, CR_UNSUPPORTED_PARAM_TYPE, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (!stmt->params[i].is_null) stmt->params[i].is_null= &is_not_null; @@ -877,7 +855,7 @@ my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bind) break; default: SET_CLIENT_STMT_ERROR(stmt, CR_UNSUPPORTED_PARAM_TYPE, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); break; } } @@ -885,28 +863,27 @@ my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bind) stmt->bind_param_done= stmt->send_types_to_server= 1; CLEAR_CLIENT_STMT_ERROR(stmt); - DBUG_RETURN(0); + return(0); } my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) { uint i; - DBUG_ENTER("mysql_stmt_bind_result"); if (stmt->state < MYSQL_STMT_PREPARED) { SET_CLIENT_STMT_ERROR(stmt, CR_NO_PREPARE_STMT, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (!stmt->field_count) { SET_CLIENT_STMT_ERROR(stmt, CR_NO_STMT_METADATA, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (!bind) - DBUG_RETURN(1); + return(1); /* In case of a stored procedure we don't allocate memory for bind in mysql_stmt_prepare @@ -919,7 +896,7 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) if (!(stmt->bind= (MYSQL_BIND *)ma_alloc_root(fields_ma_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } } @@ -931,7 +908,7 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) !stmt->mysql->methods->db_supported_buffer_type(bind[i].buffer_type)) { SET_CLIENT_STMT_ERROR(stmt, CR_UNSUPPORTED_PARAM_TYPE, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (!stmt->bind[i].is_null) @@ -975,7 +952,7 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) stmt->bind_result_done= 1; CLEAR_CLIENT_STMT_ERROR(stmt); - DBUG_RETURN(0); + return(0); } static my_bool net_stmt_close(MYSQL_STMT *stmt, my_bool remove) @@ -1018,8 +995,6 @@ static my_bool net_stmt_close(MYSQL_STMT *stmt, my_bool remove) my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt) { - DBUG_ENTER("mysql_stmt_close"); - if (stmt && stmt->mysql && stmt->mysql->net.pvio) mysql_stmt_internal_reset(stmt, 1); @@ -1028,16 +1003,13 @@ my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt) free(stmt->extension); free(stmt); - DBUG_RETURN(0); + return(0); } void STDCALL mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong offset) { my_ulonglong i= offset; MYSQL_ROWS *ptr= stmt->result.data; - DBUG_ENTER("mysql_stmt_data_seek"); - - DBUG_PRINT("info", ("total rows: %llu offset: %llu", stmt->result.rows, offset)); while(i-- && ptr) ptr= ptr->next; @@ -1045,7 +1017,7 @@ void STDCALL mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong offset) stmt->result_cursor= ptr; stmt->state= MYSQL_STMT_USER_FETCHING; - DBUG_VOID_RETURN; + return; } unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT *stmt) @@ -1068,53 +1040,49 @@ int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt) unsigned char *row; int rc; - DBUG_ENTER("mysql_stmt_fetch"); - if (stmt->state <= MYSQL_STMT_EXECUTED) { SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (stmt->state < MYSQL_STMT_WAITING_USE_OR_STORE || !stmt->field_count) { SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } else if (stmt->state== MYSQL_STMT_WAITING_USE_OR_STORE) { stmt->default_rset_handler(stmt); } if (stmt->state == MYSQL_STMT_FETCH_DONE) - DBUG_RETURN(MYSQL_NO_DATA); + return(MYSQL_NO_DATA); if ((rc= stmt->mysql->methods->db_stmt_fetch(stmt, &row))) { stmt->state= MYSQL_STMT_FETCH_DONE; stmt->mysql->status= MYSQL_STATUS_READY; /* to fetch data again, stmt must be executed again */ - DBUG_RETURN(rc); + return(rc); } if ((rc= stmt->mysql->methods->db_stmt_fetch_to_bind(stmt, row))) { - DBUG_RETURN(rc); + return(rc); } stmt->state= MYSQL_STMT_USER_FETCHING; CLEAR_CLIENT_ERROR(stmt->mysql); CLEAR_CLIENT_STMT_ERROR(stmt); - DBUG_RETURN(0); + return(0); } int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind, unsigned int column, unsigned long offset) { - DBUG_ENTER("mysql_stmt_fetch"); - if (stmt->state < MYSQL_STMT_USER_FETCHING || column >= stmt->field_count || stmt->state == MYSQL_STMT_FETCH_DONE) { SET_CLIENT_STMT_ERROR(stmt, CR_NO_DATA, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (!stmt->bind[column].row_ptr) @@ -1142,7 +1110,7 @@ int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind, unsigned mysql_ps_fetch_functions[stmt->fields[column].type].func(&bind[0], &stmt->fields[column], &stmt->bind[column].row_ptr); stmt->bind[column].row_ptr= save_ptr; } - DBUG_RETURN(0); + return(0); } unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt) @@ -1160,14 +1128,13 @@ MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql) { MYSQL_STMT *stmt= NULL; - DBUG_ENTER("mysql_stmt_init"); if (!(stmt= (MYSQL_STMT *)calloc(1, sizeof(MYSQL_STMT))) || !(stmt->extension= (MADB_STMT_EXTENSION *)calloc(1, sizeof(MADB_STMT_EXTENSION)))) { free(stmt); SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(NULL); + return(NULL); } @@ -1190,7 +1157,7 @@ MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql) ma_init_ma_alloc_root(&stmt->result.alloc, 4096, 0); ma_init_ma_alloc_root(&((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root, 2048, 0); - DBUG_RETURN(stmt); + return(stmt); } my_bool mthd_stmt_read_prepare_response(MYSQL_STMT *stmt) @@ -1198,18 +1165,14 @@ my_bool mthd_stmt_read_prepare_response(MYSQL_STMT *stmt) ulong packet_length; uchar *p; - DBUG_ENTER("read_prepare_response"); - if ((packet_length= net_safe_read(stmt->mysql)) == packet_error) - DBUG_RETURN(1); - - DBUG_PRINT("info",("packet_length= %ld",packet_length)); + return(1); p= (uchar *)stmt->mysql->net.read_pos; if (0xFF == p[0]) /* Error occured */ { - DBUG_RETURN(1); + return(1); } p++; @@ -1223,48 +1186,44 @@ my_bool mthd_stmt_read_prepare_response(MYSQL_STMT *stmt) p++; stmt->upsert_status.warning_count= uint2korr(p); - DBUG_RETURN(0); + return(0); } my_bool mthd_stmt_get_param_metadata(MYSQL_STMT *stmt) { MYSQL_DATA *result; - DBUG_ENTER("stmt_get_param_metadata"); - if (!(result= stmt->mysql->methods->db_read_rows(stmt->mysql, (MYSQL_FIELD *)0, 7))) - DBUG_RETURN(1); + return(1); free_rows(result); - DBUG_RETURN(0); + return(0); } my_bool mthd_stmt_get_result_metadata(MYSQL_STMT *stmt) { MYSQL_DATA *result; MA_MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; - DBUG_ENTER("stmt_read_result_metadata"); if (!(result= stmt->mysql->methods->db_read_rows(stmt->mysql, (MYSQL_FIELD *)0, 7))) - DBUG_RETURN(1); + return(1); if (!(stmt->fields= unpack_fields(result,fields_ma_alloc_root, stmt->field_count, 0, stmt->mysql->server_capabilities & CLIENT_LONG_FLAG))) - DBUG_RETURN(1); - DBUG_RETURN(0); + return(1); + return(0); } int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, size_t length) { MYSQL *mysql= stmt->mysql; int rc= 1; - DBUG_ENTER("mysql_stmt_prepare"); enum mariadb_com_multi multi= MARIADB_COM_MULTI_END; if (!stmt->mysql) { SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (length == -1) @@ -1343,38 +1302,37 @@ int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, size_t lengt } } stmt->state = MYSQL_STMT_PREPARED; - DBUG_RETURN(0); + return(0); fail: stmt->state= MYSQL_STMT_INITTED; SET_CLIENT_STMT_ERROR(stmt, mysql->net.last_errno, mysql->net.sqlstate, mysql->net.last_error); - DBUG_RETURN(rc); + return(rc); } int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) { unsigned int last_server_status; - DBUG_ENTER("mysql_stmt_store_result"); if (!stmt->mysql) { SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (!stmt->field_count) - DBUG_RETURN(0); + return(0); /* test_pure_coverage requires checking of error_no */ if (stmt->last_errno) - DBUG_RETURN(1); + return(1); if (stmt->state < MYSQL_STMT_EXECUTED) { SET_CLIENT_ERROR(stmt->mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } last_server_status= stmt->mysql->server_status; @@ -1388,14 +1346,14 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) if (stmt->mysql->methods->db_command(stmt->mysql, COM_STMT_FETCH, buff, sizeof(buff), 1, stmt)) - DBUG_RETURN(1); + return(1); /* todo: cursor */ } else if (stmt->mysql->status != MYSQL_STATUS_GET_RESULT) { SET_CLIENT_ERROR(stmt->mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (stmt->mysql->methods->db_stmt_read_all_rows(stmt)) @@ -1405,7 +1363,7 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) stmt->result.data= NULL; stmt->result.rows= 0; stmt->mysql->status= MYSQL_STATUS_READY; - DBUG_RETURN(1); + return(1); } /* workaround for MDEV 6304: @@ -1429,7 +1387,7 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) stmt->upsert_status.affected_rows= stmt->result.rows; stmt->mysql->affected_rows= stmt->result.rows; - DBUG_RETURN(0); + return(0); } static int madb_alloc_stmt_fields(MYSQL_STMT *stmt) @@ -1437,8 +1395,6 @@ static int madb_alloc_stmt_fields(MYSQL_STMT *stmt) uint i; MA_MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; - DBUG_ENTER("madb_alloc_stmt_fields"); - if (stmt->mysql->field_count) { ma_free_root(fields_ma_alloc_root, MYF(0)); @@ -1446,7 +1402,7 @@ static int madb_alloc_stmt_fields(MYSQL_STMT *stmt) sizeof(MYSQL_FIELD) * stmt->mysql->field_count))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } stmt->field_count= stmt->mysql->field_count; @@ -1475,28 +1431,26 @@ static int madb_alloc_stmt_fields(MYSQL_STMT *stmt) if (!(stmt->bind= (MYSQL_BIND *)ma_alloc_root(fields_ma_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } - bzero(stmt->bind, stmt->field_count * sizeof(MYSQL_BIND)); + memset(stmt->bind, 0, stmt->field_count * sizeof(MYSQL_BIND)); stmt->bind_result_done= 0; } - DBUG_RETURN(0); + return(0); } int stmt_read_execute_response(MYSQL_STMT *stmt) { MYSQL *mysql= stmt->mysql; - DBUG_ENTER("stmt_read_execute_response"); - if (!mysql) - DBUG_RETURN(1); + return(1); int ret= test((mysql->methods->db_read_stmt_result && mysql->methods->db_read_stmt_result(mysql))); /* if a reconnect occured, our connection handle is invalid */ if (!stmt->mysql) - DBUG_RETURN(1); + return(1); /* update affected rows, also if an error occured */ stmt->upsert_status.affected_rows= stmt->mysql->affected_rows; @@ -1506,7 +1460,7 @@ int stmt_read_execute_response(MYSQL_STMT *stmt) SET_CLIENT_STMT_ERROR(stmt, mysql->net.last_errno, mysql->net.sqlstate, mysql->net.last_error); stmt->state= MYSQL_STMT_PREPARED; - DBUG_RETURN(1); + return(1); } stmt->upsert_status.last_insert_id= mysql->insert_id; stmt->upsert_status.server_status= mysql->server_status; @@ -1536,7 +1490,7 @@ int stmt_read_execute_response(MYSQL_STMT *stmt) sizeof(MYSQL_FIELD) * mysql->field_count))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } stmt->field_count= mysql->field_count; @@ -1604,10 +1558,10 @@ int stmt_read_execute_response(MYSQL_STMT *stmt) { /* table was altered, see test_wl4166_2 */ SET_CLIENT_STMT_ERROR(stmt, CR_NEW_STMT_METADATA, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } } - DBUG_RETURN(0); + return(0); } int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) @@ -1618,12 +1572,10 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) size_t request_len= 0; enum mariadb_com_multi multi= MARIADB_COM_MULTI_END; - DBUG_ENTER("mysql_stmt_execute"); - if (!stmt->mysql) { SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } mysql_get_optionv(mysql, MARIADB_OPT_COM_MULTI, &multi); @@ -1632,13 +1584,13 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) { SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (stmt->param_count && !stmt->bind_param_done) { SET_CLIENT_STMT_ERROR(stmt, CR_PARAMS_NOT_BOUND, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (stmt->state == MYSQL_STMT_WAITING_USE_OR_STORE) @@ -1661,7 +1613,6 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) stmt->result.rows= 0; } request= (char *)mysql_stmt_execute_generate_request(stmt, &request_len); - DBUG_PRINT("info",("request_len=%ld", request_len)); ret= stmt->mysql->methods->db_command(mysql, COM_STMT_EXECUTE, request, request_len, 1, stmt); @@ -1673,13 +1624,13 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) { SET_CLIENT_STMT_ERROR(stmt, mysql->net.last_errno, mysql->net.sqlstate, mysql->net.last_error); - DBUG_RETURN(1); + return(1); } if (multi == MARIADB_COM_MULTI_BEGIN) - DBUG_RETURN(0); + return(0); - DBUG_RETURN(stmt_read_execute_response(stmt)); + return(stmt_read_execute_response(stmt)); } static my_bool madb_reset_stmt(MYSQL_STMT *stmt, unsigned int flags) @@ -1687,11 +1638,10 @@ static my_bool madb_reset_stmt(MYSQL_STMT *stmt, unsigned int flags) MYSQL *mysql= stmt->mysql; my_bool ret= 0; - DBUG_ENTER("madb_stmt_reset"); if (!stmt->mysql) { SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } /* clear error */ @@ -1747,7 +1697,7 @@ static my_bool madb_reset_stmt(MYSQL_STMT *stmt, unsigned int flags) { SET_CLIENT_STMT_ERROR(stmt, mysql->net.last_errno, mysql->net.sqlstate, mysql->net.last_error); - DBUG_RETURN(ret); + return(ret); } } } @@ -1764,7 +1714,7 @@ static my_bool madb_reset_stmt(MYSQL_STMT *stmt, unsigned int flags) } } - DBUG_RETURN(ret); + return(ret); } static my_bool mysql_stmt_internal_reset(MYSQL_STMT *stmt, my_bool is_close) @@ -1773,14 +1723,12 @@ static my_bool mysql_stmt_internal_reset(MYSQL_STMT *stmt, my_bool is_close) my_bool ret= 1; unsigned int flags= MADB_RESET_LONGDATA | MADB_RESET_BUFFER | MADB_RESET_ERROR; - DBUG_ENTER("mysql_stmt_internal_reset"); - if (!mysql) { /* connection could be invalid, e.g. after mysql_stmt_close or failed reconnect attempt (see bug CONC-97) */ SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (stmt->state >= MYSQL_STMT_USER_FETCHING && @@ -1819,29 +1767,27 @@ static my_bool mysql_stmt_internal_reset(MYSQL_STMT *stmt, my_bool is_close) stmt->upsert_status.warning_count= mysql->warning_count; mysql->status= MYSQL_STATUS_READY; - DBUG_RETURN(ret); + return(ret); } MYSQL_RES * STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt) { MYSQL_RES *res; - DBUG_ENTER("mysql_stmt_result_metadata"); - if (!stmt->field_count) - DBUG_RETURN(NULL); + return(NULL); /* aloocate result set structutr and copy stmt information */ if (!(res= (MYSQL_RES *)calloc(1, sizeof(MYSQL_RES)))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(NULL); + return(NULL); } res->eof= 1; res->fields= stmt->fields; res->field_count= stmt->field_count; - DBUG_RETURN(res); + return(res); } my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt) @@ -1856,8 +1802,7 @@ const char * STDCALL mysql_stmt_sqlstate(MYSQL_STMT *stmt) MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_tell(MYSQL_STMT *stmt) { - DBUG_ENTER("mysql_stmt_row_tell"); - DBUG_RETURN(stmt->result_cursor); + return(stmt->result_cursor); } unsigned long STDCALL mysql_stmt_param_count(MYSQL_STMT *stmt) @@ -1868,32 +1813,29 @@ unsigned long STDCALL mysql_stmt_param_count(MYSQL_STMT *stmt) MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_seek(MYSQL_STMT *stmt, MYSQL_ROW_OFFSET new_row) { MYSQL_ROW_OFFSET old_row; /* for returning old position */ - DBUG_ENTER("mysql_stmt_row_seek"); old_row= stmt->result_cursor; stmt->result_cursor= new_row; - DBUG_RETURN(old_row); + return(old_row); } my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number, const char *data, size_t length) { - DBUG_ENTER("mysql_stmt_send_long_data"); - CLEAR_CLIENT_ERROR(stmt->mysql); CLEAR_CLIENT_STMT_ERROR(stmt); if (stmt->state < MYSQL_STMT_PREPARED || !stmt->params) { SET_CLIENT_STMT_ERROR(stmt, CR_NO_PREPARE_STMT, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (param_number >= stmt->param_count) { SET_CLIENT_STMT_ERROR(stmt, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (length || !stmt->params[param_number].long_data_used) @@ -1908,9 +1850,9 @@ my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number, ret= stmt->mysql->methods->db_command(stmt->mysql, COM_STMT_SEND_LONG_DATA, (char *)cmd_buff, packet_len, 1, stmt); free(cmd_buff); - DBUG_RETURN(ret); + return(ret); } - DBUG_RETURN(0); + return(0); } my_ulonglong STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt) @@ -1925,11 +1867,10 @@ my_ulonglong STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt) MYSQL_RES* STDCALL mysql_stmt_param_metadata(MYSQL_STMT *stmt) { - DBUG_ENTER("mysql_stmt_param_metadata"); /* server doesn't deliver any information yet, so we just return NULL */ - DBUG_RETURN(NULL); + return(NULL); } my_bool STDCALL mysql_stmt_more_results(MYSQL_STMT *stmt) @@ -1948,23 +1889,22 @@ my_bool STDCALL mysql_stmt_more_results(MYSQL_STMT *stmt) int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt) { int rc= 0; - DBUG_ENTER("mysql_stmt_next_result"); if (!stmt->mysql) { SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (stmt->state < MYSQL_STMT_EXECUTED) { SET_CLIENT_ERROR(stmt->mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (!mysql_stmt_more_results(stmt)) - DBUG_RETURN(-1); + return(-1); if (stmt->state > MYSQL_STMT_EXECUTED && stmt->state < MYSQL_STMT_FETCH_DONE) @@ -1976,7 +1916,7 @@ int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt) stmt->state= MYSQL_STMT_FETCH_DONE; SET_CLIENT_STMT_ERROR(stmt, stmt->mysql->net.last_errno, stmt->mysql->net.sqlstate, stmt->mysql->net.last_error); - DBUG_RETURN(1); + return(1); } if (stmt->mysql->field_count) @@ -1991,7 +1931,7 @@ int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt) stmt->field_count= stmt->mysql->field_count; - DBUG_RETURN(rc); + return(rc); } int STDCALL mariadb_stmt_execute_direct(MYSQL_STMT *stmt, diff --git a/libmariadb/mf_dirname.c b/libmariadb/mf_dirname.c deleted file mode 100644 index c5ebe64e..00000000 --- a/libmariadb/mf_dirname.c +++ /dev/null @@ -1,100 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include - - /* Functions definied in this file */ - -uint ma_dirname_length(const char *name) -{ - register my_string pos,gpos; -#ifdef FN_DEVCHAR - if ((pos=(char*)strrchr(name,FN_DEVCHAR)) == 0) -#endif - pos=(char*) name-1; - - gpos= pos++; - for ( ; *pos ; pos++) /* Find last FN_LIBCHAR */ - if (*pos == FN_LIBCHAR || *pos == '/' -#ifdef FN_C_AFTER_DIR - || *pos == FN_C_AFTER_DIR || *pos == FN_C_AFTER_DIR_2 -#endif - ) - gpos=pos; - return ((uint) (uint) (gpos+1-(char*) name)); -} - - - /* Gives directory part of filename. Directory ends with '/' */ - /* Returns length of directory part */ - -uint ma_dirname_part(my_string to, const char *name) -{ - uint length; - DBUG_ENTER("ma_dirname_part"); - DBUG_PRINT("enter",("'%s'",name)); - - length=ma_dirname_length(name); - strncpy(to,(char*) name,min(length,FN_REFLEN-2)); - ma_convert_dirname(to); /* Convert chars */ - DBUG_RETURN(length); -} /* dirname */ - - - /* convert dirname to use under this system */ - /* If MSDOS converts '/' to '\' */ - /* If VMS converts '<' to '[' and '>' to ']' */ - /* Adds a '/' to end if there isn't one and the last isn't a dev_char */ - /* ARGSUSED */ - -#ifndef FN_DEVCHAR -#define FN_DEVCHAR '\0' /* For easier code */ -#endif - -char *ma_convert_dirname(my_string to) -{ - reg1 char *pos; -#if FN_LIBCHAR != '/' - { - pos=to-1; /* Change from '/' */ - while ((pos=strchr(pos+1,'/')) != 0) - *pos=FN_LIBCHAR; - } -#endif -#ifdef FN_C_BEFORE_DIR_2 - { - for (pos=to ; *pos ; pos++) - { - if (*pos == FN_C_BEFORE_DIR_2) - *pos=FN_C_BEFORE_DIR; - if (*pos == FN_C_AFTER_DIR_2) - *pos=FN_C_AFTER_DIR; - } - } -#else - { /* Append FN_LIBCHAR if not there */ - pos=strend(to); - if (pos != to && (pos[-1] != FN_LIBCHAR && pos[-1] != FN_DEVCHAR)) - { - *pos++=FN_LIBCHAR; - *pos=0; - } - } -#endif - return pos; /* Pointer to end of dir */ -} /* convert_dirname */ diff --git a/libmariadb/mf_fn_ext.c b/libmariadb/mf_fn_ext.c deleted file mode 100644 index abb98291..00000000 --- a/libmariadb/mf_fn_ext.c +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* Returnerar en pekare till filnamnets extension. */ - -#include "mysys_priv.h" -#include - - /* Return a pointerto the extension of the filename - The pointer points at the extension character (normally '.')) - If there isn't any extension, the pointer points at the end - NULL of the filename - */ - -my_string ma_fn_ext(const char *name) -{ - register my_string pos,gpos; - DBUG_ENTER("ma_fn_ext"); - DBUG_PRINT("mfunkt",("name: '%s'",name)); - -#if defined(FN_DEVCHAR) || defined(FN_C_AFTER_DIR) - { - char buff[FN_REFLEN]; - gpos=(my_string) name + ma_dirname_part(buff,(char*) name); - } -#else - if (!(gpos=strrchr(name,FNLIBCHAR))) - gpos=name; -#endif - pos=strrchr(gpos,FN_EXTCHAR); - DBUG_RETURN (pos ? pos : strend(gpos)); -} /* ma_fn_ext */ diff --git a/libmariadb/mf_format.c b/libmariadb/mf_format.c deleted file mode 100644 index 7feb4aab..00000000 --- a/libmariadb/mf_format.c +++ /dev/null @@ -1,156 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include -#ifdef HAVE_REALPATH -#include -#include -#endif - - /* format a filename with replace of library and extension */ - /* params to and name may be identicall */ - /* function doesn't change name if name != to */ - /* Flag may be: 1 replace filenames library with 'dsk' */ - /* 2 replace extension with 'form' */ - /* 4 Unpack filename (replace ~ with home) */ - /* 8 Pack filename as short as possibly */ - /* 16 Resolve symbolic links for filename */ - /* 32 Resolve filename to full path */ - /* 64 Return NULL if too long path */ - -#ifdef SCO -#define BUFF_LEN 4097 -#else -#ifdef MAXPATHLEN -#define BUFF_LEN MAXPATHLEN -#else -#define BUFF_LEN FN_LEN -#endif -#endif - -my_string ma_fn_format(my_string to, const char *name, const char *dsk, - const char *form, int flag) -{ - reg1 uint length= 0; - char dev[FN_REFLEN], buff[BUFF_LEN], *pos, *startpos; - const char *ext; - DBUG_ENTER("fn_format"); - DBUG_PRINT("enter",("name: %s dsk: %s form: %s flag: %d", - name,dsk,form,flag)); - - /* Kopiera & skippa enheten */ - name+=(length=ma_dirname_part(dev,(startpos=(my_string) name))); - if (length == 0 || flag & 1) - { - strncpy(dev,dsk, sizeof(dev) - 2); - /* Use given directory */ - ma_convert_dirname(dev); /* Fix to this OS */ - } - if (flag & 8) - ma_pack_dirname(dev,dev); /* Put in ./.. and ~/.. */ - if (flag & 4) - (void) unma_pack_dirname(dev,dev); /* Replace ~/.. with dir */ - if ((pos=(char*)strchr(name,FN_EXTCHAR)) != NullS) - { - if ((flag & 2) == 0) /* Skall vi byta extension ? */ - { - length=ma_strlength(name); /* Old extension */ - ext = ""; - } - else - { - length=(uint) (pos-(char*) name); /* Change extension */ - ext= form; - } - } - else - { - length=ma_strlength(name); /* Har ingen ext- tag nya */ - ext=form; - } - - if (strlen(dev)+length+strlen(ext) >= FN_REFLEN || length >= FN_LEN ) - { /* To long path, return original */ - uint tmp_length; - if (flag & 64) - return 0; - tmp_length=ma_strlength(startpos); - DBUG_PRINT("error",("dev: '%s' ext: '%s' length: %d",dev,ext,length)); - strncpy(to,startpos,min(tmp_length,FN_REFLEN-1)); - } - else - { - if (to == startpos) - { - bmove(buff,(char*) name,length); /* Save name for last copy */ - name=buff; - } - pos=strncpy(strmov(to,dev),name,length) + strlen(to); -#ifdef FN_UPPER_CASE - caseup_str(to); -#endif -#ifdef FN_LOWER_CASE - casedn_str(to); -#endif - (void) strmov(pos,ext); /* Don't convert extension */ - } - /* Purify gives a lot of UMR errors when using realpath */ -#if defined(HAVE_REALPATH) && !defined(HAVE_purify) && !defined(HAVE_BROKEN_REALPATH) - if (flag & 16) - { - struct stat stat_buff; - if (flag & 32 || (!lstat(to,&stat_buff) && S_ISLNK(stat_buff.st_mode))) - { - if (realpath(to,buff)) - strncpy(to,buff,FN_REFLEN-1); - } - } -#endif - DBUG_RETURN (to); -} /* fn_format */ - - - /* - ma_strlength(const string str) - Return length of string with end-space:s not counted. - */ - -size_s ma_strlength(const char *str) -{ - reg1 my_string pos; - reg2 my_string found; - DBUG_ENTER("ma_strlength"); - - pos=found=(char*) str; - - while (*pos) - { - if (*pos != ' ') - { - while (*++pos && *pos != ' ') {}; - if (!*pos) - { - found=pos; /* String ends here */ - break; - } - } - found=pos; - while (*++pos == ' ') {}; - } - DBUG_RETURN((size_s) (found-(char*) str)); -} /* ma_strlength */ diff --git a/libmariadb/mf_loadpath.c b/libmariadb/mf_loadpath.c deleted file mode 100644 index 35bf54be..00000000 --- a/libmariadb/mf_loadpath.c +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include - - /* Returns full load-path for a file. to may be = path */ - /* if path is a hard-path return path */ - /* if path starts with home-dir return path */ - /* if path starts with current dir or parent-dir unpack path */ - /* if there is no path, prepend with own_path_prefix if given */ - /* else unpack path according to current dir */ - -my_string my_load_path(my_string to, const char *path, - const char *own_path_prefix) -{ - char buff[FN_REFLEN]; - DBUG_ENTER("my_load_path"); - DBUG_PRINT("enter",("path: %s prefix: %s",path, - own_path_prefix ? own_path_prefix : "")); - - if ((path[0] == FN_HOMELIB && path[1] == FN_LIBCHAR) || - test_if_hard_path(path)) - VOID(strmov(buff,path)); - else if ((path[0] == FN_CURLIB && path[1] == FN_LIBCHAR) || - (is_prefix((gptr) path,FN_PARENTDIR) && - path[strlen(FN_PARENTDIR)] == FN_LIBCHAR) || - ! own_path_prefix) - { - if (! my_getwd(buff,(uint) (FN_REFLEN-strlen(path)),MYF(0))) - VOID(strcat(buff,path)); - else - VOID(strmov(buff,path)); - } - else - strcat(strcat(buff, own_path_prefix), path); - strcpy(to,buff); - DBUG_PRINT("exit",("to: %s",to)); - DBUG_RETURN(to); -} /* my_load_path */ diff --git a/libmariadb/mf_pack.c b/libmariadb/mf_pack.c deleted file mode 100644 index f8067ec2..00000000 --- a/libmariadb/mf_pack.c +++ /dev/null @@ -1,532 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include -#ifdef HAVE_PWD_H -#include -#endif -#ifdef VMS -#include -#include -#include -#endif /* VMS */ - -static my_string NEAR_F expand_tilde(my_string *path); - - /* Pack a dirname ; Changes HOME to ~/ and current dev to ./ */ - /* from is a dirname (from dirname() ?) ending with FN_LIBCHAR */ - /* to may be == from */ - -void ma_pack_dirname(my_string to, const char *from) -{ - int cwd_err; - uint d_length,length,buff_length= 0; - my_string start; - char buff[FN_REFLEN]; - DBUG_ENTER("ma_pack_dirname"); - - (void) ma_intern_filename(to,from); /* Change to intern name */ - -#ifdef FN_DEVCHAR - if ((start=strrchr(to,FN_DEVCHAR)) != 0) /* Skipp device part */ - start++; - else -#endif - start=to; - - LINT_INIT(buff_length); - if (!(cwd_err= my_getwd(buff,FN_REFLEN,MYF(0)))) - { - buff_length= (uint) strlen(buff); - d_length=(uint) (start-to); - if ((start == to || - (buff_length == d_length && !bcmp(buff,start,d_length))) && - *start != FN_LIBCHAR && *start) - { /* Put current dir before */ - bchange(to,d_length,buff,buff_length,(uint) strlen(to)+1); - } - } - - if ((d_length= ma_cleanup_dirname(to,to)) != 0) - { - length=0; - if (ma_ma_ma_home_dir) - { - length= (uint) strlen(ma_ma_ma_home_dir); - if (ma_ma_ma_home_dir[length-1] == FN_LIBCHAR) - length--; /* Don't test last '/' */ - } - if (length > 1 && length < d_length) - { /* test if /xx/yy -> ~/yy */ - if (bcmp(to,ma_ma_ma_home_dir,length) == 0 && to[length] == FN_LIBCHAR) - { - to[0]=FN_HOMELIB; /* Filename begins with ~ */ - (void) strmov_overlapp(to+1,to+length); - } - } - if (! cwd_err) - { /* Test if cwd is ~/... */ - if (length > 1 && length < buff_length) - { - if (bcmp(buff,ma_ma_ma_home_dir,length) == 0 && buff[length] == FN_LIBCHAR) - { - buff[0]=FN_HOMELIB; - (void) strmov_overlapp(buff+1,buff+length); - } - } - if (is_prefix(to,buff)) - { - length= (uint) strlen(buff); - if (to[length]) - (void) strmov_overlapp(to,to+length); /* Remove everything before */ - else - { - to[0]= FN_CURLIB; /* Put ./ instead of cwd */ - to[1]= FN_LIBCHAR; - to[2]= '\0'; - } - } - } - } - DBUG_PRINT("exit",("to: '%s'",to)); - DBUG_VOID_RETURN; -} /* ma_pack_dirname */ - - - /* remove unwanted chars from dirname */ - /* if "/../" removes prev dir; "/~/" removes all before ~ */ - /* "//" is same as "/", except on Win32 at start of a file */ - /* "/./" is removed */ - /* Unpacks ma_ma_ma_home_dir if "~/.." used */ - /* Unpacks current dir if if "./.." used */ - -uint ma_cleanup_dirname(register my_string to, const char *from) - /* to may be == from */ - -{ - reg5 uint length; - reg2 my_string pos; - reg3 my_string from_ptr; - reg4 my_string start; - char parent[5], /* for "FN_PARENTDIR" */ - buff[FN_REFLEN+1],*end_parentdir; - DBUG_ENTER("ma_cleanup_dirname"); - DBUG_PRINT("enter",("from: '%s'",from)); - - start=buff; - from_ptr=(my_string) from; -#ifdef FN_DEVCHAR - if ((pos=strrchr(from_ptr,FN_DEVCHAR)) != 0) - { /* Skipp device part */ - length=(uint) (pos-from_ptr)+1; - start=strnmov(buff,from_ptr,length); from_ptr+=length; - } -#endif - - parent[0]=FN_LIBCHAR; - length=(uint) (strmov(parent+1,FN_PARENTDIR)-parent); - for (pos=start ; (*pos= *from_ptr++) != 0 ; pos++) - { - if (*pos == '/') - *pos = FN_LIBCHAR; - if (*pos == FN_LIBCHAR) - { - if ((uint) (pos-start) > length && bcmp(pos-length,parent,length) == 0) - { /* If .../../; skipp prev */ - pos-=length; - if (pos != start) - { /* not /../ */ - pos--; - if (*pos == FN_HOMELIB && (pos == start || pos[-1] == FN_LIBCHAR)) - { - if (!ma_ma_ma_home_dir) - { - pos+=length+1; /* Don't unpack ~/.. */ - continue; - } - pos=strmov(buff,ma_ma_ma_home_dir)-1; /* Unpacks ~/.. */ - if (*pos == FN_LIBCHAR) - pos--; /* home ended with '/' */ - } - if (*pos == FN_CURLIB && (pos == start || pos[-1] == FN_LIBCHAR)) - { - if (my_getwd(ma_cur_dir,FN_REFLEN,MYF(0))) - { - pos+=length+1; /* Don't unpack ./.. */ - continue; - } - pos=strmov(buff,ma_cur_dir)-1; /* Unpacks ./.. */ - if (*pos == FN_LIBCHAR) - pos--; /* home ended with '/' */ - } - end_parentdir=pos; - while (pos >= start && *pos != FN_LIBCHAR) /* remove prev dir */ - pos--; - if (pos[1] == FN_HOMELIB || bcmp(pos,parent,length) == 0) - { /* Don't remove ~user/ */ - pos=strmov(end_parentdir+1,parent); - *pos=FN_LIBCHAR; - continue; - } - } - } - else if ((uint) (pos-start) == length-1 && - !bcmp(start,parent+1,length-1)) - start=pos; /* Starts with "../" */ - else if (pos-start > 0 && pos[-1] == FN_LIBCHAR) - { -#ifdef FN_NETWORK_DRIVES - if (pos-start != 1) -#endif - pos--; /* Remove dupplicate '/' */ - } - else if (pos-start > 1 && pos[-1] == FN_CURLIB && pos[-2] == FN_LIBCHAR) - pos-=2; /* Skipp /./ */ - else if (pos > buff+1 && pos[-1] == FN_HOMELIB && pos[-2] == FN_LIBCHAR) - { /* Found ..../~/ */ - buff[0]=FN_HOMELIB; - buff[1]=FN_LIBCHAR; - start=buff; pos=buff+1; - } - } - } - (void) strmov(to,buff); - DBUG_PRINT("exit",("to: '%s'",to)); - DBUG_RETURN((uint) (pos-buff)); -} /* ma_cleanup_dirname */ - - - /* - On system where you don't have symbolic links, the following - code will allow you to create a file: - directory-name.lnk that should contain the real path - to the directory. This will be used if the directory name - doesn't exists - */ - - -my_bool ma_use_symdir=0; /* Set this if you want to use symdirs */ - -#ifdef USE_SYMDIR -void symdirget(char *dir) -{ - char buff[FN_REFLEN]; - char *pos=strend(dir); - if (dir[0] && pos[-1] != FN_DEVCHAR && access(dir, F_OK)) - { - FILE *fp; - char temp= *(--pos); /* May be "/" or "\" */ - strcpy(pos,".sym"); - fp = my_fopen(dir, O_RDONLY,MYF(0)); - *pos++=temp; *pos=0; /* Restore old filename */ - if (fp) - { - if (fgets(buff, sizeof(buff)-1, fp)) - { - for (pos=strend(buff); - pos > buff && (iscntrl(pos[-1]) || isspace(pos[-1])) ; - pos --); - - /* Ensure that the symlink ends with the directory symbol */ - if (pos == buff || pos[-1] != FN_LIBCHAR) - *pos++=FN_LIBCHAR; - - strncpy(dir,buff, (uint) (pos-buff)); - } - my_fclose(fp,MYF(0)); - } - } -} -#endif /* USE_SYMDIR */ - - /* Unpacks dirname to name that can be used by open... */ - /* Make that last char of to is '/' if from not empty and - from doesn't end in FN_DEVCHAR */ - /* Uses ma_cleanup_dirname and changes ~/.. to ma_ma_ma_home_dir/.. */ - /* Returns length of new directory */ - -uint unma_pack_dirname(my_string to, const char *from) - - /* to may be == from */ -{ - uint length,h_length; - char buff[FN_REFLEN+1+4],*suffix,*tilde_expansion; - DBUG_ENTER("unma_pack_dirname"); - - (void) ma_intern_filename(buff,from); /* Change to intern name */ - length= (uint) strlen(buff); /* Fix that '/' is last */ - if (length && -#ifdef FN_DEVCHAR - buff[length-1] != FN_DEVCHAR && -#endif - buff[length-1] != FN_LIBCHAR && buff[length-1] != '/') - { - buff[length]=FN_LIBCHAR; - buff[length+1]= '\0'; - } - - length=ma_cleanup_dirname(buff,buff); - if (buff[0] == FN_HOMELIB) - { - suffix=buff+1; tilde_expansion=expand_tilde(&suffix); - if (tilde_expansion) - { - length-=(uint) (suffix-buff)-1; - if (length+(h_length= (uint) strlen(tilde_expansion)) <= FN_REFLEN) - { - if (tilde_expansion[h_length-1] == FN_LIBCHAR) - h_length--; - if (buff+h_length < suffix) - bmove(buff+h_length,suffix,length); - else - bmove_upp(buff+h_length+length,suffix+length,length); - bmove(buff,tilde_expansion,h_length); - } - } - } -#ifdef USE_SYMDIR - if (ma_use_symdir) - symdirget(buff); -#endif - DBUG_RETURN(ma_system_filename(to,buff)); /* Fix for open */ -} /* unma_pack_dirname */ - - - /* Expand tilde to home or user-directory */ - /* Path is reset to point at FN_LIBCHAR after ~xxx */ - -static my_string NEAR_F expand_tilde(my_string *path) -{ - if (path[0][0] == FN_LIBCHAR) - return ma_ma_ma_home_dir; /* ~/ expanded to home */ -#ifdef HAVE_GETPWNAM - { - char *str,save; - struct passwd *user_entry; - - if (!(str=strchr(*path,FN_LIBCHAR))) - str=strend(*path); - save= *str; *str= '\0'; - user_entry=getpwnam(*path); - *str=save; - endpwent(); - if (user_entry) - { - *path=str; - return user_entry->pw_dir; - } - } -#endif - return (my_string) 0; -} - - /* fix filename so it can be used by open, create .. */ - /* to may be == from */ - /* Returns to */ - -my_string ma_unpack_filename(my_string to, const char *from) -{ - uint length,n_length; - char buff[FN_REFLEN]; - DBUG_ENTER("ma_unpack_filename"); - - length=ma_dirname_part(buff,from); /* copy & convert dirname */ - n_length=unma_pack_dirname(buff,buff); - if (n_length+strlen(from+length) < FN_REFLEN) - { - (void) strmov(buff+n_length,from+length); - (void) ma_system_filename(to,buff); /* Fix to usably filename */ - } - else - (void) ma_system_filename(to,from); /* Fix to usably filename */ - DBUG_RETURN(to); -} /* ma_unpack_filename */ - - - /* Convert filename (unix standard) to system standard */ - /* Used before system command's like open(), create() .. */ - /* Returns to */ - -uint ma_system_filename(my_string to, const char *from) -{ -#ifndef FN_C_BEFORE_DIR - return (uint) strlen(strncpy(to,from,FN_REFLEN-1)); -#else /* VMS */ - - /* change 'dev:lib/xxx' to 'dev:[lib]xxx' */ - /* change 'dev:xxx' to 'dev:xxx' */ - /* change './xxx' to 'xxx' */ - /* change './lib/' or lib/ to '[.lib]' */ - /* change '/x/y/z to '[x.y]x' */ - /* change 'dev:/x' to 'dev:[000000]x' */ - - int libchar_found,length; - my_string to_pos,from_pos,pos; - char buff[FN_REFLEN]; - DBUG_ENTER("ma_system_filename"); - - libchar_found=0; - (void) strmov(buff,from); /* If to == from */ - from_pos= buff; - if ((pos=strrchr(from_pos,FN_DEVCHAR))) /* Skipp device part */ - { - pos++; - to_pos=strnmov(to,from_pos,(size_s) (pos-from_pos)); - from_pos=pos; - } - else - to_pos=to; - - if (from_pos[0] == FN_CURLIB && from_pos[1] == FN_LIBCHAR) - from_pos+=2; /* Skipp './' */ - if (strchr(from_pos,FN_LIBCHAR)) - { - *(to_pos++) = FN_C_BEFORE_DIR; - if (strinstr(from_pos,FN_ROOTDIR) == 1) - { - from_pos+=strlen(FN_ROOTDIR); /* Actually +1 but... */ - if (! strchr(from_pos,FN_LIBCHAR)) - { /* No dir, use [000000] */ - to_pos=strmov(to_pos,FN_C_ROOT_DIR); - libchar_found++; - } - } - else - *(to_pos++)=FN_C_DIR_SEP; /* '.' gives current dir */ - - while ((pos=strchr(from_pos,FN_LIBCHAR))) - { - if (libchar_found++) - *(to_pos++)=FN_C_DIR_SEP; /* Add '.' between dirs */ - if (strinstr(from_pos,FN_PARENTDIR) == 1 && - from_pos+strlen(FN_PARENTDIR) == pos) - to_pos=strmov(to_pos,FN_C_PARENT_DIR); /* Found '../' */ - else - to_pos=strnmov(to_pos,from_pos,(size_s) (pos-from_pos)); - from_pos=pos+1; - } - *(to_pos++)=FN_C_AFTER_DIR; - } - length=(int) (strmov(to_pos,from_pos)-to); - DBUG_PRINT("exit",("name: '%s'",to)); - DBUG_RETURN((uint) length); -#endif -} /* ma_system_filename */ - - - /* Fix a filename to intern (UNIX format) */ - -my_string ma_intern_filename(my_string to, const char *from) -{ -#ifndef VMS - { - uint length= 0; - char buff[FN_REFLEN]; - if (from == to) - { /* Dirname may destroy from */ - strcpy(buff,from); - from=buff; - } - length=ma_dirname_part(to,from); /* Copy dirname & fix chars */ - (void) strcat(to,from+length); - return (to); - } -#else /* VMS */ - - /* change 'dev:[lib]xxx' to 'dev:lib/xxx' */ - /* change 'dev:xxx' to 'dev:xxx' */ - /* change 'dev:x/y/[.lib]' to 'dev:x/y/lib/ */ - /* change '[.lib]' to './lib/' */ - /* change '[x.y]' or '[x.][y]' or '[x][.y]' to '/x/y/' */ - /* change '[000000.x] or [x.000000]' to '/x/' */ - - int par_length,root_length; - my_string pos,from_pos,to_pos,end_pos; - char buff[FN_REFLEN]; - - (void) strmov(buff,from); - convert_dirname(buff); /* change '<>' to '[]' */ - from_pos=buff; - if ((pos=strrchr(from_pos,FN_DEVCHAR))) /* Skipp device part */ - { - pos++; - to_pos=strnmov(to,from_pos,(size_s) (pos-from_pos)); - from_pos=pos; - } - else - to_pos=to; - - root_length=strlen(FN_C_ROOT_DIR); - if ((pos = strchr(from_pos,FN_C_BEFORE_DIR)) && - (end_pos = strrchr(pos+1,FN_C_AFTER_DIR))) - { - to_pos=strnmov(to_pos,from_pos,(size_s) (pos-from_pos)); - /* Copy all between ':' and '[' */ - from_pos=pos+1; - if (strinstr(from_pos,FN_C_ROOT_DIR) == 1 && - (from_pos[root_length] == FN_C_DIR_SEP || - from_pos[root_length] == FN_C_AFTER_DIR)) - { - from_pos+=root_length+1; - } - else if (*from_pos == FN_C_DIR_SEP) - *(to_pos++) = FN_CURLIB; /* Set ./ first */ - *(to_pos++) = FN_LIBCHAR; - - par_length=strlen(FN_C_PARENT_DIR); - pos=to_pos; - for (; from_pos <= end_pos ; from_pos++) - { - switch (*from_pos) { - case FN_C_DIR_SEP: - case FN_C_AFTER_DIR: - if (pos != to_pos) - { - if ((int) (to_pos-pos) == root_length && - is_suffix(pos,FN_C_ROOT_DIR)) - to_pos=pos; /* remove root-pos */ - else - { - *(to_pos++)=FN_LIBCHAR; /* Find lib */ - pos=to_pos; - } - } - break; - case FN_C_BEFORE_DIR: - break; - case '-': /* *(FN_C_PARENT_DIR): */ - if (to_pos[-1] == FN_LIBCHAR && - strncmp(from_pos,FN_C_PARENT_DIR,par_length) == 0) - { /* Change '-' to '..' */ - to_pos=strmov(to_pos,FN_PARENTDIR); - *(to_pos++)=FN_LIBCHAR; - pos=to_pos; - from_pos+=par_length-1; - break; - } - /* Fall through */ - default: - *(to_pos++)= *from_pos; - break; - } - } - } - (void) strmov(to_pos,from_pos); - return (to); -#endif /* VMS */ -} /* ma_intern_filename */ diff --git a/libmariadb/mf_path.c b/libmariadb/mf_path.c deleted file mode 100644 index 8f7fc0b9..00000000 --- a/libmariadb/mf_path.c +++ /dev/null @@ -1,120 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include - -static char *find_file_in_path(char *to,const char *name); - - /* Finds where program can find it's files. - pre_pathname is found by first locking at progname (argv[0]). - if progname contains path the path is returned. - else if progname is found in path, return it - else if progname is given and POSIX environment variable "_" is set - then path is taken from "_". - If filename doesn't contain a path append MY_BASEDIR_VERSION or - MY_BASEDIR if defined, else append "/my/running". - own_path_name_part is concatinated to result. - my_path puts result in to and returns to */ - -my_string my_path(my_string to, const char *progname, - const char *own_pathname_part) -{ - my_string start,end,prog; - DBUG_ENTER("my_path"); - - start=to; /* Return this */ - if (progname && (ma_dirname_part(to, progname) || - find_file_in_path(to,progname) || - ((prog=getenv("_")) != 0 && ma_dirname_part(to,prog)))) - { - VOID(ma_intern_filename(to,to)); - if (!test_if_hard_path(to)) - { - if (!my_getwd(ma_cur_dir,FN_REFLEN,MYF(0))) - bchange(to,0,ma_cur_dir, (uint) strlen(ma_cur_dir), (uint) strlen(to)+1); - } - } - else - { - if ((end = getenv("MY_BASEDIR_VERSION")) == 0 && - (end = getenv("MY_BASEDIR")) == 0) - { -#ifdef DEFAULT_BASEDIR - end= (char*) DEFAULT_BASEDIR; -#else - end= (char*) "/my/"; -#endif - } - VOID(ma_intern_filename(to,end)); - to=strend(to); - if (to != start && to[-1] != FN_LIBCHAR) - *to++ = FN_LIBCHAR; - VOID(strmov(to,own_pathname_part)); - } - DBUG_PRINT("exit",("to: '%s'",start)); - DBUG_RETURN(start); -} /* my_path */ - - - /* test if file without filename is found in path */ - /* Returns to if found and to has dirpart if found, else NullS */ - -#if defined(MSDOS) || defined(_WIN32) || defined(__EMX__) || defined(OS2) -#define F_OK 0 -#define PATH_SEP ';' -#define PROGRAM_EXTENSION ".exe" -#else -#define PATH_SEP ':' -#endif - -static char *find_file_in_path(char *to, const char *name) -{ - char *path,*pos,dir[2]; - const char *ext=""; - - if (!(path=getenv("PATH"))) - return NullS; - dir[0]=FN_LIBCHAR; dir[1]=0; -#ifdef PROGRAM_EXTENSION - if (!ma_fn_ext(name)[0]) - ext=PROGRAM_EXTENSION; -#endif - - for (pos=path ; (pos=strchr(pos,PATH_SEP)) ; path= ++pos) - { - if (path != pos) - { - snprintf(to, pos - path, "%s%s%s%s", path, dir, name, ext); - if (!access(to,F_OK)) - { - to[(uint) (pos-path)+1]=0; /* Return path only */ - return to; - } - } - } -#ifdef _WIN32 - to[0]=FN_CURLIB; - sprintf(to +1, "%s%s%s", dir, name, ext); - if (!access(to,F_OK)) /* Test in current dir */ - { - to[2]=0; /* Leave ".\" */ - return to; - } -#endif - return NullS; /* File not found */ -} diff --git a/libmariadb/mf_unixpath.c b/libmariadb/mf_unixpath.c deleted file mode 100644 index 6ae29f99..00000000 --- a/libmariadb/mf_unixpath.c +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include - - /* convert filename to unix style filename */ - /* If MSDOS converts '\' to '/' */ - -void to_unix_path(my_string to __attribute__((unused))) -{ -#if FN_LIBCHAR != '/' - { - to--; - while ((to=strchr(to+1,FN_LIBCHAR)) != 0) - *to='/'; - } -#endif -} diff --git a/libmariadb/mf_wcomp.c b/libmariadb/mf_wcomp.c deleted file mode 100644 index 5f1ab9b8..00000000 --- a/libmariadb/mf_wcomp.c +++ /dev/null @@ -1,68 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* Funktions for comparing with wild-cards */ - -#include "mysys_priv.h" - - /* Test if a string is "comparable" to a wild-card string */ - /* returns 0 if the strings are "comparable" */ - -char wild_many='*'; -char wild_one='?'; -char wild_prefix=0; - -int wild_compare(register const char *str, register const char *wildstr) -{ - reg3 int flag; - DBUG_ENTER("wild_compare"); - - while (*wildstr) - { - while (*wildstr && *wildstr != wild_many && *wildstr != wild_one) - { - if (*wildstr == wild_prefix && wildstr[1]) - wildstr++; - if (*wildstr++ != *str++) DBUG_RETURN(1); - } - if (! *wildstr ) DBUG_RETURN (*str != 0); - if (*wildstr++ == wild_one) - { - if (! *str++) DBUG_RETURN (1); /* One char; skipp */ - } - else - { /* Found '*' */ - if (!*wildstr) DBUG_RETURN(0); /* '*' as last char: OK */ - flag=(*wildstr != wild_many && *wildstr != wild_one); - do - { - if (flag) - { - char cmp; - if ((cmp= *wildstr) == wild_prefix && wildstr[1]) - cmp=wildstr[1]; - while (*str && *str != cmp) - str++; - if (!*str) DBUG_RETURN (1); - } - if (wild_compare(str,wildstr) == 0) DBUG_RETURN (0); - } while (*str++ && wildstr[0] != wild_many); - DBUG_RETURN(1); - } - } - DBUG_RETURN (*str != '\0'); -} /* wild_compare */ diff --git a/libmariadb/my_div.c b/libmariadb/my_div.c deleted file mode 100644 index 537c2d45..00000000 --- a/libmariadb/my_div.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" - -my_string my_filename(File fd) -{ - DBUG_ENTER("my_filename"); - if (fd >= MY_NFILE) - DBUG_RETURN((char*) "UNKNOWN"); - if (fd >= 0 && ma_file_info[fd].type != UNOPEN) - { - DBUG_RETURN(ma_file_info[fd].name); - } - else - DBUG_RETURN((char*) "UNOPENED"); /* Debug message */ -} diff --git a/libmariadb/my_fopen.c b/libmariadb/my_fopen.c deleted file mode 100644 index 9a3ff822..00000000 --- a/libmariadb/my_fopen.c +++ /dev/null @@ -1,179 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include "my_static.h" -#include -#include "mysys_err.h" -#include - -static void make_ftype(my_string to,int flag); - - /* Open a file as stream */ - -FILE *my_fopen(const char *FileName, int Flags, myf MyFlags) - /* Path-name of file */ - /* Read | write .. */ - /* Special flags */ -{ - FILE *fd; - char type[5]; - DBUG_ENTER("my_fopen"); - DBUG_PRINT("my",("Name: '%s' Flags: %d MyFlags: %d", - FileName, Flags, MyFlags)); - - make_ftype(type,Flags); -#ifdef _WIN32 - if (fopen_s(&fd, FileName, type) == 0) -#else - if ((fd = fopen(FileName, type)) != 0) -#endif - { - /* - The test works if MY_NFILE < 128. The problem is that fileno() is char - on some OS (SUNOS). Actually the filename save isn't that important - so we can ignore if this doesn't work. - */ - if ((uint) fileno(fd) >= MY_NFILE) - { - thread_safe_increment(ma_stream_opened,&THR_LOCK_open); - DBUG_RETURN(fd); /* safeguard */ - } - pthread_mutex_lock(&THR_LOCK_open); - if ((ma_file_info[fileno(fd)].name = (char*) - strdup(FileName))) - { - ma_stream_opened++; - ma_file_info[fileno(fd)].type = STREAM_BY_FOPEN; - pthread_mutex_unlock(&THR_LOCK_open); - DBUG_PRINT("exit",("stream: %lx",fd)); - DBUG_RETURN(fd); - } - pthread_mutex_unlock(&THR_LOCK_open); - (void) my_fclose(fd,MyFlags); - my_errno=ENOMEM; - } - else - my_errno=errno; - DBUG_PRINT("error",("Got error %d on open",my_errno)); - if (MyFlags & (MY_FFNF | MY_FAE | MY_WME)) - ma_error((Flags & O_RDONLY) || (Flags == O_RDONLY ) ? EE_FILENOTFOUND : - EE_CANTCREATEFILE, - MYF(ME_BELL+ME_WAITTANG), FileName,my_errno); - DBUG_RETURN((FILE*) 0); -} /* my_fopen */ - - - /* Close a stream */ - -int my_fclose(FILE *fd, myf MyFlags) -{ - int err,file; - DBUG_ENTER("my_fclose"); - DBUG_PRINT("my",("stream: %lx MyFlags: %d",fd, MyFlags)); - - pthread_mutex_lock(&THR_LOCK_open); - file=fileno(fd); - if ((err = fclose(fd)) < 0) - { - my_errno=errno; - if (MyFlags & (MY_FAE | MY_WME)) - ma_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG), - my_filename(file),errno); - } - else - ma_stream_opened--; - if ((uint) file < MY_NFILE && ma_file_info[file].type != UNOPEN) - { - ma_file_info[file].type = UNOPEN; - free(ma_file_info[file].name); - } - pthread_mutex_unlock(&THR_LOCK_open); - DBUG_RETURN(err); -} /* my_fclose */ - - - /* Make a stream out of a file handle */ - /* Name may be 0 */ - -FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags) -{ - FILE *fd; - char type[5]; - DBUG_ENTER("my_fdopen"); - DBUG_PRINT("my",("Fd: %d Flags: %d MyFlags: %d", - Filedes, Flags, MyFlags)); - - make_ftype(type,Flags); - if ((fd = fdopen(Filedes, type)) == 0) - { - my_errno=errno; - if (MyFlags & (MY_FAE | MY_WME)) - ma_error(EE_CANT_OPEN_STREAM, MYF(ME_BELL+ME_WAITTANG),errno); - } - else - { - pthread_mutex_lock(&THR_LOCK_open); - ma_stream_opened++; - if (Filedes < MY_NFILE) - { - if (ma_file_info[Filedes].type != UNOPEN) - { - ma_file_opened--; /* File is opened with my_open ! */ - } - else - { - ma_file_info[Filedes].name= strdup(name); - } - ma_file_info[Filedes].type = STREAM_BY_FDOPEN; - } - pthread_mutex_unlock(&THR_LOCK_open); - } - - DBUG_PRINT("exit",("stream: %lx",fd)); - DBUG_RETURN(fd); -} /* my_fdopen */ - - - /* Make a filehandler-open-typestring from ordinary inputflags */ - -static void make_ftype(register my_string to, register int flag) -{ -#if FILE_BINARY /* If we have binary-files */ - reg3 int org_flag=flag; -#endif - flag&= ~FILE_BINARY; /* remove binary bit */ - if (flag == O_RDONLY) - *to++= 'r'; - else if (flag == O_WRONLY) - *to++= 'w'; - else - { /* Add '+' after theese */ - if (flag == O_RDWR) - *to++= 'r'; - else if (flag & O_APPEND) - *to++= 'a'; - else - *to++= 'w'; /* Create file */ - *to++= '+'; - } -#if FILE_BINARY /* If we have binary-files */ - if (org_flag & FILE_BINARY) - *to++='b'; -#endif - *to='\0'; -} /* make_ftype */ diff --git a/libmariadb/my_fstream.c b/libmariadb/my_fstream.c deleted file mode 100644 index 0d297924..00000000 --- a/libmariadb/my_fstream.c +++ /dev/null @@ -1,171 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* USE_MY_STREAM isn't set because we can't thrust my_fclose! */ - -#include "mysys_priv.h" -#include "mysys_err.h" -#include -#include - -#ifdef HAVE_FSEEKO -#undef ftell -#undef fseek -#define ftell(A) ftello(A) -#define fseek(A,B,C) fseeko((A),(B),(C)) -#endif - - /* Read a chunk of bytes from a file */ - /* Returns (uint) -1 if error as my_read() */ - -uint my_fread(FILE *stream, unsigned char *Buffer, uint Count, myf MyFlags) - /* File descriptor */ - /* Buffer must be at least count bytes */ - /* Max number of bytes returnd */ - /* Flags on what to do on error */ -{ - uint readbytes; - DBUG_ENTER("my_fread"); - DBUG_PRINT("my",("stream: %lx Buffer: %lx Count: %u MyFlags: %d", - stream, Buffer, Count, MyFlags)); - - if ((readbytes = (uint) fread(Buffer,sizeof(char),(size_t) Count,stream)) - != Count) - { - DBUG_PRINT("error",("Read only %d bytes",readbytes)); - if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) - { - if (ferror(stream)) - ma_error(EE_READ, MYF(ME_BELL+ME_WAITTANG), - my_filename(fileno(stream)),errno); - else - if (MyFlags & (MY_NABP | MY_FNABP)) - ma_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), - my_filename(fileno(stream)),errno); - } - my_errno=errno ? errno : -1; - if (ferror(stream) || MyFlags & (MY_NABP | MY_FNABP)) - DBUG_RETURN((uint) -1); /* Return with error */ - } - if (MyFlags & (MY_NABP | MY_FNABP)) - DBUG_RETURN(0); /* Read ok */ - DBUG_RETURN(readbytes); -} /* my_fread */ - - -/* -** Write a chunk of bytes to a stream -** Returns (uint) -1 if error as my_write() -** Does retries if interrupted -*/ - -uint my_fwrite(FILE *stream, const unsigned char *Buffer, uint Count, myf MyFlags) -{ - uint writenbytes=0; - off_t seekptr; -#if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM) - uint errors; -#endif - DBUG_ENTER("my_fwrite"); - DBUG_PRINT("my",("stream: %lx Buffer: %lx Count: %u MyFlags: %d", - stream, Buffer, Count, MyFlags)); - -#if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM) - errors=0; -#endif - seekptr=ftell(stream); - for (;;) - { - uint writen; - if ((writen = (uint) fwrite((char*) Buffer,sizeof(char), - (size_t) Count, stream)) != Count) - { - DBUG_PRINT("error",("Write only %d bytes",writenbytes)); - my_errno=errno; - if (writen != (uint) -1) - { - seekptr+=writen; - Buffer+=writen; - writenbytes+=writen; - Count-=writen; - } -#ifdef EINTR - if (errno == EINTR) - { - VOID(my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0))); - continue; - } -#endif -#if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM) -#ifdef THREAD - if (my_thread_var->abort) - MyFlags&= ~ MY_WAIT_IF_FULL; /* End if aborted by user */ -#endif - if (errno == ENOSPC && (MyFlags & MY_WAIT_IF_FULL)) - { - if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE)) - ma_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH)); - sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC); - VOID(my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0))); - continue; - } -#endif - if (ferror(stream) || (MyFlags & (MY_NABP | MY_FNABP))) - { - if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) - { - ma_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG), - my_filename(fileno(stream)),errno); - } - writenbytes=(uint) -1; /* Return that we got error */ - break; - } - } - if (MyFlags & (MY_NABP | MY_FNABP)) - writenbytes=0; /* Everything OK */ - else - writenbytes+=writen; - break; - } - DBUG_RETURN(writenbytes); -} /* my_fwrite */ - - /* Seek to position in file */ - /* ARGSUSED */ - -my_off_t my_fseek(FILE *stream, my_off_t pos, int whence, myf MyFlags) -{ - DBUG_ENTER("my_fseek"); - DBUG_PRINT("my",("stream: %lx pos: %lu whence: %d MyFlags: %d", - stream, pos, whence, MyFlags)); - DBUG_RETURN(fseek(stream, (off_t) pos, whence) ? - MY_FILEPOS_ERROR : (my_off_t) ftell(stream)); -} /* my_seek */ - - - /* Tell current position of file */ - /* ARGSUSED */ - -my_off_t my_ftell(FILE *stream, myf MyFlags) -{ - off_t pos; - DBUG_ENTER("my_ftell"); - DBUG_PRINT("my",("stream: %lx MyFlags: %d",stream, MyFlags)); - pos=ftell(stream); - DBUG_PRINT("exit",("ftell: %lu",(ulong) pos)); - DBUG_RETURN((my_off_t) pos); -} /* my_ftell */ diff --git a/libmariadb/my_getwd.c b/libmariadb/my_getwd.c deleted file mode 100644 index 602d13de..00000000 --- a/libmariadb/my_getwd.c +++ /dev/null @@ -1,202 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* my_setwd() and my_getwd() works with ma_intern_filenames !! */ - -#include "mysys_priv.h" -#include -#include "mysys_err.h" -#ifdef HAVE_GETWD -#include -#endif -#if defined(MSDOS) || defined(_WIN32) -#include -#include -#include -#endif -#if defined(OS2) -#include -#endif - -#ifdef __EMX__ -// chdir2 support also drive change -#define chdir _chdir2 -#endif - - /* Gets current working directory in buff. Directory is allways ended - with FN_LIBCHAR */ - /* One must pass a buffer to my_getwd. One can allways use - ma_cur_dir[] */ - -int my_getwd(my_string buf, uint size, myf MyFlags) -{ - my_string pos; - DBUG_ENTER("my_getwd"); - DBUG_PRINT("my",("buf: %lx size: %d MyFlags %d", buf,size,MyFlags)); - -#if ! defined(MSDOS) - if (ma_cur_dir[0]) /* Current pos is saved here */ - strncpy(buf,&ma_cur_dir[0],size-1); - else -#endif - { -#if defined(HAVE_GETCWD) -#ifdef _WIN32 - if (!(_getcwd(buf,size-2)) && MyFlags & MY_WME) -#else - if (!(getcwd(buf,size-2)) && MyFlags & MY_WME) -#endif - { - my_errno=errno; - ma_error(EE_GETWD,MYF(ME_BELL+ME_WAITTANG),errno); - return(-1); - } -#elif defined(HAVE_GETWD) - { - char pathname[MAXPATHLEN]; - getwd(pathname); - strncpy(buf,pathname,size-1); - } -#elif defined(VMS) - if (!getcwd(buf,size-2,1) && MyFlags & MY_WME) - { - my_errno=errno; - ma_error(EE_GETWD,MYF(ME_BELL+ME_WAITTANG),errno); - return(-1); - } - ma_intern_filename(buf,buf); -#else -#error "No way to get current directory" -#endif - if (*((pos=strend(buf))-1) != FN_LIBCHAR) /* End with FN_LIBCHAR */ - { - pos[0]= FN_LIBCHAR; - pos[1]=0; - } - strncpy(&ma_cur_dir[0],buf,(size_s) (FN_REFLEN-1)); - } - DBUG_RETURN(0); -} /* my_getwd */ - - - /* Set new working directory */ - -int my_setwd(const char *dir, myf MyFlags) -{ - int res; - size_s length; - my_string start,pos; -#if defined(VMS) || defined(MSDOS) || defined(OS2) - char buff[FN_REFLEN]; -#endif - DBUG_ENTER("my_setwd"); - DBUG_PRINT("my",("dir: '%s' MyFlags %d", dir, MyFlags)); - - start=(my_string) dir; -#if defined(MSDOS) || defined(OS2) /* OS2/MSDOS chdir can't change drive */ -#if !defined(_DDL) && !defined(WIN32) - if ((pos=(char*) strchr(dir,FN_DEVCHAR)) != 0) - { - uint drive,drives; - - pos++; /* Skipp FN_DEVCHAR */ - drive=(uint) (toupper(dir[0])-'A'+1); drives= (uint) -1; - if ((pos-(byte*) dir) == 2 && drive > 0 && drive < 32) - { -#ifdef OS2 - _chdrive(drive); - drives = _getdrive(); -#else - _dos_setdrive(drive,&drives); - _dos_getdrive(&drives); -#endif - } - if (drive != drives) - { - *pos='\0'; /* Dir is now only drive */ - my_errno=errno; - ma_error(EE_SETWD,MYF(ME_BELL+ME_WAITTANG),dir,ENOENT); - DBUG_RETURN(-1); - } - dir=pos; /* drive changed, change now path */ - } -#endif - if (*((pos=strend(dir)-1)) == FN_LIBCHAR && pos != dir) - { - strncpy(buff, dir, strlen(dir) - 1); /* Remove last '/' */ - dir=buff; - } -#endif /* MSDOS*/ - if (! dir[0] || (dir[0] == FN_LIBCHAR && dir[1] == 0)) - dir=FN_ROOTDIR; -#ifdef VMS - { - pos=strmov(buff,dir); - if (pos[-1] != FN_LIBCHAR) - { - pos[0]=FN_LIBCHAR; /* Mark as directory */ - pos[1]=0; - } - ma_system_filename(buff,buff); /* Change to VMS format */ - dir=buff; - } -#endif /* VMS */ -#ifdef _WIN32 - if ((res=_chdir((char*) dir)) != 0) -#else - if ((res=chdir((char*) dir)) != 0) -#endif - { - my_errno=errno; - if (MyFlags & MY_WME) - ma_error(EE_SETWD,MYF(ME_BELL+ME_WAITTANG),start,errno); - } - else - { - if (test_if_hard_path(start)) - { /* Hard pathname */ - pos=strncpy(&ma_cur_dir[0],start,(size_s) FN_REFLEN-1) + strlen(&ma_cur_dir[0]); - if (pos[-1] != FN_LIBCHAR) - { - length=(uint) (pos-(char*) ma_cur_dir); - ma_cur_dir[length]=FN_LIBCHAR; /* must end with '/' */ - ma_cur_dir[length+1]='\0'; - } - } - else - ma_cur_dir[0]='\0'; /* Don't save name */ - } - DBUG_RETURN(res); -} /* my_setwd */ - - - - /* Test if hard pathname */ - /* Returns 1 if dirname is a hard path */ - -int test_if_hard_path(register const char *dir_name) -{ - if (dir_name[0] == FN_HOMELIB && dir_name[1] == FN_LIBCHAR) - return (ma_ma_ma_home_dir != NullS && test_if_hard_path(ma_ma_ma_home_dir)); - if (dir_name[0] == FN_LIBCHAR) - return (TRUE); -#ifdef FN_DEVCHAR - return (strchr(dir_name,FN_DEVCHAR) != 0); -#else - return FALSE; -#endif -} /* test_if_hard_path */ diff --git a/libmariadb/my_init.c b/libmariadb/my_init.c deleted file mode 100644 index 24a1e6ef..00000000 --- a/libmariadb/my_init.c +++ /dev/null @@ -1,222 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include "my_static.h" -#include "mysys_err.h" -#include "mariadb_ctype.h" -#include -#include -#ifdef HAVE_GETRUSAGE -#include -/* extern int getrusage(int, struct rusage *); */ -#endif -#include -#ifdef VMS -#include -#include -#endif -#ifdef _WIN32 -#ifdef _MSC_VER -#include -#include -#endif -static my_bool my_win_init(void); -#else -#define my_win_init() -#endif - -my_bool ma_init_done=0; - - - -static ulong atoi_octal(const char *str) -{ - long int tmp; - while (*str && isspace(*str)) - str++; - ma_str2int(str, - (*str == '0' ? 8 : 10), /* Octalt or decimalt */ - 0, INT_MAX, &tmp); - return (ulong) tmp; -} - - -/* Init my_sys functions and my_sys variabels */ - -void ma_init(void) -{ - my_string str; - if (ma_init_done) - return; - ma_init_done=1; -#ifdef THREAD -#if defined(HAVE_PTHREAD_INIT) - pthread_init(); /* Must be called before DBUG_ENTER */ -#endif - ma_thread_global_init(); -#ifndef _WIN32 - sigfillset(&my_signals); /* signals blocked by mf_brkhant */ -#endif -#endif /* THREAD */ -#ifdef UNIXWARE_7 - (void) isatty(0); /* Go around connect() bug in UW7 */ -#endif - { - DBUG_ENTER("ma_init"); - DBUG_PROCESS(ma_progname ? ma_progname : (char*) "unknown"); - if (!ma_ma_ma_home_dir) - { /* Don't initialize twice */ - if ((ma_ma_ma_home_dir=getenv("HOME")) != 0) - ma_ma_ma_home_dir=ma_intern_filename(ma_ma_ma_ma_ma_ma_home_dir_buff,ma_ma_ma_home_dir); -#ifndef VMS - /* Default creation of new files */ - if ((str=getenv("UMASK")) != 0) - ma_umask=(int) (atoi_octal(str) | 0600); - /* Default creation of new dir's */ - if ((str=getenv("UMASK_DIR")) != 0) - ma_umask_dir=(int) (atoi_octal(str) | 0700); -#endif -#ifdef VMS - init_ctype(); /* Stupid linker don't link _ctype.c */ -#endif - DBUG_PRINT("exit",("home: '%s'",ma_ma_ma_home_dir)); - } -#ifdef _WIN32 - my_win_init(); -#endif - DBUG_VOID_RETURN; - } -} /* ma_init */ - - - /* End my_sys */ - -void ma_end(int infoflag) -{ - FILE *info_file; - if (!(info_file=DBUG_FILE)) - info_file=stderr; - if (infoflag & MY_CHECK_ERROR || info_file != stderr) - { /* Test if some file is left open */ - if (ma_file_opened | ma_stream_opened) - { - sprintf(errbuff[0],EE(EE_OPEN_WARNING),ma_file_opened,ma_stream_opened); - (void) ma_message_no_curses(EE_OPEN_WARNING,errbuff[0],ME_BELL); - DBUG_PRINT("error",("%s",errbuff[0])); - } - } - if (infoflag & MY_GIVE_INFO || info_file != stderr) - { -#ifdef HAVE_GETRUSAGE - struct rusage rus; - if (!getrusage(RUSAGE_SELF, &rus)) - fprintf(info_file,"\n\ -User time %.2f, System time %.2f\n\ -Maximum resident set size %ld, Integral resident set size %ld\n\ -Non-physical pagefaults %ld, Physical pagefaults %ld, Swaps %ld\n\ -Blocks in %ld out %ld, Messages in %ld out %ld, Signals %ld\n\ -Voluntary context switches %ld, Involuntary context switches %ld\n", - (rus.ru_utime.tv_sec * SCALE_SEC + - rus.ru_utime.tv_usec / SCALE_USEC) / 100.0, - (rus.ru_stime.tv_sec * SCALE_SEC + - rus.ru_stime.tv_usec / SCALE_USEC) / 100.0, - rus.ru_maxrss, rus.ru_idrss, - rus.ru_minflt, rus.ru_majflt, - rus.ru_nswap, rus.ru_inblock, rus.ru_oublock, - rus.ru_msgsnd, rus.ru_msgrcv, rus.ru_nsignals, - rus.ru_nvcsw, rus.ru_nivcsw); -#endif -#if defined(MSDOS) && !defined(_WIN32) - fprintf(info_file,"\nRun time: %.1f\n",(double) clock()/CLOCKS_PER_SEC); -#endif -#if defined(SAFEMALLOC) - TERMINATE(stderr); /* Give statistic on screen */ -#elif defined(_WIN32) && defined(_MSC_VER) - _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE ); - _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDERR ); - _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE ); - _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDERR ); - _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE ); - _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR ); - _CrtCheckMemory(); - _CrtDumpMemoryLeaks(); -#endif - } -#ifdef THREAD - pthread_mutex_destroy(&THR_LOCK_malloc); - pthread_mutex_destroy(&THR_LOCK_open); - pthread_mutex_destroy(&THR_LOCK_net); - DBUG_END(); /* Must be done before ma_thread_end */ - ma_thread_end(); - ma_thread_global_end(); -#endif -#ifdef _WIN32 - WSACleanup( ); -#endif /* _WIN32 */ - ma_init_done=0; -} /* ma_end */ - -#ifdef _WIN32 - -/* - This code is specially for running MySQL, but it should work in - other cases too. - - Inizializzazione delle variabili d'ambiente per Win a 32 bit. - - Vengono inserite nelle variabili d'ambiente (utilizzando cosi' - le funzioni getenv e putenv) i valori presenti nelle chiavi - del file di registro: - - HKEY_LOCAL_MACHINE\software\MySQL - - Se la kiave non esiste nonn inserisce nessun valore -*/ - -/* Crea la stringa d'ambiente */ - -void setEnvString(char *ret, const char *name, const char *value) -{ - DBUG_ENTER("setEnvString"); - sprintf(ret, "%s=%s", name, value); - DBUG_VOID_RETURN ; -} - -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 - diff --git a/libmariadb/my_lib.c b/libmariadb/my_lib.c deleted file mode 100644 index a858dc3b..00000000 --- a/libmariadb/my_lib.c +++ /dev/null @@ -1,612 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* TODO: check for overun of memory for names. */ -/* Convert MSDOS-TIME to standar time_t */ - -#define USES_TYPES /* sys/types is included */ -#include "mysys_priv.h" -#include -#include /* Structs used by my_dir,includes sys/types */ -#include "mysys_err.h" -#include -#if defined(HAVE_DIRENT_H) -# include -# define NAMLEN(dirent) strlen((dirent)->d_name) -#else -#ifndef OS2 -# define dirent direct -#endif -# define NAMLEN(dirent) (dirent)->d_namlen -# if defined(HAVE_SYS_NDIR_H) -# include -# endif -# if defined(HAVE_SYS_DIR_H) -# include -# endif -# if defined(HAVE_NDIR_H) -# include -# endif -# if defined(MSDOS) || defined(_WIN32) -# include -# ifdef __BORLANDC__ -# include -# endif -# endif -#endif -#ifdef VMS -#include -#include -#include -#endif - -#ifdef OS2 -#include "my_os2dirsrch.h" -#endif - -#if defined(THREAD) && defined(HAVE_READDIR_R) -#define READDIR(A,B,C) ((errno=readdir_r(A,B,&C)) != 0 || !C) -#else -#define READDIR(A,B,C) (!(C=readdir(A))) -#endif - - -#define STARTSIZE ONCE_ALLOC_INIT*8 /* some mallocmargin */ - -static int comp_names(struct fileinfo *a,struct fileinfo *b); - - - /* We need this because program don't know with malloc we used */ - -void my_dirend(MY_DIR *buffer) -{ - DBUG_ENTER("my_dirend"); - if (buffer) - free(buffer); - DBUG_VOID_RETURN; -} /* my_dirend */ - - - /* Compare in sort of filenames */ - -static int comp_names(struct fileinfo *a, struct fileinfo *b) -{ - return (strcmp(a->name,b->name)); -} /* comp_names */ - - -#if !defined(MSDOS) && !defined(_WIN32) - -MY_DIR *my_dir(const char *path, myf MyFlags) -{ - DIR *dirp; - struct dirent *dp; - struct fileinfo *fnames; - char *buffer, *obuffer, *tempptr; - uint fcnt,i,size,firstfcnt, maxfcnt,length; - char tmp_path[FN_REFLEN+1],*tmp_file; - my_ptrdiff_t diff; - bool eof; -#ifdef THREAD - char dirent_tmp[sizeof(struct dirent)+_POSIX_PATH_MAX+1]; -#endif - DBUG_ENTER("my_dir"); - DBUG_PRINT("my",("path: '%s' stat: %d MyFlags: %d",path,MyFlags)); - -#if defined(THREAD) && !defined(HAVE_READDIR_R) - pthread_mutex_lock(&THR_LOCK_open); -#endif - - dirp = opendir(directory_file_name(tmp_path,(my_string) path)); - size = STARTSIZE; - if (dirp == NULL || ! (buffer = (char *) malloc(size))) - goto error; - - fcnt = 0; - tmp_file=strend(tmp_path); - firstfcnt = maxfcnt = (size - sizeof(MY_DIR)) / - (sizeof(struct fileinfo) + FN_LEN); - fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR)); - tempptr = (char *) (fnames + maxfcnt); - -#ifdef THREAD - dp= (struct dirent*) dirent_tmp; -#else - dp=0; -#endif - eof=0; - for (;;) - { - while (fcnt < maxfcnt && - !(eof= READDIR(dirp,(struct dirent*) dirent_tmp,dp))) - { - bzero((gptr) (fnames+fcnt),sizeof(fnames[0])); /* for purify */ - fnames[fcnt].name = tempptr; - tempptr = strmov(tempptr,dp->d_name) + 1; - if (MyFlags & MY_WANT_STAT) - { - (void)strmov(tmp_file,dp->d_name); - (void)my_stat(tmp_path, &fnames[fcnt].mystat, MyFlags); - } - ++fcnt; - } - if (eof) - break; - size += STARTSIZE; obuffer = buffer; - if (!(buffer = (char *) realloc((gptr) buffer, size))) - goto error; /* No memory */ - length= (uint) (sizeof(struct fileinfo ) * firstfcnt); - diff= PTR_BYTE_DIFF(buffer , obuffer) + (int) length; - fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR)); - tempptr= ADD_TO_PTR(tempptr,diff,char*); - for (i = 0; i < maxfcnt; i++) - fnames[i].name = ADD_TO_PTR(fnames[i].name,diff,char*); - - /* move filenames upp a bit */ - maxfcnt += firstfcnt; - bmove_upp(tempptr,tempptr-length, - (uint) (tempptr- (char*) (fnames+maxfcnt))); - } - - (void) closedir(dirp); - { - MY_DIR * s = (MY_DIR *) buffer; - s->number_off_files = (uint) fcnt; - s->dir_entry = fnames; - } - if (!(MyFlags & MY_DONT_SORT)) - qsort((void *) fnames, (size_s) fcnt, sizeof(struct fileinfo), - (qsort_cmp) comp_names); -#if defined(THREAD) && !defined(HAVE_READDIR_R) - pthread_mutex_unlock(&THR_LOCK_open); -#endif - DBUG_RETURN((MY_DIR *) buffer); - - error: -#if defined(THREAD) && !defined(HAVE_READDIR_R) - pthread_mutex_unlock(&THR_LOCK_open); -#endif - my_errno=errno; - if (dirp) - (void) closedir(dirp); - if (MyFlags & (MY_FAE+MY_WME)) - ma_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,my_errno); - DBUG_RETURN((MY_DIR *) NULL); -} /* my_dir */ - - -/* - * Convert from directory name to filename. - * On VMS: - * xyzzy:[mukesh.emacs] => xyzzy:[mukesh]emacs.dir.1 - * xyzzy:[mukesh] => xyzzy:[000000]mukesh.dir.1 - * On UNIX, it's simple: just make sure there is a terminating / - - * Returns pointer to dst; - */ - -my_string directory_file_name (my_string dst, const char *src) -{ -#ifndef VMS - - /* Process as Unix format: just remove test the final slash. */ - - my_string end; - - if (src[0] == 0) - src= (char*) "."; /* Use empty as current */ - end=strmov(dst, src); - if (end[-1] != FN_LIBCHAR) - { - end[0]=FN_LIBCHAR; /* Add last '/' */ - end[1]='\0'; - } - return dst; - -#else /* VMS */ - - long slen; - long rlen; - my_string ptr, rptr; - char bracket; - struct FAB fab = cc$rms_fab; - struct NAM nam = cc$rms_nam; - char esa[NAM$C_MAXRSS]; - - if (! src[0]) - src="[.]"; /* Empty is == current dir */ - - slen = strlen (src) - 1; - if (src[slen] == FN_C_AFTER_DIR || src[slen] == FN_C_AFTER_DIR_2 || - src[slen] == FN_DEVCHAR) - { - /* VMS style - convert [x.y.z] to [x.y]z, [x] to [000000]x */ - fab.fab$l_fna = src; - fab.fab$b_fns = slen + 1; - fab.fab$l_nam = &nam; - fab.fab$l_fop = FAB$M_NAM; - - nam.nam$l_esa = esa; - nam.nam$b_ess = sizeof esa; - nam.nam$b_nop |= NAM$M_SYNCHK; - - /* We call SYS$PARSE to handle such things as [--] for us. */ - if (SYS$PARSE(&fab, 0, 0) == RMS$_NORMAL) - { - slen = nam.nam$b_esl - 1; - if (esa[slen] == ';' && esa[slen - 1] == '.') - slen -= 2; - esa[slen + 1] = '\0'; - src = esa; - } - if (src[slen] != FN_C_AFTER_DIR && src[slen] != FN_C_AFTER_DIR_2) - { - /* what about when we have logical_name:???? */ - if (src[slen] == FN_DEVCHAR) - { /* Xlate logical name and see what we get */ - VOID(strmov(dst,src)); - dst[slen] = 0; /* remove colon */ - if (!(src = getenv (dst))) - return dst; /* Can't translate */ - - /* should we jump to the beginning of this procedure? - Good points: allows us to use logical names that xlate - to Unix names, - Bad points: can be a problem if we just translated to a device - name... - For now, I'll punt and always expect VMS names, and hope for - the best! */ - - slen = strlen (src) - 1; - if (src[slen] != FN_C_AFTER_DIR && src[slen] != FN_C_AFTER_DIR_2) - { /* no recursion here! */ - VOID(strmov(dst, src)); - return(dst); - } - } - else - { /* not a directory spec */ - VOID(strmov(dst, src)); - return(dst); - } - } - - bracket = src[slen]; /* End char */ - if (!(ptr = strchr (src, bracket - 2))) - { /* no opening bracket */ - VOID(strmov (dst, src)); - return dst; - } - if (!(rptr = strrchr (src, '.'))) - rptr = ptr; - slen = rptr - src; - VOID(strmake (dst, src, slen)); - - if (*rptr == '.') - { /* Put bracket and add */ - dst[slen++] = bracket; /* (rptr+1) after this */ - } - else - { - /* If we have the top-level of a rooted directory (i.e. xx:[000000]), - then translate the device and recurse. */ - - if (dst[slen - 1] == ':' - && dst[slen - 2] != ':' /* skip decnet nodes */ - && strcmp(src + slen, "[000000]") == 0) - { - dst[slen - 1] = '\0'; - if ((ptr = getenv (dst)) - && (rlen = strlen (ptr) - 1) > 0 - && (ptr[rlen] == FN_C_AFTER_DIR || ptr[rlen] == FN_C_AFTER_DIR_2) - && ptr[rlen - 1] == '.') - { - VOID(strmov(esa,ptr)); - esa[rlen - 1] = FN_C_AFTER_DIR; - esa[rlen] = '\0'; - return (directory_file_name (dst, esa)); - } - else - dst[slen - 1] = ':'; - } - VOID(strmov(dst+slen,"[000000]")); - slen += 8; - } - VOID(strmov(strmov(dst+slen,rptr+1)-1,".DIR.1")); - return dst; - } - VOID(strmov(dst, src)); - if (dst[slen] == '/' && slen > 1) - dst[slen] = 0; - return dst; -#endif /* VMS */ -} /* directory_file_name */ - -#elif defined(_WIN32) - -/* -***************************************************************************** -** Read long filename using windows rutines -***************************************************************************** -*/ - -MY_DIR *my_dir(const char *path, myf MyFlags) -{ - struct fileinfo *fnames; - char *buffer, *obuffer, *tempptr; - int eof,i,fcnt,firstfcnt,length,maxfcnt; - uint size; -#ifdef __BORLANDC__ - struct ffblk find; -#else - struct _finddata_t find; -#endif - ushort mode; - char tmp_path[FN_REFLEN],*tmp_file,attrib; - my_ptrdiff_t diff; -#ifdef _WIN64 - __int64 handle; -#else - long handle; -#endif - DBUG_ENTER("my_dir"); - DBUG_PRINT("my",("path: '%s' stat: %d MyFlags: %d",path,MyFlags)); - - /* Put LIB-CHAR as last path-character if not there */ - - tmp_file=tmp_path; - if (!*path) - *tmp_file++ ='.'; /* From current dir */ - tmp_file= strmov(tmp_file,path); - if (tmp_file[-1] == FN_DEVCHAR) - *tmp_file++= '.'; /* From current dev-dir */ - if (tmp_file[-1] != FN_LIBCHAR) - *tmp_file++ =FN_LIBCHAR; - tmp_file[0]='*'; /* MSDOS needs this !??? */ - tmp_file[1]='.'; - tmp_file[2]='*'; - tmp_file[3]='\0'; - -#ifdef __BORLANDC__ - if ((handle= findfirst(tmp_path,&find,0)) == -1L) - goto error; -#else - if ((handle=_findfirst(tmp_path,&find)) == -1L) - goto error; -#endif - - size = STARTSIZE; - firstfcnt = maxfcnt = (size - sizeof(MY_DIR)) / - (sizeof(struct fileinfo) + FN_LEN); - if (!(buffer = (char *)malloc(size))) - goto error; - fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR)); - tempptr = (char *) (fnames + maxfcnt); - - fcnt = 0; - for (;;) - { - do - { - fnames[fcnt].name = tempptr; -#ifdef __BORLANDC__ - tempptr = strmov(tempptr,find.ff_name) + 1; - fnames[fcnt].mystat.st_size=find.ff_fsize; - fnames[fcnt].mystat.st_uid=fnames[fcnt].mystat.st_gid=0; - mode=MY_S_IREAD; attrib=find.ff_attrib; -#else - tempptr = strmov(tempptr,find.name) + 1; - fnames[fcnt].mystat.st_size=find.size; - fnames[fcnt].mystat.st_uid=fnames[fcnt].mystat.st_gid=0; - mode=MY_S_IREAD; attrib=find.attrib; -#endif - if (!(attrib & _A_RDONLY)) - mode|=MY_S_IWRITE; - if (attrib & _A_SUBDIR) - mode|=MY_S_IFDIR; - fnames[fcnt].mystat.st_mode=mode; -#ifdef __BORLANDC__ - fnames[fcnt].mystat.st_mtime=((uint32) find.ff_ftime); -#else - fnames[fcnt].mystat.st_mtime=((uint32) find.time_write); -#endif - ++fcnt; -#ifdef __BORLANDC__ - } while ((eof= findnext(&find)) == 0 && fcnt < maxfcnt); -#else - } while ((eof= _findnext(handle,&find)) == 0 && fcnt < maxfcnt); -#endif - - DBUG_PRINT("test",("eof: %d errno: %d",eof,errno)); - if (eof) - break; - size += STARTSIZE; obuffer = buffer; - if (!(buffer = (char *) realloc((gptr) buffer, size))) - goto error; - length= sizeof(struct fileinfo ) * firstfcnt; - diff= PTR_BYTE_DIFF(buffer , obuffer) +length; - fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR)); - tempptr= ADD_TO_PTR(tempptr,diff,char*); - for (i = 0; i < maxfcnt; i++) - fnames[i].name = ADD_TO_PTR(fnames[i].name,diff,char*); - - /* move filenames upp a bit */ - maxfcnt += firstfcnt; - bmove_upp(tempptr,ADD_TO_PTR(tempptr,-length,char*), - (int) PTR_BYTE_DIFF(tempptr,fnames+maxfcnt)); - } - { - MY_DIR * s = (MY_DIR *) buffer; - s->number_off_files = (uint) fcnt; - s->dir_entry = fnames; - } - if (!(MyFlags & MY_DONT_SORT)) - qsort(fnames,fcnt,sizeof(struct fileinfo),(qsort_cmp) comp_names); -#ifndef __BORLANDC__ - _findclose(handle); -#endif - DBUG_RETURN((MY_DIR *) buffer); - -error: - my_errno=errno; -#ifndef __BORLANDC__ - if (handle != -1) - _findclose(handle); -#endif - if (MyFlags & MY_FAE+MY_WME) - ma_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,errno); - DBUG_RETURN((MY_DIR *) NULL); -} /* my_dir */ - -#else /* MSDOS and not WIN32 */ - - -/****************************************************************************** -** At MSDOS you always get stat of files, but time is in packed MSDOS-format -******************************************************************************/ - -MY_DIR *my_dir(const char* path, myf MyFlags) -{ - struct fileinfo *fnames; - char *buffer, *obuffer, *tempptr; - int eof,i,fcnt,firstfcnt,length,maxfcnt; - uint size; - struct find_t find; - ushort mode; - char tmp_path[FN_REFLEN],*tmp_file,attrib; - my_ptrdiff_t diff; - DBUG_ENTER("my_dir"); - DBUG_PRINT("my",("path: '%s' stat: %d MyFlags: %d",path,MyFlags)); - - /* Put LIB-CHAR as last path-character if not there */ - - tmp_file=tmp_path; - if (!*path) - *tmp_file++ ='.'; /* From current dir */ - tmp_file= strmov(tmp_file,path); - if (tmp_file[-1] == FN_DEVCHAR) - *tmp_file++= '.'; /* From current dev-dir */ - if (tmp_file[-1] != FN_LIBCHAR) - *tmp_file++ =FN_LIBCHAR; - tmp_file[0]='*'; /* MSDOS needs this !??? */ - tmp_file[1]='.'; - tmp_file[2]='*'; - tmp_file[3]='\0'; - - if (_dos_findfirst(tmp_path,_A_NORMAL | _A_SUBDIR, &find)) - goto error; - - size = STARTSIZE; - firstfcnt = maxfcnt = (size - sizeof(MY_DIR)) / - (sizeof(struct fileinfo) + FN_LEN); - if ((buffer = (char *) malloc(size) == 0) - goto error; - fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR)); - tempptr = (char *) (fnames + maxfcnt); - - fcnt = 0; - for (;;) - { - do - { - fnames[fcnt].name = tempptr; - tempptr = strmov(tempptr,find.name) + 1; - fnames[fcnt].mystat.st_size=find.size; - fnames[fcnt].mystat.st_uid=fnames[fcnt].mystat.st_gid=0; - mode=MY_S_IREAD; attrib=find.attrib; - if (!(attrib & _A_RDONLY)) - mode|=MY_S_IWRITE; - if (attrib & _A_SUBDIR) - mode|=MY_S_IFDIR; - fnames[fcnt].mystat.st_mode=mode; - fnames[fcnt].mystat.st_mtime=((uint32) find.wr_date << 16) + - find.wr_time; - ++fcnt; - } while ((eof= _dos_findnext(&find)) == 0 && fcnt < maxfcnt); - - DBUG_PRINT("test",("eof: %d errno: %d",eof,errno)); - if (eof) - break; - size += STARTSIZE; obuffer = buffer; - if (!(buffer = (char *) realloc((gptr) buffer, size))) - goto error; - length= sizeof(struct fileinfo ) * firstfcnt; - diff= PTR_BYTE_DIFF(buffer , obuffer) +length; - fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR)); - tempptr= ADD_TO_PTR(tempptr,diff,char*); - for (i = 0; i < maxfcnt; i++) - fnames[i].name = ADD_TO_PTR(fnames[i].name,diff,char*); - - /* move filenames upp a bit */ - maxfcnt += firstfcnt; - bmove_upp(tempptr,ADD_TO_PTR(tempptr,-length,char*), - (int) PTR_BYTE_DIFF(tempptr,fnames+maxfcnt)); - } - { - MY_DIR * s = (MY_DIR *) buffer; - s->number_off_files = (uint) fcnt; - s->dir_entry = fnames; - } - if (!(MyFlags & MY_DONT_SORT)) - qsort(fnames,fcnt,sizeof(struct fileinfo),(qsort_cmp) comp_names); - DBUG_RETURN((MY_DIR *) buffer); - -error: - if (MyFlags & MY_FAE+MY_WME) - ma_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,errno); - DBUG_RETURN((MY_DIR *) NULL); -} /* my_dir */ - -#endif /* WIN32 && MSDOS */ - -/**************************************************************************** -** File status -** Note that MY_STAT is assumed to be same as struct stat -****************************************************************************/ - -int my_fstat(int Filedes, MY_STAT *stat_area, myf MyFlags ) -{ - DBUG_ENTER("my_fstat"); - DBUG_PRINT("my",("fd: %d MyFlags: %d",Filedes,MyFlags)); - DBUG_RETURN(fstat(Filedes, (struct stat *) stat_area)); -} - -MY_STAT *my_stat(const char *path, MY_STAT *stat_area, myf my_flags) -{ - int m_used; - DBUG_ENTER("my_stat"); - DBUG_PRINT("my", ("path: '%s', stat_area: %lx, MyFlags: %d", path, - (unsigned char *) stat_area, my_flags)); - - if ((m_used= (stat_area == NULL))) - if (!(stat_area = (MY_STAT *) malloc(sizeof(MY_STAT)))) - goto error; - if ( ! stat((my_string) path, (struct stat *) stat_area) ) - DBUG_RETURN(stat_area); - my_errno=errno; - if (m_used) /* Free if new area */ - free(stat_area); - -error: - if (my_flags & (MY_FAE+MY_WME)) - { - ma_error(EE_STAT, MYF(ME_BELL+ME_WAITTANG),path,my_errno); - DBUG_RETURN((MY_STAT *) NULL); - } - DBUG_RETURN((MY_STAT *) NULL); -} /* my_stat */ - diff --git a/libmariadb/my_messnc.c b/libmariadb/my_messnc.c deleted file mode 100644 index b3088670..00000000 --- a/libmariadb/my_messnc.c +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -int ma_message_no_curses(uint error __attribute__((unused)), - const char *str, myf MyFlags) -{ - DBUG_ENTER("ma_message_no_curses"); - DBUG_PRINT("enter",("message: %s",str)); - (void) fflush(stdout); - if (MyFlags & ME_BELL) - (void) fputc('\007',stderr); /* Bell */ - if (ma_progname) - { - (void)fputs(ma_progname,stderr); (void)fputs(": ",stderr); - } - (void)fputs(str,stderr); - (void)fputc('\n',stderr); - (void)fflush(stderr); - DBUG_RETURN(0); -} diff --git a/libmariadb/my_net.c b/libmariadb/my_net.c deleted file mode 100644 index b865c491..00000000 --- a/libmariadb/my_net.c +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* thread safe version of some common functions */ - -#include "mysys_priv.h" -#include - -/* for thread safe my_inet_ntoa */ -#if !defined(MSDOS) && !defined(_WIN32) -#include -#ifdef HAVE_SYS_SOCKET_H -#include -#endif -#ifdef HAVE_NETINET_IN_H -#include -#endif -#ifdef HAVE_ARPA_INET_H -#include -#endif -#endif /* !defined(MSDOS) && !defined(_WIN32) */ - -void my_inet_ntoa(struct in_addr in, char *buf) -{ - char *ptr; - pthread_mutex_lock(&THR_LOCK_net); - ptr=inet_ntoa(in); - strcpy(buf,ptr); - pthread_mutex_unlock(&THR_LOCK_net); -} diff --git a/libmariadb/my_once.c b/libmariadb/my_once.c deleted file mode 100644 index 51a476a7..00000000 --- a/libmariadb/my_once.c +++ /dev/null @@ -1,88 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* Not MT-SAFE */ - -#ifdef SAFEMALLOC /* We don't need SAFEMALLOC here */ -#undef SAFEMALLOC -#endif - -#include "mysys_priv.h" -#include "my_static.h" -#include "mysys_err.h" - - /* alloc for things we don't nead to free */ - /* No DBUG_ENTER... here to get smaller dbug-startup */ - -gptr my_once_alloc(unsigned int Size, myf MyFlags) -{ - size_t get_size,max_left; - gptr point; - reg1 MA_USED_MEM *next; - reg2 MA_USED_MEM **prev; - - Size= ALIGN_SIZE(Size); - prev= &ma_once_root_block; - max_left=0; - for (next=ma_once_root_block ; next && next->left < Size ; next= next->next) - { - if (next->left > max_left) - max_left=next->left; - prev= &next->next; - } - if (! next) - { /* Time to alloc new block */ - get_size= Size+ALIGN_SIZE(sizeof(MA_USED_MEM)); - if (max_left*4 < ma_once_extra && get_size < ma_once_extra) - get_size=ma_once_extra; /* Normal alloc */ - - if ((next = (MA_USED_MEM*) malloc(get_size)) == 0) - { - my_errno=errno; - if (MyFlags & (MY_FAE+MY_WME)) - ma_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG),get_size); - return((gptr) 0); - } - DBUG_PRINT("test",("my_once_malloc %u byte malloced",get_size)); - next->next= 0; - next->size= get_size; - next->left= get_size-ALIGN_SIZE(sizeof(MA_USED_MEM)); - *prev=next; - } - point= (gptr) ((char*) next+ (next->size-next->left)); - next->left-= Size; - - return(point); -} /* my_once_alloc */ - - - /* deallocate everything used by my_once_alloc */ - -void my_once_free(void) -{ - reg1 MA_USED_MEM *next,*old; - DBUG_ENTER("my_once_free"); - - for (next=ma_once_root_block ; next ; ) - { - old=next; next= next->next ; - free((gptr) old); - } - ma_once_root_block=0; - - DBUG_VOID_RETURN; -} /* my_once_free */ diff --git a/libmariadb/my_open.c b/libmariadb/my_open.c deleted file mode 100644 index 50bf6341..00000000 --- a/libmariadb/my_open.c +++ /dev/null @@ -1,126 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#define USES_TYPES -#include "mysys_priv.h" -#include "mysys_err.h" -#include -#include -#if defined(MSDOS) || defined(_WIN32) || defined(__EMX__) || defined(OS2) -#include -#endif - - /* Open a file */ - -File my_open(const char *FileName, int Flags, myf MyFlags) - /* Path-name of file */ - /* Read | write .. */ - /* Special flags */ -{ - File fd; - DBUG_ENTER("my_open"); - DBUG_PRINT("my",("Name: '%s' Flags: %d MyFlags: %d", - FileName, Flags, MyFlags)); -#if defined(MSDOS) || defined(_WIN32) || defined(__EMX__) || defined(OS2) - if (Flags & O_SHARE) - fd = sopen((my_string) FileName, (Flags & ~O_SHARE) | O_BINARY, SH_DENYNO, - MY_S_IREAD | MY_S_IWRITE); - else - fd = open((my_string) FileName, Flags | O_BINARY, - MY_S_IREAD | MY_S_IWRITE); -#elif !defined(NO_OPEN_3) - fd = open(FileName, Flags, ma_umask); /* Normal unix */ -#else - fd = open((my_string) FileName, Flags); -#endif - DBUG_RETURN(my_register_filename(fd, FileName, FILE_BY_OPEN, - EE_FILENOTFOUND, MyFlags)); -} /* my_open */ - - - /* Close a file */ - -int my_close(File fd, myf MyFlags) -{ - int err; - DBUG_ENTER("my_close"); - DBUG_PRINT("my",("fd: %d MyFlags: %d",fd, MyFlags)); - - pthread_mutex_lock(&THR_LOCK_open); - if ((err = close(fd))) - { - DBUG_PRINT("error",("Got error %d on close",err)); - my_errno=errno; - if (MyFlags & (MY_FAE | MY_WME)) - ma_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG),my_filename(fd),errno); - } - if ((uint) fd < MY_NFILE && ma_file_info[fd].type != UNOPEN) - { - ma_free(ma_file_info[fd].name); -#if defined(THREAD) && !defined(HAVE_PREAD) - pthread_mutex_destroy(&ma_file_info[fd].mutex); -#endif - ma_file_info[fd].type = UNOPEN; - } - ma_file_opened--; - pthread_mutex_unlock(&THR_LOCK_open); - DBUG_RETURN(err); -} /* my_close */ - - -File my_register_filename(File fd, const char *FileName, enum file_type - type_of_file, uint error_message_number, myf MyFlags) -{ - if ((int) fd >= 0) - { - if ((int) fd >= MY_NFILE) - { -#if defined(THREAD) && !defined(HAVE_PREAD) - (void) my_close(fd,MyFlags); - my_errno=EMFILE; - if (MyFlags & (MY_FFNF | MY_FAE | MY_WME)) - ma_error(EE_OUT_OF_FILERESOURCES, MYF(ME_BELL+ME_WAITTANG), - FileName, my_errno); - return(-1); -#endif - thread_safe_increment(ma_file_opened,&THR_LOCK_open); - return(fd); /* safeguard */ - } - pthread_mutex_lock(&THR_LOCK_open); - if ((ma_file_info[fd].name = (char*) strdup(FileName))) - { - ma_file_opened++; - ma_file_info[fd].type = type_of_file; -#if defined(THREAD) && !defined(HAVE_PREAD) - pthread_mutex_init(&ma_file_info[fd].mutex,MY_MUTEX_INIT_FAST); -#endif - pthread_mutex_unlock(&THR_LOCK_open); - DBUG_PRINT("exit",("fd: %d",fd)); - return(fd); - } - pthread_mutex_unlock(&THR_LOCK_open); - (void) my_close(fd, MyFlags); - my_errno=ENOMEM; - } - else - my_errno=errno; - DBUG_PRINT("error",("Got error %d on open",my_errno)); - if (MyFlags & (MY_FFNF | MY_FAE | MY_WME)) - ma_error(error_message_number, MYF(ME_BELL+ME_WAITTANG), - FileName, my_errno); - return(fd); -} diff --git a/libmariadb/my_port.c b/libmariadb/my_port.c deleted file mode 100644 index bf5dbcba..00000000 --- a/libmariadb/my_port.c +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - Small functions to make code portable -*/ - -#include "mysys_priv.h" - -#ifdef _AIX - -/* - On AIX, at least with gcc 3.1, the expression - '(double) (ulonglong) var' doesn't always work for big unsigned - integers like '18446744073709551615'. The end result is that the - high bit is simply dropped. (probably bug in gcc optimizations) - Handling the conversion in a sub function seems to work. -*/ - - - -double my_ulonglong2double(unsigned long long nr) -{ - return (double) nr; -} -#endif /* _AIX */ diff --git a/libmariadb/my_pthread.c b/libmariadb/my_pthread.c deleted file mode 100644 index 1c8ada56..00000000 --- a/libmariadb/my_pthread.c +++ /dev/null @@ -1,555 +0,0 @@ -/* Copyright (C) 2000 MySQL AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* Functions to get threads more portable */ - -#define DONT_REMAP_PTHREAD_FUNCTIONS - -#include "mysys_priv.h" -#ifdef THREAD -#include -#include -#include -#include - -#ifdef _WIN32 - -int -ma_pthread_cond_init (pthread_cond_t *cv, const pthread_condattr_t *attr) -{ - DBUG_ENTER("pthread_cond_init"); - /* Initialize the count to 0 */ - InitializeCriticalSection(&cv->waiters_count_lock); - cv->waiting = 0; - - /* Create an auto-reset and manual-reset event */ - if (!(cv->events[SIGNAL] = CreateEvent (NULL, FALSE, FALSE, NULL)) || - !(cv->events[BROADCAST] = CreateEvent (NULL, TRUE, FALSE, NULL))) - { - DBUG_RETURN(GetLastError()); - } - DBUG_RETURN(0); -} - -int ma_pthread_cond_timedwait(pthread_cond_t *cond, - pthread_mutex_t *mutex, - struct timespec *abstime) -{ - int result= 0; - return result == WAIT_TIMEOUT ? ETIMEDOUT : 0; -} - -int pthread_cond_wait(pthread_cond_t *cv, pthread_mutex_t *mutex) -{ - return pthread_cond_timedwait(cv,mutex,NULL); -} - -int pthread_cond_destroy(pthread_cond_t *cv) -{ - DeleteCriticalSection(&cv->waiters_count_lock); - - if (CloseHandle(cv->events[SIGNAL]) == 0 || - CloseHandle(cv->events[BROADCAST]) == 0) - return EINVAL; - return 0; -} - -#endif - -#if (defined(__BSD__) || defined(_BSDI_VERSION)) && !defined(HAVE_mit_thread) -#define SCHED_POLICY SCHED_RR -#else -#define SCHED_POLICY SCHED_OTHER -#endif - -#ifndef my_pthread_setprio -void my_pthread_setprio(pthread_t thread_id,int prior) -{ -#ifdef HAVE_PTHREAD_SETSCHEDPARAM - struct sched_param tmp_sched_param; - bzero((char*) &tmp_sched_param,sizeof(tmp_sched_param)); - tmp_sched_param.sched_priority=prior; - VOID(pthread_setschedparam(thread_id,SCHED_POLICY,&tmp_sched_param)); -#endif -} -#endif - -#ifndef my_pthread_getprio -int my_pthread_getprio(pthread_t thread_id) -{ -#ifdef HAVE_PTHREAD_SETSCHEDPARAM - struct sched_param tmp_sched_param; - int policy; - if (!pthread_getschedparam(thread_id,&policy,&tmp_sched_param)) - { - DBUG_PRINT("thread",("policy: %d priority: %d", - policy,tmp_sched_param.sched_priority)); - return tmp_sched_param.sched_priority; - } -#endif - return -1; -} -#endif - -#ifndef my_pthread_attr_setprio -void my_pthread_attr_setprio(pthread_attr_t *attr, int priority) -{ -#ifdef HAVE_PTHREAD_SETSCHEDPARAM - struct sched_param tmp_sched_param; - bzero((char*) &tmp_sched_param,sizeof(tmp_sched_param)); - tmp_sched_param.sched_priority=priority; - VOID(pthread_attr_setschedparam(attr,&tmp_sched_param)); -#endif -} -#endif - - -/* To allow use of pthread_getspecific with two arguments */ - -#ifdef HAVE_NONPOSIX_PTHREAD_GETSPECIFIC -#undef pthread_getspecific -#ifdef HAVE_UNIXWARE7_THREADS -#define pthread_getspecific thr_getspecific -#endif - -void *my_pthread_getspecific_imp(pthread_key_t key) -{ - void *value; - if (pthread_getspecific(key,(void *) &value)) - return 0; - return value; -} -#endif - - -/* Some functions for RTS threads, AIX, Siemens Unix and UnixWare 7 - (and DEC OSF/1 3.2 too) */ - -int my_pthread_create_detached=1; - -#if defined(HAVE_NONPOSIX_SIGWAIT) || defined(HAVE_DEC_3_2_THREADS) - -int my_sigwait(const sigset_t *set,int *sig) -{ - int signal=sigwait((sigset_t*) set); - if (signal < 0) - return errno; - *sig=signal; - return 0; -} -#endif - -/* localtime_r for SCO 3.2V4.2 */ - -#ifndef HAVE_LOCALTIME_R - -extern pthread_mutex_t LOCK_localtime_r; - -struct tm *localtime_r(const time_t *clock, struct tm *res) -{ - struct tm *tmp; - pthread_mutex_lock(&LOCK_localtime_r); - tmp=localtime(clock); - *res= *tmp; - pthread_mutex_unlock(&LOCK_localtime_r); - return res; -} -#endif - - -/**************************************************************************** -** Replacement of sigwait if the system doesn't have one (like BSDI 3.0) -** -** Note: -** This version of sigwait() is assumed to called in a loop so the signalmask -** is permanently modified to reflect the signal set. This is done to get -** a much faster implementation. -** -** This implementation isn't thread safe: It assumes that only one -** thread is using sigwait. -** -** If one later supplies a different signal mask, all old signals that -** was used before are unblocked and set to SIGDFL. -** -** Author: Gary Wisniewski , much modified by Monty -****************************************************************************/ - -#if !defined(HAVE_SIGWAIT) && !defined(HAVE_mit_thread) && !defined(sigwait) && !defined(_WIN32) && !defined(HAVE_rts_threads) && !defined(HAVE_NONPOSIX_SIGWAIT) && !defined(HAVE_DEC_3_2_THREADS) && !defined(OS2) - -#if !defined(DONT_USE_SIGSUSPEND) - -static sigset_t sigwait_set,rev_sigwait_set,px_recd; - -void px_handle_sig(int sig) -{ - sigaddset(&px_recd, sig); -} - - -void sigwait_setup(sigset_t *set) -{ - int i; - struct sigaction sact,sact1; - sigset_t unblock_mask; - - sact.sa_flags = 0; - sact.sa_handler = px_handle_sig; - memcpy_fixed(&sact.sa_mask,set,sizeof(*set)); /* handler isn't thread_safe */ - sigemptyset(&unblock_mask); - pthread_sigmask(SIG_UNBLOCK,(sigset_t*) 0,&rev_sigwait_set); - - for (i = 1; i <= sizeof(sigwait_set)*8; i++) - { - if (sigismember(set,i)) - { - sigdelset(&rev_sigwait_set,i); - if (!sigismember(&sigwait_set,i)) - sigaction(i, &sact, (struct sigaction*) 0); - } - else - { - sigdelset(&px_recd,i); /* Don't handle this */ - if (sigismember(&sigwait_set,i)) - { /* Remove the old handler */ - sigaddset(&unblock_mask,i); - sigdelset(&rev_sigwait_set,i); - sact1.sa_flags = 0; - sact1.sa_handler = SIG_DFL; - sigemptyset(&sact1.sa_mask); - sigaction(i, &sact1, 0); - } - } - } - memcpy_fixed(&sigwait_set,set,sizeof(*set)); - pthread_sigmask(SIG_BLOCK,(sigset_t*) set,(sigset_t*) 0); - pthread_sigmask(SIG_UNBLOCK,&unblock_mask,(sigset_t*) 0); -} - - -int sigwait(sigset_t *setp, int *sigp) -{ - if (memcmp(setp,&sigwait_set,sizeof(sigwait_set))) - sigwait_setup(setp); /* Init or change of set */ - - for (;;) - { - /* - This is a fast, not 100% portable implementation to find the signal. - Because the handler is blocked there should be at most 1 bit set, but - the specification on this is somewhat shady so we use a set instead a - single variable. - */ - - ulong *ptr= (ulong*) &px_recd; - ulong *end=ptr+sizeof(px_recd)/sizeof(ulong); - - for ( ; ptr != end ; ptr++) - { - if (*ptr) - { - ulong set= *ptr; - int found= (int) ((char*) ptr - (char*) &px_recd)*8+1; - while (!(set & 1)) - { - found++; - set>>=1; - } - *sigp=found; - sigdelset(&px_recd,found); - return 0; - } - } - sigsuspend(&rev_sigwait_set); - } - return 0; -} -#else /* !DONT_USE_SIGSUSPEND */ - -/**************************************************************************** -** Replacement of sigwait if the system doesn't have one (like BSDI 3.0) -** -** Note: -** This version of sigwait() is assumed to called in a loop so the signalmask -** is permanently modified to reflect the signal set. This is done to get -** a much faster implementation. -** -** This implementation uses a extra thread to handle the signals and one -** must always call sigwait() with the same signal mask! -** -** BSDI 3.0 NOTE: -** -** pthread_kill() doesn't work on a thread in a select() or sleep() loop? -** After adding the sleep to sigwait_thread, all signals are checked and -** delivered every second. This isn't that terrible performance vice, but -** someone should report this to BSDI and ask for a fix! -** Another problem is that when the sleep() ends, every select() in other -** threads are interrupted! -****************************************************************************/ - -static sigset_t pending_set; -static bool inited=0; -static pthread_cond_t COND_sigwait; -static pthread_mutex_t LOCK_sigwait; - - -void sigwait_handle_sig(int sig) -{ - pthread_mutex_lock(&LOCK_sigwait); - sigaddset(&pending_set, sig); - VOID(pthread_cond_signal(&COND_sigwait)); /* inform sigwait() about signal */ - pthread_mutex_unlock(&LOCK_sigwait); -} - -extern pthread_t alarm_thread; - -void *sigwait_thread(void *set_arg) -{ - sigset_t *set=(sigset_t*) set_arg; - - int i; - struct sigaction sact; - sact.sa_flags = 0; - sact.sa_handler = sigwait_handle_sig; - memcpy_fixed(&sact.sa_mask,set,sizeof(*set)); /* handler isn't thread_safe */ - sigemptyset(&pending_set); - - for (i = 1; i <= sizeof(pending_set)*8; i++) - { - if (sigismember(set,i)) - { - sigaction(i, &sact, (struct sigaction*) 0); - } - } - sigaddset(set,THR_CLIENT_ALARM); - pthread_sigmask(SIG_UNBLOCK,(sigset_t*) set,(sigset_t*) 0); - alarm_thread=pthread_self(); /* For thr_alarm */ - - for (;;) - { /* Wait for signals */ -#ifdef HAVE_NOT_BROKEN_SELECT - fd_set fd; - FD_ZERO(&fd); - select(0,&fd,0,0,0); -#else - sleep(1); /* Because of broken BSDI */ -#endif - } -} - - -int sigwait(sigset_t *setp, int *sigp) -{ - if (!inited) - { - pthread_attr_t thr_attr; - pthread_t sigwait_thread_id; - inited=1; - sigemptyset(&pending_set); - pthread_mutex_init(&LOCK_sigwait,MY_MUTEX_INIT_FAST); - pthread_cond_init(&COND_sigwait,NULL); - - pthread_attr_init(&thr_attr); - pthread_attr_setscope(&thr_attr,PTHREAD_SCOPE_PROCESS); - pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED); - pthread_attr_setstacksize(&thr_attr,8196); - my_pthread_attr_setprio(&thr_attr,100); /* Very high priority */ - VOID(pthread_create(&sigwait_thread_id,&thr_attr,sigwait_thread,setp)); - VOID(pthread_attr_destroy(&thr_attr)); - } - - pthread_mutex_lock(&LOCK_sigwait); - for (;;) - { - ulong *ptr= (ulong*) &pending_set; - ulong *end=ptr+sizeof(pending_set)/sizeof(ulong); - - for ( ; ptr != end ; ptr++) - { - if (*ptr) - { - ulong set= *ptr; - int found= (int) ((char*) ptr - (char*) &pending_set)*8+1; - while (!(set & 1)) - { - found++; - set>>=1; - } - *sigp=found; - sigdelset(&pending_set,found); - pthread_mutex_unlock(&LOCK_sigwait); - return 0; - } - } - VOID(pthread_cond_wait(&COND_sigwait,&LOCK_sigwait)); - } - return 0; -} - -#endif /* DONT_USE_SIGSUSPEND */ -#endif /* HAVE_SIGWAIT */ - -/***************************************************************************** -** Implement pthread_signal for systems that can't use signal() with threads -** Currently this is only used with BSDI 3.0 -*****************************************************************************/ - -#ifdef USE_PTHREAD_SIGNAL - -int pthread_signal(int sig, void (*func)()) -{ - struct sigaction sact; - sact.sa_flags= 0; - sact.sa_handler= func; - sigemptyset(&sact.sa_mask); - sigaction(sig, &sact, (struct sigaction*) 0); - return 0; -} -#endif - -/**************************************************************************** - The following functions fixes that all pthread functions should work - according to latest posix standard -****************************************************************************/ - -/* Undefined wrappers set my_pthread.h so that we call os functions */ -#undef pthread_mutex_init -#undef pthread_mutex_lock -#undef pthread_mutex_unlock -#undef pthread_mutex_destroy -#undef pthread_mutex_wait -#undef pthread_mutex_timedwait -#undef pthread_mutex_trylock -#undef pthread_mutex_t -#undef pthread_cond_init -#undef pthread_cond_wait -#undef pthread_cond_timedwait -#undef pthread_cond_t - - -/***************************************************************************** -** Patches for AIX and DEC OSF/1 3.2 -*****************************************************************************/ - -#if (defined(HAVE_NONPOSIX_PTHREAD_MUTEX_INIT) && !defined(HAVE_UNIXWARE7_THREADS)) || defined(HAVE_DEC_3_2_THREADS) - -#include - -int my_pthread_mutex_init(pthread_mutex_t *mp, const pthread_mutexattr_t *attr) -{ - int error; - if (!attr) - error=pthread_mutex_init(mp,pthread_mutexattr_default); - else - error=pthread_mutex_init(mp,*attr); - return error; -} - -int my_pthread_cond_init(pthread_cond_t *mp, const pthread_condattr_t *attr) -{ - int error; - if (!attr) - error=pthread_cond_init(mp,pthread_condattr_default); - else - error=pthread_cond_init(mp,*attr); - return error; -} - -#endif - - -/***************************************************************************** - Patches for HPUX - We need these because the pthread_mutex.. code returns -1 on error, - instead of the error code. - - Note that currently we only remap pthread_ functions used by MySQL. - If we are depending on the value for some other pthread_xxx functions, - this has to be added here. -****************************************************************************/ - -#if defined(HPUX) || defined(HAVE_BROKEN_PTHREAD_COND_TIMEDWAIT) - -int my_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, - struct timespec *abstime) -{ - int error=pthread_cond_timedwait(cond, mutex, abstime); - if (error == -1) /* Safety if the lib is fixed */ - { - if (!(error=errno)) - error= ETIMEDOUT; /* Can happen on HPUX */ - } - if (error == EAGAIN) /* Correct errno to Posix */ - error= ETIMEDOUT; - return error; -} -#endif - - -#ifdef HAVE_POSIX1003_4a_MUTEX -/* - In HP-UX-10.20 and other old Posix 1003.4a Draft 4 implementations - pthread_mutex_trylock returns 1 on success, not 0 like - pthread_mutex_lock - - From the HP-UX-10.20 man page: - RETURN VALUES - If the function fails, errno may be set to one of the following - values: - Return | Error | Description - _______|__________|_________________________________________ - 1 | | Successful completion. - 0 | | The mutex is locked; therefore, it was - | | not acquired. - -1 | [EINVAL] | The value specified by mutex is invalid. - -*/ - -/* - Convert pthread_mutex_trylock to return values according to latest POSIX - - RETURN VALUES - 0 If we are able successfully lock the mutex. - EBUSY Mutex was locked by another thread - # Other error number returned by pthread_mutex_trylock() - (Not likely) -*/ - -int my_pthread_mutex_trylock(pthread_mutex_t *mutex) -{ - int error= pthread_mutex_trylock(mutex); - if (error == 1) - return 0; /* Got lock on mutex */ - if (error == 0) /* Someon else is locking mutex */ - return EBUSY; - if (error == -1) /* Safety if the lib is fixed */ - error= errno; /* Probably invalid parameter */ - return error; -} -#endif /* HAVE_POSIX1003_4a_MUTEX */ - -/* Some help functions */ - -int pthread_no_free(void *not_used __attribute__((unused))) -{ - return 0; -} - -int pthread_dummy(int ret) -{ - return ret; -} -#endif /* THREAD */ diff --git a/libmariadb/my_read.c b/libmariadb/my_read.c deleted file mode 100644 index 68a72584..00000000 --- a/libmariadb/my_read.c +++ /dev/null @@ -1,66 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include "mysys_err.h" -#include - - - /* Read a chunk of bytes from a file */ - -uint my_read(File Filedes, unsigned char *Buffer, uint Count, myf MyFlags) - /* File descriptor */ - /* Buffer must be at least count bytes */ - /* Max number of bytes returnd */ - /* Flags on what to do on error */ -{ - uint readbytes; - DBUG_ENTER("my_read"); - DBUG_PRINT("my",("Fd: %d Buffer: %lx Count: %u MyFlags: %d", - Filedes, Buffer, Count, MyFlags)); - - for (;;) - { - errno=0; /* Linux doesn't reset this */ - if ((readbytes = (uint) read(Filedes, Buffer, Count)) != Count) - { - my_errno=errno ? errno : -1; - DBUG_PRINT("warning",("Read only %ld bytes off %ld from %d, errno: %d", - readbytes,Count,Filedes,my_errno)); -#ifdef THREAD - if (readbytes == 0 && errno == EINTR) - continue; /* Interrupted */ -#endif - if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) - { - if ((int) readbytes == -1) - ma_error(EE_READ, MYF(ME_BELL+ME_WAITTANG), - my_filename(Filedes),my_errno); - else if (MyFlags & (MY_NABP | MY_FNABP)) - ma_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), - my_filename(Filedes),my_errno); - } - if ((int) readbytes == -1 || (MyFlags & (MY_FNABP | MY_NABP))) - DBUG_RETURN(MY_FILE_ERROR); /* Return with error */ - } - - if (MyFlags & (MY_NABP | MY_FNABP)) - readbytes=0; /* Ok on read */ - break; - } - DBUG_RETURN(readbytes); -} /* my_read */ diff --git a/libmariadb/my_seek.c b/libmariadb/my_seek.c deleted file mode 100644 index 7c4da4f6..00000000 --- a/libmariadb/my_seek.c +++ /dev/null @@ -1,58 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" - - /* Seek to position in file */ - /*ARGSUSED*/ - -my_off_t my_seek(File fd, my_off_t pos, int whence, - myf MyFlags __attribute__((unused))) -{ - reg1 os_off_t newpos; - DBUG_ENTER("my_seek"); - DBUG_PRINT("my",("Fd: %d Hpos: %lu Pos: %lu Whence: %d MyFlags: %d", - fd, ((ulonglong) pos) >> 32, (ulong) pos, whence, MyFlags)); - newpos=lseek(fd, pos, whence); - if (newpos == (os_off_t) -1) - { - my_errno=errno; - DBUG_PRINT("error",("lseek: %lu, errno: %d",newpos,errno)); - DBUG_RETURN(MY_FILEPOS_ERROR); - } - DBUG_RETURN((my_off_t) newpos); -} /* my_seek */ - - - /* Tell current position of file */ - /* ARGSUSED */ - -my_off_t my_tell(File fd, myf MyFlags __attribute__((unused))) -{ - os_off_t pos; - DBUG_ENTER("my_tell"); - DBUG_PRINT("my",("Fd: %d MyFlags: %d",fd, MyFlags)); -#ifdef HAVE_TELL - pos=tell(fd); -#else - pos=lseek(fd, 0L, MY_SEEK_CUR); -#endif - if (pos == (os_off_t) -1) - my_errno=errno; - DBUG_PRINT("exit",("pos: %lu",pos)); - DBUG_RETURN((my_off_t) pos); -} /* my_tell */ diff --git a/libmariadb/my_static.c b/libmariadb/my_static.c deleted file mode 100644 index 9020df27..00000000 --- a/libmariadb/my_static.c +++ /dev/null @@ -1,99 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - Static variables for mysys library. All definied here for easy making of - a shared library -*/ - -#if !defined(stdin) || defined(OS2) -#include "mysys_priv.h" -#include "my_static.h" -#include "my_alarm.h" -#endif - - /* from ma_init */ -my_string ma_ma_ma_home_dir=0,ma_progname=0; -char NEAR ma_cur_dir[FN_REFLEN]= {0}, - NEAR ma_ma_ma_ma_ma_ma_home_dir_buff[FN_REFLEN]= {0}; -ulong ma_stream_opened=0,ma_file_opened=0, ma_tmp_file_created=0; -int NEAR ma_umask=0664, NEAR ma_umask_dir=0777; -#ifndef THREAD -int NEAR my_errno=0; -#endif -struct ma_file_info ma_file_info[MY_NFILE]= {{0,UNOPEN}}; - - /* From mf_brkhant */ -int NEAR ma_dont_interrupt=0; -volatile int _ma_signals=0; -struct st_remember _ma_sig_remember[MAX_SIGNALS]={{0,0}}; -#ifdef THREAD -sigset_t my_signals; /* signals blocked by mf_brkhant */ -#endif - - /* from mf_keycache.c */ -my_bool key_cache_inited=0; - - /* from mf_reccache.c */ -ulong ma_default_record_cache_size=RECORD_CACHE_SIZE; - - /* from soundex.c */ - /* ABCDEFGHIJKLMNOPQRSTUVWXYZ */ - /* :::::::::::::::::::::::::: */ -const char *ma_soundex_map= "01230120022455012623010202"; - - /* from ma_malloc */ -MA_USED_MEM* ma_once_root_block=0; /* pointer to first block */ -uint ma_once_extra=ONCE_ALLOC_INIT; /* Memory to alloc / block */ - - /* from my_tempnam */ -#if !defined(HAVE_TEMPNAM) || defined(HPUX11) -int _my_tempnam_used=0; -#endif - - /* from safe_malloc */ -uint sf_malloc_prehunc=0, /* If you have problem with core- */ - sf_malloc_endhunc=0, /* dump when malloc-message.... */ - /* set theese to 64 or 128 */ - sf_malloc_quick=0; /* set if no calls to sanity */ -size_t lCurMemory = 0L; /* Current memory usage */ -size_t lMaxMemory = 0L; /* Maximum memory usage */ -uint cNewCount = 0; /* Number of times NEW() was called */ - -/* Root of the linked list of remembers */ -struct remember *pRememberRoot = NULL; - - /* from my_alarm */ -int volatile ma_have_got_alarm=0; /* declare variable to reset */ -ulong ma_time_to_wait_for_lock=2; /* In seconds */ - - /* from errors.c */ -#ifdef SHARED_LIBRARY -char * NEAR ma_globerrs[GLOBERRS]; /* ma_error_messages is here */ -#endif -void (*my_abort_hook)(int) = (void(*)(int)) exit; -int (*ma_error_handler_hook)(uint error,const char *str,myf MyFlags)= - ma_message_no_curses; -int (*fatal_ma_error_handler_hook)(uint error,const char *str,myf MyFlags)= - ma_message_no_curses; - - /* How to disable options */ -my_bool NEAR ma_disable_locking=0; -my_bool NEAR ma_disable_async_io=0; -my_bool NEAR ma_disable_flush_key_blocks=0; -my_bool NEAR ma_disable_symlinks=0; -my_bool NEAR mysys_uses_curses=0; diff --git a/libmariadb/my_static.h b/libmariadb/my_static.h deleted file mode 100644 index 344b0030..00000000 --- a/libmariadb/my_static.h +++ /dev/null @@ -1,69 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - Static variables for mysys library. All definied here for easy making of - a shared library -*/ - -#include "mysys_priv.h" -#include - -#define MAX_SIGNALS 10 /* Max signals under a dont-allow */ -#define MIN_KEYBLOCK (min(IO_SIZE,1024)) -#define MAX_KEYBLOCK 8192 /* Max keyblocklength == 8*IO_SIZE */ -#define MAX_BLOCK_TYPES MAX_KEYBLOCK/MIN_KEYBLOCK - -struct st_remember { - int number; - sig_handler (*func)(int number); -}; - -struct irem { - struct remember *_pNext; /* Linked list of structures */ - struct remember *_pPrev; /* Other link */ - my_string _sFileName; /* File in which memory was new'ed */ - uint _uLineNum; /* Line number in above file */ - uint _uDataSize; /* Size requested */ - long _lSpecialValue; /* Underrun marker value */ -}; - -struct remember { - struct irem tInt; - char aData[1]; -}; - -extern char NEAR ma_cur_dir[FN_REFLEN],NEAR ma_ma_ma_ma_ma_ma_home_dir_buff[FN_REFLEN]; - -extern volatile int _ma_signals; -extern struct st_remember _ma_sig_remember[MAX_SIGNALS]; - -extern const char *ma_soundex_map; - -extern MA_USED_MEM* ma_once_root_block; -extern uint ma_once_extra; - -#if !defined(HAVE_TEMPNAM) || defined(HPUX11) -extern int _my_tempnam_used; -#endif - -extern uint cNewCount; -extern struct remember *pRememberRoot; - -#if defined(THREAD) && !defined(__WIN__) -extern sigset_t my_signals; /* signals blocked by mf_brkhant */ -#endif diff --git a/libmariadb/my_symlink.c b/libmariadb/my_symlink.c deleted file mode 100644 index b26ef197..00000000 --- a/libmariadb/my_symlink.c +++ /dev/null @@ -1,138 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include "mysys_err.h" -#include -#include -#ifdef HAVE_REALPATH -#include -#include -#endif - -/* - Reads the content of a symbolic link - If the file is not a symbolic link, return the original file name in to. - Returns: 0 if table was a symlink, - 1 if table was a normal file - -1 on error. -*/ - -int my_readlink(char *to, const char *filename, myf MyFlags) -{ -#ifndef HAVE_READLINK - strcpy(to,filename); - return 1; -#else - int result=0; - int length; - DBUG_ENTER("my_readlink"); - - if ((length=readlink(filename, to, FN_REFLEN-1)) < 0) - { - /* Don't give an error if this wasn't a symlink */ - if ((my_errno=errno) == EINVAL) - { - result= 1; - strcpy(to,filename); - } - else - { - if (MyFlags & MY_WME) - ma_error(EE_CANT_READLINK, MYF(0), filename, errno); - result= -1; - } - } - else - to[length]=0; - DBUG_RETURN(result); -#endif /* HAVE_READLINK */ -} - - -/* Create a symbolic link */ - -int my_symlink(const char *content, const char *linkname, myf MyFlags) -{ -#ifndef HAVE_READLINK - return 0; -#else - int result; - DBUG_ENTER("my_symlink"); - - result= 0; - if (symlink(content, linkname)) - { - result= -1; - my_errno=errno; - if (MyFlags & MY_WME) - ma_error(EE_CANT_SYMLINK, MYF(0), linkname, content, errno); - } - DBUG_RETURN(result); -#endif /* HAVE_READLINK */ -} - -/* - Resolve all symbolic links in path - 'to' may be equal to 'filename' - - Because purify gives a lot of UMR errors when using realpath(), - this code is disabled when using purify. - - If MY_RESOLVE_LINK is given, only do realpath if the file is a link. -*/ - -#if defined(SCO) -#define BUFF_LEN 4097 -#elif defined(MAXPATHLEN) -#define BUFF_LEN MAXPATHLEN -#else -#define BUFF_LEN FN_LEN -#endif - -int my_realpath(char *to, const char *filename, myf MyFlags) -{ -#if defined(HAVE_REALPATH) && !defined(HAVE_purify) && !defined(HAVE_BROKEN_REALPATH) - int result=0; - char buff[BUFF_LEN]; - struct stat stat_buff; - DBUG_ENTER("my_realpath"); - - if (!(MyFlags & MY_RESOLVE_LINK) || - (!lstat(filename,&stat_buff) && S_ISLNK(stat_buff.st_mode))) - { - char *ptr; - if ((ptr=realpath(filename,buff))) - strncpy(to,ptr,FN_REFLEN-1); - else - { - /* Realpath didn't work; Use original name */ - my_errno=errno; - if (MyFlags & MY_WME) - ma_error(EE_REALPATH, MYF(0), filename, my_errno); - if (to != filename) - strmov(to,filename); - result= -1; - } - } - DBUG_RETURN(result); -#else - if (to != filename) - strcpy(to,filename); - return 0; -#endif -} diff --git a/libmariadb/my_thr_init.c b/libmariadb/my_thr_init.c deleted file mode 100644 index bd9a2f30..00000000 --- a/libmariadb/my_thr_init.c +++ /dev/null @@ -1,241 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* -** Functions to handle initializating and allocationg of all mysys & debug -** thread variables. -*/ - -#include "mysys_priv.h" -#include -#include - -#ifdef THREAD -#ifdef USE_TLS -pthread_key(struct st_ma_thread_var*, THR_KEY_mysys); -#else -pthread_key(struct st_ma_thread_var, THR_KEY_mysys); -#endif /* USE_TLS */ -pthread_mutex_t THR_LOCK_malloc,THR_LOCK_open, - THR_LOCK_lock, THR_LOCK_net, THR_LOCK_mysys; -#ifdef HAVE_OPENSSL -pthread_mutex_t LOCK_ssl_config; -#endif -#ifndef HAVE_LOCALTIME_R -pthread_mutex_t LOCK_localtime_r; -#endif -#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP -pthread_mutexattr_t my_fast_mutexattr; -#endif -#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP -pthread_mutexattr_t my_errchk_mutexattr; -#endif -my_bool THR_KEY_mysys_initialized= FALSE; - -/* FIXME Note. TlsAlloc does not set an auto destructor, so - the function my_thread_global_free must be called from - somewhere before final exit of the library */ - -my_bool ma_thread_global_init(void) -{ - if (pthread_key_create(&THR_KEY_mysys,free)) - { - fprintf(stderr,"Can't initialize threads: error %d\n",errno); - exit(1); - } -#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP - pthread_mutexattr_init(&my_fast_mutexattr); - pthread_mutexattr_setkind_np(&my_fast_mutexattr,PTHREAD_MUTEX_ADAPTIVE_NP); -#endif -#ifdef PPTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP - pthread_mutexattr_init(&my_errchk_mutexattr); - pthread_mutexattr_setkind_np(&my_errchk_mutexattr, - PTHREAD_MUTEX_ERRORCHECK_NP); -#endif - THR_KEY_mysys_initialized= TRUE; -#ifdef HAVE_OPENSSL - pthread_mutex_init(&LOCK_ssl_config,MY_MUTEX_INIT_FAST); -#endif - pthread_mutex_init(&THR_LOCK_malloc,MY_MUTEX_INIT_FAST); - pthread_mutex_init(&THR_LOCK_open,MY_MUTEX_INIT_FAST); - pthread_mutex_init(&THR_LOCK_lock,MY_MUTEX_INIT_FAST); - pthread_mutex_init(&THR_LOCK_net,MY_MUTEX_INIT_FAST); -#ifdef _WIN32 - /* win_pthread_init(); */ -#endif -#ifndef HAVE_LOCALTIME_R - pthread_mutex_init(&LOCK_localtime_r,MY_MUTEX_INIT_SLOW); -#endif - return ma_thread_init(); -} - -void ma_thread_global_end(void) -{ -#if defined(USE_TLS) - (void) TlsFree(THR_KEY_mysys); -#endif -#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP - pthread_mutexattr_destroy(&my_fast_mutexattr); -#endif -#ifdef PPTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP - pthread_mutexattr_destroy(&my_errchk_mutexattr); -#endif -#ifdef HAVE_OPENSSL - pthread_mutex_destroy(&LOCK_ssl_config); -#endif -} - -static long thread_id=0; - -/* - We can't use mutex_locks here if we are using windows as - we may have compiled the program with SAFE_MUTEX, in which - case the checking of mutex_locks will not work until - the pthread_self thread specific variable is initialized. -*/ - -my_bool ma_thread_init(void) -{ - struct st_ma_thread_var *tmp; - if (my_pthread_getspecific(struct st_ma_thread_var *,THR_KEY_mysys)) - { - DBUG_PRINT("info", ("ma_thread_init was already called. Thread id: %lu", - pthread_self())); - return 0; /* Safequard */ - } - /* We must have many calloc() here because these are freed on - pthread_exit */ - if (!(tmp=(struct st_ma_thread_var *) - calloc(1,sizeof(struct st_ma_thread_var)))) - { - return 1; - } - pthread_setspecific(THR_KEY_mysys,tmp); - - if (tmp->initialized) /* Already initialized */ - { - return 0; - } - - pthread_mutex_init(&tmp->mutex,MY_MUTEX_INIT_FAST); -// pthread_cond_init(&tmp->suspend, NULL); - pthread_mutex_lock(&THR_LOCK_lock); - tmp->id= ++thread_id; - pthread_mutex_unlock(&THR_LOCK_lock); - tmp->initialized= TRUE; - return 0; -} - -void ma_thread_end(void) -{ - struct st_ma_thread_var *tmp= - my_pthread_getspecific(struct st_ma_thread_var *, THR_KEY_mysys); - - if (tmp && tmp->initialized) - { -#ifdef HAVE_NSSL - ma_ssl_end(); -#endif -#if !defined(DBUG_OFF) - if (tmp->dbug) - { - DBUG_POP(); - free(tmp->dbug); - tmp->dbug=0; - } -#endif -#if !defined(__bsdi__) || defined(HAVE_mit_thread) /* bsdi dumps core here */ -// pthread_cond_destroy(&tmp->suspend); -#endif - pthread_mutex_destroy(&tmp->mutex); - free(tmp); - pthread_setspecific(THR_KEY_mysys,0); - } - else - pthread_setspecific(THR_KEY_mysys,0); -} - -struct st_ma_thread_var *_ma_thread_var(void) -{ - struct st_ma_thread_var *tmp= - my_pthread_getspecific(struct st_ma_thread_var*,THR_KEY_mysys); -#if defined(USE_TLS) - if (!tmp) - { - ma_thread_init(); - tmp=my_pthread_getspecific(struct st_ma_thread_var*,THR_KEY_mysys); - } -#endif - return tmp; -} - -/**************************************************************************** -** Get name of current thread. -****************************************************************************/ - -#define UNKNOWN_THREAD -1 - -long my_thread_id() -{ -#if defined(HAVE_PTHREAD_GETSEQUENCE_NP) - return pthread_getsequence_np(pthread_self()); -#elif (defined(__sun) || defined(__sgi) || defined(__linux__)) && !defined(HAVE_mit_thread) - return pthread_self(); -#else - return my_thread_var->id; -#endif -} - -#ifdef DBUG_OFF -const char *ma_thread_name(void) -{ - return "no_name"; -} - -#else - -const char *ma_thread_name(void) -{ - char name_buff[100]; - struct st_ma_thread_var *tmp=my_thread_var; - if (!tmp->name[0]) - { - long id=my_thread_id(); - sprintf(name_buff,"T@%ld", id); - strncpy(tmp->name,name_buff,THREAD_NAME_SIZE); - } - return tmp->name; -} - -extern void **ma_thread_var_dbug() -{ - struct st_ma_thread_var *tmp; - /* - Instead of enforcing DBUG_ASSERT(THR_KEY_mysys_initialized) here, - which causes any DBUG_ENTER and related traces to fail when - used in init / cleanup code, we are more tolerant: - using DBUG_ENTER / DBUG_PRINT / DBUG_RETURN - when the dbug instrumentation is not in place will do nothing. - */ - if (! THR_KEY_mysys_initialized) - return NULL; - tmp= _ma_thread_var(); - return tmp && tmp->initialized ? (void **)&tmp->dbug : 0; -} -#endif /* DBUG_OFF */ - -#endif /* THREAD */ diff --git a/libmariadb/my_write.c b/libmariadb/my_write.c deleted file mode 100644 index 34b82a54..00000000 --- a/libmariadb/my_write.c +++ /dev/null @@ -1,90 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include "mysys_err.h" -#include - - - /* Write a chunk of bytes to a file */ - -uint my_write(int Filedes, const unsigned char *Buffer, uint Count, myf MyFlags) -{ - uint writenbytes,errors; - ulong written; - DBUG_ENTER("my_write"); - DBUG_PRINT("my",("Fd: %d Buffer: %lx Count: %d MyFlags: %d", - Filedes, Buffer, Count, MyFlags)); - errors=0; written=0L; - - for (;;) - { - if ((writenbytes = (uint) write(Filedes, Buffer, Count)) == Count) - break; - if ((int) writenbytes != -1) - { /* Safeguard */ - written+=writenbytes; - Buffer+=writenbytes; - Count-=writenbytes; - } - my_errno=errno; - DBUG_PRINT("error",("Write only %d bytes, error: %d", - writenbytes,my_errno)); -#ifndef NO_BACKGROUND -#ifdef THREAD - if (my_thread_var->abort) - MyFlags&= ~ MY_WAIT_IF_FULL; /* End if aborted by user */ -#endif - if (my_errno == ENOSPC && (MyFlags & MY_WAIT_IF_FULL) && - (uint) writenbytes != (uint) -1) - { - if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE)) - ma_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH), - my_filename(Filedes)); - VOID(sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC)); - continue; - } - if (!writenbytes) - { - /* We may come here on an interrupt or if the file quote is exeeded */ - if (my_errno == EINTR) - continue; - if (!errors++) /* Retry once */ - { - errno=EFBIG; /* Assume this is the error */ - continue; - } - } - else if ((uint) writenbytes != (uint) -1) - continue; /* Retry */ -#endif - if (MyFlags & (MY_NABP | MY_FNABP)) - { - if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) - { - ma_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG), - my_filename(Filedes),my_errno); - } - DBUG_RETURN(MY_FILE_ERROR); /* Error on read */ - } - else - break; /* Return bytes written */ - } - if (MyFlags & (MY_NABP | MY_FNABP)) - DBUG_RETURN(0); /* Want only errors */ - DBUG_RETURN(writenbytes+written); -} /* my_write */ diff --git a/libmariadb/mysys_priv.h b/libmariadb/mysys_priv.h deleted file mode 100644 index 9e7f9c42..00000000 --- a/libmariadb/mysys_priv.h +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include -#include - -#ifdef USE_SYSTEM_WRAPPERS -#include "system_wrappers.h" -#endif - -#ifdef THREAD -#include -extern pthread_mutex_t THR_LOCK_malloc,THR_LOCK_open,THR_LOCK_keycache, - THR_LOCK_lock,THR_LOCK_isam,THR_LOCK_net,THR_LOCK_charset; -extern pthread_mutex_t LOCK_bitmap; -#else -#include -#endif diff --git a/libmariadb/secure/gnutls.c b/libmariadb/secure/gnutls.c index 30865f09..1e76b654 100644 --- a/libmariadb/secure/gnutls.c +++ b/libmariadb/secure/gnutls.c @@ -21,12 +21,12 @@ #include #include -#include -#include +#include +#include #include #include -#include -#include +#include +#include #include #include #include @@ -187,7 +187,7 @@ static int ma_ssl_set_certs(MYSQL *mysql) error: if (cipher) - ma_free(cipher); + free(cipher); return ssl_error; } diff --git a/libmariadb/secure/ma_schannel.h b/libmariadb/secure/ma_schannel.h index 94ac0941..70e8b624 100644 --- a/libmariadb/secure/ma_schannel.h +++ b/libmariadb/secure/ma_schannel.h @@ -23,11 +23,11 @@ #define _ma_schannel_h_ #define SECURITY_WIN32 -#include -#include +#include +#include #include #include -#include +#include typedef void VOID; @@ -46,12 +46,7 @@ typedef void VOID; #define SC_IO_BUFFER_SIZE 0x4000 -#ifndef HAVE_SCHANNEL_DEFAULT -#define ma_snprintf snprintf -#define ma_vsnprintf vsnprintf -#undef SAFE_MUTEX -#endif -#include +#include struct st_schannel { HCERTSTORE cert_store; diff --git a/libmariadb/secure/openssl.c b/libmariadb/secure/openssl.c index 75609b26..c35e6dda 100644 --- a/libmariadb/secure/openssl.c +++ b/libmariadb/secure/openssl.c @@ -17,11 +17,11 @@ 51 Franklin St., Fifth Floor, Boston, MA 02110, USA *************************************************************************************/ -#include -#include +#include +#include #include #include -#include +#include #include #include #include @@ -38,7 +38,7 @@ #define ma_vsnprintf vsnprintf #undef SAFE_MUTEX #endif -#include +#include extern my_bool ma_ssl_initialized; extern unsigned int mariadb_deinitialize_ssl; @@ -64,6 +64,7 @@ static void ma_ssl_set_error(MYSQL *mysql) } if ((ssl_error_reason= ERR_reason_error_string(ssl_errno))) { + printf("reason: %s\n", ssl_error_reason); pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, 0, ssl_error_reason); return; @@ -246,7 +247,7 @@ void ma_ssl_end() int ma_ssl_get_password(char *buf, int size, int rwflag, void *userdata) { - bzero(buf, size); + memset(buf, 0, size); if (userdata) strncpy(buf, (char *)userdata, size); return strlen(buf); @@ -426,6 +427,7 @@ my_bool ma_ssl_connect(MARIADB_SSL *cssl) rc= SSL_get_verify_result(ssl); if (rc != X509_V_OK) { + printf("--------------------\n"); my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, ER(CR_SSL_CONNECTION_ERROR), X509_verify_cert_error_string(rc)); /* restore blocking mode */ diff --git a/libmariadb/sha1.c b/libmariadb/sha1.c deleted file mode 100644 index b1c231af..00000000 --- a/libmariadb/sha1.c +++ /dev/null @@ -1,325 +0,0 @@ -/**************************************************************************** - 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 - 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 "my_global.h" -#include "string.h" - -/* This code is heavily based on the PHP md5 implementation */ - -#include "sha1.h" - - -static void SHA1Transform(uint32[5], const unsigned char[64]); -static void SHA1Encode(unsigned char *, uint32 *, unsigned int); -static void 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); \ - } - - -/* {{{ MYSQL_SHA1Init - * SHA1 initialization. Begins an SHA1 operation, writing a new context. - */ -void MYSQL_SHA1Init(MYSQL_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; -} -/* }}} */ - -/* {{{ MYSQL_SHA1Update - SHA1 block update operation. Continues an SHA1 message-digest - operation, processing another message block, and updating the - context. - */ -void MYSQL_SHA1Update(MYSQL_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); - SHA1Transform(context->state, context->buffer); - - for (i = partLen; i + 63 < inputLen; i += 64) - 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); -} -/* }}} */ - -/* {{{ MYSQL_SHA1Final - SHA1 finalization. Ends an SHA1 message-digest operation, writing the - the message digest and zeroizing the context. - */ -void MYSQL_SHA1Final(unsigned char digest[20], MYSQL_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); - MYSQL_SHA1Update(context, PADDING, padLen); - - /* Append length (before padding) */ - MYSQL_SHA1Update(context, bits, 8); - - /* Store state in digest */ - SHA1Encode(digest, context->state, 20); - - /* Zeroize sensitive information. - */ - memset((unsigned char*) context, 0, sizeof(*context)); -} -/* }}} */ - -/* {{{ SHA1Transform - * SHA1 basic transformation. Transforms state based on block. - */ -static void 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; - - 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)); -} -/* }}} */ - -/* {{{ SHA1Encode - Encodes input (uint32) into output (unsigned char). Assumes len is - a multiple of 4. - */ -static void 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); - } -} -/* }}} */ - -/* {{{ SHA1Decode - Decodes input (unsigned char) into output (uint32). Assumes len is - a multiple of 4. - */ -static void 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 - */ diff --git a/libmariadb/str2int.c b/libmariadb/str2int.c deleted file mode 100644 index 22c71b2f..00000000 --- a/libmariadb/str2int.c +++ /dev/null @@ -1,202 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - ma_str2int(src, radix, lower, upper, &val) - converts the string pointed to by src to an integer and stores it in - val. It skips leading spaces and tabs (but not newlines, formfeeds, - backspaces), then it accepts an optional sign and a sequence of digits - in the specified radix. The result should satisfy lower <= *val <= upper. - The result is a pointer to the first character after the number; - trailing spaces will NOT be skipped. - - If an error is detected, the result will be NullS, the value put - in val will be 0, and errno will be set to - EDOM if there are no digits - ERANGE if the result would overflow or otherwise fail to lie - within the specified bounds. - Check that the bounds are right for your machine. - This looks amazingly complicated for what you probably thought was an - easy task. Coping with integer overflow and the asymmetric range of - twos complement machines is anything but easy. - - So that users of atoi and atol can check whether an error occured, - I have taken a wholly unprecedented step: errno is CLEARED if this - call has no problems. -*/ - -#include -#include "m_string.h" -#include "mariadb_ctype.h" -#include "my_sys.h" /* defines errno */ -#include - -#define char_val(X) (X >= '0' && X <= '9' ? X-'0' :\ - X >= 'A' && X <= 'Z' ? X-'A'+10 :\ - X >= 'a' && X <= 'z' ? X-'a'+10 :\ - '\177') - -char *ma_str2int(register const char *src, register int radix, long int lower, long int upper, long int *val) -{ - int sign; /* is number negative (+1) or positive (-1) */ - int n; /* number of digits yet to be converted */ - long limit; /* "largest" possible valid input */ - long scale; /* the amount to multiply next digit by */ - long sofar; /* the running value */ - register int d; /* (negative of) next digit */ - char *start; - int digits[32]; /* Room for numbers */ - - /* Make sure *val is sensible in case of error */ - - *val = 0; - - /* Check that the radix is in the range 2..36 */ - -#ifndef DBUG_OFF - if (radix < 2 || radix > 36) { - errno=EDOM; - return NullS; - } -#endif - - /* The basic problem is: how do we handle the conversion of - a number without resorting to machine-specific code to - check for overflow? Obviously, we have to ensure that - no calculation can overflow. We are guaranteed that the - "lower" and "upper" arguments are valid machine integers. - On sign-and-magnitude, twos-complement, and ones-complement - machines all, if +|n| is representable, so is -|n|, but on - twos complement machines the converse is not true. So the - "maximum" representable number has a negative representative. - Limit is set to min(-|lower|,-|upper|); this is the "largest" - number we are concerned with. */ - - /* Calculate Limit using Scale as a scratch variable */ - - if ((limit = lower) > 0) limit = -limit; - if ((scale = upper) > 0) scale = -scale; - if (scale < limit) limit = scale; - - /* Skip leading spaces and check for a sign. - Note: because on a 2s complement machine MinLong is a valid - integer but |MinLong| is not, we have to keep the current - converted value (and the scale!) as *negative* numbers, - so the sign is the opposite of what you might expect. - */ - while (isspace(*src)) src++; - sign = -1; - if (*src == '+') src++; else - if (*src == '-') src++, sign = 1; - - /* Skip leading zeros so that we never compute a power of radix - in scale that we won't have a need for. Otherwise sticking - enough 0s in front of a number could cause the multiplication - to overflow when it neededn't. - */ - start=(char*) src; - while (*src == '0') src++; - - /* Move over the remaining digits. We have to convert from left - to left in order to avoid overflow. Answer is after last digit. - */ - - for (n = 0; (digits[n]=char_val(*src)) < radix && n < 20; n++,src++) ; - - /* Check that there is at least one digit */ - - if (start == src) { - errno=EDOM; - return NullS; - } - - /* The invariant we want to maintain is that src is just - to the right of n digits, we've converted k digits to - sofar, scale = -radix**k, and scale < sofar < 0. Now - if the final number is to be within the original - Limit, we must have (to the left)*scale+sofar >= Limit, - or (to the left)*scale >= Limit-sofar, i.e. the digits - to the left of src must form an integer <= (Limit-sofar)/(scale). - In particular, this is true of the next digit. In our - incremental calculation of Limit, - - IT IS VITAL that (-|N|)/(-|D|) = |N|/|D| - */ - - for (sofar = 0, scale = -1; --n >= 1;) - { - if ((long) -(d=digits[n]) < limit) { - errno=ERANGE; - return NullS; - } - limit = (limit+d)/radix, sofar += d*scale; scale *= radix; - } - if (n == 0) - { - if ((long) -(d=digits[n]) < limit) /* get last digit */ - { - errno=ERANGE; - return NullS; - } - sofar+=d*scale; - } - - /* Now it might still happen that sofar = -32768 or its equivalent, - so we can't just multiply by the sign and check that the result - is in the range lower..upper. All of this caution is a right - pain in the neck. If only there were a standard routine which - says generate thus and such a signal on integer overflow... - But not enough machines can do it *SIGH*. - */ - if (sign < 0) - { - if (sofar < -LONG_MAX || (sofar= -sofar) > upper) - { - errno=ERANGE; - return NullS; - } - } - else if (sofar < lower) - { - errno=ERANGE; - return NullS; - } - *val = sofar; - errno=0; /* indicate that all went well */ - return (char*) src; -} - - /* Theese are so slow compared with ordinary, optimized atoi */ - -#ifdef WANT_OUR_ATOI - -int atoi(const char *src) -{ - long val; - ma_str2int(src, 10, (long) INT_MIN, (long) INT_MAX, &val); - return (int) val; -} - - -long atol(const char *src) -{ - long val; - ma_str2int(src, 10, LONG_MIN, LONG_MAX, &val); - return val; -} - -#endif /* WANT_OUR_ATOI */ diff --git a/libmariadb/strcont.c b/libmariadb/strcont.c deleted file mode 100644 index d4e903a1..00000000 --- a/libmariadb/strcont.c +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : strcont.c - Author : Monty - Updated: 1988.07.27 - Defines: strcont() - - strcont(str, set) if str contanies any character in the string set. - The result is the position of the first found character in str, or NullS - if there isn't anything found. - -*/ - -#include -#include "m_string.h" - -my_string strcont(reg1 const char *str,reg2 const char *set) -{ - reg3 my_string start = (my_string) set; - - while (*str) - { - while (*set) - { - if (*set++ == *str) - return ((char*) str); - } - set=start; str++; - } - return (NullS); -} /* strcont */ diff --git a/libmariadb/strto.c b/libmariadb/strto.c deleted file mode 100644 index aed398b8..00000000 --- a/libmariadb/strto.c +++ /dev/null @@ -1,209 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - strtol,strtoul,strtoll,strtoull - convert string to long, unsigned long, long long or unsigned long long. - strtoxx(char *src,char **ptr,int base) - converts the string pointed to by src to an long of appropriate long and - returnes it. It skips leading spaces and tabs (but not newlines, formfeeds, - backspaces), then it accepts an optional sign and a sequence of digits - in the specified radix. - If the value of ptr is not (char **)NULL, a pointer to the character - terminating the scan is returned in the location pointed to by ptr. - Trailing spaces will NOT be skipped. - - If an error is detected, the result will be LONG_MIN, 0 or LONG_MAX, - (or LONGLONG..) and errno will be set to - EDOM if there are no digits - ERANGE if the result would overflow. - the ptr will be set to src. - This file is based on the strtol from the the GNU C Library. - it can be compiled with the UNSIGNED and/or LONGLONG flag set -*/ - -#define strtoll glob_strtoll /* Fix for True64 */ - -#include "m_string.h" -#include "mariadb_ctype.h" -#include "my_sys.h" /* defines errno */ -#include - -#undef strtoull -#undef strtoll -#undef strtoul -#undef strtol -#ifdef USE_LONGLONG -#define UTYPE_MAX (~(ulonglong) 0) -#define TYPE_MIN LONGLONG_MIN -#define TYPE_MAX LONGLONG_MAX -#define longtype longlong -#define ulongtype ulonglong -#ifdef USE_UNSIGNED -#define function ulongtype strtoull -#else -#define function longtype strtoll -#endif -#else -#define UTYPE_MAX (ulong) ~0L -#define TYPE_MIN LONG_MIN -#define TYPE_MAX LONG_MAX -#define longtype long -#define ulongtype unsigned long -#ifdef USE_UNSIGNED -#define function ulongtype strtoul -#else -#define function longtype strtol -#endif -#endif - - -/* Convert NPTR to an `unsigned long int' or `long int' in base BASE. - If BASE is 0 the base is determined by the presence of a leading - zero, indicating octal or a leading "0x" or "0X", indicating hexadecimal. - If BASE is < 2 or > 36, it is reset to 10. - If ENDPTR is not NULL, a pointer to the character after the last - one converted is stored in *ENDPTR. */ - - -function (const char *nptr,char **endptr,int base) -{ - int negative; - register ulongtype cutoff; - register unsigned int cutlim; - register ulongtype i; - register const char *s; - register unsigned char c; - const char *save; - int overflow; - - if (base < 0 || base == 1 || base > 36) - base = 10; - - s = nptr; - - /* Skip white space. */ - while (isspace (*s)) - ++s; - if (*s == '\0') - { - goto noconv; - } - - /* Check for a sign. */ - if (*s == '-') - { - negative = 1; - ++s; - } - else if (*s == '+') - { - negative = 0; - ++s; - } - else - negative = 0; - - if (base == 16 && s[0] == '0' && toupper (s[1]) == 'X') - s += 2; - - /* If BASE is zero, figure it out ourselves. */ - if (base == 0) - { - if (*s == '0') - { - if (toupper (s[1]) == 'X') - { - s += 2; - base = 16; - } - else - base = 8; - } - else - base = 10; - } - - /* Save the pointer so we can check later if anything happened. */ - save = s; - - cutoff = UTYPE_MAX / (unsigned long int) base; - cutlim = (uint) (UTYPE_MAX % (unsigned long int) base); - - overflow = 0; - i = 0; - for (c = *s; c != '\0'; c = *++s) - { - if (isdigit (c)) - c -= '0'; - else if (isalpha (c)) - c = toupper (c) - 'A' + 10; - else - break; - if (c >= base) - break; - /* Check for overflow. */ - if (i > cutoff || (i == cutoff && c > cutlim)) - overflow = 1; - else - { - i *= (ulongtype) base; - i += c; - } - } - - /* Check if anything actually happened. */ - if (s == save) - goto noconv; - - /* Store in ENDPTR the address of one character - past the last character we converted. */ - if (endptr != NULL) - *endptr = (char *) s; - -#ifndef USE_UNSIGNED - /* Check for a value that is within the range of - `unsigned long int', but outside the range of `long int'. */ - if (negative) - { - if (i > (ulongtype) TYPE_MIN) - overflow = 1; - } - else if (i > (ulongtype) TYPE_MAX) - overflow = 1; -#endif - - if (overflow) - { - my_errno=ERANGE; -#ifdef USE_UNSIGNED - return UTYPE_MAX; -#else - return negative ? TYPE_MIN : TYPE_MAX; -#endif - } - - /* Return the result of the appropriate sign. */ - return (negative ? -((longtype) i) : (longtype) i); - -noconv: - /* There was no number to convert. */ - my_errno=EDOM; - if (endptr != NULL) - *endptr = (char *) nptr; - return 0L; -} diff --git a/libmariadb/strtoll.c b/libmariadb/strtoll.c deleted file mode 100644 index 360126ce..00000000 --- a/libmariadb/strtoll.c +++ /dev/null @@ -1,198 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* This is defines strtoll() if neaded */ - -#include -#include -#if !defined(HAVE_STRTOLL) && defined(HAVE_LONG_LONG) -#define USE_LONGLONG - -#define strtoll glob_strtoll /* Fix for True64 */ - -#include "m_string.h" -#include "mariadb_ctype.h" -#include "my_sys.h" /* defines errno */ -#include - -#undef strtoull -#undef strtoll -#undef strtoul -#undef strtol -#ifdef USE_LONGLONG -#define UTYPE_MAX (~(ulonglong) 0) -#define TYPE_MIN LONGLONG_MIN -#define TYPE_MAX LONGLONG_MAX -#define longtype longlong -#define ulongtype ulonglong -#ifdef USE_UNSIGNED -#define function ulongtype strtoull -#else -#define function longtype strtoll -#endif -#else -#define UTYPE_MAX (ulong) ~0L -#define TYPE_MIN LONG_MIN -#define TYPE_MAX LONG_MAX -#define longtype long -#define ulongtype unsigned long -#ifdef USE_UNSIGNED -#define function ulongtype strtoul -#else -#define function longtype strtol -#endif -#endif - - -/* Convert NPTR to an `unsigned long int' or `long int' in base BASE. - If BASE is 0 the base is determined by the presence of a leading - zero, indicating octal or a leading "0x" or "0X", indicating hexadecimal. - If BASE is < 2 or > 36, it is reset to 10. - If ENDPTR is not NULL, a pointer to the character after the last - one converted is stored in *ENDPTR. */ - - -function (const char *nptr,char **endptr,int base) -{ - int negative; - register ulongtype cutoff; - register unsigned int cutlim; - register ulongtype i; - register const char *s; - register unsigned char c; - const char *save; - int overflow; - - if (base < 0 || base == 1 || base > 36) - base = 10; - - s = nptr; - - /* Skip white space. */ - while (isspace (*s)) - ++s; - if (*s == '\0') - { - goto noconv; - } - - /* Check for a sign. */ - if (*s == '-') - { - negative = 1; - ++s; - } - else if (*s == '+') - { - negative = 0; - ++s; - } - else - negative = 0; - - if (base == 16 && s[0] == '0' && toupper (s[1]) == 'X') - s += 2; - - /* If BASE is zero, figure it out ourselves. */ - if (base == 0) - { - if (*s == '0') - { - if (toupper (s[1]) == 'X') - { - s += 2; - base = 16; - } - else - base = 8; - } - else - base = 10; - } - - /* Save the pointer so we can check later if anything happened. */ - save = s; - - cutoff = UTYPE_MAX / (unsigned long int) base; - cutlim = (uint) (UTYPE_MAX % (unsigned long int) base); - - overflow = 0; - i = 0; - for (c = *s; c != '\0'; c = *++s) - { - if (isdigit (c)) - c -= '0'; - else if (isalpha (c)) - c = toupper (c) - 'A' + 10; - else - break; - if (c >= base) - break; - /* Check for overflow. */ - if (i > cutoff || (i == cutoff && c > cutlim)) - overflow = 1; - else - { - i *= (ulongtype) base; - i += c; - } - } - - /* Check if anything actually happened. */ - if (s == save) - goto noconv; - - /* Store in ENDPTR the address of one character - past the last character we converted. */ - if (endptr != NULL) - *endptr = (char *) s; - -#ifndef USE_UNSIGNED - /* Check for a value that is within the range of - `unsigned long int', but outside the range of `long int'. */ - if (negative) - { - if (i > (ulongtype) TYPE_MIN) - overflow = 1; - } - else if (i > (ulongtype) TYPE_MAX) - overflow = 1; -#endif - - if (overflow) - { - my_errno=ERANGE; -#ifdef USE_UNSIGNED - return UTYPE_MAX; -#else - return negative ? TYPE_MIN : TYPE_MAX; -#endif - } - - /* Return the result of the appropriate sign. */ - return (negative ? -((longtype) i) : (longtype) i); - -noconv: - /* There was no number to convert. */ - my_errno=EDOM; - if (endptr != NULL) - *endptr = (char *) nptr; - return 0L; -} - - -#endif diff --git a/libmariadb/thr_mutex.c b/libmariadb/thr_mutex.c deleted file mode 100644 index a985c58b..00000000 --- a/libmariadb/thr_mutex.c +++ /dev/null @@ -1,231 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* This makes a wrapper for mutex handling to make it easier to debug mutex */ - -#include -#if defined(HAVE_LINUXTHREADS) && !defined (__USE_UNIX98) -#define __USE_UNIX98 /* To get rw locks under Linux */ -#endif -#include -#if defined(THREAD) && defined(SAFE_MUTEX) -#undef SAFE_MUTEX /* Avoid safe_mutex redefinitions */ -#include - -#ifndef DO_NOT_REMOVE_THREAD_WRAPPERS -/* Remove wrappers */ -#undef pthread_mutex_init -#undef pthread_mutex_lock -#undef pthread_mutex_unlock -#undef pthread_mutex_destroy -#undef pthread_cond_wait -#undef pthread_cond_timedwait -#ifdef HAVE_NONPOSIX_PTHREAD_MUTEX_INIT -#define pthread_mutex_init(a,b) my_pthread_mutex_init((a),(b)) -#endif -#endif /* DO_NOT_REMOVE_THREAD_WRAPPERS */ - -int safe_mutex_init(safe_mutex_t *mp, - const pthread_mutexattr_t *attr __attribute__((unused))) -{ - bzero((char*) mp,sizeof(*mp)); - pthread_mutex_init(&mp->global,MY_MUTEX_INIT_ERRCHK); - pthread_mutex_init(&mp->mutex,attr); - return 0; -} - -int safe_mutex_lock(safe_mutex_t *mp,const char *file, uint line) -{ - int error; - pthread_mutex_lock(&mp->global); - if (mp->count > 0 && pthread_equal(pthread_self(),mp->thread)) - { - fprintf(stderr,"safe_mutex: Trying to lock mutex at %s, line %d, when the mutex was already locked at %s, line %d\n", - file,line,mp->file,mp->line); - fflush(stderr); - abort(); - } - pthread_mutex_unlock(&mp->global); - error=pthread_mutex_lock(&mp->mutex); - if (error || (error=pthread_mutex_lock(&mp->global))) - { - fprintf(stderr,"Got error %d when trying to lock mutex at %s, line %d\n", - error, file, line); - fflush(stderr); - abort(); - } - if (mp->count++) - { - fprintf(stderr,"safe_mutex: Error in thread libray: Got mutex at %s, line %d more than 1 time\n", file,line); - fflush(stderr); - abort(); - } - mp->thread=pthread_self(); - mp->file= (char*) file; - mp->line=line; - pthread_mutex_unlock(&mp->global); - return error; -} - - -int safe_mutex_unlock(safe_mutex_t *mp,const char *file, uint line) -{ - int error; - pthread_mutex_lock(&mp->global); - if (mp->count == 0) - { - fprintf(stderr,"safe_mutex: Trying to unlock mutex that wasn't locked at %s, line %d\n Last used at %s, line: %d\n", - file,line,mp->file ? mp->file : "",mp->line); - fflush(stderr); - abort(); - } - if (!pthread_equal(pthread_self(),mp->thread)) - { - fprintf(stderr,"safe_mutex: Trying to unlock mutex at %s, line %d that was locked by another thread at: %s, line: %d\n", - file,line,mp->file,mp->line); - fflush(stderr); - abort(); - } - mp->count--; -#ifdef _WIN32 - pthread_mutex_unlock(&mp->mutex); - error=0; -#else - error=pthread_mutex_unlock(&mp->mutex); - if (error) - { - fprintf(stderr,"safe_mutex: Got error: %d when trying to unlock mutex at %s, line %d\n", error, file, line); - fflush(stderr); - abort(); - } -#endif /* _WIN32 */ - pthread_mutex_unlock(&mp->global); - return error; -} - - -int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp, const char *file, - uint line) -{ - int error; - pthread_mutex_lock(&mp->global); - if (mp->count == 0) - { - fprintf(stderr,"safe_mutex: Trying to cond_wait on a unlocked mutex at %s, line %d\n",file,line); - fflush(stderr); - abort(); - } - if (!pthread_equal(pthread_self(),mp->thread)) - { - fprintf(stderr,"safe_mutex: Trying to cond_wait on a mutex at %s, line %d that was locked by another thread at: %s, line: %d\n", - file,line,mp->file,mp->line); - fflush(stderr); - abort(); - } - - if (mp->count-- != 1) - { - fprintf(stderr,"safe_mutex: Count was %d on locked mutex at %s, line %d\n", - mp->count+1, file, line); - fflush(stderr); - abort(); - } - pthread_mutex_unlock(&mp->global); - error=pthread_cond_wait(cond,&mp->mutex); - pthread_mutex_lock(&mp->global); - if (error) - { - fprintf(stderr,"safe_mutex: Got error: %d when doing a safe_mutex_wait at %s, line %d\n", error, file, line); - fflush(stderr); - abort(); - } - if (mp->count++) - { - fprintf(stderr, - "safe_mutex: Count was %d in thread %lx when locking mutex at %s, line %d\n", - mp->count-1, my_thread_id(), file, line); - fflush(stderr); - abort(); - } - mp->thread=pthread_self(); - mp->file= (char*) file; - mp->line=line; - pthread_mutex_unlock(&mp->global); - return error; -} - - -int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp, - struct timespec *abstime, - const char *file, uint line) -{ - int error; - pthread_mutex_lock(&mp->global); - if (mp->count != 1 || !pthread_equal(pthread_self(),mp->thread)) - { - fprintf(stderr,"safe_mutex: Trying to cond_wait at %s, line %d on a not hold mutex\n",file,line); - fflush(stderr); - abort(); - } - mp->count--; /* Mutex will be released */ - pthread_mutex_unlock(&mp->global); - error=pthread_cond_timedwait(cond,&mp->mutex,abstime); -#ifdef EXTRA_DEBUG - if (error && (error != EINTR && error != ETIMEDOUT)) - { - fprintf(stderr,"safe_mutex: Got error: %d when doing a safe_mutex_timedwait at %s, line %d\n", error, file, line); - } -#endif - pthread_mutex_lock(&mp->global); - if (mp->count++) - { - fprintf(stderr, - "safe_mutex: Count was %d in thread %lx when locking mutex at %s, line %d (error: %d)\n", - mp->count-1, my_thread_id(), file, line, error); - fflush(stderr); - abort(); - } - mp->thread=pthread_self(); - mp->file= (char*) file; - mp->line=line; - pthread_mutex_unlock(&mp->global); - return error; -} - -int safe_mutex_destroy(safe_mutex_t *mp, const char *file, uint line) -{ - int error=0; - if (mp->count != 0) - { - fprintf(stderr,"safe_mutex: Trying to destroy a mutex that was locked at %s, line %d at %s, line %d\n", - mp->file,mp->line, file, line); - fflush(stderr); - abort(); - } -#ifdef _WIN32 - pthread_mutex_destroy(&mp->global); - pthread_mutex_destroy(&mp->mutex); -#else - if (pthread_mutex_destroy(&mp->global)) - error=1; - if (pthread_mutex_destroy(&mp->mutex)) - error=1; -#endif - return error; -} - -#endif /* THREAD && SAFE_MUTEX */ diff --git a/libmariadb/typelib.c b/libmariadb/typelib.c deleted file mode 100644 index aa087a23..00000000 --- a/libmariadb/typelib.c +++ /dev/null @@ -1,106 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* Functions to handle typelib */ - -#include "mysys_priv.h" -#include -#include - -/*************************************************************************** -** Search after a fieldtype. Endspace in x is not compared. -** If part, uniq field is found and full_name == 0 then x is expanded -** to full field. -** full_name has the following bit values: -** If & 1 accept only whole names -** If & 2 don't expand if half field -** If & 4 allow #number# as type -****************************************************************************/ - -int ma_find_type(my_string x, TYPELIB *typelib, uint full_name) -{ - int find,pos,findpos= 0; - reg1 my_string i; - reg2 const char *j; - DBUG_ENTER("ma_find_type"); - DBUG_PRINT("enter",("x: '%s' lib: %lx",x,typelib)); - - if (!typelib->count) - { - DBUG_PRINT("exit",("no count")); - DBUG_RETURN(0); - } - LINT_INIT(findpos); - find=0; - for (pos=0 ; (j=typelib->type_names[pos]) ; pos++) - { - for (i=x ; *i && toupper(*i) == toupper(*j) ; i++, j++) ; - if (! *j) - { - while (*i == ' ') - i++; /* skipp_end_space */ - if (! *i) - DBUG_RETURN(pos+1); - } - if (! *i && (!*j || !(full_name & 1))) - { - find++; - findpos=pos; - } - } - if (find == 0 && (full_name & 4) && x[0] == '#' && strend(x)[-1] == '#' && - (findpos=atoi(x+1)-1) >= 0 && (uint) findpos < typelib->count) - find=1; - else if (find == 0 || ! x[0]) - { - DBUG_PRINT("exit",("Couldn't find type")); - DBUG_RETURN(0); - } - else if (find != 1 || (full_name & 1)) - { - DBUG_PRINT("exit",("Too many possybilities")); - DBUG_RETURN(-1); - } - if (!(full_name & 2)) - (void) strmov(x,typelib->type_names[findpos]); - DBUG_RETURN(findpos+1); -} /* ma_find_type */ - - - /* Get name of type nr 'nr' */ - /* Warning first type is 1, 0 = empty field */ - -void ma_make_type(register my_string to, register uint nr, register TYPELIB *typelib) -{ - DBUG_ENTER("ma_make_type"); - if (!nr) - to[0]=0; - else - (void) strmov(to,ma_get_type(typelib,nr-1)); - DBUG_VOID_RETURN; -} /* ma_make_type */ - - - /* Get type */ - /* Warning first type is 0 */ - -const char *ma_get_type(TYPELIB *typelib, uint nr) -{ - if (nr < (uint) typelib->count && typelib->type_names) - return(typelib->type_names[nr]); - return "?"; -} diff --git a/mariadb_config/mariadb_config.c.in b/mariadb_config/mariadb_config.c.in index 15f26618..a9e794c4 100644 --- a/mariadb_config/mariadb_config.c.in +++ b/mariadb_config/mariadb_config.c.in @@ -1,8 +1,10 @@ -#include -#include +#include +#include #include #include +static char *mariadb_progname; + #define INCLUDE "-I@PREFIX_INSTALL_DIR@/@INCLUDE_INSTALL_DIR@/@SUFFIX_INSTALL_DIR@ -I@PREFIX_INSTALL_DIR@/@INCLUDE_INSTALL_DIR@/@SUFFIX_INSTALL_DIR@/mysql" #define LIBS "-L@PREFIX_INSTALL_DIR@/@LIB_INSTALL_DIR@/@SUFFIX_INSTALL_DIR@ -lmariadb" \ "@extra_dynamic_LDFLAGS@" @@ -44,7 +46,7 @@ void usage(void) int i=0; puts("Copyright 2011-2015 MariaDB Corporation AB"); puts("Get compiler flags for using the MariaDB Connector/C."); - printf("Usage: %s [OPTIONS]\n", ma_progname); + printf("Usage: %s [OPTIONS]\n", mariadb_progname); while (long_options[i].name) { if (values[i]) @@ -57,7 +59,7 @@ void usage(void) int main(int argc, char **argv) { int c; - ma_progname= argv[0]; + mariadb_progname= argv[0]; if (argc <= 1) { diff --git a/plugins/auth/auth_gssapi_client.c b/plugins/auth/auth_gssapi_client.c index d0ed3795..4e0b57b6 100644 --- a/plugins/auth/auth_gssapi_client.c +++ b/plugins/auth/auth_gssapi_client.c @@ -33,9 +33,9 @@ POSSIBILITY OF SUCH DAMAGE. */ #include #include -#include +#include #include -#include +#include #include #include #include diff --git a/plugins/auth/dialog.c b/plugins/auth/dialog.c index 4ace14fc..1d51086c 100644 --- a/plugins/auth/dialog.c +++ b/plugins/auth/dialog.c @@ -20,7 +20,7 @@ #define _GNU_SOURCE 1 #endif -#include +#include #include #include #include diff --git a/plugins/auth/gssapi_client.c b/plugins/auth/gssapi_client.c index a05ea158..8b264c51 100644 --- a/plugins/auth/gssapi_client.c +++ b/plugins/auth/gssapi_client.c @@ -30,7 +30,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include +#include #include #include "gssapi_errmsg.h" diff --git a/plugins/auth/mariadb_cleartext.c b/plugins/auth/mariadb_cleartext.c index c0ff220a..abe41fbd 100644 --- a/plugins/auth/mariadb_cleartext.c +++ b/plugins/auth/mariadb_cleartext.c @@ -16,7 +16,7 @@ or write to the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor, Boston, MA 02110, USA *************************************************************************************/ -#include +#include #include #include #include diff --git a/plugins/auth/my_auth.c b/plugins/auth/my_auth.c index 640d705b..dbac8cc0 100644 --- a/plugins/auth/my_auth.c +++ b/plugins/auth/my_auth.c @@ -1,7 +1,7 @@ -#include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -211,7 +211,7 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, int4store(buff,mysql->client_flag); int4store(buff+4, net->max_packet_size); buff[8]= (char) mysql->charset->nr; - bzero(buff + 9, 32-9); + memset(buff + 9, 0, 32-9); if (!(mysql->server_capabilities & CLIENT_MYSQL)) { mysql->client_flag |= MARIADB_CLIENT_SUPPORTED_FLAGS; @@ -258,10 +258,6 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, } #endif /* HAVE_SSL */ - DBUG_PRINT("info",("Server version = '%s' capabilites: %lu status: %u client_flag: %lu", - mysql->server_version, mysql->server_capabilities, - mysql->server_status, mysql->client_flag)); - /* This needs to be changed as it's not useful with big packets */ if (mysql->user[0]) strncpy(end, mysql->user, USERNAME_LENGTH); @@ -269,8 +265,7 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, read_user_name(end); /* We have to handle different version of handshake here */ - DBUG_PRINT("info",("user: %s",end)); - end= strend(end) + 1; + end= strchr(end, '\0') + 1; if (data_len) { if (mysql->server_capabilities & CLIENT_SECURE_CONNECTION) @@ -424,7 +419,7 @@ static int client_mpvio_write_packet(struct st_plugin_vio *mpv, void mpvio_info(MARIADB_PVIO *pvio, MYSQL_PLUGIN_VIO_INFO *info) { - bzero(info, sizeof(*info)); + memset(info, 0, sizeof(*info)); switch (pvio->type) { case PVIO_TYPE_SOCKET: info->protocol= MYSQL_VIO_TCP; diff --git a/plugins/auth/old_password.c b/plugins/auth/old_password.c index 7836cec1..5eb5f630 100644 --- a/plugins/auth/old_password.c +++ b/plugins/auth/old_password.c @@ -16,12 +16,12 @@ or write to the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor, Boston, MA 02110, USA *************************************************************************************/ -#include +#include #include #include #include #include -#include +#include /* function prototypes */ diff --git a/plugins/auth/sspi_client.c b/plugins/auth/sspi_client.c index 41461297..6308b31d 100644 --- a/plugins/auth/sspi_client.c +++ b/plugins/auth/sspi_client.c @@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include +#include #include "sspi_common.h" diff --git a/plugins/connection/aurora.c b/plugins/connection/aurora.c index 32fbfe31..9b2c0058 100644 --- a/plugins/connection/aurora.c +++ b/plugins/connection/aurora.c @@ -22,14 +22,14 @@ /* MariaDB Connection plugin for Aurora failover */ -#include -#include -#include +#include +#include +#include #include #include #include #include -#include +#include #ifndef WIN32 #include @@ -172,8 +172,8 @@ my_bool aurora_parse_url(const char *url, AURORA *aurora) if (!url || url[0] == 0) return 1; - bzero(aurora->instance, (AURORA_MAX_INSTANCES + 1) * sizeof(char *)); - bzero(&aurora->port, (AURORA_MAX_INSTANCES + 1) * sizeof(int)); + memset(aurora->instance, 0, (AURORA_MAX_INSTANCES + 1) * sizeof(char *)); + memset(&aurora->port, 0, (AURORA_MAX_INSTANCES + 1) * sizeof(int)); if (aurora->url) free(aurora->url); diff --git a/plugins/connection/replication.c b/plugins/connection/replication.c index 6bb74cef..e0369527 100644 --- a/plugins/connection/replication.c +++ b/plugins/connection/replication.c @@ -22,13 +22,13 @@ /* MariaDB Connection plugin for load balancing */ -#include -#include -#include +#include +#include +#include #include #include #include -#include +#include #ifndef WIN32 #include @@ -108,8 +108,8 @@ my_bool repl_parse_url(const char *url, REPL_DATA *data) if (!url || url[0] == 0) return 1; - bzero(slaves, 64 * sizeof(char *)); - bzero(&port, 64 * sizeof(int)); + memset(slaves, 0, 64 * sizeof(char *)); + memset(&port, 0, 64 * sizeof(int)); memset(data->host, 0, 2 * sizeof(char *)); memset(data->port, 0, 2 * sizeof(int)); diff --git a/plugins/io/remote_io.c b/plugins/io/remote_io.c index 411aa3c5..4604c12e 100644 --- a/plugins/io/remote_io.c +++ b/plugins/io/remote_io.c @@ -43,8 +43,8 @@ smb:// */ -#include -#include +#include +#include #include #include #include diff --git a/plugins/pvio/pvio_npipe.c b/plugins/pvio/pvio_npipe.c index 623f6ba9..af849532 100644 --- a/plugins/pvio/pvio_npipe.c +++ b/plugins/pvio/pvio_npipe.c @@ -22,13 +22,13 @@ #ifdef _WIN32 -#include -#include -#include +#include +#include +#include #include #include #include -#include +#include /* Function prototypes */ my_bool pvio_npipe_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout); @@ -223,7 +223,7 @@ my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0, ""); return 1; } - bzero(cpipe, sizeof(struct st_pvio_npipe)); + memset(cpipe, 0, sizeof(struct st_pvio_npipe)); pvio->data= (void *)cpipe; cpipe->pipe= INVALID_HANDLE_VALUE; pvio->mysql= cinfo->mysql; diff --git a/plugins/pvio/pvio_shmem.c b/plugins/pvio/pvio_shmem.c index 218c88f2..a8546d87 100644 --- a/plugins/pvio/pvio_shmem.c +++ b/plugins/pvio/pvio_shmem.c @@ -21,13 +21,13 @@ #ifdef _WIN32 -#include -#include -#include +#include +#include +#include #include #include #include -#include +#include #define SHM_DEFAULT_NAME "MYSQL" #define PVIO_SHM_BUFFER_SIZE 16000 + 4 diff --git a/plugins/pvio/pvio_socket.c b/plugins/pvio/pvio_socket.c index 5ce73a11..7eac1af3 100644 --- a/plugins/pvio/pvio_socket.c +++ b/plugins/pvio/pvio_socket.c @@ -24,16 +24,17 @@ default and compiled into Connector/C. */ -#include -#include -#include +#include +#include +#include #include #include -#include -#include +#ifdef HAVE_NONBLOCK +#include +#include +#endif #include #include -#include #ifndef _WIN32 #ifdef HAVE_SYS_UN_H #include @@ -64,9 +65,11 @@ my_bool pvio_socket_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout); int pvio_socket_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type); size_t pvio_socket_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length); +#ifdef HAVE_NONBLOCK size_t pvio_socket_async_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length); -size_t pvio_socket_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length); size_t pvio_socket_async_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length); +#endif +size_t pvio_socket_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length); int pvio_socket_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout); my_bool pvio_socket_blocking(MARIADB_PVIO *pvio, my_bool value, my_bool *old_value); my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo); @@ -88,9 +91,17 @@ struct st_ma_pvio_methods pvio_socket_methods= { pvio_socket_set_timeout, pvio_socket_get_timeout, pvio_socket_read, +#ifdef HAVE_NONBLOCK pvio_socket_async_read, +#else + NULL, +#endif pvio_socket_write, +#ifdef HAVE_NONBLOCK pvio_socket_async_write, +#else + NULL, +#endif pvio_socket_wait_io_or_timeout, pvio_socket_blocking, pvio_socket_connect, @@ -275,6 +286,7 @@ size_t pvio_socket_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length) } /* }}} */ +#ifdef HAVE_NONBLOCK /* {{{ pvio_socket_async_read */ /* read from socket @@ -372,7 +384,7 @@ size_t pvio_socket_async_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t l return r; } /* }}} */ - +#endif /* {{{ pvio_socket_write */ /* @@ -666,6 +678,7 @@ static int pvio_socket_connect_sync_or_async(MARIADB_PVIO *pvio, const struct sockaddr *name, uint namelen) { +#ifdef HAVE_NONBLOCK MYSQL *mysql= pvio->mysql; if (mysql->options.extension && mysql->options.extension->async_context && mysql->options.extension->async_context->active) @@ -676,6 +689,7 @@ pvio_socket_connect_sync_or_async(MARIADB_PVIO *pvio, pvio_socket_blocking(pvio, 0, 0); return my_connect_async(pvio, name, namelen, pvio->timeout[PVIO_CONNECT_TIMEOUT]); } +#endif return pvio_socket_internal_connect(pvio, name, namelen); } @@ -707,9 +721,9 @@ my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) PVIO_SET_ERROR(cinfo->mysql, CR_SOCKET_CREATE_ERROR, unknown_sqlstate, 0, errno); goto error; } - bzero((char*) &UNIXaddr,sizeof(UNIXaddr)); + memset((char*) &UNIXaddr, 0, sizeof(UNIXaddr)); UNIXaddr.sun_family = AF_UNIX; - strmov(UNIXaddr.sun_path, cinfo->unix_socket); + strcpy(UNIXaddr.sun_path, cinfo->unix_socket); if (pvio_socket_connect_sync_or_async(pvio, (struct sockaddr *) &UNIXaddr, sizeof(UNIXaddr))) { @@ -732,11 +746,11 @@ my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) int gai_rc; int rc= 0; - bzero(&server_port, NI_MAXSERV); + memset(&server_port, 0, NI_MAXSERV); snprintf(server_port, NI_MAXSERV, "%d", cinfo->port); /* set hints for getaddrinfo */ - bzero(&hints, sizeof(hints)); + memset(&hints, 0, sizeof(hints)); hints.ai_protocol= IPPROTO_TCP; /* TCP connections only */ hints.ai_family= AF_UNSPEC; /* includes: IPv4, IPv6 or hostname */ hints.ai_socktype= SOCK_STREAM; @@ -792,10 +806,12 @@ my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) rc= pvio_socket_connect_sync_or_async(pvio, save_res->ai_addr, (uint)save_res->ai_addrlen); if (!rc) { +#ifdef HAVE_NONBLOCK MYSQL *mysql= pvio->mysql; if (mysql->options.extension && mysql->options.extension->async_context && mysql->options.extension->async_context->active) break; +#endif if (pvio_socket_blocking(pvio, 0, 0) == SOCKET_ERROR) { closesocket(csock->socket); diff --git a/plugins/trace/trace_example.c b/plugins/trace/trace_example.c index b53428e4..4993fbb2 100644 --- a/plugins/trace/trace_example.c +++ b/plugins/trace/trace_example.c @@ -20,7 +20,7 @@ #define _GNU_SOURCE 1 #endif -#include +#include #include #include #include diff --git a/unittest/libmariadb/CMakeLists.txt b/unittest/libmariadb/CMakeLists.txt index 450f892c..5f95da0c 100644 --- a/unittest/libmariadb/CMakeLists.txt +++ b/unittest/libmariadb/CMakeLists.txt @@ -21,36 +21,44 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/unittest/mytap) ADD_DEFINITIONS(-DLIBMARIADB) -SET(API_TESTS "async" "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs" - "sp" "result" "connection" "misc" "ps_new" "sqlite3" "thread" "dyncol" "features-10_2" ) +SET(API_TESTS "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs" + "sp" "result" "connection" "misc" "ps_new" "sqlite3" "thread" "features-10_2" ) +IF(WITH_DYNCOL) + SET(API_TESTS ${API_TESTS} "dyncol") +ENDIF() + +IF(WITH_NONBLCK) + SET(API_TESTS ${API_TESTS} "async") +ENDIF() #exclude following tests from ctests, since we need to run them maually with different credentials SET(MANUAL_TESTS "t_aurora") # Get finger print from server certificate -IF(WITH_SSL AND OPENSSL_FOUND) - - #create certificates - IF(EXISTS "${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs/server-cert.pem") - MESSAGE(STATUS "certificates already exist") - ELSE() - MESSAGE(STATUS "creating certificates") - IF(WIN32) - EXECUTE_PROCESS(COMMAND create_certs.bat - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs - OUTPUT_FILE x.1 ERROR_FILE x.2) +IF(WITH_SSL) + IF(OPENSSL_FOUND) + #create certificates + IF(EXISTS "${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs/server-cert.pem") + MESSAGE(STATUS "certificates already exist") ELSE() - EXECUTE_PROCESS(COMMAND ./create_certs.sh - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs) + MESSAGE(STATUS "creating certificates") + IF(WIN32) + EXECUTE_PROCESS(COMMAND create_certs.bat + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs + OUTPUT_FILE x.1 ERROR_FILE x.2) + ELSE() + EXECUTE_PROCESS(COMMAND ./create_certs.sh + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs) + ENDIF() ENDIF() + + EXECUTE_PROCESS(COMMAND openssl x509 -in server-cert.pem -sha1 -fingerprint -noout + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs + OUTPUT_VARIABLE FINGER_PRINT) + STRING(REPLACE "SHA1 Fingerprint=" "" FINGER_PRINT "${FINGER_PRINT}") + STRING(REPLACE "\n" "" FINGER_PRINT "${FINGER_PRINT}") + STRING(REPLACE ":" "" SSL_CERT_FINGER_PRINT "${FINGER_PRINT}") + ENDIF() - - EXECUTE_PROCESS(COMMAND openssl x509 -in server-cert.pem -sha1 -fingerprint -noout - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs - OUTPUT_VARIABLE FINGER_PRINT) - STRING(REPLACE "SHA1 Fingerprint=" "" FINGER_PRINT "${FINGER_PRINT}") - STRING(REPLACE "\n" "" FINGER_PRINT "${FINGER_PRINT}") - STRING(REPLACE ":" "" SSL_CERT_FINGER_PRINT "${FINGER_PRINT}") - CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/unittest/libmariadb/ssl.c.in ${CMAKE_SOURCE_DIR}/unittest/libmariadb/ssl.c) CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/unittest/libmariadb/fingerprint.list.in @@ -59,13 +67,13 @@ IF(WITH_SSL AND OPENSSL_FOUND) ENDIF() FOREACH(API_TEST ${API_TESTS}) - ADD_EXECUTABLE(${API_TEST} ${API_TEST}.c ${CMAKE_SOURCE_DIR}/libmariadb/getopt.c) + ADD_EXECUTABLE(${API_TEST} ${API_TEST}.c ma_getopt.c) TARGET_LINK_LIBRARIES(${API_TEST} mytap libmariadb) ADD_TEST(${API_TEST} ${EXECUTABLE_OUTPUT_PATH}/${API_TEST}) SET_TESTS_PROPERTIES(${API_TEST} PROPERTIES TIMEOUT 120) ENDFOREACH(API_TEST) FOREACH(API_TEST ${MANUAL_TESTS}) - ADD_EXECUTABLE(${API_TEST} ${API_TEST}.c ${CMAKE_SOURCE_DIR}/libmariadb/getopt.c) + ADD_EXECUTABLE(${API_TEST} ${API_TEST}.c getopt.c) TARGET_LINK_LIBRARIES(${API_TEST} mytap libmariadb) ENDFOREACH() diff --git a/unittest/libmariadb/charset.c b/unittest/libmariadb/charset.c index f84bcc49..8a11f09e 100644 --- a/unittest/libmariadb/charset.c +++ b/unittest/libmariadb/charset.c @@ -658,7 +658,6 @@ static int test_bug_54100(MYSQL *mysql) /* We need this internal function for the test */ -MARIADB_CHARSET_INFO * mysql_find_charset_name(const char *name); static int test_utf16_utf32_noboms(MYSQL *mysql) { @@ -713,6 +712,7 @@ static int test_utf16_utf32_noboms(MYSQL *mysql) rc= mariadb_convert_string(in_string[UTF8], &in_len, csinfo[UTF8], buffer, &out_len, csinfo[i], &error); FAIL_IF(rc==-1, "Conversion failed"); + diag("rc=%d oct_len: %d", rc, in_oct_len[i]); FAIL_IF(rc != in_oct_len[i], "Incorrect number of written bytes"); if (memcmp(buffer, in_string[i], rc) != 0) diff --git a/unittest/libmariadb/connection.c b/unittest/libmariadb/connection.c index fe1f220b..a4e36341 100644 --- a/unittest/libmariadb/connection.c +++ b/unittest/libmariadb/connection.c @@ -37,16 +37,20 @@ static int test_conc66(MYSQL *my) if (!(fp= fopen("./my.cnf", "w"))) return FAIL; + fprintf(fp, "[notmygroup]\n"); + fprintf(fp, "user=foo\n"); fprintf(fp, "[conc-66]\n"); fprintf(fp, "user=conc66\n"); + fprintf(fp, "port=3306\n"); + fprintf(fp, "enable-local-infile\n"); fprintf(fp, "password='test\\\";#test'\n"); fclose(fp); rc= mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "conc-66"); check_mysql_rc(rc, mysql); - rc= mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "./my.cnf"); - check_mysql_rc(rc, mysql); +// rc= mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "./my.cnf"); +// check_mysql_rc(rc, mysql); sprintf(query, "GRANT ALL ON %s.* TO 'conc66'@'%s' IDENTIFIED BY 'test\";#test'", schema, hostname); rc= mysql_query(my, query); diff --git a/unittest/libmariadb/dyncol.c b/unittest/libmariadb/dyncol.c index 185b034d..20e6d0c4 100644 --- a/unittest/libmariadb/dyncol.c +++ b/unittest/libmariadb/dyncol.c @@ -16,7 +16,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "my_test.h" -#include "ma_dyncol.h" +#include "mariadb_dyncol.h" static int create_dyncol_named(MYSQL *mysql) { diff --git a/libmariadb/getopt.c b/unittest/libmariadb/getopt.c similarity index 99% rename from libmariadb/getopt.c rename to unittest/libmariadb/getopt.c index cbec6678..411f4ba7 100644 --- a/libmariadb/getopt.c +++ b/unittest/libmariadb/getopt.c @@ -46,8 +46,8 @@ Cambridge, MA 02139, USA. */ #endif #endif -#include /* Changes for mysys */ -#include +#include /* Changes for mysys */ +#include /* Comment out all this code if we are using the GNU C Library, and are not actually compiling the library itself. This code is part of the GNU C @@ -82,7 +82,7 @@ Cambridge, MA 02139, USA. */ GNU application programs can use a third alternative mode in which they can distinguish the relative order of options and other arguments. */ -#include "getopt.h" +#include "ma_getopt.h" /* For communication from `getopt' to the caller. When `getopt' finds an option that takes an argument, @@ -658,12 +658,8 @@ _getopt_internal (int argc, char *const *argv, const char *optstring, const stru } } -#ifdef __EMX__ -int getopt (int argc, char **argv, __const__ char *optstring) -#else int getopt (int argc, char *const *argv, const char *optstring) -#endif { return _getopt_internal (argc, argv, optstring, (const struct option *) 0, diff --git a/unittest/libmariadb/ma_getopt.c b/unittest/libmariadb/ma_getopt.c new file mode 100644 index 00000000..411f4ba7 --- /dev/null +++ b/unittest/libmariadb/ma_getopt.c @@ -0,0 +1,742 @@ +/* Getopt for GNU. + NOTE: getopt is now part of the C library, so if you don't know what + "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu + before changing it! + + Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94 + Free Software Foundation, Inc. + +Changes by monty: +- Added include of string.h when nessessary. +- Removed two warnings from gcc. + +This file is part of the GNU C Library. Its master source is NOT part of +the C library, however. The master source lives in /gd/gnu/lib. + +The GNU C 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. + +The GNU C 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 the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +/* This tells Alpha OSF/1 not to define a getopt prototype in . + Ditto for AIX 3.2 and . */ +#ifndef _NO_PROTO +#define _NO_PROTO +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + +#if (!defined (__STDC__) || !__STDC__) && !defined(MSDOS) && !defined(OS2) +/* This is a separate conditional since some stdc systems + reject `defined (const)'. */ +#ifndef const +#define const +#endif +#endif + +#include /* Changes for mysys */ +#include + +/* Comment out all this code if we are using the GNU C Library, and are not + actually compiling the library itself. This code is part of the GNU C + Library, but also included in many other GNU distributions. Compiling + and linking in this code is a waste when using the GNU C library + (especially if it is a shared library). Rather than having every GNU + program understand `configure --with-gnu-libc' and omit the object files, + it is simpler to just do this in the source for each such file. */ + +#if defined (_LIBC) || !defined (__GNU_LIBRARY__) + + +/* This needs to come after some library #include + to get __GNU_LIBRARY__ defined. */ +#ifdef __GNU_LIBRARY__ +/* Don't include stdlib.h for non-GNU C libraries because some of them + contain conflicting prototypes for getopt. */ +#include +#endif /* GNU C library. */ + +/* This version of `getopt' appears to the caller like standard Unix `getopt' + but it behaves differently for the user, since it allows the user + to intersperse the options with the other arguments. + + As `getopt' works, it permutes the elements of ARGV so that, + when it is done, all the options precede everything else. Thus + all application programs are extended to handle flexible argument order. + + Setting the environment variable POSIXLY_CORRECT disables permutation. + Then the behavior is completely standard. + + GNU application programs can use a third alternative mode in which + they can distinguish the relative order of options and other arguments. */ + +#include "ma_getopt.h" + +/* For communication from `getopt' to the caller. + When `getopt' finds an option that takes an argument, + the argument value is returned here. + Also, when `ordering' is RETURN_IN_ORDER, + each non-option ARGV-element is returned here. */ + +char *optarg = NULL; + +/* Index in ARGV of the next element to be scanned. + This is used for communication to and from the caller + and for communication between successive calls to `getopt'. + + On entry to `getopt', zero means this is the first call; initialize. + + When `getopt' returns EOF, this is the index of the first of the + non-option elements that the caller should itself scan. + + Otherwise, `optind' communicates from one call to the next + how much of ARGV has been scanned so far. */ + +/* XXX 1003.2 says this must be 1 before any call. */ +int optind = 1; + +/* The next char to be scanned in the option-element + in which the last option character we returned was found. + This allows us to pick up the scan where we left off. + + If this is zero, or a null string, it means resume the scan + by advancing to the next ARGV-element. */ + +static char *nextchar; + +/* Callers store zero here to inhibit the error message + for unrecognized options. */ + +int opterr = 1; + +/* Set to an option character which was unrecognized. + This must be initialized on some systems to avoid linking in the + system's own getopt implementation. */ + +int optopt = '?'; + +/* Describe how to deal with options that follow non-option ARGV-elements. + + If the caller did not specify anything, + the default is REQUIRE_ORDER if the environment variable + POSIXLY_CORRECT is defined, PERMUTE otherwise. + + REQUIRE_ORDER means don't recognize them as options; + stop option processing when the first non-option is seen. + This is what Unix does. + This mode of operation is selected by either setting the environment + variable POSIXLY_CORRECT, or using `+' as the first character + of the list of option characters. + + PERMUTE is the default. We permute the contents of ARGV as we scan, + so that eventually all the non-options are at the end. This allows options + to be given in any order, even with programs that were not written to + expect this. + + RETURN_IN_ORDER is an option available to programs that were written + to expect options and other ARGV-elements in any order and that care about + the ordering of the two. We describe each non-option ARGV-element + as if it were the argument of an option with character code 1. + Using `-' as the first character of the list of option characters + selects this mode of operation. + + The special argument `--' forces an end of option-scanning regardless + of the value of `ordering'. In the case of RETURN_IN_ORDER, only + `--' can cause `getopt' to return EOF with `optind' != ARGC. */ + +static enum +{ + REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER +} ordering; + +/* Value of POSIXLY_CORRECT environment variable. */ +static char *posixly_correct; + +#ifdef __GNU_LIBRARY__ +/* We want to avoid inclusion of string.h with non-GNU libraries + because there are many ways it can cause trouble. + On some systems, it contains special magic macros that don't work + in GCC. */ +#include +#define my_index strchr +#else + +/* Avoid depending on library functions or files + whose names are inconsistent. */ + +static char * +my_index (const char *str, int chr) +{ + while (*str) + { + if (*str == chr) + return (char *) str; + str++; + } + return 0; +} + +/* If using GCC, we can safely declare strlen this way. + If not using GCC, it is ok not to declare it. */ +#ifdef __GNUC__ +/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. + That was relevant to code that was here before. */ +#if !defined (__STDC__) || !__STDC__ +/* gcc with -traditional declares the built-in strlen to return int, + and has done so at least since version 2.4.5. -- rms. */ +extern int strlen (const char *); +#endif /* not __STDC__ */ +#endif /* __GNUC__ */ + +#endif /* not __GNU_LIBRARY__ */ + +/* Handle permutation of arguments. */ + +/* Describe the part of ARGV that contains non-options that have + been skipped. `first_nonopt' is the index in ARGV of the first of them; + `last_nonopt' is the index after the last of them. */ + +static int first_nonopt; +static int last_nonopt; + +/* Exchange two adjacent subsequences of ARGV. + One subsequence is elements [first_nonopt,last_nonopt) + which contains all the non-options that have been skipped so far. + The other is elements [last_nonopt,optind), which contains all + the options processed since those non-options were skipped. + + `first_nonopt' and `last_nonopt' are relocated so that they describe + the new indices of the non-options in ARGV after they are moved. */ + +static void +exchange (char **argv) +{ + int bottom = first_nonopt; + int middle = last_nonopt; + int top = optind; + char *tem; + + /* Exchange the shorter segment with the far end of the longer segment. + That puts the shorter segment into the right place. + It leaves the longer segment in the right place overall, + but it consists of two parts that need to be swapped next. */ + + while (top > middle && middle > bottom) + { + if (top - middle > middle - bottom) + { + /* Bottom segment is the short one. */ + int len = middle - bottom; + register int i; + + /* Swap it with the top part of the top segment. */ + for (i = 0; i < len; i++) + { + tem = argv[bottom + i]; + argv[bottom + i] = argv[top - (middle - bottom) + i]; + argv[top - (middle - bottom) + i] = tem; + } + /* Exclude the moved bottom segment from further swapping. */ + top -= len; + } + else + { + /* Top segment is the short one. */ + int len = top - middle; + register int i; + + /* Swap it with the bottom part of the bottom segment. */ + for (i = 0; i < len; i++) + { + tem = argv[bottom + i]; + argv[bottom + i] = argv[middle + i]; + argv[middle + i] = tem; + } + /* Exclude the moved top segment from further swapping. */ + bottom += len; + } + } + + /* Update records for the slots the non-options now occupy. */ + + first_nonopt += (optind - last_nonopt); + last_nonopt = optind; +} + +/* Initialize the internal data when the first call is made. */ + +static const char * +_getopt_initialize (const char *optstring) +{ + /* Start processing options with ARGV-element 1 (since ARGV-element 0 + is the program name); the sequence of previously skipped + non-option ARGV-elements is empty. */ + + first_nonopt = last_nonopt = optind = 1; + + nextchar = NULL; + + posixly_correct = getenv ("POSIXLY_CORRECT"); + + /* Determine how to handle the ordering of options and nonoptions. */ + + if (optstring[0] == '-') + { + ordering = RETURN_IN_ORDER; + ++optstring; + } + else if (optstring[0] == '+') + { + ordering = REQUIRE_ORDER; + ++optstring; + } + else if (posixly_correct != NULL) + ordering = REQUIRE_ORDER; + else + ordering = PERMUTE; + + return optstring; +} + +/* Scan elements of ARGV (whose length is ARGC) for option characters + given in OPTSTRING. + + If an element of ARGV starts with '-', and is not exactly "-" or "--", + then it is an option element. The characters of this element + (aside from the initial '-') are option characters. If `getopt' + is called repeatedly, it returns successively each of the option characters + from each of the option elements. + + If `getopt' finds another option character, it returns that character, + updating `optind' and `nextchar' so that the next call to `getopt' can + resume the scan with the following option character or ARGV-element. + + If there are no more option characters, `getopt' returns `EOF'. + Then `optind' is the index in ARGV of the first ARGV-element + that is not an option. (The ARGV-elements have been permuted + so that those that are not options now come last.) + + OPTSTRING is a string containing the legitimate option characters. + If an option character is seen that is not listed in OPTSTRING, + return '?' after printing an error message. If you set `opterr' to + zero, the error message is suppressed but we still return '?'. + + If a char in OPTSTRING is followed by a colon, that means it wants an arg, + so the following text in the same ARGV-element, or the text of the following + ARGV-element, is returned in `optarg'. Two colons mean an option that + wants an optional arg; if there is text in the current ARGV-element, + it is returned in `optarg', otherwise `optarg' is set to zero. + + If OPTSTRING starts with `-' or `+', it requests different methods of + handling the non-option ARGV-elements. + See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. + + Long-named options begin with `--' instead of `-'. + Their names may be abbreviated as long as the abbreviation is unique + or is an exact match for some defined option. If they have an + argument, it follows the option name in the same ARGV-element, separated + from the option name by a `=', or else the in next ARGV-element. + When `getopt' finds a long-named option, it returns 0 if that option's + `flag' field is nonzero, the value of the option's `val' field + if the `flag' field is zero. + + The elements of ARGV aren't really const, because we permute them. + But we pretend they're const in the prototype to be compatible + with other systems. + + LONGOPTS is a vector of `struct option' terminated by an + element containing a name which is zero. + + LONGIND returns the index in LONGOPT of the long-named option found. + It is only valid when a long-named option has been found by the most + recent call. + + If LONG_ONLY is nonzero, '-' as well as '--' can introduce + long-named options. */ + +int +_getopt_internal (int argc, char *const *argv, const char *optstring, const struct option *longopts, int *longind, int long_only) +{ + optarg = NULL; + + if (optind == 0) + optstring = _getopt_initialize (optstring); + + if (nextchar == NULL || *nextchar == '\0') + { + /* Advance to the next ARGV-element. */ + + if (ordering == PERMUTE) + { + /* If we have just processed some options following some non-options, + exchange them so that the options come first. */ + + if (first_nonopt != last_nonopt && last_nonopt != optind) + exchange ((char **) argv); + else if (last_nonopt != optind) + first_nonopt = optind; + + /* Skip any additional non-options + and extend the range of non-options previously skipped. */ + + while (optind < argc + && (argv[optind][0] != '-' || argv[optind][1] == '\0')) + optind++; + last_nonopt = optind; + } + + /* The special ARGV-element `--' means premature end of options. + Skip it like a null option, + then exchange with previous non-options as if it were an option, + then skip everything else like a non-option. */ + + if (optind != argc && !strcmp (argv[optind], "--")) + { + optind++; + + if (first_nonopt != last_nonopt && last_nonopt != optind) + exchange ((char **) argv); + else if (first_nonopt == last_nonopt) + first_nonopt = optind; + last_nonopt = argc; + + optind = argc; + } + + /* If we have done all the ARGV-elements, stop the scan + and back over any non-options that we skipped and permuted. */ + + if (optind == argc) + { + /* Set the next-arg-index to point at the non-options + that we previously skipped, so the caller will digest them. */ + if (first_nonopt != last_nonopt) + optind = first_nonopt; + return EOF; + } + + /* If we have come to a non-option and did not permute it, + either stop the scan or describe it to the caller and pass it by. */ + + if ((argv[optind][0] != '-' || argv[optind][1] == '\0')) + { + if (ordering == REQUIRE_ORDER) + return EOF; + optarg = argv[optind++]; + return 1; + } + + /* We have found another option-ARGV-element. + Skip the initial punctuation. */ + + nextchar = (argv[optind] + 1 + + (longopts != NULL && argv[optind][1] == '-')); + } + + /* Decode the current option-ARGV-element. */ + + /* Check whether the ARGV-element is a long option. + + If long_only and the ARGV-element has the form "-f", where f is + a valid short option, don't consider it an abbreviated form of + a long option that starts with f. Otherwise there would be no + way to give the -f short option. + + On the other hand, if there's a long option "fubar" and + the ARGV-element is "-fu", do consider that an abbreviation of + the long option, just like "--fu", and not "-f" with arg "u". + + This distinction seems to be the most useful approach. */ + + if (longopts != NULL + && (argv[optind][1] == '-' + || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) + { + char *nameend; + const struct option *p; + const struct option *pfound = NULL; + int exact = 0; + int ambig = 0; + int indfound=0; /* Keep gcc happy */ + int option_index; + + for (nameend = nextchar; *nameend && *nameend != '='; nameend++) + /* Do nothing. */ ; + + /* Test all long options for either exact match + or abbreviated matches. */ + for (p = longopts, option_index = 0; p->name; p++, option_index++) + if (!strncmp (p->name, nextchar, nameend - nextchar)) + { + if ((size_t) (nameend - nextchar) == (size_t) strlen (p->name)) + { + /* Exact match found. */ + pfound = p; + indfound = option_index; + exact = 1; + break; + } + else if (pfound == NULL) + { + /* First nonexact match found. */ + pfound = p; + indfound = option_index; + } + else + /* Second or later nonexact match found. */ + ambig = 1; + } + + if (ambig && !exact) + { + if (opterr) + fprintf (stderr, "%s: option `%s' is ambiguous\n", + argv[0], argv[optind]); + nextchar += strlen (nextchar); + optind++; + return '?'; + } + + if (pfound != NULL) + { + option_index = indfound; + optind++; + if (*nameend) + { + /* Don't test has_arg with >, because some C compilers don't + allow it to be used on enums. */ + if (pfound->has_arg) + optarg = nameend + 1; + else + { + if (opterr) + { + if (argv[optind - 1][1] == '-') + /* --option */ + fprintf (stderr, + "%s: option `--%s' doesn't allow an argument\n", + argv[0], pfound->name); + else + /* +option or -option */ + fprintf (stderr, + "%s: option `%c%s' doesn't allow an argument\n", + argv[0], argv[optind - 1][0], pfound->name); + } + nextchar += strlen (nextchar); + return '?'; + } + } + else if (pfound->has_arg == 1) + { + if (optind < argc) + optarg = argv[optind++]; + else + { + if (opterr) + fprintf (stderr, "%s: option `%s' requires an argument\n", + argv[0], argv[optind - 1]); + nextchar += strlen (nextchar); + return optstring[0] == ':' ? ':' : '?'; + } + } + nextchar += strlen (nextchar); + if (longind != NULL) + *longind = option_index; + if (pfound->flag) + { + *(pfound->flag) = pfound->val; + return 0; + } + return pfound->val; + } + + /* Can't find it as a long option. If this is not getopt_long_only, + or the option starts with '--' or is not a valid short + option, then it's an error. + Otherwise interpret it as a short option. */ + if (!long_only || argv[optind][1] == '-' + || my_index (optstring, *nextchar) == NULL) + { + if (opterr) + { + if (argv[optind][1] == '-') + /* --option */ + fprintf (stderr, "%s: unrecognized option `--%s'\n", + argv[0], nextchar); + else + /* +option or -option */ + fprintf (stderr, "%s: unrecognized option `%c%s'\n", + argv[0], argv[optind][0], nextchar); + } + nextchar = (char *) ""; + optind++; + return '?'; + } + } + + /* Look at and handle the next short option-character. */ + + { + char c = *nextchar++; + char *temp = my_index (optstring, c); + + /* Increment `optind' when we start to process its last character. */ + if (*nextchar == '\0') + ++optind; + + if (temp == NULL || c == ':') + { + if (opterr) + { + if (posixly_correct) + /* 1003.2 specifies the format of this message. */ + fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c); + else + fprintf (stderr, "%s: invalid option -- %c\n", argv[0], c); + } + optopt = c; + return '?'; + } + if (temp[1] == ':') + { + if (temp[2] == ':') + { + /* This is an option that accepts an argument optionally. */ + if (*nextchar != '\0') + { + optarg = nextchar; + optind++; + } + else + optarg = NULL; + nextchar = NULL; + } + else + { + /* This is an option that requires an argument. */ + if (*nextchar != '\0') + { + optarg = nextchar; + /* If we end this ARGV-element by taking the rest as an arg, + we must advance to the next element now. */ + optind++; + } + else if (optind == argc) + { + if (opterr) + { + /* 1003.2 specifies the format of this message. */ + fprintf (stderr, "%s: option requires an argument -- %c\n", + argv[0], c); + } + optopt = c; + if (optstring[0] == ':') + c = ':'; + else + c = '?'; + } + else + /* We already incremented `optind' once; + increment it again when taking next ARGV-elt as argument. */ + optarg = argv[optind++]; + nextchar = NULL; + } + } + return c; + } +} + +int +getopt (int argc, char *const *argv, const char *optstring) +{ + return _getopt_internal (argc, argv, optstring, + (const struct option *) 0, + (int *) 0, + 0); +} + +#endif /* _LIBC or not __GNU_LIBRARY__. */ + +#ifdef TEST + +/* Compile with -DTEST to make an executable for use in testing + the above definition of `getopt'. */ + +int +main (argc, argv) + int argc; + char **argv; +{ + int c; + int digit_optind = 0; + + while (1) + { + int this_option_optind = optind ? optind : 1; + + c = getopt (argc, argv, "abc:d:0123456789"); + if (c == EOF) + break; + + switch (c) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if (digit_optind != 0 && digit_optind != this_option_optind) + printf ("digits occur in two different argv-elements.\n"); + digit_optind = this_option_optind; + printf ("option %c\n", c); + break; + + case 'a': + printf ("option a\n"); + break; + + case 'b': + printf ("option b\n"); + break; + + case 'c': + printf ("option c with value `%s'\n", optarg); + break; + + case '?': + break; + + default: + printf ("?? getopt returned character code 0%o ??\n", c); + } + } + + if (optind < argc) + { + printf ("non-option ARGV-elements: "); + while (optind < argc) + printf ("%s ", argv[optind++]); + printf ("\n"); + } + + exit (0); +} + +#endif /* TEST */ diff --git a/include/getopt.h b/unittest/libmariadb/ma_getopt.h similarity index 100% rename from include/getopt.h rename to unittest/libmariadb/ma_getopt.h diff --git a/unittest/libmariadb/misc.c b/unittest/libmariadb/misc.c index 993141de..56153a5e 100644 --- a/unittest/libmariadb/misc.c +++ b/unittest/libmariadb/misc.c @@ -1085,7 +1085,35 @@ static int test_get_info(MYSQL *mysql) return OK; } +static int test_zerofill(MYSQL *mysql) +{ + int rc; + MYSQL_ROW row; + MYSQL_RES *res; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a int(10) zerofill)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SELECT a FROM t1"); + check_mysql_rc(rc, mysql); + + if (res= mysql_store_result(mysql)) + { + row= mysql_fetch_row(res); + diag("zerofill: %s", row[0]); + mysql_free_result(res); + } + return OK; +} + struct my_tests_st my_tests[] = { + {"test_zerofill", test_zerofill, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, #ifdef HAVE_REMOTEIO {"test_remote1", test_remote1, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_remote2", test_remote2, TEST_CONNECTION_NEW, 0, NULL, NULL}, diff --git a/unittest/libmariadb/my_test.h b/unittest/libmariadb/my_test.h index b8816a17..0c7cf366 100644 --- a/unittest/libmariadb/my_test.h +++ b/unittest/libmariadb/my_test.h @@ -21,13 +21,13 @@ 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 St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include -#include +#include +#include #include #include -#include +#include "ma_getopt.h" #include -#include +#include #ifndef WIN32 #include diff --git a/unittest/libmariadb/ssl.c.in b/unittest/libmariadb/ssl.c.in index 516097bf..11b1c7fc 100644 --- a/unittest/libmariadb/ssl.c.in +++ b/unittest/libmariadb/ssl.c.in @@ -18,7 +18,7 @@ *************************************************************************************/ #include "my_test.h" -#include +#include static int skip_ssl= 1; diff --git a/unittest/libmariadb/thread.c b/unittest/libmariadb/thread.c index 9761e363..0c658e75 100644 --- a/unittest/libmariadb/thread.c +++ b/unittest/libmariadb/thread.c @@ -2,6 +2,7 @@ */ #include "my_test.h" +#include static int basic_connect(MYSQL *mysql) { diff --git a/unittest/mytap/tap.c b/unittest/mytap/tap.c index 06233349..89bd2471 100644 --- a/unittest/mytap/tap.c +++ b/unittest/mytap/tap.c @@ -19,7 +19,7 @@ #include "tap.h" -#include "my_global.h" +#include "ma_global.h" #include #include diff --git a/unittest/mytap/tap.h b/unittest/mytap/tap.h index d8f617c8..2b4545cb 100644 --- a/unittest/mytap/tap.h +++ b/unittest/mytap/tap.h @@ -20,7 +20,7 @@ #ifndef TAP_H #define TAP_H -#include "my_global.h" +#include "ma_global.h" /* @defgroup MyTAP MySQL support for performing unit tests according to From 1d0402ae379fd5638c19cfab36fb84846883b8d4 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Mon, 8 Feb 2016 18:47:44 +0100 Subject: [PATCH 33/39] Added ma_pthread.h --- include/ma_pthread.h | 591 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 591 insertions(+) create mode 100644 include/ma_pthread.h diff --git a/include/ma_pthread.h b/include/ma_pthread.h new file mode 100644 index 00000000..74bd83ad --- /dev/null +++ b/include/ma_pthread.h @@ -0,0 +1,591 @@ +/* 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., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +/* Defines to make different thread packages compatible */ + +#ifndef _my_pthread_h +#define _my_pthread_h + +#include +#ifndef ETIME +#define ETIME ETIMEDOUT /* For FreeBSD */ +#endif + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#if defined(_WIN32) + +typedef CRITICAL_SECTION pthread_mutex_t; + +typedef HANDLE pthread_t; +typedef struct thread_attr { + DWORD dwStackSize ; + DWORD dwCreatingFlag ; + int priority ; +} pthread_attr_t ; + +typedef struct { int dummy; } pthread_condattr_t; + +/* Implementation of posix conditions */ + +typedef struct st_pthread_link { + DWORD thread_id; + struct st_pthread_link *next; +} pthread_link; + +typedef struct { + uint32 waiting; + + enum { + SIGNAL = 0, + BROADCAST = 1, + MAX_EVENTS = 2 + } EVENTS; + HANDLE events[MAX_EVENTS]; + CRITICAL_SECTION waiters_count_lock; +} pthread_cond_t; + +#ifndef _TIMESPEC_DEFINED +#if (!defined(_MSC_VER) || _MSC_VER < 1900) +struct timespec { /* For pthread_cond_timedwait() */ + time_t tv_sec; + long tv_nsec; +}; +#endif +#endif + +typedef int pthread_mutexattr_t; +#define pthread_self() GetCurrentThreadId() + +#define pthread_handler_decl(A,B) void * __cdecl A(void *B) +typedef void * (__cdecl *pthread_handler)(void *); + +void win_pthread_init(void); + +int pthread_create(pthread_t *,pthread_attr_t *,pthread_handler,void *); +int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr); +int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex); +int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, + struct timespec *abstime); +int pthread_cond_signal(pthread_cond_t *cond); +int pthread_cond_broadcast(pthread_cond_t *cond); +int pthread_cond_destroy(pthread_cond_t *cond); +int pthread_attr_init(pthread_attr_t *connect_att); +int pthread_attr_setstacksize(pthread_attr_t *connect_att,DWORD stack); +int pthread_attr_setprio(pthread_attr_t *connect_att,int priority); +int pthread_attr_destroy(pthread_attr_t *connect_att); +struct tm *localtime_r(const time_t *timep,struct tm *tmp); + +void pthread_exit(void *a); /* was #define pthread_exit(A) ExitThread(A)*/ + +#ifndef OS2 +#define getpid() GetCurrentThreadId() +#endif + +#define HAVE_LOCALTIME_R 1 +#define _REENTRANT 1 +#define HAVE_PTHREAD_ATTR_SETSTACKSIZE 1 + +#undef SAFE_MUTEX /* This will cause conflicts */ +#define pthread_key(T,V) DWORD V +#define pthread_key_create(A,B) ((*A=TlsAlloc())==0xFFFFFFFF) +#define pthread_getspecific(A) (TlsGetValue(A)) +#define my_pthread_getspecific(T,A) ((T) TlsGetValue(A)) +#define my_pthread_getspecific_ptr(T,V) ((T) TlsGetValue(V)) +#define my_pthread_setspecific_ptr(T,V) (!TlsSetValue((T),(V))) +#define pthread_setspecific(A,B) (!TlsSetValue((A),(B))) + + +#define pthread_equal(A,B) ((A) == (B)) + +#define pthread_mutex_init(A,B) InitializeCriticalSection(A) +#define pthread_mutex_lock(A) (EnterCriticalSection(A),0) +#define pthread_mutex_trylock(A) (WaitForSingleObject((A), 0) == WAIT_TIMEOUT) +#define pthread_mutex_unlock(A) LeaveCriticalSection(A) +#define pthread_mutex_destroy(A) DeleteCriticalSection(A) +#define my_pthread_setprio(A,B) SetThreadPriority(GetCurrentThread(), (B)) +#define pthread_kill(A,B) pthread_dummy(0) + + +/* Dummy defines for easier code */ +#define pthread_attr_setdetachstate(A,B) pthread_dummy(0) +#define my_pthread_attr_setprio(A,B) pthread_attr_setprio(A,B) +#define pthread_attr_setscope(A,B) +#define pthread_detach_this_thread() +#define pthread_condattr_init(A) +#define pthread_condattr_destroy(A) + +/*Irena: compiler does not like this: */ +/*#define my_pthread_getprio(pthread_t thread_id) pthread_dummy(0) */ +#define my_pthread_getprio(thread_id) pthread_dummy(0) + +#elif defined(HAVE_UNIXWARE7_THREADS) + +#include +#include + +#ifndef _REENTRANT +#define _REENTRANT +#endif + +#define HAVE_NONPOSIX_SIGWAIT +#define pthread_t thread_t +#define pthread_cond_t cond_t +#define pthread_mutex_t mutex_t +#define pthread_key_t thread_key_t +typedef int pthread_attr_t; /* Needed by Unixware 7.0.0 */ + +#define pthread_key_create(A,B) thr_keycreate((A),(B)) + +#define pthread_handler_decl(A,B) void *A(void *B) +#define pthread_key(T,V) pthread_key_t V + +void * my_pthread_getspecific_imp(pthread_key_t key); +#define my_pthread_getspecific(A,B) ((A) my_pthread_getspecific_imp(B)) +#define my_pthread_getspecific_ptr(T,V) my_pthread_getspecific(T,V) + +#define pthread_setspecific(A,B) thr_setspecific(A,B) +#define my_pthread_setspecific_ptr(T,V) pthread_setspecific(T,V) + +#define pthread_create(A,B,C,D) thr_create(NULL,65536L,(C),(D),THR_DETACHED,(A)) +#define pthread_cond_init(a,b) cond_init((a),USYNC_THREAD,NULL) +#define pthread_cond_destroy(a) cond_destroy(a) +#define pthread_cond_signal(a) cond_signal(a) +#define pthread_cond_wait(a,b) cond_wait((a),(b)) +#define pthread_cond_timedwait(a,b,c) cond_timedwait((a),(b),(c)) +#define pthread_cond_broadcast(a) cond_broadcast(a) + +#define pthread_mutex_init(a,b) mutex_init((a),USYNC_THREAD,NULL) +#define pthread_mutex_lock(a) mutex_lock(a) +#define pthread_mutex_unlock(a) mutex_unlock(a) +#define pthread_mutex_destroy(a) mutex_destroy(a) + +#define pthread_self() thr_self() +#define pthread_exit(A) thr_exit(A) +#define pthread_equal(A,B) (((A) == (B)) ? 1 : 0) +#define pthread_kill(A,B) thr_kill((A),(B)) +#define HAVE_PTHREAD_KILL + +#define pthread_sigmask(A,B,C) thr_sigsetmask((A),(B),(C)) + +extern int my_sigwait(const sigset_t *set,int *sig); + +#define pthread_detach_this_thread() pthread_dummy(0) + +#define pthread_attr_init(A) pthread_dummy(0) +#define pthread_attr_destroy(A) pthread_dummy(0) +#define pthread_attr_setscope(A,B) pthread_dummy(0) +#define pthread_attr_setdetachstate(A,B) pthread_dummy(0) +#define my_pthread_setprio(A,B) pthread_dummy (0) +#define my_pthread_getprio(A) pthread_dummy (0) +#define my_pthread_attr_setprio(A,B) pthread_dummy(0) + +#else /* Normal threads */ + +#ifdef HAVE_rts_threads +#define sigwait org_sigwait +#include +#undef sigwait +#endif +#undef _REENTRANT /* Fix if _REENTRANT is in pthread.h */ +#include +#ifndef _REENTRANT +#define _REENTRANT +#endif +#ifdef HAVE_THR_SETCONCURRENCY +#include /* Probably solaris */ +#endif +#ifdef HAVE_SCHED_H +#include +#endif +#ifdef HAVE_SYNCH_H +#include +#endif +#if defined(__EMX__) && (!defined(EMX_PTHREAD_REV) || (EMX_PTHREAD_REV < 2)) +#error Requires at least rev 2 of EMX pthreads library. +#endif + +extern int my_pthread_getprio(pthread_t thread_id); + +#define pthread_key(T,V) pthread_key_t V +#define my_pthread_getspecific_ptr(T,V) my_pthread_getspecific(T,(V)) +#define my_pthread_setspecific_ptr(T,V) pthread_setspecific(T,(void*) (V)) +#define pthread_detach_this_thread() +#define pthread_handler_decl(A,B) void *A(void *B) +typedef void *(* pthread_handler)(void *); + +/* Test first for RTS or FSU threads */ + +#if defined(PTHREAD_SCOPE_GLOBAL) && !defined(PTHREAD_SCOPE_SYSTEM) +#define HAVE_rts_threads +extern int my_pthread_create_detached; +#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C)) +#define PTHREAD_CREATE_DETACHED &my_pthread_create_detached +#define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_GLOBAL +#define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_LOCAL +#define USE_ALARM_THREAD +#endif /* defined(PTHREAD_SCOPE_GLOBAL) && !defined(PTHREAD_SCOPE_SYSTEM) */ + +#if defined(HAVE_UNIXWARE7_POSIX) +#undef HAVE_NONPOSIX_SIGWAIT +#define HAVE_NONPOSIX_SIGWAIT /* sigwait takes only 1 argument */ +#endif + +#ifndef HAVE_NONPOSIX_SIGWAIT +#define my_sigwait(A,B) sigwait((A),(B)) +#else +int my_sigwait(const sigset_t *set,int *sig); +#endif + +#ifdef HAVE_NONPOSIX_PTHREAD_MUTEX_INIT +#ifndef SAFE_MUTEX +#define pthread_mutex_init(a,b) my_pthread_mutex_init((a),(b)) +extern int my_pthread_mutex_init(pthread_mutex_t *mp, + const pthread_mutexattr_t *attr); +#endif /* SAFE_MUTEX */ +#define pthread_cond_init(a,b) my_pthread_cond_init((a),(b)) +extern int my_pthread_cond_init(pthread_cond_t *mp, + const pthread_condattr_t *attr); +#endif /* HAVE_NONPOSIX_PTHREAD_MUTEX_INIT */ + +#if defined(HAVE_SIGTHREADMASK) && !defined(HAVE_PTHREAD_SIGMASK) +#define pthread_sigmask(A,B,C) sigthreadmask((A),(B),(C)) +#endif + +#if !defined(HAVE_SIGWAIT) && !defined(HAVE_mit_thread) && !defined(HAVE_rts_threads) && !defined(sigwait) && !defined(alpha_linux_port) && !defined(HAVE_NONPOSIX_SIGWAIT) && !defined(HAVE_DEC_3_2_THREADS) && !defined(_AIX) +int sigwait(sigset_t *setp, int *sigp); /* Use our implemention */ +#endif +#if !defined(HAVE_SIGSET) && !defined(my_sigset) +#define my_sigset(A,B) do { struct sigaction s; sigset_t set; \ + sigemptyset(&set); \ + s.sa_handler = (B); \ + s.sa_mask = set; \ + s.sa_flags = 0; \ + sigaction((A), &s, (struct sigaction *) NULL); \ + } while (0) +#elif !defined(my_sigset) + #define my_sigset(A,B) signal((A),(B)) +#endif + +#ifndef my_pthread_setprio +#if defined(HAVE_PTHREAD_SETPRIO_NP) /* FSU threads */ +#define my_pthread_setprio(A,B) pthread_setprio_np((A),(B)) +#elif defined(HAVE_PTHREAD_SETPRIO) +#define my_pthread_setprio(A,B) pthread_setprio((A),(B)) +#else +extern void my_pthread_setprio(pthread_t thread_id,int prior); +#endif +#endif + +#ifndef my_pthread_attr_setprio +#ifdef HAVE_PTHREAD_ATTR_SETPRIO +#define my_pthread_attr_setprio(A,B) pthread_attr_setprio((A),(B)) +#else +extern void my_pthread_attr_setprio(pthread_attr_t *attr, int priority); +#endif +#endif + +#if !defined(HAVE_PTHREAD_ATTR_SETSCOPE) || defined(HAVE_DEC_3_2_THREADS) +#define pthread_attr_setscope(A,B) +#undef HAVE_GETHOSTBYADDR_R /* No definition */ +#endif + +#if defined(HAVE_BROKEN_PTHREAD_COND_TIMEDWAIT) && !defined(SAFE_MUTEX) +extern int my_pthread_cond_timedwait(pthread_cond_t *cond, + pthread_mutex_t *mutex, + struct timespec *abstime); +#define pthread_cond_timedwait(A,B,C) my_pthread_cond_timedwait((A),(B),(C)) +#endif + +#if !defined( HAVE_NONPOSIX_PTHREAD_GETSPECIFIC) +#define my_pthread_getspecific(A,B) ((A) pthread_getspecific(B)) +#else +#define my_pthread_getspecific(A,B) ((A) my_pthread_getspecific_imp(B)) +void *my_pthread_getspecific_imp(pthread_key_t key); +#endif + +#ifndef HAVE_LOCALTIME_R +struct tm *localtime_r(const time_t *clock, struct tm *res); +#endif + +#ifdef HAVE_PTHREAD_CONDATTR_CREATE +/* DCE threads on HPUX 10.20 */ +#define pthread_condattr_init pthread_condattr_create +#define pthread_condattr_destroy pthread_condattr_delete +#endif + +#ifdef HAVE_CTHREADS_WRAPPER /* For MacOSX */ +#define pthread_cond_destroy(A) pthread_dummy(0) +#define pthread_mutex_destroy(A) pthread_dummy(0) +#define pthread_attr_delete(A) pthread_dummy(0) +#define pthread_condattr_delete(A) pthread_dummy(0) +#define pthread_attr_setstacksize(A,B) pthread_dummy(0) +#define pthread_equal(A,B) ((A) == (B)) +#define pthread_cond_timedwait(a,b,c) pthread_cond_wait((a),(b)) +#define pthread_attr_init(A) pthread_attr_create(A) +#define pthread_attr_destroy(A) pthread_attr_delete(A) +#define pthread_attr_setdetachstate(A,B) pthread_dummy(0) +#define pthread_create(A,B,C,D) pthread_create((A),*(B),(C),(D)) +#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C)) +#define pthread_kill(A,B) pthread_dummy(0) +#undef pthread_detach_this_thread +#define pthread_detach_this_thread() { pthread_t tmp=pthread_self() ; pthread_detach(&tmp); } +#endif + +#ifdef HAVE_DARWIN_THREADS +#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C)) +#define pthread_kill(A,B) pthread_dummy(0) +#define pthread_condattr_init(A) pthread_dummy(0) +#define pthread_condattr_destroy(A) pthread_dummy(0) +#define pthread_signal(A,B) pthread_dummy(0) +#undef pthread_detach_this_thread +#define pthread_detach_this_thread() { pthread_t tmp=pthread_self() ; pthread_detach(tmp); } +#undef sigset +#define sigset(A,B) pthread_signal((A),(void (*)(int)) (B)) +#endif + +#if ((defined(HAVE_PTHREAD_ATTR_CREATE) && !defined(HAVE_SIGWAIT)) || defined(HAVE_DEC_3_2_THREADS)) && !defined(HAVE_CTHREADS_WRAPPER) +/* This is set on AIX_3_2 and Siemens unix (and DEC OSF/1 3.2 too) */ +#define pthread_key_create(A,B) \ + pthread_keycreate(A,(B) ?\ + (pthread_destructor_t) (B) :\ + (pthread_destructor_t) pthread_dummy) +#define pthread_attr_init(A) pthread_attr_create(A) +#define pthread_attr_destroy(A) pthread_attr_delete(A) +#define pthread_attr_setdetachstate(A,B) pthread_dummy(0) +#define pthread_create(A,B,C,D) pthread_create((A),*(B),(C),(D)) +#ifndef pthread_sigmask +#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C)) +#endif +#define pthread_kill(A,B) pthread_dummy(0) +#undef pthread_detach_this_thread +#define pthread_detach_this_thread() { pthread_t tmp=pthread_self() ; pthread_detach(&tmp); } ++#elif !defined(HAVE_PTHREAD_KILL) /* HAVE_PTHREAD_ATTR_CREATE && !HAVE_SIGWAIT */ +#define HAVE_PTHREAD_KILL +#endif + +#endif /* defined(_WIN32) */ + +#if defined(HPUX) && !defined(DONT_REMAP_PTHREAD_FUNCTIONS) +#undef pthread_cond_timedwait +#define pthread_cond_timedwait(a,b,c) my_pthread_cond_timedwait((a),(b),(c)) +int my_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, + struct timespec *abstime); +#endif + +#if defined(HAVE_POSIX1003_4a_MUTEX) && !defined(DONT_REMAP_PTHREAD_FUNCTIONS) +#undef pthread_mutex_trylock +#define pthread_mutex_trylock(a) my_pthread_mutex_trylock((a)) +int my_pthread_mutex_trylock(pthread_mutex_t *mutex); +#endif + + /* safe_mutex adds checking to mutex for easier debugging */ + +typedef struct st_safe_mutex_t +{ + pthread_mutex_t global,mutex; + char *file; + uint line,count; + pthread_t thread; +} safe_mutex_t; + +int safe_mutex_init(safe_mutex_t *mp, const pthread_mutexattr_t *attr); +int safe_mutex_lock(safe_mutex_t *mp,const char *file, uint line); +int safe_mutex_unlock(safe_mutex_t *mp,const char *file, uint line); +int safe_mutex_destroy(safe_mutex_t *mp,const char *file, uint line); +int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp,const char *file, + uint line); +int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp, + struct timespec *abstime, const char *file, uint line); + + /* Wrappers if safe mutex is actually used */ +#ifdef SAFE_MUTEX +#undef pthread_mutex_init +#undef pthread_mutex_lock +#undef pthread_mutex_unlock +#undef pthread_mutex_destroy +#undef pthread_mutex_wait +#undef pthread_mutex_timedwait +#undef pthread_mutex_t +#undef pthread_cond_wait +#undef pthread_cond_timedwait +#undef pthread_mutex_trylock +#define pthread_mutex_init(A,B) safe_mutex_init((A),(B)) +#define pthread_mutex_lock(A) safe_mutex_lock((A),__FILE__,__LINE__) +#define pthread_mutex_unlock(A) safe_mutex_unlock((A),__FILE__,__LINE__) +#define pthread_mutex_destroy(A) safe_mutex_destroy((A),__FILE__,__LINE__) +#define pthread_cond_wait(A,B) safe_cond_wait((A),(B),__FILE__,__LINE__) +#define pthread_cond_timedwait(A,B,C) safe_cond_timedwait((A),(B),(C),__FILE__,__LINE__) +#define pthread_mutex_trylock(A) pthread_mutex_lock(A) +#define pthread_mutex_t safe_mutex_t +#define safe_mutex_assert_owner(mp) DBUG_ASSERT((mp)->count > 0 && pthread_equal(pthread_self(),(mp)->thread)) +#else +#define safe_mutex_assert_owner(mp) +#endif /* SAFE_MUTEX */ + + /* READ-WRITE thread locking */ + +#if defined(USE_MUTEX_INSTEAD_OF_RW_LOCKS) +/* use these defs for simple mutex locking */ +#define rw_lock_t pthread_mutex_t +#define my_rwlock_init(A,B) pthread_mutex_init((A),(B)) +#define rw_rdlock(A) pthread_mutex_lock((A)) +#define rw_wrlock(A) pthread_mutex_lock((A)) +#define rw_tryrdlock(A) pthread_mutex_trylock((A)) +#define rw_trywrlock(A) pthread_mutex_trylock((A)) +#define rw_unlock(A) pthread_mutex_unlock((A)) +#define rwlock_destroy(A) pthread_mutex_destroy((A)) +#elif defined(HAVE_PTHREAD_RWLOCK_RDLOCK) +#define rw_lock_t pthread_rwlock_t +#define my_rwlock_init(A,B) pthread_rwlock_init((A),(B)) +#define rw_rdlock(A) pthread_rwlock_rdlock(A) +#define rw_wrlock(A) pthread_rwlock_wrlock(A) +#define rw_tryrdlock(A) pthread_rwlock_tryrdlock((A)) +#define rw_trywrlock(A) pthread_rwlock_trywrlock((A)) +#define rw_unlock(A) pthread_rwlock_unlock(A) +#define rwlock_destroy(A) pthread_rwlock_destroy(A) +#elif defined(HAVE_RWLOCK_INIT) +#ifdef HAVE_RWLOCK_T /* For example Solaris 2.6-> */ +#define rw_lock_t rwlock_t +#endif +#define my_rwlock_init(A,B) rwlock_init((A),USYNC_THREAD,0) +#else +/* Use our own version of read/write locks */ +typedef struct _my_rw_lock_t { + pthread_mutex_t lock; /* lock for structure */ + pthread_cond_t readers; /* waiting readers */ + pthread_cond_t writers; /* waiting writers */ + int state; /* -1:writer,0:free,>0:readers */ + int waiters; /* number of waiting writers */ +} my_rw_lock_t; + +#define rw_lock_t my_rw_lock_t +#define rw_rdlock(A) my_rw_rdlock((A)) +#define rw_wrlock(A) my_rw_wrlock((A)) +#define rw_tryrdlock(A) my_rw_tryrdlock((A)) +#define rw_trywrlock(A) my_rw_trywrlock((A)) +#define rw_unlock(A) my_rw_unlock((A)) +#define rwlock_destroy(A) my_rwlock_destroy((A)) + +extern int my_rwlock_init(my_rw_lock_t *, void *); +extern int my_rwlock_destroy(my_rw_lock_t *); +extern int my_rw_rdlock(my_rw_lock_t *); +extern int my_rw_wrlock(my_rw_lock_t *); +extern int my_rw_unlock(my_rw_lock_t *); +extern int my_rw_tryrdlock(my_rw_lock_t *); +extern int my_rw_trywrlock(my_rw_lock_t *); +#endif /* USE_MUTEX_INSTEAD_OF_RW_LOCKS */ + +#define GETHOSTBYADDR_BUFF_SIZE 2048 + +#ifndef HAVE_THR_SETCONCURRENCY +#define thr_setconcurrency(A) pthread_dummy(0) +#endif +#if !defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE) && ! defined(pthread_attr_setstacksize) +#define pthread_attr_setstacksize(A,B) pthread_dummy(0) +#endif + +/* Define mutex types */ +#define MY_MUTEX_INIT_SLOW NULL +#define MY_MUTEX_INIT_FAST NULL +#define MY_MUTEX_INIT_ERRCHK NULL +#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP +extern pthread_mutexattr_t my_fast_mutexattr; +#undef MY_MUTEX_INIT_FAST +#define MY_MUTEX_INIT_FAST &my_fast_mutexattr +#endif +#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP +extern pthread_mutexattr_t my_errchk_mutexattr; +#undef MY_INIT_MUTEX_ERRCHK +#define MY_INIT_MUTEX_ERRCHK &my_errchk_mutexattr +#endif + +extern my_bool my_thread_global_init(void); +extern void my_thread_global_end(void); +extern my_bool my_thread_init(void); +extern void my_thread_end(void); +extern const char *my_thread_name(void); +extern long my_thread_id(void); +extern int pthread_no_free(void *); +extern int pthread_dummy(int); + +/* All thread specific variables are in the following struct */ + +#define THREAD_NAME_SIZE 10 +#if defined(__ia64__) +#define DEFAULT_THREAD_STACK (128*1024) +#else +#define DEFAULT_THREAD_STACK (64*1024) +#endif + +struct st_my_thread_var +{ + int thr_errno; + pthread_cond_t suspend; + pthread_mutex_t mutex; + pthread_mutex_t * volatile current_mutex; + pthread_cond_t * volatile current_cond; + pthread_t pthread_self; + long id; + int cmp_length; + int volatile abort; +#ifndef DBUG_OFF + gptr dbug; + char name[THREAD_NAME_SIZE+1]; +#endif + my_bool initialized; +}; + +extern struct st_my_thread_var *_my_thread_var(void) __attribute__ ((const)); +extern void **my_thread_var_dbug(); +#define my_thread_var (_my_thread_var()) +#define my_errno my_thread_var->thr_errno + + /* statistics_xxx functions are for not essential statistic */ + +#ifndef thread_safe_increment +#ifdef HAVE_ATOMIC_ADD +#define thread_safe_increment(V,L) atomic_add(1,(atomic_t*) &V); +#define thread_safe_add(V,C,L) atomic_add((C),(atomic_t*) &V); +#define thread_safe_sub(V,C,L) atomic_sub((C),(atomic_t*) &V); +#define statistic_increment(V,L) thread_safe_increment((V),(L)) +#define statistic_add(V,C,L) thread_safe_add((V),(C),(L)) +#else +#define thread_safe_increment(V,L) \ + pthread_mutex_lock((L)); (V)++; pthread_mutex_unlock((L)); +#define thread_safe_add(V,C,L) \ + pthread_mutex_lock((L)); (V)+=(C); pthread_mutex_unlock((L)); +#define thread_safe_sub(V,C,L) \ + pthread_mutex_lock((L)); (V)-=(C); pthread_mutex_unlock((L)); +#ifdef SAFE_STATISTICS +#define statistic_increment(V,L) thread_safe_increment((V),(L)) +#define statistic_add(V,C,L) thread_safe_add((V),(C),(L)) +#else +#define statistic_increment(V,L) (V)++ +#define statistic_add(V,C,L) (V)+=(C) +#endif /* SAFE_STATISTICS */ +#endif /* HAVE_ATOMIC_ADD */ +#endif /* thread_safe_increment */ + +#ifdef __cplusplus +} +#endif + +#endif /* _my_ptread_h */ From 61daa7ae8803b42f1477c994693d1eea70b5fdcd Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Mon, 8 Feb 2016 19:00:54 +0100 Subject: [PATCH 34/39] fixed installation of include files --- include/CMakeLists.txt | 7 +++---- libmariadb/CMakeLists.txt | 2 ++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 55c7b8ca..d652d628 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,15 +1,14 @@ SET(MARIADB_CLIENT_INCLUDES - ${CMAKE_SOURCE_DIR}/include/mysql_com.h + ${CMAKE_SOURCE_DIR}/include/mariadb_com.h ${CMAKE_SOURCE_DIR}/include/mysql.h - ${CMAKE_SOURCE_DIR}/include/my_stmt.h + ${CMAKE_SOURCE_DIR}/include/mariadb_stmt.h ${CMAKE_SOURCE_DIR}/include/mariadb_version.h - ${CMAKE_SOURCE_DIR}/include/my_list.h + ${CMAKE_SOURCE_DIR}/include/ma_list.h ${CMAKE_SOURCE_DIR}/include/mariadb_dyncol.h ${CMAKE_SOURCE_DIR}/include/mariadb_ctype.h) SET(MARIADB_ADDITIONAL_INCLUDES PARENT_SCOPE) INSTALL(FILES - ${CMAKE_BINARY_DIR}/include/mysql_version.h ${MARIADB_CLIENT_INCLUDES} DESTINATION ${INCLUDE_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}) INSTALL(FILES diff --git a/libmariadb/CMakeLists.txt b/libmariadb/CMakeLists.txt index 09e5e28e..fbbacc1e 100644 --- a/libmariadb/CMakeLists.txt +++ b/libmariadb/CMakeLists.txt @@ -299,11 +299,13 @@ SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} ${ZLIB_SOURCES}) ENDIF() IF(WITH_DYNCOL) + MESSAGE(STATUS "Dynamic column API support=ON") SET(MARIADB_LIB_SYMBOLS ${MARIADB_LIB_SYMBOLS} ${MARIADB_DYNCOL_SYMBOLS}) SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} mariadb_dyncol.c) ENDIF() IF(WITH_NONBLOCK) + MESSAGE(STATUS "Non blocking API support=ON") SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} mariadb_async.c ma_context.c) SET(MARIADB_LIB_SYMBOLS ${MARIADB_LIB_SYMBOLS} ${MARIADB_NONBLOCK_SYMBOLS}) ADD_DEFINITIONS(-DHAVE_NONBLOCK) From 62e69c8b950e636492d51a1fded5412f82144112 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Mon, 8 Feb 2016 19:19:33 +0100 Subject: [PATCH 35/39] Prevent multiple inclusion of mariadb_version.h in client tools --- include/mariadb_version.h.in | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/mariadb_version.h.in b/include/mariadb_version.h.in index 2e9eb6f1..d0fa54f8 100644 --- a/include/mariadb_version.h.in +++ b/include/mariadb_version.h.in @@ -3,6 +3,9 @@ /* Version numbers for protocol & mysqld */ +#ifndef _mariadb_version_h_ +#define _mariadb_version_h_ + #ifdef _CUSTOMCONFIG_ #include #else @@ -26,3 +29,4 @@ #endif #endif +#endif /* _mariadb_version_h_ */ From 74ce606c77ef72258b763d1395dc49c63d9b2b21 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Tue, 9 Feb 2016 08:43:16 +0100 Subject: [PATCH 36/39] Fix for CONC155: return trailing zero when fetching from binary columns into string --- libmariadb/ma_stmt_codec.c | 10 ++++++++ unittest/libmariadb/ps_bugs.c | 46 +++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/libmariadb/ma_stmt_codec.c b/libmariadb/ma_stmt_codec.c index 20f2a0f9..f47487bc 100644 --- a/libmariadb/ma_stmt_codec.c +++ b/libmariadb/ma_stmt_codec.c @@ -818,9 +818,19 @@ void ps_fetch_bin(MYSQL_BIND *r_param, const MYSQL_FIELD *field, ulong field_length= net_field_length(row); size_t copylen; + /* Bug conc-155: For text columns we need to store terminating zero character */ + if (!(field->flags & BINARY_FLAG) && r_param->buffer_type == MYSQL_TYPE_STRING) + field_length++; + copylen= MIN(field_length, r_param->buffer_length); memcpy(r_param->buffer, *row, copylen); *r_param->error= copylen < field_length; + + /* don't count trailing zero if we fetch into string */ + if (r_param->buffer_type == MYSQL_TYPE_STRING && + !*r_param->error) + field_length--; + *r_param->length= field_length; (*row) += field_length; diff --git a/unittest/libmariadb/ps_bugs.c b/unittest/libmariadb/ps_bugs.c index 94b946ea..d5fdded3 100644 --- a/unittest/libmariadb/ps_bugs.c +++ b/unittest/libmariadb/ps_bugs.c @@ -4012,7 +4012,52 @@ static int test_conc154(MYSQL *mysql) return OK; } +static int test_conc155(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND bind; + char buffer[50]; + int rc; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE t1 (a TEXT)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO t1 VALUES ('zero terminated string')"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, "SELECT a FROM t1", strlen("SELECT a FROM t1")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + memset(buffer, 'X', 50); + memset(&bind, 0, sizeof(MYSQL_BIND)); + + bind.buffer= buffer; + bind.buffer_length= 50; + bind.buffer_type= MYSQL_TYPE_STRING; + + rc= mysql_stmt_bind_result(stmt, &bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + if (strlen(buffer) != strlen("zero terminated string")) + { + diag("Wrong buffer length"); + return FAIL; + } + + mysql_stmt_close(stmt); + return OK; +} + struct my_tests_st my_tests[] = { + {"test_conc155", test_conc155, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc154", test_conc154, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, {"test_conc141", test_conc141, TEST_CONNECTION_NEW, 0, NULL , NULL}, {"test_conc67", test_conc67, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, @@ -4083,3 +4128,4 @@ int main(int argc, char **argv) return(exit_status()); } + From 5c193858467bb47b3e753b4759affecdf4481dea Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Tue, 9 Feb 2016 09:02:36 +0100 Subject: [PATCH 37/39] Always provide prototypes for non blocking functions in mysql.h --- include/mysql.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/mysql.h b/include/mysql.h index de1a19e0..ab34d5c8 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -539,7 +539,6 @@ unsigned int STDCALL mysql_get_timeout_value_ms(const MYSQL *mysql); my_bool STDCALL mysql_reconnect(MYSQL *mysql); /* Async API */ -#ifdef HAVE_NONBLOCK 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); @@ -650,7 +649,6 @@ int STDCALL mysql_stmt_send_long_data_start(my_bool *ret, MYSQL_STMT *stmt, size_t len); int STDCALL mysql_stmt_send_long_data_cont(my_bool *ret, MYSQL_STMT *stmt, int status); -#endif /* API function calls (used by dynmic plugins) */ struct st_mariadb_api { From 1cf84e791f6aef4375cca7d505640a1dd854ddb9 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Tue, 9 Feb 2016 10:02:21 +0100 Subject: [PATCH 38/39] Windows packaging fixes for includes and plugins --- include/CMakeLists.txt | 12 +++++++----- win/packaging/CMakeLists.txt | 14 +++++++------- win/packaging/mariadb-connector-c.xml.in | 4 +++- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index d652d628..6ee7b445 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -5,14 +5,16 @@ SET(MARIADB_CLIENT_INCLUDES ${CMAKE_SOURCE_DIR}/include/mariadb_version.h ${CMAKE_SOURCE_DIR}/include/ma_list.h ${CMAKE_SOURCE_DIR}/include/mariadb_dyncol.h - ${CMAKE_SOURCE_DIR}/include/mariadb_ctype.h) + ${CMAKE_SOURCE_DIR}/include/mariadb_ctype.h PARENT_SCOPE) SET(MARIADB_ADDITIONAL_INCLUDES - PARENT_SCOPE) + ${CMAKE_SOURCE_DIR}/include/mysql/client_plugin.h + ${CMAKE_SOURCE_DIR}/include/mysql/plugin_auth_common.h + ${CMAKE_SOURCE_DIR}/include/mysql/plugin_auth.h PARENT_SCOPE) + INSTALL(FILES ${MARIADB_CLIENT_INCLUDES} DESTINATION ${INCLUDE_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}) INSTALL(FILES - ${CMAKE_SOURCE_DIR}/include/mysql/client_plugin.h - ${CMAKE_SOURCE_DIR}/include/mysql/plugin_auth_common.h - ${CMAKE_SOURCE_DIR}/include/mysql/plugin_auth.h + ${MARIADB_ADDITIONAL_INCLUDES} DESTINATION ${INCLUDE_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}/mysql) + diff --git a/win/packaging/CMakeLists.txt b/win/packaging/CMakeLists.txt index 6decef34..768ac69d 100644 --- a/win/packaging/CMakeLists.txt +++ b/win/packaging/CMakeLists.txt @@ -31,17 +31,17 @@ FOREACH(plugin ${PLUGINS}) SET(TARGET ${${plugin}_PLUGIN_TARGET}) # Get dependencies SET(DYNAMIC_TARGETS ${DYNAMIC_TARGETS} ${TARGET}) - + GET_PROPERTY(FILE TARGET ${TARGET} PROPERTY LOCATION) + #MESSAGE(STATUS "Location for ${TARGET}: ${DIRECTORY}") # build file list - SET(FILE ${${plugin}_PLUGIN_SOURCE}) - GET_FILENAME_COMPONENT(FILE ${FILE} DIRECTORY) - STRING(REPLACE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} FILE ${FILE}) - SET(FILE ${FILE}/RelWithDebInfo/${TARGET}.dll) + STRING(REPLACE "$(Configuration)" "RelWithDebInfo" FILE ${FILE}) SET(MARIADB_PLUGINS "${MARIADB_PLUGINS} \n") ENDIF() ENDFOREACH() -FOREACH(src ${MARIADB_CLIENT_INCLUDES}) +SET(ALL_INCLUDES ${MARIADB_CLIENT_INCLUDES} ${MARIADB_ADDITIONAL_INCLUDES}) +FOREACH(src ${ALL_INCLUDES}) + STRING(REPLACE "${CMAKE_SOURCE_DIR}/include/" "" src ${src}) STRING(REPLACE "-" "_" src_id ${src}) STRING(REPLACE "mysql/" "" src_id ${src_id}) STRING(REPLACE "mysql/" "" src_name ${src}) @@ -90,7 +90,7 @@ ADD_CUSTOM_TARGET(WIXOBJ SET_TARGET_PROPERTIES(${MSI_PACKAGE} PROPERTIES EXCLUDE_FROM_ALL OFF) SET_TARGET_PROPERTIES(${WIXOBJ} PROPERTIES EXCLUDE_FROM_ALL OFF) ADD_DEPENDENCIES(${MSI_PACKAGE} WIXOBJ) -ADD_DEPENDENCIES(WIXOBJ libmariadb mariadbclient mariadb_client_plugin_info ${DYNAMIC_TARGETS}) +ADD_DEPENDENCIES(WIXOBJ libmariadb mariadbclient ${DYNAMIC_TARGETS}) CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/win/packaging/mariadb-connector-c.xml.in ${CMAKE_BINARY_DIR}/win/packaging/mariadb-connector-c.xml) diff --git a/win/packaging/mariadb-connector-c.xml.in b/win/packaging/mariadb-connector-c.xml.in index 38e648e1..a918e0c9 100644 --- a/win/packaging/mariadb-connector-c.xml.in +++ b/win/packaging/mariadb-connector-c.xml.in @@ -58,8 +58,10 @@ + From c60923bc4c1eecaf3bf2bccfb1263d44c5cf4387 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Tue, 9 Feb 2016 10:24:53 +0100 Subject: [PATCH 39/39] Added option WITH_MSI for building MSI package --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac816cdf..746e4a8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,7 @@ SET(MARIADB_CONNECTOR_C_COPYRIGHT "2013-2016 MariaDB Corporation Ab") IF(NOT WIN32) OPTION(WITH_MYSQLCOMPAT "creates libmysql* symbolic links" ON) ELSE() + OPTION(WITH_MSI "Build MSI installation package" OFF) OPTION(WITH_SIGNCODE "digitally sign files" OFF) OPTION(WITH_RTC "enables run time checks for debug builds" OFF) ENDIF() @@ -300,8 +301,8 @@ IF(CLIENT_DOCS) ENDIF() -IF(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") - ADD_SUBDIRECTORY(win/packaging) +IF(WIN32 AND WITH_MSI AND CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + DD_SUBDIRECTORY(win/packaging) ENDIF() SET(CPACK_PACKAGE_VENDOR "MariaDB Corporation Ab")