aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-05-31 08:24:42 +0000
committerChristian Grothoff <christian@grothoff.org>2010-05-31 08:24:42 +0000
commit5554d773fef027d978d8b94f2cfe10b3206c5916 (patch)
tree22c4d3cf3b820248a15fa86552dfa3d505dbc09d /src
parent46e277f53de5d77ba4414c178b511278c21b1789 (diff)
downloadgnunet-5554d773fef027d978d8b94f2cfe10b3206c5916.tar.gz
gnunet-5554d773fef027d978d8b94f2cfe10b3206c5916.zip
done
Diffstat (limited to 'src')
-rw-r--r--src/fs/fs_file_information.c74
-rw-r--r--src/fs/test_fs_file_information.c58
-rw-r--r--src/fs/test_fs_file_information_meta_data_image.jpg (renamed from src/util/test_container_meta_data_image.jpg)bin136107 -> 136107 bytes
-rw-r--r--src/include/gnunet_container_lib.h15
-rw-r--r--src/include/gnunet_fs_service.h17
-rw-r--r--src/util/Makefile.am3
-rw-r--r--src/util/container_meta_data.c65
-rw-r--r--src/util/test_container_meta_data.c56
8 files changed, 147 insertions, 141 deletions
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
@@ -36,6 +36,74 @@
36 36
37 37
38/** 38/**
39 * Add meta data that libextractor finds to our meta data
40 * container.
41 *
42 * @param cls closure, our meta data container
43 * @param plugin_name name of the plugin that produced this value;
44 * special values can be used (i.e. '&lt;zlib&gt;' for zlib being
45 * used in the main libextractor library and yielding
46 * meta data).
47 * @param type libextractor-type describing the meta data
48 * @param format basic format information about data
49 * @param data_mime_type mime-type of data (not of the original file);
50 * can be NULL (if mime-type is not known)
51 * @param data actual meta-data found
52 * @param data_len number of bytes in data
53 * @return always 0 to continue extracting
54 */
55static int
56add_to_md(void *cls,
57 const char *plugin_name,
58 enum EXTRACTOR_MetaType type,
59 enum EXTRACTOR_MetaFormat format,
60 const char *data_mime_type,
61 const char *data,
62 size_t data_len)
63{
64 struct GNUNET_CONTAINER_MetaData *md = cls;
65 (void) GNUNET_CONTAINER_meta_data_insert (md,
66 plugin_name,
67 type,
68 format,
69 data_mime_type,
70 data,
71 data_len);
72 return 0;
73}
74
75
76/**
77 * Extract meta-data from a file.
78 *
79 * @return GNUNET_SYSERR on error, otherwise the number
80 * of meta-data items obtained
81 */
82int
83GNUNET_FS_meta_data_extract_from_file (struct GNUNET_CONTAINER_MetaData
84 *md, const char *filename,
85 struct EXTRACTOR_PluginList *
86 extractors)
87{
88 int old;
89
90 if (filename == NULL)
91 return GNUNET_SYSERR;
92 if (extractors == NULL)
93 return 0;
94 old = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL);
95 GNUNET_assert (old >= 0);
96 EXTRACTOR_extract (extractors,
97 filename,
98 NULL, 0,
99 &add_to_md,
100 md);
101 return (GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL) - old);
102}
103
104
105
106/**
39 * Obtain the name under which this file information 107 * Obtain the name under which this file information
40 * structure is stored on disk. Only works for top-level 108 * structure is stored on disk. Only works for top-level
41 * file information structures. 109 * file information structures.
@@ -350,9 +418,9 @@ dir_scan_cb (void *cls,
350 else 418 else
351 { 419 {
352 meta = GNUNET_CONTAINER_meta_data_create (); 420 meta = GNUNET_CONTAINER_meta_data_create ();
353 GNUNET_CONTAINER_meta_data_extract_from_file (meta, 421 GNUNET_FS_meta_data_extract_from_file (meta,
354 filename, 422 filename,
355 dsc->extractors); 423 dsc->extractors);
356 // FIXME: remove path from filename in metadata! 424 // FIXME: remove path from filename in metadata!
357 keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta); 425 keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
358 ksk_uri = GNUNET_FS_uri_ksk_canonicalize (keywords); 426 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,
155} 155}
156 156
157 157
158static int
159testThumbnail ()
160{
161 struct GNUNET_CONTAINER_MetaData *m;
162 struct GNUNET_CONTAINER_MetaData *d;
163 struct EXTRACTOR_PluginList *ex;
164 unsigned char *thumb;
165 size_t size;
166 char *date;
167
168 ex = EXTRACTOR_plugin_add_config (NULL, "thumbnailgtk", EXTRACTOR_OPTION_DEFAULT_POLICY);
169 if (ex == NULL)
170 {
171 fprintf (stderr,
172 "Test incomplete, have no GTK thumbnail extractor available.\n");
173 return 0; /* can not test, no thumbnailer */
174 }
175 ex = EXTRACTOR_plugin_add_config (ex, "mime", EXTRACTOR_OPTION_DEFAULT_POLICY);
176 m = GNUNET_CONTAINER_meta_data_create ();
177 if (3 != GNUNET_FS_meta_data_extract_from_file (m,
178 "test_fs_file_information_meta_data_image.jpg",
179 ex))
180 {
181 GNUNET_break (0);
182 EXTRACTOR_plugin_remove_all (ex);
183 GNUNET_CONTAINER_meta_data_destroy (m);
184 return 1;
185 }
186 EXTRACTOR_plugin_remove_all (ex);
187 d = GNUNET_CONTAINER_meta_data_duplicate (m);
188 GNUNET_CONTAINER_meta_data_destroy (m);
189 thumb = NULL;
190 size = GNUNET_CONTAINER_meta_data_get_thumbnail (d, &thumb);
191 if (size == 0)
192 {
193 GNUNET_break (0);
194 GNUNET_CONTAINER_meta_data_destroy (d);
195 return 1;
196 }
197 GNUNET_free (thumb);
198 GNUNET_CONTAINER_meta_data_add_publication_date (d);
199 date = GNUNET_CONTAINER_meta_data_get_by_type (d,
200 EXTRACTOR_METATYPE_PUBLICATION_DATE);
201 if (date == NULL)
202 {
203 GNUNET_break (0);
204 GNUNET_CONTAINER_meta_data_destroy (d);
205 return 1;
206 }
207 GNUNET_free (date);
208 GNUNET_CONTAINER_meta_data_destroy (d);
209 return 0;
210}
211
212
213
158int 214int
159main (int argc, char *argv[]) 215main (int argc, char *argv[])
160{ 216{
@@ -178,6 +234,8 @@ main (int argc, char *argv[])
178 "WARNING", 234 "WARNING",
179#endif 235#endif
180 NULL); 236 NULL);
237 if (0 != testThumbnail ())
238 return 1;
181 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 239 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
182 argvx, "test-fs-file_information", 240 argvx, "test-fs-file_information",
183 "nohelp", options, &run, NULL); 241 "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
index 3d1ba3307..3d1ba3307 100644
--- a/src/util/test_container_meta_data_image.jpg
+++ b/src/fs/test_fs_file_information_meta_data_image.jpg
Binary files differ
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
365 GNUNET_CONTAINER_MetaData 365 GNUNET_CONTAINER_MetaData
366 *md, unsigned char **thumb); 366 *md, unsigned char **thumb);
367 367
368/**
369 * Extract meta-data from a file.
370 *
371 * @param md metadata to set
372 * @param filename name of file to inspect
373 * @param extractors plugins to use
374 * @return GNUNET_SYSERR on error, otherwise the number
375 * of meta-data items obtained
376 */
377int
378GNUNET_CONTAINER_meta_data_extract_from_file (struct
379 GNUNET_CONTAINER_MetaData
380 *md, const char *filename,
381 struct EXTRACTOR_PluginList *
382 extractors);
383 368
384 369
385/** 370/**
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
@@ -1574,6 +1574,23 @@ GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
1574 1574
1575 1575
1576/** 1576/**
1577 * Extract meta-data from a file.
1578 *
1579 * @param md metadata to set
1580 * @param filename name of file to inspect
1581 * @param extractors plugins to use
1582 * @return GNUNET_SYSERR on error, otherwise the number
1583 * of meta-data items obtained
1584 */
1585int
1586GNUNET_FS_meta_data_extract_from_file (struct
1587 GNUNET_CONTAINER_MetaData
1588 *md, const char *filename,
1589 struct EXTRACTOR_PluginList *
1590 extractors);
1591
1592
1593/**
1577 * Function called on entries in a GNUNET_FS_FileInformation publish-structure. 1594 * Function called on entries in a GNUNET_FS_FileInformation publish-structure.
1578 * 1595 *
1579 * @param cls closure 1596 * @param cls closure
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 = \
71libgnunetutil_la_LIBADD = \ 71libgnunetutil_la_LIBADD = \
72 $(GCLIBADD) $(WINLIB) \ 72 $(GCLIBADD) $(WINLIB) \
73 $(LIBGCRYPT_LIBS) \ 73 $(LIBGCRYPT_LIBS) \
74 -lgmp -lltdl -lz -lextractor $(XLIB) 74 -lgmp -lltdl -lz $(XLIB)
75 75
76libgnunetutil_la_LDFLAGS = \ 76libgnunetutil_la_LDFLAGS = \
77 $(GN_LIB_LDFLAGS) \ 77 $(GN_LIB_LDFLAGS) \
@@ -373,7 +373,6 @@ EXTRA_DIST = \
373 program_lib_strnlen.c \ 373 program_lib_strnlen.c \
374 program_lib_mempcpy.c \ 374 program_lib_mempcpy.c \
375 test_configuration_data.conf \ 375 test_configuration_data.conf \
376 test_container_meta_data_image.jpg \
377 test_program_data.conf \ 376 test_program_data.conf \
378 test_pseudonym_data.conf \ 377 test_pseudonym_data.conf \
379 test_resolver_api_data.conf \ 378 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
608} 608}
609 609
610 610
611/**
612 * Add meta data that libextractor finds to our meta data
613 * container.
614 *
615 * @param cls closure, our meta data container
616 * @param plugin_name name of the plugin that produced this value;
617 * special values can be used (i.e. '&lt;zlib&gt;' for zlib being
618 * used in the main libextractor library and yielding
619 * meta data).
620 * @param type libextractor-type describing the meta data
621 * @param format basic format information about data
622 * @param data_mime_type mime-type of data (not of the original file);
623 * can be NULL (if mime-type is not known)
624 * @param data actual meta-data found
625 * @param data_len number of bytes in data
626 * @return always 0 to continue extracting
627 */
628static int
629add_to_md(void *cls,
630 const char *plugin_name,
631 enum EXTRACTOR_MetaType type,
632 enum EXTRACTOR_MetaFormat format,
633 const char *data_mime_type,
634 const char *data,
635 size_t data_len)
636{
637 struct GNUNET_CONTAINER_MetaData *md = cls;
638 (void) GNUNET_CONTAINER_meta_data_insert (md,
639 plugin_name,
640 type,
641 format,
642 data_mime_type,
643 data,
644 data_len);
645 return 0;
646}
647
648
649/**
650 * Extract meta-data from a file.
651 *
652 * @return GNUNET_SYSERR on error, otherwise the number
653 * of meta-data items obtained
654 */
655int
656GNUNET_CONTAINER_meta_data_extract_from_file (struct GNUNET_CONTAINER_MetaData
657 *md, const char *filename,
658 struct EXTRACTOR_PluginList *
659 extractors)
660{
661 unsigned int old;
662
663 if (filename == NULL)
664 return GNUNET_SYSERR;
665 if (extractors == NULL)
666 return 0;
667 old = md->item_count;
668 EXTRACTOR_extract (extractors,
669 filename,
670 NULL, 0,
671 &add_to_md,
672 md);
673 return (int) (md->item_count - old);
674}
675
676 611
677/** 612/**
678 * Try to compress the given block of data. 613 * 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 ()
231} 231}
232 232
233 233
234static int
235testThumbnail ()
236{
237 struct GNUNET_CONTAINER_MetaData *m;
238 struct GNUNET_CONTAINER_MetaData *d;
239 struct EXTRACTOR_PluginList *ex;
240 unsigned char *thumb;
241 size_t size;
242 char *date;
243
244 ex = EXTRACTOR_plugin_add_config (NULL, "thumbnailgtk", EXTRACTOR_OPTION_DEFAULT_POLICY);
245 if (ex == NULL)
246 {
247 fprintf (stderr,
248 "Test incomplete, have no GTK thumbnail extractor available.\n");
249 return 0; /* can not test, no thumbnailer */
250 }
251 ex = EXTRACTOR_plugin_add_config (ex, "mime", EXTRACTOR_OPTION_DEFAULT_POLICY);
252 m = GNUNET_CONTAINER_meta_data_create ();
253 if (3 != GNUNET_CONTAINER_meta_data_extract_from_file (m,
254 "test_container_meta_data_image.jpg",
255 ex))
256 {
257 GNUNET_break (0);
258 EXTRACTOR_plugin_remove_all (ex);
259 GNUNET_CONTAINER_meta_data_destroy (m);
260 return 1;
261 }
262 EXTRACTOR_plugin_remove_all (ex);
263 d = GNUNET_CONTAINER_meta_data_duplicate (m);
264 GNUNET_CONTAINER_meta_data_destroy (m);
265 thumb = NULL;
266 size = GNUNET_CONTAINER_meta_data_get_thumbnail (d, &thumb);
267 if (size == 0)
268 {
269 GNUNET_break (0);
270 GNUNET_CONTAINER_meta_data_destroy (d);
271 return 1;
272 }
273 GNUNET_free (thumb);
274 GNUNET_CONTAINER_meta_data_add_publication_date (d);
275 date = GNUNET_CONTAINER_meta_data_get_by_type (d,
276 EXTRACTOR_METATYPE_PUBLICATION_DATE);
277 if (date == NULL)
278 {
279 GNUNET_break (0);
280 GNUNET_CONTAINER_meta_data_destroy (d);
281 return 1;
282 }
283 GNUNET_free (date);
284 GNUNET_CONTAINER_meta_data_destroy (d);
285 return 0;
286}
287
288
289int 234int
290main (int argc, char *argv[]) 235main (int argc, char *argv[])
291{ 236{
@@ -298,7 +243,6 @@ main (int argc, char *argv[])
298 for (i = 1; i < 255; i++) 243 for (i = 1; i < 255; i++)
299 failureCount += testMetaMore (i); 244 failureCount += testMetaMore (i);
300 failureCount += testMetaLink (); 245 failureCount += testMetaLink ();
301 failureCount += testThumbnail ();
302 246
303 if (failureCount != 0) 247 if (failureCount != 0)
304 return 1; 248 return 1;