The world's most popular open source database
00001 /* Copyright (C) 2000 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 /* 00018 * Vio Lite. 00019 * Purpose: include file for Vio that will work with C and C++ 00020 */ 00021 00022 #ifndef vio_violite_h_ 00023 #define vio_violite_h_ 00024 00025 #include "my_net.h" /* needed because of struct in_addr */ 00026 00027 00028 /* Simple vio interface in C; The functions are implemented in violite.c */ 00029 00030 #ifdef __cplusplus 00031 extern "C" { 00032 #endif /* __cplusplus */ 00033 00034 enum enum_vio_type 00035 { 00036 VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, VIO_TYPE_NAMEDPIPE, 00037 VIO_TYPE_SSL, VIO_TYPE_SHARED_MEMORY 00038 }; 00039 00040 00041 #define VIO_LOCALHOST 1 /* a localhost connection */ 00042 #define VIO_BUFFERED_READ 2 /* use buffered read */ 00043 #define VIO_READ_BUFFER_SIZE 16384 /* size of read buffer */ 00044 00045 Vio* vio_new(my_socket sd, enum enum_vio_type type, uint flags); 00046 #ifdef __WIN__ 00047 Vio* vio_new_win32pipe(HANDLE hPipe); 00048 Vio* vio_new_win32shared_memory(NET *net,HANDLE handle_file_map, 00049 HANDLE handle_map, 00050 HANDLE event_server_wrote, 00051 HANDLE event_server_read, 00052 HANDLE event_client_wrote, 00053 HANDLE event_client_read, 00054 HANDLE event_conn_closed); 00055 int vio_read_pipe(Vio *vio, gptr buf, int size); 00056 int vio_write_pipe(Vio *vio, const gptr buf, int size); 00057 int vio_close_pipe(Vio * vio); 00058 #else 00059 #define HANDLE void * 00060 #endif /* __WIN__ */ 00061 00062 void vio_delete(Vio* vio); 00063 int vio_close(Vio* vio); 00064 void vio_reset(Vio* vio, enum enum_vio_type type, 00065 my_socket sd, HANDLE hPipe, uint flags); 00066 int vio_read(Vio *vio, gptr buf, int size); 00067 int vio_read_buff(Vio *vio, gptr buf, int size); 00068 int vio_write(Vio *vio, const gptr buf, int size); 00069 int vio_blocking(Vio *vio, my_bool onoff, my_bool *old_mode); 00070 my_bool vio_is_blocking(Vio *vio); 00071 /* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible */ 00072 int vio_fastsend(Vio *vio); 00073 /* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible */ 00074 int vio_keepalive(Vio *vio, my_bool onoff); 00075 /* Whenever we should retry the last read/write operation. */ 00076 my_bool vio_should_retry(Vio *vio); 00077 /* Check that operation was timed out */ 00078 my_bool vio_was_interrupted(Vio *vio); 00079 /* Short text description of the socket for those, who are curious.. */ 00080 const char* vio_description(Vio *vio); 00081 /* Return the type of the connection */ 00082 enum enum_vio_type vio_type(Vio* vio); 00083 /* Return last error number */ 00084 int vio_errno(Vio*vio); 00085 /* Get socket number */ 00086 my_socket vio_fd(Vio*vio); 00087 /* Remote peer's address and name in text form */ 00088 my_bool vio_peer_addr(Vio* vio, char *buf, uint16 *port); 00089 /* Remotes in_addr */ 00090 void vio_in_addr(Vio *vio, struct in_addr *in); 00091 my_bool vio_poll_read(Vio *vio,uint timeout); 00092 void vio_timeout(Vio *vio,uint which, uint timeout); 00093 00094 #ifdef HAVE_OPENSSL 00095 #include <openssl/opensslv.h> 00096 #if OPENSSL_VERSION_NUMBER < 0x0090700f 00097 #define DES_cblock des_cblock 00098 #define DES_key_schedule des_key_schedule 00099 #define DES_set_key_unchecked(k,ks) des_set_key_unchecked((k),*(ks)) 00100 #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)) 00101 #endif 00102 00103 #define HEADER_DES_LOCL_H dummy_something 00104 #define YASSL_MYSQL_COMPATIBLE 00105 #define YASSL_PREFIX 00106 #include <openssl/ssl.h> 00107 #include <openssl/err.h> 00108 00109 struct st_VioSSLFd 00110 { 00111 SSL_CTX *ssl_context; 00112 }; 00113 00114 int sslaccept(struct st_VioSSLFd*, Vio *, long timeout); 00115 int sslconnect(struct st_VioSSLFd*, Vio *, long timeout); 00116 00117 struct st_VioSSLFd 00118 *new_VioSSLConnectorFd(const char *key_file, const char *cert_file, 00119 const char *ca_file, const char *ca_path, 00120 const char *cipher); 00121 struct st_VioSSLFd 00122 *new_VioSSLAcceptorFd(const char *key_file, const char *cert_file, 00123 const char *ca_file,const char *ca_path, 00124 const char *cipher); 00125 void free_vio_ssl_acceptor_fd(struct st_VioSSLFd *fd); 00126 #endif /* HAVE_OPENSSL */ 00127 00128 #ifdef HAVE_SMEM 00129 int vio_read_shared_memory(Vio *vio, gptr buf, int size); 00130 int vio_write_shared_memory(Vio *vio, const gptr buf, int size); 00131 int vio_close_shared_memory(Vio * vio); 00132 #endif 00133 00134 void vio_end(void); 00135 00136 #ifdef __cplusplus 00137 } 00138 #endif 00139 00140 #if !defined(DONT_MAP_VIO) 00141 #define vio_delete(vio) (vio)->viodelete(vio) 00142 #define vio_errno(vio) (vio)->vioerrno(vio) 00143 #define vio_read(vio, buf, size) ((vio)->read)(vio,buf,size) 00144 #define vio_write(vio, buf, size) ((vio)->write)(vio, buf, size) 00145 #define vio_blocking(vio, set_blocking_mode, old_mode)\ 00146 (vio)->vioblocking(vio, set_blocking_mode, old_mode) 00147 #define vio_is_blocking(vio) (vio)->is_blocking(vio) 00148 #define vio_fastsend(vio) (vio)->fastsend(vio) 00149 #define vio_keepalive(vio, set_keep_alive) (vio)->viokeepalive(vio, set_keep_alive) 00150 #define vio_should_retry(vio) (vio)->should_retry(vio) 00151 #define vio_was_interrupted(vio) (vio)->was_interrupted(vio) 00152 #define vio_close(vio) ((vio)->vioclose)(vio) 00153 #define vio_peer_addr(vio, buf, prt) (vio)->peer_addr(vio, buf, prt) 00154 #define vio_in_addr(vio, in) (vio)->in_addr(vio, in) 00155 #define vio_timeout(vio, which, seconds) (vio)->timeout(vio, which, seconds) 00156 #endif /* !defined(DONT_MAP_VIO) */ 00157 00158 /* This enumerator is used in parser - should be always visible */ 00159 enum SSL_type 00160 { 00161 SSL_TYPE_NOT_SPECIFIED= -1, 00162 SSL_TYPE_NONE, 00163 SSL_TYPE_ANY, 00164 SSL_TYPE_X509, 00165 SSL_TYPE_SPECIFIED 00166 }; 00167 00168 00169 /* HFTODO - hide this if we don't want client in embedded server */ 00170 /* This structure is for every connection on both sides */ 00171 struct st_vio 00172 { 00173 my_socket sd; /* my_socket - real or imaginary */ 00174 HANDLE hPipe; 00175 my_bool localhost; /* Are we from localhost? */ 00176 int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */ 00177 struct sockaddr_in local; /* Local internet address */ 00178 struct sockaddr_in remote; /* Remote internet address */ 00179 enum enum_vio_type type; /* Type of connection */ 00180 char desc[30]; /* String description */ 00181 char *read_buffer; /* buffer for vio_read_buff */ 00182 char *read_pos; /* start of unfetched data in the 00183 read buffer */ 00184 char *read_end; /* end of unfetched data */ 00185 /* function pointers. They are similar for socket/SSL/whatever */ 00186 void (*viodelete)(Vio*); 00187 int (*vioerrno)(Vio*); 00188 int (*read)(Vio*, gptr, int); 00189 int (*write)(Vio*, const gptr, int); 00190 int (*vioblocking)(Vio*, my_bool, my_bool *); 00191 my_bool (*is_blocking)(Vio*); 00192 int (*viokeepalive)(Vio*, my_bool); 00193 int (*fastsend)(Vio*); 00194 my_bool (*peer_addr)(Vio*, char *, uint16*); 00195 void (*in_addr)(Vio*, struct in_addr*); 00196 my_bool (*should_retry)(Vio*); 00197 my_bool (*was_interrupted)(Vio*); 00198 int (*vioclose)(Vio*); 00199 void (*timeout)(Vio*, unsigned int which, unsigned int timeout); 00200 #ifdef HAVE_OPENSSL 00201 void *ssl_arg; 00202 #endif 00203 #ifdef HAVE_SMEM 00204 HANDLE handle_file_map; 00205 char *handle_map; 00206 HANDLE event_server_wrote; 00207 HANDLE event_server_read; 00208 HANDLE event_client_wrote; 00209 HANDLE event_client_read; 00210 HANDLE event_conn_closed; 00211 long shared_memory_remain; 00212 char *shared_memory_pos; 00213 NET *net; 00214 #endif /* HAVE_SMEM */ 00215 }; 00216 #endif /* vio_violite_h_ */
1.4.7

