1 /* main.c - IOMultiplexer
2 * Copyright (C) 2012 Philipp Kreil (pk910)
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "../../IOHandler/IOHandler.h"
21 #include "../../IOHandler/IOSockets.h"
22 #include "../../IOHandler/IOLog.h"
24 #define CERTFILE "cert.pem"
25 #define KEYFILE "key.pem"
27 static IOSOCKET_CALLBACK(io_callback);
28 static IOLOG_CALLBACK(io_log);
30 static struct IOSocket *irc_iofd = NULL;
32 int main(int argc, char *argv[]) {
35 iolog_register_callback(io_log);
37 irc_iofd = iosocket_listen_ssl("0.0.0.0", 12345, CERTFILE, KEYFILE, io_callback);
44 static IOSOCKET_CALLBACK(io_callback) {
46 case IOSOCKETEVENT_ACCEPT:
47 printf("[client accepted]\n");
48 struct IOSocket *client = event->data.accept_socket;
49 client->callback = io_callback;
51 char *html = "<html><head><title>Test Page</title></head><body><h1>IOHandler SSL Test</h1></body></html>";
52 iosocket_printf(client, "HTTP/1.1 200 OK\r\n");
53 iosocket_printf(client, "Server: Apache\r\n");
54 iosocket_printf(client, "Content-Length: %d\r\n", strlen(html));
55 iosocket_printf(client, "Content-Type: text/html\r\n");
56 iosocket_printf(client, "\r\n");
57 iosocket_printf(client, "%s", html);
60 case IOSOCKETEVENT_CLOSED:
61 if(event->socket->listening)
62 printf("[server closed]\n");
64 printf("[client disconnect]\n");
66 case IOSOCKETEVENT_RECV:
68 struct IOSocketBuffer *recv_buf = event->data.recv_buf;
70 for(i = 0; i < recv_buf->bufpos; i++)
71 putchar(recv_buf->buffer[i]);
82 static IOLOG_CALLBACK(io_log) {
83 printf("%s", message);