diff options
Diffstat (limited to 'src/plugins/fs/download.c')
-rw-r--r-- | src/plugins/fs/download.c | 117 |
1 files changed, 69 insertions, 48 deletions
diff --git a/src/plugins/fs/download.c b/src/plugins/fs/download.c index 229fdfe8..e3db84f8 100644 --- a/src/plugins/fs/download.c +++ b/src/plugins/fs/download.c | |||
@@ -102,7 +102,8 @@ refreshDirectoryViewFromDisk (DownloadList * list) | |||
102 | if (S_ISDIR (buf.st_mode)) | 102 | if (S_ISDIR (buf.st_mode)) |
103 | { | 103 | { |
104 | fn = | 104 | fn = |
105 | GNUNET_malloc (strlen (list->filename) + strlen (GNUNET_DIRECTORY_EXT) + 1); | 105 | GNUNET_malloc (strlen (list->filename) + |
106 | strlen (GNUNET_DIRECTORY_EXT) + 1); | ||
106 | strcpy (fn, list->filename); | 107 | strcpy (fn, list->filename); |
107 | if (fn[strlen (fn) - 1] == '/') | 108 | if (fn[strlen (fn) - 1] == '/') |
108 | fn[strlen (fn) - 1] = '\0'; | 109 | fn[strlen (fn) - 1] = '\0'; |
@@ -134,14 +135,17 @@ refreshDirectoryViewFromDisk (DownloadList * list) | |||
134 | data = MMAP (NULL, size, PROT_READ, MAP_SHARED, fd, 0); | 135 | data = MMAP (NULL, size, PROT_READ, MAP_SHARED, fd, 0); |
135 | if ((data == MAP_FAILED) || (data == NULL)) | 136 | if ((data == MAP_FAILED) || (data == NULL)) |
136 | { | 137 | { |
137 | GNUNET_GELOG_STRERROR_FILE (ectx, GNUNET_GEERROR | GNUNET_GEADMIN | GNUNET_GEBULK, "mmap", f); | 138 | GNUNET_GELOG_STRERROR_FILE (ectx, |
139 | GNUNET_GEERROR | GNUNET_GEADMIN | | ||
140 | GNUNET_GEBULK, "mmap", f); | ||
138 | CLOSE (fd); | 141 | CLOSE (fd); |
139 | GNUNET_free_non_null (fn); | 142 | GNUNET_free_non_null (fn); |
140 | return; | 143 | return; |
141 | } | 144 | } |
142 | GNUNET_free_non_null (fn); | 145 | GNUNET_free_non_null (fn); |
143 | meta = NULL; | 146 | meta = NULL; |
144 | GNUNET_ECRS_directory_list_contents (ectx, data, size, &meta, &addFilesToDirectory, list); | 147 | GNUNET_ECRS_directory_list_contents (ectx, data, size, &meta, |
148 | &addFilesToDirectory, list); | ||
145 | MUNMAP (data, size); | 149 | MUNMAP (data, size); |
146 | CLOSE (fd); | 150 | CLOSE (fd); |
147 | if (meta != NULL) | 151 | if (meta != NULL) |
@@ -242,9 +246,9 @@ fs_download_started (struct GNUNET_FSUI_DownloadList *fsui_dl, | |||
242 | solution is to #ifndef it */ | 246 | solution is to #ifndef it */ |
243 | #ifndef MINGW | 247 | #ifndef MINGW |
244 | GNUNET_GEBREAK (ectx, | 248 | GNUNET_GEBREAK (ectx, |
245 | gtk_tree_row_reference_get_model (dl_parent-> | 249 | gtk_tree_row_reference_get_model (dl_parent-> |
246 | searchViewRowReference) | 250 | searchViewRowReference) |
247 | == model); | 251 | == model); |
248 | #endif | 252 | #endif |
249 | path = | 253 | path = |
250 | gtk_tree_row_reference_get_path (dl_parent-> | 254 | gtk_tree_row_reference_get_path (dl_parent-> |
@@ -284,8 +288,8 @@ fs_download_started (struct GNUNET_FSUI_DownloadList *fsui_dl, | |||
284 | gtk_tree_store_set (sl_parent->tree, | 288 | gtk_tree_store_set (sl_parent->tree, |
285 | &iter, | 289 | &iter, |
286 | SEARCH_CELL_BG_COLOR, | 290 | SEARCH_CELL_BG_COLOR, |
287 | getColorCode (GNUNET_URITRACK_DOWNLOAD_STARTED), | 291 | getColorCode |
288 | -1); | 292 | (GNUNET_URITRACK_DOWNLOAD_STARTED), -1); |
289 | break; | 293 | break; |
290 | } | 294 | } |
291 | valid = gtk_tree_model_iter_next (model, &iter); | 295 | valid = gtk_tree_model_iter_next (model, &iter); |
@@ -301,7 +305,8 @@ fs_download_started (struct GNUNET_FSUI_DownloadList *fsui_dl, | |||
301 | list->fsui_list = fsui_dl; | 305 | list->fsui_list = fsui_dl; |
302 | list->total = total; | 306 | list->total = total; |
303 | list->is_directory = GNUNET_ECRS_meta_data_test_for_directory (fi->meta); | 307 | list->is_directory = GNUNET_ECRS_meta_data_test_for_directory (fi->meta); |
304 | list->has_terminated = ((state != GNUNET_FSUI_ACTIVE) && (state != GNUNET_FSUI_PENDING)); | 308 | list->has_terminated = ((state != GNUNET_FSUI_ACTIVE) |
309 | && (state != GNUNET_FSUI_PENDING)); | ||
305 | list->next = download_head; | 310 | list->next = download_head; |
306 | download_head = list; | 311 | download_head = list; |
307 | if ((list->is_directory == GNUNET_YES) && (completed != 0)) | 312 | if ((list->is_directory == GNUNET_YES) && (completed != 0)) |
@@ -342,7 +347,8 @@ fs_download_update (DownloadList * list, | |||
342 | { | 347 | { |
343 | meta = NULL; | 348 | meta = NULL; |
344 | GNUNET_ECRS_directory_list_contents (ectx, | 349 | GNUNET_ECRS_directory_list_contents (ectx, |
345 | data, size, &meta, &addFilesToDirectory, list); | 350 | data, size, &meta, |
351 | &addFilesToDirectory, list); | ||
346 | if (meta != NULL) | 352 | if (meta != NULL) |
347 | GNUNET_ECRS_meta_data_destroy (meta); | 353 | GNUNET_ECRS_meta_data_destroy (meta); |
348 | } | 354 | } |
@@ -370,7 +376,8 @@ fs_download_completed (DownloadList * downloadContext) | |||
370 | gtk_tree_store_set (downloadContext->searchList->tree, | 376 | gtk_tree_store_set (downloadContext->searchList->tree, |
371 | &iter, | 377 | &iter, |
372 | SEARCH_CELL_BG_COLOR, | 378 | SEARCH_CELL_BG_COLOR, |
373 | getColorCode (GNUNET_URITRACK_DOWNLOAD_COMPLETED), -1); | 379 | getColorCode (GNUNET_URITRACK_DOWNLOAD_COMPLETED), |
380 | -1); | ||
374 | } | 381 | } |
375 | downloadContext->has_terminated = GNUNET_YES; | 382 | downloadContext->has_terminated = GNUNET_YES; |
376 | refreshDirectoryViewFromDisk (downloadContext); | 383 | refreshDirectoryViewFromDisk (downloadContext); |
@@ -398,7 +405,8 @@ fs_download_aborted (DownloadList * downloadContext) | |||
398 | gtk_tree_store_set (downloadContext->searchList->tree, | 405 | gtk_tree_store_set (downloadContext->searchList->tree, |
399 | &iter, | 406 | &iter, |
400 | SEARCH_CELL_BG_COLOR, | 407 | SEARCH_CELL_BG_COLOR, |
401 | getColorCode (GNUNET_URITRACK_DOWNLOAD_ABORTED), -1); | 408 | getColorCode (GNUNET_URITRACK_DOWNLOAD_ABORTED), |
409 | -1); | ||
402 | } | 410 | } |
403 | downloadContext->has_terminated = GNUNET_YES; | 411 | downloadContext->has_terminated = GNUNET_YES; |
404 | refreshDirectoryViewFromDisk (downloadContext); | 412 | refreshDirectoryViewFromDisk (downloadContext); |
@@ -532,15 +540,15 @@ init_download_helper (void *cls) | |||
532 | SDC *sdc = cls; | 540 | SDC *sdc = cls; |
533 | 541 | ||
534 | GNUNET_FSUI_download_start (ctx, | 542 | GNUNET_FSUI_download_start (ctx, |
535 | sdc->anonymity, | 543 | sdc->anonymity, |
536 | sdc->recursive, | 544 | sdc->recursive, |
537 | sdc->idc_uri, | 545 | sdc->idc_uri, |
538 | sdc->idc_meta, | 546 | sdc->idc_meta, |
539 | sdc->idc_final_download_destination, | 547 | sdc->idc_final_download_destination, |
540 | (sdc->searchContext != | 548 | (sdc->searchContext != |
541 | NULL) ? sdc->searchContext->fsui_list : NULL, | 549 | NULL) ? sdc->searchContext->fsui_list : NULL, |
542 | (sdc->parentContext != | 550 | (sdc->parentContext != |
543 | NULL) ? sdc->parentContext->fsui_list : NULL); | 551 | NULL) ? sdc->parentContext->fsui_list : NULL); |
544 | return NULL; | 552 | return NULL; |
545 | } | 553 | } |
546 | 554 | ||
@@ -579,7 +587,8 @@ initiateDownload (GtkTreeModel * model, | |||
579 | SEARCH_INTERNAL, &sdc.searchContext, | 587 | SEARCH_INTERNAL, &sdc.searchContext, |
580 | SEARCH_INTERNAL_PARENT, &sdc.parentContext, -1); | 588 | SEARCH_INTERNAL_PARENT, &sdc.parentContext, -1); |
581 | if ((sdc.idc_uri == NULL) || | 589 | if ((sdc.idc_uri == NULL) || |
582 | (!(GNUNET_ECRS_uri_test_chk (sdc.idc_uri) || GNUNET_ECRS_uri_test_loc (sdc.idc_uri)))) | 590 | (!(GNUNET_ECRS_uri_test_chk (sdc.idc_uri) |
591 | || GNUNET_ECRS_uri_test_loc (sdc.idc_uri)))) | ||
583 | { | 592 | { |
584 | GNUNET_GEBREAK (ectx, 0); | 593 | GNUNET_GEBREAK (ectx, 0); |
585 | GNUNET_free_non_null (idc_name); | 594 | GNUNET_free_non_null (idc_name); |
@@ -612,25 +621,27 @@ initiateDownload (GtkTreeModel * model, | |||
612 | char *filehash; | 621 | char *filehash; |
613 | 622 | ||
614 | GNUNET_GEASSERT (NULL, | 623 | GNUNET_GEASSERT (NULL, |
615 | strlen (sdc.uri_name) > | 624 | strlen (sdc.uri_name) > |
616 | strlen (GNUNET_ECRS_URI_PREFIX) + strlen (GNUNET_ECRS_FILE_INFIX)); | 625 | strlen (GNUNET_ECRS_URI_PREFIX) + |
626 | strlen (GNUNET_ECRS_FILE_INFIX)); | ||
617 | GNUNET_free_non_null (idc_name); | 627 | GNUNET_free_non_null (idc_name); |
618 | filehash = | 628 | filehash = |
619 | GNUNET_strdup (&sdc. | 629 | GNUNET_strdup (&sdc. |
620 | uri_name[strlen (GNUNET_ECRS_URI_PREFIX) + | 630 | uri_name[strlen (GNUNET_ECRS_URI_PREFIX) + |
621 | strlen (GNUNET_ECRS_FILE_INFIX)]); | 631 | strlen (GNUNET_ECRS_FILE_INFIX)]); |
622 | filehash[16] = 0; | 632 | filehash[16] = 0; |
623 | idc_name = GNUNET_strdup (filehash); | 633 | idc_name = GNUNET_strdup (filehash); |
624 | GNUNET_free_non_null (filehash); | 634 | GNUNET_free_non_null (filehash); |
625 | #else | 635 | #else |
626 | GNUNET_GEASSERT (NULL, | 636 | GNUNET_GEASSERT (NULL, |
627 | strlen (sdc.uri_name) > | 637 | strlen (sdc.uri_name) > |
628 | strlen (GNUNET_ECRS_URI_PREFIX) + strlen (GNUNET_ECRS_FILE_INFIX)); | 638 | strlen (GNUNET_ECRS_URI_PREFIX) + |
639 | strlen (GNUNET_ECRS_FILE_INFIX)); | ||
629 | GNUNET_free_non_null (idc_name); | 640 | GNUNET_free_non_null (idc_name); |
630 | idc_name = | 641 | idc_name = |
631 | GNUNET_strdup (&sdc. | 642 | GNUNET_strdup (&sdc. |
632 | uri_name[strlen (GNUNET_ECRS_URI_PREFIX) + | 643 | uri_name[strlen (GNUNET_ECRS_URI_PREFIX) + |
633 | strlen (GNUNET_ECRS_FILE_INFIX)]); | 644 | strlen (GNUNET_ECRS_FILE_INFIX)]); |
634 | #endif | 645 | #endif |
635 | } | 646 | } |
636 | 647 | ||
@@ -655,10 +666,10 @@ initiateDownload (GtkTreeModel * model, | |||
655 | cname = NULL; | 666 | cname = NULL; |
656 | 667 | ||
657 | GNUNET_GC_get_configuration_value_filename (cfg, | 668 | GNUNET_GC_get_configuration_value_filename (cfg, |
658 | "FS", | 669 | "FS", |
659 | "INCOMINGDIR", | 670 | "INCOMINGDIR", |
660 | "$HOME/gnunet-downloads/", | 671 | "$HOME/gnunet-downloads/", |
661 | &final_download_dir); | 672 | &final_download_dir); |
662 | if (strlen (dname) > 0) | 673 | if (strlen (dname) > 0) |
663 | { | 674 | { |
664 | tmp = GNUNET_malloc (strlen (final_download_dir) + strlen (dname) + 2); | 675 | tmp = GNUNET_malloc (strlen (final_download_dir) + strlen (dname) + 2); |
@@ -705,7 +716,7 @@ initiateDownload (GtkTreeModel * model, | |||
705 | /* construct completed/directory/real-filename */ | 716 | /* construct completed/directory/real-filename */ |
706 | sdc.idc_final_download_destination = | 717 | sdc.idc_final_download_destination = |
707 | GNUNET_malloc (strlen (final_download_dir) + 2 + strlen (idc_name) + | 718 | GNUNET_malloc (strlen (final_download_dir) + 2 + strlen (idc_name) + |
708 | strlen (GNUNET_DIRECTORY_EXT) + strlen (dirPath)); | 719 | strlen (GNUNET_DIRECTORY_EXT) + strlen (dirPath)); |
709 | strcpy (sdc.idc_final_download_destination, final_download_dir); | 720 | strcpy (sdc.idc_final_download_destination, final_download_dir); |
710 | if (sdc. | 721 | if (sdc. |
711 | idc_final_download_destination[strlen | 722 | idc_final_download_destination[strlen |
@@ -725,7 +736,8 @@ initiateDownload (GtkTreeModel * model, | |||
725 | } | 736 | } |
726 | else | 737 | else |
727 | { | 738 | { |
728 | GNUNET_GTK_add_log_entry (_("ERROR: already downloading `%s'"), idc_name); | 739 | GNUNET_GTK_add_log_entry (_("ERROR: already downloading `%s'"), |
740 | idc_name); | ||
729 | } | 741 | } |
730 | GNUNET_free (sdc.uri_name); | 742 | GNUNET_free (sdc.uri_name); |
731 | GNUNET_free (dirPath); | 743 | GNUNET_free (dirPath); |
@@ -746,7 +758,8 @@ on_downloadButton_clicked_fs (GtkWidget * treeview, | |||
746 | GtkTreeSelection *selection; | 758 | GtkTreeSelection *selection; |
747 | 759 | ||
748 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); | 760 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); |
749 | GNUNET_GTK_tree_selection_selected_foreach (selection, &initiateDownload, NULL); | 761 | GNUNET_GTK_tree_selection_selected_foreach (selection, &initiateDownload, |
762 | NULL); | ||
750 | } | 763 | } |
751 | 764 | ||
752 | 765 | ||
@@ -782,7 +795,7 @@ on_statusDownloadURIEntry_editing_done_fs (GtkWidget * entry, | |||
782 | if (GNUNET_ECRS_uri_test_ksk (sdc.idc_uri)) | 795 | if (GNUNET_ECRS_uri_test_ksk (sdc.idc_uri)) |
783 | { | 796 | { |
784 | GNUNET_GTK_add_log_entry (_ | 797 | GNUNET_GTK_add_log_entry (_ |
785 | ("Please use the search function for keyword (KSK) URIs!")); | 798 | ("Please use the search function for keyword (KSK) URIs!")); |
786 | GNUNET_free (urid); | 799 | GNUNET_free (urid); |
787 | GNUNET_ECRS_uri_destroy (sdc.idc_uri); | 800 | GNUNET_ECRS_uri_destroy (sdc.idc_uri); |
788 | return; | 801 | return; |
@@ -795,12 +808,13 @@ on_statusDownloadURIEntry_editing_done_fs (GtkWidget * entry, | |||
795 | return; | 808 | return; |
796 | } | 809 | } |
797 | GNUNET_GC_get_configuration_value_filename (cfg, | 810 | GNUNET_GC_get_configuration_value_filename (cfg, |
798 | "FS", | 811 | "FS", |
799 | "INCOMINGDIR", | 812 | "INCOMINGDIR", |
800 | "$HOME/gnunet-downloads/", | 813 | "$HOME/gnunet-downloads/", |
801 | &final_download_dir); | 814 | &final_download_dir); |
802 | GNUNET_disk_directory_create (ectx, final_download_dir); | 815 | GNUNET_disk_directory_create (ectx, final_download_dir); |
803 | dname = &uris[strlen (GNUNET_ECRS_URI_PREFIX) + strlen (GNUNET_ECRS_FILE_INFIX)]; | 816 | dname = |
817 | &uris[strlen (GNUNET_ECRS_URI_PREFIX) + strlen (GNUNET_ECRS_FILE_INFIX)]; | ||
804 | sdc.idc_final_download_destination = | 818 | sdc.idc_final_download_destination = |
805 | GNUNET_malloc (strlen (final_download_dir) + strlen (dname) + 2); | 819 | GNUNET_malloc (strlen (final_download_dir) + strlen (dname) + 2); |
806 | strcpy (sdc.idc_final_download_destination, final_download_dir); | 820 | strcpy (sdc.idc_final_download_destination, final_download_dir); |
@@ -814,7 +828,9 @@ on_statusDownloadURIEntry_editing_done_fs (GtkWidget * entry, | |||
814 | 828 | ||
815 | GNUNET_GTK_add_log_entry (_("Downloading `%s'\n"), uris); | 829 | GNUNET_GTK_add_log_entry (_("Downloading `%s'\n"), uris); |
816 | sdc.idc_meta = GNUNET_ECRS_meta_data_create (); | 830 | sdc.idc_meta = GNUNET_ECRS_meta_data_create (); |
817 | sdc.anonymity = getSpinButtonValue (GNUNET_GTK_get_main_glade_XML (), "fsstatusAnonymitySpin"); | 831 | sdc.anonymity = |
832 | getSpinButtonValue (GNUNET_GTK_get_main_glade_XML (), | ||
833 | "fsstatusAnonymitySpin"); | ||
818 | sdc.recursive = GNUNET_NO; | 834 | sdc.recursive = GNUNET_NO; |
819 | sdc.searchContext = NULL; | 835 | sdc.searchContext = NULL; |
820 | sdc.parentContext = NULL; | 836 | sdc.parentContext = NULL; |
@@ -826,7 +842,8 @@ on_statusDownloadURIEntry_editing_done_fs (GtkWidget * entry, | |||
826 | 842 | ||
827 | struct FCBC | 843 | struct FCBC |
828 | { | 844 | { |
829 | int (*method) (struct GNUNET_FSUI_Context * ctx, struct GNUNET_FSUI_DownloadList * list); | 845 | int (*method) (struct GNUNET_FSUI_Context * ctx, |
846 | struct GNUNET_FSUI_DownloadList * list); | ||
830 | struct GNUNET_FSUI_DownloadList *argument; | 847 | struct GNUNET_FSUI_DownloadList *argument; |
831 | }; | 848 | }; |
832 | 849 | ||
@@ -862,7 +879,7 @@ on_clearCompletedDownloadsButton_clicked_fs (void *unused, | |||
862 | GtkWidget * clearButton) | 879 | GtkWidget * clearButton) |
863 | { | 880 | { |
864 | GNUNET_GTK_tree_model_foreach (GTK_TREE_MODEL (download_summary), | 881 | GNUNET_GTK_tree_model_foreach (GTK_TREE_MODEL (download_summary), |
865 | &clearCompletedDownloadCallback, NULL); | 882 | &clearCompletedDownloadCallback, NULL); |
866 | } | 883 | } |
867 | 884 | ||
868 | static void | 885 | static void |
@@ -886,7 +903,9 @@ on_abortDownloadButton_clicked_fs (void *unused, GtkWidget * abortButton) | |||
886 | GtkTreeSelection *selection; | 903 | GtkTreeSelection *selection; |
887 | GtkWidget *downloadList; | 904 | GtkWidget *downloadList; |
888 | 905 | ||
889 | downloadList = glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "activeDownloadsList"); | 906 | downloadList = |
907 | glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), | ||
908 | "activeDownloadsList"); | ||
890 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (downloadList)); | 909 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (downloadList)); |
891 | GNUNET_GTK_tree_selection_selected_foreach | 910 | GNUNET_GTK_tree_selection_selected_foreach |
892 | (selection, &fsuiCallDownloadCallback, &GNUNET_FSUI_download_abort); | 911 | (selection, &fsuiCallDownloadCallback, &GNUNET_FSUI_download_abort); |
@@ -898,7 +917,9 @@ on_stopDownloadButton_clicked_fs (void *unused, GtkWidget * stopButton) | |||
898 | GtkTreeSelection *selection; | 917 | GtkTreeSelection *selection; |
899 | GtkWidget *downloadList; | 918 | GtkWidget *downloadList; |
900 | 919 | ||
901 | downloadList = glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "activeDownloadsList"); | 920 | downloadList = |
921 | glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), | ||
922 | "activeDownloadsList"); | ||
902 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (downloadList)); | 923 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (downloadList)); |
903 | GNUNET_GTK_tree_selection_selected_foreach | 924 | GNUNET_GTK_tree_selection_selected_foreach |
904 | (selection, &fsuiCallDownloadCallback, &GNUNET_FSUI_download_abort); | 925 | (selection, &fsuiCallDownloadCallback, &GNUNET_FSUI_download_abort); |