diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-03-21 17:22:30 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-03-21 17:22:30 +0000 |
commit | f2951f014d7778ebec8a25b37529e9e9ee9a8b1f (patch) | |
tree | 61499ae23e2ca860e19be72b0364c55bf2da747f | |
parent | 7e0d56b4ae0ada09ab717c0c5345a047bc7c2b48 (diff) | |
download | gnunet-gtk-f2951f014d7778ebec8a25b37529e9e9ee9a8b1f.tar.gz gnunet-gtk-f2951f014d7778ebec8a25b37529e9e9ee9a8b1f.zip |
- removign records
-rw-r--r-- | src/gns/gnunet-gns-gtk_zone.c | 156 |
1 files changed, 97 insertions, 59 deletions
diff --git a/src/gns/gnunet-gns-gtk_zone.c b/src/gns/gnunet-gns-gtk_zone.c index 022ae286..f5eb9a45 100644 --- a/src/gns/gnunet-gns-gtk_zone.c +++ b/src/gns/gnunet-gns-gtk_zone.c | |||
@@ -89,7 +89,10 @@ check_name_validity_and_commit_remove_proc (void *cls, | |||
89 | GNUNET_break (0); | 89 | GNUNET_break (0); |
90 | } | 90 | } |
91 | else | 91 | else |
92 | { | ||
92 | GNUNET_break (0); | 93 | GNUNET_break (0); |
94 | GNUNET_free (uc); | ||
95 | } | ||
93 | } | 96 | } |
94 | 97 | ||
95 | void | 98 | void |
@@ -115,15 +118,8 @@ check_name_validity_and_commit (struct GNUNET_GNS_Context *gns, gchar *path) | |||
115 | 118 | ||
116 | gtk_tree_model_get_iter_from_string(gns->tm, &it, path); | 119 | gtk_tree_model_get_iter_from_string(gns->tm, &it, path); |
117 | 120 | ||
118 | if (TRUE == gtk_tree_model_iter_parent (gns->tm, &parent, &it)) | 121 | if (FALSE == gtk_tree_model_iter_parent (gns->tm, &parent, &it)) |
119 | { | ||
120 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Has parent\n"); | ||
121 | } | ||
122 | else | ||
123 | { | ||
124 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No parent\n"); | ||
125 | parent = it; | 122 | parent = it; |
126 | } | ||
127 | 123 | ||
128 | children = gtk_tree_model_iter_n_children (gns->tm, &parent); | 124 | children = gtk_tree_model_iter_n_children (gns->tm, &parent); |
129 | if (children < 1) | 125 | if (children < 1) |
@@ -199,14 +195,12 @@ check_name_validity_and_commit (struct GNUNET_GNS_Context *gns, gchar *path) | |||
199 | 195 | ||
200 | if (GNUNET_NO == valid) | 196 | if (GNUNET_NO == valid) |
201 | { | 197 | { |
202 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Not valid\n"); | ||
203 | for (c = 0; c < children; c++) | 198 | for (c = 0; c < children; c++) |
204 | GNUNET_free_non_null ((void *) rd[c].data); | 199 | GNUNET_free_non_null ((void *) rd[c].data); |
205 | GNUNET_free_non_null (rd); | 200 | GNUNET_free_non_null (rd); |
206 | } | 201 | } |
207 | else | 202 | else |
208 | { | 203 | { |
209 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Valid %s\n", name); | ||
210 | /* Remove old entries */ | 204 | /* Remove old entries */ |
211 | struct UpdateContext * uc = GNUNET_malloc (sizeof (struct UpdateContext)); | 205 | struct UpdateContext * uc = GNUNET_malloc (sizeof (struct UpdateContext)); |
212 | uc->gns = gns; | 206 | uc->gns = gns; |
@@ -218,6 +212,95 @@ check_name_validity_and_commit (struct GNUNET_GNS_Context *gns, gchar *path) | |||
218 | } | 212 | } |
219 | } | 213 | } |
220 | 214 | ||
215 | void | ||
216 | check_name_validity_and_remove_proc (void *cls, | ||
217 | int32_t success, | ||
218 | const char *emsg) | ||
219 | { | ||
220 | |||
221 | } | ||
222 | void | ||
223 | check_name_validity_and_remove (struct GNUNET_GNS_Context *gns, gchar *path) | ||
224 | { | ||
225 | GtkTreeIter it; | ||
226 | GtkTreeIter parent; | ||
227 | char *name; | ||
228 | int valid = GNUNET_YES; | ||
229 | struct GNUNET_NAMESTORE_RecordData rd; | ||
230 | |||
231 | char *n_name; | ||
232 | int n_type; | ||
233 | gboolean n_public; | ||
234 | char *n_exp_color; | ||
235 | guint64 n_exp_time; | ||
236 | char *n_exp_str; | ||
237 | gboolean n_is_relative; | ||
238 | char *n_value; | ||
239 | char *n_value_color; | ||
240 | |||
241 | gtk_tree_model_get_iter_from_string(gns->tm, &it, path); | ||
242 | gtk_tree_model_get(gns->tm, &it, | ||
243 | TREE_COL_NAME, &name, | ||
244 | -1); | ||
245 | |||
246 | if (TRUE == gtk_tree_model_iter_parent (gns->tm, &parent, &it)) | ||
247 | { | ||
248 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Removing single record\n"); | ||
249 | |||
250 | gtk_tree_model_get(gns->tm, &it, | ||
251 | TREE_COL_NAME, &n_name, | ||
252 | TREE_COL_RECORD_TYPE, &n_type, | ||
253 | TREE_COL_IS_PUBLIC, &n_public, | ||
254 | TREE_COL_EXP_TIME_COLOR, &n_exp_color, | ||
255 | TREE_COL_EXP_TIME, &n_exp_time, | ||
256 | TREE_COL_EXP_TIME_IS_REL, &n_is_relative, | ||
257 | TREE_COL_EXP_TIME_AS_STR, &n_exp_str, | ||
258 | TREE_COL_VAL_AS_STR, &n_value, | ||
259 | TREE_COL_VAL_COLOR, &n_value_color, | ||
260 | -1); | ||
261 | |||
262 | /* valid name */ | ||
263 | if (NULL == n_name) | ||
264 | valid = GNUNET_NO; | ||
265 | |||
266 | /* valid record type */ | ||
267 | if (0 == n_type) | ||
268 | valid = GNUNET_NO; | ||
269 | |||
270 | /* valid expiration */ | ||
271 | if ((n_exp_color != NULL) || (NULL == n_exp_str) || (0 == n_exp_time)) | ||
272 | valid = GNUNET_NO; | ||
273 | |||
274 | /* valid value */ | ||
275 | if ((n_value_color != NULL) || (NULL == n_value)) | ||
276 | valid = GNUNET_NO; | ||
277 | |||
278 | if (GNUNET_YES == valid) | ||
279 | { | ||
280 | if (FALSE == n_public) | ||
281 | rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_PRIVATE; | ||
282 | else | ||
283 | rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_NONE; | ||
284 | rd.record_type = n_type; | ||
285 | rd.expiration.abs_value = n_exp_time; | ||
286 | rd.data_size = strlen (n_value) + 1; | ||
287 | rd.data = GNUNET_malloc(rd.data_size); | ||
288 | memcpy ((void *) rd.data, n_value, rd.data_size); | ||
289 | GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name, &rd, &check_name_validity_and_remove_proc, path); | ||
290 | GNUNET_free (rd.data); | ||
291 | } | ||
292 | g_free (n_name); | ||
293 | g_free (n_exp_color); | ||
294 | g_free (n_exp_str); | ||
295 | g_free (n_value); | ||
296 | g_free (n_value_color); | ||
297 | } | ||
298 | else | ||
299 | { | ||
300 | GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name, NULL, &check_name_validity_and_remove_proc, path); | ||
301 | } | ||
302 | g_free (name); | ||
303 | } | ||
221 | 304 | ||
222 | /** | 305 | /** |
223 | * The user has selected a new record type. Update the | 306 | * The user has selected a new record type. Update the |
@@ -742,17 +825,9 @@ void GNUNET_GNS_GTK_delete_popup_menu_delete_cb (GtkMenuItem *menuitem, | |||
742 | { | 825 | { |
743 | struct GNUNET_GNS_Context *gns = user_data; | 826 | struct GNUNET_GNS_Context *gns = user_data; |
744 | GtkTreeIter it; | 827 | GtkTreeIter it; |
745 | GtkTreeIter parent; | ||
746 | GtkTreeIter child; | ||
747 | int not_dummy; | 828 | int not_dummy; |
748 | int children; | ||
749 | int c; | ||
750 | gboolean has_parent; | ||
751 | |||
752 | char *name = ""; | ||
753 | char *path; | 829 | char *path; |
754 | struct GNUNET_NAMESTORE_RecordData *rd; | 830 | |
755 | struct Remove_Context *rcc; | ||
756 | 831 | ||
757 | GtkTreeView *tv = GTK_TREE_VIEW(gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_main_treeview")); | 832 | GtkTreeView *tv = GTK_TREE_VIEW(gtk_builder_get_object (gns->builder, "GNUNET_GNS_GTK_main_treeview")); |
758 | GtkTreeModel *tm; | 833 | GtkTreeModel *tm; |
@@ -764,46 +839,9 @@ void GNUNET_GNS_GTK_delete_popup_menu_delete_cb (GtkMenuItem *menuitem, | |||
764 | if (GNUNET_NO == not_dummy) | 839 | if (GNUNET_NO == not_dummy) |
765 | return; /* do not delete the dummy line */ | 840 | return; /* do not delete the dummy line */ |
766 | 841 | ||
767 | /* Has parent? */ | 842 | path = gtk_tree_model_get_string_from_iter (gns->tm, &it); |
768 | has_parent = gtk_tree_model_iter_parent (tm, &parent, &it); | 843 | check_name_validity_and_remove(gns, path); |
769 | if (TRUE == has_parent) | 844 | g_free (path); |
770 | { | ||
771 | /* this is a single record */ | ||
772 | gtk_tree_model_get(tm, &parent, TREE_COL_NAME, &name, -1); | ||
773 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting single record for name `%s'\n", name); | ||
774 | rd = build_rd_from_datastore (tm, &it); | ||
775 | rcc= GNUNET_malloc (sizeof (struct Remove_Context)); | ||
776 | rcc->gns = gns; | ||
777 | rcc->tm = tm; | ||
778 | rcc->path = gtk_tree_model_get_string_from_iter (tm, &it); | ||
779 | GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name,(const struct GNUNET_NAMESTORE_RecordData *) rd, &remove_proc, rcc); | ||
780 | GNUNET_free (rd); | ||
781 | |||
782 | } | ||
783 | else | ||
784 | { | ||
785 | /* this is a whole name */ | ||
786 | gtk_tree_model_get(tm, &it, TREE_COL_NAME, &name, -1); | ||
787 | children = gtk_tree_model_iter_n_children (tm, &it); | ||
788 | //path = gtk_tree_model_get_string_from_iter(tm, &it); | ||
789 | path = gtk_tree_model_get_string_from_iter (tm, &it); | ||
790 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting name `%s' with %u children\n", name, children); | ||
791 | gtk_tree_model_iter_children (tm, &child, &it); | ||
792 | for (c = 0; c < children; c++) | ||
793 | { | ||
794 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting %u record for name `%s'\n", c, name); | ||
795 | |||
796 | rd = build_rd_from_datastore (tm, &child); | ||
797 | rcc= GNUNET_malloc (sizeof (struct Remove_Context)); | ||
798 | rcc->gns = gns; | ||
799 | rcc->tm = tm; | ||
800 | rcc->path = gtk_tree_model_get_string_from_iter (tm, &child); | ||
801 | GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name,(const struct GNUNET_NAMESTORE_RecordData *) rd, &remove_proc, rcc); | ||
802 | gtk_tree_model_iter_next (tm, &child); | ||
803 | } | ||
804 | gtk_tree_model_get_iter_from_string(tm, &it, path); | ||
805 | gtk_tree_store_remove (gns->ts, &it); | ||
806 | } | ||
807 | } | 845 | } |
808 | 846 | ||
809 | void zone_iteration_proc (void *cls, | 847 | void zone_iteration_proc (void *cls, |