summaryrefslogtreecommitdiff
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.c301
1 files changed, 151 insertions, 150 deletions
diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c
index dbcfd81c4..bbbc30a6e 100644
--- a/src/fs/fs_file_information.c
+++ b/src/fs/fs_file_information.c
@@ -42,7 +42,7 @@
42 * can be used to read this fi-struct from disk. 42 * can be used to read this fi-struct from disk.
43 */ 43 */
44const char * 44const char *
45GNUNET_FS_file_information_get_id(struct GNUNET_FS_FileInformation *s) 45GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s)
46{ 46{
47 if (NULL != s->dir) 47 if (NULL != s->dir)
48 return NULL; 48 return NULL;
@@ -56,7 +56,7 @@ GNUNET_FS_file_information_get_id(struct GNUNET_FS_FileInformation *s)
56 * @return "filename" field of the structure (can be NULL) 56 * @return "filename" field of the structure (can be NULL)
57 */ 57 */
58const char * 58const char *
59GNUNET_FS_file_information_get_filename(struct GNUNET_FS_FileInformation *s) 59GNUNET_FS_file_information_get_filename (struct GNUNET_FS_FileInformation *s)
60{ 60{
61 return s->filename; 61 return s->filename;
62} 62}
@@ -71,12 +71,12 @@ GNUNET_FS_file_information_get_filename(struct GNUNET_FS_FileInformation *s)
71 * @param filename filename to set 71 * @param filename filename to set
72 */ 72 */
73void 73void
74GNUNET_FS_file_information_set_filename(struct GNUNET_FS_FileInformation *s, 74GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s,
75 const char *filename) 75 const char *filename)
76{ 76{
77 GNUNET_free_non_null(s->filename); 77 GNUNET_free_non_null (s->filename);
78 if (filename) 78 if (filename)
79 s->filename = GNUNET_strdup(filename); 79 s->filename = GNUNET_strdup (filename);
80 else 80 else
81 s->filename = NULL; 81 s->filename = NULL;
82} 82}
@@ -97,7 +97,7 @@ 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 */
99struct GNUNET_FS_FileInformation * 99struct GNUNET_FS_FileInformation *
100GNUNET_FS_file_information_create_from_file( 100GNUNET_FS_file_information_create_from_file (
101 struct GNUNET_FS_Handle *h, 101 struct GNUNET_FS_Handle *h,
102 void *client_info, 102 void *client_info,
103 const char *filename, 103 const char *filename,
@@ -114,44 +114,44 @@ GNUNET_FS_file_information_create_from_file(
114 114
115 /* FIXME: should include_symbolic_links be GNUNET_NO or GNUNET_YES here? */ 115 /* FIXME: should include_symbolic_links be GNUNET_NO or GNUNET_YES here? */
116 if (GNUNET_OK != 116 if (GNUNET_OK !=
117 GNUNET_DISK_file_size(filename, &fsize, GNUNET_NO, GNUNET_YES)) 117 GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES))
118 { 118 {
119 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "stat", filename); 119 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
120 return NULL; 120 return NULL;
121 } 121 }
122 fi = GNUNET_FS_make_file_reader_context_(filename); 122 fi = GNUNET_FS_make_file_reader_context_ (filename);
123 if (NULL == fi) 123 if (NULL == fi)
124 { 124 {
125 GNUNET_break(0); 125 GNUNET_break (0);
126 return NULL; 126 return NULL;
127 } 127 }
128 ret = 128 ret =
129 GNUNET_FS_file_information_create_from_reader(h, 129 GNUNET_FS_file_information_create_from_reader (h,
130 client_info, 130 client_info,
131 fsize, 131 fsize,
132 &GNUNET_FS_data_reader_file_, 132 &GNUNET_FS_data_reader_file_,
133 fi, 133 fi,
134 keywords, 134 keywords,
135 meta, 135 meta,
136 do_index, 136 do_index,
137 bo); 137 bo);
138 if (ret == NULL) 138 if (ret == NULL)
139 return NULL; 139 return NULL;
140 ret->h = h; 140 ret->h = h;
141 ret->filename = GNUNET_strdup(filename); 141 ret->filename = GNUNET_strdup (filename);
142 fn = filename; 142 fn = filename;
143 while (NULL != (ss = strstr(fn, DIR_SEPARATOR_STR))) 143 while (NULL != (ss = strstr (fn, DIR_SEPARATOR_STR)))
144 fn = ss + 1; 144 fn = ss + 1;
145/* FIXME: If we assume that on other platforms CRT is UTF-8-aware, then 145/* FIXME: If we assume that on other platforms CRT is UTF-8-aware, then
146 * this should be changed to EXTRACTOR_METAFORMAT_UTF8 146 * this should be changed to EXTRACTOR_METAFORMAT_UTF8
147 */ 147 */
148 GNUNET_CONTAINER_meta_data_insert(ret->meta, 148 GNUNET_CONTAINER_meta_data_insert (ret->meta,
149 "<gnunet>", 149 "<gnunet>",
150 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, 150 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
151 EXTRACTOR_METAFORMAT_C_STRING, 151 EXTRACTOR_METAFORMAT_C_STRING,
152 "text/plain", 152 "text/plain",
153 fn, 153 fn,
154 strlen(fn) + 1); 154 strlen (fn) + 1);
155 return ret; 155 return ret;
156} 156}
157 157
@@ -173,7 +173,7 @@ GNUNET_FS_file_information_create_from_file(
173 * @return publish structure entry for the file 173 * @return publish structure entry for the file
174 */ 174 */
175struct GNUNET_FS_FileInformation * 175struct GNUNET_FS_FileInformation *
176GNUNET_FS_file_information_create_from_data( 176GNUNET_FS_file_information_create_from_data (
177 struct GNUNET_FS_Handle *h, 177 struct GNUNET_FS_Handle *h,
178 void *client_info, 178 void *client_info,
179 uint64_t length, 179 uint64_t length,
@@ -184,19 +184,20 @@ GNUNET_FS_file_information_create_from_data(
184 const struct GNUNET_FS_BlockOptions *bo) 184 const struct GNUNET_FS_BlockOptions *bo)
185{ 185{
186 if (GNUNET_YES == do_index) 186 if (GNUNET_YES == do_index)
187 { 187 {
188 GNUNET_break(0); 188 GNUNET_break (0);
189 return NULL; 189 return NULL;
190 } 190 }
191 return GNUNET_FS_file_information_create_from_reader(h, 191 return GNUNET_FS_file_information_create_from_reader (h,
192 client_info, 192 client_info,
193 length, 193 length,
194 &GNUNET_FS_data_reader_copy_, 194 &
195 data, 195 GNUNET_FS_data_reader_copy_,
196 keywords, 196 data,
197 meta, 197 keywords,
198 do_index, 198 meta,
199 bo); 199 do_index,
200 bo);
200} 201}
201 202
202 203
@@ -217,7 +218,7 @@ GNUNET_FS_file_information_create_from_data(
217 * @return publish structure entry for the file 218 * @return publish structure entry for the file
218 */ 219 */
219struct GNUNET_FS_FileInformation * 220struct GNUNET_FS_FileInformation *
220GNUNET_FS_file_information_create_from_reader( 221GNUNET_FS_file_information_create_from_reader (
221 struct GNUNET_FS_Handle *h, 222 struct GNUNET_FS_Handle *h,
222 void *client_info, 223 void *client_info,
223 uint64_t length, 224 uint64_t length,
@@ -231,17 +232,17 @@ GNUNET_FS_file_information_create_from_reader(
231 struct GNUNET_FS_FileInformation *ret; 232 struct GNUNET_FS_FileInformation *ret;
232 233
233 if ((GNUNET_YES == do_index) && (reader != &GNUNET_FS_data_reader_file_)) 234 if ((GNUNET_YES == do_index) && (reader != &GNUNET_FS_data_reader_file_))
234 { 235 {
235 GNUNET_break(0); 236 GNUNET_break (0);
236 return NULL; 237 return NULL;
237 } 238 }
238 ret = GNUNET_new(struct GNUNET_FS_FileInformation); 239 ret = GNUNET_new (struct GNUNET_FS_FileInformation);
239 ret->h = h; 240 ret->h = h;
240 ret->client_info = client_info; 241 ret->client_info = client_info;
241 ret->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); 242 ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
242 if (ret->meta == NULL) 243 if (ret->meta == NULL)
243 ret->meta = GNUNET_CONTAINER_meta_data_create(); 244 ret->meta = GNUNET_CONTAINER_meta_data_create ();
244 ret->keywords = (keywords == NULL) ? NULL : GNUNET_FS_uri_dup(keywords); 245 ret->keywords = (keywords == NULL) ? NULL : GNUNET_FS_uri_dup (keywords);
245 ret->data.file.reader = reader; 246 ret->data.file.reader = reader;
246 ret->data.file.reader_cls = reader_cls; 247 ret->data.file.reader_cls = reader_cls;
247 ret->data.file.do_index = do_index; 248 ret->data.file.do_index = do_index;
@@ -258,7 +259,7 @@ GNUNET_FS_file_information_create_from_reader(
258 * @return #GNUNET_YES if so, #GNUNET_NO if not 259 * @return #GNUNET_YES if so, #GNUNET_NO if not
259 */ 260 */
260int 261int
261GNUNET_FS_file_information_is_directory( 262GNUNET_FS_file_information_is_directory (
262 const struct GNUNET_FS_FileInformation *ent) 263 const struct GNUNET_FS_FileInformation *ent)
263{ 264{
264 return ent->is_directory; 265 return ent->is_directory;
@@ -278,7 +279,7 @@ GNUNET_FS_file_information_is_directory(
278 * @return publish structure entry for the directory , NULL on error 279 * @return publish structure entry for the directory , NULL on error
279 */ 280 */
280struct GNUNET_FS_FileInformation * 281struct GNUNET_FS_FileInformation *
281GNUNET_FS_file_information_create_empty_directory( 282GNUNET_FS_file_information_create_empty_directory (
282 struct GNUNET_FS_Handle *h, 283 struct GNUNET_FS_Handle *h,
283 void *client_info, 284 void *client_info,
284 const struct GNUNET_FS_Uri *keywords, 285 const struct GNUNET_FS_Uri *keywords,
@@ -288,15 +289,15 @@ GNUNET_FS_file_information_create_empty_directory(
288{ 289{
289 struct GNUNET_FS_FileInformation *ret; 290 struct GNUNET_FS_FileInformation *ret;
290 291
291 ret = GNUNET_new(struct GNUNET_FS_FileInformation); 292 ret = GNUNET_new (struct GNUNET_FS_FileInformation);
292 ret->h = h; 293 ret->h = h;
293 ret->client_info = client_info; 294 ret->client_info = client_info;
294 ret->meta = GNUNET_CONTAINER_meta_data_duplicate(meta); 295 ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
295 ret->keywords = GNUNET_FS_uri_dup(keywords); 296 ret->keywords = GNUNET_FS_uri_dup (keywords);
296 ret->bo = *bo; 297 ret->bo = *bo;
297 ret->is_directory = GNUNET_YES; 298 ret->is_directory = GNUNET_YES;
298 if (filename != NULL) 299 if (filename != NULL)
299 ret->filename = GNUNET_strdup(filename); 300 ret->filename = GNUNET_strdup (filename);
300 return ret; 301 return ret;
301} 302}
302 303
@@ -313,15 +314,15 @@ GNUNET_FS_file_information_create_empty_directory(
313 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 314 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
314 */ 315 */
315int 316int
316GNUNET_FS_file_information_add(struct GNUNET_FS_FileInformation *dir, 317GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
317 struct GNUNET_FS_FileInformation *ent) 318 struct GNUNET_FS_FileInformation *ent)
318{ 319{
319 if ((ent->dir != NULL) || (ent->next != NULL) || 320 if ((ent->dir != NULL) || (ent->next != NULL) ||
320 (dir->is_directory != GNUNET_YES)) 321 (dir->is_directory != GNUNET_YES))
321 { 322 {
322 GNUNET_break(0); 323 GNUNET_break (0);
323 return GNUNET_SYSERR; 324 return GNUNET_SYSERR;
324 } 325 }
325 ent->dir = dir; 326 ent->dir = dir;
326 ent->next = dir->data.dir.entries; 327 ent->next = dir->data.dir.entries;
327 dir->data.dir.entries = ent; 328 dir->data.dir.entries = ent;
@@ -345,45 +346,45 @@ GNUNET_FS_file_information_add(struct GNUNET_FS_FileInformation *dir,
345 * @param proc_cls closure for @a proc 346 * @param proc_cls closure for @a proc
346 */ 347 */
347void 348void
348GNUNET_FS_file_information_inspect(struct GNUNET_FS_FileInformation *dir, 349GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
349 GNUNET_FS_FileInformationProcessor proc, 350 GNUNET_FS_FileInformationProcessor proc,
350 void *proc_cls) 351 void *proc_cls)
351{ 352{
352 struct GNUNET_FS_FileInformation *pos; 353 struct GNUNET_FS_FileInformation *pos;
353 int no; 354 int no;
354 355
355 no = GNUNET_NO; 356 no = GNUNET_NO;
356 if (GNUNET_OK != 357 if (GNUNET_OK !=
357 proc(proc_cls, 358 proc (proc_cls,
358 dir, 359 dir,
359 (dir->is_directory == GNUNET_YES) ? dir->data.dir.dir_size 360 (dir->is_directory == GNUNET_YES) ? dir->data.dir.dir_size
360 : dir->data.file.file_size, 361 : dir->data.file.file_size,
361 dir->meta, 362 dir->meta,
362 &dir->keywords, 363 &dir->keywords,
363 &dir->bo, 364 &dir->bo,
364 (dir->is_directory == GNUNET_YES) ? &no : &dir->data.file.do_index, 365 (dir->is_directory == GNUNET_YES) ? &no : &dir->data.file.do_index,
365 &dir->client_info)) 366 &dir->client_info))
366 return; 367 return;
367 if (dir->is_directory != GNUNET_YES) 368 if (dir->is_directory != GNUNET_YES)
368 return; 369 return;
369 pos = dir->data.dir.entries; 370 pos = dir->data.dir.entries;
370 while (pos != NULL) 371 while (pos != NULL)
371 { 372 {
372 no = GNUNET_NO; 373 no = GNUNET_NO;
373 if (GNUNET_OK != 374 if (GNUNET_OK !=
374 proc(proc_cls, 375 proc (proc_cls,
375 pos, 376 pos,
376 (pos->is_directory == GNUNET_YES) ? pos->data.dir.dir_size 377 (pos->is_directory == GNUNET_YES) ? pos->data.dir.dir_size
377 : pos->data.file.file_size, 378 : pos->data.file.file_size,
378 pos->meta, 379 pos->meta,
379 &pos->keywords, 380 &pos->keywords,
380 &pos->bo, 381 &pos->bo,
381 (pos->is_directory == GNUNET_YES) ? &no 382 (pos->is_directory == GNUNET_YES) ? &no
382 : &pos->data.file.do_index, 383 : &pos->data.file.do_index,
383 &pos->client_info)) 384 &pos->client_info))
384 break; 385 break;
385 pos = pos->next; 386 pos = pos->next;
386 } 387 }
387} 388}
388 389
389 390
@@ -398,75 +399,75 @@ GNUNET_FS_file_information_inspect(struct GNUNET_FS_FileInformation *dir,
398 * @param cleaner_cls closure for @a cleaner 399 * @param cleaner_cls closure for @a cleaner
399 */ 400 */
400void 401void
401GNUNET_FS_file_information_destroy(struct GNUNET_FS_FileInformation *fi, 402GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
402 GNUNET_FS_FileInformationProcessor cleaner, 403 GNUNET_FS_FileInformationProcessor cleaner,
403 void *cleaner_cls) 404 void *cleaner_cls)
404{ 405{
405 struct GNUNET_FS_FileInformation *pos; 406 struct GNUNET_FS_FileInformation *pos;
406 int no; 407 int no;
407 408
408 no = GNUNET_NO; 409 no = GNUNET_NO;
409 if (GNUNET_YES == fi->is_directory) 410 if (GNUNET_YES == fi->is_directory)
411 {
412 /* clean up directory */
413 while (NULL != (pos = fi->data.dir.entries))
410 { 414 {
411 /* clean up directory */ 415 fi->data.dir.entries = pos->next;
412 while (NULL != (pos = fi->data.dir.entries)) 416 GNUNET_FS_file_information_destroy (pos, cleaner, cleaner_cls);
413 {
414 fi->data.dir.entries = pos->next;
415 GNUNET_FS_file_information_destroy(pos, cleaner, cleaner_cls);
416 }
417 /* clean up client-info */
418 if (NULL != cleaner)
419 cleaner(cleaner_cls,
420 fi,
421 fi->data.dir.dir_size,
422 fi->meta,
423 &fi->keywords,
424 &fi->bo,
425 &no,
426 &fi->client_info);
427 GNUNET_free_non_null(fi->data.dir.dir_data);
428 } 417 }
418 /* clean up client-info */
419 if (NULL != cleaner)
420 cleaner (cleaner_cls,
421 fi,
422 fi->data.dir.dir_size,
423 fi->meta,
424 &fi->keywords,
425 &fi->bo,
426 &no,
427 &fi->client_info);
428 GNUNET_free_non_null (fi->data.dir.dir_data);
429 }
429 else 430 else
431 {
432 /* call clean-up function of the reader */
433 if (NULL != fi->data.file.reader)
430 { 434 {
431 /* call clean-up function of the reader */ 435 (void) fi->data.file.reader (fi->data.file.reader_cls, 0, 0, NULL, NULL);
432 if (NULL != fi->data.file.reader) 436 fi->data.file.reader = NULL;
433 {
434 (void)fi->data.file.reader(fi->data.file.reader_cls, 0, 0, NULL, NULL);
435 fi->data.file.reader = NULL;
436 }
437 /* clean up client-info */
438 if (NULL != cleaner)
439 cleaner(cleaner_cls,
440 fi,
441 fi->data.file.file_size,
442 fi->meta,
443 &fi->keywords,
444 &fi->bo,
445 &fi->data.file.do_index,
446 &fi->client_info);
447 } 437 }
448 GNUNET_free_non_null(fi->filename); 438 /* clean up client-info */
449 GNUNET_free_non_null(fi->emsg); 439 if (NULL != cleaner)
440 cleaner (cleaner_cls,
441 fi,
442 fi->data.file.file_size,
443 fi->meta,
444 &fi->keywords,
445 &fi->bo,
446 &fi->data.file.do_index,
447 &fi->client_info);
448 }
449 GNUNET_free_non_null (fi->filename);
450 GNUNET_free_non_null (fi->emsg);
450 if (NULL != fi->sks_uri) 451 if (NULL != fi->sks_uri)
451 GNUNET_FS_uri_destroy(fi->sks_uri); 452 GNUNET_FS_uri_destroy (fi->sks_uri);
452 if (NULL != fi->chk_uri) 453 if (NULL != fi->chk_uri)
453 GNUNET_FS_uri_destroy(fi->chk_uri); 454 GNUNET_FS_uri_destroy (fi->chk_uri);
454 /* clean up serialization */ 455 /* clean up serialization */
455 if ((NULL != fi->serialization) && (0 != unlink(fi->serialization))) 456 if ((NULL != fi->serialization) && (0 != unlink (fi->serialization)))
456 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, 457 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
457 "unlink", 458 "unlink",
458 fi->serialization); 459 fi->serialization);
459 if (NULL != fi->keywords) 460 if (NULL != fi->keywords)
460 GNUNET_FS_uri_destroy(fi->keywords); 461 GNUNET_FS_uri_destroy (fi->keywords);
461 if (NULL != fi->meta) 462 if (NULL != fi->meta)
462 GNUNET_CONTAINER_meta_data_destroy(fi->meta); 463 GNUNET_CONTAINER_meta_data_destroy (fi->meta);
463 GNUNET_free_non_null(fi->serialization); 464 GNUNET_free_non_null (fi->serialization);
464 if (NULL != fi->te) 465 if (NULL != fi->te)
465 { 466 {
466 GNUNET_FS_tree_encoder_finish(fi->te, NULL); 467 GNUNET_FS_tree_encoder_finish (fi->te, NULL);
467 fi->te = NULL; 468 fi->te = NULL;
468 } 469 }
469 GNUNET_free(fi); 470 GNUNET_free (fi);
470} 471}
471 472
472 473