gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r29958 - gnunet-gtk/src/namestore


From: gnunet
Subject: [GNUnet-SVN] r29958 - gnunet-gtk/src/namestore
Date: Tue, 8 Oct 2013 10:35:15 +0200

Author: grothoff
Date: 2013-10-08 10:35:15 +0200 (Tue, 08 Oct 2013)
New Revision: 29958

Modified:
   gnunet-gtk/src/namestore/gnunet-namestore-gtk.c
   gnunet-gtk/src/namestore/gnunet-namestore-gtk_edit.c
   gnunet-gtk/src/namestore/gnunet-namestore-gtk_edit.h
Log:
also make sure free zone selection works in edit dialogs

Modified: gnunet-gtk/src/namestore/gnunet-namestore-gtk.c
===================================================================
--- gnunet-gtk/src/namestore/gnunet-namestore-gtk.c     2013-10-08 08:35:02 UTC 
(rev 29957)
+++ gnunet-gtk/src/namestore/gnunet-namestore-gtk.c     2013-10-08 08:35:15 UTC 
(rev 29958)
@@ -182,25 +182,6 @@
 
 
 /**
- * Columns in the zone list store.
- */
-enum ZONE_COLUMNS
-{
-
-  /**
-   * A gchararray
-   */
-  ZONE_LS_NAME = 0,
-
-
-  /**
-   * A `struct GNUNET_IDENTITY_Ego`
-   */
-  ZONE_LS_EGO = 1
-};
-
-
-/**
  * Closure for 'operation_done_cont'.
  */
 struct OperationContext
@@ -253,7 +234,7 @@
   /**
    * Private key of target zone.
    */
-  struct GNUNET_CRYPTO_EccPrivateKey *pk;
+  struct GNUNET_CRYPTO_EccPrivateKey pk;
 
   /**
    * Data to free.
@@ -832,7 +813,6 @@
   {
     show_error_message (_("Record combination not permitted"),
                        _("Given the existing records, adding a new record of 
this type is not allowed."));
-    GNUNET_free (moc->pk);
     GNUNET_free (moc->data);
     GNUNET_free (moc);
     free_edit_dialog_context (edc);
@@ -845,12 +825,11 @@
   oc = GNUNET_new (struct OperationContext);
   GNUNET_CONTAINER_DLL_insert (oc_head, oc_tail, oc);
   oc->qe = GNUNET_NAMESTORE_records_store (namestore,
-                                          moc->pk,
+                                          &moc->pk,
                                           edc->name,
                                           rd_count + 1,
                                           rd_new,
                                           &operation_done_cont, oc);
-  GNUNET_free (moc->pk);
   GNUNET_free (moc->data);
   GNUNET_free (moc);
   free_edit_dialog_context (edc);
@@ -871,8 +850,13 @@
   struct MoveOperationContext *moc = cls;
   struct GNUNET_CRYPTO_EccPublicSignKey pubkey;
 
-  GNUNET_CRYPTO_ecc_key_get_public_for_signature (moc->pk,
-                                   &pubkey);
+  if (NULL == block)
+  {
+    merge_with_existing_records (moc, 0, NULL);
+    return;
+  }
+  GNUNET_CRYPTO_ecc_key_get_public_for_signature (&moc->pk,
+                                                  &pubkey);
   if (GNUNET_OK !=
       GNUNET_NAMESTORE_block_decrypt (block,
                                      &pubkey,
@@ -882,7 +866,6 @@
   {
     show_error_message (_("Failed to decode existing record in target zone"),
                        _("Failed to add new record."));
-    GNUNET_free (moc->pk);
     GNUNET_free (moc->data);
     free_edit_dialog_context (moc->edc);
     GNUNET_free (moc);
@@ -1008,37 +991,14 @@
     }
     else
     {
-      char *keyfile;
-      struct GNUNET_CRYPTO_EccPrivateKey *pk;
+      const struct GNUNET_CRYPTO_EccPrivateKey *pk;
       struct MoveOperationContext *moc;
       struct GNUNET_HashCode query;
 
       /* determine target zone */
