2 This file is part of GNUnet.
3 (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file util/container_meta_data.c
23 * @brief Storing of meta data
24 * @author Christian Grothoff
28 #include "gnunet_common.h"
29 #include "gnunet_container_lib.h"
30 #include "gnunet_strings_lib.h"
31 #include "gnunet_time_lib.h"
32 #include <extractor.h>
35 #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
43 * This is a linked list.
45 struct MetaItem *next;
48 * Name of the extracting plugin.
58 * The actual meta data.
63 * Number of bytes in 'data'.
68 * Type of the meta data.
70 enum EXTRACTOR_MetaType type;
73 * Format of the meta data.
75 enum EXTRACTOR_MetaFormat format;
80 * Meta data to associate with a file, directory or namespace.
82 struct GNUNET_CONTAINER_MetaData
85 * Linked list of the meta data items.
87 struct MetaItem *items;
90 * Complete serialized and compressed buffer of the items.
91 * NULL if we have not computed that buffer yet.
96 * Number of bytes in 'sbuf'. 0 if the buffer is stale.
101 * Number of items in the linked list.
103 unsigned int item_count;
109 * Create a fresh struct CONTAINER_MetaData token.
111 * @return empty meta-data container
113 struct GNUNET_CONTAINER_MetaData *
114 GNUNET_CONTAINER_meta_data_create ()
116 return GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_MetaData));
121 * Free meta data item.
123 * @param item item to free
126 meta_item_free (struct MetaItem *item)
128 GNUNET_free_non_null (item->plugin_name);
129 GNUNET_free_non_null (item->mime_type);
130 GNUNET_free_non_null (item->data);
136 * The meta data has changed, invalidate its serialization
139 * @param md meta data that changed
142 invalidate_sbuf (struct GNUNET_CONTAINER_MetaData *md)
144 if (md->sbuf == NULL)
146 GNUNET_free (md->sbuf);
155 * @param md what to free
158 GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md)
160 struct MetaItem *item;
164 while (NULL != (item = md->items))
166 md->items = item->next;
167 meta_item_free (item);
169 GNUNET_free_non_null (md->sbuf);
175 * Remove all items in the container.
177 * @param md metadata to manipulate
180 GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md)
182 struct MetaItem *item;
186 while (NULL != (item = md->items))
188 md->items = item->next;
189 meta_item_free (item);
191 GNUNET_free_non_null (md->sbuf);
192 memset (md, 0, sizeof (struct GNUNET_CONTAINER_MetaData));
198 * Test if two MDs are equal. We consider them equal if
199 * the meta types, formats and content match (we do not
200 * include the mime types and plugins names in this
203 * @param md1 first value to check
204 * @param md2 other value to check
205 * @return GNUNET_YES if they are equal
208 GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData
210 const struct GNUNET_CONTAINER_MetaData
219 if (md1->item_count != md2->item_count)
229 if ((i->type == j->type) && (i->format == j->format) &&
230 (i->data_size == j->data_size) &&
231 (0 == memcmp (i->data, j->data, i->data_size)))
238 if (found == GNUNET_NO)
247 * Extend metadata. Note that the list of meta data items is
248 * sorted by size (largest first).
250 * @param md metadata to extend
251 * @param plugin_name name of the plugin that produced this value;
252 * special values can be used (i.e. '<zlib>' for zlib being
253 * used in the main libextractor library and yielding
255 * @param type libextractor-type describing the meta data
256 * @param format basic format information about data
257 * @param data_mime_type mime-type of data (not of the original file);
258 * can be NULL (if mime-type is not known)
259 * @param data actual meta-data found
260 * @param data_len number of bytes in data
261 * @return GNUNET_OK on success, GNUNET_SYSERR if this entry already exists
262 * data_mime_type and plugin_name are not considered for "exists" checks
265 GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
266 const char *plugin_name,
267 enum EXTRACTOR_MetaType type,
268 enum EXTRACTOR_MetaFormat format,
269 const char *data_mime_type,
270 const char *data, size_t data_len)
272 struct MetaItem *prev;
273 struct MetaItem *pos;
281 if (pos->data_size < data_len)
283 if ((pos->type == type) && (pos->data_size == data_len) &&
284 (0 == memcmp (pos->data, data, data_len)))
286 if ((pos->mime_type == NULL) && (data_mime_type != NULL))
288 pos->mime_type = GNUNET_strdup (data_mime_type);
289 invalidate_sbuf (md);
291 if ((pos->format == EXTRACTOR_METAFORMAT_C_STRING) &&
292 (format == EXTRACTOR_METAFORMAT_UTF8))
294 pos->format = EXTRACTOR_METAFORMAT_UTF8;
295 invalidate_sbuf (md);
297 return GNUNET_SYSERR;
303 i = GNUNET_malloc (sizeof (struct MetaItem));
306 i->data_size = data_len;
313 (data_mime_type == NULL) ? NULL : GNUNET_strdup (data_mime_type);
314 i->plugin_name = (plugin_name == NULL) ? NULL : GNUNET_strdup (plugin_name);
315 i->data = GNUNET_malloc (data_len);
316 memcpy (i->data, data, data_len);
317 /* change OS native dir separators to unix '/' and others to '_' */
318 if (type == EXTRACTOR_METATYPE_FILENAME)
321 while ((*p != '\0') && (p < i->data + data_len))
323 if (*p == DIR_SEPARATOR)
330 invalidate_sbuf (md);
336 * Merge given meta data.
338 * @param cls the 'struct GNUNET_CONTAINER_MetaData' to merge into
339 * @param plugin_name name of the plugin that produced this value;
340 * special values can be used (i.e. '<zlib>' for zlib being
341 * used in the main libextractor library and yielding
343 * @param type libextractor-type describing the meta data
344 * @param format basic format information about data
345 * @param data_mime_type mime-type of data (not of the original file);
346 * can be NULL (if mime-type is not known)
347 * @param data actual meta-data found
348 * @param data_len number of bytes in data
349 * @return 0 (to continue)
352 merge_helper (void *cls, const char *plugin_name,
353 enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format,
354 const char *data_mime_type, const char *data, size_t data_len)
356 struct GNUNET_CONTAINER_MetaData *md = cls;
358 (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, type, format,
359 data_mime_type, data, data_len);
365 * Extend metadata. Merges the meta data from the second argument
366 * into the first, discarding duplicate key-value pairs.
368 * @param md metadata to extend
369 * @param in metadata to merge
372 GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md,
373 const struct GNUNET_CONTAINER_MetaData *in)
375 GNUNET_CONTAINER_meta_data_iterate (in, &merge_helper, md);
382 * @param md metadata to manipulate
383 * @param type type of the item to remove
384 * @param data specific value to remove, NULL to remove all
385 * entries of the given type
386 * @param data_len number of bytes in data
387 * @return GNUNET_OK on success, GNUNET_SYSERR if the item does not exist in md
390 GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
391 enum EXTRACTOR_MetaType type,
392 const char *data, size_t data_len)
394 struct MetaItem *pos;
395 struct MetaItem *prev;
401 if ((pos->type == type) &&
403 ((pos->data_size == data_len) &&
404 (0 == memcmp (pos->data, data, data_len)))))
407 md->items = pos->next;
409 prev->next = pos->next;
410 meta_item_free (pos);
412 invalidate_sbuf (md);
418 return GNUNET_SYSERR;
423 * Add the current time as the publication date
426 * @param md metadata to modify
429 GNUNET_CONTAINER_meta_data_add_publication_date (struct
430 GNUNET_CONTAINER_MetaData
434 struct GNUNET_TIME_Absolute t;
436 t = GNUNET_TIME_absolute_get ();
437 GNUNET_CONTAINER_meta_data_delete (md, EXTRACTOR_METATYPE_PUBLICATION_DATE,
439 dat = GNUNET_STRINGS_absolute_time_to_string (t);
440 GNUNET_CONTAINER_meta_data_insert (md, "<gnunet>",
441 EXTRACTOR_METATYPE_PUBLICATION_DATE,
442 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
443 dat, strlen (dat) + 1);
449 * Iterate over MD entries.
451 * @param md metadata to inspect
452 * @param iter function to call on each entry
453 * @param iter_cls closure for iterator
454 * @return number of entries
457 GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData
458 *md, EXTRACTOR_MetaDataProcessor iter,
461 struct MetaItem *pos;
466 return md->item_count;
471 iter (iter_cls, pos->plugin_name, pos->type, pos->format,
472 pos->mime_type, pos->data, pos->data_size))
473 return md->item_count;
476 return md->item_count;
481 * Get the first MD entry of the given type. Caller
482 * is responsible for freeing the return value.
483 * Also, only meta data items that are strings (0-terminated)
484 * are returned by this function.
486 * @param md metadata to inspect
487 * @param type type to look for
488 * @return NULL if no entry was found
491 GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData
492 *md, enum EXTRACTOR_MetaType type)
494 struct MetaItem *pos;
501 if ((type == pos->type) &&
502 ((pos->format == EXTRACTOR_METAFORMAT_UTF8) ||
503 (pos->format == EXTRACTOR_METAFORMAT_C_STRING)))
504 return GNUNET_strdup (pos->data);
512 * Get the first matching MD entry of the given types. Caller is
513 * responsible for freeing the return value. Also, only meta data
514 * items that are strings (0-terminated) are returned by this
517 * @param md metadata to inspect
518 * @param ... -1-terminated list of types
519 * @return NULL if we do not have any such entry,
520 * otherwise client is responsible for freeing the value!
523 GNUNET_CONTAINER_meta_data_get_first_by_types (const struct
524 GNUNET_CONTAINER_MetaData *md,
529 enum EXTRACTOR_MetaType type;
537 type = va_arg (args, enum EXTRACTOR_MetaType);
541 ret = GNUNET_CONTAINER_meta_data_get_by_type (md, type);
551 * Get a thumbnail from the meta-data (if present).
553 * @param md metadata to get the thumbnail from
554 * @param thumb will be set to the thumbnail data. Must be
555 * freed by the caller!
556 * @return number of bytes in thumbnail, 0 if not available
559 GNUNET_CONTAINER_meta_data_get_thumbnail (const struct
560 GNUNET_CONTAINER_MetaData * md,
561 unsigned char **thumb)
563 struct MetaItem *pos;
564 struct MetaItem *match;
572 if ((NULL != pos->mime_type) &&
573 (0 == strncasecmp ("image/", pos->mime_type, strlen ("image/"))) &&
574 (pos->format == EXTRACTOR_METAFORMAT_BINARY))
578 else if ((match->type != EXTRACTOR_METATYPE_THUMBNAIL) &&
579 (pos->type == EXTRACTOR_METATYPE_THUMBNAIL))
584 if ((match == NULL) || (match->data_size == 0))
586 *thumb = GNUNET_malloc (match->data_size);
587 memcpy (*thumb, match->data, match->data_size);
588 return match->data_size;
593 * Duplicate struct GNUNET_CONTAINER_MetaData.
595 * @param md what to duplicate
596 * @return duplicate meta-data container
598 struct GNUNET_CONTAINER_MetaData *
599 GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData
602 struct GNUNET_CONTAINER_MetaData *ret;
603 struct MetaItem *pos;
607 ret = GNUNET_CONTAINER_meta_data_create ();
611 GNUNET_CONTAINER_meta_data_insert (ret, pos->plugin_name, pos->type,
612 pos->format, pos->mime_type,
613 pos->data, pos->data_size);
622 * Try to compress the given block of data.
624 * @param data block to compress; if compression
625 * resulted in a smaller block, the first
626 * bytes of data are updated to the compressed
628 * @param oldSize number of bytes in data
629 * @param result set to the compressed data
630 * @param newSize set to size of result
631 * @return GNUNET_YES if compression reduce the size,
632 * GNUNET_NO if compression did not help
635 try_compression (const char *data, size_t oldSize, char **result,
642 dlen = compressBound (oldSize);
644 dlen = oldSize + (oldSize / 100) + 20;
645 /* documentation says 100.1% oldSize + 12 bytes, but we
646 * should be able to overshoot by more to be safe */
648 tmp = GNUNET_malloc (dlen);
650 compress2 ((Bytef *) tmp, &dlen, (const Bytef *) data, oldSize, 9))
665 * Flag in 'version' that indicates compressed meta-data.
667 #define HEADER_COMPRESSED 0x80000000
671 * Bits in 'version' that give the version number.
673 #define HEADER_VERSION_MASK 0x7FFFFFFF
677 * Header for serialized meta data.
679 struct MetaDataHeader
682 * The version of the MD serialization. The highest bit is used to
683 * indicate compression.
685 * Version 0 is traditional (pre-0.9) meta data (unsupported)
686 * Version is 1 for a NULL pointer
687 * Version 2 is for 0.9.x (and possibly higher)
688 * Other version numbers are not yet defined.
693 * How many MD entries are there?
698 * Size of the decompressed meta data.
703 * This is followed by 'entries' values of type 'struct MetaDataEntry'
704 * and then by 'entry' plugin names, mime-types and data blocks
705 * as specified in those meta data entries.
711 * Entry of serialized meta data.
716 * Meta data type. Corresponds to an 'enum EXTRACTOR_MetaType'
721 * Meta data format. Corresponds to an 'enum EXTRACTOR_MetaFormat'
726 * Number of bytes of meta data.
731 * Number of bytes in the plugin name including 0-terminator. 0 for NULL.
733 uint32_t plugin_name_len;
736 * Number of bytes in the mime type including 0-terminator. 0 for NULL.
738 uint32_t mime_type_len;
744 * Serialize meta-data to target.
746 * @param md metadata to serialize
747 * @param target where to write the serialized metadata;
748 * *target can be NULL, in which case memory is allocated
749 * @param max maximum number of bytes available in target
750 * @param opt is it ok to just write SOME of the
751 * meta-data to match the size constraint,
752 * possibly discarding some data?
753 * @return number of bytes written on success,
754 * GNUNET_SYSERR on error (typically: not enough
758 GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData
759 *md, char **target, size_t max,
761 GNUNET_CONTAINER_MetaDataSerializationOptions
764 struct GNUNET_CONTAINER_MetaData *vmd;
765 struct MetaItem *pos;
766 struct MetaDataHeader ihdr;
767 struct MetaDataHeader *hdr;
768 struct MetaDataEntry *ent;
783 if (max < sizeof (struct MetaDataHeader))
784 return GNUNET_SYSERR; /* far too small */
788 if (md->sbuf != NULL)
790 /* try to use serialization cache */
791 if (md->sbuf_size <= max)
794 *target = GNUNET_malloc (md->sbuf_size);
795 memcpy (*target, md->sbuf, md->sbuf_size);
796 return md->sbuf_size;
798 if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_PART))
799 return GNUNET_SYSERR; /* can say that this will fail */
800 /* need to compute a partial serialization, sbuf useless ... */
807 msize += sizeof (struct MetaDataEntry);
808 msize += pos->data_size;
809 if (pos->plugin_name != NULL)
810 msize += strlen (pos->plugin_name) + 1;
811 if (pos->mime_type != NULL)
812 msize += strlen (pos->mime_type) + 1;
815 size = (size_t) msize;
818 GNUNET_break (0); /* integer overflow */
819 return GNUNET_SYSERR;
821 if (size >= GNUNET_MAX_MALLOC_CHECKED)
823 /* too large to be processed */
824 return GNUNET_SYSERR;
826 ent = GNUNET_malloc (size);
827 mdata = (char *) &ent[md->item_count];
828 off = size - (md->item_count * sizeof (struct MetaDataEntry));
833 ent[i].type = htonl ((uint32_t) pos->type);
834 ent[i].format = htonl ((uint32_t) pos->format);
835 ent[i].data_size = htonl ((uint32_t) pos->data_size);
836 if (pos->plugin_name == NULL)
839 plen = strlen (pos->plugin_name) + 1;
840 ent[i].plugin_name_len = htonl ((uint32_t) plen);
841 if (pos->mime_type == NULL)
844 mlen = strlen (pos->mime_type) + 1;
845 ent[i].mime_type_len = htonl ((uint32_t) mlen);
846 off -= pos->data_size;
847 memcpy (&mdata[off], pos->data, pos->data_size);
849 if (pos->plugin_name != NULL)
850 memcpy (&mdata[off], pos->plugin_name, plen);
852 if (pos->mime_type != NULL)
853 memcpy (&mdata[off], pos->mime_type, mlen);
857 GNUNET_assert (off == 0);
867 if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS))
868 comp = try_compression ((const char *) &ent[i], left, &cdata, &clen);
870 if ((md->sbuf == NULL) && (i == 0))
872 /* fill 'sbuf'; this "modifies" md, but since this is only
873 * an internal cache we will cast away the 'const' instead
874 * of making the API look strange. */
875 vmd = (struct GNUNET_CONTAINER_MetaData *) md;
876 hdr = GNUNET_malloc (left + sizeof (struct MetaDataHeader));
877 hdr->size = htonl (left);
878 hdr->entries = htonl (md->item_count);
879 if (GNUNET_YES == comp)
881 GNUNET_assert (clen < left);
882 hdr->version = htonl (2 | HEADER_COMPRESSED);
883 memcpy (&hdr[1], cdata, clen);
884 vmd->sbuf_size = clen + sizeof (struct MetaDataHeader);
888 hdr->version = htonl (2);
889 memcpy (&hdr[1], &ent[0], left);
890 vmd->sbuf_size = left + sizeof (struct MetaDataHeader);
892 vmd->sbuf = (char *) hdr;
895 if (((left + sizeof (struct MetaDataHeader)) <= max) ||
896 ((comp == GNUNET_YES) && (clen <= max)))
898 /* success, this now fits! */
899 if (GNUNET_YES == comp)
902 dst = GNUNET_malloc (clen + sizeof (struct MetaDataHeader));
903 hdr = (struct MetaDataHeader *) dst;
904 hdr->version = htonl (2 | HEADER_COMPRESSED);
905 hdr->size = htonl (left);
906 hdr->entries = htonl (md->item_count - i);
907 memcpy (&dst[sizeof (struct MetaDataHeader)], cdata, clen);
910 rlen = clen + sizeof (struct MetaDataHeader);
915 dst = GNUNET_malloc (left + sizeof (struct MetaDataHeader));
916 hdr = (struct MetaDataHeader *) dst;
917 hdr->version = htonl (2);
918 hdr->entries = htonl (md->item_count - i);
919 hdr->size = htonl (left);
920 memcpy (&dst[sizeof (struct MetaDataHeader)], &ent[i], left);
922 rlen = left + sizeof (struct MetaDataHeader);
926 memcpy (*target, dst, clen + sizeof (struct MetaDataHeader));
936 if (0 == (opt & GNUNET_CONTAINER_META_DATA_SERIALIZE_PART))
940 return GNUNET_SYSERR;
943 /* next iteration: ignore the corresponding meta data at the
944 * end and try again without it */
945 left -= sizeof (struct MetaDataEntry);
946 left -= pos->data_size;
947 if (pos->plugin_name != NULL)
948 left -= strlen (pos->plugin_name) + 1;
949 if (pos->mime_type != NULL)
950 left -= strlen (pos->mime_type) + 1;
956 /* nothing fit, only write header! */
957 ihdr.version = htonl (2);
958 ihdr.entries = htonl (0);
959 ihdr.size = htonl (0);
961 *target = GNUNET_malloc (sizeof (struct MetaDataHeader));
962 memcpy (*target, &ihdr, sizeof (struct MetaDataHeader));
963 return sizeof (struct MetaDataHeader);
968 * Get the size of the full meta-data in serialized form.
970 * @param md metadata to inspect
971 * @return number of bytes needed for serialization, -1 on error
974 GNUNET_CONTAINER_meta_data_get_serialized_size (const struct
975 GNUNET_CONTAINER_MetaData *md)
980 if (md->sbuf != NULL)
981 return md->sbuf_size;
984 GNUNET_CONTAINER_meta_data_serialize (md, &ptr, GNUNET_MAX_MALLOC_CHECKED,
985 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
993 * Decompress input, return the decompressed data
994 * as output, set outputSize to the number of bytes
997 * @param input compressed data
998 * @param inputSize number of bytes in input
999 * @param outputSize expected size of the output
1000 * @return NULL on error
1003 decompress (const char *input, size_t inputSize, size_t outputSize)
1009 output = GNUNET_malloc (olen);
1011 uncompress ((Bytef *) output, &olen, (const Bytef *) input, inputSize))
1017 GNUNET_free (output);
1024 * Deserialize meta-data. Initializes md.
1026 * @param input buffer with the serialized metadata
1027 * @param size number of bytes available in input
1028 * @return MD on success, NULL on error (i.e.
1031 struct GNUNET_CONTAINER_MetaData *
1032 GNUNET_CONTAINER_meta_data_deserialize (const char *input, size_t size)
1034 struct GNUNET_CONTAINER_MetaData *md;
1035 struct MetaDataHeader hdr;
1036 struct MetaDataEntry ent;
1049 const char *meta_data;
1050 const char *plugin_name;
1051 const char *mime_type;
1052 enum EXTRACTOR_MetaFormat format;
1054 if (size < sizeof (struct MetaDataHeader))
1056 memcpy (&hdr, input, sizeof (struct MetaDataHeader));
1057 version = ntohl (hdr.version) & HEADER_VERSION_MASK;
1058 compressed = (ntohl (hdr.version) & HEADER_COMPRESSED) != 0;
1061 return NULL; /* null pointer */
1064 GNUNET_break_op (0); /* unsupported version */
1068 ic = ntohl (hdr.entries);
1069 dataSize = ntohl (hdr.size);
1070 if ((sizeof (struct MetaDataEntry) * ic) > dataSize)
1072 GNUNET_break_op (0);
1078 if (dataSize >= GNUNET_MAX_MALLOC_CHECKED)
1080 /* make sure we don't blow our memory limit because of a mal-formed
1082 GNUNET_break_op (0);
1086 decompress ((const char *) &input[sizeof (struct MetaDataHeader)],
1087 size - sizeof (struct MetaDataHeader), dataSize);
1090 GNUNET_break_op (0);
1098 cdata = (const char *) &input[sizeof (struct MetaDataHeader)];
1099 if (dataSize != size - sizeof (struct MetaDataHeader))
1101 GNUNET_break_op (0);
1106 md = GNUNET_CONTAINER_meta_data_create ();
1107 left = dataSize - ic * sizeof (struct MetaDataEntry);
1108 mdata = &cdata[ic * sizeof (struct MetaDataEntry)];
1109 for (i = 0; i < ic; i++)
1111 memcpy (&ent, &cdata[i * sizeof (struct MetaDataEntry)],
1112 sizeof (struct MetaDataEntry));
1113 format = (enum EXTRACTOR_MetaFormat) ntohl (ent.format);
1114 if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
1115 (format != EXTRACTOR_METAFORMAT_C_STRING) &&
1116 (format != EXTRACTOR_METAFORMAT_BINARY))
1118 GNUNET_break_op (0);
1121 dlen = ntohl (ent.data_size);
1122 plen = ntohl (ent.plugin_name_len);
1123 mlen = ntohl (ent.mime_type_len);
1126 GNUNET_break_op (0);
1130 meta_data = &mdata[left];
1131 if ((format == EXTRACTOR_METAFORMAT_UTF8) ||
1132 (format == EXTRACTOR_METAFORMAT_C_STRING))
1134 if ((dlen == 0) || (mdata[left + dlen - 1] != '\0'))
1136 GNUNET_break_op (0);
1142 GNUNET_break_op (0);
1146 if ((plen > 0) && (mdata[left + plen - 1] != '\0'))
1148 GNUNET_break_op (0);
1154 plugin_name = &mdata[left];
1158 GNUNET_break_op (0);
1162 if ((mlen > 0) && (mdata[left + mlen - 1] != '\0'))
1164 GNUNET_break_op (0);
1170 mime_type = &mdata[left];
1171 GNUNET_CONTAINER_meta_data_insert (md, plugin_name,
1172 (enum EXTRACTOR_MetaType)
1173 ntohl (ent.type), format, mime_type,
1176 GNUNET_free_non_null (data);
1181 /* end of container_meta_data.c */