Convert pop3d to mu_cli
Showing
2 changed files
with
62 additions
and
71 deletions
... | @@ -51,7 +51,7 @@ if MU_COND_DBM | ... | @@ -51,7 +51,7 @@ if MU_COND_DBM |
51 | endif | 51 | endif |
52 | 52 | ||
53 | pop3d_LDADD = \ | 53 | pop3d_LDADD = \ |
54 | ${MU_APP_LIBRARIES}\ | 54 | ${MU_APP_NEW_LIBRARIES}\ |
55 | ${MU_LIB_MBOX}\ | 55 | ${MU_LIB_MBOX}\ |
56 | ${MU_LIB_MH}\ | 56 | ${MU_LIB_MH}\ |
57 | ${MU_LIB_MAILDIR}\ | 57 | ${MU_LIB_MAILDIR}\ | ... | ... |
... | @@ -17,7 +17,7 @@ | ... | @@ -17,7 +17,7 @@ |
17 | 17 | ||
18 | #include "pop3d.h" | 18 | #include "pop3d.h" |
19 | #include "mailutils/pam.h" | 19 | #include "mailutils/pam.h" |
20 | #include "mailutils/libargp.h" | 20 | #include "mailutils/cli.h" |
21 | #include "mailutils/pop3.h" | 21 | #include "mailutils/pop3.h" |
22 | #include "mailutils/kwd.h" | 22 | #include "mailutils/kwd.h" |
23 | #include "tcpwrap.h" | 23 | #include "tcpwrap.h" |
... | @@ -59,24 +59,55 @@ char *login_stat_file = LOGIN_STAT_FILE; | ... | @@ -59,24 +59,55 @@ char *login_stat_file = LOGIN_STAT_FILE; |
59 | unsigned expire = EXPIRE_NEVER; /* Expire messages after this number of days */ | 59 | unsigned expire = EXPIRE_NEVER; /* Expire messages after this number of days */ |
60 | int expire_on_exit = 0; /* Delete expired messages on exit */ | 60 | int expire_on_exit = 0; /* Delete expired messages on exit */ |
61 | 61 | ||
62 | static error_t pop3d_parse_opt (int key, char *arg, struct argp_state *astate); | ||
63 | |||
64 | const char *program_version = "pop3d (" PACKAGE_STRING ")"; | 62 | const char *program_version = "pop3d (" PACKAGE_STRING ")"; |
65 | static char doc[] = N_("GNU pop3d -- the POP3 daemon."); | 63 | |
64 | static void | ||
65 | set_foreground (struct mu_parseopt *po, struct mu_option *opt, | ||
66 | char const *arg) | ||
67 | { | ||
68 | mu_m_server_set_foreground (server, 1); | ||
69 | } | ||
66 | 70 | ||
67 | #define OPT_FOREGROUND 256 | 71 | static void |
72 | set_inetd_mode (struct mu_parseopt *po, struct mu_option *opt, | ||
73 | char const *arg) | ||
74 | { | ||
75 | mu_m_server_set_mode (server, MODE_INTERACTIVE); | ||
76 | } | ||
77 | |||
78 | static void | ||
79 | set_daemon_mode (struct mu_parseopt *po, struct mu_option *opt, | ||
80 | char const *arg) | ||
81 | { | ||
82 | mu_m_server_set_mode (server, MODE_DAEMON); | ||
83 | if (arg) | ||
84 | { | ||
85 | size_t max_children; | ||
86 | char *errmsg; | ||
87 | int rc = mu_str_to_c (arg, mu_c_size, &max_children, &errmsg); | ||
88 | if (rc) | ||
89 | { | ||
90 | mu_parseopt_error (po, _("%s: bad argument"), arg); | ||
91 | exit (po->po_exit_error); | ||
92 | } | ||
93 | mu_m_server_set_max_children (server, max_children); | ||
94 | } | ||
95 | } | ||
68 | 96 | ||
69 | static struct argp_option options[] = { | 97 | static struct mu_option pop3d_options[] = { |
70 | #define GRP 0 | 98 | { "foreground", 0, NULL, MU_OPTION_DEFAULT, |
71 | { "foreground", OPT_FOREGROUND, 0, 0, N_("remain in foreground"), GRP+1}, | 99 | N_("remain in foreground"), |
72 | { "inetd", 'i', 0, 0, N_("run in inetd mode"), GRP+1}, | 100 | mu_c_bool, NULL, set_foreground }, |
73 | { "daemon", 'd', N_("NUMBER"), OPTION_ARG_OPTIONAL, | 101 | { "inetd", 'i', NULL, MU_OPTION_DEFAULT, |
74 | N_("runs in daemon mode with a maximum of NUMBER children"), GRP+1 }, | 102 | N_("run in inetd mode"), |
75 | #undef GRP | 103 | mu_c_bool, NULL, set_inetd_mode }, |
104 | { "daemon", 'd', N_("NUMBER"), MU_OPTION_ARG_OPTIONAL, | ||
105 | N_("runs in daemon mode with a maximum of NUMBER children"), | ||
106 | mu_c_string, NULL, set_daemon_mode }, | ||
76 | 107 | ||
77 | {NULL, 0, NULL, 0, NULL, 0} | 108 | {NULL, 0, NULL, 0, NULL, 0} |
78 | }; | 109 | }, *options[] = { pop3d_options, NULL }; |
79 | 110 | ||
80 | static int | 111 | static int |
81 | cb_bulletin_source (void *data, mu_config_value_t *val) | 112 | cb_bulletin_source (void *data, mu_config_value_t *val) |
82 | { | 113 | { |
... | @@ -271,61 +302,22 @@ static struct mu_cfg_param pop3d_cfg_param[] = { | ... | @@ -271,61 +302,22 @@ static struct mu_cfg_param pop3d_cfg_param[] = { |
271 | { NULL } | 302 | { NULL } |
272 | }; | 303 | }; |
273 | 304 | ||
274 | static struct argp argp = { | 305 | static char *capa[] = { |
275 | options, | ||
276 | pop3d_parse_opt, | ||
277 | NULL, | ||
278 | doc, | ||
279 | NULL, | ||
280 | NULL, NULL | ||
281 | }; | ||
282 | |||
283 | static const char *pop3d_argp_capa[] = { | ||
284 | "mailutils", | ||
285 | "auth", | 306 | "auth", |
286 | "common", | ||
287 | "debug", | 307 | "debug", |
288 | "mailbox", | 308 | "mailbox", |
289 | "locking", | 309 | "locking", |
290 | "logging", | 310 | "logging", |
311 | "tls", | ||
291 | NULL | 312 | NULL |
292 | }; | 313 | }; |
293 | 314 | ||
294 | static error_t | 315 | struct mu_cli_setup cli = { |
295 | pop3d_parse_opt (int key, char *arg, struct argp_state *astate) | 316 | options, |
296 | { | 317 | pop3d_cfg_param, |
297 | static mu_list_t lst; | 318 | N_("GNU pop3d -- the POP3 daemon."), |
298 | 319 | }; | |
299 | switch (key) | 320 | |
300 | { | ||
301 | case 'd': | ||
302 | mu_argp_node_list_new (lst, "mode", "daemon"); | ||
303 | if (arg) | ||
304 | mu_argp_node_list_new (lst, "max-children", arg); | ||
305 | break; | ||
306 | |||
307 | case 'i': | ||
308 | mu_argp_node_list_new (lst, "mode", "inetd"); | ||
309 | break; | ||
310 | |||
311 | case OPT_FOREGROUND: | ||
312 | mu_argp_node_list_new (lst, "foreground", "yes"); | ||
313 | break; | ||
314 | |||
315 | case ARGP_KEY_INIT: | ||
316 | mu_argp_node_list_init (&lst); | ||
317 | break; | ||
318 | |||
319 | case ARGP_KEY_FINI: | ||
320 | mu_argp_node_list_finish (lst, NULL, NULL); | ||
321 | break; | ||
322 | |||
323 | default: | ||
324 | return ARGP_ERR_UNKNOWN; | ||
325 | } | ||
326 | return 0; | ||
327 | } | ||
328 | |||
329 | int | 321 | int |
330 | pop3d_get_client_address (int fd, struct sockaddr_in *pcs) | 322 | pop3d_get_client_address (int fd, struct sockaddr_in *pcs) |
331 | { | 323 | { |
... | @@ -569,15 +561,10 @@ main (int argc, char **argv) | ... | @@ -569,15 +561,10 @@ main (int argc, char **argv) |
569 | /* Register the desired formats. */ | 561 | /* Register the desired formats. */ |
570 | mu_register_local_mbox_formats (); | 562 | mu_register_local_mbox_formats (); |
571 | 563 | ||
572 | #ifdef WITH_TLS | ||
573 | mu_gocs_register ("tls", mu_tls_module_init); | ||
574 | #endif /* WITH_TLS */ | ||
575 | mu_tcpwrapper_cfg_init (); | 564 | mu_tcpwrapper_cfg_init (); |
576 | manlock_cfg_init (); | 565 | manlock_cfg_init (); |
577 | mu_acl_cfg_init (); | 566 | mu_acl_cfg_init (); |
578 | 567 | ||
579 | mu_argp_init (NULL, NULL); | ||
580 | |||
581 | mu_m_server_create (&server, program_version); | 568 | mu_m_server_create (&server, program_version); |
582 | mu_m_server_set_config_size (server, sizeof (struct pop3d_srv_config)); | 569 | mu_m_server_set_config_size (server, sizeof (struct pop3d_srv_config)); |
583 | mu_m_server_set_conn (server, pop3d_connection); | 570 | mu_m_server_set_conn (server, pop3d_connection); |
... | @@ -598,10 +585,14 @@ main (int argc, char **argv) | ... | @@ -598,10 +585,14 @@ main (int argc, char **argv) |
598 | #ifdef ENABLE_DBM | 585 | #ifdef ENABLE_DBM |
599 | set_dbm_safety (); | 586 | set_dbm_safety (); |
600 | #endif | 587 | #endif |
601 | 588 | mu_cli_capa_register (&mu_cli_capa_tls); | |
602 | if (mu_app_init (&argp, pop3d_argp_capa, pop3d_cfg_param, | 589 | |
603 | argc, argv, 0, NULL, server)) | 590 | mu_cli (argc, argv, &cli, capa, server, &argc, &argv); |
604 | exit (EX_CONFIG); /* FIXME: No way to discern from EX_USAGE? */ | 591 | if (argc) |
592 | { | ||
593 | mu_error (_("too many arguments")); | ||
594 | exit (EX_USAGE); | ||
595 | } | ||
605 | 596 | ||
606 | if (expire == 0) | 597 | if (expire == 0) |
607 | expire_on_exit = 1; | 598 | expire_on_exit = 1; | ... | ... |
-
Please register or sign in to post a comment