-      if ( (GNUNET_OK !=
-            GNUNET_CONFIGURATION_get_value_filename (cfg,
-                                                     "gns",
-                                                     edc->new_zone_option,
-                                                     &keyfile)) ||
-           (NULL == 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);
-        break;
-      }
-      pk = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
-      GNUNET_free (keyfile);
-      if (NULL == pk)
-      {
-       show_error_message (_("Failed to load private key for target zone"),
-                           NULL);
-       break;
-      }
+      GNUNET_assert (NULL != edc->ego);
+      pk = GNUNET_IDENTITY_ego_get_private_key (edc->ego);
+      GNUNET_assert (NULL != pk);
       GNUNET_NAMESTORE_query_from_private_key (pk,
                                               edc->name,
                                               &query);
@@ -1046,9 +1006,8 @@
       moc->data = data;
       moc->rd = rd;
       moc->edc = edc;
-      moc->pk = pk;
+      moc->pk = *pk;
       GNUNET_CONTAINER_DLL_insert (moc_head, moc_tail, moc);
-
       moc->qe = GNUNET_NAMESTORE_lookup_block (namestore,
                                               &query,
                                               &decrypt_block_for_merge,
@@ -1437,7 +1396,7 @@
                "Selected row is not a record row\n");
     return FALSE;
   }
-  popup  = GTK_MENU (get_object ("gnunet_namestore_edit_popup_menu"));
+  popup  = GTK_MENU (get_object ("gnunet_namestore_gtk_edit_popup_menu"));
   gtk_widget_show_all (GTK_WIDGET (popup));
   gtk_menu_popup (popup, NULL, NULL, NULL, NULL, 0, 0);
   return TRUE;
@@ -2098,7 +2057,6 @@
                _("A pending namestore operation was not transmitted to the 
namestore.\n"));
     GNUNET_CONTAINER_DLL_remove (moc_head, moc_tail, moc);
     GNUNET_NAMESTORE_cancel (moc->qe);
-    GNUNET_free (moc->pk);
     free_edit_dialog_context (moc->edc);
     GNUNET_free (moc->data);
     GNUNET_free (moc);

Modified: gnunet-gtk/src/namestore/gnunet-namestore-gtk_edit.c
===================================================================
--- gnunet-gtk/src/namestore/gnunet-namestore-gtk_edit.c        2013-10-08 
08:35:02 UTC (rev 29957)
+++ gnunet-gtk/src/namestore/gnunet-namestore-gtk_edit.c        2013-10-08 
08:35:15 UTC (rev 29958)
@@ -27,24 +27,6 @@
 
 
 /**
- * Columns in the 'zone_liststore'.
- */
-enum ZoneListColumn
-{
-  /**
-   * A gchararray with the name of the zone for users.
-   */
-  ZONELIST_COL_NAME = 0,
-
-  /**
-   * A gchararray with the name of the configuration file option with
-   * the zone key.
-   */
-  ZONELIST_COL_OPTION = 1
-};
-
-
-/**
  * Disable 'save' button, dialog state is not acceptable.
  *
  * @param edc dialog to modify
@@ -164,6 +146,44 @@
 
 
 /**
+ * Setup the zone combobox.
+ *
+ * @param edc dialog to setup the combo box for
+ */
+static void
+setup_zone (struct EditDialogContext *edc)
+{
+  GtkTreeIter iter;
+  GtkComboBox *cb;
+  gchar *name;
+
+  cb = GTK_COMBO_BOX (gtk_builder_get_object (edc->builder,
+                                              "edit_dialog_zone_combobox"));
+
+  gtk_combo_box_set_model (cb,
+                           GTK_TREE_MODEL (edc->zone_liststore));
+  GNUNET_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL 
(edc->zone_liststore),
+                                                &iter));
+  do {
+    gtk_tree_model_get (GTK_TREE_MODEL (edc->zone_liststore),
+                        &iter,
+                        ZONE_LS_NAME, &name,
+                        -1);
+    if (0 == strcmp (name,
+                     edc->new_zone_option))
+    {
+      g_free (name);
+      break;
+    }
+    g_free (name);
+  } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (edc->zone_liststore),
+                                     &iter));
+  gtk_combo_box_set_active_iter (cb,
+                                 &iter);
+}
+
+
+/**
  * Initialize widgets of the edit dialog that are the same regardless of
  * the type of the record.
  *
@@ -173,10 +193,8 @@
 edit_dialog_setup_common_elements (struct EditDialogContext *edc)
 {
   GtkComboBox *cb;
-  GtkTreeModel *tm;
   GtkListStore *ls;
   GtkTreeIter iter;
-  gchar *opt;
   struct GNUNET_TIME_Absolute at;
   struct GNUNET_TIME_Relative rt;
   time_t tp;
@@ -270,32 +288,7 @@
   gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object 
(edc->builder,
                                                                      
"edit_dialog_expiration_absolute_seconds_spinbutton")),
                             (double) ymd->tm_sec);
-
-  /* set source zone! */
-  cb = GTK_COMBO_BOX (gtk_builder_get_object (edc->builder,
-                                             "edit_dialog_zone_combobox"));
-  tm = gtk_combo_box_get_model (cb);
-  opt = NULL;
-  if (gtk_tree_model_get_iter_first (tm, &iter))
-  {
-    do
-    {
-      gtk_tree_model_get (tm, &iter,
-                         ZONELIST_COL_OPTION, &opt,
-                         -1);
-      if ( (NULL != opt) &&
-          (0 == strcasecmp (opt,
-                            edc->new_zone_option)) )
-       break;
-      g_free (opt);
-      opt = NULL;
-    } while (gtk_tree_model_iter_next (tm, &iter));
-  }
-  if (NULL != opt)
-  {
-    gtk_combo_box_set_active_iter (cb, &iter);
-    g_free (opt);
-  }
+  setup_zone (edc);
 }
 
 
