gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r20662 - gnunet-gtk/src/gns


From: gnunet
Subject: [GNUnet-SVN] r20662 - gnunet-gtk/src/gns
Date: Wed, 21 Mar 2012 17:41:06 +0100

Author: wachs
Date: 2012-03-21 17:41:06 +0100 (Wed, 21 Mar 2012)
New Revision: 20662

Modified:
   gnunet-gtk/src/gns/gnunet-gns-gtk_zone.c
Log:
- writing records back implemented


Modified: gnunet-gtk/src/gns/gnunet-gns-gtk_zone.c
===================================================================
--- gnunet-gtk/src/gns/gnunet-gns-gtk_zone.c    2012-03-21 16:12:46 UTC (rev 
20661)
+++ gnunet-gtk/src/gns/gnunet-gns-gtk_zone.c    2012-03-21 16:41:06 UTC (rev 
20662)
@@ -52,8 +52,47 @@
   TYPE_LIST_TYPENAME
 };
 
+struct UpdateContext
+{
+  struct GNUNET_GNS_Context *gns;
+  struct GNUNET_NAMESTORE_RecordData *rd;
+  unsigned int rd_count;
+  char * name;
+};
 
 void
+check_name_validity_and_commit_remove_proc (void *cls,
+                                            int32_t success,
+                                            const char *emsg)
+{
+  struct UpdateContext * uc = cls;
+  unsigned int c;
+  if ((GNUNET_OK == success) || (GNUNET_NO == success))
+  {
+     for (c = 0; c < uc->rd_count; c++)
+     {
+       GNUNET_NAMESTORE_record_create(uc->gns->ns, uc->gns->pkey,
+           uc->name, &uc->rd[c],NULL, NULL);
+       GNUNET_free ((void *) uc->rd[c].data);
+     }
+     GNUNET_free (uc->rd);
+     GNUNET_free (uc->name);
+     GNUNET_free (uc);
+  }
+  else if (GNUNET_SYSERR == success)
+  {
+    for (c = 0; c < uc->rd_count; c++)
+      GNUNET_free ((void *) uc->rd[c].data);
+    GNUNET_free (uc->rd);
+    GNUNET_free (uc->name);
+    GNUNET_free (uc);
+    GNUNET_break (0);
+  }
+  else
+    GNUNET_break (0);
+}
+
+void
 check_name_validity_and_commit (struct GNUNET_GNS_Context *gns, gchar *path)
 {
   GtkTreeIter it;
@@ -97,7 +136,7 @@
                      TREE_COL_NAME, &name,
                      -1);
 
-  struct GNUNET_NAMESTORE_RecordData rd[children];
+  struct GNUNET_NAMESTORE_RecordData *rd = GNUNET_malloc (children * sizeof 
(struct GNUNET_NAMESTORE_RecordData));
 
   if (FALSE == gtk_tree_model_iter_children (gns->tm, &it, &parent))
   {
@@ -134,28 +173,47 @@
     if ((n_value_color != NULL) || (NULL == n_value))
         valid = GNUNET_NO;
 
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Child [%u] is %s\n", c, (GNUNET_NO 
== valid) ? "INVALID" : "VALID");
+    if (GNUNET_YES == valid)
+    {
+      if (FALSE == n_public)
+        rd[c].flags = GNUNET_NAMESTORE_RF_AUTHORITY | 
GNUNET_NAMESTORE_RF_PRIVATE;
+      else
+        rd[c].flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_NONE;
+      rd[c].record_type = n_type;
+      rd[c].expiration.abs_value = n_exp_time;
+      rd[c].data_size = strlen (n_value) + 1;
+      rd[c].data = GNUNET_malloc(rd[c].data_size);
+      memcpy ((void *) rd[c].data, n_value, rd[c].data_size);
 
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Child [%u] is %s\n",
+          c, (GNUNET_NO == valid) ? "INVALID" : "VALID");
+    }
     g_free (n_name);
     g_free (n_exp_color);
     g_free (n_exp_str);
     g_free (n_value);
     g_free (n_value_color);
 
-    if ((GNUNET_NO == valid) || (FALSE == gtk_tree_model_iter_next (gns->tm, 
&it)))
-      break;
+    gtk_tree_model_iter_next (gns->tm, &it);
   }
 
   if (GNUNET_NO == valid)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Not valid\n");
+    for (c = 0; c < children; c++)
+      GNUNET_free_non_null ((void *)  rd[c].data);
+    GNUNET_free_non_null (rd);
   }
   else
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Valid %s\n", name);
     /* Remove old entries */
-    GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name, NULL, NULL, NULL);
-    /* Create new records */
+    struct UpdateContext * uc = GNUNET_malloc (sizeof (struct UpdateContext));
+    uc->gns = gns;
+    uc->rd = rd;
+    uc->rd_count = children;
+    uc->name = strdup (name);
+    GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name, NULL, 
&check_name_validity_and_commit_remove_proc, uc);
     g_free (name);
   }
 }
@@ -489,7 +547,6 @@
 {
   GtkTreeIter it;
   GtkTreeIter parent;
-  GtkTreeIter child;
   int not_dummy;
   gboolean has_parent;
   GtkCellRendererText *renderer;
@@ -531,7 +588,6 @@
 GNUNET_GNS_GTK_main_treeview_popup_menu_exp1d_cb (GtkWidget *widget,
                                             gpointer user_data)
 {
-  GNUNET_break(0);
   set_exp (user_data, "1 d");
   return TRUE;
 }




reply via email to

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