+handle_rename_message (void *cls,
+ const struct RenameMessage *rm)
+{
+ uint16_t old_name_len;
+ struct Ego *ego;
+ const char *old_name;
+ const char *new_name;
+ struct RenameContext rename_ctx;
+ struct GNUNET_SERVICE_Client *client = cls;
+ char *fn_old;
+ char *fn_new;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received RENAME message from client\n");
+ old_name_len = ntohs (rm->old_name_len);
+ old_name = (const char *) &rm[1];
+ new_name = &old_name[old_name_len];
+
+ /* check if new name is already in use */
+ for (ego = ego_head; NULL != ego; ego = ego->next)
+ {
+ if (0 == strcmp (ego->identifier,
+ new_name))
+ {
+ send_result_code (client, 1, gettext_noop ("target name already exists"));
+ GNUNET_SERVICE_client_continue (client);
+ return;
+ }
+ }
+
+ /* locate old name and, if found, perform rename */
+ for (ego = ego_head; NULL != ego; ego = ego->next)
+ {
+ if (0 == strcmp (ego->identifier,
+ old_name))
+ {
+ fn_old = get_ego_filename (ego);
+ GNUNET_free (ego->identifier);
+ rename_ctx.old_name = old_name;
+ rename_ctx.new_name = new_name;
+ GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg,
+ &handle_ego_rename,
+ &rename_ctx);
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_write (subsystem_cfg,
+ subsystem_cfg_file))
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to write subsystem default identifier map to `%s'.\n"),
+ subsystem_cfg_file);
+ ego->identifier = GNUNET_strdup (new_name);
+ fn_new = get_ego_filename (ego);
+ if (0 != RENAME (fn_old, fn_new))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old);
+ GNUNET_free (fn_old);
+ GNUNET_free (fn_new);
+ notify_listeners (ego);
+ send_result_code (client, 0, NULL);
+ GNUNET_SERVICE_client_continue (client);
+ return;
+ }
+ }
+
+ /* failed to locate old name */
+ send_result_code (client, 1, gettext_noop ("no matching ego found"));
+ GNUNET_SERVICE_client_continue (client);
+}
+
+
+/**
+ * An ego was removed, remove it from all subsystems where it is
+ * currently set as the default.
+ *
+ * @param cls name of the removed ego (const char *)
+ * @param section a section in the configuration to process
+ */
+static void
+handle_ego_delete (void *cls,
+ const char *section)
+{
+ const char *identifier = cls;
+ char *id;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
+ section,
+ "DEFAULT_IDENTIFIER",
+ &id))
+ return;
+ if (0 != strcmp (id, identifier))
+ {
+ GNUNET_free (id);
+ return;
+ }
+ GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
+ section,
+ "DEFAULT_IDENTIFIER",
+ NULL);
+ GNUNET_free (id);
+}
+
+/**
+ * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_DELETE message
+ *
+ * @param cls client sending the message
+ * @param msg message of type `struct DeleteMessage`
+ * @return #GNUNET_OK if @a msg is well-formed
+ */
+static int
+check_delete_message (void *cls,
+ const struct DeleteMessage *msg)