diff options
Diffstat (limited to 'src/identity/gnunet-identity.c')
-rw-r--r-- | src/identity/gnunet-identity.c | 174 |
1 files changed, 166 insertions, 8 deletions
diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c index 77ba6c2cd..15cb17d1b 100644 --- a/src/identity/gnunet-identity.c +++ b/src/identity/gnunet-identity.c | |||
@@ -19,7 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file identity/gnunet-identity.c | 21 | * @file identity/gnunet-identity.c |
22 | * @brief IDENTITY monitoring command line tool | 22 | * @brief IDENTITY management command line tool |
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | */ | 24 | */ |
25 | #include "platform.h" | 25 | #include "platform.h" |
@@ -32,9 +32,34 @@ | |||
32 | static struct GNUNET_IDENTITY_Handle *sh; | 32 | static struct GNUNET_IDENTITY_Handle *sh; |
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Was verbose specified? | 35 | * Was "list" specified? |
36 | */ | 36 | */ |
37 | static int verbose; | 37 | static int list; |
38 | |||
39 | /** | ||
40 | * Was "monitor" specified? | ||
41 | */ | ||
42 | static int monitor; | ||
43 | |||
44 | /** | ||
45 | * -C option | ||
46 | */ | ||
47 | static char *create_ego; | ||
48 | |||
49 | /** | ||
50 | * -D option | ||
51 | */ | ||
52 | static char *delete_ego; | ||
53 | |||
54 | /** | ||
55 | * Handle for create operation. | ||
56 | */ | ||
57 | static struct GNUNET_IDENTITY_Operation *create_op; | ||
58 | |||
59 | /** | ||
60 | * Handle for delete operation. | ||
61 | */ | ||
62 | static struct GNUNET_IDENTITY_Operation *delete_op; | ||
38 | 63 | ||
39 | 64 | ||
40 | /** | 65 | /** |
@@ -52,6 +77,119 @@ shutdown_task (void *cls, | |||
52 | } | 77 | } |
53 | 78 | ||
54 | 79 | ||
80 | |||
81 | /** | ||
82 | * Test if we are finished yet. | ||
83 | */ | ||
84 | static void | ||
85 | test_finished () | ||
86 | { | ||
87 | if ( (NULL == create_op) && | ||
88 | (NULL == delete_op) && | ||
89 | (! list) && | ||
90 | (! monitor) ) | ||
91 | GNUNET_SCHEDULER_shutdown (); | ||
92 | } | ||
93 | |||
94 | |||
95 | /** | ||
96 | * Deletion operation finished. | ||
97 | * | ||
98 | * @param cls pointer to operation handle | ||
99 | * @param emsg NULL on success, otherwise an error message | ||
100 | */ | ||
101 | static void | ||
102 | delete_finished (void *cls, | ||
103 | const char *emsg) | ||
104 | { | ||
105 | struct GNUNET_IDENTITY_Operation **op = cls; | ||
106 | |||
107 | *op = NULL; | ||
108 | if (NULL != emsg) | ||
109 | fprintf (stderr, | ||
110 | "%s\n", | ||
111 | gettext (emsg)); | ||
112 | test_finished (); | ||
113 | } | ||
114 | |||
115 | |||
116 | /** | ||
117 | * Creation operation finished. | ||
118 | * | ||
119 | * @param cls pointer to operation handle | ||
120 | * @param ego ego handle | ||
121 | * @param ego_ctx context for application to store data for this ego | ||
122 | * (during the lifetime of this process, initially NULL) | ||
123 | * @param identifier identifier assigned by the user for this ego | ||
124 | */ | ||
125 | static void | ||
126 | create_finished (void *cls, | ||
127 | struct GNUNET_IDENTITY_Ego *ego, | ||
128 | void **ctx, | ||
129 | const char *identifier) | ||
130 | { | ||
131 | struct GNUNET_IDENTITY_Operation **op = cls; | ||
132 | |||
133 | *op = NULL; | ||
134 | if (NULL == ego) | ||
135 | fprintf (stderr, | ||
136 | "%s\n", | ||
137 | _("Failed to create ego\n")); | ||
138 | test_finished (); | ||
139 | } | ||
140 | |||
141 | |||
142 | /** | ||
143 | * If listing is enabled, prints information about the egos. | ||
144 | * | ||
145 | * This function is initially called for all egos and then again | ||
146 | * whenever a ego's identifier changes or if it is deleted. At the | ||
147 | * end of the initial pass over all egos, the function is once called | ||
148 | * with 'NULL' for 'ego'. That does NOT mean that the callback won't | ||
149 | * be invoked in the future or that there was an error. | ||
150 | * | ||
151 | * When used with 'GNUNET_IDENTITY_create' or 'GNUNET_IDENTITY_get', | ||
152 | * this function is only called ONCE, and 'NULL' being passed in | ||
153 | * 'ego' does indicate an error (i.e. name is taken or no default | ||
154 | * value is known). If 'ego' is non-NULL and if '*ctx' | ||
155 | * is set in those callbacks, the value WILL be passed to a subsequent | ||
156 | * call to the identity callback of 'GNUNET_IDENTITY_connect' (if | ||
157 | * that one was not NULL). | ||
158 | * | ||
159 | * When an identity is renamed, this function is called with the | ||
160 | * (known) ego but the NEW identifier. | ||
161 | * | ||
162 | * When an identity is deleted, this function is called with the | ||
163 | * (known) ego and "NULL" for the 'identifier'. In this case, | ||
164 | * the 'ego' is henceforth invalid (and the 'ctx' should also be | ||
165 | * cleaned up). | ||
166 | * | ||
167 | * @param cls closure | ||
168 | * @param ego ego handle | ||
169 | * @param ego_ctx context for application to store data for this ego | ||
170 | * (during the lifetime of this process, initially NULL) | ||
171 | * @param identifier identifier assigned by the user for this ego, | ||
172 | * NULL if the user just deleted the ego and it | ||
173 | * must thus no longer be used | ||
174 | */ | ||
175 | static void | ||
176 | print_ego (void *cls, | ||
177 | struct GNUNET_IDENTITY_Ego *ego, | ||
178 | void **ctx, | ||
179 | const char *identifier) | ||
180 | { | ||
181 | |||
182 | if (! (list | monitor)) | ||
183 | return; | ||
184 | if ( (NULL == ego) && (! monitor) ) | ||
185 | { | ||
186 | GNUNET_SCHEDULER_shutdown (); | ||
187 | return; | ||
188 | } | ||
189 | fprintf (stderr, "%s\n", identifier); | ||
190 | } | ||
191 | |||
192 | |||
55 | /** | 193 | /** |
56 | * Main function that will be run by the scheduler. | 194 | * Main function that will be run by the scheduler. |
57 | * | 195 | * |
@@ -64,9 +202,20 @@ static void | |||
64 | run (void *cls, char *const *args, const char *cfgfile, | 202 | run (void *cls, char *const *args, const char *cfgfile, |
65 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 203 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
66 | { | 204 | { |
67 | sh = GNUNET_IDENTITY_connect (cfg, NULL, NULL); | 205 | sh = GNUNET_IDENTITY_connect (cfg, &print_ego, NULL); |
206 | if (NULL != delete_ego) | ||
207 | delete_op = GNUNET_IDENTITY_delete (sh, | ||
208 | delete_ego, | ||
209 | &delete_finished, | ||
210 | &delete_op); | ||
211 | if (NULL != create_ego) | ||
212 | create_op = GNUNET_IDENTITY_create (sh, | ||
213 | create_ego, | ||
214 | &create_finished, | ||
215 | &create_op); | ||
68 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 216 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
69 | &shutdown_task, NULL); | 217 | &shutdown_task, NULL); |
218 | test_finished (); | ||
70 | } | 219 | } |
71 | 220 | ||
72 | 221 | ||
@@ -83,9 +232,18 @@ main (int argc, char *const *argv) | |||
83 | int res; | 232 | int res; |
84 | 233 | ||
85 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 234 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
86 | {'V', "verbose", NULL, | 235 | {'C', "create", "NAME", |
87 | gettext_noop ("verbose output"), | 236 | gettext_noop ("create ego NAME"), |
88 | 0, &GNUNET_GETOPT_set_one, &verbose}, | 237 | 1, &GNUNET_GETOPT_set_string, &create_ego}, |
238 | {'D', "delete", "NAME", | ||
239 | gettext_noop ("delete ego NAME "), | ||
240 | 1, &GNUNET_GETOPT_set_string, &delete_ego}, | ||
241 | {'L', "list", NULL, | ||
242 | gettext_noop ("list all egos"), | ||
243 | 0, &GNUNET_GETOPT_set_one, &list}, | ||
244 | {'m', "monitor", NULL, | ||
245 | gettext_noop ("run in monitor mode egos"), | ||
246 | 0, &GNUNET_GETOPT_set_one, &monitor}, | ||
89 | GNUNET_GETOPT_OPTION_END | 247 | GNUNET_GETOPT_OPTION_END |
90 | }; | 248 | }; |
91 | 249 | ||
@@ -93,7 +251,7 @@ main (int argc, char *const *argv) | |||
93 | return 2; | 251 | return 2; |
94 | 252 | ||
95 | res = GNUNET_PROGRAM_run (argc, argv, "gnunet-identity", | 253 | res = GNUNET_PROGRAM_run (argc, argv, "gnunet-identity", |
96 | gettext_noop ("Print information about IDENTITY state"), | 254 | gettext_noop ("Maintain egos"), |
97 | options, &run, | 255 | options, &run, |
98 | NULL); | 256 | NULL); |
99 | GNUNET_free ((void *) argv); | 257 | GNUNET_free ((void *) argv); |