[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r25214 - gnunet-gtk/src/setup
From: |
gnunet |
Subject: |
[GNUnet-SVN] r25214 - gnunet-gtk/src/setup |
Date: |
Tue, 4 Dec 2012 10:48:25 +0100 |
Author: grothoff
Date: 2012-12-04 10:48:25 +0100 (Tue, 04 Dec 2012)
New Revision: 25214
Modified:
gnunet-gtk/src/setup/gnunet-setup-gns-edit.h
gnunet-gtk/src/setup/gnunet-setup-gns.c
Log:
-basic move logic, adding support for shadow record flag
Modified: gnunet-gtk/src/setup/gnunet-setup-gns-edit.h
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-gns-edit.h 2012-12-04 09:48:10 UTC
(rev 25213)
+++ gnunet-gtk/src/setup/gnunet-setup-gns-edit.h 2012-12-04 09:48:25 UTC
(rev 25214)
@@ -95,6 +95,18 @@
GtkDialog *dialog;
/**
+ * Context for loading/generating the zone key for the target zone
+ * (used if the edit operation causes the record to be moved).
+ */
+ struct GNUNET_CRYPTO_RsaKeyGenerationContext *rkgc;
+
+ /**
+ * Associated namestore operation.
+ * (used if the edit operation causes the record to be moved).
+ */
+ struct GNUNET_NAMESTORE_QueueEntry *qe;
+
+ /**
* Old name of the record (for deletion).
*/
gchar *n_name;
@@ -120,6 +132,11 @@
int old_record_in_namestore;
/**
+ * Type of the record.
+ */
+ uint32_t record_type;
+
+ /**
* Is this record 'public'?
*/
gboolean n_public;
Modified: gnunet-gtk/src/setup/gnunet-setup-gns.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-gns.c 2012-12-04 09:48:10 UTC (rev
25213)
+++ gnunet-gtk/src/setup/gnunet-setup-gns.c 2012-12-04 09:48:25 UTC (rev
25214)
@@ -845,6 +845,7 @@
gchar *n_name;
gint n_type;
gboolean n_public;
+ gboolean n_is_shadow;
guint64 n_exp_time;
gboolean n_is_relative;
gchar *n_value;
@@ -857,6 +858,7 @@
GNS_TREESTORE_COL_IS_PUBLIC, &n_public,
GNS_TREESTORE_COL_EXP_TIME, &n_exp_time,
GNS_TREESTORE_COL_EXP_TIME_IS_REL, &n_is_relative,
+ GNS_TREESTORE_COL_IS_SHADOW, &n_is_shadow,
GNS_TREESTORE_COL_VAL_AS_STR, &n_value,
-1);
if ( (NULL == n_name) ||
@@ -880,6 +882,8 @@
rd[c].flags = GNUNET_NAMESTORE_RF_AUTHORITY;
else
rd[c].flags = GNUNET_NAMESTORE_RF_AUTHORITY |
GNUNET_NAMESTORE_RF_PRIVATE;
+ if (n_is_shadow)
+ rd[c].flags |= GNUNET_NAMESTORE_RF_SHADOW_RECORD;
rd[c].record_type = n_type;
rd[c].expiration_time = n_exp_time;
if (n_is_relative)
@@ -1038,6 +1042,7 @@
gboolean n_public;
guint64 n_exp_time;
gboolean n_is_relative;
+ gboolean n_is_shadow;
char *n_value;
gtk_tree_model_get_iter_from_string (tm, &it, path);
@@ -1055,6 +1060,7 @@
GNS_TREESTORE_COL_IS_PUBLIC, &n_public,
GNS_TREESTORE_COL_EXP_TIME, &n_exp_time,
GNS_TREESTORE_COL_EXP_TIME_IS_REL, &n_is_relative,
+ GNS_TREESTORE_COL_IS_SHADOW, &n_is_shadow,
GNS_TREESTORE_COL_VAL_AS_STR, &n_value,
-1);
@@ -1065,6 +1071,8 @@
rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_PRIVATE;
if (n_is_relative)
rd.flags |= GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION;
+ if (n_is_shadow)
+ rd.flags |= GNUNET_NAMESTORE_RF_SHADOW_RECORD;
rd.record_type = n_type;
rd.expiration_time = n_exp_time;
GNUNET_NAMESTORE_string_to_value (n_type, n_value,
@@ -1121,6 +1129,100 @@
/**
+ * Release resources of an edit dialog context.
+ *
+ * @param edc resources to free
+ */
+static void
+free_edit_dialog_context (struct EditDialogContext *edc)
+{
+ g_free (edc->n_name);
+ g_free (edc->n_new_name);
+ g_free (edc->n_value);
+ g_free (edc->new_zone_option);
+ GNUNET_free (edc);
+}
+
+
+/**
+ * Function called upon completion of a 'move' operation.
+ *
+ * @param cls the 'struct EditDialogContext' of the operation that completed
+ * @param success GNUNET_OK if the operation succeeded
+ * @param emsg error message if the operation failed
+ */
+static void
+record_move_finish (void *cls,
+ int32_t success,
+ const char *emsg)
+{
+ struct EditDialogContext *edc = cls;
+
+ edc->qe = NULL;
+ if (NULL != emsg)
+ show_error_message (_("Failed to move record to target zone"),
+ emsg);
+ free_edit_dialog_context (edc);
+}
+
+
+/**
+ * Function called upon completion of 'GNUNET_CRYPTO_rsa_key_create_async'.
+ * Displays an error message upon failure, otherwise stores the moved record
+ * in the target zone.
+ *
+ * @param cls closure with the struct EditDialogContext;
+ * @param pk NULL on error, otherwise the private key (which must be free'd by
the callee)
+ * @param emsg NULL on success, otherwise an error message
+ */
+static void
+record_move_continuation (void *cls,
+ struct GNUNET_CRYPTO_RsaPrivateKey *pk,
+ const char *emsg)
+{
+ struct EditDialogContext *edc = cls;
+ struct GNUNET_NAMESTORE_RecordData rd;
+ void *data;
+ size_t data_size;
+
+ edc->rkgc = NULL;
+ if (NULL != emsg)
+ {
+ show_error_message (_("Failed to access key for target zone"),
+ emsg);
+ free_edit_dialog_context (edc);
+ return;
+ }
+ if (GNUNET_OK !=
+ GNUNET_NAMESTORE_string_to_value (edc->record_type,
+ edc->n_value,
+ &data,
+ &data_size))
+ {
+ /* edit dialog produced invalid value string!? */
+ GNUNET_break (0);
+ return;
+ }
+ rd.record_type = edc->record_type;
+ rd.expiration_time = UINT64_MAX;
+ if (edc->n_public)
+ rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
+ else
+ rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_PRIVATE;
+ if (edc->n_is_relative)
+ rd.flags |= GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION;
+ if (edc->n_is_shadow)
+ rd.flags |= GNUNET_NAMESTORE_RF_SHADOW_RECORD;
+ rd.data_size = data_size;
+ rd.data = data;
+ edc->qe = GNUNET_NAMESTORE_record_create (namestore, pk,
+ edc->n_new_name,
+ &rd,
+ &record_move_finish, edc);
+}
+
+
+/**
* The edit dialog completed; update the namestore and the
* view based on the new values in 'edc'.
*
@@ -1134,8 +1236,6 @@
char *path;
char *estr;
- /* FIXME: logic to move records between zones is missing here!
- (#2473) */
switch (ret)
{
case GTK_RESPONSE_REJECT: /* code for 'delete' */
@@ -1170,39 +1270,79 @@
break;
case GTK_RESPONSE_OK:
/* update model */
- estr = exp_time_to_string (edc->n_is_relative,
- edc->n_exp_time);
- gtk_tree_store_set (ts, &edc->it,
- GNS_TREESTORE_COL_NAME, edc->n_name,
- GNS_TREESTORE_COL_IS_PUBLIC, edc->n_public,
- GNS_TREESTORE_COL_EXP_TIME, edc->n_exp_time,
- GNS_TREESTORE_COL_EXP_TIME_IS_REL, edc->n_is_relative,
- GNS_TREESTORE_COL_EXP_TIME_AS_STR, estr,
- GNS_TREESTORE_COL_IS_SHADOW, edc->n_is_shadow,
- GNS_TREESTORE_COL_VAL_AS_STR, edc->n_value,
- GNS_TREESTORE_COL_VAL_COLOR, NULL,
- -1);
- GNUNET_free (estr);
- if (GNUNET_YES == edc->old_record_in_namestore)
+ if (0 == strcmp (edc->new_zone_option,
+ current_zone_option))
{
- /* replace record in database with that from model */
- check_name_validity_and_commit (&edc->it, edc->n_name);
+ /* zone stayed the same, update record in current model/zone */
+ estr = exp_time_to_string (edc->n_is_relative,
+ edc->n_exp_time);
+ gtk_tree_store_set (ts, &edc->it,
+ GNS_TREESTORE_COL_NAME, edc->n_name,
+ GNS_TREESTORE_COL_IS_PUBLIC, edc->n_public,
+ GNS_TREESTORE_COL_EXP_TIME, edc->n_exp_time,
+ GNS_TREESTORE_COL_EXP_TIME_IS_REL, edc->n_is_relative,
+ GNS_TREESTORE_COL_EXP_TIME_AS_STR, estr,
+ GNS_TREESTORE_COL_IS_SHADOW, edc->n_is_shadow,
+ GNS_TREESTORE_COL_VAL_AS_STR, edc->n_value,
+ GNS_TREESTORE_COL_VAL_COLOR, NULL,
+ -1);
+ GNUNET_free (estr);
+ if (GNUNET_YES == edc->old_record_in_namestore)
+ {
+ /* replace record in database with that from model */
+ check_name_validity_and_commit (&edc->it, edc->n_name);
+ }
+ else
+ {
+ /* add record in database based on model */
+ check_name_validity_and_commit (&edc->it, NULL);
+ }
}
else
{
- /* add record in database based on model */
- check_name_validity_and_commit (&edc->it, NULL);
+ char *keyfile;
+
+ /* zone changed, remove record from old zone, add to new zone! */
+ if (GNUNET_YES == edc->old_record_in_namestore)
+ {
+ /* remove item from tree view and namestore */
+ path = gtk_tree_model_get_string_from_iter (tm, &edc->it);
+ remove_records_by_path (path);
+ g_free (path);
+ }
+ else
+ {
+ /* remove item just from tree view, as it was not in the model */
+ gtk_tree_store_remove (ts, &edc->it);
+ }
+
+ /* now add item to target zone */
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "gns",
+
edc->new_zone_option,
+ &keyfile))
+ {
+ char *emsg;
+
+ GNUNET_asprintf (&emsg,
+ _("Option `%s' missing in section `%s'\n"),
+ edc->new_zone_option, "gns");
+ show_error_message (_("Failed to access key for target zone"),
+ emsg);
+ GNUNET_free (emsg);
+ }
+ edc->rkgc = GNUNET_CRYPTO_rsa_key_create_start (keyfile,
+ &record_move_continuation,
+ edc);
+ GNUNET_free (keyfile);
+ return;
}
break;
default:
GNUNET_break (0);
break;
}
- g_free (edc->n_name);
- g_free (edc->n_new_name);
- g_free (edc->n_value);
- g_free (edc->new_zone_option);
- GNUNET_free (edc);
+ free_edit_dialog_context (edc);
}
@@ -1244,6 +1384,7 @@
edc->new_zone_option = g_strdup (current_zone_option);
edc->n_new_name = g_strdup (edc->n_name);
edc->cont = &edit_dialog_continuation;
+ edc->record_type = n_type;
switch (n_type)
{
case GNUNET_DNSPARSER_TYPE_A:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r25214 - gnunet-gtk/src/setup,
gnunet <=