Skip to content

Commit ec7551d

Browse files
committed
Merge pull request #7 from 9EOR9/master
Windows fixes:
2 parents ae45732 + 301d0de commit ec7551d

File tree

11 files changed

+111
-105
lines changed

11 files changed

+111
-105
lines changed

cmake/plugins.cmake

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# plugin configuration
22

3-
MACRO(REGISTER_PLUGIN name source struct type allow)
3+
MACRO(REGISTER_PLUGIN name source struct type target allow)
44
IF(PLUGINS)
55
LIST(REMOVE_ITEM PLUGINS ${name})
66
ENDIF()
77
SET(${name}_PLUGIN_SOURCE ${source})
8+
MARK_AS_ADVANCED(${name}_PLUGIN_SOURCE})
89
SET(${name}_PLUGIN_TYPE ${type})
10+
IF(NOT ${target} STREQUAL "")
11+
SET(${name}_PLUGIN_TARGET ${target})
12+
ENDIF()
913
SET(${name}_PLUGIN_STRUCT ${struct})
1014
SET(${name}_PLUGIN_SOURCE ${source})
1115
SET(${name}_PLUGIN_CHG ${allow})
@@ -15,26 +19,28 @@ ENDMACRO()
1519
MARK_AS_ADVANCED(PLUGINS)
1620

1721
# CIO
18-
REGISTER_PLUGIN("SOCKET" "${CMAKE_SOURCE_DIR}/plugins/pvio/pvio_socket.c" "pvio_socket_plugin" "STATIC" 0)
22+
REGISTER_PLUGIN("SOCKET" "${CMAKE_SOURCE_DIR}/plugins/pvio/pvio_socket.c" "pvio_socket_plugin" "STATIC" pvio_socket 0)
1923
IF(WIN32)
20-
REGISTER_PLUGIN("NPIPE" "${CMAKE_SOURCE_DIR}/plugins/pvio/pvio_npipe.c" "pvio_npipe_plugin" "DYNAMIC" 1)
21-
REGISTER_PLUGIN("SHMEM" "${CMAKE_SOURCE_DIR}/plugins/pvio/pvio_shmem.c" "pvio_shmem_plugin" "DYNAMIC" 1)
24+
REGISTER_PLUGIN("NPIPE" "${CMAKE_SOURCE_DIR}/plugins/pvio/pvio_npipe.c" "pvio_npipe_plugin" "STATIC" pvio_npipe 1)
25+
REGISTER_PLUGIN("SHMEM" "${CMAKE_SOURCE_DIR}/plugins/pvio/pvio_shmem.c" "pvio_shmem_plugin" "DYNAMIC" pvio_shmem 1)
2226
ENDIF()
2327

2428
# AUTHENTICATION
25-
REGISTER_PLUGIN("AUTH_NATIVE" "${CMAKE_SOURCE_DIR}/plugins/auth/my_auth.c" "native_password_client_plugin" "STATIC" 0)
26-
REGISTER_PLUGIN("AUTH_OLDPASSWORD" "${CMAKE_SOURCE_DIR}/plugins/auth/my_auth.c" "old_password_client_plugin" "STATIC" 0)
27-
REGISTER_PLUGIN("AUTH_DIALOG" "${CMAKE_SOURCE_DIR}/plugins/auth/dialog.c" "auth_dialog_plugin" "DYNAMIC" 1)
28-
REGISTER_PLUGIN("AUTH_CLEARTEXT" "${CMAKE_SOURCE_DIR}/plugins/auth/mariadb_clear_text.c" "auth_cleartext_plugin" "DYNAMIC" 1)
29+
REGISTER_PLUGIN("AUTH_NATIVE" "${CMAKE_SOURCE_DIR}/plugins/auth/my_auth.c" "native_password_client_plugin" "STATIC" "" 0)
30+
REGISTER_PLUGIN("AUTH_OLDPASSWORD" "${CMAKE_SOURCE_DIR}/plugins/auth/my_auth.c" "old_password_client_plugin" "STATIC" "" 0)
31+
REGISTER_PLUGIN("AUTH_DIALOG" "${CMAKE_SOURCE_DIR}/plugins/auth/dialog.c" "auth_dialog_plugin" "DYNAMIC" dialog 1)
32+
REGISTER_PLUGIN("AUTH_CLEARTEXT" "${CMAKE_SOURCE_DIR}/plugins/auth/mariadb_clear_text.c" "auth_cleartext_plugin" "DYNAMIC" "mysql_clear_password" 1)
2933

