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