gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r20664 - gnunet-gtk/src/gns
Date: Wed, 21 Mar 2012 18:22:30 +0100

Author: wachs
Date: 2012-03-21 18:22:30 +0100 (Wed, 21 Mar 2012)
New Revision: 20664

Modified:
   gnunet-gtk/src/gns/gnunet-gns-gtk_zone.c
Log:
- removign records


Modified: gnunet-gtk/src/gns/gnunet-gns-gtk_zone.c
===================================================================
--- gnunet-gtk/src/gns/gnunet-gns-gtk_zone.c    2012-03-21 17:22:21 UTC (rev 
20663)
+++ gnunet-gtk/src/gns/gnunet-gns-gtk_zone.c    2012-03-21 17:22:30 UTC (rev 
20664)
@@ -89,7 +89,10 @@
     GNUNET_break (0);
   }
   else
+  {
     GNUNET_break (0);
+    GNUNET_free (uc);
+  }
 }
 
 void
@@ -115,15 +118,8 @@
 
   gtk_tree_model_get_iter_from_string(gns->tm, &it, path);
 
-  if (TRUE == gtk_tree_model_iter_parent (gns->tm, &parent, &it))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Has parent\n");
-  }
-  else
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No parent\n");
+  if (FALSE == gtk_tree_model_iter_parent (gns->tm, &parent, &it))
     parent = it;
-  }
 
   children = gtk_tree_model_iter_n_children (gns->tm, &parent);
   if (children < 1)
@@ -199,14 +195,12 @@
 
   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 */
     struct UpdateContext * uc = GNUNET_malloc (sizeof (struct UpdateContext));
     uc->gns = gns;
@@ -218,7 +212,96 @@
   }
 }
 
+void
+check_name_validity_and_remove_proc (void *cls,
+                                            int32_t success,
+                                            const char *emsg)
+{
 
+}
+void
+check_name_validity_and_remove (struct GNUNET_GNS_Context *gns, gchar *path)
+{
+  GtkTreeIter it;
+  GtkTreeIter parent;
+  char *name;
+  int valid = GNUNET_YES;
+  struct GNUNET_NAMESTORE_RecordData rd;
+
+  char          *n_name;
+  int           n_type;
+  gboolean      n_public;
+  char          *n_exp_color;
+  guint64       n_exp_time;
+  char          *n_exp_str;
+  gboolean      n_is_relative;
+  char          *n_value;
+  char          *n_value_color;
+
+  gtk_tree_model_get_iter_from_string(gns->tm, &it, path);
+  gtk_tree_model_get(gns->tm, &it,
+                     TREE_COL_NAME, &name,
+                     -1);
+
+  if (TRUE == gtk_tree_model_iter_parent (gns->tm, &parent, &it))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Removing single record\n");
+
+    gtk_tree_model_get(gns->tm, &it,
+                       TREE_COL_NAME, &n_name,
+                       TREE_COL_RECORD_TYPE, &n_type,
+                       TREE_COL_IS_PUBLIC, &n_public,
+                       TREE_COL_EXP_TIME_COLOR, &n_exp_color,
+                       TREE_COL_EXP_TIME, &n_exp_time,
+                       TREE_COL_EXP_TIME_IS_REL, &n_is_relative,
+                       TREE_COL_EXP_TIME_AS_STR, &n_exp_str,
+                       TREE_COL_VAL_AS_STR, &n_value,
+                       TREE_COL_VAL_COLOR, &n_value_color,
+                       -1);
+
+    /* valid name */
+    if (NULL == n_name)
+        valid = GNUNET_NO;
+
+    /* valid record type */
+    if (0 == n_type)
+      valid = GNUNET_NO;
+
+    /* valid expiration */
+    if ((n_exp_color != NULL) || (NULL == n_exp_str) || (0 == n_exp_time))
+        valid = GNUNET_NO;
+
+    /* valid value */
+    if ((n_value_color != NULL) || (NULL == n_value))
+        valid = GNUNET_NO;
+
+    if (GNUNET_YES == valid)
+    {
+      if (FALSE == n_public)
+        rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_PRIVATE;
+      else
+        rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_NONE;
+      rd.record_type = n_type;
+      rd.expiration.abs_value = n_exp_time;
+      rd.data_size = strlen (n_value) + 1;
+      rd.data = GNUNET_malloc(rd.data_size);
+      memcpy ((void *) rd.data, n_value, rd.data_size);
+      GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name, &rd, 
&check_name_validity_and_remove_proc, path);
+      GNUNET_free (rd.data);
+    }
+    g_free (n_name);
+    g_free (n_exp_color);
+    g_free (n_exp_str);
+    g_free (n_value);
+    g_free (n_value_color);
+  }
+  else
+  {
+    GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name, NULL, 
&check_name_validity_and_remove_proc, path);
+  }
+  g_free (name);
+}
+
 /**
  * The user has selected a new record type.  Update the
  * model, possibly invalidating (marking 'red') the existing
@@ -742,18 +825,10 @@
 {
   struct GNUNET_GNS_Context *gns = user_data;
   GtkTreeIter it;
-  GtkTreeIter parent;
-  GtkTreeIter child;
   int not_dummy;
-  int children;
-  int c;
-  gboolean has_parent;
-
-  char *name = "";
   char *path;
-  struct GNUNET_NAMESTORE_RecordData *rd;
-  struct Remove_Context *rcc;
 
+
   GtkTreeView *tv = GTK_TREE_VIEW(gtk_builder_get_object (gns->builder, 
"GNUNET_GNS_GTK_main_treeview"));
   GtkTreeModel *tm;
   GtkTreeSelection * ts = gtk_tree_view_get_selection(tv);
@@ -764,46 +839,9 @@
   if (GNUNET_NO == not_dummy)
     return; /* do not delete the dummy line */
 
