aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_directory.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-03-05 15:54:47 +0100
committerChristian Grothoff <christian@grothoff.org>2017-03-05 15:54:47 +0100
commit29be1a71b26bed8f6b0317cc4ad12195edd6569f (patch)
treea45b210c99852e4689de1ef8c1b31e01ca37db4e /src/fs/fs_directory.c
parent6640e3beca224341f82216442c8e2d417199836f (diff)
downloadgnunet-29be1a71b26bed8f6b0317cc4ad12195edd6569f.tar.gz
gnunet-29be1a71b26bed8f6b0317cc4ad12195edd6569f.zip
indentation, comment and style fixes, no semantic changes
Diffstat (limited to 'src/fs/fs_directory.c')
-rw-r--r--src/fs/fs_directory.c78
1 files changed, 54 insertions, 24 deletions
diff --git a/src/fs/fs_directory.c b/src/fs/fs_directory.c
index a18a903be..514eb64b3 100644
--- a/src/fs/fs_directory.c
+++ b/src/fs/fs_directory.c
@@ -170,13 +170,14 @@ find_full_data (void *cls, const char *plugin_name,
170 * @param data pointer to the beginning of the directory 170 * @param data pointer to the beginning of the directory
171 * @param offset offset of data in the directory 171 * @param offset offset of data in the directory
172 * @param dep function to call on each entry 172 * @param dep function to call on each entry
173 * @param dep_cls closure for dep 173 * @param dep_cls closure for @a dep
174 * @return GNUNET_OK if this could be a block in a directory, 174 * @return #GNUNET_OK if this could be a block in a directory,
175 * GNUNET_NO if this could be part of a directory (but not 100% OK) 175 * #GNUNET_NO if this could be part of a directory (but not 100% OK)
176 * GNUNET_SYSERR if 'data' does not represent a directory 176 * #GNUNET_SYSERR if @a data does not represent a directory
177 */ 177 */
178int 178int
179GNUNET_FS_directory_list_contents (size_t size, const void *data, 179GNUNET_FS_directory_list_contents (size_t size,
180 const void *data,
180 uint64_t offset, 181 uint64_t offset,
181 GNUNET_FS_DirectoryEntryProcessor dep, 182 GNUNET_FS_DirectoryEntryProcessor dep,
182 void *dep_cls) 183 void *dep_cls)
@@ -194,12 +195,16 @@ GNUNET_FS_directory_list_contents (size_t size, const void *data,
194 195
195 if ((offset == 0) && 196 if ((offset == 0) &&
196 ((size < 8 + sizeof (uint32_t)) || 197 ((size < 8 + sizeof (uint32_t)) ||
197 (0 != memcmp (cdata, GNUNET_FS_DIRECTORY_MAGIC, 8)))) 198 (0 != memcmp (cdata,
199 GNUNET_FS_DIRECTORY_MAGIC,
200 8))))
198 return GNUNET_SYSERR; 201 return GNUNET_SYSERR;
199 pos = offset; 202 pos = offset;
200 if (offset == 0) 203 if (offset == 0)
201 { 204 {
202 GNUNET_memcpy (&mdSize, &cdata[8], sizeof (uint32_t)); 205 GNUNET_memcpy (&mdSize,
206 &cdata[8],
207 sizeof (uint32_t));
203 mdSize = ntohl (mdSize); 208 mdSize = ntohl (mdSize);
204 if (mdSize > size - 8 - sizeof (uint32_t)) 209 if (mdSize > size - 8 - sizeof (uint32_t))
205 { 210 {
@@ -215,7 +220,12 @@ GNUNET_FS_directory_list_contents (size_t size, const void *data,
215 GNUNET_break (0); 220 GNUNET_break (0);
216 return GNUNET_SYSERR; /* malformed ! */ 221 return GNUNET_SYSERR; /* malformed ! */
217 } 222 }
218 dep (dep_cls, NULL, NULL, md, 0, NULL); 223 dep (dep_cls,
224 NULL,
225 NULL,
226 md,
227 0,
228 NULL);
219 GNUNET_CONTAINER_meta_data_destroy (md); 229 GNUNET_CONTAINER_meta_data_destroy (md);
220 pos = 8 + sizeof (uint32_t) + mdSize; 230 pos = 8 + sizeof (uint32_t) + mdSize;
221 } 231 }
@@ -247,7 +257,7 @@ GNUNET_FS_directory_list_contents (size_t size, const void *data,
247 257
248 uri = GNUNET_FS_uri_parse (&cdata[pos], &emsg); 258 uri = GNUNET_FS_uri_parse (&cdata[pos], &emsg);
249 pos = epos + 1; 259 pos = epos + 1;
250 if (uri == NULL) 260 if (NULL == uri)
251 { 261 {
252 GNUNET_free (emsg); 262 GNUNET_free (emsg);
253 pos--; /* go back to '\0' to force going to next alignment */ 263 pos--; /* go back to '\0' to force going to next alignment */
@@ -260,7 +270,9 @@ GNUNET_FS_directory_list_contents (size_t size, const void *data,
260 return GNUNET_NO; /* illegal in directory! */ 270 return GNUNET_NO; /* illegal in directory! */
261 } 271 }
262 272
263 GNUNET_memcpy (&mdSize, &cdata[pos], sizeof (uint32_t)); 273 GNUNET_memcpy (&mdSize,
274 &cdata[pos],
275 sizeof (uint32_t));
264 mdSize = ntohl (mdSize); 276 mdSize = ntohl (mdSize);
265 pos += sizeof (uint32_t); 277 pos += sizeof (uint32_t);
266 if (pos + mdSize > size) 278 if (pos + mdSize > size)
@@ -269,8 +281,9 @@ GNUNET_FS_directory_list_contents (size_t size, const void *data,
269 return GNUNET_NO; /* malformed - or partial download */ 281 return GNUNET_NO; /* malformed - or partial download */
270 } 282 }
271 283
272 md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[pos], mdSize); 284 md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[pos],
273 if (md == NULL) 285 mdSize);
286 if (NULL == md)
274 { 287 {
275 GNUNET_FS_uri_destroy (uri); 288 GNUNET_FS_uri_destroy (uri);
276 GNUNET_break (0); 289 GNUNET_break (0);
@@ -282,10 +295,17 @@ GNUNET_FS_directory_list_contents (size_t size, const void *data,
282 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); 295 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
283 full_data.size = 0; 296 full_data.size = 0;
284 full_data.data = NULL; 297 full_data.data = NULL;
285 GNUNET_CONTAINER_meta_data_iterate (md, &find_full_data, &full_data); 298 GNUNET_CONTAINER_meta_data_iterate (md,
286 if (dep != NULL) 299 &find_full_data,
300 &full_data);
301 if (NULL != dep)
287 { 302 {
288 dep (dep_cls, filename, uri, md, full_data.size, full_data.data); 303 dep (dep_cls,
304 filename,
305 uri,
306 md,
307 full_data.size,
308 full_data.data);
289 } 309 }
290 GNUNET_free_non_null (full_data.data); 310 GNUNET_free_non_null (full_data.data);
291 GNUNET_free_non_null (filename); 311 GNUNET_free_non_null (filename);
@@ -548,11 +568,12 @@ block_align (size_t start, unsigned int count, const size_t * sizes,
548 * @param bld directory to finish 568 * @param bld directory to finish
549 * @param rsize set to the number of bytes needed 569 * @param rsize set to the number of bytes needed
550 * @param rdata set to the encoded directory 570 * @param rdata set to the encoded directory
551 * @return GNUNET_OK on success 571 * @return #GNUNET_OK on success
552 */ 572 */
553int 573int
554GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld, 574GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
555 size_t * rsize, void **rdata) 575 size_t * rsize,
576 void **rdata)
556{ 577{
557 char *data; 578 char *data;
558 char *sptr; 579 char *sptr;
@@ -575,9 +596,12 @@ GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
575 bes = NULL; 596 bes = NULL;
576 if (0 < bld->count) 597 if (0 < bld->count)
577 { 598 {
578 sizes = GNUNET_malloc (bld->count * sizeof (size_t)); 599 sizes = GNUNET_new_array (bld->count,
579 perm = GNUNET_malloc (bld->count * sizeof (unsigned int)); 600 size_t);
580 bes = GNUNET_malloc (bld->count * sizeof (struct BuilderEntry *)); 601 perm = GNUNET_new_array (bld->count,
602 unsigned int);
603 bes = GNUNET_new_array (bld->count,
604 struct BuilderEntry *);
581 pos = bld->head; 605 pos = bld->head;
582 for (i = 0; i < bld->count; i++) 606 for (i = 0; i < bld->count; i++)
583 { 607 {
@@ -599,7 +623,8 @@ GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
599 data = GNUNET_malloc_large (size); 623 data = GNUNET_malloc_large (size);
600 if (data == NULL) 624 if (data == NULL)
601 { 625 {
602 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc"); 626 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
627 "malloc");
603 *rsize = 0; 628 *rsize = 0;
604 *rdata = NULL; 629 *rdata = NULL;
605 GNUNET_free_non_null (sizes); 630 GNUNET_free_non_null (sizes);
@@ -608,17 +633,22 @@ GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
608 return GNUNET_SYSERR; 633 return GNUNET_SYSERR;
609 } 634 }
610 *rdata = data; 635 *rdata = data;
611 GNUNET_memcpy (data, GNUNET_DIRECTORY_MAGIC, strlen (GNUNET_DIRECTORY_MAGIC)); 636 GNUNET_memcpy (data,
637 GNUNET_DIRECTORY_MAGIC,
638 strlen (GNUNET_DIRECTORY_MAGIC));
612 off = strlen (GNUNET_DIRECTORY_MAGIC); 639 off = strlen (GNUNET_DIRECTORY_MAGIC);
613 640
614 sptr = &data[off + sizeof (uint32_t)]; 641 sptr = &data[off + sizeof (uint32_t)];
615 ret = 642 ret =
616 GNUNET_CONTAINER_meta_data_serialize (bld->meta, &sptr, 643 GNUNET_CONTAINER_meta_data_serialize (bld->meta,
644 &sptr,
617 size - off - sizeof (uint32_t), 645 size - off - sizeof (uint32_t),
618 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL); 646 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
619 GNUNET_assert (ret != -1); 647 GNUNET_assert (ret != -1);
620 big = htonl (ret); 648 big = htonl (ret);
621 GNUNET_memcpy (&data[off], &big, sizeof (uint32_t)); 649 GNUNET_memcpy (&data[off],
650 &big,
651 sizeof (uint32_t));
622 off += sizeof (uint32_t) + ret; 652 off += sizeof (uint32_t) + ret;
623 for (j = 0; j < bld->count; j++) 653 for (j = 0; j < bld->count; j++)
624 { 654 {