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/fs_file_information.c | |
parent | 4f13bc15113021ebf71d5d81e99bc29f8a07fc9c (diff) | |
download | gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.tar.gz gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.zip |
first step to remove plibc
Diffstat (limited to 'src/fs/fs_file_information.c')
-rw-r--r-- | src/fs/fs_file_information.c | 181 |
1 files changed, 105 insertions, 76 deletions
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); |