--- a/src/nexus.c Sat Feb 28 21:39:15 2009 +0200
+++ b/src/nexus.c Sat Feb 28 22:47:39 2009 +0200
@@ -8,12 +8,11 @@
#include <event2/event.h>
#include "sock.h"
-#include "line_proto.h"
-#include "irc_line.h"
+#include "irc_conn.h"
-#define CONNECT_HOST "irc.fixme.fi"
-#define CONNECT_SERV "6697"
-#define LINE_LENGTH 512
+#define DEFAULT_HOST "irc.fixme.fi"
+#define DEFAULT_PORT "6667"
+#define DEFAULT_PORT_SSL "6697"
static struct option options[] = {
{"help", 0, NULL, 'h' },
@@ -33,31 +32,23 @@
printf(" --ssl / -S use SSL\n");
}
-void on_line (char *line_buf, void *arg)
-{
- struct irc_line line;
- int err;
-
- // parse
- if ((err = irc_line_parse(&line, line_buf)))
- printf("!!! Invalid line: %s: %s\n", line_buf, error_name(err));
-
- else
- printf("<<< prefix=%s, command=%s, args={%s, %s, %s, ...}\n",
- line.prefix, line.command, line.args[0], line.args[1], line.args[2]
- );
-}
-
int main (int argc, char **argv)
{
int opt, option_index;
struct event_base *ev_base;
struct sock_stream *sock;
- struct line_proto *lp;
+ struct irc_conn *conn;
struct error_info _err;
- const char *hostname = CONNECT_HOST, *portname = CONNECT_SERV;
+ 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)",
+ };
+
+ bool port_default = true;
// parse options
while ((opt = getopt_long(argc, argv, "hH:P:S", options, &option_index)) != -1) {
@@ -72,10 +63,15 @@
case 'P':
portname = optarg;
+ port_default = false;
break;
case 'S':
ssl = true;
+
+ if (port_default)
+ portname = DEFAULT_PORT_SSL;
+
break;
case '?':
@@ -103,9 +99,9 @@
}
- // line protocol, with safety margin for buffer
- if (line_proto_create(&lp, sock, LINE_LENGTH * 2, on_line, NULL, &_err))
- errx(1, "line_proto_create: %s", error_msg(&_err));
+ // create the irc connection state
+ if (irc_conn_create(&conn, sock, &conn_config, &_err))
+ errx(1, "irc_conn_create: %s", error_msg(&_err));
// run event loop
if (event_base_dispatch(ev_base))