47 |
46 |
48 int main (int argc, char **argv) |
47 int main (int argc, char **argv) |
49 { |
48 { |
50 int opt, option_index; |
49 int opt, option_index; |
51 struct event_base *ev_base; |
50 struct event_base *ev_base; |
52 struct sock_stream *sock; |
51 struct irc_net *net; |
53 struct irc_conn *conn; |
|
54 struct error_info err; |
52 struct error_info err; |
55 |
53 |
56 const char *hostname = DEFAULT_HOST, *portname = DEFAULT_PORT; |
54 struct irc_net_info net_info = { |
57 bool ssl = 0; |
55 .network = NULL, |
58 struct irc_conn_config conn_config = { |
56 .hostname = DEFAULT_HOST, |
59 .nickname = "SpBotDev", |
57 .service = DEFAULT_PORT, |
60 .username = "spbot-dev", |
58 .use_ssl = false, |
61 .realname = "SpBot (development version)", |
59 .register_info = { |
|
60 .nickname = "SpBotDev", |
|
61 .username = "spbot-dev", |
|
62 .realname = "SpBot (development version)", |
|
63 } |
62 }; |
64 }; |
63 const char *log_database = NULL, *log_channel = NULL; |
65 const char *log_database = NULL, *log_channel = NULL; |
64 |
66 |
65 bool port_default = true; |
67 bool port_default = true; |
66 |
68 |
107 FATAL("event_base_new"); |
109 FATAL("event_base_new"); |
108 |
110 |
109 // initialize sock module |
111 // initialize sock module |
110 if (sock_init(ev_base, &err)) |
112 if (sock_init(ev_base, &err)) |
111 FATAL_ERROR(&err, "sock_init"); |
113 FATAL_ERROR(&err, "sock_init"); |
112 |
114 |
113 // over-simplified connect |
115 // the IRC network |
114 if (ssl) { |
116 if (irc_net_create(&net, &net_info, &err)) |
115 log_info("SSL connecting to [%s]:%s", hostname, portname); |
117 FATAL_ERROR(&err, "irc_net_create"); |
116 |
|
117 if (sock_ssl_connect(&sock, hostname, portname, &err)) |
|
118 FATAL_ERROR(&err, "sock_ssl_connect(%s, %s)", hostname, portname); |
|
119 |
|
120 } else { |
|
121 log_info("connecting to [%s]:%s", hostname, portname); |
|
122 |
|
123 if (sock_tcp_connect(&sock, hostname, portname, &err)) |
|
124 FATAL_ERROR(&err, "sock_tcp_connect(%s, %s)", hostname, portname); |
|
125 |
|
126 } |
|
127 |
|
128 log_info("connected, registering"); |
|
129 |
|
130 // create the irc connection state |
|
131 if (irc_conn_create(&conn, sock, &conn_config, &err)) |
|
132 FATAL_ERROR(&err, "irc_conn_create"); |
|
133 |
118 |
134 // logging? |
119 // logging? |
135 if (log_database || log_channel) { |
120 if (log_database || log_channel) { |
136 if ((ERROR_CODE(&err) = irc_log_init(ev_base, log_database, conn, log_channel))) |
121 if ((ERROR_CODE(&err) = irc_log_init(ev_base, log_database, net->conn, log_channel))) |
137 FATAL_ERROR(&err, "irc_log_init"); |
122 FATAL_ERROR(&err, "irc_log_init"); |
138 } |
123 } |
139 |
124 |
140 // run event loop |
125 // run event loop |
141 if (event_base_dispatch(ev_base)) |
126 if (event_base_dispatch(ev_base)) |