ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro-Mysql/violite.h
Revision: 1.2
Committed: Tue Aug 31 14:42:29 2010 UTC (13 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-1_1, rel-1_02, rel-1_01
Changes since 1.1: +12 -10 lines
Log Message:
1.01

File Contents

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