+handle_rename_message (void *cls,
+ const struct RenameMessage *rm)
+{
+ uint16_t old_name_len;
+ struct Ego *ego;
+ char *old_name;
+ char *new_name;
+ struct RenameContext rename_ctx;
+ struct GNUNET_SERVICE_Client *client = cls;
+ char *fn_old;
+ char *fn_new;
+ const char *old_name_tmp;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received RENAME message from client\n");
+ old_name_len = ntohs (rm->old_name_len);
+ old_name_tmp = (const char *) &rm[1];
+ old_name = GNUNET_strdup (old_name_tmp);
+ GNUNET_STRINGS_utf8_tolower (old_name_tmp, old_name);
+ new_name = GNUNET_strdup (&old_name_tmp[old_name_len]);
+ GNUNET_STRINGS_utf8_tolower (&old_name_tmp[old_name_len], new_name);
+
+ /* 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);
+ GNUNET_free (old_name);
+ GNUNET_free (new_name);
+ 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);
+ GNUNET_free (old_name);
+ GNUNET_free (new_name);
+ 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_free (old_name);
+ GNUNET_free (new_name);
+ 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)