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