diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-05-15 15:25:40 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-05-15 15:25:40 +0000 |
commit | f835ef67034791de47aa4bba18275a27952543c3 (patch) | |
tree | adf6472a8e6a927e6e702f04a1b4fa7c14ba5949 /src/fs/fs_download.c | |
parent | 3b30625dd217ffb650584df0f00fe1cbb73e2619 (diff) | |
download | gnunet-f835ef67034791de47aa4bba18275a27952543c3.tar.gz gnunet-f835ef67034791de47aa4bba18275a27952543c3.zip |
-code cleanup
Diffstat (limited to 'src/fs/fs_download.c')
-rw-r--r-- | src/fs/fs_download.c | 197 |
1 files changed, 97 insertions, 100 deletions
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index 38b55ba4d..7c4dccb3c 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c | |||
@@ -38,7 +38,7 @@ is_recursive_download (struct GNUNET_FS_DownloadContext *dc) | |||
38 | { | 38 | { |
39 | return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) && | 39 | return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) && |
40 | ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (dc->meta)) || | 40 | ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (dc->meta)) || |
41 | ((dc->meta == NULL) && | 41 | ((NULL == dc->meta) && |
42 | ((NULL == dc->filename) || | 42 | ((NULL == dc->filename) || |
43 | ((strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && | 43 | ((strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && |
44 | (NULL != | 44 | (NULL != |
@@ -72,7 +72,7 @@ compute_disk_offset (uint64_t fsize, uint64_t off, unsigned int depth) | |||
72 | uint64_t loff; /* where do IBlocks for depth "i" start? */ | 72 | uint64_t loff; /* where do IBlocks for depth "i" start? */ |
73 | unsigned int ioff; /* which IBlock corresponds to "off" at depth "i"? */ | 73 | unsigned int ioff; /* which IBlock corresponds to "off" at depth "i"? */ |
74 | 74 | ||
75 | if (depth == 0) | 75 | if (0 == depth) |
76 | return off; | 76 | return off; |
77 | /* first IBlocks start at the end of file, rounded up | 77 | /* first IBlocks start at the end of file, rounded up |
78 | * to full DBLOCK_SIZE */ | 78 | * to full DBLOCK_SIZE */ |
@@ -108,9 +108,9 @@ GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi, | |||
108 | pi->value.download.dc = dc; | 108 | pi->value.download.dc = dc; |
109 | pi->value.download.cctx = dc->client_info; | 109 | pi->value.download.cctx = dc->client_info; |
110 | pi->value.download.pctx = | 110 | pi->value.download.pctx = |
111 | (dc->parent == NULL) ? NULL : dc->parent->client_info; | 111 | (NULL == dc->parent) ? NULL : dc->parent->client_info; |
112 | pi->value.download.sctx = | 112 | pi->value.download.sctx = |
113 | (dc->search == NULL) ? NULL : dc->search->client_info; | 113 | (NULL == dc->search) ? NULL : dc->search->client_info; |
114 | pi->value.download.uri = dc->uri; | 114 | pi->value.download.uri = dc->uri; |
115 | pi->value.download.filename = dc->filename; | 115 | pi->value.download.filename = dc->filename; |
116 | pi->value.download.size = dc->length; | 116 | pi->value.download.size = dc->length; |
@@ -121,7 +121,7 @@ GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi, | |||
121 | pi->value.download.anonymity = dc->anonymity; | 121 | pi->value.download.anonymity = dc->anonymity; |
122 | pi->value.download.eta = | 122 | pi->value.download.eta = |
123 | GNUNET_TIME_calculate_eta (dc->start_time, dc->completed, dc->length); | 123 | GNUNET_TIME_calculate_eta (dc->start_time, dc->completed, dc->length); |
124 | pi->value.download.is_active = (dc->client == NULL) ? GNUNET_NO : GNUNET_YES; | 124 | pi->value.download.is_active = (NULL == dc->client) ? GNUNET_NO : GNUNET_YES; |
125 | if (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) | 125 | if (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) |
126 | dc->client_info = dc->h->upcb (dc->h->upcb_cls, pi); | 126 | dc->client_info = dc->h->upcb (dc->h->upcb_cls, pi); |
127 | else | 127 | else |
@@ -311,21 +311,21 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc) | |||
311 | ("Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n")); | 311 | ("Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n")); |
312 | return; | 312 | return; |
313 | } | 313 | } |
314 | if (dc->filename != NULL) | 314 | if (NULL != dc->filename) |
315 | { | 315 | { |
316 | h = GNUNET_DISK_file_open (dc->filename, GNUNET_DISK_OPEN_READ, | 316 | h = GNUNET_DISK_file_open (dc->filename, GNUNET_DISK_OPEN_READ, |
317 | GNUNET_DISK_PERM_NONE); | 317 | GNUNET_DISK_PERM_NONE); |
318 | } | 318 | } |
319 | else | 319 | else |
320 | { | 320 | { |
321 | GNUNET_assert (dc->temp_filename != NULL); | 321 | GNUNET_assert (NULL != dc->temp_filename); |
322 | h = GNUNET_DISK_file_open (dc->temp_filename, GNUNET_DISK_OPEN_READ, | 322 | h = GNUNET_DISK_file_open (dc->temp_filename, GNUNET_DISK_OPEN_READ, |
323 | GNUNET_DISK_PERM_NONE); | 323 | GNUNET_DISK_PERM_NONE); |
324 | } | 324 | } |
325 | if (h == NULL) | 325 | if (NULL == h) |
326 | return; /* oops */ | 326 | return; /* oops */ |
327 | data = GNUNET_DISK_file_map (h, &m, GNUNET_DISK_MAP_TYPE_READ, size); | 327 | data = GNUNET_DISK_file_map (h, &m, GNUNET_DISK_MAP_TYPE_READ, size); |
328 | if (data == NULL) | 328 | if (NULL == data) |
329 | { | 329 | { |
330 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 330 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
331 | _("Directory too large for system address space\n")); | 331 | _("Directory too large for system address space\n")); |
@@ -337,7 +337,7 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc) | |||
337 | GNUNET_DISK_file_unmap (m); | 337 | GNUNET_DISK_file_unmap (m); |
338 | } | 338 | } |
339 | GNUNET_DISK_file_close (h); | 339 | GNUNET_DISK_file_close (h); |
340 | if (dc->filename == NULL) | 340 | if (NULL == dc->filename) |
341 | { | 341 | { |
342 | if (0 != UNLINK (dc->temp_filename)) | 342 | if (0 != UNLINK (dc->temp_filename)) |
343 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", | 343 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", |
@@ -365,21 +365,19 @@ check_completed (struct GNUNET_FS_DownloadContext *dc) | |||
365 | struct GNUNET_FS_DownloadContext *pos; | 365 | struct GNUNET_FS_DownloadContext *pos; |
366 | 366 | ||
367 | /* first, check if we need to download children */ | 367 | /* first, check if we need to download children */ |
368 | if ((dc->child_head == NULL) && (is_recursive_download (dc))) | 368 | if ((NULL == dc->child_head) && (is_recursive_download (dc))) |
369 | full_recursive_download (dc); | 369 | full_recursive_download (dc); |
370 | /* then, check if children are done already */ | 370 | /* then, check if children are done already */ |
371 | pos = dc->child_head; | 371 | for (pos = dc->child_head; NULL != pos; pos = pos->next) |
372 | while (pos != NULL) | ||
373 | { | 372 | { |
374 | if ((pos->emsg == NULL) && (pos->completed < pos->length)) | 373 | if ((pos->emsg == NULL) && (pos->completed < pos->length)) |
375 | return; /* not done yet */ | 374 | return; /* not done yet */ |
376 | if ((pos->child_head != NULL) && (pos->has_finished != GNUNET_YES)) | 375 | if ((pos->child_head != NULL) && (pos->has_finished != GNUNET_YES)) |
377 | return; /* not transitively done yet */ | 376 | return; /* not transitively done yet */ |
378 | pos = pos->next; | ||
379 | } | 377 | } |
380 | /* All of our children are done, so mark this download done */ | 378 | /* All of our children are done, so mark this download done */ |
381 | dc->has_finished = GNUNET_YES; | 379 | dc->has_finished = GNUNET_YES; |
382 | if (dc->job_queue != NULL) | 380 | if (NULL != dc->job_queue) |
383 | { | 381 | { |
384 | GNUNET_FS_dequeue_ (dc->job_queue); | 382 | GNUNET_FS_dequeue_ (dc->job_queue); |
385 | dc->job_queue = NULL; | 383 | dc->job_queue = NULL; |
@@ -389,7 +387,7 @@ check_completed (struct GNUNET_FS_DownloadContext *dc) | |||
389 | GNUNET_SCHEDULER_cancel (dc->task); | 387 | GNUNET_SCHEDULER_cancel (dc->task); |
390 | dc->task = GNUNET_SCHEDULER_NO_TASK; | 388 | dc->task = GNUNET_SCHEDULER_NO_TASK; |
391 | } | 389 | } |
392 | if (dc->rfh != NULL) | 390 | if (NULL != dc->rfh) |
393 | { | 391 | { |
394 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (dc->rfh)); | 392 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (dc->rfh)); |
395 | dc->rfh = NULL; | 393 | dc->rfh = NULL; |
@@ -401,7 +399,7 @@ check_completed (struct GNUNET_FS_DownloadContext *dc) | |||
401 | GNUNET_FS_download_make_status_ (&pi, dc); | 399 | GNUNET_FS_download_make_status_ (&pi, dc); |
402 | 400 | ||
403 | /* let parent know */ | 401 | /* let parent know */ |
404 | if (dc->parent != NULL) | 402 | if (NULL != dc->parent) |
405 | check_completed (dc->parent); | 403 | check_completed (dc->parent); |
406 | } | 404 | } |
407 | 405 | ||
@@ -484,7 +482,7 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, | |||
484 | break; | 482 | break; |
485 | } | 483 | } |
486 | /* write block to disk */ | 484 | /* write block to disk */ |
487 | fn = dc->filename != NULL ? dc->filename : dc->temp_filename; | 485 | fn = (NULL != dc->filename) ? dc->filename : dc->temp_filename; |
488 | fh = GNUNET_DISK_file_open (fn, | 486 | fh = GNUNET_DISK_file_open (fn, |
489 | GNUNET_DISK_OPEN_READWRITE | | 487 | GNUNET_DISK_OPEN_READWRITE | |
490 | GNUNET_DISK_OPEN_CREATE | | 488 | GNUNET_DISK_OPEN_CREATE | |
@@ -493,7 +491,7 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, | |||
493 | GNUNET_DISK_PERM_USER_WRITE | | 491 | GNUNET_DISK_PERM_USER_WRITE | |
494 | GNUNET_DISK_PERM_GROUP_READ | | 492 | GNUNET_DISK_PERM_GROUP_READ | |
495 | GNUNET_DISK_PERM_OTHER_READ); | 493 | GNUNET_DISK_PERM_OTHER_READ); |
496 | if (fh == NULL) | 494 | if (NULL == fh) |
497 | { | 495 | { |
498 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn); | 496 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn); |
499 | GNUNET_asprintf (&dc->emsg, _("Failed to open file `%s' for writing"), | 497 | GNUNET_asprintf (&dc->emsg, _("Failed to open file `%s' for writing"), |
@@ -571,7 +569,7 @@ match_full_data (void *cls, const char *plugin_name, | |||
571 | { | 569 | { |
572 | struct GNUNET_FS_DownloadContext *dc = cls; | 570 | struct GNUNET_FS_DownloadContext *dc = cls; |
573 | 571 | ||
574 | if (type != EXTRACTOR_METATYPE_GNUNET_FULL_DATA) | 572 | if (EXTRACTOR_METATYPE_GNUNET_FULL_DATA != type) |
575 | return 0; | 573 | return 0; |
576 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u bytes of FD!\n", | 574 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u bytes of FD!\n", |
577 | (unsigned int) data_len); | 575 | (unsigned int) data_len); |
@@ -600,7 +598,7 @@ propagate_up (struct DownloadRequest *dr) | |||
600 | { | 598 | { |
601 | dr->state = BRS_DOWNLOAD_UP; | 599 | dr->state = BRS_DOWNLOAD_UP; |
602 | dr = dr->parent; | 600 | dr = dr->parent; |
603 | if (dr == NULL) | 601 | if (NULL == dr) |
604 | break; | 602 | break; |
605 | for (i = 0; i < dr->num_children; i++) | 603 | for (i = 0; i < dr->num_children; i++) |
606 | if (dr->children[i]->state != BRS_DOWNLOAD_UP) | 604 | if (dr->children[i]->state != BRS_DOWNLOAD_UP) |
@@ -635,8 +633,8 @@ try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc, | |||
635 | const struct ContentHashKey *chks; | 633 | const struct ContentHashKey *chks; |
636 | int up_done; | 634 | int up_done; |
637 | 635 | ||
638 | GNUNET_assert (dc->rfh != NULL); | 636 | GNUNET_assert (NULL != dc->rfh); |
639 | GNUNET_assert (dr->state == BRS_CHK_SET); | 637 | GNUNET_assert (BRS_CHK_SET == dr->state); |
640 | total = GNUNET_FS_uri_chk_get_file_size (dc->uri); | 638 | total = GNUNET_FS_uri_chk_get_file_size (dc->uri); |
641 | GNUNET_assert (dr->depth < dc->treedepth); | 639 | GNUNET_assert (dr->depth < dc->treedepth); |
642 | len = GNUNET_FS_tree_calculate_block_size (total, dr->offset, dr->depth); | 640 | len = GNUNET_FS_tree_calculate_block_size (total, dr->offset, dr->depth); |
@@ -663,7 +661,7 @@ try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc, | |||
663 | /* hash matches but encrypted block does not, really bad */ | 661 | /* hash matches but encrypted block does not, really bad */ |
664 | dr->state = BRS_ERROR; | 662 | dr->state = BRS_ERROR; |
665 | /* propagate up */ | 663 | /* propagate up */ |
666 | while (dr->parent != NULL) | 664 | while (NULL != dr->parent) |
667 | { | 665 | { |
668 | dr = dr->parent; | 666 | dr = dr->parent; |
669 | dr->state = BRS_ERROR; | 667 | dr->state = BRS_ERROR; |
@@ -682,16 +680,16 @@ try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc, | |||
682 | GNUNET_assert (drc->offset >= dr->offset); | 680 | GNUNET_assert (drc->offset >= dr->offset); |
683 | child_block_size = GNUNET_FS_tree_compute_tree_size (drc->depth); | 681 | child_block_size = GNUNET_FS_tree_compute_tree_size (drc->depth); |
684 | GNUNET_assert (0 == (drc->offset - dr->offset) % child_block_size); | 682 | GNUNET_assert (0 == (drc->offset - dr->offset) % child_block_size); |
685 | if (drc->state == BRS_INIT) | 683 | if (BRS_INIT == drc->state) |
686 | { | 684 | { |
687 | drc->state = BRS_CHK_SET; | 685 | drc->state = BRS_CHK_SET; |
688 | drc->chk = chks[drc->chk_idx]; | 686 | drc->chk = chks[drc->chk_idx]; |
689 | try_top_down_reconstruction (dc, drc); | 687 | try_top_down_reconstruction (dc, drc); |
690 | } | 688 | } |
691 | if (drc->state != BRS_DOWNLOAD_UP) | 689 | if (BRS_DOWNLOAD_UP != drc->state) |
692 | up_done = GNUNET_NO; /* children not all done */ | 690 | up_done = GNUNET_NO; /* children not all done */ |
693 | } | 691 | } |
694 | if (up_done == GNUNET_YES) | 692 | if (GNUNET_YES == up_done) |
695 | propagate_up (dr); /* children all done (or no children...) */ | 693 | propagate_up (dr); /* children all done (or no children...) */ |
696 | } | 694 | } |
697 | 695 | ||
@@ -746,7 +744,7 @@ schedule_block_download (struct GNUNET_FS_DownloadContext *dc, | |||
746 | return; /* already active */ | 744 | return; /* already active */ |
747 | GNUNET_CONTAINER_multihashmap_put (dc->active, &dr->chk.query, dr, | 745 | GNUNET_CONTAINER_multihashmap_put (dc->active, &dr->chk.query, dr, |
748 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 746 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
749 | if (dc->client == NULL) | 747 | if (NULL == dc->client) |
750 | return; /* download not active */ | 748 | return; /* download not active */ |
751 | GNUNET_CONTAINER_DLL_insert (dc->pending_head, dc->pending_tail, dr); | 749 | GNUNET_CONTAINER_DLL_insert (dc->pending_head, dc->pending_tail, dr); |
752 | dr->is_pending = GNUNET_YES; | 750 | dr->is_pending = GNUNET_YES; |
@@ -793,26 +791,26 @@ trigger_recursive_download (void *cls, const char *filename, | |||
793 | if (NULL == uri) | 791 | if (NULL == uri) |
794 | return; /* entry for the directory itself */ | 792 | return; /* entry for the directory itself */ |
795 | cpos = dc->child_head; | 793 | cpos = dc->child_head; |
796 | while (cpos != NULL) | 794 | while (NULL != cpos) |
797 | { | 795 | { |
798 | if ((GNUNET_FS_uri_test_equal (uri, cpos->uri)) || | 796 | if ((GNUNET_FS_uri_test_equal (uri, cpos->uri)) || |
799 | ((filename != NULL) && (0 == strcmp (cpos->filename, filename)))) | 797 | ((NULL != filename) && (0 == strcmp (cpos->filename, filename)))) |
800 | break; | 798 | break; |
801 | cpos = cpos->next; | 799 | cpos = cpos->next; |
802 | } | 800 | } |
803 | if (cpos != NULL) | 801 | if (NULL != cpos) |
804 | return; /* already exists */ | 802 | return; /* already exists */ |
805 | fn = NULL; | 803 | fn = NULL; |
806 | if (NULL == filename) | 804 | if (NULL == filename) |
807 | { | 805 | { |
808 | fn = GNUNET_FS_meta_data_suggest_filename (meta); | 806 | fn = GNUNET_FS_meta_data_suggest_filename (meta); |
809 | if (fn == NULL) | 807 | if (NULL == fn) |
810 | { | 808 | { |
811 | us = GNUNET_FS_uri_to_string (uri); | 809 | us = GNUNET_FS_uri_to_string (uri); |
812 | fn = GNUNET_strdup (&us[strlen (GNUNET_FS_URI_CHK_PREFIX)]); | 810 | fn = GNUNET_strdup (&us[strlen (GNUNET_FS_URI_CHK_PREFIX)]); |
813 | GNUNET_free (us); | 811 | GNUNET_free (us); |
814 | } | 812 | } |
815 | else if (fn[0] == '.') | 813 | else if ('.' == fn[0]) |
816 | { | 814 | { |
817 | ext = fn; | 815 | ext = fn; |
818 | us = GNUNET_FS_uri_to_string (uri); | 816 | us = GNUNET_FS_uri_to_string (uri); |
@@ -837,7 +835,7 @@ trigger_recursive_download (void *cls, const char *filename, | |||
837 | } | 835 | } |
838 | filename = fn; | 836 | filename = fn; |
839 | } | 837 | } |
840 | if (dc->filename == NULL) | 838 | if (NULL == dc->filename) |
841 | { | 839 | { |
842 | full_name = NULL; | 840 | full_name = NULL; |
843 | } | 841 | } |
@@ -849,7 +847,7 @@ trigger_recursive_download (void *cls, const char *filename, | |||
849 | strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT), | 847 | strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT), |
850 | GNUNET_FS_DIRECTORY_EXT))); | 848 | GNUNET_FS_DIRECTORY_EXT))); |
851 | sfn = GNUNET_strdup (filename); | 849 | sfn = GNUNET_strdup (filename); |
852 | while ((strlen (sfn) > 0) && (filename[strlen (sfn) - 1] == '/')) | 850 | while ((strlen (sfn) > 0) && ('/' == filename[strlen (sfn) - 1])) |
853 | sfn[strlen (sfn) - 1] = '\0'; | 851 | sfn[strlen (sfn) - 1] = '\0'; |
854 | if ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && | 852 | if ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && |
855 | (NULL != | 853 | (NULL != |
@@ -872,7 +870,7 @@ trigger_recursive_download (void *cls, const char *filename, | |||
872 | GNUNET_free (sfn); | 870 | GNUNET_free (sfn); |
873 | GNUNET_free (dn); | 871 | GNUNET_free (dn); |
874 | } | 872 | } |
875 | if ((full_name != NULL) && | 873 | if ((NULL != full_name) && |
876 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (full_name))) | 874 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (full_name))) |
877 | { | 875 | { |
878 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 876 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -909,7 +907,7 @@ GNUNET_FS_free_download_request_ (struct DownloadRequest *dr) | |||
909 | { | 907 | { |
910 | unsigned int i; | 908 | unsigned int i; |
911 | 909 | ||
912 | if (dr == NULL) | 910 | if (NULL == dr) |
913 | return; | 911 | return; |
914 | for (i = 0; i < dr->num_children; i++) | 912 | for (i = 0; i < dr->num_children; i++) |
915 | GNUNET_FS_free_download_request_ (dr->children[i]); | 913 | GNUNET_FS_free_download_request_ (dr->children[i]); |
@@ -959,13 +957,13 @@ process_result_with_request (void *cls, const GNUNET_HashCode * key, | |||
959 | { | 957 | { |
960 | GNUNET_asprintf (&dc->emsg, | 958 | GNUNET_asprintf (&dc->emsg, |
961 | _ | 959 | _ |
962 | ("Internal error or bogus download URI (expected %u bytes at depth %u and offset %llu/%llu, got %u bytes)\n"), | 960 | ("Internal error or bogus download URI (expected %u bytes at depth %u and offset %llu/%llu, got %u bytes)"), |
963 | bs, dr->depth, (unsigned long long) dr->offset, | 961 | bs, dr->depth, (unsigned long long) dr->offset, |
964 | (unsigned long long) GNUNET_ntohll (dc->uri->data. | 962 | (unsigned long long) GNUNET_ntohll (dc->uri->data. |
965 | chk.file_length), | 963 | chk.file_length), |
966 | prc->size); | 964 | prc->size); |
967 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s", dc->emsg); | 965 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", dc->emsg); |
968 | while (dr->parent != NULL) | 966 | while (NULL != dr->parent) |
969 | { | 967 | { |
970 | dr->state = BRS_ERROR; | 968 | dr->state = BRS_ERROR; |
971 | dr = dr->parent; | 969 | dr = dr->parent; |
@@ -993,12 +991,12 @@ process_result_with_request (void *cls, const GNUNET_HashCode * key, | |||
993 | dr->offset, dr->depth); | 991 | dr->offset, dr->depth); |
994 | /* save to disk */ | 992 | /* save to disk */ |
995 | if ((GNUNET_YES == prc->do_store) && | 993 | if ((GNUNET_YES == prc->do_store) && |
996 | ((dc->filename != NULL) || (is_recursive_download (dc))) && | 994 | ((NULL != dc->filename) || (is_recursive_download (dc))) && |
997 | ((dr->depth == dc->treedepth) || | 995 | ((dr->depth == dc->treedepth) || |
998 | (0 == (dc->options & GNUNET_FS_DOWNLOAD_NO_TEMPORARIES)))) | 996 | (0 == (dc->options & GNUNET_FS_DOWNLOAD_NO_TEMPORARIES)))) |
999 | { | 997 | { |
1000 | fh = GNUNET_DISK_file_open (dc->filename != | 998 | fh = GNUNET_DISK_file_open (NULL != dc->filename |
1001 | NULL ? dc->filename : dc->temp_filename, | 999 | ? dc->filename : dc->temp_filename, |
1002 | GNUNET_DISK_OPEN_READWRITE | | 1000 | GNUNET_DISK_OPEN_READWRITE | |
1003 | GNUNET_DISK_OPEN_CREATE, | 1001 | GNUNET_DISK_OPEN_CREATE, |
1004 | GNUNET_DISK_PERM_USER_READ | | 1002 | GNUNET_DISK_PERM_USER_READ | |
@@ -1008,7 +1006,7 @@ process_result_with_request (void *cls, const GNUNET_HashCode * key, | |||
1008 | if (NULL == fh) | 1006 | if (NULL == fh) |
1009 | { | 1007 | { |
1010 | GNUNET_asprintf (&dc->emsg, | 1008 | GNUNET_asprintf (&dc->emsg, |
1011 | _("Download failed: could not open file `%s': %s\n"), | 1009 | _("Download failed: could not open file `%s': %s"), |
1012 | dc->filename, STRERROR (errno)); | 1010 | dc->filename, STRERROR (errno)); |
1013 | goto signal_error; | 1011 | goto signal_error; |
1014 | } | 1012 | } |
@@ -1018,7 +1016,7 @@ process_result_with_request (void *cls, const GNUNET_HashCode * key, | |||
1018 | if ((off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET))) | 1016 | if ((off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET))) |
1019 | { | 1017 | { |
1020 | GNUNET_asprintf (&dc->emsg, | 1018 | GNUNET_asprintf (&dc->emsg, |
1021 | _("Failed to seek to offset %llu in file `%s': %s\n"), | 1019 | _("Failed to seek to offset %llu in file `%s': %s"), |
1022 | (unsigned long long) off, dc->filename, | 1020 | (unsigned long long) off, dc->filename, |
1023 | STRERROR (errno)); | 1021 | STRERROR (errno)); |
1024 | goto signal_error; | 1022 | goto signal_error; |
@@ -1027,7 +1025,7 @@ process_result_with_request (void *cls, const GNUNET_HashCode * key, | |||
1027 | { | 1025 | { |
1028 | GNUNET_asprintf (&dc->emsg, | 1026 | GNUNET_asprintf (&dc->emsg, |
1029 | _ | 1027 | _ |
1030 | ("Failed to write block of %u bytes at offset %llu in file `%s': %s\n"), | 1028 | ("Failed to write block of %u bytes at offset %llu in file `%s': %s"), |
1031 | (unsigned int) prc->size, (unsigned long long) off, | 1029 | (unsigned int) prc->size, (unsigned long long) off, |
1032 | dc->filename, STRERROR (errno)); | 1030 | dc->filename, STRERROR (errno)); |
1033 | goto signal_error; | 1031 | goto signal_error; |
@@ -1036,7 +1034,7 @@ process_result_with_request (void *cls, const GNUNET_HashCode * key, | |||
1036 | fh = NULL; | 1034 | fh = NULL; |
1037 | } | 1035 | } |
1038 | 1036 | ||
1039 | if (dr->depth == 0) | 1037 | if (0 == dr->depth) |
1040 | { | 1038 | { |
1041 | /* DBLOCK, update progress and try recursion if applicable */ | 1039 | /* DBLOCK, update progress and try recursion if applicable */ |
1042 | app = prc->size; | 1040 | app = prc->size; |
@@ -1079,7 +1077,7 @@ process_result_with_request (void *cls, const GNUNET_HashCode * key, | |||
1079 | pi.value.download.specifics.progress.block_download_duration | 1077 | pi.value.download.specifics.progress.block_download_duration |
1080 | = GNUNET_TIME_UNIT_ZERO; /* found locally */ | 1078 | = GNUNET_TIME_UNIT_ZERO; /* found locally */ |
1081 | GNUNET_FS_download_make_status_ (&pi, dc); | 1079 | GNUNET_FS_download_make_status_ (&pi, dc); |
1082 | if (dr->depth == 0) | 1080 | if (0 == dr->depth) |
1083 | propagate_up (dr); | 1081 | propagate_up (dr); |
1084 | 1082 | ||
1085 | if (dc->completed == dc->length) | 1083 | if (dc->completed == dc->length) |
@@ -1090,7 +1088,7 @@ process_result_with_request (void *cls, const GNUNET_HashCode * key, | |||
1090 | (unsigned long long) GNUNET_ntohll (dc->uri->data. | 1088 | (unsigned long long) GNUNET_ntohll (dc->uri->data. |
1091 | chk.file_length)); | 1089 | chk.file_length)); |
1092 | /* truncate file to size (since we store IBlocks at the end) */ | 1090 | /* truncate file to size (since we store IBlocks at the end) */ |
1093 | if (dc->filename != NULL) | 1091 | if (NULL != dc->filename) |
1094 | { | 1092 | { |
1095 | if (0 != | 1093 | if (0 != |
1096 | truncate (dc->filename, | 1094 | truncate (dc->filename, |
@@ -1098,10 +1096,10 @@ process_result_with_request (void *cls, const GNUNET_HashCode * key, | |||
1098 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "truncate", | 1096 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "truncate", |
1099 | dc->filename); | 1097 | dc->filename); |
1100 | } | 1098 | } |
1101 | GNUNET_assert (dr->depth == 0); | 1099 | GNUNET_assert (0 == dr->depth); |
1102 | check_completed (dc); | 1100 | check_completed (dc); |
1103 | } | 1101 | } |
1104 | if (dr->depth == 0) | 1102 | if (0 == dr->depth) |
1105 | { | 1103 | { |
1106 | /* bottom of the tree, no child downloads possible, just sync */ | 1104 | /* bottom of the tree, no child downloads possible, just sync */ |
1107 | GNUNET_FS_download_sync_ (dc); | 1105 | GNUNET_FS_download_sync_ (dc); |
@@ -1124,7 +1122,8 @@ process_result_with_request (void *cls, const GNUNET_HashCode * key, | |||
1124 | /* 'chkarr' does not have enough space for this chk_idx; | 1122 | /* 'chkarr' does not have enough space for this chk_idx; |
1125 | internal error! */ | 1123 | internal error! */ |
1126 | GNUNET_break (0); | 1124 | GNUNET_break (0); |
1127 | return GNUNET_SYSERR; | 1125 | dc->emsg = GNUNET_strdup (_("internal error decoding tree")); |
1126 | goto signal_error; | ||
1128 | } | 1127 | } |
1129 | drc->chk = chkarr[drc->chk_idx]; | 1128 | drc->chk = chkarr[drc->chk_idx]; |
1130 | drc->state = BRS_CHK_SET; | 1129 | drc->state = BRS_CHK_SET; |
@@ -1161,7 +1160,7 @@ process_result_with_request (void *cls, const GNUNET_HashCode * key, | |||
1161 | return GNUNET_YES; | 1160 | return GNUNET_YES; |
1162 | 1161 | ||
1163 | signal_error: | 1162 | signal_error: |
1164 | if (fh != NULL) | 1163 | if (NULL != fh) |
1165 | GNUNET_DISK_file_close (fh); | 1164 | GNUNET_DISK_file_close (fh); |
1166 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; | 1165 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; |
1167 | pi.value.download.specifics.error.message = dc->emsg; | 1166 | pi.value.download.specifics.error.message = dc->emsg; |
@@ -1236,7 +1235,7 @@ receive_results (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1236 | if ((NULL == msg) || (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_PUT) || | 1235 | if ((NULL == msg) || (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_PUT) || |
1237 | (sizeof (struct ClientPutMessage) > ntohs (msg->size))) | 1236 | (sizeof (struct ClientPutMessage) > ntohs (msg->size))) |
1238 | { | 1237 | { |
1239 | GNUNET_break (msg == NULL); | 1238 | GNUNET_break (NULL == msg); |
1240 | try_reconnect (dc); | 1239 | try_reconnect (dc); |
1241 | return; | 1240 | return; |
1242 | } | 1241 | } |
@@ -1245,7 +1244,7 @@ receive_results (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1245 | process_result (dc, ntohl (cm->type), | 1244 | process_result (dc, ntohl (cm->type), |
1246 | GNUNET_TIME_absolute_ntoh (cm->last_transmission), &cm[1], | 1245 | GNUNET_TIME_absolute_ntoh (cm->last_transmission), &cm[1], |
1247 | msize - sizeof (struct ClientPutMessage)); | 1246 | msize - sizeof (struct ClientPutMessage)); |
1248 | if (dc->client == NULL) | 1247 | if (NULL == dc->client) |
1249 | return; /* fatal error */ | 1248 | return; /* fatal error */ |
1250 | /* continue receiving */ | 1249 | /* continue receiving */ |
1251 | GNUNET_CLIENT_receive (dc->client, &receive_results, dc, | 1250 | GNUNET_CLIENT_receive (dc->client, &receive_results, dc, |
@@ -1253,7 +1252,6 @@ receive_results (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1253 | } | 1252 | } |
1254 | 1253 | ||
1255 | 1254 | ||
1256 | |||
1257 | /** | 1255 | /** |
1258 | * We're ready to transmit a search request to the | 1256 | * We're ready to transmit a search request to the |
1259 | * file-sharing service. Do it. If there is | 1257 | * file-sharing service. Do it. If there is |
@@ -1297,7 +1295,7 @@ transmit_download_request (void *cls, size_t size, void *buf) | |||
1297 | sm->options = htonl (GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY); | 1295 | sm->options = htonl (GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY); |
1298 | else | 1296 | else |
1299 | sm->options = htonl (GNUNET_FS_SEARCH_OPTION_NONE); | 1297 | sm->options = htonl (GNUNET_FS_SEARCH_OPTION_NONE); |
1300 | if (dr->depth == 0) | 1298 | if (0 == dr->depth) |
1301 | sm->type = htonl (GNUNET_BLOCK_TYPE_FS_DBLOCK); | 1299 | sm->type = htonl (GNUNET_BLOCK_TYPE_FS_DBLOCK); |
1302 | else | 1300 | else |
1303 | sm->type = htonl (GNUNET_BLOCK_TYPE_FS_IBLOCK); | 1301 | sm->type = htonl (GNUNET_BLOCK_TYPE_FS_IBLOCK); |
@@ -1309,7 +1307,7 @@ transmit_download_request (void *cls, size_t size, void *buf) | |||
1309 | msize += sizeof (struct SearchMessage); | 1307 | msize += sizeof (struct SearchMessage); |
1310 | sm++; | 1308 | sm++; |
1311 | } | 1309 | } |
1312 | if (dc->pending_head != NULL) | 1310 | if (NULL != dc->pending_head) |
1313 | { | 1311 | { |
1314 | dc->th = | 1312 | dc->th = |
1315 | GNUNET_CLIENT_notify_transmit_ready (dc->client, | 1313 | GNUNET_CLIENT_notify_transmit_ready (dc->client, |
@@ -1317,7 +1315,7 @@ transmit_download_request (void *cls, size_t size, void *buf) | |||
1317 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, | 1315 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, |
1318 | GNUNET_NO, | 1316 | GNUNET_NO, |
1319 | &transmit_download_request, dc); | 1317 | &transmit_download_request, dc); |
1320 | GNUNET_assert (dc->th != NULL); | 1318 | GNUNET_assert (NULL != dc->th); |
1321 | } | 1319 | } |
1322 | if (GNUNET_NO == dc->in_receive) | 1320 | if (GNUNET_NO == dc->in_receive) |
1323 | { | 1321 | { |
@@ -1351,7 +1349,7 @@ do_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1351 | return; | 1349 | return; |
1352 | } | 1350 | } |
1353 | dc->client = client; | 1351 | dc->client = client; |
1354 | if (dc->pending_head != NULL) | 1352 | if (NULL != dc->pending_head) |
1355 | { | 1353 | { |
1356 | dc->th = | 1354 | dc->th = |
1357 | GNUNET_CLIENT_notify_transmit_ready (client, | 1355 | GNUNET_CLIENT_notify_transmit_ready (client, |
@@ -1359,7 +1357,7 @@ do_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1359 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, | 1357 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, |
1360 | GNUNET_NO, | 1358 | GNUNET_NO, |
1361 | &transmit_download_request, dc); | 1359 | &transmit_download_request, dc); |
1362 | GNUNET_assert (dc->th != NULL); | 1360 | GNUNET_assert (NULL != dc->th); |
1363 | } | 1361 | } |
1364 | } | 1362 | } |
1365 | 1363 | ||
@@ -1435,8 +1433,8 @@ activate_fs_download (void *cls, struct GNUNET_CLIENT_Connection *client) | |||
1435 | 1433 | ||
1436 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download activated\n"); | 1434 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download activated\n"); |
1437 | GNUNET_assert (NULL != client); | 1435 | GNUNET_assert (NULL != client); |
1438 | GNUNET_assert (dc->client == NULL); | 1436 | GNUNET_assert (NULL == dc->client); |
1439 | GNUNET_assert (dc->th == NULL); | 1437 | GNUNET_assert (NULL == dc->th); |
1440 | dc->client = client; | 1438 | dc->client = client; |
1441 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ACTIVE; | 1439 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ACTIVE; |
1442 | GNUNET_FS_download_make_status_ (&pi, dc); | 1440 | GNUNET_FS_download_make_status_ (&pi, dc); |
@@ -1445,7 +1443,7 @@ activate_fs_download (void *cls, struct GNUNET_CLIENT_Connection *client) | |||
1445 | GNUNET_CONTAINER_multihashmap_iterate (dc->active, &retry_entry, dc); | 1443 | GNUNET_CONTAINER_multihashmap_iterate (dc->active, &retry_entry, dc); |
1446 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1447 | "Asking for transmission to FS service\n"); | 1445 | "Asking for transmission to FS service\n"); |
1448 | if (dc->pending_head != NULL) | 1446 | if (NULL != dc->pending_head) |
1449 | { | 1447 | { |
1450 | dc->th = | 1448 | dc->th = |
1451 | GNUNET_CLIENT_notify_transmit_ready (dc->client, | 1449 | GNUNET_CLIENT_notify_transmit_ready (dc->client, |
@@ -1453,7 +1451,7 @@ activate_fs_download (void *cls, struct GNUNET_CLIENT_Connection *client) | |||
1453 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, | 1451 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, |
1454 | GNUNET_NO, | 1452 | GNUNET_NO, |
1455 | &transmit_download_request, dc); | 1453 | &transmit_download_request, dc); |
1456 | GNUNET_assert (dc->th != NULL); | 1454 | GNUNET_assert (NULL != dc->th); |
1457 | } | 1455 | } |
1458 | } | 1456 | } |
1459 | 1457 | ||
@@ -1584,7 +1582,7 @@ reconstruct_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1584 | GNUNET_SCHEDULER_cancel (dc->task); | 1582 | GNUNET_SCHEDULER_cancel (dc->task); |
1585 | dc->task = GNUNET_SCHEDULER_NO_TASK; | 1583 | dc->task = GNUNET_SCHEDULER_NO_TASK; |
1586 | } | 1584 | } |
1587 | if (dc->rfh != NULL) | 1585 | if (NULL != dc->rfh) |
1588 | { | 1586 | { |
1589 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (dc->rfh)); | 1587 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (dc->rfh)); |
1590 | dc->rfh = NULL; | 1588 | dc->rfh = NULL; |
@@ -1613,7 +1611,6 @@ get_next_block (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1613 | } | 1611 | } |
1614 | 1612 | ||
1615 | 1613 | ||
1616 | |||
1617 | /** | 1614 | /** |
1618 | * Function called asking for the current (encoded) | 1615 | * Function called asking for the current (encoded) |
1619 | * block to be processed. After processing the | 1616 | * block to be processed. After processing the |
@@ -1727,7 +1724,7 @@ reconstruct_cb (void *cls, const struct ContentHashKey *chk, uint64_t offset, | |||
1727 | (unsigned long long) GNUNET_ntohll (dc->uri->data. | 1724 | (unsigned long long) GNUNET_ntohll (dc->uri->data. |
1728 | chk.file_length)); | 1725 | chk.file_length)); |
1729 | /* truncate file to size (since we store IBlocks at the end) */ | 1726 | /* truncate file to size (since we store IBlocks at the end) */ |
1730 | if (dc->filename != NULL) | 1727 | if (NULL != dc->filename) |
1731 | { | 1728 | { |
1732 | if (0 != | 1729 | if (0 != |
1733 | truncate (dc->filename, | 1730 | truncate (dc->filename, |
@@ -1814,10 +1811,10 @@ GNUNET_FS_download_start_task_ (void *cls, | |||
1814 | 1811 | ||
1815 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start task running...\n"); | 1812 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start task running...\n"); |
1816 | dc->task = GNUNET_SCHEDULER_NO_TASK; | 1813 | dc->task = GNUNET_SCHEDULER_NO_TASK; |
1817 | if (dc->length == 0) | 1814 | if (0 == dc->length) |
1818 | { | 1815 | { |
1819 | /* no bytes required! */ | 1816 | /* no bytes required! */ |
1820 | if (dc->filename != NULL) | 1817 | if (NULL != dc->filename) |
1821 | { | 1818 | { |
1822 | fh = GNUNET_DISK_file_open (dc->filename, | 1819 | fh = GNUNET_DISK_file_open (dc->filename, |
1823 | GNUNET_DISK_OPEN_READWRITE | | 1820 | GNUNET_DISK_OPEN_READWRITE | |
@@ -1838,13 +1835,13 @@ GNUNET_FS_download_start_task_ (void *cls, | |||
1838 | check_completed (dc); | 1835 | check_completed (dc); |
1839 | return; | 1836 | return; |
1840 | } | 1837 | } |
1841 | if (dc->emsg != NULL) | 1838 | if (NULL != dc->emsg) |
1842 | return; | 1839 | return; |
1843 | if (dc->top_request == NULL) | 1840 | if (NULL == dc->top_request) |
1844 | { | 1841 | { |
1845 | dc->top_request = | 1842 | dc->top_request = |
1846 | create_download_request (NULL, 0, dc->treedepth - 1, 0, dc->offset, | 1843 | create_download_request (NULL, 0, dc->treedepth - 1, 0, dc->offset, |
1847 | dc->length); | 1844 | dc->length); |
1848 | dc->top_request->state = BRS_CHK_SET; | 1845 | dc->top_request->state = BRS_CHK_SET; |
1849 | dc->top_request->chk = | 1846 | dc->top_request->chk = |
1850 | (dc->uri->type == | 1847 | (dc->uri->type == |
@@ -1865,7 +1862,7 @@ GNUNET_FS_download_start_task_ (void *cls, | |||
1865 | GNUNET_DISK_PERM_NONE); | 1862 | GNUNET_DISK_PERM_NONE); |
1866 | if (dc->top_request->state == BRS_CHK_SET) | 1863 | if (dc->top_request->state == BRS_CHK_SET) |
1867 | { | 1864 | { |
1868 | if (dc->rfh != NULL) | 1865 | if (NULL != dc->rfh) |
1869 | { | 1866 | { |
1870 | /* first, try top-down */ | 1867 | /* first, try top-down */ |
1871 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1868 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1879,7 +1876,7 @@ GNUNET_FS_download_start_task_ (void *cls, | |||
1879 | break; /* normal, some blocks already down */ | 1876 | break; /* normal, some blocks already down */ |
1880 | case BRS_DOWNLOAD_UP: | 1877 | case BRS_DOWNLOAD_UP: |
1881 | /* already done entirely, party! */ | 1878 | /* already done entirely, party! */ |
1882 | if (dc->rfh != NULL) | 1879 | if (NULL != dc->rfh) |
1883 | { | 1880 | { |
1884 | /* avoid hanging on to file handle longer than | 1881 | /* avoid hanging on to file handle longer than |
1885 | * necessary */ | 1882 | * necessary */ |
@@ -1910,9 +1907,9 @@ GNUNET_FS_download_start_task_ (void *cls, | |||
1910 | (unsigned int) | 1907 | (unsigned int) |
1911 | GNUNET_CONTAINER_meta_data_get_serialized_size (dc->meta)); | 1908 | GNUNET_CONTAINER_meta_data_get_serialized_size (dc->meta)); |
1912 | GNUNET_CONTAINER_meta_data_iterate (dc->meta, &match_full_data, dc); | 1909 | GNUNET_CONTAINER_meta_data_iterate (dc->meta, &match_full_data, dc); |
1913 | if (dc->top_request->state == BRS_DOWNLOAD_UP) | 1910 | if (BRS_DOWNLOAD_UP == dc->top_request->state) |
1914 | { | 1911 | { |
1915 | if (dc->rfh != NULL) | 1912 | if (NULL != dc->rfh) |
1916 | { | 1913 | { |
1917 | /* avoid hanging on to file handle longer than | 1914 | /* avoid hanging on to file handle longer than |
1918 | * necessary */ | 1915 | * necessary */ |
@@ -1922,7 +1919,7 @@ GNUNET_FS_download_start_task_ (void *cls, | |||
1922 | return; /* finished, status update was already done for us */ | 1919 | return; /* finished, status update was already done for us */ |
1923 | } | 1920 | } |
1924 | } | 1921 | } |
1925 | if (dc->rfh != NULL) | 1922 | if (NULL != dc->rfh) |
1926 | { | 1923 | { |
1927 | /* finally, actually run bottom-up */ | 1924 | /* finally, actually run bottom-up */ |
1928 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1925 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1941,7 +1938,7 @@ GNUNET_FS_download_start_task_ (void *cls, | |||
1941 | dc->issue_requests = GNUNET_YES; | 1938 | dc->issue_requests = GNUNET_YES; |
1942 | schedule_block_download (dc, dc->top_request); | 1939 | schedule_block_download (dc, dc->top_request); |
1943 | } | 1940 | } |
1944 | if (dc->top_request->state == BRS_DOWNLOAD_UP) | 1941 | if (BRS_DOWNLOAD_UP == dc->top_request->state) |
1945 | check_completed (dc); | 1942 | check_completed (dc); |
1946 | } | 1943 | } |
1947 | 1944 | ||
@@ -1958,42 +1955,42 @@ GNUNET_FS_download_signal_suspend_ (void *cls) | |||
1958 | struct GNUNET_FS_DownloadContext *dc = cls; | 1955 | struct GNUNET_FS_DownloadContext *dc = cls; |
1959 | struct GNUNET_FS_ProgressInfo pi; | 1956 | struct GNUNET_FS_ProgressInfo pi; |
1960 | 1957 | ||
1961 | if (dc->top != NULL) | 1958 | if (NULL != dc->top) |
1962 | GNUNET_FS_end_top (dc->h, dc->top); | 1959 | GNUNET_FS_end_top (dc->h, dc->top); |
1963 | while (NULL != dc->child_head) | 1960 | while (NULL != dc->child_head) |
1964 | GNUNET_FS_download_signal_suspend_ (dc->child_head); | 1961 | GNUNET_FS_download_signal_suspend_ (dc->child_head); |
1965 | if (dc->search != NULL) | 1962 | if (NULL != dc->search) |
1966 | { | 1963 | { |
1967 | dc->search->download = NULL; | 1964 | dc->search->download = NULL; |
1968 | dc->search = NULL; | 1965 | dc->search = NULL; |
1969 | } | 1966 | } |
1970 | if (dc->job_queue != NULL) | 1967 | if (NULL != dc->job_queue) |
1971 | { | 1968 | { |
1972 | GNUNET_FS_dequeue_ (dc->job_queue); | 1969 | GNUNET_FS_dequeue_ (dc->job_queue); |
1973 | dc->job_queue = NULL; | 1970 | dc->job_queue = NULL; |
1974 | } | 1971 | } |
1975 | if (dc->parent != NULL) | 1972 | if (NULL != dc->parent) |
1976 | GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, dc->parent->child_tail, | 1973 | GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, dc->parent->child_tail, |
1977 | dc); | 1974 | dc); |
1978 | if (dc->task != GNUNET_SCHEDULER_NO_TASK) | 1975 | if (GNUNET_SCHEDULER_NO_TASK != dc->task) |
1979 | { | 1976 | { |
1980 | GNUNET_SCHEDULER_cancel (dc->task); | 1977 | GNUNET_SCHEDULER_cancel (dc->task); |
1981 | dc->task = GNUNET_SCHEDULER_NO_TASK; | 1978 | dc->task = GNUNET_SCHEDULER_NO_TASK; |
1982 | } | 1979 | } |
1983 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_SUSPEND; | 1980 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_SUSPEND; |
1984 | GNUNET_FS_download_make_status_ (&pi, dc); | 1981 | GNUNET_FS_download_make_status_ (&pi, dc); |
1985 | if (dc->te != NULL) | 1982 | if (NULL != dc->te) |
1986 | { | 1983 | { |
1987 | GNUNET_FS_tree_encoder_finish (dc->te, NULL, NULL); | 1984 | GNUNET_FS_tree_encoder_finish (dc->te, NULL, NULL); |
1988 | dc->te = NULL; | 1985 | dc->te = NULL; |
1989 | } | 1986 | } |
1990 | if (dc->rfh != NULL) | 1987 | if (NULL != dc->rfh) |
1991 | { | 1988 | { |
1992 | GNUNET_DISK_file_close (dc->rfh); | 1989 | GNUNET_DISK_file_close (dc->rfh); |
1993 | dc->rfh = NULL; | 1990 | dc->rfh = NULL; |
1994 | } | 1991 | } |
1995 | GNUNET_FS_free_download_request_ (dc->top_request); | 1992 | GNUNET_FS_free_download_request_ (dc->top_request); |
1996 | if (dc->active != NULL) | 1993 | if (NULL != dc->active) |
1997 | { | 1994 | { |
1998 | GNUNET_CONTAINER_multihashmap_destroy (dc->active); | 1995 | GNUNET_CONTAINER_multihashmap_destroy (dc->active); |
1999 | dc->active = NULL; | 1996 | dc->active = NULL; |
@@ -2213,7 +2210,7 @@ GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc) | |||
2213 | { | 2210 | { |
2214 | if (dc->completed == dc->length) | 2211 | if (dc->completed == dc->length) |
2215 | return; | 2212 | return; |
2216 | GNUNET_assert (dc->job_queue == NULL); | 2213 | GNUNET_assert (NULL == dc->job_queue); |
2217 | dc->job_queue = | 2214 | dc->job_queue = |
2218 | GNUNET_FS_queue_ (dc->h, &activate_fs_download, &deactivate_fs_download, | 2215 | GNUNET_FS_queue_ (dc->h, &activate_fs_download, &deactivate_fs_download, |
2219 | dc, (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, | 2216 | dc, (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, |
@@ -2236,26 +2233,26 @@ GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete) | |||
2236 | int have_children; | 2233 | int have_children; |
2237 | int search_was_null; | 2234 | int search_was_null; |
2238 | 2235 | ||
2239 | if (dc->top != NULL) | 2236 | if (NULL != dc->top) |
2240 | GNUNET_FS_end_top (dc->h, dc->top); | 2237 | GNUNET_FS_end_top (dc->h, dc->top); |
2241 | if (dc->task != GNUNET_SCHEDULER_NO_TASK) | 2238 | if (GNUNET_SCHEDULER_NO_TASK != dc->task) |
2242 | { | 2239 | { |
2243 | GNUNET_SCHEDULER_cancel (dc->task); | 2240 | GNUNET_SCHEDULER_cancel (dc->task); |
2244 | dc->task = GNUNET_SCHEDULER_NO_TASK; | 2241 | dc->task = GNUNET_SCHEDULER_NO_TASK; |
2245 | } | 2242 | } |
2246 | search_was_null = (dc->search == NULL); | 2243 | search_was_null = (NULL == dc->search); |
2247 | if (dc->search != NULL) | 2244 | if (NULL != dc->search) |
2248 | { | 2245 | { |
2249 | dc->search->download = NULL; | 2246 | dc->search->download = NULL; |
2250 | GNUNET_FS_search_result_sync_ (dc->search); | 2247 | GNUNET_FS_search_result_sync_ (dc->search); |
2251 | dc->search = NULL; | 2248 | dc->search = NULL; |
2252 | } | 2249 | } |
2253 | if (dc->job_queue != NULL) | 2250 | if (NULL != dc->job_queue) |
2254 | { | 2251 | { |
2255 | GNUNET_FS_dequeue_ (dc->job_queue); | 2252 | GNUNET_FS_dequeue_ (dc->job_queue); |
2256 | dc->job_queue = NULL; | 2253 | dc->job_queue = NULL; |
2257 | } | 2254 | } |
2258 | if (dc->te != NULL) | 2255 | if (NULL != dc->te) |
2259 | { | 2256 | { |
2260 | GNUNET_FS_tree_encoder_finish (dc->te, NULL, NULL); | 2257 | GNUNET_FS_tree_encoder_finish (dc->te, NULL, NULL); |
2261 | dc->te = NULL; | 2258 | dc->te = NULL; |
@@ -2263,16 +2260,16 @@ GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete) | |||
2263 | have_children = (NULL != dc->child_head) ? GNUNET_YES : GNUNET_NO; | 2260 | have_children = (NULL != dc->child_head) ? GNUNET_YES : GNUNET_NO; |
2264 | while (NULL != dc->child_head) | 2261 | while (NULL != dc->child_head) |
2265 | GNUNET_FS_download_stop (dc->child_head, do_delete); | 2262 | GNUNET_FS_download_stop (dc->child_head, do_delete); |
2266 | if (dc->parent != NULL) | 2263 | if (NULL != dc->parent) |
2267 | GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, dc->parent->child_tail, | 2264 | GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, dc->parent->child_tail, |
2268 | dc); | 2265 | dc); |
2269 | if (dc->serialization != NULL) | 2266 | if (NULL != dc->serialization) |
2270 | GNUNET_FS_remove_sync_file_ (dc->h, | 2267 | GNUNET_FS_remove_sync_file_ (dc->h, |
2271 | ((dc->parent != NULL) || | 2268 | ((NULL != dc->parent) || |
2272 | (! search_was_null)) ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD : | 2269 | (! search_was_null)) ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD : |
2273 | GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, | 2270 | GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, |
2274 | dc->serialization); | 2271 | dc->serialization); |
2275 | if ((GNUNET_YES == have_children) && (dc->parent == NULL)) | 2272 | if ((GNUNET_YES == have_children) && (NULL == dc->parent)) |
2276 | GNUNET_FS_remove_sync_dir_ (dc->h, | 2273 | GNUNET_FS_remove_sync_dir_ (dc->h, |
2277 | (! search_was_null) ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD : | 2274 | (! search_was_null) ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD : |
2278 | GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, | 2275 | GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, |
@@ -2281,12 +2278,12 @@ GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete) | |||
2281 | GNUNET_FS_download_make_status_ (&pi, dc); | 2278 | GNUNET_FS_download_make_status_ (&pi, dc); |
2282 | GNUNET_FS_free_download_request_ (dc->top_request); | 2279 | GNUNET_FS_free_download_request_ (dc->top_request); |
2283 | dc->top_request = NULL; | 2280 | dc->top_request = NULL; |
2284 | if (dc->active != NULL) | 2281 | if (NULL != dc->active) |
2285 | { | 2282 | { |
2286 | GNUNET_CONTAINER_multihashmap_destroy (dc->active); | 2283 | GNUNET_CONTAINER_multihashmap_destroy (dc->active); |
2287 | dc->active = NULL; | 2284 | dc->active = NULL; |
2288 | } | 2285 | } |
2289 | if (dc->filename != NULL) | 2286 | if (NULL != dc->filename) |
2290 | { | 2287 | { |
2291 | if ((dc->completed != dc->length) && (GNUNET_YES == do_delete)) | 2288 | if ((dc->completed != dc->length) && (GNUNET_YES == do_delete)) |
2292 | { | 2289 | { |