GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 2, or (at your
+ by the Free Software Foundation; either version 3, or (at your
option) any later version.
GNUnet is distributed in the hope that it will be useful, but
char *mime;
int ret;
+ if (NULL == md)
+ return GNUNET_SYSERR;
mime = GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_MIMETYPE);
if (mime == NULL)
return GNUNET_SYSERR;
}
+/**
+ * Closure for 'find_full_data'.
+ */
+struct GetFullDataClosure
+{
+
+ /**
+ * Extracted binary meta data.
+ */
+ void *data;
+
+ /**
+ * Number of bytes stored in data.
+ */
+ size_t size;
+};
+
+
+/**
+ * Type of a function that libextractor calls for each
+ * meta data item found.
+ *
+ * @param cls closure (user-defined)
+ * @param plugin_name name of the plugin that produced this value;
+ * special values can be used (i.e. '<zlib>' for zlib being
+ * used in the main libextractor library and yielding
+ * meta data).
+ * @param type libextractor-type describing the meta data
+ * @param format basic format information about data
+ * @param data_mime_type mime-type of data (not of the original file);
+ * can be NULL (if mime-type is not known)
+ * @param data actual meta-data found
+ * @param data_len number of bytes in data
+ * @return 0 to continue extracting, 1 to abort
+ */
+static int
+find_full_data (void *cls,
+ const char *plugin_name,
+ enum EXTRACTOR_MetaType type,
+ enum EXTRACTOR_MetaFormat format,
+ const char *data_mime_type,
+ const char *data,
+ size_t data_len)
+{
+ struct GetFullDataClosure *gfdc = cls;
+
+ if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA)
+ {
+ gfdc->size = data_len;
+ if (data_len > 0)
+ {
+ gfdc->data = GNUNET_malloc (data_len);
+ memcpy (gfdc->data,
+ data,
+ data_len);
+ }
+ return 1;
+ }
+ return 0;
+}
+
+
/**
* Iterate over all entries in a directory. Note that directories
* are structured such that it is possible to iterate over the
* @param offset offset of data in the directory
* @param dep function to call on each entry
* @param dep_cls closure for dep
+ * @return GNUNET_OK if this could be a block in a directory,
+ * GNUNET_NO if this could be part of a directory (but not 100% OK)
+ * GNUNET_SYSERR if 'data' does not represent a directory
*/
-void
+int
GNUNET_FS_directory_list_contents (size_t size,
const void *data,
uint64_t offset,
GNUNET_FS_DirectoryEntryProcessor dep,
void *dep_cls)
{
+ struct GetFullDataClosure full_data;
const char *cdata = data;
- char *file_data;
char *emsg;
uint64_t pos;
uint64_t align;
struct GNUNET_CONTAINER_MetaData *md;
char *filename;
+ if ( (offset == 0) &&
+ ( (size < 8 + sizeof (uint32_t)) ||
+ (0 != memcmp (cdata, GNUNET_FS_DIRECTORY_MAGIC, 8)) ) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("MAGIC mismatch. This is not a GNUnet directory.\n"));
+ return GNUNET_SYSERR;
+ }
pos = offset;
- if ( (pos == 0) &&
- (size >= 8 + sizeof (uint32_t)) &&
- (0 == memcmp (cdata, GNUNET_FS_DIRECTORY_MAGIC, 8)) )
+ if (offset == 0)
{
memcpy (&mdSize, &cdata[8], sizeof (uint32_t));
mdSize = ntohl (mdSize);
{
/* invalid size */
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Not a GNUnet directory.\n"));
- return;
+ _("MAGIC mismatch. This is not a GNUnet directory.\n"));
+ return GNUNET_SYSERR;
}
md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[8 +
sizeof (uint32_t)],
mdSize);
if (md == NULL)
{
- GNUNET_break (0);
- return; /* malformed ! */
+ GNUNET_break (0);
+ return GNUNET_SYSERR; /* malformed ! */
}
dep (dep_cls,
NULL,
while ((epos < size) && (cdata[epos] != '\0'))
epos++;
if (epos >= size)
- return; /* malformed - or partial download */
+ return GNUNET_NO; /* malformed - or partial download */
uri = GNUNET_FS_uri_parse (&cdata[pos], &emsg);
pos = epos + 1;
{
GNUNET_FS_uri_destroy (uri);
GNUNET_break (0);
- return; /* illegal in directory! */
+ return GNUNET_NO; /* illegal in directory! */
}
memcpy (&mdSize, &cdata[pos], sizeof (uint32_t));
if (pos + mdSize > size)
{
GNUNET_FS_uri_destroy (uri);
- return; /* malformed - or partial download */
+ return GNUNET_NO; /* malformed - or partial download */
}
md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[pos], mdSize);
{
GNUNET_FS_uri_destroy (uri);
GNUNET_break (0);
- return; /* malformed ! */
+ return GNUNET_NO; /* malformed ! */
}
pos += mdSize;
filename = GNUNET_CONTAINER_meta_data_get_by_type (md,
EXTRACTOR_METATYPE_FILENAME);
- file_data = GNUNET_CONTAINER_meta_data_get_by_type (md,
- EXTRACTOR_METATYPE_GNUNET_FULL_DATA);
+ full_data.size = 0;
+ full_data.data = NULL;
+ GNUNET_CONTAINER_meta_data_iterate (md,
+ &find_full_data,
+ &full_data);
if (dep != NULL)
- dep (dep_cls,
- filename,
- uri,
- md,
- (file_data != NULL) ? strlen(file_data) : 0,
- file_data);
- GNUNET_free_non_null (file_data);
+ {
+ dep (dep_cls,
+ filename,
+ uri,
+ md,
+ full_data.size,
+ full_data.data);
+ }
+ GNUNET_free_non_null (full_data.data);
GNUNET_free_non_null (filename);
GNUNET_CONTAINER_meta_data_destroy (md);
GNUNET_FS_uri_destroy (uri);
}
+ return GNUNET_OK;
}
/**
GNUNET_assert (! GNUNET_FS_uri_test_ksk (uri));
if (NULL != data)
- if (GNUNET_FS_uri_test_chk (uri))
- fsize = GNUNET_FS_uri_chk_get_file_size (uri);
- else
- {
- curi = GNUNET_FS_uri_loc_get_uri (uri);
- fsize = GNUNET_FS_uri_chk_get_file_size (curi);
- GNUNET_FS_uri_destroy (curi);
- }
+ {
+ GNUNET_assert (! GNUNET_FS_uri_test_sks (uri));
+ if (GNUNET_FS_uri_test_chk (uri))
+ {
+ fsize = GNUNET_FS_uri_chk_get_file_size (uri);
+ }
+ else
+ {
+ curi = GNUNET_FS_uri_loc_get_uri (uri);
+ GNUNET_assert (NULL != curi);
+ fsize = GNUNET_FS_uri_chk_get_file_size (curi);
+ GNUNET_FS_uri_destroy (curi);
+ }
+ }
else
- fsize = 0; /* not given */
+ {
+ fsize = 0; /* not given */
+ }
if (fsize > MAX_INLINE_SIZE)
fsize = 0; /* too large */
uris = GNUNET_FS_uri_to_string (uri);
badness = cbad;
}
}
+ GNUNET_assert (best != -1);
tmp = perm[i];
perm[i] = perm[best];
perm[best] = tmp;
ssize_t ret;
uint32_t big;
- size = 8 + sizeof (uint32_t);
+ size = strlen (GNUNET_DIRECTORY_MAGIC) + sizeof (uint32_t);
size += GNUNET_CONTAINER_meta_data_get_serialized_size (bld->meta);
sizes = NULL;
perm = NULL;
"malloc");
*rsize = 0;
*rdata = NULL;
+ GNUNET_free_non_null (sizes);
+ GNUNET_free_non_null (perm);
+ GNUNET_free_non_null (bes);
return GNUNET_SYSERR;
}
*rdata = data;
- memcpy (data, GNUNET_DIRECTORY_MAGIC, 8);
- off = 8;
+ memcpy (data, GNUNET_DIRECTORY_MAGIC, strlen (GNUNET_DIRECTORY_MAGIC));
+ off = strlen (GNUNET_DIRECTORY_MAGIC);
sptr = &data[off + sizeof (uint32_t)];
ret = GNUNET_CONTAINER_meta_data_serialize (bld->meta,
GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
GNUNET_assert (ret != -1);
big = htonl (ret);
- memcpy (&data[8], &big, sizeof (uint32_t));
+ memcpy (&data[off], &big, sizeof (uint32_t));
off += sizeof (uint32_t) + ret;
for (j = 0; j < bld->count; j++)
{