-  /* Has parent? */
-  has_parent = gtk_tree_model_iter_parent (tm, &parent, &it);
-  if (TRUE == has_parent)
-  {
-    /* this is a single record */
-    gtk_tree_model_get(tm, &parent, TREE_COL_NAME, &name, -1);
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting single record for name 
`%s'\n", name);
-    rd = build_rd_from_datastore (tm, &it);
-    rcc= GNUNET_malloc (sizeof (struct Remove_Context));
-    rcc->gns = gns;
-    rcc->tm = tm;
-    rcc->path = gtk_tree_model_get_string_from_iter (tm, &it);
-    GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name,(const struct 
GNUNET_NAMESTORE_RecordData *) rd, &remove_proc, rcc);
-    GNUNET_free (rd);
-
-  }
-  else
-  {
-    /* this is a whole name */
-    gtk_tree_model_get(tm, &it, TREE_COL_NAME, &name, -1);
-    children = gtk_tree_model_iter_n_children (tm, &it);
-    //path = gtk_tree_model_get_string_from_iter(tm, &it);
-    path = gtk_tree_model_get_string_from_iter (tm, &it);
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting name `%s' with %u 
children\n", name, children);
-    gtk_tree_model_iter_children (tm, &child, &it);
-    for (c = 0; c < children; c++)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting %u record for name 
`%s'\n", c, name);
-
-      rd = build_rd_from_datastore (tm, &child);
-      rcc= GNUNET_malloc (sizeof (struct Remove_Context));
-      rcc->gns = gns;
-      rcc->tm = tm;
-      rcc->path = gtk_tree_model_get_string_from_iter (tm, &child);
-      GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name,(const struct 
GNUNET_NAMESTORE_RecordData *) rd, &remove_proc, rcc);
-      gtk_tree_model_iter_next (tm, &child);
-    }
-    gtk_tree_model_get_iter_from_string(tm, &it, path);
-    gtk_tree_store_remove (gns->ts, &it);
-  }
+  path = gtk_tree_model_get_string_from_iter (gns->tm, &it);
+  check_name_validity_and_remove(gns, path);
+  g_free (path);
 }
 
 void zone_iteration_proc (void *cls,




reply via email to

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