add keywords from metadata for files
authorChristian Grothoff <christian@grothoff.org>
Thu, 23 Dec 2010 19:39:53 +0000 (19:39 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 23 Dec 2010 19:39:53 +0000 (19:39 +0000)
src/fs/gnunet-publish.c

index 36e75a4ea63b7fab5714a7fff7f1a5b323143f4a..06040359866f5ace90a5e331f68083cbc6c0adb0 100644 (file)
@@ -209,6 +209,27 @@ meta_printer (void *cls,
 }
 
 
+/**
+ * Iterator printing keywords
+ *
+ * @param cls closure
+ * @param keyword the keyword
+ * @param is_mandatory is the keyword mandatory (in a search)
+ * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort
+ */
+
+static int
+keyword_printer (void *cls,
+                const char *keyword,
+                int is_mandatory)
+{
+  fprintf (stdout, 
+          "\t%s\n",
+          keyword);
+  return 0;
+}
+
+
 /**
  * Function called on all entries before the publication.  This is
  * where we perform modifications to the default based on command-line
@@ -276,14 +297,22 @@ publish_inspector (void *cls,
                                                   EXTRACTOR_METATYPE_FILENAME);
       fs = GNUNET_STRINGS_byte_size_fancy (length);
       fprintf (stdout,
-              _("Keywords for file `%s' (%s)\n"),
+              _("Meta data for file `%s' (%s)\n"),
               fn,
               fs);
-      GNUNET_free (fn);
-      GNUNET_free (fs);
       GNUNET_CONTAINER_meta_data_iterate (m,
                                          &meta_printer,
                                          NULL);
+      fprintf (stdout,
+              _("Keywords for file `%s' (%s)\n"),
+              fn,
+              fs);
+      GNUNET_free (fn);
+      GNUNET_free (fs);
+      if (NULL != *uri)
+       GNUNET_FS_uri_ksk_get_keywords (*uri,
+                                       &keyword_printer,
+                                       NULL);
       fprintf (stdout, "\n");
     }
   if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (m))
@@ -381,6 +410,7 @@ run (void *cls,
   struct GNUNET_FS_FileInformation *fi;
   struct GNUNET_FS_Namespace *namespace;
   struct EXTRACTOR_PluginList *plugins;
+  struct GNUNET_FS_Uri *keywords;
   struct stat sbuf;
   char *ex;
   char *emsg;
@@ -538,16 +568,18 @@ run (void *cls,
       GNUNET_FS_meta_data_extract_from_file (meta,
                                             args[0],
                                             plugins);
+      keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
       fi = GNUNET_FS_file_information_create_from_file (ctx,
                                                        NULL,
                                                        args[0],
-                                                       NULL,
+                                                       keywords,
                                                        NULL,
                                                        !do_insert,
                                                        anonymity,
                                                        priority,
                                                        GNUNET_TIME_relative_to_absolute (DEFAULT_EXPIRATION));
       GNUNET_break (fi != NULL);
+      GNUNET_FS_uri_destroy (keywords);
     }
   EXTRACTOR_plugin_remove_all (plugins);  
   if (fi == NULL)