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.c324
1 files changed, 162 insertions, 162 deletions
diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c
index fbf3181ef..ccba1a8b4 100644
--- a/src/fs/fs_file_information.c
+++ b/src/fs/fs_file_information.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file fs/fs_file_information.c 22 * @file 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,
@@ -118,58 +118,58 @@ GNUNET_FS_file_information_create_from_file (
118 118
119 /* 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? */
120 if (GNUNET_OK != 120 if (GNUNET_OK !=
121 GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES)) 121 GNUNET_DISK_file_size(filename, &fsize, GNUNET_NO, GNUNET_YES))
122 { 122 {
123 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename); 123 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "stat", filename);
124 return NULL; 124 return NULL;
125 } 125 }
126 fi = GNUNET_FS_make_file_reader_context_ (filename); 126 fi = GNUNET_FS_make_file_reader_context_(filename);
127 if (NULL == fi) 127 if (NULL == fi)
128 { 128 {
129 GNUNET_break (0); 129 GNUNET_break(0);
130 return NULL; 130 return NULL;
131 } 131 }
132 ret = 132 ret =
133 GNUNET_FS_file_information_create_from_reader (h, 133 GNUNET_FS_file_information_create_from_reader(h,
134 client_info, 134 client_info,
135 fsize, 135 fsize,
136 &GNUNET_FS_data_reader_file_, 136 &GNUNET_FS_data_reader_file_,
137 fi, 137 fi,
138 keywords, 138 keywords,
139 meta, 139 meta,
140 do_index, 140 do_index,
141 bo); 141 bo);
142 if (ret == NULL) 142 if (ret == NULL)
143 return NULL; 143 return NULL;
144 ret->h = h; 144 ret->h = h;
145 ret->filename = GNUNET_strdup (filename); 145 ret->filename = GNUNET_strdup(filename);
146#if ! WINDOWS 146#if !WINDOWS
147 fn = filename; 147 fn = filename;
148#else 148#else
149 plibc_conv_to_win_path (filename, fn_conv); 149 plibc_conv_to_win_path(filename, fn_conv);
150 fn = fn_conv; 150 fn = fn_conv;
151#endif 151#endif
152 while (NULL != (ss = strstr (fn, DIR_SEPARATOR_STR))) 152 while (NULL != (ss = strstr(fn, DIR_SEPARATOR_STR)))
153 fn = ss + 1; 153 fn = ss + 1;
154/* 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
155 * this should be changed to EXTRACTOR_METAFORMAT_UTF8 155 * this should be changed to EXTRACTOR_METAFORMAT_UTF8
156 */ 156 */
157#if ! WINDOWS 157#if !WINDOWS
158 GNUNET_CONTAINER_meta_data_insert (ret->meta, 158 GNUNET_CONTAINER_meta_data_insert(ret->meta,
159 "<gnunet>", 159 "<gnunet>",
160 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, 160 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
161 EXTRACTOR_METAFORMAT_C_STRING, 161 EXTRACTOR_METAFORMAT_C_STRING,
162 "text/plain", 162 "text/plain",
163 fn, 163 fn,
164 strlen (fn) + 1); 164 strlen(fn) + 1);
165#else 165#else
166 GNUNET_CONTAINER_meta_data_insert (ret->meta, 166 GNUNET_CONTAINER_meta_data_insert(ret->meta,
167 "<gnunet>", 167 "<gnunet>",
168 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, 168 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
169 EXTRACTOR_METAFORMAT_UTF8, 169 EXTRACTOR_METAFORMAT_UTF8,
170 "text/plain", 170 "text/plain",
171 fn, 171 fn,
172 strlen (fn) + 1); 172 strlen(fn) + 1);
173#endif 173#endif
174 return ret; 174 return ret;
175} 175}
@@ -192,7 +192,7 @@ GNUNET_FS_file_information_create_from_file (
192 * @return publish structure entry for the file 192 * @return publish structure entry for the file
193 */ 193 */
194struct GNUNET_FS_FileInformation * 194struct GNUNET_FS_FileInformation *
195GNUNET_FS_file_information_create_from_data ( 195GNUNET_FS_file_information_create_from_data(
196 struct GNUNET_FS_Handle *h, 196 struct GNUNET_FS_Handle *h,
197 void *client_info, 197 void *client_info,
198 uint64_t length, 198 uint64_t length,
@@ -203,19 +203,19 @@ GNUNET_FS_file_information_create_from_data (
203 const struct GNUNET_FS_BlockOptions *bo) 203 const struct GNUNET_FS_BlockOptions *bo)
204{ 204{
205 if (GNUNET_YES == do_index) 205 if (GNUNET_YES == do_index)
206 { 206 {
207 GNUNET_break (0); 207 GNUNET_break(0);
208 return NULL; 208 return NULL;
209 } 209 }
210 return GNUNET_FS_file_information_create_from_reader (h, 210 return GNUNET_FS_file_information_create_from_reader(h,
211 client_info, 211 client_info,
212 length, 212 length,
213 &GNUNET_FS_data_reader_copy_, 213 &GNUNET_FS_data_reader_copy_,
214 data, 214 data,
215 keywords, 215 keywords,
216 meta, 216 meta,
217 do_index, 217 do_index,
218 bo); 218 bo);
219} 219}
220 220
221 221
@@ -236,7 +236,7 @@ GNUNET_FS_file_information_create_from_data (
236 * @return publish structure entry for the file 236 * @return publish structure entry for the file
237 */ 237 */
238struct GNUNET_FS_FileInformation * 238struct GNUNET_FS_FileInformation *
239GNUNET_FS_file_information_create_from_reader ( 239GNUNET_FS_file_information_create_from_reader(
240 struct GNUNET_FS_Handle *h, 240 struct GNUNET_FS_Handle *h,
241 void *client_info, 241 void *client_info,
242 uint64_t length, 242 uint64_t length,
@@ -250,17 +250,17 @@ GNUNET_FS_file_information_create_from_reader (
250 struct GNUNET_FS_FileInformation *ret; 250 struct GNUNET_FS_FileInformation *ret;
251 251
252 if ((GNUNET_YES == do_index) && (reader != &GNUNET_FS_data_reader_file_)) 252 if ((GNUNET_YES == do_index) && (reader != &GNUNET_FS_data_reader_file_))
253 { 253 {
254 GNUNET_break (0); 254 GNUNET_break(0);
255 return NULL; 255 return NULL;
256 } 256 }
257 ret = GNUNET_new (struct GNUNET_FS_FileInformation); 257 ret = GNUNET_new(struct GNUNET_FS_FileInformation);
258 ret->h = h; 258 ret->h = h;
259 ret->client_info = client_info; 259 ret->client_info = client_info;
260 ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 260 ret->meta = GNUNET_CONTAINER_meta_data_duplicate(meta);
261 if (ret->meta == NULL) 261 if (ret->meta == NULL)
262 ret->meta = GNUNET_CONTAINER_meta_data_create (); 262 ret->meta = GNUNET_CONTAINER_meta_data_create();
263 ret->keywords = (keywords == NULL) ? NULL : GNUNET_FS_uri_dup (keywords); 263 ret->keywords = (keywords == NULL) ? NULL : GNUNET_FS_uri_dup(keywords);
264 ret->data.file.reader = reader; 264 ret->data.file.reader = reader;
265 ret->data.file.reader_cls = reader_cls; 265 ret->data.file.reader_cls = reader_cls;
266 ret->data.file.do_index = do_index; 266 ret->data.file.do_index = do_index;
@@ -277,7 +277,7 @@ GNUNET_FS_file_information_create_from_reader (
277 * @return #GNUNET_YES if so, #GNUNET_NO if not 277 * @return #GNUNET_YES if so, #GNUNET_NO if not
278 */ 278 */
279int 279int
280GNUNET_FS_file_information_is_directory ( 280GNUNET_FS_file_information_is_directory(
281 const struct GNUNET_FS_FileInformation *ent) 281 const struct GNUNET_FS_FileInformation *ent)
282{ 282{
283 return ent->is_directory; 283 return ent->is_directory;
@@ -297,7 +297,7 @@ GNUNET_FS_file_information_is_directory (
297 * @return publish structure entry for the directory , NULL on error 297 * @return publish structure entry for the directory , NULL on error
298 */ 298 */
299struct GNUNET_FS_FileInformation * 299struct GNUNET_FS_FileInformation *
300GNUNET_FS_file_information_create_empty_directory ( 300GNUNET_FS_file_information_create_empty_directory(
301 struct GNUNET_FS_Handle *h, 301 struct GNUNET_FS_Handle *h,
302 void *client_info, 302 void *client_info,
303 const struct GNUNET_FS_Uri *keywords, 303 const struct GNUNET_FS_Uri *keywords,
@@ -307,15 +307,15 @@ GNUNET_FS_file_information_create_empty_directory (
307{ 307{
308 struct GNUNET_FS_FileInformation *ret; 308 struct GNUNET_FS_FileInformation *ret;
309 309
310 ret = GNUNET_new (struct GNUNET_FS_FileInformation); 310 ret = GNUNET_new(struct GNUNET_FS_FileInformation);
311 ret->h = h; 311 ret->h = h;
312 ret->client_info = client_info; 312 ret->client_info = client_info;
313 ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 313 ret->meta = GNUNET_CONTAINER_meta_data_duplicate(meta);
314 ret->keywords = GNUNET_FS_uri_dup (keywords); 314 ret->keywords = GNUNET_FS_uri_dup(keywords);
315 ret->bo = *bo; 315 ret->bo = *bo;
316 ret->is_directory = GNUNET_YES; 316 ret->is_directory = GNUNET_YES;
317 if (filename != NULL) 317 if (filename != NULL)
318 ret->filename = GNUNET_strdup (filename); 318 ret->filename = GNUNET_strdup(filename);
319 return ret; 319 return ret;
320} 320}
321 321
@@ -332,15 +332,15 @@ GNUNET_FS_file_information_create_empty_directory (
332 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 332 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
333 */ 333 */
334int 334int
335GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir, 335GNUNET_FS_file_information_add(struct GNUNET_FS_FileInformation *dir,
336 struct GNUNET_FS_FileInformation *ent) 336 struct GNUNET_FS_FileInformation *ent)
337{ 337{
338 if ((ent->dir != NULL) || (ent->next != NULL) || 338 if ((ent->dir != NULL) || (ent->next != NULL) ||
339 (dir->is_directory != GNUNET_YES)) 339 (dir->is_directory != GNUNET_YES))
340 { 340 {
341 GNUNET_break (0); 341 GNUNET_break(0);
342 return GNUNET_SYSERR; 342 return GNUNET_SYSERR;
343 } 343 }
344 ent->dir = dir; 344 ent->dir = dir;
345 ent->next = dir->data.dir.entries; 345 ent->next = dir->data.dir.entries;
346 dir->data.dir.entries = ent; 346 dir->data.dir.entries = ent;
@@ -364,45 +364,45 @@ GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
364 * @param proc_cls closure for @a proc 364 * @param proc_cls closure for @a proc
365 */ 365 */
366void 366void
367GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir, 367GNUNET_FS_file_information_inspect(struct GNUNET_FS_FileInformation *dir,
368 GNUNET_FS_FileInformationProcessor proc, 368 GNUNET_FS_FileInformationProcessor proc,
369 void *proc_cls) 369 void *proc_cls)
370{ 370{
371 struct GNUNET_FS_FileInformation *pos; 371 struct GNUNET_FS_FileInformation *pos;
372 int no; 372 int no;
373 373
374 no = GNUNET_NO; 374 no = GNUNET_NO;
375 if (GNUNET_OK != 375 if (GNUNET_OK !=
376 proc (proc_cls, 376 proc(proc_cls,
377 dir, 377 dir,
378 (dir->is_directory == GNUNET_YES) ? dir->data.dir.dir_size 378 (dir->is_directory == GNUNET_YES) ? dir->data.dir.dir_size
379 : dir->data.file.file_size, 379 : dir->data.file.file_size,
380 dir->meta, 380 dir->meta,
381 &dir->keywords, 381 &dir->keywords,
382 &dir->bo, 382 &dir->bo,
383 (dir->is_directory == GNUNET_YES) ? &no : &dir->data.file.do_index, 383 (dir->is_directory == GNUNET_YES) ? &no : &dir->data.file.do_index,
384 &dir->client_info)) 384 &dir->client_info))
385 return; 385 return;
386 if (dir->is_directory != GNUNET_YES) 386 if (dir->is_directory != GNUNET_YES)
387 return; 387 return;
388 pos = dir->data.dir.entries; 388 pos = dir->data.dir.entries;
389 while (pos != NULL) 389 while (pos != NULL)
390 { 390 {
391 no = GNUNET_NO; 391 no = GNUNET_NO;
392 if (GNUNET_OK != 392 if (GNUNET_OK !=
393 proc (proc_cls, 393 proc(proc_cls,
394 pos, 394 pos,
395 (pos->is_directory == GNUNET_YES) ? pos->data.dir.dir_size 395 (pos->is_directory == GNUNET_YES) ? pos->data.dir.dir_size
396 : pos->data.file.file_size, 396 : pos->data.file.file_size,
397 pos->meta, 397 pos->meta,
398 &pos->keywords, 398 &pos->keywords,
399 &pos->bo, 399 &pos->bo,
400 (pos->is_directory == GNUNET_YES) ? &no 400 (pos->is_directory == GNUNET_YES) ? &no
401 : &pos->data.file.do_index, 401 : &pos->data.file.do_index,
402 &pos->client_info)) 402 &pos->client_info))
403 break; 403 break;
404 pos = pos->next; 404 pos = pos->next;
405 } 405 }
406} 406}
407 407
408 408
@@ -417,75 +417,75 @@ GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
417 * @param cleaner_cls closure for @a cleaner 417 * @param cleaner_cls closure for @a cleaner
418 */ 418 */
419void 419void
420GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi, 420GNUNET_FS_file_information_destroy(struct GNUNET_FS_FileInformation *fi,
421 GNUNET_FS_FileInformationProcessor cleaner, 421 GNUNET_FS_FileInformationProcessor cleaner,
422 void *cleaner_cls) 422 void *cleaner_cls)
423{ 423{
424 struct GNUNET_FS_FileInformation *pos; 424 struct GNUNET_FS_FileInformation *pos;
425 int no; 425 int no;
426 426
427 no = GNUNET_NO; 427 no = GNUNET_NO;
428 if (GNUNET_YES == fi->is_directory) 428 if (GNUNET_YES == fi->is_directory)
429 {
430 /* clean up directory */
431 while (NULL != (pos = fi->data.dir.entries))
432 { 429 {
433 fi->data.dir.entries = pos->next; 430 /* clean up directory */
434 GNUNET_FS_file_information_destroy (pos, cleaner, cleaner_cls); 431 while (NULL != (pos = fi->data.dir.entries))
432 {
433 fi->data.dir.entries = pos->next;
434 GNUNET_FS_file_information_destroy(pos, cleaner, cleaner_cls);
435 }
436 /* clean up client-info */
437 if (NULL != cleaner)
438 cleaner(cleaner_cls,
439 fi,
440 fi->data.dir.dir_size,
441 fi->meta,
442 &fi->keywords,
443 &fi->bo,
444 &no,
445 &fi->client_info);
446 GNUNET_free_non_null(fi->data.dir.dir_data);
435 } 447 }
436 /* clean up client-info */
437 if (NULL != cleaner)
438 cleaner (cleaner_cls,
439 fi,
440 fi->data.dir.dir_size,
441 fi->meta,
442 &fi->keywords,
443 &fi->bo,
444 &no,
445 &fi->client_info);
446 GNUNET_free_non_null (fi->data.dir.dir_data);
447 }
448 else 448 else
449 {
450 /* call clean-up function of the reader */
451 if (NULL != fi->data.file.reader)
452 { 449 {
453 (void) fi->data.file.reader (fi->data.file.reader_cls, 0, 0, NULL, NULL); 450 /* call clean-up function of the reader */
454 fi->data.file.reader = NULL; 451 if (NULL != fi->data.file.reader)
452 {
453 (void)fi->data.file.reader(fi->data.file.reader_cls, 0, 0, NULL, NULL);
454 fi->data.file.reader = NULL;
455 }
456 /* clean up client-info */
457 if (NULL != cleaner)
458 cleaner(cleaner_cls,
459 fi,
460 fi->data.file.file_size,
461 fi->meta,
462 &fi->keywords,
463 &fi->bo,
464 &fi->data.file.do_index,
465 &fi->client_info);
455 } 466 }
456 /* clean up client-info */ 467 GNUNET_free_non_null(fi->filename);
457 if (NULL != cleaner) 468 GNUNET_free_non_null(fi->emsg);
458 cleaner (cleaner_cls,
459 fi,
460 fi->data.file.file_size,
461 fi->meta,
462 &fi->keywords,
463 &fi->bo,
464 &fi->data.file.do_index,
465 &fi->client_info);
466 }
467 GNUNET_free_non_null (fi->filename);
468 GNUNET_free_non_null (fi->emsg);
469 if (NULL != fi->sks_uri) 469 if (NULL != fi->sks_uri)
470 GNUNET_FS_uri_destroy (fi->sks_uri); 470 GNUNET_FS_uri_destroy(fi->sks_uri);
471 if (NULL != fi->chk_uri) 471 if (NULL != fi->chk_uri)
472 GNUNET_FS_uri_destroy (fi->chk_uri); 472 GNUNET_FS_uri_destroy(fi->chk_uri);
473 /* clean up serialization */ 473 /* clean up serialization */
474 if ((NULL != fi->serialization) && (0 != unlink (fi->serialization))) 474 if ((NULL != fi->serialization) && (0 != unlink(fi->serialization)))
475 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 475 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING,
476 "unlink", 476 "unlink",
477 fi->serialization); 477 fi->serialization);
478 if (NULL != fi->keywords) 478 if (NULL != fi->keywords)
479 GNUNET_FS_uri_destroy (fi->keywords); 479 GNUNET_FS_uri_destroy(fi->keywords);
480 if (NULL != fi->meta) 480 if (NULL != fi->meta)
481 GNUNET_CONTAINER_meta_data_destroy (fi->meta); 481 GNUNET_CONTAINER_meta_data_destroy(fi->meta);
482 GNUNET_free_non_null (fi->serialization); 482 GNUNET_free_non_null(fi->serialization);
483 if (NULL != fi->te) 483 if (NULL != fi->te)
484 { 484 {
485 GNUNET_FS_tree_encoder_finish (fi->te, NULL); 485 GNUNET_FS_tree_encoder_finish(fi->te, NULL);
486 fi->te = NULL; 486 fi->te = NULL;
487 } 487 }
488 GNUNET_free (fi); 488 GNUNET_free(fi);
489} 489}
490 490
491 491