static struct Ego *ego_tail;
+
/**
* Task run during shutdown.
*
str,
"DEFAULT_IDENTIFIER",
ego->identifier);
- /* fixme: write configuration to disk... */
+ 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);
send_result_code (client, 0, NULL);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
GNUNET_CRYPTO_ecc_key_free (pk);
}
+/**
+ * Closure for 'handle_ego_rename'.
+ */
+struct RenameContext
+{
+ /**
+ * Old name.
+ */
+ const char *old_name;
+
+ /**
+ * New name.
+ */
+ const char *new_name;
+};
+
+
+/**
+ * An ego was renamed; rename it in all subsystems where it is
+ * currently set as the default.
+ *
+ * @param cls the 'struct RenameContext'
+ * @param section a section in the configuration to process
+ */
+static void
+handle_ego_rename (void *cls,
+ const char *section)
+{
+ struct RenameContext *rc = cls;
+ char *id;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
+ section,
+ "DEFAULT_IDENTIFIER",
+ &id))
+ return;
+ if (0 != strcmp (id, rc->old_name))
+ {
+ GNUNET_free (id);
+ return;
+ }
+ GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
+ section,
+ "DEFAULT_IDENTIFIER",
+ rc->new_name);
+ GNUNET_free (id);
+}
+
/**
* Handler for RENAME message from client, creates
struct Ego *ego;
const char *old_name;
const char *new_name;
+ struct RenameContext rename_ctx;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received RENAME message from client\n");
old_name))
{
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);
/* FIXME: also rename file! */
notify_listeners (ego);
}
+/**
+ * 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);
+}
+
+
/**
* Handler for DELETE message from client, creates
* new identity.
GNUNET_CONTAINER_DLL_remove (ego_head,
ego_tail,
ego);
+ GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg,
+ &handle_ego_delete,
+ ego->identifier);
+ 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);
/* FIXME: also delete file! */
GNUNET_free (ego->identifier);
ego->identifier = NULL;