diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 135 |
1 files changed, 67 insertions, 68 deletions
@@ -273,7 +273,7 @@ static void init_relayed_domains(void) { mu_list_foreach(relayed_domain_files, load_relay_file, NULL); - mu_list_destroy(relayed_domain_files); + mu_list_destroy(&relayed_domain_files); } /* Command line parsing */ @@ -289,7 +289,7 @@ opt_testmode(struct mu_parseopt *po, struct mu_option *op, char const *arg) if (arg) { test_state = string_to_state(arg); if (test_state == smtp_state_none) { - mu_parseopt_error(op, + mu_parseopt_error(po, _("unknown smtp state tag: %s"), arg); exit(po->po_exit_error); @@ -304,7 +304,7 @@ opt_runmode(struct mu_parseopt *po, struct mu_option *op, char const *arg) { mode = MAILFROMD_RUN; if (arg) - main_function_name = arg; + main_function_name = mu_strdup (arg); log_stream = "stderr"; need_script = 1; } @@ -395,7 +395,6 @@ opt_relayed_domain_file(struct mu_parseopt *po, struct mu_option *op, if (!relayed_domain_files) mu_list_create(&relayed_domain_files); mu_list_append(relayed_domain_files, mu_strdup(arg)); - return 0; } static void @@ -437,6 +436,12 @@ opt_set_milter_timeout(struct mu_parseopt *po, struct mu_option *op, } static void +destroy_trace_item(void *ptr) +{ + free(ptr); +} + +static void opt_trace_program(struct mu_parseopt *po, struct mu_option *op, char const *arg) { @@ -493,7 +498,7 @@ opt_gacopyz_log(struct mu_parseopt *po, struct mu_option *op, { int lev = gacopyz_string_to_log_level(arg); if (lev == -1) { - mu_parser_error(po, _("%s: invalid log level"), arg); + mu_parseopt_error(po, _("%s: invalid log level"), arg); exit(po->po_exit_error); } milter_setlogmask(SMI_LOG_FROM(lev)); @@ -507,7 +512,7 @@ opt_dump_xref(struct mu_parseopt *po, struct mu_option *op, log_stream = "stderr"; } -static struct mu_option options[] = { +static struct mu_option mailfromd_options[] = { MU_OPTION_GROUP(N_("Operation modifiers")), { "test", 't', N_("HANDLER"), MU_OPTION_ARG_OPTIONAL, N_("run in test mode"), @@ -598,10 +603,10 @@ static struct mu_option options[] = { { "dump-grammar-trace", 0, NULL, MU_OPTION_DEFAULT, N_("dump grammar traces"), - mu_c_string, NULL, opt_dump_grammar_trace } + 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 } + 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 }, @@ -620,7 +625,7 @@ static struct mu_option options[] = { mu_c_bool, &stack_trace_option }, MU_OPTION_END -}; +}, *options[] = { mailfromd_options, NULL }; static int validate_options() @@ -636,26 +641,8 @@ flush_trace_module(void *item, void *data) return 0; } -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[] = { +static char *capa[] = { "auth", - "common", "debug", "logging", "locking", @@ -663,18 +650,8 @@ static const char *capa[] = { NULL }; -static struct argp argp = { - options, - parse_opt, - args_doc, - doc, - NULL, - NULL, - NULL -}; - -/* Mailutils-2.0 configuration */ +/* Mailutils configuration */ static int cb_milter_timeout(void *data, mu_config_value_t *arg) @@ -850,27 +827,27 @@ cb_relayed_domain_file(void *data, mu_config_value_t *val) struct mu_cfg_param mf_cfg_param[] = { { ".mfd:server", mu_cfg_section, NULL, 0, NULL, NULL }, - { "stack-trace", mu_cfg_bool, &stack_trace_option, 0, NULL, + { "stack-trace", mu_c_bool, &stack_trace_option, 0, NULL, N_("Dump stack traces on runtime errors.") }, { "milter-timeout", mu_cfg_callback, NULL, 0, cb_milter_timeout, N_("Set milter timeout."), - N_("time") }, - { "callout-url", mu_cfg_string, &callout_server_url, 0, NULL, + N_("time: interval") }, + { "callout-url", mu_c_string, &callout_server_url, 0, NULL, N_("Sets the URL of the default callout server."), N_("url") }, { "include-path", mu_cfg_callback, NULL, 0, cb_include_path, N_("Add directories to the list of directories to be searched for " "header files. Argument is a list of directory names " "separated by colons."), - N_("path") }, + N_("path: string") }, { "setvar", mu_cfg_callback, NULL, 0, cb_set_variable, N_("Initialize a mailfromd variable <var> to <value>."), N_("var: string> <value: string-or-number") }, - { "script-file", mu_cfg_string, &script_file, 0, NULL, + { "script-file", mu_c_string, &script_file, 0, NULL, N_("Read filter script from <file>."), N_("file") }, - { "trace-actions", mu_cfg_bool, &do_trace, 0, NULL, + { "trace-actions", mu_c_bool, &do_trace, 0, NULL, N_("Trace executed actions.") }, { "trace-program", mu_cfg_callback, NULL, 0, cb_trace_program, N_("Enable filter program tracing."), @@ -891,7 +868,7 @@ struct mu_cfg_param mf_cfg_param[] = { N_("Set the time span between the two DBM locking attempts."), N_("time") }, - { "max-match-mx", mu_cfg_size, &max_match_mx, 0, NULL, + { "max-match-mx", mu_c_size, &max_match_mx, 0, NULL, N_("Maximum number of MXs used by MFL \"mx match\" operation.") }, { "runtime", mu_cfg_section, NULL }, @@ -1030,12 +1007,6 @@ mailfromd_show_defaults() db_format_enumerate(db_format_enumerator, NULL); } -static void -version(FILE *stream, struct argp_state *state) -{ - mailfromd_version("mailfromd", stream); -} - static int argpflag(int argc, char **argv) { @@ -1155,15 +1126,46 @@ mailfromd_alloc_die() } extern char **environ; -extern char *program_invocation_short_name;//FIXME +struct mu_cli_setup cli = { + .optv = options, + .cfg = mf_cfg_param, + .prog_doc = prog_doc, + .prog_args = args_doc +}; + +int +mf_getopt(struct mu_cli_setup *cli, int *pargc, char ***pargv, char **capa) +{ + struct mu_parseopt pohint; + struct mu_cfg_parse_hints cfhint; + + cfhint.site_rcfile = DEFAULT_CONFIG_FILE; + cfhint.flags = MU_CFG_PARSE_SITE_RCFILE; + + pohint.po_flags = 0; + + pohint.po_package_name = PACKAGE_NAME; + pohint.po_flags |= MU_PARSEOPT_PACKAGE_NAME; + + pohint.po_package_url = PACKAGE_URL; + pohint.po_flags |= MU_PARSEOPT_PACKAGE_URL; + + pohint.po_bug_address = PACKAGE_BUGREPORT; + pohint.po_flags |= MU_PARSEOPT_BUG_ADDRESS; + + pohint.po_version_hook = mailfromd_version; + pohint.po_flags |= MU_PARSEOPT_VERSION_HOOK; + + mu_cli_ext (*pargc, *pargv, cli, &pohint, &cfhint, capa, NULL, + pargc, pargv); +} + int main(int argc, char **argv) { int rc; - int index; prog_counter_t entry_point; - struct arguments args; int stderr_is_closed = stderr_closed_p(); mf_init_nls(); @@ -1173,9 +1175,6 @@ main(int argc, char **argv) MU_AUTH_REGISTER_ALL_MODULES(); mu_register_all_formats(); mu_register_all_mailer_formats(); - if (!program_invocation_short_name) - program_invocation_short_name = argv[0]; - argp_program_version_hook = version; yy_flex_debug = 0; /* Initialize milter */ @@ -1198,7 +1197,6 @@ main(int argc, char **argv) db_format_setup(); include_path_setup(); pragma_setup(); - mf_init_lock_options(); mf_server_save_cmdline(argc, argv); @@ -1208,25 +1206,26 @@ main(int argc, char **argv) srvman_init(); mf_srvcfg_init(argv[0], "(milter | callout)"); - mu_argp_init(program_version, "<" PACKAGE_BUGREPORT ">"); - mu_site_rcfile = DEFAULT_CONFIG_FILE; - init_arguments(&args); - rc = mu_app_init(&argp, capa, mf_cfg_param, argc, argv, - argpflag(argc, argv), &index, &args); + mf_getopt(&cli, &argc, &argv, capa); + if (validate_options()) exit(EX_USAGE); if (rc) exit(EX_CONFIG); init_relayed_domains(); - flush_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); + } + mf_srvcfg_flush(); alloc_ext_pp(); - argv += index; - argc -= index; - if (need_script) { char *new_script = NULL; if (argc) { |