1 |
/* adapted from violite.h from mysql 5.0.51 *( |
2 |
/* all modifications public domain */ |
3 |
/* Copyright (C) 2000 MySQL AB |
4 |
|
5 |
This program is free software; you can redistribute it and/or modify |
6 |
it under the terms of the GNU General Public License as published by |
7 |
the Free Software Foundation; version 2 of the License. |
8 |
|
9 |
This program is distributed in the hope that it will be useful, |
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
GNU General Public License for more details. |
13 |
|
14 |
You should have received a copy of the GNU General Public License |
15 |
along with this program; if not, write to the Free Software |
16 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
17 |
|
18 |
/* |
19 |
* Vio Lite. |
20 |
* Purpose: include file for Vio that will work with C and C++ |
21 |
*/ |
22 |
|
23 |
#ifndef vio_violite_h_ |
24 |
#define vio_violite_h_ |
25 |
|
26 |
/* Simple vio interface in C; The functions are implemented in violite.c */ |
27 |
|
28 |
#ifdef __cplusplus |
29 |
extern "C" { |
30 |
#endif /* __cplusplus */ |
31 |
|
32 |
enum enum_vio_type |
33 |
{ |
34 |
VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, VIO_TYPE_NAMEDPIPE, |
35 |
VIO_TYPE_SSL, VIO_TYPE_SHARED_MEMORY |
36 |
}; |
37 |
|
38 |
|
39 |
#define VIO_LOCALHOST 1 /* a localhost connection */ |
40 |
#define VIO_BUFFERED_READ 2 /* use buffered read */ |
41 |
#define VIO_READ_BUFFER_SIZE 16384 /* size of read buffer */ |
42 |
|
43 |
Vio* vio_new(my_socket sd, enum enum_vio_type type, uint flags); |
44 |
#ifdef __WIN__ |
45 |
Vio* vio_new_win32pipe(HANDLE hPipe); |
46 |
Vio* vio_new_win32shared_memory(NET *net,HANDLE handle_file_map, |
47 |
HANDLE handle_map, |
48 |
HANDLE event_server_wrote, |
49 |
HANDLE event_server_read, |
50 |
HANDLE event_client_wrote, |
51 |
HANDLE event_client_read, |
52 |
HANDLE event_conn_closed); |
53 |
int vio_read_pipe(Vio *vio, gptr buf, int size); |
54 |
int vio_write_pipe(Vio *vio, const gptr buf, int size); |
55 |
int vio_close_pipe(Vio * vio); |
56 |
#else |
57 |
#define HANDLE void * |
58 |
#endif /* __WIN__ */ |
59 |
|
60 |
void vio_delete(Vio* vio); |
61 |
int vio_close(Vio* vio); |
62 |
void vio_reset(Vio* vio, enum enum_vio_type type, |
63 |
my_socket sd, HANDLE hPipe, uint flags); |
64 |
int vio_read(Vio *vio, gptr buf, int size); |
65 |
int vio_read_buff(Vio *vio, gptr buf, int size); |
66 |
int vio_write(Vio *vio, const gptr buf, int size); |
67 |
int vio_blocking(Vio *vio, my_bool onoff, my_bool *old_mode); |
68 |
my_bool vio_is_blocking(Vio *vio); |
69 |
/* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible */ |
70 |
int vio_fastsend(Vio *vio); |
71 |
/* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible */ |
72 |
int vio_keepalive(Vio *vio, my_bool onoff); |
73 |
/* Whenever we should retry the last read/write operation. */ |
74 |
my_bool vio_should_retry(Vio *vio); |
75 |
/* Check that operation was timed out */ |
76 |
my_bool vio_was_interrupted(Vio *vio); |
77 |
/* Short text description of the socket for those, who are curious.. */ |
78 |
const char* vio_description(Vio *vio); |
79 |
/* Return the type of the connection */ |
80 |
enum enum_vio_type vio_type(Vio* vio); |
81 |
/* Return last error number */ |
82 |
int vio_errno(Vio*vio); |
83 |
/* Get socket number */ |
84 |
my_socket vio_fd(Vio*vio); |
85 |
/* Remote peer's address and name in text form */ |
86 |
my_bool vio_peer_addr(Vio* vio, char *buf, uint16 *port); |
87 |
/* Remotes in_addr */ |
88 |
void vio_in_addr(Vio *vio, struct in_addr *in); |
89 |
my_bool vio_poll_read(Vio *vio,uint timeout); |
90 |
|
91 |
#ifdef HAVE_OPENSSL |
92 |
#include <openssl/opensslv.h> |
93 |
#if OPENSSL_VERSION_NUMBER < 0x0090700f |
94 |
#define DES_cblock des_cblock |
95 |
#define DES_key_schedule des_key_schedule |
96 |
#define DES_set_key_unchecked(k,ks) des_set_key_unchecked((k),*(ks)) |
97 |
#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)) |
98 |
#endif |
99 |
|
100 |
#define HEADER_DES_LOCL_H dummy_something |
101 |
#define YASSL_MYSQL_COMPATIBLE |
102 |
#ifndef YASSL_PREFIX |
103 |
#define YASSL_PREFIX |
104 |
#endif |
105 |
/* Set yaSSL to use same type as MySQL do for socket handles */ |
106 |
typedef my_socket YASSL_SOCKET_T; |
107 |
#define YASSL_SOCKET_T_DEFINED |
108 |
#include <openssl/ssl.h> |
109 |
#include <openssl/err.h> |
110 |
|
111 |
struct st_VioSSLFd |
112 |
{ |
113 |
SSL_CTX *ssl_context; |
114 |
}; |
115 |
|
116 |
int sslaccept(struct st_VioSSLFd*, Vio *, long timeout); |
117 |
int sslconnect(struct st_VioSSLFd*, Vio *, long timeout); |
118 |
|
119 |
struct st_VioSSLFd |
120 |
*new_VioSSLConnectorFd(const char *key_file, const char *cert_file, |
121 |
const char *ca_file, const char *ca_path, |
122 |
const char *cipher); |
123 |
struct st_VioSSLFd |
124 |
*new_VioSSLAcceptorFd(const char *key_file, const char *cert_file, |
125 |
const char *ca_file,const char *ca_path, |
126 |
const char *cipher); |
127 |
#endif /* HAVE_OPENSSL */ |
128 |
|
129 |
#ifdef HAVE_SMEM |
130 |
int vio_read_shared_memory(Vio *vio, gptr buf, int size); |
131 |
int vio_write_shared_memory(Vio *vio, const gptr buf, int size); |
132 |
int vio_close_shared_memory(Vio * vio); |
133 |
#endif |
134 |
|
135 |
void vio_end(void); |
136 |
|
137 |
#ifdef __cplusplus |
138 |
} |
139 |
#endif |
140 |
|
141 |
#if !defined(DONT_MAP_VIO) |
142 |
#define vio_delete(vio) (vio)->viodelete(vio) |
143 |
#define vio_errno(vio) (vio)->vioerrno(vio) |
144 |
#define vio_read(vio, buf, size) ((vio)->read)(vio,buf,size) |
145 |
#define vio_write(vio, buf, size) ((vio)->write)(vio, buf, size) |
146 |
#define vio_blocking(vio, set_blocking_mode, old_mode)\ |
147 |
(vio)->vioblocking(vio, set_blocking_mode, old_mode) |
148 |
#define vio_is_blocking(vio) (vio)->is_blocking(vio) |
149 |
#define vio_fastsend(vio) (vio)->fastsend(vio) |
150 |
#define vio_keepalive(vio, set_keep_alive) (vio)->viokeepalive(vio, set_keep_alive) |
151 |
#define vio_should_retry(vio) (vio)->should_retry(vio) |
152 |
#define vio_was_interrupted(vio) (vio)->was_interrupted(vio) |
153 |
#define vio_close(vio) ((vio)->vioclose)(vio) |
154 |
#define vio_peer_addr(vio, buf, prt) (vio)->peer_addr(vio, buf, prt) |
155 |
#define vio_in_addr(vio, in) (vio)->in_addr(vio, in) |
156 |
#define vio_timeout(vio, which, seconds) (vio)->timeout(vio, which, seconds) |
157 |
#endif /* !defined(DONT_MAP_VIO) */ |
158 |
|
159 |
/* This enumerator is used in parser - should be always visible */ |
160 |
enum SSL_type |
161 |
{ |
162 |
SSL_TYPE_NOT_SPECIFIED= -1, |
163 |
SSL_TYPE_NONE, |
164 |
SSL_TYPE_ANY, |
165 |
SSL_TYPE_X509, |
166 |
SSL_TYPE_SPECIFIED |
167 |
}; |
168 |
|
169 |
|
170 |
/* HFTODO - hide this if we don't want client in embedded server */ |
171 |
/* This structure is for every connection on both sides */ |
172 |
struct st_vio |
173 |
{ |
174 |
my_socket sd; /* my_socket - real or imaginary */ |
175 |
HANDLE hPipe; |
176 |
my_bool localhost; /* Are we from localhost? */ |
177 |
int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */ |
178 |
struct sockaddr_in local; /* Local internet address */ |
179 |
struct sockaddr_in remote; /* Remote internet address */ |
180 |
enum enum_vio_type type; /* Type of connection */ |
181 |
char desc[30]; /* String description */ |
182 |
char *read_buffer; /* buffer for vio_read_buff */ |
183 |
char *read_pos; /* start of unfetched data in the |
184 |
read buffer */ |
185 |
char *read_end; /* end of unfetched data */ |
186 |
/* function pointers. They are similar for socket/SSL/whatever */ |
187 |
void (*viodelete)(Vio*); |
188 |
int (*vioerrno)(Vio*); |
189 |
int (*read)(Vio*, gptr, int); |
190 |
int (*write)(Vio*, const gptr, int); |
191 |
int (*vioblocking)(Vio*, my_bool, my_bool *); |
192 |
my_bool (*is_blocking)(Vio*); |
193 |
int (*viokeepalive)(Vio*, my_bool); |
194 |
int (*fastsend)(Vio*); |
195 |
my_bool (*peer_addr)(Vio*, char *, uint16*); |
196 |
void (*in_addr)(Vio*, struct in_addr*); |
197 |
my_bool (*should_retry)(Vio*); |
198 |
my_bool (*was_interrupted)(Vio*); |
199 |
int (*vioclose)(Vio*); |
200 |
void (*timeout)(Vio*, unsigned int which, unsigned int timeout); |
201 |
#ifdef HAVE_OPENSSL |
202 |
void *ssl_arg; |
203 |
#endif |
204 |
#ifdef HAVE_SMEM |
205 |
HANDLE handle_file_map; |
206 |
char *handle_map; |
207 |
HANDLE event_server_wrote; |
208 |
HANDLE event_server_read; |
209 |
HANDLE event_client_wrote; |
210 |
HANDLE event_client_read; |
211 |
HANDLE event_conn_closed; |
212 |
long shared_memory_remain; |
213 |
char *shared_memory_pos; |
214 |
NET *net; |
215 |
#endif /* HAVE_SMEM */ |
216 |
}; |
217 |
#endif /* vio_violite_h_ */ |