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
*/
#include "platform.h"
-#include "gnunet_common.h"
-#include "gnunet_container_lib.h"
-#include "gnunet_strings_lib.h"
-#include "gnunet_time_lib.h"
+#include "gnunet_util_lib.h"
#include <extractor.h>
#include <zlib.h>
struct GNUNET_CONTAINER_MetaData *
GNUNET_CONTAINER_meta_data_create ()
{
- return GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MetaData));
+ return GNUNET_new (struct GNUNET_CONTAINER_MetaData);
}
*
* @param md1 first value to check
* @param md2 other value to check
- * @return GNUNET_YES if they are equal
+ * @return #GNUNET_YES if they are equal
*/
int
GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData
* @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_size number of bytes in data
- * @return GNUNET_OK on success, GNUNET_SYSERR if this entry already exists
+ * @param data_size number of bytes in @a data
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if this entry already exists
* data_mime_type and plugin_name are not considered for "exists" checks
*/
int
struct MetaItem *mi;
char *p;
+ if ((EXTRACTOR_METAFORMAT_UTF8 == format) ||
+ (EXTRACTOR_METAFORMAT_C_STRING == format))
+ GNUNET_break ('\0' == data[data_size - 1]);
+
for (pos = md->items_head; NULL != pos; pos = pos->next)
{
if (pos->data_size < data_size)
}
}
md->item_count++;
- mi = GNUNET_malloc (sizeof (struct MetaItem));
+ mi = GNUNET_new (struct MetaItem);
mi->type = type;
mi->format = format;
mi->data_size = data_size;
/**
* Merge given meta data.
*
- * @param cls the 'struct GNUNET_CONTAINER_MetaData' to merge into
+ * @param cls the `struct GNUNET_CONTAINER_MetaData` to merge into
* @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
* @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_size number of bytes in data
+ * @param data_size number of bytes in @a data
* @return 0 (to continue)
*/
static int
* @param type type of the item to remove
* @param data specific value to remove, NULL to remove all
* entries of the given type
- * @param data_size number of bytes in data
- * @return GNUNET_OK on success, GNUNET_SYSERR if the item does not exist in md
+ * @param data_size number of bytes in @a data
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if the item does not exist in md
*/
int
GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
/**
- * Duplicate struct GNUNET_CONTAINER_MetaData.
+ * Duplicate a `struct GNUNET_CONTAINER_MetaData`.
*
* @param md what to duplicate
* @return duplicate meta-data container
* @param oldSize number of bytes in data
* @param result set to the compressed data
* @param newSize set to size of result
- * @return GNUNET_YES if compression reduce the size,
- * GNUNET_NO if compression did not help
+ * @return #GNUNET_YES if compression reduce the size,
+ * #GNUNET_NO if compression did not help
*/
static int
try_compression (const char *data, size_t oldSize, char **result,
* meta-data to match the size constraint,
* possibly discarding some data?
* @return number of bytes written on success,
- * GNUNET_SYSERR on error (typically: not enough
+ * #GNUNET_SYSERR on error (typically: not enough
* space)
*/
ssize_t
mdata = (char *) &ent[md->item_count];
off = size - (md->item_count * sizeof (struct MetaDataEntry));
i = 0;
- for (pos = md->items_tail; NULL != pos; pos = pos->prev)
+ for (pos = md->items_head; NULL != pos; pos = pos->next)
{
ent[i].type = htonl ((uint32_t) pos->type);
ent[i].format = htonl ((uint32_t) pos->format);
ent[i].data_size = htonl ((uint32_t) pos->data_size);
- if (pos->plugin_name == NULL)
+ if (NULL == pos->plugin_name)
plen = 0;
else
plen = strlen (pos->plugin_name) + 1;
ent[i].plugin_name_len = htonl ((uint32_t) plen);
- if (pos->mime_type == NULL)
+ if (NULL == pos->mime_type)
mlen = 0;
else
mlen = strlen (pos->mime_type) + 1;
ent[i].mime_type_len = htonl ((uint32_t) mlen);
off -= pos->data_size;
+ if ((EXTRACTOR_METAFORMAT_UTF8 == pos->format) ||
+ (EXTRACTOR_METAFORMAT_C_STRING == pos->format))
+ GNUNET_break ('\0' == pos->data[pos->data_size - 1]);
memcpy (&mdata[off], pos->data, pos->data_size);
off -= plen;
- if (pos->plugin_name != NULL)
+ if (NULL != pos->plugin_name)
memcpy (&mdata[off], pos->plugin_name, plen);
off -= mlen;
- if (pos->mime_type != NULL)
+ if (NULL != pos->mime_type)
memcpy (&mdata[off], pos->mime_type, mlen);
i++;
}
cdata = NULL;
left = size;
i = 0;
- for (pos = md->items_tail; NULL != pos; pos = pos->prev)
+ for (pos = md->items_head; NULL != pos; pos = pos->next)
{
comp = GNUNET_NO;
if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS))
hdr->entries = htonl (md->item_count - i);
memcpy (&dst[sizeof (struct MetaDataHeader)], cdata, clen);
GNUNET_free (cdata);
+ cdata = NULL;
GNUNET_free (ent);
rlen = clen + sizeof (struct MetaDataHeader);
}
}
if (NULL != *target)
{
- memcpy (*target, dst, clen + sizeof (struct MetaDataHeader));
+ if (GNUNET_YES == comp)
+ memcpy (*target, dst, clen + sizeof (struct MetaDataHeader));
+ else
+ memcpy (*target, dst, left + sizeof (struct MetaDataHeader));
GNUNET_free (dst);
}
else
left -= strlen (pos->plugin_name) + 1;
if (NULL != pos->mime_type)
left -= strlen (pos->mime_type) + 1;
+
+ GNUNET_free_non_null (cdata);
+ cdata = NULL;
+
i++;
}
GNUNET_free (ent);
ihdr.entries = htonl (0);
ihdr.size = htonl (0);
if (NULL == *target)
- *target = GNUNET_malloc (sizeof (struct MetaDataHeader));
+ *target = (char *) GNUNET_new (struct MetaDataHeader);
memcpy (*target, &ihdr, sizeof (struct MetaDataHeader));
return sizeof (struct MetaDataHeader);
}
uncompress ((Bytef *) output, &olen, (const Bytef *) input, inputSize))
return output;
GNUNET_free (output);
- return NULL;
+ return NULL;
}
if ((EXTRACTOR_METAFORMAT_UTF8 == format) ||
(EXTRACTOR_METAFORMAT_C_STRING == format))
{
- if ((0 == dlen) || ('\0' != mdata[left + dlen - 1]))
+ if (0 == dlen)
+ {
+ GNUNET_break_op (0);
+ break;
+ }
+ if ('\0' != meta_data[dlen - 1])
{
GNUNET_break_op (0);
break;