Convert examples to mu_cli
Showing
3 changed files
with
47 additions
and
62 deletions
... | @@ -113,14 +113,14 @@ lsf_LDADD = \ | ... | @@ -113,14 +113,14 @@ lsf_LDADD = \ |
113 | 113 | ||
114 | muauth_CPPFLAGS = @MU_APP_COMMON_INCLUDES@ | 114 | muauth_CPPFLAGS = @MU_APP_COMMON_INCLUDES@ |
115 | muauth_LDADD = \ | 115 | muauth_LDADD = \ |
116 | ${MU_APP_LIBRARIES}\ | 116 | ${MU_APP_NEW_LIBRARIES}\ |
117 | ${MU_LIB_AUTH}\ | 117 | ${MU_LIB_AUTH}\ |
118 | @MU_AUTHLIBS@ \ | 118 | @MU_AUTHLIBS@ \ |
119 | ${MU_LIB_MAILUTILS} | 119 | ${MU_LIB_MAILUTILS} |
120 | 120 | ||
121 | muemail_CPPFLAGS = @MU_APP_COMMON_INCLUDES@ | 121 | muemail_CPPFLAGS = @MU_APP_COMMON_INCLUDES@ |
122 | muemail_LDADD = \ | 122 | muemail_LDADD = \ |
123 | ${MU_APP_LIBRARIES} \ | 123 | ${MU_APP_NEW_LIBRARIES} \ |
124 | ${MU_LIB_MAILUTILS} | 124 | ${MU_LIB_MAILUTILS} |
125 | 125 | ||
126 | mboxidx_CPPFLAGS = @MU_APP_COMMON_INCLUDES@ | 126 | mboxidx_CPPFLAGS = @MU_APP_COMMON_INCLUDES@ | ... | ... |
... | @@ -24,89 +24,74 @@ | ... | @@ -24,89 +24,74 @@ |
24 | #include <ctype.h> | 24 | #include <ctype.h> |
25 | #include <string.h> | 25 | #include <string.h> |
26 | #include <mailutils/mailutils.h> | 26 | #include <mailutils/mailutils.h> |
27 | #include "mailutils/libargp.h" | ||
28 | |||
29 | static char doc[] = | ||
30 | "muauth -- test mailutils authentication and authorization schemes"; | ||
31 | static char args_doc[] = "key"; | ||
32 | |||
33 | static const char *capa[] = { | ||
34 | "mailutils", | ||
35 | "auth", | ||
36 | "common", | ||
37 | "debug", | ||
38 | NULL | ||
39 | }; | ||
40 | |||
41 | static struct argp_option options[] = { | ||
42 | { "password", 'p', "STRING", 0, "user password", 0 }, | ||
43 | { "uid", 'u', NULL, 0, "test getpwuid functions", 0 }, | ||
44 | { "name", 'n', NULL, 0, "test getpwnam functions", 0 }, | ||
45 | { NULL }, | ||
46 | }; | ||
47 | 27 | ||
48 | enum mu_auth_key_type key_type = mu_auth_key_name; | 28 | enum mu_auth_key_type key_type = mu_auth_key_name; |
49 | char *password; | 29 | char *password; |
50 | 30 | ||
51 | static error_t | 31 | static void |
52 | parse_opt (int key, char *arg, struct argp_state *state) | 32 | use_uid (struct mu_parseopt *po, struct mu_option *opt, char const *arg) |
53 | { | 33 | { |
54 | switch (key) | ||
55 | { | ||
56 | case 'p': | ||
57 | password = arg; | ||
58 | break; | ||
59 | |||
60 | case 'u': | ||
61 | key_type = mu_auth_key_uid; | 34 | key_type = mu_auth_key_uid; |
62 | break; | 35 | } |
63 | 36 | ||
64 | case 'n': | 37 | static void |
38 | use_name (struct mu_parseopt *po, struct mu_option *opt, char const *arg) | ||
39 | { | ||
65 | key_type = mu_auth_key_name; | 40 | key_type = mu_auth_key_name; |
66 | break; | ||
67 | |||
68 | default: | ||
69 | return ARGP_ERR_UNKNOWN; | ||
70 | } | ||
71 | return 0; | ||
72 | } | 41 | } |
73 | 42 | ||
74 | static struct argp argp = { | 43 | static struct mu_option muauth_options[] = { |
44 | { "password", 'p', "STRING", MU_OPTION_DEFAULT, | ||
45 | "user password", | ||
46 | mu_c_string, &password }, | ||
47 | { "uid", 'u', NULL, MU_OPTION_DEFAULT, | ||
48 | "test getpwuid functions", | ||
49 | mu_c_string, NULL, use_uid }, | ||
50 | { "name", 'n', NULL, MU_OPTION_DEFAULT, | ||
51 | "test getpwnam functions", | ||
52 | mu_c_string, NULL, use_name }, | ||
53 | MU_OPTION_END | ||
54 | }, *options[] = { muauth_options, NULL }; | ||
55 | |||
56 | static char *capa[] = { | ||
57 | "auth", | ||
58 | "debug", | ||
59 | NULL | ||
60 | }; | ||
61 | |||
62 | static struct mu_cli_setup cli = { | ||
75 | options, | 63 | options, |
76 | parse_opt, | ||
77 | args_doc, | ||
78 | doc, | ||
79 | NULL, | 64 | NULL, |
80 | NULL, NULL | 65 | "muauth -- test mailutils authentication and authorization schemes", |
66 | "key" | ||
81 | }; | 67 | }; |
82 | 68 | ||
83 | int | 69 | int |
84 | main (int argc, char * argv []) | 70 | main (int argc, char * argv []) |
85 | { | 71 | { |
86 | int rc, index; | 72 | int rc; |
87 | struct mu_auth_data *auth; | 73 | struct mu_auth_data *auth; |
88 | void *key; | 74 | void *key; |
89 | uid_t uid; | 75 | uid_t uid; |
90 | 76 | ||
91 | MU_AUTH_REGISTER_ALL_MODULES (); | 77 | MU_AUTH_REGISTER_ALL_MODULES (); |
92 | mu_argp_init (NULL, NULL); | ||
93 | if (mu_app_init (&argp, capa, NULL, argc, argv, 0, &index, NULL)) | ||
94 | exit (1); | ||
95 | 78 | ||
96 | if (index == argc) | 79 | mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv); |
80 | |||
81 | if (argc == 0) | ||
97 | { | 82 | { |
98 | mu_error ("not enough arguments, try `%s --help' for more info", | 83 | mu_error ("not enough arguments, try `%s --help' for more info", |
99 | argv[0]); | 84 | mu_program_name); |
100 | return 1; | 85 | return 1; |
101 | } | 86 | } |
102 | 87 | ||
103 | if (key_type == mu_auth_key_uid) | 88 | if (key_type == mu_auth_key_uid) |
104 | { | 89 | { |
105 | uid = strtoul (argv[index], NULL, 0); | 90 | uid = strtoul (argv[0], NULL, 0); |
106 | key = &uid; | 91 | key = &uid; |
107 | } | 92 | } |
108 | else | 93 | else |
109 | key = argv[index]; | 94 | key = argv[0]; |
110 | 95 | ||
111 | rc = mu_get_auth (&auth, key_type, key); | 96 | rc = mu_get_auth (&auth, key_type, key); |
112 | printf ("mu_get_auth => %d, %s\n", rc, mu_strerror (rc)); | 97 | printf ("mu_get_auth => %d, %s\n", rc, mu_strerror (rc)); | ... | ... |
... | @@ -21,28 +21,28 @@ | ... | @@ -21,28 +21,28 @@ |
21 | #include <stdlib.h> | 21 | #include <stdlib.h> |
22 | #include <stdio.h> | 22 | #include <stdio.h> |
23 | #include <mailutils/util.h> | 23 | #include <mailutils/util.h> |
24 | #include "mailutils/libargp.h" | 24 | #include <mailutils/cli.h> |
25 | 25 | ||
26 | const char *capa[] = { | 26 | char *capa[] = { |
27 | "mailutils", | ||
28 | "address", | 27 | "address", |
29 | NULL | 28 | NULL |
30 | }; | 29 | }; |
31 | 30 | ||
31 | static struct mu_cli_setup cli = { NULL }; | ||
32 | |||
33 | |||
32 | int | 34 | int |
33 | main (int argc, char *argv[]) | 35 | main (int argc, char *argv[]) |
34 | { | 36 | { |
35 | int arg = 1; | 37 | mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv); |
36 | |||
37 | if (mu_app_init (NULL, capa, NULL, argc, argv, 0, &arg, NULL)) | ||
38 | exit (1); | ||
39 | 38 | ||
40 | if (!argv[arg]) | 39 | if (argc == 0) |
41 | printf ("current user -> %s\n", mu_get_user_email (0)); | 40 | printf ("current user -> %s\n", mu_get_user_email (0)); |
42 | else | 41 | else |
43 | { | 42 | { |
44 | for (; argv[arg]; arg++) | 43 | int i; |
45 | printf ("%s -> %s\n", argv[arg], mu_get_user_email (argv[arg])); | 44 | for (i = 0; i < argc; i++) |
45 | printf ("%s -> %s\n", argv[i], mu_get_user_email (argv[i])); | ||
46 | } | 46 | } |
47 | 47 | ||
48 | return 0; | 48 | return 0; | ... | ... |
-
Please register or sign in to post a comment