aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-07-16 08:13:57 +0000
committerChristian Grothoff <christian@grothoff.org>2013-07-16 08:13:57 +0000
commit1edb6808e700e7872bc463a096a165ebcba784ed (patch)
treee62b434cfcf11d77aa9863b5be4795702b237e6c
parentb25336a7a9fe0e407c88d0bd95b962c031180ce8 (diff)
downloadgnunet-1edb6808e700e7872bc463a096a165ebcba784ed.tar.gz
gnunet-1edb6808e700e7872bc463a096a165ebcba784ed.zip
-handle loading, deletion and renaming of files of egos
-rw-r--r--src/identity/gnunet-service-identity.c72
1 files changed, 68 insertions, 4 deletions
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c
index 6553c797c..166f86697 100644
--- a/src/identity/gnunet-service-identity.c
+++ b/src/identity/gnunet-service-identity.c
@@ -109,6 +109,25 @@ static struct Ego *ego_head;
109static struct Ego *ego_tail; 109static struct Ego *ego_tail;
110 110
111 111
112/**
113 * Get the name of the file we use to store a given ego.
114 *
115 * @param ego ego for which we need the filename
116 * @return full filename for the given ego
117 */
118static char *
119get_ego_filename (struct Ego *ego)
120{
121 char *filename;
122
123 GNUNET_asprintf (&filename,
124 "%s%s%s",
125 ego_directory,
126 DIR_SEPARATOR_STR,
127 ego->identifier);
128 return filename;
129}
130
112 131
113/** 132/**
114 * Task run during shutdown. 133 * Task run during shutdown.
@@ -589,6 +608,8 @@ handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client,
589 const char *old_name; 608 const char *old_name;
590 const char *new_name; 609 const char *new_name;
591 struct RenameContext rename_ctx; 610 struct RenameContext rename_ctx;
611 char *fn_old;
612 char *fn_new;
592 613
593 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 614 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
594 "Received RENAME message from client\n"); 615 "Received RENAME message from client\n");
@@ -615,8 +636,20 @@ handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client,
615 for (ego = ego_head; NULL != ego; ego = ego->next) 636 for (ego = ego_head; NULL != ego; ego = ego->next)
616 { 637 {
617 if (0 == strcmp (ego->identifier, 638 if (0 == strcmp (ego->identifier,
639 new_name))
640 {
641 send_result_code (client, 1, gettext_noop ("target name already exists"));
642 GNUNET_SERVER_receive_done (client, GNUNET_OK);
643 return;
644 }
645 }
646
647 for (ego = ego_head; NULL != ego; ego = ego->next)
648 {
649 if (0 == strcmp (ego->identifier,
618 old_name)) 650 old_name))
619 { 651 {
652 fn_old = get_ego_filename (ego);
620 GNUNET_free (ego->identifier); 653 GNUNET_free (ego->identifier);
621 rename_ctx.old_name = old_name; 654 rename_ctx.old_name = old_name;
622 rename_ctx.new_name = new_name; 655 rename_ctx.new_name = new_name;
@@ -629,9 +662,13 @@ handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client,
629 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 662 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
630 _("Failed to write subsystem default identifier map to `%s'.\n"), 663 _("Failed to write subsystem default identifier map to `%s'.\n"),
631 subsystem_cfg_file); 664 subsystem_cfg_file);
632
633 ego->identifier = GNUNET_strdup (new_name); 665 ego->identifier = GNUNET_strdup (new_name);
634 /* FIXME: also rename file! */ 666 fn_new = get_ego_filename (ego);
667
668 if (0 != RENAME (fn_old, fn_new))
669 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old);
670 GNUNET_free (fn_old);
671 GNUNET_free (fn_new);
635 notify_listeners (ego); 672 notify_listeners (ego);
636 send_result_code (client, 0, NULL); 673 send_result_code (client, 0, NULL);
637 GNUNET_SERVER_receive_done (client, GNUNET_OK); 674 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -694,6 +731,7 @@ handle_delete_message (void *cls, struct GNUNET_SERVER_Client *client,
694 uint16_t name_len; 731 uint16_t name_len;
695 struct Ego *ego; 732 struct Ego *ego;
696 const char *name; 733 const char *name;
734 char *fn;
697 735
698 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
699 "Received DELETE message from client\n"); 737 "Received DELETE message from client\n");
@@ -732,7 +770,10 @@ handle_delete_message (void *cls, struct GNUNET_SERVER_Client *client,
732 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 770 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
733 _("Failed to write subsystem default identifier map to `%s'.\n"), 771 _("Failed to write subsystem default identifier map to `%s'.\n"),
734 subsystem_cfg_file); 772 subsystem_cfg_file);
735 /* FIXME: also delete file! */ 773 fn = get_ego_filename (ego);
774 if (0 != UNLINK (fn))
775 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
776 GNUNET_free (fn);
736 GNUNET_free (ego->identifier); 777 GNUNET_free (ego->identifier);
737 ego->identifier = NULL; 778 ego->identifier = NULL;
738 notify_listeners (ego); 779 notify_listeners (ego);
@@ -763,7 +804,30 @@ static int
763process_ego_file (void *cls, 804process_ego_file (void *cls,
764 const char *filename) 805 const char *filename)
765{ 806{
766 GNUNET_break (0); // not implemented 807 struct Ego *ego;
808 const char *fn;
809
810 fn = strrchr (filename, (int) DIR_SEPARATOR);
811 if (NULL == fn)
812 {
813 GNUNET_break (0);
814 return GNUNET_OK;
815 }
816 ego = GNUNET_new (struct Ego);
817 ego->pk = GNUNET_CRYPTO_ecc_key_create_from_file (filename);
818 if (NULL == ego->pk)
819 {
820 GNUNET_free (ego);
821 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
822 _("Failed to parse ego information in `%s'\n"),
823 filename);
824 return GNUNET_OK;
825 }
826
827 ego->identifier = GNUNET_strdup (fn);
828 GNUNET_CONTAINER_DLL_insert (ego_head,
829 ego_tail,
830 ego);
767 return GNUNET_OK; 831 return GNUNET_OK;
768} 832}
769 833