X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Fcontainer_meta_data.c;h=039ba86ab2dfc4c26dca7a3194efced41aa99e3b;hb=555214089c7045298f23fea9e060ea931804e75f;hp=e9c33bab2af50cbdf13aaf794ecc24852b4ad85b;hpb=af252789c772264032750979f5a6b1a23bdce02a;p=oweals%2Fgnunet.git diff --git a/src/util/container_meta_data.c b/src/util/container_meta_data.c index e9c33bab2..039ba86ab 100644 --- a/src/util/container_meta_data.c +++ b/src/util/container_meta_data.c @@ -169,6 +169,29 @@ GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md) } +/** + * Remove all items in the container. + * + * @param md metadata to manipulate + */ +void +GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md) +{ + struct MetaItem *item; + + if (md == NULL) + return; + while (NULL != (item = md->items)) + { + md->items = item->next; + meta_item_free (item); + } + GNUNET_free_non_null (md->sbuf); + memset (md, 0, sizeof (struct GNUNET_CONTAINER_MetaData)); +} + + + /** * Test if two MDs are equal. We consider them equal if * the meta types, formats and content match (we do not @@ -451,6 +474,8 @@ GNUNET_CONTAINER_meta_data_iterate (const struct { struct MetaItem *pos; + if (md == NULL) + return 0; if (iter == NULL) return md->item_count; pos = md->items; @@ -486,6 +511,8 @@ GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData { struct MetaItem *pos; + if (md == NULL) + return NULL; pos = md->items; while (NULL != pos) { @@ -519,6 +546,8 @@ GNUNET_CONTAINER_meta_data_get_first_by_types (const struct va_list args; enum EXTRACTOR_MetaType type; + if (md == NULL) + return NULL; ret = NULL; va_start (args, md); while (1) @@ -551,11 +580,14 @@ GNUNET_CONTAINER_meta_data_get_thumbnail (const struct struct MetaItem *pos; struct MetaItem *match; + if (md == NULL) + return 0; match = NULL; pos = md->items; while (NULL != pos) - { - if ( (0 == strncasecmp ("image/", pos->mime_type, + { + if ( (NULL != pos->mime_type) && + (0 == strncasecmp ("image/", pos->mime_type, strlen("image/"))) && (pos->format == EXTRACTOR_METAFORMAT_BINARY) ) { @@ -608,71 +640,6 @@ GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData } -/** - * Add meta data that libextractor finds to our meta data - * container. - * - * @param cls closure, our meta data container - * @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 always 0 to continue extracting - */ -static int -add_to_md(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 GNUNET_CONTAINER_MetaData *md = cls; - (void) GNUNET_CONTAINER_meta_data_insert (md, - plugin_name, - type, - format, - data_mime_type, - data, - data_len); - return 0; -} - - -/** - * Extract meta-data from a file. - * - * @return GNUNET_SYSERR on error, otherwise the number - * of meta-data items obtained - */ -int -GNUNET_CONTAINER_meta_data_extract_from_file (struct GNUNET_CONTAINER_MetaData - *md, const char *filename, - struct EXTRACTOR_PluginList * - extractors) -{ - unsigned int old; - - if (filename == NULL) - return GNUNET_SYSERR; - if (extractors == NULL) - return 0; - old = md->item_count; - EXTRACTOR_extract (extractors, - filename, - NULL, 0, - &add_to_md, - md); - return (int) (md->item_count - old); -} - /** * Try to compress the given block of data.