3034
#Remote_IO
31-
REGISTER_PLUGIN("REMOTEIO" "${CMAKE_SOURCE_DIR}/plugins/io/remote_io.c" "remote_io_plugin" "DYNAMIC" 1)
35+
IF(CURL_FOUND)
36+
REGISTER_PLUGIN("REMOTEIO" "${CMAKE_SOURCE_DIR}/plugins/io/remote_io.c" "remote_io_plugin" "DYNAMIC" "remote_io" 1)
37+
ENDIF()
3238

3339
#Trace
34-
REGISTER_PLUGIN("TRACE_EXAMPLE" "${CMAKE_SOURCE_DIR}/plugins/trace/trace_example.c" "trace_example_plugin" "DYNAMIC" 1)
40+
REGISTER_PLUGIN("TRACE_EXAMPLE" "${CMAKE_SOURCE_DIR}/plugins/trace/trace_example.c" "trace_example_plugin" "DYNAMIC" "trace_example" 1)
3541

3642
#Connection
37-
REGISTER_PLUGIN("REPLICATION" "${CMAKE_SOURCE_DIR}/plugins/connection/replication.c" "connection_replication_plugin" "STATIC" 1)
43+
REGISTER_PLUGIN("REPLICATION" "${CMAKE_SOURCE_DIR}/plugins/connection/replication.c" "connection_replication_plugin" "STATIC" "" 1)
3844

3945
# Allow registration of additional plugins
4046
IF(PLUGIN_CONF_FILE)

include/ma_pvio.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ typedef struct st_pvio_callback {
5353
struct st_pvio_callback *next;
5454
} PVIO_CALLBACK;
5555

