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; 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 Vio* vio_new(my_socket sd, enum enum_vio_type type, my_bool localhost); 00041 #ifdef __WIN__ 00042 Vio* vio_new_win32pipe(HANDLE hPipe); 00043 Vio* vio_new_win32shared_memory(NET *net,HANDLE handle_file_map, 00044 HANDLE handle_map, 00045 HANDLE event_server_wrote, 00046 HANDLE event_server_read, 00047 HANDLE event_client_wrote, 00048 HANDLE event_client_read, 00049 HANDLE event_conn_closed); 00050 int vio_read_pipe(Vio *vio, gptr buf, int size); 00051 int vio_write_pipe(Vio *vio, const gptr buf, int size); 00052 int vio_close_pipe(Vio * vio); 00053 #else 00054 #define HANDLE void * 00055 #endif /* __WIN__ */ 00056 00057 void vio_delete(Vio* vio); 00058 int vio_close(Vio* vio); 00059 void vio_reset(Vio* vio, enum enum_vio_type type, 00060 my_socket sd, HANDLE hPipe, my_bool localhost); 00061 int vio_read(Vio *vio, gptr buf, int size); 00062 int vio_write(Vio *vio, const gptr buf, int size); 00063 int vio_blocking(Vio *vio, my_bool onoff, my_bool *old_mode); 00064 my_bool vio_is_blocking(Vio *vio); 00065 /* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible */ 00066 int vio_fastsend(Vio *vio); 00067 /* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible */ 00068 int vio_keepalive(Vio *vio, my_bool onoff); 00069 /* Whenever we should retry the last read/write operation. */ 00070 my_bool vio_should_retry(Vio *vio); 00071 /* Check that operation was timed out */ 00072 my_bool vio_was_interrupted(Vio *vio); 00073 /* Short text description of the socket for those, who are curious.. */ 00074 const char* vio_description(Vio *vio); 00075 /* Return the type of the connection */ 00076 enum enum_vio_type vio_type(Vio* vio); 00077 /* Return last error number */ 00078 int vio_errno(Vio*vio); 00079 /* Get socket number */ 00080 my_socket vio_fd(Vio*vio); 00081 /* Remote peer's address and name in text form */ 00082 my_bool vio_peer_addr(Vio* vio, char *buf, uint16 *port); 00083 /* Remotes in_addr */ 00084 void vio_in_addr(Vio *vio, struct in_addr *in); 00085 my_bool vio_poll_read(Vio *vio,uint timeout); 00086 void vio_timeout(Vio *vio,uint which, uint timeout); 00087 00088 #ifdef HAVE_OPENSSL 00089 #include <openssl/opensslv.h> 00090 #if OPENSSL_VERSION_NUMBER < 0x0090700f 00091 #define DES_cblock des_cblock 00092 #define DES_key_schedule des_key_schedule 00093 #define DES_set_key_unchecked(k,ks) des_set_key_unchecked((k),*(ks)) 00094 #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)) 00095 #endif 00096 00097 #define HEADER_DES_LOCL_H dummy_something 00098 #include <openssl/ssl.h> 00099 #include <openssl/err.h> 00100 00101 struct st_VioSSLAcceptorFd 00102 { 00103 SSL_CTX *ssl_context; 00104 SSL_METHOD *ssl_method; 00105 struct st_VioSSLAcceptorFd *session_id_context; 00106 }; 00107 00108 /* One copy for client */ 00109 struct st_VioSSLConnectorFd 00110 { 00111 SSL_CTX *ssl_context; 00112 /* function pointers which are only once for SSL client */ 00113 SSL_METHOD *ssl_method; 00114 }; 00115 00116 int sslaccept(struct st_VioSSLAcceptorFd*, Vio *, long timeout); 00117 int sslconnect(struct st_VioSSLConnectorFd*, Vio *, long timeout); 00118 00119 struct st_VioSSLConnectorFd 00120 *new_VioSSLConnectorFd(const char *key_file, const char *cert_file, 00121 const char *ca_file, const char *ca_path, 00122 const char *cipher); 00123 struct st_VioSSLAcceptorFd 00124 *new_VioSSLAcceptorFd(const char *key_file, const char *cert_file, 00125 const char *ca_file,const char *ca_path, 00126 const char *cipher); 00127 Vio *new_VioSSL(struct st_VioSSLAcceptorFd *fd, Vio *sd, int state); 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 #ifdef __cplusplus 00137 } 00138 #endif 00139 00140 #if defined(HAVE_VIO) && !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(HAVE_VIO) && !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 #ifdef HAVE_VIO 00182 /* function pointers. They are similar for socket/SSL/whatever */ 00183 void (*viodelete)(Vio*); 00184 int (*vioerrno)(Vio*); 00185 int (*read)(Vio*, gptr, int); 00186 int (*write)(Vio*, const gptr, int); 00187 int (*vioblocking)(Vio*, my_bool, my_bool *); 00188 my_bool (*is_blocking)(Vio*); 00189 int (*viokeepalive)(Vio*, my_bool); 00190 int (*fastsend)(Vio*); 00191 my_bool (*peer_addr)(Vio*, char *, uint16*); 00192 void (*in_addr)(Vio*, struct in_addr*); 00193 my_bool (*should_retry)(Vio*); 00194 my_bool (*was_interrupted)(Vio*); 00195 int (*vioclose)(Vio*); 00196 void (*timeout)(Vio*, unsigned int which, unsigned int timeout); 00197 void *ssl_arg; 00198 #ifdef HAVE_SMEM 00199 HANDLE handle_file_map; 00200 char *handle_map; 00201 HANDLE event_server_wrote; 00202 HANDLE event_server_read; 00203 HANDLE event_client_wrote; 00204 HANDLE event_client_read; 00205 HANDLE event_conn_closed; 00206 long shared_memory_remain; 00207 char *shared_memory_pos; 00208 NET *net; 00209 #endif /* HAVE_SMEM */ 00210 #endif /* HAVE_VIO */ 00211 }; 00212 #endif /* vio_violite_h_ */