aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/builtin/dns.bi6
-rw-r--r--src/builtin/io.bi2
-rw-r--r--src/builtin/mbox.bi2
-rw-r--r--src/builtin/msg.bi2
-rw-r--r--src/main.c723
-rw-r--r--src/mfdbtool.c12
-rw-r--r--src/savsrv.c3
-rw-r--r--src/srvcfg.c456
-rw-r--r--src/srvcfg.h2
9 files changed, 531 insertions, 677 deletions
diff --git a/src/builtin/dns.bi b/src/builtin/dns.bi
index 641cf5ae..d7596f9c 100644
--- a/src/builtin/dns.bi
+++ b/src/builtin/dns.bi
@@ -25,11 +25,11 @@ static size_t max_ptr = MAX_DNS_PTR;
static size_t max_a = MAX_DNS_A;
static size_t max_mx = MAX_DNS_MX;
static struct mu_cfg_param dns_cfg_param[] = {
- { "max-dns-reply-a", mu_cfg_size, &max_a, 0, NULL,
+ { "max-dns-reply-a", mu_c_size, &max_a, 0, NULL,
N_("Maximum number of A records in a DNS reply.") },
- { "max-dns-reply-ptr", mu_cfg_size, &max_a, 0, NULL,
+ { "max-dns-reply-ptr", mu_c_size, &max_a, 0, NULL,
N_("Maximum number of PTR records in a DNS reply.") },
- { "max-dns-reply-mx", mu_cfg_size, &max_mx, 0, NULL,
+ { "max-dns-reply-mx", mu_c_size, &max_mx, 0, NULL,
N_("Maximum number of MX records in a DNS reply.") },
{ NULL }
};
diff --git a/src/builtin/io.bi b/src/builtin/io.bi
index 72ecb770..0875937f 100644
--- a/src/builtin/io.bi
+++ b/src/builtin/io.bi
@@ -24,7 +24,7 @@
static size_t nstreams = MAX_IOSTREAMS;
static struct mu_cfg_param io_cfg_param[] = {
- { "max-streams", mu_cfg_size, &nstreams, 0, NULL,
+ { "max-streams", mu_c_size, &nstreams, 0, NULL,
N_("Maximum number of stream descriptors.") },
{ NULL }
};
diff --git a/src/builtin/mbox.bi b/src/builtin/mbox.bi
index f151bd4d..ea4c1f92 100644
--- a/src/builtin/mbox.bi
+++ b/src/builtin/mbox.bi
@@ -20,7 +20,7 @@
static size_t nmboxes = MAX_MBOXES;
static struct mu_cfg_param mbox_cfg_param[] = {
- { "max-open-mailboxes", mu_cfg_size, &nmboxes, 0, NULL,
+ { "max-open-mailboxes", mu_c_size, &nmboxes, 0, NULL,
N_("Maximum number of mailboxes to open simultaneously.") },
{ NULL }
};
diff --git a/src/builtin/msg.bi b/src/builtin/msg.bi
index 0de44a20..2fe21363 100644
--- a/src/builtin/msg.bi
+++ b/src/builtin/msg.bi
@@ -20,7 +20,7 @@
static size_t nmsgs = MAX_MSGS;
static struct mu_cfg_param msg_cfg_param[] = {
- { "max-open-messages", mu_cfg_size, &nmsgs, 0, NULL,
+ { "max-open-messages", mu_c_size, &nmsgs, 0, NULL,
N_("Maximum number of messages to open simultaneously.") },
{ NULL }
};
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 @@
#include <mailutils/mailutils.h>
#include <mailutils/server.h>
#include <mailutils/syslog.h>
-#include <mailutils/libargp.h>
+#include <mailutils/cli.h>
#include <mailutils/dbm.h>
#include "mailfromd.h"
@@ -80,6 +80,10 @@ char *callout_server_url;
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;
/* Preprocessor helper function */
static void
@@ -255,17 +259,8 @@ host_in_relayed_domain_p(char *client)
free(hbuf);
return rc;
}
-
-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;
static int
load_relay_file(void *item, void *data)
@@ -275,427 +270,389 @@ 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;
}
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;
}
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;
}
+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[] = {
"auth",
"common",
@@ -1221,6 +1178,10 @@ main(int argc, char **argv)
argp_program_version_hook = version;
yy_flex_debug = 0;
+ /* Initialize milter */
+ milter_setlogmask(SMI_LOG_FROM(SMI_LOG_WARN));
+ milter_settimeout(7200);
+
/* Set default logging */
mu_set_program_name(argv[0]);
mu_log_tag = (char*)mu_program_name;
@@ -1238,7 +1199,6 @@ main(int argc, char **argv)
include_path_setup();
pragma_setup();
mf_init_lock_options();
- mf_optcache_add(option_cache, 0, MF_OCF_NULL|MF_OCF_STATIC);
mf_server_save_cmdline(argc, argv);
@@ -1253,9 +1213,12 @@ main(int argc, char **argv)
init_arguments(&args);
rc = mu_app_init(&argp, capa, mf_cfg_param, argc, argv,
argpflag(argc, argv), &index, &args);
+ if (validate_options())
+ exit(EX_USAGE);
if (rc)
exit(EX_CONFIG);
+ init_relayed_domains();
flush_arguments(&args);
mf_srvcfg_flush();
diff --git a/src/mfdbtool.c b/src/mfdbtool.c
index b22dfc8b..67e41ca2 100644
--- a/src/mfdbtool.c
+++ b/src/mfdbtool.c
@@ -24,8 +24,7 @@
#include <argp.h>
#include <mailutils/mailutils.h>
-#include <mailutils/libcfg.h>
-#include <mailutils/libargp.h>
+#include <mailutils/cli.h>
#include <mailutils/daemon.h>
#include "libmf.h"
@@ -329,11 +328,11 @@ cb_debug(void *data, mu_config_value_t *arg)
struct mu_cfg_param mfdbtool_cfg_param[] = {
- { "database-type", mu_cfg_string, &db_type_str, 0, NULL,
+ { "database-type", mu_c_string, &db_type_str, 0, NULL,
N_("Default database type"),
N_("type") },
{ "database", mu_cfg_section, NULL, 0, NULL, NULL },
- { "state-directory", mu_cfg_string, &state_dir, 0, NULL,
+ { "state-directory", mu_c_string, &state_dir, 0, NULL,
N_("Set program state directory."),
N_("dir") },
{ "debug", mu_cfg_callback, NULL, 0, cb_debug,
@@ -347,11 +346,12 @@ struct mu_cfg_param mfdbtool_cfg_param[] = {
{ "lock-retry-count", mu_cfg_callback, NULL, 0,
config_cb_lock_retry_count,
- N_("Retry acquiring DBM file lock this number of times.") },
+ N_("Retry acquiring DBM file lock this number of times."),
+ N_("arg: number")},
{ "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") },
+ N_("time: interval") },
{ NULL }
};
diff --git a/src/savsrv.c b/src/savsrv.c
index 0841cbde..4a5898b9 100644
--- a/src/savsrv.c
+++ b/src/savsrv.c
@@ -29,8 +29,7 @@
#include <netdb.h>
#include <mailutils/mailutils.h>
-#include <mailutils/libcfg.h>
-#include <mailutils/libargp.h>
+#include <mailutils/cli.h>
#include <mailutils/daemon.h>
#include "libmf.h"
diff --git a/src/srvcfg.c b/src/srvcfg.c
index 0d0e89f7..68c89081 100644
--- a/src/srvcfg.c
+++ b/src/srvcfg.c
@@ -19,9 +19,8 @@
#endif
#include <mailutils/mailutils.h>
-#include <mailutils/libargp.h>
+#include <mailutils/cli.h>
#include <mailutils/dbm.h>
-#include <argp.h>
#include <sysexits.h>
#include "mailutils/alloc.h"
@@ -135,25 +134,6 @@ parse_milter_url(const char *str)
return url;
}
-static void
-set_debug(union mf_option_value *val)
-{
- mu_debug_parse_spec(val->ov_string);
- free(val->ov_string);
-}
-
-void
-set_source_info(union mf_option_value *val)
-{
- mu_debug_line_info = val->ov_bool;
-}
-
-static void
-set_user(union mf_option_value *val)
-{
- mf_server_user = val->ov_string;
-}
-
static int
mf_option_group(const char *arg)
{
@@ -169,41 +149,6 @@ mf_option_group(const char *arg)
return 0;
}
-
-static int
-option_group(char const *opt, union mf_option_value *val, char const *arg)
-{
- return mf_option_group(arg);
-}
-
-static int
-option_pidfile(char const *opt, union mf_option_value *val, char const *arg)
-{
- if (arg[0] != '/') {
- mu_error(_("invalid pidfile name: must be absolute"));
- return 1;
- }
- return mf_option_string(opt, val, arg);
-}
-
-static void
-set_pidfile(union mf_option_value *val)
-{
- pidfile = val->ov_string;
-}
-
-static void
-set_io_timeout(union mf_option_value *val)
-{
- io_timeout = val->ov_time;
-}
-
-static void
-set_logger_option(union mf_option_value *val)
-{
- log_stream = val->ov_string;
-}
-
static int
mf_option_state_directory(const char *arg)
{
@@ -227,17 +172,23 @@ mf_option_state_directory(const char *arg)
return 0;
}
-void
-set_state_directory(union mf_option_value *val)
+static int
+set_source_ip(char const *arg)
{
- /* nothing */
-}
+ int rc;
+ struct mu_sockaddr_hints hints;
-int
-option_state_directory(char const *opt, union mf_option_value *val,
- char const *arg)
-{
- return mf_option_state_directory(arg);
+ memset(&hints, 0, sizeof hints);
+ hints.family = AF_INET;
+ hints.socktype = SOCK_STREAM;
+ hints.protocol = IPPROTO_TCP;
+ rc = mu_sockaddr_from_node(&source_address, arg, NULL, &hints);
+ if (rc) {
+ mu_error(_("cannot convert %s to sockaddr: %s"),
+ arg, mu_strerror(rc));
+ return 1;
+ }
+ return 0;
}
void
@@ -266,48 +217,6 @@ mf_srvcfg_add(const char *type, const char *urlstr)
mfd_srvman_attach_server(srv);
}
}
-
-static void
-set_port(union mf_option_value *val)
-{
- mf_srvcfg_add("default", val->ov_string);
- free(val->ov_string);
-}
-
-static void
-set_source_ip(union mf_option_value *val)
-{
- int rc;
- struct mu_sockaddr_hints hints;
-
- memset(&hints, 0, sizeof hints);
- hints.family = AF_INET;
- hints.socktype = SOCK_STREAM;
- hints.protocol = IPPROTO_TCP;
- rc = mu_sockaddr_from_node(&source_address, val->ov_string, NULL,
-