PageRenderTime 58ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/dep/mysqllite/include/internal/violite.h

https://code.google.com/p/oregoncore/
C++ Header | 241 lines | 181 code | 26 blank | 34 comment | 0 complexity | e46a2b7facc7f702fa7ba38f8938ad5b MD5 | raw file
Possible License(s): CC-BY-SA-3.0, BSD-3-Clause, GPL-2.0, LGPL-2.1
  1. /* Copyright (C) 2000 MySQL AB
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  12. /*
  13. * Vio Lite.
  14. * Purpose: include file for Vio that will work with C and C++
  15. */
  16. #ifndef vio_violite_h_
  17. #define vio_violite_h_
  18. #include "my_net.h" /* needed because of struct in_addr */
  19. /* Simple vio interface in C; The functions are implemented in violite.c */
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif /* __cplusplus */
  23. #ifdef __cplusplus
  24. typedef struct st_vio Vio;
  25. #endif /* __cplusplus */
  26. enum enum_vio_type
  27. {
  28. VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, VIO_TYPE_NAMEDPIPE,
  29. VIO_TYPE_SSL, VIO_TYPE_SHARED_MEMORY
  30. };
  31. #define VIO_LOCALHOST 1 /* a localhost connection */
  32. #define VIO_BUFFERED_READ 2 /* use buffered read */
  33. #define VIO_READ_BUFFER_SIZE 16384 /* size of read buffer */
  34. Vio* vio_new(my_socket sd, enum enum_vio_type type, uint flags);
  35. #ifdef __WIN__
  36. Vio* vio_new_win32pipe(HANDLE hPipe);
  37. Vio* vio_new_win32shared_memory(HANDLE handle_file_map,
  38. HANDLE handle_map,
  39. HANDLE event_server_wrote,
  40. HANDLE event_server_read,
  41. HANDLE event_client_wrote,
  42. HANDLE event_client_read,
  43. HANDLE event_conn_closed);
  44. #else
  45. #define HANDLE void *
  46. #endif /* __WIN__ */
  47. void vio_delete(Vio* vio);
  48. int vio_close(Vio* vio);
  49. void vio_reset(Vio* vio, enum enum_vio_type type,
  50. my_socket sd, HANDLE hPipe, uint flags);
  51. size_t vio_read(Vio *vio, uchar * buf, size_t size);
  52. size_t vio_read_buff(Vio *vio, uchar * buf, size_t size);
  53. size_t vio_write(Vio *vio, const uchar * buf, size_t size);
  54. int vio_blocking(Vio *vio, my_bool onoff, my_bool *old_mode);
  55. my_bool vio_is_blocking(Vio *vio);
  56. /* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible */
  57. int vio_fastsend(Vio *vio);
  58. /* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible */
  59. int vio_keepalive(Vio *vio, my_bool onoff);
  60. /* Whenever we should retry the last read/write operation. */
  61. my_bool vio_should_retry(Vio *vio);
  62. /* Check that operation was timed out */
  63. my_bool vio_was_interrupted(Vio *vio);
  64. /* Short text description of the socket for those, who are curious.. */
  65. const char* vio_description(Vio *vio);
  66. /* Return the type of the connection */
  67. enum enum_vio_type vio_type(Vio* vio);
  68. /* Return last error number */
  69. int vio_errno(Vio*vio);
  70. /* Get socket number */
  71. my_socket vio_fd(Vio*vio);
  72. /* Remote peer's address and name in text form */
  73. my_bool vio_peer_addr(Vio *vio, char *buf, uint16 *port, size_t buflen);
  74. my_bool vio_poll_read(Vio *vio, uint timeout);
  75. my_bool vio_is_connected(Vio *vio);
  76. ssize_t vio_pending(Vio *vio);
  77. my_bool vio_get_normalized_ip_string(const struct sockaddr *addr, int addr_length,
  78. char *ip_string, size_t ip_string_size);
  79. int vio_getnameinfo(const struct sockaddr *sa,
  80. char *hostname, size_t hostname_size,
  81. char *port, size_t port_size,
  82. int flags);
  83. #ifdef HAVE_OPENSSL
  84. #include <openssl/opensslv.h>
  85. #if OPENSSL_VERSION_NUMBER < 0x0090700f
  86. #define DES_cblock des_cblock
  87. #define DES_key_schedule des_key_schedule
  88. #define DES_set_key_unchecked(k,ks) des_set_key_unchecked((k),*(ks))
  89. #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))
  90. #endif
  91. #define HEADER_DES_LOCL_H dummy_something
  92. #define YASSL_MYSQL_COMPATIBLE
  93. #ifndef YASSL_PREFIX
  94. #define YASSL_PREFIX
  95. #endif
  96. /* Set yaSSL to use same type as MySQL do for socket handles */
  97. typedef my_socket YASSL_SOCKET_T;
  98. #define YASSL_SOCKET_T_DEFINED
  99. #include <openssl/ssl.h>
  100. #include <openssl/err.h>
  101. #ifndef EMBEDDED_LIBRARY
  102. enum enum_ssl_init_error
  103. {
  104. SSL_INITERR_NOERROR= 0, SSL_INITERR_CERT, SSL_INITERR_KEY,
  105. SSL_INITERR_NOMATCH, SSL_INITERR_BAD_PATHS, SSL_INITERR_CIPHERS,
  106. SSL_INITERR_MEMFAIL, SSL_INITERR_LASTERR
  107. };
  108. const char* sslGetErrString(enum enum_ssl_init_error err);
  109. struct st_VioSSLFd
  110. {
  111. SSL_CTX *ssl_context;
  112. };
  113. int sslaccept(struct st_VioSSLFd*, Vio *, long timeout);
  114. int sslconnect(struct st_VioSSLFd*, Vio *, long timeout);
  115. struct st_VioSSLFd
  116. *new_VioSSLConnectorFd(const char *key_file, const char *cert_file,
  117. const char *ca_file, const char *ca_path,
  118. const char *cipher);
  119. struct st_VioSSLFd
  120. *new_VioSSLAcceptorFd(const char *key_file, const char *cert_file,
  121. const char *ca_file,const char *ca_path,
  122. const char *cipher, enum enum_ssl_init_error* error);
  123. void free_vio_ssl_acceptor_fd(struct st_VioSSLFd *fd);
  124. #endif /* ! EMBEDDED_LIBRARY */
  125. #endif /* HAVE_OPENSSL */
  126. void vio_end(void);
  127. #ifdef __cplusplus
  128. }
  129. #endif
  130. #if !defined(DONT_MAP_VIO)
  131. #define vio_delete(vio) (vio)->viodelete(vio)
  132. #define vio_errno(vio) (vio)->vioerrno(vio)
  133. #define vio_read(vio, buf, size) ((vio)->read)(vio,buf,size)
  134. #define vio_write(vio, buf, size) ((vio)->write)(vio, buf, size)
  135. #define vio_blocking(vio, set_blocking_mode, old_mode)\
  136. (vio)->vioblocking(vio, set_blocking_mode, old_mode)
  137. #define vio_is_blocking(vio) (vio)->is_blocking(vio)
  138. #define vio_fastsend(vio) (vio)->fastsend(vio)
  139. #define vio_keepalive(vio, set_keep_alive) (vio)->viokeepalive(vio, set_keep_alive)
  140. #define vio_should_retry(vio) (vio)->should_retry(vio)
  141. #define vio_was_interrupted(vio) (vio)->was_interrupted(vio)
  142. #define vio_close(vio) ((vio)->vioclose)(vio)
  143. #define vio_peer_addr(vio, buf, prt, buflen) (vio)->peer_addr(vio, buf, prt, buflen)
  144. #define vio_timeout(vio, which, seconds) (vio)->timeout(vio, which, seconds)
  145. #define vio_poll_read(vio, timeout) (vio)->poll_read(vio, timeout)
  146. #define vio_is_connected(vio) (vio)->is_connected(vio)
  147. #endif /* !defined(DONT_MAP_VIO) */
  148. /* This enumerator is used in parser - should be always visible */
  149. enum SSL_type
  150. {
  151. SSL_TYPE_NOT_SPECIFIED= -1,
  152. SSL_TYPE_NONE,
  153. SSL_TYPE_ANY,
  154. SSL_TYPE_X509,
  155. SSL_TYPE_SPECIFIED
  156. };
  157. /* HFTODO - hide this if we don't want client in embedded server */
  158. /* This structure is for every connection on both sides */
  159. struct st_vio
  160. {
  161. my_socket sd; /* my_socket - real or imaginary */
  162. HANDLE hPipe;
  163. my_bool localhost; /* Are we from localhost? */
  164. int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */
  165. struct sockaddr_storage local; /* Local internet address */
  166. struct sockaddr_storage remote; /* Remote internet address */
  167. int addrLen; /* Length of remote address */
  168. enum enum_vio_type type; /* Type of connection */
  169. char desc[30]; /* String description */
  170. char *read_buffer; /* buffer for vio_read_buff */
  171. char *read_pos; /* start of unfetched data in the
  172. read buffer */
  173. char *read_end; /* end of unfetched data */
  174. /* function pointers. They are similar for socket/SSL/whatever */
  175. void (*viodelete)(Vio*);
  176. int (*vioerrno)(Vio*);
  177. size_t (*read)(Vio*, uchar *, size_t);
  178. size_t (*write)(Vio*, const uchar *, size_t);
  179. int (*vioblocking)(Vio*, my_bool, my_bool *);
  180. my_bool (*is_blocking)(Vio*);
  181. int (*viokeepalive)(Vio*, my_bool);
  182. int (*fastsend)(Vio*);
  183. my_bool (*peer_addr)(Vio*, char *, uint16*, size_t);
  184. void (*in_addr)(Vio*, struct sockaddr_storage*);
  185. my_bool (*should_retry)(Vio*);
  186. my_bool (*was_interrupted)(Vio*);
  187. int (*vioclose)(Vio*);
  188. void (*timeout)(Vio*, unsigned int which, unsigned int timeout);
  189. my_bool (*poll_read)(Vio *vio, uint timeout);
  190. my_bool (*is_connected)(Vio*);
  191. my_bool (*has_data) (Vio*);
  192. #ifdef HAVE_OPENSSL
  193. void *ssl_arg;
  194. #endif
  195. #ifdef HAVE_SMEM
  196. HANDLE handle_file_map;
  197. char *handle_map;
  198. HANDLE event_server_wrote;
  199. HANDLE event_server_read;
  200. HANDLE event_client_wrote;
  201. HANDLE event_client_read;
  202. HANDLE event_conn_closed;
  203. size_t shared_memory_remain;
  204. char *shared_memory_pos;
  205. #endif /* HAVE_SMEM */
  206. #ifdef _WIN32
  207. OVERLAPPED pipe_overlapped;
  208. DWORD read_timeout_ms;
  209. DWORD write_timeout_ms;
  210. #endif
  211. };
  212. #endif /* vio_violite_h_ */