aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/fs/namespace.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/fs/namespace.c')
-rw-r--r--src/plugins/fs/namespace.c215
1 files changed, 20 insertions, 195 deletions
diff --git a/src/plugins/fs/namespace.c b/src/plugins/fs/namespace.c
index ac5a9aea..ad04505d 100644
--- a/src/plugins/fs/namespace.c
+++ b/src/plugins/fs/namespace.c
@@ -76,7 +76,7 @@ on_namespaceContentSelectionChanged (gpointer signal, gpointer cls)
76 int ncount; 76 int ncount;
77 GtkTreeSelection *ns; 77 GtkTreeSelection *ns;
78 GtkTreeIter iter; 78 GtkTreeIter iter;
79 char *freq; 79 char *next;
80 int ok; 80 int ok;
81 81
82 count = gtk_tree_selection_count_selected_rows (content_selection); 82 count = gtk_tree_selection_count_selected_rows (content_selection);
@@ -91,12 +91,12 @@ on_namespaceContentSelectionChanged (gpointer signal, gpointer cls)
91 (ncount == 1) && 91 (ncount == 1) &&
92 (TRUE == gtk_tree_selection_get_selected (ns, NULL, &iter))) 92 (TRUE == gtk_tree_selection_get_selected (ns, NULL, &iter)))
93 { 93 {
94 freq = NULL; 94 next = NULL;
95 gtk_tree_model_get (list->model, 95 gtk_tree_model_get (list->model,
96 &iter, IN_NAMESPACE_PUB_DATE_STRING, &freq, -1); 96 &iter, IN_NAMESPACE_NEXT_STRING, &next, -1);
97 if ((freq != NULL) && (0 != strcmp (freq, _("never")))) 97 if ((next != NULL) && (0 != strlen (next)))
98 ok = 1; 98 ok = 1;
99 GNUNET_free_non_null (freq); 99 GNUNET_free_non_null (next);
100 } 100 }
101 gtk_widget_set_sensitive (list->updateButton, ok); 101 gtk_widget_set_sensitive (list->updateButton, ok);
102 list = list->next; 102 list = list->next;
@@ -134,8 +134,6 @@ makeNamespaceFrame (NamespaceList * entry)
134 G_TYPE_STRING, /* mime-type */ 134 G_TYPE_STRING, /* mime-type */
135 G_TYPE_STRING, /* last-ID */ 135 G_TYPE_STRING, /* last-ID */
136 G_TYPE_STRING, /* next-ID */ 136 G_TYPE_STRING, /* next-ID */
137 G_TYPE_STRING, /* pub-freq */
138 G_TYPE_STRING, /* next pub date */
139 G_TYPE_POINTER, /* URI */ 137 G_TYPE_POINTER, /* URI */
140 G_TYPE_POINTER); /* META */ 138 G_TYPE_POINTER); /* META */
141 entry->model = GTK_TREE_MODEL (model); 139 entry->model = GTK_TREE_MODEL (model);
@@ -217,42 +215,6 @@ makeNamespaceFrame (NamespaceList * entry)
217 renderer = gtk_cell_renderer_text_new (); 215 renderer = gtk_cell_renderer_text_new ();
218 col = 216 col =
219 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (resultList), 217 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (resultList),
220 -1,
221 _("Publication Frequency"),
222 renderer, "text",
223 IN_NAMESPACE_PUB_FREQ_STRING,
224 NULL);
225 column = gtk_tree_view_get_column (GTK_TREE_VIEW (resultList), col - 1);
226 gtk_tree_view_column_set_resizable (column, TRUE);
227 gtk_tree_view_column_set_clickable (column, TRUE);
228 gtk_tree_view_column_set_reorderable (column, TRUE);
229 gtk_tree_view_column_set_sort_column_id (column,
230 IN_NAMESPACE_PUB_FREQ_STRING);
231 /*gtk_tree_view_column_set_sort_indicator(column, TRUE); */
232 gtk_tree_view_column_set_resizable (gtk_tree_view_get_column
233 (GTK_TREE_VIEW (resultList), col - 1),
234 TRUE);
235 renderer = gtk_cell_renderer_text_new ();
236 col =
237 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (resultList),
238 -1,
239 _("Next Publication Date"),
240 renderer, "text",
241 IN_NAMESPACE_PUB_DATE_STRING,
242 NULL);
243 column = gtk_tree_view_get_column (GTK_TREE_VIEW (resultList), col - 1);
244 gtk_tree_view_column_set_reorderable (column, TRUE);
245 gtk_tree_view_column_set_resizable (column, TRUE);
246 gtk_tree_view_column_set_clickable (column, TRUE);
247 gtk_tree_view_column_set_sort_column_id (column,
248 IN_NAMESPACE_PUB_DATE_STRING);
249 /*gtk_tree_view_column_set_sort_indicator(column, TRUE); */
250 gtk_tree_view_column_set_resizable (gtk_tree_view_get_column
251 (GTK_TREE_VIEW (resultList), col - 1),
252 TRUE);
253 renderer = gtk_cell_renderer_text_new ();
254 col =
255 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (resultList),
256 -1, _("Last ID"), renderer, 218 -1, _("Last ID"), renderer,
257 "text", 219 "text",
258 IN_NAMESPACE_LAST_STRING, 220 IN_NAMESPACE_LAST_STRING,
@@ -301,10 +263,7 @@ makeNamespaceFrame (NamespaceList * entry)
301static int 263static int
302addNamespaceContentToModel (void *cls, 264addNamespaceContentToModel (void *cls,
303 const GNUNET_ECRS_FileInfo * fi, 265 const GNUNET_ECRS_FileInfo * fi,
304 const GNUNET_HashCode * lastId, 266 const char *lastId, const char *nextId)
305 const GNUNET_HashCode * nextId,
306 GNUNET_Int32Time publicationFrequency,
307 GNUNET_Int32Time nextPublicationTime)
308{ 267{
309 GtkListStore *model = GTK_LIST_STORE (cls); 268 GtkListStore *model = GTK_LIST_STORE (cls);
310 GtkTreeIter iter; 269 GtkTreeIter iter;
@@ -312,10 +271,6 @@ addNamespaceContentToModel (void *cls,
312 char *desc; 271 char *desc;
313 char *mime; 272 char *mime;
314 char *uriString; 273 char *uriString;
315 GNUNET_EncName last;
316 GNUNET_EncName next;
317 char *freq;
318 char *date;
319 unsigned long long size; 274 unsigned long long size;
320 char *size_h; 275 char *size_h;
321 276
@@ -357,21 +312,8 @@ addNamespaceContentToModel (void *cls,
357 else 312 else
358 size = 0; 313 size = 0;
359 uriString = GNUNET_ECRS_uri_to_string (fi->uri); 314 uriString = GNUNET_ECRS_uri_to_string (fi->uri);
360 GNUNET_hash_to_enc (lastId, &last); 315 if (nextId == NULL)
361 if (nextId != NULL) 316 nextId = "";
362 GNUNET_hash_to_enc (nextId, &next);
363 else
364 memset (&next, 0, sizeof (GNUNET_EncName));
365 if (publicationFrequency == GNUNET_ECRS_SBLOCK_UPDATE_SPORADIC)
366 date = GNUNET_strdup (_("unspecified"));
367 else if (publicationFrequency == GNUNET_ECRS_SBLOCK_UPDATE_NONE)
368 date = GNUNET_strdup (_("never"));
369 else
370 date = GNUNET_int32_time_to_string (&nextPublicationTime);
371 if (date[strlen (date) - 1] == '\n')
372 date[strlen (date) - 1] = '\0';
373
374 freq = updateIntervalToString (publicationFrequency);
375 size_h = GNUNET_get_byte_size_as_fancy_string (size); 317 size_h = GNUNET_get_byte_size_as_fancy_string (size);
376 gtk_list_store_append (model, &iter); 318 gtk_list_store_append (model, &iter);
377 gtk_list_store_set (model, 319 gtk_list_store_set (model,
@@ -381,18 +323,14 @@ addNamespaceContentToModel (void *cls,
381 IN_NAMESPACE_HSIZE, size_h, 323 IN_NAMESPACE_HSIZE, size_h,
382 IN_NAMESPACE_DESCRIPTION, desc, 324 IN_NAMESPACE_DESCRIPTION, desc,
383 IN_NAMESPACE_MIMETYPE, mime, 325 IN_NAMESPACE_MIMETYPE, mime,
384 IN_NAMESPACE_LAST_STRING, &last, 326 IN_NAMESPACE_LAST_STRING, &lastId,
385 IN_NAMESPACE_NEXT_STRING, &next, 327 IN_NAMESPACE_NEXT_STRING, &nextId,
386 IN_NAMESPACE_PUB_FREQ_STRING, freq,
387 IN_NAMESPACE_PUB_DATE_STRING, date,
388 IN_NAMESPACE_URI, GNUNET_ECRS_uri_duplicate (fi->uri), 328 IN_NAMESPACE_URI, GNUNET_ECRS_uri_duplicate (fi->uri),
389 IN_NAMESPACE_META, 329 IN_NAMESPACE_META,
390 GNUNET_meta_data_duplicate (fi->meta), -1); 330 GNUNET_meta_data_duplicate (fi->meta), -1);
391 GNUNET_free (size_h); 331 GNUNET_free (size_h);
392 GNUNET_free (filename); 332 GNUNET_free (filename);
393 GNUNET_free (uriString); 333 GNUNET_free (uriString);
394 GNUNET_free (freq);
395 GNUNET_free (date);
396 GNUNET_free (mime); 334 GNUNET_free (mime);
397 GNUNET_free (desc); 335 GNUNET_free (desc);
398 GNUNET_GTK_DEBUG_END (); 336 GNUNET_GTK_DEBUG_END ();
@@ -574,10 +512,8 @@ typedef struct
574 unsigned int anonymityLevel; 512 unsigned int anonymityLevel;
575 char *namespaceName; 513 char *namespaceName;
576 GNUNET_HashCode nsid; 514 GNUNET_HashCode nsid;
577 GNUNET_Int32Time updateInterval; 515 const char *thisId;
578 GNUNET_HashCode *lastId; 516 const char *nextId;
579 GNUNET_HashCode thisId;
580 GNUNET_HashCode *nextId;
581} IUC; 517} IUC;
582 518
583/** 519/**
@@ -607,9 +543,7 @@ addToNamespaceCB (GtkTreeModel * model,
607 resultURI = GNUNET_NS_add_to_namespace (ectx, cfg, cls->anonymityLevel, 1000, /* FIXME: priority */ 543 resultURI = GNUNET_NS_add_to_namespace (ectx, cfg, cls->anonymityLevel, 1000, /* FIXME: priority */
608 GNUNET_get_time () + 2 * GNUNET_CRON_YEARS, /* FIXME: expiration */ 544 GNUNET_get_time () + 2 * GNUNET_CRON_YEARS, /* FIXME: expiration */
609 &cls->nsid, 545 &cls->nsid,
610 cls->updateInterval, 546 cls->thisId, cls->nextId, dst,
611 cls->lastId,
612 &cls->thisId, cls->nextId, dst,
613 meta); 547 meta);
614 if (resultURI != NULL) 548 if (resultURI != NULL)
615 { 549 {
@@ -626,12 +560,7 @@ addToNamespaceCB (GtkTreeModel * model,
626 fi.uri = dst; 560 fi.uri = dst;
627 fi.meta = meta; 561 fi.meta = meta;
628 addNamespaceContentToModel (list->model, 562 addNamespaceContentToModel (list->model,
629 &fi, 563 &fi, cls->thisId, cls->nextId);
630 &cls->thisId,
631 cls->nextId,
632 cls->updateInterval,
633 cls->updateInterval +
634 GNUNET_get_time_int32 (NULL));
635 } 564 }
636 GNUNET_ECRS_uri_destroy (resultURI); 565 GNUNET_ECRS_uri_destroy (resultURI);
637 } 566 }
@@ -665,14 +594,11 @@ void
665on_namespaceInsertButton_clicked_fs (GtkWidget * dummy1, GtkWidget * dummy2) 594on_namespaceInsertButton_clicked_fs (GtkWidget * dummy1, GtkWidget * dummy2)
666{ 595{
667 596
668 const char *identifierName;
669 NamespaceList *list; 597 NamespaceList *list;
670 GtkWidget *nameLine; 598 GtkWidget *nameLine;
671 GtkWidget *page; 599 GtkWidget *page;
672 GtkWidget *notebook; 600 GtkWidget *notebook;
673 GtkWidget *dialog; 601 GtkWidget *dialog;
674 GtkWidget *updateIntervalComboBox;
675 GNUNET_HashCode nextId;
676 IUC cls; 602 IUC cls;
677 gint num; 603 gint num;
678 604
@@ -699,53 +625,15 @@ on_namespaceInsertButton_clicked_fs (GtkWidget * dummy1, GtkWidget * dummy2)
699 GNUNET_GTK_connect_glade_with_plugins (metaXML); 625 GNUNET_GTK_connect_glade_with_plugins (metaXML);
700 dialog = glade_xml_get_widget (metaXML, "namespaceInsertDialog"); 626 dialog = glade_xml_get_widget (metaXML, "namespaceInsertDialog");
701 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); 627 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
702
703 updateIntervalComboBox = glade_xml_get_widget (metaXML,
704 "updateIntervalComboBoxEntry");
705 gtk_combo_box_set_active (GTK_COMBO_BOX (updateIntervalComboBox), 0);
706
707
708 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) 628 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
709 { 629 {
710 if (GNUNET_OK != tryParseTimeInterval (metaXML,
711 "updateIntervalComboBoxEntry",
712 &cls.updateInterval))
713 {
714 /* this should be impossible - GNUNET_OK button is
715 deactivated while parse errors are there */
716 gtk_widget_destroy (dialog);
717 UNREF (metaXML);
718 metaXML = NULL;
719 dialog = gtk_message_dialog_new
720 (NULL,
721 GTK_DIALOG_MODAL,
722 GTK_MESSAGE_ERROR,
723 GTK_BUTTONS_CLOSE, _("Failed to parse given time interval!"));
724 gtk_dialog_run (GTK_DIALOG (dialog));
725 gtk_widget_destroy (dialog);
726 return;
727 }
728 cls.anonymityLevel 630 cls.anonymityLevel
729 = getSpinButtonValue (metaXML, "anonymitySpinButton"); 631 = getSpinButtonValue (metaXML, "anonymitySpinButton");
730 nameLine = glade_xml_get_widget (metaXML, 632 nameLine = glade_xml_get_widget (metaXML,
731 "namespaceContentIdentifierEntry"); 633 "namespaceContentIdentifierEntry");
732 identifierName = gtk_entry_get_text (GTK_ENTRY (nameLine)); 634 cls.thisId = gtk_entry_get_text (GTK_ENTRY (nameLine));
733 if (identifierName == NULL)
734 identifierName = "";
735 GNUNET_hash (identifierName, strlen (identifierName), &cls.thisId);
736 cls.lastId = NULL;
737
738 nameLine = glade_xml_get_widget (metaXML, "nextIdentifierEntry"); 635 nameLine = glade_xml_get_widget (metaXML, "nextIdentifierEntry");
739 identifierName = gtk_entry_get_text (GTK_ENTRY (nameLine)); 636 cls.nextId = gtk_entry_get_text (GTK_ENTRY (nameLine));
740 if ((identifierName == NULL) || (strlen (identifierName) == 0))
741 {
742 cls.nextId = NULL;
743 }
744 else
745 {
746 GNUNET_hash (identifierName, strlen (identifierName), &nextId);
747 cls.nextId = &nextId;
748 }
749 GNUNET_GTK_tree_selection_selected_foreach 637 GNUNET_GTK_tree_selection_selected_foreach
750 (content_selection, &addToNamespaceCB, &cls); 638 (content_selection, &addToNamespaceCB, &cls);
751 } 639 }
@@ -764,24 +652,16 @@ on_namespaceUpdateButton_clicked_fs (GtkWidget * dummy1, GtkWidget * dummy2)
764{ 652{
765 NamespaceList *list; 653 NamespaceList *list;
766 GtkTreeIter iter; 654 GtkTreeIter iter;
767 GNUNET_HashCode nextId;
768 GNUNET_HashCode lastId;
769 GtkTreeSelection *selection; 655 GtkTreeSelection *selection;
770 IUC cls; 656 IUC cls;
771 char *last; 657 char *last;
772 char *next; 658 char *next;
773 char *freq;
774 GNUNET_EncName nextnext;
775 GtkWidget *nextEntryLine; 659 GtkWidget *nextEntryLine;
776 GtkWidget *identifierLabel; 660 GtkWidget *identifierLabel;
777 GtkWidget *updateIntervalComboBox;
778 GtkWidget *dialog; 661 GtkWidget *dialog;
779 GtkWidget *mdialog;
780 GtkWidget *notebook; 662 GtkWidget *notebook;
781 GtkWidget *page; 663 GtkWidget *page;
782 GtkTreeModel *model;
783 gint num; 664 gint num;
784 const char *nn_str;
785 665
786 GNUNET_GTK_DEBUG_BEGIN (); 666 GNUNET_GTK_DEBUG_BEGIN ();
787 /* find out which namespace this is about */ 667 /* find out which namespace this is about */
@@ -810,21 +690,12 @@ on_namespaceUpdateButton_clicked_fs (GtkWidget * dummy1, GtkWidget * dummy2)
810 return; 690 return;
811 } 691 }
812 gtk_tree_model_get (list->model, 692 gtk_tree_model_get (list->model,
813 &iter, 693 &iter, IN_NAMESPACE_NEXT_STRING, &next, -1);
814 IN_NAMESPACE_LAST_STRING, &last, 694 if ((last == NULL) || (next == NULL))
815 IN_NAMESPACE_NEXT_STRING, &next,
816 IN_NAMESPACE_PUB_FREQ_STRING, &freq, -1);
817 if ((last == NULL) || (next == NULL) || (freq == NULL))
818 { 695 {
819 GNUNET_GE_BREAK (NULL, 0); 696 GNUNET_GE_BREAK (NULL, 0);
820 return; 697 return;
821 } 698 }
822 if (GNUNET_OK != parseTimeInterval (freq, &cls.updateInterval))
823 {
824 GNUNET_GE_BREAK (ectx, 0);
825 cls.updateInterval = GNUNET_ECRS_SBLOCK_UPDATE_SPORADIC;
826 }
827
828 /* create update dialog */ 699 /* create update dialog */
829 metaXML 700 metaXML
830 = glade_xml_new (GNUNET_GTK_get_glade_filename (), 701 = glade_xml_new (GNUNET_GTK_get_glade_filename (),
@@ -834,60 +705,15 @@ on_namespaceUpdateButton_clicked_fs (GtkWidget * dummy1, GtkWidget * dummy2)
834 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); 705 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
835 identifierLabel = glade_xml_get_widget (metaXML, "identifierLabel"); 706 identifierLabel = glade_xml_get_widget (metaXML, "identifierLabel");
836 gtk_label_set_text (GTK_LABEL (identifierLabel), next); 707 gtk_label_set_text (GTK_LABEL (identifierLabel), next);
837 GNUNET_enc_to_hash (last, &lastId); 708 cls.thisId = next;
838 cls.lastId = &lastId;
839 GNUNET_enc_to_hash (next, &cls.thisId);
840
841 nextEntryLine = glade_xml_get_widget (metaXML, "nextIdentifierEntry"); 709 nextEntryLine = glade_xml_get_widget (metaXML, "nextIdentifierEntry");
842 if ((cls.updateInterval != GNUNET_ECRS_SBLOCK_UPDATE_SPORADIC) &&
843 (GNUNET_OK == GNUNET_NS_compute_next_identifier (NULL,
844 cfg,
845 &cls.nsid,
846 &lastId,
847 &cls.thisId,
848 cls.updateInterval,
849 &nextId)))
850 {
851 GNUNET_hash_to_enc (&nextId, &nextnext);
852 gtk_entry_set_text (GTK_ENTRY (nextEntryLine), (char *) &nextnext);
853 gtk_widget_set_sensitive (nextEntryLine, FALSE);
854 }
855 /* set update interval in dialog to
856 the existing update interval */
857 updateIntervalComboBox = glade_xml_get_widget (metaXML,
858 "namespaceUpdateIntervalComboBoxEntry");
859 model = gtk_combo_box_get_model (GTK_COMBO_BOX (updateIntervalComboBox));
860 gtk_list_store_insert (GTK_LIST_STORE (model), &iter, 0);
861 gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, freq, -1);
862 gtk_combo_box_set_active (GTK_COMBO_BOX (updateIntervalComboBox), 0);
863
864 /* run update dialog */ 710 /* run update dialog */
865 if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK) 711 if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK)
866 goto CLEANUP; 712 goto CLEANUP;
867 gtk_widget_hide (dialog); 713 gtk_widget_hide (dialog);
868 714
869 /* get data from update dialog */ 715 /* get data from update dialog */
870 nn_str = gtk_entry_get_text (GTK_ENTRY (nextEntryLine)); 716 cls.nextId = gtk_entry_get_text (GTK_ENTRY (nextEntryLine));
871 if (nn_str == NULL)
872 nn_str = "";
873 GNUNET_hash (nn_str, strlen (nn_str), &nextId);
874 cls.nextId = &nextId;
875
876 if (GNUNET_OK != tryParseTimeInterval (metaXML,
877 "namespaceUpdateIntervalComboBoxEntry",
878 &cls.updateInterval))
879 {
880 /* This should be impossible since the
881 the GNUNET_OK button is deactivated while parse errors are present */
882 mdialog = gtk_message_dialog_new
883 (NULL,
884 GTK_DIALOG_MODAL,
885 GTK_MESSAGE_ERROR,
886 GTK_BUTTONS_CLOSE, _("Failed to parse given time interval!"));
887 gtk_dialog_run (GTK_DIALOG (mdialog));
888 gtk_widget_destroy (mdialog);
889 goto CLEANUP;
890 }
891 cls.anonymityLevel 717 cls.anonymityLevel
892 = getSpinButtonValue (metaXML, "namespaceUpdateAnonymitySpinButton"); 718 = getSpinButtonValue (metaXML, "namespaceUpdateAnonymitySpinButton");
893 719
@@ -900,7 +726,6 @@ CLEANUP:
900 metaXML = NULL; 726 metaXML = NULL;
901 free (last); 727 free (last);
902 free (next); 728 free (next);
903 free (freq);
904 GNUNET_GTK_DEBUG_END (); 729 GNUNET_GTK_DEBUG_END ();
905} 730}
906 731