aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-09 14:29:34 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-09 14:29:34 +0000
commit8595e122088dd3f3b02d0a1625a5cc403e770f96 (patch)
tree7c37e9c6362bed76fe994e82e1b3b1535d7b6486
parent766c8bc9f71de9549894beabbd61848f15c053d0 (diff)
downloadgnunet-gtk-8595e122088dd3f3b02d0a1625a5cc403e770f96.tar.gz
gnunet-gtk-8595e122088dd3f3b02d0a1625a5cc403e770f96.zip
make namestore API less brittle/sublte to use
-rw-r--r--src/conversation/gnunet-conversation-gtk_contacts.c25
-rw-r--r--src/conversation/gnunet-conversation-gtk_get_label.c13
-rw-r--r--src/conversation/gnunet-conversation-gtk_import.c34
-rw-r--r--src/conversation/gnunet-conversation-gtk_phone.c17
-rw-r--r--src/fs/gnunet-fs-gtk.c26
-rw-r--r--src/namestore/gnunet-namestore-gtk.c82
6 files changed, 167 insertions, 30 deletions
diff --git a/src/conversation/gnunet-conversation-gtk_contacts.c b/src/conversation/gnunet-conversation-gtk_contacts.c
index e9010c7d..302c28ba 100644
--- a/src/conversation/gnunet-conversation-gtk_contacts.c
+++ b/src/conversation/gnunet-conversation-gtk_contacts.c
@@ -172,13 +172,6 @@ display_record (void *cls,
172 gboolean is_public; 172 gboolean is_public;
173 char *value; 173 char *value;
174 174
175 if (NULL == zone_key)
176 {
177 /* disconnect, clear (and possibly freeze) view */
178 gtk_list_store_clear (contacts_liststore);
179 gtk_widget_hide (contacts_treeview);
180 return;
181 }
182 do_display = FALSE; 175 do_display = FALSE;
183 value = NULL; 176 value = NULL;
184 for (i = 0; i < rd_len; i++) 177 for (i = 0; i < rd_len; i++)
@@ -290,6 +283,20 @@ unfreeze_view (void *cls)
290 283
291 284
292/** 285/**
286 * Function called once the monitor has disconnected from the
287 * database.
288 *
289 * @param cls closure
290 */
291static void
292freeze_view (void *cls)
293{
294 gtk_list_store_clear (contacts_liststore);
295 gtk_widget_hide (contacts_treeview);
296}
297
298
299/**
293 * A different zone was selected in the zone toggle bar. Load the 300 * A different zone was selected in the zone toggle bar. Load the
294 * appropriate zone. 301 * appropriate zone.
295 * 302 *
@@ -322,7 +329,10 @@ gnunet_conversation_gtk_contacts_zone_combobox_changed_cb (GtkComboBox *widget,
322 zone_mon = GNUNET_NAMESTORE_zone_monitor_start (GCG_get_configuration (), 329 zone_mon = GNUNET_NAMESTORE_zone_monitor_start (GCG_get_configuration (),
323 temp_zone_pkey, 330 temp_zone_pkey,
324 GNUNET_YES, 331 GNUNET_YES,
332 &freeze_view,
333 NULL,
325 &display_record, 334 &display_record,
335 NULL,
326 &unfreeze_view, 336 &unfreeze_view,
327 NULL); 337 NULL);
328} 338}
@@ -451,4 +461,3 @@ GCG_CONTACTS_shutdown ()
451} 461}
452 462
453/* end of gnunet-conversation-gtk_contacts.c */ 463/* end of gnunet-conversation-gtk_contacts.c */
454
diff --git a/src/conversation/gnunet-conversation-gtk_get_label.c b/src/conversation/gnunet-conversation-gtk_get_label.c
index 949975c0..5bdf83d3 100644
--- a/src/conversation/gnunet-conversation-gtk_get_label.c
+++ b/src/conversation/gnunet-conversation-gtk_get_label.c
@@ -45,6 +45,17 @@ static char *target;
45 45
46 46
47/** 47/**
48 * Called on error communicating with the namestore.
49 */
50static void
51handle_error (void *cls)
52{
53 qe = NULL;
54 GCG_log (_("Error communicating with namestore!\n"));
55}
56
57
58/**
48 * Process a record that was stored in the namestore. 59 * Process a record that was stored in the namestore.
49 * 60 *
50 * @param cls closure, NULL 61 * @param cls closure, NULL
@@ -123,6 +134,8 @@ gnunet_conversation_gtk_enter_label_entry_changed_cb (GtkEditable *editable,
123 qe = GNUNET_NAMESTORE_records_lookup (GCG_IMPORT_get_namestore (), 134 qe = GNUNET_NAMESTORE_records_lookup (GCG_IMPORT_get_namestore (),
124 pkey, 135 pkey,
125 label, 136 label,
137 &handle_error,
138 builder,
126 &handle_existing_records, 139 &handle_existing_records,
127 builder); 140 builder);
128} 141}
diff --git a/src/conversation/gnunet-conversation-gtk_import.c b/src/conversation/gnunet-conversation-gtk_import.c
index e8e1eede..199ed9e2 100644
--- a/src/conversation/gnunet-conversation-gtk_import.c
+++ b/src/conversation/gnunet-conversation-gtk_import.c
@@ -251,13 +251,27 @@ add_phone_handle_existing_records (void *cls,
251 add_phone_qe = GNUNET_NAMESTORE_records_store (ns, 251 add_phone_qe = GNUNET_NAMESTORE_records_store (ns,
252 zone, 252 zone,
253 label, 253 label,
254 rd_count + 1, rd_new, 254 rd_count + 1,
255 rd_new,
255 &add_phone_continuation, 256 &add_phone_continuation,
256 NULL); 257 NULL);
257} 258}
258 259
259 260
260/** 261/**
262 * Called on error communicating with the namestore.
263 */
264static void
265handle_add_error (void *cls)
266{
267 add_phone_qe = NULL;
268 GCG_log (_("Error communicating with namestore!\n"));
269 GNUNET_free (phone_label);
270 phone_label = NULL;
271}
272
273
274/**
261 * Add the data from #my_rd under the #phone_label to the namestore. 275 * Add the data from #my_rd under the #phone_label to the namestore.
262 */ 276 */
263static void 277static void
@@ -273,6 +287,8 @@ add_phone ()
273 add_phone_qe = GNUNET_NAMESTORE_records_lookup (ns, 287 add_phone_qe = GNUNET_NAMESTORE_records_lookup (ns,
274 &zone_pkey, 288 &zone_pkey,
275 phone_label, 289 phone_label,
290 &handle_add_error,
291 NULL,
276 &add_phone_handle_existing_records, 292 &add_phone_handle_existing_records,
277 NULL); 293 NULL);
278} 294}
@@ -409,6 +425,19 @@ remove_phone_handle_existing_records (void *cls,
409 425
410 426
411/** 427/**
428 * Called on error communicating with the namestore.
429 */
430static void
431handle_remove_error (void *cls)
432{
433 remove_phone_qe = NULL;
434 GCG_log (_("Error communicating with namestore!\n"));
435 if (GNUNET_YES == in_shutdown)
436 finish_shutdown ();
437}
438
439
440/**
412 * Remove previously added phone address from namestore. 441 * Remove previously added phone address from namestore.
413 */ 442 */
414void 443void
@@ -420,6 +449,8 @@ GSC_remove_phone ()
420 remove_phone_qe = GNUNET_NAMESTORE_records_lookup (ns, 449 remove_phone_qe = GNUNET_NAMESTORE_records_lookup (ns,
421 &zone_pkey, 450 &zone_pkey,
422 phone_label, 451 phone_label,
452 &handle_remove_error,
453 NULL,
423 &remove_phone_handle_existing_records, 454 &remove_phone_handle_existing_records,
424 NULL); 455 NULL);
425 GNUNET_free (phone_label); 456 GNUNET_free (phone_label);
@@ -492,4 +523,3 @@ GCG_IMPORT_shutdown ()
492 523
493 524
494/* end of gnunet-conversation-gtk_import.c */ 525/* end of gnunet-conversation-gtk_import.c */
495
diff --git a/src/conversation/gnunet-conversation-gtk_phone.c b/src/conversation/gnunet-conversation-gtk_phone.c
index 7291fbf7..b6844a84 100644
--- a/src/conversation/gnunet-conversation-gtk_phone.c
+++ b/src/conversation/gnunet-conversation-gtk_phone.c
@@ -876,14 +876,25 @@ handle_reverse_lookup_result (void *cls,
876 struct IncomingCall *ic = cls; 876 struct IncomingCall *ic = cls;
877 877
878 ic->qe = NULL; 878 ic->qe = NULL;
879 if (NULL == label)
880 return;
881 GNUNET_free (ic->caller_id_str); 879 GNUNET_free (ic->caller_id_str);
882 ic->caller_id_str = GNUNET_strdup (label); 880 ic->caller_id_str = GNUNET_strdup (label);
883} 881}
884 882
885 883
886/** 884/**
885 * Failed to talk to namestore.
886 */
887static void
888handle_reverse_error (void *cls)
889{
890 struct IncomingCall *ic = cls;
891
892 ic->qe = NULL;
893 GCG_log (_("Error communicating with namestore!\n"));
894}
895
896
897/**
887 * Function called with an event emitted by a phone. 898 * Function called with an event emitted by a phone.
888 * 899 *
889 * @param cls closure 900 * @param cls closure
@@ -917,6 +928,8 @@ phone_event_handler (void *cls,
917 ic->qe = GNUNET_NAMESTORE_zone_to_name (GCG_IMPORT_get_namestore (), 928 ic->qe = GNUNET_NAMESTORE_zone_to_name (GCG_IMPORT_get_namestore (),
918 GNUNET_IDENTITY_ego_get_private_key (my_zone), 929 GNUNET_IDENTITY_ego_get_private_key (my_zone),
919 &ic->caller_id, 930 &ic->caller_id,
931 &handle_reverse_error,
932 ic,
920 &handle_reverse_lookup_result, 933 &handle_reverse_lookup_result,
921 ic); 934 ic);
922 ic->caller_num = caller_num_gen++; 935 ic->caller_num = caller_num_gen++;
diff --git a/src/fs/gnunet-fs-gtk.c b/src/fs/gnunet-fs-gtk.c
index c00a764f..cbbc1984 100644
--- a/src/fs/gnunet-fs-gtk.c
+++ b/src/fs/gnunet-fs-gtk.c
@@ -562,6 +562,24 @@ service_status_change (void *cls,
562} 562}
563 563
564 564
565static void
566monitor_zone_error (void *cls)
567{
568 GtkListStore *ls;
569
570 ls = GTK_LIST_STORE (GNUNET_FS_GTK_get_main_window_object ("namespace_label_liststore"));
571 gtk_list_store_clear (ls);
572 gtk_widget_hide (GTK_WIDGET (GNUNET_FS_GTK_get_main_window_object ("main_window_search_namespace_combobox")));
573}
574
575
576static void
577monitor_zone_sync (void *cls)
578{
579 gtk_widget_show (GTK_WIDGET (GNUNET_FS_GTK_get_main_window_object ("main_window_search_namespace_combobox")));
580}
581
582
565/** 583/**
566 * Process a record that was stored in the namestore in the 584 * Process a record that was stored in the namestore in the
567 * "sks_zone". Adds (or removes) the respective label to the 585 * "sks_zone". Adds (or removes) the respective label to the
@@ -588,11 +606,6 @@ monitor_zone_records (void *cls,
588 gchar *label_gnu; 606 gchar *label_gnu;
589 607
590 ls = GTK_LIST_STORE (GNUNET_FS_GTK_get_main_window_object ("namespace_label_liststore")); 608 ls = GTK_LIST_STORE (GNUNET_FS_GTK_get_main_window_object ("namespace_label_liststore"));
591 if (NULL == zone)
592 {
593 gtk_list_store_clear (ls);
594 return;
595 }
596 label_gnu = g_strdup_printf ("%s.%s", 609 label_gnu = g_strdup_printf ("%s.%s",
597 label, 610 label,
598 "gnu"); 611 "gnu");
@@ -660,8 +673,11 @@ handle_sks_zone_identity (void *cls,
660 main_context.zm = GNUNET_NAMESTORE_zone_monitor_start (main_context.cfg, 673 main_context.zm = GNUNET_NAMESTORE_zone_monitor_start (main_context.cfg,
661 main_context.sks_zone, 674 main_context.sks_zone,
662 GNUNET_YES, 675 GNUNET_YES,
676 &monitor_zone_error,
677 NULL,
663 &monitor_zone_records, 678 &monitor_zone_records,
664 NULL, 679 NULL,
680 &monitor_zone_sync,
665 NULL); 681 NULL);
666} 682}
667 683
diff --git a/src/namestore/gnunet-namestore-gtk.c b/src/namestore/gnunet-namestore-gtk.c
index 2258b5bc..60ab84d5 100644
--- a/src/namestore/gnunet-namestore-gtk.c
+++ b/src/namestore/gnunet-namestore-gtk.c
@@ -902,12 +902,6 @@ handle_records_for_merge (void *cls,
902{ 902{
903 struct MoveOperationContext *moc = cls; 903 struct MoveOperationContext *moc = cls;
904 904
905 if (NULL == label)
906 {
907 moc->it = NULL;
908 merge_with_existing_records (moc, 0, NULL);
909 return;
910 }
911 if (0 != strcmp (label, 905 if (0 != strcmp (label,
912 moc->edc->name)) 906 moc->edc->name))
913 { 907 {
@@ -921,6 +915,40 @@ handle_records_for_merge (void *cls,
921 915
922 916
923/** 917/**
918 * Error communicating with database, complain to user.
919 *
920 * @param cls the `struct MoveOperationContext`
921 */
922static void
923handle_records_for_merge_error (void *cls)
924{
925 struct MoveOperationContext *moc = cls;
926 struct GNUNET_GTK_NAMESTORE_PluginEnvironment *edc = moc->edc;
927
928 show_error_message (_("Failed to communicate with database"),
929 _("Check that your peer is configured correctly."));
930 GNUNET_free (moc->data);
931 GNUNET_free (moc);
932 free_edit_dialog_context (edc);
933}
934
935
936/**
937 * Finished zone iteration. Proceed.
938 *
939 * @param cls the `struct MoveOperationContext`
940 */
941static void
942handle_records_for_merge_end (void *cls)
943{
944 struct MoveOperationContext *moc = cls;
945
946 moc->it = NULL;
947 merge_with_existing_records (moc, 0, NULL);
948}
949
950
951/**
924 * The edit dialog completed; update the namestore and the 952 * The edit dialog completed; update the namestore and the
925 * view based on the new values in @a edc. 953 * view based on the new values in @a edc.
926 * 954 *
@@ -1069,8 +1097,12 @@ edit_dialog_continuation (struct GNUNET_GTK_NAMESTORE_PluginEnvironment *edc,
1069 GNUNET_CONTAINER_DLL_insert (moc_head, moc_tail, moc); 1097 GNUNET_CONTAINER_DLL_insert (moc_head, moc_tail, moc);
1070 moc->it = GNUNET_NAMESTORE_zone_iteration_start (namestore, 1098 moc->it = GNUNET_NAMESTORE_zone_iteration_start (namestore,
1071 pk, 1099 pk,
1100 &handle_records_for_merge_error,
1101 moc,
1072 &handle_records_for_merge, 1102 &handle_records_for_merge,
1073 moc); 1103 moc,
1104 &handle_records_for_merge_end,
1105 moc);
1074 /* zone changed, remove record from old zone, add to new zone! */ 1106 /* zone changed, remove record from old zone, add to new zone! */
1075 if (GNUNET_YES == edc->old_record_in_namestore) 1107 if (GNUNET_YES == edc->old_record_in_namestore)
1076 { 1108 {
@@ -2237,6 +2269,33 @@ zone_sync_proc (void *cls)
2237 2269
2238 2270
2239/** 2271/**
2272 * Function called once our model is again inconsistent with
2273 * the current zone. Hides the view.
2274 *
2275 * @param cls NULL
2276 */
2277static void
2278zone_iteration_error (void *cls)
2279{
2280 clear_zone_view ();
2281 gtk_widget_hide (GTK_WIDGET (get_object ("gnunet_namestore_gtk_pseu_hbox")));
2282#if HAVE_QRENCODE_H
2283 setup_qrcode ();
2284 gtk_widget_hide (GTK_WIDGET (get_object ("gnunet_namestore_gtk_qr_image")));
2285 gtk_widget_hide (GTK_WIDGET (get_object ("gnunet_namestore_gtk_qr_saveas_button")));
2286 gtk_widget_hide (GTK_WIDGET (get_object ("gnunet_namestore_gtk_qr_vseparator")));
2287#else
2288 gtk_widget_show (GTK_WIDGET (get_object ("gnunet_namestore_gtk_qr_image")));
2289 gtk_widget_show (GTK_WIDGET (get_object ("gnunet_namestore_gtk_qr_saveas_button")));
2290 gtk_widget_show (GTK_WIDGET (get_object ("gnunet_namestore_gtk_qr_vseparator")));
2291#endif
2292 gtk_widget_show (GTK_WIDGET (get_object ("gnunet_namestore_gtk_status_label")));
2293 gtk_widget_hide (GTK_WIDGET (get_object ("gnunet_namestore_gtk_scrolledwindow")));
2294 gtk_widget_hide (GTK_WIDGET (get_object ("gnunet_namestore_gtk_zone_combobox")));
2295}
2296
2297
2298/**
2240 * Function called for each record in the current zone. Update the 2299 * Function called for each record in the current zone. Update the
2241 * widgets accordingly. 2300 * widgets accordingly.
2242 * 2301 *
@@ -2272,12 +2331,6 @@ zone_iteration_proc (void *cls,
2272 GtkTreeIter sel_iter; 2331 GtkTreeIter sel_iter;
2273 GtkTreePath *sel_path; 2332 GtkTreePath *sel_path;
2274 2333
2275 if ((NULL == zone_key) && (NULL == name))
2276 {
2277 /* disconnect from namestore, clear view */
2278 clear_zone_view ();
2279 return;
2280 }
2281 if ( (GNUNET_SYSERR == GNUNET_DNSPARSER_check_label (name)) && 2334 if ( (GNUNET_SYSERR == GNUNET_DNSPARSER_check_label (name)) &&
2282 (0 != strcmp (name, GNUNET_GNS_MASTERZONE_STR)) ) 2335 (0 != strcmp (name, GNUNET_GNS_MASTERZONE_STR)) )
2283 { 2336 {
@@ -2553,7 +2606,10 @@ load_zone (const char *name,
2553#endif 2606#endif
2554 zmon = GNUNET_NAMESTORE_zone_monitor_start (cfg, pkey, 2607 zmon = GNUNET_NAMESTORE_zone_monitor_start (cfg, pkey,
2555 GNUNET_YES, 2608 GNUNET_YES,
2609 &zone_iteration_error,
2610 NULL,
2556 &zone_iteration_proc, 2611 &zone_iteration_proc,
2612 NULL,
2557 &zone_sync_proc, 2613 &zone_sync_proc,
2558 NULL); 2614 NULL);
2559} 2615}