From 5554d773fef027d978d8b94f2cfe10b3206c5916 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 31 May 2010 08:24:42 +0000 Subject: [PATCH] done --- TODO | 5 -- src/fs/fs_file_information.c | 74 +++++++++++++++++- src/fs/test_fs_file_information.c | 58 ++++++++++++++ ...t_fs_file_information_meta_data_image.jpg} | Bin src/include/gnunet_container_lib.h | 15 ---- src/include/gnunet_fs_service.h | 17 ++++ src/util/Makefile.am | 3 +- src/util/container_meta_data.c | 65 --------------- src/util/test_container_meta_data.c | 56 ------------- 9 files changed, 147 insertions(+), 146 deletions(-) rename src/{util/test_container_meta_data_image.jpg => fs/test_fs_file_information_meta_data_image.jpg} (100%) diff --git a/TODO b/TODO index c4d784bef..da8e2d07b 100644 --- a/TODO +++ b/TODO @@ -135,11 +135,6 @@ - figure out where in the GUI we should show active uploads/unindex operations and allow aborts * SETUP: - design & implement new setup tool -* UTIL: - - remove dependency on GNU LE from util (linker-wise) so that - not all binaries are linked against LE! (header is OK!) - (seems that only GNUNET_CONTAINER_meta_data_extract_from_file - needs to be moved to another location, i.e. FS/file-info for this!) 0.9.0pre3: * TRACEKIT: [MW] diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c index d9acc9595..c04c5a56e 100644 --- a/src/fs/fs_file_information.c +++ b/src/fs/fs_file_information.c @@ -35,6 +35,74 @@ #include "fs_tree.h" +/** + * 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_FS_meta_data_extract_from_file (struct GNUNET_CONTAINER_MetaData + *md, const char *filename, + struct EXTRACTOR_PluginList * + extractors) +{ + int old; + + if (filename == NULL) + return GNUNET_SYSERR; + if (extractors == NULL) + return 0; + old = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL); + GNUNET_assert (old >= 0); + EXTRACTOR_extract (extractors, + filename, + NULL, 0, + &add_to_md, + md); + return (GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL) - old); +} + + + /** * Obtain the name under which this file information * structure is stored on disk. Only works for top-level @@ -350,9 +418,9 @@ dir_scan_cb (void *cls, else { meta = GNUNET_CONTAINER_meta_data_create (); - GNUNET_CONTAINER_meta_data_extract_from_file (meta, - filename, - dsc->extractors); + GNUNET_FS_meta_data_extract_from_file (meta, + filename, + dsc->extractors); // FIXME: remove path from filename in metadata! keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta); ksk_uri = GNUNET_FS_uri_ksk_canonicalize (keywords); diff --git a/src/fs/test_fs_file_information.c b/src/fs/test_fs_file_information.c index c5b4ec997..2d66d5185 100644 --- a/src/fs/test_fs_file_information.c +++ b/src/fs/test_fs_file_information.c @@ -155,6 +155,62 @@ run (void *cls, } +static int +testThumbnail () +{ + struct GNUNET_CONTAINER_MetaData *m; + struct GNUNET_CONTAINER_MetaData *d; + struct EXTRACTOR_PluginList *ex; + unsigned char *thumb; + size_t size; + char *date; + + ex = EXTRACTOR_plugin_add_config (NULL, "thumbnailgtk", EXTRACTOR_OPTION_DEFAULT_POLICY); + if (ex == NULL) + { + fprintf (stderr, + "Test incomplete, have no GTK thumbnail extractor available.\n"); + return 0; /* can not test, no thumbnailer */ + } + ex = EXTRACTOR_plugin_add_config (ex, "mime", EXTRACTOR_OPTION_DEFAULT_POLICY); + m = GNUNET_CONTAINER_meta_data_create (); + if (3 != GNUNET_FS_meta_data_extract_from_file (m, + "test_fs_file_information_meta_data_image.jpg", + ex)) + { + GNUNET_break (0); + EXTRACTOR_plugin_remove_all (ex); + GNUNET_CONTAINER_meta_data_destroy (m); + return 1; + } + EXTRACTOR_plugin_remove_all (ex); + d = GNUNET_CONTAINER_meta_data_duplicate (m); + GNUNET_CONTAINER_meta_data_destroy (m); + thumb = NULL; + size = GNUNET_CONTAINER_meta_data_get_thumbnail (d, &thumb); + if (size == 0) + { + GNUNET_break (0); + GNUNET_CONTAINER_meta_data_destroy (d); + return 1; + } + GNUNET_free (thumb); + GNUNET_CONTAINER_meta_data_add_publication_date (d); + date = GNUNET_CONTAINER_meta_data_get_by_type (d, + EXTRACTOR_METATYPE_PUBLICATION_DATE); + if (date == NULL) + { + GNUNET_break (0); + GNUNET_CONTAINER_meta_data_destroy (d); + return 1; + } + GNUNET_free (date); + GNUNET_CONTAINER_meta_data_destroy (d); + return 0; +} + + + int main (int argc, char *argv[]) { @@ -178,6 +234,8 @@ main (int argc, char *argv[]) "WARNING", #endif NULL); + if (0 != testThumbnail ()) + return 1; GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, "test-fs-file_information", "nohelp", options, &run, NULL); diff --git a/src/util/test_container_meta_data_image.jpg b/src/fs/test_fs_file_information_meta_data_image.jpg similarity index 100% rename from src/util/test_container_meta_data_image.jpg rename to src/fs/test_fs_file_information_meta_data_image.jpg diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h index 604038955..1ac6cd4ed 100644 --- a/src/include/gnunet_container_lib.h +++ b/src/include/gnunet_container_lib.h @@ -365,21 +365,6 @@ GNUNET_CONTAINER_meta_data_get_thumbnail (const struct GNUNET_CONTAINER_MetaData *md, unsigned char **thumb); -/** - * Extract meta-data from a file. - * - * @param md metadata to set - * @param filename name of file to inspect - * @param extractors plugins to use - * @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); /** diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h index ab0eca8d0..f78ddd0ca 100644 --- a/src/include/gnunet_fs_service.h +++ b/src/include/gnunet_fs_service.h @@ -1573,6 +1573,23 @@ void GNUNET_FS_stop (struct GNUNET_FS_Handle *h); +/** + * Extract meta-data from a file. + * + * @param md metadata to set + * @param filename name of file to inspect + * @param extractors plugins to use + * @return GNUNET_SYSERR on error, otherwise the number + * of meta-data items obtained + */ +int +GNUNET_FS_meta_data_extract_from_file (struct + GNUNET_CONTAINER_MetaData + *md, const char *filename, + struct EXTRACTOR_PluginList * + extractors); + + /** * Function called on entries in a GNUNET_FS_FileInformation publish-structure. * diff --git a/src/util/Makefile.am b/src/util/Makefile.am index a8031d915..2b00e4978 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -71,7 +71,7 @@ libgnunetutil_la_SOURCES = \ libgnunetutil_la_LIBADD = \ $(GCLIBADD) $(WINLIB) \ $(LIBGCRYPT_LIBS) \ - -lgmp -lltdl -lz -lextractor $(XLIB) + -lgmp -lltdl -lz $(XLIB) libgnunetutil_la_LDFLAGS = \ $(GN_LIB_LDFLAGS) \ @@ -373,7 +373,6 @@ EXTRA_DIST = \ program_lib_strnlen.c \ program_lib_mempcpy.c \ test_configuration_data.conf \ - test_container_meta_data_image.jpg \ test_program_data.conf \ test_pseudonym_data.conf \ test_resolver_api_data.conf \ diff --git a/src/util/container_meta_data.c b/src/util/container_meta_data.c index e9c33bab2..f39b15930 100644 --- a/src/util/container_meta_data.c +++ b/src/util/container_meta_data.c @@ -608,71 +608,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. diff --git a/src/util/test_container_meta_data.c b/src/util/test_container_meta_data.c index b6196da14..a439362d0 100644 --- a/src/util/test_container_meta_data.c +++ b/src/util/test_container_meta_data.c @@ -231,61 +231,6 @@ testMetaLink () } -static int -testThumbnail () -{ - struct GNUNET_CONTAINER_MetaData *m; - struct GNUNET_CONTAINER_MetaData *d; - struct EXTRACTOR_PluginList *ex; - unsigned char *thumb; - size_t size; - char *date; - - ex = EXTRACTOR_plugin_add_config (NULL, "thumbnailgtk", EXTRACTOR_OPTION_DEFAULT_POLICY); - if (ex == NULL) - { - fprintf (stderr, - "Test incomplete, have no GTK thumbnail extractor available.\n"); - return 0; /* can not test, no thumbnailer */ - } - ex = EXTRACTOR_plugin_add_config (ex, "mime", EXTRACTOR_OPTION_DEFAULT_POLICY); - m = GNUNET_CONTAINER_meta_data_create (); - if (3 != GNUNET_CONTAINER_meta_data_extract_from_file (m, - "test_container_meta_data_image.jpg", - ex)) - { - GNUNET_break (0); - EXTRACTOR_plugin_remove_all (ex); - GNUNET_CONTAINER_meta_data_destroy (m); - return 1; - } - EXTRACTOR_plugin_remove_all (ex); - d = GNUNET_CONTAINER_meta_data_duplicate (m); - GNUNET_CONTAINER_meta_data_destroy (m); - thumb = NULL; - size = GNUNET_CONTAINER_meta_data_get_thumbnail (d, &thumb); - if (size == 0) - { - GNUNET_break (0); - GNUNET_CONTAINER_meta_data_destroy (d); - return 1; - } - GNUNET_free (thumb); - GNUNET_CONTAINER_meta_data_add_publication_date (d); - date = GNUNET_CONTAINER_meta_data_get_by_type (d, - EXTRACTOR_METATYPE_PUBLICATION_DATE); - if (date == NULL) - { - GNUNET_break (0); - GNUNET_CONTAINER_meta_data_destroy (d); - return 1; - } - GNUNET_free (date); - GNUNET_CONTAINER_meta_data_destroy (d); - return 0; -} - - int main (int argc, char *argv[]) { @@ -298,7 +243,6 @@ main (int argc, char *argv[]) for (i = 1; i < 255; i++) failureCount += testMetaMore (i); failureCount += testMetaLink (); - failureCount += testThumbnail (); if (failureCount != 0) return 1; -- 2.25.1