aboutsummaryrefslogtreecommitdiff
path: root/src/identity/gnunet-identity.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/identity/gnunet-identity.c')
-rw-r--r--src/identity/gnunet-identity.c111
1 files changed, 102 insertions, 9 deletions
diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c
index e56a05807..c1803ea1d 100644
--- a/src/identity/gnunet-identity.c
+++ b/src/identity/gnunet-identity.c
@@ -23,8 +23,7 @@
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 * 24 *
25 * Todo: 25 * Todo:
26 * - add options to get/set default egos 26 * - add options to get default egos
27 * - print short hashes of egos when printing
28 */ 27 */
29#include "platform.h" 28#include "platform.h"
30#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
@@ -56,6 +55,21 @@ static char *create_ego;
56static char *delete_ego; 55static char *delete_ego;
57 56
58/** 57/**
58 * -s option.
59 */
60static char *set_ego;
61
62/**
63 * -S option.
64 */
65static char *set_subsystem;
66
67/**
68 * Operation handle for set operation.
69 */
70static struct GNUNET_IDENTITY_Operation *set_op;
71
72/**
59 * Handle for create operation. 73 * Handle for create operation.
60 */ 74 */
61static struct GNUNET_IDENTITY_Operation *create_op; 75static struct GNUNET_IDENTITY_Operation *create_op;
@@ -76,12 +90,26 @@ static void
76shutdown_task (void *cls, 90shutdown_task (void *cls,
77 const struct GNUNET_SCHEDULER_TaskContext *tc) 91 const struct GNUNET_SCHEDULER_TaskContext *tc)
78{ 92{
93 if (NULL != set_op)
94 {
95 GNUNET_IDENTITY_cancel (set_op);
96 set_op = NULL;
97 }
98 if (NULL != create_op)
99 {
100 GNUNET_IDENTITY_cancel (create_op);
101 create_op = NULL;
102 }
103 if (NULL != delete_op)
104 {
105 GNUNET_IDENTITY_cancel (delete_op);
106 delete_op = NULL;
107 }
79 GNUNET_IDENTITY_disconnect (sh); 108 GNUNET_IDENTITY_disconnect (sh);
80 sh = NULL; 109 sh = NULL;
81} 110}
82 111
83 112
84
85/** 113/**
86 * Test if we are finished yet. 114 * Test if we are finished yet.
87 */ 115 */
@@ -90,6 +118,8 @@ test_finished ()
90{ 118{
91 if ( (NULL == create_op) && 119 if ( (NULL == create_op) &&
92 (NULL == delete_op) && 120 (NULL == delete_op) &&
121 (NULL == set_op) &&
122 (NULL == set_ego) &&
93 (! list) && 123 (! list) &&
94 (! monitor) ) 124 (! monitor) )
95 GNUNET_SCHEDULER_shutdown (); 125 GNUNET_SCHEDULER_shutdown ();
@@ -139,6 +169,25 @@ create_finished (void *cls,
139 169
140 170
141/** 171/**
172 * Function called by #GNUNET_IDENTITY_set up on completion.
173 *
174 * @param cls NULL
175 * @param emsg error message (NULL on success)
176 */
177static void
178set_done (void *cls,
179 const char *emsg)
180{
181 set_op = NULL;
182 if (NULL != emsg)
183 fprintf (stderr,
184 _("Failed to set default ego: %s\n"),
185 emsg);
186 test_finished ();
187}
188
189
190/**
142 * If listing is enabled, prints information about the egos. 191 * If listing is enabled, prints information about the egos.
143 * 192 *
144 * This function is initially called for all egos and then again 193 * This function is initially called for all egos and then again
@@ -177,17 +226,48 @@ print_ego (void *cls,
177 void **ctx, 226 void **ctx,
178 const char *identifier) 227 const char *identifier)
179{ 228{
180 if (! (list | monitor)) 229 struct GNUNET_CRYPTO_EccPublicKey pk;
181 return; 230 char *s;
231
232 if ( (NULL != set_ego) &&
233 (NULL != ego) &&
234 (NULL != identifier) &&
235 (0 == strcmp (identifier,
236 set_ego)) )
237 {
238 set_op = GNUNET_IDENTITY_set (sh,
239 set_subsystem,
240 ego,
241 &set_done,
242 NULL);
243 GNUNET_free (set_subsystem);
244 set_subsystem = NULL;
245 GNUNET_free (set_ego);
246 set_ego = NULL;
247 }
248 if ( (NULL == ego) &&
249 (NULL != set_ego) )
250 {
251 fprintf (stderr,
252 "Could not set ego to `%s' for subsystem `%s', ego not known\n",
253 set_ego,
254 set_subsystem);
255 GNUNET_free (set_subsystem);
256 set_subsystem = NULL;
257 GNUNET_free (set_ego);
258 set_ego = NULL;
259 }
182 if ( (NULL == ego) && (! monitor) ) 260 if ( (NULL == ego) && (! monitor) )
183 { 261 {
184 GNUNET_SCHEDULER_shutdown (); 262 GNUNET_SCHEDULER_shutdown ();
185 return; 263 return;
186 } 264 }
187 if (monitor) 265 if (! (list | monitor))
188 fprintf (stderr, "%s - %p\n", identifier, ego); 266 return;
189 else if (NULL != identifier) 267 GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
190 fprintf (stderr, "%s\n", identifier); 268 s = GNUNET_CRYPTO_ecc_public_key_to_string (&pk);
269 if ( (monitor) || (NULL != identifier) )
270 fprintf (stderr, "%s - %s\n", identifier, s);
191} 271}
192 272
193 273
@@ -203,6 +283,13 @@ static void
203run (void *cls, char *const *args, const char *cfgfile, 283run (void *cls, char *const *args, const char *cfgfile,
204 const struct GNUNET_CONFIGURATION_Handle *cfg) 284 const struct GNUNET_CONFIGURATION_Handle *cfg)
205{ 285{
286 if ( (NULL == set_subsystem) ^
287 (NULL == set_ego) )
288 {
289 fprintf (stderr,
290 "Options -e and -s must always be specified together\n");
291 return;
292 }
206 sh = GNUNET_IDENTITY_connect (cfg, &print_ego, NULL); 293 sh = GNUNET_IDENTITY_connect (cfg, &print_ego, NULL);
207 if (NULL != delete_ego) 294 if (NULL != delete_ego)
208 delete_op = GNUNET_IDENTITY_delete (sh, 295 delete_op = GNUNET_IDENTITY_delete (sh,
@@ -242,9 +329,15 @@ main (int argc, char *const *argv)
242 {'d', "display", NULL, 329 {'d', "display", NULL,
243 gettext_noop ("display all egos"), 330 gettext_noop ("display all egos"),
244 0, &GNUNET_GETOPT_set_one, &list}, 331 0, &GNUNET_GETOPT_set_one, &list},
332 {'e', "ego", "NAME",
333 gettext_noop ("set default identity to EGO for a subsystem SUBSYSTEM (use together with -s)"),
334 1, &GNUNET_GETOPT_set_string, &set_ego},
245 {'m', "monitor", NULL, 335 {'m', "monitor", NULL,
246 gettext_noop ("run in monitor mode egos"), 336 gettext_noop ("run in monitor mode egos"),
247 0, &GNUNET_GETOPT_set_one, &monitor}, 337 0, &GNUNET_GETOPT_set_one, &monitor},
338 {'s', "set", "SUBSYSYSTEM",
339 gettext_noop ("set default identity to EGO for a subsystem SUBSYSTEM (use together with -e)"),
340 1, &GNUNET_GETOPT_set_string, &set_subsystem},
248 GNUNET_GETOPT_OPTION_END 341 GNUNET_GETOPT_OPTION_END
249 }; 342 };
250 343