diff options
author | ng0 <ng0@n0.is> | 2019-09-06 22:46:29 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-06 22:46:29 +0000 |
commit | 6e599264ad13e8fc105493d74d7c11d46f8739ed (patch) | |
tree | 169bef1ecbade5a659831fb169f3ae6943af127f /src/fs | |
parent | 4f13bc15113021ebf71d5d81e99bc29f8a07fc9c (diff) | |
download | gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.tar.gz gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.zip |
first step to remove plibc
Diffstat (limited to 'src/fs')
36 files changed, 2137 insertions, 2115 deletions
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) | |||
56 | qe->h->active_downloads++; | 56 | qe->h->active_downloads++; |
57 | qe->start_time = GNUNET_TIME_absolute_get (); | 57 | qe->start_time = GNUNET_TIME_absolute_get (); |
58 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 58 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
59 | "Starting job %p (%u active)\n", | 59 | "Starting job %p (%u active)\n", |
60 | qe, | 60 | qe, |
61 | qe->h->active_downloads); | 61 | qe->h->active_downloads); |
62 | GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, | 62 | GNUNET_CONTAINER_DLL_remove (qe->h->pending_head, qe->h->pending_tail, qe); |
63 | qe->h->pending_tail, | ||
64 | qe); | ||
65 | GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head, | 63 | GNUNET_CONTAINER_DLL_insert_after (qe->h->running_head, |
66 | qe->h->running_tail, | 64 | qe->h->running_tail, |
67 | qe->h->running_tail, | 65 | qe->h->running_tail, |
@@ -83,17 +81,14 @@ stop_job (struct GNUNET_FS_QueueEntry *qe) | |||
83 | GNUNET_assert (0 < qe->h->active_downloads); | 81 | GNUNET_assert (0 < qe->h->active_downloads); |
84 | qe->h->active_downloads--; | 82 | qe->h->active_downloads--; |
85 | qe->h->active_blocks -= qe->blocks; | 83 | qe->h->active_blocks -= qe->blocks; |
86 | qe->run_time = | 84 | qe->run_time = GNUNET_TIME_relative_add (qe->run_time, |
87 | GNUNET_TIME_relative_add (qe->run_time, | 85 | GNUNET_TIME_absolute_get_duration ( |
88 | GNUNET_TIME_absolute_get_duration | 86 | qe->start_time)); |
89 | (qe->start_time)); | ||
90 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 87 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
91 | "Stopping job %p (%u active)\n", | 88 | "Stopping job %p (%u active)\n", |
92 | qe, | 89 | qe, |
93 | qe->h->active_downloads); | 90 | qe->h->active_downloads); |
94 | GNUNET_CONTAINER_DLL_remove (qe->h->running_head, | 91 | GNUNET_CONTAINER_DLL_remove (qe->h->running_head, qe->h->running_tail, qe); |
95 | qe->h->running_tail, | ||
96 | qe); | ||
97 | GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head, | 92 | GNUNET_CONTAINER_DLL_insert_after (qe->h->pending_head, |
98 | qe->h->pending_tail, | 93 | qe->h->pending_tail, |
99 | qe->h->pending_tail, | 94 | qe->h->pending_tail, |
@@ -167,13 +162,13 @@ process_job_queue (void *cls) | |||
167 | rst = GNUNET_TIME_absolute_get_remaining (end_time); | 162 | rst = GNUNET_TIME_absolute_get_remaining (end_time); |
168 | if (0 == rst.rel_value_us) | 163 | if (0 == rst.rel_value_us) |
169 | { | 164 | { |
170 | num_probes_expired++; | 165 | num_probes_expired++; |
171 | stop_job (qe); | 166 | stop_job (qe); |
172 | } | 167 | } |
173 | else | 168 | else |
174 | { | 169 | { |
175 | num_probes_active++; | 170 | num_probes_active++; |
176 | restart_at = GNUNET_TIME_relative_min (rst, restart_at); | 171 | restart_at = GNUNET_TIME_relative_min (rst, restart_at); |
177 | } | 172 | } |
178 | break; | 173 | break; |
179 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: | 174 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: |
@@ -184,13 +179,13 @@ process_job_queue (void *cls) | |||
184 | rst = GNUNET_TIME_absolute_get_remaining (end_time); | 179 | rst = GNUNET_TIME_absolute_get_remaining (end_time); |
185 | if (0 == rst.rel_value_us) | 180 | if (0 == rst.rel_value_us) |
186 | { | 181 | { |
187 | num_downloads_expired++; | 182 | num_downloads_expired++; |
188 | stop_job (qe); | 183 | stop_job (qe); |
189 | } | 184 | } |
190 | else | 185 | else |
191 | { | 186 | { |
192 | num_downloads_active++; | 187 | num_downloads_active++; |
193 | restart_at = GNUNET_TIME_relative_min (rst, restart_at); | 188 | restart_at = GNUNET_TIME_relative_min (rst, restart_at); |
194 | } | 189 | } |
195 | break; | 190 | break; |
196 | default: | 191 | default: |
@@ -201,41 +196,44 @@ process_job_queue (void *cls) | |||
201 | GNUNET_break (h->active_downloads == | 196 | GNUNET_break (h->active_downloads == |
202 | num_downloads_active + num_probes_active); | 197 | num_downloads_active + num_probes_active); |
203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 198 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
204 | "PA: %u, PE: %u, PW: %u; DA: %u, DE: %u, DW: %u\n", | 199 | "PA: %u, PE: %u, PW: %u; DA: %u, DE: %u, DW: %u\n", |
205 | num_probes_active, | 200 | num_probes_active, |
206 | num_probes_expired, | 201 | num_probes_expired, |
207 | num_probes_waiting, | 202 | num_probes_waiting, |
208 | num_downloads_active, | 203 | num_downloads_active, |
209 | num_downloads_expired, | 204 | num_downloads_expired, |
210 | num_downloads_waiting); | 205 | num_downloads_waiting); |
211 | GNUNET_break (h->active_downloads + num_probes_active <= | 206 | GNUNET_break (h->active_downloads + num_probes_active <= |
212 | h->max_parallel_downloads); | 207 | h->max_parallel_downloads); |
213 | /* calculate start/stop decisions */ | 208 | /* calculate start/stop decisions */ |
214 | if (h->active_downloads + num_downloads_waiting > h->max_parallel_downloads) | 209 | if (h->active_downloads + num_downloads_waiting > h->max_parallel_downloads) |
215 | { | 210 | { |
216 | /* stop as many probes as there are downloads and probes */ | 211 | /* stop as many probes as there are downloads and probes */ |
217 | num_probes_change = - GNUNET_MIN (num_probes_active, | 212 | num_probes_change = -GNUNET_MIN (num_probes_active, num_downloads_waiting); |
218 | num_downloads_waiting); | ||
219 | /* start as many downloads as there are free slots, including those | 213 | /* start as many downloads as there are free slots, including those |
220 | we just opened up */ | 214 | we just opened up */ |
221 | num_downloads_change = h->max_parallel_downloads - h->active_downloads - num_probes_change; | 215 | num_downloads_change = |
216 | h->max_parallel_downloads - h->active_downloads - num_probes_change; | ||
222 | } | 217 | } |
223 | else | 218 | else |
224 | { | 219 | { |
225 | /* start all downloads (we can) */ | 220 | /* start all downloads (we can) */ |
226 | num_downloads_change = num_downloads_waiting; | 221 | num_downloads_change = num_downloads_waiting; |
227 | /* also start probes if there is room, but use a lower cap of (mpd/4) + 1 */ | 222 | /* also start probes if there is room, but use a lower cap of (mpd/4) + 1 */ |
228 | if (1 + h->max_parallel_downloads / 4 >= (h->active_downloads + num_downloads_change)) | 223 | if (1 + h->max_parallel_downloads / 4 >= |
229 | num_probes_change = GNUNET_MIN (num_probes_waiting, | 224 | (h->active_downloads + num_downloads_change)) |
230 | (1 + h->max_parallel_downloads / 4) - (h->active_downloads + num_downloads_change)); | 225 | num_probes_change = |
226 | GNUNET_MIN (num_probes_waiting, | ||
227 | (1 + h->max_parallel_downloads / 4) - | ||
228 | (h->active_downloads + num_downloads_change)); | ||
231 | else | 229 | else |
232 | num_probes_change = 0; | 230 | num_probes_change = 0; |
233 | } | 231 | } |
234 | GNUNET_break (num_downloads_change <= num_downloads_waiting); | 232 | GNUNET_break (num_downloads_change <= num_downloads_waiting); |
235 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 233 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
236 | "Changing %d probes and %d/%u/%u downloads\n", | 234 | "Changing %d probes and %d/%u/%u downloads\n", |
237 | num_probes_change, | 235 | num_probes_change, |
238 | num_downloads_change, | 236 | num_downloads_change, |
239 | (unsigned int) h->active_downloads, | 237 | (unsigned int) h->active_downloads, |
240 | (unsigned int) h->max_parallel_downloads); | 238 | (unsigned int) h->max_parallel_downloads); |
241 | /* actually stop probes */ | 239 | /* actually stop probes */ |
@@ -250,7 +248,7 @@ process_job_queue (void *cls) | |||
250 | stop_job (qe); | 248 | stop_job (qe); |
251 | num_probes_change++; | 249 | num_probes_change++; |
252 | if (0 == num_probes_change) | 250 | if (0 == num_probes_change) |
253 | break; | 251 | break; |
254 | } | 252 | } |
255 | } | 253 | } |
256 | GNUNET_break (0 <= num_probes_change); | 254 | GNUNET_break (0 <= num_probes_change); |
@@ -258,9 +256,8 @@ process_job_queue (void *cls) | |||
258 | /* start some more tasks if we now have empty slots */ | 256 | /* start some more tasks if we now have empty slots */ |
259 | block_limit_hit = GNUNET_NO; | 257 | block_limit_hit = GNUNET_NO; |
260 | next = h->pending_head; | 258 | next = h->pending_head; |
261 | while ( (NULL != (qe = next)) && | 259 | while ((NULL != (qe = next)) && |
262 | ( (num_probes_change > 0) || | 260 | ((num_probes_change > 0) || (num_downloads_change > 0))) |
263 | (num_downloads_change > 0) ) ) | ||
264 | { | 261 | { |
265 | next = qe->next; | 262 | next = qe->next; |
266 | switch (qe->priority) | 263 | switch (qe->priority) |
@@ -268,40 +265,40 @@ process_job_queue (void *cls) | |||
268 | case GNUNET_FS_QUEUE_PRIORITY_PROBE: | 265 | case GNUNET_FS_QUEUE_PRIORITY_PROBE: |
269 | if (num_probes_change > 0) | 266 | if (num_probes_change > 0) |
270 | { | 267 | { |
271 | start_job (qe); | 268 | start_job (qe); |
272 | num_probes_change--; | 269 | num_probes_change--; |
273 | run_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2); | 270 | run_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2); |
274 | restart_at = GNUNET_TIME_relative_min (run_time, restart_at); | 271 | restart_at = GNUNET_TIME_relative_min (run_time, restart_at); |
275 | } | 272 | } |
276 | break; | 273 | break; |
277 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: | 274 | case GNUNET_FS_QUEUE_PRIORITY_NORMAL: |
278 | if ( (num_downloads_change > 0) && | 275 | if ((num_downloads_change > 0) && |
279 | ( (qe->blocks + h->active_blocks <= h->max_parallel_requests) || | 276 | ((qe->blocks + h->active_blocks <= h->max_parallel_requests) || |
280 | ( (qe->blocks > h->max_parallel_requests) && | 277 | ((qe->blocks > h->max_parallel_requests) && |
281 | (0 == h->active_downloads) ) ) ) | 278 | (0 == h->active_downloads)))) |
282 | { | 279 | { |
283 | start_job (qe); | 280 | start_job (qe); |
284 | num_downloads_change--; | 281 | num_downloads_change--; |
285 | } | 282 | } |
286 | else if (num_downloads_change > 0) | 283 | else if (num_downloads_change > 0) |
287 | block_limit_hit = GNUNET_YES; | 284 | block_limit_hit = GNUNET_YES; |
288 | break; | 285 | break; |
289 | default: | 286 | default: |
290 | GNUNET_break (0); | 287 | GNUNET_break (0); |
291 | break; | 288 | break; |
292 | } | 289 | } |
293 | } | 290 | } |
294 | GNUNET_break ( (0 == num_downloads_change) || | 291 | GNUNET_break ((0 == num_downloads_change) || (GNUNET_YES == block_limit_hit)); |
295 | (GNUNET_YES == block_limit_hit) ); | ||
296 | GNUNET_break (0 == num_probes_change); | 292 | GNUNET_break (0 == num_probes_change); |
297 | 293 | ||
298 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 294 | GNUNET_log ( |
299 | "AD: %u, MP: %u; %d probes and %d downloads to start, will run again in %s\n", | 295 | GNUNET_ERROR_TYPE_DEBUG, |
300 | h->active_downloads, | 296 | "AD: %u, MP: %u; %d probes and %d downloads to start, will run again in %s\n", |
301 | h->max_parallel_requests, | 297 | h->active_downloads, |
302 | num_probes_change, | 298 | h->max_parallel_requests, |
303 | num_downloads_change, | 299 | num_probes_change, |
304 | GNUNET_STRINGS_relative_time_to_string (restart_at, GNUNET_YES)); | 300 | num_downloads_change, |
301 | GNUNET_STRINGS_relative_time_to_string (restart_at, GNUNET_YES)); | ||
305 | 302 | ||
306 | /* make sure we run again, callbacks might have | 303 | /* make sure we run again, callbacks might have |
307 | already re-scheduled the job, so cancel such | 304 | already re-scheduled the job, so cancel such |
@@ -309,7 +306,7 @@ process_job_queue (void *cls) | |||
309 | if (NULL != h->queue_job) | 306 | if (NULL != h->queue_job) |
310 | GNUNET_SCHEDULER_cancel (h->queue_job); | 307 | GNUNET_SCHEDULER_cancel (h->queue_job); |
311 | h->queue_job = | 308 | h->queue_job = |
312 | GNUNET_SCHEDULER_add_delayed (restart_at, &process_job_queue, h); | 309 | GNUNET_SCHEDULER_add_delayed (restart_at, &process_job_queue, h); |
313 | } | 310 | } |
314 | 311 | ||
315 | 312 | ||
@@ -330,7 +327,7 @@ GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, | |||
330 | GNUNET_SCHEDULER_TaskCallback stop, | 327 | GNUNET_SCHEDULER_TaskCallback stop, |
331 | void *cls, | 328 | void *cls, |
332 | unsigned int blocks, | 329 | unsigned int blocks, |
333 | enum GNUNET_FS_QueuePriority priority) | 330 | enum GNUNET_FS_QueuePriority priority) |
334 | { | 331 | { |
335 | struct GNUNET_FS_QueueEntry *qe; | 332 | struct GNUNET_FS_QueueEntry *qe; |
336 | 333 | ||
@@ -342,14 +339,14 @@ GNUNET_FS_queue_ (struct GNUNET_FS_Handle *h, | |||
342 | qe->queue_time = GNUNET_TIME_absolute_get (); | 339 | qe->queue_time = GNUNET_TIME_absolute_get (); |
343 | qe->blocks = blocks; | 340 | qe->blocks = blocks; |
344 | qe->priority = priority; | 341 | qe->priority = priority; |
345 | GNUNET_CONTAINER_DLL_insert_after (h->pending_head, h->pending_tail, | 342 | GNUNET_CONTAINER_DLL_insert_after (h->pending_head, |
346 | h->pending_tail, qe); | 343 | h->pending_tail, |
344 | h->pending_tail, | ||
345 | qe); | ||
347 | if (NULL != h->queue_job) | 346 | if (NULL != h->queue_job) |
348 | GNUNET_SCHEDULER_cancel (h->queue_job); | 347 | GNUNET_SCHEDULER_cancel (h->queue_job); |
349 | h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h); | 348 | h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h); |
350 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing job %p\n", qe); |
351 | "Queueing job %p\n", | ||
352 | qe); | ||
353 | return qe; | 350 | return qe; |
354 | } | 351 | } |
355 | 352 | ||
@@ -365,19 +362,14 @@ GNUNET_FS_dequeue_ (struct GNUNET_FS_QueueEntry *qe) | |||
365 | struct GNUNET_FS_Handle *h; | 362 | struct GNUNET_FS_Handle *h; |
366 | 363 | ||
367 | h = qe->h; | 364 | h = qe->h; |
368 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 365 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dequeueing job %p\n", qe); |
369 | "Dequeueing job %p\n", | ||
370 | qe); | ||
371 | if (GNUNET_YES == qe->active) | 366 | if (GNUNET_YES == qe->active) |
372 | stop_job (qe); | 367 | stop_job (qe); |
373 | GNUNET_CONTAINER_DLL_remove (h->pending_head, | 368 | GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, qe); |
374 | h->pending_tail, | ||
375 | qe); | ||
376 | GNUNET_free (qe); | 369 | GNUNET_free (qe); |
377 | if (NULL != h->queue_job) | 370 | if (NULL != h->queue_job) |
378 | GNUNET_SCHEDULER_cancel (h->queue_job); | 371 | GNUNET_SCHEDULER_cancel (h->queue_job); |
379 | h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, | 372 | h->queue_job = GNUNET_SCHEDULER_add_now (&process_job_queue, h); |
380 | h); | ||
381 | } | 373 | } |
382 | 374 | ||
383 | 375 | ||
@@ -399,9 +391,7 @@ GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, | |||
399 | ret = GNUNET_new (struct TopLevelActivity); | 391 | ret = GNUNET_new (struct TopLevelActivity); |
400 | ret->ssf = ssf; | 392 | ret->ssf = ssf; |
401 | ret->ssf_cls = ssf_cls; | 393 | ret->ssf_cls = ssf_cls; |
402 | GNUNET_CONTAINER_DLL_insert (h->top_head, | 394 | GNUNET_CONTAINER_DLL_insert (h->top_head, h->top_tail, ret); |
403 | h->top_tail, | ||
404 | ret); | ||
405 | return ret; | 395 | return ret; |
406 | } | 396 | } |
407 | 397 | ||
@@ -413,12 +403,9 @@ GNUNET_FS_make_top (struct GNUNET_FS_Handle *h, | |||
413 | * @param top top level activity entry | 403 | * @param top top level activity entry |
414 | */ | 404 | */ |
415 | void | 405 | void |
416 | GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, | 406 | GNUNET_FS_end_top (struct GNUNET_FS_Handle *h, struct TopLevelActivity *top) |
417 | struct TopLevelActivity *top) | ||
418 | { | 407 | { |
419 | GNUNET_CONTAINER_DLL_remove (h->top_head, | 408 | GNUNET_CONTAINER_DLL_remove (h->top_head, h->top_tail, top); |
420 | h->top_tail, | ||
421 | top); | ||
422 | GNUNET_free (top); | 409 | GNUNET_free (top); |
423 | } | 410 | } |
424 | 411 | ||
@@ -489,33 +476,32 @@ GNUNET_FS_data_reader_file_ (void *cls, | |||
489 | } | 476 | } |
490 | if (NULL == fi->fd) | 477 | if (NULL == fi->fd) |
491 | { | 478 | { |
492 | fi->fd = | 479 | fi->fd = GNUNET_DISK_file_open (fi->filename, |
493 | GNUNET_DISK_file_open (fi->filename, | 480 | GNUNET_DISK_OPEN_READ, |
494 | GNUNET_DISK_OPEN_READ, | 481 | GNUNET_DISK_PERM_NONE); |
495 | GNUNET_DISK_PERM_NONE); | ||
496 | if (NULL == fi->fd) | 482 | if (NULL == fi->fd) |
497 | { | 483 | { |
498 | GNUNET_asprintf (emsg, | 484 | GNUNET_asprintf (emsg, |
499 | _("Could not open file `%s': %s"), | 485 | _ ("Could not open file `%s': %s"), |
500 | fi->filename, | 486 | fi->filename, |
501 | STRERROR (errno)); | 487 | strerror (errno)); |
502 | return 0; | 488 | return 0; |
503 | } | 489 | } |
504 | } | 490 | } |
505 | if ( (GNUNET_SYSERR == | 491 | if ((GNUNET_SYSERR == |
506 | GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET)) || | 492 | GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET)) || |
507 | (-1 == (ret = GNUNET_DISK_file_read (fi->fd, buf, max))) ) | 493 | (-1 == (ret = GNUNET_DISK_file_read (fi->fd, buf, max)))) |
508 | { | 494 | { |
509 | GNUNET_asprintf (emsg, | 495 | GNUNET_asprintf (emsg, |
510 | _("Could not read file `%s': %s"), | 496 | _ ("Could not read file `%s': %s"), |
511 | fi->filename, | 497 | fi->filename, |
512 | STRERROR (errno)); | 498 | strerror (errno)); |
513 | return 0; | 499 | return 0; |
514 | } | 500 | } |
515 | if (ret != max) | 501 | if (ret != max) |
516 | { | 502 | { |
517 | GNUNET_asprintf (emsg, | 503 | GNUNET_asprintf (emsg, |
518 | _("Short read reading from file `%s'!"), | 504 | _ ("Short read reading from file `%s'!"), |
519 | fi->filename); | 505 | fi->filename); |
520 | return 0; | 506 | return 0; |
521 | } | 507 | } |
@@ -604,13 +590,20 @@ get_serialization_file_name (struct GNUNET_FS_Handle *h, | |||
604 | char *ret; | 590 | char *ret; |
605 | 591 | ||
606 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) | 592 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) |
607 | return NULL; /* persistence not requested */ | 593 | return NULL; /* persistence not requested */ |
608 | if (GNUNET_OK != | 594 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg, |
609 | GNUNET_CONFIGURATION_get_value_filename (h->cfg, "fs", "STATE_DIR", | 595 | "fs", |
610 | &basename)) | 596 | "STATE_DIR", |
597 | &basename)) | ||
611 | return NULL; | 598 | return NULL; |
612 | GNUNET_asprintf (&ret, "%s%s%s%s%s%s%s", basename, DIR_SEPARATOR_STR, | 599 | GNUNET_asprintf (&ret, |
613 | h->client_name, DIR_SEPARATOR_STR, ext, DIR_SEPARATOR_STR, | 600 | "%s%s%s%s%s%s%s", |
601 | basename, | ||
602 | DIR_SEPARATOR_STR, | ||
603 | h->client_name, | ||
604 | DIR_SEPARATOR_STR, | ||
605 | ext, | ||
606 | DIR_SEPARATOR_STR, | ||
614 | ent); | 607 | ent); |
615 | GNUNET_free (basename); | 608 | GNUNET_free (basename); |
616 | return ret; | 609 | return ret; |
@@ -638,14 +631,23 @@ get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, | |||
638 | char *ret; | 631 | char *ret; |
639 | 632 | ||
640 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) | 633 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) |
641 | return NULL; /* persistence not requested */ | 634 | return NULL; /* persistence not requested */ |
642 | if (GNUNET_OK != | 635 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (h->cfg, |
643 | GNUNET_CONFIGURATION_get_value_filename (h->cfg, "fs", "STATE_DIR", | 636 | "fs", |
644 | &basename)) | 637 | "STATE_DIR", |
638 | &basename)) | ||
645 | return NULL; | 639 | return NULL; |
646 | GNUNET_asprintf (&ret, "%s%s%s%s%s%s%s.dir%s%s", basename, DIR_SEPARATOR_STR, | 640 | GNUNET_asprintf (&ret, |
647 | h->client_name, DIR_SEPARATOR_STR, ext, DIR_SEPARATOR_STR, | 641 | "%s%s%s%s%s%s%s.dir%s%s", |
648 | uni, DIR_SEPARATOR_STR, ent); | 642 | basename, |
643 | DIR_SEPARATOR_STR, | ||
644 | h->client_name, | ||
645 | DIR_SEPARATOR_STR, | ||
646 | ext, | ||
647 | DIR_SEPARATOR_STR, | ||
648 | uni, | ||
649 | DIR_SEPARATOR_STR, | ||
650 | ent); | ||
649 | GNUNET_free (basename); | 651 | GNUNET_free (basename); |
650 | return ret; | 652 | return ret; |
651 | } | 653 | } |
@@ -660,9 +662,7 @@ get_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, | |||
660 | * @return NULL on error | 662 | * @return NULL on error |
661 | */ | 663 | */ |
662 | static struct GNUNET_BIO_ReadHandle * | 664 | static struct GNUNET_BIO_ReadHandle * |
663 | get_read_handle (struct GNUNET_FS_Handle *h, | 665 | get_read_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) |
664 | const char *ext, | ||
665 | const char *ent) | ||
666 | { | 666 | { |
667 | char *fn; | 667 | char *fn; |
668 | struct GNUNET_BIO_ReadHandle *ret; | 668 | struct GNUNET_BIO_ReadHandle *ret; |
@@ -685,9 +685,7 @@ get_read_handle (struct GNUNET_FS_Handle *h, | |||
685 | * @return NULL on error | 685 | * @return NULL on error |
686 | */ | 686 | */ |
687 | static struct GNUNET_BIO_WriteHandle * | 687 | static struct GNUNET_BIO_WriteHandle * |
688 | get_write_handle (struct GNUNET_FS_Handle *h, | 688 | get_write_handle (struct GNUNET_FS_Handle *h, const char *ext, const char *ent) |
689 | const char *ext, | ||
690 | const char *ent) | ||
691 | { | 689 | { |
692 | char *fn; | 690 | char *fn; |
693 | struct GNUNET_BIO_WriteHandle *ret; | 691 | struct GNUNET_BIO_WriteHandle *ret; |
@@ -712,8 +710,10 @@ get_write_handle (struct GNUNET_FS_Handle *h, | |||
712 | * @return NULL on error | 710 | * @return NULL on error |
713 | */ | 711 | */ |
714 | static struct GNUNET_BIO_WriteHandle * | 712 | static struct GNUNET_BIO_WriteHandle * |
715 | get_write_handle_in_dir (struct GNUNET_FS_Handle *h, const char *ext, | 713 | get_write_handle_in_dir (struct GNUNET_FS_Handle *h, |
716 | const char *uni, const char *ent) | 714 | const char *ext, |
715 | const char *uni, | ||
716 | const char *ent) | ||
717 | { | 717 | { |
718 | char *fn; | 718 | char *fn; |
719 | struct GNUNET_BIO_WriteHandle *ret; | 719 | struct GNUNET_BIO_WriteHandle *ret; |
@@ -749,8 +749,7 @@ GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, | |||
749 | filename = get_serialization_file_name (h, ext, ent); | 749 | filename = get_serialization_file_name (h, ext, ent); |
750 | if (NULL != filename) | 750 | if (NULL != filename) |
751 | { | 751 | { |
752 | if ( (0 != UNLINK (filename)) && | 752 | if ((0 != unlink (filename)) && (ENOENT != errno)) |
753 | (ENOENT != errno) ) | ||
754 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); | 753 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); |
755 | GNUNET_free (filename); | 754 | GNUNET_free (filename); |
756 | } | 755 | } |
@@ -768,7 +767,8 @@ GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, | |||
768 | static void | 767 | static void |
769 | remove_sync_file_in_dir (struct GNUNET_FS_Handle *h, | 768 | remove_sync_file_in_dir (struct GNUNET_FS_Handle *h, |
770 | const char *ext, | 769 | const char *ext, |
771 | const char *uni, const char *ent) | 770 | const char *uni, |
771 | const char *ent) | ||
772 | { | 772 | { |
773 | char *filename; | 773 | char *filename; |
774 | 774 | ||
@@ -780,7 +780,7 @@ remove_sync_file_in_dir (struct GNUNET_FS_Handle *h, | |||
780 | filename = get_serialization_file_name_in_dir (h, ext, uni, ent); | 780 | filename = get_serialization_file_name_in_dir (h, ext, uni, ent); |
781 | if (NULL == filename) | 781 | if (NULL == filename) |
782 | return; | 782 | return; |
783 | if (0 != UNLINK (filename)) | 783 | if (0 != unlink (filename)) |
784 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); | 784 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); |
785 | GNUNET_free (filename); | 785 | GNUNET_free (filename); |
786 | } | 786 | } |
@@ -874,8 +874,7 @@ read_start_time (struct GNUNET_BIO_ReadHandle *rh, | |||
874 | * @return NULL on error | 874 | * @return NULL on error |
875 | */ | 875 | */ |
876 | static struct GNUNET_FS_FileInformation * | 876 | static struct GNUNET_FS_FileInformation * |
877 | deserialize_file_information (struct GNUNET_FS_Handle *h, | 877 | deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename); |
878 | const char *filename); | ||
879 | 878 | ||
880 | 879 | ||
881 | /** | 880 | /** |
@@ -915,21 +914,22 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
915 | filename = NULL; | 914 | filename = NULL; |
916 | if ((GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) || | 915 | if ((GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "metadata", &ret->meta)) || |
917 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) || | 916 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "ksk-uri", &ksks, 32 * 1024)) || |
918 | ( (NULL != ksks) && | 917 | ((NULL != ksks) && |
919 | ( (NULL == (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) || | 918 | ((NULL == (ret->keywords = GNUNET_FS_uri_parse (ksks, NULL))) || |
920 | (GNUNET_YES != GNUNET_FS_uri_test_ksk (ret->keywords)) ) ) || | 919 | (GNUNET_YES != GNUNET_FS_uri_test_ksk (ret->keywords)))) || |
921 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) || | 920 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "chk-uri", &chks, 1024)) || |
922 | ( (NULL != chks) && | 921 | ((NULL != chks) && |
923 | ( (NULL == (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) || | 922 | ((NULL == (ret->chk_uri = GNUNET_FS_uri_parse (chks, NULL))) || |
924 | (GNUNET_YES != GNUNET_FS_uri_test_chk (ret->chk_uri))) ) || | 923 | (GNUNET_YES != GNUNET_FS_uri_test_chk (ret->chk_uri)))) || |
925 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "sks-uri", &skss, 1024)) || | 924 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "sks-uri", &skss, 1024)) || |
926 | ( (NULL != skss) && | 925 | ((NULL != skss) && |
927 | ( (NULL == (ret->sks_uri = GNUNET_FS_uri_parse (skss, NULL))) || | 926 | ((NULL == (ret->sks_uri = GNUNET_FS_uri_parse (skss, NULL))) || |
928 | (GNUNET_YES != GNUNET_FS_uri_test_sks (ret->sks_uri))) ) || | 927 | (GNUNET_YES != GNUNET_FS_uri_test_sks (ret->sks_uri)))) || |
929 | (GNUNET_OK != read_start_time (rh, &ret->start_time)) || | 928 | (GNUNET_OK != read_start_time (rh, &ret->start_time)) || |
930 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024)) | 929 | (GNUNET_OK != |
931 | || (GNUNET_OK != | 930 | GNUNET_BIO_read_string (rh, "emsg", &ret->emsg, 16 * 1024)) || |
932 | GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) || | 931 | (GNUNET_OK != |
932 | GNUNET_BIO_read_string (rh, "fn", &ret->filename, 16 * 1024)) || | ||
933 | (GNUNET_OK != | 933 | (GNUNET_OK != |
934 | GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value_us)) || | 934 | GNUNET_BIO_read_int64 (rh, &ret->bo.expiration_time.abs_value_us)) || |
935 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) || | 935 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &ret->bo.anonymity_level)) || |
@@ -941,7 +941,7 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
941 | } | 941 | } |
942 | switch (b) | 942 | switch (b) |
943 | { | 943 | { |
944 | case 0: /* file-insert */ | 944 | case 0: /* file-insert */ |
945 | if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) | 945 | if (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) |
946 | { | 946 | { |
947 | GNUNET_break (0); | 947 | GNUNET_break (0); |
@@ -957,12 +957,13 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
957 | { | 957 | { |
958 | ret->data.file.reader = &GNUNET_FS_data_reader_copy_; | 958 | ret->data.file.reader = &GNUNET_FS_data_reader_copy_; |
959 | ret->data.file.reader_cls = | 959 | ret->data.file.reader_cls = |
960 | GNUNET_malloc_large (ret->data.file.file_size); | 960 | GNUNET_malloc_large (ret->data.file.file_size); |
961 | if (ret->data.file.reader_cls == NULL) | 961 | if (ret->data.file.reader_cls == NULL) |
962 | goto cleanup; | 962 | goto cleanup; |
963 | if (GNUNET_OK != | 963 | if (GNUNET_OK != GNUNET_BIO_read (rh, |
964 | GNUNET_BIO_read (rh, "file-data", ret->data.file.reader_cls, | 964 | "file-data", |
965 | ret->data.file.file_size)) | 965 | ret->data.file.reader_cls, |
966 | ret->data.file.file_size)) | ||
966 | { | 967 | { |
967 | GNUNET_break (0); | 968 | GNUNET_break (0); |
968 | goto cleanup; | 969 | goto cleanup; |
@@ -972,11 +973,11 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
972 | { | 973 | { |
973 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; | 974 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; |
974 | ret->data.file.reader_cls = | 975 | ret->data.file.reader_cls = |
975 | GNUNET_FS_make_file_reader_context_ (ret->filename); | 976 | GNUNET_FS_make_file_reader_context_ (ret->filename); |
976 | } | 977 | } |
977 | } | 978 | } |
978 | break; | 979 | break; |
979 | case 1: /* file-index, no hash */ | 980 | case 1: /* file-index, no hash */ |
980 | if (NULL == ret->filename) | 981 | if (NULL == ret->filename) |
981 | { | 982 | { |
982 | GNUNET_break (0); | 983 | GNUNET_break (0); |
@@ -993,18 +994,19 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
993 | ret->data.file.index_start_confirmed = GNUNET_NO; | 994 | ret->data.file.index_start_confirmed = GNUNET_NO; |
994 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; | 995 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; |
995 | ret->data.file.reader_cls = | 996 | ret->data.file.reader_cls = |
996 | GNUNET_FS_make_file_reader_context_ (ret->filename); | 997 | GNUNET_FS_make_file_reader_context_ (ret->filename); |
997 | break; | 998 | break; |
998 | case 2: /* file-index-with-hash */ | 999 | case 2: /* file-index-with-hash */ |
999 | if (NULL == ret->filename) | 1000 | if (NULL == ret->filename) |
1000 | { | 1001 | { |
1001 | GNUNET_break (0); | 1002 | GNUNET_break (0); |
1002 | goto cleanup; | 1003 | goto cleanup; |
1003 | } | 1004 | } |
1004 | if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || | 1005 | if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || |
1005 | (GNUNET_OK != | 1006 | (GNUNET_OK != GNUNET_BIO_read (rh, |
1006 | GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, | 1007 | "fileid", |
1007 | sizeof (struct GNUNET_HashCode)))) | 1008 | &ret->data.file.file_id, |
1009 | sizeof (struct GNUNET_HashCode)))) | ||
1008 | { | 1010 | { |
1009 | GNUNET_break (0); | 1011 | GNUNET_break (0); |
1010 | goto cleanup; | 1012 | goto cleanup; |
@@ -1015,18 +1017,19 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
1015 | ret->data.file.index_start_confirmed = GNUNET_NO; | 1017 | ret->data.file.index_start_confirmed = GNUNET_NO; |
1016 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; | 1018 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; |
1017 | ret->data.file.reader_cls = | 1019 | ret->data.file.reader_cls = |
1018 | GNUNET_FS_make_file_reader_context_ (ret->filename); | 1020 | GNUNET_FS_make_file_reader_context_ (ret->filename); |
1019 | break; | 1021 | break; |
1020 | case 3: /* file-index-with-hash-confirmed */ | 1022 | case 3: /* file-index-with-hash-confirmed */ |
1021 | if (NULL == ret->filename) | 1023 | if (NULL == ret->filename) |
1022 | { | 1024 | { |
1023 | GNUNET_break (0); | 1025 | GNUNET_break (0); |
1024 | goto cleanup; | 1026 | goto cleanup; |
1025 | } | 1027 | } |
1026 | if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || | 1028 | if ((GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.file.file_size)) || |
1027 | (GNUNET_OK != | 1029 | (GNUNET_OK != GNUNET_BIO_read (rh, |
1028 | GNUNET_BIO_read (rh, "fileid", &ret->data.file.file_id, | 1030 | "fileid", |
1029 | sizeof (struct GNUNET_HashCode)))) | 1031 | &ret->data.file.file_id, |
1032 | sizeof (struct GNUNET_HashCode)))) | ||
1030 | { | 1033 | { |
1031 | GNUNET_break (0); | 1034 | GNUNET_break (0); |
1032 | goto cleanup; | 1035 | goto cleanup; |
@@ -1037,13 +1040,15 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h, | |||
1037 | ret->data.file.index_start_confirmed = GNUNET_YES; | 1040 | ret->data.file.index_start_confirmed = GNUNET_YES; |
1038 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; | 1041 | ret->data.file.reader = &GNUNET_FS_data_reader_file_; |
1039 | ret->data.file.reader_cls = | 1042 | ret->data.file.reader_cls = |
1040 | GNUNET_FS_make_file_reader_context_ (ret->filename); | 1043 | GNUNET_FS_make_file_reader_context_ (ret->filename); |
1041 | break; | 1044 | break; |
1042 | case 4: /* directory */ | 1045 | case 4: /* directory */ |
1043 | ret->is_directory = GNUNET_YES; | 1046 | ret->is_directory = GNUNET_YES; |
1044 | if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dsize)) || | 1047 | if ((GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dsize)) || |
1045 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_completed)) || | 1048 | (GNUNET_OK != |
1046 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_size)) || | 1049 | GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_completed)) || |
1050 | (GNUNET_OK != | ||
1051 | GNUNET_BIO_read_int64 (rh, &ret->data.dir.contents_size)) || | ||
1047 | (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) || | 1052 | (NULL == (ret->data.dir.dir_data = GNUNET_malloc_large (dsize))) || |
1048 | (GNUNET_OK != | 1053 | (GNUNET_OK != |
1049 | GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) || | 1054 | GNUNET_BIO_read (rh, "dir-data", ret->data.dir.dir_data, dsize)) || |
@@ -1108,8 +1113,7 @@ cleanup: | |||
1108 | * @return NULL on error | 1113 | * @return NULL on error |
1109 | */ | 1114 | */ |
1110 | static struct GNUNET_FS_FileInformation * | 1115 | static struct GNUNET_FS_FileInformation * |
1111 | deserialize_file_information (struct GNUNET_FS_Handle *h, | 1116 | deserialize_file_information (struct GNUNET_FS_Handle *h, const char *filename) |
1112 | const char *filename) | ||
1113 | { | 1117 | { |
1114 | struct GNUNET_FS_FileInformation *ret; | 1118 | struct GNUNET_FS_FileInformation *ret; |
1115 | struct GNUNET_BIO_ReadHandle *rh; | 1119 | struct GNUNET_BIO_ReadHandle *rh; |
@@ -1123,17 +1127,19 @@ deserialize_file_information (struct GNUNET_FS_Handle *h, | |||
1123 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 1127 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) |
1124 | { | 1128 | { |
1125 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1129 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1126 | _("Failed to resume publishing information `%s': %s\n"), | 1130 | _ ("Failed to resume publishing information `%s': %s\n"), |
1127 | filename, emsg); | 1131 | filename, |
1132 | emsg); | ||
1128 | GNUNET_free (emsg); | 1133 | GNUNET_free (emsg); |
1129 | } | 1134 | } |
1130 | if (NULL == ret) | 1135 | if (NULL == ret) |
1131 | { | 1136 | { |
1132 | fn = get_serialization_file_name (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename); | 1137 | fn = |
1138 | get_serialization_file_name (h, GNUNET_FS_SYNC_PATH_FILE_INFO, filename); | ||
1133 | if (NULL != fn) | 1139 | if (NULL != fn) |
1134 | { | 1140 | { |
1135 | if (0 != UNLINK (fn)) | 1141 | if (0 != unlink (fn)) |
1136 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 1142 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
1137 | GNUNET_free (fn); | 1143 | GNUNET_free (fn); |
1138 | } | 1144 | } |
1139 | } | 1145 | } |
@@ -1184,15 +1190,14 @@ get_serialization_short_name (const char *fullname) | |||
1184 | * @return NULL on errror | 1190 | * @return NULL on errror |
1185 | */ | 1191 | */ |
1186 | static char * | 1192 | static char * |
1187 | make_serialization_file_name (struct GNUNET_FS_Handle *h, | 1193 | make_serialization_file_name (struct GNUNET_FS_Handle *h, const char *ext) |
1188 | const char *ext) | ||
1189 | { | 1194 | { |
1190 | char *fn; | 1195 | char *fn; |
1191 | char *dn; | 1196 | char *dn; |
1192 | char *ret; | 1197 | char *ret; |
1193 | 1198 | ||
1194 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) | 1199 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) |
1195 | return NULL; /* persistence not requested */ | 1200 | return NULL; /* persistence not requested */ |
1196 | dn = get_serialization_file_name (h, ext, ""); | 1201 | dn = get_serialization_file_name (h, ext, ""); |
1197 | if (NULL == dn) | 1202 | if (NULL == dn) |
1198 | return NULL; | 1203 | return NULL; |
@@ -1204,7 +1209,7 @@ make_serialization_file_name (struct GNUNET_FS_Handle *h, | |||
1204 | fn = GNUNET_DISK_mktemp (dn); | 1209 | fn = GNUNET_DISK_mktemp (dn); |
1205 | GNUNET_free (dn); | 1210 | GNUNET_free (dn); |
1206 | if (NULL == fn) | 1211 | if (NULL == fn) |
1207 | return NULL; /* epic fail */ | 1212 | return NULL; /* epic fail */ |
1208 | ret = get_serialization_short_name (fn); | 1213 | ret = get_serialization_short_name (fn); |
1209 | GNUNET_free (fn); | 1214 | GNUNET_free (fn); |
1210 | return ret; | 1215 | return ret; |
@@ -1230,7 +1235,7 @@ make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, | |||
1230 | char *ret; | 1235 | char *ret; |
1231 | 1236 | ||
1232 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) | 1237 | if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) |
1233 | return NULL; /* persistence not requested */ | 1238 | return NULL; /* persistence not requested */ |
1234 | dn = get_serialization_file_name_in_dir (h, ext, uni, ""); | 1239 | dn = get_serialization_file_name_in_dir (h, ext, uni, ""); |
1235 | if (NULL == dn) | 1240 | if (NULL == dn) |
1236 | return NULL; | 1241 | return NULL; |
@@ -1242,7 +1247,7 @@ make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, | |||
1242 | fn = GNUNET_DISK_mktemp (dn); | 1247 | fn = GNUNET_DISK_mktemp (dn); |
1243 | GNUNET_free (dn); | 1248 | GNUNET_free (dn); |
1244 | if (NULL == fn) | 1249 | if (NULL == fn) |
1245 | return NULL; /* epic fail */ | 1250 | return NULL; /* epic fail */ |
1246 | ret = get_serialization_short_name (fn); | 1251 | ret = get_serialization_short_name (fn); |
1247 | GNUNET_free (fn); | 1252 | GNUNET_free (fn); |
1248 | return ret; | 1253 | return ret; |
@@ -1272,7 +1277,7 @@ copy_from_reader (struct GNUNET_BIO_WriteHandle *wh, | |||
1272 | { | 1277 | { |
1273 | left = GNUNET_MIN (sizeof (buf), fi->data.file.file_size - off); | 1278 | left = GNUNET_MIN (sizeof (buf), fi->data.file.file_size - off); |
1274 | ret = | 1279 | ret = |
1275 | fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg); | 1280 | fi->data.file.reader (fi->data.file.reader_cls, off, left, buf, &emsg); |
1276 | if (0 == ret) | 1281 | if (0 == ret) |
1277 | { | 1282 | { |
1278 | GNUNET_free (emsg); | 1283 | GNUNET_free (emsg); |
@@ -1304,11 +1309,11 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1304 | 1309 | ||
1305 | if (NULL == fi->serialization) | 1310 | if (NULL == fi->serialization) |
1306 | fi->serialization = | 1311 | fi->serialization = |
1307 | make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO); | 1312 | make_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO); |
1308 | if (NULL == fi->serialization) | 1313 | if (NULL == fi->serialization) |
1309 | return; | 1314 | return; |
1310 | wh = get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, | 1315 | wh = |
1311 | fi->serialization); | 1316 | get_write_handle (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization); |
1312 | if (NULL == wh) | 1317 | if (NULL == wh) |
1313 | { | 1318 | { |
1314 | GNUNET_free (fi->serialization); | 1319 | GNUNET_free (fi->serialization); |
@@ -1363,7 +1368,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1363 | 1368 | ||
1364 | switch (b) | 1369 | switch (b) |
1365 | { | 1370 | { |
1366 | case 0: /* file-insert */ | 1371 | case 0: /* file-insert */ |
1367 | if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) | 1372 | if (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) |
1368 | { | 1373 | { |
1369 | GNUNET_break (0); | 1374 | GNUNET_break (0); |
@@ -1376,7 +1381,7 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1376 | goto cleanup; | 1381 | goto cleanup; |
1377 | } | 1382 | } |
1378 | break; | 1383 | break; |
1379 | case 1: /* file-index, no hash */ | 1384 | case 1: /* file-index, no hash */ |
1380 | if (NULL == fi->filename) | 1385 | if (NULL == fi->filename) |
1381 | { | 1386 | { |
1382 | GNUNET_break (0); | 1387 | GNUNET_break (0); |
@@ -1388,37 +1393,39 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1388 | goto cleanup; | 1393 | goto cleanup; |
1389 | } | 1394 | } |
1390 | break; | 1395 | break; |
1391 | case 2: /* file-index-with-hash */ | 1396 | case 2: /* file-index-with-hash */ |
1392 | case 3: /* file-index-with-hash-confirmed */ | 1397 | case 3: /* file-index-with-hash-confirmed */ |
1393 | if (NULL == fi->filename) | 1398 | if (NULL == fi->filename) |
1394 | { | 1399 | { |
1395 | GNUNET_break (0); | 1400 | GNUNET_break (0); |
1396 | goto cleanup; | 1401 | goto cleanup; |
1397 | } | 1402 | } |
1398 | if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) || | 1403 | if ((GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.file.file_size)) || |
1399 | (GNUNET_OK != | 1404 | (GNUNET_OK != GNUNET_BIO_write (wh, |
1400 | GNUNET_BIO_write (wh, &fi->data.file.file_id, | 1405 | &fi->data.file.file_id, |
1401 | sizeof (struct GNUNET_HashCode)))) | 1406 | sizeof (struct GNUNET_HashCode)))) |
1402 | { | 1407 | { |
1403 | GNUNET_break (0); | 1408 | GNUNET_break (0); |
1404 | goto cleanup; | 1409 | goto cleanup; |
1405 | } | 1410 | } |
1406 | break; | 1411 | break; |
1407 | case 4: /* directory */ | 1412 | case 4: /* directory */ |
1408 | if ( (NULL != fi->data.dir.entries) && | 1413 | if ((NULL != fi->data.dir.entries) && |
1409 | (NULL == fi->data.dir.entries->serialization) ) | 1414 | (NULL == fi->data.dir.entries->serialization)) |
1410 | GNUNET_FS_file_information_sync_ (fi->data.dir.entries); | 1415 | GNUNET_FS_file_information_sync_ (fi->data.dir.entries); |
1411 | if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) || | 1416 | if ((GNUNET_OK != GNUNET_BIO_write_int32 (wh, fi->data.dir.dir_size)) || |
1412 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_completed)) || | ||
1413 | (GNUNET_OK != GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_size)) || | ||
1414 | (GNUNET_OK != | 1417 | (GNUNET_OK != |
1415 | GNUNET_BIO_write (wh, fi->data.dir.dir_data, | 1418 | GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_completed)) || |
1416 | (uint32_t) fi->data.dir.dir_size)) || | 1419 | (GNUNET_OK != |
1420 | GNUNET_BIO_write_int64 (wh, fi->data.dir.contents_size)) || | ||
1421 | (GNUNET_OK != GNUNET_BIO_write (wh, | ||
1422 | fi->data.dir.dir_data, | ||
1423 | (uint32_t) fi->data.dir.dir_size)) || | ||
1417 | (GNUNET_OK != | 1424 | (GNUNET_OK != |
1418 | GNUNET_BIO_write_string (wh, | 1425 | GNUNET_BIO_write_string (wh, |
1419 | (fi->data.dir.entries == | 1426 | (fi->data.dir.entries == NULL) |
1420 | NULL) ? NULL : fi->data.dir. | 1427 | ? NULL |
1421 | entries->serialization))) | 1428 | : fi->data.dir.entries->serialization))) |
1422 | { | 1429 | { |
1423 | GNUNET_break (0); | 1430 | GNUNET_break (0); |
1424 | goto cleanup; | 1431 | goto cleanup; |
@@ -1428,13 +1435,12 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1428 | GNUNET_assert (0); | 1435 | GNUNET_assert (0); |
1429 | goto cleanup; | 1436 | goto cleanup; |
1430 | } | 1437 | } |
1431 | if ( (NULL != fi->next) && | 1438 | if ((NULL != fi->next) && (NULL == fi->next->serialization)) |
1432 | (NULL == fi->next->serialization) ) | ||
1433 | GNUNET_FS_file_information_sync_ (fi->next); | 1439 | GNUNET_FS_file_information_sync_ (fi->next); |
1434 | if (GNUNET_OK != | 1440 | if (GNUNET_OK != GNUNET_BIO_write_string (wh, |
1435 | GNUNET_BIO_write_string (wh, | 1441 | (fi->next != NULL) |
1436 | (fi->next != | 1442 | ? fi->next->serialization |
1437 | NULL) ? fi->next->serialization : NULL)) | 1443 | : NULL)) |
1438 | { | 1444 | { |
1439 | GNUNET_break (0); | 1445 | GNUNET_break (0); |
1440 | goto cleanup; | 1446 | goto cleanup; |
@@ -1445,18 +1451,19 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation *fi) | |||
1445 | GNUNET_break (0); | 1451 | GNUNET_break (0); |
1446 | goto cleanup; | 1452 | goto cleanup; |
1447 | } | 1453 | } |
1448 | return; /* done! */ | 1454 | return; /* done! */ |
1449 | cleanup: | 1455 | cleanup: |
1450 | if (NULL != wh) | 1456 | if (NULL != wh) |
1451 | (void) GNUNET_BIO_write_close (wh); | 1457 | (void) GNUNET_BIO_write_close (wh); |
1452 | GNUNET_free_non_null (chks); | 1458 | GNUNET_free_non_null (chks); |
1453 | GNUNET_free_non_null (ksks); | 1459 | GNUNET_free_non_null (ksks); |
1454 | GNUNET_free_non_null (skss); | 1460 | GNUNET_free_non_null (skss); |
1455 | fn = get_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, | 1461 | fn = get_serialization_file_name (fi->h, |
1462 | GNUNET_FS_SYNC_PATH_FILE_INFO, | ||
1456 | fi->serialization); | 1463 | fi->serialization); |
1457 | if (NULL != fn) | 1464 | if (NULL != fn) |
1458 | { | 1465 | { |
1459 | if (0 != UNLINK (fn)) | 1466 | if (0 != unlink (fn)) |
1460 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 1467 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
1461 | GNUNET_free (fn); | 1468 | GNUNET_free (fn); |
1462 | } | 1469 | } |
@@ -1465,7 +1472,6 @@ cleanup: | |||
1465 | } | 1472 | } |
1466 | 1473 | ||
1467 | 1474 | ||
1468 | |||
1469 | /** | 1475 | /** |
1470 | * Find the entry in the file information struct where the | 1476 | * Find the entry in the file information struct where the |
1471 | * serialization filename matches the given name. | 1477 | * serialization filename matches the given name. |
@@ -1475,8 +1481,7 @@ cleanup: | |||
1475 | * @return NULL if srch was not found in this subtree | 1481 | * @return NULL if srch was not found in this subtree |
1476 | */ | 1482 | */ |
1477 | static struct GNUNET_FS_FileInformation * | 1483 | static struct GNUNET_FS_FileInformation * |
1478 | find_file_position (struct GNUNET_FS_FileInformation *pos, | 1484 | find_file_position (struct GNUNET_FS_FileInformation *pos, const char *srch) |
1479 | const char *srch) | ||
1480 | { | 1485 | { |
1481 | struct GNUNET_FS_FileInformation *r; | 1486 | struct GNUNET_FS_FileInformation *r; |
1482 | 1487 | ||
@@ -1484,8 +1489,8 @@ find_file_position (struct GNUNET_FS_FileInformation *pos, | |||
1484 | { | 1489 | { |
1485 | if (0 == strcmp (srch, pos->serialization)) | 1490 | if (0 == strcmp (srch, pos->serialization)) |
1486 | return pos; | 1491 | return pos; |
1487 | if ( (GNUNET_YES == pos->is_directory) && | 1492 | if ((GNUNET_YES == pos->is_directory) && |
1488 | (NULL != (r = find_file_position (pos->data.dir.entries, srch))) ) | 1493 | (NULL != (r = find_file_position (pos->data.dir.entries, srch)))) |
1489 | return r; | 1494 | return r; |
1490 | pos = pos->next; | 1495 | pos = pos->next; |
1491 | } | 1496 | } |
@@ -1548,8 +1553,7 @@ fip_signal_resume (void *cls, | |||
1548 | * @return #GNUNET_OK (continue to iterate) | 1553 | * @return #GNUNET_OK (continue to iterate) |
1549 | */ | 1554 | */ |
1550 | static int | 1555 | static int |
1551 | deserialize_publish_file (void *cls, | 1556 | deserialize_publish_file (void *cls, const char *filename) |
1552 | const char *filename) | ||
1553 | { | 1557 | { |
1554 | struct GNUNET_FS_Handle *h = cls; | 1558 | struct GNUNET_FS_Handle *h = cls; |
1555 | struct GNUNET_BIO_ReadHandle *rh; | 1559 | struct GNUNET_BIO_ReadHandle *rh; |
@@ -1573,17 +1577,19 @@ deserialize_publish_file (void *cls, | |||
1573 | GNUNET_break (0); | 1577 | GNUNET_break (0); |
1574 | goto cleanup; | 1578 | goto cleanup; |
1575 | } | 1579 | } |
1576 | if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) | 1580 | if ((GNUNET_OK != |
1577 | || (GNUNET_OK != | 1581 | GNUNET_BIO_read_string (rh, "publish-nid", &pc->nid, 1024)) || |
1578 | GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) || | 1582 | (GNUNET_OK != |
1583 | GNUNET_BIO_read_string (rh, "publish-nuid", &pc->nuid, 1024)) || | ||
1579 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || | 1584 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &options)) || |
1580 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &all_done)) || | 1585 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &all_done)) || |
1581 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &have_ns)) || | 1586 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &have_ns)) || |
1582 | (GNUNET_OK != | 1587 | (GNUNET_OK != |
1583 | GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) || | 1588 | GNUNET_BIO_read_string (rh, "publish-firoot", &fi_root, 128)) || |
1584 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) | 1589 | (GNUNET_OK != |
1585 | || ( (GNUNET_YES == have_ns) && | 1590 | GNUNET_BIO_read_string (rh, "publish-fipos", &fi_pos, 128)) || |
1586 | (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof (ns)))) ) | 1591 | ((GNUNET_YES == have_ns) && |
1592 | (GNUNET_OK != GNUNET_BIO_read (rh, "publish-ns", &ns, sizeof (ns))))) | ||
1587 | { | 1593 | { |
1588 | GNUNET_break (0); | 1594 | GNUNET_break (0); |
1589 | goto cleanup; | 1595 | goto cleanup; |
@@ -1636,20 +1642,19 @@ deserialize_publish_file (void *cls, | |||
1636 | { | 1642 | { |
1637 | GNUNET_assert (NULL == pc->upload_task); | 1643 | GNUNET_assert (NULL == pc->upload_task); |
1638 | pc->upload_task = | 1644 | pc->upload_task = |
1639 | GNUNET_SCHEDULER_add_with_priority | 1645 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
1640 | (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 1646 | &GNUNET_FS_publish_main_, |
1641 | &GNUNET_FS_publish_main_, pc); | 1647 | pc); |
1642 | } | 1648 | } |
1643 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 1649 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) |
1644 | { | 1650 | { |
1645 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1651 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1646 | _("Failure while resuming publishing operation `%s': %s\n"), | 1652 | _ ("Failure while resuming publishing operation `%s': %s\n"), |
1647 | filename, emsg); | 1653 | filename, |
1654 | emsg); | ||
1648 | GNUNET_free (emsg); | 1655 | GNUNET_free (emsg); |
1649 | } | 1656 | } |
1650 | pc->top = GNUNET_FS_make_top (h, | 1657 | pc->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, pc); |
1651 | &GNUNET_FS_publish_signal_suspend_, | ||
1652 | pc); | ||
1653 | return GNUNET_OK; | 1658 | return GNUNET_OK; |
1654 | cleanup: | 1659 | cleanup: |
1655 | GNUNET_free_non_null (pc->nid); | 1660 | GNUNET_free_non_null (pc->nid); |
@@ -1659,13 +1664,14 @@ cleanup: | |||
1659 | if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))) | 1664 | if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))) |
1660 | { | 1665 | { |
1661 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1666 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1662 | _("Failed to resume publishing operation `%s': %s\n"), filename, | 1667 | _ ("Failed to resume publishing operation `%s': %s\n"), |
1668 | filename, | ||
1663 | emsg); | 1669 | emsg); |
1664 | GNUNET_free (emsg); | 1670 | GNUNET_free (emsg); |
1665 | } | 1671 | } |
1666 | if (NULL != pc->fi) | 1672 | if (NULL != pc->fi) |
1667 | GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL); | 1673 | GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL); |
1668 | if (0 != UNLINK (filename)) | 1674 | if (0 != unlink (filename)) |
1669 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); | 1675 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); |
1670 | GNUNET_free (pc->serialization); | 1676 | GNUNET_free (pc->serialization); |
1671 | GNUNET_free (pc); | 1677 | GNUNET_free (pc); |
@@ -1689,8 +1695,7 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) | |||
1689 | 1695 | ||
1690 | if (NULL == pc->serialization) | 1696 | if (NULL == pc->serialization) |
1691 | pc->serialization = | 1697 | pc->serialization = |
1692 | make_serialization_file_name (pc->h, | 1698 | make_serialization_file_name (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH); |
1693 | GNUNET_FS_SYNC_PATH_MASTER_PUBLISH); | ||
1694 | if (NULL == pc->serialization) | 1699 | if (NULL == pc->serialization) |
1695 | return; | 1700 | return; |
1696 | if (NULL == pc->fi) | 1701 | if (NULL == pc->fi) |
@@ -1700,7 +1705,8 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) | |||
1700 | GNUNET_break (0); | 1705 | GNUNET_break (0); |
1701 | return; | 1706 | return; |
1702 | } | 1707 | } |
1703 | wh = get_write_handle (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | 1708 | wh = get_write_handle (pc->h, |
1709 | GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | ||
1704 | pc->serialization); | 1710 | pc->serialization); |
1705 | if (NULL == wh) | 1711 | if (NULL == wh) |
1706 | { | 1712 | { |
@@ -1714,13 +1720,15 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) | |||
1714 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->all_done)) || | 1720 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pc->all_done)) || |
1715 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, have_ns)) || | 1721 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, have_ns)) || |
1716 | (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->fi->serialization)) || | 1722 | (GNUNET_OK != GNUNET_BIO_write_string (wh, pc->fi->serialization)) || |
1717 | (GNUNET_OK != | 1723 | (GNUNET_OK != GNUNET_BIO_write_string (wh, |
1718 | GNUNET_BIO_write_string (wh, | 1724 | (NULL == pc->fi_pos) |
1719 | (NULL == pc->fi_pos) ? NULL : pc->fi_pos->serialization)) || | 1725 | ? NULL |
1720 | ( (NULL != pc->ns) && | 1726 | : pc->fi_pos->serialization)) || |
1721 | (GNUNET_OK != GNUNET_BIO_write (wh, | 1727 | ((NULL != pc->ns) && |
1722 | pc->ns, | 1728 | (GNUNET_OK != |
1723 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)) ) )) | 1729 | GNUNET_BIO_write (wh, |
1730 | pc->ns, | ||
1731 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))))) | ||
1724 | { | 1732 | { |
1725 | GNUNET_break (0); | 1733 | GNUNET_break (0); |
1726 | goto cleanup; | 1734 | goto cleanup; |
@@ -1735,7 +1743,8 @@ GNUNET_FS_publish_sync_ (struct GNUNET_FS_PublishContext *pc) | |||
1735 | cleanup: | 1743 | cleanup: |
1736 | if (NULL != wh) | 1744 | if (NULL != wh) |
1737 | (void) GNUNET_BIO_write_close (wh); | 1745 | (void) GNUNET_BIO_write_close (wh); |
1738 | GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | 1746 | GNUNET_FS_remove_sync_file_ (pc->h, |
1747 | GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | ||
1739 | pc->serialization); | 1748 | pc->serialization); |
1740 | GNUNET_free (pc->serialization); | 1749 | GNUNET_free (pc->serialization); |
1741 | pc->serialization = NULL; | 1750 | pc->serialization = NULL; |
@@ -1758,11 +1767,11 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc) | |||
1758 | 1767 | ||
1759 | if (NULL == uc->serialization) | 1768 | if (NULL == uc->serialization) |
1760 | uc->serialization = | 1769 | uc->serialization = |
1761 | make_serialization_file_name (uc->h, | 1770 | make_serialization_file_name (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX); |
1762 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX); | ||
1763 | if (NULL == uc->serialization) | 1771 | if (NULL == uc->serialization) |
1764 | return; | 1772 | return; |
1765 | wh = get_write_handle (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 1773 | wh = get_write_handle (uc->h, |
1774 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | ||
1766 | uc->serialization); | 1775 | uc->serialization); |
1767 | if (NULL == wh) | 1776 | if (NULL == wh) |
1768 | { | 1777 | { |
@@ -1782,8 +1791,9 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc) | |||
1782 | (GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || | 1791 | (GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || |
1783 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->ksk_offset)) || | 1792 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, (uint32_t) uc->ksk_offset)) || |
1784 | ((uc->state == UNINDEX_STATE_FS_NOTIFY) && | 1793 | ((uc->state == UNINDEX_STATE_FS_NOTIFY) && |
1785 | (GNUNET_OK != | 1794 | (GNUNET_OK != GNUNET_BIO_write (wh, |
1786 | GNUNET_BIO_write (wh, &uc->file_id, sizeof (struct GNUNET_HashCode)))) || | 1795 | &uc->file_id, |
1796 | sizeof (struct GNUNET_HashCode)))) || | ||
1787 | ((uc->state == UNINDEX_STATE_ERROR) && | 1797 | ((uc->state == UNINDEX_STATE_ERROR) && |
1788 | (GNUNET_OK != GNUNET_BIO_write_string (wh, uc->emsg)))) | 1798 | (GNUNET_OK != GNUNET_BIO_write_string (wh, uc->emsg)))) |
1789 | { | 1799 | { |
@@ -1800,7 +1810,8 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc) | |||
1800 | cleanup: | 1810 | cleanup: |
1801 | if (NULL != wh) | 1811 | if (NULL != wh) |
1802 | (void) GNUNET_BIO_write_close (wh); | 1812 | (void) GNUNET_BIO_write_close (wh); |
1803 | GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 1813 | GNUNET_FS_remove_sync_file_ (uc->h, |
1814 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | ||
1804 | uc->serialization); | 1815 | uc->serialization); |
1805 | GNUNET_free (uc->serialization); | 1816 | GNUNET_free (uc->serialization); |
1806 | uc->serialization = NULL; | 1817 | uc->serialization = NULL; |
@@ -1854,8 +1865,7 @@ read_download_request (struct GNUNET_BIO_ReadHandle *rh) | |||
1854 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->num_children)) || | 1865 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->num_children)) || |
1855 | (dr->num_children > CHK_PER_INODE) || | 1866 | (dr->num_children > CHK_PER_INODE) || |
1856 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->depth)) || | 1867 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &dr->depth)) || |
1857 | ( (0 == dr->depth) && | 1868 | ((0 == dr->depth) && (dr->num_children > 0)) || |
1858 | (dr->num_children > 0) ) || | ||
1859 | ((dr->depth > 0) && (0 == dr->num_children))) | 1869 | ((dr->depth > 0) && (0 == dr->num_children))) |
1860 | { | 1870 | { |
1861 | GNUNET_break (0); | 1871 | GNUNET_break (0); |
@@ -1864,7 +1874,7 @@ read_download_request (struct GNUNET_BIO_ReadHandle *rh) | |||
1864 | } | 1874 | } |
1865 | if (dr->num_children > 0) | 1875 | if (dr->num_children > 0) |
1866 | dr->children = | 1876 | dr->children = |
1867 | GNUNET_malloc (dr->num_children * sizeof (struct DownloadRequest *)); | 1877 | GNUNET_malloc (dr->num_children * sizeof (struct DownloadRequest *)); |
1868 | switch (dr->state) | 1878 | switch (dr->state) |
1869 | { | 1879 | { |
1870 | case BRS_INIT: | 1880 | case BRS_INIT: |
@@ -1917,9 +1927,9 @@ get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc, | |||
1917 | 1927 | ||
1918 | if (dc->parent == NULL) | 1928 | if (dc->parent == NULL) |
1919 | return get_serialization_file_name (dc->h, | 1929 | return get_serialization_file_name (dc->h, |
1920 | (dc->search != NULL) ? | 1930 | (dc->search != NULL) |
1921 | GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD : | 1931 | ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD |
1922 | GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, | 1932 | : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, |
1923 | uni); | 1933 | uni); |
1924 | if (NULL == dc->parent->serialization) | 1934 | if (NULL == dc->parent->serialization) |
1925 | return NULL; | 1935 | return NULL; |
@@ -2028,7 +2038,7 @@ cleanup: | |||
2028 | if (NULL != wh) | 2038 | if (NULL != wh) |
2029 | (void) GNUNET_BIO_write_close (wh); | 2039 | (void) GNUNET_BIO_write_close (wh); |
2030 | GNUNET_free_non_null (uris); | 2040 | GNUNET_free_non_null (uris); |
2031 | if (0 != UNLINK (fn)) | 2041 | if (0 != unlink (fn)) |
2032 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 2042 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
2033 | GNUNET_free (fn); | 2043 | GNUNET_free (fn); |
2034 | GNUNET_free (dc->serialization); | 2044 | GNUNET_free (dc->serialization); |
@@ -2055,19 +2065,19 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr) | |||
2055 | uris = NULL; | 2065 | uris = NULL; |
2056 | if (NULL == sr->serialization) | 2066 | if (NULL == sr->serialization) |
2057 | sr->serialization = | 2067 | sr->serialization = |
2058 | make_serialization_file_name_in_dir (sr->h, | 2068 | make_serialization_file_name_in_dir (sr->h, |
2059 | (sr->sc->psearch_result == | 2069 | (sr->sc->psearch_result == NULL) |
2060 | NULL) ? | 2070 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2061 | GNUNET_FS_SYNC_PATH_MASTER_SEARCH : | 2071 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2062 | GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2072 | sr->sc->serialization); |
2063 | sr->sc->serialization); | ||
2064 | if (NULL == sr->serialization) | 2073 | if (NULL == sr->serialization) |
2065 | return; | 2074 | return; |
2066 | wh = get_write_handle_in_dir (sr->h, | 2075 | wh = get_write_handle_in_dir (sr->h, |
2067 | (sr->sc->psearch_result == | 2076 | (sr->sc->psearch_result == NULL) |
2068 | NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH : | 2077 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2069 | GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2078 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2070 | sr->sc->serialization, sr->serialization); | 2079 | sr->sc->serialization, |
2080 | sr->serialization); | ||
2071 | if (NULL == wh) | 2081 | if (NULL == wh) |
2072 | { | 2082 | { |
2073 | GNUNET_break (0); | 2083 | GNUNET_break (0); |
@@ -2075,28 +2085,31 @@ GNUNET_FS_search_result_sync_ (struct GNUNET_FS_SearchResult *sr) | |||
2075 | } | 2085 | } |
2076 | uris = GNUNET_FS_uri_to_string (sr->uri); | 2086 | uris = GNUNET_FS_uri_to_string (sr->uri); |
2077 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || | 2087 | if ((GNUNET_OK != GNUNET_BIO_write_string (wh, uris)) || |
2088 | (GNUNET_OK != GNUNET_BIO_write_string (wh, | ||
2089 | sr->download != NULL | ||
2090 | ? sr->download->serialization | ||
2091 | : NULL)) || | ||
2078 | (GNUNET_OK != | 2092 | (GNUNET_OK != |
2079 | GNUNET_BIO_write_string (wh, | 2093 | GNUNET_BIO_write_string (wh, |
2080 | sr->download != | 2094 | sr->update_search != NULL |
2081 | NULL ? sr->download->serialization : NULL)) || | 2095 | ? sr->update_search->serialization |
2096 | : NULL)) || | ||
2097 | (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) || | ||
2082 | (GNUNET_OK != | 2098 | (GNUNET_OK != |
2083 | GNUNET_BIO_write_string (wh, | 2099 | GNUNET_BIO_write (wh, &sr->key, sizeof (struct GNUNET_HashCode))) || |
2084 | sr->update_search != | 2100 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) || |
2085 | NULL ? sr->update_search->serialization : NULL)) | ||
2086 | || (GNUNET_OK != GNUNET_BIO_write_meta_data (wh, sr->meta)) || | ||
2087 | (GNUNET_OK != GNUNET_BIO_write (wh, &sr->key, sizeof (struct GNUNET_HashCode))) | ||
2088 | || (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) || | ||
2089 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->optional_support)) || | 2101 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->optional_support)) || |
2090 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_success)) || | 2102 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_success)) || |
2091 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_trials)) ) | 2103 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, sr->availability_trials))) |
2092 | { | 2104 | { |
2093 | GNUNET_break (0); | 2105 | GNUNET_break (0); |
2094 | goto cleanup; | 2106 | goto cleanup; |
2095 | } | 2107 | } |
2096 | if ( (NULL != sr->uri) && | 2108 | if ((NULL != sr->uri) && (GNUNET_FS_URI_KSK == sr->sc->uri->type) && |
2097 | (GNUNET_FS_URI_KSK == sr->sc->uri->type) && | 2109 | (GNUNET_OK != |
2098 | (GNUNET_OK != GNUNET_BIO_write (wh, sr->keyword_bitmap, | 2110 | GNUNET_BIO_write (wh, |
2099 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8)) ) | 2111 | sr->keyword_bitmap, |
2112 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8))) | ||
2100 | { | 2113 | { |
2101 | GNUNET_break (0); | 2114 | GNUNET_break (0); |
2102 | goto cleanup; | 2115 | goto cleanup; |
@@ -2115,9 +2128,10 @@ cleanup: | |||
2115 | (void) GNUNET_BIO_write_close (wh); | 2128 | (void) GNUNET_BIO_write_close (wh); |
2116 | remove_sync_file_in_dir (sr->h, | 2129 | remove_sync_file_in_dir (sr->h, |
2117 | (NULL == sr->sc->psearch_result) | 2130 | (NULL == sr->sc->psearch_result) |
2118 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | 2131 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2119 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2132 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2120 | sr->sc->serialization, sr->serialization); | 2133 | sr->sc->serialization, |
2134 | sr->serialization); | ||
2121 | GNUNET_free (sr->serialization); | 2135 | GNUNET_free (sr->serialization); |
2122 | sr->serialization = NULL; | 2136 | sr->serialization = NULL; |
2123 | } | 2137 | } |
@@ -2139,10 +2153,8 @@ GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc) | |||
2139 | char in_pause; | 2153 | char in_pause; |
2140 | const char *category; | 2154 | const char *category; |
2141 | 2155 | ||
2142 | category = | 2156 | category = (NULL == sc->psearch_result) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2143 | (NULL == sc->psearch_result) | 2157 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH; |
2144 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | ||
2145 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH; | ||
2146 | if (NULL == sc->serialization) | 2158 | if (NULL == sc->serialization) |
2147 | sc->serialization = make_serialization_file_name (sc->h, category); | 2159 | sc->serialization = make_serialization_file_name (sc->h, category); |
2148 | if (NULL == sc->serialization) | 2160 | if (NULL == sc->serialization) |
@@ -2196,8 +2208,7 @@ cleanup: | |||
2196 | * @return #GNUNET_OK (continue to iterate) | 2208 | * @return #GNUNET_OK (continue to iterate) |
2197 | */ | 2209 | */ |
2198 | static int | 2210 | static int |
2199 | deserialize_unindex_file (void *cls, | 2211 | deserialize_unindex_file (void *cls, const char *filename) |
2200 | const char *filename) | ||
2201 | { | 2212 | { |
2202 | struct GNUNET_FS_Handle *h = cls; | 2213 | struct GNUNET_FS_Handle *h = cls; |
2203 | struct GNUNET_BIO_ReadHandle *rh; | 2214 | struct GNUNET_BIO_ReadHandle *rh; |
@@ -2222,9 +2233,11 @@ deserialize_unindex_file (void *cls, | |||
2222 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &uc->file_size)) || | 2233 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &uc->file_size)) || |
2223 | (GNUNET_OK != read_start_time (rh, &uc->start_time)) || | 2234 | (GNUNET_OK != read_start_time (rh, &uc->start_time)) || |
2224 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)) || | 2235 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &state)) || |
2225 | (GNUNET_OK != GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof (struct ContentHashKey))) || | 2236 | (GNUNET_OK != |
2226 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) || | 2237 | GNUNET_BIO_read (rh, "uri", &uc->chk, sizeof (struct ContentHashKey))) || |
2227 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset)) ) | 2238 | (GNUNET_OK != |
2239 | GNUNET_BIO_read_string (rh, "unindex-kskuri", &uris, 10 * 1024)) || | ||
2240 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &uc->ksk_offset))) | ||
2228 | { | 2241 | { |
2229 | GNUNET_free_non_null (uris); | 2242 | GNUNET_free_non_null (uris); |
2230 | GNUNET_break (0); | 2243 | GNUNET_break (0); |
@@ -2241,9 +2254,9 @@ deserialize_unindex_file (void *cls, | |||
2241 | goto cleanup; | 2254 | goto cleanup; |
2242 | } | 2255 | } |
2243 | } | 2256 | } |
2244 | if ( (uc->ksk_offset > 0) && | 2257 | if ((uc->ksk_offset > 0) && |
2245 | ( (NULL == uc->ksk_uri) || | 2258 | ((NULL == uc->ksk_uri) || |
2246 | (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount) ) ) | 2259 | (uc->ksk_offset > uc->ksk_uri->data.ksk.keywordCount))) |
2247 | { | 2260 | { |
2248 | GNUNET_break (0); | 2261 | GNUNET_break (0); |
2249 | goto cleanup; | 2262 | goto cleanup; |
@@ -2254,9 +2267,10 @@ deserialize_unindex_file (void *cls, | |||
2254 | case UNINDEX_STATE_HASHING: | 2267 | case UNINDEX_STATE_HASHING: |
2255 | break; | 2268 | break; |
2256 | case UNINDEX_STATE_FS_NOTIFY: | 2269 | case UNINDEX_STATE_FS_NOTIFY: |
2257 | if (GNUNET_OK != | 2270 | if (GNUNET_OK != GNUNET_BIO_read (rh, |
2258 | GNUNET_BIO_read (rh, "unindex-hash", &uc->file_id, | 2271 | "unindex-hash", |
2259 | sizeof (struct GNUNET_HashCode))) | 2272 | &uc->file_id, |
2273 | sizeof (struct GNUNET_HashCode))) | ||
2260 | { | 2274 | { |
2261 | GNUNET_break (0); | 2275 | GNUNET_break (0); |
2262 | goto cleanup; | 2276 | goto cleanup; |
@@ -2280,21 +2294,22 @@ deserialize_unindex_file (void *cls, | |||
2280 | GNUNET_break (0); | 2294 | GNUNET_break (0); |
2281 | goto cleanup; | 2295 | goto cleanup; |
2282 | } | 2296 | } |
2283 | uc->top = GNUNET_FS_make_top (h, | 2297 | uc->top = GNUNET_FS_make_top (h, &GNUNET_FS_unindex_signal_suspend_, uc); |
2284 | &GNUNET_FS_unindex_signal_suspend_, | ||
2285 | uc); | ||
2286 | pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME; | 2298 | pi.status = GNUNET_FS_STATUS_UNINDEX_RESUME; |
2287 | pi.value.unindex.specifics.resume.message = uc->emsg; | 2299 | pi.value.unindex.specifics.resume.message = uc->emsg; |
2288 | GNUNET_FS_unindex_make_status_ (&pi, uc, | 2300 | GNUNET_FS_unindex_make_status_ (&pi, |
2289 | (uc->state == | 2301 | uc, |
2290 | UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); | 2302 | (uc->state == UNINDEX_STATE_COMPLETE) |
2303 | ? uc->file_size | ||
2304 | : 0); | ||
2291 | switch (uc->state) | 2305 | switch (uc->state) |
2292 | { | 2306 | { |
2293 | case UNINDEX_STATE_HASHING: | 2307 | case UNINDEX_STATE_HASHING: |
2294 | uc->fhc = | 2308 | uc->fhc = GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, |
2295 | GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, uc->filename, | 2309 | uc->filename, |
2296 | HASHING_BLOCKSIZE, | 2310 | HASHING_BLOCKSIZE, |
2297 | &GNUNET_FS_unindex_process_hash_, uc); | 2311 | &GNUNET_FS_unindex_process_hash_, |
2312 | uc); | ||
2298 | break; | 2313 | break; |
2299 | case UNINDEX_STATE_FS_NOTIFY: | 2314 | case UNINDEX_STATE_FS_NOTIFY: |
2300 | uc->state = UNINDEX_STATE_HASHING; | 2315 | uc->state = UNINDEX_STATE_HASHING; |
@@ -2319,8 +2334,9 @@ deserialize_unindex_file (void *cls, | |||
2319 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 2334 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) |
2320 | { | 2335 | { |
2321 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2336 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2322 | _("Failure while resuming unindexing operation `%s': %s\n"), | 2337 | _ ("Failure while resuming unindexing operation `%s': %s\n"), |
2323 | filename, emsg); | 2338 | filename, |
2339 | emsg); | ||
2324 | GNUNET_free (emsg); | 2340 | GNUNET_free (emsg); |
2325 | } | 2341 | } |
2326 | return GNUNET_OK; | 2342 | return GNUNET_OK; |
@@ -2329,13 +2345,14 @@ cleanup: | |||
2329 | if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))) | 2345 | if ((NULL != rh) && (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))) |
2330 | { | 2346 | { |
2331 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2347 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2332 | _("Failed to resume unindexing operation `%s': %s\n"), | 2348 | _ ("Failed to resume unindexing operation `%s': %s\n"), |
2333 | filename, | 2349 | filename, |
2334 | emsg); | 2350 | emsg); |
2335 | GNUNET_free (emsg); | 2351 | GNUNET_free (emsg); |
2336 | } | 2352 | } |
2337 | if (NULL != uc->serialization) | 2353 | if (NULL != uc->serialization) |
2338 | GNUNET_FS_remove_sync_file_ (h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 2354 | GNUNET_FS_remove_sync_file_ (h, |
2355 | GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | ||
2339 | uc->serialization); | 2356 | uc->serialization); |
2340 | GNUNET_free_non_null (uc->serialization); | 2357 | GNUNET_free_non_null (uc->serialization); |
2341 | GNUNET_free (uc); | 2358 | GNUNET_free (uc); |
@@ -2384,8 +2401,7 @@ deserialize_search (struct GNUNET_FS_Handle *h, | |||
2384 | * @return #GNUNET_OK (continue to iterate) | 2401 | * @return #GNUNET_OK (continue to iterate) |
2385 | */ | 2402 | */ |
2386 | static int | 2403 | static int |
2387 | deserialize_search_result (void *cls, | 2404 | deserialize_search_result (void *cls, const char *filename) |
2388 | const char *filename) | ||
2389 | { | 2405 | { |
2390 | struct GNUNET_FS_SearchContext *sc = cls; | 2406 | struct GNUNET_FS_SearchContext *sc = cls; |
2391 | char *ser; | 2407 | char *ser; |
@@ -2405,9 +2421,10 @@ deserialize_search_result (void *cls, | |||
2405 | { | 2421 | { |
2406 | remove_sync_file_in_dir (sc->h, | 2422 | remove_sync_file_in_dir (sc->h, |
2407 | (NULL == sc->psearch_result) | 2423 | (NULL == sc->psearch_result) |
2408 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH | 2424 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2409 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2425 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2410 | sc->serialization, ser); | 2426 | sc->serialization, |
2427 | ser); | ||
2411 | GNUNET_free (ser); | 2428 | GNUNET_free (ser); |
2412 | } | 2429 | } |
2413 | return GNUNET_OK; | 2430 | return GNUNET_OK; |
@@ -2420,15 +2437,19 @@ deserialize_search_result (void *cls, | |||
2420 | sr->h = sc->h; | 2437 | sr->h = sc->h; |
2421 | sr->sc = sc; | 2438 | sr->sc = sc; |
2422 | sr->serialization = ser; | 2439 | sr->serialization = ser; |
2423 | if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024)) | 2440 | if ((GNUNET_OK != |
2424 | || (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) || | 2441 | GNUNET_BIO_read_string (rh, "result-uri", &uris, 10 * 1024)) || |
2425 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) | 2442 | (NULL == (sr->uri = GNUNET_FS_uri_parse (uris, &emsg))) || |
2426 | || (GNUNET_OK != | ||
2427 | GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) || | ||
2428 | (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) || | ||
2429 | (GNUNET_OK != | 2443 | (GNUNET_OK != |
2430 | GNUNET_BIO_read (rh, "result-key", &sr->key, sizeof (struct GNUNET_HashCode))) | 2444 | GNUNET_BIO_read_string (rh, "download-lnk", &download, 16)) || |
2431 | || (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) || | 2445 | (GNUNET_OK != |
2446 | GNUNET_BIO_read_string (rh, "search-lnk", &update_srch, 16)) || | ||
2447 | (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "result-meta", &sr->meta)) || | ||
2448 | (GNUNET_OK != GNUNET_BIO_read (rh, | ||
2449 | "result-key", | ||
2450 | &sr->key, | ||
2451 | sizeof (struct GNUNET_HashCode))) || | ||
2452 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->mandatory_missing)) || | ||
2432 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->optional_support)) || | 2453 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->optional_support)) || |
2433 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_success)) || | 2454 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_success)) || |
2434 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_trials))) | 2455 | (GNUNET_OK != GNUNET_BIO_read_int32 (rh, &sr->availability_trials))) |
@@ -2438,10 +2459,13 @@ deserialize_search_result (void *cls, | |||
2438 | } | 2459 | } |
2439 | if (GNUNET_FS_URI_KSK == sr->sc->uri->type) | 2460 | if (GNUNET_FS_URI_KSK == sr->sc->uri->type) |
2440 | { | 2461 | { |
2441 | sr->keyword_bitmap = GNUNET_malloc ((sr->sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */ | 2462 | sr->keyword_bitmap = GNUNET_malloc ( |
2442 | if (GNUNET_OK != GNUNET_BIO_read (rh, "keyword-bitmap", | 2463 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8); /* round up, count bits */ |
2443 | sr->keyword_bitmap, | 2464 | if (GNUNET_OK != |
2444 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8)) | 2465 | GNUNET_BIO_read (rh, |
2466 | "keyword-bitmap", | ||
2467 | sr->keyword_bitmap, | ||
2468 | (sr->sc->uri->data.ksk.keywordCount + 7) / 8)) | ||
2445 | { | 2469 | { |
2446 | GNUNET_break (0); | 2470 | GNUNET_break (0); |
2447 | goto cleanup; | 2471 | goto cleanup; |
@@ -2457,7 +2481,7 @@ deserialize_search_result (void *cls, | |||
2457 | if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg)) | 2481 | if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg)) |
2458 | { | 2482 | { |
2459 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2483 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2460 | _("Failed to resume sub-download `%s': %s\n"), | 2484 | _ ("Failed to resume sub-download `%s': %s\n"), |
2461 | download, | 2485 | download, |
2462 | emsg); | 2486 | emsg); |
2463 | GNUNET_free (emsg); | 2487 | GNUNET_free (emsg); |
@@ -2468,14 +2492,14 @@ deserialize_search_result (void *cls, | |||
2468 | if (NULL != update_srch) | 2492 | if (NULL != update_srch) |
2469 | { | 2493 | { |
2470 | drh = | 2494 | drh = |
2471 | get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch); | 2495 | get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch); |
2472 | if (NULL != drh) | 2496 | if (NULL != drh) |
2473 | { | 2497 | { |
2474 | deserialize_search (sc->h, drh, sr, update_srch); | 2498 | deserialize_search (sc->h, drh, sr, update_srch); |
2475 | if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg)) | 2499 | if (GNUNET_OK != GNUNET_BIO_read_close (drh, &emsg)) |
2476 | { | 2500 | { |
2477 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2501 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2478 | _("Failed to resume sub-search `%s': %s\n"), | 2502 | _ ("Failed to resume sub-search `%s': %s\n"), |
2479 | update_srch, | 2503 | update_srch, |
2480 | emsg); | 2504 | emsg); |
2481 | GNUNET_free (emsg); | 2505 | GNUNET_free (emsg); |
@@ -2483,15 +2507,17 @@ deserialize_search_result (void *cls, | |||
2483 | } | 2507 | } |
2484 | GNUNET_free (update_srch); | 2508 | GNUNET_free (update_srch); |
2485 | } | 2509 | } |
2486 | GNUNET_break (GNUNET_YES == | 2510 | GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_multihashmap_put ( |
2487 | GNUNET_CONTAINER_multihashmap_put (sc->master_result_map, | 2511 | sc->master_result_map, |
2488 | &sr->key, sr, | 2512 | &sr->key, |
2489 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 2513 | sr, |
2514 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | ||
2490 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 2515 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) |
2491 | { | 2516 | { |
2492 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2517 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2493 | _("Failure while resuming search operation `%s': %s\n"), | 2518 | _ ("Failure while resuming search operation `%s': %s\n"), |
2494 | filename, emsg); | 2519 | filename, |
2520 | emsg); | ||
2495 | GNUNET_free (emsg); | 2521 | GNUNET_free (emsg); |
2496 | } | 2522 | } |
2497 | return GNUNET_OK; | 2523 | return GNUNET_OK; |
@@ -2509,8 +2535,9 @@ cleanup: | |||
2509 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 2535 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) |
2510 | { | 2536 | { |
2511 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2537 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2512 | _("Failure while resuming search operation `%s': %s\n"), | 2538 | _ ("Failure while resuming search operation `%s': %s\n"), |
2513 | filename, emsg); | 2539 | filename, |
2540 | emsg); | ||
2514 | GNUNET_free (emsg); | 2541 | GNUNET_free (emsg); |
2515 | } | 2542 | } |
2516 | return GNUNET_OK; | 2543 | return GNUNET_OK; |
@@ -2564,9 +2591,7 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc); | |||
2564 | * @return #GNUNET_YES (we should continue to iterate) | 2591 | * @return #GNUNET_YES (we should continue to iterate) |
2565 | */ | 2592 | */ |
2566 | static int | 2593 | static int |
2567 | signal_result_resume (void *cls, | 2594 | signal_result_resume (void *cls, const struct GNUNET_HashCode *key, void *value) |
2568 | const struct GNUNET_HashCode *key, | ||
2569 | void *value) | ||
2570 | { | 2595 | { |
2571 | struct GNUNET_FS_SearchContext *sc = cls; | 2596 | struct GNUNET_FS_SearchContext *sc = cls; |
2572 | struct GNUNET_FS_ProgressInfo pi; | 2597 | struct GNUNET_FS_ProgressInfo pi; |
@@ -2579,11 +2604,11 @@ signal_result_resume (void *cls, | |||
2579 | pi.value.search.specifics.resume_result.uri = sr->uri; | 2604 | pi.value.search.specifics.resume_result.uri = sr->uri; |
2580 | pi.value.search.specifics.resume_result.result = sr; | 2605 | pi.value.search.specifics.resume_result.result = sr; |
2581 | pi.value.search.specifics.resume_result.availability_rank = | 2606 | pi.value.search.specifics.resume_result.availability_rank = |
2582 | 2 * sr->availability_success - sr->availability_trials; | 2607 | 2 * sr->availability_success - sr->availability_trials; |
2583 | pi.value.search.specifics.resume_result.availability_certainty = | 2608 | pi.value.search.specifics.resume_result.availability_certainty = |
2584 | sr->availability_trials; | 2609 | sr->availability_trials; |
2585 | pi.value.search.specifics.resume_result.applicability_rank = | 2610 | pi.value.search.specifics.resume_result.applicability_rank = |
2586 | sr->optional_support; | 2611 | sr->optional_support; |
2587 | sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); | 2612 | sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); |
2588 | } | 2613 | } |
2589 | if (NULL != sr->download) | 2614 | if (NULL != sr->download) |
@@ -2618,9 +2643,7 @@ free_search_context (struct GNUNET_FS_SearchContext *sc); | |||
2618 | * @return #GNUNET_YES (we should continue to iterate) | 2643 | * @return #GNUNET_YES (we should continue to iterate) |
2619 | */ | 2644 | */ |
2620 | static int | 2645 | static int |
2621 | free_result (void *cls, | 2646 | free_result (void *cls, const struct GNUNET_HashCode *key, void *value) |
2622 | const struct GNUNET_HashCode *key, | ||
2623 | void *value) | ||
2624 | { | 2647 | { |
2625 | struct GNUNET_FS_SearchResult *sr = value; | 2648 | struct GNUNET_FS_SearchResult *sr = value; |
2626 | 2649 | ||
@@ -2647,14 +2670,14 @@ free_search_context (struct GNUNET_FS_SearchContext *sc) | |||
2647 | if (NULL != sc->serialization) | 2670 | if (NULL != sc->serialization) |
2648 | { | 2671 | { |
2649 | GNUNET_FS_remove_sync_file_ (sc->h, | 2672 | GNUNET_FS_remove_sync_file_ (sc->h, |
2650 | (sc->psearch_result == | 2673 | (sc->psearch_result == NULL) |
2651 | NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH : | 2674 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2652 | GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2675 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2653 | sc->serialization); | 2676 | sc->serialization); |
2654 | GNUNET_FS_remove_sync_dir_ (sc->h, | 2677 | GNUNET_FS_remove_sync_dir_ (sc->h, |
2655 | (sc->psearch_result == | 2678 | (sc->psearch_result == NULL) |
2656 | NULL) ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH : | 2679 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2657 | GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2680 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2658 | sc->serialization); | 2681 | sc->serialization); |
2659 | } | 2682 | } |
2660 | GNUNET_free_non_null (sc->serialization); | 2683 | GNUNET_free_non_null (sc->serialization); |
@@ -2663,7 +2686,8 @@ free_search_context (struct GNUNET_FS_SearchContext *sc) | |||
2663 | GNUNET_FS_uri_destroy (sc->uri); | 2686 | GNUNET_FS_uri_destroy (sc->uri); |
2664 | if (NULL != sc->master_result_map) | 2687 | if (NULL != sc->master_result_map) |
2665 | { | 2688 | { |
2666 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, &free_result, | 2689 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, |
2690 | &free_result, | ||
2667 | sc); | 2691 | sc); |
2668 | GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); | 2692 | GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map); |
2669 | } | 2693 | } |
@@ -2680,8 +2704,7 @@ free_search_context (struct GNUNET_FS_SearchContext *sc) | |||
2680 | * @return #GNUNET_OK (continue to iterate) | 2704 | * @return #GNUNET_OK (continue to iterate) |
2681 | */ | 2705 | */ |
2682 | static int | 2706 | static int |
2683 | deserialize_subdownload (void *cls, | 2707 | deserialize_subdownload (void *cls, const char *filename) |
2684 | const char *filename) | ||
2685 | { | 2708 | { |
2686 | struct GNUNET_FS_DownloadContext *parent = cls; | 2709 | struct GNUNET_FS_DownloadContext *parent = cls; |
2687 | char *ser; | 2710 | char *ser; |
@@ -2693,7 +2716,8 @@ deserialize_subdownload (void *cls, | |||
2693 | if (NULL == rh) | 2716 | if (NULL == rh) |
2694 | { | 2717 | { |
2695 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2718 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2696 | _("Failed to resume sub-download `%s': could not open file `%s'\n"), | 2719 | _ ( |
2720 | "Failed to resume sub-download `%s': could not open file `%s'\n"), | ||
2697 | ser, | 2721 | ser, |
2698 | filename); | 2722 | filename); |
2699 | GNUNET_free (ser); | 2723 | GNUNET_free (ser); |
@@ -2703,7 +2727,7 @@ deserialize_subdownload (void *cls, | |||
2703 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 2727 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) |
2704 | { | 2728 | { |
2705 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2729 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2706 | _("Failed to resume sub-download `%s': %s\n"), | 2730 | _ ("Failed to resume sub-download `%s': %s\n"), |
2707 | ser, | 2731 | ser, |
2708 | emsg); | 2732 | emsg); |
2709 | GNUNET_free (emsg); | 2733 | GNUNET_free (emsg); |
@@ -2735,9 +2759,7 @@ free_download_context (struct GNUNET_FS_DownloadContext *dc) | |||
2735 | GNUNET_free_non_null (dc->serialization); | 2759 | GNUNET_free_non_null (dc->serialization); |
2736 | while (NULL != (dcc = dc->child_head)) | 2760 | while (NULL != (dcc = dc->child_head)) |
2737 | { | 2761 | { |
2738 | GNUNET_CONTAINER_DLL_remove (dc->child_head, | 2762 | GNUNET_CONTAINER_DLL_remove (dc->child_head, dc->child_tail, dcc); |
2739 | dc->child_tail, | ||
2740 | dcc); | ||
2741 | free_download_context (dcc); | 2763 | free_download_context (dcc); |
2742 | } | 2764 | } |
2743 | GNUNET_FS_free_download_request_ (dc->top_request); | 2765 | GNUNET_FS_free_download_request_ (dc->top_request); |
@@ -2781,14 +2803,16 @@ deserialize_download (struct GNUNET_FS_Handle *h, | |||
2781 | (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || | 2803 | (NULL == (dc->uri = GNUNET_FS_uri_parse (uris, &emsg))) || |
2782 | ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) && | 2804 | ((GNUNET_YES != GNUNET_FS_uri_test_chk (dc->uri)) && |
2783 | (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) || | 2805 | (GNUNET_YES != GNUNET_FS_uri_test_loc (dc->uri))) || |
2784 | (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) | ||
2785 | || (GNUNET_OK != | ||
2786 | GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) || | ||
2787 | (GNUNET_OK != | 2806 | (GNUNET_OK != |
2788 | GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) || | 2807 | GNUNET_BIO_read_meta_data (rh, "download-meta", &dc->meta)) || |
2808 | (GNUNET_OK != | ||
2809 | GNUNET_BIO_read_string (rh, "download-emsg", &dc->emsg, 10 * 1024)) || | ||
2789 | (GNUNET_OK != | 2810 | (GNUNET_OK != |
2790 | GNUNET_BIO_read_string (rh, "download-tfn", &dc->temp_filename, | 2811 | GNUNET_BIO_read_string (rh, "download-fn", &dc->filename, 10 * 1024)) || |
2791 | 10 * 1024)) || | 2812 | (GNUNET_OK != GNUNET_BIO_read_string (rh, |
2813 | "download-tfn", | ||
2814 | &dc->temp_filename, | ||
2815 | 10 * 1024)) || | ||
2792 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) || | 2816 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->old_file_size)) || |
2793 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->offset)) || | 2817 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->offset)) || |
2794 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->length)) || | 2818 | (GNUNET_OK != GNUNET_BIO_read_int64 (rh, &dc->length)) || |
@@ -2803,14 +2827,14 @@ deserialize_download (struct GNUNET_FS_Handle *h, | |||
2803 | } | 2827 | } |
2804 | dc->options = (enum GNUNET_FS_DownloadOptions) options; | 2828 | dc->options = (enum GNUNET_FS_DownloadOptions) options; |
2805 | dc->active = | 2829 | dc->active = |
2806 | GNUNET_CONTAINER_multihashmap_create (1 + 2 * (dc->length / DBLOCK_SIZE), GNUNET_NO); | 2830 | GNUNET_CONTAINER_multihashmap_create (1 + 2 * (dc->length / DBLOCK_SIZE), |
2831 | GNUNET_NO); | ||
2807 | dc->has_finished = (int) status; | 2832 | dc->has_finished = (int) status; |
2808 | dc->treedepth = | 2833 | dc->treedepth = |
2809 | GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri)); | 2834 | GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri)); |
2810 | if (GNUNET_FS_uri_test_loc (dc->uri)) | 2835 | if (GNUNET_FS_uri_test_loc (dc->uri)) |
2811 | GNUNET_assert (GNUNET_OK == | 2836 | GNUNET_assert (GNUNET_OK == |
2812 | GNUNET_FS_uri_loc_get_peer_identity (dc->uri, | 2837 | GNUNET_FS_uri_loc_get_peer_identity (dc->uri, &dc->target)); |
2813 | &dc->target)); | ||
2814 | if (NULL == dc->emsg) | 2838 | if (NULL == dc->emsg) |
2815 | { | 2839 | { |
2816 | dc->top_request = read_download_request (rh); | 2840 | dc->top_request = read_download_request (rh); |
@@ -2820,43 +2844,31 @@ deserialize_download (struct GNUNET_FS_Handle *h, | |||
2820 | goto cleanup; | 2844 | goto cleanup; |
2821 | } | 2845 | } |
2822 | } | 2846 | } |
2823 | dn = get_download_sync_filename (dc, | 2847 | dn = get_download_sync_filename (dc, dc->serialization, ".dir"); |
2824 | dc->serialization, | ||
2825 | ".dir"); | ||
2826 | if (NULL != dn) | 2848 | if (NULL != dn) |
2827 | { | 2849 | { |
2828 | if (GNUNET_YES == | 2850 | if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) |
2829 | GNUNET_DISK_directory_test (dn, | 2851 | GNUNET_DISK_directory_scan (dn, &deserialize_subdownload, dc); |
2830 | GNUNET_YES)) | ||
2831 | GNUNET_DISK_directory_scan (dn, | ||
2832 | &deserialize_subdownload, | ||
2833 | dc); | ||
2834 | GNUNET_free (dn); | 2852 | GNUNET_free (dn); |
2835 | } | 2853 | } |
2836 | if (NULL != parent) | 2854 | if (NULL != parent) |
2837 | { | 2855 | { |
2838 | GNUNET_CONTAINER_DLL_insert (parent->child_head, | 2856 | GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc); |
2839 | parent->child_tail, | ||
2840 | dc); | ||
2841 | } | 2857 | } |
2842 | if (NULL != search) | 2858 | if (NULL != search) |
2843 | { | 2859 | { |
2844 | dc->search = search; | 2860 | dc->search = search; |
2845 | search->download = dc; | 2861 | search->download = dc; |
2846 | } | 2862 | } |
2847 | if ( (NULL == parent) && | 2863 | if ((NULL == parent) && (NULL == search)) |
2848 | (NULL == search) ) | ||
2849 | { | 2864 | { |
2850 | dc->top | 2865 | dc->top = |
2851 | = GNUNET_FS_make_top (dc->h, | 2866 | GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc); |
2852 | &GNUNET_FS_download_signal_suspend_, | ||
2853 | dc); | ||
2854 | signal_download_resume (dc); | 2867 | signal_download_resume (dc); |
2855 | } | 2868 | } |
2856 | GNUNET_free (uris); | 2869 | GNUNET_free (uris); |
2857 | GNUNET_assert (NULL == dc->job_queue); | 2870 | GNUNET_assert (NULL == dc->job_queue); |
2858 | dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, | 2871 | dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc); |
2859 | dc); | ||
2860 | return; | 2872 | return; |
2861 | cleanup: | 2873 | cleanup: |
2862 | GNUNET_free_non_null (uris); | 2874 | GNUNET_free_non_null (uris); |
@@ -2879,11 +2891,11 @@ signal_search_resume (struct GNUNET_FS_SearchContext *sc) | |||
2879 | pi.status = GNUNET_FS_STATUS_SEARCH_RESUME; | 2891 | pi.status = GNUNET_FS_STATUS_SEARCH_RESUME; |
2880 | pi.value.search.specifics.resume.message = sc->emsg; | 2892 | pi.value.search.specifics.resume.message = sc->emsg; |
2881 | pi.value.search.specifics.resume.is_paused = | 2893 | pi.value.search.specifics.resume.is_paused = |
2882 | (NULL == sc->mq) ? GNUNET_YES : GNUNET_NO; | 2894 | (NULL == sc->mq) ? GNUNET_YES : GNUNET_NO; |
2883 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); | 2895 | sc->client_info = GNUNET_FS_search_make_status_ (&pi, sc->h, sc); |
2884 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, | 2896 | GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map, |
2885 | &signal_result_resume, sc); | 2897 | &signal_result_resume, |
2886 | 2898 | sc); | |
2887 | } | 2899 | } |
2888 | 2900 | ||
2889 | 2901 | ||
@@ -2942,10 +2954,11 @@ deserialize_search (struct GNUNET_FS_Handle *h, | |||
2942 | sc->options = (enum GNUNET_FS_SearchOptions) options; | 2954 | sc->options = (enum GNUNET_FS_SearchOptions) options; |
2943 | sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO); | 2955 | sc->master_result_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO); |
2944 | dn = get_serialization_file_name_in_dir (h, | 2956 | dn = get_serialization_file_name_in_dir (h, |
2945 | (NULL == sc->psearch_result) ? | 2957 | (NULL == sc->psearch_result) |
2946 | GNUNET_FS_SYNC_PATH_MASTER_SEARCH : | 2958 | ? GNUNET_FS_SYNC_PATH_MASTER_SEARCH |
2947 | GNUNET_FS_SYNC_PATH_CHILD_SEARCH, | 2959 | : GNUNET_FS_SYNC_PATH_CHILD_SEARCH, |
2948 | sc->serialization, ""); | 2960 | sc->serialization, |
2961 | ""); | ||
2949 | if (NULL != dn) | 2962 | if (NULL != dn) |
2950 | { | 2963 | { |
2951 | if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) | 2964 | if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) |
@@ -2955,8 +2968,9 @@ deserialize_search (struct GNUNET_FS_Handle *h, | |||
2955 | if (('\0' == in_pause) && | 2968 | if (('\0' == in_pause) && |
2956 | (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc))) | 2969 | (GNUNET_OK != GNUNET_FS_search_start_searching_ (sc))) |
2957 | { | 2970 | { |
2958 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2971 | GNUNET_log ( |
2959 | _("Could not resume running search, will resume as paused search\n")); | 2972 | GNUNET_ERROR_TYPE_WARNING, |
2973 | _ ("Could not resume running search, will resume as paused search\n")); | ||
2960 | } | 2974 | } |
2961 | signal_search_resume (sc); | 2975 | signal_search_resume (sc); |
2962 | GNUNET_free (uris); | 2976 | GNUNET_free (uris); |
@@ -2978,8 +2992,7 @@ cleanup: | |||
2978 | * @return #GNUNET_OK (continue to iterate) | 2992 | * @return #GNUNET_OK (continue to iterate) |
2979 | */ | 2993 | */ |
2980 | static int | 2994 | static int |
2981 | deserialize_search_file (void *cls, | 2995 | deserialize_search_file (void *cls, const char *filename) |
2982 | const char *filename) | ||
2983 | { | 2996 | { |
2984 | struct GNUNET_FS_Handle *h = cls; | 2997 | struct GNUNET_FS_Handle *h = cls; |
2985 | char *ser; | 2998 | char *ser; |
@@ -2988,7 +3001,7 @@ deserialize_search_file (void *cls, | |||
2988 | struct GNUNET_FS_SearchContext *sc; | 3001 | struct GNUNET_FS_SearchContext *sc; |
2989 | struct stat buf; | 3002 | struct stat buf; |
2990 | 3003 | ||
2991 | if (0 != STAT (filename, &buf)) | 3004 | if (0 != stat (filename, &buf)) |
2992 | { | 3005 | { |
2993 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); | 3006 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); |
2994 | return GNUNET_OK; | 3007 | return GNUNET_OK; |
@@ -3013,8 +3026,9 @@ deserialize_search_file (void *cls, | |||
3013 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 3026 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) |
3014 | { | 3027 | { |
3015 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3028 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3016 | _("Failure while resuming search operation `%s': %s\n"), | 3029 | _ ("Failure while resuming search operation `%s': %s\n"), |
3017 | filename, emsg); | 3030 | filename, |
3031 | emsg); | ||
3018 | GNUNET_free (emsg); | 3032 | GNUNET_free (emsg); |
3019 | } | 3033 | } |
3020 | return GNUNET_OK; | 3034 | return GNUNET_OK; |
@@ -3041,7 +3055,7 @@ deserialize_download_file (void *cls, const char *filename) | |||
3041 | rh = GNUNET_BIO_read_open (filename); | 3055 | rh = GNUNET_BIO_read_open (filename); |
3042 | if (NULL == rh) | 3056 | if (NULL == rh) |
3043 | { | 3057 | { |
3044 | if (0 != UNLINK (filename)) | 3058 | if (0 != unlink (filename)) |
3045 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); | 3059 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename); |
3046 | GNUNET_free (ser); | 3060 | GNUNET_free (ser); |
3047 | return GNUNET_OK; | 3061 | return GNUNET_OK; |
@@ -3051,8 +3065,9 @@ deserialize_download_file (void *cls, const char *filename) | |||
3051 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 3065 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) |
3052 | { | 3066 | { |
3053 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3067 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3054 | _("Failure while resuming download operation `%s': %s\n"), | 3068 | _ ("Failure while resuming download operation `%s': %s\n"), |
3055 | filename, emsg); | 3069 | filename, |
3070 | emsg); | ||
3056 | GNUNET_free (emsg); | 3071 | GNUNET_free (emsg); |
3057 | } | 3072 | } |
3058 | return GNUNET_OK; | 3073 | return GNUNET_OK; |
@@ -3068,7 +3083,7 @@ deserialize_download_file (void *cls, const char *filename) | |||
3068 | */ | 3083 | */ |
3069 | static void | 3084 | static void |
3070 | deserialization_master (const char *master_path, | 3085 | deserialization_master (const char *master_path, |
3071 | GNUNET_FileNameCallback proc, | 3086 | GNUNET_FileNameCallback proc, |
3072 | struct GNUNET_FS_Handle *h) | 3087 | struct GNUNET_FS_Handle *h) |
3073 | { | 3088 | { |
3074 | char *dn; | 3089 | char *dn; |
@@ -3098,7 +3113,8 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3098 | const char *client_name, | 3113 | const char *client_name, |
3099 | GNUNET_FS_ProgressCallback upcb, | 3114 | GNUNET_FS_ProgressCallback upcb, |
3100 | void *upcb_cls, | 3115 | void *upcb_cls, |
3101 | enum GNUNET_FS_Flags flags, ...) | 3116 | enum GNUNET_FS_Flags flags, |
3117 | ...) | ||
3102 | { | 3118 | { |
3103 | struct GNUNET_FS_Handle *ret; | 3119 | struct GNUNET_FS_Handle *ret; |
3104 | enum GNUNET_FS_OPTIONS opt; | 3120 | enum GNUNET_FS_OPTIONS opt; |
@@ -3112,9 +3128,11 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3112 | ret->flags = flags; | 3128 | ret->flags = flags; |
3113 | ret->max_parallel_downloads = DEFAULT_MAX_PARALLEL_DOWNLOADS; | 3129 | ret->max_parallel_downloads = DEFAULT_MAX_PARALLEL_DOWNLOADS; |
3114 | ret->max_parallel_requests = DEFAULT_MAX_PARALLEL_REQUESTS; | 3130 | ret->max_parallel_requests = DEFAULT_MAX_PARALLEL_REQUESTS; |
3115 | ret->avg_block_latency = GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */ | 3131 | ret->avg_block_latency = |
3132 | GNUNET_TIME_UNIT_MINUTES; /* conservative starting point */ | ||
3116 | va_start (ap, flags); | 3133 | va_start (ap, flags); |
3117 | while (GNUNET_FS_OPTIONS_END != (opt = GNUNET_VA_ARG_ENUM (ap,GNUNET_FS_OPTIONS))) | 3134 | while (GNUNET_FS_OPTIONS_END != |
3135 | (opt = GNUNET_VA_ARG_ENUM (ap, GNUNET_FS_OPTIONS))) | ||
3118 | { | 3136 | { |
3119 | switch (opt) | 3137 | switch (opt) |
3120 | { | 3138 | { |
@@ -3138,13 +3156,17 @@ GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3138 | if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags)) | 3156 | if (0 != (GNUNET_FS_FLAGS_PERSISTENCE & flags)) |
3139 | { | 3157 | { |
3140 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, | 3158 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, |
3141 | &deserialize_publish_file, ret); | 3159 | &deserialize_publish_file, |
3160 | ret); | ||
3142 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_SEARCH, | 3161 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_SEARCH, |
3143 | &deserialize_search_file, ret); | 3162 | &deserialize_search_file, |
3163 | ret); | ||
3144 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, | 3164 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, |
3145 | &deserialize_download_file, ret); | 3165 | &deserialize_download_file, |
3166 | ret); | ||
3146 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, | 3167 | deserialization_master (GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, |
3147 | &deserialize_unindex_file, ret); | 3168 | &deserialize_unindex_file, |
3169 | ret); | ||
3148 | } | 3170 | } |
3149 | return ret; | 3171 | return ret; |
3150 | } | 3172 | } |
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 | |||
80 | /** | 80 | /** |
81 | * Task scheduled when we are done. | 81 | * Task scheduled when we are done. |
82 | */ | 82 | */ |
83 | struct GNUNET_SCHEDULER_Task * stop_task; | 83 | struct GNUNET_SCHEDULER_Task *stop_task; |
84 | 84 | ||
85 | /** | 85 | /** |
86 | * Arguments for helper. | 86 | * Arguments for helper. |
87 | */ | 87 | */ |
88 | char *args[4]; | 88 | char *args[4]; |
89 | |||
90 | }; | 89 | }; |
91 | 90 | ||
92 | 91 | ||
@@ -151,11 +150,9 @@ advance (struct GNUNET_FS_ShareTreeItem *pos) | |||
151 | 150 | ||
152 | GNUNET_assert (NULL != pos); | 151 | GNUNET_assert (NULL != pos); |
153 | moved = 0; /* must not terminate, even on file, otherwise "normal" */ | 152 | moved = 0; /* must not terminate, even on file, otherwise "normal" */ |
154 | while ( (pos->is_directory == GNUNET_YES) || | 153 | while ((pos->is_directory == GNUNET_YES) || (0 == moved)) |
155 | (0 == moved) ) | ||
156 | { | 154 | { |
157 | if ( (moved != -1) && | 155 | if ((moved != -1) && (NULL != pos->children_head)) |
158 | (NULL != pos->children_head) ) | ||
159 | { | 156 | { |
160 | pos = pos->children_head; | 157 | pos = pos->children_head; |
161 | moved = 1; /* can terminate if file */ | 158 | moved = 1; /* can terminate if file */ |
@@ -190,8 +187,8 @@ advance (struct GNUNET_FS_ShareTreeItem *pos) | |||
190 | */ | 187 | */ |
191 | static struct GNUNET_FS_ShareTreeItem * | 188 | static struct GNUNET_FS_ShareTreeItem * |
192 | expand_tree (struct GNUNET_FS_ShareTreeItem *parent, | 189 | expand_tree (struct GNUNET_FS_ShareTreeItem *parent, |
193 | const char *filename, | 190 | const char *filename, |
194 | int is_directory) | 191 | int is_directory) |
195 | { | 192 | { |
196 | struct GNUNET_FS_ShareTreeItem *chld; | 193 | struct GNUNET_FS_ShareTreeItem *chld; |
197 | size_t slen; | 194 | size_t slen; |
@@ -200,20 +197,19 @@ expand_tree (struct GNUNET_FS_ShareTreeItem *parent, | |||
200 | chld->parent = parent; | 197 | chld->parent = parent; |
201 | chld->filename = GNUNET_strdup (filename); | 198 | chld->filename = GNUNET_strdup (filename); |
202 | GNUNET_asprintf (&chld->short_filename, | 199 | GNUNET_asprintf (&chld->short_filename, |
203 | "%s%s", | 200 | "%s%s", |
204 | GNUNET_STRINGS_get_short_name (filename), | 201 | GNUNET_STRINGS_get_short_name (filename), |
205 | is_directory == GNUNET_YES ? "/" : ""); | 202 | is_directory == GNUNET_YES ? "/" : ""); |
206 | /* make sure we do not end with '//' */ | 203 | /* make sure we do not end with '//' */ |
207 | slen = strlen (chld->short_filename); | 204 | slen = strlen (chld->short_filename); |
208 | if ( (slen >= 2) && | 205 | if ((slen >= 2) && (chld->short_filename[slen - 1] == '/') && |
209 | (chld->short_filename[slen-1] == '/') && | 206 | (chld->short_filename[slen - 2] == '/')) |
210 | (chld->short_filename[slen-2] == '/') ) | 207 | chld->short_filename[slen - 1] = '\0'; |
211 | chld->short_filename[slen-1] = '\0'; | ||
212 | chld->is_directory = is_directory; | 208 | chld->is_directory = is_directory; |
213 | if (NULL != parent) | 209 | if (NULL != parent) |
214 | GNUNET_CONTAINER_DLL_insert (parent->children_head, | 210 | GNUNET_CONTAINER_DLL_insert (parent->children_head, |
215 | parent->children_tail, | 211 | parent->children_tail, |
216 | chld); | 212 | chld); |
217 | return chld; | 213 | return chld; |
218 | } | 214 | } |
219 | 215 | ||
@@ -235,8 +231,9 @@ finish_scan (void *cls) | |||
235 | ds->helper = NULL; | 231 | ds->helper = NULL; |
236 | } | 232 | } |
237 | ds->progress_callback (ds->progress_callback_cls, | 233 | ds->progress_callback (ds->progress_callback_cls, |
238 | NULL, GNUNET_SYSERR, | 234 | NULL, |
239 | GNUNET_FS_DIRSCANNER_FINISHED); | 235 | GNUNET_SYSERR, |
236 | GNUNET_FS_DIRSCANNER_FINISHED); | ||
240 | } | 237 | } |
241 | 238 | ||
242 | 239 | ||
@@ -251,8 +248,7 @@ finish_scan (void *cls) | |||
251 | * #GNUNET_SYSERR to stop further processing with error | 248 | * #GNUNET_SYSERR to stop further processing with error |
252 | */ | 249 | */ |
253 | static int | 250 | static int |
254 | process_helper_msgs (void *cls, | 251 | process_helper_msgs (void *cls, const struct GNUNET_MessageHeader *msg) |
255 | const struct GNUNET_MessageHeader *msg) | ||
256 | { | 252 | { |
257 | struct GNUNET_FS_DirScanner *ds = cls; | 253 | struct GNUNET_FS_DirScanner *ds = cls; |
258 | const char *filename; | 254 | const char *filename; |
@@ -265,34 +261,31 @@ process_helper_msgs (void *cls, | |||
265 | (unsigned int) ntohs (msg->type)); | 261 | (unsigned int) ntohs (msg->type)); |
266 | #endif | 262 | #endif |
267 | left = ntohs (msg->size) - sizeof (struct GNUNET_MessageHeader); | 263 | left = ntohs (msg->size) - sizeof (struct GNUNET_MessageHeader); |
268 | filename = (const char*) &msg[1]; | 264 | filename = (const char *) &msg[1]; |
269 | switch (ntohs (msg->type)) | 265 | switch (ntohs (msg->type)) |
270 | { | 266 | { |
271 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE: | 267 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE: |
272 | if (filename[left-1] != '\0') | 268 | if (filename[left - 1] != '\0') |
273 | { | 269 | { |
274 | GNUNET_break (0); | 270 | GNUNET_break (0); |
275 | break; | 271 | break; |
276 | } | 272 | } |
277 | ds->progress_callback (ds->progress_callback_cls, | 273 | ds->progress_callback (ds->progress_callback_cls, |
278 | filename, GNUNET_NO, | 274 | filename, |
279 | GNUNET_FS_DIRSCANNER_FILE_START); | 275 | GNUNET_NO, |
276 | GNUNET_FS_DIRSCANNER_FILE_START); | ||
280 | if (NULL == ds->toplevel) | 277 | if (NULL == ds->toplevel) |
281 | { | 278 | { |
282 | ds->toplevel = expand_tree (ds->pos, | 279 | ds->toplevel = expand_tree (ds->pos, filename, GNUNET_NO); |
283 | filename, | ||
284 | GNUNET_NO); | ||
285 | } | 280 | } |
286 | else | 281 | else |
287 | { | 282 | { |
288 | GNUNET_assert (NULL != ds->pos); | 283 | GNUNET_assert (NULL != ds->pos); |
289 | (void) expand_tree (ds->pos, | 284 | (void) expand_tree (ds->pos, filename, GNUNET_NO); |
290 | filename, | ||
291 | GNUNET_NO); | ||
292 | } | 285 | } |
293 | return GNUNET_OK; | 286 | return GNUNET_OK; |
294 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY: | 287 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY: |
295 | if (filename[left-1] != '\0') | 288 | if (filename[left - 1] != '\0') |
296 | { | 289 | { |
297 | GNUNET_break (0); | 290 | GNUNET_break (0); |
298 | break; | 291 | break; |
@@ -301,29 +294,29 @@ process_helper_msgs (void *cls, | |||
301 | { | 294 | { |
302 | if (NULL == ds->pos) | 295 | if (NULL == ds->pos) |
303 | { | 296 | { |
304 | GNUNET_break (0); | 297 | GNUNET_break (0); |
305 | break; | 298 | break; |
306 | } | 299 | } |
307 | ds->pos = ds->pos->parent; | 300 | ds->pos = ds->pos->parent; |
308 | return GNUNET_OK; | 301 | return GNUNET_OK; |
309 | } | 302 | } |
310 | ds->progress_callback (ds->progress_callback_cls, | 303 | ds->progress_callback (ds->progress_callback_cls, |
311 | filename, GNUNET_YES, | 304 | filename, |
312 | GNUNET_FS_DIRSCANNER_FILE_START); | 305 | GNUNET_YES, |
313 | ds->pos = expand_tree (ds->pos, | 306 | GNUNET_FS_DIRSCANNER_FILE_START); |
314 | filename, | 307 | ds->pos = expand_tree (ds->pos, filename, GNUNET_YES); |
315 | GNUNET_YES); | ||
316 | if (NULL == ds->toplevel) | 308 | if (NULL == ds->toplevel) |
317 | ds->toplevel = ds->pos; | 309 | ds->toplevel = ds->pos; |
318 | return GNUNET_OK; | 310 | return GNUNET_OK; |
319 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR: | 311 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR: |
320 | break; | 312 | break; |
321 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE: | 313 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE: |
322 | if ('\0' != filename[left-1]) | 314 | if ('\0' != filename[left - 1]) |
323 | break; | 315 | break; |
324 | ds->progress_callback (ds->progress_callback_cls, | 316 | ds->progress_callback (ds->progress_callback_cls, |
325 | filename, GNUNET_SYSERR, | 317 | filename, |
326 | GNUNET_FS_DIRSCANNER_FILE_IGNORED); | 318 | GNUNET_SYSERR, |
319 | GNUNET_FS_DIRSCANNER_FILE_IGNORED); | ||
327 | return GNUNET_OK; | 320 | return GNUNET_OK; |
328 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE: | 321 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE: |
329 | if (0 != left) | 322 | if (0 != left) |
@@ -334,65 +327,66 @@ process_helper_msgs (void *cls, | |||
334 | if (NULL == ds->toplevel) | 327 | if (NULL == ds->toplevel) |
335 | break; | 328 | break; |
336 | ds->progress_callback (ds->progress_callback_cls, | 329 | ds->progress_callback (ds->progress_callback_cls, |
337 | NULL, GNUNET_SYSERR, | 330 | NULL, |
338 | GNUNET_FS_DIRSCANNER_ALL_COUNTED); | 331 | GNUNET_SYSERR, |
332 | GNUNET_FS_DIRSCANNER_ALL_COUNTED); | ||
339 | ds->pos = ds->toplevel; | 333 | ds->pos = ds->toplevel; |
340 | if (GNUNET_YES == ds->pos->is_directory) | 334 | if (GNUNET_YES == ds->pos->is_directory) |
341 | ds->pos = advance (ds->pos); | 335 | ds->pos = advance (ds->pos); |
342 | return GNUNET_OK; | 336 | return GNUNET_OK; |
343 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA: | 337 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA: { |
344 | { | 338 | size_t nlen; |
345 | size_t nlen; | 339 | const char *end; |
346 | const char *end; | ||
347 | 340 | ||
348 | if (NULL == ds->pos) | 341 | if (NULL == ds->pos) |
349 | { | 342 | { |
350 | GNUNET_break (0); | 343 | GNUNET_break (0); |
351 | break; | 344 | break; |
352 | } | 345 | } |
353 | end = memchr (filename, 0, left); | 346 | end = memchr (filename, 0, left); |
354 | if (NULL == end) | 347 | if (NULL == end) |
355 | { | 348 | { |
356 | GNUNET_break (0); | 349 | GNUNET_break (0); |
357 | break; | 350 | break; |
358 | } | 351 | } |
359 | end++; | 352 | end++; |
360 | nlen = end - filename; | 353 | nlen = end - filename; |
361 | left -= nlen; | 354 | left -= nlen; |
362 | if (0 != strcmp (filename, | 355 | if (0 != strcmp (filename, ds->pos->filename)) |
363 | ds->pos->filename)) | 356 | { |
364 | { | 357 | GNUNET_break (0); |
365 | GNUNET_break (0); | 358 | break; |
366 | break; | 359 | } |
367 | } | 360 | ds->progress_callback (ds->progress_callback_cls, |
368 | ds->progress_callback (ds->progress_callback_cls, | 361 | filename, |
369 | filename, | 362 | GNUNET_YES, |
370 | GNUNET_YES, | 363 | GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED); |
371 | GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED); | 364 | if (0 < left) |
372 | if (0 < left) | 365 | { |
366 | ds->pos->meta = GNUNET_CONTAINER_meta_data_deserialize (end, left); | ||
367 | if (NULL == ds->pos->meta) | ||
373 | { | 368 | { |
374 | ds->pos->meta = GNUNET_CONTAINER_meta_data_deserialize (end, | 369 | GNUNET_break (0); |
375 | left); | 370 | break; |
376 | if (NULL == ds->pos->meta) | ||
377 | { | ||
378 | GNUNET_break (0); | ||
379 | break; | ||
380 | } | ||
381 | /* having full filenames is too dangerous; always make sure we clean them up */ | ||
382 | GNUNET_CONTAINER_meta_data_delete (ds->pos->meta, | ||
383 | EXTRACTOR_METATYPE_FILENAME, | ||
384 | NULL, 0); | ||
385 | /* instead, put in our 'safer' original filename */ | ||
386 | GNUNET_CONTAINER_meta_data_insert (ds->pos->meta, "<libgnunetfs>", | ||
387 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | ||
388 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", | ||
389 | ds->pos->short_filename, | ||
390 | strlen (ds->pos->short_filename) + 1); | ||
391 | } | 371 | } |
392 | ds->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data (ds->pos->meta); | 372 | /* having full filenames is too dangerous; always make sure we clean them up */ |
393 | ds->pos = advance (ds->pos); | 373 | GNUNET_CONTAINER_meta_data_delete (ds->pos->meta, |
394 | return GNUNET_OK; | 374 | EXTRACTOR_METATYPE_FILENAME, |
375 | NULL, | ||
376 | 0); | ||
377 | /* instead, put in our 'safer' original filename */ | ||
378 | GNUNET_CONTAINER_meta_data_insert (ds->pos->meta, | ||
379 | "<libgnunetfs>", | ||
380 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | ||
381 | EXTRACTOR_METAFORMAT_UTF8, | ||
382 | "text/plain", | ||
383 | ds->pos->short_filename, | ||
384 | strlen (ds->pos->short_filename) + 1); | ||
395 | } | 385 | } |
386 | ds->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data (ds->pos->meta); | ||
387 | ds->pos = advance (ds->pos); | ||
388 | return GNUNET_OK; | ||
389 | } | ||
396 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED: | 390 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED: |
397 | if (NULL != ds->pos) | 391 | if (NULL != ds->pos) |
398 | { | 392 | { |
@@ -406,16 +400,16 @@ process_helper_msgs (void *cls, | |||
406 | } | 400 | } |
407 | if (NULL == ds->toplevel) | 401 | if (NULL == ds->toplevel) |
408 | break; | 402 | break; |
409 | ds->stop_task = GNUNET_SCHEDULER_add_now (&finish_scan, | 403 | ds->stop_task = GNUNET_SCHEDULER_add_now (&finish_scan, ds); |
410 | ds); | ||
411 | return GNUNET_OK; | 404 | return GNUNET_OK; |
412 | default: | 405 | default: |
413 | GNUNET_break (0); | 406 | GNUNET_break (0); |
414 | break; | 407 | break; |
415 | } | 408 | } |
416 | ds->progress_callback (ds->progress_callback_cls, | 409 | ds->progress_callback (ds->progress_callback_cls, |
417 | NULL, GNUNET_SYSERR, | 410 | NULL, |
418 | GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); | 411 | GNUNET_SYSERR, |
412 | GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); | ||
419 | return GNUNET_OK; | 413 | return GNUNET_OK; |
420 | } | 414 | } |
421 | 415 | ||
@@ -434,8 +428,9 @@ helper_died_cb (void *cls) | |||
434 | if (NULL != ds->stop_task) | 428 | if (NULL != ds->stop_task) |
435 | return; /* normal death, was finished */ | 429 | return; /* normal death, was finished */ |
436 | ds->progress_callback (ds->progress_callback_cls, | 430 | ds->progress_callback (ds->progress_callback_cls, |
437 | NULL, GNUNET_SYSERR, | 431 | NULL, |
438 | GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); | 432 | GNUNET_SYSERR, |
433 | GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); | ||
439 | } | 434 | } |
440 | 435 | ||
441 | 436 | ||
@@ -452,22 +447,23 @@ helper_died_cb (void *cls) | |||
452 | */ | 447 | */ |
453 | struct GNUNET_FS_DirScanner * | 448 | struct GNUNET_FS_DirScanner * |
454 | GNUNET_FS_directory_scan_start (const char *filename, | 449 | GNUNET_FS_directory_scan_start (const char *filename, |
455 | int disable_extractor, const char *ex, | 450 | int disable_extractor, |
456 | GNUNET_FS_DirScannerProgressCallback cb, | 451 | const char *ex, |
457 | void *cb_cls) | 452 | GNUNET_FS_DirScannerProgressCallback cb, |
453 | void *cb_cls) | ||
458 | { | 454 | { |
459 | struct stat sbuf; | 455 | struct stat sbuf; |
460 | char *filename_expanded; | 456 | char *filename_expanded; |
461 | struct GNUNET_FS_DirScanner *ds; | 457 | struct GNUNET_FS_DirScanner *ds; |
462 | 458 | ||
463 | if (0 != STAT (filename, &sbuf)) | 459 | if (0 != stat (filename, &sbuf)) |
464 | return NULL; | 460 | return NULL; |
465 | filename_expanded = GNUNET_STRINGS_filename_expand (filename); | 461 | filename_expanded = GNUNET_STRINGS_filename_expand (filename); |
466 | if (NULL == filename_expanded) | 462 | if (NULL == filename_expanded) |
467 | return NULL; | 463 | return NULL; |
468 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 464 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
469 | "Starting to scan directory `%s'\n", | 465 | "Starting to scan directory `%s'\n", |
470 | filename_expanded); | 466 | filename_expanded); |
471 | ds = GNUNET_new (struct GNUNET_FS_DirScanner); | 467 | ds = GNUNET_new (struct GNUNET_FS_DirScanner); |
472 | ds->progress_callback = cb; | 468 | ds->progress_callback = cb; |
473 | ds->progress_callback_cls = cb_cls; | 469 | ds->progress_callback_cls = cb_cls; |
@@ -481,12 +477,13 @@ GNUNET_FS_directory_scan_start (const char *filename, | |||
481 | ds->args[2] = ds->ex_arg; | 477 | ds->args[2] = ds->ex_arg; |
482 | ds->args[3] = NULL; | 478 | ds->args[3] = NULL; |
483 | ds->helper = GNUNET_HELPER_start (GNUNET_NO, | 479 | ds->helper = GNUNET_HELPER_start (GNUNET_NO, |
484 | "gnunet-helper-fs-publish", | 480 | "gnunet-helper-fs-publish", |
485 | ds->args, | 481 | ds->args, |
486 | &process_helper_msgs, | 482 | &process_helper_msgs, |
487 | &helper_died_cb, ds); | 483 | &helper_died_cb, |
484 | ds); | ||
488 | if (NULL == ds->helper) | 485 | if (NULL == ds->helper) |
489 | { | 486 | { |
490 | GNUNET_free (filename_expanded); | 487 | GNUNET_free (filename_expanded); |
491 | GNUNET_free (ds); | 488 | GNUNET_free (ds); |
492 | return NULL; | 489 | 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 | |||
37 | is_recursive_download (struct GNUNET_FS_DownloadContext *dc) | 37 | is_recursive_download (struct GNUNET_FS_DownloadContext *dc) |
38 | { | 38 | { |
39 | return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) && | 39 | return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) && |
40 | ( (GNUNET_YES == | 40 | ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (dc->meta)) || |
41 | GNUNET_FS_meta_data_test_for_directory (dc->meta)) || | 41 | ((NULL == dc->meta) && |
42 | ( (NULL == dc->meta) && | 42 | ((NULL == dc->filename) || |
43 | ( (NULL == dc->filename) || | 43 | ((strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && |
44 | ( (strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && | 44 | (NULL != strstr (dc->filename + strlen (dc->filename) - |
45 | (NULL != | 45 | strlen (GNUNET_FS_DIRECTORY_EXT), |
46 | strstr (dc->filename + strlen (dc->filename) - | 46 | GNUNET_FS_DIRECTORY_EXT)))))); |
47 | strlen (GNUNET_FS_DIRECTORY_EXT), | ||
48 | GNUNET_FS_DIRECTORY_EXT)) ) ) ) ); | ||
49 | } | 47 | } |
50 | 48 | ||
51 | 49 | ||
@@ -69,9 +67,9 @@ static uint64_t | |||
69 | compute_disk_offset (uint64_t fsize, uint64_t off, unsigned int depth) | 67 | compute_disk_offset (uint64_t fsize, uint64_t off, unsigned int depth) |
70 | { | 68 | { |
71 | unsigned int i; | 69 | unsigned int i; |
72 | uint64_t lsize; /* what is the size of all IBlocks for depth "i"? */ | 70 | uint64_t lsize; /* what is the size of all IBlocks for depth "i"? */ |
73 | uint64_t loff; /* where do IBlocks for depth "i" start? */ | 71 | uint64_t loff; /* where do IBlocks for depth "i" start? */ |
74 | unsigned int ioff; /* which IBlock corresponds to "off" at depth "i"? */ | 72 | unsigned int ioff; /* which IBlock corresponds to "off" at depth "i"? */ |
75 | 73 | ||
76 | if (0 == depth) | 74 | if (0 == depth) |
77 | return off; | 75 | return off; |
@@ -79,8 +77,7 @@ compute_disk_offset (uint64_t fsize, uint64_t off, unsigned int depth) | |||
79 | * to full DBLOCK_SIZE */ | 77 | * to full DBLOCK_SIZE */ |
80 | loff = ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * DBLOCK_SIZE; | 78 | loff = ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * DBLOCK_SIZE; |
81 | lsize = | 79 | lsize = |
82 | ((fsize + DBLOCK_SIZE - | 80 | ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * sizeof (struct ContentHashKey); |
83 | 1) / DBLOCK_SIZE) * sizeof (struct ContentHashKey); | ||
84 | GNUNET_assert (0 == (off % DBLOCK_SIZE)); | 81 | GNUNET_assert (0 == (off % DBLOCK_SIZE)); |
85 | ioff = (off / DBLOCK_SIZE); | 82 | ioff = (off / DBLOCK_SIZE); |
86 | for (i = 1; i < depth; i++) | 83 | for (i = 1; i < depth; i++) |
@@ -109,19 +106,19 @@ GNUNET_FS_download_make_status_ (struct GNUNET_FS_ProgressInfo *pi, | |||
109 | pi->value.download.dc = dc; | 106 | pi->value.download.dc = dc; |
110 | pi->value.download.cctx = dc->client_info; | 107 | pi->value.download.cctx = dc->client_info; |
111 | pi->value.download.pctx = | 108 | pi->value.download.pctx = |
112 | (NULL == dc->parent) ? NULL : dc->parent->client_info; | 109 | (NULL == dc->parent) ? NULL : dc->parent->client_info; |
113 | pi->value.download.sctx = | 110 | pi->value.download.sctx = |
114 | (NULL == dc->search) ? NULL : dc->search->client_info; | 111 | (NULL == dc->search) ? NULL : dc->search->client_info; |
115 | pi->value.download.uri = dc->uri; | 112 | pi->value.download.uri = dc->uri; |
116 | pi->value.download.filename = dc->filename; | 113 | pi->value.download.filename = dc->filename; |
117 | pi->value.download.size = dc->length; | 114 | pi->value.download.size = dc->length; |
118 | /* FIXME: Fix duration calculation to account for pauses */ | 115 | /* FIXME: Fix duration calculation to account for pauses */ |
119 | pi->value.download.duration = | 116 | pi->value.download.duration = |
120 | GNUNET_TIME_absolute_get_duration (dc->start_time); | 117 | GNUNET_TIME_absolute_get_duration (dc->start_time); |
121 | pi->value.download.completed = dc->completed; | 118 | pi->value.download.completed = dc->completed; |
122 | pi->value.download.anonymity = dc->anonymity; | 119 | pi->value.download.anonymity = dc->anonymity; |
123 | pi->value.download.eta = | 120 | pi->value.download.eta = |
124 | GNUNET_TIME_calculate_eta (dc->start_time, dc->completed, dc->length); | 121 | GNUNET_TIME_calculate_eta (dc->start_time, dc->completed, dc->length); |
125 | pi->value.download.is_active = (NULL == dc->mq) ? GNUNET_NO : GNUNET_YES; | 122 | pi->value.download.is_active = (NULL == dc->mq) ? GNUNET_NO : GNUNET_YES; |
126 | pi->fsh = dc->h; | 123 | pi->fsh = dc->h; |
127 | if (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) | 124 | if (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) |
@@ -181,7 +178,6 @@ struct ProcessResultClosure | |||
181 | * how often did we transmit the query? | 178 | * how often did we transmit the query? |
182 | */ | 179 | */ |
183 | uint32_t num_transmissions; | 180 | uint32_t num_transmissions; |
184 | |||
185 | }; | 181 | }; |
186 | 182 | ||
187 | 183 | ||
@@ -196,7 +192,7 @@ struct ProcessResultClosure | |||
196 | */ | 192 | */ |
197 | static int | 193 | static int |
198 | process_result_with_request (void *cls, | 194 | process_result_with_request (void *cls, |
199 | const struct GNUNET_HashCode * key, | 195 | const struct GNUNET_HashCode *key, |
200 | void *value); | 196 | void *value); |
201 | 197 | ||
202 | 198 | ||
@@ -216,8 +212,10 @@ process_result_with_request (void *cls, | |||
216 | static int | 212 | static int |
217 | encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc, | 213 | encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc, |
218 | const struct ContentHashKey *chk, | 214 | const struct ContentHashKey *chk, |
219 | struct DownloadRequest *dr, const char *block, | 215 | struct DownloadRequest *dr, |
220 | size_t len, int do_store) | 216 | const char *block, |
217 | size_t len, | ||
218 | int do_store) | ||
221 | { | 219 | { |
222 | struct ProcessResultClosure prc; | 220 | struct ProcessResultClosure prc; |
223 | char enc[len]; | 221 | char enc[len]; |
@@ -237,17 +235,18 @@ encrypt_existing_match (struct GNUNET_FS_DownloadContext *dc, | |||
237 | GNUNET_break_op (0); | 235 | GNUNET_break_op (0); |
238 | return GNUNET_SYSERR; | 236 | return GNUNET_SYSERR; |
239 | } | 237 | } |
240 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 238 | GNUNET_log ( |
241 | "Matching %u byte block for `%s' at offset %llu already present, no need for download!\n", | 239 | GNUNET_ERROR_TYPE_DEBUG, |
242 | (unsigned int) len, | 240 | "Matching %u byte block for `%s' at offset %llu already present, no need for download!\n", |
243 | dc->filename, (unsigned long long) dr->offset); | 241 | (unsigned int) len, |
242 | dc->filename, | ||
243 | (unsigned long long) dr->offset); | ||
244 | /* already got it! */ | 244 | /* already got it! */ |
245 | prc.dc = dc; | 245 | prc.dc = dc; |
246 | prc.data = enc; | 246 | prc.data = enc; |
247 | prc.size = len; | 247 | prc.size = len; |
248 | prc.type = | 248 | prc.type = (0 == dr->depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK |
249 | (0 == | 249 | : GNUNET_BLOCK_TYPE_FS_IBLOCK; |
250 | dr->depth) ? GNUNET_BLOCK_TYPE_FS_DBLOCK : GNUNET_BLOCK_TYPE_FS_IBLOCK; | ||
251 | prc.query = chk->query; | 250 | prc.query = chk->query; |
252 | prc.do_store = do_store; | 251 | prc.do_store = do_store; |
253 | prc.last_transmission = GNUNET_TIME_UNIT_FOREVER_ABS; | 252 | prc.last_transmission = GNUNET_TIME_UNIT_FOREVER_ABS; |
@@ -306,8 +305,10 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc) | |||
306 | size = (size_t) size64; | 305 | size = (size_t) size64; |
307 | if (size64 != (uint64_t) size) | 306 | if (size64 != (uint64_t) size) |
308 | { | 307 | { |
309 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 308 | GNUNET_log ( |
310 | _("Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n")); | 309 | GNUNET_ERROR_TYPE_ERROR, |
310 | _ ( | ||
311 | "Recursive downloads of directories larger than 4 GB are not supported on 32-bit systems\n")); | ||
311 | return; | 312 | return; |
312 | } | 313 | } |
313 | if (NULL != dc->filename) | 314 | if (NULL != dc->filename) |
@@ -324,15 +325,12 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc) | |||
324 | GNUNET_DISK_PERM_NONE); | 325 | GNUNET_DISK_PERM_NONE); |
325 | } | 326 | } |
326 | if (NULL == h) | 327 | if (NULL == h) |
327 | return; /* oops */ | 328 | return; /* oops */ |
328 | data = GNUNET_DISK_file_map (h, | 329 | data = GNUNET_DISK_file_map (h, &m, GNUNET_DISK_MAP_TYPE_READ, size); |
329 | &m, | ||
330 | GNUNET_DISK_MAP_TYPE_READ, | ||
331 | size); | ||
332 | if (NULL == data) | 330 | if (NULL == data) |
333 | { | 331 | { |
334 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 332 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
335 | _("Directory too large for system address space\n")); | 333 | _ ("Directory too large for system address space\n")); |
336 | } | 334 | } |
337 | else | 335 | else |
338 | { | 336 | { |
@@ -343,16 +341,18 @@ full_recursive_download (struct GNUNET_FS_DownloadContext *dc) | |||
343 | &trigger_recursive_download, | 341 | &trigger_recursive_download, |
344 | dc)) | 342 | dc)) |
345 | { | 343 | { |
346 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 344 | GNUNET_log ( |
347 | _("Failed to access full directroy contents of `%s' for recursive download\n"), | 345 | GNUNET_ERROR_TYPE_WARNING, |
348 | dc->filename); | 346 | _ ( |
347 | "Failed to access full directroy contents of `%s' for recursive download\n"), | ||
348 | dc->filename); | ||
349 | } | 349 | } |
350 | GNUNET_DISK_file_unmap (m); | 350 | GNUNET_DISK_file_unmap (m); |
351 | } | 351 | } |
352 | GNUNET_DISK_file_close (h); | 352 | GNUNET_DISK_file_close (h); |
353 | if (NULL == dc->filename) | 353 | if (NULL == dc->filename) |
354 | { | 354 | { |
355 | if (0 != UNLINK (dc->temp_filename)) | 355 | if (0 != unlink (dc->temp_filename)) |
356 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 356 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
357 | "unlink", | 357 | "unlink", |
358 | dc->temp_filename); | 358 | dc->temp_filename); |
@@ -384,12 +384,10 @@ check_completed (struct GNUNET_FS_DownloadContext *dc) | |||
384 | /* then, check if children are done already */ | 384 | /* then, check if children are done already */ |
385 | for (pos = dc->child_head; NULL != pos; pos = pos->next) | 385 | for (pos = dc->child_head; NULL != pos; pos = pos->next) |
386 | { | 386 | { |
387 | if ( (NULL == pos->emsg) && | 387 | if ((NULL == pos->emsg) && (pos->completed < pos->length)) |
388 | (pos->completed < pos->length) ) | 388 | return; /* not done yet */ |
389 | return; /* not done yet */ | 389 | if ((NULL != pos->child_head) && (pos->has_finished != GNUNET_YES)) |
390 | if ( (NULL != pos->child_head) && | 390 | return; /* not transitively done yet */ |
391 | (pos->has_finished != GNUNET_YES) ) | ||
392 | return; /* not transitively done yet */ | ||
393 | } | 391 | } |
394 | /* All of our children are done, so mark this download done */ | 392 | /* All of our children are done, so mark this download done */ |
395 | dc->has_finished = GNUNET_YES; | 393 | dc->has_finished = GNUNET_YES; |
@@ -432,7 +430,9 @@ check_completed (struct GNUNET_FS_DownloadContext *dc) | |||
432 | */ | 430 | */ |
433 | static void | 431 | static void |
434 | try_match_block (struct GNUNET_FS_DownloadContext *dc, | 432 | try_match_block (struct GNUNET_FS_DownloadContext *dc, |
435 | struct DownloadRequest *dr, const char *data, size_t data_len) | 433 | struct DownloadRequest *dr, |
434 | const char *data, | ||
435 | size_t data_len) | ||
436 | { | 436 | { |
437 | struct GNUNET_FS_ProgressInfo pi; | 437 | struct GNUNET_FS_ProgressInfo pi; |
438 | unsigned int i; | 438 | unsigned int i; |
@@ -455,8 +455,8 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, | |||
455 | return; | 455 | return; |
456 | if (dr->depth > 0) | 456 | if (dr->depth > 0) |
457 | { | 457 | { |
458 | if ( (dc->offset > 0) || | 458 | if ((dc->offset > 0) || |
459 | (dc->length < GNUNET_ntohll (dc->uri->data.chk.file_length)) ) | 459 | (dc->length < GNUNET_ntohll (dc->uri->data.chk.file_length))) |
460 | { | 460 | { |
461 | /* NOTE: this test is not tight, but should suffice; the issue | 461 | /* NOTE: this test is not tight, but should suffice; the issue |
462 | here is that 'dr->num_children' may inherently only specify a | 462 | here is that 'dr->num_children' may inherently only specify a |
@@ -485,16 +485,13 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, | |||
485 | else | 485 | else |
486 | { | 486 | { |
487 | if (dr->offset > data_len) | 487 | if (dr->offset > data_len) |
488 | return; /* oops */ | 488 | return; /* oops */ |
489 | dlen = GNUNET_MIN (data_len - dr->offset, DBLOCK_SIZE); | 489 | dlen = GNUNET_MIN (data_len - dr->offset, DBLOCK_SIZE); |
490 | } | 490 | } |
491 | GNUNET_CRYPTO_hash (&data[dr->offset], dlen, &in_chk.key); | 491 | GNUNET_CRYPTO_hash (&data[dr->offset], dlen, &in_chk.key); |
492 | GNUNET_CRYPTO_hash_to_aes_key (&in_chk.key, &sk, &iv); | 492 | GNUNET_CRYPTO_hash_to_aes_key (&in_chk.key, &sk, &iv); |
493 | if (-1 == GNUNET_CRYPTO_symmetric_encrypt (&data[dr->offset], | 493 | if (-1 == |
494 | dlen, | 494 | GNUNET_CRYPTO_symmetric_encrypt (&data[dr->offset], dlen, &sk, &iv, enc)) |
495 | &sk, | ||
496 | &iv, | ||
497 | enc)) | ||
498 | { | 495 | { |
499 | GNUNET_break (0); | 496 | GNUNET_break (0); |
500 | return; | 497 | return; |
@@ -507,9 +504,7 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, | |||
507 | dr->state = BRS_RECONSTRUCT_META_UP; | 504 | dr->state = BRS_RECONSTRUCT_META_UP; |
508 | break; | 505 | break; |
509 | case BRS_CHK_SET: | 506 | case BRS_CHK_SET: |
510 | if (0 != memcmp (&in_chk, | 507 | if (0 != memcmp (&in_chk, &dr->chk, sizeof (struct ContentHashKey))) |
511 | &dr->chk, | ||
512 | sizeof (struct ContentHashKey))) | ||
513 | { | 508 | { |
514 | /* other peer provided bogus meta data */ | 509 | /* other peer provided bogus meta data */ |
515 | GNUNET_break_op (0); | 510 | GNUNET_break_op (0); |
@@ -521,17 +516,17 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, | |||
521 | { | 516 | { |
522 | fh = GNUNET_DISK_file_open (fn, | 517 | fh = GNUNET_DISK_file_open (fn, |
523 | GNUNET_DISK_OPEN_READWRITE | | 518 | GNUNET_DISK_OPEN_READWRITE | |
524 | GNUNET_DISK_OPEN_CREATE | | 519 | GNUNET_DISK_OPEN_CREATE | |
525 | GNUNET_DISK_OPEN_TRUNCATE, | 520 | GNUNET_DISK_OPEN_TRUNCATE, |
526 | GNUNET_DISK_PERM_USER_READ | | 521 | GNUNET_DISK_PERM_USER_READ | |
527 | GNUNET_DISK_PERM_USER_WRITE | | 522 | GNUNET_DISK_PERM_USER_WRITE | |
528 | GNUNET_DISK_PERM_GROUP_READ | | 523 | GNUNET_DISK_PERM_GROUP_READ | |
529 | GNUNET_DISK_PERM_OTHER_READ); | 524 | GNUNET_DISK_PERM_OTHER_READ); |
530 | if (NULL == fh) | 525 | if (NULL == fh) |
531 | { | 526 | { |
532 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn); | 527 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn); |
533 | GNUNET_asprintf (&dc->emsg, | 528 | GNUNET_asprintf (&dc->emsg, |
534 | _("Failed to open file `%s' for writing"), | 529 | _ ("Failed to open file `%s' for writing"), |
535 | fn); | 530 | fn); |
536 | GNUNET_DISK_file_close (fh); | 531 | GNUNET_DISK_file_close (fh); |
537 | dr->state = BRS_ERROR; | 532 | dr->state = BRS_ERROR; |
@@ -543,7 +538,8 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, | |||
543 | if (data_len != GNUNET_DISK_file_write (fh, odata, odata_len)) | 538 | if (data_len != GNUNET_DISK_file_write (fh, odata, odata_len)) |
544 | { | 539 | { |
545 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn); | 540 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn); |
546 | GNUNET_asprintf (&dc->emsg, _("Failed to open file `%s' for writing"), | 541 | GNUNET_asprintf (&dc->emsg, |
542 | _ ("Failed to open file `%s' for writing"), | ||
547 | fn); | 543 | fn); |
548 | GNUNET_DISK_file_close (fh); | 544 | GNUNET_DISK_file_close (fh); |
549 | dr->state = BRS_ERROR; | 545 | dr->state = BRS_ERROR; |
@@ -564,13 +560,14 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, | |||
564 | pi.value.download.specifics.progress.data_len = dlen; | 560 | pi.value.download.specifics.progress.data_len = dlen; |
565 | pi.value.download.specifics.progress.depth = 0; | 561 | pi.value.download.specifics.progress.depth = 0; |
566 | pi.value.download.specifics.progress.respect_offered = 0; | 562 | pi.value.download.specifics.progress.respect_offered = 0; |
567 | pi.value.download.specifics.progress.block_download_duration = GNUNET_TIME_UNIT_ZERO; | 563 | pi.value.download.specifics.progress.block_download_duration = |
564 | GNUNET_TIME_UNIT_ZERO; | ||
568 | GNUNET_FS_download_make_status_ (&pi, dc); | 565 | GNUNET_FS_download_make_status_ (&pi, dc); |
569 | if ((NULL != dc->filename) && | 566 | if ((NULL != dc->filename) && |
570 | (0 != | 567 | (0 != truncate (dc->filename, |
571 | TRUNCATE (dc->filename, | 568 | GNUNET_ntohll (dc->uri->data.chk.file_length)))) |
572 | GNUNET_ntohll (dc->uri->data.chk.file_length)))) | 569 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
573 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "truncate", | 570 | "truncate", |
574 | dc->filename); | 571 | dc->filename); |
575 | check_completed (dc); | 572 | check_completed (dc); |
576 | break; | 573 | break; |
@@ -601,25 +598,27 @@ try_match_block (struct GNUNET_FS_DownloadContext *dc, | |||
601 | * @return 0 to continue extracting, 1 to abort | 598 | * @return 0 to continue extracting, 1 to abort |
602 | */ | 599 | */ |
603 | static int | 600 | static int |
604 | match_full_data (void *cls, const char *plugin_name, | 601 | match_full_data (void *cls, |
605 | enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, | 602 | const char *plugin_name, |
606 | const char *data_mime_type, const char *data, size_t data_len) | 603 | enum EXTRACTOR_MetaType type, |
604 | enum EXTRACTOR_MetaFormat format, | ||
605 | const char *data_mime_type, | ||
606 | const char *data, | ||
607 | size_t data_len) | ||
607 | { | 608 | { |
608 | struct GNUNET_FS_DownloadContext *dc = cls; | 609 | struct GNUNET_FS_DownloadContext *dc = cls; |
609 | 610 | ||
610 | if (EXTRACTOR_METATYPE_GNUNET_FULL_DATA != type) | 611 | if (EXTRACTOR_METATYPE_GNUNET_FULL_DATA != type) |
611 | return 0; | 612 | return 0; |
612 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u bytes of FD!\n", | 613 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
614 | "Found %u bytes of FD!\n", | ||
613 | (unsigned int) data_len); | 615 | (unsigned int) data_len); |
614 | if (GNUNET_FS_uri_chk_get_file_size (dc->uri) != data_len) | 616 | if (GNUNET_FS_uri_chk_get_file_size (dc->uri) != data_len) |
615 | { | 617 | { |
616 | GNUNET_break_op (0); | 618 | GNUNET_break_op (0); |
617 | return 1; /* bogus meta data */ | 619 | return 1; /* bogus meta data */ |
618 | } | 620 | } |
619 | try_match_block (dc, | 621 | try_match_block (dc, dc->top_request, data, data_len); |
620 | dc->top_request, | ||
621 | data, | ||
622 | data_len); | ||
623 | return 1; | 622 | return 1; |
624 | } | 623 | } |
625 | 624 | ||
@@ -644,8 +643,7 @@ propagate_up (struct DownloadRequest *dr) | |||
644 | for (i = 0; i < dr->num_children; i++) | 643 | for (i = 0; i < dr->num_children; i++) |
645 | if (dr->children[i]->state != BRS_DOWNLOAD_UP) | 644 | if (dr->children[i]->state != BRS_DOWNLOAD_UP) |
646 | break; | 645 | break; |
647 | } | 646 | } while (i == dr->num_children); |
648 | while (i == dr->num_children); | ||
649 | } | 647 | } |
650 | 648 | ||
651 | 649 | ||
@@ -682,20 +680,20 @@ try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc, | |||
682 | GNUNET_assert (len <= DBLOCK_SIZE); | 680 | GNUNET_assert (len <= DBLOCK_SIZE); |
683 | off = compute_disk_offset (total, dr->offset, dr->depth); | 681 | off = compute_disk_offset (total, dr->offset, dr->depth); |
684 | if (dc->old_file_size < off + len) | 682 | if (dc->old_file_size < off + len) |
685 | return; /* failure */ | 683 | return; /* failure */ |
686 | if (off != GNUNET_DISK_file_seek (dc->rfh, off, GNUNET_DISK_SEEK_SET)) | 684 | if (off != GNUNET_DISK_file_seek (dc->rfh, off, GNUNET_DISK_SEEK_SET)) |
687 | { | 685 | { |
688 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "seek", dc->filename); | 686 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "seek", dc->filename); |
689 | return; /* failure */ | 687 | return; /* failure */ |
690 | } | 688 | } |
691 | if (len != GNUNET_DISK_file_read (dc->rfh, block, len)) | 689 | if (len != GNUNET_DISK_file_read (dc->rfh, block, len)) |
692 | { | 690 | { |
693 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", dc->filename); | 691 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", dc->filename); |
694 | return; /* failure */ | 692 | return; /* failure */ |
695 | } | 693 | } |
696 | GNUNET_CRYPTO_hash (block, len, &key); | 694 | GNUNET_CRYPTO_hash (block, len, &key); |
697 | if (0 != memcmp (&key, &dr->chk.key, sizeof (struct GNUNET_HashCode))) | 695 | if (0 != memcmp (&key, &dr->chk.key, sizeof (struct GNUNET_HashCode))) |
698 | return; /* mismatch */ | 696 | return; /* mismatch */ |
699 | if (GNUNET_OK != | 697 | if (GNUNET_OK != |
700 | encrypt_existing_match (dc, &dr->chk, dr, block, len, GNUNET_NO)) | 698 | encrypt_existing_match (dc, &dr->chk, dr, block, len, GNUNET_NO)) |
701 | { | 699 | { |
@@ -728,10 +726,10 @@ try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc, | |||
728 | try_top_down_reconstruction (dc, drc); | 726 | try_top_down_reconstruction (dc, drc); |
729 | } | 727 | } |
730 | if (BRS_DOWNLOAD_UP != drc->state) | 728 | if (BRS_DOWNLOAD_UP != drc->state) |
731 | up_done = GNUNET_NO; /* children not all done */ | 729 | up_done = GNUNET_NO; /* children not all done */ |
732 | } | 730 | } |
733 | if (GNUNET_YES == up_done) | 731 | if (GNUNET_YES == up_done) |
734 | propagate_up (dr); /* children all done (or no children...) */ | 732 | propagate_up (dr); /* children all done (or no children...) */ |
735 | } | 733 | } |
736 | 734 | ||
737 | 735 | ||
@@ -744,17 +742,14 @@ try_top_down_reconstruction (struct GNUNET_FS_DownloadContext *dc, | |||
744 | * @return #GNUNET_OK | 742 | * @return #GNUNET_OK |
745 | */ | 743 | */ |
746 | static int | 744 | static int |
747 | retry_entry (void *cls, | 745 | retry_entry (void *cls, const struct GNUNET_HashCode *key, void *entry) |
748 | const struct GNUNET_HashCode *key, | ||
749 | void *entry) | ||
750 | { | 746 | { |
751 | struct GNUNET_FS_DownloadContext *dc = cls; | 747 | struct GNUNET_FS_DownloadContext *dc = cls; |
752 | struct DownloadRequest *dr = entry; | 748 | struct DownloadRequest *dr = entry; |
753 | struct SearchMessage *sm; | 749 | struct SearchMessage *sm; |
754 | struct GNUNET_MQ_Envelope *env; | 750 | struct GNUNET_MQ_Envelope *env; |
755 | 751 | ||
756 | env = GNUNET_MQ_msg (sm, | 752 | env = GNUNET_MQ_msg (sm, GNUNET_MESSAGE_TYPE_FS_START_SEARCH); |
757 | GNUNET_MESSAGE_TYPE_FS_START_SEARCH); | ||
758 | if (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY)) | 753 | if (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY)) |
759 | sm->options = htonl (GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY); | 754 | sm->options = htonl (GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY); |
760 | else | 755 | else |
@@ -766,8 +761,7 @@ retry_entry (void *cls, | |||
766 | sm->anonymity_level = htonl (dc->anonymity); | 761 | sm->anonymity_level = htonl (dc->anonymity); |
767 | sm->target = dc->target; | 762 | sm->target = dc->target; |
768 | sm->query = dr->chk.query; | 763 | sm->query = dr->chk.query; |
769 | GNUNET_MQ_send (dc->mq, | 764 | GNUNET_MQ_send (dc->mq, env); |
770 | env); | ||
771 | return GNUNET_OK; | 765 | return GNUNET_OK; |
772 | } | 766 | } |
773 | 767 | ||
@@ -817,20 +811,17 @@ schedule_block_download (struct GNUNET_FS_DownloadContext *dc, | |||
817 | (unsigned long long) dr->offset, | 811 | (unsigned long long) dr->offset, |
818 | dr->depth, | 812 | dr->depth, |
819 | GNUNET_h2s (&dr->chk.query)); | 813 | GNUNET_h2s (&dr->chk.query)); |
820 | if (GNUNET_NO != | 814 | if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains_value (dc->active, |
821 | GNUNET_CONTAINER_multihashmap_contains_value (dc->active, | 815 | &dr->chk.query, |
822 | &dr->chk.query, | 816 | dr)) |
823 | dr)) | 817 | return; /* already active */ |
824 | return; /* already active */ | ||
825 | GNUNET_CONTAINER_multihashmap_put (dc->active, | 818 | GNUNET_CONTAINER_multihashmap_put (dc->active, |
826 | &dr->chk.query, | 819 | &dr->chk.query, |
827 | dr, | 820 | dr, |
828 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 821 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
829 | if (NULL == dc->mq) | 822 | if (NULL == dc->mq) |
830 | return; /* download not active */ | 823 | return; /* download not active */ |
831 | retry_entry (dc, | 824 | retry_entry (dc, &dr->chk.query, dr); |
832 | &dr->chk.query, | ||
833 | dr); | ||
834 | } | 825 | } |
835 | 826 | ||
836 | 827 | ||
@@ -867,7 +858,7 @@ trigger_recursive_download (void *cls, | |||
867 | char *sfn; | 858 | char *sfn; |
868 | 859 | ||
869 | if (NULL == uri) | 860 | if (NULL == uri) |
870 | return; /* entry for the directory itself */ | 861 | return; /* entry for the directory itself */ |
871 | cpos = dc->child_head; | 862 | cpos = dc->child_head; |
872 | while (NULL != cpos) | 863 | while (NULL != cpos) |
873 | { | 864 | { |
@@ -877,7 +868,7 @@ trigger_recursive_download (void *cls, | |||
877 | cpos = cpos->next; | 868 | cpos = cpos->next; |
878 | } | 869 | } |
879 | if (NULL != cpos) | 870 | if (NULL != cpos) |
880 | return; /* already exists */ | 871 | return; /* already exists */ |
881 | fn = NULL; | 872 | fn = NULL; |
882 | if (NULL == filename) | 873 | if (NULL == filename) |
883 | { | 874 | { |
@@ -892,7 +883,9 @@ trigger_recursive_download (void *cls, | |||
892 | { | 883 | { |
893 | ext = fn; | 884 | ext = fn; |
894 | us = GNUNET_FS_uri_to_string (uri); | 885 | us = GNUNET_FS_uri_to_string (uri); |
895 | GNUNET_asprintf (&fn, "%s%s", &us[strlen (GNUNET_FS_URI_CHK_PREFIX)], | 886 | GNUNET_asprintf (&fn, |
887 | "%s%s", | ||
888 | &us[strlen (GNUNET_FS_URI_CHK_PREFIX)], | ||
896 | ext); | 889 | ext); |
897 | GNUNET_free (ext); | 890 | GNUNET_free (ext); |
898 | GNUNET_free (us); | 891 | GNUNET_free (us); |
@@ -920,25 +913,28 @@ trigger_recursive_download (void *cls, | |||
920 | else | 913 | else |
921 | { | 914 | { |
922 | dn = GNUNET_strdup (dc->filename); | 915 | dn = GNUNET_strdup (dc->filename); |
923 | GNUNET_break ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && | 916 | GNUNET_break ( |
924 | (NULL != | 917 | (strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && |
925 | strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT), | 918 | (NULL != strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT), |
926 | GNUNET_FS_DIRECTORY_EXT))); | 919 | GNUNET_FS_DIRECTORY_EXT))); |
927 | sfn = GNUNET_strdup (filename); | 920 | sfn = GNUNET_strdup (filename); |
928 | while ((strlen (sfn) > 0) && ('/' == filename[strlen (sfn) - 1])) | 921 | while ((strlen (sfn) > 0) && ('/' == filename[strlen (sfn) - 1])) |
929 | sfn[strlen (sfn) - 1] = '\0'; | 922 | sfn[strlen (sfn) - 1] = '\0'; |
930 | if ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && | 923 | if ((strlen (dn) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && |
931 | (NULL != | 924 | (NULL != strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT), |
932 | strstr (dn + strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT), | 925 | GNUNET_FS_DIRECTORY_EXT))) |
933 | GNUNET_FS_DIRECTORY_EXT))) | ||
934 | dn[strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT)] = '\0'; | 926 | dn[strlen (dn) - strlen (GNUNET_FS_DIRECTORY_EXT)] = '\0'; |
935 | if ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) && | 927 | if ((GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta)) && |
936 | ((strlen (filename) < strlen (GNUNET_FS_DIRECTORY_EXT)) || | 928 | ((strlen (filename) < strlen (GNUNET_FS_DIRECTORY_EXT)) || |
937 | (NULL == | 929 | (NULL == strstr (filename + strlen (filename) - |
938 | strstr (filename + strlen (filename) - | 930 | strlen (GNUNET_FS_DIRECTORY_EXT), |
939 | strlen (GNUNET_FS_DIRECTORY_EXT), GNUNET_FS_DIRECTORY_EXT)))) | 931 | GNUNET_FS_DIRECTORY_EXT)))) |
940 | { | 932 | { |
941 | GNUNET_asprintf (&full_name, "%s%s%s%s", dn, DIR_SEPARATOR_STR, sfn, | 933 | GNUNET_asprintf (&full_name, |
934 | "%s%s%s%s", | ||
935 | dn, | ||
936 | DIR_SEPARATOR_STR, | ||
937 | sfn, | ||
942 | GNUNET_FS_DIRECTORY_EXT); | 938 | GNUNET_FS_DIRECTORY_EXT); |
943 | } | 939 | } |
944 | else | 940 | else |
@@ -952,8 +948,8 @@ trigger_recursive_download (void *cls, | |||
952 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (full_name))) | 948 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (full_name))) |
953 | { | 949 | { |
954 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 950 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
955 | _ | 951 | _ ( |
956 | ("Failed to create directory for recursive download of `%s'\n"), | 952 | "Failed to create directory for recursive download of `%s'\n"), |
957 | full_name); | 953 | full_name); |
958 | GNUNET_free (full_name); | 954 | GNUNET_free (full_name); |
959 | GNUNET_free_non_null (fn); | 955 | GNUNET_free_non_null (fn); |
@@ -964,8 +960,8 @@ trigger_recursive_download (void *cls, | |||
964 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 960 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
965 | "Triggering recursive download of size %llu with %u bytes MD\n", | 961 | "Triggering recursive download of size %llu with %u bytes MD\n", |
966 | (unsigned long long) GNUNET_FS_uri_chk_get_file_size (uri), | 962 | (unsigned long long) GNUNET_FS_uri_chk_get_file_size (uri), |
967 | (unsigned int) | 963 | (unsigned int) GNUNET_CONTAINER_meta_data_get_serialized_size ( |
968 | GNUNET_CONTAINER_meta_data_get_serialized_size (meta)); | 964 | meta)); |
969 | GNUNET_FS_download_start (dc->h, | 965 | GNUNET_FS_download_start (dc->h, |
970 | uri, | 966 | uri, |
971 | meta, | 967 | meta, |
@@ -1029,26 +1025,29 @@ process_result_with_request (void *cls, | |||
1029 | int i; | 1025 | int i; |
1030 | struct ContentHashKey *chkarr; | 1026 | struct ContentHashKey *chkarr; |
1031 | 1027 | ||
1032 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1028 | GNUNET_log ( |
1033 | "Received %u byte block `%s' matching pending request at depth %u and offset %llu/%llu\n", | 1029 | GNUNET_ERROR_TYPE_DEBUG, |
1034 | (unsigned int) prc->size, | 1030 | "Received %u byte block `%s' matching pending request at depth %u and offset %llu/%llu\n", |
1035 | GNUNET_h2s (key), | 1031 | (unsigned int) prc->size, |
1036 | dr->depth, | 1032 | GNUNET_h2s (key), |
1037 | (unsigned long long) dr->offset, | 1033 | dr->depth, |
1038 | (unsigned long long) GNUNET_ntohll (dc->uri->data. | 1034 | (unsigned long long) dr->offset, |
1039 | chk.file_length)); | 1035 | (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length)); |
1040 | bs = GNUNET_FS_tree_calculate_block_size (GNUNET_ntohll | 1036 | bs = GNUNET_FS_tree_calculate_block_size (GNUNET_ntohll ( |
1041 | (dc->uri->data.chk.file_length), | 1037 | dc->uri->data.chk.file_length), |
1042 | dr->offset, dr->depth); | 1038 | dr->offset, |
1039 | dr->depth); | ||
1043 | if (prc->size != bs) | 1040 | if (prc->size != bs) |
1044 | { | 1041 | { |
1045 | GNUNET_asprintf (&dc->emsg, | 1042 | GNUNET_asprintf ( |
1046 | _ | 1043 | &dc->emsg, |
1047 | ("Internal error or bogus download URI (expected %u bytes at depth %u and offset %llu/%llu, got %u bytes)"), | 1044 | _ ( |
1048 | bs, dr->depth, (unsigned long long) dr->offset, | 1045 | "Internal error or bogus download URI (expected %u bytes at depth %u and offset %llu/%llu, got %u bytes)"), |
1049 | (unsigned long long) GNUNET_ntohll (dc->uri->data. | 1046 | bs, |
1050 | chk.file_length), | 1047 | dr->depth, |
1051 | prc->size); | 1048 | (unsigned long long) dr->offset, |
1049 | (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length), | ||
1050 | prc->size); | ||
1052 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", dc->emsg); | 1051 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", dc->emsg); |
1053 | while (NULL != dr->parent) | 1052 | while (NULL != dr->parent) |
1054 | { | 1053 | { |
@@ -1059,69 +1058,61 @@ process_result_with_request (void *cls, | |||
1059 | goto signal_error; | 1058 | goto signal_error; |
1060 | } | 1059 | } |
1061 | 1060 | ||
1062 | (void) GNUNET_CONTAINER_multihashmap_remove (dc->active, | 1061 | (void) GNUNET_CONTAINER_multihashmap_remove (dc->active, &prc->query, dr); |
1063 | &prc->query, | 1062 | GNUNET_CRYPTO_hash_to_aes_key (&dr->chk.key, &skey, &iv); |
1064 | dr); | 1063 | if (-1 == |
1065 | GNUNET_CRYPTO_hash_to_aes_key (&dr->chk.key, | 1064 | GNUNET_CRYPTO_symmetric_decrypt (prc->data, prc->size, &skey, &iv, pt)) |
1066 | &skey, | ||
1067 | &iv); | ||
1068 | if (-1 == GNUNET_CRYPTO_symmetric_decrypt (prc->data, | ||
1069 | prc->size, | ||
1070 | &skey, | ||
1071 | &iv, | ||
1072 | pt)) | ||
1073 | { | 1065 | { |
1074 | GNUNET_break (0); | 1066 | GNUNET_break (0); |
1075 | dc->emsg = GNUNET_strdup (_("internal error decrypting content")); | 1067 | dc->emsg = GNUNET_strdup (_ ("internal error decrypting content")); |
1076 | goto signal_error; | 1068 | goto signal_error; |
1077 | } | 1069 | } |
1078 | off = | 1070 | off = compute_disk_offset (GNUNET_ntohll (dc->uri->data.chk.file_length), |
1079 | compute_disk_offset (GNUNET_ntohll (dc->uri->data.chk.file_length), | 1071 | dr->offset, |
1080 | dr->offset, | 1072 | dr->depth); |
1081 | dr->depth); | ||
1082 | /* save to disk */ | 1073 | /* save to disk */ |
1083 | if ((GNUNET_YES == prc->do_store) && | 1074 | if ((GNUNET_YES == prc->do_store) && |
1084 | ((NULL != dc->filename) || (is_recursive_download (dc))) && | 1075 | ((NULL != dc->filename) || (is_recursive_download (dc))) && |
1085 | ((dr->depth == dc->treedepth) || | 1076 | ((dr->depth == dc->treedepth) || |
1086 | (0 == (dc->options & GNUNET_FS_DOWNLOAD_NO_TEMPORARIES)))) | 1077 | (0 == (dc->options & GNUNET_FS_DOWNLOAD_NO_TEMPORARIES)))) |
1087 | { | 1078 | { |
1088 | fh = GNUNET_DISK_file_open (NULL != dc->filename | 1079 | fh = GNUNET_DISK_file_open (NULL != dc->filename ? dc->filename |
1089 | ? dc->filename : dc->temp_filename, | 1080 | : dc->temp_filename, |
1090 | GNUNET_DISK_OPEN_READWRITE | | 1081 | GNUNET_DISK_OPEN_READWRITE | |
1091 | GNUNET_DISK_OPEN_CREATE, | 1082 | GNUNET_DISK_OPEN_CREATE, |
1092 | GNUNET_DISK_PERM_USER_READ | | 1083 | GNUNET_DISK_PERM_USER_READ | |
1093 | GNUNET_DISK_PERM_USER_WRITE | | 1084 | GNUNET_DISK_PERM_USER_WRITE | |
1094 | GNUNET_DISK_PERM_GROUP_READ | | 1085 | GNUNET_DISK_PERM_GROUP_READ | |
1095 | GNUNET_DISK_PERM_OTHER_READ); | 1086 | GNUNET_DISK_PERM_OTHER_READ); |
1096 | if (NULL == fh) | 1087 | if (NULL == fh) |
1097 | { | 1088 | { |
1098 | GNUNET_asprintf (&dc->emsg, | 1089 | GNUNET_asprintf (&dc->emsg, |
1099 | _("Download failed: could not open file `%s': %s"), | 1090 | _ ("Download failed: could not open file `%s': %s"), |
1100 | dc->filename, STRERROR (errno)); | 1091 | dc->filename, |
1092 | strerror (errno)); | ||
1101 | goto signal_error; | 1093 | goto signal_error; |
1102 | } | 1094 | } |
1103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1095 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1104 | "Saving decrypted block to disk at offset %llu\n", | 1096 | "Saving decrypted block to disk at offset %llu\n", |
1105 | (unsigned long long) off); | 1097 | (unsigned long long) off); |
1106 | if ((off != GNUNET_DISK_file_seek (fh, | 1098 | if ((off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET))) |
1107 | off, | ||
1108 | GNUNET_DISK_SEEK_SET))) | ||
1109 | { | 1099 | { |
1110 | GNUNET_asprintf (&dc->emsg, | 1100 | GNUNET_asprintf (&dc->emsg, |
1111 | _("Failed to seek to offset %llu in file `%s': %s"), | 1101 | _ ("Failed to seek to offset %llu in file `%s': %s"), |
1112 | (unsigned long long) off, | 1102 | (unsigned long long) off, |
1113 | dc->filename, | 1103 | dc->filename, |
1114 | STRERROR (errno)); | 1104 | strerror (errno)); |
1115 | goto signal_error; | 1105 | goto signal_error; |
1116 | } | 1106 | } |
1117 | if (prc->size != GNUNET_DISK_file_write (fh, pt, prc->size)) | 1107 | if (prc->size != GNUNET_DISK_file_write (fh, pt, prc->size)) |
1118 | { | 1108 | { |
1119 | GNUNET_asprintf (&dc->emsg, | 1109 | GNUNET_asprintf ( |
1120 | _("Failed to write block of %u bytes at offset %llu in file `%s': %s"), | 1110 | &dc->emsg, |
1121 | (unsigned int) prc->size, | 1111 | _ ("Failed to write block of %u bytes at offset %llu in file `%s': %s"), |
1122 | (unsigned long long) off, | 1112 | (unsigned int) prc->size, |
1123 | dc->filename, | 1113 | (unsigned long long) off, |
1124 | STRERROR (errno)); | 1114 | dc->filename, |
1115 | strerror (errno)); | ||
1125 | goto signal_error; | 1116 | goto signal_error; |
1126 | } | 1117 | } |
1127 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh)); | 1118 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh)); |
@@ -1153,8 +1144,11 @@ process_result_with_request (void *cls, | |||
1153 | * says it is a directory or if no meta data is given AND filename | 1144 | * says it is a directory or if no meta data is given AND filename |
1154 | * ends in '.gnd' (top-level case) */ | 1145 | * ends in '.gnd' (top-level case) */ |
1155 | if (is_recursive_download (dc)) | 1146 | if (is_recursive_download (dc)) |
1156 | GNUNET_FS_directory_list_contents (prc->size, pt, off, | 1147 | GNUNET_FS_directory_list_contents (prc->size, |
1157 | &trigger_recursive_download, dc); | 1148 | pt, |
1149 | off, | ||
1150 | &trigger_recursive_download, | ||
1151 | dc); | ||
1158 | } | 1152 | } |
1159 | GNUNET_assert (dc->completed <= dc->length); | 1153 | GNUNET_assert (dc->completed <= dc->length); |
1160 | dr->state = BRS_DOWNLOAD_DOWN; | 1154 | dr->state = BRS_DOWNLOAD_DOWN; |
@@ -1164,13 +1158,15 @@ process_result_with_request (void *cls, | |||
1164 | pi.value.download.specifics.progress.data_len = prc->size; | 1158 | pi.value.download.specifics.progress.data_len = prc->size; |
1165 | pi.value.download.specifics.progress.depth = dr->depth; | 1159 | pi.value.download.specifics.progress.depth = dr->depth; |
1166 | pi.value.download.specifics.progress.respect_offered = prc->respect_offered; | 1160 | pi.value.download.specifics.progress.respect_offered = prc->respect_offered; |
1167 | pi.value.download.specifics.progress.num_transmissions = prc->num_transmissions; | 1161 | pi.value.download.specifics.progress.num_transmissions = |
1168 | if (prc->last_transmission.abs_value_us != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) | 1162 | prc->num_transmissions; |
1169 | pi.value.download.specifics.progress.block_download_duration | 1163 | if (prc->last_transmission.abs_value_us != |
1170 | = GNUNET_TIME_absolute_get_duration (prc->last_transmission); | 1164 | GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) |
1165 | pi.value.download.specifics.progress.block_download_duration = | ||
1166 | GNUNET_TIME_absolute_get_duration (prc->last_transmission); | ||
1171 | else | 1167 | else |
1172 | pi.value.download.specifics.progress.block_download_duration | 1168 | pi.value.download.specifics.progress.block_download_duration = |
1173 | = GNUNET_TIME_UNIT_ZERO; /* found locally */ | 1169 | GNUNET_TIME_UNIT_ZERO; /* found locally */ |
1174 | GNUNET_FS_download_make_status_ (&pi, dc); | 1170 | GNUNET_FS_download_make_status_ (&pi, dc); |
1175 | if (0 == dr->depth) | 1171 | if (0 == dr->depth) |
1176 | propagate_up (dr); | 1172 | propagate_up (dr); |
@@ -1180,15 +1176,15 @@ process_result_with_request (void *cls, | |||
1180 | /* download completed, signal */ | 1176 | /* download completed, signal */ |
1181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1182 | "Download completed, truncating file to desired length %llu\n", | 1178 | "Download completed, truncating file to desired length %llu\n", |
1183 | (unsigned long long) GNUNET_ntohll (dc->uri->data. | 1179 | (unsigned long long) GNUNET_ntohll ( |
1184 | chk.file_length)); | 1180 | dc->uri->data.chk.file_length)); |
1185 | /* truncate file to size (since we store IBlocks at the end) */ | 1181 | /* truncate file to size (since we store IBlocks at the end) */ |
1186 | if (NULL != dc->filename) | 1182 | if (NULL != dc->filename) |
1187 | { | 1183 | { |
1188 | if (0 != | 1184 | if (0 != truncate (dc->filename, |
1189 | TRUNCATE (dc->filename, | 1185 | GNUNET_ntohll (dc->uri->data.chk.file_length))) |
1190 | GNUNET_ntohll (dc->uri->data.chk.file_length))) | 1186 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
1191 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "truncate", | 1187 | "truncate", |
1192 | dc->filename); | 1188 | dc->filename); |
1193 | } | 1189 | } |
1194 | GNUNET_assert (0 == dr->depth); | 1190 | GNUNET_assert (0 == dr->depth); |
@@ -1201,9 +1197,11 @@ process_result_with_request (void *cls, | |||
1201 | return GNUNET_YES; | 1197 | return GNUNET_YES; |
1202 | } | 1198 | } |
1203 | 1199 | ||
1204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1200 | GNUNET_log ( |
1205 | "Triggering downloads of children (this block was at depth %u and offset %llu)\n", | 1201 | GNUNET_ERROR_TYPE_DEBUG, |
1206 | dr->depth, (unsigned long long) dr->offset); | 1202 | "Triggering downloads of children (this block was at depth %u and offset %llu)\n", |
1203 | dr->depth, | ||
1204 | (unsigned long long) dr->offset); | ||
1207 | GNUNET_assert (0 == (prc->size % sizeof (struct ContentHashKey))); | 1205 | GNUNET_assert (0 == (prc->size % sizeof (struct ContentHashKey))); |
1208 | chkarr = (struct ContentHashKey *) pt; | 1206 | chkarr = (struct ContentHashKey *) pt; |
1209 | for (i = dr->num_children - 1; i >= 0; i--) | 1207 | for (i = dr->num_children - 1; i >= 0; i--) |
@@ -1214,16 +1212,17 @@ process_result_with_request (void *cls, | |||
1214 | case BRS_INIT: | 1212 | case BRS_INIT: |
1215 | if ((drc->chk_idx + 1) * sizeof (struct ContentHashKey) > prc->size) | 1213 | if ((drc->chk_idx + 1) * sizeof (struct ContentHashKey) > prc->size) |
1216 | { | 1214 | { |
1217 | /* 'chkarr' does not have enough space for this chk_idx; | 1215 | /* 'chkarr' does not have enough space for this chk_idx; |
1218 | internal error! */ | 1216 | internal error! */ |
1219 | GNUNET_break (0); GNUNET_assert (0); | 1217 | GNUNET_break (0); |
1220 | dc->emsg = GNUNET_strdup (_("internal error decoding tree")); | 1218 | GNUNET_assert (0); |
1221 | goto signal_error; | 1219 | dc->emsg = GNUNET_strdup (_ ("internal error decoding tree")); |
1220 | goto signal_error; | ||
1222 | } | 1221 | } |
1223 | drc->chk = chkarr[drc->chk_idx]; | 1222 | drc->chk = chkarr[drc->chk_idx]; |
1224 | drc->state = BRS_CHK_SET; | 1223 | drc->state = BRS_CHK_SET; |
1225 | if (GNUNET_YES == dc->issue_requests) | 1224 | if (GNUNET_YES == dc->issue_requests) |
1226 | schedule_block_download (dc, drc); | 1225 | schedule_block_download (dc, drc); |
1227 | break; | 1226 | break; |
1228 | case BRS_RECONSTRUCT_DOWN: | 1227 | case BRS_RECONSTRUCT_DOWN: |
1229 | GNUNET_assert (0); | 1228 | GNUNET_assert (0); |
@@ -1282,8 +1281,7 @@ signal_error: | |||
1282 | * @param msg message received | 1281 | * @param msg message received |
1283 | */ | 1282 | */ |
1284 | static int | 1283 | static int |
1285 | check_put (void *cls, | 1284 | check_put (void *cls, const struct ClientPutMessage *cm) |
1286 | const struct ClientPutMessage *cm) | ||
1287 | { | 1285 | { |
1288 | /* any varsize length is OK */ | 1286 | /* any varsize length is OK */ |
1289 | return GNUNET_OK; | 1287 | return GNUNET_OK; |
@@ -1298,8 +1296,7 @@ check_put (void *cls, | |||
1298 | * @param msg message received | 1296 | * @param msg message received |
1299 | */ | 1297 | */ |
1300 | static void | 1298 | static void |
1301 | handle_put (void *cls, | 1299 | handle_put (void *cls, const struct ClientPutMessage *cm) |
1302 | const struct ClientPutMessage *cm) | ||
1303 | { | 1300 | { |
1304 | struct GNUNET_FS_DownloadContext *dc = cls; | 1301 | struct GNUNET_FS_DownloadContext *dc = cls; |
1305 | uint16_t msize = ntohs (cm->header.size) - sizeof (*cm); | 1302 | uint16_t msize = ntohs (cm->header.size) - sizeof (*cm); |
@@ -1313,9 +1310,7 @@ handle_put (void *cls, | |||
1313 | prc.do_store = GNUNET_YES; | 1310 | prc.do_store = GNUNET_YES; |
1314 | prc.respect_offered = ntohl (cm->respect_offered); | 1311 | prc.respect_offered = ntohl (cm->respect_offered); |
1315 | prc.num_transmissions = ntohl (cm->num_transmissions); | 1312 | prc.num_transmissions = ntohl (cm->num_transmissions); |
1316 | GNUNET_CRYPTO_hash (prc.data, | 1313 | GNUNET_CRYPTO_hash (prc.data, msize, &prc.query); |
1317 | msize, | ||
1318 | &prc.query); | ||
1319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1314 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1320 | "Received result for query `%s' from FS service\n", | 1315 | "Received result for query `%s' from FS service\n", |
1321 | GNUNET_h2s (&prc.query)); | 1316 | GNUNET_h2s (&prc.query)); |
@@ -1335,8 +1330,7 @@ handle_put (void *cls, | |||
1335 | * @param error error code | 1330 | * @param error error code |
1336 | */ | 1331 | */ |
1337 | static void | 1332 | static void |
1338 | download_mq_error_handler (void *cls, | 1333 | download_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
1339 | enum GNUNET_MQ_Error error) | ||
1340 | { | 1334 | { |
1341 | struct GNUNET_FS_DownloadContext *dc = cls; | 1335 | struct GNUNET_FS_DownloadContext *dc = cls; |
1342 | 1336 | ||
@@ -1360,13 +1354,12 @@ static void | |||
1360 | do_reconnect (void *cls) | 1354 | do_reconnect (void *cls) |
1361 | { | 1355 | { |
1362 | struct GNUNET_FS_DownloadContext *dc = cls; | 1356 | struct GNUNET_FS_DownloadContext *dc = cls; |
1363 | struct GNUNET_MQ_MessageHandler handlers[] = { | 1357 | struct GNUNET_MQ_MessageHandler handlers[] = |
1364 | GNUNET_MQ_hd_var_size (put, | 1358 | {GNUNET_MQ_hd_var_size (put, |
1365 | GNUNET_MESSAGE_TYPE_FS_PUT, | 1359 | GNUNET_MESSAGE_TYPE_FS_PUT, |
1366 | struct ClientPutMessage, | 1360 | struct ClientPutMessage, |
1367 | dc), | 1361 | dc), |
1368 | GNUNET_MQ_handler_end () | 1362 | GNUNET_MQ_handler_end ()}; |
1369 | }; | ||
1370 | 1363 | ||
1371 | dc->task = NULL; | 1364 | dc->task = NULL; |
1372 | dc->mq = GNUNET_CLIENT_connect (dc->h->cfg, | 1365 | dc->mq = GNUNET_CLIENT_connect (dc->h->cfg, |
@@ -1377,13 +1370,12 @@ do_reconnect (void *cls) | |||
1377 | if (NULL == dc->mq) | 1370 | if (NULL == dc->mq) |
1378 | { | 1371 | { |
1379 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1372 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1380 | "Connecting to `%s'-service failed, will try again.\n", "FS"); | 1373 | "Connecting to `%s'-service failed, will try again.\n", |
1374 | "FS"); | ||
1381 | try_reconnect (dc); | 1375 | try_reconnect (dc); |
1382 | return; | 1376 | return; |
1383 | } | 1377 | } |
1384 | GNUNET_CONTAINER_multihashmap_iterate (dc->active, | 1378 | GNUNET_CONTAINER_multihashmap_iterate (dc->active, &retry_entry, dc); |
1385 | &retry_entry, | ||
1386 | dc); | ||
1387 | } | 1379 | } |
1388 | 1380 | ||
1389 | 1381 | ||
@@ -1411,13 +1403,11 @@ try_reconnect (struct GNUNET_FS_DownloadContext *dc) | |||
1411 | 1403 | ||
1412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1404 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1413 | "Will try to reconnect in %s\n", | 1405 | "Will try to reconnect in %s\n", |
1414 | GNUNET_STRINGS_relative_time_to_string (dc->reconnect_backoff, | 1406 | GNUNET_STRINGS_relative_time_to_string (dc->reconnect_backoff, |
1415 | GNUNET_YES)); | 1407 | GNUNET_YES)); |
1416 | GNUNET_break (NULL != dc->job_queue); | 1408 | GNUNET_break (NULL != dc->job_queue); |
1417 | dc->task = | 1409 | dc->task = |
1418 | GNUNET_SCHEDULER_add_delayed (dc->reconnect_backoff, | 1410 | GNUNET_SCHEDULER_add_delayed (dc->reconnect_backoff, &do_reconnect, dc); |
1419 | &do_reconnect, | ||
1420 | dc); | ||
1421 | } | 1411 | } |
1422 | 1412 | ||
1423 | 1413 | ||
@@ -1437,11 +1427,9 @@ activate_fs_download (void *cls) | |||
1437 | GNUNET_assert (NULL != dc->active); | 1427 | GNUNET_assert (NULL != dc->active); |
1438 | do_reconnect (dc); | 1428 | do_reconnect (dc); |
1439 | if (NULL != dc->mq) | 1429 | if (NULL != dc->mq) |
1440 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1430 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download activated\n"); |
1441 | "Download activated\n"); | ||
1442 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ACTIVE; | 1431 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ACTIVE; |
1443 | GNUNET_FS_download_make_status_ (&pi, | 1432 | GNUNET_FS_download_make_status_ (&pi, dc); |
1444 | dc); | ||
1445 | } | 1433 | } |
1446 | 1434 | ||
1447 | 1435 | ||
@@ -1456,16 +1444,14 @@ deactivate_fs_download (void *cls) | |||
1456 | struct GNUNET_FS_DownloadContext *dc = cls; | 1444 | struct GNUNET_FS_DownloadContext *dc = cls; |
1457 | struct GNUNET_FS_ProgressInfo pi; | 1445 | struct GNUNET_FS_ProgressInfo pi; |
1458 | 1446 | ||
1459 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1447 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download deactivated\n"); |
1460 | "Download deactivated\n"); | ||
1461 | if (NULL != dc->mq) | 1448 | if (NULL != dc->mq) |
1462 | { | 1449 | { |
1463 | GNUNET_MQ_destroy (dc->mq); | 1450 | GNUNET_MQ_destroy (dc->mq); |
1464 | dc->mq = NULL; | 1451 | dc->mq = NULL; |
1465 | } | 1452 | } |
1466 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_INACTIVE; | 1453 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_INACTIVE; |
1467 | GNUNET_FS_download_make_status_ (&pi, | 1454 | GNUNET_FS_download_make_status_ (&pi, dc); |
1468 | dc); | ||
1469 | } | 1455 | } |
1470 | 1456 | ||
1471 | 1457 | ||
@@ -1490,8 +1476,8 @@ deactivate_fs_download (void *cls) | |||
1490 | */ | 1476 | */ |
1491 | static struct DownloadRequest * | 1477 | static struct DownloadRequest * |
1492 | create_download_request (struct DownloadRequest *parent, | 1478 | create_download_request (struct DownloadRequest *parent, |
1493 | unsigned int chk_idx, | 1479 | unsigned int chk_idx, |
1494 | unsigned int depth, | 1480 | unsigned int depth, |
1495 | uint64_t dr_offset, | 1481 | uint64_t dr_offset, |
1496 | uint64_t file_start_offset, | 1482 | uint64_t file_start_offset, |
1497 | uint64_t desired_length) | 1483 | uint64_t desired_length) |
@@ -1523,36 +1509,35 @@ create_download_request (struct DownloadRequest *parent, | |||
1523 | } | 1509 | } |
1524 | 1510 | ||
1525 | /* calculate index of last block at this level that is interesting (rounded up) */ | 1511 | /* calculate index of last block at this level that is interesting (rounded up) */ |
1526 | dr->num_children = (file_start_offset + desired_length - dr_offset) / child_block_size; | 1512 | dr->num_children = |
1513 | (file_start_offset + desired_length - dr_offset) / child_block_size; | ||
1527 | if (dr->num_children * child_block_size < | 1514 | if (dr->num_children * child_block_size < |
1528 | file_start_offset + desired_length - dr_offset) | 1515 | file_start_offset + desired_length - dr_offset) |
1529 | dr->num_children++; /* round up */ | 1516 | dr->num_children++; /* round up */ |
1530 | GNUNET_assert (dr->num_children > head_skip); | 1517 | GNUNET_assert (dr->num_children > head_skip); |
1531 | dr->num_children -= head_skip; | 1518 | dr->num_children -= head_skip; |
1532 | if (dr->num_children > CHK_PER_INODE) | 1519 | if (dr->num_children > CHK_PER_INODE) |
1533 | dr->num_children = CHK_PER_INODE; /* cap at max */ | 1520 | dr->num_children = CHK_PER_INODE; /* cap at max */ |
1534 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1521 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1535 | "Block at offset %llu and depth %u has %u children\n", | 1522 | "Block at offset %llu and depth %u has %u children\n", |
1536 | (unsigned long long) dr_offset, | 1523 | (unsigned long long) dr_offset, |
1537 | depth, | 1524 | depth, |
1538 | dr->num_children); | 1525 | dr->num_children); |
1539 | 1526 | ||
1540 | /* now we can get the total number of *interesting* children for this block */ | 1527 | /* now we can get the total number of *interesting* children for this block */ |
1541 | 1528 | ||
1542 | /* why else would we have gotten here to begin with? (that'd be a bad logic error) */ | 1529 | /* why else would we have gotten here to begin with? (that'd be a bad logic error) */ |
1543 | GNUNET_assert (dr->num_children > 0); | 1530 | GNUNET_assert (dr->num_children > 0); |
1544 | 1531 | ||
1545 | dr->children = | 1532 | dr->children = GNUNET_new_array (dr->num_children, struct DownloadRequest *); |
1546 | GNUNET_new_array (dr->num_children, | ||
1547 | struct DownloadRequest *); | ||
1548 | for (i = 0; i < dr->num_children; i++) | 1533 | for (i = 0; i < dr->num_children; i++) |
1549 | { | 1534 | { |
1550 | dr->children[i] = | 1535 | dr->children[i] = |
1551 | create_download_request (dr, | 1536 | create_download_request (dr, |
1552 | i + head_skip, | 1537 | i + head_skip, |
1553 | depth - 1, | 1538 | depth - 1, |
1554 | dr_offset + (i + head_skip) * child_block_size, | 1539 | dr_offset + (i + head_skip) * child_block_size, |
1555 | file_start_offset, | 1540 | file_start_offset, |
1556 | desired_length); | 1541 | desired_length); |
1557 | } | 1542 | } |
1558 | return dr; | 1543 | return dr; |
@@ -1583,8 +1568,7 @@ reconstruct_cont (void *cls) | |||
1583 | } | 1568 | } |
1584 | /* start "normal" download */ | 1569 | /* start "normal" download */ |
1585 | dc->issue_requests = GNUNET_YES; | 1570 | dc->issue_requests = GNUNET_YES; |
1586 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1571 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting normal download\n"); |
1587 | "Starting normal download\n"); | ||
1588 | schedule_block_download (dc, dc->top_request); | 1572 | schedule_block_download (dc, dc->top_request); |
1589 | } | 1573 | } |
1590 | 1574 | ||
@@ -1646,29 +1630,29 @@ reconstruct_cb (void *cls, | |||
1646 | if (chld < dr->children[0]->chk_idx) | 1630 | if (chld < dr->children[0]->chk_idx) |
1647 | { | 1631 | { |
1648 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1632 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1649 | "Block %u < %u irrelevant for our range\n", | 1633 | "Block %u < %u irrelevant for our range\n", |
1650 | chld, | 1634 | chld, |
1651 | dr->children[0]->chk_idx); | 1635 | dr->children[0]->chk_idx); |
1652 | dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, | 1636 | dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); |
1653 | dc); | ||
1654 | return; /* irrelevant block */ | 1637 | return; /* irrelevant block */ |
1655 | } | 1638 | } |
1656 | if (chld > dr->children[dr->num_children-1]->chk_idx) | 1639 | if (chld > dr->children[dr->num_children - 1]->chk_idx) |
1657 | { | 1640 | { |
1658 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1641 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1659 | "Block %u > %u irrelevant for our range\n", | 1642 | "Block %u > %u irrelevant for our range\n", |
1660 | chld, | 1643 | chld, |
1661 | dr->children[dr->num_children-1]->chk_idx); | 1644 | dr->children[dr->num_children - 1]->chk_idx); |
1662 | dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); | 1645 | dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); |
1663 | return; /* irrelevant block */ | 1646 | return; /* irrelevant block */ |
1664 | } | 1647 | } |
1665 | dr = dr->children[chld - dr->children[0]->chk_idx]; | 1648 | dr = dr->children[chld - dr->children[0]->chk_idx]; |
1666 | } | 1649 | } |
1667 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1650 | GNUNET_log ( |
1668 | "Matched TE block with request at offset %llu and depth %u in state %d\n", | 1651 | GNUNET_ERROR_TYPE_DEBUG, |
1669 | (unsigned long long) dr->offset, | 1652 | "Matched TE block with request at offset %llu and depth %u in state %d\n", |
1670 | dr->depth, | 1653 | (unsigned long long) dr->offset, |
1671 | dr->state); | 1654 | dr->depth, |
1655 | dr->state); | ||
1672 | /* FIXME: this code needs more testing and might | 1656 | /* FIXME: this code needs more testing and might |
1673 | need to handle more states... */ | 1657 | need to handle more states... */ |
1674 | switch (dr->state) | 1658 | switch (dr->state) |
@@ -1684,10 +1668,11 @@ reconstruct_cb (void *cls, | |||
1684 | case BRS_CHK_SET: | 1668 | case BRS_CHK_SET: |
1685 | if (0 == memcmp (chk, &dr->chk, sizeof (struct ContentHashKey))) | 1669 | if (0 == memcmp (chk, &dr->chk, sizeof (struct ContentHashKey))) |
1686 | { | 1670 | { |
1687 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1671 | GNUNET_log ( |
1688 | "Reconstruction succeeded, can use block at offset %llu, depth %u\n", | 1672 | GNUNET_ERROR_TYPE_DEBUG, |
1689 | (unsigned long long) offset, | 1673 | "Reconstruction succeeded, can use block at offset %llu, depth %u\n", |
1690 | depth); | 1674 | (unsigned long long) offset, |
1675 | depth); | ||
1691 | /* block matches, hence tree below matches; | 1676 | /* block matches, hence tree below matches; |
1692 | * this request is done! */ | 1677 | * this request is done! */ |
1693 | dr->state = BRS_DOWNLOAD_UP; | 1678 | dr->state = BRS_DOWNLOAD_UP; |
@@ -1707,32 +1692,34 @@ reconstruct_cb (void *cls, | |||
1707 | pi.value.download.specifics.progress.data_len = 0; | 1692 | pi.value.download.specifics.progress.data_len = 0; |
1708 | pi.value.download.specifics.progress.depth = 0; | 1693 | pi.value.download.specifics.progress.depth = 0; |
1709 | pi.value.download.specifics.progress.respect_offered = 0; | 1694 | pi.value.download.specifics.progress.respect_offered = 0; |
1710 | pi.value.download.specifics.progress.block_download_duration = GNUNET_TIME_UNIT_ZERO; | 1695 | pi.value.download.specifics.progress.block_download_duration = |
1696 | GNUNET_TIME_UNIT_ZERO; | ||
1711 | GNUNET_FS_download_make_status_ (&pi, dc); | 1697 | GNUNET_FS_download_make_status_ (&pi, dc); |
1712 | /* FIXME: duplicated code from 'process_result_with_request - refactor */ | 1698 | /* FIXME: duplicated code from 'process_result_with_request - refactor */ |
1713 | if (dc->completed == dc->length) | 1699 | if (dc->completed == dc->length) |
1714 | { | 1700 | { |
1715 | /* download completed, signal */ | 1701 | /* download completed, signal */ |
1716 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1702 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1717 | "Download completed, truncating file to desired length %llu\n", | 1703 | "Download completed, truncating file to desired length %llu\n", |
1718 | (unsigned long long) GNUNET_ntohll (dc->uri->data. | 1704 | (unsigned long long) GNUNET_ntohll ( |
1719 | chk.file_length)); | 1705 | dc->uri->data.chk.file_length)); |
1720 | /* truncate file to size (since we store IBlocks at the end) */ | 1706 | /* truncate file to size (since we store IBlocks at the end) */ |
1721 | if (NULL != dc->filename) | 1707 | if (NULL != dc->filename) |
1722 | { | 1708 | { |
1723 | if (0 != | 1709 | if (0 != truncate (dc->filename, |
1724 | TRUNCATE (dc->filename, | 1710 | GNUNET_ntohll (dc->uri->data.chk.file_length))) |
1725 | GNUNET_ntohll (dc->uri->data.chk.file_length))) | 1711 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
1726 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "truncate", | 1712 | "truncate", |
1727 | dc->filename); | 1713 | dc->filename); |
1728 | } | 1714 | } |
1729 | } | 1715 | } |
1730 | } | 1716 | } |
1731 | else | 1717 | else |
1732 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1718 | GNUNET_log ( |
1733 | "Reconstruction failed, need to download block at offset %llu, depth %u\n", | 1719 | GNUNET_ERROR_TYPE_DEBUG, |
1734 | (unsigned long long) offset, | 1720 | "Reconstruction failed, need to download block at offset %llu, depth %u\n", |
1735 | depth); | 1721 | (unsigned long long) offset, |
1722 | depth); | ||
1736 | break; | 1723 | break; |
1737 | case BRS_DOWNLOAD_DOWN: | 1724 | case BRS_DOWNLOAD_DOWN: |
1738 | break; | 1725 | break; |
@@ -1744,10 +1731,8 @@ reconstruct_cb (void *cls, | |||
1744 | GNUNET_assert (0); | 1731 | GNUNET_assert (0); |
1745 | break; | 1732 | break; |
1746 | } | 1733 | } |
1747 | dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, | 1734 | dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); |
1748 | dc); | 1735 | if ((dr == dc->top_request) && (dr->state == BRS_DOWNLOAD_UP)) |
1749 | if ( (dr == dc->top_request) && | ||
1750 | (dr->state == BRS_DOWNLOAD_UP) ) | ||
1751 | check_completed (dc); | 1736 | check_completed (dc); |
1752 | } | 1737 | } |
1753 | 1738 | ||
@@ -1803,8 +1788,7 @@ GNUNET_FS_download_start_task_ (void *cls) | |||
1803 | struct GNUNET_FS_ProgressInfo pi; | 1788 | struct GNUNET_FS_ProgressInfo pi; |
1804 | struct GNUNET_DISK_FileHandle *fh; | 1789 | struct GNUNET_DISK_FileHandle *fh; |
1805 | 1790 | ||
1806 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1791 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start task running...\n"); |
1807 | "Start task running...\n"); | ||
1808 | dc->task = NULL; | 1792 | dc->task = NULL; |
1809 | if (0 == dc->length) | 1793 | if (0 == dc->length) |
1810 | { | 1794 | { |
@@ -1813,14 +1797,15 @@ GNUNET_FS_download_start_task_ (void *cls) | |||
1813 | { | 1797 | { |
1814 | fh = GNUNET_DISK_file_open (dc->filename, | 1798 | fh = GNUNET_DISK_file_open (dc->filename, |
1815 | GNUNET_DISK_OPEN_READWRITE | | 1799 | GNUNET_DISK_OPEN_READWRITE | |
1816 | GNUNET_DISK_OPEN_CREATE | | 1800 | GNUNET_DISK_OPEN_CREATE | |
1817 | ((0 == | 1801 | ((0 == |
1818 | GNUNET_FS_uri_chk_get_file_size (dc->uri)) ? | 1802 | GNUNET_FS_uri_chk_get_file_size (dc->uri)) |
1819 | GNUNET_DISK_OPEN_TRUNCATE : 0), | 1803 | ? GNUNET_DISK_OPEN_TRUNCATE |
1804 | : 0), | ||
1820 | GNUNET_DISK_PERM_USER_READ | | 1805 | GNUNET_DISK_PERM_USER_READ | |
1821 | GNUNET_DISK_PERM_USER_WRITE | | 1806 | GNUNET_DISK_PERM_USER_WRITE | |
1822 | GNUNET_DISK_PERM_GROUP_READ | | 1807 | GNUNET_DISK_PERM_GROUP_READ | |
1823 | GNUNET_DISK_PERM_OTHER_READ); | 1808 | GNUNET_DISK_PERM_OTHER_READ); |
1824 | GNUNET_DISK_file_close (fh); | 1809 | GNUNET_DISK_file_close (fh); |
1825 | } | 1810 | } |
1826 | GNUNET_FS_download_sync_ (dc); | 1811 | GNUNET_FS_download_sync_ (dc); |
@@ -1834,13 +1819,16 @@ GNUNET_FS_download_start_task_ (void *cls) | |||
1834 | return; | 1819 | return; |
1835 | if (NULL == dc->top_request) | 1820 | if (NULL == dc->top_request) |
1836 | { | 1821 | { |
1837 | dc->top_request = | 1822 | dc->top_request = create_download_request (NULL, |
1838 | create_download_request (NULL, 0, dc->treedepth - 1, 0, dc->offset, | 1823 | 0, |
1839 | dc->length); | 1824 | dc->treedepth - 1, |
1825 | 0, | ||
1826 | dc->offset, | ||
1827 | dc->length); | ||
1840 | dc->top_request->state = BRS_CHK_SET; | 1828 | dc->top_request->state = BRS_CHK_SET; |
1841 | dc->top_request->chk = | 1829 | dc->top_request->chk = (dc->uri->type == GNUNET_FS_URI_CHK) |
1842 | (dc->uri->type == | 1830 | ? dc->uri->data.chk.chk |
1843 | GNUNET_FS_URI_CHK) ? dc->uri->data.chk.chk : dc->uri->data.loc.fi.chk; | 1831 | : dc->uri->data.loc.fi.chk; |
1844 | /* signal start */ | 1832 | /* signal start */ |
1845 | GNUNET_FS_download_sync_ (dc); | 1833 | GNUNET_FS_download_sync_ (dc); |
1846 | if (NULL != dc->search) | 1834 | if (NULL != dc->search) |
@@ -1852,23 +1840,24 @@ GNUNET_FS_download_start_task_ (void *cls) | |||
1852 | GNUNET_FS_download_start_downloading_ (dc); | 1840 | GNUNET_FS_download_start_downloading_ (dc); |
1853 | /* attempt reconstruction from disk */ | 1841 | /* attempt reconstruction from disk */ |
1854 | if (GNUNET_YES == GNUNET_DISK_file_test (dc->filename)) | 1842 | if (GNUNET_YES == GNUNET_DISK_file_test (dc->filename)) |
1855 | dc->rfh = | 1843 | dc->rfh = GNUNET_DISK_file_open (dc->filename, |
1856 | GNUNET_DISK_file_open (dc->filename, GNUNET_DISK_OPEN_READ, | 1844 | GNUNET_DISK_OPEN_READ, |
1857 | GNUNET_DISK_PERM_NONE); | 1845 | GNUNET_DISK_PERM_NONE); |
1858 | if (dc->top_request->state == BRS_CHK_SET) | 1846 | if (dc->top_request->state == BRS_CHK_SET) |
1859 | { | 1847 | { |
1860 | if (NULL != dc->rfh) | 1848 | if (NULL != dc->rfh) |
1861 | { | 1849 | { |
1862 | /* first, try top-down */ | 1850 | /* first, try top-down */ |
1863 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1851 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1864 | "Trying top-down reconstruction for `%s'\n", dc->filename); | 1852 | "Trying top-down reconstruction for `%s'\n", |
1853 | dc->filename); | ||
1865 | try_top_down_reconstruction (dc, dc->top_request); | 1854 | try_top_down_reconstruction (dc, dc->top_request); |
1866 | switch (dc->top_request->state) | 1855 | switch (dc->top_request->state) |
1867 | { | 1856 | { |
1868 | case BRS_CHK_SET: | 1857 | case BRS_CHK_SET: |
1869 | break; /* normal */ | 1858 | break; /* normal */ |
1870 | case BRS_DOWNLOAD_DOWN: | 1859 | case BRS_DOWNLOAD_DOWN: |
1871 | break; /* normal, some blocks already down */ | 1860 | break; /* normal, some blocks already down */ |
1872 | case BRS_DOWNLOAD_UP: | 1861 | case BRS_DOWNLOAD_UP: |
1873 | /* already done entirely, party! */ | 1862 | /* already done entirely, party! */ |
1874 | if (NULL != dc->rfh) | 1863 | if (NULL != dc->rfh) |
@@ -1880,7 +1869,7 @@ GNUNET_FS_download_start_task_ (void *cls) | |||
1880 | } | 1869 | } |
1881 | return; | 1870 | return; |
1882 | case BRS_ERROR: | 1871 | case BRS_ERROR: |
1883 | GNUNET_asprintf (&dc->emsg, _("Invalid URI")); | 1872 | GNUNET_asprintf (&dc->emsg, _ ("Invalid URI")); |
1884 | GNUNET_FS_download_sync_ (dc); | 1873 | GNUNET_FS_download_sync_ (dc); |
1885 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; | 1874 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; |
1886 | pi.value.download.specifics.error.message = dc->emsg; | 1875 | pi.value.download.specifics.error.message = dc->emsg; |
@@ -1896,11 +1885,11 @@ GNUNET_FS_download_start_task_ (void *cls) | |||
1896 | if ((GNUNET_FS_uri_chk_get_file_size (dc->uri) <= MAX_INLINE_SIZE) && | 1885 | if ((GNUNET_FS_uri_chk_get_file_size (dc->uri) <= MAX_INLINE_SIZE) && |
1897 | (NULL != dc->meta)) | 1886 | (NULL != dc->meta)) |
1898 | { | 1887 | { |
1899 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1888 | GNUNET_log ( |
1900 | "Trying to find embedded meta data for download of size %llu with %u bytes MD\n", | 1889 | GNUNET_ERROR_TYPE_DEBUG, |
1901 | (unsigned long long) GNUNET_FS_uri_chk_get_file_size (dc->uri), | 1890 | "Trying to find embedded meta data for download of size %llu with %u bytes MD\n", |
1902 | (unsigned int) | 1891 | (unsigned long long) GNUNET_FS_uri_chk_get_file_size (dc->uri), |
1903 | GNUNET_CONTAINER_meta_data_get_serialized_size (dc->meta)); | 1892 | (unsigned int) GNUNET_CONTAINER_meta_data_get_serialized_size (dc->meta)); |
1904 | GNUNET_CONTAINER_meta_data_iterate (dc->meta, &match_full_data, dc); | 1893 | GNUNET_CONTAINER_meta_data_iterate (dc->meta, &match_full_data, dc); |
1905 | if (BRS_DOWNLOAD_UP == dc->top_request->state) | 1894 | if (BRS_DOWNLOAD_UP == dc->top_request->state) |
1906 | { | 1895 | { |
@@ -1911,24 +1900,24 @@ GNUNET_FS_download_start_task_ (void *cls) | |||
1911 | GNUNET_DISK_file_close (dc->rfh); | 1900 | GNUNET_DISK_file_close (dc->rfh); |
1912 | dc->rfh = NULL; | 1901 | dc->rfh = NULL; |
1913 | } | 1902 | } |
1914 | return; /* finished, status update was already done for us */ | 1903 | return; /* finished, status update was already done for us */ |
1915 | } | 1904 | } |
1916 | } | 1905 | } |
1917 | if (NULL != dc->rfh) | 1906 | if (NULL != dc->rfh) |
1918 | { | 1907 | { |
1919 | /* finally, actually run bottom-up */ | 1908 | /* finally, actually run bottom-up */ |
1920 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1909 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1921 | "Trying bottom-up reconstruction of file `%s'\n", dc->filename); | 1910 | "Trying bottom-up reconstruction of file `%s'\n", |
1911 | dc->filename); | ||
1922 | dc->te = | 1912 | dc->te = |
1923 | GNUNET_FS_tree_encoder_create (dc->h, | 1913 | GNUNET_FS_tree_encoder_create (dc->h, |
1924 | GNUNET_FS_uri_chk_get_file_size (dc->uri), | 1914 | GNUNET_FS_uri_chk_get_file_size (dc->uri), |
1925 | dc, | 1915 | dc, |
1926 | &fh_reader, | 1916 | &fh_reader, |
1927 | &reconstruct_cb, | 1917 | &reconstruct_cb, |
1928 | NULL, | 1918 | NULL, |
1929 | &reconstruct_cont); | 1919 | &reconstruct_cont); |
1930 | dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, | 1920 | dc->task = GNUNET_SCHEDULER_add_now (&get_next_block, dc); |
1931 | dc); | ||
1932 | } | 1921 | } |
1933 | else | 1922 | else |
1934 | { | 1923 | { |
@@ -1968,7 +1957,8 @@ GNUNET_FS_download_signal_suspend_ (void *cls) | |||
1968 | dc->job_queue = NULL; | 1957 | dc->job_queue = NULL; |
1969 | } | 1958 | } |
1970 | if (NULL != dc->parent) | 1959 | if (NULL != dc->parent) |
1971 | GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, dc->parent->child_tail, | 1960 | GNUNET_CONTAINER_DLL_remove (dc->parent->child_head, |
1961 | dc->parent->child_tail, | ||
1972 | dc); | 1962 | dc); |
1973 | if (NULL != dc->task) | 1963 | if (NULL != dc->task) |
1974 | { | 1964 | { |
@@ -2024,14 +2014,14 @@ GNUNET_FS_download_signal_suspend_ (void *cls) | |||
2024 | */ | 2014 | */ |
2025 | struct GNUNET_FS_DownloadContext * | 2015 | struct GNUNET_FS_DownloadContext * |
2026 | create_download_context (struct GNUNET_FS_Handle *h, | 2016 | create_download_context (struct GNUNET_FS_Handle *h, |
2027 | const struct GNUNET_FS_Uri *uri, | 2017 | const struct GNUNET_FS_Uri *uri, |
2028 | const struct GNUNET_CONTAINER_MetaData *meta, | 2018 | const struct GNUNET_CONTAINER_MetaData *meta, |
2029 | const char *filename, | 2019 | const char *filename, |
2030 | const char *tempname, | 2020 | const char *tempname, |
2031 | uint64_t offset, | 2021 | uint64_t offset, |
2032 | uint64_t length, | 2022 | uint64_t length, |
2033 | uint32_t anonymity, | 2023 | uint32_t anonymity, |
2034 | enum GNUNET_FS_DownloadOptions options, | 2024 | enum GNUNET_FS_DownloadOptions options, |
2035 | void *cctx) | 2025 | void *cctx) |
2036 | { | 2026 | { |
2037 | struct GNUNET_FS_DownloadContext *dc; | 2027 | struct GNUNET_FS_DownloadContext *dc; |
@@ -2045,10 +2035,10 @@ create_download_context (struct GNUNET_FS_Handle *h, | |||
2045 | } | 2035 | } |
2046 | dc = GNUNET_new (struct GNUNET_FS_DownloadContext); | 2036 | dc = GNUNET_new (struct GNUNET_FS_DownloadContext); |
2047 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2037 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2048 | "Starting download %p, %u bytes at offset %llu\n", | 2038 | "Starting download %p, %u bytes at offset %llu\n", |
2049 | dc, | 2039 | dc, |
2050 | (unsigned int) length, | 2040 | (unsigned int) length, |
2051 | (unsigned long long) offset); | 2041 | (unsigned long long) offset); |
2052 | dc->h = h; | 2042 | dc->h = h; |
2053 | dc->uri = GNUNET_FS_uri_dup (uri); | 2043 | dc->uri = GNUNET_FS_uri_dup (uri); |
2054 | dc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); | 2044 | dc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); |
@@ -2058,7 +2048,10 @@ create_download_context (struct GNUNET_FS_Handle *h, | |||
2058 | { | 2048 | { |
2059 | dc->filename = GNUNET_strdup (filename); | 2049 | dc->filename = GNUNET_strdup (filename); |
2060 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) | 2050 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) |
2061 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_size (filename, &dc->old_file_size, GNUNET_YES, GNUNET_YES)); | 2051 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_size (filename, |
2052 | &dc->old_file_size, | ||
2053 | GNUNET_YES, | ||
2054 | GNUNET_YES)); | ||
2062 | } | 2055 | } |
2063 | if (GNUNET_FS_uri_test_loc (dc->uri)) | 2056 | if (GNUNET_FS_uri_test_loc (dc->uri)) |
2064 | GNUNET_assert (GNUNET_OK == | 2057 | GNUNET_assert (GNUNET_OK == |
@@ -2068,9 +2061,10 @@ create_download_context (struct GNUNET_FS_Handle *h, | |||
2068 | dc->anonymity = anonymity; | 2061 | dc->anonymity = anonymity; |
2069 | dc->options = options; | 2062 | dc->options = options; |
2070 | dc->active = | 2063 | dc->active = |
2071 | GNUNET_CONTAINER_multihashmap_create (1 + 2 * (length / DBLOCK_SIZE), GNUNET_NO); | 2064 | GNUNET_CONTAINER_multihashmap_create (1 + 2 * (length / DBLOCK_SIZE), |
2065 | GNUNET_NO); | ||
2072 | dc->treedepth = | 2066 | dc->treedepth = |
2073 | GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri)); | 2067 | GNUNET_FS_compute_depth (GNUNET_FS_uri_chk_get_file_size (dc->uri)); |
2074 | if ((NULL == filename) && (is_recursive_download (dc))) | 2068 | if ((NULL == filename) && (is_recursive_download (dc))) |
2075 | { | 2069 | { |
2076 | if (NULL != tempname) | 2070 | if (NULL != tempname) |
@@ -2079,13 +2073,12 @@ create_download_context (struct GNUNET_FS_Handle *h, | |||
2079 | dc->temp_filename = GNUNET_DISK_mktemp ("gnunet-directory-download-tmp"); | 2073 | dc->temp_filename = GNUNET_DISK_mktemp ("gnunet-directory-download-tmp"); |
2080 | } | 2074 | } |
2081 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2075 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2082 | "Starting download `%s' of %llu bytes with tree depth %u\n", | 2076 | "Starting download `%s' of %llu bytes with tree depth %u\n", |
2083 | filename, | 2077 | filename, |
2084 | (unsigned long long) length, | 2078 | (unsigned long long) length, |
2085 | dc->treedepth); | 2079 | dc->treedepth); |
2086 | GNUNET_assert (NULL == dc->job_queue); | 2080 | GNUNET_assert (NULL == dc->job_queue); |
2087 | dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, | 2081 | dc->task = GNUNET_SCHEDULER_add_now (&GNUNET_FS_download_start_task_, dc); |
2088 | dc); | ||
2089 | return dc; | 2082 | return dc; |
2090 | } | 2083 | } |
2091 | 2084 | ||
@@ -2140,7 +2133,7 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, | |||
2140 | meta, | 2133 | meta, |
2141 | filename, | 2134 | filename, |
2142 | tempname, | 2135 | tempname, |
2143 | offset, | 2136 | offset, |
2144 | length, | 2137 | length, |
2145 | anonymity, | 2138 | anonymity, |
2146 | options, | 2139 | options, |
@@ -2150,9 +2143,9 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, | |||
2150 | dc->parent = parent; | 2143 | dc->parent = parent; |
2151 | if (NULL != parent) | 2144 | if (NULL != parent) |
2152 | GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc); | 2145 | GNUNET_CONTAINER_DLL_insert (parent->child_head, parent->child_tail, dc); |
2153 | else if (0 == (GNUNET_FS_DOWNLOAD_IS_PROBE & options) ) | 2146 | else if (0 == (GNUNET_FS_DOWNLOAD_IS_PROBE & options)) |
2154 | dc->top = | 2147 | dc->top = |
2155 | GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc); | 2148 | GNUNET_FS_make_top (dc->h, &GNUNET_FS_download_signal_suspend_, dc); |
2156 | return dc; | 2149 | return dc; |
2157 | } | 2150 | } |
2158 | 2151 | ||
@@ -2214,7 +2207,7 @@ GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h, | |||
2214 | sr->meta, | 2207 | sr->meta, |
2215 | filename, | 2208 | filename, |
2216 | tempname, | 2209 | tempname, |
2217 | offset, | 2210 | offset, |
2218 | length, | 2211 | length, |
2219 | anonymity, | 2212 | anonymity, |
2220 | options, | 2213 | options, |
@@ -2248,19 +2241,19 @@ GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc) | |||
2248 | GNUNET_assert (NULL == dc->job_queue); | 2241 | GNUNET_assert (NULL == dc->job_queue); |
2249 | GNUNET_assert (NULL == dc->task); | 2242 | GNUNET_assert (NULL == dc->task); |
2250 | GNUNET_assert (NULL != dc->active); | 2243 | GNUNET_assert (NULL != dc->active); |
2251 | dc->job_queue | 2244 | dc->job_queue = |
2252 | = GNUNET_FS_queue_ (dc->h, | 2245 | GNUNET_FS_queue_ (dc->h, |
2253 | &activate_fs_download, | 2246 | &activate_fs_download, |
2254 | &deactivate_fs_download, | 2247 | &deactivate_fs_download, |
2255 | dc, | 2248 | dc, |
2256 | (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, | 2249 | (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, |
2257 | (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) | 2250 | (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) |
2258 | ? GNUNET_FS_QUEUE_PRIORITY_NORMAL | 2251 | ? GNUNET_FS_QUEUE_PRIORITY_NORMAL |
2259 | : GNUNET_FS_QUEUE_PRIORITY_PROBE); | 2252 | : GNUNET_FS_QUEUE_PRIORITY_PROBE); |
2260 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2261 | "Download %p put into queue as job %p\n", | 2254 | "Download %p put into queue as job %p\n", |
2262 | dc, | 2255 | dc, |
2263 | dc->job_queue); | 2256 | dc->job_queue); |
2264 | } | 2257 | } |
2265 | 2258 | ||
2266 | /** | 2259 | /** |
@@ -2271,7 +2264,7 @@ GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc) | |||
2271 | void | 2264 | void |
2272 | GNUNET_FS_download_suspend (struct GNUNET_FS_DownloadContext *dc) | 2265 | GNUNET_FS_download_suspend (struct GNUNET_FS_DownloadContext *dc) |
2273 | { | 2266 | { |
2274 | deactivate_fs_download(dc); | 2267 | deactivate_fs_download (dc); |
2275 | } | 2268 | } |
2276 | 2269 | ||
2277 | 2270 | ||
@@ -2289,15 +2282,15 @@ GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc) | |||
2289 | GNUNET_FS_download_make_status_ (&pi, dc); | 2282 | GNUNET_FS_download_make_status_ (&pi, dc); |
2290 | 2283 | ||
2291 | GNUNET_assert (NULL == dc->task); | 2284 | GNUNET_assert (NULL == dc->task); |
2292 | dc->job_queue | 2285 | dc->job_queue = |
2293 | = GNUNET_FS_queue_ (dc->h, | 2286 | GNUNET_FS_queue_ (dc->h, |
2294 | &activate_fs_download, | 2287 | &activate_fs_download, |
2295 | &deactivate_fs_download, | 2288 | &deactivate_fs_download, |
2296 | dc, (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, | 2289 | dc, |
2297 | (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) | 2290 | (dc->length + DBLOCK_SIZE - 1) / DBLOCK_SIZE, |
2291 | (0 == (dc->options & GNUNET_FS_DOWNLOAD_IS_PROBE)) | ||
2298 | ? GNUNET_FS_QUEUE_PRIORITY_NORMAL | 2292 | ? GNUNET_FS_QUEUE_PRIORITY_NORMAL |
2299 | : GNUNET_FS_QUEUE_PRIORITY_PROBE); | 2293 | : GNUNET_FS_QUEUE_PRIORITY_PROBE); |
2300 | |||
2301 | } | 2294 | } |
2302 | 2295 | ||
2303 | 2296 | ||
@@ -2308,8 +2301,7 @@ GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc) | |||
2308 | * @param do_delete delete files of incomplete downloads | 2301 | * @param do_delete delete files of incomplete downloads |
2309 | */ | 2302 | */ |
2310 | void | 2303 | void |
2311 | GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, | 2304 | GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete) |
2312 | int do_delete) | ||
2313 | { | 2305 | { |
2314 | struct GNUNET_FS_ProgressInfo pi; | 2306 | struct GNUNET_FS_ProgressInfo pi; |
2315 | int have_children; | 2307 | int have_children; |
@@ -2348,14 +2340,15 @@ GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, | |||
2348 | dc); | 2340 | dc); |
2349 | if (NULL != dc->serialization) | 2341 | if (NULL != dc->serialization) |
2350 | GNUNET_FS_remove_sync_file_ (dc->h, | 2342 | GNUNET_FS_remove_sync_file_ (dc->h, |
2351 | ((NULL != dc->parent) || | 2343 | ((NULL != dc->parent) || (! search_was_null)) |
2352 | (! search_was_null)) ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD : | 2344 | ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD |
2353 | GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, | 2345 | : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, |
2354 | dc->serialization); | 2346 | dc->serialization); |
2355 | if ((GNUNET_YES == have_children) && (NULL == dc->parent)) | 2347 | if ((GNUNET_YES == have_children) && (NULL == dc->parent)) |
2356 | GNUNET_FS_remove_sync_dir_ (dc->h, | 2348 | GNUNET_FS_remove_sync_dir_ (dc->h, |
2357 | (! search_was_null) ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD : | 2349 | (! search_was_null) |
2358 | GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, | 2350 | ? GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD |
2351 | : GNUNET_FS_SYNC_PATH_MASTER_DOWNLOAD, | ||
2359 | dc->serialization); | 2352 | dc->serialization); |
2360 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_STOPPED; | 2353 | pi.status = GNUNET_FS_STATUS_DOWNLOAD_STOPPED; |
2361 | GNUNET_FS_download_make_status_ (&pi, dc); | 2354 | GNUNET_FS_download_make_status_ (&pi, dc); |
@@ -2370,8 +2363,7 @@ GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, | |||
2370 | { | 2363 | { |
2371 | if ((dc->completed != dc->length) && (GNUNET_YES == do_delete)) | 2364 | if ((dc->completed != dc->length) && (GNUNET_YES == do_delete)) |
2372 | { | 2365 | { |
2373 | if ( (0 != UNLINK (dc->filename)) && | 2366 | if ((0 != unlink (dc->filename)) && (ENOENT != errno)) |
2374 | (ENOENT != errno) ) | ||
2375 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 2367 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
2376 | "unlink", | 2368 | "unlink", |
2377 | dc->filename); | 2369 | dc->filename); |
@@ -2382,7 +2374,7 @@ GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, | |||
2382 | GNUNET_FS_uri_destroy (dc->uri); | 2374 | GNUNET_FS_uri_destroy (dc->uri); |
2383 | if (NULL != dc->temp_filename) | 2375 | if (NULL != dc->temp_filename) |
2384 | { | 2376 | { |
2385 | if (0 != UNLINK (dc->temp_filename)) | 2377 | if (0 != unlink (dc->temp_filename)) |
2386 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | 2378 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, |
2387 | "unlink", | 2379 | "unlink", |
2388 | dc->temp_filename); | 2380 | 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, | |||
97 | * @return publish structure entry for the file | 97 | * @return publish structure entry for the file |
98 | */ | 98 | */ |
99 | struct GNUNET_FS_FileInformation * | 99 | struct GNUNET_FS_FileInformation * |
100 | GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h, | 100 | GNUNET_FS_file_information_create_from_file ( |
101 | void *client_info, | 101 | struct GNUNET_FS_Handle *h, |
102 | const char *filename, | 102 | void *client_info, |
103 | const struct GNUNET_FS_Uri | 103 | const char *filename, |
104 | *keywords, | 104 | const struct GNUNET_FS_Uri *keywords, |
105 | const struct | 105 | const struct GNUNET_CONTAINER_MetaData *meta, |
106 | GNUNET_CONTAINER_MetaData *meta, | 106 | int do_index, |
107 | int do_index, | 107 | const struct GNUNET_FS_BlockOptions *bo) |
108 | const struct GNUNET_FS_BlockOptions | ||
109 | *bo) | ||
110 | { | 108 | { |
111 | struct FileInfo *fi; | 109 | struct FileInfo *fi; |
112 | uint64_t fsize; | 110 | uint64_t fsize; |
@@ -119,7 +117,8 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h, | |||
119 | #endif | 117 | #endif |
120 | 118 | ||
121 | /* FIXME: should include_symbolic_links be GNUNET_NO or GNUNET_YES here? */ | 119 | /* FIXME: should include_symbolic_links be GNUNET_NO or GNUNET_YES here? */ |
122 | if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES)) | 120 | if (GNUNET_OK != |
121 | GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES)) | ||
123 | { | 122 | { |
124 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); | 123 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); |
125 | return NULL; | 124 | return NULL; |
@@ -131,16 +130,20 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h, | |||
131 | return NULL; | 130 | return NULL; |
132 | } | 131 | } |
133 | ret = | 132 | ret = |
134 | GNUNET_FS_file_information_create_from_reader (h, client_info, | 133 | GNUNET_FS_file_information_create_from_reader (h, |
135 | fsize, | 134 | client_info, |
136 | &GNUNET_FS_data_reader_file_, | 135 | fsize, |
137 | fi, keywords, meta, | 136 | &GNUNET_FS_data_reader_file_, |
138 | do_index, bo); | 137 | fi, |
138 | keywords, | ||
139 | meta, | ||
140 | do_index, | ||
141 | bo); | ||
139 | if (ret == NULL) | 142 | if (ret == NULL) |
140 | return NULL; | 143 | return NULL; |
141 | ret->h = h; | 144 | ret->h = h; |
142 | ret->filename = GNUNET_strdup (filename); | 145 | ret->filename = GNUNET_strdup (filename); |
143 | #if !WINDOWS | 146 | #if ! WINDOWS |
144 | fn = filename; | 147 | fn = filename; |
145 | #else | 148 | #else |
146 | plibc_conv_to_win_path (filename, fn_conv); | 149 | plibc_conv_to_win_path (filename, fn_conv); |
@@ -151,16 +154,22 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h, | |||
151 | /* FIXME: If we assume that on other platforms CRT is UTF-8-aware, then | 154 | /* FIXME: If we assume that on other platforms CRT is UTF-8-aware, then |
152 | * this should be changed to EXTRACTOR_METAFORMAT_UTF8 | 155 | * this should be changed to EXTRACTOR_METAFORMAT_UTF8 |
153 | */ | 156 | */ |
154 | #if !WINDOWS | 157 | #if ! WINDOWS |
155 | GNUNET_CONTAINER_meta_data_insert (ret->meta, "<gnunet>", | 158 | GNUNET_CONTAINER_meta_data_insert (ret->meta, |
159 | "<gnunet>", | ||
156 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | 160 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, |
157 | EXTRACTOR_METAFORMAT_C_STRING, | 161 | EXTRACTOR_METAFORMAT_C_STRING, |
158 | "text/plain", fn, strlen (fn) + 1); | 162 | "text/plain", |
163 | fn, | ||
164 | strlen (fn) + 1); | ||
159 | #else | 165 | #else |
160 | GNUNET_CONTAINER_meta_data_insert (ret->meta, "<gnunet>", | 166 | GNUNET_CONTAINER_meta_data_insert (ret->meta, |
167 | "<gnunet>", | ||
161 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | 168 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, |
162 | EXTRACTOR_METAFORMAT_UTF8, | 169 | EXTRACTOR_METAFORMAT_UTF8, |
163 | "text/plain", fn, strlen (fn) + 1); | 170 | "text/plain", |
171 | fn, | ||
172 | strlen (fn) + 1); | ||
164 | #endif | 173 | #endif |
165 | return ret; | 174 | return ret; |
166 | } | 175 | } |
@@ -183,26 +192,30 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h, | |||
183 | * @return publish structure entry for the file | 192 | * @return publish structure entry for the file |
184 | */ | 193 | */ |
185 | struct GNUNET_FS_FileInformation * | 194 | struct GNUNET_FS_FileInformation * |
186 | GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h, | 195 | GNUNET_FS_file_information_create_from_data ( |
187 | void *client_info, uint64_t length, | 196 | struct GNUNET_FS_Handle *h, |
188 | void *data, | 197 | void *client_info, |
189 | const struct GNUNET_FS_Uri | 198 | uint64_t length, |
190 | *keywords, | 199 | void *data, |
191 | const struct | 200 | const struct GNUNET_FS_Uri *keywords, |
192 | GNUNET_CONTAINER_MetaData *meta, | 201 | const struct GNUNET_CONTAINER_MetaData *meta, |
193 | int do_index, | 202 | int do_index, |
194 | const struct GNUNET_FS_BlockOptions | 203 | const struct GNUNET_FS_BlockOptions *bo) |
195 | *bo) | ||
196 | { | 204 | { |
197 | if (GNUNET_YES == do_index) | 205 | if (GNUNET_YES == do_index) |
198 | { | 206 | { |
199 | GNUNET_break (0); | 207 | GNUNET_break (0); |
200 | return NULL; | 208 | return NULL; |
201 | } | 209 | } |
202 | return GNUNET_FS_file_information_create_from_reader (h, client_info, length, | 210 | return GNUNET_FS_file_information_create_from_reader (h, |
211 | client_info, | ||
212 | length, | ||
203 | &GNUNET_FS_data_reader_copy_, | 213 | &GNUNET_FS_data_reader_copy_, |
204 | data, keywords, meta, | 214 | data, |
205 | do_index, bo); | 215 | keywords, |
216 | meta, | ||
217 | do_index, | ||
218 | bo); | ||
206 | } | 219 | } |
207 | 220 | ||
208 | 221 | ||
@@ -223,18 +236,16 @@ GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h, | |||
223 | * @return publish structure entry for the file | 236 | * @return publish structure entry for the file |
224 | */ | 237 | */ |
225 | struct GNUNET_FS_FileInformation * | 238 | struct GNUNET_FS_FileInformation * |
226 | GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h, | 239 | GNUNET_FS_file_information_create_from_reader ( |
227 | void *client_info, | 240 | struct GNUNET_FS_Handle *h, |
228 | uint64_t length, | 241 | void *client_info, |
229 | GNUNET_FS_DataReader reader, | 242 | uint64_t length, |
230 | void *reader_cls, | 243 | GNUNET_FS_DataReader reader, |
231 | const struct GNUNET_FS_Uri | 244 | void *reader_cls, |
232 | *keywords, | 245 | const struct GNUNET_FS_Uri *keywords, |
233 | const struct | 246 | const struct GNUNET_CONTAINER_MetaData *meta, |
234 | GNUNET_CONTAINER_MetaData *meta, | 247 | int do_index, |
235 | int do_index, | 248 | const struct GNUNET_FS_BlockOptions *bo) |
236 | const struct | ||
237 | GNUNET_FS_BlockOptions *bo) | ||
238 | { | 249 | { |
239 | struct GNUNET_FS_FileInformation *ret; | 250 | struct GNUNET_FS_FileInformation *ret; |
240 | 251 | ||
@@ -266,8 +277,8 @@ GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h, | |||
266 | * @return #GNUNET_YES if so, #GNUNET_NO if not | 277 | * @return #GNUNET_YES if so, #GNUNET_NO if not |
267 | */ | 278 | */ |
268 | int | 279 | int |
269 | GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation | 280 | GNUNET_FS_file_information_is_directory ( |
270 | *ent) | 281 | const struct GNUNET_FS_FileInformation *ent) |
271 | { | 282 | { |
272 | return ent->is_directory; | 283 | return ent->is_directory; |
273 | } | 284 | } |
@@ -286,16 +297,13 @@ GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation | |||
286 | * @return publish structure entry for the directory , NULL on error | 297 | * @return publish structure entry for the directory , NULL on error |
287 | */ | 298 | */ |
288 | struct GNUNET_FS_FileInformation * | 299 | struct GNUNET_FS_FileInformation * |
289 | GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h, | 300 | GNUNET_FS_file_information_create_empty_directory ( |
290 | void *client_info, | 301 | struct GNUNET_FS_Handle *h, |
291 | const struct GNUNET_FS_Uri | 302 | void *client_info, |
292 | *keywords, | 303 | const struct GNUNET_FS_Uri *keywords, |
293 | const struct | 304 | const struct GNUNET_CONTAINER_MetaData *meta, |
294 | GNUNET_CONTAINER_MetaData | 305 | const struct GNUNET_FS_BlockOptions *bo, |
295 | *meta, | 306 | const char *filename) |
296 | const struct | ||
297 | GNUNET_FS_BlockOptions *bo, | ||
298 | const char *filename) | ||
299 | { | 307 | { |
300 | struct GNUNET_FS_FileInformation *ret; | 308 | struct GNUNET_FS_FileInformation *ret; |
301 | 309 | ||
@@ -327,7 +335,8 @@ int | |||
327 | GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir, | 335 | GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir, |
328 | struct GNUNET_FS_FileInformation *ent) | 336 | struct GNUNET_FS_FileInformation *ent) |
329 | { | 337 | { |
330 | if ((ent->dir != NULL) || (ent->next != NULL) || (dir->is_directory != GNUNET_YES)) | 338 | if ((ent->dir != NULL) || (ent->next != NULL) || |
339 | (dir->is_directory != GNUNET_YES)) | ||
331 | { | 340 | { |
332 | GNUNET_break (0); | 341 | GNUNET_break (0); |
333 | return GNUNET_SYSERR; | 342 | return GNUNET_SYSERR; |
@@ -364,10 +373,13 @@ GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir, | |||
364 | 373 | ||
365 | no = GNUNET_NO; | 374 | no = GNUNET_NO; |
366 | if (GNUNET_OK != | 375 | if (GNUNET_OK != |
367 | proc (proc_cls, dir, | 376 | proc (proc_cls, |
368 | (dir->is_directory == GNUNET_YES) ? dir->data.dir.dir_size : dir->data. | 377 | dir, |
369 | file.file_size, | 378 | (dir->is_directory == GNUNET_YES) ? dir->data.dir.dir_size |
370 | dir->meta, &dir->keywords, &dir->bo, | 379 | : dir->data.file.file_size, |
380 | dir->meta, | ||
381 | &dir->keywords, | ||
382 | &dir->bo, | ||
371 | (dir->is_directory == GNUNET_YES) ? &no : &dir->data.file.do_index, | 383 | (dir->is_directory == GNUNET_YES) ? &no : &dir->data.file.do_index, |
372 | &dir->client_info)) | 384 | &dir->client_info)) |
373 | return; | 385 | return; |
@@ -378,10 +390,15 @@ GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir, | |||
378 | { | 390 | { |
379 | no = GNUNET_NO; | 391 | no = GNUNET_NO; |
380 | if (GNUNET_OK != | 392 | if (GNUNET_OK != |
381 | proc (proc_cls, pos, | 393 | proc (proc_cls, |
382 | (pos->is_directory == GNUNET_YES) ? pos->data.dir.dir_size : pos->data. | 394 | pos, |
383 | file.file_size, pos->meta, &pos->keywords, &pos->bo, | 395 | (pos->is_directory == GNUNET_YES) ? pos->data.dir.dir_size |
384 | (pos->is_directory == GNUNET_YES) ? &no : &pos->data.file.do_index, | 396 | : pos->data.file.file_size, |
397 | pos->meta, | ||
398 | &pos->keywords, | ||
399 | &pos->bo, | ||
400 | (pos->is_directory == GNUNET_YES) ? &no | ||
401 | : &pos->data.file.do_index, | ||
385 | &pos->client_info)) | 402 | &pos->client_info)) |
386 | break; | 403 | break; |
387 | pos = pos->next; | 404 | pos = pos->next; |
@@ -418,8 +435,14 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi, | |||
418 | } | 435 | } |
419 | /* clean up client-info */ | 436 | /* clean up client-info */ |
420 | if (NULL != cleaner) | 437 | if (NULL != cleaner) |
421 | cleaner (cleaner_cls, fi, fi->data.dir.dir_size, fi->meta, &fi->keywords, | 438 | cleaner (cleaner_cls, |
422 | &fi->bo, &no, &fi->client_info); | 439 | fi, |
440 | fi->data.dir.dir_size, | ||
441 | fi->meta, | ||
442 | &fi->keywords, | ||
443 | &fi->bo, | ||
444 | &no, | ||
445 | &fi->client_info); | ||
423 | GNUNET_free_non_null (fi->data.dir.dir_data); | 446 | GNUNET_free_non_null (fi->data.dir.dir_data); |
424 | } | 447 | } |
425 | else | 448 | else |
@@ -432,19 +455,25 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi, | |||
432 | } | 455 | } |
433 | /* clean up client-info */ | 456 | /* clean up client-info */ |
434 | if (NULL != cleaner) | 457 | if (NULL != cleaner) |
435 | cleaner (cleaner_cls, fi, fi->data.file.file_size, fi->meta, | 458 | cleaner (cleaner_cls, |
436 | &fi->keywords, &fi->bo, &fi->data.file.do_index, | 459 | fi, |
460 | fi->data.file.file_size, | ||
461 | fi->meta, | ||
462 | &fi->keywords, | ||
463 | &fi->bo, | ||
464 | &fi->data.file.do_index, | ||
437 | &fi->client_info); | 465 | &fi->client_info); |
438 | } | 466 | } |
439 | GNUNET_free_non_null (fi->filename); | 467 | GNUNET_free_non_null (fi->filename); |
440 | GNUNET_free_non_null (fi->emsg); | 468 | GNUNET_free_non_null (fi->emsg); |
441 | if (NULL != fi->sks_uri) | 469 | if (NULL != fi->sks_uri) |
442 | GNUNET_FS_uri_destroy (fi->sks_uri); | 470 | GNUNET_FS_uri_destroy (fi->sks_uri); |
443 | if (NULL != fi->chk_uri) | 471 | if (NULL != fi->chk_uri) |
444 | GNUNET_FS_uri_destroy (fi->chk_uri); | 472 | GNUNET_FS_uri_destroy (fi->chk_uri); |
445 | /* clean up serialization */ | 473 | /* clean up serialization */ |
446 | if ((NULL != fi->serialization) && (0 != UNLINK (fi->serialization))) | 474 | if ((NULL != fi->serialization) && (0 != unlink (fi->serialization))) |
447 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", | 475 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
476 | "unlink", | ||
448 | fi->serialization); | 477 | fi->serialization); |
449 | if (NULL != fi->keywords) | 478 | if (NULL != fi->keywords) |
450 | GNUNET_FS_uri_destroy (fi->keywords); | 479 | 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 | |||
69 | * TREE this entry belongs to (if nug is current). | 69 | * TREE this entry belongs to (if nug is current). |
70 | */ | 70 | */ |
71 | unsigned int tree_id; | 71 | unsigned int tree_id; |
72 | |||
73 | }; | 72 | }; |
74 | 73 | ||
75 | 74 | ||
@@ -126,8 +125,9 @@ struct GNUNET_FS_UpdateInformationGraph | |||
126 | * @return NULL on error, otherwise the name of the directory | 125 | * @return NULL on error, otherwise the name of the directory |
127 | */ | 126 | */ |
128 | static char * | 127 | static char * |
129 | get_update_information_directory (struct GNUNET_FS_Handle *h, | 128 | get_update_information_directory ( |
130 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) | 129 | struct GNUNET_FS_Handle *h, |
130 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) | ||
131 | { | 131 | { |
132 | char *dn; | 132 | char *dn; |
133 | char *ret; | 133 | char *ret; |
@@ -136,21 +136,19 @@ get_update_information_directory (struct GNUNET_FS_Handle *h, | |||
136 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; | 136 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; |
137 | 137 | ||
138 | if (GNUNET_OK != | 138 | if (GNUNET_OK != |
139 | GNUNET_CONFIGURATION_get_value_filename (h->cfg, "FS", "UPDATE_DIR", | 139 | GNUNET_CONFIGURATION_get_value_filename (h->cfg, "FS", "UPDATE_DIR", &dn)) |
140 | &dn)) | ||
141 | { | 140 | { |
142 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 141 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "fs", "UPDATE_DIR"); |
143 | "fs", "UPDATE_DIR"); | ||
144 | return NULL; | 142 | return NULL; |
145 | } | 143 | } |
146 | GNUNET_CRYPTO_ecdsa_key_get_public (ns, &pub); | 144 | GNUNET_CRYPTO_ecdsa_key_get_public (ns, &pub); |
147 | GNUNET_CRYPTO_hash (&pub, sizeof (pub), &hc); | 145 | GNUNET_CRYPTO_hash (&pub, sizeof (pub), &hc); |
148 | GNUNET_CRYPTO_hash_to_enc (&hc, | 146 | GNUNET_CRYPTO_hash_to_enc (&hc, &enc); |
149 | &enc); | 147 | GNUNET_asprintf (&ret, |
150 | GNUNET_asprintf (&ret, "%s%s%s", | 148 | "%s%s%s", |
151 | dn, | 149 | dn, |
152 | DIR_SEPARATOR_STR, | 150 | DIR_SEPARATOR_STR, |
153 | (const char *) enc.encoding); | 151 | (const char *) enc.encoding); |
154 | GNUNET_free (dn); | 152 | GNUNET_free (dn); |
155 | return ret; | 153 | return ret; |
156 | } | 154 | } |
@@ -176,8 +174,7 @@ free_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) | |||
176 | GNUNET_free (nsn->update); | 174 | GNUNET_free (nsn->update); |
177 | GNUNET_free (nsn); | 175 | GNUNET_free (nsn); |
178 | } | 176 | } |
179 | GNUNET_array_grow (uig->update_nodes, uig->update_node_count, | 177 | GNUNET_array_grow (uig->update_nodes, uig->update_node_count, 0); |
180 | 0); | ||
181 | if (NULL != uig->update_map) | 178 | if (NULL != uig->update_map) |
182 | GNUNET_CONTAINER_multihashmap_destroy (uig->update_map); | 179 | GNUNET_CONTAINER_multihashmap_destroy (uig->update_map); |
183 | GNUNET_free (uig); | 180 | GNUNET_free (uig); |
@@ -198,15 +195,14 @@ write_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) | |||
198 | struct NamespaceUpdateNode *n; | 195 | struct NamespaceUpdateNode *n; |
199 | char *uris; | 196 | char *uris; |
200 | 197 | ||
201 | fn = get_update_information_directory (uig->h, | 198 | fn = get_update_information_directory (uig->h, &uig->ns); |
202 | &uig->ns); | ||
203 | wh = GNUNET_BIO_write_open (fn); | 199 | wh = GNUNET_BIO_write_open (fn); |
204 | if (NULL == wh) | 200 | if (NULL == wh) |
205 | { | 201 | { |
206 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 202 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
207 | _("Failed to open `%s' for writing: %s\n"), | 203 | _ ("Failed to open `%s' for writing: %s\n"), |
208 | fn, | 204 | fn, |
209 | STRERROR (errno)); | 205 | strerror (errno)); |
210 | GNUNET_free (fn); | 206 | GNUNET_free (fn); |
211 | return; | 207 | return; |
212 | } | 208 | } |
@@ -229,9 +225,9 @@ write_update_information_graph (struct GNUNET_FS_UpdateInformationGraph *uig) | |||
229 | END: | 225 | END: |
230 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 226 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) |
231 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 227 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
232 | _("Failed to write `%s': %s\n"), | 228 | _ ("Failed to write `%s': %s\n"), |
233 | fn, | 229 | fn, |
234 | STRERROR (errno)); | 230 | strerror (errno)); |
235 | GNUNET_free (fn); | 231 | GNUNET_free (fn); |
236 | } | 232 | } |
237 | 233 | ||
@@ -245,7 +241,7 @@ END: | |||
245 | */ | 241 | */ |
246 | static struct GNUNET_FS_UpdateInformationGraph * | 242 | static struct GNUNET_FS_UpdateInformationGraph * |
247 | read_update_information_graph (struct GNUNET_FS_Handle *h, | 243 | read_update_information_graph (struct GNUNET_FS_Handle *h, |
248 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) | 244 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns) |
249 | { | 245 | { |
250 | struct GNUNET_FS_UpdateInformationGraph *uig; | 246 | struct GNUNET_FS_UpdateInformationGraph *uig; |
251 | char *fn; | 247 | char *fn; |
@@ -289,8 +285,9 @@ read_update_information_graph (struct GNUNET_FS_Handle *h, | |||
289 | for (i = 0; i < count; i++) | 285 | for (i = 0; i < count; i++) |
290 | { | 286 | { |
291 | n = GNUNET_new (struct NamespaceUpdateNode); | 287 | n = GNUNET_new (struct NamespaceUpdateNode); |
292 | if ((GNUNET_OK != GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024)) | 288 | if ((GNUNET_OK != |
293 | || (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) || | 289 | GNUNET_BIO_read_string (rh, "identifier", &n->id, 1024)) || |
290 | (GNUNET_OK != GNUNET_BIO_read_meta_data (rh, "meta", &n->md)) || | ||
294 | (GNUNET_OK != | 291 | (GNUNET_OK != |
295 | GNUNET_BIO_read_string (rh, "update-id", &n->update, 1024)) || | 292 | GNUNET_BIO_read_string (rh, "update-id", &n->update, 1024)) || |
296 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "uri", &uris, 1024 * 2))) | 293 | (GNUNET_OK != GNUNET_BIO_read_string (rh, "uri", &uris, 1024 * 2))) |
@@ -318,11 +315,13 @@ read_update_information_graph (struct GNUNET_FS_Handle *h, | |||
318 | uig->update_nodes[i] = n; | 315 | uig->update_nodes[i] = n; |
319 | } | 316 | } |
320 | uig->update_node_count = i; | 317 | uig->update_node_count = i; |
321 | END: | 318 | END: |
322 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) | 319 | if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) |
323 | { | 320 | { |
324 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to read `%s': %s\n"), | 321 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
325 | fn, emsg); | 322 | _ ("Failed to read `%s': %s\n"), |
323 | fn, | ||
324 | emsg); | ||
326 | GNUNET_free (emsg); | 325 | GNUNET_free (emsg); |
327 | } | 326 | } |
328 | GNUNET_free (fn); | 327 | GNUNET_free (fn); |
@@ -387,8 +386,7 @@ struct GNUNET_FS_PublishSksContext | |||
387 | * @param msg error message (or NULL) | 386 | * @param msg error message (or NULL) |
388 | */ | 387 | */ |
389 | static void | 388 | static void |
390 | sks_publish_cont (void *cls, | 389 | sks_publish_cont (void *cls, const char *msg) |
391 | const char *msg) | ||
392 | { | 390 | { |
393 | struct GNUNET_FS_PublishSksContext *psc = cls; | 391 | struct GNUNET_FS_PublishSksContext *psc = cls; |
394 | struct GNUNET_FS_UpdateInformationGraph *uig; | 392 | struct GNUNET_FS_UpdateInformationGraph *uig; |
@@ -406,11 +404,8 @@ sks_publish_cont (void *cls, | |||
406 | /* FIXME: this can be done much more | 404 | /* FIXME: this can be done much more |
407 | * efficiently by simply appending to the | 405 | * efficiently by simply appending to the |
408 | * file and overwriting the 4-byte header */ | 406 | * file and overwriting the 4-byte header */ |
409 | uig = read_update_information_graph (psc->h, | 407 | uig = read_update_information_graph (psc->h, &psc->ns); |
410 | &psc->ns); | 408 | GNUNET_array_append (uig->update_nodes, uig->update_node_count, psc->nsn); |
411 | GNUNET_array_append (uig->update_nodes, | ||
412 | uig->update_node_count, | ||
413 | psc->nsn); | ||
414 | psc->nsn = NULL; | 409 | psc->nsn = NULL; |
415 | write_update_information_graph (uig); | 410 | write_update_information_graph (uig); |
416 | free_update_information_graph (uig); | 411 | free_update_information_graph (uig); |
@@ -439,12 +434,14 @@ sks_publish_cont (void *cls, | |||
439 | struct GNUNET_FS_PublishSksContext * | 434 | struct GNUNET_FS_PublishSksContext * |
440 | GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, | 435 | GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, |
441 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, | 436 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, |
442 | const char *identifier, const char *update, | 437 | const char *identifier, |
438 | const char *update, | ||
443 | const struct GNUNET_CONTAINER_MetaData *meta, | 439 | const struct GNUNET_CONTAINER_MetaData *meta, |
444 | const struct GNUNET_FS_Uri *uri, | 440 | const struct GNUNET_FS_Uri *uri, |
445 | const struct GNUNET_FS_BlockOptions *bo, | 441 | const struct GNUNET_FS_BlockOptions *bo, |
446 | enum GNUNET_FS_PublishOptions options, | 442 | enum GNUNET_FS_PublishOptions options, |
447 | GNUNET_FS_PublishContinuation cont, void *cont_cls) | 443 | GNUNET_FS_PublishContinuation cont, |
444 | void *cont_cls) | ||
448 | { | 445 | { |
449 | struct GNUNET_FS_PublishSksContext *psc; | 446 | struct GNUNET_FS_PublishSksContext *psc; |
450 | struct GNUNET_FS_Uri *sks_uri; | 447 | struct GNUNET_FS_Uri *sks_uri; |
@@ -452,8 +449,7 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, | |||
452 | sks_uri = GNUNET_new (struct GNUNET_FS_Uri); | 449 | sks_uri = GNUNET_new (struct GNUNET_FS_Uri); |
453 | sks_uri->type = GNUNET_FS_URI_SKS; | 450 | sks_uri->type = GNUNET_FS_URI_SKS; |
454 | sks_uri->data.sks.identifier = GNUNET_strdup (identifier); | 451 | sks_uri->data.sks.identifier = GNUNET_strdup (identifier); |
455 | GNUNET_CRYPTO_ecdsa_key_get_public (ns, | 452 | GNUNET_CRYPTO_ecdsa_key_get_public (ns, &sks_uri->data.sks.ns); |
456 | &sks_uri->data.sks.ns); | ||
457 | 453 | ||
458 | psc = GNUNET_new (struct GNUNET_FS_PublishSksContext); | 454 | psc = GNUNET_new (struct GNUNET_FS_PublishSksContext); |
459 | psc->h = h; | 455 | psc->h = h; |
@@ -466,8 +462,7 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, | |||
466 | psc->dsh = GNUNET_DATASTORE_connect (h->cfg); | 462 | psc->dsh = GNUNET_DATASTORE_connect (h->cfg); |
467 | if (NULL == psc->dsh) | 463 | if (NULL == psc->dsh) |
468 | { | 464 | { |
469 | sks_publish_cont (psc, | 465 | sks_publish_cont (psc, _ ("Failed to connect to datastore.")); |
470 | _("Failed to connect to datastore.")); | ||
471 | return NULL; | 466 | return NULL; |
472 | } | 467 | } |
473 | } | 468 | } |
@@ -480,16 +475,16 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, | |||
480 | psc->nsn->uri = GNUNET_FS_uri_dup (uri); | 475 | psc->nsn->uri = GNUNET_FS_uri_dup (uri); |
481 | } | 476 | } |
482 | psc->uc = GNUNET_FS_publish_ublock_ (h, | 477 | psc->uc = GNUNET_FS_publish_ublock_ (h, |
483 | psc->dsh, | 478 | psc->dsh, |
484 | identifier, | 479 | identifier, |
485 | update, | 480 | update, |
486 | ns, | 481 | ns, |
487 | meta, | 482 | meta, |
488 | uri, | 483 | uri, |
489 | bo, | 484 | bo, |
490 | options, | 485 | options, |
491 | &sks_publish_cont, | 486 | &sks_publish_cont, |
492 | psc); | 487 | psc); |
493 | return psc; | 488 | return psc; |
494 | } | 489 | } |
495 | 490 | ||
@@ -553,18 +548,12 @@ struct ProcessUpdateClosure | |||
553 | * GNUNET_NO if not. | 548 | * GNUNET_NO if not. |
554 | */ | 549 | */ |
555 | static int | 550 | static int |
556 | process_update_node (void *cls, | 551 | process_update_node (void *cls, const struct GNUNET_HashCode *key, void *value) |
557 | const struct GNUNET_HashCode *key, | ||
558 | void *value) | ||
559 | { | 552 | { |
560 | struct ProcessUpdateClosure *pc = cls; | 553 | struct ProcessUpdateClosure *pc = cls; |
561 | struct NamespaceUpdateNode *nsn = value; | 554 | struct NamespaceUpdateNode *nsn = value; |
562 | 555 | ||
563 | pc->ip (pc->ip_cls, | 556 | pc->ip (pc->ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); |
564 | nsn->id, | ||
565 | nsn->uri, | ||
566 | nsn->md, | ||
567 | nsn->update); | ||
568 | return GNUNET_YES; | 557 | return GNUNET_YES; |
569 | } | 558 | } |
570 | 559 | ||
@@ -622,9 +611,7 @@ struct FindTreeClosure | |||
622 | * GNUNET_NO if not. | 611 | * GNUNET_NO if not. |
623 | */ | 612 | */ |
624 | static int | 613 | static int |
625 | find_trees (void *cls, | 614 | find_trees (void *cls, const struct GNUNET_HashCode *key, void *value) |
626 | const struct GNUNET_HashCode *key, | ||
627 | void *value) | ||
628 | { | 615 | { |
629 | struct FindTreeClosure *fc = cls; | 616 | struct FindTreeClosure *fc = cls; |
630 | struct NamespaceUpdateNode *nsn = value; | 617 | struct NamespaceUpdateNode *nsn = value; |
@@ -633,26 +620,28 @@ find_trees (void *cls, | |||
633 | if (nsn->nug == fc->nug) | 620 | if (nsn->nug == fc->nug) |
634 | { | 621 | { |
635 | if (UINT_MAX == nsn->tree_id) | 622 | if (UINT_MAX == nsn->tree_id) |
636 | return GNUNET_YES; /* circular */ | 623 | return GNUNET_YES; /* circular */ |
637 | GNUNET_assert (nsn->tree_id < fc->tree_array_size); | 624 | GNUNET_assert (nsn->tree_id < fc->tree_array_size); |
638 | if (fc->tree_array[nsn->tree_id] != nsn) | 625 | if (fc->tree_array[nsn->tree_id] != nsn) |
639 | return GNUNET_YES; /* part of "another" (directed) TREE, | 626 | return GNUNET_YES; /* part of "another" (directed) TREE, |
640 | * and not root of it, end trace */ | 627 | * and not root of it, end trace */ |
641 | if (nsn->tree_id == fc->id) | 628 | if (nsn->tree_id == fc->id) |
642 | return GNUNET_YES; /* that's our own root (can this be?) */ | 629 | return GNUNET_YES; /* that's our own root (can this be?) */ |
643 | /* merge existing TREE, we have a root for both */ | 630 | /* merge existing TREE, we have a root for both */ |
644 | fc->tree_array[nsn->tree_id] = NULL; | 631 | fc->tree_array[nsn->tree_id] = NULL; |
645 | if (UINT_MAX == fc->id) | 632 | if (UINT_MAX == fc->id) |
646 | fc->id = nsn->tree_id; /* take over ID */ | 633 | fc->id = nsn->tree_id; /* take over ID */ |
647 | } | 634 | } |
648 | else | 635 | else |
649 | { | 636 | { |
650 | nsn->nug = fc->nug; | 637 | nsn->nug = fc->nug; |
651 | nsn->tree_id = UINT_MAX; /* mark as undef */ | 638 | nsn->tree_id = UINT_MAX; /* mark as undef */ |
652 | /* trace */ | 639 | /* trace */ |
653 | GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc); | 640 | GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc); |
654 | GNUNET_CONTAINER_multihashmap_get_multiple (fc->uig->update_map, &hc, | 641 | GNUNET_CONTAINER_multihashmap_get_multiple (fc->uig->update_map, |
655 | &find_trees, fc); | 642 | &hc, |
643 | &find_trees, | ||
644 | fc); | ||
656 | } | 645 | } |
657 | return GNUNET_YES; | 646 | return GNUNET_YES; |
658 | } | 647 | } |
@@ -682,11 +671,12 @@ find_trees (void *cls, | |||
682 | * @param ip_cls closure for ip | 671 | * @param ip_cls closure for ip |
683 | */ | 672 | */ |
684 | void | 673 | void |
685 | GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h, | 674 | GNUNET_FS_namespace_list_updateable ( |
686 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, | 675 | struct GNUNET_FS_Handle *h, |
687 | const char *next_id, | 676 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, |
688 | GNUNET_FS_IdentifierProcessor ip, | 677 | const char *next_id, |
689 | void *ip_cls) | 678 | GNUNET_FS_IdentifierProcessor ip, |
679 | void *ip_cls) | ||
690 | { | 680 | { |
691 | unsigned int i; | 681 | unsigned int i; |
692 | unsigned int nug; | 682 | unsigned int nug; |
@@ -700,29 +690,33 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h, | |||
700 | if (NULL == uig->update_nodes) | 690 | if (NULL == uig->update_nodes) |
701 | { | 691 | { |
702 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 692 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
703 | "No updateable nodes found for ID `%s'\n", next_id); | 693 | "No updateable nodes found for ID `%s'\n", |
694 | next_id); | ||
704 | free_update_information_graph (uig); | 695 | free_update_information_graph (uig); |
705 | return; /* no nodes */ | 696 | return; /* no nodes */ |
706 | } | 697 | } |
707 | uig->update_map = | 698 | uig->update_map = |
708 | GNUNET_CONTAINER_multihashmap_create (2 + | 699 | GNUNET_CONTAINER_multihashmap_create (2 + 3 * uig->update_node_count / 4, |
709 | 3 * uig->update_node_count / | 700 | GNUNET_NO); |
710 | 4, | ||
711 | GNUNET_NO); | ||
712 | for (i = 0; i < uig->update_node_count; i++) | 701 | for (i = 0; i < uig->update_node_count; i++) |
713 | { | 702 | { |
714 | nsn = uig->update_nodes[i]; | 703 | nsn = uig->update_nodes[i]; |
715 | GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc); | 704 | GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc); |
716 | GNUNET_CONTAINER_multihashmap_put (uig->update_map, &hc, nsn, | 705 | GNUNET_CONTAINER_multihashmap_put ( |
717 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 706 | uig->update_map, |
707 | &hc, | ||
708 | nsn, | ||
709 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
718 | } | 710 | } |
719 | if (NULL != next_id) | 711 | if (NULL != next_id) |
720 | { | 712 | { |
721 | GNUNET_CRYPTO_hash (next_id, strlen (next_id), &hc); | 713 | GNUNET_CRYPTO_hash (next_id, strlen (next_id), &hc); |
722 | pc.ip = ip; | 714 | pc.ip = ip; |
723 | pc.ip_cls = ip_cls; | 715 | pc.ip_cls = ip_cls; |
724 | GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, &hc, | 716 | GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, |
725 | &process_update_node, &pc); | 717 | &hc, |
718 | &process_update_node, | ||
719 | &pc); | ||
726 | free_update_information_graph (uig); | 720 | free_update_information_graph (uig); |
727 | return; | 721 | return; |
728 | } | 722 | } |
@@ -738,9 +732,11 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h, | |||
738 | nsn = uig->update_nodes[i]; | 732 | nsn = uig->update_nodes[i]; |
739 | if (nsn->nug == nug) | 733 | if (nsn->nug == nug) |
740 | { | 734 | { |
741 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TREE of node `%s' is %u\n", nsn->id, | 735 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
736 | "TREE of node `%s' is %u\n", | ||
737 | nsn->id, | ||
742 | nsn->nug); | 738 | nsn->nug); |
743 | continue; /* already placed in TREE */ | 739 | continue; /* already placed in TREE */ |
744 | } | 740 | } |
745 | GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc); | 741 | GNUNET_CRYPTO_hash (nsn->update, strlen (nsn->update), &hc); |
746 | nsn->nug = nug; | 742 | nsn->nug = nug; |
@@ -748,8 +744,10 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h, | |||
748 | fc.id = UINT_MAX; | 744 | fc.id = UINT_MAX; |
749 | fc.nug = nug; | 745 | fc.nug = nug; |
750 | fc.uig = uig; | 746 | fc.uig = uig; |
751 | GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, &hc, | 747 | GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, |
752 | &find_trees, &fc); | 748 | &hc, |
749 | &find_trees, | ||
750 | &fc); | ||
753 | if (UINT_MAX == fc.id) | 751 | if (UINT_MAX == fc.id) |
754 | { | 752 | { |
755 | /* start new TREE */ | 753 | /* start new TREE */ |
@@ -768,15 +766,18 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h, | |||
768 | nsn->tree_id = fc.id; | 766 | nsn->tree_id = fc.id; |
769 | } | 767 | } |
770 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 768 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
771 | "Starting new TREE %u with node `%s'\n", nsn->tree_id, | 769 | "Starting new TREE %u with node `%s'\n", |
770 | nsn->tree_id, | ||
772 | nsn->id); | 771 | nsn->id); |
773 | /* put all nodes with same identifier into this TREE */ | 772 | /* put all nodes with same identifier into this TREE */ |
774 | GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc); | 773 | GNUNET_CRYPTO_hash (nsn->id, strlen (nsn->id), &hc); |
775 | fc.id = nsn->tree_id; | 774 | fc.id = nsn->tree_id; |
776 | fc.nug = nug; | 775 | fc.nug = nug; |
777 | fc.uig = uig; | 776 | fc.uig = uig; |
778 | GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, &hc, | 777 | GNUNET_CONTAINER_multihashmap_get_multiple (uig->update_map, |
779 | &find_trees, &fc); | 778 | &hc, |
779 | &find_trees, | ||
780 | &fc); | ||
780 | } | 781 | } |
781 | else | 782 | else |
782 | { | 783 | { |
@@ -785,7 +786,8 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h, | |||
785 | nsn->tree_id = fc.id; | 786 | nsn->tree_id = fc.id; |
786 | } | 787 | } |
787 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 788 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
788 | "TREE of node `%s' is %u\n", nsn->id, | 789 | "TREE of node `%s' is %u\n", |
790 | nsn->id, | ||
789 | fc.id); | 791 | fc.id); |
790 | } | 792 | } |
791 | for (i = 0; i < fc.tree_array_size; i++) | 793 | for (i = 0; i < fc.tree_array_size; i++) |
@@ -793,7 +795,9 @@ GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Handle *h, | |||
793 | nsn = fc.tree_array[i]; | 795 | nsn = fc.tree_array[i]; |
794 | if (NULL != nsn) | 796 | if (NULL != nsn) |
795 | { | 797 | { |
796 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Root of TREE %u is node `%s'\n", i, | 798 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
799 | "Root of TREE %u is node `%s'\n", | ||
800 | i, | ||
797 | nsn->id); | 801 | nsn->id); |
798 | ip (ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); | 802 | ip (ip_cls, nsn->id, nsn->uri, nsn->md, nsn->update); |
799 | } | 803 | } |
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 @@ | |||
91 | #include <unistdio.h> | 91 | #include <unistdio.h> |
92 | 92 | ||
93 | 93 | ||
94 | |||
95 | /** | 94 | /** |
96 | * Get a unique key from a URI. This is for putting URIs | 95 | * Get a unique key from a URI. This is for putting URIs |
97 | * into HashMaps. The key may change between FS implementations. | 96 | * into HashMaps. The key may change between FS implementations. |
@@ -102,7 +101,7 @@ | |||
102 | */ | 101 | */ |
103 | int | 102 | int |
104 | GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, | 103 | GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, |
105 | struct GNUNET_HashCode *key) | 104 | struct GNUNET_HashCode *key) |
106 | { | 105 | { |
107 | switch (uri->type) | 106 | switch (uri->type) |
108 | { | 107 | { |
@@ -112,14 +111,14 @@ GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, | |||
112 | case GNUNET_FS_URI_SKS: | 111 | case GNUNET_FS_URI_SKS: |
113 | GNUNET_CRYPTO_hash (uri->data.sks.identifier, | 112 | GNUNET_CRYPTO_hash (uri->data.sks.identifier, |
114 | strlen (uri->data.sks.identifier), | 113 | strlen (uri->data.sks.identifier), |
115 | key); | 114 | key); |
116 | return GNUNET_OK; | 115 | return GNUNET_OK; |
117 | case GNUNET_FS_URI_KSK: | 116 | case GNUNET_FS_URI_KSK: |
118 | if (uri->data.ksk.keywordCount > 0) | 117 | if (uri->data.ksk.keywordCount > 0) |
119 | { | 118 | { |
120 | GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0], | 119 | GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0], |
121 | strlen (uri->data.ksk.keywords[0]), | 120 | strlen (uri->data.ksk.keywords[0]), |
122 | key); | 121 | key); |
123 | return GNUNET_OK; | 122 | return GNUNET_OK; |
124 | } | 123 | } |
125 | else | 124 | else |
@@ -131,7 +130,7 @@ GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, | |||
131 | case GNUNET_FS_URI_LOC: | 130 | case GNUNET_FS_URI_LOC: |
132 | GNUNET_CRYPTO_hash (&uri->data.loc.fi, | 131 | GNUNET_CRYPTO_hash (&uri->data.loc.fi, |
133 | sizeof (struct FileIdentifier) + | 132 | sizeof (struct FileIdentifier) + |
134 | sizeof (struct GNUNET_PeerIdentity), | 133 | sizeof (struct GNUNET_PeerIdentity), |
135 | key); | 134 | key); |
136 | return GNUNET_OK; | 135 | return GNUNET_OK; |
137 | default: | 136 | default: |
@@ -213,8 +212,7 @@ GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri) | |||
213 | * @return decodded string with leading space (or preserved plus) | 212 | * @return decodded string with leading space (or preserved plus) |
214 | */ | 213 | */ |
215 | static char * | 214 | static char * |
216 | percent_decode_keyword (const char *in, | 215 | percent_decode_keyword (const char *in, char **emsg) |
217 | char **emsg) | ||
218 | { | 216 | { |
219 | char *out; | 217 | char *out; |
220 | char *ret; | 218 | char *ret; |
@@ -229,16 +227,17 @@ percent_decode_keyword (const char *in, | |||
229 | { | 227 | { |
230 | if (out[rpos] == '%') | 228 | if (out[rpos] == '%') |
231 | { | 229 | { |
232 | if (1 != SSCANF (&out[rpos + 1], "%2X", &hx)) | 230 | if (1 != sscanf (&out[rpos + 1], "%2X", &hx)) |
233 | { | 231 | { |
234 | GNUNET_free (out); | 232 | GNUNET_free (out); |
235 | *emsg = GNUNET_strdup (_(/* xgettext:no-c-format */ | 233 | *emsg = GNUNET_strdup ( |
236 | "Malformed KSK URI (`%' must be followed by HEX number)")); | 234 | _ (/* xgettext:no-c-format */ |
235 | "Malformed KSK URI (`%' must be followed by HEX number)")); | ||
237 | return NULL; | 236 | return NULL; |
238 | } | 237 | } |
239 | rpos += 3; | 238 | rpos += 3; |
240 | if (hx == '"') | 239 | if (hx == '"') |
241 | continue; /* skip double quote */ | 240 | continue; /* skip double quote */ |
242 | out[wpos++] = (char) hx; | 241 | out[wpos++] = (char) hx; |
243 | } | 242 | } |
244 | else | 243 | else |
@@ -272,8 +271,7 @@ percent_decode_keyword (const char *in, | |||
272 | * @return NULL on error, otherwise the KSK URI | 271 | * @return NULL on error, otherwise the KSK URI |
273 | */ | 272 | */ |
274 | static struct GNUNET_FS_Uri * | 273 | static struct GNUNET_FS_Uri * |
275 | uri_ksk_parse (const char *s, | 274 | uri_ksk_parse (const char *s, char **emsg) |
276 | char **emsg) | ||
277 | { | 275 | { |
278 | struct GNUNET_FS_Uri *ret; | 276 | struct GNUNET_FS_Uri *ret; |
279 | char **keywords; | 277 | char **keywords; |
@@ -288,11 +286,11 @@ uri_ksk_parse (const char *s, | |||
288 | slen = strlen (s); | 286 | slen = strlen (s); |
289 | pos = strlen (GNUNET_FS_URI_KSK_PREFIX); | 287 | pos = strlen (GNUNET_FS_URI_KSK_PREFIX); |
290 | if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX, pos))) | 288 | if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX, pos))) |
291 | return NULL; /* not KSK URI */ | 289 | return NULL; /* not KSK URI */ |
292 | if ((s[slen - 1] == '+') || (s[pos] == '+')) | 290 | if ((s[slen - 1] == '+') || (s[pos] == '+')) |
293 | { | 291 | { |
294 | *emsg = | 292 | *emsg = |
295 | GNUNET_strdup (_("Malformed KSK URI (must not begin or end with `+')")); | 293 | GNUNET_strdup (_ ("Malformed KSK URI (must not begin or end with `+')")); |
296 | return NULL; | 294 | return NULL; |
297 | } | 295 | } |
298 | max = 1; | 296 | max = 1; |
@@ -310,20 +308,19 @@ uri_ksk_parse (const char *s, | |||
310 | max++; | 308 | max++; |
311 | if (s[i - 1] == '+') | 309 | if (s[i - 1] == '+') |
312 | { | 310 | { |
313 | *emsg = GNUNET_strdup (_("Malformed KSK URI (`++' not allowed)")); | 311 | *emsg = GNUNET_strdup (_ ("Malformed KSK URI (`++' not allowed)")); |
314 | return NULL; | 312 | return NULL; |
315 | } | 313 | } |
316 | } | 314 | } |
317 | } | 315 | } |
318 | if (saw_quote == 1) | 316 | if (saw_quote == 1) |
319 | { | 317 | { |
320 | *emsg = GNUNET_strdup (_("Malformed KSK URI (quotes not balanced)")); | 318 | *emsg = GNUNET_strdup (_ ("Malformed KSK URI (quotes not balanced)")); |
321 | return NULL; | 319 | return NULL; |
322 | } | 320 | } |
323 | iret = max; | 321 | iret = max; |
324 | dup = GNUNET_strdup (s); | 322 | dup = GNUNET_strdup (s); |
325 | keywords = GNUNET_new_array (max, | 323 | keywords = GNUNET_new_array (max, char *); |
326 | char *); | ||
327 | for (i = slen - 1; i >= (int) pos; i--) | 324 | for (i = slen - 1; i >= (int) pos; i--) |
328 | { | 325 | { |
329 | if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22"))) | 326 | if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22"))) |
@@ -368,8 +365,7 @@ CLEANUP: | |||
368 | * @return NULL on error, SKS URI otherwise | 365 | * @return NULL on error, SKS URI otherwise |
369 | */ | 366 | */ |
370 | static struct GNUNET_FS_Uri * | 367 | static struct GNUNET_FS_Uri * |
371 | uri_sks_parse (const char *s, | 368 | uri_sks_parse (const char *s, char **emsg) |
372 | char **emsg) | ||
373 | { | 369 | { |
374 | struct GNUNET_FS_Uri *ret; | 370 | struct GNUNET_FS_Uri *ret; |
375 | struct GNUNET_CRYPTO_EcdsaPublicKey ns; | 371 | struct GNUNET_CRYPTO_EcdsaPublicKey ns; |
@@ -378,16 +374,15 @@ uri_sks_parse (const char *s, | |||
378 | 374 | ||
379 | pos = strlen (GNUNET_FS_URI_SKS_PREFIX); | 375 | pos = strlen (GNUNET_FS_URI_SKS_PREFIX); |
380 | if ((strlen (s) <= pos) || (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, pos))) | 376 | if ((strlen (s) <= pos) || (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, pos))) |
381 | return NULL; /* not an SKS URI */ | 377 | return NULL; /* not an SKS URI */ |
382 | end = strchr (&s[pos], '/'); | 378 | end = strchr (&s[pos], '/'); |
383 | if ( (NULL == end) || | 379 | if ((NULL == end) || |
384 | (GNUNET_OK != | 380 | (GNUNET_OK != GNUNET_STRINGS_string_to_data (&s[pos], |
385 | GNUNET_STRINGS_string_to_data (&s[pos], | 381 | end - &s[pos], |
386 | end - &s[pos], | 382 | &ns, |
387 | &ns, | 383 | sizeof (ns)))) |
388 | sizeof (ns))) ) | ||
389 | { | 384 | { |
390 | *emsg = GNUNET_strdup (_("Malformed SKS URI (wrong syntax)")); | 385 | *emsg = GNUNET_strdup (_ ("Malformed SKS URI (wrong syntax)")); |
391 | return NULL; /* malformed */ | 386 | return NULL; /* malformed */ |
392 | } | 387 | } |
393 | end++; /* skip over '/' */ | 388 | end++; /* skip over '/' */ |
@@ -409,8 +404,7 @@ uri_sks_parse (const char *s, | |||
409 | * @return NULL on error, CHK URI otherwise | 404 | * @return NULL on error, CHK URI otherwise |
410 | */ | 405 | */ |
411 | static struct GNUNET_FS_Uri * | 406 | static struct GNUNET_FS_Uri * |
412 | uri_chk_parse (const char *s, | 407 | uri_chk_parse (const char *s, char **emsg) |
413 | char **emsg) | ||
414 | { | 408 | { |
415 | struct GNUNET_FS_Uri *ret; | 409 | struct GNUNET_FS_Uri *ret; |
416 | struct FileIdentifier fi; | 410 | struct FileIdentifier fi; |
@@ -424,26 +418,28 @@ uri_chk_parse (const char *s, | |||
424 | pos = strlen (GNUNET_FS_URI_CHK_PREFIX); | 418 | pos = strlen (GNUNET_FS_URI_CHK_PREFIX); |
425 | if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || | 419 | if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || |
426 | (0 != strncmp (s, GNUNET_FS_URI_CHK_PREFIX, pos))) | 420 | (0 != strncmp (s, GNUNET_FS_URI_CHK_PREFIX, pos))) |
427 | return NULL; /* not a CHK URI */ | 421 | return NULL; /* not a CHK URI */ |
428 | if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || | 422 | if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || |
429 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) | 423 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) |
430 | { | 424 | { |
431 | *emsg = GNUNET_strdup (_("Malformed CHK URI (wrong syntax)")); | 425 | *emsg = GNUNET_strdup (_ ("Malformed CHK URI (wrong syntax)")); |
432 | return NULL; | 426 | return NULL; |
433 | } | 427 | } |
434 | GNUNET_memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | 428 | GNUNET_memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); |
435 | h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | 429 | h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
436 | GNUNET_memcpy (h2, &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], | 430 | GNUNET_memcpy (h2, |
437 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | 431 | &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], |
432 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | ||
438 | h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | 433 | h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
439 | 434 | ||
440 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &fi.chk.key)) || | 435 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &fi.chk.key)) || |
441 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &fi.chk.query)) || | 436 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &fi.chk.query)) || |
442 | (1 != | 437 | (1 != |
443 | SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], | 438 | sscanf (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], |
444 | "%llu", &flen))) | 439 | "%llu", |
440 | &flen))) | ||
445 | { | 441 | { |
446 | *emsg = GNUNET_strdup (_("Malformed CHK URI (failed to decode CHK)")); | 442 | *emsg = GNUNET_strdup (_ ("Malformed CHK URI (failed to decode CHK)")); |
447 | return NULL; | 443 | return NULL; |
448 | } | 444 | } |
449 | fi.file_length = GNUNET_htonll (flen); | 445 | fi.file_length = GNUNET_htonll (flen); |
@@ -481,7 +477,6 @@ struct LocUriAssembly | |||
481 | * Peer offering the file. | 477 | * Peer offering the file. |
482 | */ | 478 | */ |
483 | struct GNUNET_PeerIdentity peer; | 479 | struct GNUNET_PeerIdentity peer; |
484 | |||
485 | }; | 480 | }; |
486 | GNUNET_NETWORK_STRUCT_END | 481 | GNUNET_NETWORK_STRUCT_END |
487 | 482 | ||
@@ -499,8 +494,7 @@ GNUNET_NETWORK_STRUCT_END | |||
499 | * @return NULL on error, valid LOC URI otherwise | 494 | * @return NULL on error, valid LOC URI otherwise |
500 | */ | 495 | */ |
501 | static struct GNUNET_FS_Uri * | 496 | static struct GNUNET_FS_Uri * |
502 | uri_loc_parse (const char *s, | 497 | uri_loc_parse (const char *s, char **emsg) |
503 | char **emsg) | ||
504 | { | 498 | { |
505 | struct GNUNET_FS_Uri *uri; | 499 | struct GNUNET_FS_Uri *uri; |
506 | char h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; | 500 | char h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; |
@@ -518,26 +512,28 @@ uri_loc_parse (const char *s, | |||
518 | pos = strlen (GNUNET_FS_URI_LOC_PREFIX); | 512 | pos = strlen (GNUNET_FS_URI_LOC_PREFIX); |
519 | if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || | 513 | if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) || |
520 | (0 != strncmp (s, GNUNET_FS_URI_LOC_PREFIX, pos))) | 514 | (0 != strncmp (s, GNUNET_FS_URI_LOC_PREFIX, pos))) |
521 | return NULL; /* not a LOC URI */ | 515 | return NULL; /* not a LOC URI */ |
522 | if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || | 516 | if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') || |
523 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) | 517 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.')) |
524 | { | 518 | { |
525 | *emsg = GNUNET_strdup (_("LOC URI malformed (wrong syntax)")); | 519 | *emsg = GNUNET_strdup (_ ("LOC URI malformed (wrong syntax)")); |
526 | return NULL; | 520 | return NULL; |
527 | } | 521 | } |
528 | GNUNET_memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | 522 | GNUNET_memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); |
529 | h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | 523 | h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
530 | GNUNET_memcpy (h2, &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], | 524 | GNUNET_memcpy (h2, |
531 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | 525 | &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], |
526 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | ||
532 | h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | 527 | h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
533 | 528 | ||
534 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &ass.fi.chk.key)) || | 529 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &ass.fi.chk.key)) || |
535 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &ass.fi.chk.query)) || | 530 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &ass.fi.chk.query)) || |
536 | (1 != | 531 | (1 != |
537 | SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], | 532 | sscanf (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], |
538 | "%llu", &flen))) | 533 | "%llu", |
534 | &flen))) | ||
539 | { | 535 | { |
540 | *emsg = GNUNET_strdup (_("LOC URI malformed (no CHK)")); | 536 | *emsg = GNUNET_strdup (_ ("LOC URI malformed (no CHK)")); |
541 | return NULL; | 537 | return NULL; |
542 | } | 538 | } |
543 | ass.fi.file_length = GNUNET_htonll (flen); | 539 | ass.fi.file_length = GNUNET_htonll (flen); |
@@ -547,56 +543,61 @@ uri_loc_parse (const char *s, | |||
547 | npos++; | 543 | npos++; |
548 | if (s[npos] == '\0') | 544 | if (s[npos] == '\0') |
549 | { | 545 | { |
550 | *emsg = GNUNET_strdup (_("LOC URI malformed (missing LOC)")); | 546 | *emsg = GNUNET_strdup (_ ("LOC URI malformed (missing LOC)")); |
551 | goto ERR; | 547 | goto ERR; |
552 | } | 548 | } |
553 | npos++; | 549 | npos++; |
554 | if ( (strlen (&s[npos]) <= GNUNET_CRYPTO_PKEY_ASCII_LENGTH + 1) || | 550 | if ((strlen (&s[npos]) <= GNUNET_CRYPTO_PKEY_ASCII_LENGTH + 1) || |
555 | ('.' != s[npos+GNUNET_CRYPTO_PKEY_ASCII_LENGTH]) ) | 551 | ('.' != s[npos + GNUNET_CRYPTO_PKEY_ASCII_LENGTH])) |
556 | { | 552 | { |
557 | *emsg = | 553 | *emsg = |
558 | GNUNET_strdup (_("LOC URI malformed (wrong syntax for public key)")); | 554 | GNUNET_strdup (_ ("LOC URI malformed (wrong syntax for public key)")); |
559 | } | 555 | } |
560 | if (GNUNET_OK != | 556 | if ( |
561 | GNUNET_CRYPTO_eddsa_public_key_from_string (&s[npos], | 557 | GNUNET_OK != |
562 | GNUNET_CRYPTO_PKEY_ASCII_LENGTH, | 558 | GNUNET_CRYPTO_eddsa_public_key_from_string (&s[npos], |
563 | &ass.peer.public_key)) | 559 | GNUNET_CRYPTO_PKEY_ASCII_LENGTH, |
560 | &ass.peer.public_key)) | ||
564 | { | 561 | { |
565 | *emsg = | 562 | *emsg = |
566 | GNUNET_strdup (_("LOC URI malformed (could not decode public key)")); | 563 | GNUNET_strdup (_ ("LOC URI malformed (could not decode public key)")); |
567 | goto ERR; | 564 | goto ERR; |
568 | } | 565 | } |
569 | npos += GNUNET_CRYPTO_PKEY_ASCII_LENGTH; | 566 | npos += GNUNET_CRYPTO_PKEY_ASCII_LENGTH; |
570 | if (s[npos++] != '.') | 567 | if (s[npos++] != '.') |
571 | { | 568 | { |
572 | *emsg = GNUNET_strdup (_("LOC URI malformed (could not find signature)")); | 569 | *emsg = GNUNET_strdup (_ ("LOC URI malformed (could not find signature)")); |
573 | goto ERR; | 570 | goto ERR; |
574 | } | 571 | } |
575 | if ( (strlen (&s[npos]) <= SIGNATURE_ASCII_LENGTH + 1) || | 572 | if ((strlen (&s[npos]) <= SIGNATURE_ASCII_LENGTH + 1) || |
576 | ('.' != s[npos + SIGNATURE_ASCII_LENGTH]) ) | 573 | ('.' != s[npos + SIGNATURE_ASCII_LENGTH])) |
577 | { | 574 | { |
578 | *emsg = GNUNET_strdup (_("LOC URI malformed (wrong syntax for signature)")); | 575 | *emsg = |
576 | GNUNET_strdup (_ ("LOC URI malformed (wrong syntax for signature)")); | ||
579 | goto ERR; | 577 | goto ERR; |
580 | } | 578 | } |
581 | if (GNUNET_OK != | 579 | if (GNUNET_OK != |
582 | GNUNET_STRINGS_string_to_data (&s[npos], | 580 | GNUNET_STRINGS_string_to_data (&s[npos], |
583 | SIGNATURE_ASCII_LENGTH, | 581 | SIGNATURE_ASCII_LENGTH, |
584 | &sig, | 582 | &sig, |
585 | sizeof (struct GNUNET_CRYPTO_EddsaSignature))) | 583 | sizeof ( |
584 | struct GNUNET_CRYPTO_EddsaSignature))) | ||
586 | { | 585 | { |
587 | *emsg = GNUNET_strdup (_("LOC URI malformed (could not decode signature)")); | 586 | *emsg = |
587 | GNUNET_strdup (_ ("LOC URI malformed (could not decode signature)")); | ||
588 | goto ERR; | 588 | goto ERR; |
589 | } | 589 | } |
590 | npos += SIGNATURE_ASCII_LENGTH; | 590 | npos += SIGNATURE_ASCII_LENGTH; |
591 | if (s[npos++] != '.') | 591 | if (s[npos++] != '.') |
592 | { | 592 | { |
593 | *emsg = GNUNET_strdup (_("LOC URI malformed (wrong syntax for expiration time)")); | 593 | *emsg = GNUNET_strdup ( |
594 | _ ("LOC URI malformed (wrong syntax for expiration time)")); | ||
594 | goto ERR; | 595 | goto ERR; |
595 | } | 596 | } |
596 | if (1 != SSCANF (&s[npos], "%llu", &exptime)) | 597 | if (1 != sscanf (&s[npos], "%llu", &exptime)) |
597 | { | 598 | { |
598 | *emsg = | 599 | *emsg = |
599 | GNUNET_strdup (_("LOC URI malformed (could not parse expiration time)")); | 600 | GNUNET_strdup (_ ("LOC URI malformed (could not parse expiration time)")); |
600 | goto ERR; | 601 | goto ERR; |
601 | } | 602 | } |
602 | ass.purpose.size = htonl (sizeof (struct LocUriAssembly)); | 603 | ass.purpose.size = htonl (sizeof (struct LocUriAssembly)); |
@@ -605,10 +606,12 @@ uri_loc_parse (const char *s, | |||
605 | ass.exptime = GNUNET_TIME_absolute_hton (et); | 606 | ass.exptime = GNUNET_TIME_absolute_hton (et); |
606 | if (GNUNET_OK != | 607 | if (GNUNET_OK != |
607 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT, | 608 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT, |
608 | &ass.purpose, &sig, &ass.peer.public_key)) | 609 | &ass.purpose, |
610 | &sig, | ||
611 | &ass.peer.public_key)) | ||
609 | { | 612 | { |
610 | *emsg = | 613 | *emsg = |
611 | GNUNET_strdup (_("LOC URI malformed (signature failed validation)")); | 614 | GNUNET_strdup (_ ("LOC URI malformed (signature failed validation)")); |
612 | goto ERR; | 615 | goto ERR; |
613 | } | 616 | } |
614 | uri = GNUNET_new (struct GNUNET_FS_Uri); | 617 | uri = GNUNET_new (struct GNUNET_FS_Uri); |
@@ -632,8 +635,7 @@ ERR: | |||
632 | * @return NULL on error | 635 | * @return NULL on error |
633 | */ | 636 | */ |
634 | struct GNUNET_FS_Uri * | 637 | struct GNUNET_FS_Uri * |
635 | GNUNET_FS_uri_parse (const char *uri, | 638 | GNUNET_FS_uri_parse (const char *uri, char **emsg) |
636 | char **emsg) | ||
637 | { | 639 | { |
638 | struct GNUNET_FS_Uri *ret; | 640 | struct GNUNET_FS_Uri *ret; |
639 | char *msg; | 641 | char *msg; |
@@ -642,7 +644,7 @@ GNUNET_FS_uri_parse (const char *uri, | |||
642 | { | 644 | { |
643 | GNUNET_break (0); | 645 | GNUNET_break (0); |
644 | if (NULL != emsg) | 646 | if (NULL != emsg) |
645 | *emsg = GNUNET_strdup (_("invalid argument")); | 647 | *emsg = GNUNET_strdup (_ ("invalid argument")); |
646 | return NULL; | 648 | return NULL; |
647 | } | 649 | } |
648 | if (NULL == emsg) | 650 | if (NULL == emsg) |
@@ -654,7 +656,7 @@ GNUNET_FS_uri_parse (const char *uri, | |||
654 | (NULL != (ret = uri_loc_parse (uri, emsg)))) | 656 | (NULL != (ret = uri_loc_parse (uri, emsg)))) |
655 | return ret; | 657 | return ret; |
656 | if (NULL == *emsg) | 658 | if (NULL == *emsg) |
657 | *emsg = GNUNET_strdup (_("Unrecognized URI type")); | 659 | *emsg = GNUNET_strdup (_ ("Unrecognized URI type")); |
658 | if (emsg == &msg) | 660 | if (emsg == &msg) |
659 | GNUNET_free (msg); | 661 | GNUNET_free (msg); |
660 | return NULL; | 662 | return NULL; |
@@ -789,8 +791,9 @@ GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri, | |||
789 | if (0 == strcmp (&old[1], keyword)) | 791 | if (0 == strcmp (&old[1], keyword)) |
790 | { | 792 | { |
791 | uri->data.ksk.keywords[i] = | 793 | uri->data.ksk.keywords[i] = |
792 | uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1]; | 794 | uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1]; |
793 | GNUNET_array_grow (uri->data.ksk.keywords, uri->data.ksk.keywordCount, | 795 | GNUNET_array_grow (uri->data.ksk.keywords, |
796 | uri->data.ksk.keywordCount, | ||
794 | uri->data.ksk.keywordCount - 1); | 797 | uri->data.ksk.keywordCount - 1); |
795 | GNUNET_free (old); | 798 | GNUNET_free (old); |
796 | return; | 799 | return; |
@@ -877,8 +880,7 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri, | |||
877 | return NULL; | 880 | return NULL; |
878 | /* we round expiration time to full seconds for SKS URIs */ | 881 | /* we round expiration time to full seconds for SKS URIs */ |
879 | et.abs_value_us = (expiration_time.abs_value_us / 1000000LL) * 1000000LL; | 882 | et.abs_value_us = (expiration_time.abs_value_us / 1000000LL) * 1000000LL; |
880 | GNUNET_CRYPTO_eddsa_key_get_public (sign_key, | 883 | GNUNET_CRYPTO_eddsa_key_get_public (sign_key, &my_public_key); |
881 | &my_public_key); | ||
882 | ass.purpose.size = htonl (sizeof (struct LocUriAssembly)); | 884 | ass.purpose.size = htonl (sizeof (struct LocUriAssembly)); |
883 | ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); | 885 | ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); |
884 | ass.exptime = GNUNET_TIME_absolute_hton (et); | 886 | ass.exptime = GNUNET_TIME_absolute_hton (et); |
@@ -906,7 +908,7 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri, | |||
906 | */ | 908 | */ |
907 | struct GNUNET_FS_Uri * | 909 | struct GNUNET_FS_Uri * |
908 | GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, | 910 | GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, |
909 | const char *id) | 911 | const char *id) |
910 | { | 912 | { |
911 | struct GNUNET_FS_Uri *ns_uri; | 913 | struct GNUNET_FS_Uri *ns_uri; |
912 | 914 | ||
@@ -951,8 +953,7 @@ GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1, | |||
951 | return NULL; | 953 | return NULL; |
952 | } | 954 | } |
953 | kc = u1->data.ksk.keywordCount; | 955 | kc = u1->data.ksk.keywordCount; |
954 | kl = GNUNET_new_array (kc + u2->data.ksk.keywordCount, | 956 | kl = GNUNET_new_array (kc + u2->data.ksk.keywordCount, char *); |
955 | char *); | ||
956 | for (i = 0; i < u1->data.ksk.keywordCount; i++) | 957 | for (i = 0; i < u1->data.ksk.keywordCount; i++) |
957 | kl[i] = GNUNET_strdup (u1->data.ksk.keywords[i]); | 958 | kl[i] = GNUNET_strdup (u1->data.ksk.keywords[i]); |
958 | for (i = 0; i < u2->data.ksk.keywordCount; i++) | 959 | for (i = 0; i < u2->data.ksk.keywordCount; i++) |
@@ -1006,14 +1007,13 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri) | |||
1006 | } | 1007 | } |
1007 | if (ret->data.ksk.keywordCount > 0) | 1008 | if (ret->data.ksk.keywordCount > 0) |
1008 | { | 1009 | { |
1009 | ret->data.ksk.keywords | 1010 | ret->data.ksk.keywords = |
1010 | = GNUNET_new_array (ret->data.ksk.keywordCount, | 1011 | GNUNET_new_array (ret->data.ksk.keywordCount, char *); |
1011 | char *); | ||
1012 | for (i = 0; i < ret->data.ksk.keywordCount; i++) | 1012 | for (i = 0; i < ret->data.ksk.keywordCount; i++) |
1013 | ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]); | 1013 | ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]); |
1014 | } | 1014 | } |
1015 | else | 1015 | else |
1016 | ret->data.ksk.keywords = NULL; /* just to be sure */ | 1016 | ret->data.ksk.keywords = NULL; /* just to be sure */ |
1017 | break; | 1017 | break; |
1018 | case GNUNET_FS_URI_SKS: | 1018 | case GNUNET_FS_URI_SKS: |
1019 | ret->data.sks.identifier = GNUNET_strdup (uri->data.sks.identifier); | 1019 | ret->data.sks.identifier = GNUNET_strdup (uri->data.sks.identifier); |
@@ -1045,8 +1045,7 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri) | |||
1045 | * if keywords is not legal (i.e. empty). | 1045 | * if keywords is not legal (i.e. empty). |
1046 | */ | 1046 | */ |
1047 | struct GNUNET_FS_Uri * | 1047 | struct GNUNET_FS_Uri * |
1048 | GNUNET_FS_uri_ksk_create (const char *keywords, | 1048 | GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg) |
1049 | char **emsg) | ||
1050 | { | 1049 | { |
1051 | char **keywordarr; | 1050 | char **keywordarr; |
1052 | unsigned int num_Words; | 1051 | unsigned int num_Words; |
@@ -1058,7 +1057,7 @@ GNUNET_FS_uri_ksk_create (const char *keywords, | |||
1058 | 1057 | ||
1059 | if (keywords == NULL) | 1058 | if (keywords == NULL) |
1060 | { | 1059 | { |
1061 | *emsg = GNUNET_strdup (_("No keywords specified!\n")); | 1060 | *emsg = GNUNET_strdup (_ ("No keywords specified!\n")); |
1062 | GNUNET_break (0); | 1061 | GNUNET_break (0); |
1063 | return NULL; | 1062 | return NULL; |
1064 | } | 1063 | } |
@@ -1085,17 +1084,16 @@ GNUNET_FS_uri_ksk_create (const char *keywords, | |||
1085 | if (num_Words == 0) | 1084 | if (num_Words == 0) |
1086 | { | 1085 | { |
1087 | GNUNET_free (searchString); | 1086 | GNUNET_free (searchString); |
1088 | *emsg = GNUNET_strdup (_("No keywords specified!\n")); | 1087 | *emsg = GNUNET_strdup (_ ("No keywords specified!\n")); |
1089 | return NULL; | 1088 | return NULL; |
1090 | } | 1089 | } |
1091 | if (saw_quote != 0) | 1090 | if (saw_quote != 0) |
1092 | { | 1091 | { |
1093 | GNUNET_free (searchString); | 1092 | GNUNET_free (searchString); |
1094 | *emsg = GNUNET_strdup (_("Number of double-quotes not balanced!\n")); | 1093 | *emsg = GNUNET_strdup (_ ("Number of double-quotes not balanced!\n")); |
1095 | return NULL; | 1094 | return NULL; |
1096 | } | 1095 | } |
1097 | keywordarr = GNUNET_new_array (num_Words, | 1096 | keywordarr = GNUNET_new_array (num_Words, char *); |
1098 | char *); | ||
1099 | num_Words = 0; | 1097 | num_Words = 0; |
1100 | inWord = 0; | 1098 | inWord = 0; |
1101 | pos = searchString; | 1099 | pos = searchString; |
@@ -1117,8 +1115,7 @@ GNUNET_FS_uri_ksk_create (const char *keywords, | |||
1117 | pos++; | 1115 | pos++; |
1118 | } | 1116 | } |
1119 | uri = | 1117 | uri = |
1120 | GNUNET_FS_uri_ksk_create_from_args (num_Words, | 1118 | GNUNET_FS_uri_ksk_create_from_args (num_Words, (const char **) keywordarr); |
1121 | (const char **) keywordarr); | ||
1122 | GNUNET_free (keywordarr); | 1119 | GNUNET_free (keywordarr); |
1123 | GNUNET_free (searchString); | 1120 | GNUNET_free (searchString); |
1124 | return uri; | 1121 | return uri; |
@@ -1143,8 +1140,7 @@ GNUNET_FS_uri_ksk_create (const char *keywords, | |||
1143 | * if keywords is not legal (i.e. empty). | 1140 | * if keywords is not legal (i.e. empty). |
1144 | */ | 1141 | */ |
1145 | struct GNUNET_FS_Uri * | 1142 | struct GNUNET_FS_Uri * |
1146 | GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, | 1143 | GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv) |
1147 | const char **argv) | ||
1148 | { | 1144 | { |
1149 | unsigned int i; | 1145 | unsigned int i; |
1150 | struct GNUNET_FS_Uri *uri; | 1146 | struct GNUNET_FS_Uri *uri; |
@@ -1160,16 +1156,16 @@ GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, | |||
1160 | * handle accordingly */ | 1156 | * handle accordingly */ |
1161 | emsg = NULL; | 1157 | emsg = NULL; |
1162 | if ((argc == 1) && (strlen (argv[0]) > strlen (GNUNET_FS_URI_PREFIX)) && | 1158 | if ((argc == 1) && (strlen (argv[0]) > strlen (GNUNET_FS_URI_PREFIX)) && |
1163 | (0 == | 1159 | (0 == strncmp (argv[0], |
1164 | strncmp (argv[0], GNUNET_FS_URI_PREFIX, strlen (GNUNET_FS_URI_PREFIX))) | 1160 | GNUNET_FS_URI_PREFIX, |
1165 | && (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg)))) | 1161 | strlen (GNUNET_FS_URI_PREFIX))) && |
1162 | (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg)))) | ||
1166 | return uri; | 1163 | return uri; |
1167 | GNUNET_free_non_null (emsg); | 1164 | GNUNET_free_non_null (emsg); |
1168 | uri = GNUNET_new (struct GNUNET_FS_Uri); | 1165 | uri = GNUNET_new (struct GNUNET_FS_Uri); |
1169 | uri->type = GNUNET_FS_URI_KSK; | 1166 | uri->type = GNUNET_FS_URI_KSK; |
1170 | uri->data.ksk.keywordCount = argc; | 1167 | uri->data.ksk.keywordCount = argc; |
1171 | uri->data.ksk.keywords = GNUNET_new_array (argc, | 1168 | uri->data.ksk.keywords = GNUNET_new_array (argc, char *); |
1172 | char *); | ||
1173 | for (i = 0; i < argc; i++) | 1169 | for (i = 0; i < argc; i++) |
1174 | { | 1170 | { |
1175 | keyword = argv[i]; | 1171 | keyword = argv[i]; |
@@ -1220,9 +1216,9 @@ GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, | |||
1220 | return GNUNET_YES; | 1216 | return GNUNET_YES; |
1221 | return GNUNET_NO; | 1217 | return GNUNET_NO; |
1222 | case GNUNET_FS_URI_SKS: | 1218 | case GNUNET_FS_URI_SKS: |
1223 | if ((0 == | 1219 | if ((0 == memcmp (&u1->data.sks.ns, |
1224 | memcmp (&u1->data.sks.ns, &u2->data.sks.ns, | 1220 | &u2->data.sks.ns, |
1225 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) && | 1221 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) && |
1226 | (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier))) | 1222 | (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier))) |
1227 | 1223 | ||
1228 | return GNUNET_YES; | 1224 | return GNUNET_YES; |
@@ -1246,12 +1242,12 @@ GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, | |||
1246 | } | 1242 | } |
1247 | return GNUNET_YES; | 1243 | return GNUNET_YES; |
1248 | case GNUNET_FS_URI_LOC: | 1244 | case GNUNET_FS_URI_LOC: |
1249 | if (memcmp | 1245 | if (memcmp (&u1->data.loc, |
1250 | (&u1->data.loc, &u2->data.loc, | 1246 | &u2->data.loc, |
1251 | sizeof (struct FileIdentifier) + | 1247 | sizeof (struct FileIdentifier) + |
1252 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) + | 1248 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) + |
1253 | sizeof (struct GNUNET_TIME_Absolute) + sizeof (unsigned short) + | 1249 | sizeof (struct GNUNET_TIME_Absolute) + |
1254 | sizeof (unsigned short)) != 0) | 1250 | sizeof (unsigned short) + sizeof (unsigned short)) != 0) |
1255 | return GNUNET_NO; | 1251 | return GNUNET_NO; |
1256 | return GNUNET_YES; | 1252 | return GNUNET_YES; |
1257 | default: | 1253 | default: |
@@ -1285,7 +1281,7 @@ int | |||
1285 | GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, | 1281 | GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, |
1286 | struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym) | 1282 | struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym) |
1287 | { | 1283 | { |
1288 | if (!GNUNET_FS_uri_test_sks (uri)) | 1284 | if (! GNUNET_FS_uri_test_sks (uri)) |
1289 | { | 1285 | { |
1290 | GNUNET_break (0); | 1286 | GNUNET_break (0); |
1291 | return GNUNET_SYSERR; | 1287 | return GNUNET_SYSERR; |
@@ -1304,7 +1300,7 @@ GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, | |||
1304 | char * | 1300 | char * |
1305 | GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri) | 1301 | GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri) |
1306 | { | 1302 | { |
1307 | if (!GNUNET_FS_uri_test_sks (uri)) | 1303 | if (! GNUNET_FS_uri_test_sks (uri)) |
1308 | { | 1304 | { |
1309 | GNUNET_break (0); | 1305 | GNUNET_break (0); |
1310 | return NULL; | 1306 | return NULL; |
@@ -1327,7 +1323,7 @@ GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri) | |||
1327 | 1323 | ||
1328 | if (uri->type == GNUNET_FS_URI_KSK) | 1324 | if (uri->type == GNUNET_FS_URI_KSK) |
1329 | { | 1325 | { |
1330 | for (i=0;i < uri->data.ksk.keywordCount; i++) | 1326 | for (i = 0; i < uri->data.ksk.keywordCount; i++) |
1331 | GNUNET_assert (uri->data.ksk.keywords[i] != NULL); | 1327 | GNUNET_assert (uri->data.ksk.keywords[i] != NULL); |
1332 | } | 1328 | } |
1333 | #endif | 1329 | #endif |
@@ -1356,7 +1352,7 @@ GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri) | |||
1356 | * @return size of the file as specified in the CHK URI | 1352 | * @return size of the file as specified in the CHK URI |
1357 | */ | 1353 | */ |
1358 | uint64_t | 1354 | uint64_t |
1359 | GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri * uri) | 1355 | GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri) |
1360 | { | 1356 | { |
1361 | switch (uri->type) | 1357 | switch (uri->type) |
1362 | { | 1358 | { |
@@ -1367,7 +1363,7 @@ GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri * uri) | |||
1367 | default: | 1363 | default: |
1368 | GNUNET_assert (0); | 1364 | GNUNET_assert (0); |
1369 | } | 1365 | } |
1370 | return 0; /* unreachable */ | 1366 | return 0; /* unreachable */ |
1371 | } | 1367 | } |
1372 | 1368 | ||
1373 | 1369 | ||
@@ -1394,9 +1390,7 @@ GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri) | |||
1394 | * @param index offset where to add the keyword | 1390 | * @param index offset where to add the keyword |
1395 | */ | 1391 | */ |
1396 | static void | 1392 | static void |
1397 | insert_non_mandatory_keyword (const char *s, | 1393 | insert_non_mandatory_keyword (const char *s, char **array, int index) |
1398 | char **array, | ||
1399 | int index) | ||
1400 | { | 1394 | { |
1401 | char *nkword; | 1395 | char *nkword; |
1402 | 1396 | ||
@@ -1417,9 +1411,7 @@ insert_non_mandatory_keyword (const char *s, | |||
1417 | * @return #GNUNET_YES if the keyword exists, #GNUNET_NO if not | 1411 | * @return #GNUNET_YES if the keyword exists, #GNUNET_NO if not |
1418 | */ | 1412 | */ |
1419 | static int | 1413 | static int |
1420 | find_duplicate (const char *s, | 1414 | find_duplicate (const char *s, const char **array, int array_length) |
1421 | const char **array, | ||
1422 | int array_length) | ||
1423 | { | 1415 | { |
1424 | int j; | 1416 | int j; |
1425 | 1417 | ||
@@ -1455,12 +1447,19 @@ normalize_metadata (enum EXTRACTOR_MetaFormat format, | |||
1455 | } | 1447 | } |
1456 | if (format == EXTRACTOR_METAFORMAT_C_STRING) | 1448 | if (format == EXTRACTOR_METAFORMAT_C_STRING) |
1457 | { | 1449 | { |
1458 | free_str = u8_strconv_from_encoding (data, locale_charset (), iconveh_escape_sequence); | 1450 | free_str = u8_strconv_from_encoding (data, |
1451 | locale_charset (), | ||
1452 | iconveh_escape_sequence); | ||
1459 | if (free_str == NULL) | 1453 | if (free_str == NULL) |
1460 | return NULL; | 1454 | return NULL; |
1461 | } | 1455 | } |
1462 | 1456 | ||
1463 | normalized = u8_tolower (str_to_normalize, strlen ((char *) str_to_normalize), NULL, UNINORM_NFD, NULL, &r_len); | 1457 | normalized = u8_tolower (str_to_normalize, |
1458 | strlen ((char *) str_to_normalize), | ||
1459 | NULL, | ||
1460 | UNINORM_NFD, | ||
1461 | NULL, | ||
1462 | &r_len); | ||
1464 | /* free_str is allocated by libunistring internally, use free() */ | 1463 | /* free_str is allocated by libunistring internally, use free() */ |
1465 | if (free_str != NULL) | 1464 | if (free_str != NULL) |
1466 | free (free_str); | 1465 | free (free_str); |
@@ -1512,9 +1511,7 @@ u8_strcount (const uint8_t *s) | |||
1512 | * were duplicates (when extracting). | 1511 | * were duplicates (when extracting). |
1513 | */ | 1512 | */ |
1514 | static int | 1513 | static int |
1515 | get_keywords_from_parens (const char *s, | 1514 | get_keywords_from_parens (const char *s, char **array, int index) |
1516 | char **array, | ||
1517 | int index) | ||
1518 | { | 1515 | { |
1519 | int count = 0; | 1516 | int count = 0; |
1520 | char *open_paren; | 1517 | char *open_paren; |
@@ -1564,28 +1561,33 @@ get_keywords_from_parens (const char *s, | |||
1564 | { | 1561 | { |
1565 | char *normalized; | 1562 | char *normalized; |
1566 | if (GNUNET_NO == find_duplicate ((const char *) &open_paren[1], | 1563 | if (GNUNET_NO == find_duplicate ((const char *) &open_paren[1], |
1567 | (const char **) array, index + count)) | 1564 | (const char **) array, |
1565 | index + count)) | ||
1568 | { | 1566 | { |
1569 | insert_non_mandatory_keyword ((const char *) &open_paren[1], array, | 1567 | insert_non_mandatory_keyword ((const char *) &open_paren[1], |
1570 | index + count); | 1568 | array, |
1569 | index + count); | ||
1571 | count++; | 1570 | count++; |
1572 | } | 1571 | } |
1573 | normalized = normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, | 1572 | normalized = normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, |
1574 | &open_paren[1], close_paren - &open_paren[1]); | 1573 | &open_paren[1], |
1574 | close_paren - &open_paren[1]); | ||
1575 | if (normalized != NULL) | 1575 | if (normalized != NULL) |
1576 | { | 1576 | { |
1577 | if (GNUNET_NO == find_duplicate ((const char *) normalized, | 1577 | if (GNUNET_NO == find_duplicate ((const char *) normalized, |
1578 | (const char **) array, index + count)) | 1578 | (const char **) array, |
1579 | index + count)) | ||
1579 | { | 1580 | { |
1580 | insert_non_mandatory_keyword ((const char *) normalized, array, | 1581 | insert_non_mandatory_keyword ((const char *) normalized, |
1581 | index + count); | 1582 | array, |
1583 | index + count); | ||
1582 | count++; | 1584 | count++; |
1583 | } | 1585 | } |
1584 | GNUNET_free (normalized); | 1586 | GNUNET_free (normalized); |
1585 | } | 1587 | } |
1586 | } | 1588 | } |
1587 | else | 1589 | else |
1588 | count++; | 1590 | count++; |
1589 | close_paren[0] = tmp; | 1591 | close_paren[0] = tmp; |
1590 | } | 1592 | } |
1591 | } | 1593 | } |
@@ -1614,9 +1616,7 @@ get_keywords_from_parens (const char *s, | |||
1614 | * duplicates (when extracting). | 1616 | * duplicates (when extracting). |
1615 | */ | 1617 | */ |
1616 | static int | 1618 | static int |
1617 | get_keywords_from_tokens (const char *s, | 1619 | get_keywords_from_tokens (const char *s, char **array, int index) |
1618 | char **array, | ||
1619 | int index) | ||
1620 | { | 1620 | { |
1621 | char *p; | 1621 | char *p; |
1622 | char *ss; | 1622 | char *ss; |
@@ -1633,19 +1633,20 @@ get_keywords_from_tokens (const char *s, | |||
1633 | char *normalized; | 1633 | char *normalized; |
1634 | if (GNUNET_NO == find_duplicate (p, (const char **) array, index + seps)) | 1634 | if (GNUNET_NO == find_duplicate (p, (const char **) array, index + seps)) |
1635 | { | 1635 | { |
1636 | insert_non_mandatory_keyword (p, array, | 1636 | insert_non_mandatory_keyword (p, array, index + seps); |
1637 | index + seps); | 1637 | seps++; |
1638 | seps++; | ||
1639 | } | 1638 | } |
1640 | normalized = normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, | 1639 | normalized = |
1641 | p, strlen (p)); | 1640 | normalize_metadata (EXTRACTOR_METAFORMAT_UTF8, p, strlen (p)); |
1642 | if (normalized != NULL) | 1641 | if (normalized != NULL) |
1643 | { | 1642 | { |
1644 | if (GNUNET_NO == find_duplicate ((const char *) normalized, | 1643 | if (GNUNET_NO == find_duplicate ((const char *) normalized, |
1645 | (const char **) array, index + seps)) | 1644 | (const char **) array, |
1645 | index + seps)) | ||
1646 | { | 1646 | { |
1647 | insert_non_mandatory_keyword ((const char *) normalized, array, | 1647 | insert_non_mandatory_keyword ((const char *) normalized, |
1648 | index + seps); | 1648 | array, |
1649 | index + seps); | ||
1649 | seps++; | 1650 | seps++; |
1650 | } | 1651 | } |
1651 | GNUNET_free (normalized); | 1652 | GNUNET_free (normalized); |
@@ -1678,7 +1679,8 @@ get_keywords_from_tokens (const char *s, | |||
1678 | * @return 0 (always) | 1679 | * @return 0 (always) |
1679 | */ | 1680 | */ |
1680 | static int | 1681 | static int |
1681 | gather_uri_data (void *cls, const char *plugin_name, | 1682 | gather_uri_data (void *cls, |
1683 | const char *plugin_name, | ||
1682 | enum EXTRACTOR_MetaType type, | 1684 | enum EXTRACTOR_MetaType type, |
1683 | enum EXTRACTOR_MetaFormat format, | 1685 | enum EXTRACTOR_MetaFormat format, |
1684 | const char *data_mime_type, | 1686 | const char *data_mime_type, |
@@ -1699,16 +1701,12 @@ gather_uri_data (void *cls, const char *plugin_name, | |||
1699 | */ | 1701 | */ |
1700 | if (u8_strcount ((const uint8_t *) data) <= 2) | 1702 | if (u8_strcount ((const uint8_t *) data) <= 2) |
1701 | return 0; | 1703 | return 0; |
1702 | if ( (EXTRACTOR_METATYPE_MIMETYPE == type) && | 1704 | if ((EXTRACTOR_METATYPE_MIMETYPE == type) && |
1703 | (NULL != (sep = memchr (data, '/', data_len))) && | 1705 | (NULL != (sep = memchr (data, '/', data_len))) && (sep != data)) |
1704 | (sep != data) ) | ||
1705 | { | 1706 | { |
1706 | char *xtra; | 1707 | char *xtra; |
1707 | 1708 | ||
1708 | GNUNET_asprintf (&xtra, | 1709 | GNUNET_asprintf (&xtra, "mimetype:%.*s", (int) (sep - data), data); |
1709 | "mimetype:%.*s", | ||
1710 | (int) (sep - data), | ||
1711 | data); | ||
1712 | if (! find_duplicate (xtra, | 1710 | if (! find_duplicate (xtra, |
1713 | (const char **) uri->data.ksk.keywords, | 1711 | (const char **) uri->data.ksk.keywords, |
1714 | uri->data.ksk.keywordCount)) | 1712 | uri->data.ksk.keywordCount)) |
@@ -1727,17 +1725,19 @@ gather_uri_data (void *cls, const char *plugin_name, | |||
1727 | uri->data.ksk.keywordCount)) | 1725 | uri->data.ksk.keywordCount)) |
1728 | { | 1726 | { |
1729 | insert_non_mandatory_keyword (data, | 1727 | insert_non_mandatory_keyword (data, |
1730 | uri->data.ksk.keywords, uri->data.ksk.keywordCount); | 1728 | uri->data.ksk.keywords, |
1729 | uri->data.ksk.keywordCount); | ||
1731 | uri->data.ksk.keywordCount++; | 1730 | uri->data.ksk.keywordCount++; |
1732 | } | 1731 | } |
1733 | if (NULL != normalized_data) | 1732 | if (NULL != normalized_data) |
1734 | { | 1733 | { |
1735 | if (! find_duplicate (normalized_data, | 1734 | if (! find_duplicate (normalized_data, |
1736 | (const char **) uri->data.ksk.keywords, | 1735 | (const char **) uri->data.ksk.keywords, |
1737 | uri->data.ksk.keywordCount)) | 1736 | uri->data.ksk.keywordCount)) |
1738 | { | 1737 | { |
1739 | insert_non_mandatory_keyword (normalized_data, | 1738 | insert_non_mandatory_keyword (normalized_data, |
1740 | uri->data.ksk.keywords, uri->data.ksk.keywordCount); | 1739 | uri->data.ksk.keywords, |
1740 | uri->data.ksk.keywordCount); | ||
1741 | uri->data.ksk.keywordCount++; | 1741 | uri->data.ksk.keywordCount++; |
1742 | } | 1742 | } |
1743 | GNUNET_free (normalized_data); | 1743 | GNUNET_free (normalized_data); |
@@ -1755,7 +1755,8 @@ gather_uri_data (void *cls, const char *plugin_name, | |||
1755 | * @return NULL on error, otherwise a KSK URI | 1755 | * @return NULL on error, otherwise a KSK URI |
1756 | */ | 1756 | */ |
1757 | struct GNUNET_FS_Uri * | 1757 | struct GNUNET_FS_Uri * |
1758 | GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md) | 1758 | GNUNET_FS_uri_ksk_create_from_meta_data ( |
1759 | const struct GNUNET_CONTAINER_MetaData *md) | ||
1759 | { | 1760 | { |
1760 | struct GNUNET_FS_Uri *ret; | 1761 | struct GNUNET_FS_Uri *ret; |
1761 | char *filename; | 1762 | char *filename; |
@@ -1772,8 +1773,10 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData | |||
1772 | ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL); | 1773 | ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL); |
1773 | if (ent > 0) | 1774 | if (ent > 0) |
1774 | { | 1775 | { |
1775 | full_name = GNUNET_CONTAINER_meta_data_get_first_by_types (md, | 1776 | full_name = GNUNET_CONTAINER_meta_data_get_first_by_types ( |
1776 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, -1); | 1777 | md, |
1778 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | ||
1779 | -1); | ||
1777 | if (NULL != full_name) | 1780 | if (NULL != full_name) |
1778 | { | 1781 | { |
1779 | filename = full_name; | 1782 | filename = full_name; |
@@ -1784,19 +1787,20 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData | |||
1784 | } | 1787 | } |
1785 | /* x3 because there might be a normalized variant of every keyword, | 1788 | /* x3 because there might be a normalized variant of every keyword, |
1786 | plus theoretically one more for mime... */ | 1789 | plus theoretically one more for mime... */ |
1787 | ret->data.ksk.keywords | 1790 | ret->data.ksk.keywords = |
1788 | = GNUNET_new_array ((ent + tok_keywords + paren_keywords) * 3, | 1791 | GNUNET_new_array ((ent + tok_keywords + paren_keywords) * 3, char *); |
1789 | char *); | ||
1790 | GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret); | 1792 | GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret); |
1791 | } | 1793 | } |
1792 | if (tok_keywords > 0) | 1794 | if (tok_keywords > 0) |
1793 | ret->data.ksk.keywordCount += get_keywords_from_tokens (filename, | 1795 | ret->data.ksk.keywordCount += |
1794 | ret->data.ksk.keywords, | 1796 | get_keywords_from_tokens (filename, |
1795 | ret->data.ksk.keywordCount); | 1797 | ret->data.ksk.keywords, |
1798 | ret->data.ksk.keywordCount); | ||
1796 | if (paren_keywords > 0) | 1799 | if (paren_keywords > 0) |
1797 | ret->data.ksk.keywordCount += get_keywords_from_parens (filename, | 1800 | ret->data.ksk.keywordCount += |
1798 | ret->data.ksk.keywords, | 1801 | get_keywords_from_parens (filename, |
1799 | ret->data.ksk.keywordCount); | 1802 | ret->data.ksk.keywords, |
1803 | ret->data.ksk.keywordCount); | ||
1800 | if (ent > 0) | 1804 | if (ent > 0) |
1801 | GNUNET_free_non_null (full_name); | 1805 | GNUNET_free_non_null (full_name); |
1802 | return ret; | 1806 | return ret; |
@@ -1810,9 +1814,8 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData | |||
1810 | static int | 1814 | static int |
1811 | needs_percent (char c) | 1815 | needs_percent (char c) |
1812 | { | 1816 | { |
1813 | return (! | 1817 | return (! ((isalnum ((unsigned char) c)) || (c == '-') || (c == '_') || |
1814 | ((isalnum ((unsigned char) c)) || (c == '-') || (c == '_') || | 1818 | (c == '.') || (c == '~'))); |
1815 | (c == '.') || (c == '~'))); | ||
1816 | } | 1819 | } |
1817 | 1820 | ||
1818 | 1821 | ||
@@ -1851,10 +1854,10 @@ uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) | |||
1851 | if ((j == 0) && (keyword[j] == ' ')) | 1854 | if ((j == 0) && (keyword[j] == ' ')) |
1852 | { | 1855 | { |
1853 | n--; | 1856 | n--; |
1854 | continue; /* skip leading space */ | 1857 | continue; /* skip leading space */ |
1855 | } | 1858 | } |
1856 | if (needs_percent (keyword[j])) | 1859 | if (needs_percent (keyword[j])) |
1857 | n += 2; /* will use %-encoding */ | 1860 | n += 2; /* will use %-encoding */ |
1858 | } | 1861 | } |
1859 | } | 1862 | } |
1860 | ret = GNUNET_malloc (n); | 1863 | ret = GNUNET_malloc (n); |
@@ -1868,7 +1871,7 @@ uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) | |||
1868 | for (j = 0; j < slen; j++) | 1871 | for (j = 0; j < slen; j++) |
1869 | { | 1872 | { |
1870 | if ((j == 0) && (keyword[j] == ' ')) | 1873 | if ((j == 0) && (keyword[j] == ' ')) |
1871 | continue; /* skip leading space */ | 1874 | continue; /* skip leading space */ |
1872 | if (needs_percent (keyword[j])) | 1875 | if (needs_percent (keyword[j])) |
1873 | { | 1876 | { |
1874 | sprintf (&ret[wpos], "%%%02X", (unsigned char) keyword[j]); | 1877 | sprintf (&ret[wpos], "%%%02X", (unsigned char) keyword[j]); |
@@ -1900,15 +1903,19 @@ uri_sks_to_string (const struct GNUNET_FS_Uri *uri) | |||
1900 | 1903 | ||
1901 | if (GNUNET_FS_URI_SKS != uri->type) | 1904 | if (GNUNET_FS_URI_SKS != uri->type) |
1902 | return NULL; | 1905 | return NULL; |
1903 | ret = GNUNET_STRINGS_data_to_string (&uri->data.sks.ns, | 1906 | ret = |
1904 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), | 1907 | GNUNET_STRINGS_data_to_string (&uri->data.sks.ns, |
1905 | buf, | 1908 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), |
1906 | sizeof (buf)); | 1909 | buf, |
1910 | sizeof (buf)); | ||
1907 | GNUNET_assert (NULL != ret); | 1911 | GNUNET_assert (NULL != ret); |
1908 | ret[0] = '\0'; | 1912 | ret[0] = '\0'; |
1909 | GNUNET_asprintf (&ret, "%s%s%s/%s", GNUNET_FS_URI_PREFIX, | 1913 | GNUNET_asprintf (&ret, |
1910 | GNUNET_FS_URI_SKS_INFIX, buf, | 1914 | "%s%s%s/%s", |
1911 | uri->data.sks.identifier); | 1915 | GNUNET_FS_URI_PREFIX, |
1916 | GNUNET_FS_URI_SKS_INFIX, | ||
1917 | buf, | ||
1918 | uri->data.sks.identifier); | ||
1912 | return ret; | 1919 | return ret; |
1913 | } | 1920 | } |
1914 | 1921 | ||
@@ -1933,9 +1940,13 @@ uri_chk_to_string (const struct GNUNET_FS_Uri *uri) | |||
1933 | GNUNET_CRYPTO_hash_to_enc (&fi->chk.key, &keyhash); | 1940 | GNUNET_CRYPTO_hash_to_enc (&fi->chk.key, &keyhash); |
1934 | GNUNET_CRYPTO_hash_to_enc (&fi->chk.query, &queryhash); | 1941 | GNUNET_CRYPTO_hash_to_enc (&fi->chk.query, &queryhash); |
1935 | 1942 | ||
1936 | GNUNET_asprintf (&ret, "%s%s%s.%s.%llu", GNUNET_FS_URI_PREFIX, | 1943 | GNUNET_asprintf (&ret, |
1937 | GNUNET_FS_URI_CHK_INFIX, (const char *) &keyhash, | 1944 | "%s%s%s.%s.%llu", |
1938 | (const char *) &queryhash, GNUNET_ntohll (fi->file_length)); | 1945 | GNUNET_FS_URI_PREFIX, |
1946 | GNUNET_FS_URI_CHK_INFIX, | ||
1947 | (const char *) &keyhash, | ||
1948 | (const char *) &queryhash, | ||
1949 | GNUNET_ntohll (fi->file_length)); | ||
1939 | return ret; | 1950 | return ret; |
1940 | } | 1951 | } |
1941 | 1952 | ||
@@ -1959,20 +1970,25 @@ uri_loc_to_string (const struct GNUNET_FS_Uri *uri) | |||
1959 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash); | 1970 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash); |
1960 | peer_id = | 1971 | peer_id = |
1961 | GNUNET_CRYPTO_eddsa_public_key_to_string (&uri->data.loc.peer.public_key); | 1972 | GNUNET_CRYPTO_eddsa_public_key_to_string (&uri->data.loc.peer.public_key); |
1962 | GNUNET_assert (NULL != | 1973 | GNUNET_assert ( |
1963 | GNUNET_STRINGS_data_to_string (&uri->data.loc.contentSignature, | 1974 | NULL != |
1964 | sizeof (struct GNUNET_CRYPTO_EddsaSignature), | 1975 | GNUNET_STRINGS_data_to_string (&uri->data.loc.contentSignature, |
1965 | peer_sig, | 1976 | sizeof (struct GNUNET_CRYPTO_EddsaSignature), |
1966 | sizeof (peer_sig))); | 1977 | peer_sig, |
1978 | sizeof (peer_sig))); | ||
1967 | GNUNET_asprintf (&ret, | 1979 | GNUNET_asprintf (&ret, |
1968 | "%s%s%s.%s.%llu.%s.%s.%llu", GNUNET_FS_URI_PREFIX, | 1980 | "%s%s%s.%s.%llu.%s.%s.%llu", |
1969 | GNUNET_FS_URI_LOC_INFIX, (const char *) &keyhash, | 1981 | GNUNET_FS_URI_PREFIX, |
1982 | GNUNET_FS_URI_LOC_INFIX, | ||
1983 | (const char *) &keyhash, | ||
1970 | (const char *) &queryhash, | 1984 | (const char *) &queryhash, |
1971 | (unsigned long long) GNUNET_ntohll (uri->data.loc. | 1985 | (unsigned long long) GNUNET_ntohll ( |
1972 | fi.file_length), | 1986 | uri->data.loc.fi.file_length), |
1973 | peer_id, | 1987 | peer_id, |
1974 | peer_sig, | 1988 | peer_sig, |
1975 | (unsigned long long) uri->data.loc.expirationTime.abs_value_us / 1000000LL); | 1989 | (unsigned long long) |
1990 | uri->data.loc.expirationTime.abs_value_us / | ||
1991 | 1000000LL); | ||
1976 | GNUNET_free (peer_id); | 1992 | GNUNET_free (peer_id); |
1977 | return ret; | 1993 | return ret; |
1978 | } | 1994 | } |
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) | |||
512 | struct GNUNET_HashCode fx[2]; | 512 | struct GNUNET_HashCode fx[2]; |
513 | struct GNUNET_HashCode ft; | 513 | struct GNUNET_HashCode ft; |
514 | 514 | ||
515 | if (0 != STAT (filename, &sbuf)) | 515 | if (0 != stat (filename, &sbuf)) |
516 | { | 516 | { |
517 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); | 517 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); |
518 | return GNUNET_OK; | 518 | 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, | |||
50 | { | 50 | { |
51 | if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA) | 51 | if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA) |
52 | { | 52 | { |
53 | printf (_("\t<original file embedded in %u bytes of meta data>\n"), | 53 | printf (_ ("\t<original file embedded in %u bytes of meta data>\n"), |
54 | (unsigned int) data_size); | 54 | (unsigned int) data_size); |
55 | return 0; | 55 | return 0; |
56 | } | 56 | } |
@@ -63,17 +63,14 @@ item_printer (void *cls, | |||
63 | printf ("\t%20s: %s\n", | 63 | printf ("\t%20s: %s\n", |
64 | dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, | 64 | dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, |
65 | EXTRACTOR_metatype_to_string (type)), | 65 | EXTRACTOR_metatype_to_string (type)), |
66 | data); | ||
67 | #else | ||
68 | printf ("\t%20d: %s\n", | ||
69 | type, | ||
70 | data); | 66 | data); |
67 | #else | ||
68 | printf ("\t%20d: %s\n", type, data); | ||
71 | #endif | 69 | #endif |
72 | return 0; | 70 | return 0; |
73 | } | 71 | } |
74 | 72 | ||
75 | 73 | ||
76 | |||
77 | /** | 74 | /** |
78 | * Print an entry in a directory. | 75 | * Print an entry in a directory. |
79 | * | 76 | * |
@@ -90,22 +87,25 @@ item_printer (void *cls, | |||
90 | * @param data data available for the file (length bytes) | 87 | * @param data data available for the file (length bytes) |
91 | */ | 88 | */ |
92 | static void | 89 | static void |
93 | print_entry (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, | 90 | print_entry (void *cls, |
94 | const struct GNUNET_CONTAINER_MetaData *meta, size_t length, | 91 | const char *filename, |
92 | const struct GNUNET_FS_Uri *uri, | ||
93 | const struct GNUNET_CONTAINER_MetaData *meta, | ||
94 | size_t length, | ||
95 | const void *data) | 95 | const void *data) |
96 | { | 96 | { |
97 | char *string; | 97 | char *string; |
98 | char *name; | 98 | char *name; |
99 | 99 | ||
100 | name = | 100 | name = GNUNET_CONTAINER_meta_data_get_by_type ( |
101 | GNUNET_CONTAINER_meta_data_get_by_type (meta, | 101 | meta, |
102 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); | 102 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); |
103 | if (uri == NULL) | 103 | if (uri == NULL) |
104 | { | 104 | { |
105 | printf (_("Directory `%s' meta data:\n"), name ? name : ""); | 105 | printf (_ ("Directory `%s' meta data:\n"), name ? name : ""); |
106 | GNUNET_CONTAINER_meta_data_iterate (meta, &item_printer, NULL); | 106 | GNUNET_CONTAINER_meta_data_iterate (meta, &item_printer, NULL); |
107 | printf ("\n"); | 107 | printf ("\n"); |
108 | printf (_("Directory `%s' contents:\n"), name ? name : ""); | 108 | printf (_ ("Directory `%s' contents:\n"), name ? name : ""); |
109 | GNUNET_free_non_null (name); | 109 | GNUNET_free_non_null (name); |
110 | return; | 110 | return; |
111 | } | 111 | } |
@@ -127,7 +127,9 @@ print_entry (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, | |||
127 | * @param cfg configuration | 127 | * @param cfg configuration |
128 | */ | 128 | */ |
129 | static void | 129 | static void |
130 | run (void *cls, char *const *args, const char *cfgfile, | 130 | run (void *cls, |
131 | char *const *args, | ||
132 | const char *cfgfile, | ||
131 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 133 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
132 | { | 134 | { |
133 | struct GNUNET_DISK_MapHandle *map; | 135 | struct GNUNET_DISK_MapHandle *map; |
@@ -140,20 +142,21 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
140 | 142 | ||
141 | if (NULL == args[0]) | 143 | if (NULL == args[0]) |
142 | { | 144 | { |
143 | FPRINTF (stderr, "%s", _("You must specify a filename to inspect.\n")); | 145 | fprintf (stderr, "%s", _ ("You must specify a filename to inspect.\n")); |
144 | ret = 1; | 146 | ret = 1; |
145 | return; | 147 | return; |
146 | } | 148 | } |
147 | i = 0; | 149 | i = 0; |
148 | while (NULL != (filename = args[i++])) | 150 | while (NULL != (filename = args[i++])) |
149 | { | 151 | { |
150 | if ((GNUNET_OK != GNUNET_DISK_file_size (filename, &size, GNUNET_YES, GNUNET_YES)) || | 152 | if ((GNUNET_OK != |
151 | (NULL == | 153 | GNUNET_DISK_file_size (filename, &size, GNUNET_YES, GNUNET_YES)) || |
152 | (h = | 154 | (NULL == (h = GNUNET_DISK_file_open (filename, |
153 | GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, | 155 | GNUNET_DISK_OPEN_READ, |
154 | GNUNET_DISK_PERM_NONE)))) | 156 | GNUNET_DISK_PERM_NONE)))) |
155 | { | 157 | { |
156 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to read directory `%s'\n"), | 158 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
159 | _ ("Failed to read directory `%s'\n"), | ||
157 | filename); | 160 | filename); |
158 | ret = 1; | 161 | ret = 1; |
159 | continue; | 162 | continue; |
@@ -161,9 +164,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
161 | len = (size_t) size; | 164 | len = (size_t) size; |
162 | data = GNUNET_DISK_file_map (h, &map, GNUNET_DISK_MAP_TYPE_READ, len); | 165 | data = GNUNET_DISK_file_map (h, &map, GNUNET_DISK_MAP_TYPE_READ, len); |
163 | GNUNET_assert (NULL != data); | 166 | GNUNET_assert (NULL != data); |
164 | if (GNUNET_OK != GNUNET_FS_directory_list_contents (len, data, 0, &print_entry, NULL)) | 167 | if (GNUNET_OK != |
165 | fprintf (stdout, _("`%s' is not a GNUnet directory\n"), | 168 | GNUNET_FS_directory_list_contents (len, data, 0, &print_entry, NULL)) |
166 | filename); | 169 | fprintf (stdout, _ ("`%s' is not a GNUnet directory\n"), filename); |
167 | else | 170 | else |
168 | printf ("\n"); | 171 | printf ("\n"); |
169 | GNUNET_DISK_file_unmap (map); | 172 | GNUNET_DISK_file_unmap (map); |
@@ -182,18 +185,23 @@ int | |||
182 | main (int argc, char *const *argv) | 185 | main (int argc, char *const *argv) |
183 | { | 186 | { |
184 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 187 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
185 | GNUNET_GETOPT_OPTION_END | 188 | GNUNET_GETOPT_OPTION_END}; |
186 | }; | ||
187 | 189 | ||
188 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 190 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
189 | return 2; | 191 | return 2; |
190 | 192 | ||
191 | ret = (GNUNET_OK == | 193 | ret = (GNUNET_OK == |
192 | GNUNET_PROGRAM_run (argc, argv, "gnunet-directory [OPTIONS] FILENAME", | 194 | GNUNET_PROGRAM_run (argc, |
193 | gettext_noop | 195 | argv, |
194 | ("Display contents of a GNUnet directory"), | 196 | "gnunet-directory [OPTIONS] FILENAME", |
195 | options, &run, NULL)) ? ret : 1; | 197 | gettext_noop ( |
196 | GNUNET_free ((void*) argv); | 198 | "Display contents of a GNUnet directory"), |
199 | options, | ||
200 | &run, | ||
201 | NULL)) | ||
202 | ? ret | ||
203 | : 1; | ||
204 | GNUNET_free ((void *) argv); | ||
197 | return ret; | 205 | return ret; |
198 | } | 206 | } |
199 | 207 | ||
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) | |||
80 | * @param w desired number of steps in the progress bar | 80 | * @param w desired number of steps in the progress bar |
81 | */ | 81 | */ |
82 | static void | 82 | static void |
83 | display_bar (unsigned long long x, | 83 | display_bar (unsigned long long x, unsigned long long n, unsigned int w) |
84 | unsigned long long n, | ||
85 | unsigned int w) | ||
86 | { | 84 | { |
87 | char buf[w + 20]; | 85 | char buf[w + 20]; |
88 | unsigned int p; | 86 | unsigned int p; |
89 | unsigned int endeq; | 87 | unsigned int endeq; |
90 | float ratio_complete; | 88 | float ratio_complete; |
91 | 89 | ||
92 | #if !WINDOWS | 90 | #if ! WINDOWS |
93 | if (0 == isatty (1)) | 91 | if (0 == isatty (1)) |
94 | return; | 92 | return; |
95 | #else | 93 | #else |
96 | if (FILE_TYPE_CHAR != GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) | 94 | if (FILE_TYPE_CHAR != GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) |
97 | return; | 95 | return; |
98 | #endif | 96 | #endif |
99 | ratio_complete = x/(float)n; | 97 | ratio_complete = x / (float) n; |
100 | endeq = ratio_complete * w; | 98 | endeq = ratio_complete * w; |
101 | GNUNET_snprintf (buf, sizeof (buf), | 99 | GNUNET_snprintf (buf, sizeof (buf), "%3d%% [", (int) (ratio_complete * 100)); |
102 | "%3d%% [", (int)(ratio_complete*100) ); | 100 | for (p = 0; p < endeq; p++) |
103 | for (p=0; p<endeq; p++) | ||
104 | strcat (buf, "="); | 101 | strcat (buf, "="); |
105 | for (p=endeq; p<w; p++) | 102 | for (p = endeq; p < w; p++) |
106 | strcat (buf, " "); | 103 | strcat (buf, " "); |
107 | strcat (buf, "]\r"); | 104 | strcat (buf, "]\r"); |
108 | printf ("%s", buf); | 105 | printf ("%s", buf); |
109 | fflush(stdout); | 106 | fflush (stdout); |
110 | } | 107 | } |
111 | 108 | ||
112 | 109 | ||
@@ -124,8 +121,7 @@ display_bar (unsigned long long x, | |||
124 | * field in the `struct GNUNET_FS_ProgressInfo` | 121 | * field in the `struct GNUNET_FS_ProgressInfo` |
125 | */ | 122 | */ |
126 | static void * | 123 | static void * |
127 | progress_cb (void *cls, | 124 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) |
128 | const struct GNUNET_FS_ProgressInfo *info) | ||
129 | { | 125 | { |
130 | char *s; | 126 | char *s; |
131 | const char *s2; | 127 | const char *s2; |
@@ -135,71 +131,75 @@ progress_cb (void *cls, | |||
135 | { | 131 | { |
136 | case GNUNET_FS_STATUS_DOWNLOAD_START: | 132 | case GNUNET_FS_STATUS_DOWNLOAD_START: |
137 | if (verbose > 1) | 133 | if (verbose > 1) |
138 | FPRINTF (stderr, | 134 | fprintf (stderr, |
139 | _("Starting download `%s'.\n"), | 135 | _ ("Starting download `%s'.\n"), |
140 | info->value.download.filename); | 136 | info->value.download.filename); |
141 | break; | 137 | break; |
142 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | 138 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: |
143 | if (verbose) | 139 | if (verbose) |
144 | { | 140 | { |
145 | s = GNUNET_strdup (GNUNET_STRINGS_relative_time_to_string (info->value.download.eta, | 141 | s = GNUNET_strdup ( |
146 | GNUNET_YES)); | 142 | GNUNET_STRINGS_relative_time_to_string (info->value.download.eta, |
147 | if (info->value.download.specifics.progress.block_download_duration.rel_value_us | 143 | GNUNET_YES)); |
148 | == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) | 144 | if (info->value.download.specifics.progress.block_download_duration |
149 | s2 = _("<unknown time>"); | 145 | .rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) |
146 | s2 = _ ("<unknown time>"); | ||
150 | else | 147 | else |
151 | s2 = GNUNET_STRINGS_relative_time_to_string (info->value.download.specifics.progress.block_download_duration, | 148 | s2 = GNUNET_STRINGS_relative_time_to_string (info->value.download |
152 | GNUNET_YES); | 149 | .specifics.progress |
153 | t = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed * | 150 | .block_download_duration, |
154 | 1000LL / | 151 | GNUNET_YES); |
155 | (info->value.download. | 152 | t = GNUNET_STRINGS_byte_size_fancy ( |
156 | duration.rel_value_us + 1)); | 153 | info->value.download.completed * 1000LL / |
157 | FPRINTF (stdout, | 154 | (info->value.download.duration.rel_value_us + 1)); |
158 | _("Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"), | 155 | fprintf ( |
159 | info->value.download.filename, | 156 | stdout, |
160 | (unsigned long long) info->value.download.completed, | 157 | _ ( |
161 | (unsigned long long) info->value.download.size, | 158 | "Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"), |
162 | s, | 159 | info->value.download.filename, |
163 | t, | 160 | (unsigned long long) info->value.download.completed, |
164 | s2); | 161 | (unsigned long long) info->value.download.size, |
162 | s, | ||
163 | t, | ||
164 | s2); | ||
165 | GNUNET_free (s); | 165 | GNUNET_free (s); |
166 | GNUNET_free (t); | 166 | GNUNET_free (t); |
167 | } | 167 | } |
168 | else | 168 | else |
169 | { | 169 | { |
170 | display_bar (info->value.download.completed, | 170 | display_bar (info->value.download.completed, |
171 | info->value.download.size, | 171 | info->value.download.size, |
172 | 60); | 172 | 60); |
173 | } | 173 | } |
174 | break; | 174 | break; |
175 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | 175 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: |
176 | #if !WINDOWS | 176 | #if ! WINDOWS |
177 | if (0 != isatty (1)) | 177 | if (0 != isatty (1)) |
178 | fprintf (stdout, "\n"); | 178 | fprintf (stdout, "\n"); |
179 | #else | 179 | #else |
180 | if (FILE_TYPE_CHAR == | 180 | if (FILE_TYPE_CHAR == GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) |
181 | GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) | ||
182 | fprintf (stdout, "\n"); | 181 | fprintf (stdout, "\n"); |
183 | #endif | 182 | #endif |
184 | FPRINTF (stderr, _("Error downloading: %s.\n"), | 183 | fprintf (stderr, |
184 | _ ("Error downloading: %s.\n"), | ||
185 | info->value.download.specifics.error.message); | 185 | info->value.download.specifics.error.message); |
186 | GNUNET_SCHEDULER_shutdown (); | 186 | GNUNET_SCHEDULER_shutdown (); |
187 | break; | 187 | break; |
188 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | 188 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: |
189 | s = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed * 1000 / | 189 | s = GNUNET_STRINGS_byte_size_fancy ( |
190 | (info->value.download. | 190 | info->value.download.completed * 1000 / |
191 | duration.rel_value_us + 1)); | 191 | (info->value.download.duration.rel_value_us + 1)); |
192 | #if !WINDOWS | 192 | #if ! WINDOWS |
193 | if (0 != isatty (1)) | 193 | if (0 != isatty (1)) |
194 | fprintf (stdout, "\n"); | 194 | fprintf (stdout, "\n"); |
195 | #else | 195 | #else |
196 | if (FILE_TYPE_CHAR == | 196 | if (FILE_TYPE_CHAR == GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) |
197 | GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) | ||
198 | fprintf (stdout, "\n"); | 197 | fprintf (stdout, "\n"); |
199 | #endif | 198 | #endif |
200 | FPRINTF (stdout, | 199 | fprintf (stdout, |
201 | _("Downloading `%s' done (%s/s).\n"), | 200 | _ ("Downloading `%s' done (%s/s).\n"), |
202 | info->value.download.filename, s); | 201 | info->value.download.filename, |
202 | s); | ||
203 | GNUNET_free (s); | 203 | GNUNET_free (s); |
204 | if (info->value.download.dc == dc) | 204 | if (info->value.download.dc == dc) |
205 | GNUNET_SCHEDULER_shutdown (); | 205 | GNUNET_SCHEDULER_shutdown (); |
@@ -212,9 +212,7 @@ progress_cb (void *cls, | |||
212 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: | 212 | case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: |
213 | break; | 213 | break; |
214 | default: | 214 | default: |
215 | FPRINTF (stderr, | 215 | fprintf (stderr, _ ("Unexpected status: %d\n"), info->status); |
216 | _("Unexpected status: %d\n"), | ||
217 | info->status); | ||
218 | break; | 216 | break; |
219 | } | 217 | } |
220 | return NULL; | 218 | return NULL; |
@@ -241,55 +239,45 @@ run (void *cls, | |||
241 | 239 | ||
242 | if (NULL == args[0]) | 240 | if (NULL == args[0]) |
243 | { | 241 | { |
244 | FPRINTF (stderr, | 242 | fprintf (stderr, "%s", _ ("You need to specify a URI argument.\n")); |
245 | "%s", | ||
246 | _("You need to specify a URI argument.\n")); | ||
247 | return; | 243 | return; |
248 | } | 244 | } |
249 | uri = GNUNET_FS_uri_parse (args[0], &emsg); | 245 | uri = GNUNET_FS_uri_parse (args[0], &emsg); |
250 | if (NULL == uri) | 246 | if (NULL == uri) |
251 | { | 247 | { |
252 | FPRINTF (stderr, | 248 | fprintf (stderr, _ ("Failed to parse URI: %s\n"), emsg); |
253 | _("Failed to parse URI: %s\n"), | ||
254 | emsg); | ||
255 | GNUNET_free (emsg); | 249 | GNUNET_free (emsg); |
256 | ret = 1; | 250 | ret = 1; |
257 | return; | 251 | return; |
258 | } | 252 | } |
259 | if ( (! GNUNET_FS_uri_test_chk (uri)) && | 253 | if ((! GNUNET_FS_uri_test_chk (uri)) && (! GNUNET_FS_uri_test_loc (uri))) |
260 | (! GNUNET_FS_uri_test_loc (uri))) | ||
261 | { | 254 | { |
262 | FPRINTF (stderr, | 255 | fprintf (stderr, "%s", _ ("Only CHK or LOC URIs supported.\n")); |
263 | "%s", | ||
264 | _("Only CHK or LOC URIs supported.\n")); | ||
265 | ret = 1; | 256 | ret = 1; |
266 | GNUNET_FS_uri_destroy (uri); | 257 | GNUNET_FS_uri_destroy (uri); |
267 | return; | 258 | return; |
268 | } | 259 | } |
269 | if (NULL == filename) | 260 | if (NULL == filename) |
270 | { | 261 | { |
271 | FPRINTF (stderr, | 262 | fprintf (stderr, "%s", _ ("Target filename must be specified.\n")); |
272 | "%s", | ||
273 | _("Target filename must be specified.\n")); | ||
274 | ret = 1; | 263 | ret = 1; |
275 | GNUNET_FS_uri_destroy (uri); | 264 | GNUNET_FS_uri_destroy (uri); |
276 | return; | 265 | return; |
277 | } | 266 | } |
278 | cfg = c; | 267 | cfg = c; |
279 | ctx = GNUNET_FS_start (cfg, | 268 | ctx = GNUNET_FS_start (cfg, |
280 | "gnunet-download", | 269 | "gnunet-download", |
281 | &progress_cb, NULL, | 270 | &progress_cb, |
282 | GNUNET_FS_FLAGS_NONE, | 271 | NULL, |
283 | GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, | 272 | GNUNET_FS_FLAGS_NONE, |
284 | parallelism, | 273 | GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, |
285 | GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, | 274 | parallelism, |
286 | request_parallelism, | 275 | GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, |
287 | GNUNET_FS_OPTIONS_END); | 276 | request_parallelism, |
277 | GNUNET_FS_OPTIONS_END); | ||
288 | if (NULL == ctx) | 278 | if (NULL == ctx) |
289 | { | 279 | { |
290 | FPRINTF (stderr, | 280 | fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS"); |
291 | _("Could not initialize `%s' subsystem.\n"), | ||
292 | "FS"); | ||
293 | GNUNET_FS_uri_destroy (uri); | 281 | GNUNET_FS_uri_destroy (uri); |
294 | ret = 1; | 282 | ret = 1; |
295 | return; | 283 | return; |
@@ -300,16 +288,16 @@ run (void *cls, | |||
300 | if (local_only) | 288 | if (local_only) |
301 | options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY; | 289 | options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY; |
302 | dc = GNUNET_FS_download_start (ctx, | 290 | dc = GNUNET_FS_download_start (ctx, |
303 | uri, | 291 | uri, |
304 | NULL, | 292 | NULL, |
305 | filename, | 293 | filename, |
306 | NULL, | 294 | NULL, |
307 | 0, | 295 | 0, |
308 | GNUNET_FS_uri_chk_get_file_size (uri), | 296 | GNUNET_FS_uri_chk_get_file_size (uri), |
309 | anonymity, | 297 | anonymity, |
310 | options, | 298 | options, |
311 | NULL, | 299 | NULL, |
312 | NULL); | 300 | NULL); |
313 | GNUNET_FS_uri_destroy (uri); | 301 | GNUNET_FS_uri_destroy (uri); |
314 | if (dc == NULL) | 302 | if (dc == NULL) |
315 | { | 303 | { |
@@ -317,8 +305,7 @@ run (void *cls, | |||
317 | ctx = NULL; | 305 | ctx = NULL; |
318 | return; | 306 | return; |
319 | } | 307 | } |
320 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 308 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
321 | NULL); | ||
322 | } | 309 | } |
323 | 310 | ||
324 | 311 | ||
@@ -332,61 +319,73 @@ run (void *cls, | |||
332 | int | 319 | int |
333 | main (int argc, char *const *argv) | 320 | main (int argc, char *const *argv) |
334 | { | 321 | { |
335 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 322 | struct GNUNET_GETOPT_CommandLineOption options[] = |
336 | GNUNET_GETOPT_option_uint ('a', | 323 | {GNUNET_GETOPT_option_uint ('a', |
337 | "anonymity", | 324 | "anonymity", |
338 | "LEVEL", | 325 | "LEVEL", |
339 | gettext_noop ("set the desired LEVEL of receiver-anonymity"), | 326 | gettext_noop ( |
340 | &anonymity), | 327 | "set the desired LEVEL of receiver-anonymity"), |
341 | 328 | &anonymity), | |
342 | GNUNET_GETOPT_option_flag ('D', | 329 | |
343 | "delete-incomplete", | 330 | GNUNET_GETOPT_option_flag ( |
344 | gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"), | 331 | 'D', |
345 | &delete_incomplete), | 332 | "delete-incomplete", |
346 | 333 | gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"), | |
347 | GNUNET_GETOPT_option_flag ('n', | 334 | &delete_incomplete), |
348 | "no-network", | 335 | |
349 | gettext_noop ("only search the local peer (no P2P network search)"), | 336 | GNUNET_GETOPT_option_flag ( |
350 | &local_only), | 337 | 'n', |
351 | GNUNET_GETOPT_option_string ('o', | 338 | "no-network", |
352 | "output", | 339 | gettext_noop ("only search the local peer (no P2P network search)"), |
353 | "FILENAME", | 340 | &local_only), |
354 | gettext_noop ("write the file to FILENAME"), | 341 | GNUNET_GETOPT_option_string ('o', |
355 | &filename), | 342 | "output", |
356 | GNUNET_GETOPT_option_uint ('p', | 343 | "FILENAME", |
357 | "parallelism", | 344 | gettext_noop ("write the file to FILENAME"), |
358 | "DOWNLOADS", | 345 | &filename), |
359 | gettext_noop ("set the maximum number of parallel downloads that is allowed"), | 346 | GNUNET_GETOPT_option_uint ( |
360 | ¶llelism), | 347 | 'p', |
361 | GNUNET_GETOPT_option_uint ('r', | 348 | "parallelism", |
362 | "request-parallelism", | 349 | "DOWNLOADS", |
363 | "REQUESTS", | 350 | gettext_noop ( |
364 | gettext_noop ("set the maximum number of parallel requests for blocks that is allowed"), | 351 | "set the maximum number of parallel downloads that is allowed"), |
365 | &request_parallelism), | 352 | ¶llelism), |
366 | GNUNET_GETOPT_option_flag ('R', | 353 | GNUNET_GETOPT_option_uint ( |
367 | "recursive", | 354 | 'r', |
368 | gettext_noop ("download a GNUnet directory recursively"), | 355 | "request-parallelism", |
369 | &do_recursive), | 356 | "REQUESTS", |
370 | GNUNET_GETOPT_option_increment_uint ('V', | 357 | gettext_noop ( |
371 | "verbose", | 358 | "set the maximum number of parallel requests for blocks that is allowed"), |
372 | gettext_noop ("be verbose (print progress information)"), | 359 | &request_parallelism), |
373 | &verbose), | 360 | GNUNET_GETOPT_option_flag ('R', |
374 | GNUNET_GETOPT_OPTION_END | 361 | "recursive", |
375 | }; | 362 | gettext_noop ( |
376 | 363 | "download a GNUnet directory recursively"), | |
377 | if (GNUNET_OK != | 364 | &do_recursive), |
378 | GNUNET_STRINGS_get_utf8_args (argc, argv, | 365 | GNUNET_GETOPT_option_increment_uint ( |
379 | &argc, &argv)) | 366 | 'V', |
367 | "verbose", | ||
368 | gettext_noop ("be verbose (print progress information)"), | ||
369 | &verbose), | ||
370 | GNUNET_GETOPT_OPTION_END}; | ||
371 | |||
372 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | ||
380 | return 2; | 373 | return 2; |
381 | 374 | ||
382 | ret = (GNUNET_OK == | 375 | ret = |
383 | GNUNET_PROGRAM_run (argc, argv, | 376 | (GNUNET_OK == |
384 | "gnunet-download [OPTIONS] URI", | 377 | GNUNET_PROGRAM_run ( |
385 | gettext_noop | 378 | argc, |
386 | ("Download files from GNUnet using a GNUnet CHK or LOC URI (gnunet://fs/chk/...)"), | 379 | argv, |
387 | options, | 380 | "gnunet-download [OPTIONS] URI", |
388 | &run, NULL)) ? ret : 1; | 381 | gettext_noop ( |
389 | GNUNET_free ((void*) argv); | 382 | "Download files from GNUnet using a GNUnet CHK or LOC URI (gnunet://fs/chk/...)"), |
383 | options, | ||
384 | &run, | ||
385 | NULL)) | ||
386 | ? ret | ||
387 | : 1; | ||
388 | GNUNET_free ((void *) argv); | ||
390 | return ret; | 389 | return ret; |
391 | } | 390 | } |
392 | 391 | ||
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; | |||
55 | * @return GNUNET_OK to continue iteration | 55 | * @return GNUNET_OK to continue iteration |
56 | */ | 56 | */ |
57 | static int | 57 | static int |
58 | print_indexed (void *cls, const char *filename, const struct GNUNET_HashCode * file_id) | 58 | print_indexed (void *cls, |
59 | const char *filename, | ||
60 | const struct GNUNET_HashCode *file_id) | ||
59 | { | 61 | { |
60 | if (NULL == filename) | 62 | if (NULL == filename) |
61 | { | 63 | { |
@@ -64,9 +66,9 @@ print_indexed (void *cls, const char *filename, const struct GNUNET_HashCode * f | |||
64 | return GNUNET_OK; | 66 | return GNUNET_OK; |
65 | } | 67 | } |
66 | if (verbose) | 68 | if (verbose) |
67 | FPRINTF (stdout, "%s: %s\n", GNUNET_h2s (file_id), filename); | 69 | fprintf (stdout, "%s: %s\n", GNUNET_h2s (file_id), filename); |
68 | else | 70 | else |
69 | FPRINTF (stdout, "%s\n", filename); | 71 | fprintf (stdout, "%s\n", filename); |
70 | return GNUNET_OK; | 72 | return GNUNET_OK; |
71 | } | 73 | } |
72 | 74 | ||
@@ -80,12 +82,18 @@ print_indexed (void *cls, const char *filename, const struct GNUNET_HashCode * f | |||
80 | * @param cfg configuration | 82 | * @param cfg configuration |
81 | */ | 83 | */ |
82 | static void | 84 | static void |
83 | run (void *cls, char *const *args, const char *cfgfile, | 85 | run (void *cls, |
86 | char *const *args, | ||
87 | const char *cfgfile, | ||
84 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 88 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
85 | { | 89 | { |
86 | if (list_indexed_files) | 90 | if (list_indexed_files) |
87 | { | 91 | { |
88 | fs = GNUNET_FS_start (cfg, "gnunet-fs", NULL, NULL, GNUNET_FS_FLAGS_NONE, | 92 | fs = GNUNET_FS_start (cfg, |
93 | "gnunet-fs", | ||
94 | NULL, | ||
95 | NULL, | ||
96 | GNUNET_FS_FLAGS_NONE, | ||
89 | GNUNET_FS_OPTIONS_END); | 97 | GNUNET_FS_OPTIONS_END); |
90 | if (NULL == fs) | 98 | if (NULL == fs) |
91 | { | 99 | { |
@@ -115,21 +123,27 @@ main (int argc, char *const *argv) | |||
115 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 123 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
116 | 124 | ||
117 | GNUNET_GETOPT_option_flag ('i', | 125 | GNUNET_GETOPT_option_flag ('i', |
118 | "list-indexed", | 126 | "list-indexed", |
119 | gettext_noop ("print a list of all indexed files"), | 127 | gettext_noop ( |
120 | &list_indexed_files), | 128 | "print a list of all indexed files"), |
129 | &list_indexed_files), | ||
121 | 130 | ||
122 | GNUNET_GETOPT_option_verbose (&verbose), | 131 | GNUNET_GETOPT_option_verbose (&verbose), |
123 | GNUNET_GETOPT_OPTION_END | 132 | GNUNET_GETOPT_OPTION_END}; |
124 | }; | ||
125 | 133 | ||
126 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 134 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
127 | return 2; | 135 | return 2; |
128 | ret = (GNUNET_OK == | 136 | ret = (GNUNET_OK == |
129 | GNUNET_PROGRAM_run (argc, argv, "gnunet-fs [OPTIONS]", | 137 | GNUNET_PROGRAM_run (argc, |
130 | gettext_noop ("Special file-sharing operations"), | 138 | argv, |
131 | options, &run, NULL)) ? ret : 1; | 139 | "gnunet-fs [OPTIONS]", |
132 | GNUNET_free ((void*) argv); | 140 | gettext_noop ("Special file-sharing operations"), |
141 | options, | ||
142 | &run, | ||
143 | NULL)) | ||
144 | ? ret | ||
145 | : 1; | ||
146 | GNUNET_free ((void *) argv); | ||
133 | return ret; | 147 | return ret; |
134 | } | 148 | } |
135 | 149 | ||
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 | |||
78 | * #GNUNET_YES if this is a directory | 78 | * #GNUNET_YES if this is a directory |
79 | */ | 79 | */ |
80 | int is_directory; | 80 | int is_directory; |
81 | |||
82 | }; | 81 | }; |
83 | 82 | ||
84 | 83 | ||
@@ -124,20 +123,30 @@ add_to_md (void *cls, | |||
124 | { | 123 | { |
125 | struct GNUNET_CONTAINER_MetaData *md = cls; | 124 | struct GNUNET_CONTAINER_MetaData *md = cls; |
126 | 125 | ||
127 | if ( ((EXTRACTOR_METAFORMAT_UTF8 == format) || | 126 | if (((EXTRACTOR_METAFORMAT_UTF8 == format) || |
128 | (EXTRACTOR_METAFORMAT_C_STRING == format)) && | 127 | (EXTRACTOR_METAFORMAT_C_STRING == format)) && |
129 | ('\0' != data[data_len - 1]) ) | 128 | ('\0' != data[data_len - 1])) |
130 | { | 129 | { |
131 | char zdata[data_len + 1]; | 130 | char zdata[data_len + 1]; |
132 | GNUNET_memcpy (zdata, data, data_len); | 131 | GNUNET_memcpy (zdata, data, data_len); |
133 | zdata[data_len] = '\0'; | 132 | zdata[data_len] = '\0'; |
134 | (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, type, format, | 133 | (void) GNUNET_CONTAINER_meta_data_insert (md, |
135 | data_mime_type, zdata, data_len + 1); | 134 | plugin_name, |
135 | type, | ||
136 | format, | ||
137 | data_mime_type, | ||
138 | zdata, | ||
139 | data_len + 1); | ||
136 | } | 140 | } |
137 | else | 141 | else |
138 | { | 142 | { |
139 | (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, type, format, | 143 | (void) GNUNET_CONTAINER_meta_data_insert (md, |
140 | data_mime_type, data, data_len); | 144 | plugin_name, |
145 | type, | ||
146 | format, | ||
147 | data_mime_type, | ||
148 | data, | ||
149 | data_len); | ||
141 | } | 150 | } |
142 | return 0; | 151 | return 0; |
143 | } | 152 | } |
@@ -158,8 +167,8 @@ free_tree (struct ScanTreeNode *tree) | |||
158 | free_tree (pos); | 167 | free_tree (pos); |
159 | if (NULL != tree->parent) | 168 | if (NULL != tree->parent) |
160 | GNUNET_CONTAINER_DLL_remove (tree->parent->children_head, | 169 | GNUNET_CONTAINER_DLL_remove (tree->parent->children_head, |
161 | tree->parent->children_tail, | 170 | tree->parent->children_tail, |
162 | tree); | 171 | tree); |
163 | GNUNET_free (tree->filename); | 172 | GNUNET_free (tree->filename); |
164 | GNUNET_free (tree); | 173 | GNUNET_free (tree); |
165 | } | 174 | } |
@@ -173,8 +182,7 @@ free_tree (struct ScanTreeNode *tree) | |||
173 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 182 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
174 | */ | 183 | */ |
175 | static int | 184 | static int |
176 | write_all (const void *buf, | 185 | write_all (const void *buf, size_t size) |
177 | size_t size) | ||
178 | { | 186 | { |
179 | const char *cbuf = buf; | 187 | const char *cbuf = buf; |
180 | size_t total; | 188 | size_t total; |
@@ -183,16 +191,14 @@ write_all (const void *buf, | |||
183 | total = 0; | 191 | total = 0; |
184 | do | 192 | do |
185 | { | 193 | { |
186 | wr = write (output_stream, | 194 | wr = write (output_stream, &cbuf[total], size - total); |
187 | &cbuf[total], | ||
188 | size - total); | ||
189 | if (wr > 0) | 195 | if (wr > 0) |
190 | total += wr; | 196 | total += wr; |
191 | } while ( (wr > 0) && (total < size) ); | 197 | } while ((wr > 0) && (total < size)); |
192 | if (wr <= 0) | 198 | if (wr <= 0) |
193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
194 | "Failed to write to stdout: %s\n", | 200 | "Failed to write to stdout: %s\n", |
195 | strerror (errno)); | 201 | strerror (errno)); |
196 | return (total == size) ? GNUNET_OK : GNUNET_SYSERR; | 202 | return (total == size) ? GNUNET_OK : GNUNET_SYSERR; |
197 | } | 203 | } |
198 | 204 | ||
@@ -206,9 +212,7 @@ write_all (const void *buf, | |||
206 | * @return #GNUNET_SYSERR to stop scanning (the pipe was broken somehow) | 212 | * @return #GNUNET_SYSERR to stop scanning (the pipe was broken somehow) |
207 | */ | 213 | */ |
208 | static int | 214 | static int |
209 | write_message (uint16_t message_type, | 215 | write_message (uint16_t message_type, const char *data, size_t data_length) |
210 | const char *data, | ||
211 | size_t data_length) | ||
212 | { | 216 | { |
213 | struct GNUNET_MessageHeader hdr; | 217 | struct GNUNET_MessageHeader hdr; |
214 | 218 | ||
@@ -220,12 +224,8 @@ write_message (uint16_t message_type, | |||
220 | #endif | 224 | #endif |
221 | hdr.type = htons (message_type); | 225 | hdr.type = htons (message_type); |
222 | hdr.size = htons (sizeof (struct GNUNET_MessageHeader) + data_length); | 226 | hdr.size = htons (sizeof (struct GNUNET_MessageHeader) + data_length); |
223 | if ( (GNUNET_OK != | 227 | if ((GNUNET_OK != write_all (&hdr, sizeof (hdr))) || |
224 | write_all (&hdr, | 228 | (GNUNET_OK != write_all (data, data_length))) |
225 | sizeof (hdr))) || | ||
226 | (GNUNET_OK != | ||
227 | write_all (data, | ||
228 | data_length)) ) | ||
229 | return GNUNET_SYSERR; | 229 | return GNUNET_SYSERR; |
230 | return GNUNET_OK; | 230 | return GNUNET_OK; |
231 | } | 231 | } |
@@ -242,8 +242,7 @@ write_message (uint16_t message_type, | |||
242 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 242 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
243 | */ | 243 | */ |
244 | static int | 244 | static int |
245 | preprocess_file (const char *filename, | 245 | preprocess_file (const char *filename, struct ScanTreeNode **dst); |
246 | struct ScanTreeNode **dst); | ||
247 | 246 | ||
248 | 247 | ||
249 | /** | 248 | /** |
@@ -273,15 +272,12 @@ struct RecursionContext | |||
273 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 272 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
274 | */ | 273 | */ |
275 | static int | 274 | static int |
276 | scan_callback (void *cls, | 275 | scan_callback (void *cls, const char *filename) |
277 | const char *filename) | ||
278 | { | 276 | { |
279 | struct RecursionContext *rc = cls; | 277 | struct RecursionContext *rc = cls; |
280 | struct ScanTreeNode *chld; | 278 | struct ScanTreeNode *chld; |
281 | 279 | ||
282 | if (GNUNET_OK != | 280 | if (GNUNET_OK != preprocess_file (filename, &chld)) |
283 | preprocess_file (filename, | ||
284 | &chld)) | ||
285 | { | 281 | { |
286 | rc->stop = GNUNET_YES; | 282 | rc->stop = GNUNET_YES; |
287 | return GNUNET_SYSERR; | 283 | return GNUNET_SYSERR; |
@@ -290,8 +286,8 @@ scan_callback (void *cls, | |||
290 | return GNUNET_OK; | 286 | return GNUNET_OK; |
291 | chld->parent = rc->parent; | 287 | chld->parent = rc->parent; |
292 | GNUNET_CONTAINER_DLL_insert (rc->parent->children_head, | 288 | GNUNET_CONTAINER_DLL_insert (rc->parent->children_head, |
293 | rc->parent->children_tail, | 289 | rc->parent->children_tail, |
294 | chld); | 290 | chld); |
295 | return GNUNET_OK; | 291 | return GNUNET_OK; |
296 | } | 292 | } |
297 | 293 | ||
@@ -307,22 +303,23 @@ scan_callback (void *cls, | |||
307 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 303 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
308 | */ | 304 | */ |
309 | static int | 305 | static int |
310 | preprocess_file (const char *filename, | 306 | preprocess_file (const char *filename, struct ScanTreeNode **dst) |
311 | struct ScanTreeNode **dst) | ||
312 | { | 307 | { |
313 | struct ScanTreeNode *item; | 308 | struct ScanTreeNode *item; |
314 | struct stat sbuf; | 309 | struct stat sbuf; |
315 | uint64_t fsize = 0; | 310 | uint64_t fsize = 0; |
316 | 311 | ||
317 | if ((0 != STAT (filename, &sbuf)) || | 312 | if ((0 != stat (filename, &sbuf)) || |
318 | ((!S_ISDIR (sbuf.st_mode)) && (GNUNET_OK != GNUNET_DISK_file_size ( | 313 | ((! S_ISDIR (sbuf.st_mode)) && |
319 | filename, &fsize, GNUNET_NO, GNUNET_YES)))) | 314 | (GNUNET_OK != |
315 | GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES)))) | ||
320 | { | 316 | { |
321 | /* If the file doesn't exist (or is not stat-able for any other reason) | 317 | /* If the file doesn't exist (or is not stat-able for any other reason) |
322 | skip it (but report it), but do continue. */ | 318 | skip it (but report it), but do continue. */ |
323 | if (GNUNET_OK != | 319 | if (GNUNET_OK != |
324 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE, | 320 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE, |
325 | filename, strlen (filename) + 1)) | 321 | filename, |
322 | strlen (filename) + 1)) | ||
326 | return GNUNET_SYSERR; | 323 | return GNUNET_SYSERR; |
327 | /* recoverable error, store 'NULL' in *dst */ | 324 | /* recoverable error, store 'NULL' in *dst */ |
328 | *dst = NULL; | 325 | *dst = NULL; |
@@ -330,11 +327,13 @@ preprocess_file (const char *filename, | |||
330 | } | 327 | } |
331 | 328 | ||
332 | /* Report the progress */ | 329 | /* Report the progress */ |
333 | if (GNUNET_OK != | 330 | if ( |
334 | write_message (S_ISDIR (sbuf.st_mode) | 331 | GNUNET_OK != |
335 | ? GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY | 332 | write_message (S_ISDIR (sbuf.st_mode) |
336 | : GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE, | 333 | ? GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY |
337 | filename, strlen (filename) + 1)) | 334 | : GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE, |
335 | filename, | ||
336 | strlen (filename) + 1)) | ||
338 | return GNUNET_SYSERR; | 337 | return GNUNET_SYSERR; |
339 | item = GNUNET_new (struct ScanTreeNode); | 338 | item = GNUNET_new (struct ScanTreeNode); |
340 | item->filename = GNUNET_strdup (filename); | 339 | item->filename = GNUNET_strdup (filename); |
@@ -346,13 +345,13 @@ preprocess_file (const char *filename, | |||
346 | 345 | ||
347 | rc.parent = item; | 346 | rc.parent = item; |
348 | rc.stop = GNUNET_NO; | 347 | rc.stop = GNUNET_NO; |
349 | GNUNET_DISK_directory_scan (filename, | 348 | GNUNET_DISK_directory_scan (filename, &scan_callback, &rc); |
350 | &scan_callback, | 349 | if ( |
351 | &rc); | 350 | (GNUNET_YES == rc.stop) || |
352 | if ( (GNUNET_YES == rc.stop) || | 351 | (GNUNET_OK != |
353 | (GNUNET_OK != | 352 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY, |
354 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY, | 353 | "..", |
355 | "..", 3)) ) | 354 | 3))) |
356 | { | 355 | { |
357 | free_tree (item); | 356 | free_tree (item); |
358 | return GNUNET_SYSERR; | 357 | return GNUNET_SYSERR; |
@@ -383,20 +382,15 @@ extract_files (struct ScanTreeNode *item) | |||
383 | struct ScanTreeNode *pos; | 382 | struct ScanTreeNode *pos; |
384 | 383 | ||
385 | for (pos = item->children_head; NULL != pos; pos = pos->next) | 384 | for (pos = item->children_head; NULL != pos; pos = pos->next) |
386 | if (GNUNET_OK != | 385 | if (GNUNET_OK != extract_files (pos)) |
387 | extract_files (pos)) | 386 | return GNUNET_SYSERR; |
388 | return GNUNET_SYSERR; | ||
389 | return GNUNET_OK; | 387 | return GNUNET_OK; |
390 | } | 388 | } |
391 | 389 | ||
392 | /* this is the expensive operation, *afterwards* we'll check for aborts */ | 390 | /* this is the expensive operation, *afterwards* we'll check for aborts */ |
393 | meta = GNUNET_CONTAINER_meta_data_create (); | 391 | meta = GNUNET_CONTAINER_meta_data_create (); |
394 | #if HAVE_LIBEXTRACTOR | 392 | #if HAVE_LIBEXTRACTOR |
395 | EXTRACTOR_extract (plugins, | 393 | EXTRACTOR_extract (plugins, item->filename, NULL, 0, &add_to_md, meta); |
396 | item->filename, | ||
397 | NULL, 0, | ||
398 | &add_to_md, | ||
399 | meta); | ||
400 | #endif | 394 | #endif |
401 | slen = strlen (item->filename) + 1; | 395 | slen = strlen (item->filename) + 1; |
402 | size = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); | 396 | size = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); |
@@ -405,8 +399,9 @@ extract_files (struct ScanTreeNode *item) | |||
405 | /* no meta data */ | 399 | /* no meta data */ |
406 | GNUNET_CONTAINER_meta_data_destroy (meta); | 400 | GNUNET_CONTAINER_meta_data_destroy (meta); |
407 | if (GNUNET_OK != | 401 | if (GNUNET_OK != |
408 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, | 402 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, |
409 | item->filename, slen)) | 403 | item->filename, |
404 | slen)) | ||
410 | return GNUNET_SYSERR; | 405 | return GNUNET_SYSERR; |
411 | return GNUNET_OK; | 406 | return GNUNET_OK; |
412 | } | 407 | } |
@@ -420,9 +415,11 @@ extract_files (struct ScanTreeNode *item) | |||
420 | char *dst = &buf[slen]; | 415 | char *dst = &buf[slen]; |
421 | 416 | ||
422 | GNUNET_memcpy (buf, item->filename, slen); | 417 | GNUNET_memcpy (buf, item->filename, slen); |
423 | size = GNUNET_CONTAINER_meta_data_serialize (meta, | 418 | size = GNUNET_CONTAINER_meta_data_serialize ( |
424 | &dst, size, | 419 | meta, |
425 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); | 420 | &dst, |
421 | size, | ||
422 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); | ||
426 | if (size < 0) | 423 | if (size < 0) |
427 | { | 424 | { |
428 | GNUNET_break (0); | 425 | GNUNET_break (0); |
@@ -430,9 +427,9 @@ extract_files (struct ScanTreeNode *item) | |||
430 | } | 427 | } |
431 | GNUNET_CONTAINER_meta_data_destroy (meta); | 428 | GNUNET_CONTAINER_meta_data_destroy (meta); |
432 | if (GNUNET_OK != | 429 | if (GNUNET_OK != |
433 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, | 430 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, |
434 | buf, | 431 | buf, |
435 | slen + size)) | 432 | slen + size)) |
436 | return GNUNET_SYSERR; | 433 | return GNUNET_SYSERR; |
437 | } | 434 | } |
438 | return GNUNET_OK; | 435 | return GNUNET_OK; |
@@ -453,13 +450,14 @@ ignore_sigpipe () | |||
453 | sig.sa_handler = SIG_IGN; | 450 | sig.sa_handler = SIG_IGN; |
454 | sigemptyset (&sig.sa_mask); | 451 | sigemptyset (&sig.sa_mask); |
455 | #ifdef SA_INTERRUPT | 452 | #ifdef SA_INTERRUPT |
456 | sig.sa_flags = SA_INTERRUPT; /* SunOS */ | 453 | sig.sa_flags = SA_INTERRUPT; /* SunOS */ |
457 | #else | 454 | #else |
458 | sig.sa_flags = SA_RESTART; | 455 | sig.sa_flags = SA_RESTART; |
459 | #endif | 456 | #endif |
460 | if (0 != sigaction (SIGPIPE, &sig, &oldsig)) | 457 | if (0 != sigaction (SIGPIPE, &sig, &oldsig)) |
461 | fprintf (stderr, | 458 | fprintf (stderr, |
462 | "Failed to install SIGPIPE handler: %s\n", strerror (errno)); | 459 | "Failed to install SIGPIPE handler: %s\n", |
460 | strerror (errno)); | ||
463 | } | 461 | } |
464 | 462 | ||
465 | 463 | ||
@@ -470,8 +468,7 @@ ignore_sigpipe () | |||
470 | * @param flags flags to use (O_RDONLY or O_WRONLY) | 468 | * @param flags flags to use (O_RDONLY or O_WRONLY) |
471 | */ | 469 | */ |
472 | static void | 470 | static void |
473 | make_dev_zero (int fd, | 471 | make_dev_zero (int fd, int flags) |
474 | int flags) | ||
475 | { | 472 | { |
476 | int z; | 473 | int z; |
477 | 474 | ||
@@ -498,8 +495,7 @@ make_dev_zero (int fd, | |||
498 | * @return 0 on success | 495 | * @return 0 on success |
499 | */ | 496 | */ |
500 | int | 497 | int |
501 | main (int argc, | 498 | main (int argc, char *const *argv) |
502 | char *const *argv) | ||
503 | { | 499 | { |
504 | const char *filename_expanded; | 500 | const char *filename_expanded; |
505 | const char *ex; | 501 | const char *ex; |
@@ -524,79 +520,83 @@ main (int argc, | |||
524 | #endif | 520 | #endif |
525 | 521 | ||
526 | /* parse command line */ | 522 | /* parse command line */ |
527 | if ( (3 != argc) && (2 != argc) ) | 523 | if ((3 != argc) && (2 != argc)) |
528 | { | 524 | { |
529 | FPRINTF (stderr, | 525 | fprintf (stderr, |
530 | "%s", | 526 | "%s", |
531 | "gnunet-helper-fs-publish needs exactly one or two arguments\n"); | 527 | "gnunet-helper-fs-publish needs exactly one or two arguments\n"); |
532 | #if WINDOWS | 528 | #if WINDOWS |
533 | GNUNET_free ((void*) argv); | 529 | GNUNET_free ((void *) argv); |
534 | #endif | 530 | #endif |
535 | return 1; | 531 | return 1; |
536 | } | 532 | } |
537 | filename_expanded = argv[1]; | 533 | filename_expanded = argv[1]; |
538 | ex = argv[2]; | 534 | ex = argv[2]; |
539 | if ( (NULL == ex) || | 535 | if ((NULL == ex) || (0 != strcmp (ex, "-"))) |
540 | (0 != strcmp (ex, "-")) ) | ||
541 | { | 536 | { |
542 | #if HAVE_LIBEXTRACTOR | 537 | #if HAVE_LIBEXTRACTOR |
543 | plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY); | 538 | plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY); |
544 | if (NULL != ex) | 539 | if (NULL != ex) |
545 | plugins = EXTRACTOR_plugin_add_config (plugins, ex, | 540 | plugins = EXTRACTOR_plugin_add_config (plugins, |
546 | EXTRACTOR_OPTION_DEFAULT_POLICY); | 541 | ex, |
542 | EXTRACTOR_OPTION_DEFAULT_POLICY); | ||
547 | #endif | 543 | #endif |
548 | } | 544 | } |
549 | 545 | ||
550 | /* scan tree to find out how much work there is to be done */ | 546 | /* scan tree to find out how much work there is to be done */ |
551 | if (GNUNET_OK != preprocess_file (filename_expanded, | 547 | if (GNUNET_OK != preprocess_file (filename_expanded, &root)) |
552 | &root)) | ||
553 | { | 548 | { |
554 | (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0); | 549 | (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0); |
555 | #if HAVE_LIBEXTRACTOR | 550 | #if HAVE_LIBEXTRACTOR |
556 | EXTRACTOR_plugin_remove_all (plugins); | 551 | EXTRACTOR_plugin_remove_all (plugins); |
557 | #endif | 552 | #endif |
558 | #if WINDOWS | 553 | #if WINDOWS |
559 | GNUNET_free ((void*) argv); | 554 | GNUNET_free ((void *) argv); |
560 | #endif | 555 | #endif |
561 | return 2; | 556 | return 2; |
562 | } | 557 | } |
563 | /* signal that we're done counting files, so that a percentage of | 558 | /* signal that we're done counting files, so that a percentage of |
564 | progress can now be calculated */ | 559 | progress can now be calculated */ |
565 | if (GNUNET_OK != | 560 | if (GNUNET_OK != |
566 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE, NULL, 0)) | 561 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE, |
562 | NULL, | ||
563 | 0)) | ||
567 | { | 564 | { |
568 | #if HAVE_LIBEXTRACTOR | 565 | #if HAVE_LIBEXTRACTOR |
569 | EXTRACTOR_plugin_remove_all (plugins); | 566 | EXTRACTOR_plugin_remove_all (plugins); |
570 | #endif | 567 | #endif |
571 | #if WINDOWS | 568 | #if WINDOWS |
572 | GNUNET_free ((void*) argv); | 569 | GNUNET_free ((void *) argv); |
573 | #endif | 570 | #endif |
574 | return 3; | 571 | return 3; |
575 | } | 572 | } |
576 | if (NULL != root) | 573 | if (NULL != root) |
577 | { | 574 | { |
578 | if (GNUNET_OK != | 575 | if (GNUNET_OK != extract_files (root)) |
579 | extract_files (root)) | ||
580 | { | 576 | { |
581 | (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0); | 577 | (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, |
578 | NULL, | ||
579 | 0); | ||
582 | free_tree (root); | 580 | free_tree (root); |
583 | #if HAVE_LIBEXTRACTOR | 581 | #if HAVE_LIBEXTRACTOR |
584 | EXTRACTOR_plugin_remove_all (plugins); | 582 | EXTRACTOR_plugin_remove_all (plugins); |
585 | #endif | 583 | #endif |
586 | #if WINDOWS | 584 | #if WINDOWS |
587 | GNUNET_free ((void*) argv); | 585 | GNUNET_free ((void *) argv); |
588 | #endif | 586 | #endif |
589 | return 4; | 587 | return 4; |
590 | } | 588 | } |
591 | free_tree (root); | 589 | free_tree (root); |
592 | } | 590 | } |
593 | /* enable "clean" shutdown by telling parent that we are done */ | 591 | /* enable "clean" shutdown by telling parent that we are done */ |
594 | (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED, NULL, 0); | 592 | (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED, |
593 | NULL, | ||
594 | 0); | ||
595 | #if HAVE_LIBEXTRACTOR | 595 | #if HAVE_LIBEXTRACTOR |
596 | EXTRACTOR_plugin_remove_all (plugins); | 596 | EXTRACTOR_plugin_remove_all (plugins); |
597 | #endif | 597 | #endif |
598 | #if WINDOWS | 598 | #if WINDOWS |
599 | GNUNET_free ((void*) argv); | 599 | GNUNET_free ((void *) argv); |
600 | #endif | 600 | #endif |
601 | return 0; | 601 | return 0; |
602 | } | 602 | } |
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; | |||
67 | /** | 67 | /** |
68 | * Options we set for published blocks. | 68 | * Options we set for published blocks. |
69 | */ | 69 | */ |
70 | static struct GNUNET_FS_BlockOptions bo = { {0LL}, 1, 365, 1 }; | 70 | static struct GNUNET_FS_BlockOptions bo = {{0LL}, 1, 365, 1}; |
71 | 71 | ||
72 | /** | 72 | /** |
73 | * Value of URI provided on command-line (when not publishing | 73 | * Value of URI provided on command-line (when not publishing |
@@ -200,8 +200,7 @@ do_stop_task (void *cls) | |||
200 | * field in the GNUNET_FS_ProgressInfo struct. | 200 | * field in the GNUNET_FS_ProgressInfo struct. |
201 | */ | 201 | */ |
202 | static void * | 202 | static void * |
203 | progress_cb (void *cls, | 203 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) |
204 | const struct GNUNET_FS_ProgressInfo *info) | ||
205 | { | 204 | { |
206 | const char *s; | 205 | const char *s; |
207 | char *suri; | 206 | char *suri; |
@@ -214,50 +213,51 @@ progress_cb (void *cls, | |||
214 | if (verbose) | 213 | if (verbose) |
215 | { | 214 | { |
216 | s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.eta, | 215 | s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.eta, |
217 | GNUNET_YES); | 216 | GNUNET_YES); |
218 | FPRINTF (stdout, | 217 | fprintf (stdout, |
219 | _("Publishing `%s' at %llu/%llu (%s remaining)\n"), | 218 | _ ("Publishing `%s' at %llu/%llu (%s remaining)\n"), |
220 | info->value.publish.filename, | 219 | info->value.publish.filename, |
221 | (unsigned long long) info->value.publish.completed, | 220 | (unsigned long long) info->value.publish.completed, |
222 | (unsigned long long) info->value.publish.size, s); | 221 | (unsigned long long) info->value.publish.size, |
222 | s); | ||
223 | } | 223 | } |
224 | break; | 224 | break; |
225 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: | 225 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: |
226 | if (verbose) | 226 | if (verbose) |
227 | { | 227 | { |
228 | s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.specifics.progress_directory.eta, | 228 | s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.specifics |
229 | GNUNET_YES); | 229 | .progress_directory.eta, |
230 | FPRINTF (stdout, | 230 | GNUNET_YES); |
231 | _("Publishing `%s' at %llu/%llu (%s remaining)\n"), | 231 | fprintf (stdout, |
232 | _ ("Publishing `%s' at %llu/%llu (%s remaining)\n"), | ||
232 | info->value.publish.filename, | 233 | info->value.publish.filename, |
233 | (unsigned long long) info->value.publish.specifics.progress_directory.completed, | 234 | (unsigned long long) |
234 | (unsigned long long) info->value.publish.specifics.progress_directory.total, s); | 235 | info->value.publish.specifics.progress_directory.completed, |
236 | (unsigned long long) | ||
237 | info->value.publish.specifics.progress_directory.total, | ||
238 | s); | ||
235 | } | 239 | } |
236 | break; | 240 | break; |
237 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 241 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
238 | FPRINTF (stderr, | 242 | fprintf (stderr, |
239 | _("Error publishing: %s.\n"), | 243 | _ ("Error publishing: %s.\n"), |
240 | info->value.publish.specifics.error.message); | 244 | info->value.publish.specifics.error.message); |
241 | ret = 1; | 245 | ret = 1; |
242 | GNUNET_SCHEDULER_shutdown (); | 246 | GNUNET_SCHEDULER_shutdown (); |
243 | break; | 247 | break; |
244 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 248 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
245 | FPRINTF (stdout, | 249 | fprintf (stdout, |
246 | _("Publishing `%s' done.\n"), | 250 | _ ("Publishing `%s' done.\n"), |
247 | info->value.publish.filename); | 251 | info->value.publish.filename); |
248 | suri = GNUNET_FS_uri_to_string (info->value.publish.specifics. | 252 | suri = |
249 | completed.chk_uri); | 253 | GNUNET_FS_uri_to_string (info->value.publish.specifics.completed.chk_uri); |
250 | FPRINTF (stdout, | 254 | fprintf (stdout, _ ("URI is `%s'.\n"), suri); |
251 | _("URI is `%s'.\n"), | ||
252 | suri); | ||
253 | GNUNET_free (suri); | 255 | GNUNET_free (suri); |
254 | if (NULL != info->value.publish.specifics.completed.sks_uri) | 256 | if (NULL != info->value.publish.specifics.completed.sks_uri) |
255 | { | 257 | { |
256 | suri = GNUNET_FS_uri_to_string (info->value.publish.specifics. | 258 | suri = GNUNET_FS_uri_to_string ( |
257 | completed.sks_uri); | 259 | info->value.publish.specifics.completed.sks_uri); |
258 | FPRINTF (stdout, | 260 | fprintf (stdout, _ ("Namespace URI is `%s'.\n"), suri); |
259 | _("Namespace URI is `%s'.\n"), | ||
260 | suri); | ||
261 | GNUNET_free (suri); | 261 | GNUNET_free (suri); |
262 | } | 262 | } |
263 | if (NULL == info->value.publish.pctx) | 263 | if (NULL == info->value.publish.pctx) |
@@ -270,33 +270,25 @@ progress_cb (void *cls, | |||
270 | GNUNET_break (NULL == pc); | 270 | GNUNET_break (NULL == pc); |
271 | return NULL; | 271 | return NULL; |
272 | case GNUNET_FS_STATUS_UNINDEX_START: | 272 | case GNUNET_FS_STATUS_UNINDEX_START: |
273 | FPRINTF (stderr, | 273 | fprintf (stderr, "%s", _ ("Starting cleanup after abort\n")); |
274 | "%s", | ||
275 | _("Starting cleanup after abort\n")); | ||
276 | return NULL; | 274 | return NULL; |
277 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: | 275 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: |
278 | return NULL; | 276 | return NULL; |
279 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: | 277 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: |
280 | FPRINTF (stderr, | 278 | fprintf (stderr, "%s", _ ("Cleanup after abort completed.\n")); |
281 | "%s", | ||
282 | _("Cleanup after abort completed.\n")); | ||
283 | GNUNET_FS_unindex_stop (info->value.unindex.uc); | 279 | GNUNET_FS_unindex_stop (info->value.unindex.uc); |
284 | return NULL; | 280 | return NULL; |
285 | case GNUNET_FS_STATUS_UNINDEX_ERROR: | 281 | case GNUNET_FS_STATUS_UNINDEX_ERROR: |
286 | FPRINTF (stderr, | 282 | fprintf (stderr, "%s", _ ("Cleanup after abort failed.\n")); |
287 | "%s", | ||
288 | _("Cleanup after abort failed.\n")); | ||
289 | GNUNET_FS_unindex_stop (info->value.unindex.uc); | 283 | GNUNET_FS_unindex_stop (info->value.unindex.uc); |
290 | return NULL; | 284 | return NULL; |
291 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: | 285 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: |
292 | return NULL; | 286 | return NULL; |
293 | default: | 287 | default: |
294 | FPRINTF (stderr, | 288 | fprintf (stderr, _ ("Unexpected status: %d\n"), info->status); |
295 | _("Unexpected status: %d\n"), | ||
296 | info->status); | ||
297 | return NULL; | 289 | return NULL; |
298 | } | 290 | } |
299 | return ""; /* non-null */ | 291 | return ""; /* non-null */ |
300 | } | 292 | } |
301 | 293 | ||
302 | 294 | ||
@@ -319,7 +311,8 @@ meta_printer (void *cls, | |||
319 | enum EXTRACTOR_MetaType type, | 311 | enum EXTRACTOR_MetaType type, |
320 | enum EXTRACTOR_MetaFormat format, | 312 | enum EXTRACTOR_MetaFormat format, |
321 | const char *data_mime_type, | 313 | const char *data_mime_type, |
322 | const char *data, size_t data_size) | 314 | const char *data, |
315 | size_t data_size) | ||
323 | { | 316 | { |
324 | if ((EXTRACTOR_METAFORMAT_UTF8 != format) && | 317 | if ((EXTRACTOR_METAFORMAT_UTF8 != format) && |
325 | (EXTRACTOR_METAFORMAT_C_STRING != format)) | 318 | (EXTRACTOR_METAFORMAT_C_STRING != format)) |
@@ -327,15 +320,9 @@ meta_printer (void *cls, | |||
327 | if (EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME == type) | 320 | if (EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME == type) |
328 | return 0; | 321 | return 0; |
329 | #if HAVE_LIBEXTRACTOR | 322 | #if HAVE_LIBEXTRACTOR |
330 | FPRINTF (stdout, | 323 | fprintf (stdout, "\t%s - %s\n", EXTRACTOR_metatype_to_string (type), data); |
331 | "\t%s - %s\n", | ||
332 | EXTRACTOR_metatype_to_string (type), | ||
333 | data); | ||
334 | #else | 324 | #else |
335 | FPRINTF (stdout, | 325 | fprintf (stdout, "\t%d - %s\n", type, data); |
336 | "\t%d - %s\n", | ||
337 | type, | ||
338 | data); | ||
339 | #endif | 326 | #endif |
340 | return 0; | 327 | return 0; |
341 | } | 328 | } |
@@ -350,11 +337,9 @@ meta_printer (void *cls, | |||
350 | * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to abort | 337 | * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to abort |
351 | */ | 338 | */ |
352 | static int | 339 | static int |
353 | keyword_printer (void *cls, | 340 | keyword_printer (void *cls, const char *keyword, int is_mandatory) |
354 | const char *keyword, | ||
355 | int is_mandatory) | ||
356 | { | 341 | { |
357 | FPRINTF (stdout, "\t%s\n", keyword); | 342 | fprintf (stdout, "\t%s\n", keyword); |
358 | return GNUNET_OK; | 343 | return GNUNET_OK; |
359 | } | 344 | } |
360 | 345 | ||
@@ -392,8 +377,7 @@ publish_inspector (void *cls, | |||
392 | 377 | ||
393 | if (cls == fi) | 378 | if (cls == fi) |
394 | return GNUNET_OK; | 379 | return GNUNET_OK; |
395 | if ( (disable_extractor) && | 380 | if ((disable_extractor) && (NULL != *uri)) |
396 | (NULL != *uri) ) | ||
397 | { | 381 | { |
398 | GNUNET_FS_uri_destroy (*uri); | 382 | GNUNET_FS_uri_destroy (*uri); |
399 | *uri = NULL; | 383 | *uri = NULL; |
@@ -423,29 +407,21 @@ publish_inspector (void *cls, | |||
423 | GNUNET_CONTAINER_meta_data_add_publication_date (m); | 407 | GNUNET_CONTAINER_meta_data_add_publication_date (m); |
424 | if (extract_only) | 408 | if (extract_only) |
425 | { | 409 | { |
426 | fn = GNUNET_CONTAINER_meta_data_get_by_type (m, | 410 | fn = GNUNET_CONTAINER_meta_data_get_by_type ( |
427 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); | 411 | m, |
412 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); | ||
428 | fs = GNUNET_STRINGS_byte_size_fancy (length); | 413 | fs = GNUNET_STRINGS_byte_size_fancy (length); |
429 | FPRINTF (stdout, | 414 | fprintf (stdout, _ ("Meta data for file `%s' (%s)\n"), fn, fs); |
430 | _("Meta data for file `%s' (%s)\n"), | ||
431 | fn, | ||
432 | fs); | ||
433 | GNUNET_CONTAINER_meta_data_iterate (m, &meta_printer, NULL); | 415 | GNUNET_CONTAINER_meta_data_iterate (m, &meta_printer, NULL); |
434 | FPRINTF (stdout, | 416 | fprintf (stdout, _ ("Keywords for file `%s' (%s)\n"), fn, fs); |
435 | _("Keywords for file `%s' (%s)\n"), | ||
436 | fn, | ||
437 | fs); | ||
438 | GNUNET_free (fn); | 417 | GNUNET_free (fn); |
439 | GNUNET_free (fs); | 418 | GNUNET_free (fs); |
440 | if (NULL != *uri) | 419 | if (NULL != *uri) |
441 | GNUNET_FS_uri_ksk_get_keywords (*uri, &keyword_printer, NULL); | 420 | GNUNET_FS_uri_ksk_get_keywords (*uri, &keyword_printer, NULL); |
442 | FPRINTF (stdout, | 421 | fprintf (stdout, "%s", "\n"); |
443 | "%s", | ||
444 | "\n"); | ||
445 | } | 422 | } |
446 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (m)) | 423 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (m)) |
447 | GNUNET_FS_file_information_inspect (fi, | 424 | GNUNET_FS_file_information_inspect (fi, &publish_inspector, fi); |
448 | &publish_inspector, fi); | ||
449 | return GNUNET_OK; | 425 | return GNUNET_OK; |
450 | } | 426 | } |
451 | 427 | ||
@@ -466,9 +442,7 @@ uri_sks_continuation (void *cls, | |||
466 | { | 442 | { |
467 | if (NULL != emsg) | 443 | if (NULL != emsg) |
468 | { | 444 | { |
469 | FPRINTF (stderr, | 445 | fprintf (stderr, "%s\n", emsg); |
470 | "%s\n", | ||
471 | emsg); | ||
472 | ret = 1; | 446 | ret = 1; |
473 | } | 447 | } |
474 | GNUNET_SCHEDULER_shutdown (); | 448 | GNUNET_SCHEDULER_shutdown (); |
@@ -493,9 +467,7 @@ uri_ksk_continuation (void *cls, | |||
493 | 467 | ||
494 | if (NULL != emsg) | 468 | if (NULL != emsg) |
495 | { | 469 | { |
496 | FPRINTF (stderr, | 470 | fprintf (stderr, "%s\n", emsg); |
497 | "%s\n", | ||
498 | emsg); | ||
499 | ret = 1; | 471 | ret = 1; |
500 | } | 472 | } |
501 | if (NULL == namespace) | 473 | if (NULL == namespace) |
@@ -505,15 +477,15 @@ uri_ksk_continuation (void *cls, | |||
505 | } | 477 | } |
506 | priv = GNUNET_IDENTITY_ego_get_private_key (namespace); | 478 | priv = GNUNET_IDENTITY_ego_get_private_key (namespace); |
507 | GNUNET_FS_publish_sks (ctx, | 479 | GNUNET_FS_publish_sks (ctx, |
508 | priv, | 480 | priv, |
509 | this_id, | 481 | this_id, |
510 | next_id, | 482 | next_id, |
511 | meta, | 483 | meta, |
512 | uri, | 484 | uri, |
513 | &bo, | 485 | &bo, |
514 | GNUNET_FS_PUBLISH_OPTION_NONE, | 486 | GNUNET_FS_PUBLISH_OPTION_NONE, |
515 | &uri_sks_continuation, | 487 | &uri_sks_continuation, |
516 | NULL); | 488 | NULL); |
517 | } | 489 | } |
518 | 490 | ||
519 | 491 | ||
@@ -536,8 +508,9 @@ get_file_information (struct GNUNET_FS_ShareTreeItem *item) | |||
536 | if (NULL == item->meta) | 508 | if (NULL == item->meta) |
537 | item->meta = GNUNET_CONTAINER_meta_data_create (); | 509 | item->meta = GNUNET_CONTAINER_meta_data_create (); |
538 | GNUNET_CONTAINER_meta_data_delete (item->meta, | 510 | GNUNET_CONTAINER_meta_data_delete (item->meta, |
539 | EXTRACTOR_METATYPE_MIMETYPE, | 511 | EXTRACTOR_METATYPE_MIMETYPE, |
540 | NULL, 0); | 512 | NULL, |
513 | 0); | ||
541 | GNUNET_FS_meta_data_make_directory (item->meta); | 514 | GNUNET_FS_meta_data_make_directory (item->meta); |
542 | if (NULL == item->ksk_uri) | 515 | if (NULL == item->ksk_uri) |
543 | { | 516 | { |
@@ -545,12 +518,15 @@ get_file_information (struct GNUNET_FS_ShareTreeItem *item) | |||
545 | item->ksk_uri = GNUNET_FS_uri_ksk_create_from_args (1, &mime); | 518 | item->ksk_uri = GNUNET_FS_uri_ksk_create_from_args (1, &mime); |
546 | } | 519 | } |
547 | else | 520 | else |
548 | GNUNET_FS_uri_ksk_add_keyword (item->ksk_uri, GNUNET_FS_DIRECTORY_MIME, | 521 | GNUNET_FS_uri_ksk_add_keyword (item->ksk_uri, |
549 | GNUNET_NO); | 522 | GNUNET_FS_DIRECTORY_MIME, |
550 | fi = GNUNET_FS_file_information_create_empty_directory (ctx, NULL, | 523 | GNUNET_NO); |
551 | item->ksk_uri, | 524 | fi = GNUNET_FS_file_information_create_empty_directory (ctx, |
552 | item->meta, | 525 | NULL, |
553 | &bo, item->filename); | 526 | item->ksk_uri, |
527 | item->meta, | ||
528 | &bo, | ||
529 | item->filename); | ||
554 | for (child = item->children_head; child; child = child->next) | 530 | for (child = item->children_head; child; child = child->next) |
555 | { | 531 | { |
556 | fic = get_file_information (child); | 532 | fic = get_file_information (child); |
@@ -559,11 +535,13 @@ get_file_information (struct GNUNET_FS_ShareTreeItem *item) | |||
559 | } | 535 | } |
560 | else | 536 | else |
561 | { | 537 | { |
562 | fi = GNUNET_FS_file_information_create_from_file (ctx, NULL, | 538 | fi = GNUNET_FS_file_information_create_from_file (ctx, |
563 | item->filename, | 539 | NULL, |
564 | item->ksk_uri, item->meta, | 540 | item->filename, |
565 | !do_insert, | 541 | item->ksk_uri, |
566 | &bo); | 542 | item->meta, |
543 | ! do_insert, | ||
544 | &bo); | ||
567 | } | 545 | } |
568 | return fi; | 546 | return fi; |
569 | } | 547 | } |
@@ -585,9 +563,7 @@ directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result) | |||
585 | GNUNET_FS_share_tree_free (directory_scan_result); | 563 | GNUNET_FS_share_tree_free (directory_scan_result); |
586 | if (NULL == fi) | 564 | if (NULL == fi) |
587 | { | 565 | { |
588 | FPRINTF (stderr, | 566 | fprintf (stderr, "%s", _ ("Could not publish\n")); |
589 | "%s", | ||
590 | _("Could not publish\n")); | ||
591 | ret = 1; | 567 | ret = 1; |
592 | GNUNET_SCHEDULER_shutdown (); | 568 | GNUNET_SCHEDULER_shutdown (); |
593 | return; | 569 | return; |
@@ -603,16 +579,17 @@ directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result) | |||
603 | priv = NULL; | 579 | priv = NULL; |
604 | else | 580 | else |
605 | priv = GNUNET_IDENTITY_ego_get_private_key (namespace); | 581 | priv = GNUNET_IDENTITY_ego_get_private_key (namespace); |
606 | pc = GNUNET_FS_publish_start (ctx, fi, | 582 | pc = GNUNET_FS_publish_start (ctx, |
607 | priv, this_id, next_id, | 583 | fi, |
608 | (do_simulate) ? | 584 | priv, |
609 | GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY : | 585 | this_id, |
610 | GNUNET_FS_PUBLISH_OPTION_NONE); | 586 | next_id, |
587 | (do_simulate) | ||
588 | ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY | ||
589 | : GNUNET_FS_PUBLISH_OPTION_NONE); | ||
611 | if (NULL == pc) | 590 | if (NULL == pc) |
612 | { | 591 | { |
613 | FPRINTF (stderr, | 592 | fprintf (stderr, "%s", _ ("Could not start publishing.\n")); |
614 | "%s", | ||
615 | _("Could not start publishing.\n")); | ||
616 | ret = 1; | 593 | ret = 1; |
617 | GNUNET_SCHEDULER_shutdown (); | 594 | GNUNET_SCHEDULER_shutdown (); |
618 | return; | 595 | return; |
@@ -633,9 +610,9 @@ directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result) | |||
633 | */ | 610 | */ |
634 | static void | 611 | static void |
635 | directory_scan_cb (void *cls, | 612 | directory_scan_cb (void *cls, |
636 | const char *filename, | 613 | const char *filename, |
637 | int is_directory, | 614 | int is_directory, |
638 | enum GNUNET_FS_DirScannerProgressUpdateReason reason) | 615 | enum GNUNET_FS_DirScannerProgressUpdateReason reason) |
639 | { | 616 | { |
640 | struct GNUNET_FS_ShareTreeItem *directory_scan_result; | 617 | struct GNUNET_FS_ShareTreeItem *directory_scan_result; |
641 | 618 | ||
@@ -645,46 +622,36 @@ directory_scan_cb (void *cls, | |||
645 | if (verbose > 1) | 622 | if (verbose > 1) |
646 | { | 623 | { |
647 | if (is_directory == GNUNET_YES) | 624 | if (is_directory == GNUNET_YES) |
648 | FPRINTF (stdout, | 625 | fprintf (stdout, _ ("Scanning directory `%s'.\n"), filename); |
649 | _("Scanning directory `%s'.\n"), | ||
650 | filename); | ||
651 | else | 626 | else |
652 | FPRINTF (stdout, | 627 | fprintf (stdout, _ ("Scanning file `%s'.\n"), filename); |
653 | _("Scanning file `%s'.\n"), | ||
654 | filename); | ||
655 | } | 628 | } |
656 | break; | 629 | break; |
657 | case GNUNET_FS_DIRSCANNER_FILE_IGNORED: | 630 | case GNUNET_FS_DIRSCANNER_FILE_IGNORED: |
658 | FPRINTF (stderr, | 631 | fprintf (stderr, |
659 | _("There was trouble processing file `%s', skipping it.\n"), | 632 | _ ("There was trouble processing file `%s', skipping it.\n"), |
660 | filename); | 633 | filename); |
661 | break; | 634 | break; |
662 | case GNUNET_FS_DIRSCANNER_ALL_COUNTED: | 635 | case GNUNET_FS_DIRSCANNER_ALL_COUNTED: |
663 | if (verbose) | 636 | if (verbose) |
664 | FPRINTF (stdout, | 637 | fprintf (stdout, "%s", _ ("Preprocessing complete.\n")); |
665 | "%s", | ||
666 | _("Preprocessing complete.\n")); | ||
667 | break; | 638 | break; |
668 | case GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED: | 639 | case GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED: |
669 | if (verbose > 2) | 640 | if (verbose > 2) |
670 | FPRINTF (stdout, | 641 | fprintf (stdout, |
671 | _("Extracting meta data from file `%s' complete.\n"), | 642 | _ ("Extracting meta data from file `%s' complete.\n"), |
672 | filename); | 643 | filename); |
673 | break; | 644 | break; |
674 | case GNUNET_FS_DIRSCANNER_FINISHED: | 645 | case GNUNET_FS_DIRSCANNER_FINISHED: |
675 | if (verbose > 1) | 646 | if (verbose > 1) |
676 | FPRINTF (stdout, | 647 | fprintf (stdout, "%s", _ ("Meta data extraction has finished.\n")); |
677 | "%s", | ||
678 | _("Meta data extraction has finished.\n")); | ||
679 | directory_scan_result = GNUNET_FS_directory_scan_get_result (ds); | 648 | directory_scan_result = GNUNET_FS_directory_scan_get_result (ds); |
680 | ds = NULL; | 649 | ds = NULL; |
681 | GNUNET_FS_share_tree_trim (directory_scan_result); | 650 | GNUNET_FS_share_tree_trim (directory_scan_result); |
682 | directory_trim_complete (directory_scan_result); | 651 | directory_trim_complete (directory_scan_result); |
683 | break; | 652 | break; |
684 | case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR: | 653 | case GNUNET_FS_DIRSCANNER_INTERNAL_ERROR: |
685 | FPRINTF (stdout, | 654 | fprintf (stdout, "%s", _ ("Error scanning directory.\n")); |
686 | "%s", | ||
687 | _("Error scanning directory.\n")); | ||
688 | ret = 1; | 655 | ret = 1; |
689 | GNUNET_SCHEDULER_shutdown (); | 656 | GNUNET_SCHEDULER_shutdown (); |
690 | break; | 657 | break; |
@@ -708,12 +675,9 @@ identity_continuation (const char *args0) | |||
708 | char *ex; | 675 | char *ex; |
709 | char *emsg; | 676 | char *emsg; |
710 | 677 | ||
711 | if ( (NULL != pseudonym) && | 678 | if ((NULL != pseudonym) && (NULL == namespace)) |
712 | (NULL == namespace) ) | ||
713 | { | 679 | { |
714 | FPRINTF (stderr, | 680 | fprintf (stderr, _ ("Selected pseudonym `%s' unknown\n"), pseudonym); |
715 | _("Selected pseudonym `%s' unknown\n"), | ||
716 | pseudonym); | ||
717 | ret = 1; | 681 | ret = 1; |
718 | GNUNET_SCHEDULER_shutdown (); | 682 | GNUNET_SCHEDULER_shutdown (); |
719 | return; | 683 | return; |
@@ -723,17 +687,16 @@ identity_continuation (const char *args0) | |||
723 | emsg = NULL; | 687 | emsg = NULL; |
724 | if (NULL == (uri = GNUNET_FS_uri_parse (uri_string, &emsg))) | 688 | if (NULL == (uri = GNUNET_FS_uri_parse (uri_string, &emsg))) |
725 | { | 689 | { |
726 | FPRINTF (stderr, | 690 | fprintf (stderr, _ ("Failed to parse URI: %s\n"), emsg); |
727 | _("Failed to parse URI: %s\n"), | ||
728 | emsg); | ||
729 | GNUNET_free (emsg); | 691 | GNUNET_free (emsg); |
730 | ret = 1; | 692 | ret = 1; |
731 | GNUNET_SCHEDULER_shutdown (); | 693 | GNUNET_SCHEDULER_shutdown (); |
732 | return; | 694 | return; |
733 | } | 695 | } |
734 | GNUNET_FS_publish_ksk (ctx, | 696 | GNUNET_FS_publish_ksk (ctx, |
735 | topKeywords, | 697 | topKeywords, |
736 | meta, uri, | 698 | meta, |
699 | uri, | ||
737 | &bo, | 700 | &bo, |
738 | GNUNET_FS_PUBLISH_OPTION_NONE, | 701 | GNUNET_FS_PUBLISH_OPTION_NONE, |
739 | &uri_ksk_continuation, | 702 | &uri_ksk_continuation, |
@@ -743,24 +706,27 @@ identity_continuation (const char *args0) | |||
743 | if (GNUNET_OK != | 706 | if (GNUNET_OK != |
744 | GNUNET_CONFIGURATION_get_value_string (cfg, "FS", "EXTRACTORS", &ex)) | 707 | GNUNET_CONFIGURATION_get_value_string (cfg, "FS", "EXTRACTORS", &ex)) |
745 | ex = NULL; | 708 | ex = NULL; |
746 | if (0 != ACCESS (args0, R_OK)) | 709 | if (0 != access (args0, R_OK)) |
747 | { | 710 | { |
748 | FPRINTF (stderr, | 711 | fprintf (stderr, |
749 | _("Failed to access `%s': %s\n"), | 712 | _ ("Failed to access `%s': %s\n"), |
750 | args0, | 713 | args0, |
751 | STRERROR (errno)); | 714 | strerror (errno)); |
752 | GNUNET_free_non_null (ex); | 715 | GNUNET_free_non_null (ex); |
753 | return; | 716 | return; |
754 | } | 717 | } |
755 | ds = GNUNET_FS_directory_scan_start (args0, | 718 | ds = GNUNET_FS_directory_scan_start (args0, |
756 | disable_extractor, | 719 | disable_extractor, |
757 | ex, | 720 | ex, |
758 | &directory_scan_cb, NULL); | 721 | &directory_scan_cb, |
722 | NULL); | ||
759 | if (NULL == ds) | 723 | if (NULL == ds) |
760 | { | 724 | { |
761 | FPRINTF (stderr, | 725 | fprintf ( |
762 | "%s", | 726 | stderr, |
763 | _("Failed to start meta directory scanner. Is gnunet-helper-publish-fs installed?\n")); | 727 | "%s", |
728 | _ ( | ||
729 | "Failed to start meta directory scanner. Is gnunet-helper-publish-fs installed?\n")); | ||
764 | GNUNET_free_non_null (ex); | 730 | GNUNET_free_non_null (ex); |
765 | return; | 731 | return; |
766 | } | 732 | } |
@@ -781,9 +747,9 @@ identity_continuation (const char *args0) | |||
781 | */ | 747 | */ |
782 | static void | 748 | static void |
783 | identity_cb (void *cls, | 749 | identity_cb (void *cls, |
784 | struct GNUNET_IDENTITY_Ego *ego, | 750 | struct GNUNET_IDENTITY_Ego *ego, |
785 | void **ctx, | 751 | void **ctx, |
786 | const char *name) | 752 | const char *name) |
787 | { | 753 | { |
788 | const char *args0 = cls; | 754 | const char *args0 = cls; |
789 | 755 | ||
@@ -795,7 +761,7 @@ identity_cb (void *cls, | |||
795 | if (NULL == name) | 761 | if (NULL == name) |
796 | return; | 762 | return; |
797 | if (0 == strcmp (name, pseudonym)) | 763 | if (0 == strcmp (name, pseudonym)) |
798 | namespace = ego; | 764 | namespace = ego; |
799 | } | 765 | } |
800 | 766 | ||
801 | 767 | ||
@@ -816,20 +782,20 @@ run (void *cls, | |||
816 | /* check arguments */ | 782 | /* check arguments */ |
817 | if ((NULL != uri_string) && (extract_only)) | 783 | if ((NULL != uri_string) && (extract_only)) |
818 | { | 784 | { |
819 | printf (_("Cannot extract metadata from a URI!\n")); | 785 | printf (_ ("Cannot extract metadata from a URI!\n")); |
820 | ret = -1; | 786 | ret = -1; |
821 | return; | 787 | return; |
822 | } | 788 | } |
823 | if (((NULL == uri_string) || (extract_only)) && | 789 | if (((NULL == uri_string) || (extract_only)) && |
824 | ((NULL == args[0]) || (NULL != args[1]))) | 790 | ((NULL == args[0]) || (NULL != args[1]))) |
825 | { | 791 | { |
826 | printf (_("You must specify one and only one filename for insertion.\n")); | 792 | printf (_ ("You must specify one and only one filename for insertion.\n")); |
827 | ret = -1; | 793 | ret = -1; |
828 | return; | 794 | return; |
829 | } | 795 | } |
830 | if ((NULL != uri_string) && (NULL != args[0])) | 796 | if ((NULL != uri_string) && (NULL != args[0])) |
831 | { | 797 | { |
832 | printf (_("You must NOT specify an URI and a filename.\n")); | 798 | printf (_ ("You must NOT specify an URI and a filename.\n")); |
833 | ret = -1; | 799 | ret = -1; |
834 | return; | 800 | return; |
835 | } | 801 | } |
@@ -837,49 +803,51 @@ run (void *cls, | |||
837 | { | 803 | { |
838 | if (NULL == this_id) | 804 | if (NULL == this_id) |
839 | { | 805 | { |
840 | FPRINTF (stderr, _("Option `%s' is required when using option `%s'.\n"), | 806 | fprintf (stderr, |
841 | "-t", "-P"); | 807 | _ ("Option `%s' is required when using option `%s'.\n"), |
808 | "-t", | ||
809 | "-P"); | ||
842 | ret = -1; | 810 | ret = -1; |
843 | return; | 811 | return; |
844 | } | 812 | } |
845 | } | 813 | } |
846 | else | 814 | else |
847 | { /* ordinary insertion checks */ | 815 | { /* ordinary insertion checks */ |
848 | if (NULL != next_id) | 816 | if (NULL != next_id) |
849 | { | 817 | { |
850 | FPRINTF (stderr, | 818 | fprintf (stderr, |
851 | _("Option `%s' makes no sense without option `%s'.\n"), | 819 | _ ("Option `%s' makes no sense without option `%s'.\n"), |
852 | "-N", "-P"); | 820 | "-N", |
821 | "-P"); | ||
853 | ret = -1; | 822 | ret = -1; |
854 | return; | 823 | return; |
855 | } | 824 | } |
856 | if (NULL != this_id) | 825 | if (NULL != this_id) |
857 | { | 826 | { |
858 | FPRINTF (stderr, | 827 | fprintf (stderr, |
859 | _("Option `%s' makes no sense without option `%s'.\n"), | 828 | _ ("Option `%s' makes no sense without option `%s'.\n"), |
860 | "-t", "-P"); | 829 | "-t", |
830 | "-P"); | ||
861 | ret = -1; | 831 | ret = -1; |
862 | return; | 832 | return; |
863 | } | 833 | } |
864 | } | 834 | } |
865 | cfg = c; | 835 | cfg = c; |
866 | ctx = | 836 | ctx = GNUNET_FS_start (cfg, |
867 | GNUNET_FS_start (cfg, "gnunet-publish", &progress_cb, NULL, | 837 | "gnunet-publish", |
868 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 838 | &progress_cb, |
839 | NULL, | ||
840 | GNUNET_FS_FLAGS_NONE, | ||
841 | GNUNET_FS_OPTIONS_END); | ||
869 | if (NULL == ctx) | 842 | if (NULL == ctx) |
870 | { | 843 | { |
871 | FPRINTF (stderr, | 844 | fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS"); |
872 | _("Could not initialize `%s' subsystem.\n"), | ||
873 | "FS"); | ||
874 | ret = 1; | 845 | ret = 1; |
875 | return; | 846 | return; |
876 | } | 847 | } |
877 | GNUNET_SCHEDULER_add_shutdown (&do_stop_task, | 848 | GNUNET_SCHEDULER_add_shutdown (&do_stop_task, NULL); |
878 | NULL); | ||
879 | if (NULL != pseudonym) | 849 | if (NULL != pseudonym) |
880 | identity = GNUNET_IDENTITY_connect (cfg, | 850 | identity = GNUNET_IDENTITY_connect (cfg, &identity_cb, args[0]); |
881 | &identity_cb, | ||
882 | args[0]); | ||
883 | else | 851 | else |
884 | identity_continuation (args[0]); | 852 | identity_continuation (args[0]); |
885 | } | 853 | } |
@@ -893,104 +861,120 @@ run (void *cls, | |||
893 | * @return 0 ok, 1 on error | 861 | * @return 0 ok, 1 on error |
894 | */ | 862 | */ |
895 | int | 863 | int |
896 | main (int argc, | 864 | main (int argc, char *const *argv) |
897 | char *const *argv) | ||
898 | { | 865 | { |
899 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 866 | struct GNUNET_GETOPT_CommandLineOption options[] = |
900 | GNUNET_GETOPT_option_uint ('a', | 867 | {GNUNET_GETOPT_option_uint ('a', |
901 | "anonymity", | 868 | "anonymity", |
902 | "LEVEL", | 869 | "LEVEL", |
903 | gettext_noop ("set the desired LEVEL of sender-anonymity"), | 870 | gettext_noop ( |
904 | &bo.anonymity_level), | 871 | "set the desired LEVEL of sender-anonymity"), |
905 | GNUNET_GETOPT_option_flag ('D', | 872 | &bo.anonymity_level), |
906 | "disable-extractor", | 873 | GNUNET_GETOPT_option_flag ( |
907 | gettext_noop ("do not use libextractor to add keywords or metadata"), | 874 | 'D', |
908 | &disable_extractor), | 875 | "disable-extractor", |
909 | GNUNET_GETOPT_option_flag ('E', | 876 | gettext_noop ("do not use libextractor to add keywords or metadata"), |
910 | "enable-creation-time", | 877 | &disable_extractor), |
911 | gettext_noop ("enable adding the creation time to the " | 878 | GNUNET_GETOPT_option_flag ('E', |
912 | "metadata of the uploaded file"), | 879 | "enable-creation-time", |
913 | &enable_creation_time), | 880 | gettext_noop ( |
914 | GNUNET_GETOPT_option_flag ('e', | 881 | "enable adding the creation time to the " |
915 | "extract", | 882 | "metadata of the uploaded file"), |
916 | gettext_noop ("print list of extracted keywords that would " | 883 | &enable_creation_time), |
917 | "be used, but do not perform upload"), | 884 | GNUNET_GETOPT_option_flag ('e', |
918 | &extract_only), | 885 | "extract", |
919 | GNUNET_FS_GETOPT_KEYWORDS ('k', | 886 | gettext_noop ( |
920 | "key", | 887 | "print list of extracted keywords that would " |
921 | "KEYWORD", | 888 | "be used, but do not perform upload"), |
922 | gettext_noop ("add an additional keyword for the top-level " | 889 | &extract_only), |
923 | "file or directory (this option can be specified multiple times)"), | 890 | GNUNET_FS_GETOPT_KEYWORDS ( |
924 | &topKeywords), | 891 | 'k', |
925 | GNUNET_FS_GETOPT_METADATA ('m', | 892 | "key", |
926 | "meta", | 893 | "KEYWORD", |
927 | "TYPE:VALUE", | 894 | gettext_noop ( |
928 | gettext_noop ("set the meta-data for the given TYPE to the given VALUE"), | 895 | "add an additional keyword for the top-level " |
929 | &meta), | 896 | "file or directory (this option can be specified multiple times)"), |
930 | GNUNET_GETOPT_option_flag ('n', | 897 | &topKeywords), |
931 | "noindex", | 898 | GNUNET_FS_GETOPT_METADATA ( |
932 | gettext_noop ("do not index, perform full insertion (stores " | 899 | 'm', |
933 | "entire file in encrypted form in GNUnet database)"), | 900 | "meta", |
934 | &do_insert), | 901 | "TYPE:VALUE", |
935 | GNUNET_GETOPT_option_string ('N', | 902 | gettext_noop ("set the meta-data for the given TYPE to the given VALUE"), |
936 | "next", | 903 | &meta), |
937 | "ID", | 904 | GNUNET_GETOPT_option_flag ( |
938 | gettext_noop ("specify ID of an updated version to be " | 905 | 'n', |
939 | "published in the future (for namespace insertions only)"), | 906 | "noindex", |
940 | &next_id), | 907 | gettext_noop ("do not index, perform full insertion (stores " |
941 | GNUNET_GETOPT_option_uint ('p', | 908 | "entire file in encrypted form in GNUnet database)"), |
942 | "priority", | 909 | &do_insert), |
943 | "PRIORITY", | 910 | GNUNET_GETOPT_option_string ( |
944 | gettext_noop ("specify the priority of the content"), | 911 | 'N', |
945 | &bo.content_priority), | 912 | "next", |
946 | GNUNET_GETOPT_option_string ('P', | 913 | "ID", |
947 | "pseudonym", | 914 | gettext_noop ("specify ID of an updated version to be " |
948 | "NAME", | 915 | "published in the future (for namespace insertions only)"), |
949 | gettext_noop ("publish the files under the pseudonym " | 916 | &next_id), |
950 | "NAME (place file into namespace)"), | 917 | GNUNET_GETOPT_option_uint ('p', |
951 | &pseudonym), | 918 | "priority", |
952 | GNUNET_GETOPT_option_uint ('r', | 919 | "PRIORITY", |
953 | "replication", | 920 | gettext_noop ( |
954 | "LEVEL", | 921 | "specify the priority of the content"), |
955 | gettext_noop ("set the desired replication LEVEL"), | 922 | &bo.content_priority), |
956 | &bo.replication_level), | 923 | GNUNET_GETOPT_option_string ('P', |
957 | GNUNET_GETOPT_option_flag ('s', | 924 | "pseudonym", |
958 | "simulate-only", | 925 | "NAME", |
959 | gettext_noop ("only simulate the process but do not do " | 926 | gettext_noop ( |
960 | "any actual publishing (useful to compute URIs)"), | 927 | "publish the files under the pseudonym " |
961 | &do_simulate), | 928 | "NAME (place file into namespace)"), |
962 | GNUNET_GETOPT_option_string ('t', | 929 | &pseudonym), |
963 | "this", | 930 | GNUNET_GETOPT_option_uint ('r', |
964 | "ID", | 931 | "replication", |
965 | gettext_noop ("set the ID of this version of the publication " | 932 | "LEVEL", |
966 | "(for namespace insertions only)"), | 933 | gettext_noop ( |
967 | &this_id), | 934 | "set the desired replication LEVEL"), |
968 | GNUNET_GETOPT_option_string ('u', | 935 | &bo.replication_level), |
969 | "uri", | 936 | GNUNET_GETOPT_option_flag ('s', |
970 | "URI", | 937 | "simulate-only", |
971 | gettext_noop ("URI to be published (can be used instead of passing a " | 938 | gettext_noop ( |
972 | "file to add keywords to the file with the respective URI)"), | 939 | "only simulate the process but do not do " |
973 | &uri_string), | 940 | "any actual publishing (useful to compute URIs)"), |
974 | 941 | &do_simulate), | |
975 | GNUNET_GETOPT_option_verbose (&verbose), | 942 | GNUNET_GETOPT_option_string ('t', |
976 | 943 | "this", | |
977 | GNUNET_GETOPT_OPTION_END | 944 | "ID", |
978 | }; | 945 | gettext_noop ( |
946 | "set the ID of this version of the publication " | ||
947 | "(for namespace insertions only)"), | ||
948 | &this_id), | ||
949 | GNUNET_GETOPT_option_string ( | ||
950 | 'u', | ||
951 | "uri", | ||
952 | "URI", | ||
953 | gettext_noop ( | ||
954 | "URI to be published (can be used instead of passing a " | ||
955 | "file to add keywords to the file with the respective URI)"), | ||
956 | &uri_string), | ||
957 | |||
958 | GNUNET_GETOPT_option_verbose (&verbose), | ||
959 | |||
960 | GNUNET_GETOPT_OPTION_END}; | ||
979 | bo.expiration_time = | 961 | bo.expiration_time = |
980 | GNUNET_TIME_year_to_time (GNUNET_TIME_get_current_year () + 2); | 962 | GNUNET_TIME_year_to_time (GNUNET_TIME_get_current_year () + 2); |
981 | 963 | ||
982 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 964 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
983 | return 2; | 965 | return 2; |
984 | ret = (GNUNET_OK == | 966 | ret = |
985 | GNUNET_PROGRAM_run (argc, | 967 | (GNUNET_OK == |
986 | argv, | 968 | GNUNET_PROGRAM_run (argc, |
987 | "gnunet-publish [OPTIONS] FILENAME", | 969 | argv, |
988 | gettext_noop | 970 | "gnunet-publish [OPTIONS] FILENAME", |
989 | ("Publish a file or directory on GNUnet"), | 971 | gettext_noop ("Publish a file or directory on GNUnet"), |
990 | options, | 972 | options, |
991 | &run, | 973 | &run, |
992 | NULL)) ? ret : 1; | 974 | NULL)) |
993 | GNUNET_free ((void*) argv); | 975 | ? ret |
976 | : 1; | ||
977 | GNUNET_free ((void *) argv); | ||
994 | return ret; | 978 | return ret; |
995 | } | 979 | } |
996 | 980 | ||
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, | |||
92 | #if HAVE_LIBEXTRACTOR | 92 | #if HAVE_LIBEXTRACTOR |
93 | printf ("\t%20s: %s\n", | 93 | printf ("\t%20s: %s\n", |
94 | dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, | 94 | dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, |
95 | EXTRACTOR_metatype_to_string (type)), data); | 95 | EXTRACTOR_metatype_to_string (type)), |
96 | #else | ||
97 | printf ("\t%20d: %s\n", | ||
98 | type, | ||
99 | data); | 96 | data); |
97 | #else | ||
98 | printf ("\t%20d: %s\n", type, data); | ||
100 | #endif | 99 | #endif |
101 | return 0; | 100 | return 0; |
102 | } | 101 | } |
@@ -118,13 +117,14 @@ clean_task (void *cls) | |||
118 | GNUNET_free (output_filename); | 117 | GNUNET_free (output_filename); |
119 | return; | 118 | return; |
120 | } | 119 | } |
121 | if (dsize != | 120 | if (dsize != GNUNET_DISK_fn_write (output_filename, |
122 | GNUNET_DISK_fn_write (output_filename, ddata, dsize, | 121 | ddata, |
123 | GNUNET_DISK_PERM_USER_READ | | 122 | dsize, |
124 | GNUNET_DISK_PERM_USER_WRITE)) | 123 | GNUNET_DISK_PERM_USER_READ | |
124 | GNUNET_DISK_PERM_USER_WRITE)) | ||
125 | { | 125 | { |
126 | FPRINTF (stderr, | 126 | fprintf (stderr, |
127 | _("Failed to write directory with search results to `%s'\n"), | 127 | _ ("Failed to write directory with search results to `%s'\n"), |
128 | output_filename); | 128 | output_filename); |
129 | } | 129 | } |
130 | GNUNET_free_non_null (ddata); | 130 | GNUNET_free_non_null (ddata); |
@@ -165,31 +165,35 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) | |||
165 | NULL); | 165 | NULL); |
166 | uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri); | 166 | uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri); |
167 | printf ("#%u:\n", ++cnt); | 167 | printf ("#%u:\n", ++cnt); |
168 | filename = | 168 | filename = GNUNET_CONTAINER_meta_data_get_by_type ( |
169 | GNUNET_CONTAINER_meta_data_get_by_type (info->value.search. | 169 | info->value.search.specifics.result.meta, |
170 | specifics.result.meta, | 170 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); |
171 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); | 171 | is_directory = GNUNET_FS_meta_data_test_for_directory ( |
172 | is_directory = | 172 | info->value.search.specifics.result.meta); |
173 | GNUNET_FS_meta_data_test_for_directory (info->value.search. | ||
174 | specifics.result.meta); | ||
175 | if (NULL != filename) | 173 | if (NULL != filename) |
176 | { | 174 | { |
177 | while ( (filename[0] != '\0') && | 175 | while ((filename[0] != '\0') && ('/' == filename[strlen (filename) - 1])) |
178 | ('/' == filename[strlen(filename)-1]) ) | 176 | filename[strlen (filename) - 1] = '\0'; |
179 | filename[strlen(filename)-1] = '\0'; | ||
180 | GNUNET_DISK_filename_canonicalize (filename); | 177 | GNUNET_DISK_filename_canonicalize (filename); |
181 | if (GNUNET_YES == is_directory) | 178 | if (GNUNET_YES == is_directory) |
182 | printf ("gnunet-download -o \"%s%s\" -R %s\n", filename, GNUNET_FS_DIRECTORY_EXT, uri); | 179 | printf ("gnunet-download -o \"%s%s\" -R %s\n", |
180 | filename, | ||
181 | GNUNET_FS_DIRECTORY_EXT, | ||
182 | uri); | ||
183 | else | 183 | else |
184 | printf ("gnunet-download -o \"%s\" %s\n", filename, uri); | 184 | printf ("gnunet-download -o \"%s\" %s\n", filename, uri); |
185 | } | 185 | } |
186 | else if (GNUNET_YES == is_directory) | 186 | else if (GNUNET_YES == is_directory) |
187 | printf ("gnunet-download -o \"collection%s\" -R %s\n", GNUNET_FS_DIRECTORY_EXT, uri); | 187 | printf ("gnunet-download -o \"collection%s\" -R %s\n", |
188 | GNUNET_FS_DIRECTORY_EXT, | ||
189 | uri); | ||
188 | else | 190 | else |
189 | printf ("gnunet-download %s\n", uri); | 191 | printf ("gnunet-download %s\n", uri); |
190 | if (verbose) | 192 | if (verbose) |
191 | GNUNET_CONTAINER_meta_data_iterate (info->value.search.specifics. | 193 | GNUNET_CONTAINER_meta_data_iterate (info->value.search.specifics.result |
192 | result.meta, &item_printer, NULL); | 194 | .meta, |
195 | &item_printer, | ||
196 | NULL); | ||
193 | printf ("\n"); | 197 | printf ("\n"); |
194 | fflush (stdout); | 198 | fflush (stdout); |
195 | GNUNET_free_non_null (filename); | 199 | GNUNET_free_non_null (filename); |
@@ -204,7 +208,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) | |||
204 | /* ignore */ | 208 | /* ignore */ |
205 | break; | 209 | break; |
206 | case GNUNET_FS_STATUS_SEARCH_ERROR: | 210 | case GNUNET_FS_STATUS_SEARCH_ERROR: |
207 | FPRINTF (stderr, _("Error searching: %s.\n"), | 211 | fprintf (stderr, |
212 | _ ("Error searching: %s.\n"), | ||
208 | info->value.search.specifics.error.message); | 213 | info->value.search.specifics.error.message); |
209 | GNUNET_SCHEDULER_shutdown (); | 214 | GNUNET_SCHEDULER_shutdown (); |
210 | break; | 215 | break; |
@@ -212,7 +217,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) | |||
212 | GNUNET_SCHEDULER_add_now (&clean_task, NULL); | 217 | GNUNET_SCHEDULER_add_now (&clean_task, NULL); |
213 | break; | 218 | break; |
214 | default: | 219 | default: |
215 | FPRINTF (stderr, _("Unexpected status: %d\n"), info->status); | 220 | fprintf (stderr, _ ("Unexpected status: %d\n"), info->status); |
216 | break; | 221 | break; |
217 | } | 222 | } |
218 | return NULL; | 223 | return NULL; |
@@ -247,7 +252,9 @@ timeout_task (void *cls) | |||
247 | * @param c configuration | 252 | * @param c configuration |
248 | */ | 253 | */ |
249 | static void | 254 | static void |
250 | run (void *cls, char *const *args, const char *cfgfile, | 255 | run (void *cls, |
256 | char *const *args, | ||
257 | const char *cfgfile, | ||
251 | const struct GNUNET_CONFIGURATION_Handle *c) | 258 | const struct GNUNET_CONFIGURATION_Handle *c) |
252 | { | 259 | { |
253 | struct GNUNET_FS_Uri *uri; | 260 | struct GNUNET_FS_Uri *uri; |
@@ -260,17 +267,22 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
260 | uri = GNUNET_FS_uri_ksk_create_from_args (argc, (const char **) args); | 267 | uri = GNUNET_FS_uri_ksk_create_from_args (argc, (const char **) args); |
261 | if (NULL == uri) | 268 | if (NULL == uri) |
262 | { | 269 | { |
263 | FPRINTF (stderr, "%s", _("Could not create keyword URI from arguments.\n")); | 270 | fprintf (stderr, |
271 | "%s", | ||
272 | _ ("Could not create keyword URI from arguments.\n")); | ||
264 | ret = 1; | 273 | ret = 1; |
265 | return; | 274 | return; |
266 | } | 275 | } |
267 | cfg = c; | 276 | cfg = c; |
268 | ctx = | 277 | ctx = GNUNET_FS_start (cfg, |
269 | GNUNET_FS_start (cfg, "gnunet-search", &progress_cb, NULL, | 278 | "gnunet-search", |
270 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 279 | &progress_cb, |
280 | NULL, | ||
281 | GNUNET_FS_FLAGS_NONE, | ||
282 | GNUNET_FS_OPTIONS_END); | ||
271 | if (NULL == ctx) | 283 | if (NULL == ctx) |
272 | { | 284 | { |
273 | FPRINTF (stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); | 285 | fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS"); |
274 | GNUNET_FS_uri_destroy (uri); | 286 | GNUNET_FS_uri_destroy (uri); |
275 | ret = 1; | 287 | ret = 1; |
276 | return; | 288 | return; |
@@ -284,17 +296,14 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
284 | GNUNET_FS_uri_destroy (uri); | 296 | GNUNET_FS_uri_destroy (uri); |
285 | if (NULL == sc) | 297 | if (NULL == sc) |
286 | { | 298 | { |
287 | FPRINTF (stderr, "%s", _("Could not start searching.\n")); | 299 | fprintf (stderr, "%s", _ ("Could not start searching.\n")); |
288 | GNUNET_FS_stop (ctx); | 300 | GNUNET_FS_stop (ctx); |
289 | ret = 1; | 301 | ret = 1; |
290 | return; | 302 | return; |
291 | } | 303 | } |
292 | if (0 != timeout.rel_value_us) | 304 | if (0 != timeout.rel_value_us) |
293 | tt = GNUNET_SCHEDULER_add_delayed (timeout, | 305 | tt = GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, NULL); |
294 | &timeout_task, | 306 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
295 | NULL); | ||
296 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
297 | NULL); | ||
298 | } | 307 | } |
299 | 308 | ||
300 | 309 | ||
@@ -308,49 +317,55 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
308 | int | 317 | int |
309 | main (int argc, char *const *argv) | 318 | main (int argc, char *const *argv) |
310 | { | 319 | { |
311 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 320 | struct GNUNET_GETOPT_CommandLineOption options[] = |
312 | GNUNET_GETOPT_option_uint ('a', | 321 | {GNUNET_GETOPT_option_uint ('a', |
313 | "anonymity", | 322 | "anonymity", |
314 | "LEVEL", | 323 | "LEVEL", |
315 | gettext_noop ("set the desired LEVEL of receiver-anonymity"), | 324 | gettext_noop ( |
316 | &anonymity), | 325 | "set the desired LEVEL of receiver-anonymity"), |
317 | GNUNET_GETOPT_option_flag ('n', | 326 | &anonymity), |
318 | "no-network", | 327 | GNUNET_GETOPT_option_flag ( |
319 | gettext_noop ("only search the local peer (no P2P network search)"), | 328 | 'n', |
320 | &local_only), | 329 | "no-network", |
321 | GNUNET_GETOPT_option_string ('o', | 330 | gettext_noop ("only search the local peer (no P2P network search)"), |
322 | "output", | 331 | &local_only), |
323 | "PREFIX", | 332 | GNUNET_GETOPT_option_string ( |
324 | gettext_noop ("write search results to file starting with PREFIX"), | 333 | 'o', |
325 | &output_filename), | 334 | "output", |
326 | GNUNET_GETOPT_option_relative_time ('t', | 335 | "PREFIX", |
327 | "timeout", | 336 | gettext_noop ("write search results to file starting with PREFIX"), |
328 | "DELAY", | 337 | &output_filename), |
329 | gettext_noop ("automatically terminate search after DELAY"), | 338 | GNUNET_GETOPT_option_relative_time ( |
330 | &timeout), | 339 | 't', |
331 | GNUNET_GETOPT_option_verbose (&verbose), | 340 | "timeout", |
332 | GNUNET_GETOPT_option_uint ('N', | 341 | "DELAY", |
333 | "results", | 342 | gettext_noop ("automatically terminate search after DELAY"), |
334 | "VALUE", | 343 | &timeout), |
335 | gettext_noop ("automatically terminate search " | 344 | GNUNET_GETOPT_option_verbose (&verbose), |
336 | "after VALUE results are found"), | 345 | GNUNET_GETOPT_option_uint ('N', |
337 | &results_limit), | 346 | "results", |
338 | GNUNET_GETOPT_OPTION_END | 347 | "VALUE", |
339 | }; | 348 | gettext_noop ("automatically terminate search " |
340 | 349 | "after VALUE results are found"), | |
341 | if (GNUNET_OK != | 350 | &results_limit), |
342 | GNUNET_STRINGS_get_utf8_args (argc, argv, | 351 | GNUNET_GETOPT_OPTION_END}; |
343 | &argc, &argv)) | 352 | |
353 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | ||
344 | return 2; | 354 | return 2; |
345 | 355 | ||
346 | ret = (GNUNET_OK == | 356 | ret = |
347 | GNUNET_PROGRAM_run (argc, | 357 | (GNUNET_OK == |
348 | argv, | 358 | GNUNET_PROGRAM_run (argc, |
349 | "gnunet-search [OPTIONS] KEYWORD", | 359 | argv, |
350 | gettext_noop | 360 | "gnunet-search [OPTIONS] KEYWORD", |
351 | ("Search GNUnet for files that were published on GNUnet"), | 361 | gettext_noop ( |
352 | options, &run, NULL)) ? ret : 1; | 362 | "Search GNUnet for files that were published on GNUnet"), |
353 | GNUNET_free ((void*) argv); | 363 | options, |
364 | &run, | ||
365 | NULL)) | ||
366 | ? ret | ||
367 | : 1; | ||
368 | GNUNET_free ((void *) argv); | ||
354 | return ret; | 369 | return ret; |
355 | } | 370 | } |
356 | 371 | ||
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 | |||
73 | * Hash of the contents of the file. | 73 | * Hash of the contents of the file. |
74 | */ | 74 | */ |
75 | struct GNUNET_HashCode file_id; | 75 | struct GNUNET_HashCode file_id; |
76 | |||
77 | }; | 76 | }; |
78 | 77 | ||
79 | 78 | ||
@@ -118,12 +117,10 @@ write_index_list () | |||
118 | struct IndexInfo *pos; | 117 | struct IndexInfo *pos; |
119 | 118 | ||
120 | if (GNUNET_OK != | 119 | if (GNUNET_OK != |
121 | GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", | 120 | GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn)) |
122 | "INDEXDB", | ||
123 | &fn)) | ||
124 | { | 121 | { |
125 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 122 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
126 | "fs", | 123 | "fs", |
127 | "INDEXDB"); | 124 | "INDEXDB"); |
128 | return; | 125 | return; |
129 | } | 126 | } |
@@ -131,24 +128,21 @@ write_index_list () | |||
131 | if (NULL == wh) | 128 | if (NULL == wh) |
132 | { | 129 | { |
133 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 130 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
134 | _("Could not open `%s'.\n"), | 131 | _ ("Could not open `%s'.\n"), |
135 | fn); | 132 | fn); |
136 | GNUNET_free (fn); | 133 | GNUNET_free (fn); |
137 | return; | 134 | return; |
138 | } | 135 | } |
139 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) | 136 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) |
140 | if ((GNUNET_OK != | 137 | if ((GNUNET_OK != GNUNET_BIO_write (wh, |
141 | GNUNET_BIO_write (wh, | 138 | &pos->file_id, |
142 | &pos->file_id, | 139 | sizeof (struct GNUNET_HashCode))) || |
143 | sizeof (struct GNUNET_HashCode))) || | 140 | (GNUNET_OK != GNUNET_BIO_write_string (wh, pos->filename))) |
144 | (GNUNET_OK != | ||
145 | GNUNET_BIO_write_string (wh, | ||
146 | pos->filename))) | ||
147 | break; | 141 | break; |
148 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 142 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) |
149 | { | 143 | { |
150 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 144 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
151 | _("Error writing `%s'.\n"), | 145 | _ ("Error writing `%s'.\n"), |
152 | fn); | 146 | fn); |
153 | GNUNET_free (fn); | 147 | GNUNET_free (fn); |
154 | return; | 148 | return; |
@@ -172,13 +166,10 @@ read_index_list () | |||
172 | char *emsg; | 166 | char *emsg; |
173 | 167 | ||
174 | if (GNUNET_OK != | 168 | if (GNUNET_OK != |
175 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 169 | GNUNET_CONFIGURATION_get_value_filename (cfg, "FS", "INDEXDB", &fn)) |
176 | "FS", | ||
177 | "INDEXDB", | ||
178 | &fn)) | ||
179 | { | 170 | { |
180 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 171 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
181 | "fs", | 172 | "fs", |
182 | "INDEXDB"); | 173 | "INDEXDB"); |
183 | return; | 174 | return; |
184 | } | 175 | } |
@@ -192,39 +183,36 @@ read_index_list () | |||
192 | if (NULL == rh) | 183 | if (NULL == rh) |
193 | { | 184 | { |
194 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 185 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
195 | _("Could not open `%s'.\n"), | 186 | _ ("Could not open `%s'.\n"), |
196 | fn); | 187 | fn); |
197 | GNUNET_free (fn); | 188 | GNUNET_free (fn); |
198 | return; | 189 | return; |
199 | } | 190 | } |
200 | while ( (GNUNET_OK == | 191 | while ( |
201 | GNUNET_BIO_read (rh, | 192 | (GNUNET_OK == GNUNET_BIO_read (rh, |
202 | "Hash of indexed file", | 193 | "Hash of indexed file", |
203 | &hc, | 194 | &hc, |
204 | sizeof (struct GNUNET_HashCode))) && | 195 | sizeof (struct GNUNET_HashCode))) && |
205 | (GNUNET_OK == | 196 | (GNUNET_OK == |
206 | GNUNET_BIO_read_string (rh, | 197 | GNUNET_BIO_read_string (rh, "Name of indexed file", &fname, 1024 * 16)) && |
207 | "Name of indexed file", | 198 | (fname != NULL)) |
208 | &fname, | ||
209 | 1024 * 16)) && | ||
210 | (fname != NULL) ) | ||
211 | { | 199 | { |
212 | slen = strlen (fname) + 1; | 200 | slen = strlen (fname) + 1; |
213 | pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen); | 201 | pos = GNUNET_malloc (sizeof (struct IndexInfo) + slen); |
214 | pos->file_id = hc; | 202 | pos->file_id = hc; |
215 | pos->filename = (const char *) &pos[1]; | 203 | pos->filename = (const char *) &pos[1]; |
216 | GNUNET_memcpy (&pos[1], fname, slen); | 204 | GNUNET_memcpy (&pos[1], fname, slen); |
217 | if (GNUNET_SYSERR == | 205 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put ( |
218 | GNUNET_CONTAINER_multihashmap_put (ifm, &pos->file_id, pos, | 206 | ifm, |
219 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | 207 | &pos->file_id, |
208 | pos, | ||
209 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
220 | { | 210 | { |
221 | GNUNET_free (pos); | 211 | GNUNET_free (pos); |
222 | } | 212 | } |
223 | else | 213 | else |
224 | { | 214 | { |
225 | GNUNET_CONTAINER_DLL_insert (indexed_files_head, | 215 | GNUNET_CONTAINER_DLL_insert (indexed_files_head, indexed_files_tail, pos); |
226 | indexed_files_tail, | ||
227 | pos); | ||
228 | } | 216 | } |
229 | GNUNET_free (fname); | 217 | GNUNET_free (fname); |
230 | } | 218 | } |
@@ -244,13 +232,15 @@ read_index_list () | |||
244 | * @param msg error message | 232 | * @param msg error message |
245 | */ | 233 | */ |
246 | static void | 234 | static void |
247 | remove_cont (void *cls, int success, | 235 | remove_cont (void *cls, |
248 | struct GNUNET_TIME_Absolute min_expiration, | 236 | int success, |
249 | const char *msg) | 237 | struct GNUNET_TIME_Absolute min_expiration, |
238 | const char *msg) | ||
250 | { | 239 | { |
251 | if (GNUNET_OK != success) | 240 | if (GNUNET_OK != success) |
252 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 241 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
253 | _("Failed to delete bogus block: %s\n"), msg); | 242 | _ ("Failed to delete bogus block: %s\n"), |
243 | msg); | ||
254 | } | 244 | } |
255 | 245 | ||
256 | 246 | ||
@@ -275,7 +265,7 @@ remove_cont (void *cls, int success, | |||
275 | * @return GNUNET_OK on success | 265 | * @return GNUNET_OK on success |
276 | */ | 266 | */ |
277 | int | 267 | int |
278 | GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode * key, | 268 | GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode *key, |
279 | uint32_t size, | 269 | uint32_t size, |
280 | const void *data, | 270 | const void *data, |
281 | enum GNUNET_BLOCK_Type type, | 271 | enum GNUNET_BLOCK_Type type, |
@@ -303,19 +293,12 @@ GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode * key, | |||
303 | if (size != sizeof (struct OnDemandBlock)) | 293 | if (size != sizeof (struct OnDemandBlock)) |
304 | { | 294 | { |
305 | GNUNET_break (0); | 295 | GNUNET_break (0); |
306 | GNUNET_DATASTORE_remove (dsh, | 296 | GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); |
307 | key, | ||
308 | size, | ||
309 | data, | ||
310 | -1, | ||
311 | -1, | ||
312 | &remove_cont, NULL); | ||
313 | return GNUNET_SYSERR; | 297 | return GNUNET_SYSERR; |
314 | } | 298 | } |
315 | odb = (const struct OnDemandBlock *) data; | 299 | odb = (const struct OnDemandBlock *) data; |
316 | off = GNUNET_ntohll (odb->offset); | 300 | off = GNUNET_ntohll (odb->offset); |
317 | ii = GNUNET_CONTAINER_multihashmap_get (ifm, | 301 | ii = GNUNET_CONTAINER_multihashmap_get (ifm, &odb->file_id); |
318 | &odb->file_id); | ||
319 | if (NULL == ii) | 302 | if (NULL == ii) |
320 | { | 303 | { |
321 | GNUNET_break (0); | 304 | GNUNET_break (0); |
@@ -325,83 +308,46 @@ GNUNET_FS_handle_on_demand_block (const struct GNUNET_HashCode * key, | |||
325 | return GNUNET_SYSERR; | 308 | return GNUNET_SYSERR; |
326 | } | 309 | } |
327 | fn = ii->filename; | 310 | fn = ii->filename; |
328 | if ((NULL == fn) || (0 != ACCESS (fn, R_OK))) | 311 | if ((NULL == fn) || (0 != access (fn, R_OK))) |
329 | { | 312 | { |
330 | GNUNET_STATISTICS_update (GSF_stats, | 313 | GNUNET_STATISTICS_update ( |
331 | gettext_noop ("# index blocks removed: original file inaccessible"), | 314 | GSF_stats, |
332 | 1, | 315 | gettext_noop ("# index blocks removed: original file inaccessible"), |
333 | GNUNET_YES); | 316 | 1, |
334 | GNUNET_DATASTORE_remove (dsh, | 317 | GNUNET_YES); |
335 | key, | 318 | GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); |
336 | size, | ||
337 | data, | ||
338 | -1, | ||
339 | -1, | ||
340 | &remove_cont, | ||
341 | NULL); | ||
342 | return GNUNET_SYSERR; | 319 | return GNUNET_SYSERR; |
343 | } | 320 | } |
344 | if ( (NULL == | 321 | if ((NULL == (fh = GNUNET_DISK_file_open (fn, |
345 | (fh = | 322 | GNUNET_DISK_OPEN_READ, |
346 | GNUNET_DISK_file_open (fn, | 323 | GNUNET_DISK_PERM_NONE))) || |
347 | GNUNET_DISK_OPEN_READ, | 324 | (off != GNUNET_DISK_file_seek (fh, off, GNUNET_DISK_SEEK_SET)) || |
348 | GNUNET_DISK_PERM_NONE))) || | 325 | (-1 == (nsize = GNUNET_DISK_file_read (fh, ndata, sizeof (ndata))))) |
349 | (off != GNUNET_DISK_file_seek (fh, | ||
350 | off, | ||
351 | GNUNET_DISK_SEEK_SET)) || | ||
352 | (-1 == (nsize = GNUNET_DISK_file_read (fh, | ||
353 | ndata, | ||
354 | sizeof (ndata)))) ) | ||
355 | { | 326 | { |
356 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 327 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
357 | _("Could not access indexed file `%s' (%s) at offset %llu: %s\n"), | 328 | _ ( |
329 | "Could not access indexed file `%s' (%s) at offset %llu: %s\n"), | ||
358 | GNUNET_h2s (&odb->file_id), | 330 | GNUNET_h2s (&odb->file_id), |
359 | fn, | 331 | fn, |
360 | (unsigned long long) off, | 332 | (unsigned long long) off, |
361 | (fn == NULL) ? _("not indexed") : STRERROR (errno)); | 333 | (fn == NULL) ? _ ("not indexed") : strerror (errno)); |
362 | if (fh != NULL) | 334 | if (fh != NULL) |
363 | GNUNET_DISK_file_close (fh); | 335 | GNUNET_DISK_file_close (fh); |
364 | GNUNET_DATASTORE_remove (dsh, | 336 | GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); |
365 | key, | ||
366 | size, | ||
367 | data, | ||
368 | -1, | ||
369 | -1, | ||
370 | &remove_cont, | ||
371 | NULL); | ||
372 | return GNUNET_SYSERR; | 337 | return GNUNET_SYSERR; |
373 | } | 338 | } |
374 | GNUNET_DISK_file_close (fh); | 339 | GNUNET_DISK_file_close (fh); |
375 | GNUNET_CRYPTO_hash (ndata, | 340 | GNUNET_CRYPTO_hash (ndata, nsize, &nkey); |
376 | nsize, | 341 | GNUNET_CRYPTO_hash_to_aes_key (&nkey, &skey, &iv); |
377 | &nkey); | 342 | GNUNET_CRYPTO_symmetric_encrypt (ndata, nsize, &skey, &iv, edata); |
378 | GNUNET_CRYPTO_hash_to_aes_key (&nkey, | 343 | GNUNET_CRYPTO_hash (edata, nsize, &query); |
379 | &skey, | 344 | if (0 != memcmp (&query, key, sizeof (struct GNUNET_HashCode))) |
380 | &iv); | ||
381 | GNUNET_CRYPTO_symmetric_encrypt (ndata, | ||
382 | nsize, | ||
383 | &skey, | ||
384 | &iv, | ||
385 | edata); | ||
386 | GNUNET_CRYPTO_hash (edata, | ||
387 | nsize, | ||
388 | &query); | ||
389 | if (0 != memcmp (&query, | ||
390 | key, | ||
391 | sizeof (struct GNUNET_HashCode))) | ||
392 | { | 345 | { |
393 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 346 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
394 | _("Indexed file `%s' changed at offset %llu\n"), | 347 | _ ("Indexed file `%s' changed at offset %llu\n"), |
395 | fn, | 348 | fn, |
396 | (unsigned long long) off); | 349 | (unsigned long long) off); |
397 | GNUNET_DATASTORE_remove (dsh, | 350 | GNUNET_DATASTORE_remove (dsh, key, size, data, -1, -1, &remove_cont, NULL); |
398 | key, | ||
399 | size, | ||
400 | data, | ||
401 | -1, | ||
402 | -1, | ||
403 | &remove_cont, | ||
404 | NULL); | ||
405 | return GNUNET_SYSERR; | 351 | return GNUNET_SYSERR; |
406 | } | 352 | } |
407 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 353 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -440,27 +386,20 @@ GNUNET_FS_indexing_send_list (struct GNUNET_MQ_Handle *mq) | |||
440 | { | 386 | { |
441 | fn = pos->filename; | 387 | fn = pos->filename; |
442 | slen = strlen (fn) + 1; | 388 | slen = strlen (fn) + 1; |
443 | if (slen + sizeof (struct IndexInfoMessage) >= | 389 | if (slen + sizeof (struct IndexInfoMessage) >= GNUNET_MAX_MESSAGE_SIZE) |
444 | GNUNET_MAX_MESSAGE_SIZE) | ||
445 | { | 390 | { |
446 | GNUNET_break (0); | 391 | GNUNET_break (0); |
447 | break; | 392 | break; |
448 | } | 393 | } |
449 | env = GNUNET_MQ_msg_extra (iim, | 394 | env = |
450 | slen, | 395 | GNUNET_MQ_msg_extra (iim, slen, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY); |
451 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY); | ||
452 | iim->reserved = 0; | 396 | iim->reserved = 0; |
453 | iim->file_id = pos->file_id; | 397 | iim->file_id = pos->file_id; |
454 | GNUNET_memcpy (&iim[1], | 398 | GNUNET_memcpy (&iim[1], fn, slen); |
455 | fn, | 399 | GNUNET_MQ_send (mq, env); |
456 | slen); | ||
457 | GNUNET_MQ_send (mq, | ||
458 | env); | ||
459 | } | 400 | } |
460 | env = GNUNET_MQ_msg (iem, | 401 | env = GNUNET_MQ_msg (iem, GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END); |
461 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END); | 402 | GNUNET_MQ_send (mq, env); |
462 | GNUNET_MQ_send (mq, | ||
463 | env); | ||
464 | } | 403 | } |
465 | 404 | ||
466 | 405 | ||
@@ -477,17 +416,12 @@ GNUNET_FS_indexing_do_unindex (const struct GNUNET_HashCode *fid) | |||
477 | 416 | ||
478 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) | 417 | for (pos = indexed_files_head; NULL != pos; pos = pos->next) |
479 | { | 418 | { |
480 | if (0 == memcmp (&pos->file_id, | 419 | if (0 == memcmp (&pos->file_id, fid, sizeof (struct GNUNET_HashCode))) |
481 | fid, | ||
482 | sizeof (struct GNUNET_HashCode))) | ||
483 | { | 420 | { |
484 | GNUNET_CONTAINER_DLL_remove (indexed_files_head, | 421 | GNUNET_CONTAINER_DLL_remove (indexed_files_head, indexed_files_tail, pos); |
485 | indexed_files_tail, | 422 | GNUNET_break ( |
486 | pos); | 423 | GNUNET_OK == |
487 | GNUNET_break (GNUNET_OK == | 424 | GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id, pos)); |
488 | GNUNET_CONTAINER_multihashmap_remove (ifm, | ||
489 | &pos->file_id, | ||
490 | pos)); | ||
491 | GNUNET_free (pos); | 425 | GNUNET_free (pos); |
492 | write_index_list (); | 426 | write_index_list (); |
493 | return GNUNET_YES; | 427 | return GNUNET_YES; |
@@ -510,14 +444,15 @@ GNUNET_FS_add_to_index (const char *filename, | |||
510 | struct IndexInfo *ii; | 444 | struct IndexInfo *ii; |
511 | size_t slen; | 445 | size_t slen; |
512 | 446 | ||
513 | ii = GNUNET_CONTAINER_multihashmap_get (ifm, | 447 | ii = GNUNET_CONTAINER_multihashmap_get (ifm, file_id); |
514 | file_id); | ||
515 | if (NULL != ii) | 448 | if (NULL != ii) |
516 | { | 449 | { |
517 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 450 | GNUNET_log ( |
518 | _("Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"), | 451 | GNUNET_ERROR_TYPE_INFO, |
519 | filename, | 452 | _ ( |
520 | ii->filename); | 453 | "Index request received for file `%s' is already indexed as `%s'. Permitting anyway.\n"), |
454 | filename, | ||
455 | ii->filename); | ||
521 | return; | 456 | return; |
522 | } | 457 | } |
523 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 458 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -528,17 +463,14 @@ GNUNET_FS_add_to_index (const char *filename, | |||
528 | ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen); | 463 | ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen); |
529 | ii->file_id = *file_id; | 464 | ii->file_id = *file_id; |
530 | ii->filename = (const char *) &ii[1]; | 465 | ii->filename = (const char *) &ii[1]; |
531 | GNUNET_memcpy (&ii[1], | 466 | GNUNET_memcpy (&ii[1], filename, slen); |
532 | filename, | 467 | GNUNET_CONTAINER_DLL_insert (indexed_files_head, indexed_files_tail, ii); |
533 | slen); | ||
534 | GNUNET_CONTAINER_DLL_insert (indexed_files_head, | ||
535 | indexed_files_tail, | ||
536 | ii); | ||
537 | GNUNET_assert (GNUNET_OK == | 468 | GNUNET_assert (GNUNET_OK == |
538 | GNUNET_CONTAINER_multihashmap_put (ifm, | 469 | GNUNET_CONTAINER_multihashmap_put ( |
539 | &ii->file_id, | 470 | ifm, |
540 | ii, | 471 | &ii->file_id, |
541 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 472 | ii, |
473 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
542 | write_index_list (); | 474 | write_index_list (); |
543 | } | 475 | } |
544 | 476 | ||
@@ -553,15 +485,12 @@ GNUNET_FS_indexing_done () | |||
553 | 485 | ||
554 | while (NULL != (pos = indexed_files_head)) | 486 | while (NULL != (pos = indexed_files_head)) |
555 | { | 487 | { |
556 | GNUNET_CONTAINER_DLL_remove (indexed_files_head, | 488 | GNUNET_CONTAINER_DLL_remove (indexed_files_head, indexed_files_tail, pos); |
557 | indexed_files_tail, | ||
558 | pos); | ||
559 | if (pos->fhc != NULL) | 489 | if (pos->fhc != NULL) |
560 | GNUNET_CRYPTO_hash_file_cancel (pos->fhc); | 490 | GNUNET_CRYPTO_hash_file_cancel (pos->fhc); |
561 | GNUNET_break (GNUNET_OK == | 491 | GNUNET_break ( |
562 | GNUNET_CONTAINER_multihashmap_remove (ifm, | 492 | GNUNET_OK == |
563 | &pos->file_id, | 493 | GNUNET_CONTAINER_multihashmap_remove (ifm, &pos->file_id, pos)); |
564 | pos)); | ||
565 | GNUNET_free (pos); | 494 | GNUNET_free (pos); |
566 | } | 495 | } |
567 | GNUNET_CONTAINER_multihashmap_destroy (ifm); | 496 | GNUNET_CONTAINER_multihashmap_destroy (ifm); |
@@ -582,8 +511,7 @@ GNUNET_FS_indexing_init (const struct GNUNET_CONFIGURATION_Handle *c, | |||
582 | { | 511 | { |
583 | cfg = c; | 512 | cfg = c; |
584 | dsh = d; | 513 | dsh = d; |
585 | ifm = GNUNET_CONTAINER_multihashmap_create (128, | 514 | ifm = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES); |
586 | GNUNET_YES); | ||
587 | read_index_list (); | 515 | read_index_list (); |
588 | return GNUNET_OK; | 516 | return GNUNET_OK; |
589 | } | 517 | } |
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) | |||
85 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: | 85 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: |
86 | if (verbose) | 86 | if (verbose) |
87 | { | 87 | { |
88 | s = GNUNET_STRINGS_relative_time_to_string (info->value.unindex.eta, GNUNET_YES); | 88 | s = GNUNET_STRINGS_relative_time_to_string (info->value.unindex.eta, |
89 | FPRINTF (stdout, _("Unindexing at %llu/%llu (%s remaining)\n"), | 89 | GNUNET_YES); |
90 | fprintf (stdout, | ||
91 | _ ("Unindexing at %llu/%llu (%s remaining)\n"), | ||
90 | (unsigned long long) info->value.unindex.completed, | 92 | (unsigned long long) info->value.unindex.completed, |
91 | (unsigned long long) info->value.unindex.size, s); | 93 | (unsigned long long) info->value.unindex.size, |
94 | s); | ||
92 | } | 95 | } |
93 | break; | 96 | break; |
94 | case GNUNET_FS_STATUS_UNINDEX_ERROR: | 97 | case GNUNET_FS_STATUS_UNINDEX_ERROR: |
95 | FPRINTF (stderr, _("Error unindexing: %s.\n"), | 98 | fprintf (stderr, |
99 | _ ("Error unindexing: %s.\n"), | ||
96 | info->value.unindex.specifics.error.message); | 100 | info->value.unindex.specifics.error.message); |
97 | GNUNET_SCHEDULER_shutdown (); | 101 | GNUNET_SCHEDULER_shutdown (); |
98 | break; | 102 | break; |
99 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: | 103 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: |
100 | FPRINTF (stdout, "%s", _("Unindexing done.\n")); | 104 | fprintf (stdout, "%s", _ ("Unindexing done.\n")); |
101 | GNUNET_SCHEDULER_shutdown (); | 105 | GNUNET_SCHEDULER_shutdown (); |
102 | break; | 106 | break; |
103 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: | 107 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: |
104 | GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); | 108 | GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); |
105 | break; | 109 | break; |
106 | default: | 110 | default: |
107 | FPRINTF (stderr, _("Unexpected status: %d\n"), info->status); | 111 | fprintf (stderr, _ ("Unexpected status: %d\n"), info->status); |
108 | break; | 112 | break; |
109 | } | 113 | } |
110 | return NULL; | 114 | return NULL; |
@@ -120,35 +124,39 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) | |||
120 | * @param c configuration | 124 | * @param c configuration |
121 | */ | 125 | */ |
122 | static void | 126 | static void |
123 | run (void *cls, char *const *args, const char *cfgfile, | 127 | run (void *cls, |
128 | char *const *args, | ||
129 | const char *cfgfile, | ||
124 | const struct GNUNET_CONFIGURATION_Handle *c) | 130 | const struct GNUNET_CONFIGURATION_Handle *c) |
125 | { | 131 | { |
126 | /* check arguments */ | 132 | /* check arguments */ |
127 | if ((args[0] == NULL) || (args[1] != NULL)) | 133 | if ((args[0] == NULL) || (args[1] != NULL)) |
128 | { | 134 | { |
129 | printf (_("You must specify one and only one filename for unindexing.\n")); | 135 | printf (_ ("You must specify one and only one filename for unindexing.\n")); |
130 | ret = -1; | 136 | ret = -1; |
131 | return; | 137 | return; |
132 | } | 138 | } |
133 | cfg = c; | 139 | cfg = c; |
134 | ctx = | 140 | ctx = GNUNET_FS_start (cfg, |
135 | GNUNET_FS_start (cfg, "gnunet-unindex", &progress_cb, NULL, | 141 | "gnunet-unindex", |
136 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 142 | &progress_cb, |
143 | NULL, | ||
144 | GNUNET_FS_FLAGS_NONE, | ||
145 | GNUNET_FS_OPTIONS_END); | ||
137 | if (NULL == ctx) | 146 | if (NULL == ctx) |
138 | { | 147 | { |
139 | FPRINTF (stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); | 148 | fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS"); |
140 | ret = 1; | 149 | ret = 1; |
141 | return; | 150 | return; |
142 | } | 151 | } |
143 | uc = GNUNET_FS_unindex_start (ctx, args[0], NULL); | 152 | uc = GNUNET_FS_unindex_start (ctx, args[0], NULL); |
144 | if (NULL == uc) | 153 | if (NULL == uc) |
145 | { | 154 | { |
146 | FPRINTF (stderr, "%s", _("Could not start unindex operation.\n")); | 155 | fprintf (stderr, "%s", _ ("Could not start unindex operation.\n")); |
147 | GNUNET_FS_stop (ctx); | 156 | GNUNET_FS_stop (ctx); |
148 | return; | 157 | return; |
149 | } | 158 | } |
150 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 159 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
151 | NULL); | ||
152 | } | 160 | } |
153 | 161 | ||
154 | 162 | ||
@@ -166,18 +174,24 @@ main (int argc, char *const *argv) | |||
166 | 174 | ||
167 | GNUNET_GETOPT_option_verbose (&verbose), | 175 | GNUNET_GETOPT_option_verbose (&verbose), |
168 | 176 | ||
169 | GNUNET_GETOPT_OPTION_END | 177 | GNUNET_GETOPT_OPTION_END}; |
170 | }; | ||
171 | 178 | ||
172 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 179 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
173 | return 2; | 180 | return 2; |
174 | 181 | ||
175 | ret = (GNUNET_OK == | 182 | ret = (GNUNET_OK == |
176 | GNUNET_PROGRAM_run (argc, argv, "gnunet-unindex [OPTIONS] FILENAME", | 183 | GNUNET_PROGRAM_run ( |
177 | gettext_noop | 184 | argc, |
178 | ("Unindex a file that was previously indexed with gnunet-publish."), | 185 | argv, |
179 | options, &run, NULL)) ? ret : 1; | 186 | "gnunet-unindex [OPTIONS] FILENAME", |
180 | GNUNET_free ((void*) argv); | 187 | gettext_noop ( |
188 | "Unindex a file that was previously indexed with gnunet-publish."), | ||
189 | options, | ||
190 | &run, | ||
191 | NULL)) | ||
192 | ? ret | ||
193 | : 1; | ||
194 | GNUNET_free ((void *) argv); | ||
181 | return ret; | 195 | return ret; |
182 | } | 196 | } |
183 | 197 | ||
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, | |||
116 | { | 116 | { |
117 | struct StatMaster *sm = cls; | 117 | struct StatMaster *sm = cls; |
118 | 118 | ||
119 | FPRINTF (stderr, | 119 | fprintf (stderr, |
120 | "Peer %2u: %12s/%50s = %12llu\n", | 120 | "Peer %2u: %12s/%50s = %12llu\n", |
121 | sm->daemon, | 121 | sm->daemon, |
122 | subsystem, | 122 | subsystem, |
@@ -267,7 +267,7 @@ do_report (void *cls) | |||
267 | fancy = | 267 | fancy = |
268 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * | 268 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * |
269 | 1000000LL / del.rel_value_us); | 269 | 1000000LL / del.rel_value_us); |
270 | FPRINTF (stdout, | 270 | fprintf (stdout, |
271 | "Download speed was %s/s\n", | 271 | "Download speed was %s/s\n", |
272 | fancy); | 272 | fancy); |
273 | GNUNET_free (fancy); | 273 | 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, | |||
168 | { | 168 | { |
169 | struct StatMaster *sm = cls; | 169 | struct StatMaster *sm = cls; |
170 | 170 | ||
171 | FPRINTF (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem, | 171 | fprintf (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem, |
172 | name, (unsigned long long) value); | 172 | name, (unsigned long long) value); |
173 | return GNUNET_OK; | 173 | return GNUNET_OK; |
174 | } | 174 | } |
@@ -304,7 +304,7 @@ do_report (void *cls) | |||
304 | fancy = | 304 | fancy = |
305 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * | 305 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * |
306 | 1000000LL / del.rel_value_us); | 306 | 1000000LL / del.rel_value_us); |
307 | FPRINTF (stderr, "Download speed of type `%s' was %s/s\n", type, fancy); | 307 | fprintf (stderr, "Download speed of type `%s' was %s/s\n", type, fancy); |
308 | GNUNET_free (fancy); | 308 | GNUNET_free (fancy); |
309 | if (NUM_DAEMONS != ++download_counter) | 309 | if (NUM_DAEMONS != ++download_counter) |
310 | return; /* more downloads to come */ | 310 | 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: | |||
226 | GNUNET_FSUI_stop (ctx); | 226 | GNUNET_FSUI_stop (ctx); |
227 | if (filename != NULL) | 227 | if (filename != NULL) |
228 | { | 228 | { |
229 | UNLINK (filename); | 229 | unlink (filename); |
230 | GNUNET_free (filename); | 230 | GNUNET_free (filename); |
231 | } | 231 | } |
232 | if (download != NULL) | 232 | if (download != NULL) |
@@ -236,7 +236,7 @@ FAILURE: | |||
236 | } | 236 | } |
237 | filename = makeName (43); | 237 | filename = makeName (43); |
238 | /* TODO: verify file 'filename(42)' == file 'filename(43)' */ | 238 | /* TODO: verify file 'filename(42)' == file 'filename(43)' */ |
239 | UNLINK (filename); | 239 | unlink (filename); |
240 | GNUNET_free (filename); | 240 | GNUNET_free (filename); |
241 | 241 | ||
242 | #if START_DAEMON | 242 | #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, | |||
59 | return; | 59 | return; |
60 | } | 60 | } |
61 | } | 61 | } |
62 | FPRINTF (stderr, "Error at %s:%d\n", __FILE__, __LINE__); | 62 | fprintf (stderr, "Error at %s:%d\n", __FILE__, __LINE__); |
63 | } | 63 | } |
64 | 64 | ||
65 | static int | 65 | static int |
@@ -136,7 +136,7 @@ testDirectory (unsigned int i) | |||
136 | s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration | 136 | s = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration |
137 | (start), | 137 | (start), |
138 | GNUNET_YES); | 138 | GNUNET_YES); |
139 | FPRINTF (stdout, | 139 | fprintf (stdout, |
140 | "Creating directory with %u entires and total size %llu took %s\n", | 140 | "Creating directory with %u entires and total size %llu took %s\n", |
141 | i, (unsigned long long) dlen, s); | 141 | i, (unsigned long long) dlen, s); |
142 | if (i < 100) | 142 | 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) | |||
195 | progress.offset); | 195 | progress.offset); |
196 | break; | 196 | break; |
197 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 197 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
198 | FPRINTF (stderr, "Error publishing file: %s\n", | 198 | fprintf (stderr, "Error publishing file: %s\n", |
199 | event->value.publish.specifics.error.message); | 199 | event->value.publish.specifics.error.message); |
200 | GNUNET_break (0); | 200 | GNUNET_break (0); |
201 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 201 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
202 | GNUNET_SCHEDULER_shutdown (); | 202 | GNUNET_SCHEDULER_shutdown (); |
203 | break; | 203 | break; |
204 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | 204 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: |
205 | FPRINTF (stderr, "Error downloading file: %s\n", | 205 | fprintf (stderr, "Error downloading file: %s\n", |
206 | event->value.download.specifics.error.message); | 206 | event->value.download.specifics.error.message); |
207 | GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); | 207 | GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); |
208 | GNUNET_SCHEDULER_shutdown (); | 208 | GNUNET_SCHEDULER_shutdown (); |
@@ -342,7 +342,7 @@ main (int argc, char *argv[]) | |||
342 | return 1; | 342 | return 1; |
343 | if (NULL != fn1) | 343 | if (NULL != fn1) |
344 | { | 344 | { |
345 | UNLINK (fn1); | 345 | unlink (fn1); |
346 | GNUNET_free (fn1); | 346 | GNUNET_free (fn1); |
347 | } | 347 | } |
348 | return err; | 348 | 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) | |||
198 | progress.offset); | 198 | progress.offset); |
199 | break; | 199 | break; |
200 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 200 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
201 | FPRINTF (stderr, "Error publishing file: %s\n", | 201 | fprintf (stderr, "Error publishing file: %s\n", |
202 | event->value.publish.specifics.error.message); | 202 | event->value.publish.specifics.error.message); |
203 | GNUNET_break (0); | 203 | GNUNET_break (0); |
204 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 204 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
205 | break; | 205 | break; |
206 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | 206 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: |
207 | FPRINTF (stderr, "Error downloading file: %s\n", | 207 | fprintf (stderr, "Error downloading file: %s\n", |
208 | event->value.download.specifics.error.message); | 208 | event->value.download.specifics.error.message); |
209 | GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); | 209 | GNUNET_SCHEDULER_add_now (&abort_download_task, NULL); |
210 | break; | 210 | 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[]) | |||
32 | GNUNET_log_setup ("test_fs_getopt", | 32 | GNUNET_log_setup ("test_fs_getopt", |
33 | "WARNING", | 33 | "WARNING", |
34 | NULL); | 34 | NULL); |
35 | FPRINTF (stderr, "%s", "WARNING: testcase not yet written.\n"); | 35 | fprintf (stderr, "%s", "WARNING: testcase not yet written.\n"); |
36 | return 0; /* testcase passed */ | 36 | return 0; /* testcase passed */ |
37 | } | 37 | } |
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) | |||
117 | break; | 117 | break; |
118 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 118 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
119 | ret = event->value.publish.cctx; | 119 | ret = event->value.publish.cctx; |
120 | FPRINTF (stderr, "Error publishing file: %s\n", | 120 | fprintf (stderr, "Error publishing file: %s\n", |
121 | event->value.publish.specifics.error.message); | 121 | event->value.publish.specifics.error.message); |
122 | err = 1; | 122 | err = 1; |
123 | if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) | 123 | 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 | |||
85 | do_timeout (void *cls) | 85 | do_timeout (void *cls) |
86 | { | 86 | { |
87 | err = 1; | 87 | err = 1; |
88 | FPRINTF (stderr, "%s", "Operation timed out\n"); | 88 | fprintf (stderr, "%s", "Operation timed out\n"); |
89 | kill_task = NULL; | 89 | kill_task = NULL; |
90 | abort_sks_search_task (NULL); | 90 | abort_sks_search_task (NULL); |
91 | abort_ksk_search_task (NULL); | 91 | abort_ksk_search_task (NULL); |
@@ -103,7 +103,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
103 | if (!GNUNET_FS_uri_test_equal | 103 | if (!GNUNET_FS_uri_test_equal |
104 | (sks_expect_uri, event->value.search.specifics.result.uri)) | 104 | (sks_expect_uri, event->value.search.specifics.result.uri)) |
105 | { | 105 | { |
106 | FPRINTF (stderr, "%s", "Wrong result for sks search!\n"); | 106 | fprintf (stderr, "%s", "Wrong result for sks search!\n"); |
107 | err = 1; | 107 | err = 1; |
108 | } | 108 | } |
109 | /* give system 1ms to initiate update search! */ | 109 | /* give system 1ms to initiate update search! */ |
@@ -115,19 +115,19 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
115 | if (!GNUNET_FS_uri_test_equal | 115 | if (!GNUNET_FS_uri_test_equal |
116 | (ksk_expect_uri, event->value.search.specifics.result.uri)) | 116 | (ksk_expect_uri, event->value.search.specifics.result.uri)) |
117 | { | 117 | { |
118 | FPRINTF (stderr, "%s", "Wrong result for ksk search!\n"); | 118 | fprintf (stderr, "%s", "Wrong result for ksk search!\n"); |
119 | err = 1; | 119 | err = 1; |
120 | } | 120 | } |
121 | GNUNET_SCHEDULER_add_now (&abort_ksk_search_task, NULL); | 121 | GNUNET_SCHEDULER_add_now (&abort_ksk_search_task, NULL); |
122 | } | 122 | } |
123 | else | 123 | else |
124 | { | 124 | { |
125 | FPRINTF (stderr, "%s", "Unexpected search result received!\n"); | 125 | fprintf (stderr, "%s", "Unexpected search result received!\n"); |
126 | GNUNET_break (0); | 126 | GNUNET_break (0); |
127 | } | 127 | } |
128 | break; | 128 | break; |
129 | case GNUNET_FS_STATUS_SEARCH_ERROR: | 129 | case GNUNET_FS_STATUS_SEARCH_ERROR: |
130 | FPRINTF (stderr, "Error searching file: %s\n", | 130 | fprintf (stderr, "Error searching file: %s\n", |
131 | event->value.search.specifics.error.message); | 131 | event->value.search.specifics.error.message); |
132 | if (sks_search == event->value.search.sc) | 132 | if (sks_search == event->value.search.sc) |
133 | GNUNET_SCHEDULER_add_now (&abort_sks_search_task, NULL); | 133 | GNUNET_SCHEDULER_add_now (&abort_sks_search_task, NULL); |
@@ -152,7 +152,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
152 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | 152 | case GNUNET_FS_STATUS_SEARCH_STOPPED: |
153 | return NULL; | 153 | return NULL; |
154 | default: | 154 | default: |
155 | FPRINTF (stderr, "Unexpected event: %d\n", event->status); | 155 | fprintf (stderr, "Unexpected event: %d\n", event->status); |
156 | break; | 156 | break; |
157 | } | 157 | } |
158 | return event->value.search.cctx; | 158 | return event->value.search.cctx; |
@@ -170,7 +170,7 @@ publish_cont (void *cls, const struct GNUNET_FS_Uri *ksk_uri, const char *emsg) | |||
170 | 170 | ||
171 | if (NULL != emsg) | 171 | if (NULL != emsg) |
172 | { | 172 | { |
173 | FPRINTF (stderr, "Error publishing: %s\n", emsg); | 173 | fprintf (stderr, "Error publishing: %s\n", emsg); |
174 | err = 1; | 174 | err = 1; |
175 | GNUNET_FS_stop (fs); | 175 | GNUNET_FS_stop (fs); |
176 | return; | 176 | return; |
@@ -182,7 +182,7 @@ publish_cont (void *cls, const struct GNUNET_FS_Uri *ksk_uri, const char *emsg) | |||
182 | sks_uri = GNUNET_FS_uri_parse (sbuf, &msg); | 182 | sks_uri = GNUNET_FS_uri_parse (sbuf, &msg); |
183 | if (NULL == sks_uri) | 183 | if (NULL == sks_uri) |
184 | { | 184 | { |
185 | FPRINTF (stderr, "failed to parse URI `%s': %s\n", sbuf, msg); | 185 | fprintf (stderr, "failed to parse URI `%s': %s\n", sbuf, msg); |
186 | err = 1; | 186 | err = 1; |
187 | GNUNET_FS_stop (fs); | 187 | GNUNET_FS_stop (fs); |
188 | GNUNET_free_non_null (msg); | 188 | GNUNET_free_non_null (msg); |
@@ -239,7 +239,7 @@ adv_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) | |||
239 | 239 | ||
240 | if (NULL != emsg) | 240 | if (NULL != emsg) |
241 | { | 241 | { |
242 | FPRINTF (stderr, "Error publishing: %s\n", emsg); | 242 | fprintf (stderr, "Error publishing: %s\n", emsg); |
243 | err = 1; | 243 | err = 1; |
244 | GNUNET_FS_stop (fs); | 244 | GNUNET_FS_stop (fs); |
245 | return; | 245 | 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) | |||
105 | break; | 105 | break; |
106 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 106 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
107 | ret = event->value.publish.cctx; | 107 | ret = event->value.publish.cctx; |
108 | FPRINTF (stderr, "Error publishing file: %s\n", | 108 | fprintf (stderr, "Error publishing file: %s\n", |
109 | event->value.publish.specifics.error.message); | 109 | event->value.publish.specifics.error.message); |
110 | err = 1; | 110 | err = 1; |
111 | if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) | 111 | if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) |
112 | { | 112 | { |
113 | FPRINTF (stderr, "Scheduling abort task for error on `%s'\n", | 113 | fprintf (stderr, "Scheduling abort task for error on `%s'\n", |
114 | (const char *) event->value.publish.cctx); | 114 | (const char *) event->value.publish.cctx); |
115 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 115 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
116 | } | 116 | } |
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, | |||
177 | break; | 177 | break; |
178 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 178 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
179 | ret = event->value.publish.cctx; | 179 | ret = event->value.publish.cctx; |
180 | FPRINTF (stderr, "Error publishing file: %s\n", | 180 | fprintf (stderr, "Error publishing file: %s\n", |
181 | event->value.publish.specifics.error.message); | 181 | event->value.publish.specifics.error.message); |
182 | err = 1; | 182 | err = 1; |
183 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 183 | 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) | |||
140 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); | 140 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); |
141 | break; | 141 | break; |
142 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 142 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
143 | FPRINTF (stderr, "Error publishing file: %s\n", | 143 | fprintf (stderr, "Error publishing file: %s\n", |
144 | event->value.publish.specifics.error.message); | 144 | event->value.publish.specifics.error.message); |
145 | GNUNET_break (0); | 145 | GNUNET_break (0); |
146 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 146 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
147 | break; | 147 | break; |
148 | case GNUNET_FS_STATUS_SEARCH_ERROR: | 148 | case GNUNET_FS_STATUS_SEARCH_ERROR: |
149 | FPRINTF (stderr, "Error searching file: %s\n", | 149 | fprintf (stderr, "Error searching file: %s\n", |
150 | event->value.search.specifics.error.message); | 150 | event->value.search.specifics.error.message); |
151 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); | 151 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); |
152 | break; | 152 | break; |
@@ -176,7 +176,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
176 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 176 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
177 | break; | 177 | break; |
178 | default: | 178 | default: |
179 | FPRINTF (stderr, "Unexpected event: %d\n", event->status); | 179 | fprintf (stderr, "Unexpected event: %d\n", event->status); |
180 | break; | 180 | break; |
181 | } | 181 | } |
182 | return NULL; | 182 | 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) | |||
187 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); | 187 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); |
188 | break; | 188 | break; |
189 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 189 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
190 | FPRINTF (stderr, "Error publishing file: %s\n", | 190 | fprintf (stderr, "Error publishing file: %s\n", |
191 | event->value.publish.specifics.error.message); | 191 | event->value.publish.specifics.error.message); |
192 | GNUNET_break (0); | 192 | GNUNET_break (0); |
193 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 193 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
194 | break; | 194 | break; |
195 | case GNUNET_FS_STATUS_SEARCH_ERROR: | 195 | case GNUNET_FS_STATUS_SEARCH_ERROR: |
196 | FPRINTF (stderr, "Error searching file: %s\n", | 196 | fprintf (stderr, "Error searching file: %s\n", |
197 | event->value.search.specifics.error.message); | 197 | event->value.search.specifics.error.message); |
198 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); | 198 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); |
199 | break; | 199 | break; |
@@ -237,7 +237,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
237 | search = NULL; | 237 | search = NULL; |
238 | break; | 238 | break; |
239 | default: | 239 | default: |
240 | FPRINTF (stderr, "Unexpected event: %d\n", event->status); | 240 | fprintf (stderr, "Unexpected event: %d\n", event->status); |
241 | break; | 241 | break; |
242 | } | 242 | } |
243 | return NULL; | 243 | 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) | |||
137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Search complete.\n"); | 137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Search complete.\n"); |
138 | break; | 138 | break; |
139 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 139 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
140 | FPRINTF (stderr, "Error publishing file: %s\n", | 140 | fprintf (stderr, "Error publishing file: %s\n", |
141 | event->value.publish.specifics.error.message); | 141 | event->value.publish.specifics.error.message); |
142 | GNUNET_break (0); | 142 | GNUNET_break (0); |
143 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 143 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
144 | break; | 144 | break; |
145 | case GNUNET_FS_STATUS_SEARCH_ERROR: | 145 | case GNUNET_FS_STATUS_SEARCH_ERROR: |
146 | FPRINTF (stderr, "Error searching file: %s\n", | 146 | fprintf (stderr, "Error searching file: %s\n", |
147 | event->value.search.specifics.error.message); | 147 | event->value.search.specifics.error.message); |
148 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); | 148 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); |
149 | break; | 149 | break; |
@@ -178,7 +178,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
178 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 178 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
179 | break; | 179 | break; |
180 | default: | 180 | default: |
181 | FPRINTF (stderr, | 181 | fprintf (stderr, |
182 | "Unexpected event: %d\n", | 182 | "Unexpected event: %d\n", |
183 | event->status); | 183 | event->status); |
184 | break; | 184 | 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) | |||
153 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); | 153 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); |
154 | break; | 154 | break; |
155 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 155 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
156 | FPRINTF (stderr, "Error publishing file: %s\n", | 156 | fprintf (stderr, "Error publishing file: %s\n", |
157 | event->value.publish.specifics.error.message); | 157 | event->value.publish.specifics.error.message); |
158 | GNUNET_break (0); | 158 | GNUNET_break (0); |
159 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 159 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
160 | break; | 160 | break; |
161 | case GNUNET_FS_STATUS_SEARCH_ERROR: | 161 | case GNUNET_FS_STATUS_SEARCH_ERROR: |
162 | FPRINTF (stderr, "Error searching file: %s\n", | 162 | fprintf (stderr, "Error searching file: %s\n", |
163 | event->value.search.specifics.error.message); | 163 | event->value.search.specifics.error.message); |
164 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); | 164 | GNUNET_SCHEDULER_add_now (&abort_search_task, NULL); |
165 | break; | 165 | break; |
@@ -189,7 +189,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
189 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 189 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
190 | break; | 190 | break; |
191 | default: | 191 | default: |
192 | FPRINTF (stderr, "Unexpected event: %d\n", event->status); | 192 | fprintf (stderr, "Unexpected event: %d\n", event->status); |
193 | break; | 193 | break; |
194 | } | 194 | } |
195 | return NULL; | 195 | 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) | |||
121 | progress.offset); | 121 | progress.offset); |
122 | break; | 122 | break; |
123 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 123 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
124 | FPRINTF (stderr, "Error publishing file: %s\n", | 124 | fprintf (stderr, "Error publishing file: %s\n", |
125 | event->value.publish.specifics.error.message); | 125 | event->value.publish.specifics.error.message); |
126 | GNUNET_break (0); | 126 | GNUNET_break (0); |
127 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 127 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); |
128 | break; | 128 | break; |
129 | case GNUNET_FS_STATUS_UNINDEX_ERROR: | 129 | case GNUNET_FS_STATUS_UNINDEX_ERROR: |
130 | FPRINTF (stderr, "Error unindexing file: %s\n", | 130 | fprintf (stderr, "Error unindexing file: %s\n", |
131 | event->value.unindex.specifics.error.message); | 131 | event->value.unindex.specifics.error.message); |
132 | GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL); | 132 | GNUNET_SCHEDULER_add_now (&abort_unindex_task, NULL); |
133 | break; | 133 | 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) | |||
183 | unindex = event->value.unindex.uc; | 183 | unindex = event->value.unindex.uc; |
184 | return "unindex"; | 184 | return "unindex"; |
185 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 185 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
186 | FPRINTF (stderr, "Error publishing file: %s\n", | 186 | fprintf (stderr, "Error publishing file: %s\n", |
187 | event->value.publish.specifics.error.message); | 187 | event->value.publish.specifics.error.message); |
188 | GNUNET_break (0); | 188 | GNUNET_break (0); |
189 | GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); | 189 | 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[]) | |||
314 | failureCount += testLocation (); | 314 | failureCount += testLocation (); |
315 | for (i = 0; i < 255; i++) | 315 | for (i = 0; i < 255; i++) |
316 | { | 316 | { |
317 | /* FPRINTF (stderr, "%s", "."); */ | 317 | /* fprintf (stderr, "%s", "."); */ |
318 | failureCount += testNamespace (i); | 318 | failureCount += testNamespace (i); |
319 | failureCount += testFile (i); | 319 | failureCount += testFile (i); |
320 | } | 320 | } |
321 | /* FPRINTF (stderr, "%s", "\n"); */ | 321 | /* fprintf (stderr, "%s", "\n"); */ |
322 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-uri"); | 322 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-uri"); |
323 | if (failureCount != 0) | 323 | if (failureCount != 0) |
324 | return 1; | 324 | 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) | |||
86 | fancy = | 86 | fancy = |
87 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * | 87 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * |
88 | 1000000LL / del.rel_value_us); | 88 | 1000000LL / del.rel_value_us); |
89 | FPRINTF (stdout, | 89 | fprintf (stdout, |
90 | "Download speed was %s/s\n", | 90 | "Download speed was %s/s\n", |
91 | fancy); | 91 | fancy); |
92 | GNUNET_free (fancy); | 92 | 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) | |||
77 | fancy = | 77 | fancy = |
78 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * | 78 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * |
79 | 1000000LL / del.rel_value_us); | 79 | 1000000LL / del.rel_value_us); |
80 | FPRINTF (stdout, | 80 | fprintf (stdout, |
81 | "Download speed was %s/s\n", | 81 | "Download speed was %s/s\n", |
82 | fancy); | 82 | fancy); |
83 | GNUNET_free (fancy); | 83 | 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[]) | |||
84 | GNUNET_BLOCK_context_destroy (ctx); | 84 | GNUNET_BLOCK_context_destroy (ctx); |
85 | GNUNET_CONFIGURATION_destroy (cfg); | 85 | GNUNET_CONFIGURATION_destroy (cfg); |
86 | if (ret != 0) | 86 | if (ret != 0) |
87 | FPRINTF (stderr, "Tests failed: %d\n", ret); | 87 | fprintf (stderr, "Tests failed: %d\n", ret); |
88 | return ret; | 88 | return ret; |
89 | } | 89 | } |
90 | 90 | ||