diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/identity/Makefile.am | 20 | ||||
-rw-r--r-- | src/identity/gnunet-identity.c | 86 | ||||
-rw-r--r-- | src/identity/gnunet-service-identity.c | 263 | ||||
-rw-r--r-- | src/identity/identity.h | 58 | ||||
-rw-r--r-- | src/identity/identity_api.c | 209 | ||||
-rw-r--r-- | src/identity/plugin_rest_identity.c | 382 | ||||
-rw-r--r-- | src/identity/test_identity.c | 24 | ||||
-rw-r--r-- | src/identity/test_identity_defaults.c | 301 | ||||
-rwxr-xr-x | src/identity/test_identity_messages.sh | 8 | ||||
-rw-r--r-- | src/include/gnunet_identity_service.h | 8 | ||||
-rw-r--r-- | src/messenger/gnunet-service-messenger_ego_store.c | 30 | ||||
-rw-r--r-- | src/namestore/gnunet-namestore-zonefile.c | 6 | ||||
-rw-r--r-- | src/namestore/gnunet-namestore.c | 120 | ||||
-rw-r--r-- | src/reclaim/gnunet-did.c | 6 |
14 files changed, 218 insertions, 1303 deletions
diff --git a/src/identity/Makefile.am b/src/identity/Makefile.am index 5a2110974..12d3906a8 100644 --- a/src/identity/Makefile.am +++ b/src/identity/Makefile.am | |||
@@ -49,10 +49,10 @@ bin_PROGRAMS = \ | |||
49 | gnunet-identity | 49 | gnunet-identity |
50 | 50 | ||
51 | libexec_PROGRAMS = \ | 51 | libexec_PROGRAMS = \ |
52 | gnunet-service-identity | 52 | gnunet-service-identity |
53 | 53 | ||
54 | gnunet_service_identity_SOURCES = \ | 54 | gnunet_service_identity_SOURCES = \ |
55 | gnunet-service-identity.c | 55 | gnunet-service-identity.c |
56 | gnunet_service_identity_LDADD = \ | 56 | gnunet_service_identity_LDADD = \ |
57 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 57 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
58 | $(top_builddir)/src/util/libgnunetutil.la \ | 58 | $(top_builddir)/src/util/libgnunetutil.la \ |
@@ -60,7 +60,7 @@ gnunet_service_identity_LDADD = \ | |||
60 | 60 | ||
61 | 61 | ||
62 | gnunet_identity_SOURCES = \ | 62 | gnunet_identity_SOURCES = \ |
63 | gnunet-identity.c | 63 | gnunet-identity.c |
64 | gnunet_identity_LDADD = \ | 64 | gnunet_identity_LDADD = \ |
65 | libgnunetidentity.la \ | 65 | libgnunetidentity.la \ |
66 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 66 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
@@ -68,8 +68,7 @@ gnunet_identity_LDADD = \ | |||
68 | $(GN_LIBINTL) | 68 | $(GN_LIBINTL) |
69 | 69 | ||
70 | check_PROGRAMS = \ | 70 | check_PROGRAMS = \ |
71 | test_identity \ | 71 | test_identity |
72 | test_identity_defaults | ||
73 | 72 | ||
74 | check_SCRIPTS = \ | 73 | check_SCRIPTS = \ |
75 | test_identity_messages.sh | 74 | test_identity_messages.sh |
@@ -85,17 +84,10 @@ test_identity_SOURCES = \ | |||
85 | test_identity_LDADD = \ | 84 | test_identity_LDADD = \ |
86 | libgnunetidentity.la \ | 85 | libgnunetidentity.la \ |
87 | $(top_builddir)/src/testing/libgnunettesting.la \ | 86 | $(top_builddir)/src/testing/libgnunettesting.la \ |
88 | $(top_builddir)/src/util/libgnunetutil.la | 87 | $(top_builddir)/src/util/libgnunetutil.la |
89 | |||
90 | test_identity_defaults_SOURCES = \ | ||
91 | test_identity_defaults.c | ||
92 | test_identity_defaults_LDADD = \ | ||
93 | libgnunetidentity.la \ | ||
94 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
95 | $(top_builddir)/src/util/libgnunetutil.la | ||
96 | 88 | ||
97 | EXTRA_DIST = \ | 89 | EXTRA_DIST = \ |
98 | test_identity.conf \ | 90 | test_identity.conf \ |
99 | test_identity_messages.sh | 91 | test_identity_messages.sh |
100 | 92 | ||
101 | 93 | ||
diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c index 97dc2ce7e..6f09113d8 100644 --- a/src/identity/gnunet-identity.c +++ b/src/identity/gnunet-identity.c | |||
@@ -106,11 +106,6 @@ static char *pubkey_msg; | |||
106 | static char *set_ego; | 106 | static char *set_ego; |
107 | 107 | ||
108 | /** | 108 | /** |
109 | * -S option. | ||
110 | */ | ||
111 | static char *set_subsystem; | ||
112 | |||
113 | /** | ||
114 | * Operation handle for set operation. | 109 | * Operation handle for set operation. |
115 | */ | 110 | */ |
116 | static struct GNUNET_IDENTITY_Operation *set_op; | 111 | static struct GNUNET_IDENTITY_Operation *set_op; |
@@ -178,7 +173,6 @@ test_finished (void) | |||
178 | if ( (NULL == create_op) && | 173 | if ( (NULL == create_op) && |
179 | (NULL == delete_op) && | 174 | (NULL == delete_op) && |
180 | (NULL == set_op) && | 175 | (NULL == set_op) && |
181 | (NULL == set_subsystem) && | ||
182 | (NULL == write_msg) && | 176 | (NULL == write_msg) && |
183 | (NULL == read_msg) && | 177 | (NULL == read_msg) && |
184 | (! list) && | 178 | (! list) && |
@@ -195,17 +189,17 @@ test_finished (void) | |||
195 | * Deletion operation finished. | 189 | * Deletion operation finished. |
196 | * | 190 | * |
197 | * @param cls pointer to operation handle | 191 | * @param cls pointer to operation handle |
198 | * @param emsg NULL on success, otherwise an error message | 192 | * @param ec the error code |
199 | */ | 193 | */ |
200 | static void | 194 | static void |
201 | delete_finished (void *cls, | 195 | delete_finished (void *cls, |
202 | const char *emsg) | 196 | enum GNUNET_ErrorCode ec) |
203 | { | 197 | { |
204 | struct GNUNET_IDENTITY_Operation **op = cls; | 198 | struct GNUNET_IDENTITY_Operation **op = cls; |
205 | 199 | ||
206 | *op = NULL; | 200 | *op = NULL; |
207 | if (NULL != emsg) | 201 | if (GNUNET_EC_NONE != ec) |
208 | fprintf (stderr, "%s\n", gettext (emsg)); | 202 | fprintf (stderr, "%s\n", GNUNET_ErrorCode_get_hint (ec)); |
209 | test_finished (); | 203 | test_finished (); |
210 | } | 204 | } |
211 | 205 | ||
@@ -215,12 +209,12 @@ delete_finished (void *cls, | |||
215 | * | 209 | * |
216 | * @param cls pointer to operation handle | 210 | * @param cls pointer to operation handle |
217 | * @param pk private key of the ego, or NULL on error | 211 | * @param pk private key of the ego, or NULL on error |
218 | * @param emsg error message, NULL on success | 212 | * @param ec the error code |
219 | */ | 213 | */ |
220 | static void | 214 | static void |
221 | create_finished (void *cls, | 215 | create_finished (void *cls, |
222 | const struct GNUNET_IDENTITY_PrivateKey *pk, | 216 | const struct GNUNET_IDENTITY_PrivateKey *pk, |
223 | const char *emsg) | 217 | enum GNUNET_ErrorCode ec) |
224 | { | 218 | { |
225 | struct GNUNET_IDENTITY_Operation **op = cls; | 219 | struct GNUNET_IDENTITY_Operation **op = cls; |
226 | 220 | ||
@@ -229,7 +223,7 @@ create_finished (void *cls, | |||
229 | { | 223 | { |
230 | fprintf (stderr, | 224 | fprintf (stderr, |
231 | _ ("Failed to create ego: %s\n"), | 225 | _ ("Failed to create ego: %s\n"), |
232 | emsg); | 226 | GNUNET_ErrorCode_get_hint (ec)); |
233 | global_ret = 1; | 227 | global_ret = 1; |
234 | } | 228 | } |
235 | else if (verbose) | 229 | else if (verbose) |
@@ -258,25 +252,6 @@ create_finished (void *cls, | |||
258 | 252 | ||
259 | 253 | ||
260 | /** | 254 | /** |
261 | * Function called by #GNUNET_IDENTITY_set up on completion. | ||
262 | * | ||
263 | * @param cls NULL | ||
264 | * @param emsg error message (NULL on success) | ||
265 | */ | ||
266 | static void | ||
267 | set_done (void *cls, const char *emsg) | ||
268 | { | ||
269 | set_op = NULL; | ||
270 | if (NULL != emsg) | ||
271 | { | ||
272 | fprintf (stderr, _ ("Failed to set default ego: %s\n"), emsg); | ||
273 | global_ret = 1; | ||
274 | } | ||
275 | test_finished (); | ||
276 | } | ||
277 | |||
278 | |||
279 | /** | ||
280 | * Encrypt a message given with -W, encrypted using public key of | 255 | * Encrypt a message given with -W, encrypted using public key of |
281 | * an identity given with -k. | 256 | * an identity given with -k. |
282 | */ | 257 | */ |
@@ -447,35 +422,6 @@ print_ego (void *cls, | |||
447 | char *s; | 422 | char *s; |
448 | char *privs; | 423 | char *privs; |
449 | 424 | ||
450 | if ( (NULL != set_ego) && | ||
451 | (NULL != set_subsystem) && | ||
452 | (NULL != ego) && | ||
453 | (NULL != identifier) && | ||
454 | (0 == strcmp (identifier, set_ego))) | ||
455 | { | ||
456 | set_op = GNUNET_IDENTITY_set (sh, | ||
457 | set_subsystem, | ||
458 | ego, | ||
459 | &set_done, | ||
460 | NULL); | ||
461 | GNUNET_free (set_subsystem); | ||
462 | set_subsystem = NULL; | ||
463 | GNUNET_free (set_ego); | ||
464 | set_ego = NULL; | ||
465 | } | ||
466 | if ( (NULL == ego) && | ||
467 | (NULL != set_ego) && | ||
468 | (NULL != set_subsystem) ) | ||
469 | { | ||
470 | fprintf (stderr, | ||
471 | "Could not set ego to `%s' for subsystem `%s', ego not known\n", | ||
472 | set_ego, | ||
473 | set_subsystem); | ||
474 | GNUNET_free (set_subsystem); | ||
475 | set_subsystem = NULL; | ||
476 | GNUNET_free (set_ego); | ||
477 | set_ego = NULL; | ||
478 | } | ||
479 | if ( (NULL == ego) && | 425 | if ( (NULL == ego) && |
480 | (NULL != set_ego) && | 426 | (NULL != set_ego) && |
481 | (NULL != read_msg) ) | 427 | (NULL != read_msg) ) |
@@ -557,12 +503,6 @@ run (void *cls, | |||
557 | const char *cfgfile, | 503 | const char *cfgfile, |
558 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 504 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
559 | { | 505 | { |
560 | if ((NULL != set_subsystem) && (NULL == set_ego)) | ||
561 | { | ||
562 | fprintf (stderr, "Option -s requires option -e to be specified as well.\n"); | ||
563 | return; | ||
564 | } | ||
565 | |||
566 | if ((NULL != read_msg) && (NULL == set_ego)) | 506 | if ((NULL != read_msg) && (NULL == set_ego)) |
567 | { | 507 | { |
568 | fprintf (stderr, | 508 | fprintf (stderr, |
@@ -577,8 +517,7 @@ run (void *cls, | |||
577 | } | 517 | } |
578 | sh = GNUNET_IDENTITY_connect (cfg, | 518 | sh = GNUNET_IDENTITY_connect (cfg, |
579 | (monitor | list) || | 519 | (monitor | list) || |
580 | (NULL != set_ego) || | 520 | (NULL != set_ego) |
581 | (NULL != set_subsystem) | ||
582 | ? &print_ego | 521 | ? &print_ego |
583 | : NULL, | 522 | : NULL, |
584 | NULL); | 523 | NULL); |
@@ -686,7 +625,7 @@ main (int argc, char *const *argv) | |||
686 | "ego", | 625 | "ego", |
687 | "NAME", | 626 | "NAME", |
688 | gettext_noop ( | 627 | gettext_noop ( |
689 | "set default identity to NAME for a subsystem SUBSYSTEM (use together with -s), restrict results to NAME (use together with -d) or read and decrypt a message for NAME (use together with -R)"), | 628 | "restrict results to NAME (use together with -d) or read and decrypt a message for NAME (use together with -R)"), |
690 | &set_ego), | 629 | &set_ego), |
691 | GNUNET_GETOPT_option_string ('k', | 630 | GNUNET_GETOPT_option_string ('k', |
692 | "key", | 631 | "key", |
@@ -702,13 +641,6 @@ main (int argc, char *const *argv) | |||
702 | "private-keys", | 641 | "private-keys", |
703 | gettext_noop ("display private keys as well"), | 642 | gettext_noop ("display private keys as well"), |
704 | &private_keys), | 643 | &private_keys), |
705 | GNUNET_GETOPT_option_string ( | ||
706 | 's', | ||
707 | "set", | ||
708 | "SUBSYSTEM", | ||
709 | gettext_noop ( | ||
710 | "set default identity to EGO for a subsystem SUBSYSTEM (use together with -e)"), | ||
711 | &set_subsystem), | ||
712 | GNUNET_GETOPT_option_verbose (&verbose), | 644 | GNUNET_GETOPT_option_verbose (&verbose), |
713 | GNUNET_GETOPT_OPTION_END | 645 | GNUNET_GETOPT_OPTION_END |
714 | }; | 646 | }; |
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c index 51fca7816..5e3f7bb35 100644 --- a/src/identity/gnunet-service-identity.c +++ b/src/identity/gnunet-service-identity.c | |||
@@ -205,30 +205,21 @@ shutdown_task (void *cls) | |||
205 | * | 205 | * |
206 | * @param client client that should receive the result code | 206 | * @param client client that should receive the result code |
207 | * @param result_code code to transmit | 207 | * @param result_code code to transmit |
208 | * @param emsg error message to include (or NULL for none) | ||
209 | */ | 208 | */ |
210 | static void | 209 | static void |
211 | send_result_code (struct GNUNET_SERVICE_Client *client, | 210 | send_result_code (struct GNUNET_SERVICE_Client *client, |
212 | uint32_t result_code, | 211 | uint32_t result_code) |
213 | const char *emsg) | ||
214 | { | 212 | { |
215 | struct ResultCodeMessage *rcm; | 213 | struct ResultCodeMessage *rcm; |
216 | struct GNUNET_MQ_Envelope *env; | 214 | struct GNUNET_MQ_Envelope *env; |
217 | size_t elen; | ||
218 | 215 | ||
219 | if (NULL == emsg) | ||
220 | elen = 0; | ||
221 | else | ||
222 | elen = strlen (emsg) + 1; | ||
223 | env = | 216 | env = |
224 | GNUNET_MQ_msg_extra (rcm, elen, GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE); | 217 | GNUNET_MQ_msg (rcm, GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE); |
225 | rcm->result_code = htonl (result_code); | 218 | rcm->result_code = htonl (result_code); |
226 | if (0 < elen) | ||
227 | GNUNET_memcpy (&rcm[1], emsg, elen); | ||
228 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 219 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
229 | "Sending result %d (%s) to client\n", | 220 | "Sending result %d (%s) to client\n", |
230 | (int) result_code, | 221 | (int) result_code, |
231 | emsg); | 222 | GNUNET_ErrorCode_get_hint (result_code)); |
232 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); | 223 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); |
233 | } | 224 | } |
234 | 225 | ||
@@ -257,33 +248,6 @@ create_update_message (struct Ego *ego) | |||
257 | 248 | ||
258 | 249 | ||
259 | /** | 250 | /** |
260 | * Create a set default message with information about the current state of an ego. | ||
261 | * | ||
262 | * @param ego ego to create message for | ||
263 | * @param servicename name of the service to provide in the message | ||
264 | * @return corresponding set default message | ||
265 | */ | ||
266 | static struct GNUNET_MQ_Envelope * | ||
267 | create_set_default_message (struct Ego *ego, | ||
268 | const char *servicename) | ||
269 | { | ||
270 | struct SetDefaultMessage *sdm; | ||
271 | struct GNUNET_MQ_Envelope *env; | ||
272 | size_t name_len; | ||
273 | |||
274 | name_len = (NULL == servicename) ? 0 : (strlen (servicename) + 1); | ||
275 | env = GNUNET_MQ_msg_extra (sdm, | ||
276 | name_len, | ||
277 | GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); | ||
278 | sdm->name_len = htons (name_len); | ||
279 | sdm->reserved = htons (0); | ||
280 | sdm->private_key = ego->pk; | ||
281 | GNUNET_memcpy (&sdm[1], servicename, name_len); | ||
282 | return env; | ||
283 | } | ||
284 | |||
285 | |||
286 | /** | ||
287 | * Handler for START message from client, sends information | 251 | * Handler for START message from client, sends information |
288 | * about all identities to the client immediately and | 252 | * about all identities to the client immediately and |
289 | * adds the client to the notification context for future | 253 | * adds the client to the notification context for future |
@@ -370,7 +334,7 @@ handle_lookup_message (void *cls, | |||
370 | GNUNET_SERVICE_client_continue (client); | 334 | GNUNET_SERVICE_client_continue (client); |
371 | return; | 335 | return; |
372 | } | 336 | } |
373 | send_result_code (client, 0, "ego not found"); | 337 | send_result_code (client, GNUNET_EC_IDENTITY_NOT_FOUND); |
374 | GNUNET_SERVICE_client_continue (client); | 338 | GNUNET_SERVICE_client_continue (client); |
375 | } | 339 | } |
376 | 340 | ||
@@ -433,200 +397,7 @@ handle_lookup_by_suffix_message (void *cls, | |||
433 | GNUNET_SERVICE_client_continue (client); | 397 | GNUNET_SERVICE_client_continue (client); |
434 | return; | 398 | return; |
435 | } | 399 | } |
436 | send_result_code (client, 0, "ego not found"); | 400 | send_result_code (client, GNUNET_EC_IDENTITY_NOT_FOUND); |
437 | GNUNET_SERVICE_client_continue (client); | ||
438 | } | ||
439 | |||
440 | |||
441 | /** | ||
442 | * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT message | ||
443 | * | ||
444 | * @param cls client sending the message | ||
445 | * @param msg message of type `struct GetDefaultMessage` | ||
446 | * @return #GNUNET_OK if @a msg is well-formed | ||
447 | */ | ||
448 | static int | ||
449 | check_get_default_message (void *cls, | ||
450 | const struct GetDefaultMessage *msg) | ||
451 | { | ||
452 | uint16_t size; | ||
453 | uint16_t name_len; | ||
454 | const char *name; | ||
455 | |||
456 | size = ntohs (msg->header.size); | ||
457 | if (size <= sizeof(struct GetDefaultMessage)) | ||
458 | { | ||
459 | GNUNET_break (0); | ||
460 | return GNUNET_SYSERR; | ||
461 | } | ||
462 | name = (const char *) &msg[1]; | ||
463 | name_len = ntohs (msg->name_len); | ||
464 | if ((name_len + sizeof(struct GetDefaultMessage) != size) || | ||
465 | (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1])) | ||
466 | { | ||
467 | GNUNET_break (0); | ||
468 | return GNUNET_SYSERR; | ||
469 | } | ||
470 | return GNUNET_OK; | ||
471 | } | ||
472 | |||
473 | |||
474 | /** | ||
475 | * Handler for GET_DEFAULT message from client, returns | ||
476 | * default identity for some service. | ||
477 | * | ||
478 | * @param cls unused | ||
479 | * @param gdm the message received | ||
480 | */ | ||
481 | static void | ||
482 | handle_get_default_message (void *cls, | ||
483 | const struct GetDefaultMessage *gdm) | ||
484 | { | ||
485 | struct GNUNET_MQ_Envelope *env; | ||
486 | struct GNUNET_SERVICE_Client *client = cls; | ||
487 | char *name; | ||
488 | char *identifier; | ||
489 | |||
490 | name = GNUNET_strdup ((const char *) &gdm[1]); | ||
491 | GNUNET_STRINGS_utf8_tolower ((const char *) &gdm[1], name); | ||
492 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
493 | "Received GET_DEFAULT for service `%s' from client\n", | ||
494 | name); | ||
495 | if (GNUNET_OK != | ||
496 | GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, | ||
497 | name, | ||
498 | "DEFAULT_IDENTIFIER", | ||
499 | &identifier)) | ||
500 | { | ||
501 | send_result_code (client, 1, gettext_noop ("no default known")); | ||
502 | GNUNET_SERVICE_client_continue (client); | ||
503 | GNUNET_free (name); | ||
504 | return; | ||
505 | } | ||
506 | for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next) | ||
507 | { | ||
508 | if (0 == strcmp (ego->identifier, identifier)) | ||
509 | { | ||
510 | env = create_set_default_message (ego, name); | ||
511 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); | ||
512 | GNUNET_SERVICE_client_continue (client); | ||
513 | GNUNET_free (identifier); | ||
514 | GNUNET_free (name); | ||
515 | return; | ||
516 | } | ||
517 | } | ||
518 | GNUNET_free (identifier); | ||
519 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
520 | "Failed to find ego `%s'\n", | ||
521 | name); | ||
522 | GNUNET_free (name); | ||
523 | send_result_code (client, | ||
524 | 1, | ||
525 | gettext_noop ( | ||
526 | "default configured, but ego unknown (internal error)")); | ||
527 | GNUNET_SERVICE_client_continue (client); | ||
528 | } | ||
529 | |||
530 | |||
531 | /** | ||
532 | * Compare the given two private keys for equality. | ||
533 | * | ||
534 | * @param pk1 one private key | ||
535 | * @param pk2 another private key | ||
536 | * @return 0 if the keys are equal | ||
537 | */ | ||
538 | static int | ||
539 | key_cmp (const struct GNUNET_IDENTITY_PrivateKey *pk1, | ||
540 | const struct GNUNET_IDENTITY_PrivateKey *pk2) | ||
541 | { | ||
542 | return GNUNET_memcmp (pk1, pk2); | ||
543 | } | ||
544 | |||
545 | |||
546 | /** | ||
547 | * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT message | ||
548 | * | ||
549 | * @param cls client sending the message | ||
550 | * @param msg message of type `struct SetDefaultMessage` | ||
551 | * @return #GNUNET_OK if @a msg is well-formed | ||
552 | */ | ||
553 | static int | ||
554 | check_set_default_message (void *cls, | ||
555 | const struct SetDefaultMessage *msg) | ||
556 | { | ||
557 | uint16_t size; | ||
558 | uint16_t name_len; | ||
559 | const char *str; | ||
560 | |||
561 | size = ntohs (msg->header.size); | ||
562 | if (size <= sizeof(struct SetDefaultMessage)) | ||
563 | { | ||
564 | GNUNET_break (0); | ||
565 | return GNUNET_SYSERR; | ||
566 | } | ||
567 | name_len = ntohs (msg->name_len); | ||
568 | GNUNET_break (0 == ntohs (msg->reserved)); | ||
569 | if (name_len + sizeof(struct SetDefaultMessage) != size) | ||
570 | { | ||
571 | GNUNET_break (0); | ||
572 | return GNUNET_SYSERR; | ||
573 | } | ||
574 | str = (const char *) &msg[1]; | ||
575 | if ('\0' != str[name_len - 1]) | ||
576 | { | ||
577 | GNUNET_break (0); | ||
578 | return GNUNET_SYSERR; | ||
579 | } | ||
580 | return GNUNET_OK; | ||
581 | } | ||
582 | |||
583 | |||
584 | /** | ||
585 | * Handler for SET_DEFAULT message from client, updates | ||
586 | * default identity for some service. | ||
587 | * | ||
588 | * @param cls unused | ||
589 | * @param sdm the message received | ||
590 | */ | ||
591 | static void | ||
592 | handle_set_default_message (void *cls, | ||
593 | const struct SetDefaultMessage *sdm) | ||
594 | { | ||
595 | struct Ego *ego; | ||
596 | struct GNUNET_SERVICE_Client *client = cls; | ||
597 | char *str; | ||
598 | |||
599 | str = GNUNET_strdup ((const char *) &sdm[1]); | ||
600 | GNUNET_STRINGS_utf8_tolower ((const char *) &sdm[1], str); | ||
601 | |||
602 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
603 | "Received SET_DEFAULT for service `%s' from client\n", | ||
604 | str); | ||
605 | for (ego = ego_head; NULL != ego; ego = ego->next) | ||
606 | { | ||
607 | if (0 == key_cmp (&ego->pk, | ||
608 | &sdm->private_key)) | ||
609 | { | ||
610 | GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, | ||
611 | str, | ||
612 | "DEFAULT_IDENTIFIER", | ||
613 | ego->identifier); | ||
614 | if (GNUNET_OK != | ||
615 | GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file)) | ||
616 | GNUNET_log ( | ||
617 | GNUNET_ERROR_TYPE_ERROR, | ||
618 | _ ("Failed to write subsystem default identifier map to `%s'.\n"), | ||
619 | subsystem_cfg_file); | ||
620 | send_result_code (client, 0, NULL); | ||
621 | GNUNET_SERVICE_client_continue (client); | ||
622 | GNUNET_free (str); | ||
623 | return; | ||
624 | } | ||
625 | } | ||
626 | send_result_code (client, | ||
627 | 1, | ||
628 | _ ("Unknown ego specified for service (internal error)")); | ||
629 | GNUNET_free (str); | ||
630 | GNUNET_SERVICE_client_continue (client); | 401 | GNUNET_SERVICE_client_continue (client); |
631 | } | 402 | } |
632 | 403 | ||
@@ -716,9 +487,7 @@ handle_create_message (void *cls, | |||
716 | if (0 == strcmp (ego->identifier, str)) | 487 | if (0 == strcmp (ego->identifier, str)) |
717 | { | 488 | { |
718 | send_result_code (client, | 489 | send_result_code (client, |
719 | 1, | 490 | GNUNET_EC_IDENTITY_NAME_CONFLICT); |
720 | gettext_noop ( | ||
721 | "identifier already in use for another ego")); | ||
722 | GNUNET_SERVICE_client_continue (client); | 491 | GNUNET_SERVICE_client_continue (client); |
723 | GNUNET_free (str); | 492 | GNUNET_free (str); |
724 | return; | 493 | return; |
@@ -730,7 +499,7 @@ handle_create_message (void *cls, | |||
730 | GNUNET_CONTAINER_DLL_insert (ego_head, | 499 | GNUNET_CONTAINER_DLL_insert (ego_head, |
731 | ego_tail, | 500 | ego_tail, |
732 | ego); | 501 | ego); |
733 | send_result_code (client, 0, NULL); | 502 | send_result_code (client, GNUNET_EC_NONE); |
734 | fn = get_ego_filename (ego); | 503 | fn = get_ego_filename (ego); |
735 | if (GNUNET_OK != | 504 | if (GNUNET_OK != |
736 | GNUNET_DISK_fn_write (fn, | 505 | GNUNET_DISK_fn_write (fn, |
@@ -864,7 +633,7 @@ handle_rename_message (void *cls, const struct RenameMessage *rm) | |||
864 | { | 633 | { |
865 | if (0 == strcmp (ego->identifier, new_name)) | 634 | if (0 == strcmp (ego->identifier, new_name)) |
866 | { | 635 | { |
867 | send_result_code (client, 1, gettext_noop ("target name already exists")); | 636 | send_result_code (client, GNUNET_EC_IDENTITY_NAME_CONFLICT); |
868 | GNUNET_SERVICE_client_continue (client); | 637 | GNUNET_SERVICE_client_continue (client); |
869 | GNUNET_free (old_name); | 638 | GNUNET_free (old_name); |
870 | GNUNET_free (new_name); | 639 | GNUNET_free (new_name); |
@@ -899,14 +668,14 @@ handle_rename_message (void *cls, const struct RenameMessage *rm) | |||
899 | GNUNET_free (old_name); | 668 | GNUNET_free (old_name); |
900 | GNUNET_free (new_name); | 669 | GNUNET_free (new_name); |
901 | notify_listeners (ego); | 670 | notify_listeners (ego); |
902 | send_result_code (client, 0, NULL); | 671 | send_result_code (client, GNUNET_EC_NONE); |
903 | GNUNET_SERVICE_client_continue (client); | 672 | GNUNET_SERVICE_client_continue (client); |
904 | return; | 673 | return; |
905 | } | 674 | } |
906 | } | 675 | } |
907 | 676 | ||
908 | /* failed to locate old name */ | 677 | /* failed to locate old name */ |
909 | send_result_code (client, 1, gettext_noop ("no matching ego found")); | 678 | send_result_code (client, GNUNET_EC_IDENTITY_NOT_FOUND); |
910 | GNUNET_free (old_name); | 679 | GNUNET_free (old_name); |
911 | GNUNET_free (new_name); | 680 | GNUNET_free (new_name); |
912 | GNUNET_SERVICE_client_continue (client); | 681 | GNUNET_SERVICE_client_continue (client); |
@@ -1018,13 +787,13 @@ handle_delete_message (void *cls, const struct DeleteMessage *dm) | |||
1018 | notify_listeners (ego); | 787 | notify_listeners (ego); |
1019 | GNUNET_free (ego); | 788 | GNUNET_free (ego); |
1020 | GNUNET_free (name); | 789 | GNUNET_free (name); |
1021 | send_result_code (client, 0, NULL); | 790 | send_result_code (client, GNUNET_EC_NONE); |
1022 | GNUNET_SERVICE_client_continue (client); | 791 | GNUNET_SERVICE_client_continue (client); |
1023 | return; | 792 | return; |
1024 | } | 793 | } |
1025 | } | 794 | } |
1026 | 795 | ||
1027 | send_result_code (client, 1, gettext_noop ("no matching ego found")); | 796 | send_result_code (client, GNUNET_EC_IDENTITY_NOT_FOUND); |
1028 | GNUNET_free (name); | 797 | GNUNET_free (name); |
1029 | GNUNET_SERVICE_client_continue (client); | 798 | GNUNET_SERVICE_client_continue (client); |
1030 | } | 799 | } |
@@ -1221,14 +990,6 @@ GNUNET_SERVICE_MAIN ( | |||
1221 | GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX, | 990 | GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX, |
1222 | struct LookupMessage, | 991 | struct LookupMessage, |
1223 | NULL), | 992 | NULL), |
1224 | GNUNET_MQ_hd_var_size (get_default_message, | ||
1225 | GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT, | ||
1226 | struct GetDefaultMessage, | ||
1227 | NULL), | ||
1228 | GNUNET_MQ_hd_var_size (set_default_message, | ||
1229 | GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, | ||
1230 | struct SetDefaultMessage, | ||
1231 | NULL), | ||
1232 | GNUNET_MQ_hd_var_size (create_message, | 993 | GNUNET_MQ_hd_var_size (create_message, |
1233 | GNUNET_MESSAGE_TYPE_IDENTITY_CREATE, | 994 | GNUNET_MESSAGE_TYPE_IDENTITY_CREATE, |
1234 | struct CreateRequestMessage, | 995 | struct CreateRequestMessage, |
diff --git a/src/identity/identity.h b/src/identity/identity.h index 11c5883bc..57ce091b8 100644 --- a/src/identity/identity.h +++ b/src/identity/identity.h | |||
@@ -89,8 +89,6 @@ struct ResultCodeMessage | |||
89 | * (currently not used). | 89 | * (currently not used). |
90 | */ | 90 | */ |
91 | uint32_t result_code GNUNET_PACKED; | 91 | uint32_t result_code GNUNET_PACKED; |
92 | |||
93 | /* followed by 0-terminated error message (on error) */ | ||
94 | }; | 92 | }; |
95 | 93 | ||
96 | 94 | ||
@@ -140,62 +138,6 @@ struct UpdateMessage | |||
140 | 138 | ||
141 | 139 | ||
142 | /** | 140 | /** |
143 | * Client requests knowledge about default identity for | ||
144 | * a subsystem from identity service. | ||
145 | */ | ||
146 | struct GetDefaultMessage | ||
147 | { | ||
148 | /** | ||
149 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT | ||
150 | */ | ||
151 | struct GNUNET_MessageHeader header; | ||
152 | |||
153 | /** | ||
154 | * Number of bytes in service name string including 0-termination, in NBO. | ||
155 | */ | ||
156 | uint16_t name_len GNUNET_PACKED; | ||
157 | |||
158 | /** | ||
159 | * Always zero. | ||
160 | */ | ||
161 | uint16_t reserved GNUNET_PACKED; | ||
162 | |||
163 | |||
164 | /* followed by 0-terminated service name */ | ||
165 | }; | ||
166 | |||
167 | |||
168 | /** | ||
169 | * Used from service to client as a result to the GET_DEFAULT | ||
170 | * message, used from client to service to SET_DEFAULT. | ||
171 | */ | ||
172 | struct SetDefaultMessage | ||
173 | { | ||
174 | /** | ||
175 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT | ||
176 | */ | ||
177 | struct GNUNET_MessageHeader header; | ||
178 | |||
179 | /** | ||
180 | * Number of bytes in service name string including 0-termination, in NBO. | ||
181 | */ | ||
182 | uint16_t name_len GNUNET_PACKED; | ||
183 | |||
184 | /** | ||
185 | * Always zero. | ||
186 | */ | ||
187 | uint16_t reserved GNUNET_PACKED; | ||
188 | |||
189 | /** | ||
190 | * The private key | ||
191 | */ | ||
192 | struct GNUNET_IDENTITY_PrivateKey private_key; | ||
193 | |||
194 | /* followed by 0-terminated service name */ | ||
195 | }; | ||
196 | |||
197 | |||
198 | /** | ||
199 | * Client requests creation of an identity. Service | 141 | * Client requests creation of an identity. Service |
200 | * will respond with a result code. | 142 | * will respond with a result code. |
201 | */ | 143 | */ |
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c index 934ee31c6..d41e05104 100644 --- a/src/identity/identity_api.c +++ b/src/identity/identity_api.c | |||
@@ -279,13 +279,13 @@ reschedule_connect (struct GNUNET_IDENTITY_Handle *h) | |||
279 | op); | 279 | op); |
280 | if (NULL != op->cont) | 280 | if (NULL != op->cont) |
281 | op->cont (op->cls, | 281 | op->cont (op->cls, |
282 | "Error in communication with the identity service"); | 282 | GNUNET_EC_SERVICE_COMMUNICATION_FAILED); |
283 | else if (NULL != op->cb) | 283 | else if (NULL != op->cb) |
284 | op->cb (op->cls, NULL, NULL, NULL); | 284 | op->cb (op->cls, NULL, NULL, NULL); |
285 | else if (NULL != op->create_cont) | 285 | else if (NULL != op->create_cont) |
286 | op->create_cont (op->cls, | 286 | op->create_cont (op->cls, |
287 | NULL, | 287 | NULL, |
288 | "Failed to communicate with the identity service"); | 288 | GNUNET_EC_SERVICE_COMMUNICATION_FAILED); |
289 | GNUNET_free (op); | 289 | GNUNET_free (op); |
290 | } | 290 | } |
291 | GNUNET_CONTAINER_multihashmap_iterate (h->egos, | 291 | GNUNET_CONTAINER_multihashmap_iterate (h->egos, |
@@ -322,24 +322,6 @@ mq_error_handler (void *cls, | |||
322 | 322 | ||
323 | 323 | ||
324 | /** | 324 | /** |
325 | * We received a result code from the service. Check the message | ||
326 | * is well-formed. | ||
327 | * | ||
328 | * @param cls closure | ||
329 | * @param rcm result message received | ||
330 | * @return #GNUNET_OK if the message is well-formed | ||
331 | */ | ||
332 | static int | ||
333 | check_identity_result_code (void *cls, | ||
334 | const struct ResultCodeMessage *rcm) | ||
335 | { | ||
336 | if (sizeof(*rcm) != htons (rcm->header.size)) | ||
337 | GNUNET_MQ_check_zero_termination (rcm); | ||
338 | return GNUNET_OK; | ||
339 | } | ||
340 | |||
341 | |||
342 | /** | ||
343 | * We received a result code from the service. | 325 | * We received a result code from the service. |
344 | * | 326 | * |
345 | * @param cls closure | 327 | * @param cls closure |
@@ -351,8 +333,7 @@ handle_identity_result_code (void *cls, | |||
351 | { | 333 | { |
352 | struct GNUNET_IDENTITY_Handle *h = cls; | 334 | struct GNUNET_IDENTITY_Handle *h = cls; |
353 | struct GNUNET_IDENTITY_Operation *op; | 335 | struct GNUNET_IDENTITY_Operation *op; |
354 | uint16_t size = ntohs (rcm->header.size) - sizeof(*rcm); | 336 | enum GNUNET_ErrorCode ec = ntohl (rcm->result_code); |
355 | const char *str = (0 == size) ? NULL : (const char *) &rcm[1]; | ||
356 | 337 | ||
357 | op = h->op_head; | 338 | op = h->op_head; |
358 | if (NULL == op) | 339 | if (NULL == op) |
@@ -363,11 +344,11 @@ handle_identity_result_code (void *cls, | |||
363 | } | 344 | } |
364 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | 345 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); |
365 | if (NULL != op->cont) | 346 | if (NULL != op->cont) |
366 | op->cont (op->cls, str); | 347 | op->cont (op->cls, ec); |
367 | else if (NULL != op->cb) | 348 | else if (NULL != op->cb) |
368 | op->cb (op->cls, NULL, NULL, NULL); | 349 | op->cb (op->cls, NULL, NULL, NULL); |
369 | else if (NULL != op->create_cont) | 350 | else if (NULL != op->create_cont) |
370 | op->create_cont (op->cls, (NULL == str) ? &op->pk : NULL, str); | 351 | op->create_cont (op->cls, (GNUNET_EC_NONE == ec) ? &op->pk : NULL, ec); |
371 | GNUNET_free (op); | 352 | GNUNET_free (op); |
372 | } | 353 | } |
373 | 354 | ||
@@ -477,80 +458,6 @@ handle_identity_update (void *cls, | |||
477 | 458 | ||
478 | 459 | ||
479 | /** | 460 | /** |
480 | * Function called when we receive a set default message from the | ||
481 | * service. | ||
482 | * | ||
483 | * @param cls closure | ||
484 | * @param sdm message received | ||
485 | * @return #GNUNET_OK if the message is well-formed | ||
486 | */ | ||
487 | static int | ||
488 | check_identity_set_default (void *cls, | ||
489 | const struct SetDefaultMessage *sdm) | ||
490 | { | ||
491 | uint16_t size = ntohs (sdm->header.size) - sizeof(*sdm); | ||
492 | uint16_t name_len = ntohs (sdm->name_len); | ||
493 | const char *str = (const char *) &sdm[1]; | ||
494 | |||
495 | if ((size != name_len) || ((0 != name_len) && ('\0' != str[name_len - 1]))) | ||
496 | { | ||
497 | GNUNET_break (0); | ||
498 | return GNUNET_SYSERR; | ||
499 | } | ||
500 | GNUNET_break (0 == ntohs (sdm->reserved)); | ||
501 | return GNUNET_OK; | ||
502 | } | ||
503 | |||
504 | |||
505 | /** | ||
506 | * Type of a function to call when we receive a message | ||
507 | * from the service. | ||
508 | * | ||
509 | * @param cls closure | ||
510 | * @param sdm message received | ||
511 | */ | ||
512 | static void | ||
513 | handle_identity_set_default (void *cls, | ||
514 | const struct SetDefaultMessage *sdm) | ||
515 | { | ||
516 | struct GNUNET_IDENTITY_Handle *h = cls; | ||
517 | struct GNUNET_IDENTITY_Operation *op; | ||
518 | struct GNUNET_HashCode id; | ||
519 | struct GNUNET_IDENTITY_Ego *ego; | ||
520 | |||
521 | GNUNET_CRYPTO_hash (&sdm->private_key, | ||
522 | sizeof(sdm->private_key), | ||
523 | &id); | ||
524 | ego = GNUNET_CONTAINER_multihashmap_get (h->egos, | ||
525 | &id); | ||
526 | if (NULL == ego) | ||
527 | { | ||
528 | GNUNET_break (0); | ||
529 | reschedule_connect (h); | ||
530 | return; | ||
531 | } | ||
532 | op = h->op_head; | ||
533 | if (NULL == op) | ||
534 | { | ||
535 | GNUNET_break (0); | ||
536 | reschedule_connect (h); | ||
537 | return; | ||
538 | } | ||
539 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
540 | "Received SET_DEFAULT message from identity service\n"); | ||
541 | GNUNET_CONTAINER_DLL_remove (h->op_head, | ||
542 | h->op_tail, | ||
543 | op); | ||
544 | if (NULL != op->cb) | ||
545 | op->cb (op->cls, | ||
546 | ego, | ||
547 | &ego->ctx, | ||
548 | ego->name); | ||
549 | GNUNET_free (op); | ||
550 | } | ||
551 | |||
552 | |||
553 | /** | ||
554 | * Try again to connect to the identity service. | 461 | * Try again to connect to the identity service. |
555 | * | 462 | * |
556 | * @param cls handle to the identity service. | 463 | * @param cls handle to the identity service. |
@@ -560,18 +467,14 @@ reconnect (void *cls) | |||
560 | { | 467 | { |
561 | struct GNUNET_IDENTITY_Handle *h = cls; | 468 | struct GNUNET_IDENTITY_Handle *h = cls; |
562 | struct GNUNET_MQ_MessageHandler handlers[] = { | 469 | struct GNUNET_MQ_MessageHandler handlers[] = { |
563 | GNUNET_MQ_hd_var_size (identity_result_code, | 470 | GNUNET_MQ_hd_fixed_size (identity_result_code, |
564 | GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, | 471 | GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, |
565 | struct ResultCodeMessage, | 472 | struct ResultCodeMessage, |
566 | h), | 473 | h), |
567 | GNUNET_MQ_hd_var_size (identity_update, | 474 | GNUNET_MQ_hd_var_size (identity_update, |
568 | GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, | 475 | GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, |
569 | struct UpdateMessage, | 476 | struct UpdateMessage, |
570 | h), | 477 | h), |
571 | GNUNET_MQ_hd_var_size (identity_set_default, | ||
572 | GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, | ||
573 | struct SetDefaultMessage, | ||
574 | h), | ||
575 | GNUNET_MQ_handler_end () | 478 | GNUNET_MQ_handler_end () |
576 | }; | 479 | }; |
577 | struct GNUNET_MQ_Envelope *env; | 480 | struct GNUNET_MQ_Envelope *env; |
@@ -662,88 +565,6 @@ GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego, | |||
662 | 565 | ||
663 | 566 | ||
664 | struct GNUNET_IDENTITY_Operation * | 567 | struct GNUNET_IDENTITY_Operation * |
665 | GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *h, | ||
666 | const char *service_name, | ||
667 | GNUNET_IDENTITY_Callback cb, | ||
668 | void *cb_cls) | ||
669 | { | ||
670 | struct GNUNET_IDENTITY_Operation *op; | ||
671 | struct GNUNET_MQ_Envelope *env; | ||
672 | struct GetDefaultMessage *gdm; | ||
673 | size_t slen; | ||
674 | |||
675 | if (NULL == h->mq) | ||
676 | return NULL; | ||
677 | GNUNET_assert (NULL != h->cb); | ||
678 | slen = strlen (service_name) + 1; | ||
679 | if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct GetDefaultMessage)) | ||
680 | { | ||
681 | GNUNET_break (0); | ||
682 | return NULL; | ||
683 | } | ||
684 | op = GNUNET_new (struct GNUNET_IDENTITY_Operation); | ||
685 | op->h = h; | ||
686 | op->cb = cb; | ||
687 | op->cls = cb_cls; | ||
688 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | ||
689 | env = | ||
690 | GNUNET_MQ_msg_extra (gdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT); | ||
691 | gdm->name_len = htons (slen); | ||
692 | gdm->reserved = htons (0); | ||
693 | GNUNET_memcpy (&gdm[1], service_name, slen); | ||
694 | GNUNET_MQ_send (h->mq, env); | ||
695 | return op; | ||
696 | } | ||
697 | |||
698 | |||
699 | /** | ||
700 | * Set the preferred/default identity for a service. | ||
701 | * | ||
702 | * @param h identity service to inform | ||
703 | * @param service_name for which service is an identity set | ||
704 | * @param ego new default identity to be set for this service | ||
705 | * @param cont function to call once the operation finished | ||
706 | * @param cont_cls closure for @a cont | ||
707 | * @return handle to abort the operation | ||
708 | */ | ||
709 | struct GNUNET_IDENTITY_Operation * | ||
710 | GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h, | ||
711 | const char *service_name, | ||
712 | struct GNUNET_IDENTITY_Ego *ego, | ||
713 | GNUNET_IDENTITY_Continuation cont, | ||
714 | void *cont_cls) | ||
715 | { | ||
716 | struct GNUNET_IDENTITY_Operation *op; | ||
717 | struct GNUNET_MQ_Envelope *env; | ||
718 | struct SetDefaultMessage *sdm; | ||
719 | size_t slen; | ||
720 | |||
721 | if (NULL == h->mq) | ||
722 | return NULL; | ||
723 | GNUNET_assert (NULL != h->cb); | ||
724 | slen = strlen (service_name) + 1; | ||
725 | if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct SetDefaultMessage)) | ||
726 | { | ||
727 | GNUNET_break (0); | ||
728 | return NULL; | ||
729 | } | ||
730 | op = GNUNET_new (struct GNUNET_IDENTITY_Operation); | ||
731 | op->h = h; | ||
732 | op->cont = cont; | ||
733 | op->cls = cont_cls; | ||
734 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | ||
735 | env = | ||
736 | GNUNET_MQ_msg_extra (sdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); | ||
737 | sdm->name_len = htons (slen); | ||
738 | sdm->reserved = htons (0); | ||
739 | sdm->private_key = ego->pk; | ||
740 | GNUNET_memcpy (&sdm[1], service_name, slen); | ||
741 | GNUNET_MQ_send (h->mq, env); | ||
742 | return op; | ||
743 | } | ||
744 | |||
745 | |||
746 | struct GNUNET_IDENTITY_Operation * | ||
747 | GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, | 568 | GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, |
748 | const char *name, | 569 | const char *name, |
749 | const struct GNUNET_IDENTITY_PrivateKey *privkey, | 570 | const struct GNUNET_IDENTITY_PrivateKey *privkey, |
@@ -1119,11 +940,13 @@ GNUNET_IDENTITY_sign_raw_ (const struct | |||
1119 | { | 940 | { |
1120 | case GNUNET_IDENTITY_TYPE_ECDSA: | 941 | case GNUNET_IDENTITY_TYPE_ECDSA: |
1121 | return GNUNET_CRYPTO_ecdsa_sign_ (&(priv->ecdsa_key), purpose, | 942 | return GNUNET_CRYPTO_ecdsa_sign_ (&(priv->ecdsa_key), purpose, |
1122 | (struct GNUNET_CRYPTO_EcdsaSignature*)sig); | 943 | (struct |
944 | GNUNET_CRYPTO_EcdsaSignature*) sig); | ||
1123 | break; | 945 | break; |
1124 | case GNUNET_IDENTITY_TYPE_EDDSA: | 946 | case GNUNET_IDENTITY_TYPE_EDDSA: |
1125 | return GNUNET_CRYPTO_eddsa_sign_ (&(priv->eddsa_key), purpose, | 947 | return GNUNET_CRYPTO_eddsa_sign_ (&(priv->eddsa_key), purpose, |
1126 | (struct GNUNET_CRYPTO_EddsaSignature*)sig); | 948 | (struct |
949 | GNUNET_CRYPTO_EddsaSignature*) sig); | ||
1127 | break; | 950 | break; |
1128 | default: | 951 | default: |
1129 | GNUNET_break (0); | 952 | GNUNET_break (0); |
@@ -1202,12 +1025,14 @@ GNUNET_IDENTITY_signature_verify_raw_ (uint32_t purpose, | |||
1202 | { | 1025 | { |
1203 | case GNUNET_IDENTITY_TYPE_ECDSA: | 1026 | case GNUNET_IDENTITY_TYPE_ECDSA: |
1204 | return GNUNET_CRYPTO_ecdsa_verify_ (purpose, validate, | 1027 | return GNUNET_CRYPTO_ecdsa_verify_ (purpose, validate, |
1205 | (struct GNUNET_CRYPTO_EcdsaSignature*)sig, | 1028 | (struct |
1029 | GNUNET_CRYPTO_EcdsaSignature*) sig, | ||
1206 | &(pub->ecdsa_key)); | 1030 | &(pub->ecdsa_key)); |
1207 | break; | 1031 | break; |
1208 | case GNUNET_IDENTITY_TYPE_EDDSA: | 1032 | case GNUNET_IDENTITY_TYPE_EDDSA: |
1209 | return GNUNET_CRYPTO_eddsa_verify_ (purpose, validate, | 1033 | return GNUNET_CRYPTO_eddsa_verify_ (purpose, validate, |
1210 | (struct GNUNET_CRYPTO_EddsaSignature*)sig, | 1034 | (struct |
1035 | GNUNET_CRYPTO_EddsaSignature*) sig, | ||
1211 | &(pub->eddsa_key)); | 1036 | &(pub->eddsa_key)); |
1212 | break; | 1037 | break; |
1213 | default: | 1038 | default: |
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c index 5327d0b1f..17d214c15 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/identity/plugin_rest_identity.c | |||
@@ -49,11 +49,6 @@ | |||
49 | #define GNUNET_REST_API_NS_IDENTITY_NAME "/identity/name" | 49 | #define GNUNET_REST_API_NS_IDENTITY_NAME "/identity/name" |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * Identity Subsystem Namespace | ||
53 | */ | ||
54 | #define GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM "/identity/subsystem" | ||
55 | |||
56 | /** | ||
57 | * Identity Namespace with sign specifier | 52 | * Identity Namespace with sign specifier |
58 | */ | 53 | */ |
59 | #define GNUNET_REST_API_NS_SIGN "/sign" | 54 | #define GNUNET_REST_API_NS_SIGN "/sign" |
@@ -69,11 +64,6 @@ | |||
69 | #define GNUNET_REST_IDENTITY_PARAM_PRIVKEY "privkey" | 64 | #define GNUNET_REST_IDENTITY_PARAM_PRIVKEY "privkey" |
70 | 65 | ||
71 | /** | 66 | /** |
72 | * Parameter subsystem | ||
73 | */ | ||
74 | #define GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM "subsystem" | ||
75 | |||
76 | /** | ||
77 | * Parameter name | 67 | * Parameter name |
78 | */ | 68 | */ |
79 | #define GNUNET_REST_IDENTITY_PARAM_NAME "name" | 69 | #define GNUNET_REST_IDENTITY_PARAM_NAME "name" |
@@ -84,16 +74,6 @@ | |||
84 | #define GNUNET_REST_IDENTITY_PARAM_NEWNAME "newname" | 74 | #define GNUNET_REST_IDENTITY_PARAM_NEWNAME "newname" |
85 | 75 | ||
86 | /** | 76 | /** |
87 | * Error message Unknown Error | ||
88 | */ | ||
89 | #define GNUNET_REST_IDENTITY_ERROR_UNKNOWN "Unknown Error" | ||
90 | |||
91 | /** | ||
92 | * Error message No identity found | ||
93 | */ | ||
94 | #define GNUNET_REST_IDENTITY_NOT_FOUND "No identity found" | ||
95 | |||
96 | /** | ||
97 | * Error message Missing identity name | 77 | * Error message Missing identity name |
98 | */ | 78 | */ |
99 | #define GNUNET_REST_IDENTITY_MISSING_NAME "Missing identity name" | 79 | #define GNUNET_REST_IDENTITY_MISSING_NAME "Missing identity name" |
@@ -258,14 +238,9 @@ struct RequestHandle | |||
258 | char *url; | 238 | char *url; |
259 | 239 | ||
260 | /** | 240 | /** |
261 | * Error response message | 241 | * Error code |
262 | */ | ||
263 | char *emsg; | ||
264 | |||
265 | /** | ||
266 | * Response code | ||
267 | */ | 242 | */ |
268 | int response_code; | 243 | enum GNUNET_ErrorCode ec; |
269 | }; | 244 | }; |
270 | 245 | ||
271 | /** | 246 | /** |
@@ -296,8 +271,6 @@ cleanup_handle (void *cls) | |||
296 | 271 | ||
297 | if (NULL != handle->url) | 272 | if (NULL != handle->url) |
298 | GNUNET_free (handle->url); | 273 | GNUNET_free (handle->url); |
299 | if (NULL != handle->emsg) | ||
300 | GNUNET_free (handle->emsg); | ||
301 | if (NULL != handle->name) | 274 | if (NULL != handle->name) |
302 | GNUNET_free (handle->name); | 275 | GNUNET_free (handle->name); |
303 | GNUNET_CONTAINER_DLL_remove (requests_head, | 276 | GNUNET_CONTAINER_DLL_remove (requests_head, |
@@ -319,20 +292,20 @@ do_error (void *cls) | |||
319 | struct MHD_Response *resp; | 292 | struct MHD_Response *resp; |
320 | json_t *json_error = json_object (); | 293 | json_t *json_error = json_object (); |
321 | char *response; | 294 | char *response; |
295 | int response_code; | ||
322 | 296 | ||
323 | if (NULL == handle->emsg) | 297 | json_object_set_new (json_error, "error", |
324 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_ERROR_UNKNOWN); | 298 | json_string (GNUNET_ErrorCode_get_hint (handle->ec))); |
325 | 299 | json_object_set_new (json_error, "error_code", json_integer (handle->ec)); | |
326 | json_object_set_new (json_error, "error", json_string (handle->emsg)); | 300 | response_code = GNUNET_ErrorCode_get_http_status (handle->ec); |
327 | 301 | if (0 == response_code) | |
328 | if (0 == handle->response_code) | 302 | response_code = MHD_HTTP_OK; |
329 | handle->response_code = MHD_HTTP_OK; | ||
330 | response = json_dumps (json_error, 0); | 303 | response = json_dumps (json_error, 0); |
331 | resp = GNUNET_REST_create_response (response); | 304 | resp = GNUNET_REST_create_response (response); |
332 | GNUNET_assert (MHD_NO != MHD_add_response_header (resp, | 305 | GNUNET_assert (MHD_NO != MHD_add_response_header (resp, |
333 | "Content-Type", | 306 | "Content-Type", |
334 | "application/json")); | 307 | "application/json")); |
335 | handle->proc (handle->proc_cls, resp, handle->response_code); | 308 | handle->proc (handle->proc_cls, resp, response_code); |
336 | json_decref (json_error); | 309 | json_decref (json_error); |
337 | GNUNET_free (response); | 310 | GNUNET_free (response); |
338 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 311 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); |
@@ -378,101 +351,6 @@ get_egoentry (struct RequestHandle *handle, char *pubkey, char *name) | |||
378 | 351 | ||
379 | 352 | ||
380 | /** | 353 | /** |
381 | * Callback for GET Request with subsystem | ||
382 | * | ||
383 | * @param cls the RequestHandle | ||
384 | * @param ego the Ego found | ||
385 | * @param ctx the context | ||
386 | * @param name the id of the ego | ||
387 | */ | ||
388 | static void | ||
389 | ego_get_for_subsystem (void *cls, | ||
390 | struct GNUNET_IDENTITY_Ego *ego, | ||
391 | void **ctx, | ||
392 | const char *name) | ||
393 | { | ||
394 | struct RequestHandle *handle = cls; | ||
395 | struct MHD_Response *resp; | ||
396 | struct GNUNET_IDENTITY_PublicKey public_key; | ||
397 | json_t *json_root; | ||
398 | char *result_str; | ||
399 | char *public_key_string; | ||
400 | |||
401 | if (NULL == ego) | ||
402 | { | ||
403 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
404 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); | ||
405 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
406 | return; | ||
407 | } | ||
408 | |||
409 | GNUNET_IDENTITY_ego_get_public_key (ego, &public_key); | ||
410 | public_key_string = GNUNET_IDENTITY_public_key_to_string (&public_key); | ||
411 | |||
412 | // create json with subsystem identity | ||
413 | json_root = json_object (); | ||
414 | json_object_set_new (json_root, | ||
415 | GNUNET_REST_IDENTITY_PARAM_PUBKEY, | ||
416 | json_string (public_key_string)); | ||
417 | json_object_set_new (json_root, | ||
418 | GNUNET_REST_IDENTITY_PARAM_NAME, | ||
419 | json_string (name)); | ||
420 | |||
421 | result_str = json_dumps (json_root, 0); | ||
422 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | ||
423 | resp = GNUNET_REST_create_response (result_str); | ||
424 | GNUNET_assert (MHD_NO != MHD_add_response_header (resp, | ||
425 | "Content-Type", | ||
426 | "application/json")); | ||
427 | json_decref (json_root); | ||
428 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | ||
429 | GNUNET_free (result_str); | ||
430 | GNUNET_free (public_key_string); | ||
431 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | ||
432 | } | ||
433 | |||
434 | |||
435 | /** | ||
436 | * Handle identity GET request for subsystem | ||
437 | * | ||
438 | * @param con_handle the connection handle | ||
439 | * @param url the url | ||
440 | * @param cls the RequestHandle | ||
441 | */ | ||
442 | void | ||
443 | ego_get_subsystem (struct GNUNET_REST_RequestHandle *con_handle, | ||
444 | const char *url, | ||
445 | void *cls) | ||
446 | { | ||
447 | struct RequestHandle *handle = cls; | ||
448 | char *subsystem; | ||
449 | |||
450 | if (strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) >= strlen (handle->url)) | ||
451 | { | ||
452 | handle->emsg = GNUNET_strdup ("Missing subsystem name"); | ||
453 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
454 | return; | ||
455 | } | ||
456 | subsystem = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) + 1]; | ||
457 | // requested default identity of subsystem | ||
458 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking for %s's ego\n", subsystem); | ||
459 | |||
460 | handle->op = GNUNET_IDENTITY_get (identity_handle, | ||
461 | subsystem, | ||
462 | &ego_get_for_subsystem, | ||
463 | handle); | ||
464 | |||
465 | if (NULL == handle->op) | ||
466 | { | ||
467 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
468 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); | ||
469 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
470 | return; | ||
471 | } | ||
472 | } | ||
473 | |||
474 | |||
475 | /** | ||
476 | * Handle identity GET request - responds with all identities | 354 | * Handle identity GET request - responds with all identities |
477 | * | 355 | * |
478 | * @param con_handle the connection handle | 356 | * @param con_handle the connection handle |
@@ -603,8 +481,7 @@ ego_get_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | |||
603 | 481 | ||
604 | if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) | 482 | if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) |
605 | { | 483 | { |
606 | handle->response_code = MHD_HTTP_NOT_FOUND; | 484 | handle->ec = GNUNET_EC_IDENTITY_NOT_FOUND; |
607 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_PUBKEY); | ||
608 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 485 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
609 | return; | 486 | return; |
610 | } | 487 | } |
@@ -613,8 +490,7 @@ ego_get_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | |||
613 | 490 | ||
614 | if (NULL == ego_entry) | 491 | if (NULL == ego_entry) |
615 | { | 492 | { |
616 | handle->response_code = MHD_HTTP_NOT_FOUND; | 493 | handle->ec = GNUNET_EC_IDENTITY_NOT_FOUND; |
617 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); | ||
618 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 494 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
619 | return; | 495 | return; |
620 | } | 496 | } |
@@ -643,8 +519,7 @@ ego_get_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
643 | 519 | ||
644 | if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) | 520 | if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) |
645 | { | 521 | { |
646 | handle->response_code = MHD_HTTP_NOT_FOUND; | 522 | handle->ec = GNUNET_EC_IDENTITY_NOT_FOUND; |
647 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_NAME); | ||
648 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 523 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
649 | return; | 524 | return; |
650 | } | 525 | } |
@@ -653,8 +528,7 @@ ego_get_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
653 | 528 | ||
654 | if (NULL == ego_entry) | 529 | if (NULL == ego_entry) |
655 | { | 530 | { |
656 | handle->response_code = MHD_HTTP_NOT_FOUND; | 531 | handle->ec = GNUNET_EC_IDENTITY_NOT_FOUND; |
657 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); | ||
658 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 532 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
659 | return; | 533 | return; |
660 | } | 534 | } |
@@ -667,27 +541,28 @@ ego_get_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
667 | * Processing finished | 541 | * Processing finished |
668 | * | 542 | * |
669 | * @param cls request handle | 543 | * @param cls request handle |
670 | * @param emsg error message | 544 | * @param ec error code |
671 | */ | 545 | */ |
672 | static void | 546 | static void |
673 | do_finished (void *cls, const char *emsg) | 547 | do_finished (void *cls, enum GNUNET_ErrorCode ec) |
674 | { | 548 | { |
675 | struct RequestHandle *handle = cls; | 549 | struct RequestHandle *handle = cls; |
676 | struct MHD_Response *resp; | 550 | struct MHD_Response *resp; |
551 | int response_code; | ||
677 | 552 | ||
678 | handle->op = NULL; | 553 | handle->op = NULL; |
679 | if (NULL != emsg) | 554 | handle->ec = ec; |
555 | if (GNUNET_EC_NONE != ec) | ||
680 | { | 556 | { |
681 | handle->emsg = GNUNET_strdup (emsg); | ||
682 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 557 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
683 | return; | 558 | return; |
684 | } | 559 | } |
685 | if (0 == handle->response_code) | 560 | if (GNUNET_EC_NONE == handle->ec) |
686 | { | 561 | response_code = MHD_HTTP_NO_CONTENT; |
687 | handle->response_code = MHD_HTTP_NO_CONTENT; | 562 | else |
688 | } | 563 | response_code = GNUNET_ErrorCode_get_http_status (ec); |
689 | resp = GNUNET_REST_create_response (NULL); | 564 | resp = GNUNET_REST_create_response (NULL); |
690 | handle->proc (handle->proc_cls, resp, handle->response_code); | 565 | handle->proc (handle->proc_cls, resp, response_code); |
691 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 566 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); |
692 | } | 567 | } |
693 | 568 | ||
@@ -697,17 +572,17 @@ do_finished (void *cls, const char *emsg) | |||
697 | * | 572 | * |
698 | * @param cls request handle | 573 | * @param cls request handle |
699 | * @param pk private key of the ego, or NULL on error | 574 | * @param pk private key of the ego, or NULL on error |
700 | * @param emsg error message | 575 | * @param ec error code |
701 | */ | 576 | */ |
702 | static void | 577 | static void |
703 | do_finished_create (void *cls, | 578 | do_finished_create (void *cls, |
704 | const struct GNUNET_IDENTITY_PrivateKey *pk, | 579 | const struct GNUNET_IDENTITY_PrivateKey *pk, |
705 | const char *emsg) | 580 | enum GNUNET_ErrorCode ec) |
706 | { | 581 | { |
707 | struct RequestHandle *handle = cls; | 582 | struct RequestHandle *handle = cls; |
708 | 583 | ||
709 | (void) pk; | 584 | (void) pk; |
710 | do_finished (handle, emsg); | 585 | do_finished (handle, ec); |
711 | } | 586 | } |
712 | 587 | ||
713 | 588 | ||
@@ -720,8 +595,6 @@ do_finished_create (void *cls, | |||
720 | void | 595 | void |
721 | ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry) | 596 | ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry) |
722 | { | 597 | { |
723 | struct EgoEntry *ego_entry_tmp; | ||
724 | struct MHD_Response *resp; | ||
725 | json_t *data_js; | 598 | json_t *data_js; |
726 | json_error_t err; | 599 | json_error_t err; |
727 | char *newname; | 600 | char *newname; |
@@ -731,7 +604,7 @@ ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry) | |||
731 | // if no data | 604 | // if no data |
732 | if (0 >= handle->data_size) | 605 | if (0 >= handle->data_size) |
733 | { | 606 | { |
734 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); | 607 | handle->ec = GNUNET_EC_IDENTITY_INVALID; |
735 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 608 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
736 | return; | 609 | return; |
737 | } | 610 | } |
@@ -742,7 +615,7 @@ ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry) | |||
742 | 615 | ||
743 | if (NULL == data_js) | 616 | if (NULL == data_js) |
744 | { | 617 | { |
745 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); | 618 | handle->ec = GNUNET_EC_IDENTITY_INVALID; |
746 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 619 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
747 | return; | 620 | return; |
748 | } | 621 | } |
@@ -757,7 +630,7 @@ ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry) | |||
757 | // Change name with pubkey or name identifier | 630 | // Change name with pubkey or name identifier |
758 | if (0 != json_state) | 631 | if (0 != json_state) |
759 | { | 632 | { |
760 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 633 | handle->ec = GNUNET_EC_IDENTITY_INVALID; |
761 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 634 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
762 | json_decref (data_js); | 635 | json_decref (data_js); |
763 | return; | 636 | return; |
@@ -765,7 +638,7 @@ ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry) | |||
765 | 638 | ||
766 | if (NULL == newname) | 639 | if (NULL == newname) |
767 | { | 640 | { |
768 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 641 | handle->ec = GNUNET_EC_IDENTITY_INVALID; |
769 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 642 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
770 | json_decref (data_js); | 643 | json_decref (data_js); |
771 | return; | 644 | return; |
@@ -773,22 +646,12 @@ ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry) | |||
773 | 646 | ||
774 | if (0 >= strlen (newname)) | 647 | if (0 >= strlen (newname)) |
775 | { | 648 | { |
776 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 649 | handle->ec = GNUNET_EC_IDENTITY_INVALID; |
777 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 650 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
778 | json_decref (data_js); | 651 | json_decref (data_js); |
779 | return; | 652 | return; |
780 | } | 653 | } |
781 | 654 | ||
782 | ego_entry_tmp = get_egoentry (handle, NULL, newname); | ||
783 | if (NULL != ego_entry_tmp) | ||
784 | { | ||
785 | // Ego with same name not allowed (even if its the ego we change) | ||
786 | resp = GNUNET_REST_create_response (NULL); | ||
787 | handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); | ||
788 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | ||
789 | json_decref (data_js); | ||
790 | return; | ||
791 | } | ||
792 | handle->op = GNUNET_IDENTITY_rename (identity_handle, | 655 | handle->op = GNUNET_IDENTITY_rename (identity_handle, |
793 | ego_entry->identifier, | 656 | ego_entry->identifier, |
794 | newname, | 657 | newname, |
@@ -796,7 +659,7 @@ ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry) | |||
796 | handle); | 659 | handle); |
797 | if (NULL == handle->op) | 660 | if (NULL == handle->op) |
798 | { | 661 | { |
799 | handle->emsg = GNUNET_strdup ("Rename failed"); | 662 | handle->ec = GNUNET_EC_UNKNOWN; |
800 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 663 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
801 | json_decref (data_js); | 664 | json_decref (data_js); |
802 | return; | 665 | return; |
@@ -826,8 +689,7 @@ ego_edit_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | |||
826 | 689 | ||
827 | if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) | 690 | if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) |
828 | { | 691 | { |
829 | handle->response_code = MHD_HTTP_NOT_FOUND; | 692 | handle->ec = GNUNET_EC_IDENTITY_NOT_FOUND; |
830 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_PUBKEY); | ||
831 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 693 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
832 | return; | 694 | return; |
833 | } | 695 | } |
@@ -836,8 +698,7 @@ ego_edit_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | |||
836 | 698 | ||
837 | if (NULL == ego_entry) | 699 | if (NULL == ego_entry) |
838 | { | 700 | { |
839 | handle->response_code = MHD_HTTP_NOT_FOUND; | 701 | handle->ec = GNUNET_EC_IDENTITY_NOT_FOUND; |
840 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); | ||
841 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 702 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
842 | return; | 703 | return; |
843 | } | 704 | } |
@@ -866,8 +727,7 @@ ego_edit_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
866 | 727 | ||
867 | if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) | 728 | if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) |
868 | { | 729 | { |
869 | handle->response_code = MHD_HTTP_NOT_FOUND; | 730 | handle->ec = GNUNET_EC_IDENTITY_NOT_FOUND; |
870 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_NAME); | ||
871 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 731 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
872 | return; | 732 | return; |
873 | } | 733 | } |
@@ -876,8 +736,7 @@ ego_edit_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
876 | 736 | ||
877 | if (NULL == ego_entry) | 737 | if (NULL == ego_entry) |
878 | { | 738 | { |
879 | handle->response_code = MHD_HTTP_NOT_FOUND; | 739 | handle->ec = GNUNET_EC_IDENTITY_NOT_FOUND; |
880 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); | ||
881 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 740 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
882 | return; | 741 | return; |
883 | } | 742 | } |
@@ -887,115 +746,6 @@ ego_edit_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
887 | 746 | ||
888 | 747 | ||
889 | /** | 748 | /** |
890 | * Handle identity subsystem PUT request with name | ||
891 | * | ||
892 | * @param con_handle the connection handle | ||
893 | * @param url the url | ||
894 | * @param cls the RequestHandle | ||
895 | */ | ||
896 | void | ||
897 | ego_edit_subsystem (struct GNUNET_REST_RequestHandle *con_handle, | ||
898 | const char *url, | ||
899 | void *cls) | ||
900 | { | ||
901 | struct RequestHandle *handle = cls; | ||
902 | struct EgoEntry *ego_entry; | ||
903 | json_t *data_js; | ||
904 | json_error_t err; | ||
905 | char *newsubsys; | ||
906 | char *name; | ||
907 | char term_data[handle->data_size + 1]; | ||
908 | int json_state; | ||
909 | |||
910 | name = NULL; | ||
911 | |||
912 | if (strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) >= strlen (handle->url)) | ||
913 | { | ||
914 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
915 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_NAME); | ||
916 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
917 | return; | ||
918 | } | ||
919 | name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) + 1]; | ||
920 | ego_entry = get_egoentry (handle, NULL, name); | ||
921 | |||
922 | if (NULL == ego_entry) | ||
923 | { | ||
924 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
925 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); | ||
926 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
927 | return; | ||
928 | } | ||
929 | |||
930 | // if no data | ||
931 | if (0 >= handle->data_size) | ||
932 | { | ||
933 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); | ||
934 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
935 | return; | ||
936 | } | ||
937 | // if not json | ||
938 | term_data[handle->data_size] = '\0'; | ||
939 | GNUNET_memcpy (term_data, handle->data, handle->data_size); | ||
940 | data_js = json_loads (term_data, JSON_DECODE_ANY, &err); | ||
941 | |||
942 | if (NULL == data_js) | ||
943 | { | ||
944 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); | ||
945 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
946 | return; | ||
947 | } | ||
948 | |||
949 | newsubsys = NULL; | ||
950 | // SUBSYSTEM | ||
951 | json_state = 0; | ||
952 | json_state = json_unpack (data_js, | ||
953 | "{s:s!}", | ||
954 | GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM, | ||
955 | &newsubsys); | ||
956 | // Change subsystem with pubkey or name identifier | ||
957 | if (0 != json_state) | ||
958 | { | ||
959 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | ||
960 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
961 | json_decref (data_js); | ||
962 | return; | ||
963 | } | ||
964 | |||
965 | if (NULL == newsubsys) | ||
966 | { | ||
967 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | ||
968 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
969 | json_decref (data_js); | ||
970 | return; | ||
971 | } | ||
972 | |||
973 | if (0 >= strlen (newsubsys)) | ||
974 | { | ||
975 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | ||
976 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
977 | json_decref (data_js); | ||
978 | return; | ||
979 | } | ||
980 | |||
981 | handle->response_code = MHD_HTTP_NO_CONTENT; | ||
982 | handle->op = GNUNET_IDENTITY_set (identity_handle, | ||
983 | newsubsys, | ||
984 | ego_entry->ego, | ||
985 | &do_finished, | ||
986 | handle); | ||
987 | if (NULL == handle->op) | ||
988 | { | ||
989 | handle->emsg = GNUNET_strdup ("Setting subsystem failed"); | ||
990 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
991 | return; | ||
992 | } | ||
993 | json_decref (data_js); | ||
994 | return; | ||
995 | } | ||
996 | |||
997 | |||
998 | /** | ||
999 | * Handle identity POST request | 749 | * Handle identity POST request |
1000 | * | 750 | * |
1001 | * @param con_handle the connection handle | 751 | * @param con_handle the connection handle |
@@ -1008,8 +758,6 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
1008 | void *cls) | 758 | void *cls) |
1009 | { | 759 | { |
1010 | struct RequestHandle *handle = cls; | 760 | struct RequestHandle *handle = cls; |
1011 | struct EgoEntry *ego_entry; | ||
1012 | struct MHD_Response *resp; | ||
1013 | json_t *data_js; | 761 | json_t *data_js; |
1014 | json_error_t err; | 762 | json_error_t err; |
1015 | char *egoname; | 763 | char *egoname; |
@@ -1027,7 +775,7 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
1027 | 775 | ||
1028 | if (0 >= handle->data_size) | 776 | if (0 >= handle->data_size) |
1029 | { | 777 | { |
1030 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); | 778 | handle->ec = GNUNET_EC_IDENTITY_INVALID; |
1031 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 779 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1032 | return; | 780 | return; |
1033 | } | 781 | } |
@@ -1036,7 +784,7 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
1036 | data_js = json_loads (term_data, JSON_DECODE_ANY, &err); | 784 | data_js = json_loads (term_data, JSON_DECODE_ANY, &err); |
1037 | if (NULL == data_js) | 785 | if (NULL == data_js) |
1038 | { | 786 | { |
1039 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); | 787 | handle->ec = GNUNET_EC_IDENTITY_INVALID; |
1040 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 788 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1041 | json_decref (data_js); | 789 | json_decref (data_js); |
1042 | return; | 790 | return; |
@@ -1049,7 +797,7 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
1049 | GNUNET_REST_IDENTITY_PARAM_PRIVKEY, &privkey); | 797 | GNUNET_REST_IDENTITY_PARAM_PRIVKEY, &privkey); |
1050 | if (0 != json_unpack_state) | 798 | if (0 != json_unpack_state) |
1051 | { | 799 | { |
1052 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 800 | handle->ec = GNUNET_EC_IDENTITY_INVALID; |
1053 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 801 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1054 | json_decref (data_js); | 802 | json_decref (data_js); |
1055 | return; | 803 | return; |
@@ -1057,31 +805,19 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
1057 | 805 | ||
1058 | if (NULL == egoname) | 806 | if (NULL == egoname) |
1059 | { | 807 | { |
1060 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 808 | handle->ec = GNUNET_EC_IDENTITY_INVALID; |
1061 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 809 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1062 | json_decref (data_js); | 810 | json_decref (data_js); |
1063 | return; | 811 | return; |
1064 | } | 812 | } |
1065 | if (0 >= strlen (egoname)) | 813 | if (0 >= strlen (egoname)) |
1066 | { | 814 | { |
815 | handle->ec = GNUNET_EC_IDENTITY_INVALID; | ||
1067 | json_decref (data_js); | 816 | json_decref (data_js); |
1068 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | ||
1069 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 817 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1070 | return; | 818 | return; |
1071 | } | 819 | } |
1072 | GNUNET_STRINGS_utf8_tolower (egoname, egoname); | 820 | GNUNET_STRINGS_utf8_tolower (egoname, egoname); |
1073 | for (ego_entry = ego_head; NULL != ego_entry; | ||
1074 | ego_entry = ego_entry->next) | ||
1075 | { | ||
1076 | if (0 == strcasecmp (egoname, ego_entry->identifier)) | ||
1077 | { | ||
1078 | resp = GNUNET_REST_create_response (NULL); | ||
1079 | handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); | ||
1080 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | ||
1081 | json_decref (data_js); | ||
1082 | return; | ||
1083 | } | ||
1084 | } | ||
1085 | handle->name = GNUNET_strdup (egoname); | 821 | handle->name = GNUNET_strdup (egoname); |
1086 | if (NULL != privkey) | 822 | if (NULL != privkey) |
1087 | { | 823 | { |
@@ -1095,7 +831,6 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
1095 | else | 831 | else |
1096 | pk_ptr = NULL; | 832 | pk_ptr = NULL; |
1097 | json_decref (data_js); | 833 | json_decref (data_js); |
1098 | handle->response_code = MHD_HTTP_CREATED; | ||
1099 | handle->op = GNUNET_IDENTITY_create (identity_handle, | 834 | handle->op = GNUNET_IDENTITY_create (identity_handle, |
1100 | handle->name, | 835 | handle->name, |
1101 | pk_ptr, | 836 | pk_ptr, |
@@ -1125,8 +860,7 @@ ego_delete_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | |||
1125 | 860 | ||
1126 | if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) | 861 | if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) |
1127 | { | 862 | { |
1128 | handle->response_code = MHD_HTTP_NOT_FOUND; | 863 | handle->ec = GNUNET_EC_IDENTITY_NOT_FOUND; |
1129 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_PUBKEY); | ||
1130 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 864 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1131 | return; | 865 | return; |
1132 | } | 866 | } |
@@ -1135,13 +869,11 @@ ego_delete_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | |||
1135 | 869 | ||
1136 | if (NULL == ego_entry) | 870 | if (NULL == ego_entry) |
1137 | { | 871 | { |
1138 | handle->response_code = MHD_HTTP_NOT_FOUND; | 872 | handle->ec = GNUNET_EC_IDENTITY_NOT_FOUND; |
1139 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); | ||
1140 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 873 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1141 | return; | 874 | return; |
1142 | } | 875 | } |
1143 | 876 | ||
1144 | handle->response_code = MHD_HTTP_NO_CONTENT; | ||
1145 | handle->op = GNUNET_IDENTITY_delete (identity_handle, | 877 | handle->op = GNUNET_IDENTITY_delete (identity_handle, |
1146 | ego_entry->identifier, | 878 | ego_entry->identifier, |
1147 | &do_finished, | 879 | &do_finished, |
@@ -1169,8 +901,7 @@ ego_delete_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
1169 | 901 | ||
1170 | if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) | 902 | if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) |
1171 | { | 903 | { |
1172 | handle->response_code = MHD_HTTP_NOT_FOUND; | 904 | handle->ec = GNUNET_EC_IDENTITY_NOT_FOUND; |
1173 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_NAME); | ||
1174 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 905 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1175 | return; | 906 | return; |
1176 | } | 907 | } |
@@ -1179,13 +910,11 @@ ego_delete_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
1179 | 910 | ||
1180 | if (NULL == ego_entry) | 911 | if (NULL == ego_entry) |
1181 | { | 912 | { |
1182 | handle->response_code = MHD_HTTP_NOT_FOUND; | 913 | handle->ec = GNUNET_EC_IDENTITY_NOT_FOUND; |
1183 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); | ||
1184 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 914 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1185 | return; | 915 | return; |
1186 | } | 916 | } |
1187 | 917 | ||
1188 | handle->response_code = MHD_HTTP_NO_CONTENT; | ||
1189 | handle->op = GNUNET_IDENTITY_delete (identity_handle, | 918 | handle->op = GNUNET_IDENTITY_delete (identity_handle, |
1190 | ego_entry->identifier, | 919 | ego_entry->identifier, |
1191 | &do_finished, | 920 | &do_finished, |
@@ -1211,16 +940,14 @@ ego_sign_data_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
1211 | 940 | ||
1212 | if (ego == NULL) | 941 | if (ego == NULL) |
1213 | { | 942 | { |
1214 | handle->response_code = MHD_HTTP_BAD_REQUEST; | 943 | handle->ec = GNUNET_EC_IDENTITY_NOT_FOUND; |
1215 | handle->emsg = GNUNET_strdup ("Ego not found"); | ||
1216 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 944 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1217 | return; | 945 | return; |
1218 | } | 946 | } |
1219 | 947 | ||
1220 | if (ntohl (ego->pk.type) != GNUNET_IDENTITY_TYPE_EDDSA) | 948 | if (ntohl (ego->pk.type) != GNUNET_IDENTITY_TYPE_EDDSA) |
1221 | { | 949 | { |
1222 | handle->response_code = MHD_HTTP_BAD_REQUEST; | 950 | handle->ec = GNUNET_EC_IDENTITY_NOT_FOUND; |
1223 | handle->emsg = GNUNET_strdup ("Ego has to use an EdDSA key"); | ||
1224 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 951 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1225 | return; | 952 | return; |
1226 | } | 953 | } |
@@ -1230,8 +957,7 @@ ego_sign_data_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
1230 | strlen ( (char*) data), | 957 | strlen ( (char*) data), |
1231 | &sig)) | 958 | &sig)) |
1232 | { | 959 | { |
1233 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; | 960 | handle->ec = GNUNET_EC_UNKNOWN; |
1234 | handle->emsg = GNUNET_strdup ("Signature creation failed"); | ||
1235 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 961 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1236 | return; | 962 | return; |
1237 | } | 963 | } |
@@ -1287,8 +1013,7 @@ ego_sign_data (struct GNUNET_REST_RequestHandle *con_handle, | |||
1287 | handle->rest_handle->url_param_map, | 1013 | handle->rest_handle->url_param_map, |
1288 | &cache_key_data))) | 1014 | &cache_key_data))) |
1289 | { | 1015 | { |
1290 | handle->response_code = MHD_HTTP_BAD_REQUEST; | 1016 | handle->ec = GNUNET_EC_UNKNOWN; |
1291 | handle->emsg = GNUNET_strdup ("URL parameter missing"); | ||
1292 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1017 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1293 | return; | 1018 | return; |
1294 | } | 1019 | } |
@@ -1441,17 +1166,11 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
1441 | { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_PUBKEY, | 1166 | { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_PUBKEY, |
1442 | &ego_get_pubkey }, | 1167 | &ego_get_pubkey }, |
1443 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_get_name }, | 1168 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_get_name }, |
1444 | { MHD_HTTP_METHOD_GET, | ||
1445 | GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, | ||
1446 | &ego_get_subsystem }, | ||
1447 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_get_all }, | 1169 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_get_all }, |
1448 | { MHD_HTTP_METHOD_PUT, | 1170 | { MHD_HTTP_METHOD_PUT, |
1449 | GNUNET_REST_API_NS_IDENTITY_PUBKEY, | 1171 | GNUNET_REST_API_NS_IDENTITY_PUBKEY, |
1450 | &ego_edit_pubkey }, | 1172 | &ego_edit_pubkey }, |
1451 | { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_edit_name }, | 1173 | { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_edit_name }, |
1452 | { MHD_HTTP_METHOD_PUT, | ||
1453 | GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, | ||
1454 | &ego_edit_subsystem }, | ||
1455 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create }, | 1174 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create }, |
1456 | { MHD_HTTP_METHOD_DELETE, | 1175 | { MHD_HTTP_METHOD_DELETE, |
1457 | GNUNET_REST_API_NS_IDENTITY_PUBKEY, | 1176 | GNUNET_REST_API_NS_IDENTITY_PUBKEY, |
@@ -1464,7 +1183,6 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
1464 | GNUNET_REST_HANDLER_END }; | 1183 | GNUNET_REST_HANDLER_END }; |
1465 | 1184 | ||
1466 | 1185 | ||
1467 | handle->response_code = 0; | ||
1468 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 1186 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
1469 | handle->proc_cls = proc_cls; | 1187 | handle->proc_cls = proc_cls; |
1470 | handle->proc = proc; | 1188 | handle->proc = proc; |
diff --git a/src/identity/test_identity.c b/src/identity/test_identity.c index 58c2c8d9e..2c44f73ba 100644 --- a/src/identity/test_identity.c +++ b/src/identity/test_identity.c | |||
@@ -189,13 +189,13 @@ notification_cb (void *cls, | |||
189 | * Continuation called from successful delete operation. | 189 | * Continuation called from successful delete operation. |
190 | * | 190 | * |
191 | * @param cls NULL | 191 | * @param cls NULL |
192 | * @param emsg (should also be NULL) | 192 | * @param ec |
193 | */ | 193 | */ |
194 | static void | 194 | static void |
195 | delete_cont (void *cls, const char *emsg) | 195 | delete_cont (void *cls, enum GNUNET_ErrorCode ec) |
196 | { | 196 | { |
197 | op = NULL; | 197 | op = NULL; |
198 | CHECK (NULL == emsg); | 198 | CHECK (GNUNET_EC_NONE == ec); |
199 | res = 0; | 199 | res = 0; |
200 | end (); | 200 | end (); |
201 | } | 201 | } |
@@ -217,12 +217,12 @@ finally_delete (void *cls) | |||
217 | * Continuation called from expected-to-fail rename operation. | 217 | * Continuation called from expected-to-fail rename operation. |
218 | * | 218 | * |
219 | * @param cls NULL | 219 | * @param cls NULL |
220 | * @param emsg (should also be NULL) | 220 | * @param ec |
221 | */ | 221 | */ |
222 | static void | 222 | static void |
223 | fail_rename_cont (void *cls, const char *emsg) | 223 | fail_rename_cont (void *cls, enum GNUNET_ErrorCode ec) |
224 | { | 224 | { |
225 | CHECK (NULL != emsg); | 225 | CHECK (GNUNET_EC_NONE != ec); |
226 | op = NULL; | 226 | op = NULL; |
227 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 227 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
228 | &finally_delete, | 228 | &finally_delete, |
@@ -234,12 +234,12 @@ fail_rename_cont (void *cls, const char *emsg) | |||
234 | * Continuation called from successful rename operation. | 234 | * Continuation called from successful rename operation. |
235 | * | 235 | * |
236 | * @param cls NULL | 236 | * @param cls NULL |
237 | * @param emsg (should also be NULL) | 237 | * @param ec |
238 | */ | 238 | */ |
239 | static void | 239 | static void |
240 | success_rename_cont (void *cls, const char *emsg) | 240 | success_rename_cont (void *cls, enum GNUNET_ErrorCode ec) |
241 | { | 241 | { |
242 | CHECK (NULL == emsg); | 242 | CHECK (GNUNET_EC_NONE == ec); |
243 | op = GNUNET_IDENTITY_rename (h, "test-id", "test", &fail_rename_cont, NULL); | 243 | op = GNUNET_IDENTITY_rename (h, "test-id", "test", &fail_rename_cont, NULL); |
244 | } | 244 | } |
245 | 245 | ||
@@ -249,15 +249,15 @@ success_rename_cont (void *cls, const char *emsg) | |||
249 | * | 249 | * |
250 | * @param cls NULL | 250 | * @param cls NULL |
251 | * @param pk private key of the ego, or NULL on error | 251 | * @param pk private key of the ego, or NULL on error |
252 | * @param emsg error message | 252 | * @param ec |
253 | */ | 253 | */ |
254 | static void | 254 | static void |
255 | create_cb (void *cls, | 255 | create_cb (void *cls, |
256 | const struct GNUNET_IDENTITY_PrivateKey *pk, | 256 | const struct GNUNET_IDENTITY_PrivateKey *pk, |
257 | const char *emsg) | 257 | enum GNUNET_ErrorCode ec) |
258 | { | 258 | { |
259 | CHECK (NULL != pk); | 259 | CHECK (NULL != pk); |
260 | CHECK (NULL == emsg); | 260 | CHECK (GNUNET_EC_NONE == ec); |
261 | op = | 261 | op = |
262 | GNUNET_IDENTITY_rename (h, "test-id", "test", &success_rename_cont, NULL); | 262 | GNUNET_IDENTITY_rename (h, "test-id", "test", &success_rename_cont, NULL); |
263 | } | 263 | } |
diff --git a/src/identity/test_identity_defaults.c b/src/identity/test_identity_defaults.c deleted file mode 100644 index 63db58a1a..000000000 --- a/src/identity/test_identity_defaults.c +++ /dev/null | |||
@@ -1,301 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2013 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file identity/test_identity.c | ||
23 | * @brief testcase for identity service | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_identity_service.h" | ||
29 | #include "gnunet_testing_lib.h" | ||
30 | |||
31 | |||
32 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
33 | |||
34 | |||
35 | /** | ||
36 | * Return value from 'main'. | ||
37 | */ | ||
38 | static int res; | ||
39 | |||
40 | /** | ||
41 | * Handle to identity service. | ||
42 | */ | ||
43 | static struct GNUNET_IDENTITY_Handle *h; | ||
44 | |||
45 | /** | ||
46 | * Handle to identity operation. | ||
47 | */ | ||
48 | static struct GNUNET_IDENTITY_Operation *op; | ||
49 | |||
50 | /** | ||
51 | * Handle for task for timeout termination. | ||
52 | */ | ||
53 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | ||
54 | |||
55 | #define CHECK(cond) \ | ||
56 | do \ | ||
57 | { \ | ||
58 | if (! (cond)) \ | ||
59 | { \ | ||
60 | GNUNET_break (0); \ | ||
61 | end (); \ | ||
62 | return; \ | ||
63 | } \ | ||
64 | } while (0) | ||
65 | |||
66 | |||
67 | /** | ||
68 | * Clean up all resources used. | ||
69 | */ | ||
70 | static void | ||
71 | cleanup (void *cls) | ||
72 | { | ||
73 | (void) cls; | ||
74 | if (NULL != op) | ||
75 | { | ||
76 | GNUNET_IDENTITY_cancel (op); | ||
77 | op = NULL; | ||
78 | } | ||
79 | if (NULL != h) | ||
80 | { | ||
81 | GNUNET_IDENTITY_disconnect (h); | ||
82 | h = NULL; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | |||
87 | /** | ||
88 | * Termiante the testcase (failure). | ||
89 | * | ||
90 | * @param cls NULL | ||
91 | */ | ||
92 | static void | ||
93 | endbadly (void *cls) | ||
94 | { | ||
95 | GNUNET_SCHEDULER_shutdown (); | ||
96 | res = 1; | ||
97 | } | ||
98 | |||
99 | |||
100 | /** | ||
101 | * Termiante the testcase. | ||
102 | */ | ||
103 | static void | ||
104 | end () | ||
105 | { | ||
106 | if (NULL != endbadly_task) | ||
107 | { | ||
108 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
109 | endbadly_task = NULL; | ||
110 | } | ||
111 | GNUNET_SCHEDULER_shutdown (); | ||
112 | } | ||
113 | |||
114 | |||
115 | /** | ||
116 | * Continuation called from successful delete operation. | ||
117 | * | ||
118 | * @param cls NULL | ||
119 | * @param emsg (should also be NULL) | ||
120 | */ | ||
121 | static void | ||
122 | delete_cont (void *cls, const char *emsg) | ||
123 | { | ||
124 | op = NULL; | ||
125 | CHECK (NULL == emsg); | ||
126 | res = 0; | ||
127 | end (); | ||
128 | } | ||
129 | |||
130 | |||
131 | /** | ||
132 | * Continuation called from expected-to-fail rename operation. | ||
133 | * | ||
134 | * @param cls NULL | ||
135 | * @param emsg (should also be NULL) | ||
136 | */ | ||
137 | static void | ||
138 | get_cb (void *cls, | ||
139 | struct GNUNET_IDENTITY_Ego *ego, | ||
140 | void **ctx, | ||
141 | const char *identifier) | ||
142 | { | ||
143 | op = NULL; | ||
144 | CHECK (NULL != ego); | ||
145 | CHECK (NULL != identifier); | ||
146 | CHECK (0 == strcmp (identifier, "test-id")); | ||
147 | op = GNUNET_IDENTITY_delete (h, "test-id", &delete_cont, NULL); | ||
148 | } | ||
149 | |||
150 | |||
151 | /** | ||
152 | * Called with events about egos. | ||
153 | * | ||
154 | * @param cls NULL | ||
155 | * @param ego ego handle | ||
156 | * @param ego_ctx context for application to store data for this ego | ||
157 | * (during the lifetime of this process, initially NULL) | ||
158 | * @param identifier identifier assigned by the user for this ego, | ||
159 | * NULL if the user just deleted the ego and it | ||
160 | * must thus no longer be used | ||
161 | */ | ||
162 | static void | ||
163 | dummy_cb (void *cls, | ||
164 | struct GNUNET_IDENTITY_Ego *ego, | ||
165 | void **ctx, | ||
166 | const char *identifier) | ||
167 | { | ||
168 | (void) cls; | ||
169 | (void) ego; | ||
170 | (void) ctx; | ||
171 | (void) identifier; | ||
172 | } | ||
173 | |||
174 | |||
175 | /** | ||
176 | * Main function of the test, run from scheduler. | ||
177 | * | ||
178 | * @param cls NULL | ||
179 | * @param cfg configuration we use (also to connect to identity service) | ||
180 | * @param peer handle to access more of the peer (not used) | ||
181 | */ | ||
182 | static void | ||
183 | run_get (void *cls, | ||
184 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
185 | struct GNUNET_TESTING_Peer *peer) | ||
186 | { | ||
187 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); | ||
188 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); | ||
189 | h = GNUNET_IDENTITY_connect (cfg, &dummy_cb, NULL); | ||
190 | CHECK (NULL != h); | ||
191 | op = GNUNET_IDENTITY_get (h, "test-service", &get_cb, NULL); | ||
192 | } | ||
193 | |||
194 | |||
195 | /** | ||
196 | * Continuation called from successful rename operation. | ||
197 | * | ||
198 | * @param cls NULL | ||
199 | * @param emsg (should also be NULL) | ||
200 | */ | ||
201 | static void | ||
202 | success_set_cont (void *cls, const char *emsg) | ||
203 | { | ||
204 | op = NULL; | ||
205 | CHECK (NULL == emsg); | ||
206 | end (); | ||
207 | } | ||
208 | |||
209 | |||
210 | /** | ||
211 | * Called with events about egos. | ||
212 | * | ||
213 | * @param cls NULL | ||
214 | * @param ego ego handle | ||
215 | * @param ego_ctx context for application to store data for this ego | ||
216 | * (during the lifetime of this process, initially NULL) | ||
217 | * @param identifier identifier assigned by the user for this ego, | ||
218 | * NULL if the user just deleted the ego and it | ||
219 | * must thus no longer be used | ||
220 | */ | ||
221 | static void | ||
222 | notification_cb (void *cls, | ||
223 | struct GNUNET_IDENTITY_Ego *ego, | ||
224 | void **ctx, | ||
225 | const char *identifier) | ||
226 | { | ||
227 | if (NULL == ego) | ||
228 | return; /* skip first call */ | ||
229 | if (NULL == identifier) | ||
230 | return; /* deletion / shutdown */ | ||
231 | op = GNUNET_IDENTITY_set (h, "test-service", ego, &success_set_cont, NULL); | ||
232 | } | ||
233 | |||
234 | |||
235 | /** | ||
236 | * Called with events about created ego. | ||
237 | * | ||
238 | * @param cls NULL | ||
239 | * @param pk private key of the ego, or NULL on error | ||
240 | * @param emsg error message | ||
241 | */ | ||
242 | static void | ||
243 | create_cb (void *cls, | ||
244 | const struct GNUNET_IDENTITY_PrivateKey *pk, | ||
245 | const char *emsg) | ||
246 | { | ||
247 | CHECK (NULL == emsg); | ||
248 | CHECK (NULL != pk); | ||
249 | op = NULL; | ||
250 | } | ||
251 | |||
252 | |||
253 | /** | ||
254 | * Main function of the test, run from scheduler. | ||
255 | * | ||
256 | * @param cls NULL | ||
257 | * @param cfg configuration we use (also to connect to identity service) | ||
258 | * @param peer handle to access more of the peer (not used) | ||
259 | */ | ||
260 | static void | ||
261 | run_set (void *cls, | ||
262 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
263 | struct GNUNET_TESTING_Peer *peer) | ||
264 | { | ||
265 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); | ||
266 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); | ||
267 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); | ||
268 | CHECK (NULL != h); | ||
269 | op = GNUNET_IDENTITY_create (h, | ||
270 | "test-id", | ||
271 | NULL, | ||
272 | GNUNET_IDENTITY_TYPE_ECDSA, | ||
273 | &create_cb, NULL); | ||
274 | } | ||
275 | |||
276 | |||
277 | int | ||
278 | main (int argc, char *argv[]) | ||
279 | { | ||
280 | GNUNET_DISK_purge_cfg_dir ("test_identity.conf", | ||
281 | "GNUNET_TEST_HOME"); | ||
282 | res = 1; | ||
283 | if (0 != GNUNET_TESTING_service_run ("test-identity-defaults", | ||
284 | "identity", | ||
285 | "test_identity.conf", | ||
286 | &run_set, | ||
287 | NULL)) | ||
288 | return 1; | ||
289 | if (0 != GNUNET_TESTING_service_run ("test-identity-defaults", | ||
290 | "identity", | ||
291 | "test_identity.conf", | ||
292 | &run_get, | ||
293 | NULL)) | ||
294 | return 1; | ||
295 | GNUNET_DISK_purge_cfg_dir ("test_identity.conf", | ||
296 | "GNUNET_TEST_HOME"); | ||
297 | return res; | ||
298 | } | ||
299 | |||
300 | |||
301 | /* end of test_identity_defaults.c */ | ||
diff --git a/src/identity/test_identity_messages.sh b/src/identity/test_identity_messages.sh index 250c6a6f1..daecb1ed2 100755 --- a/src/identity/test_identity_messages.sh +++ b/src/identity/test_identity_messages.sh | |||
@@ -23,12 +23,12 @@ gnunet-identity -C recipientego -c test_identity.conf | |||
23 | RECIPIENT_KEY=$(gnunet-identity -d -e recipientego -q -c test_identity.conf) | 23 | RECIPIENT_KEY=$(gnunet-identity -d -e recipientego -q -c test_identity.conf) |
24 | MSG_ENC=$(gnunet-identity -W "$TEST_MSG" -k $RECIPIENT_KEY -c test_identity.conf) | 24 | MSG_ENC=$(gnunet-identity -W "$TEST_MSG" -k $RECIPIENT_KEY -c test_identity.conf) |
25 | MSG_DEC=$(gnunet-identity -R "$MSG_ENC" -e recipientego -c test_identity.conf) | 25 | MSG_DEC=$(gnunet-identity -R "$MSG_ENC" -e recipientego -c test_identity.conf) |
26 | 26 | gnunet-identity -D recipientego -c test_identity.conf | |
27 | if test "$TEST_MSG" != "$MSG_DEC" | 27 | gnunet-arm -e -c test_identity.conf |
28 | if [ "$TEST_MSG" != "$MSG_DEC" ] | ||
28 | then | 29 | then |
29 | echo "Failed - $TEST_MSG != $MSG_DEC" | 30 | echo "Failed - $TEST_MSG != $MSG_DEC" |
30 | exit 1 | 31 | exit 1 |
31 | fi | 32 | fi |
32 | 33 | ||
33 | gnunet-identity -D recipientego -c test_identity.conf | 34 | |
34 | gnunet-arm -e -c test_identity.conf | ||
diff --git a/src/include/gnunet_identity_service.h b/src/include/gnunet_identity_service.h index c54f6abf8..d234ff552 100644 --- a/src/include/gnunet_identity_service.h +++ b/src/include/gnunet_identity_service.h | |||
@@ -280,11 +280,11 @@ GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *id, | |||
280 | * been completed. | 280 | * been completed. |
281 | * | 281 | * |
282 | * @param cls closure | 282 | * @param cls closure |
283 | * @param emsg NULL on success, otherwise an error message | 283 | * @param ec the #GNUNET_ErrorCode |
284 | */ | 284 | */ |
285 | typedef void | 285 | typedef void |
286 | (*GNUNET_IDENTITY_Continuation) (void *cls, | 286 | (*GNUNET_IDENTITY_Continuation) (void *cls, |
287 | const char *emsg); | 287 | enum GNUNET_ErrorCode ec); |
288 | 288 | ||
289 | 289 | ||
290 | /** | 290 | /** |
@@ -320,13 +320,13 @@ GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h); | |||
320 | * | 320 | * |
321 | * @param cls closure | 321 | * @param cls closure |
322 | * @param pk private key, NULL on error | 322 | * @param pk private key, NULL on error |
323 | * @param emsg error message, NULL on success | 323 | * @param ec the #GNUNET_ErrorCode |
324 | */ | 324 | */ |
325 | typedef void | 325 | typedef void |
326 | (*GNUNET_IDENTITY_CreateContinuation) ( | 326 | (*GNUNET_IDENTITY_CreateContinuation) ( |
327 | void *cls, | 327 | void *cls, |
328 | const struct GNUNET_IDENTITY_PrivateKey *pk, | 328 | const struct GNUNET_IDENTITY_PrivateKey *pk, |
329 | const char *emsg); | 329 | enum GNUNET_ErrorCode ec); |
330 | 330 | ||
331 | 331 | ||
332 | /** | 332 | /** |
diff --git a/src/messenger/gnunet-service-messenger_ego_store.c b/src/messenger/gnunet-service-messenger_ego_store.c index 8250d0902..434c418e5 100644 --- a/src/messenger/gnunet-service-messenger_ego_store.c +++ b/src/messenger/gnunet-service-messenger_ego_store.c | |||
@@ -139,15 +139,19 @@ iterate_create_ego (void *cls, | |||
139 | static void | 139 | static void |
140 | callback_ego_create (void *cls, | 140 | callback_ego_create (void *cls, |
141 | const struct GNUNET_IDENTITY_PrivateKey *key, | 141 | const struct GNUNET_IDENTITY_PrivateKey *key, |
142 | const char *emsg) | 142 | enum GNUNET_ErrorCode ec) |
143 | { | 143 | { |
144 | struct GNUNET_MESSENGER_EgoOperation *element = cls; | 144 | struct GNUNET_MESSENGER_EgoOperation *element = cls; |
145 | struct GNUNET_MESSENGER_EgoStore *store = element->store; | 145 | struct GNUNET_MESSENGER_EgoStore *store = element->store; |
146 | 146 | ||
147 | GNUNET_assert (element->identifier); | 147 | GNUNET_assert (element->identifier); |
148 | 148 | ||
149 | if (emsg) | 149 | /** |
150 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg); | 150 | * FIXME: This is dangerous, please handle errors |
151 | */ | ||
152 | if (GNUNET_EC_NONE != ec) | ||
153 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", | ||
154 | GNUNET_ErrorCode_get_hint (ec)); | ||
151 | 155 | ||
152 | if (key) | 156 | if (key) |
153 | { | 157 | { |
@@ -360,15 +364,19 @@ delete_store_ego (struct GNUNET_MESSENGER_EgoStore *store, | |||
360 | 364 | ||
361 | static void | 365 | static void |
362 | callback_ego_rename (void *cls, | 366 | callback_ego_rename (void *cls, |
363 | const char *emsg) | 367 | enum GNUNET_ErrorCode ec) |
364 | { | 368 | { |
365 | struct GNUNET_MESSENGER_EgoOperation *element = cls; | 369 | struct GNUNET_MESSENGER_EgoOperation *element = cls; |
366 | struct GNUNET_MESSENGER_EgoStore *store = element->store; | 370 | struct GNUNET_MESSENGER_EgoStore *store = element->store; |
367 | 371 | ||
368 | GNUNET_assert (element->identifier); | 372 | GNUNET_assert (element->identifier); |
369 | 373 | ||
370 | if (emsg) | 374 | /** |
371 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg); | 375 | * FIXME: Dangerous, handle error |
376 | */ | ||
377 | if (GNUNET_EC_NONE != ec) | ||
378 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", | ||
379 | GNUNET_ErrorCode_get_hint (ec)); | ||
372 | 380 | ||
373 | struct GNUNET_HashCode hash; | 381 | struct GNUNET_HashCode hash; |
374 | GNUNET_CRYPTO_hash (element->identifier, strlen (element->identifier), &hash); | 382 | GNUNET_CRYPTO_hash (element->identifier, strlen (element->identifier), &hash); |
@@ -426,15 +434,19 @@ rename_store_ego (struct GNUNET_MESSENGER_EgoStore *store, | |||
426 | 434 | ||
427 | static void | 435 | static void |
428 | callback_ego_delete (void *cls, | 436 | callback_ego_delete (void *cls, |
429 | const char *emsg) | 437 | enum GNUNET_ErrorCode ec) |
430 | { | 438 | { |
431 | struct GNUNET_MESSENGER_EgoOperation *element = cls; | 439 | struct GNUNET_MESSENGER_EgoOperation *element = cls; |
432 | struct GNUNET_MESSENGER_EgoStore *store = element->store; | 440 | struct GNUNET_MESSENGER_EgoStore *store = element->store; |
433 | 441 | ||
434 | GNUNET_assert (element->identifier); | 442 | GNUNET_assert (element->identifier); |
435 | 443 | ||
436 | if (emsg) | 444 | /** |
437 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg); | 445 | * FIXME: Dangerous, handle error |
446 | */ | ||
447 | if (GNUNET_EC_NONE != ec) | ||
448 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", | ||
449 | GNUNET_ErrorCode_get_hint (ec)); | ||
438 | 450 | ||
439 | create_store_ego (store, element->identifier); | 451 | create_store_ego (store, element->identifier); |
440 | 452 | ||
diff --git a/src/namestore/gnunet-namestore-zonefile.c b/src/namestore/gnunet-namestore-zonefile.c index 8820dcdfa..d9331aa32 100644 --- a/src/namestore/gnunet-namestore-zonefile.c +++ b/src/namestore/gnunet-namestore-zonefile.c | |||
@@ -283,12 +283,12 @@ parse_origin (char *token, char *origin) | |||
283 | 283 | ||
284 | static void | 284 | static void |
285 | origin_create_cb (void *cls, const struct GNUNET_IDENTITY_PrivateKey *pk, | 285 | origin_create_cb (void *cls, const struct GNUNET_IDENTITY_PrivateKey *pk, |
286 | const char *emsg) | 286 | enum GNUNET_ErrorCode ec) |
287 | { | 287 | { |
288 | id_op = NULL; | 288 | id_op = NULL; |
289 | if (NULL != emsg) | 289 | if (GNUNET_EC_NONE != ec) |
290 | { | 290 | { |
291 | fprintf (stderr, "Error: %s\n", emsg); | 291 | fprintf (stderr, "Error: %s\n", GNUNET_ErrorCode_get_hint (ec)); |
292 | ret = 1; | 292 | ret = 1; |
293 | GNUNET_SCHEDULER_shutdown (); | 293 | GNUNET_SCHEDULER_shutdown (); |
294 | return; | 294 | return; |
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index d6154f0aa..843158c68 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -1195,6 +1195,16 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1195 | unsigned int rd_count; | 1195 | unsigned int rd_count; |
1196 | struct GNUNET_GNSRECORD_Data *rd; | 1196 | struct GNUNET_GNSRECORD_Data *rd; |
1197 | 1197 | ||
1198 | if (NULL == ego_name) | ||
1199 | { | ||
1200 | fprintf (stderr, | ||
1201 | _ ("Missing option `%s' for operation `%s'\n"), | ||
1202 | "-z", | ||
1203 | _ ("replace")); | ||
1204 | GNUNET_SCHEDULER_shutdown (); | ||
1205 | ret = 1; | ||
1206 | return; | ||
1207 | } | ||
1198 | if (NULL == name) | 1208 | if (NULL == name) |
1199 | { | 1209 | { |
1200 | fprintf (stderr, | 1210 | fprintf (stderr, |
@@ -1247,6 +1257,16 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1247 | 1257 | ||
1248 | if (add) | 1258 | if (add) |
1249 | { | 1259 | { |
1260 | if (NULL == ego_name) | ||
1261 | { | ||
1262 | fprintf (stderr, | ||
1263 | _ ("Missing option `%s' for operation `%s'\n"), | ||
1264 | "-z", | ||
1265 | _ ("add")); | ||
1266 | GNUNET_SCHEDULER_shutdown (); | ||
1267 | ret = 1; | ||
1268 | return; | ||
1269 | } | ||
1250 | if (NULL == name) | 1270 | if (NULL == name) |
1251 | { | 1271 | { |
1252 | fprintf (stderr, | 1272 | fprintf (stderr, |
@@ -1334,6 +1354,16 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1334 | } | 1354 | } |
1335 | if (del) | 1355 | if (del) |
1336 | { | 1356 | { |
1357 | if (NULL == ego_name) | ||
1358 | { | ||
1359 | fprintf (stderr, | ||
1360 | _ ("Missing option `%s' for operation `%s'\n"), | ||
1361 | "-z", | ||
1362 | _ ("del")); | ||
1363 | GNUNET_SCHEDULER_shutdown (); | ||
1364 | ret = 1; | ||
1365 | return; | ||
1366 | } | ||
1337 | if (NULL == name) | 1367 | if (NULL == name) |
1338 | { | 1368 | { |
1339 | fprintf (stderr, | 1369 | fprintf (stderr, |
@@ -1367,6 +1397,16 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1367 | } | 1397 | } |
1368 | else if (purge_zone) | 1398 | else if (purge_zone) |
1369 | { | 1399 | { |
1400 | if (NULL == ego_name) | ||
1401 | { | ||
1402 | fprintf (stderr, | ||
1403 | _ ("Missing option `%s' for operation `%s'\n"), | ||
1404 | "-z", | ||
1405 | _ ("purge-zone")); | ||
1406 | GNUNET_SCHEDULER_shutdown (); | ||
1407 | ret = 1; | ||
1408 | return; | ||
1409 | } | ||
1370 | list_it = GNUNET_NAMESTORE_zone_iteration_start2 (ns, | 1410 | list_it = GNUNET_NAMESTORE_zone_iteration_start2 (ns, |
1371 | &zone_pkey, | 1411 | &zone_pkey, |
1372 | &zone_iteration_error_cb, | 1412 | &zone_iteration_error_cb, |
@@ -1381,6 +1421,17 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1381 | else if (list || list_orphaned) | 1421 | else if (list || list_orphaned) |
1382 | { | 1422 | { |
1383 | if (NULL != name) | 1423 | if (NULL != name) |
1424 | { | ||
1425 | if (NULL == ego_name) | ||
1426 | { | ||
1427 | fprintf (stderr, | ||
1428 | _ ("Missing option `%s' for operation `%s'\n"), | ||
1429 | "-z", | ||
1430 | _ ("list")); | ||
1431 | GNUNET_SCHEDULER_shutdown (); | ||
1432 | ret = 1; | ||
1433 | return; | ||
1434 | } | ||
1384 | get_qe = GNUNET_NAMESTORE_records_lookup (ns, | 1435 | get_qe = GNUNET_NAMESTORE_records_lookup (ns, |
1385 | &zone_pkey, | 1436 | &zone_pkey, |
1386 | name, | 1437 | name, |
@@ -1388,6 +1439,7 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1388 | NULL, | 1439 | NULL, |
1389 | &display_record_lookup, | 1440 | &display_record_lookup, |
1390 | NULL); | 1441 | NULL); |
1442 | } | ||
1391 | else | 1443 | else |
1392 | list_it = GNUNET_NAMESTORE_zone_iteration_start2 (ns, | 1444 | list_it = GNUNET_NAMESTORE_zone_iteration_start2 (ns, |
1393 | (NULL == ego_name) ? | 1445 | (NULL == ego_name) ? |
@@ -1404,6 +1456,16 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1404 | { | 1456 | { |
1405 | struct GNUNET_IDENTITY_PublicKey pubkey; | 1457 | struct GNUNET_IDENTITY_PublicKey pubkey; |
1406 | 1458 | ||
1459 | if (NULL == ego_name) | ||
1460 | { | ||
1461 | fprintf (stderr, | ||
1462 | _ ("Missing option `%s' for operation `%s'\n"), | ||
1463 | "-z", | ||
1464 | _ ("reverse-pkey")); | ||
1465 | GNUNET_SCHEDULER_shutdown (); | ||
1466 | ret = 1; | ||
1467 | return; | ||
1468 | } | ||
1407 | if (GNUNET_OK != | 1469 | if (GNUNET_OK != |
1408 | GNUNET_IDENTITY_public_key_from_string (reverse_pkey, | 1470 | GNUNET_IDENTITY_public_key_from_string (reverse_pkey, |
1409 | &pubkey)) | 1471 | &pubkey)) |
@@ -1426,6 +1488,16 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1426 | char sh[105]; | 1488 | char sh[105]; |
1427 | char sname[64]; | 1489 | char sname[64]; |
1428 | struct GNUNET_IDENTITY_PublicKey pkey; | 1490 | struct GNUNET_IDENTITY_PublicKey pkey; |
1491 | if (NULL == ego_name) | ||
1492 | { | ||
1493 | fprintf (stderr, | ||
1494 | _ ("Missing option `%s' for operation `%s'\n"), | ||
1495 | "-z", | ||
1496 | _ ("uri")); | ||
1497 | GNUNET_SCHEDULER_shutdown (); | ||
1498 | ret = 1; | ||
1499 | return; | ||
1500 | } | ||
1429 | 1501 | ||
1430 | memset (sh, 0, 105); | 1502 | memset (sh, 0, 105); |
1431 | memset (sname, 0, 64); | 1503 | memset (sname, 0, 64); |
@@ -1476,7 +1548,8 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1476 | if (monitor) | 1548 | if (monitor) |
1477 | { | 1549 | { |
1478 | zm = GNUNET_NAMESTORE_zone_monitor_start2 (cfg, | 1550 | zm = GNUNET_NAMESTORE_zone_monitor_start2 (cfg, |
1479 | &zone_pkey, | 1551 | (NULL != ego_name) ? |
1552 | &zone_pkey : NULL, | ||
1480 | GNUNET_YES, | 1553 | GNUNET_YES, |
1481 | &monitor_error_cb, | 1554 | &monitor_error_cb, |
1482 | NULL, | 1555 | NULL, |
@@ -1523,44 +1596,6 @@ identity_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
1523 | 1596 | ||
1524 | 1597 | ||
1525 | /** | 1598 | /** |
1526 | * Function called with the default ego to be used for GNS | ||
1527 | * operations. Used if the user did not specify a zone via | ||
1528 | * command-line or environment variables. | ||
1529 | * | ||
1530 | * @param cls NULL | ||
1531 | * @param ego default ego, NULL for none | ||
1532 | * @param ctx NULL | ||
1533 | * @param name unused | ||
1534 | */ | ||
1535 | static void | ||
1536 | default_ego_cb (void *cls, | ||
1537 | struct GNUNET_IDENTITY_Ego *ego, | ||
1538 | void **ctx, | ||
1539 | const char *name) | ||
1540 | { | ||
1541 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
1542 | |||
1543 | (void) ctx; | ||
1544 | (void) name; | ||
1545 | get_default = NULL; | ||
1546 | if (NULL == ego) | ||
1547 | { | ||
1548 | fprintf (stderr, | ||
1549 | _ ("No default identity configured for `namestore' subsystem\n" | ||
1550 | "Run gnunet-identity -s namestore -e $NAME to set the default to $NAME\n" | ||
1551 | "Run gnunet-identity -d to get a list of choices for $NAME\n")); | ||
1552 | GNUNET_SCHEDULER_shutdown (); | ||
1553 | ret = -1; | ||
1554 | return; | ||
1555 | } | ||
1556 | else | ||
1557 | { | ||
1558 | identity_cb ((void *) cfg, ego); | ||
1559 | } | ||
1560 | } | ||
1561 | |||
1562 | |||
1563 | /** | ||
1564 | * Function called with ALL of the egos known to the | 1599 | * Function called with ALL of the egos known to the |
1565 | * identity service, used on startup if the user did | 1600 | * identity service, used on startup if the user did |
1566 | * not specify a zone on the command-line. | 1601 | * not specify a zone on the command-line. |
@@ -1597,11 +1632,10 @@ id_connect_cb (void *cls, | |||
1597 | } | 1632 | } |
1598 | if (NULL != ego) | 1633 | if (NULL != ego) |
1599 | return; | 1634 | return; |
1600 | if (NULL != ego_name) | 1635 | if (NULL == ego_name) |
1601 | el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &identity_cb, (void *) cfg); | 1636 | run_with_zone_pkey (cfg); |
1602 | else | 1637 | else |
1603 | get_default = | 1638 | el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &identity_cb, (void *) cfg); |
1604 | GNUNET_IDENTITY_get (idh, "namestore", &default_ego_cb, (void *) cfg); | ||
1605 | } | 1639 | } |
1606 | 1640 | ||
1607 | 1641 | ||
diff --git a/src/reclaim/gnunet-did.c b/src/reclaim/gnunet-did.c index b5f5f4922..1f91e0ee2 100644 --- a/src/reclaim/gnunet-did.c +++ b/src/reclaim/gnunet-did.c | |||
@@ -336,11 +336,11 @@ create_did_cb (enum GNUNET_GenericReturnValue status, void *cls) | |||
336 | static void | 336 | static void |
337 | create_did_ego_create_cb (void *cls, | 337 | create_did_ego_create_cb (void *cls, |
338 | const struct GNUNET_IDENTITY_PrivateKey *pk, | 338 | const struct GNUNET_IDENTITY_PrivateKey *pk, |
339 | const char *emsg) | 339 | enum GNUNET_ErrorCode ec) |
340 | { | 340 | { |
341 | if (emsg != NULL) | 341 | if (GNUNET_EC_NONE != ec) |
342 | { | 342 | { |
343 | printf ("%s\n", emsg); | 343 | printf ("%s\n", GNUNET_ErrorCode_get_hint (ec)); |
344 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | 344 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); |
345 | ret = 1; | 345 | ret = 1; |
346 | return; | 346 | return; |