diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-03-21 16:41:06 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-03-21 16:41:06 +0000 |
commit | 7e0d56b4ae0ada09ab717c0c5345a047bc7c2b48 (patch) | |
tree | e86f7aa469fbb527d1c2453baa1b4a1b953a9db2 | |
parent | 31ab107f5d28cb35801c2a54ac59681f3550e8c3 (diff) | |
download | gnunet-gtk-7e0d56b4ae0ada09ab717c0c5345a047bc7c2b48.tar.gz gnunet-gtk-7e0d56b4ae0ada09ab717c0c5345a047bc7c2b48.zip |
- writing records back implemented
-rw-r--r-- | src/gns/gnunet-gns-gtk_zone.c | 74 |
1 files changed, 65 insertions, 9 deletions
diff --git a/src/gns/gnunet-gns-gtk_zone.c b/src/gns/gnunet-gns-gtk_zone.c index 3a273390..022ae286 100644 --- a/src/gns/gnunet-gns-gtk_zone.c +++ b/src/gns/gnunet-gns-gtk_zone.c | |||
@@ -52,6 +52,45 @@ enum LIST_COLUMNS | |||
52 | TYPE_LIST_TYPENAME | 52 | TYPE_LIST_TYPENAME |
53 | }; | 53 | }; |
54 | 54 | ||
55 | struct UpdateContext | ||
56 | { | ||
57 | struct GNUNET_GNS_Context *gns; | ||
58 | struct GNUNET_NAMESTORE_RecordData *rd; | ||
59 | unsigned int rd_count; | ||
60 | char * name; | ||
61 | }; | ||
62 | |||
63 | void | ||
64 | check_name_validity_and_commit_remove_proc (void *cls, | ||
65 | int32_t success, | ||
66 | const char *emsg) | ||
67 | { | ||
68 | struct UpdateContext * uc = cls; | ||
69 | unsigned int c; | ||
70 | if ((GNUNET_OK == success) || (GNUNET_NO == success)) | ||
71 | { | ||
72 | for (c = 0; c < uc->rd_count; c++) | ||
73 | { | ||
74 | GNUNET_NAMESTORE_record_create(uc->gns->ns, uc->gns->pkey, | ||
75 | uc->name, &uc->rd[c],NULL, NULL); | ||
76 | GNUNET_free ((void *) uc->rd[c].data); | ||
77 | } | ||
78 | GNUNET_free (uc->rd); | ||
79 | GNUNET_free (uc->name); | ||
80 | GNUNET_free (uc); | ||
81 | } | ||
82 | else if (GNUNET_SYSERR == success) | ||
83 | { | ||
84 | for (c = 0; c < uc->rd_count; c++) | ||
85 | GNUNET_free ((void *) uc->rd[c].data); | ||
86 | GNUNET_free (uc->rd); | ||
87 | GNUNET_free (uc->name); | ||
88 | GNUNET_free (uc); | ||
89 | GNUNET_break (0); | ||
90 | } | ||
91 | else | ||
92 | GNUNET_break (0); | ||
93 | } | ||
55 | 94 | ||
56 | void | 95 | void |
57 | check_name_validity_and_commit (struct GNUNET_GNS_Context *gns, gchar *path) | 96 | check_name_validity_and_commit (struct GNUNET_GNS_Context *gns, gchar *path) |
@@ -97,7 +136,7 @@ check_name_validity_and_commit (struct GNUNET_GNS_Context *gns, gchar *path) | |||
97 | TREE_COL_NAME, &name, | 136 | TREE_COL_NAME, &name, |
98 | -1); | 137 | -1); |
99 | 138 | ||
100 | struct GNUNET_NAMESTORE_RecordData rd[children]; | 139 | struct GNUNET_NAMESTORE_RecordData *rd = GNUNET_malloc (children * sizeof (struct GNUNET_NAMESTORE_RecordData)); |
101 | 140 | ||
102 | if (FALSE == gtk_tree_model_iter_children (gns->tm, &it, &parent)) | 141 | if (FALSE == gtk_tree_model_iter_children (gns->tm, &it, &parent)) |
103 | { | 142 | { |
@@ -134,28 +173,47 @@ check_name_validity_and_commit (struct GNUNET_GNS_Context *gns, gchar *path) | |||
134 | if ((n_value_color != NULL) || (NULL == n_value)) | 173 | if ((n_value_color != NULL) || (NULL == n_value)) |
135 | valid = GNUNET_NO; | 174 | valid = GNUNET_NO; |
136 | 175 | ||
137 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Child [%u] is %s\n", c, (GNUNET_NO == valid) ? "INVALID" : "VALID"); | 176 | if (GNUNET_YES == valid) |
138 | 177 | { | |
178 | if (FALSE == n_public) | ||
179 | rd[c].flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_PRIVATE; | ||
180 | else | ||
181 | rd[c].flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_NONE; | ||
182 | rd[c].record_type = n_type; | ||
183 | rd[c].expiration.abs_value = n_exp_time; | ||
184 | rd[c].data_size = strlen (n_value) + 1; | ||
185 | rd[c].data = GNUNET_malloc(rd[c].data_size); | ||
186 | memcpy ((void *) rd[c].data, n_value, rd[c].data_size); | ||
187 | |||
188 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Child [%u] is %s\n", | ||
189 | c, (GNUNET_NO == valid) ? "INVALID" : "VALID"); | ||
190 | } | ||
139 | g_free (n_name); | 191 | g_free (n_name); |
140 | g_free (n_exp_color); | 192 | g_free (n_exp_color); |
141 | g_free (n_exp_str); | 193 | g_free (n_exp_str); |
142 | g_free (n_value); | 194 | g_free (n_value); |
143 | g_free (n_value_color); | 195 | g_free (n_value_color); |
144 | 196 | ||
145 | if ((GNUNET_NO == valid) || (FALSE == gtk_tree_model_iter_next (gns->tm, &it))) | 197 | gtk_tree_model_iter_next (gns->tm, &it); |
146 | break; | ||
147 | } | 198 | } |
148 | 199 | ||
149 | if (GNUNET_NO == valid) | 200 | if (GNUNET_NO == valid) |
150 | { | 201 | { |
151 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Not valid\n"); | 202 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Not valid\n"); |
203 | for (c = 0; c < children; c++) | ||
204 | GNUNET_free_non_null ((void *) rd[c].data); | ||
205 | GNUNET_free_non_null (rd); | ||
152 | } | 206 | } |
153 | else | 207 | else |
154 | { | 208 | { |
155 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Valid %s\n", name); | 209 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Valid %s\n", name); |
156 | /* Remove old entries */ | 210 | /* Remove old entries */ |
157 | GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name, NULL, NULL, NULL); | 211 | struct UpdateContext * uc = GNUNET_malloc (sizeof (struct UpdateContext)); |
158 | /* Create new records */ | 212 | uc->gns = gns; |
213 | uc->rd = rd; | ||
214 | uc->rd_count = children; | ||
215 | uc->name = strdup (name); | ||
216 | GNUNET_NAMESTORE_record_remove(gns->ns, gns->pkey, name, NULL, &check_name_validity_and_commit_remove_proc, uc); | ||
159 | g_free (name); | 217 | g_free (name); |
160 | } | 218 | } |
161 | } | 219 | } |
@@ -489,7 +547,6 @@ void set_exp (struct GNUNET_GNS_Context *gns, char * exp) | |||
489 | { | 547 | { |
490 | GtkTreeIter it; | 548 | GtkTreeIter it; |
491 | GtkTreeIter parent; | 549 | GtkTreeIter parent; |
492 | GtkTreeIter child; | ||
493 | int not_dummy; | 550 | int not_dummy; |
494 | gboolean has_parent; | 551 | gboolean has_parent; |
495 | GtkCellRendererText *renderer; | 552 | GtkCellRendererText *renderer; |
@@ -531,7 +588,6 @@ gboolean | |||
531 | GNUNET_GNS_GTK_main_treeview_popup_menu_exp1d_cb (GtkWidget *widget, | 588 | GNUNET_GNS_GTK_main_treeview_popup_menu_exp1d_cb (GtkWidget *widget, |
532 | gpointer user_data) | 589 | gpointer user_data) |
533 | { | 590 | { |
534 | GNUNET_break(0); | ||
535 | set_exp (user_data, "1 d"); | 591 | set_exp (user_data, "1 d"); |
536 | return TRUE; | 592 | return TRUE; |
537 | } | 593 | } |