From 6e599264ad13e8fc105493d74d7c11d46f8739ed Mon Sep 17 00:00:00 2001 From: ng0 Date: Fri, 6 Sep 2019 22:46:29 +0000 Subject: first step to remove plibc --- src/fs/fs_api.c | 842 ++++++++++++++-------------- src/fs/fs_dirmetascan.c | 217 ++++--- src/fs/fs_download.c | 736 ++++++++++++------------ src/fs/fs_file_information.c | 181 +++--- src/fs/fs_namespace.c | 188 ++++--- src/fs/fs_uri.c | 400 ++++++------- src/fs/gnunet-auto-share.c | 2 +- src/fs/gnunet-directory.c | 70 ++- src/fs/gnunet-download.c | 277 +++++---- src/fs/gnunet-fs.c | 42 +- src/fs/gnunet-helper-fs-publish.c | 194 +++---- src/fs/gnunet-publish.c | 530 +++++++++-------- src/fs/gnunet-search.c | 173 +++--- src/fs/gnunet-service-fs_indexing.c | 248 +++----- src/fs/gnunet-unindex.c | 58 +- src/fs/perf_gnunet_service_fs_p2p.c | 4 +- src/fs/perf_gnunet_service_fs_p2p_respect.c | 4 +- src/fs/test_fs.c | 4 +- src/fs/test_fs_directory.c | 4 +- src/fs/test_fs_download.c | 6 +- src/fs/test_fs_download_persistence.c | 4 +- src/fs/test_fs_getopt.c | 2 +- src/fs/test_fs_list_indexed.c | 2 +- src/fs/test_fs_namespace.c | 18 +- src/fs/test_fs_publish.c | 4 +- src/fs/test_fs_publish_persistence.c | 2 +- src/fs/test_fs_search.c | 6 +- src/fs/test_fs_search_persistence.c | 6 +- src/fs/test_fs_search_probes.c | 6 +- src/fs/test_fs_search_with_and.c | 6 +- src/fs/test_fs_unindex.c | 4 +- src/fs/test_fs_unindex_persistence.c | 2 +- src/fs/test_fs_uri.c | 4 +- src/fs/test_gnunet_service_fs_migration.c | 2 +- src/fs/test_gnunet_service_fs_p2p.c | 2 +- src/fs/test_plugin_block_fs.c | 2 +- 36 files changed, 2137 insertions(+), 2115 deletions(-) (limited to 'src/fs') diff --git a/src/fs/fs_api.c b/src/fs/fs_api.c index aec5ff340..f7b64a5c9 100644 --- a/src/fs/fs_api.c +++ b/src/fs/fs_api.c @@ -56,12 +56,10 @@ start_job (struct GNUNET_FS_QueueEntry *qe) qe->h->active_downloads++; qe->start_time = GNUNET_TIME_absolute_get (); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting job %p (%u active)\n", - qe, - qe->h->active_downloads); - GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, - qe->h->pending_tail, - qe); + "Starting job %p (%u active)\n", + qe, + qe->h->active_downloads); + GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, qe->h->pending_tail, qe); GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head, qe->h->running_tail, qe->h->running_tail, @@ -83,17 +81,14 @@ stop_job (struct GNUNET_FS_QueueEntry *qe) GNUNET_assert (0 < qe->h->active_downloads); qe->h->active_downloads--; qe->h->active_blocks -= qe->blocks; - qe->run_time = - GNUNET_TIME_relative_add (qe->run_time, - GNUNET_TIME_absolute_get_duration - (qe->start_time)); + qe->run_time = GNUNET_TIME_relative_add (qe->run_time, + GNUNET_TIME_absolute_get_duration ( + qe->start_time)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Stopping job %p (%u active)\n", - qe, - qe->h->active_downloads); - GNUNET_CONTAINER_DLL_remove (qe->h->running_head, - qe->h->running_tail, - qe); + "Stopping job %p (%u active)\n", + qe, + qe->h->active_downloads); + GNUNET_CONTAINER_DLL_remove (qe->h->running_head, qe->h->running_tail, qe); GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head, qe->h->pending_tail, qe->h->pending_tail, @@ -167,13 +162,13 @@ process_job_queue (void *cls) rst = GNUNET_TIME_absolute_get_remaining (end_time); if (0 == rst.rel_value_us) { - num_probes_expired++; - stop_job (qe); + num_probes_expired++; + stop_job (qe); } else { - num_probes_active++; - restart_at = GNUNET_TIME_relative_min (rst, restart_at); + num_probes_active++; + restart_at = GNUNET_TIME_relative_min (rst, restart_at); } break; case GNUNET_FS_QUEUE_PRIORITY_NORMAL: @@ -184,13 +179,13 @@ process_job_queue (void *cls) rst = GNUNET_TIME_absolute_get_remaining (end_time); if (0 == rst.rel_value_us) { - num_downloads_expired++; - stop_job (qe); + num_downloads_expired++; + stop_job (qe); } else { - num_downloads_active++; - restart_at = GNUNET_TIME_relative_min (rst, restart_at); + num_downloads_active++; + restart_at = GNUNET_TIME_relative_min (rst, restart_at); } break; default: @@ -201,41 +196,44 @@ process_job_queue (void *cls) GNUNET_break (h->active_downloads == num_downloads_active + num_probes_active); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "PA: %u, PE: %u, PW: %u; DA: %u, DE: %u, DW: %u\n", - num_probes_active, - num_probes_expired, - num_probes_waiting, - num_downloads_active, - num_downloads_expired, - num_downloads_waiting); + "PA: %u, PE: %u, PW: %u; DA: %u, DE: %u, DW: %u\n", + num_probes_active, + num_probes_expired, + num_probes_waiting, + num_downloads_active, + num_downloads_expired, + num_downloads_waiting); GNUNET_break (h->active_downloads + num_probes_active <= h->max_parallel_downloads); /* calculate start/stop decisions */ if (h->active_downloads + num_downloads_waiting > h->max_parallel_downloads) { /* stop as many probes as there are downloads and probes */ - num_probes_change = - GNUNET_MIN (num_probes_active, - num_downloads_waiting); + num_probes_change = -GNUNET_MIN (num_probes_active, num_downloads_waiting); /* start as many downloads as there are free slots, including those we just opened up */ - num_downloads_change = h->max_parallel_downloads - h->active_downloads - num_probes_change; + num_downloads_change = + h->max_parallel_downloads - h->active_downloads - num_probes_change; } else { /* start all downloads (we can) */ num_downloads_change = num_downloads_waiting; /* also start probes if there is room, but use a lower cap of (mpd/4) + 1 */ - if (1 + h->max_parallel_downloads / 4 >= (h->active_downloads + num_downloads_change)) - num_probes_change = GNUNET_MIN (num_probes_waiting, - (1 + h->max_parallel_downloads / 4) - (h->active_downloads + num_downloads_change)); + if (1 + h->max_parallel_downloads / 4 >= + (h->active_downloads + num_downloads_change)) + num_probes_change = + GNUNET_MIN (num_probes_waiting, + (1 + h->max_parallel_downloads / 4) - + (h->active_downloads + num_downloads_change)); else num_probes_change = 0; } GNUNET_break (num_downloads_change <= num_downloads_waiting); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Changing %d probes and %d/%u/%u downloads\n", - num_probes_change, - num_downloads_change, + "Changing %d probes and %d/%u/%u downloads\n", + num_probes_change, + num_downloads_change, (unsigned int) h->active_downloads, (unsigned int) h->max_parallel_downloads); /* actually stop probes */ @@ -250,7 +248,7 @@ process_job_queue (void *cls) stop_job (qe); num_probes_change++; if (0 == num_probes_change) - break; + break; } } GNUNET_break (0 <= num_probes_change); @@ -258,9 +256,8 @@ process_job_queue (void *cls) /* start some more tasks if we now have empty slots */ block_limit_hit = GNUNET_NO; next = h->pending_head; - while ( (NULL != (qe = next)) && - ( (num_probes_change > 0) || - (num_downloads_change > 0) ) ) + while ((NULL != (qe = next)) && + ((num_probes_change > 0) || (num_downloads_change > 0))) { next = qe->next; switch (qe->priority) @@ -268,40 +265,40 @@ process_job_queue (void *cls) case GNUNET_FS_QUEUE_PRIORITY_PROBE: if (num_probes_change > 0) { - start_job (qe); - num_probes_change--; - run_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2); - restart_at = GNUNET_TIME_relative_min (run_time, restart_at); + start_job (qe); + num_probes_change--; + run_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2); + restart_at = GNUNET_TIME_relative_min (run_time, restart_at); } break; case GNUNET_FS_QUEUE_PRIORITY_NORMAL: - if ( (num_downloads_change > 0) && - ( (qe->blocks + h->active_blocks <= h->max_parallel_requests) || - ( (qe->blocks > h->max_parallel_requests) && - (0 == h->active_downloads) ) ) ) + if ((num_downloads_change > 0) && + ((qe->blocks + h->active_blocks <= h->max_parallel_requests) || + ((qe->blocks > h->max_parallel_requests) && + (0 == h->active_downloads)))) { - start_job (qe); - num_downloads_change--; + start_job (qe); + num_downloads_change--; } else if (num_downloads_change > 0) - block_limit_hit = GNUNET_YES; + block_limit_hit = GNUNET_YES; break; default: GNUNET_break (0); break; } } - GNUNET_break ( (0 == num_downloads_change) || - (GNUNET_YES == block_limit_hit) ); + GNUNET_break ((0 == num_downloads_change) || (GNUNET_YES == block_limit_hit)); GNUNET_break (0 == num_probes_change); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "AD: %u, MP: %u; %d probes and %d downloads to start, will run again in %s\n", - h->active_downloads, - h->max_parallel_requests, - num_probes_change, - num_downloads_change, - GNUNET_STRINGS_relative_time_to_string (restart_at, GNUNET_YES)); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "AD: %u, MP: %u; %d probes and %d downloads to start, will run again in %s\n", + h->active_downloads, + h->max_parallel_requests, + num_probes_change, + num_downloads_change, + GNUNET_STRINGS_relative_time_to_string (restart_at, GNUNET_YES)); /* make sure we run again, callbacks might have already re-scheduled the job, so cancel such @@ -309,7 +306,7 @@ process_job_queue (void *cls) if (NULL != h->queue_job) GNUNET_SCHEDULER_cancel (h->queue_job); h->queue_job = - GNUNET_SCHEDULER_add_delayed (restart_at, &process_job_queue, h); + GNUNET_SCHEDULER_add_delayed (restart_at, &process_job_queue, h); } @@ -330,7 +327,7 @@ GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, GNUNET_SCHEDULER_TaskCallback stop, void *cls, unsigned int blocks, - enum GNUNET_FS_QueuePriority priority) + enum GNUNET_FS_QueuePriority priority) { struct GNUNET_FS_QueueEntry *qe; @@ -342,14 +339,14 @@ GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, qe->queue_time = GNUNET_TIME_absolute_get (); qe->blocks = blocks; qe->priority = priority; - GNUNET_CONTAINER_DLL_insert_after (h->pending_head, h->pending_tail, - h->pending_tail, qe); + GNUNET_CONTAINER_DLL_insert_after (h->pending_head, + h->pending_tail, + h->pending_tail, + qe); if (NULL != h->queue_job) GNUNET_SCHEDULER_cancel (h->queue_job); h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Queueing job %p\n", - qe); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing job %p\n", qe); return qe; } @@ -365,19 +362,14 @@ GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe) struct GNUNET_FS_Handle *h; h = qe->h; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Dequeueing job %p\n", - qe); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dequeueing job %p\n", qe); if (GNUNET_YES == qe->active) stop_job (qe); - GNUNET_CONTAINER_DLL_remove (h->pending_head, - h->pending_tail, - qe); + GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, qe); GNUNET_free (qe); if (NULL != h->queue_job) GNUNET_SCHEDULER_cancel (h->queue_job); - h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, - h); + h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h); } @@ -399,9 +391,7 @@ GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, ret = GNUNET_new (struct TopLevelActivity); ret->ssf = ssf; ret->ssf_cls = ssf_cls; - GNUNET_CONTAINER_DLL_insert (h->top_head, - h->top_tail, - ret); + GNUNET_CONTAINER_DLL_insert (h->top_head, h->top_tail, ret); return ret; } @@ -413,12 +403,9 @@ GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, * @param top top level activity entry */ void -GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, - struct TopLevelActivity *top) +GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, struct TopLevelActivity *top) { - GNUNET_CONTAINER_DLL_remove (h->top_head, - h->top_tail, - top); + GNUNET_CONTAINER_DLL_remove (h->top_head, h->top_tail, top); GNUNET_free (top); } @@ -489,33 +476,32 @@ GNUNET_FS_data_reader_file_ (void *cls, } if (NULL == fi->fd) { - fi->fd = - GNUNET_DISK_file_open (fi->filename, - GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE); + fi->fd = GNUNET_DISK_file_open (fi->filename, + GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_NONE); if (NULL == fi->fd) { GNUNET_asprintf (emsg, - _("Could not open file `%s': %s"), + _ ("Could not open file `%s': %s"), fi->filename, - STRERROR (errno)); + strerror (errno)); return 0; } } - if ( (GNUNET_SYSERR == - GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET)) || - (-1 == (ret = GNUNET_DISK_file_read (fi->fd, buf, max))) ) + if ((GNUNET_SYSERR == + GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET)) || + (-1 == (ret = GNUNET_DISK_file_read (fi->fd, buf, max)))) { GNUNET_asprintf (emsg, - _("Could not read file `%s': %s"), + _ ("Could not read file `%s': %s"), fi->filename, - STRERROR (errno)); + strerror (errno)); return 0; } if (ret != max) { GNUNET_asprintf (emsg, - _("Short read reading from file `%s'!"), + _ ("Short read reading from file `%s'!"), fi->filename); return 0; } @@ -604,13 +590,20 @@ get_serialization_file_name (struct GNUNET_FS_Handle *h, char *ret; if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) - return NULL; /* persistence not requested */ - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (h->cfg, "fs", "STATE_DIR", - &basename)) + return NULL; /* persistence not requested */ + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg, + "fs", + "STATE_DIR", + &basename)) return NULL; - GNUNET_asprintf (&ret, "%s%s%s%s%s%s%s", basename, DIR_SEPARATOR_STR, - h->client_name, DIR_SEPARATOR_STR, ext, DIR_SEPARATOR_STR, + GNUNET_asprintf (&ret, + "%s%s%s%s%s%s%s", + basename, + DIR_SEPARATOR_STR, + h->client_name, + DIR_SEPARATOR_STR, + ext, + DIR_SEPARATOR_STR, ent); GNUNET_free (basename); return ret; @@ -638,14 +631,23 @@ get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, char *ret; if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) - return NULL; /* persistence not requested */ - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (h->cfg, "fs", "STATE_DIR", - &basename)) + return NULL; /* persistence not requested */ + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg, + "fs", + "STATE_DIR", + &basename)) return NULL; - GNUNET_asprintf (&ret, "%s%s%s%s%s%s%s.dir%s%s", basename, DIR_SEPARATOR_STR, - h->client_name, DIR_SEPARATOR_STR, ext, DIR_SEPARATOR_STR, - uni, DIR_SEPARATOR_STR, ent); + GNUNET_asprintf (&ret, + "%s%s%s%s%s%s%s.dir%s%s", + basename, + DIR_SEPARATOR_STR, + h->client_name, + DIR_SEPARATOR_STR, + ext, + DIR_SEPARATOR_STR, + uni, + DIR_SEPARATOR_STR, + ent); GNUNET_free (basename); return ret; } @@ -660,9 +662,7 @@ get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, * @return NULL on error */ static struct GNUNET_BIO_ReadHandle * -get_read_handle (struct GNUNET_FS_Handle *h, - const char *ext, - const char *ent) +get_read_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) { char *fn; struct GNUNET_BIO_ReadHandle *ret; @@ -685,9 +685,7 @@ get_read_handle (struct GNUNET_FS_Handle *h, * @return NULL on error */ static struct GNUNET_BIO_WriteHandle * -get_write_handle (struct GNUNET_FS_Handle *h, - const char *ext, - const char *ent) +get_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) { char *fn; struct GNUNET_BIO_WriteHandle *ret; @@ -712,8 +710,10 @@ get_write_handle (struct GNUNET_FS_Handle *h, * @return NULL on error */ static struct GNUNET_BIO_WriteHandle * -get_write_handle_in_dir (struct GNUNET_FS_Handle *h, const char *ext, - const char *uni, const char *ent) +get_write_handle_in_dir (struct GNUNET_FS_Handle *h, + const char *ext, + const char *uni, + const char *ent) { char *fn; struct GNUNET_BIO_WriteHandle *ret; @@ -749,8 +749,7 @@ GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, filename = get_serialization_file_name (h, ext, ent); if (NULL != filename) { - if ( (0 != UNLINK (filename)) && - (ENOENT != errno) ) + if ((0 != unlink (filename)) && (ENOENT != errno)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); GNUNET_free (filename); } @@ -768,7 +767,8 @@ GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, static void remove_sync_file_in_dir (struct GNUNET_FS_Handle *h, const char *ext, - const char *uni, const char *ent) + const char *uni, + const char *ent) { char *filename; @@ -780,7 +780,7 @@ remove_sync_file_in_dir (struct GNUNET_FS_Handle *h, filename = get_serialization_file_name_in_dir (h, ext, uni, ent); if (NULL == filename) return; - if (0 != UNLINK (filename)) + if (0 != unlink (filename)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); GNUNET_free (filename); } @@ -874,8 +874,7 @@ read_start_time (struct GNUNET_BIO_ReadHandle *rh, * @return NULL on error */ static struct GNUNET_FS_FileInformation * -deserialize_file_information (struct GNUNET_FS_Handle *h, - const char *filename); +deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename); /** @@ -915,21 +914,22 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, filename = NULL; if ((GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) || (GNUNET_OK != GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) || - ( (NULL != ksks) && - ( (NULL == (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) || - (GNUNET_YES != GNUNET_FS_uri_test_ksk (ret->keywords)) ) ) || + ((NULL != ksks) && + ((NULL == (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) || + (GNUNET_YES != GNUNET_FS_uri_test_ksk (ret->keywords)))) || (GNUNET_OK != GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) || - ( (NULL != chks) && - ( (NULL == (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) || - (GNUNET_YES != GNUNET_FS_uri_test_chk (ret->chk_uri))) ) || + ((NULL != chks) && + ((NULL == (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) || + (GNUNET_YES != GNUNET_FS_uri_test_chk (ret->chk_uri)))) || (GNUNET_OK != GNUNET_BIO_read_string (rh, "sks-uri", &skss, 1024)) || - ( (NULL != skss) && - ( (NULL == (ret->sks_uri = GNUNET_FS_uri_parse (skss, NULL))) || - (GNUNET_YES != GNUNET_FS_uri_test_sks (ret->sks_uri))) ) || + ((NULL != skss) && + ((NULL == (ret->sks_uri = GNUNET_FS_uri_parse (skss, NULL))) || + (GNUNET_YES != GNUNET_FS_uri_test_sks (ret->sks_uri)))) || (GNUNET_OK != read_start_time (rh, &ret->start_time)) || - (GNUNET_OK != GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024)) - || (GNUNET_OK != - GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) || + (GNUNET_OK != + GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024)) || + (GNUNET_OK != + GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) || (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value_us)) || (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) || @@ -941,7 +941,7 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, } switch (b) { - case 0: /* file-insert */ + case 0: /* file-insert */ if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) { GNUNET_break (0); @@ -957,12 +957,13 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, { ret->data.file.reader = &GNUNET_FS_data_reader_copy_; ret->data.file.reader_cls = - GNUNET_malloc_large (ret->data.file.file_size); + GNUNET_malloc_large (ret->data.file.file_size); if (ret->data.file.reader_cls == NULL) goto cleanup; - if (GNUNET_OK != - GNUNET_BIO_read (rh, "file-data", ret->data.file.reader_cls, - ret->data.file.file_size)) + if (GNUNET_OK != GNUNET_BIO_read (rh, + "file-data", + ret->data.file.reader_cls, + ret->data.file.file_size)) { GNUNET_break (0); goto cleanup; @@ -972,11 +973,11 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, { ret->data.file.reader = &GNUNET_FS_data_reader_file_; ret->data.file.reader_cls = - GNUNET_FS_make_file_reader_context_ (ret->filename); + GNUNET_FS_make_file_reader_context_ (ret->filename); } } break; - case 1: /* file-index, no hash */ + case 1: /* file-index, no hash */ if (NULL == ret->filename) { GNUNET_break (0); @@ -993,18 +994,19 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, ret->data.file.index_start_confirmed = GNUNET_NO; ret->data.file.reader = &GNUNET_FS_data_reader_file_; ret->data.file.reader_cls = - GNUNET_FS_make_file_reader_context_ (ret->filename); + GNUNET_FS_make_file_reader_context_ (ret->filename); break; - case 2: /* file-index-with-hash */ + case 2: /* file-index-with-hash */ if (NULL == ret->filename) { GNUNET_break (0); goto cleanup; } if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || - (GNUNET_OK != - GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, - sizeof (struct GNUNET_HashCode)))) + (GNUNET_OK != GNUNET_BIO_read (rh, + "fileid", + &ret->data.file.file_id, + sizeof (struct GNUNET_HashCode)))) { GNUNET_break (0); goto cleanup; @@ -1015,18 +1017,19 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, ret->data.file.index_start_confirmed = GNUNET_NO; ret->data.file.reader = &GNUNET_FS_data_reader_file_; ret->data.file.reader_cls = - GNUNET_FS_make_file_reader_context_ (ret->filename); + GNUNET_FS_make_file_reader_context_ (ret->filename); break; - case 3: /* file-index-with-hash-confirmed */ + case 3: /* file-index-with-hash-confirmed */ if (NULL == ret->filename) { GNUNET_break (0); goto cleanup; } if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || - (GNUNET_OK != - GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, - sizeof (struct GNUNET_HashCode)))) + (GNUNET_OK != GNUNET_BIO_read (rh, + "fileid", + &ret->data.file.file_id, + sizeof (struct GNUNET_HashCode)))) { GNUNET_break (0); goto cleanup; @@ -1037,13 +1040,15 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, ret->data.file.index_start_confirmed = GNUNET_YES; ret->data.file.reader = &GNUNET_FS_data_reader_file_; ret->data.file.reader_cls = - GNUNET_FS_make_file_reader_context_ (ret->filename); + GNUNET_FS_make_file_reader_context_ (ret->filename); break; - case 4: /* directory */ + case 4: /* directory */ ret->is_directory = GNUNET_YES; if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dsize)) || - (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_completed)) || - (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_size)) || + (GNUNET_OK != + GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_completed)) || + (GNUNET_OK != + GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_size)) || (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) || (GNUNET_OK != GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) || @@ -1108,8 +1113,7 @@ cleanup: * @return NULL on error */ static struct GNUNET_FS_FileInformation * -deserialize_file_information (struct GNUNET_FS_Handle *h, - const char *filename) +deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename) { struct GNUNET_FS_FileInformation *ret; struct GNUNET_BIO_ReadHandle *rh; @@ -1123,17 +1127,19 @@ deserialize_file_information (struct GNUNET_FS_Handle *h, if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to resume publishing information `%s': %s\n"), - filename, emsg); + _ ("Failed to resume publishing information `%s': %s\n"), + filename, + emsg); GNUNET_free (emsg); } if (NULL == ret) { - fn = get_serialization_file_name (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename); + fn = + get_serialization_file_name (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename); if (NULL != fn) { - if (0 != UNLINK (fn)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); + if (0 != unlink (fn)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); GNUNET_free (fn); } } @@ -1184,15 +1190,14 @@ get_serialization_short_name (const char *fullname) * @return NULL on errror */ static char * -make_serialization_file_name (struct GNUNET_FS_Handle *h, - const char *ext) +make_serialization_file_name (struct GNUNET_FS_Handle *h, const char *ext) { char *fn; char *dn; char *ret; if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) - return NULL; /* persistence not requested */ + return NULL; /* persistence not requested */ dn = get_serialization_file_name (h, ext, ""); if (NULL == dn) return NULL; @@ -1204,7 +1209,7 @@ make_serialization_file_name (struct GNUNET_FS_Handle *h, fn = GNUNET_DISK_mktemp (dn); GNUNET_free (dn); if (NULL == fn) - return NULL; /* epic fail */ + return NULL; /* epic fail */ ret = get_serialization_short_name (fn); GNUNET_free (fn); return ret; @@ -1230,7 +1235,7 @@ make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, char *ret; if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) - return NULL; /* persistence not requested */ + return NULL; /* persistence not requested */ dn = get_serialization_file_name_in_dir (h, ext, uni, ""); if (NULL == dn) return NULL; @@ -1242,7 +1247,7 @@ make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, fn = GNUNET_DISK_mktemp (dn); GNUNET_free (dn); if (NULL == fn) - return NULL; /* epic fail */ + return NULL; /* epic fail */ ret = get_serialization_short_name (fn); GNUNET_free (fn); return ret; @@ -1272,7 +1277,7 @@ copy_from_reader (struct GNUNET_BIO_WriteHandle *wh, { left = GNUNET_MIN (sizeof (buf), fi->data.file.file_size - off); ret = - fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg); + fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg); if (0 == ret) { GNUNET_free (emsg); @@ -1304,11 +1309,11 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) if (NULL == fi->serialization) fi->serialization = - make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO); + make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO); if (NULL == fi->serialization) return; - wh = get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, - fi->serialization); + wh = + get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization); if (NULL == wh) { GNUNET_free (fi->serialization); @@ -1363,7 +1368,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) switch (b) { - case 0: /* file-insert */ + case 0: /* file-insert */ if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) { GNUNET_break (0); @@ -1376,7 +1381,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) goto cleanup; } break; - case 1: /* file-index, no hash */ + case 1: /* file-index, no hash */ if (NULL == fi->filename) { GNUNET_break (0); @@ -1388,37 +1393,39 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) goto cleanup; } break; - case 2: /* file-index-with-hash */ - case 3: /* file-index-with-hash-confirmed */ + case 2: /* file-index-with-hash */ + case 3: /* file-index-with-hash-confirmed */ if (NULL == fi->filename) { GNUNET_break (0); goto cleanup; } if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) || - (GNUNET_OK != - GNUNET_BIO_write (wh, &fi->data.file.file_id, - sizeof (struct GNUNET_HashCode)))) + (GNUNET_OK != GNUNET_BIO_write (wh, + &fi->data.file.file_id, + sizeof (struct GNUNET_HashCode)))) { GNUNET_break (0); goto cleanup; } break; - case 4: /* directory */ - if ( (NULL != fi->data.dir.entries) && - (NULL == fi->data.dir.entries->serialization) ) + case 4: /* directory */ + if ((NULL != fi->data.dir.entries) && + (NULL == fi->data.dir.entries->serialization)) GNUNET_FS_file_information_sync_ (fi->data.dir.entries); if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) || - (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_completed)) || - (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_size)) || (GNUNET_OK != - GNUNET_BIO_write (wh, fi->data.dir.dir_data, - (uint32_t) fi->data.dir.dir_size)) || + GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_completed)) || + (GNUNET_OK != + GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_size)) || + (GNUNET_OK != GNUNET_BIO_write (wh, + fi->data.dir.dir_data, + (uint32_t) fi->data.dir.dir_size)) || (GNUNET_OK != GNUNET_BIO_write_string (wh, - (fi->data.dir.entries == - NULL) ? NULL : fi->data.dir. - entries->serialization))) + (fi->data.dir.entries == NULL) + ? NULL + : fi->data.dir.entries->serialization))) { GNUNET_break (0); goto cleanup; @@ -1428,13 +1435,12 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) GNUNET_assert (0); goto cleanup; } - if ( (NULL != fi->next) && - (NULL == fi->next->serialization) ) + if ((NULL != fi->next) && (NULL == fi->next->serialization)) GNUNET_FS_file_information_sync_ (fi->next); - if (GNUNET_OK != - GNUNET_BIO_write_string (wh, - (fi->next != - NULL) ? fi->next->serialization : NULL)) + if (GNUNET_OK != GNUNET_BIO_write_string (wh, + (fi->next != NULL) + ? fi->next->serialization + : NULL)) { GNUNET_break (0); goto cleanup; @@ -1445,18 +1451,19 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) GNUNET_break (0); goto cleanup; } - return; /* done! */ + return; /* done! */ cleanup: if (NULL != wh) (void) GNUNET_BIO_write_close (wh); GNUNET_free_non_null (chks); GNUNET_free_non_null (ksks); GNUNET_free_non_null (skss); - fn = get_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, + fn = get_serialization_file_name (fi->h, + GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization); if (NULL != fn) { - if (0 != UNLINK (fn)) + if (0 != unlink (fn)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); GNUNET_free (fn); } @@ -1465,7 +1472,6 @@ cleanup: } - /** * Find the entry in the file information struct where the * serialization filename matches the given name. @@ -1475,8 +1481,7 @@ cleanup: * @return NULL if srch was not found in this subtree */ static struct GNUNET_FS_FileInformation * -find_file_position (struct GNUNET_FS_FileInformation *pos, - const char *srch) +find_file_position (struct GNUNET_FS_FileInformation *pos, const char *srch) { struct GNUNET_FS_FileInformation *r; @@ -1484,8 +1489,8 @@ find_file_position (struct GNUNET_FS_FileInformation *pos, { if (0 == strcmp (srch, pos->serialization)) return pos; - if ( (GNUNET_YES == pos->is_directory) && - (NULL != (r = find_file_position (pos->data.dir.entries, srch))) ) + if ((GNUNET_YES == pos->is_directory) && + (NULL != (r = find_file_position (pos->data.dir.entries, srch)))) return r; pos = pos->next; } @@ -1548,8 +1553,7 @@ fip_signal_resume (void *cls, * @return #GNUNET_OK (continue to iterate) */ static int -deserialize_publish_file (void *cls, - const char *filename) +deserialize_publish_file (void *cls, const char *filename) { struct GNUNET_FS_Handle *h = cls; struct GNUNET_BIO_ReadHandle *rh; @@ -1573,17 +1577,19 @@ deserialize_publish_file (void *cls, GNUNET_break (0); goto cleanup; } - if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) - || (GNUNET_OK != - GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) || + if ((GNUNET_OK != + GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) || + (GNUNET_OK != + GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) || (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &all_done)) || (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &have_ns)) || (GNUNET_OK != GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) || - (GNUNET_OK != GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) - || ( (GNUNET_YES == have_ns) && - (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof (ns)))) ) + (GNUNET_OK != + GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) || + ((GNUNET_YES == have_ns) && + (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof (ns))))) { GNUNET_break (0); goto cleanup; @@ -1636,20 +1642,19 @@ deserialize_publish_file (void *cls, { GNUNET_assert (NULL == pc->upload_task); pc->upload_task = - GNUNET_SCHEDULER_add_with_priority - (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, - &GNUNET_FS_publish_main_, pc); + GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, + &GNUNET_FS_publish_main_, + pc); } if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failure while resuming publishing operation `%s': %s\n"), - filename, emsg); + _ ("Failure while resuming publishing operation `%s': %s\n"), + filename, + emsg); GNUNET_free (emsg); } - pc->top = GNUNET_FS_make_top (h, - &GNUNET_FS_publish_signal_suspend_, - pc); + pc->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, pc); return GNUNET_OK; cleanup: GNUNET_free_non_null (pc->nid); @@ -1659,13 +1664,14 @@ cleanup: if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to resume publishing operation `%s': %s\n"), filename, + _ ("Failed to resume publishing operation `%s': %s\n"), + filename, emsg); GNUNET_free (emsg); } if (NULL != pc->fi) GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL); - if (0 != UNLINK (filename)) + if (0 != unlink (filename)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); GNUNET_free (pc->serialization); GNUNET_free (pc); @@ -1689,8 +1695,7 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) if (NULL == pc->serialization) pc->serialization = - make_serialization_file_name (pc->h, - GNUNET_FS_SYNC_PATH_MASTER_PUBLISH); + make_serialization_file_name (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH); if (NULL == pc->serialization) return; if (NULL == pc->fi) @@ -1700,7 +1705,8 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) GNUNET_break (0); return; } - wh = get_write_handle (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, + wh = get_write_handle (pc->h, + GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, pc->serialization); if (NULL == wh) { @@ -1714,13 +1720,15 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->all_done)) || (GNUNET_OK != GNUNET_BIO_write_int32 (wh, have_ns)) || (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->fi->serialization)) || - (GNUNET_OK != - GNUNET_BIO_write_string (wh, - (NULL == pc->fi_pos) ? NULL : pc->fi_pos->serialization)) || - ( (NULL != pc->ns) && - (GNUNET_OK != GNUNET_BIO_write (wh, - pc->ns, - sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)) ) )) + (GNUNET_OK != GNUNET_BIO_write_string (wh, + (NULL == pc->fi_pos) + ? NULL + : pc->fi_pos->serialization)) || + ((NULL != pc->ns) && + (GNUNET_OK != + GNUNET_BIO_write (wh, + pc->ns, + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))))) { GNUNET_break (0); goto cleanup; @@ -1735,7 +1743,8 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) cleanup: if (NULL != wh) (void) GNUNET_BIO_write_close (wh); - GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, + GNUNET_FS_remove_sync_file_ (pc->h, + GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, pc->serialization); GNUNET_free (pc->serialization); pc->serialization = NULL; @@ -1758,11 +1767,11 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc) if (NULL == uc->serialization) uc->serialization = - make_serialization_file_name (uc->h, - GNUNET_FS_SYNC_PATH_MASTER_UNINDEX); + make_serialization_file_name (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX); if (NULL == uc->serialization) return; - wh = get_write_handle (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, + wh = get_write_handle (uc->h, + GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization); if (NULL == wh) { @@ -1782,8 +1791,9 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc) (GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->ksk_offset)) || ((uc->state == UNINDEX_STATE_FS_NOTIFY) && - (GNUNET_OK != - GNUNET_BIO_write (wh, &uc->file_id, sizeof (struct GNUNET_HashCode)))) || + (GNUNET_OK != GNUNET_BIO_write (wh, + &uc->file_id, + sizeof (struct GNUNET_HashCode)))) || ((uc->state == UNINDEX_STATE_ERROR) && (GNUNET_OK != GNUNET_BIO_write_string (wh, uc->emsg)))) { @@ -1800,7 +1810,8 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc) cleanup: if (NULL != wh) (void) GNUNET_BIO_write_close (wh); - GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, + GNUNET_FS_remove_sync_file_ (uc->h, + GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization); GNUNET_free (uc->serialization); uc->serialization = NULL; @@ -1854,8 +1865,7 @@ read_download_request (struct GNUNET_BIO_ReadHandle *rh) (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->num_children)) || (dr->num_children > CHK_PER_INODE) || (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->depth)) || - ( (0 == dr->depth) && - (dr->num_children > 0) ) || + ((0 == dr->depth) && (dr->num_children > 0)) || ((dr->depth > 0) && (0 == dr->num_children))) { GNUNET_break (0); @@ -1864,7 +1874,7 @@ read_download_request (struct GNUNET_BIO_ReadHandle *rh) } if (dr->num_children > 0) dr->children = - GNUNET_malloc (dr->num_children * sizeof (struct DownloadRequest *)); + GNUNET_malloc (dr->num_children * sizeof (struct DownloadRequest *)); switch (dr->state) { case BRS_INIT: @@ -1917,9 +1927,9 @@ get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc, if (dc->parent == NULL) return get_serialization_file_name (dc->h, - (dc->search != NULL) ? - GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD : - GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, + (dc->search != NULL) + ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD + : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, uni); if (NULL == dc->parent->serialization) return NULL; @@ -2028,7 +2038,7 @@ cleanup: if (NULL != wh) (void) GNUNET_BIO_write_close (wh); GNUNET_free_non_null (uris); - if (0 != UNLINK (fn)) + if (0 != unlink (fn)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); GNUNET_free (fn); GNUNET_free (dc->serialization); @@ -2055,19 +2065,19 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr) uris = NULL; if (NULL == sr->serialization) sr->serialization = - make_serialization_file_name_in_dir (sr->h, - (sr->sc->psearch_result == - NULL) ? - GNUNET_FS_SYNC_PATH_MASTER_SEARCH : - GNUNET_FS_SYNC_PATH_CHILD_SEARCH, - sr->sc->serialization); + make_serialization_file_name_in_dir (sr->h, + (sr->sc->psearch_result == NULL) + ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH + : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, + sr->sc->serialization); if (NULL == sr->serialization) return; wh = get_write_handle_in_dir (sr->h, - (sr->sc->psearch_result == - NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH : - GNUNET_FS_SYNC_PATH_CHILD_SEARCH, - sr->sc->serialization, sr->serialization); + (sr->sc->psearch_result == NULL) + ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH + : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, + sr->sc->serialization, + sr->serialization); if (NULL == wh) { GNUNET_break (0); @@ -2075,28 +2085,31 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr) } uris = GNUNET_FS_uri_to_string (sr->uri); if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || + (GNUNET_OK != GNUNET_BIO_write_string (wh, + sr->download != NULL + ? sr->download->serialization + : NULL)) || (GNUNET_OK != GNUNET_BIO_write_string (wh, - sr->download != - NULL ? sr->download->serialization : NULL)) || + sr->update_search != NULL + ? sr->update_search->serialization + : NULL)) || + (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) || (GNUNET_OK != - GNUNET_BIO_write_string (wh, - sr->update_search != - NULL ? sr->update_search->serialization : NULL)) - || (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) || - (GNUNET_OK != GNUNET_BIO_write (wh, &sr->key, sizeof (struct GNUNET_HashCode))) - || (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) || + GNUNET_BIO_write (wh, &sr->key, sizeof (struct GNUNET_HashCode))) || + (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) || (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->optional_support)) || (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_success)) || - (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_trials)) ) + (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_trials))) { GNUNET_break (0); goto cleanup; } - if ( (NULL != sr->uri) && - (GNUNET_FS_URI_KSK == sr->sc->uri->type) && - (GNUNET_OK != GNUNET_BIO_write (wh, sr->keyword_bitmap, - (sr->sc->uri->data.ksk.keywordCount + 7) / 8)) ) + if ((NULL != sr->uri) && (GNUNET_FS_URI_KSK == sr->sc->uri->type) && + (GNUNET_OK != + GNUNET_BIO_write (wh, + sr->keyword_bitmap, + (sr->sc->uri->data.ksk.keywordCount + 7) / 8))) { GNUNET_break (0); goto cleanup; @@ -2115,9 +2128,10 @@ cleanup: (void) GNUNET_BIO_write_close (wh); remove_sync_file_in_dir (sr->h, (NULL == sr->sc->psearch_result) - ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH - : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, - sr->sc->serialization, sr->serialization); + ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH + : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, + sr->sc->serialization, + sr->serialization); GNUNET_free (sr->serialization); sr->serialization = NULL; } @@ -2139,10 +2153,8 @@ GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc) char in_pause; const char *category; - category = - (NULL == sc->psearch_result) - ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH - : GNUNET_FS_SYNC_PATH_CHILD_SEARCH; + category = (NULL == sc->psearch_result) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH + : GNUNET_FS_SYNC_PATH_CHILD_SEARCH; if (NULL == sc->serialization) sc->serialization = make_serialization_file_name (sc->h, category); if (NULL == sc->serialization) @@ -2196,8 +2208,7 @@ cleanup: * @return #GNUNET_OK (continue to iterate) */ static int -deserialize_unindex_file (void *cls, - const char *filename) +deserialize_unindex_file (void *cls, const char *filename) { struct GNUNET_FS_Handle *h = cls; struct GNUNET_BIO_ReadHandle *rh; @@ -2222,9 +2233,11 @@ deserialize_unindex_file (void *cls, (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &uc->file_size)) || (GNUNET_OK != read_start_time (rh, &uc->start_time)) || (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)) || - (GNUNET_OK != GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof (struct ContentHashKey))) || - (GNUNET_OK != GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) || - (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset)) ) + (GNUNET_OK != + GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof (struct ContentHashKey))) || + (GNUNET_OK != + GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) || + (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset))) { GNUNET_free_non_null (uris); GNUNET_break (0); @@ -2241,9 +2254,9 @@ deserialize_unindex_file (void *cls, goto cleanup; } } - if ( (uc->ksk_offset > 0) && - ( (NULL == uc->ksk_uri) || - (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount) ) ) + if ((uc->ksk_offset > 0) && + ((NULL == uc->ksk_uri) || + (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount))) { GNUNET_break (0); goto cleanup; @@ -2254,9 +2267,10 @@ deserialize_unindex_file (void *cls, case UNINDEX_STATE_HASHING: break; case UNINDEX_STATE_FS_NOTIFY: - if (GNUNET_OK != - GNUNET_BIO_read (rh, "unindex-hash", &uc->file_id, - sizeof (struct GNUNET_HashCode))) + if (GNUNET_OK != GNUNET_BIO_read (rh, + "unindex-hash", + &uc->file_id, + sizeof (struct GNUNET_HashCode))) { GNUNET_break (0); goto cleanup; @@ -2280,21 +2294,22 @@ deserialize_unindex_file (void *cls, GNUNET_break (0); goto cleanup; } - uc->top = GNUNET_FS_make_top (h, - &GNUNET_FS_unindex_signal_suspend_, - uc); + uc->top = GNUNET_FS_make_top (h, &GNUNET_FS_unindex_signal_suspend_, uc); pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME; pi.value.unindex.specifics.resume.message = uc->emsg; - GNUNET_FS_unindex_make_status_ (&pi, uc, - (uc->state == - UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); + GNUNET_FS_unindex_make_status_ (&pi, + uc, + (uc->state == UNINDEX_STATE_COMPLETE) + ? uc->file_size + : 0); switch (uc->state) { case UNINDEX_STATE_HASHING: - uc->fhc = - GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, uc->filename, - HASHING_BLOCKSIZE, - &GNUNET_FS_unindex_process_hash_, uc); + uc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, + uc->filename, + HASHING_BLOCKSIZE, + &GNUNET_FS_unindex_process_hash_, + uc); break; case UNINDEX_STATE_FS_NOTIFY: uc->state = UNINDEX_STATE_HASHING; @@ -2319,8 +2334,9 @@ deserialize_unindex_file (void *cls, if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failure while resuming unindexing operation `%s': %s\n"), - filename, emsg); + _ ("Failure while resuming unindexing operation `%s': %s\n"), + filename, + emsg); GNUNET_free (emsg); } return GNUNET_OK; @@ -2329,13 +2345,14 @@ cleanup: if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to resume unindexing operation `%s': %s\n"), + _ ("Failed to resume unindexing operation `%s': %s\n"), filename, emsg); GNUNET_free (emsg); } if (NULL != uc->serialization) - GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, + GNUNET_FS_remove_sync_file_ (h, + GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization); GNUNET_free_non_null (uc->serialization); GNUNET_free (uc); @@ -2384,8 +2401,7 @@ deserialize_search (struct GNUNET_FS_Handle *h, * @return #GNUNET_OK (continue to iterate) */ static int -deserialize_search_result (void *cls, - const char *filename) +deserialize_search_result (void *cls, const char *filename) { struct GNUNET_FS_SearchContext *sc = cls; char *ser; @@ -2405,9 +2421,10 @@ deserialize_search_result (void *cls, { remove_sync_file_in_dir (sc->h, (NULL == sc->psearch_result) - ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH - : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, - sc->serialization, ser); + ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH + : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, + sc->serialization, + ser); GNUNET_free (ser); } return GNUNET_OK; @@ -2420,15 +2437,19 @@ deserialize_search_result (void *cls, sr->h = sc->h; sr->sc = sc; sr->serialization = ser; - if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024)) - || (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) || - (GNUNET_OK != GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) - || (GNUNET_OK != - GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) || - (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) || + if ((GNUNET_OK != + GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024)) || + (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) || (GNUNET_OK != - GNUNET_BIO_read (rh, "result-key", &sr->key, sizeof (struct GNUNET_HashCode))) - || (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) || + GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) || + (GNUNET_OK != + GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) || + (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) || + (GNUNET_OK != GNUNET_BIO_read (rh, + "result-key", + &sr->key, + sizeof (struct GNUNET_HashCode))) || + (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) || (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->optional_support)) || (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_success)) || (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_trials))) @@ -2438,10 +2459,13 @@ deserialize_search_result (void *cls, } if (GNUNET_FS_URI_KSK == sr->sc->uri->type) { - sr->keyword_bitmap = GNUNET_malloc ((sr->sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */ - if (GNUNET_OK != GNUNET_BIO_read (rh, "keyword-bitmap", - sr->keyword_bitmap, - (sr->sc->uri->data.ksk.keywordCount + 7) / 8)) + sr->keyword_bitmap = GNUNET_malloc ( + (sr->sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */ + if (GNUNET_OK != + GNUNET_BIO_read (rh, + "keyword-bitmap", + sr->keyword_bitmap, + (sr->sc->uri->data.ksk.keywordCount + 7) / 8)) { GNUNET_break (0); goto cleanup; @@ -2457,7 +2481,7 @@ deserialize_search_result (void *cls, if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to resume sub-download `%s': %s\n"), + _ ("Failed to resume sub-download `%s': %s\n"), download, emsg); GNUNET_free (emsg); @@ -2468,14 +2492,14 @@ deserialize_search_result (void *cls, if (NULL != update_srch) { drh = - get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch); + get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch); if (NULL != drh) { deserialize_search (sc->h, drh, sr, update_srch); if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to resume sub-search `%s': %s\n"), + _ ("Failed to resume sub-search `%s': %s\n"), update_srch, emsg); GNUNET_free (emsg); @@ -2483,15 +2507,17 @@ deserialize_search_result (void *cls, } GNUNET_free (update_srch); } - GNUNET_break (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, - &sr->key, sr, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_multihashmap_put ( + sc->master_result_map, + &sr->key, + sr, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failure while resuming search operation `%s': %s\n"), - filename, emsg); + _ ("Failure while resuming search operation `%s': %s\n"), + filename, + emsg); GNUNET_free (emsg); } return GNUNET_OK; @@ -2509,8 +2535,9 @@ cleanup: if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failure while resuming search operation `%s': %s\n"), - filename, emsg); + _ ("Failure while resuming search operation `%s': %s\n"), + filename, + emsg); GNUNET_free (emsg); } return GNUNET_OK; @@ -2564,9 +2591,7 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc); * @return #GNUNET_YES (we should continue to iterate) */ static int -signal_result_resume (void *cls, - const struct GNUNET_HashCode *key, - void *value) +signal_result_resume (void *cls, const struct GNUNET_HashCode *key, void *value) { struct GNUNET_FS_SearchContext *sc = cls; struct GNUNET_FS_ProgressInfo pi; @@ -2579,11 +2604,11 @@ signal_result_resume (void *cls, pi.value.search.specifics.resume_result.uri = sr->uri; pi.value.search.specifics.resume_result.result = sr; pi.value.search.specifics.resume_result.availability_rank = - 2 * sr->availability_success - sr->availability_trials; + 2 * sr->availability_success - sr->availability_trials; pi.value.search.specifics.resume_result.availability_certainty = - sr->availability_trials; + sr->availability_trials; pi.value.search.specifics.resume_result.applicability_rank = - sr->optional_support; + sr->optional_support; sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); } if (NULL != sr->download) @@ -2618,9 +2643,7 @@ free_search_context (struct GNUNET_FS_SearchContext *sc); * @return #GNUNET_YES (we should continue to iterate) */ static int -free_result (void *cls, - const struct GNUNET_HashCode *key, - void *value) +free_result (void *cls, const struct GNUNET_HashCode *key, void *value) { struct GNUNET_FS_SearchResult *sr = value; @@ -2647,14 +2670,14 @@ free_search_context (struct GNUNET_FS_SearchContext *sc) if (NULL != sc->serialization) { GNUNET_FS_remove_sync_file_ (sc->h, - (sc->psearch_result == - NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH : - GNUNET_FS_SYNC_PATH_CHILD_SEARCH, + (sc->psearch_result == NULL) + ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH + : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, sc->serialization); GNUNET_FS_remove_sync_dir_ (sc->h, - (sc->psearch_result == - NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH : - GNUNET_FS_SYNC_PATH_CHILD_SEARCH, + (sc->psearch_result == NULL) + ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH + : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, sc->serialization); } GNUNET_free_non_null (sc->serialization); @@ -2663,7 +2686,8 @@ free_search_context (struct GNUNET_FS_SearchContext *sc) GNUNET_FS_uri_destroy (sc->uri); if (NULL != sc->master_result_map) { - GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, &free_result, + GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, + &free_result, sc); GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); } @@ -2680,8 +2704,7 @@ free_search_context (struct GNUNET_FS_SearchContext *sc) * @return #GNUNET_OK (continue to iterate) */ static int -deserialize_subdownload (void *cls, - const char *filename) +deserialize_subdownload (void *cls, const char *filename) { struct GNUNET_FS_DownloadContext *parent = cls; char *ser; @@ -2693,7 +2716,8 @@ deserialize_subdownload (void *cls, if (NULL == rh) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to resume sub-download `%s': could not open file `%s'\n"), + _ ( + "Failed to resume sub-download `%s': could not open file `%s'\n"), ser, filename); GNUNET_free (ser); @@ -2703,7 +2727,7 @@ deserialize_subdownload (void *cls, if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to resume sub-download `%s': %s\n"), + _ ("Failed to resume sub-download `%s': %s\n"), ser, emsg); GNUNET_free (emsg); @@ -2735,9 +2759,7 @@ free_download_context (struct GNUNET_FS_DownloadContext *dc) GNUNET_free_non_null (dc->serialization); while (NULL != (dcc = dc->child_head)) { - GNUNET_CONTAINER_DLL_remove (dc->child_head, - dc->child_tail, - dcc); + GNUNET_CONTAINER_DLL_remove (dc->child_head, dc->child_tail, dcc); free_download_context (dcc); } GNUNET_FS_free_download_request_ (dc->top_request); @@ -2781,14 +2803,16 @@ deserialize_download (struct GNUNET_FS_Handle *h, (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) && (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) || - (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) - || (GNUNET_OK != - GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) || (GNUNET_OK != - GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) || + GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) || + (GNUNET_OK != + GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) || (GNUNET_OK != - GNUNET_BIO_read_string (rh, "download-tfn", &dc->temp_filename, - 10 * 1024)) || + GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) || + (GNUNET_OK != GNUNET_BIO_read_string (rh, + "download-tfn", + &dc->temp_filename, + 10 * 1024)) || (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) || (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->offset)) || (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->length)) || @@ -2803,14 +2827,14 @@ deserialize_download (struct GNUNET_FS_Handle *h, } dc->options = (enum GNUNET_FS_DownloadOptions) options; dc->active = - GNUNET_CONTAINER_multihashmap_create (1 + 2 * (dc->length / DBLOCK_SIZE), GNUNET_NO); + GNUNET_CONTAINER_multihashmap_create (1 + 2 * (dc->length / DBLOCK_SIZE), + GNUNET_NO); dc->has_finished = (int) status; dc->treedepth = - GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri)); + GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri)); if (GNUNET_FS_uri_test_loc (dc->uri)) GNUNET_assert (GNUNET_OK == - GNUNET_FS_uri_loc_get_peer_identity (dc->uri, - &dc->target)); + GNUNET_FS_uri_loc_get_peer_identity (dc->uri, &dc->target)); if (NULL == dc->emsg) { dc->top_request = read_download_request (rh); @@ -2820,43 +2844,31 @@ deserialize_download (struct GNUNET_FS_Handle *h, goto cleanup; } } - dn = get_download_sync_filename (dc, - dc->serialization, - ".dir"); + dn = get_download_sync_filename (dc, dc->serialization, ".dir"); if (NULL != dn) { - if (GNUNET_YES == - GNUNET_DISK_directory_test (dn, - GNUNET_YES)) - GNUNET_DISK_directory_scan (dn, - &deserialize_subdownload, - dc); + if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) + GNUNET_DISK_directory_scan (dn, &deserialize_subdownload, dc); GNUNET_free (dn); } if (NULL != parent) { - GNUNET_CONTAINER_DLL_insert (parent->child_head, - parent->child_tail, - dc); + GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc); } if (NULL != search) { dc->search = search; search->download = dc; } - if ( (NULL == parent) && - (NULL == search) ) + if ((NULL == parent) && (NULL == search)) { - dc->top - = GNUNET_FS_make_top (dc->h, - &GNUNET_FS_download_signal_suspend_, - dc); + dc->top = + GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc); signal_download_resume (dc); } GNUNET_free (uris); GNUNET_assert (NULL == dc->job_queue); - dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, - dc); + dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc); return; cleanup: GNUNET_free_non_null (uris); @@ -2879,11 +2891,11 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc) pi.status = GNUNET_FS_STATUS_SEARCH_RESUME; pi.value.search.specifics.resume.message = sc->emsg; pi.value.search.specifics.resume.is_paused = - (NULL == sc->mq) ? GNUNET_YES : GNUNET_NO; + (NULL == sc->mq) ? GNUNET_YES : GNUNET_NO; sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, - &signal_result_resume, sc); - + &signal_result_resume, + sc); } @@ -2942,10 +2954,11 @@ deserialize_search (struct GNUNET_FS_Handle *h, sc->options = (enum GNUNET_FS_SearchOptions) options; sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO); dn = get_serialization_file_name_in_dir (h, - (NULL == sc->psearch_result) ? - GNUNET_FS_SYNC_PATH_MASTER_SEARCH : - GNUNET_FS_SYNC_PATH_CHILD_SEARCH, - sc->serialization, ""); + (NULL == sc->psearch_result) + ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH + : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, + sc->serialization, + ""); if (NULL != dn) { if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) @@ -2955,8 +2968,9 @@ deserialize_search (struct GNUNET_FS_Handle *h, if (('\0' == in_pause) && (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc))) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Could not resume running search, will resume as paused search\n")); + GNUNET_log ( + GNUNET_ERROR_TYPE_WARNING, + _ ("Could not resume running search, will resume as paused search\n")); } signal_search_resume (sc); GNUNET_free (uris); @@ -2978,8 +2992,7 @@ cleanup: * @return #GNUNET_OK (continue to iterate) */ static int -deserialize_search_file (void *cls, - const char *filename) +deserialize_search_file (void *cls, const char *filename) { struct GNUNET_FS_Handle *h = cls; char *ser; @@ -2988,7 +3001,7 @@ deserialize_search_file (void *cls, struct GNUNET_FS_SearchContext *sc; struct stat buf; - if (0 != STAT (filename, &buf)) + if (0 != stat (filename, &buf)) { GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); return GNUNET_OK; @@ -3013,8 +3026,9 @@ deserialize_search_file (void *cls, if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failure while resuming search operation `%s': %s\n"), - filename, emsg); + _ ("Failure while resuming search operation `%s': %s\n"), + filename, + emsg); GNUNET_free (emsg); } return GNUNET_OK; @@ -3041,7 +3055,7 @@ deserialize_download_file (void *cls, const char *filename) rh = GNUNET_BIO_read_open (filename); if (NULL == rh) { - if (0 != UNLINK (filename)) + if (0 != unlink (filename)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); GNUNET_free (ser); return GNUNET_OK; @@ -3051,8 +3065,9 @@ deserialize_download_file (void *cls, const char *filename) if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failure while resuming download operation `%s': %s\n"), - filename, emsg); + _ ("Failure while resuming download operation `%s': %s\n"), + filename, + emsg); GNUNET_free (emsg); } return GNUNET_OK; @@ -3068,7 +3083,7 @@ deserialize_download_file (void *cls, const char *filename) */ static void deserialization_master (const char *master_path, - GNUNET_FileNameCallback proc, + GNUNET_FileNameCallback proc, struct GNUNET_FS_Handle *h) { char *dn; @@ -3098,7 +3113,8 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *client_name, GNUNET_FS_ProgressCallback upcb, void *upcb_cls, - enum GNUNET_FS_Flags flags, ...) + enum GNUNET_FS_Flags flags, + ...) { struct GNUNET_FS_Handle *ret; enum GNUNET_FS_OPTIONS opt; @@ -3112,9 +3128,11 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, ret->flags = flags; ret->max_parallel_downloads = DEFAULT_MAX_PARALLEL_DOWNLOADS; ret->max_parallel_requests = DEFAULT_MAX_PARALLEL_REQUESTS; - ret->avg_block_latency = GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */ + ret->avg_block_latency = + GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */ va_start (ap, flags); - while (GNUNET_FS_OPTIONS_END != (opt = GNUNET_VA_ARG_ENUM (ap,GNUNET_FS_OPTIONS))) + while (GNUNET_FS_OPTIONS_END != + (opt = GNUNET_VA_ARG_ENUM (ap, GNUNET_FS_OPTIONS))) { switch (opt) { @@ -3138,13 +3156,17 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags)) { deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, - &deserialize_publish_file, ret); + &deserialize_publish_file, + ret); deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_SEARCH, - &deserialize_search_file, ret); + &deserialize_search_file, + ret); deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, - &deserialize_download_file, ret); + &deserialize_download_file, + ret); deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, - &deserialize_unindex_file, ret); + &deserialize_unindex_file, + ret); } return ret; } diff --git a/src/fs/fs_dirmetascan.c b/src/fs/fs_dirmetascan.c index 115f99391..dd207e2c9 100644 --- a/src/fs/fs_dirmetascan.c +++ b/src/fs/fs_dirmetascan.c @@ -80,13 +80,12 @@ struct GNUNET_FS_DirScanner /** * Task scheduled when we are done. */ - struct GNUNET_SCHEDULER_Task * stop_task; + struct GNUNET_SCHEDULER_Task *stop_task; /** * Arguments for helper. */ char *args[4]; - }; @@ -151,11 +150,9 @@ advance (struct GNUNET_FS_ShareTreeItem *pos) GNUNET_assert (NULL != pos); moved = 0; /* must not terminate, even on file, otherwise "normal" */ - while ( (pos->is_directory == GNUNET_YES) || - (0 == moved) ) + while ((pos->is_directory == GNUNET_YES) || (0 == moved)) { - if ( (moved != -1) && - (NULL != pos->children_head) ) + if ((moved != -1) && (NULL != pos->children_head)) { pos = pos->children_head; moved = 1; /* can terminate if file */ @@ -190,8 +187,8 @@ advance (struct GNUNET_FS_ShareTreeItem *pos) */ static struct GNUNET_FS_ShareTreeItem * expand_tree (struct GNUNET_FS_ShareTreeItem *parent, - const char *filename, - int is_directory) + const char *filename, + int is_directory) { struct GNUNET_FS_ShareTreeItem *chld; size_t slen; @@ -200,20 +197,19 @@ expand_tree (struct GNUNET_FS_ShareTreeItem *parent, chld->parent = parent; chld->filename = GNUNET_strdup (filename); GNUNET_asprintf (&chld->short_filename, - "%s%s", - GNUNET_STRINGS_get_short_name (filename), - is_directory == GNUNET_YES ? "/" : ""); + "%s%s", + GNUNET_STRINGS_get_short_name (filename), + is_directory == GNUNET_YES ? "/" : ""); /* make sure we do not end with '//' */ slen = strlen (chld->short_filename); - if ( (slen >= 2) && - (chld->short_filename[slen-1] == '/') && - (chld->short_filename[slen-2] == '/') ) - chld->short_filename[slen-1] = '\0'; + if ((slen >= 2) && (chld->short_filename[slen - 1] == '/') && + (chld->short_filename[slen - 2] == '/')) + chld->short_filename[slen - 1] = '\0'; chld->is_directory = is_directory; if (NULL != parent) GNUNET_CONTAINER_DLL_insert (parent->children_head, - parent->children_tail, - chld); + parent->children_tail, + chld); return chld; } @@ -235,8 +231,9 @@ finish_scan (void *cls) ds->helper = NULL; } ds->progress_callback (ds->progress_callback_cls, - NULL, GNUNET_SYSERR, - GNUNET_FS_DIRSCANNER_FINISHED); + NULL, + GNUNET_SYSERR, + GNUNET_FS_DIRSCANNER_FINISHED); } @@ -251,8 +248,7 @@ finish_scan (void *cls) * #GNUNET_SYSERR to stop further processing with error */ static int -process_helper_msgs (void *cls, - const struct GNUNET_MessageHeader *msg) +process_helper_msgs (void *cls, const struct GNUNET_MessageHeader *msg) { struct GNUNET_FS_DirScanner *ds = cls; const char *filename; @@ -265,34 +261,31 @@ process_helper_msgs (void *cls, (unsigned int) ntohs (msg->type)); #endif left = ntohs (msg->size) - sizeof (struct GNUNET_MessageHeader); - filename = (const char*) &msg[1]; + filename = (const char *) &msg[1]; switch (ntohs (msg->type)) { case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE: - if (filename[left-1] != '\0') + if (filename[left - 1] != '\0') { GNUNET_break (0); break; } ds->progress_callback (ds->progress_callback_cls, - filename, GNUNET_NO, - GNUNET_FS_DIRSCANNER_FILE_START); + filename, + GNUNET_NO, + GNUNET_FS_DIRSCANNER_FILE_START); if (NULL == ds->toplevel) { - ds->toplevel = expand_tree (ds->pos, - filename, - GNUNET_NO); + ds->toplevel = expand_tree (ds->pos, filename, GNUNET_NO); } else { GNUNET_assert (NULL != ds->pos); - (void) expand_tree (ds->pos, - filename, - GNUNET_NO); + (void) expand_tree (ds->pos, filename, GNUNET_NO); } return GNUNET_OK; case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY: - if (filename[left-1] != '\0') + if (filename[left - 1] != '\0') { GNUNET_break (0); break; @@ -301,29 +294,29 @@ process_helper_msgs (void *cls, { if (NULL == ds->pos) { - GNUNET_break (0); - break; + GNUNET_break (0); + break; } ds->pos = ds->pos->parent; return GNUNET_OK; } ds->progress_callback (ds->progress_callback_cls, - filename, GNUNET_YES, - GNUNET_FS_DIRSCANNER_FILE_START); - ds->pos = expand_tree (ds->pos, - filename, - GNUNET_YES); + filename, + GNUNET_YES, + GNUNET_FS_DIRSCANNER_FILE_START); + ds->pos = expand_tree (ds->pos, filename, GNUNET_YES); if (NULL == ds->toplevel) ds->toplevel = ds->pos; return GNUNET_OK; case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR: break; case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE: - if ('\0' != filename[left-1]) + if ('\0' != filename[left - 1]) break; ds->progress_callback (ds->progress_callback_cls, - filename, GNUNET_SYSERR, - GNUNET_FS_DIRSCANNER_FILE_IGNORED); + filename, + GNUNET_SYSERR, + GNUNET_FS_DIRSCANNER_FILE_IGNORED); return GNUNET_OK; case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE: if (0 != left) @@ -334,65 +327,66 @@ process_helper_msgs (void *cls, if (NULL == ds->toplevel) break; ds->progress_callback (ds->progress_callback_cls, - NULL, GNUNET_SYSERR, - GNUNET_FS_DIRSCANNER_ALL_COUNTED); + NULL, + GNUNET_SYSERR, + GNUNET_FS_DIRSCANNER_ALL_COUNTED); ds->pos = ds->toplevel; if (GNUNET_YES == ds->pos->is_directory) ds->pos = advance (ds->pos); return GNUNET_OK; - case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA: - { - size_t nlen; - const char *end; + case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA: { + size_t nlen; + const char *end; - if (NULL == ds->pos) - { - GNUNET_break (0); - break; - } - end = memchr (filename, 0, left); - if (NULL == end) - { - GNUNET_break (0); - break; - } - end++; - nlen = end - filename; - left -= nlen; - if (0 != strcmp (filename, - ds->pos->filename)) - { - GNUNET_break (0); - break; - } - ds->progress_callback (ds->progress_callback_cls, - filename, - GNUNET_YES, - GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED); - if (0 < left) + if (NULL == ds->pos) + { + GNUNET_break (0); + break; + } + end = memchr (filename, 0, left); + if (NULL == end) + { + GNUNET_break (0); + break; + } + end++; + nlen = end - filename; + left -= nlen; + if (0 != strcmp (filename, ds->pos->filename)) + { + GNUNET_break (0); + break; + } + ds->progress_callback (ds->progress_callback_cls, + filename, + GNUNET_YES, + GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED); + if (0 < left) + { + ds->pos->meta = GNUNET_CONTAINER_meta_data_deserialize (end, left); + if (NULL == ds->pos->meta) { - ds->pos->meta = GNUNET_CONTAINER_meta_data_deserialize (end, - left); - if (NULL == ds->pos->meta) - { - GNUNET_break (0); - break; - } - /* having full filenames is too dangerous; always make sure we clean them up */ - GNUNET_CONTAINER_meta_data_delete (ds->pos->meta, - EXTRACTOR_METATYPE_FILENAME, - NULL, 0); - /* instead, put in our 'safer' original filename */ - GNUNET_CONTAINER_meta_data_insert (ds->pos->meta, "", - EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, - EXTRACTOR_METAFORMAT_UTF8, "text/plain", - ds->pos->short_filename, - strlen (ds->pos->short_filename) + 1); + GNUNET_break (0); + break; } - ds->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data (ds->pos->meta); - ds->pos = advance (ds->pos); - return GNUNET_OK; + /* having full filenames is too dangerous; always make sure we clean them up */ + GNUNET_CONTAINER_meta_data_delete (ds->pos->meta, + EXTRACTOR_METATYPE_FILENAME, + NULL, + 0); + /* instead, put in our 'safer' original filename */ + GNUNET_CONTAINER_meta_data_insert (ds->pos->meta, + "", + EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, + EXTRACTOR_METAFORMAT_UTF8, + "text/plain", + ds->pos->short_filename, + strlen (ds->pos->short_filename) + 1); } + ds->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data (ds->pos->meta); + ds->pos = advance (ds->pos); + return GNUNET_OK; + } case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED: if (NULL != ds->pos) { @@ -406,16 +400,16 @@ process_helper_msgs (void *cls, } if (NULL == ds->toplevel) break; - ds->stop_task = GNUNET_SCHEDULER_add_now (&finish_scan, - ds); + ds->stop_task = GNUNET_SCHEDULER_add_now (&finish_scan, ds); return GNUNET_OK; default: GNUNET_break (0); break; } ds->progress_callback (ds->progress_callback_cls, - NULL, GNUNET_SYSERR, - GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); + NULL, + GNUNET_SYSERR, + GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); return GNUNET_OK; } @@ -434,8 +428,9 @@ helper_died_cb (void *cls) if (NULL != ds->stop_task) return; /* normal death, was finished */ ds->progress_callback (ds->progress_callback_cls, - NULL, GNUNET_SYSERR, - GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); + NULL, + GNUNET_SYSERR, + GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); } @@ -452,22 +447,23 @@ helper_died_cb (void *cls) */ struct GNUNET_FS_DirScanner * GNUNET_FS_directory_scan_start (const char *filename, - int disable_extractor, const char *ex, - GNUNET_FS_DirScannerProgressCallback cb, - void *cb_cls) + int disable_extractor, + const char *ex, + GNUNET_FS_DirScannerProgressCallback cb, + void *cb_cls) { struct stat sbuf; char *filename_expanded; struct GNUNET_FS_DirScanner *ds; - if (0 != STAT (filename, &sbuf)) + if (0 != stat (filename, &sbuf)) return NULL; filename_expanded = GNUNET_STRINGS_filename_expand (filename); if (NULL == filename_expanded) return NULL; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting to scan directory `%s'\n", - filename_expanded); + "Starting to scan directory `%s'\n", + filename_expanded); ds = GNUNET_new (struct GNUNET_FS_DirScanner); ds->progress_callback = cb; ds->progress_callback_cls = cb_cls; @@ -481,12 +477,13 @@ GNUNET_FS_directory_scan_start (const char *filename, ds->args[2] = ds->ex_arg; ds->args[3] = NULL; ds->helper = GNUNET_HELPER_start (GNUNET_NO, - "gnunet-helper-fs-publish", - ds->args, - &process_helper_msgs, - &helper_died_cb, ds); + "gnunet-helper-fs-publish", + ds->args, + &process_helper_msgs, + &helper_died_cb, + ds); if (NULL == ds->helper) - { + { GNUNET_free (filename_expanded); GNUNET_free (ds); return NULL; diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index 2d64bba11..59821f8a5 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c @@ -37,15 +37,13 @@ static int is_recursive_download (struct GNUNET_FS_DownloadContext *dc) { return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) && - ( (GNUNET_YES == - GNUNET_FS_meta_data_test_for_directory (dc->meta)) || - ( (NULL == dc->meta) && - ( (NULL == dc->filename) || - ( (strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && - (NULL != - strstr (dc->filename + strlen (dc->filename) - - strlen (GNUNET_FS_DIRECTORY_EXT), - GNUNET_FS_DIRECTORY_EXT)) ) ) ) ); + ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (dc->meta)) || + ((NULL == dc->meta) && + ((NULL == dc->filename) || + ((strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && + (NULL != strstr (dc->filename + strlen (dc->filename) - + strlen (GNUNET_FS_DIRECTORY_EXT), + GNUNET_FS_DIRECTORY_EXT)))))); } @@ -69,9 +67,9 @@ static uint64_t compute_disk_offset (uint64_t fsize, uint64_t off, unsigned int depth) { unsigned int i; - uint64_t lsize; /* what is the size of all IBlocks for depth "i"? */ - uint64_t loff; /* where do IBlocks for depth "i" start? */ - unsigned int ioff; /* which IBlock corresponds to "off" at depth "i"? */ + uint64_t lsize; /* what is the size of all IBlocks for depth "i"? */ + uint64_t loff; /* where do IBlocks for depth "i" start? */ + unsigned int ioff; /* which IBlock corresponds to "off" at depth "i"? */ if (0 == depth) return off; @@ -79,8 +77,7 @@ compute_disk_offset (uint64_t fsize, uint64_t off, unsigned int depth) * to full DBLOCK_SIZE */ loff = ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * DBLOCK_SIZE; lsize = - ((fsize + DBLOCK_SIZE - - 1) / DBLOCK_SIZE) * sizeof (struct ContentHashKey); + ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * sizeof (struct ContentHashKey); GNUNET_assert (0 == (off % DBLOCK_SIZE)); ioff = (off / DBLOCK_SIZE); for (i = 1; i < depth; i++) @@ -109,19 +106,19 @@ GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi, pi->value.download.dc = dc; pi->value.download.cctx = dc->client_info; pi->value.download.pctx = - (NULL == dc->parent) ? NULL : dc->parent->client_info; + (NULL == dc->parent) ? NULL : dc->parent->client_info; pi->value.download.sctx = - (NULL == dc->search) ? NULL : dc->search->client_info; + (NULL == dc->search) ? NULL : dc->search->client_info; pi->value.download.uri = dc->uri; pi->value.download.filename = dc->filename; pi->value.download.size = dc->length; /* FIXME: Fix duration calculation to account for pauses */ pi->value.download.duration = - GNUNET_TIME_absolute_get_duration (dc->start_time); + GNUNET_TIME_absolute_get_duration (dc->start_time); pi->value.download.completed = dc->completed; pi->value.download.anonymity = dc->anonymity; pi->value.download.eta = - GNUNET_TIME_calculate_eta (dc->start_time, dc->completed, dc->length); + GNUNET_TIME_calculate_eta (dc->start_time, dc->completed, dc->length); pi->value.download.is_active = (NULL == dc->mq) ? GNUNET_NO : GNUNET_YES; pi->fsh = dc->h; if (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) @@ -181,7 +178,6 @@ struct ProcessResultClosure * how often did we transmit the query? */ uint32_t num_transmissions; - }; @@ -196,7 +192,7 @@ struct ProcessResultClosure */ static int process_result_with_request (void *cls, - const struct GNUNET_HashCode * key, + const struct GNUNET_HashCode *key, void *value); @@ -216,8 +212,10 @@ process_result_with_request (void *cls, static int encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc, const struct ContentHashKey *chk, - struct DownloadRequest *dr, const char *block, - size_t len, int do_store) + struct DownloadRequest *dr, + const char *block, + size_t len, + int do_store) { struct ProcessResultClosure prc; char enc[len]; @@ -237,17 +235,18 @@ encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc, GNUNET_break_op (0); return GNUNET_SYSERR; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Matching %u byte block for `%s' at offset %llu already present, no need for download!\n", - (unsigned int) len, - dc->filename, (unsigned long long) dr->offset); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Matching %u byte block for `%s' at offset %llu already present, no need for download!\n", + (unsigned int) len, + dc->filename, + (unsigned long long) dr->offset); /* already got it! */ prc.dc = dc; prc.data = enc; prc.size = len; - prc.type = - (0 == - dr->depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK : GNUNET_BLOCK_TYPE_FS_IBLOCK; + prc.type = (0 == dr->depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK + : GNUNET_BLOCK_TYPE_FS_IBLOCK; prc.query = chk->query; prc.do_store = do_store; prc.last_transmission = GNUNET_TIME_UNIT_FOREVER_ABS; @@ -306,8 +305,10 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc) size = (size_t) size64; if (size64 != (uint64_t) size) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n")); + GNUNET_log ( + GNUNET_ERROR_TYPE_ERROR, + _ ( + "Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n")); return; } if (NULL != dc->filename) @@ -324,15 +325,12 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc) GNUNET_DISK_PERM_NONE); } if (NULL == h) - return; /* oops */ - data = GNUNET_DISK_file_map (h, - &m, - GNUNET_DISK_MAP_TYPE_READ, - size); + return; /* oops */ + data = GNUNET_DISK_file_map (h, &m, GNUNET_DISK_MAP_TYPE_READ, size); if (NULL == data) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Directory too large for system address space\n")); + _ ("Directory too large for system address space\n")); } else { @@ -343,16 +341,18 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc) &trigger_recursive_download, dc)) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to access full directroy contents of `%s' for recursive download\n"), - dc->filename); + GNUNET_log ( + GNUNET_ERROR_TYPE_WARNING, + _ ( + "Failed to access full directroy contents of `%s' for recursive download\n"), + dc->filename); } GNUNET_DISK_file_unmap (m); } GNUNET_DISK_file_close (h); if (NULL == dc->filename) { - if (0 != UNLINK (dc->temp_filename)) + if (0 != unlink (dc->temp_filename)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", dc->temp_filename); @@ -384,12 +384,10 @@ check_completed (struct GNUNET_FS_DownloadContext *dc) /* then, check if children are done already */ for (pos = dc->child_head; NULL != pos; pos = pos->next) { - if ( (NULL == pos->emsg) && - (pos->completed < pos->length) ) - return; /* not done yet */ - if ( (NULL != pos->child_head) && - (pos->has_finished != GNUNET_YES) ) - return; /* not transitively done yet */ + if ((NULL == pos->emsg) && (pos->completed < pos->length)) + return; /* not done yet */ + if ((NULL != pos->child_head) && (pos->has_finished != GNUNET_YES)) + return; /* not transitively done yet */ } /* All of our children are done, so mark this download done */ dc->has_finished = GNUNET_YES; @@ -432,7 +430,9 @@ check_completed (struct GNUNET_FS_DownloadContext *dc) */ static void try_match_block (struct GNUNET_FS_DownloadContext *dc, - struct DownloadRequest *dr, const char *data, size_t data_len) + struct DownloadRequest *dr, + const char *data, + size_t data_len) { struct GNUNET_FS_ProgressInfo pi; unsigned int i; @@ -455,8 +455,8 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, return; if (dr->depth > 0) { - if ( (dc->offset > 0) || - (dc->length < GNUNET_ntohll (dc->uri->data.chk.file_length)) ) + if ((dc->offset > 0) || + (dc->length < GNUNET_ntohll (dc->uri->data.chk.file_length))) { /* NOTE: this test is not tight, but should suffice; the issue here is that 'dr->num_children' may inherently only specify a @@ -485,16 +485,13 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, else { if (dr->offset > data_len) - return; /* oops */ + return; /* oops */ dlen = GNUNET_MIN (data_len - dr->offset, DBLOCK_SIZE); } GNUNET_CRYPTO_hash (&data[dr->offset], dlen, &in_chk.key); GNUNET_CRYPTO_hash_to_aes_key (&in_chk.key, &sk, &iv); - if (-1 == GNUNET_CRYPTO_symmetric_encrypt (&data[dr->offset], - dlen, - &sk, - &iv, - enc)) + if (-1 == + GNUNET_CRYPTO_symmetric_encrypt (&data[dr->offset], dlen, &sk, &iv, enc)) { GNUNET_break (0); return; @@ -507,9 +504,7 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, dr->state = BRS_RECONSTRUCT_META_UP; break; case BRS_CHK_SET: - if (0 != memcmp (&in_chk, - &dr->chk, - sizeof (struct ContentHashKey))) + if (0 != memcmp (&in_chk, &dr->chk, sizeof (struct ContentHashKey))) { /* other peer provided bogus meta data */ GNUNET_break_op (0); @@ -521,17 +516,17 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, { fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READWRITE | - GNUNET_DISK_OPEN_CREATE | - GNUNET_DISK_OPEN_TRUNCATE, + GNUNET_DISK_OPEN_CREATE | + GNUNET_DISK_OPEN_TRUNCATE, GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE | - GNUNET_DISK_PERM_GROUP_READ | - GNUNET_DISK_PERM_OTHER_READ); + GNUNET_DISK_PERM_USER_WRITE | + GNUNET_DISK_PERM_GROUP_READ | + GNUNET_DISK_PERM_OTHER_READ); if (NULL == fh) { GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn); GNUNET_asprintf (&dc->emsg, - _("Failed to open file `%s' for writing"), + _ ("Failed to open file `%s' for writing"), fn); GNUNET_DISK_file_close (fh); dr->state = BRS_ERROR; @@ -543,7 +538,8 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, if (data_len != GNUNET_DISK_file_write (fh, odata, odata_len)) { GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn); - GNUNET_asprintf (&dc->emsg, _("Failed to open file `%s' for writing"), + GNUNET_asprintf (&dc->emsg, + _ ("Failed to open file `%s' for writing"), fn); GNUNET_DISK_file_close (fh); dr->state = BRS_ERROR; @@ -564,13 +560,14 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, pi.value.download.specifics.progress.data_len = dlen; pi.value.download.specifics.progress.depth = 0; pi.value.download.specifics.progress.respect_offered = 0; - pi.value.download.specifics.progress.block_download_duration = GNUNET_TIME_UNIT_ZERO; + pi.value.download.specifics.progress.block_download_duration = + GNUNET_TIME_UNIT_ZERO; GNUNET_FS_download_make_status_ (&pi, dc); if ((NULL != dc->filename) && - (0 != - TRUNCATE (dc->filename, - GNUNET_ntohll (dc->uri->data.chk.file_length)))) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "truncate", + (0 != truncate (dc->filename, + GNUNET_ntohll (dc->uri->data.chk.file_length)))) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, + "truncate", dc->filename); check_completed (dc); break; @@ -601,25 +598,27 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, * @return 0 to continue extracting, 1 to abort */ static int -match_full_data (void *cls, const char *plugin_name, - enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, - const char *data_mime_type, const char *data, size_t data_len) +match_full_data (void *cls, + const char *plugin_name, + enum EXTRACTOR_MetaType type, + enum EXTRACTOR_MetaFormat format, + const char *data_mime_type, + const char *data, + size_t data_len) { struct GNUNET_FS_DownloadContext *dc = cls; if (EXTRACTOR_METATYPE_GNUNET_FULL_DATA != type) return 0; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u bytes of FD!\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Found %u bytes of FD!\n", (unsigned int) data_len); if (GNUNET_FS_uri_chk_get_file_size (dc->uri) != data_len) { GNUNET_break_op (0); - return 1; /* bogus meta data */ + return 1; /* bogus meta data */ } - try_match_block (dc, - dc->top_request, - data, - data_len); + try_match_block (dc, dc->top_request, data, data_len); return 1; } @@ -644,8 +643,7 @@ propagate_up (struct DownloadRequest *dr) for (i = 0; i < dr->num_children; i++) if (dr->children[i]->state != BRS_DOWNLOAD_UP) break; - } - while (i == dr->num_children); + } while (i == dr->num_children); } @@ -682,20 +680,20 @@ try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc, GNUNET_assert (len <= DBLOCK_SIZE); off = compute_disk_offset (total, dr->offset, dr->depth); if (dc->old_file_size < off + len) - return; /* failure */ + return; /* failure */ if (off != GNUNET_DISK_file_seek (dc->rfh, off, GNUNET_DISK_SEEK_SET)) { GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "seek", dc->filename); - return; /* failure */ + return; /* failure */ } if (len != GNUNET_DISK_file_read (dc->rfh, block, len)) { GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", dc->filename); - return; /* failure */ + return; /* failure */ } GNUNET_CRYPTO_hash (block, len, &key); if (0 != memcmp (&key, &dr->chk.key, sizeof (struct GNUNET_HashCode))) - return; /* mismatch */ + return; /* mismatch */ if (GNUNET_OK != encrypt_existing_match (dc, &dr->chk, dr, block, len, GNUNET_NO)) { @@ -728,10 +726,10 @@ try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc, try_top_down_reconstruction (dc, drc); } if (BRS_DOWNLOAD_UP != drc->state) - up_done = GNUNET_NO; /* children not all done */ + up_done = GNUNET_NO; /* children not all done */ } if (GNUNET_YES == up_done) - propagate_up (dr); /* children all done (or no children...) */ + propagate_up (dr); /* children all done (or no children...) */ } @@ -744,17 +742,14 @@ try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc, * @return #GNUNET_OK */ static int -retry_entry (void *cls, - const struct GNUNET_HashCode *key, - void *entry) +retry_entry (void *cls, const struct GNUNET_HashCode *key, void *entry) { struct GNUNET_FS_DownloadContext *dc = cls; struct DownloadRequest *dr = entry; struct SearchMessage *sm; struct GNUNET_MQ_Envelope *env; - env = GNUNET_MQ_msg (sm, - GNUNET_MESSAGE_TYPE_FS_START_SEARCH); + env = GNUNET_MQ_msg (sm, GNUNET_MESSAGE_TYPE_FS_START_SEARCH); if (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY)) sm->options = htonl (GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY); else @@ -766,8 +761,7 @@ retry_entry (void *cls, sm->anonymity_level = htonl (dc->anonymity); sm->target = dc->target; sm->query = dr->chk.query; - GNUNET_MQ_send (dc->mq, - env); + GNUNET_MQ_send (dc->mq, env); return GNUNET_OK; } @@ -817,20 +811,17 @@ schedule_block_download (struct GNUNET_FS_DownloadContext *dc, (unsigned long long) dr->offset, dr->depth, GNUNET_h2s (&dr->chk.query)); - if (GNUNET_NO != - GNUNET_CONTAINER_multihashmap_contains_value (dc->active, - &dr->chk.query, - dr)) - return; /* already active */ + if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains_value (dc->active, + &dr->chk.query, + dr)) + return; /* already active */ GNUNET_CONTAINER_multihashmap_put (dc->active, &dr->chk.query, dr, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); if (NULL == dc->mq) - return; /* download not active */ - retry_entry (dc, - &dr->chk.query, - dr); + return; /* download not active */ + retry_entry (dc, &dr->chk.query, dr); } @@ -867,7 +858,7 @@ trigger_recursive_download (void *cls, char *sfn; if (NULL == uri) - return; /* entry for the directory itself */ + return; /* entry for the directory itself */ cpos = dc->child_head; while (NULL != cpos) { @@ -877,7 +868,7 @@ trigger_recursive_download (void *cls, cpos = cpos->next; } if (NULL != cpos) - return; /* already exists */ + return; /* already exists */ fn = NULL; if (NULL == filename) { @@ -892,7 +883,9 @@ trigger_recursive_download (void *cls, { ext = fn; us = GNUNET_FS_uri_to_string (uri); - GNUNET_asprintf (&fn, "%s%s", &us[strlen (GNUNET_FS_URI_CHK_PREFIX)], + GNUNET_asprintf (&fn, + "%s%s", + &us[strlen (GNUNET_FS_URI_CHK_PREFIX)], ext); GNUNET_free (ext); GNUNET_free (us); @@ -920,25 +913,28 @@ trigger_recursive_download (void *cls, else { dn = GNUNET_strdup (dc->filename); - GNUNET_break ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && - (NULL != - strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT), - GNUNET_FS_DIRECTORY_EXT))); + GNUNET_break ( + (strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && + (NULL != strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT), + GNUNET_FS_DIRECTORY_EXT))); sfn = GNUNET_strdup (filename); while ((strlen (sfn) > 0) && ('/' == filename[strlen (sfn) - 1])) sfn[strlen (sfn) - 1] = '\0'; if ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && - (NULL != - strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT), - GNUNET_FS_DIRECTORY_EXT))) + (NULL != strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT), + GNUNET_FS_DIRECTORY_EXT))) dn[strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT)] = '\0'; if ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) && ((strlen (filename) < strlen (GNUNET_FS_DIRECTORY_EXT)) || - (NULL == - strstr (filename + strlen (filename) - - strlen (GNUNET_FS_DIRECTORY_EXT), GNUNET_FS_DIRECTORY_EXT)))) + (NULL == strstr (filename + strlen (filename) - + strlen (GNUNET_FS_DIRECTORY_EXT), + GNUNET_FS_DIRECTORY_EXT)))) { - GNUNET_asprintf (&full_name, "%s%s%s%s", dn, DIR_SEPARATOR_STR, sfn, + GNUNET_asprintf (&full_name, + "%s%s%s%s", + dn, + DIR_SEPARATOR_STR, + sfn, GNUNET_FS_DIRECTORY_EXT); } else @@ -952,8 +948,8 @@ trigger_recursive_download (void *cls, (GNUNET_OK != GNUNET_DISK_directory_create_for_file (full_name))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ - ("Failed to create directory for recursive download of `%s'\n"), + _ ( + "Failed to create directory for recursive download of `%s'\n"), full_name); GNUNET_free (full_name); GNUNET_free_non_null (fn); @@ -964,8 +960,8 @@ trigger_recursive_download (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Triggering recursive download of size %llu with %u bytes MD\n", (unsigned long long) GNUNET_FS_uri_chk_get_file_size (uri), - (unsigned int) - GNUNET_CONTAINER_meta_data_get_serialized_size (meta)); + (unsigned int) GNUNET_CONTAINER_meta_data_get_serialized_size ( + meta)); GNUNET_FS_download_start (dc->h, uri, meta, @@ -1029,26 +1025,29 @@ process_result_with_request (void *cls, int i; struct ContentHashKey *chkarr; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received %u byte block `%s' matching pending request at depth %u and offset %llu/%llu\n", - (unsigned int) prc->size, - GNUNET_h2s (key), - dr->depth, - (unsigned long long) dr->offset, - (unsigned long long) GNUNET_ntohll (dc->uri->data. - chk.file_length)); - bs = GNUNET_FS_tree_calculate_block_size (GNUNET_ntohll - (dc->uri->data.chk.file_length), - dr->offset, dr->depth); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Received %u byte block `%s' matching pending request at depth %u and offset %llu/%llu\n", + (unsigned int) prc->size, + GNUNET_h2s (key), + dr->depth, + (unsigned long long) dr->offset, + (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length)); + bs = GNUNET_FS_tree_calculate_block_size (GNUNET_ntohll ( + dc->uri->data.chk.file_length), + dr->offset, + dr->depth); if (prc->size != bs) { - GNUNET_asprintf (&dc->emsg, - _ - ("Internal error or bogus download URI (expected %u bytes at depth %u and offset %llu/%llu, got %u bytes)"), - bs, dr->depth, (unsigned long long) dr->offset, - (unsigned long long) GNUNET_ntohll (dc->uri->data. - chk.file_length), - prc->size); + GNUNET_asprintf ( + &dc->emsg, + _ ( + "Internal error or bogus download URI (expected %u bytes at depth %u and offset %llu/%llu, got %u bytes)"), + bs, + dr->depth, + (unsigned long long) dr->offset, + (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length), + prc->size); GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", dc->emsg); while (NULL != dr->parent) { @@ -1059,69 +1058,61 @@ process_result_with_request (void *cls, goto signal_error; } - (void) GNUNET_CONTAINER_multihashmap_remove (dc->active, - &prc->query, - dr); - GNUNET_CRYPTO_hash_to_aes_key (&dr->chk.key, - &skey, - &iv); - if (-1 == GNUNET_CRYPTO_symmetric_decrypt (prc->data, - prc->size, - &skey, - &iv, - pt)) + (void) GNUNET_CONTAINER_multihashmap_remove (dc->active, &prc->query, dr); + GNUNET_CRYPTO_hash_to_aes_key (&dr->chk.key, &skey, &iv); + if (-1 == + GNUNET_CRYPTO_symmetric_decrypt (prc->data, prc->size, &skey, &iv, pt)) { GNUNET_break (0); - dc->emsg = GNUNET_strdup (_("internal error decrypting content")); + dc->emsg = GNUNET_strdup (_ ("internal error decrypting content")); goto signal_error; } - off = - compute_disk_offset (GNUNET_ntohll (dc->uri->data.chk.file_length), - dr->offset, - dr->depth); + off = compute_disk_offset (GNUNET_ntohll (dc->uri->data.chk.file_length), + dr->offset, + dr->depth); /* save to disk */ if ((GNUNET_YES == prc->do_store) && ((NULL != dc->filename) || (is_recursive_download (dc))) && ((dr->depth == dc->treedepth) || (0 == (dc->options & GNUNET_FS_DOWNLOAD_NO_TEMPORARIES)))) { - fh = GNUNET_DISK_file_open (NULL != dc->filename - ? dc->filename : dc->temp_filename, + fh = GNUNET_DISK_file_open (NULL != dc->filename ? dc->filename + : dc->temp_filename, GNUNET_DISK_OPEN_READWRITE | - GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE | - GNUNET_DISK_PERM_GROUP_READ | - GNUNET_DISK_PERM_OTHER_READ); + GNUNET_DISK_PERM_USER_WRITE | + GNUNET_DISK_PERM_GROUP_READ | + GNUNET_DISK_PERM_OTHER_READ); if (NULL == fh) { GNUNET_asprintf (&dc->emsg, - _("Download failed: could not open file `%s': %s"), - dc->filename, STRERROR (errno)); + _ ("Download failed: could not open file `%s': %s"), + dc->filename, + strerror (errno)); goto signal_error; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Saving decrypted block to disk at offset %llu\n", (unsigned long long) off); - if ((off != GNUNET_DISK_file_seek (fh, - off, - GNUNET_DISK_SEEK_SET))) + if ((off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET))) { GNUNET_asprintf (&dc->emsg, - _("Failed to seek to offset %llu in file `%s': %s"), + _ ("Failed to seek to offset %llu in file `%s': %s"), (unsigned long long) off, dc->filename, - STRERROR (errno)); + strerror (errno)); goto signal_error; } if (prc->size != GNUNET_DISK_file_write (fh, pt, prc->size)) { - GNUNET_asprintf (&dc->emsg, - _("Failed to write block of %u bytes at offset %llu in file `%s': %s"), - (unsigned int) prc->size, - (unsigned long long) off, - dc->filename, - STRERROR (errno)); + GNUNET_asprintf ( + &dc->emsg, + _ ("Failed to write block of %u bytes at offset %llu in file `%s': %s"), + (unsigned int) prc->size, + (unsigned long long) off, + dc->filename, + strerror (errno)); goto signal_error; } GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh)); @@ -1153,8 +1144,11 @@ process_result_with_request (void *cls, * says it is a directory or if no meta data is given AND filename * ends in '.gnd' (top-level case) */ if (is_recursive_download (dc)) - GNUNET_FS_directory_list_contents (prc->size, pt, off, - &trigger_recursive_download, dc); + GNUNET_FS_directory_list_contents (prc->size, + pt, + off, + &trigger_recursive_download, + dc); } GNUNET_assert (dc->completed <= dc->length); dr->state = BRS_DOWNLOAD_DOWN; @@ -1164,13 +1158,15 @@ process_result_with_request (void *cls, pi.value.download.specifics.progress.data_len = prc->size; pi.value.download.specifics.progress.depth = dr->depth; pi.value.download.specifics.progress.respect_offered = prc->respect_offered; - pi.value.download.specifics.progress.num_transmissions = prc->num_transmissions; - if (prc->last_transmission.abs_value_us != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) - pi.value.download.specifics.progress.block_download_duration - = GNUNET_TIME_absolute_get_duration (prc->last_transmission); + pi.value.download.specifics.progress.num_transmissions = + prc->num_transmissions; + if (prc->last_transmission.abs_value_us != + GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) + pi.value.download.specifics.progress.block_download_duration = + GNUNET_TIME_absolute_get_duration (prc->last_transmission); else - pi.value.download.specifics.progress.block_download_duration - = GNUNET_TIME_UNIT_ZERO; /* found locally */ + pi.value.download.specifics.progress.block_download_duration = + GNUNET_TIME_UNIT_ZERO; /* found locally */ GNUNET_FS_download_make_status_ (&pi, dc); if (0 == dr->depth) propagate_up (dr); @@ -1180,15 +1176,15 @@ process_result_with_request (void *cls, /* download completed, signal */ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download completed, truncating file to desired length %llu\n", - (unsigned long long) GNUNET_ntohll (dc->uri->data. - chk.file_length)); + (unsigned long long) GNUNET_ntohll ( + dc->uri->data.chk.file_length)); /* truncate file to size (since we store IBlocks at the end) */ if (NULL != dc->filename) { - if (0 != - TRUNCATE (dc->filename, - GNUNET_ntohll (dc->uri->data.chk.file_length))) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "truncate", + if (0 != truncate (dc->filename, + GNUNET_ntohll (dc->uri->data.chk.file_length))) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, + "truncate", dc->filename); } GNUNET_assert (0 == dr->depth); @@ -1201,9 +1197,11 @@ process_result_with_request (void *cls, return GNUNET_YES; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Triggering downloads of children (this block was at depth %u and offset %llu)\n", - dr->depth, (unsigned long long) dr->offset); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Triggering downloads of children (this block was at depth %u and offset %llu)\n", + dr->depth, + (unsigned long long) dr->offset); GNUNET_assert (0 == (prc->size % sizeof (struct ContentHashKey))); chkarr = (struct ContentHashKey *) pt; for (i = dr->num_children - 1; i >= 0; i--) @@ -1214,16 +1212,17 @@ process_result_with_request (void *cls, case BRS_INIT: if ((drc->chk_idx + 1) * sizeof (struct ContentHashKey) > prc->size) { - /* 'chkarr' does not have enough space for this chk_idx; + /* 'chkarr' does not have enough space for this chk_idx; internal error! */ - GNUNET_break (0); GNUNET_assert (0); - dc->emsg = GNUNET_strdup (_("internal error decoding tree")); - goto signal_error; + GNUNET_break (0); + GNUNET_assert (0); + dc->emsg = GNUNET_strdup (_ ("internal error decoding tree")); + goto signal_error; } drc->chk = chkarr[drc->chk_idx]; drc->state = BRS_CHK_SET; if (GNUNET_YES == dc->issue_requests) - schedule_block_download (dc, drc); + schedule_block_download (dc, drc); break; case BRS_RECONSTRUCT_DOWN: GNUNET_assert (0); @@ -1282,8 +1281,7 @@ signal_error: * @param msg message received */ static int -check_put (void *cls, - const struct ClientPutMessage *cm) +check_put (void *cls, const struct ClientPutMessage *cm) { /* any varsize length is OK */ return GNUNET_OK; @@ -1298,8 +1296,7 @@ check_put (void *cls, * @param msg message received */ static void -handle_put (void *cls, - const struct ClientPutMessage *cm) +handle_put (void *cls, const struct ClientPutMessage *cm) { struct GNUNET_FS_DownloadContext *dc = cls; uint16_t msize = ntohs (cm->header.size) - sizeof (*cm); @@ -1313,9 +1310,7 @@ handle_put (void *cls, prc.do_store = GNUNET_YES; prc.respect_offered = ntohl (cm->respect_offered); prc.num_transmissions = ntohl (cm->num_transmissions); - GNUNET_CRYPTO_hash (prc.data, - msize, - &prc.query); + GNUNET_CRYPTO_hash (prc.data, msize, &prc.query); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received result for query `%s' from FS service\n", GNUNET_h2s (&prc.query)); @@ -1335,8 +1330,7 @@ handle_put (void *cls, * @param error error code */ static void -download_mq_error_handler (void *cls, - enum GNUNET_MQ_Error error) +download_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) { struct GNUNET_FS_DownloadContext *dc = cls; @@ -1360,13 +1354,12 @@ static void do_reconnect (void *cls) { struct GNUNET_FS_DownloadContext *dc = cls; - struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_var_size (put, - GNUNET_MESSAGE_TYPE_FS_PUT, - struct ClientPutMessage, - dc), - GNUNET_MQ_handler_end () - }; + struct GNUNET_MQ_MessageHandler handlers[] = + {GNUNET_MQ_hd_var_size (put, + GNUNET_MESSAGE_TYPE_FS_PUT, + struct ClientPutMessage, + dc), + GNUNET_MQ_handler_end ()}; dc->task = NULL; dc->mq = GNUNET_CLIENT_connect (dc->h->cfg, @@ -1377,13 +1370,12 @@ do_reconnect (void *cls) if (NULL == dc->mq) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Connecting to `%s'-service failed, will try again.\n", "FS"); + "Connecting to `%s'-service failed, will try again.\n", + "FS"); try_reconnect (dc); return; } - GNUNET_CONTAINER_multihashmap_iterate (dc->active, - &retry_entry, - dc); + GNUNET_CONTAINER_multihashmap_iterate (dc->active, &retry_entry, dc); } @@ -1411,13 +1403,11 @@ try_reconnect (struct GNUNET_FS_DownloadContext *dc) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Will try to reconnect in %s\n", - GNUNET_STRINGS_relative_time_to_string (dc->reconnect_backoff, + GNUNET_STRINGS_relative_time_to_string (dc->reconnect_backoff, GNUNET_YES)); GNUNET_break (NULL != dc->job_queue); dc->task = - GNUNET_SCHEDULER_add_delayed (dc->reconnect_backoff, - &do_reconnect, - dc); + GNUNET_SCHEDULER_add_delayed (dc->reconnect_backoff, &do_reconnect, dc); } @@ -1437,11 +1427,9 @@ activate_fs_download (void *cls) GNUNET_assert (NULL != dc->active); do_reconnect (dc); if (NULL != dc->mq) - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Download activated\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download activated\n"); pi.status = GNUNET_FS_STATUS_DOWNLOAD_ACTIVE; - GNUNET_FS_download_make_status_ (&pi, - dc); + GNUNET_FS_download_make_status_ (&pi, dc); } @@ -1456,16 +1444,14 @@ deactivate_fs_download (void *cls) struct GNUNET_FS_DownloadContext *dc = cls; struct GNUNET_FS_ProgressInfo pi; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Download deactivated\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download deactivated\n"); if (NULL != dc->mq) { GNUNET_MQ_destroy (dc->mq); dc->mq = NULL; } pi.status = GNUNET_FS_STATUS_DOWNLOAD_INACTIVE; - GNUNET_FS_download_make_status_ (&pi, - dc); + GNUNET_FS_download_make_status_ (&pi, dc); } @@ -1490,8 +1476,8 @@ deactivate_fs_download (void *cls) */ static struct DownloadRequest * create_download_request (struct DownloadRequest *parent, - unsigned int chk_idx, - unsigned int depth, + unsigned int chk_idx, + unsigned int depth, uint64_t dr_offset, uint64_t file_start_offset, uint64_t desired_length) @@ -1523,36 +1509,35 @@ create_download_request (struct DownloadRequest *parent, } /* calculate index of last block at this level that is interesting (rounded up) */ - dr->num_children = (file_start_offset + desired_length - dr_offset) / child_block_size; + dr->num_children = + (file_start_offset + desired_length - dr_offset) / child_block_size; if (dr->num_children * child_block_size < file_start_offset + desired_length - dr_offset) - dr->num_children++; /* round up */ + dr->num_children++; /* round up */ GNUNET_assert (dr->num_children > head_skip); dr->num_children -= head_skip; if (dr->num_children > CHK_PER_INODE) dr->num_children = CHK_PER_INODE; /* cap at max */ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Block at offset %llu and depth %u has %u children\n", - (unsigned long long) dr_offset, - depth, - dr->num_children); + "Block at offset %llu and depth %u has %u children\n", + (unsigned long long) dr_offset, + depth, + dr->num_children); /* now we can get the total number of *interesting* children for this block */ /* why else would we have gotten here to begin with? (that'd be a bad logic error) */ GNUNET_assert (dr->num_children > 0); - dr->children = - GNUNET_new_array (dr->num_children, - struct DownloadRequest *); + dr->children = GNUNET_new_array (dr->num_children, struct DownloadRequest *); for (i = 0; i < dr->num_children; i++) { dr->children[i] = create_download_request (dr, i + head_skip, depth - 1, - dr_offset + (i + head_skip) * child_block_size, - file_start_offset, + dr_offset + (i + head_skip) * child_block_size, + file_start_offset, desired_length); } return dr; @@ -1583,8 +1568,7 @@ reconstruct_cont (void *cls) } /* start "normal" download */ dc->issue_requests = GNUNET_YES; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting normal download\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting normal download\n"); schedule_block_download (dc, dc->top_request); } @@ -1646,29 +1630,29 @@ reconstruct_cb (void *cls, if (chld < dr->children[0]->chk_idx) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Block %u < %u irrelevant for our range\n", - chld, - dr->children[0]->chk_idx); - dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, - dc); + "Block %u < %u irrelevant for our range\n", + chld, + dr->children[0]->chk_idx); + dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); return; /* irrelevant block */ } - if (chld > dr->children[dr->num_children-1]->chk_idx) + if (chld > dr->children[dr->num_children - 1]->chk_idx) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Block %u > %u irrelevant for our range\n", - chld, - dr->children[dr->num_children-1]->chk_idx); + "Block %u > %u irrelevant for our range\n", + chld, + dr->children[dr->num_children - 1]->chk_idx); dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); return; /* irrelevant block */ } dr = dr->children[chld - dr->children[0]->chk_idx]; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Matched TE block with request at offset %llu and depth %u in state %d\n", - (unsigned long long) dr->offset, - dr->depth, - dr->state); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Matched TE block with request at offset %llu and depth %u in state %d\n", + (unsigned long long) dr->offset, + dr->depth, + dr->state); /* FIXME: this code needs more testing and might need to handle more states... */ switch (dr->state) @@ -1684,10 +1668,11 @@ reconstruct_cb (void *cls, case BRS_CHK_SET: if (0 == memcmp (chk, &dr->chk, sizeof (struct ContentHashKey))) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Reconstruction succeeded, can use block at offset %llu, depth %u\n", - (unsigned long long) offset, - depth); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Reconstruction succeeded, can use block at offset %llu, depth %u\n", + (unsigned long long) offset, + depth); /* block matches, hence tree below matches; * this request is done! */ dr->state = BRS_DOWNLOAD_UP; @@ -1707,32 +1692,34 @@ reconstruct_cb (void *cls, pi.value.download.specifics.progress.data_len = 0; pi.value.download.specifics.progress.depth = 0; pi.value.download.specifics.progress.respect_offered = 0; - pi.value.download.specifics.progress.block_download_duration = GNUNET_TIME_UNIT_ZERO; + pi.value.download.specifics.progress.block_download_duration = + GNUNET_TIME_UNIT_ZERO; GNUNET_FS_download_make_status_ (&pi, dc); /* FIXME: duplicated code from 'process_result_with_request - refactor */ if (dc->completed == dc->length) { - /* download completed, signal */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Download completed, truncating file to desired length %llu\n", - (unsigned long long) GNUNET_ntohll (dc->uri->data. - chk.file_length)); - /* truncate file to size (since we store IBlocks at the end) */ - if (NULL != dc->filename) - { - if (0 != - TRUNCATE (dc->filename, - GNUNET_ntohll (dc->uri->data.chk.file_length))) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "truncate", - dc->filename); - } + /* download completed, signal */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Download completed, truncating file to desired length %llu\n", + (unsigned long long) GNUNET_ntohll ( + dc->uri->data.chk.file_length)); + /* truncate file to size (since we store IBlocks at the end) */ + if (NULL != dc->filename) + { + if (0 != truncate (dc->filename, + GNUNET_ntohll (dc->uri->data.chk.file_length))) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, + "truncate", + dc->filename); + } } } else - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Reconstruction failed, need to download block at offset %llu, depth %u\n", - (unsigned long long) offset, - depth); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Reconstruction failed, need to download block at offset %llu, depth %u\n", + (unsigned long long) offset, + depth); break; case BRS_DOWNLOAD_DOWN: break; @@ -1744,10 +1731,8 @@ reconstruct_cb (void *cls, GNUNET_assert (0); break; } - dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, - dc); - if ( (dr == dc->top_request) && - (dr->state == BRS_DOWNLOAD_UP) ) + dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); + if ((dr == dc->top_request) && (dr->state == BRS_DOWNLOAD_UP)) check_completed (dc); } @@ -1803,8 +1788,7 @@ GNUNET_FS_download_start_task_ (void *cls) struct GNUNET_FS_ProgressInfo pi; struct GNUNET_DISK_FileHandle *fh; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Start task running...\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start task running...\n"); dc->task = NULL; if (0 == dc->length) { @@ -1813,14 +1797,15 @@ GNUNET_FS_download_start_task_ (void *cls) { fh = GNUNET_DISK_file_open (dc->filename, GNUNET_DISK_OPEN_READWRITE | - GNUNET_DISK_OPEN_CREATE | - ((0 == - GNUNET_FS_uri_chk_get_file_size (dc->uri)) ? - GNUNET_DISK_OPEN_TRUNCATE : 0), + GNUNET_DISK_OPEN_CREATE | + ((0 == + GNUNET_FS_uri_chk_get_file_size (dc->uri)) + ? GNUNET_DISK_OPEN_TRUNCATE + : 0), GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE | - GNUNET_DISK_PERM_GROUP_READ | - GNUNET_DISK_PERM_OTHER_READ); + GNUNET_DISK_PERM_USER_WRITE | + GNUNET_DISK_PERM_GROUP_READ | + GNUNET_DISK_PERM_OTHER_READ); GNUNET_DISK_file_close (fh); } GNUNET_FS_download_sync_ (dc); @@ -1834,13 +1819,16 @@ GNUNET_FS_download_start_task_ (void *cls) return; if (NULL == dc->top_request) { - dc->top_request = - create_download_request (NULL, 0, dc->treedepth - 1, 0, dc->offset, - dc->length); + dc->top_request = create_download_request (NULL, + 0, + dc->treedepth - 1, + 0, + dc->offset, + dc->length); dc->top_request->state = BRS_CHK_SET; - dc->top_request->chk = - (dc->uri->type == - GNUNET_FS_URI_CHK) ? dc->uri->data.chk.chk : dc->uri->data.loc.fi.chk; + dc->top_request->chk = (dc->uri->type == GNUNET_FS_URI_CHK) + ? dc->uri->data.chk.chk + : dc->uri->data.loc.fi.chk; /* signal start */ GNUNET_FS_download_sync_ (dc); if (NULL != dc->search) @@ -1852,23 +1840,24 @@ GNUNET_FS_download_start_task_ (void *cls) GNUNET_FS_download_start_downloading_ (dc); /* attempt reconstruction from disk */ if (GNUNET_YES == GNUNET_DISK_file_test (dc->filename)) - dc->rfh = - GNUNET_DISK_file_open (dc->filename, GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE); + dc->rfh = GNUNET_DISK_file_open (dc->filename, + GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_NONE); if (dc->top_request->state == BRS_CHK_SET) { if (NULL != dc->rfh) { /* first, try top-down */ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Trying top-down reconstruction for `%s'\n", dc->filename); + "Trying top-down reconstruction for `%s'\n", + dc->filename); try_top_down_reconstruction (dc, dc->top_request); switch (dc->top_request->state) { case BRS_CHK_SET: - break; /* normal */ + break; /* normal */ case BRS_DOWNLOAD_DOWN: - break; /* normal, some blocks already down */ + break; /* normal, some blocks already down */ case BRS_DOWNLOAD_UP: /* already done entirely, party! */ if (NULL != dc->rfh) @@ -1880,7 +1869,7 @@ GNUNET_FS_download_start_task_ (void *cls) } return; case BRS_ERROR: - GNUNET_asprintf (&dc->emsg, _("Invalid URI")); + GNUNET_asprintf (&dc->emsg, _ ("Invalid URI")); GNUNET_FS_download_sync_ (dc); pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; pi.value.download.specifics.error.message = dc->emsg; @@ -1896,11 +1885,11 @@ GNUNET_FS_download_start_task_ (void *cls) if ((GNUNET_FS_uri_chk_get_file_size (dc->uri) <= MAX_INLINE_SIZE) && (NULL != dc->meta)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Trying to find embedded meta data for download of size %llu with %u bytes MD\n", - (unsigned long long) GNUNET_FS_uri_chk_get_file_size (dc->uri), - (unsigned int) - GNUNET_CONTAINER_meta_data_get_serialized_size (dc->meta)); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Trying to find embedded meta data for download of size %llu with %u bytes MD\n", + (unsigned long long) GNUNET_FS_uri_chk_get_file_size (dc->uri), + (unsigned int) GNUNET_CONTAINER_meta_data_get_serialized_size (dc->meta)); GNUNET_CONTAINER_meta_data_iterate (dc->meta, &match_full_data, dc); if (BRS_DOWNLOAD_UP == dc->top_request->state) { @@ -1911,24 +1900,24 @@ GNUNET_FS_download_start_task_ (void *cls) GNUNET_DISK_file_close (dc->rfh); dc->rfh = NULL; } - return; /* finished, status update was already done for us */ + return; /* finished, status update was already done for us */ } } if (NULL != dc->rfh) { /* finally, actually run bottom-up */ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Trying bottom-up reconstruction of file `%s'\n", dc->filename); + "Trying bottom-up reconstruction of file `%s'\n", + dc->filename); dc->te = GNUNET_FS_tree_encoder_create (dc->h, - GNUNET_FS_uri_chk_get_file_size (dc->uri), - dc, + GNUNET_FS_uri_chk_get_file_size (dc->uri), + dc, &fh_reader, - &reconstruct_cb, + &reconstruct_cb, NULL, - &reconstruct_cont); - dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, - dc); + &reconstruct_cont); + dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); } else { @@ -1968,7 +1957,8 @@ GNUNET_FS_download_signal_suspend_ (void *cls) dc->job_queue = NULL; } if (NULL != dc->parent) - GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, dc->parent->child_tail, + GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, + dc->parent->child_tail, dc); if (NULL != dc->task) { @@ -2024,14 +2014,14 @@ GNUNET_FS_download_signal_suspend_ (void *cls) */ struct GNUNET_FS_DownloadContext * create_download_context (struct GNUNET_FS_Handle *h, - const struct GNUNET_FS_Uri *uri, - const struct GNUNET_CONTAINER_MetaData *meta, - const char *filename, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_CONTAINER_MetaData *meta, + const char *filename, const char *tempname, - uint64_t offset, + uint64_t offset, uint64_t length, uint32_t anonymity, - enum GNUNET_FS_DownloadOptions options, + enum GNUNET_FS_DownloadOptions options, void *cctx) { struct GNUNET_FS_DownloadContext *dc; @@ -2045,10 +2035,10 @@ create_download_context (struct GNUNET_FS_Handle *h, } dc = GNUNET_new (struct GNUNET_FS_DownloadContext); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting download %p, %u bytes at offset %llu\n", - dc, - (unsigned int) length, - (unsigned long long) offset); + "Starting download %p, %u bytes at offset %llu\n", + dc, + (unsigned int) length, + (unsigned long long) offset); dc->h = h; dc->uri = GNUNET_FS_uri_dup (uri); dc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); @@ -2058,7 +2048,10 @@ create_download_context (struct GNUNET_FS_Handle *h, { dc->filename = GNUNET_strdup (filename); if (GNUNET_YES == GNUNET_DISK_file_test (filename)) - GNUNET_break (GNUNET_OK == GNUNET_DISK_file_size (filename, &dc->old_file_size, GNUNET_YES, GNUNET_YES)); + GNUNET_break (GNUNET_OK == GNUNET_DISK_file_size (filename, + &dc->old_file_size, + GNUNET_YES, + GNUNET_YES)); } if (GNUNET_FS_uri_test_loc (dc->uri)) GNUNET_assert (GNUNET_OK == @@ -2068,9 +2061,10 @@ create_download_context (struct GNUNET_FS_Handle *h, dc->anonymity = anonymity; dc->options = options; dc->active = - GNUNET_CONTAINER_multihashmap_create (1 + 2 * (length / DBLOCK_SIZE), GNUNET_NO); + GNUNET_CONTAINER_multihashmap_create (1 + 2 * (length / DBLOCK_SIZE), + GNUNET_NO); dc->treedepth = - GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri)); + GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri)); if ((NULL == filename) && (is_recursive_download (dc))) { if (NULL != tempname) @@ -2079,13 +2073,12 @@ create_download_context (struct GNUNET_FS_Handle *h, dc->temp_filename = GNUNET_DISK_mktemp ("gnunet-directory-download-tmp"); } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting download `%s' of %llu bytes with tree depth %u\n", - filename, - (unsigned long long) length, + "Starting download `%s' of %llu bytes with tree depth %u\n", + filename, + (unsigned long long) length, dc->treedepth); GNUNET_assert (NULL == dc->job_queue); - dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, - dc); + dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc); return dc; } @@ -2140,7 +2133,7 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, meta, filename, tempname, - offset, + offset, length, anonymity, options, @@ -2150,9 +2143,9 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, dc->parent = parent; if (NULL != parent) GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc); - else if (0 == (GNUNET_FS_DOWNLOAD_IS_PROBE & options) ) + else if (0 == (GNUNET_FS_DOWNLOAD_IS_PROBE & options)) dc->top = - GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc); + GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc); return dc; } @@ -2214,7 +2207,7 @@ GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h, sr->meta, filename, tempname, - offset, + offset, length, anonymity, options, @@ -2248,19 +2241,19 @@ GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc) GNUNET_assert (NULL == dc->job_queue); GNUNET_assert (NULL == dc->task); GNUNET_assert (NULL != dc->active); - dc->job_queue - = GNUNET_FS_queue_ (dc->h, - &activate_fs_download, - &deactivate_fs_download, - dc, - (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, - (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) - ? GNUNET_FS_QUEUE_PRIORITY_NORMAL - : GNUNET_FS_QUEUE_PRIORITY_PROBE); + dc->job_queue = + GNUNET_FS_queue_ (dc->h, + &activate_fs_download, + &deactivate_fs_download, + dc, + (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, + (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) + ? GNUNET_FS_QUEUE_PRIORITY_NORMAL + : GNUNET_FS_QUEUE_PRIORITY_PROBE); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Download %p put into queue as job %p\n", - dc, - dc->job_queue); + "Download %p put into queue as job %p\n", + dc, + dc->job_queue); } /** @@ -2271,7 +2264,7 @@ GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc) void GNUNET_FS_download_suspend (struct GNUNET_FS_DownloadContext *dc) { - deactivate_fs_download(dc); + deactivate_fs_download (dc); } @@ -2289,15 +2282,15 @@ GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc) GNUNET_FS_download_make_status_ (&pi, dc); GNUNET_assert (NULL == dc->task); - dc->job_queue - = GNUNET_FS_queue_ (dc->h, - &activate_fs_download, - &deactivate_fs_download, - dc, (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, - (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) + dc->job_queue = + GNUNET_FS_queue_ (dc->h, + &activate_fs_download, + &deactivate_fs_download, + dc, + (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, + (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) ? GNUNET_FS_QUEUE_PRIORITY_NORMAL : GNUNET_FS_QUEUE_PRIORITY_PROBE); - } @@ -2308,8 +2301,7 @@ GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc) * @param do_delete delete files of incomplete downloads */ void -GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, - int do_delete) +GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete) { struct GNUNET_FS_ProgressInfo pi; int have_children; @@ -2348,14 +2340,15 @@ GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, dc); if (NULL != dc->serialization) GNUNET_FS_remove_sync_file_ (dc->h, - ((NULL != dc->parent) || - (! search_was_null)) ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD : - GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, + ((NULL != dc->parent) || (! search_was_null)) + ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD + : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, dc->serialization); if ((GNUNET_YES == have_children) && (NULL == dc->parent)) GNUNET_FS_remove_sync_dir_ (dc->h, - (! search_was_null) ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD : - GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, + (! search_was_null) + ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD + : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, dc->serialization); pi.status = GNUNET_FS_STATUS_DOWNLOAD_STOPPED; GNUNET_FS_download_make_status_ (&pi, dc); @@ -2370,8 +2363,7 @@ GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, { if ((dc->completed != dc->length) && (GNUNET_YES == do_delete)) { - if ( (0 != UNLINK (dc->filename)) && - (ENOENT != errno) ) + if ((0 != unlink (dc->filename)) && (ENOENT != errno)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", dc->filename); @@ -2382,7 +2374,7 @@ GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, GNUNET_FS_uri_destroy (dc->uri); if (NULL != dc->temp_filename) { - if (0 != UNLINK (dc->temp_filename)) + if (0 != unlink (dc->temp_filename)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "unlink", dc->temp_filename); diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c index 49cfc1a68..fbf3181ef 100644 --- a/src/fs/fs_file_information.c +++ b/src/fs/fs_file_information.c @@ -97,16 +97,14 @@ GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s, * @return publish structure entry for the file */ struct GNUNET_FS_FileInformation * -GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h, - void *client_info, - const char *filename, - const struct GNUNET_FS_Uri - *keywords, - const struct - GNUNET_CONTAINER_MetaData *meta, - int do_index, - const struct GNUNET_FS_BlockOptions - *bo) +GNUNET_FS_file_information_create_from_file ( + struct GNUNET_FS_Handle *h, + void *client_info, + const char *filename, + const struct GNUNET_FS_Uri *keywords, + const struct GNUNET_CONTAINER_MetaData *meta, + int do_index, + const struct GNUNET_FS_BlockOptions *bo) { struct FileInfo *fi; uint64_t fsize; @@ -119,7 +117,8 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h, #endif /* FIXME: should include_symbolic_links be GNUNET_NO or GNUNET_YES here? */ - if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES)) + if (GNUNET_OK != + GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES)) { GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); return NULL; @@ -131,16 +130,20 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h, return NULL; } ret = - GNUNET_FS_file_information_create_from_reader (h, client_info, - fsize, - &GNUNET_FS_data_reader_file_, - fi, keywords, meta, - do_index, bo); + GNUNET_FS_file_information_create_from_reader (h, + client_info, + fsize, + &GNUNET_FS_data_reader_file_, + fi, + keywords, + meta, + do_index, + bo); if (ret == NULL) return NULL; ret->h = h; ret->filename = GNUNET_strdup (filename); -#if !WINDOWS +#if ! WINDOWS fn = filename; #else plibc_conv_to_win_path (filename, fn_conv); @@ -151,16 +154,22 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h, /* FIXME: If we assume that on other platforms CRT is UTF-8-aware, then * this should be changed to EXTRACTOR_METAFORMAT_UTF8 */ -#if !WINDOWS - GNUNET_CONTAINER_meta_data_insert (ret->meta, "", +#if ! WINDOWS + GNUNET_CONTAINER_meta_data_insert (ret->meta, + "", EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, EXTRACTOR_METAFORMAT_C_STRING, - "text/plain", fn, strlen (fn) + 1); + "text/plain", + fn, + strlen (fn) + 1); #else - GNUNET_CONTAINER_meta_data_insert (ret->meta, "", + GNUNET_CONTAINER_meta_data_insert (ret->meta, + "", EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, EXTRACTOR_METAFORMAT_UTF8, - "text/plain", fn, strlen (fn) + 1); + "text/plain", + fn, + strlen (fn) + 1); #endif return ret; } @@ -183,26 +192,30 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h, * @return publish structure entry for the file */ struct GNUNET_FS_FileInformation * -GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h, - void *client_info, uint64_t length, - void *data, - const struct GNUNET_FS_Uri - *keywords, - const struct - GNUNET_CONTAINER_MetaData *meta, - int do_index, - const struct GNUNET_FS_BlockOptions - *bo) +GNUNET_FS_file_information_create_from_data ( + struct GNUNET_FS_Handle *h, + void *client_info, + uint64_t length, + void *data, + const struct GNUNET_FS_Uri *keywords, + const struct GNUNET_CONTAINER_MetaData *meta, + int do_index, + const struct GNUNET_FS_BlockOptions *bo) { if (GNUNET_YES == do_index) { GNUNET_break (0); return NULL; } - return GNUNET_FS_file_information_create_from_reader (h, client_info, length, + return GNUNET_FS_file_information_create_from_reader (h, + client_info, + length, &GNUNET_FS_data_reader_copy_, - data, keywords, meta, - do_index, bo); + data, + keywords, + meta, + do_index, + bo); } @@ -223,18 +236,16 @@ GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h, * @return publish structure entry for the file */ struct GNUNET_FS_FileInformation * -GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h, - void *client_info, - uint64_t length, - GNUNET_FS_DataReader reader, - void *reader_cls, - const struct GNUNET_FS_Uri - *keywords, - const struct - GNUNET_CONTAINER_MetaData *meta, - int do_index, - const struct - GNUNET_FS_BlockOptions *bo) +GNUNET_FS_file_information_create_from_reader ( + struct GNUNET_FS_Handle *h, + void *client_info, + uint64_t length, + GNUNET_FS_DataReader reader, + void *reader_cls, + const struct GNUNET_FS_Uri *keywords, + const struct GNUNET_CONTAINER_MetaData *meta, + int do_index, + const struct GNUNET_FS_BlockOptions *bo) { struct GNUNET_FS_FileInformation *ret; @@ -266,8 +277,8 @@ GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h, * @return #GNUNET_YES if so, #GNUNET_NO if not */ int -GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation - *ent) +GNUNET_FS_file_information_is_directory ( + const struct GNUNET_FS_FileInformation *ent) { return ent->is_directory; } @@ -286,16 +297,13 @@ GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation * @return publish structure entry for the directory , NULL on error */ struct GNUNET_FS_FileInformation * -GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h, - void *client_info, - const struct GNUNET_FS_Uri - *keywords, - const struct - GNUNET_CONTAINER_MetaData - *meta, - const struct - GNUNET_FS_BlockOptions *bo, - const char *filename) +GNUNET_FS_file_information_create_empty_directory ( + struct GNUNET_FS_Handle *h, + void *client_info, + const struct GNUNET_FS_Uri *keywords, + const struct GNUNET_CONTAINER_MetaData *meta, + const struct GNUNET_FS_BlockOptions *bo, + const char *filename) { struct GNUNET_FS_FileInformation *ret; @@ -327,7 +335,8 @@ int GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir, struct GNUNET_FS_FileInformation *ent) { - if ((ent->dir != NULL) || (ent->next != NULL) || (dir->is_directory != GNUNET_YES)) + if ((ent->dir != NULL) || (ent->next != NULL) || + (dir->is_directory != GNUNET_YES)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -364,10 +373,13 @@ GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir, no = GNUNET_NO; if (GNUNET_OK != - proc (proc_cls, dir, - (dir->is_directory == GNUNET_YES) ? dir->data.dir.dir_size : dir->data. - file.file_size, - dir->meta, &dir->keywords, &dir->bo, + proc (proc_cls, + dir, + (dir->is_directory == GNUNET_YES) ? dir->data.dir.dir_size + : dir->data.file.file_size, + dir->meta, + &dir->keywords, + &dir->bo, (dir->is_directory == GNUNET_YES) ? &no : &dir->data.file.do_index, &dir->client_info)) return; @@ -378,10 +390,15 @@ GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir, { no = GNUNET_NO; if (GNUNET_OK != - proc (proc_cls, pos, - (pos->is_directory == GNUNET_YES) ? pos->data.dir.dir_size : pos->data. - file.file_size, pos->meta, &pos->keywords, &pos->bo, - (pos->is_directory == GNUNET_YES) ? &no : &pos->data.file.do_index, + proc (proc_cls, + pos, + (pos->is_directory == GNUNET_YES) ? pos->data.dir.dir_size + : pos->data.file.file_size, + pos->meta, + &pos->keywords, + &pos->bo, + (pos->is_directory == GNUNET_YES) ? &no + : &pos->data.file.do_index, &pos->client_info)) break; pos = pos->next; @@ -418,8 +435,14 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi, } /* clean up client-info */ if (NULL != cleaner) - cleaner (cleaner_cls, fi, fi->data.dir.dir_size, fi->meta, &fi->keywords, - &fi->bo, &no, &fi->client_info); + cleaner (cleaner_cls, + fi, + fi->data.dir.dir_size, + fi->meta, + &fi->keywords, + &fi->bo, + &no, + &fi->client_info); GNUNET_free_non_null (fi->data.dir.dir_data); } else @@ -432,19 +455,25 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi, } /* clean up client-info */ if (NULL != cleaner) - cleaner (cleaner_cls, fi, fi->data.file.file_size, fi->meta, - &fi->keywords, &fi->bo, &fi->data.file.do_index, + cleaner (cleaner_cls, + fi, + fi->data.file.file_size, + fi->meta, + &fi->keywords, + &fi->bo, + &fi->data.file.do_index, &fi->client_info); } GNUNET_free_non_null (fi->filename); GNUNET_free_non_null (fi->emsg); if (NULL != fi->sks_uri) - GNUNET_FS_uri_destroy (fi->sks_uri); + GNUNET_FS_uri_destroy (fi->sks_uri); if (NULL != fi->chk_uri) - GNUNET_FS_uri_destroy (fi->chk_uri); + GNUNET_FS_uri_destroy (fi->chk_uri); /* clean up serialization */ - if ((NULL != fi->serialization) && (0 != UNLINK (fi->serialization))) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", + if ((NULL != fi->serialization) && (0 != unlink (fi->serialization))) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, + "unlink", fi->serialization); if (NULL != fi->keywords) GNUNET_FS_uri_destroy (fi->keywords); diff --git a/src/fs/fs_namespace.c b/src/fs/fs_namespace.c index 675253b90..11a137a09 100644 --- a/src/fs/fs_namespace.c +++ b/src/fs/fs_namespace.c @@ -69,7 +69,6 @@ struct NamespaceUpdateNode * TREE this entry belongs to (if nug is current). */ unsigned int tree_id; - }; @@ -126,8 +125,9 @@ struct GNUNET_FS_UpdateInformationGraph * @return NULL on error, otherwise the name of the directory */ static char * -get_update_information_directory (struct GNUNET_FS_Handle *h, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) +get_update_information_directory ( + struct GNUNET_FS_Handle *h, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) { char *dn; char *ret; @@ -136,21 +136,19 @@ get_update_information_directory (struct GNUNET_FS_Handle *h, struct GNUNET_CRYPTO_HashAsciiEncoded enc; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (h->cfg, "FS", "UPDATE_DIR", - &dn)) + GNUNET_CONFIGURATION_get_value_filename (h->cfg, "FS", "UPDATE_DIR", &dn)) { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - "fs", "UPDATE_DIR"); + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "fs", "UPDATE_DIR"); return NULL; } GNUNET_CRYPTO_ecdsa_key_get_public (ns, &pub); GNUNET_CRYPTO_hash (&pub, sizeof (pub), &hc); - GNUNET_CRYPTO_hash_to_enc (&hc, - &enc); - GNUNET_asprintf (&ret, "%s%s%s", - dn, - DIR_SEPARATOR_STR, - (const char *) enc.encoding); + GNUNET_CRYPTO_hash_to_enc (&hc, &enc); + GNUNET_asprintf (&ret, + "%s%s%s", + dn, + DIR_SEPARATOR_STR, + (const char *) enc.encoding); GNUNET_free (dn); return ret; } @@ -176,8 +174,7 @@ free_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) GNUNET_free (nsn->update); GNUNET_free (nsn); } - GNUNET_array_grow (uig->update_nodes, uig->update_node_count, - 0); + GNUNET_array_grow (uig->update_nodes, uig->update_node_count, 0); if (NULL != uig->update_map) GNUNET_CONTAINER_multihashmap_destroy (uig->update_map); GNUNET_free (uig); @@ -198,15 +195,14 @@ write_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) struct NamespaceUpdateNode *n; char *uris; - fn = get_update_information_directory (uig->h, - &uig->ns); + fn = get_update_information_directory (uig->h, &uig->ns); wh = GNUNET_BIO_write_open (fn); if (NULL == wh) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Failed to open `%s' for writing: %s\n"), + _ ("Failed to open `%s' for writing: %s\n"), fn, - STRERROR (errno)); + strerror (errno)); GNUNET_free (fn); return; } @@ -229,9 +225,9 @@ write_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) END: if (GNUNET_OK != GNUNET_BIO_write_close (wh)) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Failed to write `%s': %s\n"), + _ ("Failed to write `%s': %s\n"), fn, - STRERROR (errno)); + strerror (errno)); GNUNET_free (fn); } @@ -245,7 +241,7 @@ END: */ static struct GNUNET_FS_UpdateInformationGraph * read_update_information_graph (struct GNUNET_FS_Handle *h, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) + const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) { struct GNUNET_FS_UpdateInformationGraph *uig; char *fn; @@ -289,8 +285,9 @@ read_update_information_graph (struct GNUNET_FS_Handle *h, for (i = 0; i < count; i++) { n = GNUNET_new (struct NamespaceUpdateNode); - if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024)) - || (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) || + if ((GNUNET_OK != + GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024)) || + (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) || (GNUNET_OK != GNUNET_BIO_read_string (rh, "update-id", &n->update, 1024)) || (GNUNET_OK != GNUNET_BIO_read_string (rh, "uri", &uris, 1024 * 2))) @@ -318,11 +315,13 @@ read_update_information_graph (struct GNUNET_FS_Handle *h, uig->update_nodes[i] = n; } uig->update_node_count = i; - END: +END: if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to read `%s': %s\n"), - fn, emsg); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Failed to read `%s': %s\n"), + fn, + emsg); GNUNET_free (emsg); } GNUNET_free (fn); @@ -387,8 +386,7 @@ struct GNUNET_FS_PublishSksContext * @param msg error message (or NULL) */ static void -sks_publish_cont (void *cls, - const char *msg) +sks_publish_cont (void *cls, const char *msg) { struct GNUNET_FS_PublishSksContext *psc = cls; struct GNUNET_FS_UpdateInformationGraph *uig; @@ -406,11 +404,8 @@ sks_publish_cont (void *cls, /* FIXME: this can be done much more * efficiently by simply appending to the * file and overwriting the 4-byte header */ - uig = read_update_information_graph (psc->h, - &psc->ns); - GNUNET_array_append (uig->update_nodes, - uig->update_node_count, - psc->nsn); + uig = read_update_information_graph (psc->h, &psc->ns); + GNUNET_array_append (uig->update_nodes, uig->update_node_count, psc->nsn); psc->nsn = NULL; write_update_information_graph (uig); free_update_information_graph (uig); @@ -439,12 +434,14 @@ sks_publish_cont (void *cls, struct GNUNET_FS_PublishSksContext * GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, - const char *identifier, const char *update, + const char *identifier, + const char *update, const struct GNUNET_CONTAINER_MetaData *meta, const struct GNUNET_FS_Uri *uri, const struct GNUNET_FS_BlockOptions *bo, enum GNUNET_FS_PublishOptions options, - GNUNET_FS_PublishContinuation cont, void *cont_cls) + GNUNET_FS_PublishContinuation cont, + void *cont_cls) { struct GNUNET_FS_PublishSksContext *psc; struct GNUNET_FS_Uri *sks_uri; @@ -452,8 +449,7 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, sks_uri = GNUNET_new (struct GNUNET_FS_Uri); sks_uri->type = GNUNET_FS_URI_SKS; sks_uri->data.sks.identifier = GNUNET_strdup (identifier); - GNUNET_CRYPTO_ecdsa_key_get_public (ns, - &sks_uri->data.sks.ns); + GNUNET_CRYPTO_ecdsa_key_get_public (ns, &sks_uri->data.sks.ns); psc = GNUNET_new (struct GNUNET_FS_PublishSksContext); psc->h = h; @@ -466,8 +462,7 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, psc->dsh = GNUNET_DATASTORE_connect (h->cfg); if (NULL == psc->dsh) { - sks_publish_cont (psc, - _("Failed to connect to datastore.")); + sks_publish_cont (psc, _ ("Failed to connect to datastore.")); return NULL; } } @@ -480,16 +475,16 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, psc->nsn->uri = GNUNET_FS_uri_dup (uri); } psc->uc = GNUNET_FS_publish_ublock_ (h, - psc->dsh, - identifier, - update, - ns, - meta, - uri, - bo, - options, - &sks_publish_cont, - psc); + psc->dsh, + identifier, + update, + ns, + meta, + uri, + bo, + options, + &sks_publish_cont, + psc); return psc; } @@ -553,18 +548,12 @@ struct ProcessUpdateClosure * GNUNET_NO if not. */ static int -process_update_node (void *cls, - const struct GNUNET_HashCode *key, - void *value) +process_update_node (void *cls, const struct GNUNET_HashCode *key, void *value) { struct ProcessUpdateClosure *pc = cls; struct NamespaceUpdateNode *nsn = value; - pc->ip (pc->ip_cls, - nsn->id, - nsn->uri, - nsn->md, - nsn->update); + pc->ip (pc->ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); return GNUNET_YES; } @@ -622,9 +611,7 @@ struct FindTreeClosure * GNUNET_NO if not. */ static int -find_trees (void *cls, - const struct GNUNET_HashCode *key, - void *value) +find_trees (void *cls, const struct GNUNET_HashCode *key, void *value) { struct FindTreeClosure *fc = cls; struct NamespaceUpdateNode *nsn = value; @@ -633,26 +620,28 @@ find_trees (void *cls, if (nsn->nug == fc->nug) { if (UINT_MAX == nsn->tree_id) - return GNUNET_YES; /* circular */ + return GNUNET_YES; /* circular */ GNUNET_assert (nsn->tree_id < fc->tree_array_size); if (fc->tree_array[nsn->tree_id] != nsn) - return GNUNET_YES; /* part of "another" (directed) TREE, + return GNUNET_YES; /* part of "another" (directed) TREE, * and not root of it, end trace */ if (nsn->tree_id == fc->id) - return GNUNET_YES; /* that's our own root (can this be?) */ + return GNUNET_YES; /* that's our own root (can this be?) */ /* merge existing TREE, we have a root for both */ fc->tree_array[nsn->tree_id] = NULL; if (UINT_MAX == fc->id) - fc->id = nsn->tree_id; /* take over ID */ + fc->id = nsn->tree_id; /* take over ID */ } else { nsn->nug = fc->nug; - nsn->tree_id = UINT_MAX; /* mark as undef */ + nsn->tree_id = UINT_MAX; /* mark as undef */ /* trace */ GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc); - GNUNET_CONTAINER_multihashmap_get_multiple (fc->uig->update_map, &hc, - &find_trees, fc); + GNUNET_CONTAINER_multihashmap_get_multiple (fc->uig->update_map, + &hc, + &find_trees, + fc); } return GNUNET_YES; } @@ -682,11 +671,12 @@ find_trees (void *cls, * @param ip_cls closure for ip */ void -GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, - const char *next_id, - GNUNET_FS_IdentifierProcessor ip, - void *ip_cls) +GNUNET_FS_namespace_list_updateable ( + struct GNUNET_FS_Handle *h, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, + const char *next_id, + GNUNET_FS_IdentifierProcessor ip, + void *ip_cls) { unsigned int i; unsigned int nug; @@ -700,29 +690,33 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h, if (NULL == uig->update_nodes) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "No updateable nodes found for ID `%s'\n", next_id); + "No updateable nodes found for ID `%s'\n", + next_id); free_update_information_graph (uig); - return; /* no nodes */ + return; /* no nodes */ } uig->update_map = - GNUNET_CONTAINER_multihashmap_create (2 + - 3 * uig->update_node_count / - 4, - GNUNET_NO); + GNUNET_CONTAINER_multihashmap_create (2 + 3 * uig->update_node_count / 4, + GNUNET_NO); for (i = 0; i < uig->update_node_count; i++) { nsn = uig->update_nodes[i]; GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc); - GNUNET_CONTAINER_multihashmap_put (uig->update_map, &hc, nsn, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + GNUNET_CONTAINER_multihashmap_put ( + uig->update_map, + &hc, + nsn, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); } if (NULL != next_id) { GNUNET_CRYPTO_hash (next_id, strlen (next_id), &hc); pc.ip = ip; pc.ip_cls = ip_cls; - GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, &hc, - &process_update_node, &pc); + GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, + &hc, + &process_update_node, + &pc); free_update_information_graph (uig); return; } @@ -738,9 +732,11 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h, nsn = uig->update_nodes[i]; if (nsn->nug == nug) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TREE of node `%s' is %u\n", nsn->id, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "TREE of node `%s' is %u\n", + nsn->id, nsn->nug); - continue; /* already placed in TREE */ + continue; /* already placed in TREE */ } GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc); nsn->nug = nug; @@ -748,8 +744,10 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h, fc.id = UINT_MAX; fc.nug = nug; fc.uig = uig; - GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, &hc, - &find_trees, &fc); + GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, + &hc, + &find_trees, + &fc); if (UINT_MAX == fc.id) { /* start new TREE */ @@ -768,15 +766,18 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h, nsn->tree_id = fc.id; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Starting new TREE %u with node `%s'\n", nsn->tree_id, + "Starting new TREE %u with node `%s'\n", + nsn->tree_id, nsn->id); /* put all nodes with same identifier into this TREE */ GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc); fc.id = nsn->tree_id; fc.nug = nug; fc.uig = uig; - GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, &hc, - &find_trees, &fc); + GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, + &hc, + &find_trees, + &fc); } else { @@ -785,7 +786,8 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h, nsn->tree_id = fc.id; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "TREE of node `%s' is %u\n", nsn->id, + "TREE of node `%s' is %u\n", + nsn->id, fc.id); } for (i = 0; i < fc.tree_array_size; i++) @@ -793,7 +795,9 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h, nsn = fc.tree_array[i]; if (NULL != nsn) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Root of TREE %u is node `%s'\n", i, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Root of TREE %u is node `%s'\n", + i, nsn->id); ip (ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); } diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c index 9097d9884..5a67afbc0 100644 --- a/src/fs/fs_uri.c +++ b/src/fs/fs_uri.c @@ -91,7 +91,6 @@ #include - /** * Get a unique key from a URI. This is for putting URIs * into HashMaps. The key may change between FS implementations. @@ -102,7 +101,7 @@ */ int GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, - struct GNUNET_HashCode *key) + struct GNUNET_HashCode *key) { switch (uri->type) { @@ -112,14 +111,14 @@ GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, case GNUNET_FS_URI_SKS: GNUNET_CRYPTO_hash (uri->data.sks.identifier, strlen (uri->data.sks.identifier), - key); + key); return GNUNET_OK; case GNUNET_FS_URI_KSK: if (uri->data.ksk.keywordCount > 0) { GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0], strlen (uri->data.ksk.keywords[0]), - key); + key); return GNUNET_OK; } else @@ -131,7 +130,7 @@ GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, case GNUNET_FS_URI_LOC: GNUNET_CRYPTO_hash (&uri->data.loc.fi, sizeof (struct FileIdentifier) + - sizeof (struct GNUNET_PeerIdentity), + sizeof (struct GNUNET_PeerIdentity), key); return GNUNET_OK; default: @@ -213,8 +212,7 @@ GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri) * @return decodded string with leading space (or preserved plus) */ static char * -percent_decode_keyword (const char *in, - char **emsg) +percent_decode_keyword (const char *in, char **emsg) { char *out; char *ret; @@ -229,16 +227,17 @@ percent_decode_keyword (const char *in, { if (out[rpos] == '%') { - if (1 != SSCANF (&out[rpos + 1], "%2X", &hx)) + if (1 != sscanf (&out[rpos + 1], "%2X", &hx)) { GNUNET_free (out); - *emsg = GNUNET_strdup (_(/* xgettext:no-c-format */ - "Malformed KSK URI (`%' must be followed by HEX number)")); + *emsg = GNUNET_strdup ( + _ (/* xgettext:no-c-format */ + "Malformed KSK URI (`%' must be followed by HEX number)")); return NULL; } rpos += 3; if (hx == '"') - continue; /* skip double quote */ + continue; /* skip double quote */ out[wpos++] = (char) hx; } else @@ -272,8 +271,7 @@ percent_decode_keyword (const char *in, * @return NULL on error, otherwise the KSK URI */ static struct GNUNET_FS_Uri * -uri_ksk_parse (const char *s, - char **emsg) +uri_ksk_parse (const char *s, char **emsg) { struct GNUNET_FS_Uri *ret; char **keywords; @@ -288,11 +286,11 @@ uri_ksk_parse (const char *s, slen = strlen (s); pos = strlen (GNUNET_FS_URI_KSK_PREFIX); if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX, pos))) - return NULL; /* not KSK URI */ + return NULL; /* not KSK URI */ if ((s[slen - 1] == '+') || (s[pos] == '+')) { *emsg = - GNUNET_strdup (_("Malformed KSK URI (must not begin or end with `+')")); + GNUNET_strdup (_ ("Malformed KSK URI (must not begin or end with `+')")); return NULL; } max = 1; @@ -310,20 +308,19 @@ uri_ksk_parse (const char *s, max++; if (s[i - 1] == '+') { - *emsg = GNUNET_strdup (_("Malformed KSK URI (`++' not allowed)")); + *emsg = GNUNET_strdup (_ ("Malformed KSK URI (`++' not allowed)")); return NULL; } } } if (saw_quote == 1) { - *emsg = GNUNET_strdup (_("Malformed KSK URI (quotes not balanced)")); + *emsg = GNUNET_strdup (_ ("Malformed KSK URI (quotes not balanced)")); return NULL; } iret = max; dup = GNUNET_strdup (s); - keywords = GNUNET_new_array (max, - char *); + keywords = GNUNET_new_array (max, char *); for (i = slen - 1; i >= (int) pos; i--) { if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22"))) @@ -368,8 +365,7 @@ CLEANUP: * @return NULL on error, SKS URI otherwise */ static struct GNUNET_FS_Uri * -uri_sks_parse (const char *s, - char **emsg) +uri_sks_parse (const char *s, char **emsg) { struct GNUNET_FS_Uri *ret; struct GNUNET_CRYPTO_EcdsaPublicKey ns; @@ -378,16 +374,15 @@ uri_sks_parse (const char *s, pos = strlen (GNUNET_FS_URI_SKS_PREFIX); if ((strlen (s) <= pos) || (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, pos))) - return NULL; /* not an SKS URI */ + return NULL; /* not an SKS URI */ end = strchr (&s[pos], '/'); - if ( (NULL == end) || - (GNUNET_OK != - GNUNET_STRINGS_string_to_data (&s[pos], - end - &s[pos], - &ns, - sizeof (ns))) ) + if ((NULL == end) || + (GNUNET_OK != GNUNET_STRINGS_string_to_data (&s[pos], + end - &s[pos], + &ns, + sizeof (ns)))) { - *emsg = GNUNET_strdup (_("Malformed SKS URI (wrong syntax)")); + *emsg = GNUNET_strdup (_ ("Malformed SKS URI (wrong syntax)")); return NULL; /* malformed */ } end++; /* skip over '/' */ @@ -409,8 +404,7 @@ uri_sks_parse (const char *s, * @return NULL on error, CHK URI otherwise */ static struct GNUNET_FS_Uri * -uri_chk_parse (const char *s, - char **emsg) +uri_chk_parse (const char *s, char **emsg) { struct GNUNET_FS_Uri *ret; struct FileIdentifier fi; @@ -424,26 +418,28 @@ uri_chk_parse (const char *s, pos = strlen (GNUNET_FS_URI_CHK_PREFIX); if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || (0 != strncmp (s, GNUNET_FS_URI_CHK_PREFIX, pos))) - return NULL; /* not a CHK URI */ + return NULL; /* not a CHK URI */ if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) { - *emsg = GNUNET_strdup (_("Malformed CHK URI (wrong syntax)")); + *emsg = GNUNET_strdup (_ ("Malformed CHK URI (wrong syntax)")); return NULL; } GNUNET_memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; - GNUNET_memcpy (h2, &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); + GNUNET_memcpy (h2, + &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &fi.chk.key)) || (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &fi.chk.query)) || (1 != - SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], - "%llu", &flen))) + sscanf (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], + "%llu", + &flen))) { - *emsg = GNUNET_strdup (_("Malformed CHK URI (failed to decode CHK)")); + *emsg = GNUNET_strdup (_ ("Malformed CHK URI (failed to decode CHK)")); return NULL; } fi.file_length = GNUNET_htonll (flen); @@ -481,7 +477,6 @@ struct LocUriAssembly * Peer offering the file. */ struct GNUNET_PeerIdentity peer; - }; GNUNET_NETWORK_STRUCT_END @@ -499,8 +494,7 @@ GNUNET_NETWORK_STRUCT_END * @return NULL on error, valid LOC URI otherwise */ static struct GNUNET_FS_Uri * -uri_loc_parse (const char *s, - char **emsg) +uri_loc_parse (const char *s, char **emsg) { struct GNUNET_FS_Uri *uri; char h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; @@ -518,26 +512,28 @@ uri_loc_parse (const char *s, pos = strlen (GNUNET_FS_URI_LOC_PREFIX); if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || (0 != strncmp (s, GNUNET_FS_URI_LOC_PREFIX, pos))) - return NULL; /* not a LOC URI */ + return NULL; /* not a LOC URI */ if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) { - *emsg = GNUNET_strdup (_("LOC URI malformed (wrong syntax)")); + *emsg = GNUNET_strdup (_ ("LOC URI malformed (wrong syntax)")); return NULL; } GNUNET_memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; - GNUNET_memcpy (h2, &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); + GNUNET_memcpy (h2, + &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &ass.fi.chk.key)) || (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &ass.fi.chk.query)) || (1 != - SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], - "%llu", &flen))) + sscanf (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], + "%llu", + &flen))) { - *emsg = GNUNET_strdup (_("LOC URI malformed (no CHK)")); + *emsg = GNUNET_strdup (_ ("LOC URI malformed (no CHK)")); return NULL; } ass.fi.file_length = GNUNET_htonll (flen); @@ -547,56 +543,61 @@ uri_loc_parse (const char *s, npos++; if (s[npos] == '\0') { - *emsg = GNUNET_strdup (_("LOC URI malformed (missing LOC)")); + *emsg = GNUNET_strdup (_ ("LOC URI malformed (missing LOC)")); goto ERR; } npos++; - if ( (strlen (&s[npos]) <= GNUNET_CRYPTO_PKEY_ASCII_LENGTH + 1) || - ('.' != s[npos+GNUNET_CRYPTO_PKEY_ASCII_LENGTH]) ) + if ((strlen (&s[npos]) <= GNUNET_CRYPTO_PKEY_ASCII_LENGTH + 1) || + ('.' != s[npos + GNUNET_CRYPTO_PKEY_ASCII_LENGTH])) { *emsg = - GNUNET_strdup (_("LOC URI malformed (wrong syntax for public key)")); + GNUNET_strdup (_ ("LOC URI malformed (wrong syntax for public key)")); } - if (GNUNET_OK != - GNUNET_CRYPTO_eddsa_public_key_from_string (&s[npos], - GNUNET_CRYPTO_PKEY_ASCII_LENGTH, - &ass.peer.public_key)) + if ( + GNUNET_OK != + GNUNET_CRYPTO_eddsa_public_key_from_string (&s[npos], + GNUNET_CRYPTO_PKEY_ASCII_LENGTH, + &ass.peer.public_key)) { *emsg = - GNUNET_strdup (_("LOC URI malformed (could not decode public key)")); + GNUNET_strdup (_ ("LOC URI malformed (could not decode public key)")); goto ERR; } npos += GNUNET_CRYPTO_PKEY_ASCII_LENGTH; if (s[npos++] != '.') { - *emsg = GNUNET_strdup (_("LOC URI malformed (could not find signature)")); + *emsg = GNUNET_strdup (_ ("LOC URI malformed (could not find signature)")); goto ERR; } - if ( (strlen (&s[npos]) <= SIGNATURE_ASCII_LENGTH + 1) || - ('.' != s[npos + SIGNATURE_ASCII_LENGTH]) ) + if ((strlen (&s[npos]) <= SIGNATURE_ASCII_LENGTH + 1) || + ('.' != s[npos + SIGNATURE_ASCII_LENGTH])) { - *emsg = GNUNET_strdup (_("LOC URI malformed (wrong syntax for signature)")); + *emsg = + GNUNET_strdup (_ ("LOC URI malformed (wrong syntax for signature)")); goto ERR; } if (GNUNET_OK != GNUNET_STRINGS_string_to_data (&s[npos], SIGNATURE_ASCII_LENGTH, &sig, - sizeof (struct GNUNET_CRYPTO_EddsaSignature))) + sizeof ( + struct GNUNET_CRYPTO_EddsaSignature))) { - *emsg = GNUNET_strdup (_("LOC URI malformed (could not decode signature)")); + *emsg = + GNUNET_strdup (_ ("LOC URI malformed (could not decode signature)")); goto ERR; } npos += SIGNATURE_ASCII_LENGTH; if (s[npos++] != '.') { - *emsg = GNUNET_strdup (_("LOC URI malformed (wrong syntax for expiration time)")); + *emsg = GNUNET_strdup ( + _ ("LOC URI malformed (wrong syntax for expiration time)")); goto ERR; } - if (1 != SSCANF (&s[npos], "%llu", &exptime)) + if (1 != sscanf (&s[npos], "%llu", &exptime)) { *emsg = - GNUNET_strdup (_("LOC URI malformed (could not parse expiration time)")); + GNUNET_strdup (_ ("LOC URI malformed (could not parse expiration time)")); goto ERR; } ass.purpose.size = htonl (sizeof (struct LocUriAssembly)); @@ -605,10 +606,12 @@ uri_loc_parse (const char *s, ass.exptime = GNUNET_TIME_absolute_hton (et); if (GNUNET_OK != GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT, - &ass.purpose, &sig, &ass.peer.public_key)) + &ass.purpose, + &sig, + &ass.peer.public_key)) { *emsg = - GNUNET_strdup (_("LOC URI malformed (signature failed validation)")); + GNUNET_strdup (_ ("LOC URI malformed (signature failed validation)")); goto ERR; } uri = GNUNET_new (struct GNUNET_FS_Uri); @@ -632,8 +635,7 @@ ERR: * @return NULL on error */ struct GNUNET_FS_Uri * -GNUNET_FS_uri_parse (const char *uri, - char **emsg) +GNUNET_FS_uri_parse (const char *uri, char **emsg) { struct GNUNET_FS_Uri *ret; char *msg; @@ -642,7 +644,7 @@ GNUNET_FS_uri_parse (const char *uri, { GNUNET_break (0); if (NULL != emsg) - *emsg = GNUNET_strdup (_("invalid argument")); + *emsg = GNUNET_strdup (_ ("invalid argument")); return NULL; } if (NULL == emsg) @@ -654,7 +656,7 @@ GNUNET_FS_uri_parse (const char *uri, (NULL != (ret = uri_loc_parse (uri, emsg)))) return ret; if (NULL == *emsg) - *emsg = GNUNET_strdup (_("Unrecognized URI type")); + *emsg = GNUNET_strdup (_ ("Unrecognized URI type")); if (emsg == &msg) GNUNET_free (msg); return NULL; @@ -789,8 +791,9 @@ GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri, if (0 == strcmp (&old[1], keyword)) { uri->data.ksk.keywords[i] = - uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1]; - GNUNET_array_grow (uri->data.ksk.keywords, uri->data.ksk.keywordCount, + uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1]; + GNUNET_array_grow (uri->data.ksk.keywords, + uri->data.ksk.keywordCount, uri->data.ksk.keywordCount - 1); GNUNET_free (old); return; @@ -877,8 +880,7 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri, return NULL; /* we round expiration time to full seconds for SKS URIs */ et.abs_value_us = (expiration_time.abs_value_us / 1000000LL) * 1000000LL; - GNUNET_CRYPTO_eddsa_key_get_public (sign_key, - &my_public_key); + GNUNET_CRYPTO_eddsa_key_get_public (sign_key, &my_public_key); ass.purpose.size = htonl (sizeof (struct LocUriAssembly)); ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); ass.exptime = GNUNET_TIME_absolute_hton (et); @@ -906,7 +908,7 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri, */ struct GNUNET_FS_Uri * GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, - const char *id) + const char *id) { struct GNUNET_FS_Uri *ns_uri; @@ -951,8 +953,7 @@ GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1, return NULL; } kc = u1->data.ksk.keywordCount; - kl = GNUNET_new_array (kc + u2->data.ksk.keywordCount, - char *); + kl = GNUNET_new_array (kc + u2->data.ksk.keywordCount, char *); for (i = 0; i < u1->data.ksk.keywordCount; i++) kl[i] = GNUNET_strdup (u1->data.ksk.keywords[i]); for (i = 0; i < u2->data.ksk.keywordCount; i++) @@ -1006,14 +1007,13 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri) } if (ret->data.ksk.keywordCount > 0) { - ret->data.ksk.keywords - = GNUNET_new_array (ret->data.ksk.keywordCount, - char *); + ret->data.ksk.keywords = + GNUNET_new_array (ret->data.ksk.keywordCount, char *); for (i = 0; i < ret->data.ksk.keywordCount; i++) ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]); } else - ret->data.ksk.keywords = NULL; /* just to be sure */ + ret->data.ksk.keywords = NULL; /* just to be sure */ break; case GNUNET_FS_URI_SKS: ret->data.sks.identifier = GNUNET_strdup (uri->data.sks.identifier); @@ -1045,8 +1045,7 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri) * if keywords is not legal (i.e. empty). */ struct GNUNET_FS_Uri * -GNUNET_FS_uri_ksk_create (const char *keywords, - char **emsg) +GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg) { char **keywordarr; unsigned int num_Words; @@ -1058,7 +1057,7 @@ GNUNET_FS_uri_ksk_create (const char *keywords, if (keywords == NULL) { - *emsg = GNUNET_strdup (_("No keywords specified!\n")); + *emsg = GNUNET_strdup (_ ("No keywords specified!\n")); GNUNET_break (0); return NULL; } @@ -1085,17 +1084,16 @@ GNUNET_FS_uri_ksk_create (const char *keywords, if (num_Words == 0) { GNUNET_free (searchString); - *emsg = GNUNET_strdup (_("No keywords specified!\n")); + *emsg = GNUNET_strdup (_ ("No keywords specified!\n")); return NULL; } if (saw_quote != 0) { GNUNET_free (searchString); - *emsg = GNUNET_strdup (_("Number of double-quotes not balanced!\n")); + *emsg = GNUNET_strdup (_ ("Number of double-quotes not balanced!\n")); return NULL; } - keywordarr = GNUNET_new_array (num_Words, - char *); + keywordarr = GNUNET_new_array (num_Words, char *); num_Words = 0; inWord = 0; pos = searchString; @@ -1117,8 +1115,7 @@ GNUNET_FS_uri_ksk_create (const char *keywords, pos++; } uri = - GNUNET_FS_uri_ksk_create_from_args (num_Words, - (const char **) keywordarr); + GNUNET_FS_uri_ksk_create_from_args (num_Words, (const char **) keywordarr); GNUNET_free (keywordarr); GNUNET_free (searchString); return uri; @@ -1143,8 +1140,7 @@ GNUNET_FS_uri_ksk_create (const char *keywords, * if keywords is not legal (i.e. empty). */ struct GNUNET_FS_Uri * -GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, - const char **argv) +GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv) { unsigned int i; struct GNUNET_FS_Uri *uri; @@ -1160,16 +1156,16 @@ GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, * handle accordingly */ emsg = NULL; if ((argc == 1) && (strlen (argv[0]) > strlen (GNUNET_FS_URI_PREFIX)) && - (0 == - strncmp (argv[0], GNUNET_FS_URI_PREFIX, strlen (GNUNET_FS_URI_PREFIX))) - && (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg)))) + (0 == strncmp (argv[0], + GNUNET_FS_URI_PREFIX, + strlen (GNUNET_FS_URI_PREFIX))) && + (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg)))) return uri; GNUNET_free_non_null (emsg); uri = GNUNET_new (struct GNUNET_FS_Uri); uri->type = GNUNET_FS_URI_KSK; uri->data.ksk.keywordCount = argc; - uri->data.ksk.keywords = GNUNET_new_array (argc, - char *); + uri->data.ksk.keywords = GNUNET_new_array (argc, char *); for (i = 0; i < argc; i++) { keyword = argv[i]; @@ -1220,9 +1216,9 @@ GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, return GNUNET_YES; return GNUNET_NO; case GNUNET_FS_URI_SKS: - if ((0 == - memcmp (&u1->data.sks.ns, &u2->data.sks.ns, - sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) && + if ((0 == memcmp (&u1->data.sks.ns, + &u2->data.sks.ns, + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) && (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier))) return GNUNET_YES; @@ -1246,12 +1242,12 @@ GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, } return GNUNET_YES; case GNUNET_FS_URI_LOC: - if (memcmp - (&u1->data.loc, &u2->data.loc, - sizeof (struct FileIdentifier) + - sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) + - sizeof (struct GNUNET_TIME_Absolute) + sizeof (unsigned short) + - sizeof (unsigned short)) != 0) + if (memcmp (&u1->data.loc, + &u2->data.loc, + sizeof (struct FileIdentifier) + + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) + + sizeof (struct GNUNET_TIME_Absolute) + + sizeof (unsigned short) + sizeof (unsigned short)) != 0) return GNUNET_NO; return GNUNET_YES; default: @@ -1285,7 +1281,7 @@ int GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym) { - if (!GNUNET_FS_uri_test_sks (uri)) + if (! GNUNET_FS_uri_test_sks (uri)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -1304,7 +1300,7 @@ GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, char * GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri) { - if (!GNUNET_FS_uri_test_sks (uri)) + if (! GNUNET_FS_uri_test_sks (uri)) { GNUNET_break (0); return NULL; @@ -1327,7 +1323,7 @@ GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri) if (uri->type == GNUNET_FS_URI_KSK) { - for (i=0;i < uri->data.ksk.keywordCount; i++) + for (i = 0; i < uri->data.ksk.keywordCount; i++) GNUNET_assert (uri->data.ksk.keywords[i] != NULL); } #endif @@ -1356,7 +1352,7 @@ GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri) * @return size of the file as specified in the CHK URI */ uint64_t -GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri * uri) +GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri) { switch (uri->type) { @@ -1367,7 +1363,7 @@ GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri * uri) default: GNUNET_assert (0); } - return 0; /* unreachable */ + return 0; /* unreachable */ } @@ -1394,9 +1390,7 @@ GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri) * @param index offset where to add the keyword */ static void -insert_non_mandatory_keyword (const char *s, - char **array, - int index) +insert_non_mandatory_keyword (const char *s, char **array, int index) { char *nkword; @@ -1417,9 +1411,7 @@ insert_non_mandatory_keyword (const char *s, * @return #GNUNET_YES if the keyword exists, #GNUNET_NO if not */ static int -find_duplicate (const char *s, - const char **array, - int array_length) +find_duplicate (const char *s, const char **array, int array_length) { int j; @@ -1455,12 +1447,19 @@ normalize_metadata (enum EXTRACTOR_MetaFormat format, } if (format == EXTRACTOR_METAFORMAT_C_STRING) { - free_str = u8_strconv_from_encoding (data, locale_charset (), iconveh_escape_sequence); + free_str = u8_strconv_from_encoding (data, + locale_charset (), + iconveh_escape_sequence); if (free_str == NULL) return NULL; } - normalized = u8_tolower (str_to_normalize, strlen ((char *) str_to_normalize), NULL, UNINORM_NFD, NULL, &r_len); + normalized = u8_tolower (str_to_normalize, + strlen ((char *) str_to_normalize), + NULL, + UNINORM_NFD, + NULL, + &r_len); /* free_str is allocated by libunistring internally, use free() */ if (free_str != NULL) free (free_str); @@ -1512,9 +1511,7 @@ u8_strcount (const uint8_t *s) * were duplicates (when extracting). */ static int -get_keywords_from_parens (const char *s, - char **array, - int index) +get_keywords_from_parens (const char *s, char **array, int index) { int count = 0; char *open_paren; @@ -1564,28 +1561,33 @@ get_keywords_from_parens (const char *s, { char *normalized; if (GNUNET_NO == find_duplicate ((const char *) &open_paren[1], - (const char **) array, index + count)) + (const char **) array, + index + count)) { - insert_non_mandatory_keyword ((const char *) &open_paren[1], array, - index + count); + insert_non_mandatory_keyword ((const char *) &open_paren[1], + array, + index + count); count++; } normalized = normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, - &open_paren[1], close_paren - &open_paren[1]); + &open_paren[1], + close_paren - &open_paren[1]); if (normalized != NULL) { if (GNUNET_NO == find_duplicate ((const char *) normalized, - (const char **) array, index + count)) + (const char **) array, + index + count)) { - insert_non_mandatory_keyword ((const char *) normalized, array, - index + count); + insert_non_mandatory_keyword ((const char *) normalized, + array, + index + count); count++; } GNUNET_free (normalized); } } else - count++; + count++; close_paren[0] = tmp; } } @@ -1614,9 +1616,7 @@ get_keywords_from_parens (const char *s, * duplicates (when extracting). */ static int -get_keywords_from_tokens (const char *s, - char **array, - int index) +get_keywords_from_tokens (const char *s, char **array, int index) { char *p; char *ss; @@ -1633,19 +1633,20 @@ get_keywords_from_tokens (const char *s, char *normalized; if (GNUNET_NO == find_duplicate (p, (const char **) array, index + seps)) { - insert_non_mandatory_keyword (p, array, - index + seps); - seps++; + insert_non_mandatory_keyword (p, array, index + seps); + seps++; } - normalized = normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, - p, strlen (p)); + normalized = + normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, p, strlen (p)); if (normalized != NULL) { if (GNUNET_NO == find_duplicate ((const char *) normalized, - (const char **) array, index + seps)) + (const char **) array, + index + seps)) { - insert_non_mandatory_keyword ((const char *) normalized, array, - index + seps); + insert_non_mandatory_keyword ((const char *) normalized, + array, + index + seps); seps++; } GNUNET_free (normalized); @@ -1678,7 +1679,8 @@ get_keywords_from_tokens (const char *s, * @return 0 (always) */ static int -gather_uri_data (void *cls, const char *plugin_name, +gather_uri_data (void *cls, + const char *plugin_name, enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, const char *data_mime_type, @@ -1699,16 +1701,12 @@ gather_uri_data (void *cls, const char *plugin_name, */ if (u8_strcount ((const uint8_t *) data) <= 2) return 0; - if ( (EXTRACTOR_METATYPE_MIMETYPE == type) && - (NULL != (sep = memchr (data, '/', data_len))) && - (sep != data) ) + if ((EXTRACTOR_METATYPE_MIMETYPE == type) && + (NULL != (sep = memchr (data, '/', data_len))) && (sep != data)) { char *xtra; - GNUNET_asprintf (&xtra, - "mimetype:%.*s", - (int) (sep - data), - data); + GNUNET_asprintf (&xtra, "mimetype:%.*s", (int) (sep - data), data); if (! find_duplicate (xtra, (const char **) uri->data.ksk.keywords, uri->data.ksk.keywordCount)) @@ -1727,17 +1725,19 @@ gather_uri_data (void *cls, const char *plugin_name, uri->data.ksk.keywordCount)) { insert_non_mandatory_keyword (data, - uri->data.ksk.keywords, uri->data.ksk.keywordCount); + uri->data.ksk.keywords, + uri->data.ksk.keywordCount); uri->data.ksk.keywordCount++; } if (NULL != normalized_data) - { + { if (! find_duplicate (normalized_data, (const char **) uri->data.ksk.keywords, uri->data.ksk.keywordCount)) { insert_non_mandatory_keyword (normalized_data, - uri->data.ksk.keywords, uri->data.ksk.keywordCount); + uri->data.ksk.keywords, + uri->data.ksk.keywordCount); uri->data.ksk.keywordCount++; } GNUNET_free (normalized_data); @@ -1755,7 +1755,8 @@ gather_uri_data (void *cls, const char *plugin_name, * @return NULL on error, otherwise a KSK URI */ struct GNUNET_FS_Uri * -GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md) +GNUNET_FS_uri_ksk_create_from_meta_data ( + const struct GNUNET_CONTAINER_MetaData *md) { struct GNUNET_FS_Uri *ret; char *filename; @@ -1772,8 +1773,10 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL); if (ent > 0) { - full_name = GNUNET_CONTAINER_meta_data_get_first_by_types (md, - EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, -1); + full_name = GNUNET_CONTAINER_meta_data_get_first_by_types ( + md, + EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, + -1); if (NULL != full_name) { filename = full_name; @@ -1784,19 +1787,20 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData } /* x3 because there might be a normalized variant of every keyword, plus theoretically one more for mime... */ - ret->data.ksk.keywords - = GNUNET_new_array ((ent + tok_keywords + paren_keywords) * 3, - char *); + ret->data.ksk.keywords = + GNUNET_new_array ((ent + tok_keywords + paren_keywords) * 3, char *); GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret); } if (tok_keywords > 0) - ret->data.ksk.keywordCount += get_keywords_from_tokens (filename, - ret->data.ksk.keywords, - ret->data.ksk.keywordCount); + ret->data.ksk.keywordCount += + get_keywords_from_tokens (filename, + ret->data.ksk.keywords, + ret->data.ksk.keywordCount); if (paren_keywords > 0) - ret->data.ksk.keywordCount += get_keywords_from_parens (filename, - ret->data.ksk.keywords, - ret->data.ksk.keywordCount); + ret->data.ksk.keywordCount += + get_keywords_from_parens (filename, + ret->data.ksk.keywords, + ret->data.ksk.keywordCount); if (ent > 0) GNUNET_free_non_null (full_name); return ret; @@ -1810,9 +1814,8 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData static int needs_percent (char c) { - return (! - ((isalnum ((unsigned char) c)) || (c == '-') || (c == '_') || - (c == '.') || (c == '~'))); + return (! ((isalnum ((unsigned char) c)) || (c == '-') || (c == '_') || + (c == '.') || (c == '~'))); } @@ -1851,10 +1854,10 @@ uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) if ((j == 0) && (keyword[j] == ' ')) { n--; - continue; /* skip leading space */ + continue; /* skip leading space */ } if (needs_percent (keyword[j])) - n += 2; /* will use %-encoding */ + n += 2; /* will use %-encoding */ } } ret = GNUNET_malloc (n); @@ -1868,7 +1871,7 @@ uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) for (j = 0; j < slen; j++) { if ((j == 0) && (keyword[j] == ' ')) - continue; /* skip leading space */ + continue; /* skip leading space */ if (needs_percent (keyword[j])) { sprintf (&ret[wpos], "%%%02X", (unsigned char) keyword[j]); @@ -1900,15 +1903,19 @@ uri_sks_to_string (const struct GNUNET_FS_Uri *uri) if (GNUNET_FS_URI_SKS != uri->type) return NULL; - ret = GNUNET_STRINGS_data_to_string (&uri->data.sks.ns, - sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), - buf, - sizeof (buf)); + ret = + GNUNET_STRINGS_data_to_string (&uri->data.sks.ns, + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), + buf, + sizeof (buf)); GNUNET_assert (NULL != ret); ret[0] = '\0'; - GNUNET_asprintf (&ret, "%s%s%s/%s", GNUNET_FS_URI_PREFIX, - GNUNET_FS_URI_SKS_INFIX, buf, - uri->data.sks.identifier); + GNUNET_asprintf (&ret, + "%s%s%s/%s", + GNUNET_FS_URI_PREFIX, + GNUNET_FS_URI_SKS_INFIX, + buf, + uri->data.sks.identifier); return ret; } @@ -1933,9 +1940,13 @@ uri_chk_to_string (const struct GNUNET_FS_Uri *uri) GNUNET_CRYPTO_hash_to_enc (&fi->chk.key, &keyhash); GNUNET_CRYPTO_hash_to_enc (&fi->chk.query, &queryhash); - GNUNET_asprintf (&ret, "%s%s%s.%s.%llu", GNUNET_FS_URI_PREFIX, - GNUNET_FS_URI_CHK_INFIX, (const char *) &keyhash, - (const char *) &queryhash, GNUNET_ntohll (fi->file_length)); + GNUNET_asprintf (&ret, + "%s%s%s.%s.%llu", + GNUNET_FS_URI_PREFIX, + GNUNET_FS_URI_CHK_INFIX, + (const char *) &keyhash, + (const char *) &queryhash, + GNUNET_ntohll (fi->file_length)); return ret; } @@ -1959,20 +1970,25 @@ uri_loc_to_string (const struct GNUNET_FS_Uri *uri) GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash); peer_id = GNUNET_CRYPTO_eddsa_public_key_to_string (&uri->data.loc.peer.public_key); - GNUNET_assert (NULL != - GNUNET_STRINGS_data_to_string (&uri->data.loc.contentSignature, - sizeof (struct GNUNET_CRYPTO_EddsaSignature), - peer_sig, - sizeof (peer_sig))); + GNUNET_assert ( + NULL != + GNUNET_STRINGS_data_to_string (&uri->data.loc.contentSignature, + sizeof (struct GNUNET_CRYPTO_EddsaSignature), + peer_sig, + sizeof (peer_sig))); GNUNET_asprintf (&ret, - "%s%s%s.%s.%llu.%s.%s.%llu", GNUNET_FS_URI_PREFIX, - GNUNET_FS_URI_LOC_INFIX, (const char *) &keyhash, + "%s%s%s.%s.%llu.%s.%s.%llu", + GNUNET_FS_URI_PREFIX, + GNUNET_FS_URI_LOC_INFIX, + (const char *) &keyhash, (const char *) &queryhash, - (unsigned long long) GNUNET_ntohll (uri->data.loc. - fi.file_length), + (unsigned long long) GNUNET_ntohll ( + uri->data.loc.fi.file_length), peer_id, peer_sig, - (unsigned long long) uri->data.loc.expirationTime.abs_value_us / 1000000LL); + (unsigned long long) + uri->data.loc.expirationTime.abs_value_us / + 1000000LL); GNUNET_free (peer_id); return ret; } diff --git a/src/fs/gnunet-auto-share.c b/src/fs/gnunet-auto-share.c index ba28c5c23..8b04e474d 100644 --- a/src/fs/gnunet-auto-share.c +++ b/src/fs/gnunet-auto-share.c @@ -512,7 +512,7 @@ determine_id (void *cls, const char *filename) struct GNUNET_HashCode fx[2]; struct GNUNET_HashCode ft; - if (0 != STAT (filename, &sbuf)) + if (0 != stat (filename, &sbuf)) { GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); return GNUNET_OK; diff --git a/src/fs/gnunet-directory.c b/src/fs/gnunet-directory.c index 097dd4406..4cce69d72 100644 --- a/src/fs/gnunet-directory.c +++ b/src/fs/gnunet-directory.c @@ -50,7 +50,7 @@ item_printer (void *cls, { if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA) { - printf (_("\t\n"), + printf (_ ("\t\n"), (unsigned int) data_size); return 0; } @@ -63,17 +63,14 @@ item_printer (void *cls, printf ("\t%20s: %s\n", dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, EXTRACTOR_metatype_to_string (type)), - data); -#else - printf ("\t%20d: %s\n", - type, data); +#else + printf ("\t%20d: %s\n", type, data); #endif return 0; } - /** * Print an entry in a directory. * @@ -90,22 +87,25 @@ item_printer (void *cls, * @param data data available for the file (length bytes) */ static void -print_entry (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, - const struct GNUNET_CONTAINER_MetaData *meta, size_t length, +print_entry (void *cls, + const char *filename, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_CONTAINER_MetaData *meta, + size_t length, const void *data) { char *string; char *name; - name = - GNUNET_CONTAINER_meta_data_get_by_type (meta, - EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); + name = GNUNET_CONTAINER_meta_data_get_by_type ( + meta, + EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); if (uri == NULL) { - printf (_("Directory `%s' meta data:\n"), name ? name : ""); + printf (_ ("Directory `%s' meta data:\n"), name ? name : ""); GNUNET_CONTAINER_meta_data_iterate (meta, &item_printer, NULL); printf ("\n"); - printf (_("Directory `%s' contents:\n"), name ? name : ""); + printf (_ ("Directory `%s' contents:\n"), name ? name : ""); GNUNET_free_non_null (name); return; } @@ -127,7 +127,9 @@ print_entry (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, * @param cfg configuration */ static void -run (void *cls, char *const *args, const char *cfgfile, +run (void *cls, + char *const *args, + const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_DISK_MapHandle *map; @@ -140,20 +142,21 @@ run (void *cls, char *const *args, const char *cfgfile, if (NULL == args[0]) { - FPRINTF (stderr, "%s", _("You must specify a filename to inspect.\n")); + fprintf (stderr, "%s", _ ("You must specify a filename to inspect.\n")); ret = 1; return; } i = 0; while (NULL != (filename = args[i++])) { - if ((GNUNET_OK != GNUNET_DISK_file_size (filename, &size, GNUNET_YES, GNUNET_YES)) || - (NULL == - (h = - GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE)))) + if ((GNUNET_OK != + GNUNET_DISK_file_size (filename, &size, GNUNET_YES, GNUNET_YES)) || + (NULL == (h = GNUNET_DISK_file_open (filename, + GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_NONE)))) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to read directory `%s'\n"), + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Failed to read directory `%s'\n"), filename); ret = 1; continue; @@ -161,9 +164,9 @@ run (void *cls, char *const *args, const char *cfgfile, len = (size_t) size; data = GNUNET_DISK_file_map (h, &map, GNUNET_DISK_MAP_TYPE_READ, len); GNUNET_assert (NULL != data); - if (GNUNET_OK != GNUNET_FS_directory_list_contents (len, data, 0, &print_entry, NULL)) - fprintf (stdout, _("`%s' is not a GNUnet directory\n"), - filename); + if (GNUNET_OK != + GNUNET_FS_directory_list_contents (len, data, 0, &print_entry, NULL)) + fprintf (stdout, _ ("`%s' is not a GNUnet directory\n"), filename); else printf ("\n"); GNUNET_DISK_file_unmap (map); @@ -182,18 +185,23 @@ int main (int argc, char *const *argv) { static struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_OPTION_END - }; + GNUNET_GETOPT_OPTION_END}; if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) return 2; ret = (GNUNET_OK == - GNUNET_PROGRAM_run (argc, argv, "gnunet-directory [OPTIONS] FILENAME", - gettext_noop - ("Display contents of a GNUnet directory"), - options, &run, NULL)) ? ret : 1; - GNUNET_free ((void*) argv); + GNUNET_PROGRAM_run (argc, + argv, + "gnunet-directory [OPTIONS] FILENAME", + gettext_noop ( + "Display contents of a GNUnet directory"), + options, + &run, + NULL)) + ? ret + : 1; + GNUNET_free ((void *) argv); return ret; } diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c index 31e62c603..00e8336a2 100644 --- a/src/fs/gnunet-download.c +++ b/src/fs/gnunet-download.c @@ -80,33 +80,30 @@ shutdown_task (void *cls) * @param w desired number of steps in the progress bar */ static void -display_bar (unsigned long long x, - unsigned long long n, - unsigned int w) +display_bar (unsigned long long x, unsigned long long n, unsigned int w) { char buf[w + 20]; unsigned int p; unsigned int endeq; float ratio_complete; -#if !WINDOWS +#if ! WINDOWS if (0 == isatty (1)) return; #else if (FILE_TYPE_CHAR != GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) return; #endif - ratio_complete = x/(float)n; + ratio_complete = x / (float) n; endeq = ratio_complete * w; - GNUNET_snprintf (buf, sizeof (buf), - "%3d%% [", (int)(ratio_complete*100) ); - for (p=0; p 1) - FPRINTF (stderr, - _("Starting download `%s'.\n"), + fprintf (stderr, + _ ("Starting download `%s'.\n"), info->value.download.filename); break; case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: if (verbose) { - s = GNUNET_strdup (GNUNET_STRINGS_relative_time_to_string (info->value.download.eta, - GNUNET_YES)); - if (info->value.download.specifics.progress.block_download_duration.rel_value_us - == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) - s2 = _(""); + s = GNUNET_strdup ( + GNUNET_STRINGS_relative_time_to_string (info->value.download.eta, + GNUNET_YES)); + if (info->value.download.specifics.progress.block_download_duration + .rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) + s2 = _ (""); else - s2 = GNUNET_STRINGS_relative_time_to_string (info->value.download.specifics.progress.block_download_duration, - GNUNET_YES); - t = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed * - 1000LL / - (info->value.download. - duration.rel_value_us + 1)); - FPRINTF (stdout, - _("Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"), - info->value.download.filename, - (unsigned long long) info->value.download.completed, - (unsigned long long) info->value.download.size, - s, - t, - s2); + s2 = GNUNET_STRINGS_relative_time_to_string (info->value.download + .specifics.progress + .block_download_duration, + GNUNET_YES); + t = GNUNET_STRINGS_byte_size_fancy ( + info->value.download.completed * 1000LL / + (info->value.download.duration.rel_value_us + 1)); + fprintf ( + stdout, + _ ( + "Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"), + info->value.download.filename, + (unsigned long long) info->value.download.completed, + (unsigned long long) info->value.download.size, + s, + t, + s2); GNUNET_free (s); GNUNET_free (t); } else { display_bar (info->value.download.completed, - info->value.download.size, - 60); + info->value.download.size, + 60); } break; case GNUNET_FS_STATUS_DOWNLOAD_ERROR: -#if !WINDOWS +#if ! WINDOWS if (0 != isatty (1)) fprintf (stdout, "\n"); #else - if (FILE_TYPE_CHAR == - GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) + if (FILE_TYPE_CHAR == GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) fprintf (stdout, "\n"); #endif - FPRINTF (stderr, _("Error downloading: %s.\n"), + fprintf (stderr, + _ ("Error downloading: %s.\n"), info->value.download.specifics.error.message); GNUNET_SCHEDULER_shutdown (); break; case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: - s = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed * 1000 / - (info->value.download. - duration.rel_value_us + 1)); -#if !WINDOWS + s = GNUNET_STRINGS_byte_size_fancy ( + info->value.download.completed * 1000 / + (info->value.download.duration.rel_value_us + 1)); +#if ! WINDOWS if (0 != isatty (1)) fprintf (stdout, "\n"); #else - if (FILE_TYPE_CHAR == - GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) + if (FILE_TYPE_CHAR == GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) fprintf (stdout, "\n"); #endif - FPRINTF (stdout, - _("Downloading `%s' done (%s/s).\n"), - info->value.download.filename, s); + fprintf (stdout, + _ ("Downloading `%s' done (%s/s).\n"), + info->value.download.filename, + s); GNUNET_free (s); if (info->value.download.dc == dc) GNUNET_SCHEDULER_shutdown (); @@ -212,9 +212,7 @@ progress_cb (void *cls, case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: break; default: - FPRINTF (stderr, - _("Unexpected status: %d\n"), - info->status); + fprintf (stderr, _ ("Unexpected status: %d\n"), info->status); break; } return NULL; @@ -241,55 +239,45 @@ run (void *cls, if (NULL == args[0]) { - FPRINTF (stderr, - "%s", - _("You need to specify a URI argument.\n")); + fprintf (stderr, "%s", _ ("You need to specify a URI argument.\n")); return; } uri = GNUNET_FS_uri_parse (args[0], &emsg); if (NULL == uri) { - FPRINTF (stderr, - _("Failed to parse URI: %s\n"), - emsg); + fprintf (stderr, _ ("Failed to parse URI: %s\n"), emsg); GNUNET_free (emsg); ret = 1; return; } - if ( (! GNUNET_FS_uri_test_chk (uri)) && - (! GNUNET_FS_uri_test_loc (uri))) + if ((! GNUNET_FS_uri_test_chk (uri)) && (! GNUNET_FS_uri_test_loc (uri))) { - FPRINTF (stderr, - "%s", - _("Only CHK or LOC URIs supported.\n")); + fprintf (stderr, "%s", _ ("Only CHK or LOC URIs supported.\n")); ret = 1; GNUNET_FS_uri_destroy (uri); return; } if (NULL == filename) { - FPRINTF (stderr, - "%s", - _("Target filename must be specified.\n")); + fprintf (stderr, "%s", _ ("Target filename must be specified.\n")); ret = 1; GNUNET_FS_uri_destroy (uri); return; } cfg = c; ctx = GNUNET_FS_start (cfg, - "gnunet-download", - &progress_cb, NULL, - GNUNET_FS_FLAGS_NONE, - GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, - parallelism, - GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, - request_parallelism, - GNUNET_FS_OPTIONS_END); + "gnunet-download", + &progress_cb, + NULL, + GNUNET_FS_FLAGS_NONE, + GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, + parallelism, + GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, + request_parallelism, + GNUNET_FS_OPTIONS_END); if (NULL == ctx) { - FPRINTF (stderr, - _("Could not initialize `%s' subsystem.\n"), - "FS"); + fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS"); GNUNET_FS_uri_destroy (uri); ret = 1; return; @@ -300,16 +288,16 @@ run (void *cls, if (local_only) options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY; dc = GNUNET_FS_download_start (ctx, - uri, - NULL, - filename, - NULL, - 0, + uri, + NULL, + filename, + NULL, + 0, GNUNET_FS_uri_chk_get_file_size (uri), anonymity, - options, - NULL, - NULL); + options, + NULL, + NULL); GNUNET_FS_uri_destroy (uri); if (dc == NULL) { @@ -317,8 +305,7 @@ run (void *cls, ctx = NULL; return; } - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, - NULL); + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); } @@ -332,61 +319,73 @@ run (void *cls, int main (int argc, char *const *argv) { - struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_option_uint ('a', - "anonymity", - "LEVEL", - gettext_noop ("set the desired LEVEL of receiver-anonymity"), - &anonymity), - - GNUNET_GETOPT_option_flag ('D', - "delete-incomplete", - gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"), - &delete_incomplete), - - GNUNET_GETOPT_option_flag ('n', - "no-network", - gettext_noop ("only search the local peer (no P2P network search)"), - &local_only), - GNUNET_GETOPT_option_string ('o', - "output", - "FILENAME", - gettext_noop ("write the file to FILENAME"), - &filename), - GNUNET_GETOPT_option_uint ('p', - "parallelism", - "DOWNLOADS", - gettext_noop ("set the maximum number of parallel downloads that is allowed"), - ¶llelism), - GNUNET_GETOPT_option_uint ('r', - "request-parallelism", - "REQUESTS", - gettext_noop ("set the maximum number of parallel requests for blocks that is allowed"), - &request_parallelism), - GNUNET_GETOPT_option_flag ('R', - "recursive", - gettext_noop ("download a GNUnet directory recursively"), - &do_recursive), - GNUNET_GETOPT_option_increment_uint ('V', - "verbose", - gettext_noop ("be verbose (print progress information)"), - &verbose), - GNUNET_GETOPT_OPTION_END - }; - - if (GNUNET_OK != - GNUNET_STRINGS_get_utf8_args (argc, argv, - &argc, &argv)) + struct GNUNET_GETOPT_CommandLineOption options[] = + {GNUNET_GETOPT_option_uint ('a', + "anonymity", + "LEVEL", + gettext_noop ( + "set the desired LEVEL of receiver-anonymity"), + &anonymity), + + GNUNET_GETOPT_option_flag ( + 'D', + "delete-incomplete", + gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"), + &delete_incomplete), + + GNUNET_GETOPT_option_flag ( + 'n', + "no-network", + gettext_noop ("only search the local peer (no P2P network search)"), + &local_only), + GNUNET_GETOPT_option_string ('o', + "output", + "FILENAME", + gettext_noop ("write the file to FILENAME"), + &filename), + GNUNET_GETOPT_option_uint ( + 'p', + "parallelism", + "DOWNLOADS", + gettext_noop ( + "set the maximum number of parallel downloads that is allowed"), + ¶llelism), + GNUNET_GETOPT_option_uint ( + 'r', + "request-parallelism", + "REQUESTS", + gettext_noop ( + "set the maximum number of parallel requests for blocks that is allowed"), + &request_parallelism), + GNUNET_GETOPT_option_flag ('R', + "recursive", + gettext_noop ( + "download a GNUnet directory recursively"), + &do_recursive), + GNUNET_GETOPT_option_increment_uint ( + 'V', + "verbose", + gettext_noop ("be verbose (print progress information)"), + &verbose), + GNUNET_GETOPT_OPTION_END}; + + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) return 2; - ret = (GNUNET_OK == - GNUNET_PROGRAM_run (argc, argv, - "gnunet-download [OPTIONS] URI", - gettext_noop - ("Download files from GNUnet using a GNUnet CHK or LOC URI (gnunet://fs/chk/...)"), - options, - &run, NULL)) ? ret : 1; - GNUNET_free ((void*) argv); + ret = + (GNUNET_OK == + GNUNET_PROGRAM_run ( + argc, + argv, + "gnunet-download [OPTIONS] URI", + gettext_noop ( + "Download files from GNUnet using a GNUnet CHK or LOC URI (gnunet://fs/chk/...)"), + options, + &run, + NULL)) + ? ret + : 1; + GNUNET_free ((void *) argv); return ret; } diff --git a/src/fs/gnunet-fs.c b/src/fs/gnunet-fs.c index 26970c06a..ad2a8d6c5 100644 --- a/src/fs/gnunet-fs.c +++ b/src/fs/gnunet-fs.c @@ -55,7 +55,9 @@ static unsigned int verbose; * @return GNUNET_OK to continue iteration */ static int -print_indexed (void *cls, const char *filename, const struct GNUNET_HashCode * file_id) +print_indexed (void *cls, + const char *filename, + const struct GNUNET_HashCode *file_id) { if (NULL == filename) { @@ -64,9 +66,9 @@ print_indexed (void *cls, const char *filename, const struct GNUNET_HashCode * f return GNUNET_OK; } if (verbose) - FPRINTF (stdout, "%s: %s\n", GNUNET_h2s (file_id), filename); + fprintf (stdout, "%s: %s\n", GNUNET_h2s (file_id), filename); else - FPRINTF (stdout, "%s\n", filename); + fprintf (stdout, "%s\n", filename); return GNUNET_OK; } @@ -80,12 +82,18 @@ print_indexed (void *cls, const char *filename, const struct GNUNET_HashCode * f * @param cfg configuration */ static void -run (void *cls, char *const *args, const char *cfgfile, +run (void *cls, + char *const *args, + const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { if (list_indexed_files) { - fs = GNUNET_FS_start (cfg, "gnunet-fs", NULL, NULL, GNUNET_FS_FLAGS_NONE, + fs = GNUNET_FS_start (cfg, + "gnunet-fs", + NULL, + NULL, + GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); if (NULL == fs) { @@ -115,21 +123,27 @@ main (int argc, char *const *argv) struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_option_flag ('i', - "list-indexed", - gettext_noop ("print a list of all indexed files"), - &list_indexed_files), + "list-indexed", + gettext_noop ( + "print a list of all indexed files"), + &list_indexed_files), GNUNET_GETOPT_option_verbose (&verbose), - GNUNET_GETOPT_OPTION_END - }; + GNUNET_GETOPT_OPTION_END}; if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) return 2; ret = (GNUNET_OK == - GNUNET_PROGRAM_run (argc, argv, "gnunet-fs [OPTIONS]", - gettext_noop ("Special file-sharing operations"), - options, &run, NULL)) ? ret : 1; - GNUNET_free ((void*) argv); + GNUNET_PROGRAM_run (argc, + argv, + "gnunet-fs [OPTIONS]", + gettext_noop ("Special file-sharing operations"), + options, + &run, + NULL)) + ? ret + : 1; + GNUNET_free ((void *) argv); return ret; } diff --git a/src/fs/gnunet-helper-fs-publish.c b/src/fs/gnunet-helper-fs-publish.c index fefb33e14..dcb4b47cd 100644 --- a/src/fs/gnunet-helper-fs-publish.c +++ b/src/fs/gnunet-helper-fs-publish.c @@ -78,7 +78,6 @@ struct ScanTreeNode * #GNUNET_YES if this is a directory */ int is_directory; - }; @@ -124,20 +123,30 @@ add_to_md (void *cls, { struct GNUNET_CONTAINER_MetaData *md = cls; - if ( ((EXTRACTOR_METAFORMAT_UTF8 == format) || - (EXTRACTOR_METAFORMAT_C_STRING == format)) && - ('\0' != data[data_len - 1]) ) + if (((EXTRACTOR_METAFORMAT_UTF8 == format) || + (EXTRACTOR_METAFORMAT_C_STRING == format)) && + ('\0' != data[data_len - 1])) { char zdata[data_len + 1]; GNUNET_memcpy (zdata, data, data_len); zdata[data_len] = '\0'; - (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, type, format, - data_mime_type, zdata, data_len + 1); + (void) GNUNET_CONTAINER_meta_data_insert (md, + plugin_name, + type, + format, + data_mime_type, + zdata, + data_len + 1); } else { - (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, type, format, - data_mime_type, data, data_len); + (void) GNUNET_CONTAINER_meta_data_insert (md, + plugin_name, + type, + format, + data_mime_type, + data, + data_len); } return 0; } @@ -158,8 +167,8 @@ free_tree (struct ScanTreeNode *tree) free_tree (pos); if (NULL != tree->parent) GNUNET_CONTAINER_DLL_remove (tree->parent->children_head, - tree->parent->children_tail, - tree); + tree->parent->children_tail, + tree); GNUNET_free (tree->filename); GNUNET_free (tree); } @@ -173,8 +182,7 @@ free_tree (struct ScanTreeNode *tree) * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int -write_all (const void *buf, - size_t size) +write_all (const void *buf, size_t size) { const char *cbuf = buf; size_t total; @@ -183,16 +191,14 @@ write_all (const void *buf, total = 0; do { - wr = write (output_stream, - &cbuf[total], - size - total); + wr = write (output_stream, &cbuf[total], size - total); if (wr > 0) total += wr; - } while ( (wr > 0) && (total < size) ); + } while ((wr > 0) && (total < size)); if (wr <= 0) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Failed to write to stdout: %s\n", - strerror (errno)); + "Failed to write to stdout: %s\n", + strerror (errno)); return (total == size) ? GNUNET_OK : GNUNET_SYSERR; } @@ -206,9 +212,7 @@ write_all (const void *buf, * @return #GNUNET_SYSERR to stop scanning (the pipe was broken somehow) */ static int -write_message (uint16_t message_type, - const char *data, - size_t data_length) +write_message (uint16_t message_type, const char *data, size_t data_length) { struct GNUNET_MessageHeader hdr; @@ -220,12 +224,8 @@ write_message (uint16_t message_type, #endif hdr.type = htons (message_type); hdr.size = htons (sizeof (struct GNUNET_MessageHeader) + data_length); - if ( (GNUNET_OK != - write_all (&hdr, - sizeof (hdr))) || - (GNUNET_OK != - write_all (data, - data_length)) ) + if ((GNUNET_OK != write_all (&hdr, sizeof (hdr))) || + (GNUNET_OK != write_all (data, data_length))) return GNUNET_SYSERR; return GNUNET_OK; } @@ -242,8 +242,7 @@ write_message (uint16_t message_type, * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int -preprocess_file (const char *filename, - struct ScanTreeNode **dst); +preprocess_file (const char *filename, struct ScanTreeNode **dst); /** @@ -273,15 +272,12 @@ struct RecursionContext * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int -scan_callback (void *cls, - const char *filename) +scan_callback (void *cls, const char *filename) { struct RecursionContext *rc = cls; struct ScanTreeNode *chld; - if (GNUNET_OK != - preprocess_file (filename, - &chld)) + if (GNUNET_OK != preprocess_file (filename, &chld)) { rc->stop = GNUNET_YES; return GNUNET_SYSERR; @@ -290,8 +286,8 @@ scan_callback (void *cls, return GNUNET_OK; chld->parent = rc->parent; GNUNET_CONTAINER_DLL_insert (rc->parent->children_head, - rc->parent->children_tail, - chld); + rc->parent->children_tail, + chld); return GNUNET_OK; } @@ -307,22 +303,23 @@ scan_callback (void *cls, * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int -preprocess_file (const char *filename, - struct ScanTreeNode **dst) +preprocess_file (const char *filename, struct ScanTreeNode **dst) { struct ScanTreeNode *item; struct stat sbuf; uint64_t fsize = 0; - if ((0 != STAT (filename, &sbuf)) || - ((!S_ISDIR (sbuf.st_mode)) && (GNUNET_OK != GNUNET_DISK_file_size ( - filename, &fsize, GNUNET_NO, GNUNET_YES)))) + if ((0 != stat (filename, &sbuf)) || + ((! S_ISDIR (sbuf.st_mode)) && + (GNUNET_OK != + GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES)))) { /* If the file doesn't exist (or is not stat-able for any other reason) skip it (but report it), but do continue. */ if (GNUNET_OK != - write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE, - filename, strlen (filename) + 1)) + write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE, + filename, + strlen (filename) + 1)) return GNUNET_SYSERR; /* recoverable error, store 'NULL' in *dst */ *dst = NULL; @@ -330,11 +327,13 @@ preprocess_file (const char *filename, } /* Report the progress */ - if (GNUNET_OK != - write_message (S_ISDIR (sbuf.st_mode) - ? GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY - : GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE, - filename, strlen (filename) + 1)) + if ( + GNUNET_OK != + write_message (S_ISDIR (sbuf.st_mode) + ? GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY + : GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE, + filename, + strlen (filename) + 1)) return GNUNET_SYSERR; item = GNUNET_new (struct ScanTreeNode); item->filename = GNUNET_strdup (filename); @@ -346,13 +345,13 @@ preprocess_file (const char *filename, rc.parent = item; rc.stop = GNUNET_NO; - GNUNET_DISK_directory_scan (filename, - &scan_callback, - &rc); - if ( (GNUNET_YES == rc.stop) || - (GNUNET_OK != - write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY, - "..", 3)) ) + GNUNET_DISK_directory_scan (filename, &scan_callback, &rc); + if ( + (GNUNET_YES == rc.stop) || + (GNUNET_OK != + write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY, + "..", + 3))) { free_tree (item); return GNUNET_SYSERR; @@ -383,20 +382,15 @@ extract_files (struct ScanTreeNode *item) struct ScanTreeNode *pos; for (pos = item->children_head; NULL != pos; pos = pos->next) - if (GNUNET_OK != - extract_files (pos)) - return GNUNET_SYSERR; + if (GNUNET_OK != extract_files (pos)) + return GNUNET_SYSERR; return GNUNET_OK; } /* this is the expensive operation, *afterwards* we'll check for aborts */ meta = GNUNET_CONTAINER_meta_data_create (); #if HAVE_LIBEXTRACTOR - EXTRACTOR_extract (plugins, - item->filename, - NULL, 0, - &add_to_md, - meta); + EXTRACTOR_extract (plugins, item->filename, NULL, 0, &add_to_md, meta); #endif slen = strlen (item->filename) + 1; size = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); @@ -405,8 +399,9 @@ extract_files (struct ScanTreeNode *item) /* no meta data */ GNUNET_CONTAINER_meta_data_destroy (meta); if (GNUNET_OK != - write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, - item->filename, slen)) + write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, + item->filename, + slen)) return GNUNET_SYSERR; return GNUNET_OK; } @@ -420,9 +415,11 @@ extract_files (struct ScanTreeNode *item) char *dst = &buf[slen]; GNUNET_memcpy (buf, item->filename, slen); - size = GNUNET_CONTAINER_meta_data_serialize (meta, - &dst, size, - GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); + size = GNUNET_CONTAINER_meta_data_serialize ( + meta, + &dst, + size, + GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); if (size < 0) { GNUNET_break (0); @@ -430,9 +427,9 @@ extract_files (struct ScanTreeNode *item) } GNUNET_CONTAINER_meta_data_destroy (meta); if (GNUNET_OK != - write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, - buf, - slen + size)) + write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, + buf, + slen + size)) return GNUNET_SYSERR; } return GNUNET_OK; @@ -453,13 +450,14 @@ ignore_sigpipe () sig.sa_handler = SIG_IGN; sigemptyset (&sig.sa_mask); #ifdef SA_INTERRUPT - sig.sa_flags = SA_INTERRUPT; /* SunOS */ + sig.sa_flags = SA_INTERRUPT; /* SunOS */ #else sig.sa_flags = SA_RESTART; #endif if (0 != sigaction (SIGPIPE, &sig, &oldsig)) fprintf (stderr, - "Failed to install SIGPIPE handler: %s\n", strerror (errno)); + "Failed to install SIGPIPE handler: %s\n", + strerror (errno)); } @@ -470,8 +468,7 @@ ignore_sigpipe () * @param flags flags to use (O_RDONLY or O_WRONLY) */ static void -make_dev_zero (int fd, - int flags) +make_dev_zero (int fd, int flags) { int z; @@ -498,8 +495,7 @@ make_dev_zero (int fd, * @return 0 on success */ int -main (int argc, - char *const *argv) +main (int argc, char *const *argv) { const char *filename_expanded; const char *ex; @@ -524,79 +520,83 @@ main (int argc, #endif /* parse command line */ - if ( (3 != argc) && (2 != argc) ) + if ((3 != argc) && (2 != argc)) { - FPRINTF (stderr, - "%s", - "gnunet-helper-fs-publish needs exactly one or two arguments\n"); + fprintf (stderr, + "%s", + "gnunet-helper-fs-publish needs exactly one or two arguments\n"); #if WINDOWS - GNUNET_free ((void*) argv); + GNUNET_free ((void *) argv); #endif return 1; } filename_expanded = argv[1]; ex = argv[2]; - if ( (NULL == ex) || - (0 != strcmp (ex, "-")) ) + if ((NULL == ex) || (0 != strcmp (ex, "-"))) { #if HAVE_LIBEXTRACTOR plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY); if (NULL != ex) - plugins = EXTRACTOR_plugin_add_config (plugins, ex, - EXTRACTOR_OPTION_DEFAULT_POLICY); + plugins = EXTRACTOR_plugin_add_config (plugins, + ex, + EXTRACTOR_OPTION_DEFAULT_POLICY); #endif } /* scan tree to find out how much work there is to be done */ - if (GNUNET_OK != preprocess_file (filename_expanded, - &root)) + if (GNUNET_OK != preprocess_file (filename_expanded, &root)) { (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0); #if HAVE_LIBEXTRACTOR EXTRACTOR_plugin_remove_all (plugins); #endif #if WINDOWS - GNUNET_free ((void*) argv); + GNUNET_free ((void *) argv); #endif return 2; } /* signal that we're done counting files, so that a percentage of progress can now be calculated */ if (GNUNET_OK != - write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE, NULL, 0)) + write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE, + NULL, + 0)) { #if HAVE_LIBEXTRACTOR EXTRACTOR_plugin_remove_all (plugins); #endif #if WINDOWS - GNUNET_free ((void*) argv); + GNUNET_free ((void *) argv); #endif return 3; } if (NULL != root) { - if (GNUNET_OK != - extract_files (root)) + if (GNUNET_OK != extract_files (root)) { - (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0); + (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, + NULL, + 0); free_tree (root); #if HAVE_LIBEXTRACTOR EXTRACTOR_plugin_remove_all (plugins); #endif #if WINDOWS - GNUNET_free ((void*) argv); + GNUNET_free ((void *) argv); #endif return 4; } free_tree (root); } /* enable "clean" shutdown by telling parent that we are done */ - (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED, NULL, 0); + (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED, + NULL, + 0); #if HAVE_LIBEXTRACTOR EXTRACTOR_plugin_remove_all (plugins); #endif #if WINDOWS - GNUNET_free ((void*) argv); + GNUNET_free ((void *) argv); #endif return 0; } diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c index fbf32c2a7..84cbf0aac 100644 --- a/src/fs/gnunet-publish.c +++ b/src/fs/gnunet-publish.c @@ -67,7 +67,7 @@ static struct GNUNET_FS_Uri *topKeywords; /** * Options we set for published blocks. */ -static struct GNUNET_FS_BlockOptions bo = { {0LL}, 1, 365, 1 }; +static struct GNUNET_FS_BlockOptions bo = {{0LL}, 1, 365, 1}; /** * Value of URI provided on command-line (when not publishing @@ -200,8 +200,7 @@ do_stop_task (void *cls) * field in the GNUNET_FS_ProgressInfo struct. */ static void * -progress_cb (void *cls, - const struct GNUNET_FS_ProgressInfo *info) +progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) { const char *s; char *suri; @@ -214,50 +213,51 @@ progress_cb (void *cls, if (verbose) { s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.eta, - GNUNET_YES); - FPRINTF (stdout, - _("Publishing `%s' at %llu/%llu (%s remaining)\n"), + GNUNET_YES); + fprintf (stdout, + _ ("Publishing `%s' at %llu/%llu (%s remaining)\n"), info->value.publish.filename, (unsigned long long) info->value.publish.completed, - (unsigned long long) info->value.publish.size, s); + (unsigned long long) info->value.publish.size, + s); } break; case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: if (verbose) { - s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.specifics.progress_directory.eta, - GNUNET_YES); - FPRINTF (stdout, - _("Publishing `%s' at %llu/%llu (%s remaining)\n"), + s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.specifics + .progress_directory.eta, + GNUNET_YES); + fprintf (stdout, + _ ("Publishing `%s' at %llu/%llu (%s remaining)\n"), info->value.publish.filename, - (unsigned long long) info->value.publish.specifics.progress_directory.completed, - (unsigned long long) info->value.publish.specifics.progress_directory.total, s); + (unsigned long long) + info->value.publish.specifics.progress_directory.completed, + (unsigned long long) + info->value.publish.specifics.progress_directory.total, + s); } break; case GNUNET_FS_STATUS_PUBLISH_ERROR: - FPRINTF (stderr, - _("Error publishing: %s.\n"), + fprintf (stderr, + _ ("Error publishing: %s.\n"), info->value.publish.specifics.error.message); ret = 1; GNUNET_SCHEDULER_shutdown (); break; case GNUNET_FS_STATUS_PUBLISH_COMPLETED: - FPRINTF (stdout, - _("Publishing `%s' done.\n"), + fprintf (stdout, + _ ("Publishing `%s' done.\n"), info->value.publish.filename); - suri = GNUNET_FS_uri_to_string (info->value.publish.specifics. - completed.chk_uri); - FPRINTF (stdout, - _("URI is `%s'.\n"), - suri); + suri = + GNUNET_FS_uri_to_string (info->value.publish.specifics.completed.chk_uri); + fprintf (stdout, _ ("URI is `%s'.\n"), suri); GNUNET_free (suri); if (NULL != info->value.publish.specifics.completed.sks_uri) { - suri = GNUNET_FS_uri_to_string (info->value.publish.specifics. - completed.sks_uri); - FPRINTF (stdout, - _("Namespace URI is `%s'.\n"), - suri); + suri = GNUNET_FS_uri_to_string ( + info->value.publish.specifics.completed.sks_uri); + fprintf (stdout, _ ("Namespace URI is `%s'.\n"), suri); GNUNET_free (suri); } if (NULL == info->value.publish.pctx) @@ -270,33 +270,25 @@ progress_cb (void *cls, GNUNET_break (NULL == pc); return NULL; case GNUNET_FS_STATUS_UNINDEX_START: - FPRINTF (stderr, - "%s", - _("Starting cleanup after abort\n")); + fprintf (stderr, "%s", _ ("Starting cleanup after abort\n")); return NULL; case GNUNET_FS_STATUS_UNINDEX_PROGRESS: return NULL; case GNUNET_FS_STATUS_UNINDEX_COMPLETED: - FPRINTF (stderr, - "%s", - _("Cleanup after abort completed.\n")); + fprintf (stderr, "%s", _ ("Cleanup after abort completed.\n")); GNUNET_FS_unindex_stop (info->value.unindex.uc); return NULL; case GNUNET_FS_STATUS_UNINDEX_ERROR: - FPRINTF (stderr, - "%s", - _("Cleanup after abort failed.\n")); + fprintf (stderr, "%s", _ ("Cleanup after abort failed.\n")); GNUNET_FS_unindex_stop (info->value.unindex.uc); return NULL; case GNUNET_FS_STATUS_UNINDEX_STOPPED: return NULL; default: - FPRINTF (stderr, - _("Unexpected status: %d\n"), - info->status); + fprintf (stderr, _ ("Unexpected status: %d\n"), info->status); return NULL; } - return ""; /* non-null */ + return ""; /* non-null */ } @@ -319,7 +311,8 @@ meta_printer (void *cls, enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, const char *data_mime_type, - const char *data, size_t data_size) + const char *data, + size_t data_size) { if ((EXTRACTOR_METAFORMAT_UTF8 != format) && (EXTRACTOR_METAFORMAT_C_STRING != format)) @@ -327,15 +320,9 @@ meta_printer (void *cls, if (EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME == type) return 0; #if HAVE_LIBEXTRACTOR - FPRINTF (stdout, - "\t%s - %s\n", - EXTRACTOR_metatype_to_string (type), - data); + fprintf (stdout, "\t%s - %s\n", EXTRACTOR_metatype_to_string (type), data); #else - FPRINTF (stdout, - "\t%d - %s\n", - type, - data); + fprintf (stdout, "\t%d - %s\n", type, data); #endif return 0; } @@ -350,11 +337,9 @@ meta_printer (void *cls, * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to abort */ static int -keyword_printer (void *cls, - const char *keyword, - int is_mandatory) +keyword_printer (void *cls, const char *keyword, int is_mandatory) { - FPRINTF (stdout, "\t%s\n", keyword); + fprintf (stdout, "\t%s\n", keyword); return GNUNET_OK; } @@ -392,8 +377,7 @@ publish_inspector (void *cls, if (cls == fi) return GNUNET_OK; - if ( (disable_extractor) && - (NULL != *uri) ) + if ((disable_extractor) && (NULL != *uri)) { GNUNET_FS_uri_destroy (*uri); *uri = NULL; @@ -423,29 +407,21 @@ publish_inspector (void *cls, GNUNET_CONTAINER_meta_data_add_publication_date (m); if (extract_only) { - fn = GNUNET_CONTAINER_meta_data_get_by_type (m, - EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); + fn = GNUNET_CONTAINER_meta_data_get_by_type ( + m, + EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); fs = GNUNET_STRINGS_byte_size_fancy (length); - FPRINTF (stdout, - _("Meta data for file `%s' (%s)\n"), - fn, - fs); + fprintf (stdout, _ ("Meta data for file `%s' (%s)\n"), fn, fs); GNUNET_CONTAINER_meta_data_iterate (m, &meta_printer, NULL); - FPRINTF (stdout, - _("Keywords for file `%s' (%s)\n"), - fn, - fs); + fprintf (stdout, _ ("Keywords for file `%s' (%s)\n"), fn, fs); GNUNET_free (fn); GNUNET_free (fs); if (NULL != *uri) GNUNET_FS_uri_ksk_get_keywords (*uri, &keyword_printer, NULL); - FPRINTF (stdout, - "%s", - "\n"); + fprintf (stdout, "%s", "\n"); } if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (m)) - GNUNET_FS_file_information_inspect (fi, - &publish_inspector, fi); + GNUNET_FS_file_information_inspect (fi, &publish_inspector, fi); return GNUNET_OK; } @@ -466,9 +442,7 @@ uri_sks_continuation (void *cls, { if (NULL != emsg) { - FPRINTF (stderr, - "%s\n", - emsg); + fprintf (stderr, "%s\n", emsg); ret = 1; } GNUNET_SCHEDULER_shutdown (); @@ -493,9 +467,7 @@ uri_ksk_continuation (void *cls, if (NULL != emsg) { - FPRINTF (stderr, - "%s\n", - emsg); + fprintf (stderr, "%s\n", emsg); ret = 1; } if (NULL == namespace) @@ -505,15 +477,15 @@ uri_ksk_continuation (void *cls, } priv = GNUNET_IDENTITY_ego_get_private_key (namespace); GNUNET_FS_publish_sks (ctx, - priv, - this_id, - next_id, - meta, - uri, - &bo, - GNUNET_FS_PUBLISH_OPTION_NONE, - &uri_sks_continuation, - NULL); + priv, + this_id, + next_id, + meta, + uri, + &bo, + GNUNET_FS_PUBLISH_OPTION_NONE, + &uri_sks_continuation, + NULL); } @@ -536,8 +508,9 @@ get_file_information (struct GNUNET_FS_ShareTreeItem *item) if (NULL == item->meta) item->meta = GNUNET_CONTAINER_meta_data_create (); GNUNET_CONTAINER_meta_data_delete (item->meta, - EXTRACTOR_METATYPE_MIMETYPE, - NULL, 0); + EXTRACTOR_METATYPE_MIMETYPE, + NULL, + 0); GNUNET_FS_meta_data_make_directory (item->meta); if (NULL == item->ksk_uri) { @@ -545,12 +518,15 @@ get_file_information (struct GNUNET_FS_ShareTreeItem *item) item->ksk_uri = GNUNET_FS_uri_ksk_create_from_args (1, &mime); } else - GNUNET_FS_uri_ksk_add_keyword (item->ksk_uri, GNUNET_FS_DIRECTORY_MIME, - GNUNET_NO); - fi = GNUNET_FS_file_information_create_empty_directory (ctx, NULL, - item->ksk_uri, - item->meta, - &bo, item->filename); + GNUNET_FS_uri_ksk_add_keyword (item->ksk_uri, + GNUNET_FS_DIRECTORY_MIME, + GNUNET_NO); + fi = GNUNET_FS_file_information_create_empty_directory (ctx, + NULL, + item->ksk_uri, + item->meta, + &bo, + item->filename); for (child = item->children_head; child; child = child->next) { fic = get_file_information (child); @@ -559,11 +535,13 @@ get_file_information (struct GNUNET_FS_ShareTreeItem *item) } else { - fi = GNUNET_FS_file_information_create_from_file (ctx, NULL, - item->filename, - item->ksk_uri, item->meta, - !do_insert, - &bo); + fi = GNUNET_FS_file_information_create_from_file (ctx, + NULL, + item->filename, + item->ksk_uri, + item->meta, + ! do_insert, + &bo); } return fi; } @@ -585,9 +563,7 @@ directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result) GNUNET_FS_share_tree_free (directory_scan_result); if (NULL == fi) { - FPRINTF (stderr, - "%s", - _("Could not publish\n")); + fprintf (stderr, "%s", _ ("Could not publish\n")); ret = 1; GNUNET_SCHEDULER_shutdown (); return; @@ -603,16 +579,17 @@ directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result) priv = NULL; else priv = GNUNET_IDENTITY_ego_get_private_key (namespace); - pc = GNUNET_FS_publish_start (ctx, fi, - priv, this_id, next_id, - (do_simulate) ? - GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY : - GNUNET_FS_PUBLISH_OPTION_NONE); + pc = GNUNET_FS_publish_start (ctx, + fi, + priv, + this_id, + next_id, + (do_simulate) + ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY + : GNUNET_FS_PUBLISH_OPTION_NONE); if (NULL == pc) { - FPRINTF (stderr, - "%s", - _("Could not start publishing.\n")); + fprintf (stderr, "%s", _ ("Could not start publishing.\n")); ret = 1; GNUNET_SCHEDULER_shutdown (); return; @@ -633,9 +610,9 @@ directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result) */ static void directory_scan_cb (void *cls, - const char *filename, - int is_directory, - enum GNUNET_FS_DirScannerProgressUpdateReason reason) + const char *filename, + int is_directory, + enum GNUNET_FS_DirScannerProgressUpdateReason reason) { struct GNUNET_FS_ShareTreeItem *directory_scan_result; @@ -645,46 +622,36 @@ directory_scan_cb (void *cls, if (verbose > 1) { if (is_directory == GNUNET_YES) - FPRINTF (stdout, - _("Scanning directory `%s'.\n"), - filename); + fprintf (stdout, _ ("Scanning directory `%s'.\n"), filename); else - FPRINTF (stdout, - _("Scanning file `%s'.\n"), - filename); + fprintf (stdout, _ ("Scanning file `%s'.\n"), filename); } break; case GNUNET_FS_DIRSCANNER_FILE_IGNORED: - FPRINTF (stderr, - _("There was trouble processing file `%s', skipping it.\n"), - filename); + fprintf (stderr, + _ ("There was trouble processing file `%s', skipping it.\n"), + filename); break; case GNUNET_FS_DIRSCANNER_ALL_COUNTED: if (verbose) - FPRINTF (stdout, - "%s", - _("Preprocessing complete.\n")); + fprintf (stdout, "%s", _ ("Preprocessing complete.\n")); break; case GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED: if (verbose > 2) - FPRINTF (stdout, - _("Extracting meta data from file `%s' complete.\n"), + fprintf (stdout, + _ ("Extracting meta data from file `%s' complete.\n"), filename); break; case GNUNET_FS_DIRSCANNER_FINISHED: if (verbose > 1) - FPRINTF (stdout, - "%s", - _("Meta data extraction has finished.\n")); + fprintf (stdout, "%s", _ ("Meta data extraction has finished.\n")); directory_scan_result = GNUNET_FS_directory_scan_get_result (ds); ds = NULL; GNUNET_FS_share_tree_trim (directory_scan_result); directory_trim_complete (directory_scan_result); break; case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR: - FPRINTF (stdout, - "%s", - _("Error scanning directory.\n")); + fprintf (stdout, "%s", _ ("Error scanning directory.\n")); ret = 1; GNUNET_SCHEDULER_shutdown (); break; @@ -708,12 +675,9 @@ identity_continuation (const char *args0) char *ex; char *emsg; - if ( (NULL != pseudonym) && - (NULL == namespace) ) + if ((NULL != pseudonym) && (NULL == namespace)) { - FPRINTF (stderr, - _("Selected pseudonym `%s' unknown\n"), - pseudonym); + fprintf (stderr, _ ("Selected pseudonym `%s' unknown\n"), pseudonym); ret = 1; GNUNET_SCHEDULER_shutdown (); return; @@ -723,17 +687,16 @@ identity_continuation (const char *args0) emsg = NULL; if (NULL == (uri = GNUNET_FS_uri_parse (uri_string, &emsg))) { - FPRINTF (stderr, - _("Failed to parse URI: %s\n"), - emsg); + fprintf (stderr, _ ("Failed to parse URI: %s\n"), emsg); GNUNET_free (emsg); ret = 1; GNUNET_SCHEDULER_shutdown (); return; } GNUNET_FS_publish_ksk (ctx, - topKeywords, - meta, uri, + topKeywords, + meta, + uri, &bo, GNUNET_FS_PUBLISH_OPTION_NONE, &uri_ksk_continuation, @@ -743,24 +706,27 @@ identity_continuation (const char *args0) if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "FS", "EXTRACTORS", &ex)) ex = NULL; - if (0 != ACCESS (args0, R_OK)) + if (0 != access (args0, R_OK)) { - FPRINTF (stderr, - _("Failed to access `%s': %s\n"), - args0, - STRERROR (errno)); + fprintf (stderr, + _ ("Failed to access `%s': %s\n"), + args0, + strerror (errno)); GNUNET_free_non_null (ex); return; } ds = GNUNET_FS_directory_scan_start (args0, - disable_extractor, - ex, - &directory_scan_cb, NULL); + disable_extractor, + ex, + &directory_scan_cb, + NULL); if (NULL == ds) { - FPRINTF (stderr, - "%s", - _("Failed to start meta directory scanner. Is gnunet-helper-publish-fs installed?\n")); + fprintf ( + stderr, + "%s", + _ ( + "Failed to start meta directory scanner. Is gnunet-helper-publish-fs installed?\n")); GNUNET_free_non_null (ex); return; } @@ -781,9 +747,9 @@ identity_continuation (const char *args0) */ static void identity_cb (void *cls, - struct GNUNET_IDENTITY_Ego *ego, - void **ctx, - const char *name) + struct GNUNET_IDENTITY_Ego *ego, + void **ctx, + const char *name) { const char *args0 = cls; @@ -795,7 +761,7 @@ identity_cb (void *cls, if (NULL == name) return; if (0 == strcmp (name, pseudonym)) - namespace = ego; + namespace = ego; } @@ -816,20 +782,20 @@ run (void *cls, /* check arguments */ if ((NULL != uri_string) && (extract_only)) { - printf (_("Cannot extract metadata from a URI!\n")); + printf (_ ("Cannot extract metadata from a URI!\n")); ret = -1; return; } if (((NULL == uri_string) || (extract_only)) && ((NULL == args[0]) || (NULL != args[1]))) { - printf (_("You must specify one and only one filename for insertion.\n")); + printf (_ ("You must specify one and only one filename for insertion.\n")); ret = -1; return; } if ((NULL != uri_string) && (NULL != args[0])) { - printf (_("You must NOT specify an URI and a filename.\n")); + printf (_ ("You must NOT specify an URI and a filename.\n")); ret = -1; return; } @@ -837,49 +803,51 @@ run (void *cls, { if (NULL == this_id) { - FPRINTF (stderr, _("Option `%s' is required when using option `%s'.\n"), - "-t", "-P"); + fprintf (stderr, + _ ("Option `%s' is required when using option `%s'.\n"), + "-t", + "-P"); ret = -1; return; } } else - { /* ordinary insertion checks */ + { /* ordinary insertion checks */ if (NULL != next_id) { - FPRINTF (stderr, - _("Option `%s' makes no sense without option `%s'.\n"), - "-N", "-P"); + fprintf (stderr, + _ ("Option `%s' makes no sense without option `%s'.\n"), + "-N", + "-P"); ret = -1; return; } if (NULL != this_id) { - FPRINTF (stderr, - _("Option `%s' makes no sense without option `%s'.\n"), - "-t", "-P"); + fprintf (stderr, + _ ("Option `%s' makes no sense without option `%s'.\n"), + "-t", + "-P"); ret = -1; return; } } cfg = c; - ctx = - GNUNET_FS_start (cfg, "gnunet-publish", &progress_cb, NULL, - GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); + ctx = GNUNET_FS_start (cfg, + "gnunet-publish", + &progress_cb, + NULL, + GNUNET_FS_FLAGS_NONE, + GNUNET_FS_OPTIONS_END); if (NULL == ctx) { - FPRINTF (stderr, - _("Could not initialize `%s' subsystem.\n"), - "FS"); + fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS"); ret = 1; return; } - GNUNET_SCHEDULER_add_shutdown (&do_stop_task, - NULL); + GNUNET_SCHEDULER_add_shutdown (&do_stop_task, NULL); if (NULL != pseudonym) - identity = GNUNET_IDENTITY_connect (cfg, - &identity_cb, - args[0]); + identity = GNUNET_IDENTITY_connect (cfg, &identity_cb, args[0]); else identity_continuation (args[0]); } @@ -893,104 +861,120 @@ run (void *cls, * @return 0 ok, 1 on error */ int -main (int argc, - char *const *argv) +main (int argc, char *const *argv) { - struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_option_uint ('a', - "anonymity", - "LEVEL", - gettext_noop ("set the desired LEVEL of sender-anonymity"), - &bo.anonymity_level), - GNUNET_GETOPT_option_flag ('D', - "disable-extractor", - gettext_noop ("do not use libextractor to add keywords or metadata"), - &disable_extractor), - GNUNET_GETOPT_option_flag ('E', - "enable-creation-time", - gettext_noop ("enable adding the creation time to the " - "metadata of the uploaded file"), - &enable_creation_time), - GNUNET_GETOPT_option_flag ('e', - "extract", - gettext_noop ("print list of extracted keywords that would " - "be used, but do not perform upload"), - &extract_only), - GNUNET_FS_GETOPT_KEYWORDS ('k', - "key", - "KEYWORD", - gettext_noop ("add an additional keyword for the top-level " - "file or directory (this option can be specified multiple times)"), - &topKeywords), - GNUNET_FS_GETOPT_METADATA ('m', - "meta", - "TYPE:VALUE", - gettext_noop ("set the meta-data for the given TYPE to the given VALUE"), - &meta), - GNUNET_GETOPT_option_flag ('n', - "noindex", - gettext_noop ("do not index, perform full insertion (stores " - "entire file in encrypted form in GNUnet database)"), - &do_insert), - GNUNET_GETOPT_option_string ('N', - "next", - "ID", - gettext_noop ("specify ID of an updated version to be " - "published in the future (for namespace insertions only)"), - &next_id), - GNUNET_GETOPT_option_uint ('p', - "priority", - "PRIORITY", - gettext_noop ("specify the priority of the content"), - &bo.content_priority), - GNUNET_GETOPT_option_string ('P', - "pseudonym", - "NAME", - gettext_noop ("publish the files under the pseudonym " - "NAME (place file into namespace)"), - &pseudonym), - GNUNET_GETOPT_option_uint ('r', - "replication", - "LEVEL", - gettext_noop ("set the desired replication LEVEL"), - &bo.replication_level), - GNUNET_GETOPT_option_flag ('s', - "simulate-only", - gettext_noop ("only simulate the process but do not do " - "any actual publishing (useful to compute URIs)"), - &do_simulate), - GNUNET_GETOPT_option_string ('t', - "this", - "ID", - gettext_noop ("set the ID of this version of the publication " - "(for namespace insertions only)"), - &this_id), - GNUNET_GETOPT_option_string ('u', - "uri", - "URI", - gettext_noop ("URI to be published (can be used instead of passing a " - "file to add keywords to the file with the respective URI)"), - &uri_string), - - GNUNET_GETOPT_option_verbose (&verbose), - - GNUNET_GETOPT_OPTION_END - }; + struct GNUNET_GETOPT_CommandLineOption options[] = + {GNUNET_GETOPT_option_uint ('a', + "anonymity", + "LEVEL", + gettext_noop ( + "set the desired LEVEL of sender-anonymity"), + &bo.anonymity_level), + GNUNET_GETOPT_option_flag ( + 'D', + "disable-extractor", + gettext_noop ("do not use libextractor to add keywords or metadata"), + &disable_extractor), + GNUNET_GETOPT_option_flag ('E', + "enable-creation-time", + gettext_noop ( + "enable adding the creation time to the " + "metadata of the uploaded file"), + &enable_creation_time), + GNUNET_GETOPT_option_flag ('e', + "extract", + gettext_noop ( + "print list of extracted keywords that would " + "be used, but do not perform upload"), + &extract_only), + GNUNET_FS_GETOPT_KEYWORDS ( + 'k', + "key", + "KEYWORD", + gettext_noop ( + "add an additional keyword for the top-level " + "file or directory (this option can be specified multiple times)"), + &topKeywords), + GNUNET_FS_GETOPT_METADATA ( + 'm', + "meta", + "TYPE:VALUE", + gettext_noop ("set the meta-data for the given TYPE to the given VALUE"), + &meta), + GNUNET_GETOPT_option_flag ( + 'n', + "noindex", + gettext_noop ("do not index, perform full insertion (stores " + "entire file in encrypted form in GNUnet database)"), + &do_insert), + GNUNET_GETOPT_option_string ( + 'N', + "next", + "ID", + gettext_noop ("specify ID of an updated version to be " + "published in the future (for namespace insertions only)"), + &next_id), + GNUNET_GETOPT_option_uint ('p', + "priority", + "PRIORITY", + gettext_noop ( + "specify the priority of the content"), + &bo.content_priority), + GNUNET_GETOPT_option_string ('P', + "pseudonym", + "NAME", + gettext_noop ( + "publish the files under the pseudonym " + "NAME (place file into namespace)"), + &pseudonym), + GNUNET_GETOPT_option_uint ('r', + "replication", + "LEVEL", + gettext_noop ( + "set the desired replication LEVEL"), + &bo.replication_level), + GNUNET_GETOPT_option_flag ('s', + "simulate-only", + gettext_noop ( + "only simulate the process but do not do " + "any actual publishing (useful to compute URIs)"), + &do_simulate), + GNUNET_GETOPT_option_string ('t', + "this", + "ID", + gettext_noop ( + "set the ID of this version of the publication " + "(for namespace insertions only)"), + &this_id), + GNUNET_GETOPT_option_string ( + 'u', + "uri", + "URI", + gettext_noop ( + "URI to be published (can be used instead of passing a " + "file to add keywords to the file with the respective URI)"), + &uri_string), + + GNUNET_GETOPT_option_verbose (&verbose), + + GNUNET_GETOPT_OPTION_END}; bo.expiration_time = - GNUNET_TIME_year_to_time (GNUNET_TIME_get_current_year () + 2); + GNUNET_TIME_year_to_time (GNUNET_TIME_get_current_year () + 2); if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) return 2; - ret = (GNUNET_OK == - GNUNET_PROGRAM_run (argc, - argv, - "gnunet-publish [OPTIONS] FILENAME", - gettext_noop - ("Publish a file or directory on GNUnet"), - options, - &run, - NULL)) ? ret : 1; - GNUNET_free ((void*) argv); + ret = + (GNUNET_OK == + GNUNET_PROGRAM_run (argc, + argv, + "gnunet-publish [OPTIONS] FILENAME", + gettext_noop ("Publish a file or directory on GNUnet"), + options, + &run, + NULL)) + ? ret + : 1; + GNUNET_free ((void *) argv); return ret; } diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c index 3995b1b5b..7d6ff4c6b 100644 --- a/src/fs/gnunet-search.c +++ b/src/fs/gnunet-search.c @@ -92,11 +92,10 @@ item_printer (void *cls, #if HAVE_LIBEXTRACTOR printf ("\t%20s: %s\n", dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, - EXTRACTOR_metatype_to_string (type)), data); -#else - printf ("\t%20d: %s\n", - type, + EXTRACTOR_metatype_to_string (type)), data); +#else + printf ("\t%20d: %s\n", type, data); #endif return 0; } @@ -118,13 +117,14 @@ clean_task (void *cls) GNUNET_free (output_filename); return; } - if (dsize != - GNUNET_DISK_fn_write (output_filename, ddata, dsize, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE)) + if (dsize != GNUNET_DISK_fn_write (output_filename, + ddata, + dsize, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE)) { - FPRINTF (stderr, - _("Failed to write directory with search results to `%s'\n"), + fprintf (stderr, + _ ("Failed to write directory with search results to `%s'\n"), output_filename); } GNUNET_free_non_null (ddata); @@ -165,31 +165,35 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) NULL); uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri); printf ("#%u:\n", ++cnt); - filename = - GNUNET_CONTAINER_meta_data_get_by_type (info->value.search. - specifics.result.meta, - EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); - is_directory = - GNUNET_FS_meta_data_test_for_directory (info->value.search. - specifics.result.meta); + filename = GNUNET_CONTAINER_meta_data_get_by_type ( + info->value.search.specifics.result.meta, + EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); + is_directory = GNUNET_FS_meta_data_test_for_directory ( + info->value.search.specifics.result.meta); if (NULL != filename) { - while ( (filename[0] != '\0') && - ('/' == filename[strlen(filename)-1]) ) - filename[strlen(filename)-1] = '\0'; + while ((filename[0] != '\0') && ('/' == filename[strlen (filename) - 1])) + filename[strlen (filename) - 1] = '\0'; GNUNET_DISK_filename_canonicalize (filename); if (GNUNET_YES == is_directory) - printf ("gnunet-download -o \"%s%s\" -R %s\n", filename, GNUNET_FS_DIRECTORY_EXT, uri); + printf ("gnunet-download -o \"%s%s\" -R %s\n", + filename, + GNUNET_FS_DIRECTORY_EXT, + uri); else printf ("gnunet-download -o \"%s\" %s\n", filename, uri); } else if (GNUNET_YES == is_directory) - printf ("gnunet-download -o \"collection%s\" -R %s\n", GNUNET_FS_DIRECTORY_EXT, uri); + printf ("gnunet-download -o \"collection%s\" -R %s\n", + GNUNET_FS_DIRECTORY_EXT, + uri); else printf ("gnunet-download %s\n", uri); if (verbose) - GNUNET_CONTAINER_meta_data_iterate (info->value.search.specifics. - result.meta, &item_printer, NULL); + GNUNET_CONTAINER_meta_data_iterate (info->value.search.specifics.result + .meta, + &item_printer, + NULL); printf ("\n"); fflush (stdout); GNUNET_free_non_null (filename); @@ -204,7 +208,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) /* ignore */ break; case GNUNET_FS_STATUS_SEARCH_ERROR: - FPRINTF (stderr, _("Error searching: %s.\n"), + fprintf (stderr, + _ ("Error searching: %s.\n"), info->value.search.specifics.error.message); GNUNET_SCHEDULER_shutdown (); break; @@ -212,7 +217,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) GNUNET_SCHEDULER_add_now (&clean_task, NULL); break; default: - FPRINTF (stderr, _("Unexpected status: %d\n"), info->status); + fprintf (stderr, _ ("Unexpected status: %d\n"), info->status); break; } return NULL; @@ -247,7 +252,9 @@ timeout_task (void *cls) * @param c configuration */ static void -run (void *cls, char *const *args, const char *cfgfile, +run (void *cls, + char *const *args, + const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) { struct GNUNET_FS_Uri *uri; @@ -260,17 +267,22 @@ run (void *cls, char *const *args, const char *cfgfile, uri = GNUNET_FS_uri_ksk_create_from_args (argc, (const char **) args); if (NULL == uri) { - FPRINTF (stderr, "%s", _("Could not create keyword URI from arguments.\n")); + fprintf (stderr, + "%s", + _ ("Could not create keyword URI from arguments.\n")); ret = 1; return; } cfg = c; - ctx = - GNUNET_FS_start (cfg, "gnunet-search", &progress_cb, NULL, - GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); + ctx = GNUNET_FS_start (cfg, + "gnunet-search", + &progress_cb, + NULL, + GNUNET_FS_FLAGS_NONE, + GNUNET_FS_OPTIONS_END); if (NULL == ctx) { - FPRINTF (stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); + fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS"); GNUNET_FS_uri_destroy (uri); ret = 1; return; @@ -284,17 +296,14 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_FS_uri_destroy (uri); if (NULL == sc) { - FPRINTF (stderr, "%s", _("Could not start searching.\n")); + fprintf (stderr, "%s", _ ("Could not start searching.\n")); GNUNET_FS_stop (ctx); ret = 1; return; } if (0 != timeout.rel_value_us) - tt = GNUNET_SCHEDULER_add_delayed (timeout, - &timeout_task, - NULL); - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, - NULL); + tt = GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, NULL); + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); } @@ -308,49 +317,55 @@ run (void *cls, char *const *args, const char *cfgfile, int main (int argc, char *const *argv) { - struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_option_uint ('a', - "anonymity", - "LEVEL", - gettext_noop ("set the desired LEVEL of receiver-anonymity"), - &anonymity), - GNUNET_GETOPT_option_flag ('n', - "no-network", - gettext_noop ("only search the local peer (no P2P network search)"), - &local_only), - GNUNET_GETOPT_option_string ('o', - "output", - "PREFIX", - gettext_noop ("write search results to file starting with PREFIX"), - &output_filename), - GNUNET_GETOPT_option_relative_time ('t', - "timeout", - "DELAY", - gettext_noop ("automatically terminate search after DELAY"), - &timeout), - GNUNET_GETOPT_option_verbose (&verbose), - GNUNET_GETOPT_option_uint ('N', - "results", - "VALUE", - gettext_noop ("automatically terminate search " - "after VALUE results are found"), - &results_limit), - GNUNET_GETOPT_OPTION_END - }; - - if (GNUNET_OK != - GNUNET_STRINGS_get_utf8_args (argc, argv, - &argc, &argv)) + struct GNUNET_GETOPT_CommandLineOption options[] = + {GNUNET_GETOPT_option_uint ('a', + "anonymity", + "LEVEL", + gettext_noop ( + "set the desired LEVEL of receiver-anonymity"), + &anonymity), + GNUNET_GETOPT_option_flag ( + 'n', + "no-network", + gettext_noop ("only search the local peer (no P2P network search)"), + &local_only), + GNUNET_GETOPT_option_string ( + 'o', + "output", + "PREFIX", + gettext_noop ("write search results to file starting with PREFIX"), + &output_filename), + GNUNET_GETOPT_option_relative_time ( + 't', + "timeout", + "DELAY", + gettext_noop ("automatically terminate search after DELAY"), + &timeout), + GNUNET_GETOPT_option_verbose (&verbose), + GNUNET_GETOPT_option_uint ('N', + "results", + "VALUE", + gettext_noop ("automatically terminate search " + "after VALUE results are found"), + &results_limit), + GNUNET_GETOPT_OPTION_END}; + + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) return 2; - ret = (GNUNET_OK == - GNUNET_PROGRAM_run (argc, - argv, - "gnunet-search [OPTIONS] KEYWORD", - gettext_noop - ("Search GNUnet for files that were published on GNUnet"), - options, &run, NULL)) ? ret : 1; - GNUNET_free ((void*) argv); + ret = + (GNUNET_OK == + GNUNET_PROGRAM_run (argc, + argv, + "gnunet-search [OPTIONS] KEYWORD", + gettext_noop ( + "Search GNUnet for files that were published on GNUnet"), + options, + &run, + NULL)) + ? ret + : 1; + GNUNET_free ((void *) argv); return ret; } diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c index 0e8e62fc7..df5f70b3d 100644 --- a/src/fs/gnunet-service-fs_indexing.c +++ b/src/fs/gnunet-service-fs_indexing.c @@ -73,7 +73,6 @@ struct IndexInfo * Hash of the contents of the file. */ struct GNUNET_HashCode file_id; - }; @@ -118,12 +117,10 @@ write_index_list () struct IndexInfo *pos; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", - "INDEXDB", - &fn)) + GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "fs", + "fs", "INDEXDB"); return; } @@ -131,24 +128,21 @@ write_index_list () if (NULL == wh) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - _("Could not open `%s'.\n"), + _ ("Could not open `%s'.\n"), fn); GNUNET_free (fn); return; } for (pos = indexed_files_head; NULL != pos; pos = pos->next) - if ((GNUNET_OK != - GNUNET_BIO_write (wh, - &pos->file_id, - sizeof (struct GNUNET_HashCode))) || - (GNUNET_OK != - GNUNET_BIO_write_string (wh, - pos->filename))) + if ((GNUNET_OK != GNUNET_BIO_write (wh, + &pos->file_id, + sizeof (struct GNUNET_HashCode))) || + (GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename))) break; if (GNUNET_OK != GNUNET_BIO_write_close (wh)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - _("Error writing `%s'.\n"), + _ ("Error writing `%s'.\n"), fn); GNUNET_free (fn); return; @@ -172,13 +166,10 @@ read_index_list () char *emsg; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (cfg, - "FS", - "INDEXDB", - &fn)) + GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "fs", + "fs", "INDEXDB"); return; } @@ -192,39 +183,36 @@ read_index_list () if (NULL == rh) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - _("Could not open `%s'.\n"), + _ ("Could not open `%s'.\n"), fn); GNUNET_free (fn); return; } - while ( (GNUNET_OK == - GNUNET_BIO_read (rh, - "Hash of indexed file", - &hc, - sizeof (struct GNUNET_HashCode))) && - (GNUNET_OK == - GNUNET_BIO_read_string (rh, - "Name of indexed file", - &fname, - 1024 * 16)) && - (fname != NULL) ) + while ( + (GNUNET_OK == GNUNET_BIO_read (rh, + "Hash of indexed file", + &hc, + sizeof (struct GNUNET_HashCode))) && + (GNUNET_OK == + GNUNET_BIO_read_string (rh, "Name of indexed file", &fname, 1024 * 16)) && + (fname != NULL)) { slen = strlen (fname) + 1; pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen); pos->file_id = hc; pos->filename = (const char *) &pos[1]; GNUNET_memcpy (&pos[1], fname, slen); - if (GNUNET_SYSERR == - GNUNET_CONTAINER_multihashmap_put (ifm, &pos->file_id, pos, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) + if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put ( + ifm, + &pos->file_id, + pos, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) { GNUNET_free (pos); } else { - GNUNET_CONTAINER_DLL_insert (indexed_files_head, - indexed_files_tail, - pos); + GNUNET_CONTAINER_DLL_insert (indexed_files_head, indexed_files_tail, pos); } GNUNET_free (fname); } @@ -244,13 +232,15 @@ read_index_list () * @param msg error message */ static void -remove_cont (void *cls, int success, - struct GNUNET_TIME_Absolute min_expiration, - const char *msg) +remove_cont (void *cls, + int success, + struct GNUNET_TIME_Absolute min_expiration, + const char *msg) { if (GNUNET_OK != success) GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to delete bogus block: %s\n"), msg); + _ ("Failed to delete bogus block: %s\n"), + msg); } @@ -275,7 +265,7 @@ remove_cont (void *cls, int success, * @return GNUNET_OK on success */ int -GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode * key, +GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode *key, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, @@ -303,19 +293,12 @@ GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode * key, if (size != sizeof (struct OnDemandBlock)) { GNUNET_break (0); - GNUNET_DATASTORE_remove (dsh, - key, - size, - data, - -1, - -1, - &remove_cont, NULL); + GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); return GNUNET_SYSERR; } odb = (const struct OnDemandBlock *) data; off = GNUNET_ntohll (odb->offset); - ii = GNUNET_CONTAINER_multihashmap_get (ifm, - &odb->file_id); + ii = GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id); if (NULL == ii) { GNUNET_break (0); @@ -325,83 +308,46 @@ GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode * key, return GNUNET_SYSERR; } fn = ii->filename; - if ((NULL == fn) || (0 != ACCESS (fn, R_OK))) + if ((NULL == fn) || (0 != access (fn, R_OK))) { - GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# index blocks removed: original file inaccessible"), - 1, - GNUNET_YES); - GNUNET_DATASTORE_remove (dsh, - key, - size, - data, - -1, - -1, - &remove_cont, - NULL); + GNUNET_STATISTICS_update ( + GSF_stats, + gettext_noop ("# index blocks removed: original file inaccessible"), + 1, + GNUNET_YES); + GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); return GNUNET_SYSERR; } - if ( (NULL == - (fh = - GNUNET_DISK_file_open (fn, - GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_NONE))) || - (off != GNUNET_DISK_file_seek (fh, - off, - GNUNET_DISK_SEEK_SET)) || - (-1 == (nsize = GNUNET_DISK_file_read (fh, - ndata, - sizeof (ndata)))) ) + if ((NULL == (fh = GNUNET_DISK_file_open (fn, + GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_NONE))) || + (off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET)) || + (-1 == (nsize = GNUNET_DISK_file_read (fh, ndata, sizeof (ndata))))) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Could not access indexed file `%s' (%s) at offset %llu: %s\n"), + _ ( + "Could not access indexed file `%s' (%s) at offset %llu: %s\n"), GNUNET_h2s (&odb->file_id), fn, (unsigned long long) off, - (fn == NULL) ? _("not indexed") : STRERROR (errno)); + (fn == NULL) ? _ ("not indexed") : strerror (errno)); if (fh != NULL) GNUNET_DISK_file_close (fh); - GNUNET_DATASTORE_remove (dsh, - key, - size, - data, - -1, - -1, - &remove_cont, - NULL); + GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); return GNUNET_SYSERR; } GNUNET_DISK_file_close (fh); - GNUNET_CRYPTO_hash (ndata, - nsize, - &nkey); - GNUNET_CRYPTO_hash_to_aes_key (&nkey, - &skey, - &iv); - GNUNET_CRYPTO_symmetric_encrypt (ndata, - nsize, - &skey, - &iv, - edata); - GNUNET_CRYPTO_hash (edata, - nsize, - &query); - if (0 != memcmp (&query, - key, - sizeof (struct GNUNET_HashCode))) + GNUNET_CRYPTO_hash (ndata, nsize, &nkey); + GNUNET_CRYPTO_hash_to_aes_key (&nkey, &skey, &iv); + GNUNET_CRYPTO_symmetric_encrypt (ndata, nsize, &skey, &iv, edata); + GNUNET_CRYPTO_hash (edata, nsize, &query); + if (0 != memcmp (&query, key, sizeof (struct GNUNET_HashCode))) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Indexed file `%s' changed at offset %llu\n"), + _ ("Indexed file `%s' changed at offset %llu\n"), fn, (unsigned long long) off); - GNUNET_DATASTORE_remove (dsh, - key, - size, - data, - -1, - -1, - &remove_cont, - NULL); + GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); return GNUNET_SYSERR; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -440,27 +386,20 @@ GNUNET_FS_indexing_send_list (struct GNUNET_MQ_Handle *mq) { fn = pos->filename; slen = strlen (fn) + 1; - if (slen + sizeof (struct IndexInfoMessage) >= - GNUNET_MAX_MESSAGE_SIZE) + if (slen + sizeof (struct IndexInfoMessage) >= GNUNET_MAX_MESSAGE_SIZE) { GNUNET_break (0); break; } - env = GNUNET_MQ_msg_extra (iim, - slen, - GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY); + env = + GNUNET_MQ_msg_extra (iim, slen, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY); iim->reserved = 0; iim->file_id = pos->file_id; - GNUNET_memcpy (&iim[1], - fn, - slen); - GNUNET_MQ_send (mq, - env); + GNUNET_memcpy (&iim[1], fn, slen); + GNUNET_MQ_send (mq, env); } - env = GNUNET_MQ_msg (iem, - GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END); - GNUNET_MQ_send (mq, - env); + env = GNUNET_MQ_msg (iem, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END); + GNUNET_MQ_send (mq, env); } @@ -477,17 +416,12 @@ GNUNET_FS_indexing_do_unindex (const struct GNUNET_HashCode *fid) for (pos = indexed_files_head; NULL != pos; pos = pos->next) { - if (0 == memcmp (&pos->file_id, - fid, - sizeof (struct GNUNET_HashCode))) + if (0 == memcmp (&pos->file_id, fid, sizeof (struct GNUNET_HashCode))) { - GNUNET_CONTAINER_DLL_remove (indexed_files_head, - indexed_files_tail, - pos); - GNUNET_break (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_remove (ifm, - &pos->file_id, - pos)); + GNUNET_CONTAINER_DLL_remove (indexed_files_head, indexed_files_tail, pos); + GNUNET_break ( + GNUNET_OK == + GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id, pos)); GNUNET_free (pos); write_index_list (); return GNUNET_YES; @@ -510,14 +444,15 @@ GNUNET_FS_add_to_index (const char *filename, struct IndexInfo *ii; size_t slen; - ii = GNUNET_CONTAINER_multihashmap_get (ifm, - file_id); + ii = GNUNET_CONTAINER_multihashmap_get (ifm, file_id); if (NULL != ii) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"), - filename, - ii->filename); + GNUNET_log ( + GNUNET_ERROR_TYPE_INFO, + _ ( + "Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"), + filename, + ii->filename); return; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -528,17 +463,14 @@ GNUNET_FS_add_to_index (const char *filename, ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen); ii->file_id = *file_id; ii->filename = (const char *) &ii[1]; - GNUNET_memcpy (&ii[1], - filename, - slen); - GNUNET_CONTAINER_DLL_insert (indexed_files_head, - indexed_files_tail, - ii); + GNUNET_memcpy (&ii[1], filename, slen); + GNUNET_CONTAINER_DLL_insert (indexed_files_head, indexed_files_tail, ii); GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (ifm, - &ii->file_id, - ii, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_CONTAINER_multihashmap_put ( + ifm, + &ii->file_id, + ii, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); write_index_list (); } @@ -553,15 +485,12 @@ GNUNET_FS_indexing_done () while (NULL != (pos = indexed_files_head)) { - GNUNET_CONTAINER_DLL_remove (indexed_files_head, - indexed_files_tail, - pos); + GNUNET_CONTAINER_DLL_remove (indexed_files_head, indexed_files_tail, pos); if (pos->fhc != NULL) GNUNET_CRYPTO_hash_file_cancel (pos->fhc); - GNUNET_break (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_remove (ifm, - &pos->file_id, - pos)); + GNUNET_break ( + GNUNET_OK == + GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id, pos)); GNUNET_free (pos); } GNUNET_CONTAINER_multihashmap_destroy (ifm); @@ -582,8 +511,7 @@ GNUNET_FS_indexing_init (const struct GNUNET_CONFIGURATION_Handle *c, { cfg = c; dsh = d; - ifm = GNUNET_CONTAINER_multihashmap_create (128, - GNUNET_YES); + ifm = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES); read_index_list (); return GNUNET_OK; } diff --git a/src/fs/gnunet-unindex.c b/src/fs/gnunet-unindex.c index f9a3f8f3a..4d13e7ef3 100644 --- a/src/fs/gnunet-unindex.c +++ b/src/fs/gnunet-unindex.c @@ -85,26 +85,30 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) case GNUNET_FS_STATUS_UNINDEX_PROGRESS: if (verbose) { - s = GNUNET_STRINGS_relative_time_to_string (info->value.unindex.eta, GNUNET_YES); - FPRINTF (stdout, _("Unindexing at %llu/%llu (%s remaining)\n"), + s = GNUNET_STRINGS_relative_time_to_string (info->value.unindex.eta, + GNUNET_YES); + fprintf (stdout, + _ ("Unindexing at %llu/%llu (%s remaining)\n"), (unsigned long long) info->value.unindex.completed, - (unsigned long long) info->value.unindex.size, s); + (unsigned long long) info->value.unindex.size, + s); } break; case GNUNET_FS_STATUS_UNINDEX_ERROR: - FPRINTF (stderr, _("Error unindexing: %s.\n"), + fprintf (stderr, + _ ("Error unindexing: %s.\n"), info->value.unindex.specifics.error.message); GNUNET_SCHEDULER_shutdown (); break; case GNUNET_FS_STATUS_UNINDEX_COMPLETED: - FPRINTF (stdout, "%s", _("Unindexing done.\n")); + fprintf (stdout, "%s", _ ("Unindexing done.\n")); GNUNET_SCHEDULER_shutdown (); break; case GNUNET_FS_STATUS_UNINDEX_STOPPED: GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); break; default: - FPRINTF (stderr, _("Unexpected status: %d\n"), info->status); + fprintf (stderr, _ ("Unexpected status: %d\n"), info->status); break; } return NULL; @@ -120,35 +124,39 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) * @param c configuration */ static void -run (void *cls, char *const *args, const char *cfgfile, +run (void *cls, + char *const *args, + const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) { /* check arguments */ if ((args[0] == NULL) || (args[1] != NULL)) { - printf (_("You must specify one and only one filename for unindexing.\n")); + printf (_ ("You must specify one and only one filename for unindexing.\n")); ret = -1; return; } cfg = c; - ctx = - GNUNET_FS_start (cfg, "gnunet-unindex", &progress_cb, NULL, - GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); + ctx = GNUNET_FS_start (cfg, + "gnunet-unindex", + &progress_cb, + NULL, + GNUNET_FS_FLAGS_NONE, + GNUNET_FS_OPTIONS_END); if (NULL == ctx) { - FPRINTF (stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); + fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS"); ret = 1; return; } uc = GNUNET_FS_unindex_start (ctx, args[0], NULL); if (NULL == uc) { - FPRINTF (stderr, "%s", _("Could not start unindex operation.\n")); + fprintf (stderr, "%s", _ ("Could not start unindex operation.\n")); GNUNET_FS_stop (ctx); return; } - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, - NULL); + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); } @@ -166,18 +174,24 @@ main (int argc, char *const *argv) GNUNET_GETOPT_option_verbose (&verbose), - GNUNET_GETOPT_OPTION_END - }; + GNUNET_GETOPT_OPTION_END}; if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) return 2; ret = (GNUNET_OK == - GNUNET_PROGRAM_run (argc, argv, "gnunet-unindex [OPTIONS] FILENAME", - gettext_noop - ("Unindex a file that was previously indexed with gnunet-publish."), - options, &run, NULL)) ? ret : 1; - GNUNET_free ((void*) argv); + GNUNET_PROGRAM_run ( + argc, + argv, + "gnunet-unindex [OPTIONS] FILENAME", + gettext_noop ( + "Unindex a file that was previously indexed with gnunet-publish."), + options, + &run, + NULL)) + ? ret + : 1; + GNUNET_free ((void *) argv); return ret; } diff --git a/src/fs/perf_gnunet_service_fs_p2p.c b/src/fs/perf_gnunet_service_fs_p2p.c index 61f859235..0d76dfc3d 100644 --- a/src/fs/perf_gnunet_service_fs_p2p.c +++ b/src/fs/perf_gnunet_service_fs_p2p.c @@ -116,7 +116,7 @@ print_stat (void *cls, const char *subsystem, const char *name, uint64_t value, { struct StatMaster *sm = cls; - FPRINTF (stderr, + fprintf (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem, @@ -267,7 +267,7 @@ do_report (void *cls) fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * 1000000LL / del.rel_value_us); - FPRINTF (stdout, + fprintf (stdout, "Download speed was %s/s\n", fancy); GNUNET_free (fancy); diff --git a/src/fs/perf_gnunet_service_fs_p2p_respect.c b/src/fs/perf_gnunet_service_fs_p2p_respect.c index afde310a0..9b14b9eb6 100644 --- a/src/fs/perf_gnunet_service_fs_p2p_respect.c +++ b/src/fs/perf_gnunet_service_fs_p2p_respect.c @@ -168,7 +168,7 @@ print_stat (void *cls, const char *subsystem, const char *name, uint64_t value, { struct StatMaster *sm = cls; - FPRINTF (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem, + fprintf (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem, name, (unsigned long long) value); return GNUNET_OK; } @@ -304,7 +304,7 @@ do_report (void *cls) fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * 1000000LL / del.rel_value_us); - FPRINTF (stderr, "Download speed of type `%s' was %s/s\n", type, fancy); + fprintf (stderr, "Download speed of type `%s' was %s/s\n", type, fancy); GNUNET_free (fancy); if (NUM_DAEMONS != ++download_counter) return; /* more downloads to come */ diff --git a/src/fs/test_fs.c b/src/fs/test_fs.c index 95368f108..e88c74464 100644 --- a/src/fs/test_fs.c +++ b/src/fs/test_fs.c @@ -226,7 +226,7 @@ FAILURE: GNUNET_FSUI_stop (ctx); if (filename != NULL) { - UNLINK (filename); + unlink (filename); GNUNET_free (filename); } if (download != NULL) @@ -236,7 +236,7 @@ FAILURE: } filename = makeName (43); /* TODO: verify file 'filename(42)' == file 'filename(43)' */ - UNLINK (filename); + unlink (filename); GNUNET_free (filename); #if START_DAEMON diff --git a/src/fs/test_fs_directory.c b/src/fs/test_fs_directory.c index a2d131ca1..5cdbd9d07 100644 --- a/src/fs/test_fs_directory.c +++ b/src/fs/test_fs_directory.c @@ -59,7 +59,7 @@ processor (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, return; } } - FPRINTF (stderr, "Error at %s:%d\n", __FILE__, __LINE__); + fprintf (stderr, "Error at %s:%d\n", __FILE__, __LINE__); } static int @@ -136,7 +136,7 @@ testDirectory (unsigned int i) s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES); - FPRINTF (stdout, + fprintf (stdout, "Creating directory with %u entires and total size %llu took %s\n", i, (unsigned long long) dlen, s); if (i < 100) diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c index 135e2d378..242e6f1aa 100644 --- a/src/fs/test_fs_download.c +++ b/src/fs/test_fs_download.c @@ -195,14 +195,14 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) progress.offset); break; case GNUNET_FS_STATUS_PUBLISH_ERROR: - FPRINTF (stderr, "Error publishing file: %s\n", + fprintf (stderr, "Error publishing file: %s\n", event->value.publish.specifics.error.message); GNUNET_break (0); GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); GNUNET_SCHEDULER_shutdown (); break; case GNUNET_FS_STATUS_DOWNLOAD_ERROR: - FPRINTF (stderr, "Error downloading file: %s\n", + fprintf (stderr, "Error downloading file: %s\n", event->value.download.specifics.error.message); GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); GNUNET_SCHEDULER_shutdown (); @@ -342,7 +342,7 @@ main (int argc, char *argv[]) return 1; if (NULL != fn1) { - UNLINK (fn1); + unlink (fn1); GNUNET_free (fn1); } return err; diff --git a/src/fs/test_fs_download_persistence.c b/src/fs/test_fs_download_persistence.c index 183a407e0..97c2a338c 100644 --- a/src/fs/test_fs_download_persistence.c +++ b/src/fs/test_fs_download_persistence.c @@ -198,13 +198,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) progress.offset); break; case GNUNET_FS_STATUS_PUBLISH_ERROR: - FPRINTF (stderr, "Error publishing file: %s\n", + fprintf (stderr, "Error publishing file: %s\n", event->value.publish.specifics.error.message); GNUNET_break (0); GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); break; case GNUNET_FS_STATUS_DOWNLOAD_ERROR: - FPRINTF (stderr, "Error downloading file: %s\n", + fprintf (stderr, "Error downloading file: %s\n", event->value.download.specifics.error.message); GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); break; diff --git a/src/fs/test_fs_getopt.c b/src/fs/test_fs_getopt.c index 03de383a4..3562069e1 100644 --- a/src/fs/test_fs_getopt.c +++ b/src/fs/test_fs_getopt.c @@ -32,6 +32,6 @@ main (int argc, char *argv[]) GNUNET_log_setup ("test_fs_getopt", "WARNING", NULL); - FPRINTF (stderr, "%s", "WARNING: testcase not yet written.\n"); + fprintf (stderr, "%s", "WARNING: testcase not yet written.\n"); return 0; /* testcase passed */ } diff --git a/src/fs/test_fs_list_indexed.c b/src/fs/test_fs_list_indexed.c index 632cba43e..a4e7eb53f 100644 --- a/src/fs/test_fs_list_indexed.c +++ b/src/fs/test_fs_list_indexed.c @@ -117,7 +117,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) break; case GNUNET_FS_STATUS_PUBLISH_ERROR: ret = event->value.publish.cctx; - FPRINTF (stderr, "Error publishing file: %s\n", + fprintf (stderr, "Error publishing file: %s\n", event->value.publish.specifics.error.message); err = 1; if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) diff --git a/src/fs/test_fs_namespace.c b/src/fs/test_fs_namespace.c index 56a36825c..43c899b72 100644 --- a/src/fs/test_fs_namespace.c +++ b/src/fs/test_fs_namespace.c @@ -85,7 +85,7 @@ static void do_timeout (void *cls) { err = 1; - FPRINTF (stderr, "%s", "Operation timed out\n"); + fprintf (stderr, "%s", "Operation timed out\n"); kill_task = NULL; abort_sks_search_task (NULL); abort_ksk_search_task (NULL); @@ -103,7 +103,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) if (!GNUNET_FS_uri_test_equal (sks_expect_uri, event->value.search.specifics.result.uri)) { - FPRINTF (stderr, "%s", "Wrong result for sks search!\n"); + fprintf (stderr, "%s", "Wrong result for sks search!\n"); err = 1; } /* give system 1ms to initiate update search! */ @@ -115,19 +115,19 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) if (!GNUNET_FS_uri_test_equal (ksk_expect_uri, event->value.search.specifics.result.uri)) { - FPRINTF (stderr, "%s", "Wrong result for ksk search!\n"); + fprintf (stderr, "%s", "Wrong result for ksk search!\n"); err = 1; } GNUNET_SCHEDULER_add_now (&abort_ksk_search_task, NULL); } else { - FPRINTF (stderr, "%s", "Unexpected search result received!\n"); + fprintf (stderr, "%s", "Unexpected search result received!\n"); GNUNET_break (0); } break; case GNUNET_FS_STATUS_SEARCH_ERROR: - FPRINTF (stderr, "Error searching file: %s\n", + fprintf (stderr, "Error searching file: %s\n", event->value.search.specifics.error.message); if (sks_search == event->value.search.sc) GNUNET_SCHEDULER_add_now (&abort_sks_search_task, NULL); @@ -152,7 +152,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) case GNUNET_FS_STATUS_SEARCH_STOPPED: return NULL; default: - FPRINTF (stderr, "Unexpected event: %d\n", event->status); + fprintf (stderr, "Unexpected event: %d\n", event->status); break; } return event->value.search.cctx; @@ -170,7 +170,7 @@ publish_cont (void *cls, const struct GNUNET_FS_Uri *ksk_uri, const char *emsg) if (NULL != emsg) { - FPRINTF (stderr, "Error publishing: %s\n", emsg); + fprintf (stderr, "Error publishing: %s\n", emsg); err = 1; GNUNET_FS_stop (fs); return; @@ -182,7 +182,7 @@ publish_cont (void *cls, const struct GNUNET_FS_Uri *ksk_uri, const char *emsg) sks_uri = GNUNET_FS_uri_parse (sbuf, &msg); if (NULL == sks_uri) { - FPRINTF (stderr, "failed to parse URI `%s': %s\n", sbuf, msg); + fprintf (stderr, "failed to parse URI `%s': %s\n", sbuf, msg); err = 1; GNUNET_FS_stop (fs); GNUNET_free_non_null (msg); @@ -239,7 +239,7 @@ adv_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) if (NULL != emsg) { - FPRINTF (stderr, "Error publishing: %s\n", emsg); + fprintf (stderr, "Error publishing: %s\n", emsg); err = 1; GNUNET_FS_stop (fs); return; diff --git a/src/fs/test_fs_publish.c b/src/fs/test_fs_publish.c index bc38d316a..fe54bb552 100644 --- a/src/fs/test_fs_publish.c +++ b/src/fs/test_fs_publish.c @@ -105,12 +105,12 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) break; case GNUNET_FS_STATUS_PUBLISH_ERROR: ret = event->value.publish.cctx; - FPRINTF (stderr, "Error publishing file: %s\n", + fprintf (stderr, "Error publishing file: %s\n", event->value.publish.specifics.error.message); err = 1; if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) { - FPRINTF (stderr, "Scheduling abort task for error on `%s'\n", + fprintf (stderr, "Scheduling abort task for error on `%s'\n", (const char *) event->value.publish.cctx); GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); } diff --git a/src/fs/test_fs_publish_persistence.c b/src/fs/test_fs_publish_persistence.c index 4d27b1509..6242e66f8 100644 --- a/src/fs/test_fs_publish_persistence.c +++ b/src/fs/test_fs_publish_persistence.c @@ -177,7 +177,7 @@ progress_cb (void *cls, break; case GNUNET_FS_STATUS_PUBLISH_ERROR: ret = event->value.publish.cctx; - FPRINTF (stderr, "Error publishing file: %s\n", + fprintf (stderr, "Error publishing file: %s\n", event->value.publish.specifics.error.message); err = 1; GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); diff --git a/src/fs/test_fs_search.c b/src/fs/test_fs_search.c index 2377cb1a2..2a7f4b1dd 100644 --- a/src/fs/test_fs_search.c +++ b/src/fs/test_fs_search.c @@ -140,13 +140,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); break; case GNUNET_FS_STATUS_PUBLISH_ERROR: - FPRINTF (stderr, "Error publishing file: %s\n", + fprintf (stderr, "Error publishing file: %s\n", event->value.publish.specifics.error.message); GNUNET_break (0); GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); break; case GNUNET_FS_STATUS_SEARCH_ERROR: - FPRINTF (stderr, "Error searching file: %s\n", + fprintf (stderr, "Error searching file: %s\n", event->value.search.specifics.error.message); GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); break; @@ -176,7 +176,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); break; default: - FPRINTF (stderr, "Unexpected event: %d\n", event->status); + fprintf (stderr, "Unexpected event: %d\n", event->status); break; } return NULL; diff --git a/src/fs/test_fs_search_persistence.c b/src/fs/test_fs_search_persistence.c index a0483e723..68e3a4a62 100644 --- a/src/fs/test_fs_search_persistence.c +++ b/src/fs/test_fs_search_persistence.c @@ -187,13 +187,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); break; case GNUNET_FS_STATUS_PUBLISH_ERROR: - FPRINTF (stderr, "Error publishing file: %s\n", + fprintf (stderr, "Error publishing file: %s\n", event->value.publish.specifics.error.message); GNUNET_break (0); GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); break; case GNUNET_FS_STATUS_SEARCH_ERROR: - FPRINTF (stderr, "Error searching file: %s\n", + fprintf (stderr, "Error searching file: %s\n", event->value.search.specifics.error.message); GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); break; @@ -237,7 +237,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) search = NULL; break; default: - FPRINTF (stderr, "Unexpected event: %d\n", event->status); + fprintf (stderr, "Unexpected event: %d\n", event->status); break; } return NULL; diff --git a/src/fs/test_fs_search_probes.c b/src/fs/test_fs_search_probes.c index ca504c08e..c65649108 100644 --- a/src/fs/test_fs_search_probes.c +++ b/src/fs/test_fs_search_probes.c @@ -137,13 +137,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Search complete.\n"); break; case GNUNET_FS_STATUS_PUBLISH_ERROR: - FPRINTF (stderr, "Error publishing file: %s\n", + fprintf (stderr, "Error publishing file: %s\n", event->value.publish.specifics.error.message); GNUNET_break (0); GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); break; case GNUNET_FS_STATUS_SEARCH_ERROR: - FPRINTF (stderr, "Error searching file: %s\n", + fprintf (stderr, "Error searching file: %s\n", event->value.search.specifics.error.message); GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); break; @@ -178,7 +178,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); break; default: - FPRINTF (stderr, + fprintf (stderr, "Unexpected event: %d\n", event->status); break; diff --git a/src/fs/test_fs_search_with_and.c b/src/fs/test_fs_search_with_and.c index daaf38a19..f1072a4a1 100644 --- a/src/fs/test_fs_search_with_and.c +++ b/src/fs/test_fs_search_with_and.c @@ -153,13 +153,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); break; case GNUNET_FS_STATUS_PUBLISH_ERROR: - FPRINTF (stderr, "Error publishing file: %s\n", + fprintf (stderr, "Error publishing file: %s\n", event->value.publish.specifics.error.message); GNUNET_break (0); GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); break; case GNUNET_FS_STATUS_SEARCH_ERROR: - FPRINTF (stderr, "Error searching file: %s\n", + fprintf (stderr, "Error searching file: %s\n", event->value.search.specifics.error.message); GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); break; @@ -189,7 +189,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); break; default: - FPRINTF (stderr, "Unexpected event: %d\n", event->status); + fprintf (stderr, "Unexpected event: %d\n", event->status); break; } return NULL; diff --git a/src/fs/test_fs_unindex.c b/src/fs/test_fs_unindex.c index 9e358dade..b4bdc1b80 100644 --- a/src/fs/test_fs_unindex.c +++ b/src/fs/test_fs_unindex.c @@ -121,13 +121,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) progress.offset); break; case GNUNET_FS_STATUS_PUBLISH_ERROR: - FPRINTF (stderr, "Error publishing file: %s\n", + fprintf (stderr, "Error publishing file: %s\n", event->value.publish.specifics.error.message); GNUNET_break (0); GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); break; case GNUNET_FS_STATUS_UNINDEX_ERROR: - FPRINTF (stderr, "Error unindexing file: %s\n", + fprintf (stderr, "Error unindexing file: %s\n", event->value.unindex.specifics.error.message); GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL); break; diff --git a/src/fs/test_fs_unindex_persistence.c b/src/fs/test_fs_unindex_persistence.c index 4d6d63c6a..50d45708a 100644 --- a/src/fs/test_fs_unindex_persistence.c +++ b/src/fs/test_fs_unindex_persistence.c @@ -183,7 +183,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) unindex = event->value.unindex.uc; return "unindex"; case GNUNET_FS_STATUS_PUBLISH_ERROR: - FPRINTF (stderr, "Error publishing file: %s\n", + fprintf (stderr, "Error publishing file: %s\n", event->value.publish.specifics.error.message); GNUNET_break (0); GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); diff --git a/src/fs/test_fs_uri.c b/src/fs/test_fs_uri.c index d4ee8c302..e0a2ecea7 100644 --- a/src/fs/test_fs_uri.c +++ b/src/fs/test_fs_uri.c @@ -314,11 +314,11 @@ main (int argc, char *argv[]) failureCount += testLocation (); for (i = 0; i < 255; i++) { - /* FPRINTF (stderr, "%s", "."); */ + /* fprintf (stderr, "%s", "."); */ failureCount += testNamespace (i); failureCount += testFile (i); } - /* FPRINTF (stderr, "%s", "\n"); */ + /* fprintf (stderr, "%s", "\n"); */ GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-uri"); if (failureCount != 0) return 1; diff --git a/src/fs/test_gnunet_service_fs_migration.c b/src/fs/test_gnunet_service_fs_migration.c index 4a3bf67c7..f7daf6b1a 100644 --- a/src/fs/test_gnunet_service_fs_migration.c +++ b/src/fs/test_gnunet_service_fs_migration.c @@ -86,7 +86,7 @@ do_stop (void *cls) fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * 1000000LL / del.rel_value_us); - FPRINTF (stdout, + fprintf (stdout, "Download speed was %s/s\n", fancy); GNUNET_free (fancy); diff --git a/src/fs/test_gnunet_service_fs_p2p.c b/src/fs/test_gnunet_service_fs_p2p.c index e33df8502..2050b0835 100644 --- a/src/fs/test_gnunet_service_fs_p2p.c +++ b/src/fs/test_gnunet_service_fs_p2p.c @@ -77,7 +77,7 @@ do_stop (void *cls) fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * 1000000LL / del.rel_value_us); - FPRINTF (stdout, + fprintf (stdout, "Download speed was %s/s\n", fancy); GNUNET_free (fancy); diff --git a/src/fs/test_plugin_block_fs.c b/src/fs/test_plugin_block_fs.c index 30981abc5..3b17b6917 100644 --- a/src/fs/test_plugin_block_fs.c +++ b/src/fs/test_plugin_block_fs.c @@ -84,7 +84,7 @@ main (int argc, char *argv[]) GNUNET_BLOCK_context_destroy (ctx); GNUNET_CONFIGURATION_destroy (cfg); if (ret != 0) - FPRINTF (stderr, "Tests failed: %d\n", ret); + fprintf (stderr, "Tests failed: %d\n", ret); return ret; } -- cgit v1.2.3