author | Tero Marttila <terom@fixme.fi> |
Mon, 16 Mar 2009 23:34:05 +0200 | |
changeset 70 | a9a4c5e6aa30 |
parent 66 | ef8c9d7daf62 |
child 71 | 0a13030f795d |
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" |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
2 |
#include "signals.h" |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
3 |
#include "log.h" |
0 | 4 |
|
5 |
#include <stdlib.h> |
|
15
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
6 |
#include <stdbool.h> |
0 | 7 |
#include <stdio.h> |
15
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
8 |
#include <getopt.h> |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
9 |
#include <signal.h> |
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
10 |
#include <string.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 |
|
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
16 |
/** |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
17 |
* Command-line option codes |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
18 |
*/ |
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
|
19 |
enum option_code { |
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
20 |
OPT_HELP = 'h', |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
21 |
OPT_NETWORK = 'n', |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
22 |
OPT_CHANNEL = 'c', |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
23 |
OPT_MODULE = 'm', |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
24 |
OPT_CONFIG = 'C', |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
25 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
26 |
/** Options without short names */ |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
27 |
_OPT_EXT_BEGIN = 0x00ff, |
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 |
|
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 |
}; |
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 |
|
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
31 |
/** |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
32 |
* Command-line option definitions |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
33 |
*/ |
15
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
34 |
static struct option options[] = { |
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
35 |
{"help", 0, NULL, OPT_HELP }, |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
36 |
{"network", 1, NULL, OPT_NETWORK }, |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
37 |
{"channel", 1, NULL, OPT_CHANNEL }, |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
38 |
{"module", 1, NULL, OPT_MODULE }, |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
39 |
{"config", 1, NULL, OPT_CONFIG }, |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
40 |
{0, 0, 0, 0 }, |
15
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
41 |
}; |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
42 |
|
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
43 |
/** |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
44 |
* Display --help output on stdout |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
45 |
*/ |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
46 |
static void usage (const char *exe) |
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 |
printf("Usage: %s [OPTIONS]\n", exe); |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
49 |
printf("\n"); |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
50 |
printf(" --help / -h display this message\n"); |
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
51 |
printf(" --network / -n add an IRC network using '<name>:<hostname>[:<port>[:ssl]]' format\n"); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
52 |
printf(" --channel / -c add an IRC channel using '<network>:<channel>' format\n"); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
53 |
printf(" --module / -m add a module using '<name>:<path>' format\n"); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
54 |
printf(" --config / -C add a module configuration option using '<mod_name>:<name>[:<value>]' format\n"); |
15
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
55 |
} |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
56 |
|
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
57 |
/** |
65
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
58 |
* Parse and apply a --network option, adding the given network to our irc_client. |
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
59 |
*/ |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
60 |
static err_t apply_network (struct nexus *nexus, char *opt, struct error_info *err) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
61 |
{ |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
62 |
struct irc_net_info info = { |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
63 |
.network = NULL, |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
64 |
.hostname = NULL, |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
65 |
.service = DEFAULT_PORT, |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
66 |
.use_ssl = false, |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
67 |
.register_info = { |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
68 |
.nickname = "SpBotDev", |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
69 |
.username = "spbot-dev", |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
70 |
.realname = "SpBot (development version)" |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
71 |
} |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
72 |
}; |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
73 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
74 |
// parse the required fields |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
75 |
if ((info.network = strsep(&opt, ":")) == NULL) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
76 |
RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <name> field for --network"); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
77 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
78 |
if ((info.hostname = strsep(&opt, ":")) == NULL) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
79 |
RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <hostname> field for --network"); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
80 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
81 |
// parse the optional fields |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
82 |
if (opt) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
83 |
info.service = strsep(&opt, ":"); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
84 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
85 |
// parse any remaining flags |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
86 |
while (opt) { |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
87 |
char *flag = strsep(&opt, ":"); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
88 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
89 |
if (strcmp(flag, "ssl")) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
90 |
info.use_ssl = true; |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
91 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
92 |
else |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
93 |
RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "unrecognized flag for --network"); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
94 |
} |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
95 |
|
66
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
96 |
// create the net |
65
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
97 |
log_info("add network '%s' at '%s:%s'", info.network, info.hostname, info.service); |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
98 |
|
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
99 |
if (irc_client_add_net(nexus->client, NULL, &info, err)) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
100 |
return ERROR_CODE(err); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
101 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
102 |
// ok |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
103 |
return SET_ERROR(err, SUCCESS); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
104 |
} |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
105 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
106 |
/** |
65
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
107 |
* Parse and apply a --channel option, adding the given channel to the given irc_net. |
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
108 |
*/ |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
109 |
static err_t apply_channel (struct nexus *nexus, char *opt, struct error_info *err) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
110 |
{ |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
111 |
const char *network = NULL; |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
112 |
struct irc_net *net; |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
113 |
struct irc_chan_info info = { |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
114 |
.channel = NULL, |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
115 |
}; |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
116 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
117 |
// parse the required fields |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
118 |
if ((network = strsep(&opt, ":")) == NULL) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
119 |
RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <network> field for --channel"); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
120 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
121 |
if ((info.channel = strsep(&opt, ":")) == NULL) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
122 |
RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <channel> field for --channel"); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
123 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
124 |
// trailing garbage? |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
125 |
if (opt) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
126 |
RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "trailing values for --channel"); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
127 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
128 |
// look up the net |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
129 |
if ((net = irc_client_get_net(nexus->client, network)) == NULL) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
130 |
RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "unknown network for --channel"); |
65
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
131 |
|
66
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
132 |
// add the channel |
65
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
133 |
log_info("add channel '%s' on network '%s'", info.channel, net->info.network); |
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
134 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
135 |
if (irc_net_add_chan(net, NULL, &info, err)) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
136 |
return ERROR_CODE(err); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
137 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
138 |
// ok |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
139 |
return SUCCESS; |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
140 |
} |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
141 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
142 |
/** |
65
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
143 |
* Parse and apply a --module option, loading the given module. |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
144 |
*/ |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
145 |
static err_t apply_module (struct nexus *nexus, char *opt, struct error_info *err) |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
146 |
{ |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
147 |
struct module_info info = { |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
148 |
.name = NULL, |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
149 |
.path = NULL, |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
150 |
}; |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
151 |
struct module *module; |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
152 |
|
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
153 |
// parse the required fields |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
154 |
if ((info.name = strsep(&opt, ":")) == NULL) |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
155 |
RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <name> field for --module"); |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
156 |
|
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
157 |
if ((info.path = strsep(&opt, ":")) == NULL) |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
158 |
RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <path> field for --module"); |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
159 |
|
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
160 |
// trailing garbage? |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
161 |
if (opt) |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
162 |
RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "trailing values for --channel"); |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
163 |
|
66
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
164 |
// load it |
65
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
165 |
log_info("loading module '%s' from path '%s'", info.name, info.path); |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
166 |
|
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
167 |
if (module_load(nexus->modules, &module, &info, err)) |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
168 |
return ERROR_CODE(err); |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
169 |
|
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
170 |
// ok |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
171 |
return SUCCESS; |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
172 |
} |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
173 |
|
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
174 |
/** |
66
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
175 |
* Parse and apply a --config option, calling the module's conf func. |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
176 |
*/ |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
177 |
static err_t apply_config (struct nexus *nexus, char *opt, struct error_info *err) |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
178 |
{ |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
179 |
struct module *module; |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
180 |
const char *module_name, *conf_name; |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
181 |
char *conf_value; |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
182 |
|
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
183 |
// parse the required fields |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
184 |
if ((module_name = strsep(&opt, ":")) == NULL) |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
185 |
RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <module> field for --config"); |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
186 |
|
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
187 |
if ((conf_name = strsep(&opt, ":")) == NULL) |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
188 |
RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <name> field for --config"); |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
189 |
|
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
190 |
// value is the rest of the data, might be NULL |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
191 |
conf_value = opt; |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
192 |
|
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
193 |
// lookup the module |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
194 |
if ((module = module_get(nexus->modules, module_name)) == NULL) |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
195 |
RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "unknown module for --config"); |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
196 |
|
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
197 |
// do the config |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
198 |
log_info("applying module '%s' config name '%s' with value: %s", module->info.name, conf_name, conf_value); |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
199 |
|
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
200 |
if (module_conf(module, conf_name, conf_value, err)) |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
201 |
return ERROR_CODE(err); |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
202 |
|
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
203 |
// ok |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
204 |
return SUCCESS; |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
205 |
} |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
206 |
|
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
207 |
/** |
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
208 |
* Parse arguments and apply them to the given nexus |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
209 |
*/ |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
210 |
static err_t parse_args (struct nexus *nexus, int argc, char **argv, struct error_info *err) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
211 |
{ |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
212 |
int opt, option_index; |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
213 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
214 |
// parse options |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
215 |
while ((opt = getopt_long(argc, argv, "hn:c:m:C:", options, &option_index)) != -1) { |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
216 |
switch (opt) { |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
217 |
case OPT_HELP: |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
218 |
usage(argv[0]); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
219 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
220 |
// XXX: return instead |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
221 |
exit(EXIT_SUCCESS); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
222 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
223 |
case OPT_NETWORK: |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
224 |
if (apply_network(nexus, optarg, err)) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
225 |
return ERROR_CODE(err); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
226 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
227 |
break; |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
228 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
229 |
case OPT_CHANNEL: |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
230 |
if (apply_channel(nexus, optarg, err)) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
231 |
return ERROR_CODE(err); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
232 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
233 |
break; |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
234 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
235 |
case OPT_MODULE: |
65
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
236 |
if (apply_module(nexus, optarg, err)) |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
237 |
return ERROR_CODE(err); |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
238 |
|
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
239 |
break; |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
63
diff
changeset
|
240 |
|
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
241 |
case OPT_CONFIG: |
66
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
242 |
if (apply_config(nexus, optarg, err)) |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
243 |
return ERROR_CODE(err); |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
244 |
|
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
245 |
break; |
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
246 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
247 |
case '?': |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
248 |
usage(argv[0]); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
249 |
return SET_ERROR(err, ERR_CMD_OPT); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
250 |
} |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
251 |
} |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
252 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
253 |
// ok |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
254 |
return SUCCESS; |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
255 |
} |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
256 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
257 |
static void on_sigint (evutil_socket_t sig, short what, void *arg) |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
258 |
{ |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
259 |
struct nexus *ctx = arg; |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
260 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
261 |
(void) sig; |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
262 |
(void) what; |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
263 |
|
70
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
264 |
log_info("Quitting..."); |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
265 |
|
70
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
266 |
// unload the modules |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
267 |
modules_unload(ctx->modules); |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
268 |
|
70
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
269 |
// quit the irc client |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
270 |
irc_client_quit(ctx->client, "Goodbye, cruel world ;("); |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
271 |
|
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
272 |
// remove the signal handlers (ourself) |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
273 |
signals_free(ctx->signals); |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
274 |
} |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
275 |
|
15
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
276 |
int main (int argc, char **argv) |
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
277 |
{ |
70
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
278 |
struct nexus _nexus, *nexus = &_nexus; |
21 | 279 |
struct error_info err; |
0 | 280 |
|
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
281 |
// zero nexus |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
282 |
memset(nexus, 0, sizeof(*nexus)); |
15
9bbeace56269
add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents:
14
diff
changeset
|
283 |
|
9
4c4c906cc649
add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents:
8
diff
changeset
|
284 |
// initialize libevent |
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
285 |
if ((nexus->ev_base = event_base_new()) == NULL) |
21 | 286 |
FATAL("event_base_new"); |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
287 |
|
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
288 |
// initialize signal handlers |
70
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
289 |
if ((ERROR_CODE(&err) = signals_create(&nexus->signals, nexus->ev_base))) |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
290 |
FATAL("signals_create"); |
9
4c4c906cc649
add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents:
8
diff
changeset
|
291 |
|
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
292 |
// add our signal handlers |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
293 |
if ( |
70
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
294 |
(ERROR_CODE(&err) = signals_add(nexus->signals, SIGPIPE, &signals_ignore, nexus->signals)) |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
295 |
|| (ERROR_CODE(&err) = signals_add(nexus->signals, SIGINT, &on_sigint, nexus)) |
48
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
296 |
) |
4841f4398fd2
add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents:
26
diff
changeset
|
297 |
FATAL_ERROR(&err, "signals_add"); |
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
298 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
299 |
// initialize sock module |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
300 |
if (sock_init(nexus->ev_base, &err)) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
301 |
FATAL_ERROR(&err, "sock_init"); |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
302 |
|
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
303 |
// modules |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
304 |
if ((ERROR_CODE(&err) = modules_create(&nexus->modules, nexus))) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
305 |
FATAL_ERROR(&err, "modules_create"); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
306 |
|
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
307 |
// the IRC client |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
308 |
if (irc_client_create(&nexus->client, &err)) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
309 |
FATAL_ERROR(&err, "irc_client_create"); |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
53
diff
changeset
|
310 |
|
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
311 |
// parse args |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
312 |
if (parse_args(nexus, argc, argv, &err)) |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
313 |
FATAL_ERROR(&err, "parse_args"); |
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
314 |
|
11
14e79683c48c
working event-based operation for sock_tcp
Tero Marttila <terom@fixme.fi>
parents:
10
diff
changeset
|
315 |
// run event loop |
63
d399a1d915a3
start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
316 |
if (event_base_dispatch(nexus->ev_base)) |
21 | 317 |
FATAL("event_base_dispatch"); |
0 | 318 |
|
11
14e79683c48c
working event-based operation for sock_tcp
Tero Marttila <terom@fixme.fi>
parents:
10
diff
changeset
|
319 |
// ok, no cleanup |
0 | 320 |
return 0; |
321 |
} |
|
322 |