56-
struct st_ma_pvio {
56+
typedef struct st_ma_pvio {
5757
void *data;
5858
/* read ahead cache */
5959
uchar *cache;
@@ -69,7 +69,7 @@ struct st_ma_pvio {
6969
FILE *fp;
7070
void (*set_error)(MYSQL *mysql, unsigned int error_nr, const char *sqlstate, const char *format, ...);
7171
void (*callback)(MARIADB_PVIO *pvio, my_bool is_read, const char *buffer, size_t length);
72-
};
72+
} MARIADB_PVIO;
7373

7474
typedef struct st_ma_pvio_cinfo
7575
{
@@ -84,8 +84,8 @@ struct st_ma_pvio_methods
8484
{
8585
my_bool (*set_timeout)(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout);
8686
int (*get_timeout)(MARIADB_PVIO *pvio, enum enum_pvio_timeout type);
87-
size_t (*read)(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
88-
size_t (*async_read)(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
87+
size_t (*read)(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
88+
size_t (*async_read)(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
8989
size_t (*write)(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
9090
size_t (*async_write)(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
9191
int (*wait_io_or_timeout)(MARIADB_PVIO *pvio, my_bool is_read, int timeout);
@@ -103,7 +103,7 @@ struct st_ma_pvio_methods
103103
MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo);
104104
void ma_pvio_close(MARIADB_PVIO *pvio);
105105
size_t ma_pvio_cache_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
106-
size_t ma_pvio_read(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
106+
size_t ma_pvio_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
107107
size_t ma_pvio_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
108108
int ma_pvio_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type);
109109
my_bool ma_pvio_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout);

include/mysql_async.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extern int my_connect_async(MARIADB_PVIO *pvio,
2222
const struct sockaddr *name, uint namelen,
2323
int vio_timeout);
2424
extern ssize_t my_recv_async(MARIADB_PVIO *pvio,
25-
const unsigned char *buf, size_t size, int timeout);
25+
unsigned char *buf, size_t size, int timeout);
2626
extern ssize_t my_send_async(MARIADB_PVIO *pvio,
2727
const unsigned char *buf, size_t size,
2828
int timeout);

libmariadb/client_plugin.c.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static int get_plugin_nr(int type)
109109
return -1;
110110
}
111111

112-
static my_bool check_plugin_version(struct st_mysql_client_plugin *plugin, int version, char *errmsg)
112+
static my_bool check_plugin_version(struct st_mysql_client_plugin *plugin, unsigned int version, char *errmsg)
113113
{
114114
if (plugin->interface_version < version ||
115115
(plugin->interface_version >> 8) > (version >> 8))

libmariadb/get_password.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ static char *get_password(FILE *file, char *buffer, int length)
5151
{
5252
char inChar;
5353
int CharsProcessed= 1;
54+
#ifdef _WIN32
55+
DWORD Offset= 0;
56+
#else
5457
int Offset= 0;
55-
58+
#endif
5659
memset(buffer, 0, length);
5760

5861
do

libmariadb/ma_pvio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ my_bool ma_pvio_set_timeout(MARIADB_PVIO *pvio,
170170
/* }}} */
171171

172172
/* {{{ size_t ma_pvio_read_async */
173-
static size_t ma_pvio_read_async(MARIADB_PVIO *pvio, const uchar *buffer, size_t length)
173+
static size_t ma_pvio_read_async(MARIADB_PVIO *pvio, uchar *buffer, size_t length)
174174
{
175175
ssize_t res;
176176
struct mysql_async_context *b= pvio->async_context;
@@ -201,7 +201,7 @@ static size_t ma_pvio_read_async(MARIADB_PVIO *pvio, const uchar *buffer, size_t
201201
/* }}} */
202202

203203
/* {{{ size_t ma_pvio_read */
204-
size_t ma_pvio_read(MARIADB_PVIO *pvio, const uchar *buffer, size_t length)
204+
size_t ma_pvio_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length)
205205
{
206206
size_t r= -1;
207207
if (!pvio)

libmariadb/mysql_async.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ my_connect_async(MARIADB_PVIO *pvio,
135135
#endif
136136

137137
ssize_t
138-
my_recv_async(MARIADB_PVIO *pvio, const unsigned char *buf, size_t size, int timeout)
138+
my_recv_async(MARIADB_PVIO *pvio, unsigned char *buf, size_t size, int timeout)
139139
{
140140
ssize_t res;
141141
struct mysql_async_context *b= pvio->async_context;

plugins/pvio/pvio_npipe.c

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,34 @@
3030
#include <string.h>
3131
#include <m_string.h>
3232

33-
#ifdef HAVE_NPIPE_DYNAMIC
34-
#define my_malloc(A, B) malloc((A))
35-
#undef my_free
36-
#define my_free(A,B) free(((A)))
37-
#endif
38-
3933
/* Function prototypes */
4034
my_bool pvio_npipe_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout);
4135
int pvio_npipe_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type);
4236
size_t pvio_npipe_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
43-
size_t pvio_npipe_write(MARIADB_PVIO *pvio, uchar *buffer, size_t length);
37+
size_t pvio_npipe_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length);
4438
int pvio_npipe_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout);
4539
my_bool pvio_npipe_blocking(MARIADB_PVIO *pvio, my_bool value, my_bool *old_value);
4640
my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo);
4741
my_bool pvio_npipe_close(MARIADB_PVIO *pvio);
4842
int pvio_npipe_fast_send(MARIADB_PVIO *pvio);
4943
int pvio_npipe_keepalive(MARIADB_PVIO *pvio);
50-
my_socket pvio_npipe_get_socket(MARIADB_PVIO *pvio);
44+
my_bool pvio_npipe_get_handle(MARIADB_PVIO *pvio, void *handle);
5145
my_bool pvio_npipe_is_blocking(MARIADB_PVIO *pvio);
5246

5347
struct st_ma_pvio_methods pvio_npipe_methods= {
5448
pvio_npipe_set_timeout,
5549
pvio_npipe_get_timeout,
5650
pvio_npipe_read,
51+
NULL,
5752
pvio_npipe_write,
53+
NULL,
5854
pvio_npipe_wait_io_or_timeout,
5955
pvio_npipe_blocking,
6056
pvio_npipe_connect,
6157
pvio_npipe_close,
6258
pvio_npipe_fast_send,
6359
pvio_npipe_keepalive,
64-
pvio_npipe_get_socket,
60+
pvio_npipe_get_handle,
6561
pvio_npipe_is_blocking
6662
};
6763

@@ -87,7 +83,6 @@ struct st_pvio_npipe {
8783
HANDLE pipe;
8884
OVERLAPPED overlapped;
8985
size_t rw_size;
90-
int fcntl_mode;
9186
MYSQL *mysql;
9287
};
9388

@@ -117,7 +112,7 @@ size_t pvio_npipe_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length)
117112

118113
cpipe= (struct st_pvio_npipe *)pvio->data;
119114

120-
if (ReadFile(cpipe->pipe, buffer, length, &dwRead, &cpipe->overlapped))
115+
if (ReadFile(cpipe->pipe, (LPVOID)buffer, length, &dwRead, &cpipe->overlapped))
121116
{
122117
r= (size_t)dwRead;
123118
goto end;
@@ -131,7 +126,7 @@ size_t pvio_npipe_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length)
131126
return r;
132127
}
133128

134-
size_t pvio_npipe_write(MARIADB_PVIO *pvio, uchar *buffer, size_t length)
129+
size_t pvio_npipe_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length)
135130
{
136131
DWORD dwWrite= 0;
137132
size_t r= -1;
@@ -171,10 +166,11 @@ int pvio_npipe_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeo
171166
status= WaitForSingleObject(cpipe->overlapped.hEvent, timeout);
172167
if (status == WAIT_OBJECT_0)
173168
{
174-
if (GetOverlappedResult(cpipe->pipe, &cpipe->overlapped, &cpipe->rw_size, FALSE))
169+
if (GetOverlappedResult(cpipe->pipe, &cpipe->overlapped, (LPDWORD)&cpipe->rw_size, FALSE))
175170
return 0;
176171
}
177-
/* other status codes are: WAIT_ABANDONED, WAIT_TIMEOUT and WAIT_FAILED */
172+
/* For other status codes (WAIT_ABANDONED, WAIT_TIMEOUT and WAIT_FAILED)
173+
we return error */
178174
save_error= GetLastError();
179175
CancelIo(cpipe->pipe);
180176
SetLastError(save_error);
@@ -184,12 +180,27 @@ int pvio_npipe_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeo
184180
my_bool pvio_npipe_blocking(MARIADB_PVIO *pvio, my_bool block, my_bool *previous_mode)
185181
{
186182
/* not supported */
183+
DWORD flags= 0;
184+
struct st_pvio_npipe *cpipe= NULL;
185+
186+
cpipe= (struct st_pvio_npipe *)pvio->data;
187+
188+
if (previous_mode)
189+
{
190+
if (!GetNamedPipeHandleState(cpipe->pipe, &flags, NULL, NULL, NULL, NULL, 0))
191+
return 1;
192+
*previous_mode= flags & PIPE_NOWAIT ? 0 : 1;
193+
}
194+
195+
flags= block ? PIPE_WAIT : PIPE_NOWAIT;
196+
if (!SetNamedPipeHandleState(cpipe->pipe, &flags, NULL, NULL))
197+
return 1;
187198
return 0;
188199
}
189200

190201
int pvio_npipe_keepalive(MARIADB_PVIO *pvio)
191202
{
192-
/* not supported */
203+
/* keep alive is used for TCP/IP connections only */
193204
return 0;
194205
}
195206

@@ -205,7 +216,7 @@ my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo)
205216
if (!pvio || !cinfo)
206217
return 1;
207218

208-
if (!(cpipe= (struct st_pvio_npipe *)my_malloc(sizeof(struct st_pvio_npipe), MYF(0))))
219+
if (!(cpipe= (struct st_pvio_npipe *)LocalAlloc(sizeof(struct st_pvio_npipe), 0)))
209220
{
210221
PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0, "");
211222
return 1;
@@ -244,14 +255,14 @@ my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo)
244255

245256
if (GetLastError() != ERROR_PIPE_BUSY)
246257
{
247-
pvio->set_error(pvio, CR_NAMEDPIPEOPEN_ERROR, SQLSTATE_UNKNOWN, 0,
258+
pvio->set_error(pvio->mysql, CR_NAMEDPIPEOPEN_ERROR, SQLSTATE_UNKNOWN, 0,
248259
cinfo->host, cinfo->unix_socket, GetLastError());
249260
goto end;
250261
}
251262

252263
if (has_timedout || !WaitNamedPipe(szPipeName, pvio->timeout[PVIO_CONNECT_TIMEOUT]))
253264
{
254-
pvio->set_error(pvio, CR_NAMEDPIPEWAIT_ERROR, SQLSTATE_UNKNOWN, 0,
265+
pvio->set_error(pvio->mysql, CR_NAMEDPIPEWAIT_ERROR, SQLSTATE_UNKNOWN, 0,
255266
cinfo->host, cinfo->unix_socket, GetLastError());
256267
goto end;
257268
}
@@ -261,15 +272,15 @@ my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo)
261272
dwMode = PIPE_READMODE_BYTE | PIPE_WAIT;
262273
if (!SetNamedPipeHandleState(cpipe->pipe, &dwMode, NULL, NULL))
263274
{
264-
pvio->set_error(pvio, CR_NAMEDPIPESETSTATE_ERROR, SQLSTATE_UNKNOWN, 0,
275+
pvio->set_error(pvio->mysql, CR_NAMEDPIPESETSTATE_ERROR, SQLSTATE_UNKNOWN, 0,
265276
cinfo->host, cinfo->unix_socket, (ulong) GetLastError());
266277
goto end;
267278
}
268279

269280
/* Register event handler for overlapped IO */
270281
if (!(cpipe->overlapped.hEvent= CreateEvent(NULL, FALSE, FALSE, NULL)))
271282
{
272-
pvio->set_error(pvio, CR_EVENT_CREATE_FAILED, SQLSTATE_UNKNOWN, 0,
283+
pvio->set_error(pvio->mysql, CR_EVENT_CREATE_FAILED, SQLSTATE_UNKNOWN, 0,
273284
GetLastError());
274285
goto end;
275286
}
@@ -280,7 +291,7 @@ my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo)
280291
{
281292
if (cpipe->pipe != INVALID_HANDLE_VALUE)
282293
CloseHandle(cpipe->pipe);
283-
my_free((gptr)cpipe, MYF(0));
294+
LocalFree(cpipe);
284295
pvio->data= NULL;
285296
}
286297
return 1;
@@ -303,22 +314,32 @@ my_bool pvio_npipe_close(MARIADB_PVIO *pvio)
303314
CloseHandle(cpipe->pipe);
304315
cpipe->pipe= INVALID_HANDLE_VALUE;
305316
}
306-
my_free((gptr)pvio->data, MYF(0));
317+
LocalFree(pvio->data);
307318
pvio->data= NULL;
308319
}
309320
return r;
310321
}
311322

312-
my_socket pvio_npipe_get_socket(MARIADB_PVIO *pvio)
323+
my_bool pvio_npipe_get_handle(MARIADB_PVIO *pvio, void *handle)
313324
{
314325
if (pvio && pvio->data)
315-
return (my_socket)((struct st_pvio_npipe *)pvio->data)->pipe;
316-
return INVALID_SOCKET;
326+
{
327+
*(HANDLE *)handle= ((struct st_pvio_npipe *)pvio->data)->pipe;
328+
return 0;
329+
}
330+
return 1;
317331
}
318332

319333
my_bool pvio_npipe_is_blocking(MARIADB_PVIO *pvio)
320334
{
321-
return 1;
335+
DWORD flags= 0;
336+
struct st_pvio_npipe *cpipe= NULL;
337+
338+
cpipe= (struct st_pvio_npipe *)pvio->data;
339+
340+
if (!GetNamedPipeHandleState(cpipe->pipe, &flags, NULL, NULL, NULL, NULL, 0))
341+
return 1;
342+
return (flags & PIPE_NOWAIT) ? 0 : 1;
322343
}
323344

324345
#endif

0 commit comments

Comments
 (0)