--- a/src/nexus.c Mon Mar 09 16:30:30 2009 +0200
+++ b/src/nexus.c Mon Mar 09 16:30:59 2009 +0200
@@ -1,7 +1,6 @@
#include "log.h"
-#include "sock.h"
-#include "irc_conn.h"
+#include "irc_net.h"
#include "irc_log.h"
#include <stdlib.h>
@@ -49,16 +48,19 @@
{
int opt, option_index;
struct event_base *ev_base;
- struct sock_stream *sock;
- struct irc_conn *conn;
+ struct irc_net *net;
struct error_info err;
- const char *hostname = DEFAULT_HOST, *portname = DEFAULT_PORT;
- bool ssl = 0;
- struct irc_conn_config conn_config = {
- .nickname = "SpBotDev",
- .username = "spbot-dev",
- .realname = "SpBot (development version)",
+ struct irc_net_info net_info = {
+ .network = NULL,
+ .hostname = DEFAULT_HOST,
+ .service = DEFAULT_PORT,
+ .use_ssl = false,
+ .register_info = {
+ .nickname = "SpBotDev",
+ .username = "spbot-dev",
+ .realname = "SpBot (development version)",
+ }
};
const char *log_database = NULL, *log_channel = NULL;
@@ -72,19 +74,19 @@
return EXIT_SUCCESS;
case 'H':
- hostname = optarg;
+ net_info.hostname = optarg;
break;
case 'P':
- portname = optarg;
+ net_info.service = optarg;
port_default = false;
break;
case 'S':
- ssl = true;
+ net_info.use_ssl = true;
if (port_default)
- portname = DEFAULT_PORT_SSL;
+ net_info.service = DEFAULT_PORT_SSL;
break;
@@ -109,31 +111,14 @@
// initialize sock module
if (sock_init(ev_base, &err))
FATAL_ERROR(&err, "sock_init");
-
- // over-simplified connect
- if (ssl) {
- log_info("SSL connecting to [%s]:%s", hostname, portname);
-
- if (sock_ssl_connect(&sock, hostname, portname, &err))
- FATAL_ERROR(&err, "sock_ssl_connect(%s, %s)", hostname, portname);
-
- } else {
- log_info("connecting to [%s]:%s", hostname, portname);
-
- if (sock_tcp_connect(&sock, hostname, portname, &err))
- FATAL_ERROR(&err, "sock_tcp_connect(%s, %s)", hostname, portname);
-
- }
-
- log_info("connected, registering");
-
- // create the irc connection state
- if (irc_conn_create(&conn, sock, &conn_config, &err))
- FATAL_ERROR(&err, "irc_conn_create");
+
+ // the IRC network
+ if (irc_net_create(&net, &net_info, &err))
+ FATAL_ERROR(&err, "irc_net_create");
// logging?
if (log_database || log_channel) {
- if ((ERROR_CODE(&err) = irc_log_init(ev_base, log_database, conn, log_channel)))
+ if ((ERROR_CODE(&err) = irc_log_init(ev_base, log_database, net->conn, log_channel)))
FATAL_ERROR(&err, "irc_log_init");
}