merge meta data for search results
authorChristian Grothoff <christian@grothoff.org>
Wed, 28 Apr 2010 08:07:19 +0000 (08:07 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 28 Apr 2010 08:07:19 +0000 (08:07 +0000)
src/fs/fs_search.c
src/fs/gnunet-publish.c
src/include/gnunet_container_lib.h
src/util/container_meta_data.c
src/util/pseudonym.c

index c75b21668363e94486c23753ec97a539e891f544..b5b7a3c8a77d8b1576cb7fd326f1232a33318b52 100644 (file)
@@ -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)
index f341594c5d1ae71e91c6bed5aaaba9f6a313918d..279eedcced74878e14aac52185a1a4887e57ffe0 100644 (file)
@@ -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;
     }
index 6ab61dfdadfe6332f568ea829d06a72d13d8a53f..60403895513f2897f5255bb229821f81486af2a1 100644 (file)
@@ -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.
  *
index 89a63d659b860fd6bc7b885ef4f2af360fdaa2fd..e44984b649f03f489d928d8b2284b7ef5f90c9ab 100644 (file)
@@ -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. '<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)
+ */ 
+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.
  *
index fcef2e9f86c8d2bbe29d30b2ca038ac7ed44ab20..643d5717e72308df3006a723e3caa03ca53acb27 100644 (file)
@@ -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);