diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2016-10-24 15:14:16 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2016-10-24 15:14:16 +0300 |
commit | f964cda496a9e01e5c941da71a9841fb0c2b2174 (patch) | |
tree | e6fc68cbd6e18077c24f5e3fd93de8860ce246b6 /src/main.c | |
parent | 8a582f9452db32de19dbb1de095353f5d68144e1 (diff) | |
download | mailfromd-f964cda496a9e01e5c941da71a9841fb0c2b2174.tar.gz mailfromd-f964cda496a9e01e5c941da71a9841fb0c2b2174.tar.bz2 |
Convert mailfromd to new interface.
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 135 |
1 files changed, 67 insertions, 68 deletions
@@ -270,13 +270,13 @@ load_relay_file(void *item, void *data) } 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 */ const char *program_version = "mailfromd (" PACKAGE_STRING ")"; static char prog_doc[] = N_("mailfromd -- a general purpose milter daemon"); @@ -286,13 +286,13 @@ static void opt_testmode(struct mu_parseopt *po, struct mu_option *op, char const *arg) { mode = MAILFROMD_TEST; 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); } log_stream = "stderr"; need_script = 1; @@ -301,13 +301,13 @@ opt_testmode(struct mu_parseopt *po, struct mu_option *op, char const *arg) static void 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; } static void opt_lint(struct mu_parseopt *po, struct mu_option *op, char const *arg) @@ -392,13 +392,12 @@ static void opt_relayed_domain_file(struct mu_parseopt *po, struct mu_option *op, char const *arg) { if (!relayed_domain_files) mu_list_create(&relayed_domain_files); mu_list_append(relayed_domain_files, mu_strdup(arg)); - return 0; } static void opt_clear_ext_pp(struct mu_parseopt *po, struct mu_option *op, char const *arg) { ext_pp = NULL; @@ -434,12 +433,18 @@ opt_set_milter_timeout(struct mu_parseopt *po, struct mu_option *op, mu_parseopt_error(po, _("invalid milter timeout: %s"), arg); exit(po->po_exit_error); } } 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) { if (!trace_modules) { mu_list_create(&trace_modules); mu_list_set_destroy_item(trace_modules, destroy_trace_item); @@ -490,13 +495,13 @@ opt_dump_tree(struct mu_parseopt *po, struct mu_option *op, 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); + mu_parseopt_error(po, _("%s: invalid log level"), arg); exit(po->po_exit_error); } milter_setlogmask(SMI_LOG_FROM(lev)); } static void @@ -504,13 +509,13 @@ opt_dump_xref(struct mu_parseopt *po, struct mu_option *op, char const *arg) { script_dump_xref = 1; 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"), 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)"), @@ -595,16 +600,16 @@ static struct mu_option options[] = { { "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 } + 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 }, { "dump-macros", 0, NULL, MU_OPTION_DEFAULT, N_("show used Sendmail macros"), mu_c_string, NULL, opt_dump_macros }, @@ -617,13 +622,13 @@ static struct mu_option options[] = { 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 -}; +}, *options[] = { mailfromd_options, NULL }; static int validate_options() { /* FIXME */ return 0; @@ -633,51 +638,23 @@ static int flush_trace_module(void *item, void *data) { enable_prog_trace((const char *) item); 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", "mailer", 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) { struct timeval tv; int rc = config_cb_timeout (&tv, arg); @@ -847,33 +824,33 @@ cb_relayed_domain_file(void *data, mu_config_value_t *val) return 0; } 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."), N_("modules: list") }, { "relayed-domain-file", mu_cfg_callback, NULL, 0, @@ -888,13 +865,13 @@ struct mu_cfg_param mf_cfg_param[] = { N_("Retry acquiring DBM file lock this number of times.") }, { "lock-retry-timeout", mu_cfg_callback, NULL, 0, config_cb_lock_retry_timeout, 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 }, { NULL } }; @@ -1027,18 +1004,12 @@ mailfromd_show_defaults() #endif printf("\n"); 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) { int i; int flag = 0; for (i = 0; i < argc; i++) { @@ -1152,33 +1123,61 @@ mailfromd_alloc_die() { parse_error("not enough memory"); abort(); } 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(); mf_proctitle_init(argc, argv, environ); mu_alloc_die_hook = mailfromd_alloc_die; 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 */ milter_setlogmask(SMI_LOG_FROM(SMI_LOG_WARN)); milter_settimeout(7200); @@ -1195,41 +1194,41 @@ main(int argc, char **argv) init_symbols(); builtin_setup(); mf_runtime_param_finish(); db_format_setup(); include_path_setup(); pragma_setup(); - mf_init_lock_options(); mf_server_save_cmdline(argc, argv); dnsbase_init(); mu_acl_cfg_init(); database_cfg_init(); 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) { int i, n = -1; for (i = 0; i < argc; i++) { if (strchr(argv[i], '=') == 0) { |