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