author | Tero Marttila <terom@fixme.fi> |
Thu, 12 Mar 2009 23:54:03 +0200 | |
changeset 48 | 4841f4398fd2 |
parent 26 | aec062af155d |
child 53 | 12d806823775 |
permissions | -rw-r--r-- |
21 | 1 |
|
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
23
diff
changeset
|
2 |
#include "irc_net.h" |
23
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
3 |
#include "irc_log.h" |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
4 |
#include "signals.h" |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
5 |
#include "log.h" |
0 | 6 |
|
7 |
#include <stdlib.h> |
|
15
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
8 |
#include <stdbool.h> |
0 | 9 |
#include <stdio.h> |
15
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
10 |
#include <getopt.h> |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
11 |
#include <signal.h> |
0 | 12 |
|
9
4c4c906cc649
add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents:
8
diff
changeset
|
13 |
#include <event2/event.h> |
0 | 14 |
|
1
cf0e1bb6bcab
a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
15 |
|
18
dedf137b504f
add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
16 |
#define DEFAULT_HOST "irc.fixme.fi" |
dedf137b504f
add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
17 |
#define DEFAULT_PORT "6667" |
dedf137b504f
add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
18 |
#define DEFAULT_PORT_SSL "6697" |
0 | 19 |
|
23
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
20 |
enum option_code { |
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
21 |
_OPT_LOG_BEGIN = 0x00ff, |
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
22 |
|
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
23 |
OPT_LOG_DATABASE, |
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
24 |
OPT_LOG_CHANNEL, |
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
25 |
}; |
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
26 |
|
15
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
27 |
static struct option options[] = { |
23
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
28 |
{"help", 0, NULL, 'h' }, |
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
29 |
{"hostname", 1, NULL, 'H' }, |
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
30 |
{"port", 1, NULL, 'P' }, |
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
31 |
{"ssl", 0, NULL, 'S' }, |
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
32 |
{"log-database", 1, NULL, OPT_LOG_DATABASE }, |
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
33 |
{"log-channel", 1, NULL, OPT_LOG_CHANNEL }, |
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
34 |
{0, 0, 0, 0 }, |
15
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
35 |
}; |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
36 |
|
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
37 |
void usage (const char *exe) |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
38 |
{ |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
39 |
printf("Usage: %s [OPTIONS]\n", exe); |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
40 |
printf("\n"); |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
41 |
printf(" --help / -h display this message\n"); |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
42 |
printf(" --hostname / -H HOST set hostname to connect to\n"); |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
43 |
printf(" --port / -P PORT set service port to connect to\n"); |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
44 |
printf(" --ssl / -S use SSL\n"); |
23
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
45 |
printf(" --log-database database connection string for logging\n"); |
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
46 |
printf(" --log-channel channel to log\n"); |
15
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
47 |
} |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
48 |
|
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
49 |
/** |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
50 |
* Context for async nexus operation |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
51 |
*/ |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
52 |
struct nexus_ctx { |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
53 |
/** The libevent base */ |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
54 |
struct event_base *ev_base; |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
55 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
56 |
/** The one IRC network */ |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
57 |
struct irc_net *net; |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
58 |
}; |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
59 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
60 |
void on_sigint (evutil_socket_t sig, short what, void *arg) |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
61 |
{ |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
62 |
struct nexus_ctx *ctx = arg; |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
63 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
64 |
(void) sig; |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
65 |
(void) what; |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
66 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
67 |
if (ctx->net && ctx->net->conn && !ctx->net->conn->quitting) { |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
68 |
log_info("Quitting..."); |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
69 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
70 |
// quit it |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
71 |
irc_net_quit(ctx->net, "Goodbye, cruel world ;("); |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
72 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
73 |
} else { |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
74 |
log_error("Aborting"); |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
75 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
76 |
// die |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
77 |
if (ctx->net) { |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
78 |
irc_net_destroy(ctx->net); |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
79 |
ctx->net = NULL; |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
80 |
} |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
81 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
82 |
// exit |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
83 |
event_base_loopexit(ctx->ev_base, NULL); |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
84 |
} |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
85 |
} |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
86 |
|
15
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
87 |
int main (int argc, char **argv) |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
88 |
{ |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
89 |
int opt, option_index; |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
90 |
struct nexus_ctx ctx; |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
91 |
struct signals *signals; |
21 | 92 |
struct error_info err; |
0 | 93 |
|
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
23
diff
changeset
|
94 |
struct irc_net_info net_info = { |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
23
diff
changeset
|
95 |
.network = NULL, |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
23
diff
changeset
|
96 |
.hostname = DEFAULT_HOST, |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
23
diff
changeset
|
97 |
.service = DEFAULT_PORT, |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
23
diff
changeset
|
98 |
.use_ssl = false, |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
23
diff
changeset
|
99 |
.register_info = { |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
23
diff
changeset
|
100 |
.nickname = "SpBotDev", |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
23
diff
changeset
|
101 |
.username = "spbot-dev", |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
23
diff
changeset
|
102 |
.realname = "SpBot (development version)", |
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
23
diff
changeset
|
103 |
} |
18
dedf137b504f
add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
104 |
}; |
26 | 105 |
|
106 |
struct irc_chan_info log_chan_info = { |
|
107 |
.channel = NULL, |
|
108 |
}; |
|
109 |
||
110 |
struct irc_log_info log_info = { |
|
111 |
.db_info = NULL, |
|
112 |
.channel = NULL, |
|
113 |
}; |
|
18
dedf137b504f
add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
114 |
|
dedf137b504f
add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
115 |
bool port_default = true; |
15
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
116 |
|
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
117 |
// parse options |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
118 |
while ((opt = getopt_long(argc, argv, "hH:P:S", options, &option_index)) != -1) { |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
119 |
switch (opt) { |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
120 |
case 'h': |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
121 |
usage(argv[0]); |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
122 |
return EXIT_SUCCESS; |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
123 |
|
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
124 |
case 'H': |
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
23
diff
changeset
|
125 |
net_info.hostname = optarg; |
15
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
126 |
break; |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
127 |
|
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
128 |
case 'P': |
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
23
diff
changeset
|
129 |
net_info.service = optarg; |
18
dedf137b504f
add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
130 |
port_default = false; |
15
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
131 |
break; |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
132 |
|
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
133 |
case 'S': |
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
23
diff
changeset
|
134 |
net_info.use_ssl = true; |
18
dedf137b504f
add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
135 |
|
dedf137b504f
add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
136 |
if (port_default) |
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
23
diff
changeset
|
137 |
net_info.service = DEFAULT_PORT_SSL; |
18
dedf137b504f
add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
17
diff
changeset
|
138 |
|
16 | 139 |
break; |
23
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
140 |
|
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
141 |
case OPT_LOG_DATABASE: |
26 | 142 |
log_info.db_info = optarg; |
23
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
143 |
break; |
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
144 |
|
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
145 |
case OPT_LOG_CHANNEL: |
26 | 146 |
log_chan_info.channel = optarg; |
23
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
147 |
break; |
15
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
148 |
|
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
149 |
case '?': |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
150 |
usage(argv[0]); |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
151 |
return EXIT_FAILURE; |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
152 |
} |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
153 |
} |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
154 |
|
9
4c4c906cc649
add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents:
8
diff
changeset
|
155 |
// initialize libevent |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
156 |
if ((ctx.ev_base = event_base_new()) == NULL) |
21 | 157 |
FATAL("event_base_new"); |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
158 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
159 |
// initialize signal handlers |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
160 |
if ((ERROR_CODE(&err) = signals_create(&signals, ctx.ev_base))) |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
161 |
FATAL("signals_create"); |
9
4c4c906cc649
add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents:
8
diff
changeset
|
162 |
|
4c4c906cc649
add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents:
8
diff
changeset
|
163 |
// initialize sock module |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
164 |
if (sock_init(ctx.ev_base, &err)) |
21 | 165 |
FATAL_ERROR(&err, "sock_init"); |
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
23
diff
changeset
|
166 |
|
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
23
diff
changeset
|
167 |
// the IRC network |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
168 |
if (irc_net_create(&ctx.net, &net_info, &err)) |
25
56367df4ce5b
add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents:
23
diff
changeset
|
169 |
FATAL_ERROR(&err, "irc_net_create"); |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
170 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
171 |
// add our signal handlers |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
172 |
if ( |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
173 |
(ERROR_CODE(&err) = signals_add(signals, SIGPIPE, &signals_ignore, signals)) |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
174 |
|| (ERROR_CODE(&err) = signals_add(signals, SIGINT, &on_sigint, &ctx)) |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
175 |
) |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
176 |
FATAL_ERROR(&err, "signals_add"); |
23
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
177 |
|
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
178 |
// logging? |
26 | 179 |
if (log_info.db_info || log_chan_info.channel) { |
180 |
// get the channel |
|
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
181 |
if (log_chan_info.channel && (log_info.channel = irc_net_add_chan(ctx.net, &log_chan_info)) == NULL) |
26 | 182 |
FATAL("irc_net_add_chan"); |
183 |
||
184 |
// init the irc_log module |
|
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
185 |
if ((ERROR_CODE(&err) = irc_log_init(ctx.ev_base, &log_info))) |
23
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
186 |
FATAL_ERROR(&err, "irc_log_init"); |
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
22
diff
changeset
|
187 |
} |
8
be88e543c8ff
split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents:
7
diff
changeset
|
188 |
|
11
14e79683c48c
working event-based operation for sock_tcp
Tero Marttila <terom@fixme.fi>
parents:
10
diff
changeset
|
189 |
// run event loop |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
190 |
if (event_base_dispatch(ctx.ev_base)) |
21 | 191 |
FATAL("event_base_dispatch"); |
0 | 192 |
|
11
14e79683c48c
working event-based operation for sock_tcp
Tero Marttila <terom@fixme.fi>
parents:
10
diff
changeset
|
193 |
// ok, no cleanup |
0 | 194 |
return 0; |
195 |
} |
|
196 |