common.c
8.44 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "cmdline.h"
#include <unistd.h>
#include <string.h>
#include <mailutils/syslog.h>
#include <mailutils/mailbox.h>
/* ************************************************************************* */
/* Common */
/* ************************************************************************* */
enum {
OPT_SHOW_OPTIONS=256,
OPT_NO_USER_RCFILE,
OPT_NO_SITE_RCFILE,
OPT_RCFILE,
OPT_RCFILE_LINT,
OPT_RCFILE_VERBOSE,
OPT_LOG_FACILITY,
OPT_LICENSE,
OPT_DEBUG_LEVEL,
OPT_LINE_INFO,
OPT_HELP_CONFIG,
OPT_SET
};
static struct argp_option mu_common_argp_options[] =
{
{ NULL, 0, NULL, 0, N_("Common options"), 0},
{ "show-config-options", OPT_SHOW_OPTIONS, NULL, 0,
N_("show compilation options"), 0 },
{ "config-help", OPT_HELP_CONFIG, NULL, 0,
N_("show configuration file summary"), 0 },
{ "no-user-config", OPT_NO_USER_RCFILE, NULL, 0,
N_("do not load user configuration file"), 0 },
{ "no-user-rcfile", 0, NULL, OPTION_ALIAS, NULL },
{ "no-site-config", OPT_NO_SITE_RCFILE, NULL, 0,
N_("do not load site configuration file"), 0 },
{ "no-site-rcfile", 0, NULL, OPTION_ALIAS, NULL },
{ "config-file", OPT_RCFILE, N_("FILE"), 0,
N_("load this configuration file"), 0, },
{ "rcfile", 0, NULL, OPTION_ALIAS, NULL },
{ "config-verbose", OPT_RCFILE_VERBOSE, NULL, 0,
N_("verbosely log parsing of the configuration files"), 0 },
{ "rcfile-verbose", 0, NULL, OPTION_ALIAS, NULL },
{ "config-lint", OPT_RCFILE_LINT, NULL, 0,
N_("check configuration file syntax and exit"), 0 },
{ "rcfile-lint", 0, NULL, OPTION_ALIAS, NULL },
{ "set", OPT_SET, N_("PARAM=VALUE"), 0,
N_("set configuration parameter"), 0 },
{ NULL, 0, NULL, 0, NULL, 0 }
};
static void
set_config_param (const char *path, struct argp_state *state)
{
mu_cfg_node_t *node;
int rc = mu_cfg_create_subtree (path, &node);
if (rc)
argp_error (state, "cannot create node: %s", mu_strerror (rc));
mu_cfg_tree_add_node (mu_argp_tree, node);
}
static error_t
mu_common_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case OPT_SHOW_OPTIONS:
mu_print_options ();
exit (0);
case OPT_NO_USER_RCFILE:
mu_load_user_rcfile = 0;
break;
case OPT_NO_SITE_RCFILE:
mu_load_site_rcfile = 0;
break;
case OPT_RCFILE:
mu_load_rcfile = arg;
break;
case OPT_RCFILE_LINT:
mu_cfg_parser_verbose++;
mu_rcfile_lint = 1;
break;
case OPT_RCFILE_VERBOSE:
mu_cfg_parser_verbose++;
break;
case OPT_HELP_CONFIG:
mu_help_config_mode = 1;
break;
case OPT_SET:
set_config_param (arg, state);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_common_argp = {
mu_common_argp_options,
mu_common_argp_parser,
};
struct argp_child mu_common_argp_child = {
&mu_common_argp,
0,
NULL,
0,
};
struct mu_cmdline_capa mu_common_cmdline = {
"common", &mu_common_argp_child
};
/* ************************************************************************* */
/* Logging */
/* ************************************************************************* */
static struct argp_option mu_logging_argp_option[] = {
{"log-facility", OPT_LOG_FACILITY, N_("FACILITY"), 0,
N_("output logs to syslog FACILITY"), 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t
mu_logging_argp_parser (int key, char *arg, struct argp_state *state)
{
static struct mu_argp_node_list lst;
switch (key)
{
/* log */
case OPT_LOG_FACILITY:
mu_argp_node_list_new (&lst, "facility", arg);
break;
case ARGP_KEY_INIT:
mu_argp_node_list_init (&lst);
break;
case ARGP_KEY_FINI:
mu_argp_node_list_finish (&lst, "logging", NULL);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_logging_argp = {
mu_logging_argp_option,
mu_logging_argp_parser,
};
struct argp_child mu_logging_argp_child = {
&mu_logging_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_logging_cmdline = {
"logging", &mu_logging_argp_child
};
/* ************************************************************************* */
/* License */
/* ************************************************************************* */
/* Option to print the license. */
static struct argp_option mu_license_argp_option[] = {
{ "license", OPT_LICENSE, NULL, 0, N_("print license and exit"), -2 },
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t
mu_license_argp_parser (int key, char *arg, struct argp_state *state)
{
switch (key)
{
case OPT_LICENSE:
printf (_("License for %s:\n\n"), argp_program_version);
printf ("%s", mu_license_text);
exit (0);
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_license_argp = {
mu_license_argp_option,
mu_license_argp_parser,
};
struct argp_child mu_license_argp_child = {
&mu_license_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_license_cmdline = {
"license", &mu_license_argp_child
};
/* ************************************************************************* */
/* Mailer */
/* ************************************************************************* */
/* Options used by programs that send mail. */
static struct argp_option mu_mailer_argp_option[] = {
{"mailer", 'M', N_("MAILER"), 0,
N_("use specified URL as the default mailer"), 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t
mu_mailer_argp_parser (int key, char *arg, struct argp_state *state)
{
static struct mu_argp_node_list lst;
switch (key)
{
/* mailer */
case 'M':
mu_argp_node_list_new (&lst, "url", arg);
break;
case ARGP_KEY_INIT:
mu_argp_node_list_init (&lst);
break;
case ARGP_KEY_FINI:
mu_argp_node_list_finish (&lst, "mailer", NULL);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_mailer_argp = {
mu_mailer_argp_option,
mu_mailer_argp_parser,
};
struct argp_child mu_mailer_argp_child = {
&mu_mailer_argp,
0,
NULL,
0
};
struct mu_cmdline_capa mu_mailer_cmdline = {
"mailer", &mu_mailer_argp_child
};
static struct argp_option mu_debug_argp_options[] =
{
{ "debug-level", OPT_DEBUG_LEVEL, N_("LEVEL"), 0,
N_("set Mailutils debugging level"), 0 },
{ "debug-line-info", OPT_LINE_INFO, NULL, 0,
N_("show source info with debugging messages"), 0 },
{ NULL }
};
static error_t
mu_debug_argp_parser (int key, char *arg, struct argp_state *state)
{
static struct mu_argp_node_list lst;
switch (key)
{
case OPT_DEBUG_LEVEL:
mu_global_debug_from_string (arg, "command line");
/*mu_argp_node_list_new (&lst, "level", arg);*/
break;
case OPT_LINE_INFO:
mu_argp_node_list_new (&lst, "line-info", "yes");
break;
case ARGP_KEY_INIT:
mu_argp_node_list_init (&lst);
break;
case ARGP_KEY_FINI:
mu_argp_node_list_finish (&lst, "debug", NULL);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
struct argp mu_debug_argp = {
mu_debug_argp_options,
mu_debug_argp_parser,
};
struct argp_child mu_debug_argp_child = {
&mu_debug_argp,
0,
N_("Global debugging settings"),
0
};
struct mu_cmdline_capa mu_debug_cmdline = {
"debug", &mu_debug_argp_child
};