added SSL backend for IOMultiplexer
[TransparentIRC.git] / src / IOHandler.h
index 7d33ce23f9ee070b37be8129e8e0acd5863290bc..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 {
@@ -47,7 +49,8 @@ enum IOEventType {
     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 {
@@ -65,6 +68,11 @@ struct IODescriptor {
     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;
 };
@@ -79,15 +87,16 @@ struct IOEvent {
     } data;
 };
 
-struct IODescriptor *iohandler_add(int sockfd, enum IOType type, 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, const char *bind, 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();