aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2016-10-24 14:42:43 +0300
committerSergey Poznyakoff <gray@gnu.org>2016-10-24 14:42:43 +0300
commit8a582f9452db32de19dbb1de095353f5d68144e1 (patch)
tree0b25d70293f1bbc4f07c1fd0f188a999031c7bc2 /src/main.c
parent1d0f2efe1b3247b6cf86120f74df4bccb2afff7a (diff)
downloadmailfromd-8a582f9452db32de19dbb1de095353f5d68144e1.tar.gz
mailfromd-8a582f9452db32de19dbb1de095353f5d68144e1.tar.bz2
Start transition to mu_cli interface
* configure.ac: Require mailutils 2.99.991 * src/main.c: Start transition to mu_cli * lib/optcache.c: Remove file. * lib/Makefile.am (optcache.c): Remove. * lib/libmf.h: Remove optcache prototypes. * lib/dbcfg.c: Convert to mu_option. * lib/utils.c: Likewise. * src/builtin/dns.bi: Likewise. * src/builtin/io.bi: Likewise. * src/builtin/mbox.bi: Likewise. * src/builtin/msg.bi: Likewise. * src/mfdbtool.c: Likewise. * src/savsrv.c: Likewise. * src/srvcfg.c: Likewise. * src/srvcfg.h: Likewise.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c723
1 files changed, 343 insertions, 380 deletions
diff --git a/src/main.c b/src/main.c
index 255500a9..3c4b8462 100644
--- a/src/main.c
+++ b/src/main.c
@@ -35,7 +35,7 @@
35#include <mailutils/mailutils.h> 35#include <mailutils/mailutils.h>
36#include <mailutils/server.h> 36#include <mailutils/server.h>
37#include <mailutils/syslog.h> 37#include <mailutils/syslog.h>
38#include <mailutils/libargp.h> 38#include <mailutils/cli.h>
39#include <mailutils/dbm.h> 39#include <mailutils/dbm.h>
40 40
41#include "mailfromd.h" 41#include "mailfromd.h"
@@ -80,6 +80,10 @@ char *callout_server_url;
80 80
81mu_stream_t mf_strecho; /* Output stream for 'echo' statements */ 81mu_stream_t mf_strecho; /* Output stream for 'echo' statements */
82 82
83#define ARG_UNSET (-1)
84
85static int trace_option = ARG_UNSET;
86static mu_list_t trace_modules;
83 87
84/* Preprocessor helper function */ 88/* Preprocessor helper function */
85static void 89static void
@@ -255,17 +259,8 @@ host_in_relayed_domain_p(char *client)
255 free(hbuf); 259 free(hbuf);
256 return rc; 260 return rc;
257} 261}
258
259 262
260static void 263static mu_list_t relayed_domain_files;
261set_milter_timeout(union mf_option_value *val)
262{
263 if (smfi_settimeout(val->ov_time) == MI_FAILURE) {
264 mu_error(_("invalid milter timeout: %lu"),
265 (unsigned long)val->ov_time);
266 exit(EX_USAGE);
267 }
268}
269 264
270static int 265static int
271load_relay_file(void *item, void *data) 266load_relay_file(void *item, void *data)
@@ -275,427 +270,389 @@ load_relay_file(void *item, void *data)
275} 270}
276 271
277static void 272static void
278set_relay(union mf_option_value *val) 273init_relayed_domains(void)
279{ 274{
280 mu_list_foreach(val->ov_list, load_relay_file, NULL); 275 mu_list_foreach(relayed_domain_files, load_relay_file, NULL);
281 mu_list_destroy(&val->ov_list); 276 mu_list_destroy(relayed_domain_files);
282} 277}
278
279/* Command line parsing */
283 280
284void 281const char *program_version = "mailfromd (" PACKAGE_STRING ")";
285set_stack_trace(union mf_option_value *val) 282static char prog_doc[] = N_("mailfromd -- a general purpose milter daemon");
283static char args_doc[] = "[var=value...][SCRIPT]";
284
285static void
286opt_testmode(struct mu_parseopt *po, struct mu_option *op, char const *arg)
286{ 287{
287 stack_trace_option = val->ov_bool; 288 mode = MAILFROMD_TEST;
289 if (arg) {
290 test_state = string_to_state(arg);
291 if (test_state == smtp_state_none) {
292 mu_parseopt_error(op,
293 _("unknown smtp state tag: %s"),
294 arg);
295 exit(po->po_exit_error);
296 }
297 log_stream = "stderr";
298 need_script = 1;
299 }
288} 300}
289 301
290static int 302static void
291option_relay(char const *opt, union mf_option_value *val, char const *newval) 303opt_runmode(struct mu_parseopt *po, struct mu_option *op, char const *arg)
292{ 304{
293 if (!val->ov_list) 305 mode = MAILFROMD_RUN;
294 mu_list_create(&val->ov_list); 306 if (arg)
295 mu_list_append(val->ov_list, strdup(newval)); 307 main_function_name = arg;
296 return 0; 308 log_stream = "stderr";
309 need_script = 1;
297} 310}
298 311
299struct mf_option_cache option_cache[] = { 312static void
300 { "stack-trace", mf_option_boolean, set_stack_trace }, 313opt_lint(struct mu_parseopt *po, struct mu_option *op, char const *arg)
301 { "milter-timeout", mf_option_timeout, set_milter_timeout }, 314{
302 { "relay", option_relay, set_relay }, 315 log_stream = "stderr";
303 { NULL } 316 script_check = 1;
304}; 317 need_script = 1;
305 318}
306
307/* Command line parsing */
308
309const char *program_version = "mailfromd (" PACKAGE_STRING ")";
310static char doc[] = N_("mailfromd -- a general purpose milter daemon");
311static char args_doc[] = "[var=value...][SCRIPT]";
312 319
313enum mailfromd_option { 320static void
314 OPTION_DAEMON = 256, 321opt_show_defaults(struct mu_parseopt *po, struct mu_option *op,
315 OPTION_DOMAIN_FILE, 322 char const *arg)
316 OPTION_DUMP_CODE, 323{
317 OPTION_DUMP_GRAMMAR_TRACE, 324 mode = MAILFROMD_SHOW_DEFAULTS;
318 OPTION_DUMP_LEX_TRACE, 325 need_script = 0;
319 OPTION_DUMP_MACROS, 326}
320 OPTION_DUMP_TREE,
321 OPTION_DUMP_XREF,
322 OPTION_LOCATION_COLUMN,
323 OPTION_GACOPYZ_LOG,
324 OPTION_LINT,
325 OPTION_MILTER_TIMEOUT,
326 OPTION_MTASIM,
327 OPTION_NO_PREPROCESSOR,
328 OPTION_PREPROCESSOR,
329 OPTION_RUN,
330 OPTION_SHOW_DEFAULTS,
331 OPTION_STACK_TRACE,
332 OPTION_TIMEOUT,
333 OPTION_TRACE,
334 OPTION_TRACE_PROGRAM,
335};
336 327
337static struct argp_option options[] = { 328static void
338#define GRP 0 329opt_daemon(struct mu_parseopt *po, struct mu_option *op,
339 { NULL, 0, NULL, 0, 330 char const *arg)
340 N_("Operation modifiers"), GRP }, 331{
341 { "test", 't', N_("HANDLER"), OPTION_ARG_OPTIONAL, 332 mode = MAILFROMD_DAEMON;
342 N_("run in test mode"), GRP+1 }, 333 need_script = 1;
343 { "run", OPTION_RUN, N_("FUNC"), OPTION_ARG_OPTIONAL, 334}
344 N_("run script and execute function FUNC (\"main\" if not given)"),
345 GRP+1 },
346 { "lint", OPTION_LINT, NULL, 0,
347 N_("check syntax and exit"), GRP+1 },
348 { "syntax-check", 0, NULL, OPTION_ALIAS, NULL, GRP+1 },
349 { "show-defaults", OPTION_SHOW_DEFAULTS, NULL, 0,
350 N_("show compilation defaults"), GRP+1 },
351 { "daemon", OPTION_DAEMON, NULL, 0,
352 N_("run in daemon mode (default)"), GRP+1 },
353
354 { NULL, 'E', NULL, 0,
355 N_("preprocess source files and exit"), GRP+1 },
356 /* Reserved for future use: */
357 { "compile", 'c', NULL, OPTION_HIDDEN,
358 N_("compile files"), GRP+1 },
359 { "load", 'l', N_("FILE"), OPTION_HIDDEN,
360 N_("load library"), GRP+1 },
361 { "load-dir", 'L', N_("DIR"), OPTION_HIDDEN,
362 N_("add DIR to the load path"), GRP+1 },
363
364#undef GRP
365#define GRP 20
366 { NULL, 0, NULL, 0,
367 N_("General options"), GRP },
368 { "include", 'I', N_("DIR"), 0,
369 N_("add the directory DIR to the list of directories to be "
370 "searched for header files"), GRP+1 },
371 { "port", 'p', N_("STRING"), 0,
372 N_("set communication socket"), GRP+1 },
373 { "mtasim", OPTION_MTASIM, NULL, 0,
374 N_("run in mtasim compatibility mode"), GRP+1 },
375 { "optimize", 'O', N_("LEVEL"), OPTION_ARG_OPTIONAL,
376 N_("set code optimization level"), GRP+1 },
377 { "variable", 'v', N_("VAR=VALUE"), 0,
378 N_("assign VALUE to VAR"), GRP+1 },
379 { "relayed-domain-file", OPTION_DOMAIN_FILE, N_("FILE"), 0,
380 N_("read relayed domains from FILE"), GRP+1 },
381
382#undef GRP
383#define GRP 25
384 { NULL, 0, NULL, 0,
385 N_("Preprocessor options"), GRP },
386 { "preprocessor", OPTION_PREPROCESSOR, N_("COMMAND"), 0,
387 N_("use command as external preprocessor"), GRP+1 },
388 { "no-preprocessor", OPTION_NO_PREPROCESSOR, NULL, 0,
389 N_("disable the use of external preprocessor"), GRP+1 },
390 { "define", 'D', N_("NAME[=VALUE]"), 0,
391 N_("define a preprocessor symbol NAME as having VALUE, or empty"),
392 GRP+1 },
393 { "undefine", 'U', N_("NAME"), 0,
394 N_("undefine a preprocessor symbol NAME"),
395 GRP+1 },
396
397#undef GRP
398#define GRP 30
399 { NULL, 0, NULL, 0,
400 N_("Timeout control"), GRP },
401 { "milter-timeout", OPTION_MILTER_TIMEOUT, N_("TIME"), 0,
402 N_("set MTA connection timeout"), GRP+1 },
403 { "timeout", OPTION_TIMEOUT, N_("TIME"), 0,
404 N_("set I/O operation timeout"), GRP+1 },
405
406#undef GRP
407#define GRP 40
408