aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-07-16 08:00:30 +0000
committerChristian Grothoff <christian@grothoff.org>2013-07-16 08:00:30 +0000
commitb25336a7a9fe0e407c88d0bd95b962c031180ce8 (patch)
tree78de09ae9cdbf1256a280b3d6af6e76f17854ead
parentb5a13bc0febdb8cf1a9d6dcca65b210882a21d95 (diff)
downloadgnunet-b25336a7a9fe0e407c88d0bd95b962c031180ce8.tar.gz
gnunet-b25336a7a9fe0e407c88d0bd95b962c031180ce8.zip
-update subsystem cfg on rename/delete
-rw-r--r--src/identity/gnunet-service-identity.c112
1 files changed, 111 insertions, 1 deletions
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c
index e1d4dff82..6553c797c 100644
--- a/src/identity/gnunet-service-identity.c
+++ b/src/identity/gnunet-service-identity.c
@@ -109,6 +109,7 @@ static struct Ego *ego_head;
109static struct Ego *ego_tail; 109static struct Ego *ego_tail;
110 110
111 111
112
112/** 113/**
113 * Task run during shutdown. 114 * Task run during shutdown.
114 * 115 *
@@ -413,7 +414,12 @@ handle_set_default_message (void *cls, struct GNUNET_SERVER_Client *client,
413 str, 414 str,
414 "DEFAULT_IDENTIFIER", 415 "DEFAULT_IDENTIFIER",
415 ego->identifier); 416 ego->identifier);
416 /* fixme: write configuration to disk... */ 417 if (GNUNET_OK !=
418 GNUNET_CONFIGURATION_write (subsystem_cfg,
419 subsystem_cfg_file))
420 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
421 _("Failed to write subsystem default identifier map to `%s'.\n"),
422 subsystem_cfg_file);
417 send_result_code (client, 0, NULL); 423 send_result_code (client, 0, NULL);
418 GNUNET_SERVER_receive_done (client, GNUNET_OK); 424 GNUNET_SERVER_receive_done (client, GNUNET_OK);
419 GNUNET_CRYPTO_ecc_key_free (pk); 425 GNUNET_CRYPTO_ecc_key_free (pk);
@@ -513,6 +519,55 @@ handle_create_message (void *cls, struct GNUNET_SERVER_Client *client,
513} 519}
514 520
515 521
522/**
523 * Closure for 'handle_ego_rename'.
524 */
525struct RenameContext
526{
527 /**
528 * Old name.
529 */
530 const char *old_name;
531
532 /**
533 * New name.
534 */
535 const char *new_name;
536};
537
538
539/**
540 * An ego was renamed; rename it in all subsystems where it is
541 * currently set as the default.
542 *
543 * @param cls the 'struct RenameContext'
544 * @param section a section in the configuration to process
545 */
546static void
547handle_ego_rename (void *cls,
548 const char *section)
549{
550 struct RenameContext *rc = cls;
551 char *id;
552
553 if (GNUNET_OK !=
554 GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
555 section,
556 "DEFAULT_IDENTIFIER",
557 &id))
558 return;
559 if (0 != strcmp (id, rc->old_name))
560 {
561 GNUNET_free (id);
562 return;
563 }
564 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
565 section,
566 "DEFAULT_IDENTIFIER",
567 rc->new_name);
568 GNUNET_free (id);
569}
570
516 571
517/** 572/**
518 * Handler for RENAME message from client, creates 573 * Handler for RENAME message from client, creates
@@ -533,6 +588,7 @@ handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client,
533 struct Ego *ego; 588 struct Ego *ego;
534 const char *old_name; 589 const char *old_name;
535 const char *new_name; 590 const char *new_name;
591 struct RenameContext rename_ctx;
536 592
537 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 593 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
538 "Received RENAME message from client\n"); 594 "Received RENAME message from client\n");
@@ -562,6 +618,18 @@ handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client,
562 old_name)) 618 old_name))
563 { 619 {
564 GNUNET_free (ego->identifier); 620 GNUNET_free (ego->identifier);
621 rename_ctx.old_name = old_name;
622 rename_ctx.new_name = new_name;
623 GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg,
624 &handle_ego_rename,
625 &rename_ctx);
626 if (GNUNET_OK !=
627 GNUNET_CONFIGURATION_write (subsystem_cfg,
628 subsystem_cfg_file))
629 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
630 _("Failed to write subsystem default identifier map to `%s'.\n"),
631 subsystem_cfg_file);
632
565 ego->identifier = GNUNET_strdup (new_name); 633 ego->identifier = GNUNET_strdup (new_name);
566 /* FIXME: also rename file! */ 634 /* FIXME: also rename file! */
567 notify_listeners (ego); 635 notify_listeners (ego);
@@ -577,6 +645,39 @@ handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client,
577 645
578 646
579/** 647/**
648 * An ego was removed, remove it from all subsystems where it is
649 * currently set as the default.
650 *
651 * @param cls name of the removed ego (const char *)
652 * @param section a section in the configuration to process
653 */
654static void
655handle_ego_delete (void *cls,
656 const char *section)
657{
658 const char *identifier = cls;
659 char *id;
660
661 if (GNUNET_OK !=
662 GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
663 section,
664 "DEFAULT_IDENTIFIER",
665 &id))
666 return;
667 if (0 != strcmp (id, identifier))
668 {
669 GNUNET_free (id);
670 return;
671 }
672 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
673 section,
674 "DEFAULT_IDENTIFIER",
675 NULL);
676 GNUNET_free (id);
677}
678
679
680/**
580 * Handler for DELETE message from client, creates 681 * Handler for DELETE message from client, creates
581 * new identity. 682 * new identity.
582 * 683 *
@@ -622,6 +723,15 @@ handle_delete_message (void *cls, struct GNUNET_SERVER_Client *client,
622 GNUNET_CONTAINER_DLL_remove (ego_head, 723 GNUNET_CONTAINER_DLL_remove (ego_head,
623 ego_tail, 724 ego_tail,
624 ego); 725 ego);
726 GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg,
727 &handle_ego_delete,
728 ego->identifier);
729 if (GNUNET_OK !=
730 GNUNET_CONFIGURATION_write (subsystem_cfg,
731 subsystem_cfg_file))
732 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
733 _("Failed to write subsystem default identifier map to `%s'.\n"),
734 subsystem_cfg_file);
625 /* FIXME: also delete file! */ 735 /* FIXME: also delete file! */
626 GNUNET_free (ego->identifier); 736 GNUNET_free (ego->identifier);
627 ego->identifier = NULL; 737 ego->identifier = NULL;