18
18
* Purpose: include file for Vio that will work with C and C++
21
#ifndef PLUGIN_DRIZZLE_PROTOCOL_VIO_H
22
#define PLUGIN_DRIZZLE_PROTOCOL_VIO_H
24
#include <sys/socket.h>
21
#ifndef vio_violite_h_
22
#define vio_violite_h_
24
#include "my_net.h" /* needed because of struct in_addr */
27
27
/* Simple vio interface in C; The functions are implemented in violite.c */
31
#endif /* __cplusplus */
31
35
VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, VIO_TYPE_NAMEDPIPE,
32
36
VIO_TYPE_SSL, VIO_TYPE_SHARED_MEMORY
35
typedef struct st_vio Vio;
40
#define VIO_LOCALHOST 1 /* a localhost connection */
37
41
#define VIO_BUFFERED_READ 2 /* use buffered read */
38
42
#define VIO_READ_BUFFER_SIZE 16384 /* size of read buffer */
40
Vio* drizzleclient_vio_new(int sd, enum enum_vio_type type, unsigned int flags);
44
Vio* vio_new(my_socket sd, enum enum_vio_type type, uint flags);
42
void drizzleclient_vio_delete(Vio* vio);
43
int drizzleclient_vio_close(Vio* vio);
44
void drizzleclient_vio_reset(Vio* vio, enum enum_vio_type type, int sd, uint32_t flags);
45
size_t drizzleclient_vio_read(Vio *vio, unsigned char * buf, size_t size);
46
size_t drizzleclient_vio_read_buff(Vio *vio, unsigned char * buf, size_t size);
47
size_t drizzleclient_vio_write(Vio *vio, const unsigned char * buf, size_t size);
48
int drizzleclient_vio_blocking(Vio *vio, bool onoff, bool *old_mode);
49
bool drizzleclient_vio_is_blocking(Vio *vio);
47
void vio_delete(Vio* vio);
48
int vio_close(Vio* vio);
49
void vio_reset(Vio* vio, enum enum_vio_type type,
50
my_socket sd, HANDLE hPipe, uint flags);
51
size_t vio_read(Vio *vio, uchar * buf, size_t size);
52
size_t vio_read_buff(Vio *vio, uchar * buf, size_t size);
53
size_t vio_write(Vio *vio, const uchar * buf, size_t size);
54
int vio_blocking(Vio *vio, my_bool onoff, my_bool *old_mode);
55
my_bool vio_is_blocking(Vio *vio);
50
56
/* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible */
51
int drizzleclient_vio_fastsend(Vio *vio);
57
int vio_fastsend(Vio *vio);
52
58
/* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible */
53
int32_t drizzleclient_vio_keepalive(Vio *vio, bool onoff);
59
int vio_keepalive(Vio *vio, my_bool onoff);
54
60
/* Whenever we should retry the last read/write operation. */
55
bool drizzleclient_vio_should_retry(Vio *vio);
61
my_bool vio_should_retry(Vio *vio);
56
62
/* Check that operation was timed out */
57
bool drizzleclient_vio_was_interrupted(Vio *vio);
63
my_bool vio_was_interrupted(Vio *vio);
58
64
/* Short text description of the socket for those, who are curious.. */
59
const char* drizzleclient_vio_description(Vio *vio);
65
const char* vio_description(Vio *vio);
60
66
/* Return the type of the connection */
61
enum enum_vio_type drizzleclient_vio_type(Vio* vio);
67
enum enum_vio_type vio_type(Vio* vio);
62
68
/* Return last error number */
63
int drizzleclient_vio_errno(Vio*vio);
69
int vio_errno(Vio*vio);
64
70
/* Get socket number */
65
int drizzleclient_vio_fd(Vio*vio);
71
my_socket vio_fd(Vio*vio);
66
72
/* Remote peer's address and name in text form */
67
bool drizzleclient_vio_peer_addr(Vio *vio, char *buf, uint16_t *port, size_t buflen);
68
bool drizzleclient_vio_poll_read(Vio *vio, int timeout);
69
bool drizzleclient_vio_peek_read(Vio *vio, unsigned int *bytes);
71
void drizzleclient_vio_end(void);
73
void drizzleclient_vio_ignore_timeout(Vio *vio, bool is_sndtimeo, int32_t timeout);
74
void drizzleclient_vio_timeout(Vio *vio, bool is_sndtimeo, int32_t timeout);
73
my_bool vio_peer_addr(Vio *vio, char *buf, uint16 *port, size_t buflen);
74
my_bool vio_poll_read(Vio *vio,uint timeout);
75
my_bool vio_peek_read(Vio *vio, uint *bytes);
78
#include <openssl/opensslv.h>
79
#if OPENSSL_VERSION_NUMBER < 0x0090700f
80
#define DES_cblock des_cblock
81
#define DES_key_schedule des_key_schedule
82
#define DES_set_key_unchecked(k,ks) des_set_key_unchecked((k),*(ks))
83
#define DES_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e) des_ede3_cbc_encrypt((i),(o),(l),*(k1),*(k2),*(k3),(iv),(e))
86
#define HEADER_DES_LOCL_H dummy_something
87
#define YASSL_MYSQL_COMPATIBLE
91
/* Set yaSSL to use same type as MySQL do for socket handles */
92
typedef my_socket YASSL_SOCKET_T;
93
#define YASSL_SOCKET_T_DEFINED
94
#include <openssl/ssl.h>
95
#include <openssl/err.h>
97
#ifndef EMBEDDED_LIBRARY
101
SSL_CTX *ssl_context;
104
int sslaccept(struct st_VioSSLFd*, Vio *, long timeout);
105
int sslconnect(struct st_VioSSLFd*, Vio *, long timeout);
108
*new_VioSSLConnectorFd(const char *key_file, const char *cert_file,
109
const char *ca_file, const char *ca_path,
112
*new_VioSSLAcceptorFd(const char *key_file, const char *cert_file,
113
const char *ca_file,const char *ca_path,
115
void free_vio_ssl_acceptor_fd(struct st_VioSSLFd *fd);
116
#endif /* ! EMBEDDED_LIBRARY */
117
#endif /* HAVE_OPENSSL */
120
size_t vio_read_shared_memory(Vio *vio, uchar * buf, size_t size);
121
size_t vio_write_shared_memory(Vio *vio, const uchar * buf, size_t size);
122
int vio_close_shared_memory(Vio * vio);
76
131
#if !defined(DONT_MAP_VIO)
77
#define drizzleclient_vio_delete(vio) (vio)->viodelete(vio)
78
#define drizzleclient_vio_errno(vio) (vio)->vioerrno(vio)
79
#define drizzleclient_vio_read(vio, buf, size) ((vio)->read)(vio,buf,size)
80
#define drizzleclient_vio_write(vio, buf, size) ((vio)->write)(vio, buf, size)
81
#define drizzleclient_vio_blocking(vio, set_blocking_mode, old_mode)\
132
#define vio_delete(vio) (vio)->viodelete(vio)
133
#define vio_errno(vio) (vio)->vioerrno(vio)
134
#define vio_read(vio, buf, size) ((vio)->read)(vio,buf,size)
135
#define vio_write(vio, buf, size) ((vio)->write)(vio, buf, size)
136
#define vio_blocking(vio, set_blocking_mode, old_mode)\
82
137
(vio)->vioblocking(vio, set_blocking_mode, old_mode)
83
#define drizzleclient_vio_is_blocking(vio) (vio)->is_blocking(vio)
84
#define drizzleclient_vio_fastsend(vio) (vio)->fastsend(vio)
85
#define drizzleclient_vio_keepalive(vio, set_keep_alive) (vio)->viokeepalive(vio, set_keep_alive)
86
#define drizzleclient_vio_should_retry(vio) (vio)->should_retry(vio)
87
#define drizzleclient_vio_was_interrupted(vio) (vio)->was_interrupted(vio)
88
#define drizzleclient_vio_close(vio) ((vio)->vioclose)(vio)
89
#define drizzleclient_vio_peer_addr(vio, buf, prt, buflen) (vio)->peer_addr(vio, buf, prt, buflen)
90
#define drizzleclient_vio_timeout(vio, which, seconds) (vio)->timeout(vio, which, seconds)
138
#define vio_is_blocking(vio) (vio)->is_blocking(vio)
139
#define vio_fastsend(vio) (vio)->fastsend(vio)
140
#define vio_keepalive(vio, set_keep_alive) (vio)->viokeepalive(vio, set_keep_alive)
141
#define vio_should_retry(vio) (vio)->should_retry(vio)
142
#define vio_was_interrupted(vio) (vio)->was_interrupted(vio)
143
#define vio_close(vio) ((vio)->vioclose)(vio)
144
#define vio_peer_addr(vio, buf, prt, buflen) (vio)->peer_addr(vio, buf, prt, buflen)
145
#define vio_timeout(vio, which, seconds) (vio)->timeout(vio, which, seconds)
91
146
#endif /* !defined(DONT_MAP_VIO) */
93
148
/* This enumerator is used in parser - should be always visible */
100
155
SSL_TYPE_SPECIFIED
103
159
/* HFTODO - hide this if we don't want client in embedded server */
104
160
/* This structure is for every connection on both sides */
107
int sd; /* int - real or imaginary */
163
my_socket sd; /* my_socket - real or imaginary */
165
my_bool localhost; /* Are we from localhost? */
108
166
int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */
109
167
struct sockaddr_storage local; /* Local internet address */
110
168
struct sockaddr_storage remote; /* Remote internet address */
111
169
int addrLen; /* Length of remote address */
112
170
enum enum_vio_type type; /* Type of connection */
113
171
char desc[30]; /* String description */
172
char *read_buffer; /* buffer for vio_read_buff */
114
173
char *read_pos; /* start of unfetched data in the
116
175
char *read_end; /* end of unfetched data */
118
176
/* function pointers. They are similar for socket/SSL/whatever */
119
177
void (*viodelete)(Vio*);
120
int32_t (*vioerrno)(Vio*);
121
size_t (*read)(Vio*, unsigned char *, size_t);
122
size_t (*write)(Vio*, const unsigned char *, size_t);
123
int32_t (*vioblocking)(Vio*, bool, bool *);
124
bool (*is_blocking)(Vio*);
125
int32_t (*viokeepalive)(Vio*, bool);
126
int32_t (*fastsend)(Vio*);
127
bool (*peer_addr)(Vio*, char *, uint16_t *, size_t);
178
int (*vioerrno)(Vio*);
179
size_t (*read)(Vio*, uchar *, size_t);
180
size_t (*write)(Vio*, const uchar *, size_t);
181
int (*vioblocking)(Vio*, my_bool, my_bool *);
182
my_bool (*is_blocking)(Vio*);
183
int (*viokeepalive)(Vio*, my_bool);
184
int (*fastsend)(Vio*);
185
my_bool (*peer_addr)(Vio*, char *, uint16*, size_t);
128
186
void (*in_addr)(Vio*, struct sockaddr_storage*);
129
bool (*should_retry)(Vio*);
130
bool (*was_interrupted)(Vio*);
131
int32_t (*vioclose)(Vio*);
132
void (*timeout)(Vio*, bool is_sndtimeo, int32_t timeout);
133
char *read_buffer; /* buffer for drizzleclient_vio_read_buff */
187
my_bool (*should_retry)(Vio*);
188
my_bool (*was_interrupted)(Vio*);
189
int (*vioclose)(Vio*);
190
void (*timeout)(Vio*, unsigned int which, unsigned int timeout);
195
HANDLE handle_file_map;
197
HANDLE event_server_wrote;
198
HANDLE event_server_read;
199
HANDLE event_client_wrote;
200
HANDLE event_client_read;
201
HANDLE event_conn_closed;
202
size_t shared_memory_remain;
203
char *shared_memory_pos;
205
#endif /* HAVE_SMEM */
136
#endif /* PLUGIN_DRIZZLE_PROTOCOL_VIO_H */
207
#endif /* vio_violite_h_ */