1
/* Copyright (C) 2000 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
* Purpose: include file for Vio that will work with C and C++
21
#ifndef vio_violite_h_
22
#define vio_violite_h_
24
#include "my_net.h" /* needed because of struct in_addr */
27
/* Simple vio interface in C; The functions are implemented in violite.c */
31
#endif /* __cplusplus */
35
VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, VIO_TYPE_NAMEDPIPE,
36
VIO_TYPE_SSL, VIO_TYPE_SHARED_MEMORY
40
#define VIO_LOCALHOST 1 /* a localhost connection */
41
#define VIO_BUFFERED_READ 2 /* use buffered read */
42
#define VIO_READ_BUFFER_SIZE 16384 /* size of read buffer */
44
Vio* vio_new(my_socket sd, enum enum_vio_type type, uint flags);
46
Vio* vio_new_win32pipe(HANDLE hPipe);
47
Vio* vio_new_win32shared_memory(HANDLE handle_file_map,
49
HANDLE event_server_wrote,
50
HANDLE event_server_read,
51
HANDLE event_client_wrote,
52
HANDLE event_client_read,
53
HANDLE event_conn_closed);
54
size_t vio_read_pipe(Vio *vio, uchar * buf, size_t size);
55
size_t vio_write_pipe(Vio *vio, const uchar * buf, size_t size);
56
int vio_close_pipe(Vio * vio);
61
void vio_delete(Vio* vio);
62
int vio_close(Vio* vio);
63
void vio_reset(Vio* vio, enum enum_vio_type type,
64
my_socket sd, HANDLE hPipe, uint flags);
65
size_t vio_read(Vio *vio, uchar * buf, size_t size);
66
size_t vio_read_buff(Vio *vio, uchar * buf, size_t size);
67
size_t vio_write(Vio *vio, const uchar * buf, size_t size);
68
int vio_blocking(Vio *vio, my_bool onoff, my_bool *old_mode);
69
my_bool vio_is_blocking(Vio *vio);
70
/* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible */
71
int vio_fastsend(Vio *vio);
72
/* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible */
73
int vio_keepalive(Vio *vio, my_bool onoff);
74
/* Whenever we should retry the last read/write operation. */
75
my_bool vio_should_retry(Vio *vio);
76
/* Check that operation was timed out */
77
my_bool vio_was_interrupted(Vio *vio);
78
/* Short text description of the socket for those, who are curious.. */
79
const char* vio_description(Vio *vio);
80
/* Return the type of the connection */
81
enum enum_vio_type vio_type(Vio* vio);
82
/* Return last error number */
83
int vio_errno(Vio*vio);
84
/* Get socket number */
85
my_socket vio_fd(Vio*vio);
86
/* Remote peer's address and name in text form */
87
my_bool vio_peer_addr(Vio* vio, char *buf, uint16 *port);
89
void vio_in_addr(Vio *vio, struct in_addr *in);
90
my_bool vio_poll_read(Vio *vio,uint timeout);
93
#include <openssl/opensslv.h>
94
#if OPENSSL_VERSION_NUMBER < 0x0090700f
95
#define DES_cblock des_cblock
96
#define DES_key_schedule des_key_schedule
97
#define DES_set_key_unchecked(k,ks) des_set_key_unchecked((k),*(ks))
98
#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))
101
#define HEADER_DES_LOCL_H dummy_something
102
#define YASSL_MYSQL_COMPATIBLE
106
/* Set yaSSL to use same type as MySQL do for socket handles */
107
typedef my_socket YASSL_SOCKET_T;
108
#define YASSL_SOCKET_T_DEFINED
109
#include <openssl/ssl.h>
110
#include <openssl/err.h>
112
enum enum_ssl_init_error
114
SSL_INITERR_NOERROR= 0, SSL_INITERR_CERT, SSL_INITERR_KEY,
115
SSL_INITERR_NOMATCH, SSL_INITERR_BAD_PATHS, SSL_INITERR_CIPHERS,
116
SSL_INITERR_MEMFAIL, SSL_INITERR_LASTERR
118
const char* sslGetErrString(enum enum_ssl_init_error err);
122
SSL_CTX *ssl_context;
125
int sslaccept(struct st_VioSSLFd*, Vio *, long timeout);
126
int sslconnect(struct st_VioSSLFd*, Vio *, long timeout);
129
*new_VioSSLConnectorFd(const char *key_file, const char *cert_file,
130
const char *ca_file, const char *ca_path,
133
*new_VioSSLAcceptorFd(const char *key_file, const char *cert_file,
134
const char *ca_file,const char *ca_path,
135
const char *cipher, enum enum_ssl_init_error* error);
136
void free_vio_ssl_acceptor_fd(struct st_VioSSLFd *fd);
137
#endif /* HAVE_OPENSSL */
140
size_t vio_read_shared_memory(Vio *vio, uchar * buf, size_t size);
141
size_t vio_write_shared_memory(Vio *vio, const uchar * buf, size_t size);
142
int vio_close_shared_memory(Vio * vio);
151
#if !defined(DONT_MAP_VIO)
152
#define vio_delete(vio) (vio)->viodelete(vio)
153
#define vio_errno(vio) (vio)->vioerrno(vio)
154
#define vio_read(vio, buf, size) ((vio)->read)(vio,buf,size)
155
#define vio_write(vio, buf, size) ((vio)->write)(vio, buf, size)
156
#define vio_blocking(vio, set_blocking_mode, old_mode)\
157
(vio)->vioblocking(vio, set_blocking_mode, old_mode)
158
#define vio_is_blocking(vio) (vio)->is_blocking(vio)
159
#define vio_fastsend(vio) (vio)->fastsend(vio)
160
#define vio_keepalive(vio, set_keep_alive) (vio)->viokeepalive(vio, set_keep_alive)
161
#define vio_should_retry(vio) (vio)->should_retry(vio)
162
#define vio_was_interrupted(vio) (vio)->was_interrupted(vio)
163
#define vio_close(vio) ((vio)->vioclose)(vio)
164
#define vio_peer_addr(vio, buf, prt) (vio)->peer_addr(vio, buf, prt)
165
#define vio_in_addr(vio, in) (vio)->in_addr(vio, in)
166
#define vio_timeout(vio, which, seconds) (vio)->timeout(vio, which, seconds)
167
#endif /* !defined(DONT_MAP_VIO) */
169
/* This enumerator is used in parser - should be always visible */
172
SSL_TYPE_NOT_SPECIFIED= -1,
180
/* HFTODO - hide this if we don't want client in embedded server */
181
/* This structure is for every connection on both sides */
184
my_socket sd; /* my_socket - real or imaginary */
186
my_bool localhost; /* Are we from localhost? */
187
int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */
188
struct sockaddr_in local; /* Local internet address */
189
struct sockaddr_in remote; /* Remote internet address */
190
enum enum_vio_type type; /* Type of connection */
191
char desc[30]; /* String description */
192
char *read_buffer; /* buffer for vio_read_buff */
193
char *read_pos; /* start of unfetched data in the
195
char *read_end; /* end of unfetched data */
196
/* function pointers. They are similar for socket/SSL/whatever */
197
void (*viodelete)(Vio*);
198
int (*vioerrno)(Vio*);
199
size_t (*read)(Vio*, uchar *, size_t);
200
size_t (*write)(Vio*, const uchar *, size_t);
201
int (*vioblocking)(Vio*, my_bool, my_bool *);
202
my_bool (*is_blocking)(Vio*);
203
int (*viokeepalive)(Vio*, my_bool);
204
int (*fastsend)(Vio*);
205
my_bool (*peer_addr)(Vio*, char *, uint16*);
206
void (*in_addr)(Vio*, struct in_addr*);
207
my_bool (*should_retry)(Vio*);
208
my_bool (*was_interrupted)(Vio*);
209
int (*vioclose)(Vio*);
210
void (*timeout)(Vio*, unsigned int which, unsigned int timeout);
215
HANDLE handle_file_map;
217
HANDLE event_server_wrote;
218
HANDLE event_server_read;
219
HANDLE event_client_wrote;
220
HANDLE event_client_read;
221
HANDLE event_conn_closed;
222
size_t shared_memory_remain;
223
char *shared_memory_pos;
224
#endif /* HAVE_SMEM */
226
OVERLAPPED pipe_overlapped;
227
DWORD read_timeout_ms;
228
DWORD write_timeout_ms;
231
#endif /* vio_violite_h_ */