@@ -315,6 +308,7 @@
   GtkTreeModel *tm;
   GtkTreeIter iter;
   gchar *opt;
+  struct GNUNET_IDENTITY_Ego *ego;
 
   /* is public flag */
   edc->n_public = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON 
(gtk_builder_get_object (edc->builder,
@@ -402,15 +396,19 @@
   else
   {
     gtk_tree_model_get (tm, &iter,
-                       ZONELIST_COL_OPTION, &opt,
+                       ZONE_LS_NAME, &opt,
+                        ZONE_LS_EGO, &ego,
                        -1);
     if (NULL == opt)
+    {
       GNUNET_break (0);
+    }
     else
     {
       g_free (edc->new_zone_option);
       edc->new_zone_option = g_strdup (opt);
       g_free (opt);
+      edc->ego = ego;
     }
   }
 }

Modified: gnunet-gtk/src/namestore/gnunet-namestore-gtk_edit.h
===================================================================
--- gnunet-gtk/src/namestore/gnunet-namestore-gtk_edit.h        2013-10-08 
08:35:02 UTC (rev 29957)
+++ gnunet-gtk/src/namestore/gnunet-namestore-gtk_edit.h        2013-10-08 
08:35:15 UTC (rev 29958)
@@ -32,6 +32,26 @@
 
 
 /**
+ * Columns in the zone list store.
+ */
+enum ZONE_COLUMNS
+{
+
+  /**
+   * A gchararray
+   */
+  ZONE_LS_NAME = 0,
+
+
+  /**
+   * A `struct GNUNET_IDENTITY_Ego`
+   */
+  ZONE_LS_EGO = 1
+};
+
+
+
+/**
  * Context for edit operations.
  */
 struct EditDialogContext;
@@ -99,11 +119,16 @@
   gchar *n_value;
 
   /**
-   * Zone into which the record should be placed.
+   * Name of the zone into which the record should be placed.
    */
   gchar *new_zone_option;
 
   /**
+   * Ego of the zone into which the record should be placed.
+   */
+  struct GNUNET_IDENTITY_Ego *ego;
+
+  /**
    * Expiration time value (absolute or relative).
    */
   guint64 n_exp_time;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]