-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.c
141 lines (126 loc) · 3.25 KB
/
init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#define MODULE_NAME "init"
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include "util.h"
#include "core.h"
#include "sett.h"
#include "log.h"
void usage(FILE *f, const char *a0, int ec, bool sh)
{
#define O(STR) fputs(STR "\n", f);
#define F(STR, ...) fprintf(f, STR "\n", __VA_ARGS__)
O("sBNC-"VERSION"- simple irc bouncer");
F("usage: %s [-hHVirfjvlLtTpNURPQ] <hostspec>", a0);
if(!sh){
O("\t-h: Display usage statement.");
O("\t-H: Display this statement.");
O("\t-V: Display version.");
O("\t-i <str>: Set host to <str>.");
O("\t-r <str>: Set store log path.");
O("\t-f <str>: Set store filename format. (%E(poch) %D(ay)/%M(onth)/%Y(ear) %h(ost)#%c(han))");
O("\t-j: Log join and part messages.");
O("\t-v <int>: Set console verbosity to <int>. (0:silent,1:error,2:warn,3:info.4:debug)");
O("\t-l <str>: Set the of the logfile to <str>.");
O("\t-L <int>: Set logfile verbosity to <int>. (0:silent,1:error,2:warn,3:info.4:debug)");
O("\t-t <int>: Send heartbeat pings every <int> seconds.");
O("\t-T <int>: Bouncer port.");
O("\t-p <str>: Use <str> as bouncer password.");
O("\t-N <str>: Use <str> as nick.");
O("\t-U <str>: Use <str> as username.");
O("\t-R <str>: Use <str> as realname.");
O("\t-P <str>: Use <str> as server password.");
O("\t-Q <str>: Use <str> as quit message.");
O("\t<hostspec>: In [!]<host:port> format. ! denotes ssl.");
}
#undef O
#undef F
exit(ec);
}
void process_args(int *argc, char ***argv)
{
char *a0 = (*argv)[0];
struct settings *s = sett_get();
#define CSET(STR) util_strncpy(STR, optarg, sizeof STR)
int c;
while((c = getopt(*argc, *argv, "hHVi:r:f:jv:l:L:t:T:p:N:U:R:P:Q:")) != -1){
switch(c){
case 'h':
usage(stdout, a0, EXIT_SUCCESS, true);
break;
case 'H':
usage(stdout, a0, EXIT_SUCCESS, false);
break;
case 'V':
puts("sBNC-"VERSION);
exit(EXIT_SUCCESS);
break;
case 'i': //Should probably set this with reverse DNS or /etc/hostname
CSET(s->host);
break;
case 'r':
CSET(s->spath);
break;
case 'f':
CSET(s->sfmt);
break;
case 'j':
s->sjoin = true;
break;
case 'v':
log_cverb_set(util_clamp(strtol(optarg, NULL, 10), LOGGER_SILENT, LOGGER_DEBUG));
break;
case 'l':
log_file_set(optarg);
break;
case 'L':
log_fverb_set(util_clamp(strtol(optarg, NULL, 10), LOGGER_SILENT, LOGGER_DEBUG));
break;
case 't':
s->hbeat = strtol(optarg, NULL, 10);
break;
case 'T':
s->port = strtol(optarg, NULL, 10);
break;
case 'p':
CSET(s->pass);
break;
case 'N':
CSET(s->nick);
break;
case 'U':
CSET(s->uname);
break;
case 'R':
CSET(s->rname);
break;
case 'P':
CSET(s->server.pass);
break;
case 'Q':
CSET(s->qmsg);
break;
case '?':
default:
usage(stderr, a0, EXIT_FAILURE, true);
}
}
#undef CSET
*argc -= optind;
*argv += optind;
if(!*argc){
ERR("No hostspec given.");
usage(stderr, a0, EXIT_FAILURE, true);
}
util_parse_hostspec(s->server.host, sizeof s->server.host, &s->server.port, &s->server.ssl, (*argv)[0]);
}
int main(int argc, char **argv)
{
sett_init();
process_args(&argc, &argv);
ALL("Running sBNC-"VERSION);
srand(time(NULL));
sett_dump();
exit(core_run());
}
#undef MODULE_NAME