aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_file_information.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/fs_file_information.c')
-rw-r--r--src/fs/fs_file_information.c503
1 files changed, 228 insertions, 275 deletions
diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c
index 62ae285d8..bb323bbbc 100644
--- a/src/fs/fs_file_information.c
+++ b/src/fs/fs_file_information.c
@@ -52,22 +52,19 @@
52 * @return always 0 to continue extracting 52 * @return always 0 to continue extracting
53 */ 53 */
54static int 54static int
55add_to_md(void *cls, 55add_to_md (void *cls,
56 const char *plugin_name, 56 const char *plugin_name,
57 enum EXTRACTOR_MetaType type, 57 enum EXTRACTOR_MetaType type,
58 enum EXTRACTOR_MetaFormat format, 58 enum EXTRACTOR_MetaFormat format,
59 const char *data_mime_type, 59 const char *data_mime_type, const char *data, size_t data_len)
60 const char *data,
61 size_t data_len)
62{ 60{
63 struct GNUNET_CONTAINER_MetaData *md = cls; 61 struct GNUNET_CONTAINER_MetaData *md = cls;
62
64 (void) GNUNET_CONTAINER_meta_data_insert (md, 63 (void) GNUNET_CONTAINER_meta_data_insert (md,
65 plugin_name, 64 plugin_name,
66 type, 65 type,
67 format, 66 format,
68 data_mime_type, 67 data_mime_type, data, data_len);
69 data,
70 data_len);
71 return 0; 68 return 0;
72} 69}
73 70
@@ -80,9 +77,8 @@ add_to_md(void *cls,
80 */ 77 */
81int 78int
82GNUNET_FS_meta_data_extract_from_file (struct GNUNET_CONTAINER_MetaData 79GNUNET_FS_meta_data_extract_from_file (struct GNUNET_CONTAINER_MetaData
83 *md, const char *filename, 80 *md, const char *filename,
84 struct EXTRACTOR_PluginList * 81 struct EXTRACTOR_PluginList *extractors)
85 extractors)
86{ 82{
87 int old; 83 int old;
88 84
@@ -92,11 +88,7 @@ GNUNET_FS_meta_data_extract_from_file (struct GNUNET_CONTAINER_MetaData
92 return 0; 88 return 0;
93 old = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL); 89 old = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL);
94 GNUNET_assert (old >= 0); 90 GNUNET_assert (old >= 0);
95 EXTRACTOR_extract (extractors, 91 EXTRACTOR_extract (extractors, filename, NULL, 0, &add_to_md, md);
96 filename,
97 NULL, 0,
98 &add_to_md,
99 md);
100 return (GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL) - old); 92 return (GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL) - old);
101} 93}
102 94
@@ -137,44 +129,44 @@ GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s)
137 */ 129 */
138struct GNUNET_FS_FileInformation * 130struct GNUNET_FS_FileInformation *
139GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h, 131GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
140 void *client_info, 132 void *client_info,
141 const char *filename, 133 const char *filename,
142 const struct GNUNET_FS_Uri *keywords, 134 const struct GNUNET_FS_Uri
143 const struct GNUNET_CONTAINER_MetaData *meta, 135 *keywords,
144 int do_index, 136 const struct
145 const struct GNUNET_FS_BlockOptions *bo) 137 GNUNET_CONTAINER_MetaData *meta,
138 int do_index,
139 const struct GNUNET_FS_BlockOptions
140 *bo)
146{ 141{
147 struct FileInfo *fi; 142 struct FileInfo *fi;
148 struct stat sbuf; 143 struct stat sbuf;
149 struct GNUNET_FS_FileInformation *ret; 144 struct GNUNET_FS_FileInformation *ret;
150 const char *fn; 145 const char *fn;
151 const char *ss; 146 const char *ss;
147
152#if WINDOWS 148#if WINDOWS
153 char fn_conv[MAX_PATH]; 149 char fn_conv[MAX_PATH];
154#endif 150#endif
155 151
156 if (0 != STAT (filename, &sbuf)) 152 if (0 != STAT (filename, &sbuf))
157 { 153 {
158 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 154 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
159 "stat", 155 return NULL;
160 filename); 156 }
161 return NULL;
162 }
163 fi = GNUNET_FS_make_file_reader_context_ (filename); 157 fi = GNUNET_FS_make_file_reader_context_ (filename);
164 if (fi == NULL) 158 if (fi == NULL)
165 { 159 {
166 GNUNET_break (0); 160 GNUNET_break (0);
167 return NULL; 161 return NULL;
168 } 162 }
169 ret = GNUNET_FS_file_information_create_from_reader (h, 163 ret = GNUNET_FS_file_information_create_from_reader (h,
170 client_info, 164 client_info,
171 sbuf.st_size, 165 sbuf.st_size,
172 &GNUNET_FS_data_reader_file_, 166 &GNUNET_FS_data_reader_file_,
173 fi, 167 fi,
174 keywords, 168 keywords,
175 meta, 169 meta, do_index, bo);
176 do_index,
177 bo);
178 if (ret == NULL) 170 if (ret == NULL)
179 return NULL; 171 return NULL;
180 ret->h = h; 172 ret->h = h;
@@ -185,16 +177,13 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
185 plibc_conv_to_win_path (filename, fn_conv); 177 plibc_conv_to_win_path (filename, fn_conv);
186 fn = fn_conv; 178 fn = fn_conv;
187#endif 179#endif
188 while (NULL != (ss = strstr (fn, 180 while (NULL != (ss = strstr (fn, DIR_SEPARATOR_STR)))
189 DIR_SEPARATOR_STR)))
190 fn = ss + 1; 181 fn = ss + 1;
191 GNUNET_CONTAINER_meta_data_insert (ret->meta, 182 GNUNET_CONTAINER_meta_data_insert (ret->meta,
192 "<gnunet>", 183 "<gnunet>",
193 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, 184 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
194 EXTRACTOR_METAFORMAT_C_STRING, 185 EXTRACTOR_METAFORMAT_C_STRING,
195 "text/plain", 186 "text/plain", fn, strlen (fn) + 1);
196 fn,
197 strlen (fn) + 1);
198 return ret; 187 return ret;
199} 188}
200 189
@@ -217,28 +206,29 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
217 */ 206 */
218struct GNUNET_FS_FileInformation * 207struct GNUNET_FS_FileInformation *
219GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h, 208GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
220 void *client_info, 209 void *client_info,
221 uint64_t length, 210 uint64_t length,
222 void *data, 211 void *data,
223 const struct GNUNET_FS_Uri *keywords, 212 const struct GNUNET_FS_Uri
224 const struct GNUNET_CONTAINER_MetaData *meta, 213 *keywords,
225 int do_index, 214 const struct
226 const struct GNUNET_FS_BlockOptions *bo) 215 GNUNET_CONTAINER_MetaData *meta,
216 int do_index,
217 const struct GNUNET_FS_BlockOptions
218 *bo)
227{ 219{
228 if (GNUNET_YES == do_index) 220 if (GNUNET_YES == do_index)
229 { 221 {
230 GNUNET_break (0); 222 GNUNET_break (0);
231 return NULL; 223 return NULL;
232 } 224 }
233 return GNUNET_FS_file_information_create_from_reader (h, 225 return GNUNET_FS_file_information_create_from_reader (h,
234 client_info, 226 client_info,
235 length, 227 length,
236 &GNUNET_FS_data_reader_copy_, 228 &GNUNET_FS_data_reader_copy_,
237 data, 229 data,
238 keywords, 230 keywords,
239 meta, 231 meta, do_index, bo);
240 do_index,
241 bo);
242} 232}
243 233
244 234
@@ -260,31 +250,33 @@ GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
260 */ 250 */
261struct GNUNET_FS_FileInformation * 251struct GNUNET_FS_FileInformation *
262GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h, 252GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
263 void *client_info, 253 void *client_info,
264 uint64_t length, 254 uint64_t length,
265 GNUNET_FS_DataReader reader, 255 GNUNET_FS_DataReader reader,
266 void *reader_cls, 256 void *reader_cls,
267 const struct GNUNET_FS_Uri *keywords, 257 const struct GNUNET_FS_Uri
268 const struct GNUNET_CONTAINER_MetaData *meta, 258 *keywords,
269 int do_index, 259 const struct
270 const struct GNUNET_FS_BlockOptions *bo) 260 GNUNET_CONTAINER_MetaData *meta,
261 int do_index,
262 const struct
263 GNUNET_FS_BlockOptions *bo)
271{ 264{
272 struct GNUNET_FS_FileInformation *ret; 265 struct GNUNET_FS_FileInformation *ret;
273 266
274 if ( (GNUNET_YES == do_index) && 267 if ((GNUNET_YES == do_index) && (reader != &GNUNET_FS_data_reader_file_))
275 (reader != &GNUNET_FS_data_reader_file_) ) 268 {
276 { 269 GNUNET_break (0);
277 GNUNET_break (0); 270 return NULL;
278 return NULL; 271 }
279 }
280 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation)); 272 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
281 ret->h = h; 273 ret->h = h;
282 ret->client_info = client_info; 274 ret->client_info = client_info;
283 ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 275 ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
284 if (ret->meta == NULL) 276 if (ret->meta == NULL)
285 ret->meta = GNUNET_CONTAINER_meta_data_create (); 277 ret->meta = GNUNET_CONTAINER_meta_data_create ();
286 ret->keywords = (keywords == NULL) ? NULL : GNUNET_FS_uri_dup (keywords); 278 ret->keywords = (keywords == NULL) ? NULL : GNUNET_FS_uri_dup (keywords);
287 ret->data.file.reader = reader; 279 ret->data.file.reader = reader;
288 ret->data.file.reader_cls = reader_cls; 280 ret->data.file.reader_cls = reader_cls;
289 ret->data.file.do_index = do_index; 281 ret->data.file.do_index = do_index;
290 ret->data.file.file_size = length; 282 ret->data.file.file_size = length;
@@ -296,7 +288,7 @@ GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
296/** 288/**
297 * Closure for "dir_scan_cb". 289 * Closure for "dir_scan_cb".
298 */ 290 */
299struct DirScanCls 291struct DirScanCls
300{ 292{
301 /** 293 /**
302 * Metadata extractors to use. 294 * Metadata extractors to use.
@@ -305,14 +297,14 @@ struct DirScanCls
305 297
306 /** 298 /**
307 * Master context. 299 * Master context.
308 */ 300 */
309 struct GNUNET_FS_Handle *h; 301 struct GNUNET_FS_Handle *h;
310 302
311 /** 303 /**
312 * Function to call on each directory entry. 304 * Function to call on each directory entry.
313 */ 305 */
314 GNUNET_FS_FileProcessor proc; 306 GNUNET_FS_FileProcessor proc;
315 307
316 /** 308 /**
317 * Closure for proc. 309 * Closure for proc.
318 */ 310 */
@@ -331,7 +323,7 @@ struct DirScanCls
331 /** 323 /**
332 * Set to an error message (if any). 324 * Set to an error message (if any).
333 */ 325 */
334 char *emsg; 326 char *emsg;
335 327
336 /** 328 /**
337 * Block options. 329 * Block options.
@@ -340,7 +332,7 @@ struct DirScanCls
340 332
341 /** 333 /**
342 * Should files be indexed? 334 * Should files be indexed?
343 */ 335 */
344 int do_index; 336 int do_index;
345 337
346}; 338};
@@ -354,10 +346,9 @@ struct DirScanCls
354 * @return GNUNET_OK on success, GNUNET_SYSERR to abort 346 * @return GNUNET_OK on success, GNUNET_SYSERR to abort
355 */ 347 */
356static int 348static int
357dir_scan_cb (void *cls, 349dir_scan_cb (void *cls, const char *filename)
358 const char *filename)
359{ 350{
360 struct DirScanCls *dsc = cls; 351 struct DirScanCls *dsc = cls;
361 struct stat sbuf; 352 struct stat sbuf;
362 struct GNUNET_FS_FileInformation *fi; 353 struct GNUNET_FS_FileInformation *fi;
363 struct GNUNET_FS_Uri *ksk_uri; 354 struct GNUNET_FS_Uri *ksk_uri;
@@ -365,52 +356,44 @@ dir_scan_cb (void *cls,
365 struct GNUNET_CONTAINER_MetaData *meta; 356 struct GNUNET_CONTAINER_MetaData *meta;
366 357
367 if (0 != STAT (filename, &sbuf)) 358 if (0 != STAT (filename, &sbuf))
368 { 359 {
369 GNUNET_asprintf (&dsc->emsg, 360 GNUNET_asprintf (&dsc->emsg,
370 _("`%s' failed on file `%s': %s"), 361 _("`%s' failed on file `%s': %s"),
371 "stat", 362 "stat", filename, STRERROR (errno));
372 filename, 363 return GNUNET_SYSERR;
373 STRERROR (errno)); 364 }
374 return GNUNET_SYSERR;
375 }
376 if (S_ISDIR (sbuf.st_mode)) 365 if (S_ISDIR (sbuf.st_mode))
366 {
367 fi = GNUNET_FS_file_information_create_from_directory (dsc->h,
368 NULL,
369 filename,
370 dsc->scanner,
371 dsc->scanner_cls,
372 dsc->do_index,
373 dsc->bo, &dsc->emsg);
374 if (NULL == fi)
377 { 375 {
378 fi = GNUNET_FS_file_information_create_from_directory (dsc->h, 376 GNUNET_assert (NULL != dsc->emsg);
379 NULL, 377 return GNUNET_SYSERR;
380 filename,
381 dsc->scanner,
382 dsc->scanner_cls,
383 dsc->do_index,
384 dsc->bo,
385 &dsc->emsg);
386 if (NULL == fi)
387 {
388 GNUNET_assert (NULL != dsc->emsg);
389 return GNUNET_SYSERR;
390 }
391 } 378 }
379 }
392 else 380 else
393 { 381 {
394 meta = GNUNET_CONTAINER_meta_data_create (); 382 meta = GNUNET_CONTAINER_meta_data_create ();
395 GNUNET_FS_meta_data_extract_from_file (meta, 383 GNUNET_FS_meta_data_extract_from_file (meta, filename, dsc->extractors);
396 filename, 384 keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
397 dsc->extractors); 385 ksk_uri = GNUNET_FS_uri_ksk_canonicalize (keywords);
398 keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta); 386 fi = GNUNET_FS_file_information_create_from_file (dsc->h,
399 ksk_uri = GNUNET_FS_uri_ksk_canonicalize (keywords); 387 NULL,
400 fi = GNUNET_FS_file_information_create_from_file (dsc->h, 388 filename,
401 NULL, 389 ksk_uri,
402 filename, 390 meta,
403 ksk_uri, 391 dsc->do_index, dsc->bo);
404 meta, 392 GNUNET_CONTAINER_meta_data_destroy (meta);
405 dsc->do_index, 393 GNUNET_FS_uri_destroy (keywords);
406 dsc->bo); 394 GNUNET_FS_uri_destroy (ksk_uri);
407 GNUNET_CONTAINER_meta_data_destroy (meta); 395 }
408 GNUNET_FS_uri_destroy (keywords); 396 dsc->proc (dsc->proc_cls, filename, fi);
409 GNUNET_FS_uri_destroy (ksk_uri);
410 }
411 dsc->proc (dsc->proc_cls,
412 filename,
413 fi);
414 return GNUNET_OK; 397 return GNUNET_OK;
415} 398}
416 399
@@ -438,13 +421,12 @@ dir_scan_cb (void *cls,
438 */ 421 */
439int 422int
440GNUNET_FS_directory_scanner_default (void *cls, 423GNUNET_FS_directory_scanner_default (void *cls,
441 struct GNUNET_FS_Handle *h, 424 struct GNUNET_FS_Handle *h,
442 const char *dirname, 425 const char *dirname,
443 int do_index, 426 int do_index,
444 const struct GNUNET_FS_BlockOptions *bo, 427 const struct GNUNET_FS_BlockOptions *bo,
445 GNUNET_FS_FileProcessor proc, 428 GNUNET_FS_FileProcessor proc,
446 void *proc_cls, 429 void *proc_cls, char **emsg)
447 char **emsg)
448{ 430{
449 struct EXTRACTOR_PluginList *ex = cls; 431 struct EXTRACTOR_PluginList *ex = cls;
450 struct DirScanCls dsc; 432 struct DirScanCls dsc;
@@ -457,14 +439,12 @@ GNUNET_FS_directory_scanner_default (void *cls,
457 dsc.scanner_cls = cls; 439 dsc.scanner_cls = cls;
458 dsc.do_index = do_index; 440 dsc.do_index = do_index;
459 dsc.bo = bo; 441 dsc.bo = bo;
460 if (-1 == GNUNET_DISK_directory_scan (dirname, 442 if (-1 == GNUNET_DISK_directory_scan (dirname, &dir_scan_cb, &dsc))
461 &dir_scan_cb, 443 {
462 &dsc)) 444 GNUNET_assert (NULL != dsc.emsg);
463 { 445 *emsg = dsc.emsg;
464 GNUNET_assert (NULL != dsc.emsg); 446 return GNUNET_SYSERR;
465 *emsg = dsc.emsg; 447 }
466 return GNUNET_SYSERR;
467 }
468 return GNUNET_OK; 448 return GNUNET_OK;
469} 449}
470 450
@@ -491,9 +471,7 @@ struct EntryProcCls
491 * @param fi information for publishing the file 471 * @param fi information for publishing the file
492 */ 472 */
493static void 473static void
494dirproc (void *cls, 474dirproc (void *cls, const char *filename, struct GNUNET_FS_FileInformation *fi)
495 const char *filename,
496 struct GNUNET_FS_FileInformation *fi)
497{ 475{
498 struct EntryProcCls *dc = cls; 476 struct EntryProcCls *dc = cls;
499 477
@@ -526,13 +504,14 @@ dirproc (void *cls,
526 */ 504 */
527struct GNUNET_FS_FileInformation * 505struct GNUNET_FS_FileInformation *
528GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h, 506GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
529 void *client_info, 507 void *client_info,
530 const char *filename, 508 const char *filename,
531 GNUNET_FS_DirectoryScanner scanner, 509 GNUNET_FS_DirectoryScanner
532 void *scanner_cls, 510 scanner, void *scanner_cls,
533 int do_index, 511 int do_index,
534 const struct GNUNET_FS_BlockOptions *bo, 512 const struct
535 char **emsg) 513 GNUNET_FS_BlockOptions *bo,
514 char **emsg)
536{ 515{
537 struct GNUNET_FS_FileInformation *ret; 516 struct GNUNET_FS_FileInformation *ret;
538 struct EntryProcCls dc; 517 struct EntryProcCls dc;
@@ -545,43 +524,28 @@ GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
545 dc.entries = NULL; 524 dc.entries = NULL;
546 meta = GNUNET_CONTAINER_meta_data_create (); 525 meta = GNUNET_CONTAINER_meta_data_create ();
547 GNUNET_FS_meta_data_make_directory (meta); 526 GNUNET_FS_meta_data_make_directory (meta);
548 scanner (scanner_cls, 527 scanner (scanner_cls, h, filename, do_index, bo, &dirproc, &dc, emsg);
549 h, 528 ksk = NULL; // FIXME...
550 filename,
551 do_index,
552 bo,
553 &dirproc,
554 &dc,
555 emsg);
556 ksk = NULL; // FIXME...
557 // FIXME: create meta! 529 // FIXME: create meta!
558 ret = GNUNET_FS_file_information_create_empty_directory (h, 530 ret = GNUNET_FS_file_information_create_empty_directory (h,
559 client_info, 531 client_info,
560 ksk, 532 ksk, meta, bo);
561 meta,
562 bo);
563 GNUNET_CONTAINER_meta_data_destroy (meta); 533 GNUNET_CONTAINER_meta_data_destroy (meta);
564 ret->data.dir.entries = dc.entries; 534 ret->data.dir.entries = dc.entries;
565 while (dc.entries != NULL) 535 while (dc.entries != NULL)
566 { 536 {
567 dc.entries->dir = ret; 537 dc.entries->dir = ret;
568 dc.entries = dc.entries->next; 538 dc.entries = dc.entries->next;
569 } 539 }
570 fn = filename; 540 fn = filename;
571 while ( (NULL != (ss = strstr (fn, 541 while ((NULL != (ss = strstr (fn, DIR_SEPARATOR_STR))) && (strlen (ss) > 1))
572 DIR_SEPARATOR_STR))) &&
573 (strlen (ss) > 1) )
574 fn = ss + 1; 542 fn = ss + 1;
575 GNUNET_asprintf (&dn, 543 GNUNET_asprintf (&dn, "%s/", fn);
576 "%s/",
577 fn);
578 GNUNET_CONTAINER_meta_data_insert (ret->meta, 544 GNUNET_CONTAINER_meta_data_insert (ret->meta,
579 "<gnunet>", 545 "<gnunet>",
580 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, 546 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
581 EXTRACTOR_METAFORMAT_C_STRING, 547 EXTRACTOR_METAFORMAT_C_STRING,
582 "text/plain", 548 "text/plain", dn, strlen (dn) + 1);
583 dn,
584 strlen (dn) + 1);
585 GNUNET_free (dn); 549 GNUNET_free (dn);
586 ret->filename = GNUNET_strdup (filename); 550 ret->filename = GNUNET_strdup (filename);
587 return ret; 551 return ret;
@@ -595,7 +559,8 @@ GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
595 * @return GNUNET_YES if so, GNUNET_NO if not 559 * @return GNUNET_YES if so, GNUNET_NO if not
596 */ 560 */
597int 561int
598GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation *ent) 562GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
563 *ent)
599{ 564{
600 return ent->is_directory; 565 return ent->is_directory;
601} 566}
@@ -617,10 +582,14 @@ GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
617 */ 582 */
618struct GNUNET_FS_FileInformation * 583struct GNUNET_FS_FileInformation *
619GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h, 584GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
620 void *client_info, 585 void *client_info,
621 const struct GNUNET_FS_Uri *keywords, 586 const struct GNUNET_FS_Uri
622 const struct GNUNET_CONTAINER_MetaData *meta, 587 *keywords,
623 const struct GNUNET_FS_BlockOptions *bo) 588 const struct
589 GNUNET_CONTAINER_MetaData
590 *meta,
591 const struct
592 GNUNET_FS_BlockOptions *bo)
624{ 593{
625 struct GNUNET_FS_FileInformation *ret; 594 struct GNUNET_FS_FileInformation *ret;
626 595
@@ -648,15 +617,13 @@ GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
648 */ 617 */
649int 618int
650GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir, 619GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
651 struct GNUNET_FS_FileInformation *ent) 620 struct GNUNET_FS_FileInformation *ent)
652{ 621{
653 if ( (ent->dir != NULL) || 622 if ((ent->dir != NULL) || (ent->next != NULL) || (!dir->is_directory))
654 (ent->next != NULL) || 623 {
655 (! dir->is_directory) ) 624 GNUNET_break (0);
656 { 625 return GNUNET_SYSERR;
657 GNUNET_break (0); 626 }
658 return GNUNET_SYSERR;
659 }
660 ent->dir = dir; 627 ent->dir = dir;
661 ent->next = dir->data.dir.entries; 628 ent->next = dir->data.dir.entries;
662 dir->data.dir.entries = ent; 629 dir->data.dir.entries = ent;
@@ -681,41 +648,37 @@ GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
681 */ 648 */
682void 649void
683GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir, 650GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
684 GNUNET_FS_FileInformationProcessor proc, 651 GNUNET_FS_FileInformationProcessor proc,
685 void *proc_cls) 652 void *proc_cls)
686{ 653{
687 struct GNUNET_FS_FileInformation *pos; 654 struct GNUNET_FS_FileInformation *pos;
688 int no; 655 int no;
689 656
690 no = GNUNET_NO; 657 no = GNUNET_NO;
691 if (GNUNET_OK != 658 if (GNUNET_OK !=
692 proc (proc_cls, 659 proc (proc_cls,
693 dir, 660 dir,
694 (dir->is_directory) ? dir->data.dir.dir_size : dir->data.file.file_size, 661 (dir->is_directory) ? dir->data.dir.dir_size : dir->data.
695 dir->meta, 662 file.file_size, dir->meta, &dir->keywords, &dir->bo,
696 &dir->keywords, 663 (dir->is_directory) ? &no : &dir->data.file.do_index,
697 &dir->bo, 664 &dir->client_info))
698 (dir->is_directory) ? &no : &dir->data.file.do_index,
699 &dir->client_info))
700 return; 665 return;
701 if (! dir->is_directory) 666 if (!dir->is_directory)
702 return; 667 return;
703 pos = dir->data.dir.entries; 668 pos = dir->data.dir.entries;
704 while (pos != NULL) 669 while (pos != NULL)
705 { 670 {
706 no = GNUNET_NO; 671 no = GNUNET_NO;
707 if (GNUNET_OK != 672 if (GNUNET_OK !=
708 proc (proc_cls, 673 proc (proc_cls,
709 pos, 674 pos,
710 (pos->is_directory) ? pos->data.dir.dir_size : pos->data.file.file_size, 675 (pos->is_directory) ? pos->data.dir.dir_size : pos->data.
711 pos->meta, 676 file.file_size, pos->meta, &pos->keywords, &pos->bo,
712 &pos->keywords, 677 (dir->is_directory) ? &no : &dir->data.file.do_index,
713 &pos->bo, 678 &pos->client_info))
714 (dir->is_directory) ? &no : &dir->data.file.do_index, 679 break;
715 &pos->client_info)) 680 pos = pos->next;
716 break; 681 }
717 pos = pos->next;
718 }
719} 682}
720 683
721 684
@@ -731,70 +694,60 @@ GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
731 */ 694 */
732void 695void
733GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi, 696GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
734 GNUNET_FS_FileInformationProcessor cleaner, 697 GNUNET_FS_FileInformationProcessor cleaner,
735 void *cleaner_cls) 698 void *cleaner_cls)
736{ 699{
737 struct GNUNET_FS_FileInformation *pos; 700 struct GNUNET_FS_FileInformation *pos;
738 int no; 701 int no;
739 702
740 no = GNUNET_NO; 703 no = GNUNET_NO;
741 if (fi->is_directory) 704 if (fi->is_directory)
705 {
706 /* clean up directory */
707 while (NULL != (pos = fi->data.dir.entries))
742 { 708 {
743 /* clean up directory */ 709 fi->data.dir.entries = pos->next;
744 while (NULL != (pos = fi->data.dir.entries)) 710 GNUNET_FS_file_information_destroy (pos, cleaner, cleaner_cls);
745 {
746 fi->data.dir.entries = pos->next;
747 GNUNET_FS_file_information_destroy (pos, cleaner, cleaner_cls);
748 }
749 /* clean up client-info */
750 if (NULL != cleaner)
751 cleaner (cleaner_cls,
752 fi,
753 fi->data.dir.dir_size,
754 fi->meta,
755 &fi->keywords,
756 &fi->bo,
757 &no,
758 &fi->client_info);
759 GNUNET_free_non_null (fi->data.dir.dir_data);
760 } 711 }
712 /* clean up client-info */
713 if (NULL != cleaner)
714 cleaner (cleaner_cls,
715 fi,
716 fi->data.dir.dir_size,
717 fi->meta, &fi->keywords, &fi->bo, &no, &fi->client_info);
718 GNUNET_free_non_null (fi->data.dir.dir_data);
719 }
761 else 720 else
762 { 721 {
763 /* call clean-up function of the reader */ 722 /* call clean-up function of the reader */
764 if (fi->data.file.reader != NULL) 723 if (fi->data.file.reader != NULL)
765 fi->data.file.reader (fi->data.file.reader_cls, 0, 0, 724 fi->data.file.reader (fi->data.file.reader_cls, 0, 0, NULL, NULL);
766 NULL, NULL); 725 /* clean up client-info */
767 /* clean up client-info */ 726 if (NULL != cleaner)
768 if (NULL != cleaner) 727 cleaner (cleaner_cls,
769 cleaner (cleaner_cls, 728 fi,
770 fi, 729 fi->data.file.file_size,
771 fi->data.file.file_size, 730 fi->meta,
772 fi->meta, 731 &fi->keywords,
773 &fi->keywords, 732 &fi->bo, &fi->data.file.do_index, &fi->client_info);
774 &fi->bo, 733 }
775 &fi->data.file.do_index,
776 &fi->client_info);
777 }
778 GNUNET_free_non_null (fi->filename); 734 GNUNET_free_non_null (fi->filename);
779 GNUNET_free_non_null (fi->emsg); 735 GNUNET_free_non_null (fi->emsg);
780 GNUNET_free_non_null (fi->chk_uri); 736 GNUNET_free_non_null (fi->chk_uri);
781 /* clean up serialization */ 737 /* clean up serialization */
782 if ( (NULL != fi->serialization) && 738 if ((NULL != fi->serialization) && (0 != UNLINK (fi->serialization)))
783 (0 != UNLINK (fi->serialization)) )
784 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 739 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
785 "unlink", 740 "unlink", fi->serialization);
786 fi->serialization);
787 if (NULL != fi->keywords) 741 if (NULL != fi->keywords)
788 GNUNET_FS_uri_destroy (fi->keywords); 742 GNUNET_FS_uri_destroy (fi->keywords);
789 if (NULL != fi->meta) 743 if (NULL != fi->meta)
790 GNUNET_CONTAINER_meta_data_destroy (fi->meta); 744 GNUNET_CONTAINER_meta_data_destroy (fi->meta);
791 GNUNET_free_non_null (fi->serialization); 745 GNUNET_free_non_null (fi->serialization);
792 if (fi->te != NULL) 746 if (fi->te != NULL)
793 { 747 {
794 GNUNET_FS_tree_encoder_finish (fi->te, 748 GNUNET_FS_tree_encoder_finish (fi->te, NULL, NULL);
795 NULL, NULL); 749 fi->te = NULL;
796 fi->te = NULL; 750 }
797 }
798 GNUNET_free (fi); 751 GNUNET_free (fi);
799} 752}
800 753