36 { |
37 { |
37 int opt, option_index; |
38 int opt, option_index; |
38 struct event_base *ev_base; |
39 struct event_base *ev_base; |
39 struct sock_stream *sock; |
40 struct sock_stream *sock; |
40 struct irc_conn *conn; |
41 struct irc_conn *conn; |
41 struct error_info _err; |
42 struct error_info err; |
42 |
43 |
43 const char *hostname = DEFAULT_HOST, *portname = DEFAULT_PORT; |
44 const char *hostname = DEFAULT_HOST, *portname = DEFAULT_PORT; |
44 bool ssl = 0; |
45 bool ssl = 0; |
45 struct irc_conn_config conn_config = { |
46 struct irc_conn_config conn_config = { |
46 .nickname = "SpBotDev", |
47 .nickname = "SpBotDev", |
80 } |
81 } |
81 } |
82 } |
82 |
83 |
83 // initialize libevent |
84 // initialize libevent |
84 if ((ev_base = event_base_new()) == NULL) |
85 if ((ev_base = event_base_new()) == NULL) |
85 err(1, "event_base_new"); |
86 FATAL("event_base_new"); |
86 |
87 |
87 // initialize sock module |
88 // initialize sock module |
88 if (sock_init(ev_base, &_err)) |
89 if (sock_init(ev_base, &err)) |
89 errx(1, "sock_init: %s", error_msg(&_err)); |
90 FATAL_ERROR(&err, "sock_init"); |
90 |
91 |
91 // over-simplified connect |
92 // over-simplified connect |
92 if (ssl) { |
93 if (ssl) { |
93 if (sock_ssl_connect(&sock, hostname, portname, &_err)) |
94 if (sock_ssl_connect(&sock, hostname, portname, &err)) |
94 errx(1, "sock_ssl_connect: %s", error_msg(&_err)); |
95 FATAL_ERROR(&err, "sock_ssl_connect(%s, %s)", hostname, portname); |
95 |
96 |
96 } else { |
97 } else { |
97 if (sock_tcp_connect(&sock, hostname, portname, &_err)) |
98 if (sock_tcp_connect(&sock, hostname, portname, &err)) |
98 errx(1, "sock_tcp_connect: %s", error_msg(&_err)); |
99 FATAL_ERROR(&err, "sock_tcp_connect(%s, %s)", hostname, portname); |
99 |
100 |
100 } |
101 } |
101 |
102 |
102 // create the irc connection state |
103 // create the irc connection state |
103 if (irc_conn_create(&conn, sock, &conn_config, &_err)) |
104 if (irc_conn_create(&conn, sock, &conn_config, &err)) |
104 errx(1, "irc_conn_create: %s", error_msg(&_err)); |
105 FATAL_ERROR(&err, "irc_conn_create"); |
105 |
106 |
106 // run event loop |
107 // run event loop |
107 if (event_base_dispatch(ev_base)) |
108 if (event_base_dispatch(ev_base)) |
108 errx(1, "event_base_dispatch"); |
109 FATAL("event_base_dispatch"); |
109 |
110 |
110 // ok, no cleanup |
111 // ok, no cleanup |
111 return 0; |
112 return 0; |
112 } |
113 } |
113 |
114 |