~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to include/violite.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 MySQL AB
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
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 */
 
15
 
 
16
/*
 
17
 * Vio Lite.
 
18
 * Purpose: include file for Vio that will work with C and C++
 
19
 */
 
20
 
 
21
#ifndef vio_violite_h_
 
22
#define vio_violite_h_
 
23
 
 
24
#include "my_net.h"                     /* needed because of struct in_addr */
 
25
 
 
26
 
 
27
/* Simple vio interface in C;  The functions are implemented in violite.c */
 
28
 
 
29
#ifdef  __cplusplus
 
30
extern "C" {
 
31
#endif /* __cplusplus */
 
32
 
 
33
enum enum_vio_type
 
34
{
 
35
  VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, VIO_TYPE_NAMEDPIPE,
 
36
  VIO_TYPE_SSL, VIO_TYPE_SHARED_MEMORY
 
37
};
 
38
 
 
39
 
 
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 */
 
43
 
 
44
Vio*    vio_new(my_socket sd, enum enum_vio_type type, uint flags);
 
45
#ifdef __WIN__
 
46
Vio* vio_new_win32pipe(HANDLE hPipe);
 
47
Vio* vio_new_win32shared_memory(HANDLE handle_file_map,
 
48
                                HANDLE handle_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);
 
57
#else
 
58
#define HANDLE void *
 
59
#endif /* __WIN__ */
 
60
 
 
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);
 
88
/* Remotes in_addr */
 
89
void    vio_in_addr(Vio *vio, struct in_addr *in);
 
90
my_bool vio_poll_read(Vio *vio,uint timeout);
 
91
 
 
92
#ifdef HAVE_OPENSSL
 
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))
 
99
#endif
 
100
 
 
101
#define HEADER_DES_LOCL_H dummy_something
 
102
#define YASSL_MYSQL_COMPATIBLE
 
103
#ifndef YASSL_PREFIX
 
104
#define YASSL_PREFIX
 
105
#endif
 
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>
 
111
 
 
112
enum enum_ssl_init_error
 
113
{
 
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
 
117
};
 
118
const char* sslGetErrString(enum enum_ssl_init_error err);
 
119
 
 
120
struct st_VioSSLFd
 
121
{
 
122
  SSL_CTX *ssl_context;
 
123
};
 
124
 
 
125
int sslaccept(struct st_VioSSLFd*, Vio *, long timeout);
 
126
int sslconnect(struct st_VioSSLFd*, Vio *, long timeout);
 
127
 
 
128
struct st_VioSSLFd
 
129
*new_VioSSLConnectorFd(const char *key_file, const char *cert_file,
 
130
                       const char *ca_file,  const char *ca_path,
 
131
                       const char *cipher);
 
132
struct st_VioSSLFd
 
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 */
 
138
 
 
139
#ifdef HAVE_SMEM
 
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);
 
143
#endif
 
144
 
 
145
void vio_end(void);
 
146
 
 
147
#ifdef  __cplusplus
 
148
}
 
149
#endif
 
150
 
 
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) */
 
168
 
 
169
/* This enumerator is used in parser - should be always visible */
 
170
enum SSL_type
 
171
{
 
172
  SSL_TYPE_NOT_SPECIFIED= -1,
 
173
  SSL_TYPE_NONE,
 
174
  SSL_TYPE_ANY,
 
175
  SSL_TYPE_X509,
 
176
  SSL_TYPE_SPECIFIED
 
177
};
 
178
 
 
179
 
 
180
/* HFTODO - hide this if we don't want client in embedded server */
 
181
/* This structure is for every connection on both sides */
 
182
struct st_vio
 
183
{
 
184
  my_socket             sd;             /* my_socket - real or imaginary */
 
185
  HANDLE hPipe;
 
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
 
194
                                           read buffer */
 
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);
 
211
#ifdef HAVE_OPENSSL
 
212
  void    *ssl_arg;
 
213
#endif
 
214
#ifdef HAVE_SMEM
 
215
  HANDLE  handle_file_map;
 
216
  char    *handle_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 */
 
225
#ifdef _WIN32
 
226
  OVERLAPPED pipe_overlapped;
 
227
  DWORD read_timeout_ms;
 
228
  DWORD write_timeout_ms;
 
229
#endif
 
230
};
 
231
#endif /* vio_violite_h_ */