diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2016-10-24 14:42:43 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2016-10-24 14:42:43 +0300 |
commit | 8a582f9452db32de19dbb1de095353f5d68144e1 (patch) | |
tree | 0b25d70293f1bbc4f07c1fd0f188a999031c7bc2 /src/main.c | |
parent | 1d0f2efe1b3247b6cf86120f74df4bccb2afff7a (diff) | |
download | mailfromd-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.c | 723 |
1 files changed, 343 insertions, 380 deletions
@@ -37,3 +37,3 @@ #include <mailutils/syslog.h> -#include <mailutils/libargp.h> +#include <mailutils/cli.h> #include <mailutils/dbm.h> @@ -82,2 +82,6 @@ mu_stream_t mf_strecho; /* Output stream for 'echo' statements */ +#define ARG_UNSET (-1) + +static int trace_option = ARG_UNSET; +static mu_list_t trace_modules; @@ -257,13 +261,4 @@ host_in_relayed_domain_p(char *client) } - -static void -set_milter_timeout(union mf_option_value *val) -{ - if (smfi_settimeout(val->ov_time) == MI_FAILURE) { - mu_error(_("invalid milter timeout: %lu"), - (unsigned long)val->ov_time); - exit(EX_USAGE); - } -} +static mu_list_t relayed_domain_files; @@ -277,197 +272,127 @@ load_relay_file(void *item, void *data) static void -set_relay(union mf_option_value *val) +init_relayed_domains(void) { - mu_list_foreach(val->ov_list, load_relay_file, NULL); - mu_list_destroy(&val->ov_list); + mu_list_foreach(relayed_domain_files, load_relay_file, NULL); + mu_list_destroy(relayed_domain_files); } + +/* Command line parsing */ -void -set_stack_trace(union mf_option_value *val) +const char *program_version = "mailfromd (" PACKAGE_STRING ")"; +static char prog_doc[] = N_("mailfromd -- a general purpose milter daemon"); +static char args_doc[] = "[var=value...][SCRIPT]"; + +static void +opt_testmode(struct mu_parseopt *po, struct mu_option *op, char const *arg) { - stack_trace_option = val->ov_bool; + mode = MAILFROMD_TEST; + if (arg) { + test_state = string_to_state(arg); + if (test_state == smtp_state_none) { + mu_parseopt_error(op, + _("unknown smtp state tag: %s"), + arg); + exit(po->po_exit_error); + } + log_stream = "stderr"; + need_script = 1; + } } -static int -option_relay(char const *opt, union mf_option_value *val, char const *newval) +static void +opt_runmode(struct mu_parseopt *po, struct mu_option *op, char const *arg) { - if (!val->ov_list) - mu_list_create(&val->ov_list); - mu_list_append(val->ov_list, strdup(newval)); - return 0; + mode = MAILFROMD_RUN; + if (arg) + main_function_name = arg; + log_stream = "stderr"; + need_script = 1; } -struct mf_option_cache option_cache[] = { - { "stack-trace", mf_option_boolean, set_stack_trace }, - { "milter-timeout", mf_option_timeout, set_milter_timeout }, - { "relay", option_relay, set_relay }, - { NULL } -}; - - -/* Command line parsing */ - -const char *program_version = "mailfromd (" PACKAGE_STRING ")"; -static char doc[] = N_("mailfromd -- a general purpose milter daemon"); -static char args_doc[] = "[var=value...][SCRIPT]"; +static void +opt_lint(struct mu_parseopt *po, struct mu_option *op, char const *arg) +{ + log_stream = "stderr"; + script_check = 1; + need_script = 1; +} -enum mailfromd_option { - OPTION_DAEMON = 256, - OPTION_DOMAIN_FILE, - OPTION_DUMP_CODE, - OPTION_DUMP_GRAMMAR_TRACE, - OPTION_DUMP_LEX_TRACE, - OPTION_DUMP_MACROS, - OPTION_DUMP_TREE, - OPTION_DUMP_XREF, - OPTION_LOCATION_COLUMN, - OPTION_GACOPYZ_LOG, - OPTION_LINT, - OPTION_MILTER_TIMEOUT, - OPTION_MTASIM, - OPTION_NO_PREPROCESSOR, - OPTION_PREPROCESSOR, - OPTION_RUN, - OPTION_SHOW_DEFAULTS, - OPTION_STACK_TRACE, - OPTION_TIMEOUT, - OPTION_TRACE, - OPTION_TRACE_PROGRAM, -}; +static void +opt_show_defaults(struct mu_parseopt *po, struct mu_option *op, + char const *arg) +{ + mode = MAILFROMD_SHOW_DEFAULTS; + need_script = 0; +} -static struct argp_option options[] = { -#define GRP 0 - { NULL, 0, NULL, 0, - N_("Operation modifiers"), GRP }, - { "test", 't', N_("HANDLER"), OPTION_ARG_OPTIONAL, - N_("run in test mode"), GRP+1 }, - { "run", OPTION_RUN, N_("FUNC"), OPTION_ARG_OPTIONAL, - N_("run script and execute function FUNC (\"main\" if not given)"), - GRP+1 }, - { "lint", OPTION_LINT, NULL, 0, - N_("check syntax and exit"), GRP+1 }, - { "syntax-check", 0, NULL, OPTION_ALIAS, NULL, GRP+1 }, - { "show-defaults", OPTION_SHOW_DEFAULTS, NULL, 0, - N_("show compilation defaults"), GRP+1 }, - { "daemon", OPTION_DAEMON, NULL, 0, - N_("run in daemon mode (default)"), GRP+1 }, - - { NULL, 'E', NULL, 0, - N_("preprocess source files and exit"), GRP+1 }, - /* Reserved for future use: */ - { "compile", 'c', NULL, OPTION_HIDDEN, - N_("compile files"), GRP+1 }, - { "load", 'l', N_("FILE"), OPTION_HIDDEN, - N_("load library"), GRP+1 }, - { "load-dir", 'L', N_("DIR"), OPTION_HIDDEN, - N_("add DIR to the load path"), GRP+1 }, - -#undef GRP -#define GRP 20 - { NULL, 0, NULL, 0, - N_("General options"), GRP }, - { "include", 'I', N_("DIR"), 0, - N_("add the directory DIR to the list of directories to be " - "searched for header files"), GRP+1 }, - { "port", 'p', N_("STRING"), 0, - N_("set communication socket"), GRP+1 }, - { "mtasim", OPTION_MTASIM, NULL, 0, - N_("run in mtasim compatibility mode"), GRP+1 }, - { "optimize", 'O', N_("LEVEL"), OPTION_ARG_OPTIONAL, - N_("set code optimization level"), GRP+1 }, - { "variable", 'v', N_("VAR=VALUE"), 0, - N_("assign VALUE to VAR"), GRP+1 }, - { "relayed-domain-file", OPTION_DOMAIN_FILE, N_("FILE"), 0, - N_("read relayed domains from FILE"), GRP+1 }, - -#undef GRP -#define GRP 25 - { NULL, 0, NULL, 0, - N_("Preprocessor options"), GRP }, - { "preprocessor", OPTION_PREPROCESSOR, N_("COMMAND"), 0, - N_("use command as external preprocessor"), GRP+1 }, - { "no-preprocessor", OPTION_NO_PREPROCESSOR, NULL, 0, - N_("disable the use of external preprocessor"), GRP+1 }, - { "define", 'D', N_("NAME[=VALUE]"), 0, - N_("define a preprocessor symbol NAME as having VALUE, or empty"), - GRP+1 }, - { "undefine", 'U', N_("NAME"), 0, - N_("undefine a preprocessor symbol NAME"), - GRP+1 }, - -#undef GRP -#define GRP 30 - { NULL, 0, NULL, 0, - N_("Timeout control"), GRP }, - { "milter-timeout", OPTION_MILTER_TIMEOUT, N_("TIME"), 0, - N_("set MTA connection timeout"), GRP+1 }, - { "timeout", OPTION_TIMEOUT, N_("TIME"), 0, - N_("set I/O operation timeout"), GRP+1 }, - -#undef GRP -#define GRP 40 - { NULL, 0, NULL, 0, - N_("Informational and debugging options"), GRP }, - { "location-column", OPTION_LOCATION_COLUMN, NULL, 0, - N_("print location column numbers in compiler diagnostics messages"), - GRP+1 }, - { "trace", OPTION_TRACE, NULL, 0, - N_("trace executed actions"), GRP+1 }, - { "trace-program", OPTION_TRACE_PROGRAM, N_("MODULES"), - OPTION_ARG_OPTIONAL, - N_("enable filter program tracing"), GRP+1 }, - { "dump-code", OPTION_DUMP_CODE, NULL, 0, - N_("dump disassembled code"), GRP+1 }, - { "dump-grammar-trace", OPTION_DUMP_GRAMMAR_TRACE, NULL, 0, - N_("dump grammar traces"), GRP+1 }, - { "dump-lex-trace", OPTION_DUMP_LEX_TRACE, NULL, 0, - N_("dump lexical analyzer traces"), GRP+1 }, - { "dump-tree", OPTION_DUMP_TREE, NULL, 0, - N_("dump parser tree"), GRP+1 }, - { "dump-macros", OPTION_DUMP_MACROS, NULL, 0, - N_("show used Sendmail macros"), GRP+1 }, - { "xref", OPTION_DUMP_XREF, NULL, 0, - N_("produce a cross-reference listing"), GRP+1 }, - { "dump-xref", 0, NULL, OPTION_ALIAS, NULL, GRP+1 }, - { "gacopyz-log", OPTION_GACOPYZ_LOG, N_("LEVEL"), 0, - N_("set Gacopyz log level"), GRP+1 }, - { "stack-trace", OPTION_STACK_TRACE, NULL, 0, - N_("enable stack traces on runtime errors"), GRP+1 }, -#undef GRP +static void +opt_daemon(struct mu_parseopt *po, struct mu_option *op, + char const *arg) +{ + mode = MAILFROMD_DAEMON; + need_script = 1; +} -#if 0 -/* This entry is to pacify `make check-docs'. The options below - are defined in libmailutils. - */ - { "log-facility", } - { "mailer", } -#endif - { NULL } -}; +static void +opt_include_dir(struct mu_parseopt *po, struct mu_option *op, + char const *arg) +{ + add_include_dir(arg); +} -static int -validate_options() +static void +opt_port(struct mu_parseopt *po, struct mu_option *op, + char const *arg) { - /* FIXME */ - return 0; + mf_srvcfg_add("default", arg); } -struct arguments +static void +opt_mtasim(struct mu_parseopt *po, struct mu_option *op, + char const *arg) { - int trace; - mu_list_t trace_modules; -}; + mtasim_option = 1; + server_flags |= MF_SERVER_FOREGROUND; +} -#define ARG_UNSET (-1) +static void +opt_optimize(struct mu_parseopt *po, struct mu_option *op, + char const *arg) +{ + if (!arg) + optimization_level = 1; + else { + char *p; + optimization_level = strtoul(arg, &p, 0); + if (*p) + mu_parseopt_error(po, + _("-O level must be a non-negative integer")); + } +} static void -init_arguments(struct arguments *args) +opt_variable(struct mu_parseopt *po, struct mu_option *op, + char const *arg) { - args->trace = ARG_UNSET; - args->trace_modules = NULL; + char *p; + struct locus locus = { "<command line>", 1, 0 }; + + p = strchr(arg, '='); + if (!p) { + mu_parseopt_error(po, + _("expected assignment, but found `%s'"), + arg); + exit(po->po_exit_error); + } + *p++ = 0; + defer_initialize_variable(arg, p, &locus); } -static int -flush_trace_module(void *item, void *data) +static void +opt_relayed_domain_file(struct mu_parseopt *po, struct mu_option *op, + char const *arg) { - enable_prog_trace((const char *) item); + if (!relayed_domain_files) + mu_list_create(&relayed_domain_files); + mu_list_append(relayed_domain_files, mu_strdup(arg)); return 0; @@ -476,10 +401,5 @@ flush_trace_module(void *item, void *data) static void -flush_arguments(struct arguments *args) +opt_clear_ext_pp(struct mu_parseopt *po, struct mu_option *op, char const *arg) { - if (args->trace != ARG_UNSET) - do_trace = args->trace; - if (args->trace_modules) { - mu_list_foreach(args->trace_modules, flush_trace_module, NULL); - mu_list_destroy(&args->trace_modules); - } + ext_pp = NULL; } @@ -487,210 +407,230 @@ flush_arguments(struct arguments *args) static void -destroy_trace_item(void *ptr) +opt_define(struct mu_parseopt *po, struct mu_option *op, char const *arg) { - free(ptr); + ext_pp_options_given = 1; + add_pp_option("-D", arg); } -static error_t -parse_opt(int key, char *arg, struct argp_state *state) +static void +opt_undefine(struct mu_parseopt *po, struct mu_option *op, char const *arg) { - struct arguments *args = state->input; - switch (key) { - case 'D': - ext_pp_options_given = 1; - add_pp_option("-D", arg); - break; + ext_pp_options_given = 1; + add_pp_option("-U", arg); +} - case 'd': - mf_optcache_set_option("debug", arg); - break; - - case 'U': - ext_pp_options_given = 1; - add_pp_option("-U", arg); - break; - - case 'E': - preprocess_option = 1; - break; - - case 'I': - add_include_dir(arg); - break; - - case OPTION_LOCATION_COLUMN: - location_column_option = 1; - break; - - case OPTION_PREPROCESSOR: - ext_pp = arg; - break; +static void +opt_set_milter_timeout(struct mu_parseopt *po, struct mu_option *op, + char const *arg) +{ + int rc; + time_t v; + + if (mu_str_to_c(arg, mu_c_time, &v, NULL)) { + mu_parseopt_error(po, _("%s: not a valid interval"), arg); + exit(po->po_exit_error); + } - case OPTION_NO_PREPROCESSOR: - ext_pp = NULL; - break; - - case 'c': - case 'l': - case 'L': - argp_error(state, - _("the option `-%c' is not yet implemented"), - key); - break; - - case OPTION_LINT: - log_stream = "stderr"; - script_check = 1; - need_script = 1; - break; - - case 'p': - mf_optcache_set_option("port", arg); - break; - - case OPTION_RUN: - mode = MAILFROMD_RUN; - if (arg) - main_function_name = arg; - log_stream = "stderr"; - need_script = 1; - break; - - case 'O': - if (!arg) - optimization_level = 1; - else { - char *p; - optimization_level = strtoul(arg, &p, 0); - if (*p) - argp_error(state, - _("-O level must be a non-negative integer")); - } - break; - - case 't': - mode = MAILFROMD_TEST; - if (arg) { - test_state = string_to_state(arg); - if (test_state == smtp_state_none) - argp_error(state, - _("unknown smtp state tag: %s"), - arg); - } - log_stream = "stderr"; - need_script = 1; - break; + if (smfi_settimeout(v) == MI_FAILURE) { + mu_parseopt_error(po, _("invalid milter timeout: %s"), arg); + exit(po->po_exit_error); + } +} - case 'v': - { - char *p; - struct locus locus = { "<command line>", 1, 0 }; - - p = strchr(arg, '='); - if (!p) - argp_error(state, - _("expected assignment, but found `%s'"), - arg); - *p++ = 0; - defer_initialize_variable(arg, p, &locus); - break; +static void +opt_trace_program(struct mu_parseopt *po, struct mu_option *op, + char const *arg) +{ + if (!trace_modules) { + mu_list_create(&trace_modules); + mu_list_set_destroy_item(trace_modules, destroy_trace_item); } + mu_list_append(trace_modules, mu_strdup(arg ? arg : "all")); +} - case OPTION_DAEMON: - mode = MAILFROMD_DAEMON; - need_script = 1; - break; - - case OPTION_DOMAIN_FILE: - mf_optcache_set_option("relay", arg); - break; +static void +opt_dump_code(struct mu_parseopt *po, struct mu_option *op, + char const *arg) +{ + script_dump_code = 1; + log_stream = "stderr"; +} - case OPTION_DUMP_CODE: - script_dump_code = 1; - log_stream = "stderr"; - break; - - case OPTION_DUMP_GRAMMAR_TRACE: - script_ydebug = 1; - log_stream = "stderr"; - break; - - case OPTION_DUMP_LEX_TRACE: - yy_flex_debug = 1; - log_stream = "stderr"; - break; - - case OPTION_DUMP_MACROS: - script_dump_macros = 1; - log_stream = "stderr"; - break; - - case OPTION_DUMP_TREE: - script_dump_tree = 1; - log_stream = "stderr"; - break; +static void +opt_dump_grammar_trace(struct mu_parseopt *po, struct mu_option *op, + char const *arg) +{ + script_ydebug = 1; + log_stream = "stderr"; +} - case OPTION_DUMP_XREF: - script_dump_xref = 1; - log_stream = "stderr"; - break; - - case OPTION_GACOPYZ_LOG: - { - int lev = gacopyz_string_to_log_level(arg); - if (lev == -1) - argp_error(state, - _("%s: invalid log level"), - arg); - milter_setlogmask(SMI_LOG_FROM(lev)); - break; +static void +opt_dump_lex_trace(struct mu_parseopt *po, struct mu_option *op, + char const *arg) +{ + yy_flex_debug = 1; + log_stream = "stderr"; +} + +static void +opt_dump_macros(struct mu_parseopt *po, struct mu_option *op, + char const *arg) +{ + script_dump_macros = 1; + log_stream = "stderr"; +} + +static void +opt_dump_tree(struct mu_parseopt *po, struct mu_option *op, + char const *arg) +{ + script_dump_tree = 1; + log_stream = "stderr"; +} + +static void +opt_gacopyz_log(struct mu_parseopt *po, struct mu_option *op, + char const *arg) +{ + int lev = gacopyz_string_to_log_level(arg); + if (lev == -1) { + mu_parser_error(po, _("%s: invalid log level"), arg); + exit(po->po_exit_error); } - - case OPTION_MILTER_TIMEOUT: - mf_optcache_set_option("milter-timeout", arg); - break; + milter_setlogmask(SMI_LOG_FROM(lev)); +} - case OPTION_MTASIM: - mtasim_option = 1; - server_flags |= MF_SERVER_FOREGROUND; - break; - - case OPTION_SHOW_DEFAULTS: - mode = MAILFROMD_SHOW_DEFAULTS; - need_script = 0; - break; +static void +opt_dump_xref(struct mu_parseopt *po, struct mu_option *op, + char const *arg) +{ + script_dump_xref = 1; + log_stream = "stderr"; +} - case OPTION_STACK_TRACE: - mf_optcache_set_option("stack-trace", "yes"); - break; +static struct mu_option options[] = { + MU_OPTION_GROUP(N_("Operation modifiers")), + { "test", 't', N_("HANDLER"), MU_OPTION_ARG_OPTIONAL, + N_("run in test mode"), + mu_c_string, NULL, opt_testmode }, + { "run", 0, N_("FUNC"), MU_OPTION_ARG_OPTIONAL, + N_("run script and execute function FUNC (\"main\" if not given)"), + mu_c_string, NULL, opt_runmode }, + { "lint", 0, NULL, MU_OPTION_DEFAULT, + N_("check syntax and exit"), + mu_c_string, NULL, opt_lint }, + { "syntax-check", 0, NULL, MU_OPTION_ALIAS, }, + { "show-defaults", 0, NULL, MU_OPTION_DEFAULT, + N_("show compilation defaults"), + mu_c_string, NULL, opt_show_defaults }, + + { "daemon", 0, NULL, MU_OPTION_DEFAULT, + N_("run in daemon mode (default)"), + mu_c_string, NULL, opt_daemon }, - case OPTION_TIMEOUT: - mf_optcache_set_option("timeout", arg); - break; + { NULL, 'E', NULL, MU_OPTION_DEFAULT, + N_("preprocess source files and exit"), + mu_c_bool, &preprocess_option }, + /* Reserved for future use: */ + { "compile", 'c', NULL, MU_OPTION_HIDDEN, + N_("compile files"), + mu_c_void }, + { "load", 'l', N_("FILE"), MU_OPTION_HIDDEN, + N_("load library"), + mu_c_void }, + { "load-dir", 'L', N_("DIR"), MU_OPTION_HIDDEN, + N_("add DIR to the load path"), + mu_c_void }, + + MU_OPTION_GROUP(N_("General options")), + { "include", 'I', N_("DIR"), MU_OPTION_DEFAULT, + N_("add the directory DIR to the list of directories to be " + "searched for header files"), + mu_c_string, NULL, opt_include_dir }, + { "port", 'p', N_("STRING"), MU_OPTION_DEFAULT, + N_("set communication socket"), + mu_c_string, NULL, opt_port }, + { "mtasim", 0, NULL, MU_OPTION_DEFAULT, + N_("run in mtasim compatibility mode"), + mu_c_string, NULL, opt_mtasim }, + { "optimize", 'O', N_("LEVEL"), MU_OPTION_ARG_OPTIONAL, + N_("set code optimization level"), + mu_c_string, NULL, opt_optimize }, + { "variable", 'v', N_("VAR=VALUE"), MU_OPTION_DEFAULT, + N_("assign VALUE to VAR"), + mu_c_string, NULL, opt_variable }, + { "relayed-domain-file", 0, N_("FILE"), MU_OPTION_DEFAULT, + N_("read relayed domains from FILE"), + mu_c_string, NULL, opt_relayed_domain_file }, + + MU_OPTION_GROUP(N_("Preprocessor options")), + { "preprocessor", 0, N_("COMMAND"), MU_OPTION_DEFAULT, + N_("use command as external preprocessor"), + mu_c_string, &ext_pp }, + { "no-preprocessor", 0, NULL, MU_OPTION_DEFAULT, + N_("disable the use of external preprocessor"), + mu_c_string, NULL, opt_clear_ext_pp }, + { "define", 'D', N_("NAME[=VALUE]"), MU_OPTION_DEFAULT, + N_("define a preprocessor symbol NAME as having VALUE, or empty"), + mu_c_string, NULL, opt_define }, + { "undefine", 'U', N_("NAME"), MU_OPTION_DEFAULT, + N_("undefine a preprocessor symbol NAME"), + mu_c_string, NULL, opt_undefine }, - case OPTION_TRACE: - args->trace = 1; - break; + MU_OPTION_GROUP(N_("Timeout control")), + { "milter-timeout", 0, N_("TIME"), MU_OPTION_DEFAULT, + N_("set MTA connection timeout"), + mu_c_string, NULL, opt_set_milter_timeout }, + + MU_OPTION_GROUP (N_("Informational and debugging options")), + { "location-column", 0, NULL, MU_OPTION_DEFAULT, + N_("print location column numbers in compiler diagnostics messages"), + mu_c_bool, &location_column_option }, + { "trace", 0, NULL, MU_OPTION_DEFAULT, + N_("trace executed actions"), + mu_c_bool, &trace_option }, + { "trace-program", 0, N_("MODULES"), MU_OPTION_ARG_OPTIONAL, + N_("enable filter program tracing"), + mu_c_string, NULL, opt_trace_program }, + + { "dump-code", 0, NULL, MU_OPTION_DEFAULT, + N_("dump disassembled code"), + mu_c_string, NULL, opt_dump_code }, + + { "dump-grammar-trace", 0, NULL, MU_OPTION_DEFAULT, + N_("dump grammar traces"), + mu_c_string, NULL, opt_dump_grammar_trace } + { "dump-lex-trace", 0, NULL, MU_OPTION_DEFAULT, + N_("dump lexical analyzer traces"), + mu_c_string, NULL, opt_dump_lex_trace } + { "dump-tree", 0, NULL, MU_OPTION_DEFAULT, + N_("dump parser tree"), + mu_c_string, NULL, opt_dump_tree }, + { "dump-macros", 0, NULL, MU_OPTION_DEFAULT, + N_("show used Sendmail macros"), + mu_c_string, NULL, opt_dump_macros }, + { "xref", 0, NULL, MU_OPTION_DEFAULT, + N_("produce a cross-reference listing"), + mu_c_string, NULL, opt_dump_xref }, + { "dump-xref", 0, NULL, MU_OPTION_ALIAS }, + { "gacopyz-log", 0, N_("LEVEL"), MU_OPTION_DEFAULT, + N_("set Gacopyz log level"), + mu_c_string, NULL, opt_gacopyz_log }, + { "stack-trace", 0, NULL, MU_OPTION_DEFAULT, + N_("enable stack traces on runtime errors"), + mu_c_bool, &stack_trace_option }, + + MU_OPTION_END +}; - case OPTION_TRACE_PROGRAM: - if (!args->trace_modules) { - mu_list_create(&args->trace_modules); - mu_list_set_destroy_item(args->trace_modules, - destroy_trace_item); - } - mu_list_append(args->trace_modules, mu_strdup(arg ? arg : "all")); - break; +static int +validate_options() +{ + /* FIXME */ + return 0; +} - case ARGP_KEY_INIT: - milter_setlogmask(SMI_LOG_FROM(SMI_LOG_WARN)); - milter_settimeout(7200); - break; - - case ARGP_KEY_FINI: - if (validate_options()) - exit(EX_USAGE); - break; - - default: - return ARGP_ERR_UNKNOWN; - } +static int +flush_trace_module(void *item, void *data) +{ + enable_prog_trace((const char *) item); return 0; @@ -698,2 +638,19 @@ parse_opt(int key, char *arg, struct argp_state *state) +static void +flush_arguments(struct arguments *args) +{ + if (trace_option != ARG_UNSET) + do_trace = trace_option; + if (trace_modules) { + mu_list_foreach(trace_modules, flush_trace_module, NULL); + mu_list_destroy(&trace_modules); + } +} + +static void +destroy_trace_item(void *ptr) +{ + free(ptr); +} + static const char *capa[] = { @@ -1223,2 +1180,6 @@ main(int argc, char **argv) + /* Initialize milter */ + milter_setlogmask(SMI_LOG_FROM(SMI_LOG_WARN)); + milter_settimeout(7200); + /* Set default logging */ @@ -1240,3 +1201,2 @@ main(int argc, char **argv) mf_init_lock_options(); - mf_optcache_add(option_cache, 0, MF_OCF_NULL|MF_OCF_STATIC); @@ -1255,2 +1215,4 @@ main(int argc, char **argv) argpflag(argc, argv), &index, &args); + if (validate_options()) + exit(EX_USAGE); if (rc) @@ -1258,2 +1220,3 @@ main(int argc, char **argv) + init_relayed_domains(); flush_arguments(&args); |