summaryrefslogtreecommitdiff
path: root/include/violite.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/violite.h')
-rw-r--r--include/violite.h166
1 files changed, 151 insertions, 15 deletions
diff --git a/include/violite.h b/include/violite.h
index 7b14dae3610..bc10a8f527c 100644
--- a/include/violite.h
+++ b/include/violite.h
@@ -25,9 +25,6 @@
#include "my_net.h" /* needed because of struct in_addr */
-#ifdef HAVE_VIO
-#include <Vio.h> /* Full VIO interface */
-#else
/* Simple vio interface in C; The functions are implemented in violite.c */
@@ -35,14 +32,12 @@
extern "C" {
#endif /* __cplusplus */
-#ifndef Vio_defined
-#define Vio_defined
-struct st_vio; /* Only C */
-typedef struct st_vio Vio;
-#endif
-
enum enum_vio_type { VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET,
- VIO_TYPE_NAMEDPIPE, VIO_TYPE_SSL};
+ VIO_TYPE_NAMEDPIPE, VIO_TYPE_SSL};
+
+#ifndef __WIN__
+#define HANDLE void *
+#endif
Vio* vio_new(my_socket sd,
enum enum_vio_type type,
@@ -54,6 +49,10 @@ void vio_delete(Vio* vio);
#ifdef EMBEDDED_LIBRARY
void vio_reset(Vio *vio);
+#else
+void vio_reset(Vio* vio, enum enum_vio_type type,
+ my_socket sd, HANDLE hPipe,
+ my_bool localhost);
#endif
/*
@@ -87,7 +86,7 @@ my_bool vio_should_retry( Vio* vio);
/*
* When the workday is over...
*/
-int vio_close( Vio* vio);
+int vio_close(Vio* vio);
/*
* Short text description of the socket for those, who are curious..
*/
@@ -97,15 +96,15 @@ const char* vio_description( Vio* vio);
enum enum_vio_type vio_type(Vio* vio);
/* Return last error number */
-int vio_errno(Vio *vio);
+int vio_errno(Vio*vio);
/* Get socket number */
-my_socket vio_fd(Vio *vio);
+my_socket vio_fd(Vio*vio);
/*
* Remote peer's address and name in text form.
*/
-my_bool vio_peer_addr(Vio * vio, char *buf);
+my_bool vio_peer_addr(Vio* vio, char *buf);
/* Remotes in_addr */
@@ -117,5 +116,142 @@ my_bool vio_poll_read(Vio *vio,uint timeout);
#ifdef __cplusplus
}
#endif
-#endif /* HAVE_VIO */
#endif /* vio_violite_h_ */
+#ifdef HAVE_VIO
+#ifndef DONT_MAP_VIO
+#define vio_delete(vio) (vio)->viodelete(vio)
+#define vio_errno(vio) (vio)->vioerrno(vio)
+#define vio_read(vio, buf, size) (vio)->read(vio,buf,size)
+#define vio_write(vio, buf, size) (vio)->write(vio, buf, size)
+#define vio_blocking(vio, set_blocking_mode) (vio)->vioblocking(vio, set_blocking_mode)
+#define vio_is_blocking(vio) (vio)->is_blocking(vio)
+#define vio_fastsend(vio) (vio)->fastsend(vio)
+#define vio_keepalive(vio, set_keep_alive) (vio)->viokeepalive(vio, set_keep_alive)
+#define vio_should_retry(vio) (vio)->should_retry(vio)
+#define vio_close(vio) ((vio)->vioclose)(vio)
+#define vio_peer_addr(vio, buf) (vio)->peer_addr(vio, buf)
+#define vio_in_addr(vio, in) (vio)->in_addr(vio, in)
+#define vio_poll_read(vio,timeout) (vio)->poll_read(vio,timeout)
+#endif /* !DONT_MAP_VIO */
+#endif /* HAVE_VIO */
+
+
+#ifdef HAVE_OPENSSL
+#include <openssl/x509.h>
+#include <openssl/ssl.h>
+#include <openssl/err.h>
+#include <openssl/pem.h>
+#include <openssl/asn1.h>
+#include "my_net.h" /* needed because of struct in_addr */
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+void vio_ssl_delete(Vio* vio);
+
+int vio_ssl_read(Vio* vio,gptr buf, int size);
+int vio_ssl_write(Vio* vio,const gptr buf,int size);
+int vio_ssl_blocking(Vio* vio,my_bool onoff);
+my_bool vio_ssl_is_blocking(Vio* vio);
+
+/* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible. */
+ int vio_ssl_fastsend(Vio* vio);
+/* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible. */
+int vio_ssl_keepalive(Vio* vio, my_bool onoff);
+/* Whenever we should retry the last read/write operation. */
+my_bool vio_ssl_should_retry(Vio* vio);
+/* When the workday is over... */
+int vio_ssl_close(Vio* vio);
+/* Return last error number */
+int vio_ssl_errno(Vio *vio);
+my_bool vio_ssl_peer_addr(Vio* vio, char *buf);
+void vio_ssl_in_addr(Vio *vio, struct in_addr *in);
+
+/* Return 1 if there is data to be read */
+my_bool vio_ssl_poll_read(Vio *vio,uint timeout);
+
+#ifdef HAVE_OPENSSL
+
+/* Single copy for server */
+struct st_VioSSLAcceptorFd
+{
+ SSL_CTX* ssl_context_;
+ SSL_METHOD* ssl_method_;
+ struct st_VioSSLAcceptorFd* session_id_context_;
+ enum {
+ state_connect = 1,
+ state_accept = 2
+ };
+ BIO* bio_;
+ char *ssl_cip_;
+ char desc_[100];
+ Vio* sd_;
+
+ /* function pointers which are only once for SSL server
+ Vio*(*sslaccept)(struct st_VioSSLAcceptorFd*,Vio*); */
+};
+
+/* One copy for client */
+struct st_VioSSLConnectorFd
+{
+ SSL_CTX* ssl_context_;
+ SSL_METHOD* ssl_method_;
+ /* function pointers which are only once for SSL client */
+};
+Vio *sslaccept(struct st_VioSSLAcceptorFd*, Vio*);
+Vio *sslconnect(struct st_VioSSLConnectorFd*, Vio*);
+
+#else /* HAVE_OPENSSL */
+/* This dummy is required to maintain proper size of st_mysql in mysql.h */
+struct st_VioSSLConnectorFd {};
+#endif /* HAVE_OPENSSL */
+struct st_VioSSLConnectorFd *new_VioSSLConnectorFd(
+ const char* key_file,const char* cert_file,const char* ca_file,const char* ca_path);
+struct st_VioSSLAcceptorFd *new_VioSSLAcceptorFd(
+ const char* key_file,const char* cert_file,const char* ca_file,const char* ca_path);
+Vio* new_VioSSL(struct st_VioSSLAcceptorFd* fd, Vio* sd,int state);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* HAVE_OPENSSL */
+
+#ifndef EMBEDDED_LIBRARY
+/* This structure is for every connection on both sides */
+struct st_vio
+{
+ my_socket sd; /* my_socket - real or imaginary */
+ HANDLE hPipe;
+ my_bool localhost; /* Are we from localhost? */
+ int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */
+ struct sockaddr_in local; /* Local internet address */
+ struct sockaddr_in remote; /* Remote internet address */
+ enum enum_vio_type type; /* Type of connection */
+ char desc[30]; /* String description */
+#ifdef HAVE_VIO
+ /* function pointers. They are similar for socket/SSL/whatever */
+ void (*viodelete)(Vio*);
+ int(*vioerrno)(Vio*);
+ int(*read)(Vio*, gptr, int);
+ int(*write)(Vio*, gptr, int);
+ int(*vioblocking)(Vio*, my_bool);
+ my_bool(*is_blocking)(Vio*);
+ int(*viokeepalive)(Vio*, my_bool);
+ int(*fastsend)(Vio*);
+ my_bool(*peer_addr)(Vio*, gptr);
+ void(*in_addr)(Vio*, struct in_addr*);
+ my_bool(*should_retry)(Vio*);
+ int(*vioclose)(Vio*);
+ my_bool(*poll_read)(Vio*,uint);
+
+#ifdef HAVE_OPENSSL
+ BIO* bio_;
+ SSL* ssl_;
+ my_bool open_;
+#endif /* HAVE_OPENSSL */
+#endif /* HAVE_VIO */
+};
+#endif /* EMBEDDED_LIBRARY */
+