added SSL backend for IOMultiplexer
[TransparentIRC.git] / src / IOHandler.h
index 34e49d4c2f699bf4256a028c62d91521ba9995de..6d57ca541901329f2d485523279db163cc3f1078 100644 (file)
@@ -20,6 +20,7 @@
 
 struct IODescriptor;
 struct IOEvent;
+struct IOSSLNode;
 
 #define IOHANDLER_CALLBACK(NAME) void NAME(UNUSED_ARG(struct IOEvent *io_event))
 typedef IOHANDLER_CALLBACK(iohandler_callback);
@@ -36,7 +37,8 @@ enum IOStatus {
     IO_CLOSED, /* descriptor is dead (socket waiting for removal or timer) */
     IO_LISTENING, /* descriptor is waiting for connections (server socket) */
     IO_CONNECTING, /* descriptor is waiting for connection approval (connecting client socket) */
-    IO_CONNECTED /* descriptor is connected (connected client socket) */
+    IO_CONNECTED, /* descriptor is connected (connected client socket) */
+    IO_SSLWAIT /* waiting for SSL backend (e.g. handshake) */
 };
 
 enum IOEventType {
@@ -44,50 +46,57 @@ enum IOEventType {
     IOEVENT_READABLE, /* socket is readable - not read anything yet, could also be disconnect notification */
     IOEVENT_RECV, /* client socket received something (recv_str valid) */
     IOEVENT_CONNECTED, /* client socket connected successful */
-    IOEVENT_NOTCONNECTED, /* client socket could not connect (errno valid) */
-    IOEVENT_CLOSED, /* client socket lost connection (errno valid) */
+    IOEVENT_NOTCONNECTED, /* client socket could not connect (errid valid) */
+    IOEVENT_CLOSED, /* client socket lost connection (errid valid) */
     IOEVENT_ACCEPT, /* server socket accepted new connection (accept_fd valid) */
-    IOEVENT_TIMEOUT /* timer timed out */
+    IOEVENT_TIMEOUT, /* timer timed out */
+    IOEVENT_SSLFAILED /* failed to initialize SSL session */
 };
 
 struct IOBuffer {
-    char buffer;
+    char *buffer;
     size_t bufpos, buflen;
 };
 
 struct IODescriptor {
     int fd;
-    IOType type;
-    IOStatus state;
+    enum IOType type;
+    enum IOStatus state;
     struct timeval timeout;
     iohandler_callback *callback;
     struct IOBuffer readbuf;
     struct IOBuffer writebuf;
     void *data;
     int read_lines : 1;
+    int ssl : 1;
+    int ssl_active : 1;
+    int ssl_hs_read : 1;
+    int ssl_hs_write : 1;
+    struct IOSSLNode *sslnode;
     
     struct IODescriptor *next, *prev;
 };
 
 struct IOEvent {
-    IOEventType type;
+    enum IOEventType type;
     struct IODescriptor *iofd;
     union {
         char *recv_str;
         int accept_fd;
-        int errno;
+        int errid;
     } data;
 };
 
-struct IODescriptor *iohandler_add(int sockfd, IOType type, iohandler_callback *callback);
-struct IODescriptor *iohandler_timer(timeval timeout, iohandler_callback *callback);
-struct IODescriptor *iohandler_connect(const char *hostname, unsigned int port, const char *bind, iohandler_callback *callback);
+struct IODescriptor *iohandler_add(int sockfd, enum IOType type, struct timeval *timeout, iohandler_callback *callback);
+struct IODescriptor *iohandler_timer(struct timeval timeout, iohandler_callback *callback);
+struct IODescriptor *iohandler_connect(const char *hostname, unsigned int port, int ssl, const char *bind, iohandler_callback *callback);
 struct IODescriptor *iohandler_listen(const char *hostname, unsigned int port, iohandler_callback *callback);
 void iohandler_write(struct IODescriptor *iofd, const char *line);
 void iohandler_send(struct IODescriptor *iofd, const char *data, size_t datalen);
 void iohandler_printf(struct IODescriptor *iofd, const char *text, ...);
 void iohandler_close(struct IODescriptor *iofd);
 void iohandler_update(struct IODescriptor *iofd);
+void iohandler_set_timeout(struct IODescriptor *iofd, struct timeval *timeout);
 
 void iohandler_poll();