aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2016-10-28 20:36:29 +0300
committerSergey Poznyakoff <gray@gnu.org>2016-10-28 20:46:42 +0300
commit8a851aaa1382d188ca2968e7bbd813e99507c4ff (patch)
treef10b7611125dc5124a66a0a5cda7d544a93d14d1 /src
parentf964cda496a9e01e5c941da71a9841fb0c2b2174 (diff)
downloadmailfromd-8a851aaa1382d188ca2968e7bbd813e99507c4ff.tar.gz
mailfromd-8a851aaa1382d188ca2968e7bbd813e99507c4ff.tar.bz2
Finish conversion. Version 7.99.96
Diffstat (limited to 'src')
-rw-r--r--src/calloutd.c63
-rw-r--r--src/mailfromd.h1
-rw-r--r--src/main.c42
-rw-r--r--src/mfdbtool.c310
4 files changed, 136 insertions, 280 deletions
diff --git a/src/calloutd.c b/src/calloutd.c
index b5c2d56b..4ad4103f 100644
--- a/src/calloutd.c
+++ b/src/calloutd.c
@@ -29,8 +29,7 @@
#include <sysexits.h>
#include <mailutils/mailutils.h>
-#include <mailutils/libcfg.h>
-#include <mailutils/libargp.h>
+#include <mailutils/cli.h>
#include <mailutils/daemon.h>
#include "libmf.h"
@@ -45,33 +44,9 @@ callout_alloc_die()
mu_error(_("not enough memory"));
abort();
}
-
-
-static void
-version(FILE *stream, struct argp_state *state)
-{
- mailfromd_version("calloutd", stream);
-}
-
const char *program_version = "calloutd (" PACKAGE_STRING ")";
-static char doc[] = N_("calloutd -- a call out server");
-static char args_doc[] = "";
-
-static struct argp_option options[] = {
- { NULL }
-};
-
-static error_t
-parse_opt(int key, char *arg, struct argp_state *state)
-{
- switch (key) {
- default:
- return ARGP_ERR_UNKNOWN;
- }
- return 0;
-}
-
+static char prog_doc[] = N_("calloutd -- a call out server");
struct mu_cfg_param callout_cfg_param[] = {
{ ".mfd:server", mu_cfg_section, NULL, 0, NULL, NULL },
@@ -90,24 +65,13 @@ struct mu_cfg_param callout_cfg_param[] = {
extern char **environ;
-static const char *capa[] = {
- "common",
+static char *capa[] = {
"debug",
"logging",
"locking",
+ ".mfd:server",
NULL
};
-
-static struct argp argp = {
- options,
- parse_opt,
- args_doc,
- doc,
- NULL,
- NULL,
- NULL
-};
-
int
mf_server_function(const char *key, struct mf_srvcfg *cfg)
@@ -116,7 +80,12 @@ mf_server_function(const char *key, struct mf_srvcfg *cfg)
return 0;
}
-extern char *program_invocation_short_name;//FIXME
+static char const calloutd_config_file[] = SYSCONFDIR "/calloutd.conf";
+
+struct mu_cli_setup cli = {
+ .cfg = callout_cfg_param,
+ .prog_doc = prog_doc,
+};
int
main(int argc, char **argv)
@@ -126,9 +95,6 @@ main(int argc, char **argv)
mf_init_nls();
mf_proctitle_init(argc, argv, environ);
mu_alloc_die_hook = callout_alloc_die;
- if (!program_invocation_short_name)
- program_invocation_short_name = argv[0];
- argp_program_version_hook = version;
/* Set default logging */
mu_log_facility = DEFAULT_LOG_FACILITY;
mu_stdstream_setup(MU_STDSTREAM_RESET_NONE);
@@ -140,18 +106,11 @@ main(int argc, char **argv)
mf_server_save_cmdline(argc, argv);
dnsbase_init();
database_cfg_init();
- mf_init_lock_options();
mu_acl_cfg_init();
srvman_init();
mf_srvcfg_init(argv[0], NULL);
+ mf_getopt(&cli, &argc, &argv, capa, 0, calloutd_config_file);
- mu_argp_init(program_version, "<" PACKAGE_BUGREPORT ">");
- mu_site_rcfile = SYSCONFDIR "/calloutd.conf";
- rc = mu_app_init(&argp, capa, callout_cfg_param, argc, argv,
- 0, NULL, NULL);
- if (rc)
- exit(EX_CONFIG);
- mf_optcache_flush();
mf_srvcfg_flush();
mf_server_lint_option = "--config-lint";
diff --git a/src/mailfromd.h b/src/mailfromd.h
index a0c2fc1e..892188ae 100644
--- a/src/mailfromd.h
+++ b/src/mailfromd.h
@@ -21,7 +21,6 @@
#include <mfapi.h>
#include <dns.h>
#include <mailutils/alloc.h>
-#include <argp.h>
#include <sysexits.h>
#define obstack_chunk_alloc malloc
#define obstack_chunk_free free
diff --git a/src/main.c b/src/main.c
index 2e143011..94b7f6b0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -647,6 +647,7 @@ static char *capa[] = {
"logging",
"locking",
"mailer",
+ ".mfd:server",
NULL
};
@@ -1008,7 +1009,7 @@ mailfromd_show_defaults()
}
static int
-argpflag(int argc, char **argv)
+args_in_order(int argc, char **argv)
{
int i;
int flag = 0;
@@ -1017,16 +1018,15 @@ argpflag(int argc, char **argv)
if (len > 3
&& (memcmp(argv[i], "--ru", 4) == 0
|| memcmp(argv[i], "--run", 5) == 0)) {
- flag = ARGP_IN_ORDER;
- break;
+ return 1;
}
}
- return flag;
+ return 0;
}
static void
-provide_default_milter_server()
+provide_default_milter_server(void)
{
if (mfd_srvman_count_servers() == 0) {
mu_diag_output(MU_DIAG_WARNING,
@@ -1135,33 +1135,6 @@ struct mu_cli_setup cli = {
};
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;
@@ -1206,12 +1179,11 @@ main(int argc, char **argv)
srvman_init();
mf_srvcfg_init(argv[0], "(milter | callout)");
- mf_getopt(&cli, &argc, &argv, capa);
+ mf_getopt(&cli, &argc, &argv, capa, args_in_order(argc, argv),
+ DEFAULT_CONFIG_FILE);
if (validate_options())
exit(EX_USAGE);
- if (rc)
- exit(EX_CONFIG);
init_relayed_domains();
diff --git a/src/mfdbtool.c b/src/mfdbtool.c
index 67e41ca2..ab32a57c 100644
--- a/src/mfdbtool.c
+++ b/src/mfdbtool.c
@@ -22,7 +22,6 @@
#include <stdlib.h>
#include <sysexits.h>
-#include <argp.h>
#include <mailutils/mailutils.h>
#include <mailutils/cli.h>
#include <mailutils/daemon.h>
@@ -170,65 +169,120 @@ mfdbtool_compact(int argc, char **argv)
const char *program_version = "mfdbtool (" PACKAGE_STRING ")";
-static char doc[] = N_("mfdbtool -- Mailfromd database management tool");
-static char args_doc[] = "";
-
-enum {
- OPTION_STATE_DIRECTORY = 256,
- OPTION_DELETE,
- OPTION_LIST,
- OPTION_EXPIRE,
- OPTION_COMPACT,
- OPTION_IGNORE_FAILED_READS,
- OPTION_PREDICT_NEXT,
- OPTION_ALL,
- OPTION_TIME_FORMAT
-};
+static char prog_doc[] = N_("mfdbtool -- Mailfromd database management tool");
+
+static void
+opt_delete(struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+ run = mfdbtool_delete;
+}
+
+static void
+opt_list(struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+ run = mfdbtool_list;
+}
+
+static void
+opt_expire(struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+ run = mfdbtool_expire;
+}
+
+static void
+opt_compact(struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+ run = mfdbtool_compact;
+}
-static struct argp_option options[] = {
-#define GRP 10
- { NULL, 0, NULL, 0,
- N_("Database management commands"), GRP },
- { "delete", OPTION_DELETE, NULL, 0,
- N_("delete given entries from the database"), GRP+1 },
- { "list", OPTION_LIST, NULL, 0,
- N_("list given database (default cache)"), GRP+1 },
- { "expire", OPTION_EXPIRE, NULL, 0,
- N_("delete expired entries from the database"), GRP+1 },
- { "compact", OPTION_COMPACT, NULL, 0,
- N_("compact the database"), GRP+1 },
-#undef GRP
-#define GRP 20
- { NULL, 0, NULL, 0,
- N_("Command modifiers"), GRP },
- { "file", 'f', N_("FILE"), 0,
+static void
+opt_format(struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+ format_option = db_format_lookup(arg);
+ if (format_option == NULL) {
+ mu_parseopt_error(po, _("unknown database format: %s"), arg);
+ exit(po->po_exit_error);
+ }
+}
+
+static void
+opt_predict(struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+ format_option = db_format_lookup("rate");
+ if (convert_rate(arg, &predict_rate) == 0)
+ predict_next_option = 1;
+}
+
+static void
+opt_debug(struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+ mu_debug_parse_spec(arg);
+}
+
+static void
+opt_expire_interval(struct mu_parseopt *po, struct mu_option *op,
+ char const *arg)
+{
+ time_t interval;
+ const char *endp;
+ if (parse_time_interval(arg, &interval, &endp)) {
+ mu_parseopt_error(po,
+ _("unrecognized time format (near `%s')"),
+ endp);
+ exit(po->po_exit_error);
+ }
+ expire_interval = interval;
+}
+
+static struct mu_option options[] = {
+ MU_OPTION_GROUP(N_("Database management commands")),
+ { "delete", 0, NULL, MU_OPTION_DEFAULT,
+ N_("delete given entries from the database"),
+ mu_c_string, NULL, opt_delete },
+ { "list", 0, NULL, MU_OPTION_DEFAULT,
+ N_("list given database (default cache)"),
+ mu_c_string, NULL, opt_list },
+ { "expire", 0, NULL, MU_OPTION_DEFAULT,
+ N_("delete expired entries from the database"),
+ mu_c_string, NULL, opt_expire },
+ { "compact", 0, NULL, MU_OPTION_DEFAULT,
+ N_("compact the database"),
+ mu_c_string, NULL, opt_compact },
+
+ MU_OPTION_GROUP(N_("Command modifiers")),
+ { "file", 'f', N_("FILE"), MU_OPTION_DEFAULT,
N_("DB file name to operate upon"),
- GRP+1 },
- { "format", 'H', N_("FORMAT"), 0,
- N_("format of the DB file to operate upon"), GRP+1 },
- { "ignore-failed-reads", OPTION_IGNORE_FAILED_READS, NULL, 0,
- N_("ignore failed reads while compacting the database"), GRP+1 },
- { "predict", OPTION_PREDICT_NEXT, N_("RATE"), 0,
+ mu_c_string, &file_option },
+ { "format", 'H', N_("FORMAT"), MU_OPTION_DEFAULT,
+ N_("format of the DB file to operate upon"),
+ mu_c_string, NULL, opt_format },
+ { "ignore-failed-reads", 0, NULL, MU_OPTION_DEFAULT,
+ N_("ignore failed reads while compacting the database"),
+ mu_c_bool, &ignore_failed_reads_option },
+ { "predict", 0, N_("RATE"), MU_OPTION_DEFAULT,
N_("predict when the user will be able to send next message"),
- GRP+1 },
- { "all", OPTION_ALL, NULL, 0,
+ mu_c_string, NULL, opt_predict },
+ { "all", 0, NULL, MU_OPTION_DEFAULT,
N_("with --compact or --expire: apply the operation to all "
- "available databases"), GRP+1 },
- { "time-format", OPTION_TIME_FORMAT, N_("FMT"), 0,
- N_("output timestamps using given format (default \"%c\")"), GRP+1 },
- { "debug", 'd', N_("LEVEL"), 0,
- N_("set debugging level"), GRP+1 },
+ "available databases"),
+ mu_c_bool, &all_option },
+ /* FIXME
+ { "time-format", 0, N_("FMT"), MU_OPTION_DEFAULT,
+ N_("output timestamps using given format (default \"%c\")"),
+ },
+ */
+ { "debug", 'd', N_("LEVEL"), MU_OPTION_DEFAULT,
+ N_("set debugging level"),
+ mu_c_string, NULL, opt_debug },
-#undef GRP
-#define GRP 30
- { NULL, 0, NULL, 0,
- N_("Configuration modifiers"), GRP },
- { "state-directory", OPTION_STATE_DIRECTORY, N_("DIR"), 0,
- N_("set new program state directory"), GRP+1 },
- { "expire-interval", 'e', N_("NUMBER"), 0,
- N_("set database expiration interval to NUMBER seconds"), GRP+1 },
-#undef GRP
- { NULL }
+ MU_OPTION_GROUP(N_("Configuration modifiers")),
+ { "state-directory", 0, N_("DIR"), MU_OPTION_DEFAULT,
+ N_("set new program state directory"),
+ mu_c_string, &state_dir },
+ { "expire-interval", 'e', N_("NUMBER"), MU_OPTION_DEFAULT,
+ N_("set database expiration interval to NUMBER seconds"),
+ mu_c_string, NULL, opt_expire_interval },
+ MU_OPTION_END
};
static int
@@ -237,85 +291,6 @@ db_proc_set_expire(struct db_format *fmt, void *data)
fmt->expire_interval = expire_interval;
return 0;
}
-
-static error_t
-parse_opt(int key, char *arg, struct argp_state *state)
-{
- switch (key) {
- case OPTION_STATE_DIRECTORY:
- mf_optcache_set_option("state-directory", arg);
- break;
-
- case 'd':
- mf_optcache_set_option("debug", arg);
- break;
-
- case 'e': {
- time_t interval;
- const char *endp;
- if (parse_time_interval(arg, &interval, &endp)) {
- argp_error(state,
- _("unrecognized time format (near `%s')"),
- endp);
- }
- expire_interval = interval;
- break;
- }
-
- case OPTION_PREDICT_NEXT:
- format_option = db_format_lookup("rate");
- if (convert_rate(arg, &predict_rate) == 0)
- predict_next_option = 1;
- break;
-
- case OPTION_IGNORE_FAILED_READS:
- ignore_failed_reads_option = 1;
- break;
-
- case OPTION_ALL:
- all_option = 1;
- break;
-
- case OPTION_TIME_FORMAT:
- ignore_failed_reads_option = 1;
- break;
-
- case 'f':
- file_option = arg;
- break;
-
- case 'H':
- format_option = db_format_lookup(arg);
- if (format_option == NULL)
- argp_error(state, _("unknown database format: %s"),
- arg);
- break;
-
- case OPTION_DELETE:
- run = mfdbtool_delete;
- break;
-
- case OPTION_LIST:
- run = mfdbtool_list;
- break;
-
- case OPTION_EXPIRE:
- run = mfdbtool_expire;
- break;
-
- case OPTION_COMPACT:
- run = mfdbtool_compact;
- break;
-
- case ARGP_KEY_FINI:
- break;
-
- default:
- return ARGP_ERR_UNKNOWN;
- }
- return 0;
-}
-
static int
cb_debug(void *data, mu_config_value_t *arg)
@@ -326,7 +301,6 @@ cb_debug(void *data, mu_config_value_t *arg)
return 0;
}
-
struct mu_cfg_param mfdbtool_cfg_param[] = {
{ "database-type", mu_c_string, &db_type_str, 0, NULL,
N_("Default database type"),
@@ -356,81 +330,38 @@ struct mu_cfg_param mfdbtool_cfg_param[] = {
{ NULL }
};
-static void
-set_state_directory(union mf_option_value *val)
-{
- state_dir = val->ov_string;
-}
-
-static void
-set_debug(union mf_option_value *val)
-{
- mu_debug_parse_spec(val->ov_string);
- free(val->ov_string);
-}
-
-static struct mf_option_cache option_cache[] = {
- { "state-directory", mf_option_string, set_state_directory },
- { "debug", mf_option_string, set_debug },
-
- { NULL }
-};
-
-static const char *capa[] = {
+static char *capa[] = {
"common",
"debug",
"locking",
NULL
};
-static struct argp argp = {
- options,
- parse_opt,
- args_doc,
- doc,
- NULL,
- NULL,
- NULL
+struct mu_cli_setup cli = {
+ .cfg = mfdbtool_cfg_param,
+ .prog_doc = prog_doc,
};
-static void
-version(FILE *stream, struct argp_state *state)
-{
- mailfromd_version("mfdbtool", stream);
-}
-
void
-alloc_die_fun()
+alloc_die_fun(void)
{
mu_error(_("not enough memory"));
abort();
}
-extern char *program_invocation_short_name;//FIXME
-
int
main(int argc, char **argv)
{
- int rc, index;
+ int rc;
mf_init_nls();
mu_alloc_die_hook = alloc_die_fun;
- if (!program_invocation_short_name)
- program_invocation_short_name = argv[0];
- argp_program_version_hook = version;
db_format_setup();
database_cfg_init();
- mf_init_lock_options();
- mf_optcache_add(option_cache, 0, MF_OCF_NULL|MF_OCF_STATIC);
-
- mu_argp_init(program_version, "<" PACKAGE_BUGREPORT ">");
- /* FIXME: Use mailfromd.conf somehow? */
- mu_site_rcfile = SYSCONFDIR "/mfdbtool.conf";
- rc = mu_app_init(&argp, capa, mfdbtool_cfg_param, argc, argv,
- 0, &index, NULL);
- if (rc)
- exit(EX_CONFIG);
+ mf_getopt(&cli, &argc, &argv, capa, 0,
+ /* FIXME: Use mailfromd.conf somehow? */
+ SYSCONFDIR "/mfdbtool.conf");
if (db_type_str) {
mu_url_t dbhint;
@@ -469,11 +400,6 @@ main(int argc, char **argv)
if (expire_interval)
db_format_enumerate(db_proc_set_expire, NULL);
- mf_optcache_flush();
-
- argv += index;
- argc -= index;
-
if (chdir(state_dir)) {
mu_error(_("cannot change to %s: %s"),
state_dir, strerror(errno));

Return to:

Send suggestions and report system problems to the System administrator.