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
@@ -31,4 +31,3 @@
#include <mailutils/mailutils.h>
-#include <mailutils/libcfg.h>
-#include <mailutils/libargp.h>
+#include <mailutils/cli.h>
#include <mailutils/daemon.h>
@@ -47,29 +46,5 @@ callout_alloc_die()
}
-
-
-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");
@@ -92,4 +67,3 @@ extern char **environ;
-static const char *capa[] = {
- "common",
+static char *capa[] = {
"debug",
@@ -97,15 +71,5 @@ static const char *capa[] = {
"locking",
+ ".mfd:server",
NULL
};
-
-static struct argp argp = {
- options,
- parse_opt,
- args_doc,
- doc,
- NULL,
- NULL,
- NULL
-};
-
@@ -118,3 +82,8 @@ mf_server_function(const char *key, struct mf_srvcfg *cfg)
-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,
+};
@@ -128,5 +97,2 @@ main(int argc, char **argv)
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 */
@@ -142,3 +108,2 @@ main(int argc, char **argv)
database_cfg_init();
- mf_init_lock_options();
mu_acl_cfg_init();
@@ -146,10 +111,4 @@ main(int argc, char **argv)
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();
diff --git a/src/mailfromd.h b/src/mailfromd.h
index a0c2fc1e..892188ae 100644
--- a/src/mailfromd.h
+++ b/src/mailfromd.h
@@ -23,3 +23,2 @@
#include <mailutils/alloc.h>
-#include <argp.h>
#include <sysexits.h>
diff --git a/src/main.c b/src/main.c
index 2e143011..94b7f6b0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -649,2 +649,3 @@ static char *capa[] = {
"mailer",
+ ".mfd:server",
NULL
@@ -1010,3 +1011,3 @@ mailfromd_show_defaults()
static int
-argpflag(int argc, char **argv)
+args_in_order(int argc, char **argv)
{
@@ -1019,7 +1020,6 @@ argpflag(int argc, char **argv)
|| memcmp(argv[i], "--run", 5) == 0)) {
- flag = ARGP_IN_ORDER;
- break;
+ return 1;
}
}
- return flag;
+ return 0;
}
@@ -1028,3 +1028,3 @@ argpflag(int argc, char **argv)
static void
-provide_default_milter_server()
+provide_default_milter_server(void)
{
@@ -1137,29 +1137,2 @@ 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)
@@ -1208,3 +1181,4 @@ main(int argc, char **argv)
- mf_getopt(&cli, &argc, &argv, capa);
+ mf_getopt(&cli, &argc, &argv, capa, args_in_order(argc, argv),
+ DEFAULT_CONFIG_FILE);
@@ -1212,4 +1186,2 @@ main(int argc, char **argv)
exit(EX_USAGE);
- if (rc)
- exit(EX_CONFIG);
diff --git a/src/mfdbtool.c b/src/mfdbtool.c
index 67e41ca2..ab32a57c 100644
--- a/src/mfdbtool.c
+++ b/src/mfdbtool.c
@@ -24,3 +24,2 @@
-#include <argp.h>
#include <mailutils/mailutils.h>
@@ -172,61 +171,116 @@ 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
};
@@ -239,81 +293,2 @@ db_proc_set_expire(struct db_format *fmt, void *data)
}
-
-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;
-}
-
@@ -328,3 +303,2 @@ cb_debug(void *data, mu_config_value_t *arg)
-
struct mu_cfg_param mfdbtool_cfg_param[] = {
@@ -358,23 +332,3 @@ struct mu_cfg_param mfdbtool_cfg_param[] = {
-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",
@@ -385,20 +339,9 @@ static const char *capa[] = {
-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)
{
@@ -408,4 +351,2 @@ alloc_die_fun()
-extern char *program_invocation_short_name;//FIXME
-
int
@@ -413,3 +354,3 @@ main(int argc, char **argv)
{
- int rc, index;
+ int rc;
@@ -417,5 +358,2 @@ main(int argc, char **argv)
mu_alloc_die_hook = alloc_die_fun;
- if (!program_invocation_short_name)
- program_invocation_short_name = argv[0];
- argp_program_version_hook = version;
@@ -423,12 +361,5 @@ main(int argc, char **argv)
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");
@@ -471,7 +402,2 @@ main(int argc, char **argv)
- mf_optcache_flush();
-
- argv += index;
- argc -= index;
-
if (chdir(state_dir)) {

Return to:

Send suggestions and report system problems to the System administrator.