From: Christian Grothoff Date: Wed, 28 Apr 2010 08:07:19 +0000 (+0000) Subject: merge meta data for search results X-Git-Tag: initial-import-from-subversion-38251~21988 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=b393f0f2c8f2075c16310a8edbe552020fd8b147;p=oweals%2Fgnunet.git merge meta data for search results --- diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index c75b21668..b5b7a3c8a 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c @@ -234,7 +234,7 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc, } else { - /* FIXME: consider combining the meta data */ + GNUNET_CONTAINER_meta_data_merge (sr->meta, meta); } /* check if mandatory satisfied */ if (ent->mandatory) diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c index f341594c5..279eedcce 100644 --- a/src/fs/gnunet-publish.c +++ b/src/fs/gnunet-publish.c @@ -215,40 +215,6 @@ meta_printer (void *cls, } -/** - * Merge metadata entries. - * - * @param cls closure, target metadata structure - * @param plugin_name name of the plugin that generated the meta data - * @param type type of the meta data - * @param format format of data - * @param data_mime_type mime type of data - * @param data value of the meta data - * @param data_size number of bytes in data - * @return always 0 - */ -static int -meta_merger (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_size) -{ - struct GNUNET_CONTAINER_MetaData *m = cls; - - GNUNET_CONTAINER_meta_data_insert (m, - plugin_name, - type, - format, - data_mime_type, - data, - data_size); - return 0; -} - - /** * Function called on all entries before the publication. This is * where we perform modifications to the default based on command-line @@ -302,9 +268,7 @@ publish_inspector (void *cls, } if (NULL != meta) { - GNUNET_CONTAINER_meta_data_iterate (meta, - &meta_merger, - m); + GNUNET_CONTAINER_meta_data_merge (m, meta); GNUNET_CONTAINER_meta_data_destroy (meta); meta = NULL; } diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h index 6ab61dfda..604038955 100644 --- a/src/include/gnunet_container_lib.h +++ b/src/include/gnunet_container_lib.h @@ -265,6 +265,18 @@ GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, size_t data_len); +/** + * Extend metadata. Merges the meta data from the second argument + * into the first, discarding duplicate key-value pairs. + * + * @param md metadata to extend + * @param in metadata to merge + */ +void +GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md, + const struct GNUNET_CONTAINER_MetaData *in); + + /** * Remove an item. * diff --git a/src/util/container_meta_data.c b/src/util/container_meta_data.c index 89a63d659..e44984b64 100644 --- a/src/util/container_meta_data.c +++ b/src/util/container_meta_data.c @@ -310,6 +310,54 @@ GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, } +/** + * Merge given meta data. + * + * @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. '' 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) + */ +static int +merge_helper(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; +} + + +/** + * Extend metadata. Merges the meta data from the second argument + * into the first, discarding duplicate key-value pairs. + * + * @param md metadata to extend + * @param in metadata to merge + */ +void +GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md, + const struct GNUNET_CONTAINER_MetaData *in) +{ + GNUNET_CONTAINER_meta_data_iterate (in, &merge_helper, md); +} + + /** * Remove an item. * diff --git a/src/util/pseudonym.c b/src/util/pseudonym.c index fcef2e9f8..643d5717e 100644 --- a/src/util/pseudonym.c +++ b/src/util/pseudonym.c @@ -538,38 +538,6 @@ GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg, } -/** - * Insert metadata into existing MD record (passed as cls). - * - * @param cls metadata to add to - * @param plugin_name name of the plugin that generated the meta data - * @param type type of entry to insert - * @param format format of data - * @param data_mime_type mime type of data - * @param data value of the meta data - * @param data_len number of bytes in data - * @return always 0 - */ -static int -merge_meta_helper (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 *meta = cls; - - (void) GNUNET_CONTAINER_meta_data_insert (meta, plugin_name, - type, format, - data_mime_type, - data, data_len); - return 0; -} - - - /** * Add a pseudonym to the set of known pseudonyms. * For all pseudonym advertisements that we discover @@ -597,7 +565,7 @@ GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg, if ((0 == STAT (fn, &sbuf)) && (GNUNET_OK == read_info (cfg, id, &old, &ranking, &name))) { - GNUNET_CONTAINER_meta_data_iterate (meta, &merge_meta_helper, old); + GNUNET_CONTAINER_meta_data_merge (old, meta); write_pseudonym_info (cfg, id, old, ranking, name); GNUNET_CONTAINER_meta_data_destroy (old); GNUNET_free_non_null (name);