tracker r1117 - in trunk: . src/tracker-extract



Author: laguerre
Date: Sun Feb  3 22:20:54 2008
New Revision: 1117
URL: http://svn.gnome.org/viewvc/tracker?rev=1117&view=rev

Log:
GNOME Bug #509601: make tracker-extract more modular

Added:
   trunk/src/tracker-extract/tracker-xmp.c   (contents, props changed)
   trunk/src/tracker-extract/tracker-xmp.h   (contents, props changed)
Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/src/tracker-extract/Makefile.am
   trunk/src/tracker-extract/tracker-extract-abw.c
   trunk/src/tracker-extract/tracker-extract-exif.c
   trunk/src/tracker-extract/tracker-extract-gstreamer.c
   trunk/src/tracker-extract/tracker-extract-html.c
   trunk/src/tracker-extract/tracker-extract-imagemagick.c
   trunk/src/tracker-extract/tracker-extract-libxine.c
   trunk/src/tracker-extract/tracker-extract-mp3.c
   trunk/src/tracker-extract/tracker-extract-mplayer.c
   trunk/src/tracker-extract/tracker-extract-msoffice.c
   trunk/src/tracker-extract/tracker-extract-oasis.c
   trunk/src/tracker-extract/tracker-extract-pdf.c
   trunk/src/tracker-extract/tracker-extract-png.c
   trunk/src/tracker-extract/tracker-extract-ps.c
   trunk/src/tracker-extract/tracker-extract-totem.c
   trunk/src/tracker-extract/tracker-extract-vorbis.c
   trunk/src/tracker-extract/tracker-extract-xmp.c
   trunk/src/tracker-extract/tracker-extract.c
   trunk/src/tracker-extract/tracker-extract.h

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Sun Feb  3 22:20:54 2008
@@ -54,6 +54,11 @@
 AC_SUBST(GOBJECT_CFLAGS)
 AC_SUBST(GOBJECT_LIBS)
 
+# Check for gmodule 2.0
+PKG_CHECK_MODULES(GMODULE, [ gmodule-2.0 >= $GLIB_REQUIRED ])
+AC_SUBST(GMODULE_CFLAGS)
+AC_SUBST(GMODULE_LIBS)
+
 #Check for pango
 PKG_CHECK_MODULES(PANGO, [ pango >= $PANGO_REQUIRED ])
 AC_SUBST(PANGO_CFLAGS)
@@ -329,19 +334,19 @@
 fi
 if test "$videos_handler" = "GStreamer"; then
 	AC_DEFINE(HAVE_GSTREAMER, [], [Define if we have GStreamer])
-	AM_CONDITIONAL(USING_GSTREAMER, true)
-	AM_CONDITIONAL(USING_LIBXINE, false)
+	AM_CONDITIONAL(HAVE_GSTREAMER, true)
+	AM_CONDITIONAL(HAVE_LIBXINE, false)
 	AM_CONDITIONAL(USING_EXTERNAL_VIDEO_PLAYER, false)
 elif test "$videos_handler" = "Xine"; then
 	AC_DEFINE(HAVE_LIBXINE, [], [Define if we have Libxine])
-	AM_CONDITIONAL(USING_LIBXINE, true)
+	AM_CONDITIONAL(HAVE_LIBXINE, true)
+	AM_CONDITIONAL(HAVE_GSTREAMER, false)
 	AM_CONDITIONAL(USING_EXTERNAL_VIDEO_PLAYER, false)
-	AM_CONDITIONAL(USING_GSTREAMER, false)
 else
-	AM_CONDITIONAL(USING_EXTERNAL_VIDEO_PLAYER, true)
 	AC_DEFINE(USING_EXTERNAL_VIDEO_PLAYER, [], [Define that Tracker will try to use external video players])
-	AM_CONDITIONAL(USING_LIBXINE, false)
-	AM_CONDITIONAL(USING_GSTREAMER, false)
+	AM_CONDITIONAL(USING_EXTERNAL_VIDEO_PLAYER, true)
+	AM_CONDITIONAL(HAVE_GSTREAMER, false)
+	AM_CONDITIONAL(HAVE_LIBXINE, false)
 fi
 
 

Modified: trunk/src/tracker-extract/Makefile.am
==============================================================================
--- trunk/src/tracker-extract/Makefile.am	(original)
+++ trunk/src/tracker-extract/Makefile.am	Sun Feb  3 22:20:54 2008
@@ -1,52 +1,134 @@
-INCLUDES = $(GLIB2_CFLAGS)			\
-	$(POPPLER_GLIB_CFLAGS)			\
-	$(LIBPNG_CFLAGS)			\
-	$(LIBEXIF_CFLAGS)			\
-	$(LIBGSF_CFLAGS)			\
-	$(LIBGSF_CFLAGS)			\
-	$(GSTREAMER_CFLAGS)			\
-	$(LIBXML2_CFLAGS)			\
-	$(EXEMPI_CFLAGS)			\
-	$(XINE_CFLAGS)
+module_flags = -module -avoid-version -no-undefined
+modulesdir = $(prefix)/lib/tracker/extract-modules
 
-bin_PROGRAMS = tracker-extract
+INCLUDES = \
+	$(GLIB2_CFLAGS) \
+	$(GMODULE_CFLAGS) \
+	$(EXEMPI_CFLAGS) \
+	$(LIBEXIF_CFLAGS) \
+	$(LIBGSF_CFLAGS) \
+	$(LIBXML2_CFLAGS) \
+	$(LIBPNG_CFLAGS) \
+	$(POPPLER_GLIB_CFLAGS) \
+	$(GSTREAMER_CFLAGS) \
+	$(XINE_CFLAGS) \
+	-DMODULES_DIR=\"$(modulesdir)\"
+
+modules_LTLIBRARIES = \
+	libextract-abw.la \
+	libextract-imagemagick.la \
+	libextract-mp3.la \
+	libextract-mplayer.la \
+	libextract-oasis.la \
+	libextract-png.la \
+	libextract-ps.la \
+	libextract-totem.la
+
+if HAVE_EXEMPI
+modules_LTLIBRARIES += libextract-xmp.la
+endif
 
-if USING_GSTREAMER
-video_sources = tracker-extract-gstreamer.c
-else
-if USING_LIBXINE
-video_sources = tracker-extract-libxine.c
-else
-if USING_EXTERNAL_VIDEO_PLAYER
-video_sources =
+if HAVE_LIBEXIF
+modules_LTLIBRARIES += libextract-exif.la
 endif
+
+if HAVE_LIBXML2
+modules_LTLIBRARIES += libextract-html.la
+endif
+
+if HAVE_LIBGSF
+modules_LTLIBRARIES += libextract-msoffice.la
 endif
+
+if HAVE_POPPLER_GLIB
+modules_LTLIBRARIES += libextract-pdf.la
 endif
 
-tracker_extract_SOURCES = tracker-extract.c	\
-	tracker-extract.h			\
-	tracker-extract-oasis.c			\
-	tracker-extract-ps.c			\
-	tracker-extract-pdf.c			\
-	tracker-extract-abw.c			\
-	tracker-extract-png.c			\
-	tracker-extract-mp3.c			\
-	tracker-extract-exif.c			\
-	tracker-extract-msoffice.c		\
-	tracker-extract-imagemagick.c		\
-	tracker-extract-mplayer.c		\
-	tracker-extract-totem.c			\
-	tracker-extract-html.c			\
-	tracker-extract-xmp.c			\
-	$(video_sources)
+if HAVE_GSTREAMER
+modules_LTLIBRARIES += libextract-gstreamer.la
+endif
+
+if HAVE_LIBXINE
+modules_LTLIBRARIES += libextract-xine.la
+endif
+
+libextract_abw_la_SOURCES = tracker-extract-abw.c
+libextract_abw_la_LDFLAGS = $(module_flags)
+libextract_abw_la_LIBADD = $(GLIB2_LIBS)
+
+libextract_imagemagick_la_SOURCES = \
+	tracker-extract-imagemagick.c	\
+	tracker-xmp.c tracker-xmp.h
+libextract_imagemagick_la_LDFLAGS = $(module_flags)
+libextract_imagemagick_la_INCLUDES = $(GLIB2_CFLAGS) $(EXEMPI_CFLAGS)
+libextract_imagemagick_la_LIBADD = $(GLIB2_LIBS) $(EXEMPI_LIBS)
+
+libextract_mp3_la_SOURCES = tracker-extract-mp3.c
+libextract_mp3_la_LDFLAGS = $(module_flags)
+libextract_mp3_la_LIBADD = $(GLIB2_LIBS)
+
+libextract_mplayer_la_SOURCES = tracker-extract-mplayer.c
+libextract_mplayer_la_LDFLAGS = $(module_flags)
+libextract_mplayer_la_LIBADD = $(GLIB2_LIBS)
+
+libextract_oasis_la_SOURCES = tracker-extract-oasis.c
+libextract_oasis_la_LDFLAGS = $(module_flags)
+libextract_oasis_la_LIBADD = $(GLIB2_LIBS)
+
+libextract_png_la_SOURCES = \
+	tracker-extract-png.c	\
+	tracker-xmp.c tracker-xmp.h
+libextract_png_la_LDFLAGS = $(module_flags)
+libextract_png_la_LIBADD = $(GLIB2_LIBS) $(LIBPNG_LIBS) $(EXEMPI_LIBS)
+
+libextract_ps_la_SOURCES = tracker-extract-ps.c
+libextract_ps_la_LDFLAGS = $(module_flags)
+libextract_ps_la_LIBADD = $(GLIB2_LIBS)
+
+libextract_totem_la_SOURCES = tracker-extract-totem.c
+libextract_totem_la_LDFLAGS = $(module_flags)
+libextract_totem_la_LIBADD = $(GLIB2_LIBS)
+
+libextract_xmp_la_SOURCES = \
+	tracker-extract-xmp.c	\
+	tracker-xmp.c tracker-xmp.h
+libextract_xmp_la_LDFLAGS = $(module_flags)
+libextract_xmp_la_LIBADD = $(GLIB2_LIBS) $(EXEMPI_LIBS)
+
+libextract_exif_la_SOURCES = tracker-extract-exif.c
+libextract_exif_la_LDFLAGS = $(module_flags)
+libextract_exif_la_LIBADD = $(GLIB2_LIBS) $(LIBEXIF_LIBS)
+
+libextract_html_la_SOURCES = tracker-extract-html.c
+libextract_html_la_LDFLAGS = $(module_flags)
+libextract_html_la_LIBADD = $(GLIB2_LIBS) $(LIBXML2_LIBS)
+
+libextract_msoffice_la_SOURCES = tracker-extract-msoffice.c
+libextract_msoffice_la_LDFLAGS = $(module_flags)
+libextract_msoffice_la_LIBADD = $(GLIB2_LIBS) $(LIBGSF_LIBS)
+
+libextract_pdf_la_SOURCES = \
+	tracker-extract-pdf.c	\
+	tracker-xmp.c tracker-xmp.h
+libextract_pdf_la_LDFLAGS = $(module_flags)
+libextract_pdf_la_LIBADD = $(GLIB2_LIBS) $(POPPLER_GLIB_LIBS) $(EXEMPI_LIBS)
+
+libextract_gstreamer_la_SOURCES = tracker-extract-gstreamer.c
+libextract_gstreamer_la_LDFLAGS = $(module_flags)
+libextract_gstreamer_la_LIBADD = $(GLIB2_LIBS) $(GSTREAMER_LIBS)
+
+libextract_xine_la_SOURCES = tracker-extract-libxine.c
+libextract_xine_la_LDFLAGS = $(module_flags)
+libextract_xine_la_LIBADD = $(GLIB2_LIBS) $(XINE_LIBS)
+
+
+bin_PROGRAMS = tracker-extract
+
+tracker_extract_SOURCES = \
+	tracker-extract.c			\
+	tracker-extract.h
 
-tracker_extract_LDADD = $(GLIB2_LIBS)		\
+tracker_extract_LDADD = \
+	$(GLIB2_LIBS)				\
 	$(GTHREAD_LIBS)				\
-	$(POPPLER_GLIB_LIBS)			\
-	$(LIBPNG_LIBS)				\
-	$(LIBEXIF_LIBS)				\
-	$(LIBGSF_LIBS)				\
-	$(GSTREAMER_LIBS)			\
-	$(EXEMPI_LIBS)				\
-	$(LIBXML2_LIBS)				\
-	$(XINE_LIBS)
+	$(GMODULE_LIBS)

Modified: trunk/src/tracker-extract/tracker-extract-abw.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-abw.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-abw.c	Sun Feb  3 22:20:54 2008
@@ -28,9 +28,11 @@
 #include <unistd.h>
 #include <glib.h>
 #include <glib/gstdio.h>
+#include "tracker-extract.h"
 
 
-void tracker_extract_abw (gchar *filename, GHashTable *metadata)
+static void
+tracker_extract_abw (const gchar *filename, GHashTable *metadata)
 {
         gint fd;
 	FILE *f;
@@ -92,3 +94,15 @@
         }
 }
 
+
+TrackerExtractorData data[] = {
+	{ "application/x-abiword", tracker_extract_abw },
+	{ NULL, NULL }
+};
+
+
+TrackerExtractorData *
+tracker_get_extractor_data (void)
+{
+	return data;
+}

Modified: trunk/src/tracker-extract/tracker-extract-exif.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-exif.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-exif.c	Sun Feb  3 22:20:54 2008
@@ -19,8 +19,6 @@
 
 #include "config.h"
 
-#ifdef HAVE_LIBEXIF
-
 #include "tracker-extract.h"
 #include <stdio.h>
 #include <string.h>
@@ -145,8 +143,8 @@
 };
 
 
-void
-tracker_extract_exif (gchar *filename, GHashTable *metadata)
+static void
+tracker_extract_exif (const gchar *filename, GHashTable *metadata)
 {
 	ExifData *exif;
 	TagType  *p;
@@ -172,6 +170,15 @@
 	}
 }
 
-#else
-#warning "Not building EXIF metadata extractor."
-#endif  /* HAVE_LIBEXIF */
+
+TrackerExtractorData data[] = {
+	{ "image/jpeg", tracker_extract_exif },
+	{ NULL, NULL }
+};
+
+
+TrackerExtractorData *
+tracker_get_extractor_data (void)
+{
+	return data;
+}

Modified: trunk/src/tracker-extract/tracker-extract-gstreamer.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-gstreamer.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-gstreamer.c	Sun Feb  3 22:20:54 2008
@@ -54,6 +54,7 @@
 #include <glib.h>
 #include <gst/gst.h>
 
+#include "tracker-extract.h"
 
 typedef struct {
 	GstElement	*playbin;
@@ -652,8 +653,8 @@
 }
 
 
-void
-tracker_extract_gstreamer (gchar *uri, GHashTable *metadata)
+static void
+tracker_extract_gstreamer (const gchar *uri, GHashTable *metadata)
 {
 	MetadataExtractor *extractor;
 	gchar		  *mrl;
@@ -720,3 +721,17 @@
 
 	g_slice_free (MetadataExtractor, extractor);
 }
+
+
+TrackerExtractorData data[] = {
+	{ "audio/*", tracker_extract_gstreamer },
+	{ "video/*", tracker_extract_gstreamer },
+	{ NULL, NULL }
+};
+
+
+TrackerExtractorData *
+tracker_get_extractor_data (void)
+{
+	return data;
+}

Modified: trunk/src/tracker-extract/tracker-extract-html.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-html.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-html.c	Sun Feb  3 22:20:54 2008
@@ -19,32 +19,33 @@
 
 #include "config.h"
 
-#ifdef HAVE_LIBXML2
-
 #include <string.h>
 #include <glib.h>
 #include <libxml/HTMLparser.h>
+#include "tracker-extract.h"
 
 typedef enum {
 	READ_TITLE,
 } tag_type;
 
+
 typedef struct {
 	GHashTable *metadata;
 	tag_type current;
 } HTMLParseInfo;
 
+
 gboolean
-has_attribute( const xmlChar ** atts, const char *attr, const char*val )
+has_attribute (const xmlChar **atts, const char *attr, const char *val)
 {
-	if (! (atts && attr && val)) {
+	if (!(atts && attr && val)) {
 		return FALSE;
 	}
 
 	int i;
-	for ( i = 0; atts[i] && atts[i+1]; i+=2 ) {
-		if ( strcasecmp((char*)atts[i],attr) == 0 ) {
-			if (strcasecmp((char*)atts[i+1],val) == 0) {
+	for (i = 0; atts[i] && atts[i+1]; i+=2) {
+		if (strcasecmp ((char*)atts[i], attr) == 0) {
+			if (strcasecmp ((char*)atts[i+1], val) == 0) {
 				return TRUE;
 			}
 		}
@@ -53,16 +54,17 @@
 	return FALSE;
 }
 
+
 const xmlChar *
-lookup_attribute( const xmlChar **atts, const char *attr )
+lookup_attribute (const xmlChar **atts, const char *attr)
 {
 	if (!atts || !attr) {
 		return NULL;
 	}
 
 	int i;
-	for ( i = 0; atts[i] && atts[i+1]; i+=2 ) {
-		if ( strcasecmp((char*)atts[i],attr) == 0 ) {
+	for (i = 0; atts[i] && atts[i+1]; i+=2) {
+		if (strcasecmp ((char*)atts[i], attr) == 0) {
 			return atts[i+1];
 		}
 	}
@@ -70,76 +72,81 @@
 	return NULL;
 }
 
+
 void
-startElement (void * info, const xmlChar * name, const xmlChar ** atts)
+startElement (void *info, const xmlChar *name, const xmlChar **atts)
 {
-	if (! (info && name)) {
+	if (!(info && name)) {
 		return;
 	}
 
 	/* Look for RDFa triple describing the license */
-	if ( strcasecmp((char*)name,"a") == 0 ) {
+	if (strcasecmp ((char*)name, "a") == 0) {
 
 		/* This tag is a license.  Ignore, however, if it is referring to another document */
-		if ( has_attribute(atts,"rel","license") && !has_attribute(atts,"about",NULL) ) {
+		if (has_attribute (atts, "rel", "license") && !has_attribute (atts, "about", NULL)) {
 
-			const xmlChar *href = lookup_attribute(atts,"href");
-			if ( href ) {
+			const xmlChar *href = lookup_attribute (atts, "href");
+			if (href) {
 				g_hash_table_insert (((HTMLParseInfo *)info)->metadata, g_strdup ("File:License"),
-				                     g_strdup( (char*)href ));
+				                     g_strdup ((char*)href));
 			}
 		}
 
-	} else if ( strcasecmp((char*)name,"title") == 0 ) {
+	} else if (strcasecmp ((char*)name, "title") == 0) {
 
 		((HTMLParseInfo *)info)->current = READ_TITLE;
 
-	} else if ( strcasecmp((char*)name,"meta") == 0 ) {
+	} else if (strcasecmp ((char*)name, "meta") == 0) {
 
-		if ( has_attribute(atts,"name","Author") ) {
+		if (has_attribute (atts, "name", "Author")) {
 
-			const xmlChar *author = lookup_attribute(atts,"content");
-			if ( author ) {
+			const xmlChar *author = lookup_attribute (atts, "content");
+			if (author) {
 				g_hash_table_insert (((HTMLParseInfo *)info)->metadata, g_strdup ("Doc:Author"),
-				                     g_strdup( (char*)author ));
+				                     g_strdup ((char*)author));
 			}
 		}
 
-		if ( has_attribute(atts,"name","DC.Description") ) {
+		if (has_attribute (atts, "name", "DC.Description")) {
 
-			const xmlChar *desc = lookup_attribute(atts,"content");
-			if ( desc ) {
+			const xmlChar *desc = lookup_attribute (atts,"content");
+			if (desc) {
 				g_hash_table_insert (((HTMLParseInfo *)info)->metadata, g_strdup ("Doc:Comments"),
-				                     g_strdup( (char*)desc ));
+				                     g_strdup ((char*)desc));
 			}
 		}
 
-            if ( has_attribute(atts, "name", "KEYWORDS") || has_attribute(atts, "name", "keywords") ) {
+            if (has_attribute (atts, "name", "KEYWORDS") || has_attribute (atts, "name", "keywords")) {
 									
-			const xmlChar *keywords = lookup_attribute(atts, "content");
+			const xmlChar *keywords = lookup_attribute (atts, "content");
 			if ( keywords ) {
 				g_hash_table_insert (((HTMLParseInfo *)info)->metadata, g_strdup ("Doc:Keywords"),
-							   g_strdup((char*) keywords));			
+							   g_strdup ((char*)keywords));			
 			}					
 		}
 	}
 }
 
+
 void
-characters(void * info, const xmlChar * ch, int len)
+characters (void *info, const xmlChar *ch, int len)
 {
-	switch(((HTMLParseInfo *)info)->current) {
+	switch (((HTMLParseInfo *)info)->current) {
 		case READ_TITLE:
 				g_hash_table_insert (((HTMLParseInfo *)info)->metadata, g_strdup ("Doc:Title"),
-				                     g_strdup( (char*)ch ));
+				                     g_strdup ((char*)ch));
 				break;
-		default: break;
+		default:
+                                break;
 	}
 
 	((HTMLParseInfo *)info)->current = -1;
 }
 
-void tracker_extract_html (gchar* filename, GHashTable *metadata)
+
+static void
+tracker_extract_html (const gchar* filename, GHashTable *metadata)
 {
 	xmlSAXHandler SAXHandlerStruct = {
 			NULL, /* internalSubset */
@@ -179,12 +186,22 @@
 	HTMLParseInfo   info = { metadata, -1 };
 
 	htmlDocPtr doc;
-	doc = htmlSAXParseFile(filename, NULL, &SAXHandlerStruct, &info);
-	if ( doc ) {
-		xmlFreeDoc(doc);
+	doc = htmlSAXParseFile (filename, NULL, &SAXHandlerStruct, &info);
+	if (doc) {
+		xmlFreeDoc (doc);
 	}
 }
 
-#else
-#warning "Not building HTML metadata extractor."
-#endif
+
+TrackerExtractorData data[] = {
+ 	{ "text/html",             tracker_extract_html },
+ 	{ "application/xhtml+xml", tracker_extract_html },
+	{ NULL, NULL }
+};
+
+
+TrackerExtractorData *
+tracker_get_extractor_data (void)
+{
+	return data;
+}

Modified: trunk/src/tracker-extract/tracker-extract-imagemagick.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-imagemagick.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-imagemagick.c	Sun Feb  3 22:20:54 2008
@@ -25,9 +25,11 @@
 #include <glib.h>
 
 #include "tracker-extract.h"
+#include "tracker-xmp.h"
 
-void
-tracker_extract_imagemagick (gchar *filename, GHashTable *metadata)
+
+static void
+tracker_extract_imagemagick (const gchar *filename, GHashTable *metadata)
 {
 	gchar *argv[6];
 	gchar *identify;
@@ -79,3 +81,16 @@
 	}
 #endif
 }
+
+
+TrackerExtractorData data[] = {
+	{ "image/*", tracker_extract_imagemagick },
+	{ NULL, NULL }
+};
+
+
+TrackerExtractorData *
+tracker_get_extractor_data (void)
+{
+	return data;
+}

Modified: trunk/src/tracker-extract/tracker-extract-libxine.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-libxine.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-libxine.c	Sun Feb  3 22:20:54 2008
@@ -20,6 +20,8 @@
 #include <xine.h>
 #include <glib.h>
 
+#include "tracker-extract.h"
+
 
 static void
 add_uint32_info (GHashTable *metadata, char *key, uint32_t info)
@@ -237,3 +239,17 @@
 
 	xine_exit (xine_base);
 }
+
+
+TrackerExtractorData data[] = {
+	{ "audio/*", tracker_extract_xine },
+	{ "video/*", tracker_extract_xine },
+	{ NULL, NULL }
+};
+
+
+TrackerExtractorData *
+tracker_get_extractor_data (void)
+{
+	return data;
+}

Modified: trunk/src/tracker-extract/tracker-extract-mp3.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-mp3.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-mp3.c	Sun Feb  3 22:20:54 2008
@@ -35,6 +35,7 @@
 #include <fcntl.h>
 #include <glib.h>
 #include <glib/gstdio.h>
+#include "tracker-extract.h"
 
 #define MAX_FILE_READ 1024 * 1024 * 10
 
@@ -44,6 +45,7 @@
 	char * type;
 } Matches;
 
+
 static struct {
 	char * name;
 	char *meta_name;
@@ -91,6 +93,7 @@
 	char * genre;
 } id3tag;
 
+
 static const char *const genre_names[] = {
 	"Blues",
 	"Classic Rock",
@@ -972,7 +975,7 @@
 
 }
 
-void 
+static void
 tracker_extract_mp3 (const char *filename, GHashTable *metadata)
 {
 	int file;
@@ -1077,3 +1080,15 @@
 	
 }
 
+
+TrackerExtractorData data[] = {
+	{ "audio/mp3", tracker_extract_mp3 },
+	{ NULL, NULL }
+};
+
+
+TrackerExtractorData *
+tracker_get_extractor_data (void)
+{
+	return data;
+}

Modified: trunk/src/tracker-extract/tracker-extract-mplayer.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-mplayer.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-mplayer.c	Sun Feb  3 22:20:54 2008
@@ -32,6 +32,7 @@
 	{ NULL,			NULL			}
 };
 
+
 static gchar *audio_tags[][2] = {
 	{ "ID_AUDIO_BITRATE",	"Audio:Bitrate"		},
 	{ "ID_AUDIO_RATE",	"Audio:Samplerate"	},
@@ -40,6 +41,7 @@
 	{ NULL,			NULL			}
 };
 
+
 /* Some of "info_tags" tags can belong to Audio or/and video or none, so 3 cases :
  * 1/ tag does not belong to audio nor video, it is a general tag ;
  * 2/ tag only belongs to audio ;
@@ -66,8 +68,8 @@
 }
 
 
-void
-tracker_extract_mplayer (gchar *filename, GHashTable *metadata)
+static void
+tracker_extract_mplayer (const gchar *filename, GHashTable *metadata)
 {
 	gchar *argv[10];
 	gchar *mplayer;
@@ -85,7 +87,6 @@
 
 	if (tracker_spawn (argv, 10, &mplayer, NULL)) {
 	
-
 		GPatternSpec *pattern_ID_AUDIO_ID, *pattern_ID_VIDEO_ID;
 		GPatternSpec *pattern_ID_AUDIO, *pattern_ID_VIDEO, *pattern_ID_CLIP_INFO_NAME, *pattern_ID_CLIP_INFO_VALUE, *pattern_ID_LENGTH;
 		GHashTable   *tmp_metadata_audio, *tmp_metadata_video;
@@ -226,3 +227,17 @@
 		g_hash_table_destroy (tmp_metadata_video);
 	}
 }
+
+
+TrackerExtractorData data[] = {
+	{ "audio/*", tracker_extract_mplayer },
+	{ "video/*", tracker_extract_mplayer },
+	{ NULL, NULL }
+};
+
+
+TrackerExtractorData *
+tracker_get_extractor_data (void)
+{
+	return data;
+}

Modified: trunk/src/tracker-extract/tracker-extract-msoffice.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-msoffice.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-msoffice.c	Sun Feb  3 22:20:54 2008
@@ -21,8 +21,6 @@
 #include "config.h"
 #include "tracker-extract.h"
 
-#ifdef HAVE_LIBGSF
-
 #include <string.h>
 #include <glib.h>
 #include <gsf/gsf.h>
@@ -127,8 +125,8 @@
 }
 
 
-void
-tracker_extract_msoffice (gchar *filename, GHashTable *metadata)
+static void
+tracker_extract_msoffice (const gchar *filename, GHashTable *metadata)
 {
 	GsfInput  *input;
 	GsfInfile *infile;
@@ -191,6 +189,15 @@
 }
 
 
-#else
-#warning "Not building Microsoft Office metadata extractor."
-#endif  /* HAVE_LIBGSF */
+TrackerExtractorData data[] = {
+ 	{ "application/msword",	  tracker_extract_msoffice },
+ 	{ "application/vnd.ms-*", tracker_extract_msoffice },
+	{ NULL, NULL }
+};
+
+
+TrackerExtractorData *
+tracker_get_extractor_data (void)
+{
+	return data;
+}

Modified: trunk/src/tracker-extract/tracker-extract-oasis.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-oasis.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-oasis.c	Sun Feb  3 22:20:54 2008
@@ -17,7 +17,6 @@
  * Boston, MA  02110-1301, USA.
  */
 
-
 #include <stdio.h>
 #include <string.h>
 #include <glib.h>
@@ -34,11 +33,13 @@
 		READ_FILE_OTHER
 	} tag_type;
 
+
 typedef struct {
 	GHashTable *metadata;
 	tag_type current;
 } ODTParseInfo;
 
+
 static void start_element_handler (GMarkupParseContext *context,
                                    const gchar *element_name,
                                    const gchar **attribute_names,
@@ -58,7 +59,8 @@
                           GError **error);
 
 
-void tracker_extract_oasis (gchar *filename, GHashTable *metadata)
+static void
+tracker_extract_oasis (const gchar *filename, GHashTable *metadata)
 {
 	gchar         *argv[5];
 	gchar         *xml;
@@ -123,7 +125,7 @@
 		GHashTable *metadata = data->metadata;
 		const gchar **a, **v;
 
-		for(a = attribute_names, v = attribute_values; *a; ++a, ++v) {
+		for (a = attribute_names, v = attribute_values; *a; ++a, ++v) {
 			if (strcmp (*a, "meta:word-count") == 0) {
 				g_hash_table_insert (metadata,
 					g_strdup ("Doc:WordCount"), g_strdup (*v));
@@ -165,15 +167,15 @@
         ODTParseInfo *data = user_data;
 	GHashTable *metadata = data->metadata;
 
-	switch(data->current) {
+	switch (data->current) {
 		case READ_TITLE:
-			g_hash_table_insert (metadata, g_strdup("Doc:Title"), g_strdup (text));
+			g_hash_table_insert (metadata, g_strdup ("Doc:Title"), g_strdup (text));
 			break;
 		case READ_SUBJECT:
-			g_hash_table_insert (metadata, g_strdup("Doc:Subject"), g_strdup (text));
+			g_hash_table_insert (metadata, g_strdup ("Doc:Subject"), g_strdup (text));
 			break;
 		case READ_AUTHOR:
-			g_hash_table_insert (metadata, g_strdup("Doc:Author"), g_strdup (text));
+			g_hash_table_insert (metadata, g_strdup ("Doc:Author"), g_strdup (text));
 			break;
 		case READ_KEYWORDS: {
 				gchar *keywords;
@@ -181,21 +183,34 @@
 					g_hash_table_replace (metadata, g_strdup ("Doc:Keywords"),
 							g_strconcat (keywords, ",", text, NULL));
 				} else {
-					g_hash_table_insert (metadata, g_strdup("Doc:Keywords"), g_strdup (text));
+					g_hash_table_insert (metadata, g_strdup ("Doc:Keywords"), g_strdup (text));
 				}
 			}
 			break;
 		case READ_COMMENTS:
-			g_hash_table_insert (metadata, g_strdup("Doc:Comments"), g_strdup (text));
+			g_hash_table_insert (metadata, g_strdup ("Doc:Comments"), g_strdup (text));
 			break;
 		case READ_CREATED:
-			g_hash_table_insert (metadata, g_strdup("Doc:Created"), g_strdup (text));
+			g_hash_table_insert (metadata, g_strdup ("Doc:Created"), g_strdup (text));
 			break;
 		case READ_FILE_OTHER:
-			g_hash_table_insert (metadata, g_strdup("File:Other"), g_strdup (text));
+			g_hash_table_insert (metadata, g_strdup ("File:Other"), g_strdup (text));
 			break;
 
 		default:
 			break;
 	}
 }
+
+
+TrackerExtractorData data[] = {
+	{ "application/vnd.oasis.opendocument.*", tracker_extract_oasis },
+	{ NULL, NULL }
+};
+
+
+TrackerExtractorData *
+tracker_get_extractor_data (void)
+{
+	return data;
+}

Modified: trunk/src/tracker-extract/tracker-extract-pdf.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-pdf.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-pdf.c	Sun Feb  3 22:20:54 2008
@@ -20,17 +20,16 @@
 
 #include "config.h"
 
-#ifdef HAVE_POPPLER
-
 #include <poppler.h>
 #include <string.h>
 #include <glib.h>
 
 #include "tracker-extract.h"
+#include "tracker-xmp.h"
 
 
-void
-tracker_extract_pdf (gchar *filename, GHashTable *metadata)
+static void
+tracker_extract_pdf (const gchar *filename, GHashTable *metadata)
 {
 	PopplerDocument *document;
 	gchar           *tmp;
@@ -101,6 +100,15 @@
 	g_object_unref (document);
 }
 
-#else
-#warning "Not building PDF metadata extractor."
-#endif  /* HAVE_POPPLER */
+
+TrackerExtractorData data[] = {
+ 	{ "application/pdf", tracker_extract_pdf },
+	{ NULL, NULL }
+};
+
+
+TrackerExtractorData *
+tracker_get_extractor_data (void)
+{
+	return data;
+}

Modified: trunk/src/tracker-extract/tracker-extract-png.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-png.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-png.c	Sun Feb  3 22:20:54 2008
@@ -23,6 +23,7 @@
 
 #include "config.h"
 #include "tracker-extract.h"
+#include "tracker-xmp.h"
 
 #include <fcntl.h>
 #include <string.h>
@@ -72,8 +73,8 @@
 };
 
 
-void
-tracker_extract_png (gchar *filename, GHashTable *metadata)
+static void
+tracker_extract_png (const gchar *filename, GHashTable *metadata)
 {
         gint        fd_png;
 	FILE        *png;
@@ -94,7 +95,7 @@
                 return;
         }
 
-	if ((png = fdopen(fd_png, "r"))) {
+	if ((png = fdopen (fd_png, "r"))) {
 		png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
 		                                  NULL, NULL, NULL);
 		if (!png_ptr) {
@@ -127,7 +128,7 @@
 				if (text_ptr[i].key) {
                                         gint j;
 					#if defined(HAVE_EXEMPI) && defined(PNG_iTXt_SUPPORTED)
-					if (strcmp("XML:com.adobe.xmp", text_ptr[i].key) == 0) {
+					if (strcmp ("XML:com.adobe.xmp", text_ptr[i].key) == 0) {
 						tracker_read_xmp (text_ptr[i].text,
                                                                   text_ptr[i].itxt_length,
                                                                   metadata);
@@ -156,10 +157,23 @@
 		}
 
 		png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
-		
+
 		fclose (png);
 
         } else {
                 close (fd_png);
         }
 }
+
+
+TrackerExtractorData data[] = {
+	{ "image/png", tracker_extract_png },
+	{ NULL, NULL }
+};
+
+
+TrackerExtractorData *
+tracker_get_extractor_data (void)
+{
+	return data;
+}

Modified: trunk/src/tracker-extract/tracker-extract-ps.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-ps.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-ps.c	Sun Feb  3 22:20:54 2008
@@ -40,6 +40,7 @@
 #undef getdelim
 #undef getline
 
+
 static ssize_t
 igetdelim (gchar **linebuf, size_t *linebufsz, gint delimiter, FILE *file)
 {
@@ -191,8 +192,8 @@
 }
 
 
-void
-tracker_extract_ps (gchar *filename, GHashTable *metadata)
+static void
+tracker_extract_ps (const gchar *filename, GHashTable *metadata)
 {
         gint fd;
 	FILE *f;
@@ -268,11 +269,13 @@
         }
 }
 
+
 /* our private prototype */
 void tracker_child_cb (gpointer user_data);
 
-void
-tracker_extract_ps_gz (gchar *filename, GHashTable *metadata)
+
+static void
+tracker_extract_ps_gz (const gchar *filename, GHashTable *metadata)
 {
 	FILE   * fz        = NULL;
 	GError * error     = NULL;
@@ -287,7 +290,7 @@
 		return;
 	}
 
-	char * argv [4];
+	const char * argv [4];
 	argv [0] = "gunzip";
 	argv [1] = "-c";
 	argv [2] = filename;
@@ -295,7 +298,7 @@
 
 	gboolean stat = g_spawn_async_with_pipes (
 			"/tmp",
-			argv,
+			(char **) argv,
 			NULL, /* envp */
 			G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL,
 			tracker_child_cb, /* child setup func */
@@ -330,3 +333,17 @@
 	tracker_extract_ps (gunzipped, metadata);
 	g_unlink (gunzipped);
 }
+
+
+TrackerExtractorData data[] = {
+	{ "application/x-gzpostscript",	tracker_extract_ps_gz },
+	{ "application/postscript",	tracker_extract_ps    },
+	{ NULL, NULL }
+};
+
+
+TrackerExtractorData *
+tracker_get_extractor_data (void)
+{
+	return data;
+}

Modified: trunk/src/tracker-extract/tracker-extract-totem.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-totem.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-totem.c	Sun Feb  3 22:20:54 2008
@@ -41,8 +41,8 @@
 };
 
 
-void
-tracker_extract_totem (gchar *filename, GHashTable *metadata)
+static void
+tracker_extract_totem (const gchar *filename, GHashTable *metadata)
 {
 	gchar *argv[3];
 	gchar *totem;
@@ -71,3 +71,17 @@
 		}
 	}
 }
+
+
+TrackerExtractorData data[] = {
+	{ "audio/*", tracker_extract_totem },
+	{ "video/*", tracker_extract_totem },
+	{ NULL, NULL }
+};
+
+
+TrackerExtractorData *
+tracker_get_extractor_data (void)
+{
+	return data;
+}

Modified: trunk/src/tracker-extract/tracker-extract-vorbis.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-vorbis.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-vorbis.c	Sun Feb  3 22:20:54 2008
@@ -16,6 +16,7 @@
  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA  02110-1301, USA.
  */
+
 #include "config.h"
 
 #ifdef HAVE_VORBIS
@@ -25,6 +26,8 @@
 #include <glib.h>
 #include <vorbis/vorbisfile.h>
 
+#include "tracker-extract.h"
+
 /*#include "tracker-utils.h"*/
 
 static struct {
@@ -85,6 +88,7 @@
 
 }
 
+
 gboolean
 tracker_metadata_ogg_is_writable (const char *meta)
 {

Modified: trunk/src/tracker-extract/tracker-extract-xmp.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-xmp.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-xmp.c	Sun Feb  3 22:20:54 2008
@@ -19,22 +19,32 @@
 
 #include "config.h"
 
-#ifdef HAVE_EXEMPI
-
 #include <glib.h>
 
 #include "tracker-extract.h"
+#include "tracker-xmp.h"
+
 
-void tracker_extract_xmp (gchar* filename, GHashTable *metadata)
+static void
+tracker_extract_xmp (const gchar* filename, GHashTable *metadata)
 {
 	gchar *contents;
 	gsize length;
 	GError *error;
 
-	if ( g_file_get_contents( filename, &contents, &length, &error ) )
-		tracker_read_xmp(contents, length, metadata);
+	if ( g_file_get_contents ( filename, &contents, &length, &error ) )
+		tracker_read_xmp (contents, length, metadata);
 }
 
-#else
-#warning "Not building XMP metadata extractor."
-#endif  /* HAVE_EXEMPI */
+
+TrackerExtractorData data[] = {
+	{ "application/rdf+xml", tracker_extract_xmp },
+	{ NULL, NULL }
+};
+
+
+TrackerExtractorData *
+tracker_get_extractor_data (void)
+{
+	return data;
+}

Modified: trunk/src/tracker-extract/tracker-extract.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract.c	(original)
+++ trunk/src/tracker-extract/tracker-extract.c	Sun Feb  3 22:20:54 2008
@@ -32,17 +32,13 @@
 #include <sys/time.h>
 #include <unistd.h>
 #include <glib.h>
+#include <gmodule.h>
 
 #include "tracker-extract.h"
 
 #define MAX_MEM 128
 #define MAX_MEM_AMD64 512
 
-#ifdef HAVE_EXEMPI
-#include <exempi/xmp.h>
-#include <exempi/xmpconsts.h>
-#endif
-
 typedef enum {
 	IGNORE_METADATA,
 	NO_METADATA,
@@ -53,117 +49,7 @@
 } MetadataFileType;
 
 
-
-typedef void (*MetadataExtractFunc)(gchar *, GHashTable *);
- 
-typedef struct {
- 	char			*mime;
- 	MetadataExtractFunc	extractor;
-} MimeToExtractor;
-
-void tracker_extract_mplayer	(gchar *, GHashTable *);
-void tracker_extract_totem	(gchar *, GHashTable *);
-void tracker_extract_oasis	(gchar *, GHashTable *);
-void tracker_extract_ps		(gchar *, GHashTable *);
-void tracker_extract_ps_gz	(gchar *, GHashTable *);
-#ifdef HAVE_LIBXML2
-void tracker_extract_html       (gchar *, GHashTable *);
-#endif
-#ifdef HAVE_POPPLER
-void tracker_extract_pdf	(gchar *, GHashTable *);
-#endif
-void tracker_extract_abw	(gchar *, GHashTable *);
-#ifdef HAVE_LIBGSF
-void tracker_extract_msoffice	(gchar *, GHashTable *);
-#endif
-#ifdef HAVE_EXEMPI
-void tracker_extract_xmp	(gchar *, GHashTable *);
-#endif
-void tracker_extract_mp3	(gchar *, GHashTable *);
-#ifdef HAVE_VORBIS
-void tracker_extract_vorbis	(gchar *, GHashTable *);
-#endif
-void tracker_extract_png	(gchar *, GHashTable *);
-#ifdef HAVE_LIBEXIF
-void tracker_extract_exif	(gchar *, GHashTable *);
-#endif
-void tracker_extract_imagemagick (gchar *, GHashTable *);
-#ifdef HAVE_GSTREAMER
-void tracker_extract_gstreamer	(gchar *, GHashTable *);
-#else
-#ifdef HAVE_LIBXINE
-void tracker_extract_xine	(gchar *, GHashTable *);
-#else
-#ifdef USING_EXTERNAL_VIDEO_PLAYER
-
-#endif
-#endif
-#endif
-  
-MimeToExtractor extractors[] = {
-	/* Document extractors */
- 	{ "application/vnd.oasis.opendocument.*",	tracker_extract_oasis		},
- 	{ "application/x-gzpostscript",			tracker_extract_ps_gz		},
- 	{ "application/postscript",			tracker_extract_ps		},
-#ifdef HAVE_LIBXML2
- 	{ "text/html",                                  tracker_extract_html            },
- 	{ "application/xhtml+xml",                      tracker_extract_html            },
-#endif
-#ifdef HAVE_POPPLER
- 	{ "application/pdf",				tracker_extract_pdf		},
-#endif
-	{ "application/x-abiword",			tracker_extract_abw		},
-#ifdef HAVE_LIBGSF
- 	{ "application/msword",				tracker_extract_msoffice	},
- 	{ "application/vnd.ms-*",			tracker_extract_msoffice	},
-#endif
-#ifdef HAVE_EXEMPI
- 	{ "application/rdf+xml",			tracker_extract_xmp		},
-#endif
-
-  	/* Video extractors */
-#ifdef HAVE_GSTREAMER
- 	{ "video/*",					tracker_extract_gstreamer	},
-#else
-#ifdef HAVE_LIBXINE
- 	{ "video/*",					tracker_extract_xine		},
- 	{ "video/*",					tracker_extract_mplayer		},
- 	{ "video/*",					tracker_extract_totem		},
-#else
-#ifdef USING_EXTERNAL_VIDEO_PLAYER
- 	{ "video/*",					tracker_extract_mplayer		},
- 	{ "video/*",					tracker_extract_totem		},
-#endif
-#endif
-#endif
-  
-  	/* Audio extractors */
-	
-#ifdef HAVE_GSTREAMER
-	{ "audio/*",					tracker_extract_gstreamer	},
-
-#else
-#ifdef HAVE_LIBXINE
-	{ "audio/*",					tracker_extract_xine		},
- 	{ "audio/*",					tracker_extract_mplayer		},
-#else
-#ifdef USING_EXTERNAL_VIDEO_PLAYER
- 	{ "audio/*",					tracker_extract_mplayer		},
- 	{ "audio/*",					tracker_extract_totem		},
-#endif
-#endif
-#endif
-  
-	{ "audio/mp3",					tracker_extract_mp3		},
-
-     /* Image extractors */
-	{ "image/png",					tracker_extract_png		},
-#ifdef HAVE_LIBEXIF
-	{ "image/jpeg",					tracker_extract_exif		},
-#endif
-	{ "image/*",					tracker_extract_imagemagick	},
-	{ "",						NULL				}
-};
+GArray *extractors = NULL;
 
 
 static gboolean
@@ -465,7 +351,7 @@
 		g_printerr ("Error trying to set resource limit for cpu\n");
 	}
 
-	set_memory_rlimits();
+	set_memory_rlimits ();
 
 	/* Set child's niceness to 19 */
         errno = 0;
@@ -498,205 +384,94 @@
 }
 
 
-#ifdef HAVE_EXEMPI
-void
-tracker_append_string_to_hash_table (GHashTable *metadata, const gchar *key, const gchar *value, gboolean append)
-{
-	gchar *new_value;
-
-	if (append) {
-		gchar *orig;
-		if (g_hash_table_lookup_extended (metadata, key, NULL, (gpointer)&orig )) {
-			new_value = g_strconcat (orig, " ", value, NULL);
-		} else {
-			new_value = g_strdup (value);
-		}
-	} else {
-		new_value = g_strdup (value);
-	}
-
-	g_hash_table_insert (metadata, g_strdup(key), new_value);
-}
-
-
-void tracker_xmp_iter (XmpPtr xmp, XmpIteratorPtr iter, GHashTable *metadata, gboolean append);
-void tracker_xmp_iter_simple (GHashTable *metadata, const gchar *schema, const gchar *path, const gchar *value, gboolean append);
-
-
-/* We have an array, now recursively iterate over it's children.  Set 'append' to true so that all values of the array are added
-   under one entry. */
-void
-tracker_xmp_iter_array (XmpPtr xmp, GHashTable *metadata, const gchar *schema, const gchar *path)
-{
-		XmpIteratorPtr iter = xmp_iterator_new (xmp, schema, path, XMP_ITER_JUSTCHILDREN);
-		tracker_xmp_iter (xmp, iter, metadata, TRUE);
-		xmp_iterator_free (iter);
-}
-
-
-/* We have an array, now recursively iterate over it's children.  Set 'append' to false so that only one item is used. */
-void
-tracker_xmp_iter_alt_text (XmpPtr xmp, GHashTable *metadata, const gchar *schema, const gchar *path)
-{
-		XmpIteratorPtr iter = xmp_iterator_new (xmp, schema, path, XMP_ITER_JUSTCHILDREN);
-		tracker_xmp_iter (xmp, iter, metadata, FALSE);
-		xmp_iterator_free (iter);
-}
-
-
-/* We have a simple element, but need to iterate over the qualifiers */
-void
-tracker_xmp_iter_simple_qual (XmpPtr xmp, GHashTable *metadata,
-                              const gchar *schema, const gchar *path, const gchar *value, gboolean append)
+static void
+initialize_extractors (void)
 {
-	XmpIteratorPtr iter = xmp_iterator_new(xmp, schema, path, XMP_ITER_JUSTCHILDREN | XMP_ITER_JUSTLEAFNAME);
+	GDir        *dir;
+	GError      *error = NULL;
+	const gchar *name;
+	GArray      *generic_extractors = NULL;
 
-	XmpStringPtr the_path = xmp_string_new ();
-	XmpStringPtr the_prop = xmp_string_new ();
+	if (extractors != NULL)
+		return;
 
-	gchar *locale = setlocale (LC_ALL, NULL);
-	gchar *sep = strchr (locale,'.');
-	if (sep) {
-		locale[sep - locale] = '\0';
-	}
-	sep = strchr (locale, '_');
-	if (sep) {
-		locale[sep - locale] = '-';
+	if (!g_module_supported ()) {
+		g_error ("Modules are not supported for this platform");
+		return;
 	}
 
-	gboolean ignore_element = FALSE;
+	extractors = g_array_sized_new (FALSE, TRUE,
+					sizeof (TrackerExtractorData),
+					10);
 
-	while (xmp_iterator_next (iter, NULL, the_path, the_prop, NULL)) {
-		const gchar *qual_path = xmp_string_cstr (the_path);
-		const gchar *qual_value = xmp_string_cstr (the_prop);
+	/* This array is going to be used to store
+	 * temporarily extractors with mimetypes such as "audio / *"
+	 */
+	generic_extractors = g_array_sized_new (FALSE, TRUE,
+						sizeof (TrackerExtractorData),
+						10);
 
-		if (strcmp (qual_path, "xml:lang") == 0) {
-			/* is this a language we should ignore? */
-			if (strcmp (qual_value, "x-default") != 0 && strcmp (qual_value, "x-repair") != 0 && strcmp (qual_value, locale) != 0) {
-				ignore_element = TRUE;
-				break;
-			}
-		}
-	}
+	dir = g_dir_open (MODULES_DIR, 0, &error);
 
-	if (!ignore_element) {
-		tracker_xmp_iter_simple (metadata, schema, path, value, append);
+	if (!dir) {
+		g_error ("Error opening modules directory: %s\n", error->message);
+		g_error_free (error);
+                g_array_free (extractors, TRUE);
+                extractors = NULL;
+                g_array_free (generic_extractors, TRUE);
+		return;
 	}
 
-	xmp_string_free (the_prop);
-	xmp_string_free (the_path);
+	while ((name = g_dir_read_name (dir)) != NULL) {
+		GModule                  *module;
+		gchar                    *module_path;
+		TrackerExtractorDataFunc func;
+		TrackerExtractorData     *data;
 
-	xmp_iterator_free (iter);
-}
+		if (!g_str_has_suffix (name, "." G_MODULE_SUFFIX)) {
+			continue;
+		}
 
+		module_path = g_build_filename (MODULES_DIR, name, NULL);
 
-/* We have a simple element. Add any metadata we know about to the hash table  */
-void
-tracker_xmp_iter_simple (GHashTable *metadata,
-                         const gchar *schema, const gchar *path, const gchar *value, gboolean append)
-{
-	gchar *name = g_strdup (strchr (path, ':')+1);
-	const gchar *index = strrchr (name, '[');
-	if (index) {
-		name[index-name] = '\0';
-	}
+		module = g_module_open (module_path, G_MODULE_BIND_LOCAL);
 
-	/* Dublin Core */
-	if (strcmp(schema, NS_DC) == 0) {
-		if (strcmp (name, "title") == 0) {
-			tracker_append_string_to_hash_table (metadata, "Image:Title", value, append);
-		}
-		else if (strcmp (name, "rights") == 0) {
-			tracker_append_string_to_hash_table (metadata, "File:Copyright", value, append);
-		}
-		else if (strcmp (name, "creator") == 0) {
-			tracker_append_string_to_hash_table (metadata, "Image:Creator", value, append);
-		}
-		else if (strcmp (name, "description") == 0) {
-			tracker_append_string_to_hash_table (metadata, "Image:Description", value, append);
-		}
-		else if (strcmp (name, "date") == 0) {
-			tracker_append_string_to_hash_table (metadata, "Image:Date", value, append);
-		}
-		else if (strcmp (name, "keywords") == 0) {
-			tracker_append_string_to_hash_table (metadata, "Image:Keywords", value, append);
+		if (!module) {
+			g_warning ("Could not load module: %s", name);
+			g_free (module_path);
+			continue;
 		}
-	}
-	/* Creative Commons */
-	else if (strcmp (schema, NS_CC) == 0) {
-		if (strcmp (name, "license") == 0) {
-			tracker_append_string_to_hash_table (metadata, "File:License", value, append);
-		}
-	}
 
-	free(name);
-}
+		g_module_make_resident (module);
 
+		if (g_module_symbol (module, "tracker_get_extractor_data", (gpointer *) &func)) {
+			data = (func) ();
 
-/* Iterate over the XMP, dispatching to the appropriate element type (simple, simple w/qualifiers, or an array) handler */
-void
-tracker_xmp_iter (XmpPtr xmp, XmpIteratorPtr iter, GHashTable *metadata, gboolean append)
-{
-	XmpStringPtr the_schema = xmp_string_new ();
-	XmpStringPtr the_path = xmp_string_new ();
-	XmpStringPtr the_prop = xmp_string_new ();
-
-	uint32_t opt;
-	while (xmp_iterator_next (iter, the_schema, the_path, the_prop, &opt)) {
-		const gchar *schema = xmp_string_cstr (the_schema);
-		const gchar *path = xmp_string_cstr (the_path);
-		const gchar *value = xmp_string_cstr (the_prop);
-
-		if (XMP_IS_PROP_SIMPLE (opt)) {
-			if (strcmp (path,"") != 0) {
-				if (XMP_HAS_PROP_QUALIFIERS (opt)) {
-					tracker_xmp_iter_simple_qual (xmp, metadata, schema, path, value, append);
+			while (data->mime) {
+				if (strchr (data->mime, '*') != NULL) {
+					g_array_append_val (generic_extractors, *data);
 				} else {
-					tracker_xmp_iter_simple (metadata, schema, path, value, append);
+					g_array_append_val (extractors, *data);
 				}
-			}	
-		}
-		else if (XMP_IS_PROP_ARRAY (opt)) {
-			if (XMP_IS_ARRAY_ALTTEXT (opt)) {
-				tracker_xmp_iter_alt_text (xmp, metadata, schema, path);
-				xmp_iterator_skip (iter, XMP_ITER_SKIPSUBTREE);
-			} else {
-				tracker_xmp_iter_array (xmp, metadata, schema, path);
-				xmp_iterator_skip (iter, XMP_ITER_SKIPSUBTREE);
+
+				data++;
 			}
 		}
-	}
-
-	xmp_string_free (the_prop);
-	xmp_string_free (the_path);
-	xmp_string_free (the_schema);
-}
-#endif
 
-
-void
-tracker_read_xmp (const gchar *buffer, size_t len, GHashTable *metadata)
-{
-	#ifdef HAVE_EXEMPI
-	xmp_init ();
-
-	XmpPtr xmp = xmp_new_empty ();
-	xmp_parse (xmp, buffer, len);
-	if (xmp != NULL) {
-		XmpIteratorPtr iter = xmp_iterator_new (xmp, NULL, NULL, XMP_ITER_PROPERTIES);
-		tracker_xmp_iter (xmp, iter, metadata, FALSE);
-		xmp_iterator_free (iter);
-	
-		xmp_free (xmp);
+		g_free (module_path);
 	}
 
-	xmp_terminate ();
-	#endif
+	/* append the generic extractors at the end of
+	 * the list, so the specific ones are used first
+	 */
+	g_array_append_vals (extractors, generic_extractors->data, generic_extractors->len);
+
+	g_array_free (generic_extractors, TRUE);
 }
 
 
 static GHashTable *
-tracker_get_file_metadata (const gchar *uri, gchar *mime)
+tracker_get_file_metadata (const gchar *uri, const gchar *mime)
 {
 	GHashTable      *meta_table;
 	gchar		*uri_in_locale;
@@ -719,24 +494,24 @@
 	meta_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
 
 	if (mime) {
-		MimeToExtractor *p;
+		guint i;
+		TrackerExtractorData *data;
+
+		for (i = 0; i < extractors->len; i++) {
+			data = &g_array_index (extractors, TrackerExtractorData, i);
 
-		for (p = extractors; p->extractor; ++p) {
-			if (g_pattern_match_simple (p->mime, mime)) {
-				(*p->extractor)(uri_in_locale, meta_table);
+			if (g_pattern_match_simple (data->mime, mime)) {
+				(*data->extractor) (uri_in_locale, meta_table);
 
 				if (g_hash_table_size (meta_table) == 0) {
 					continue;
 				}
 
 				g_free (uri_in_locale);
-				g_free (mime);
 
 				return meta_table;
 			}
 		}
-
-		g_free (mime);
 	}
 
 	g_free (uri_in_locale);
@@ -776,11 +551,12 @@
 	exit (EXIT_FAILURE);
 }
 
+
 gint
 main (gint argc, gchar *argv[])
 {
-	GHashTable	*meta;
-	gchar		*filename;
+	GHashTable *meta;
+	gchar	   *filename;
 
 	set_memory_rlimits ();
 
@@ -793,9 +569,11 @@
 
 	setlocale (LC_ALL, "");
 
-	if ((argc == 1) || (argc > 3)) {
+	initialize_extractors ();
+
+	if (argc == 1 || argc > 3) {
 		g_print ("usage: tracker-extract file [mimetype]\n");
-		return 0;
+		return EXIT_FAILURE;
 	}
 
 	filename = g_filename_to_utf8 (argv[1], -1, NULL, NULL, NULL);
@@ -810,11 +588,11 @@
 
 		if (!mime) {
 			g_warning ("locale to UTF8 failed for mime!");
-			return 1;
+			return EXIT_FAILURE;
 		}
 
-		/* mime will be free in tracker_get_file_metadata() */
 		meta = tracker_get_file_metadata (filename, mime);
+		g_free (mime);
 	} else {
 		meta = tracker_get_file_metadata (filename, NULL);
 	}
@@ -826,5 +604,5 @@
 		g_hash_table_destroy (meta);
 	}
 
-	return 0;
+	return EXIT_SUCCESS;
 }

Modified: trunk/src/tracker-extract/tracker-extract.h
==============================================================================
--- trunk/src/tracker-extract/tracker-extract.h	(original)
+++ trunk/src/tracker-extract/tracker-extract.h	Sun Feb  3 22:20:54 2008
@@ -34,6 +34,16 @@
         LAST_STEP       /* This is the end... The end my friend... */
 } steps;
 
+typedef struct TrackerExtractorData TrackerExtractorData;
+typedef TrackerExtractorData * (* TrackerExtractorDataFunc) (void);
+
+struct TrackerExtractorData {
+	const gchar *mime;
+
+	void (* extractor) (const gchar *filename,
+			    GHashTable  *metadata);
+};
+
 
 gchar *         tracker_generic_date_extractor (gchar *date, steps steps_to_do[]);
 
@@ -41,6 +51,4 @@
 
 gboolean	tracker_spawn (gchar **argv, int timeout, gchar **tmp_stdout, gint *exit_status);
 
-void 		tracker_read_xmp (const gchar *buffer, size_t len, GHashTable *metadata);
-
 #endif

Added: trunk/src/tracker-extract/tracker-xmp.c
==============================================================================
--- (empty file)
+++ trunk/src/tracker-extract/tracker-xmp.c	Sun Feb  3 22:20:54 2008
@@ -0,0 +1,234 @@
+/* Tracker Xmp - Xmp helper functions
+ * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#include <locale.h>
+#include <string.h>
+#include <glib.h>
+
+#include "config.h"
+#include "tracker-xmp.h"
+
+#ifdef HAVE_EXEMPI
+
+#include <exempi/xmp.h>
+#include <exempi/xmpconsts.h>
+
+static void tracker_xmp_iter        (XmpPtr          xmp,
+				     XmpIteratorPtr  iter,
+				     GHashTable     *metadata,
+				     gboolean        append);
+
+static void tracker_xmp_iter_simple (GHashTable  *metadata,
+				     const gchar *schema,
+				     const gchar *path,
+				     const gchar *value,
+				     gboolean     append);
+
+
+static void
+tracker_append_string_to_hash_table (GHashTable *metadata, const gchar *key, const gchar *value, gboolean append)
+{
+	gchar *new_value;
+
+	if (append) {
+		gchar *orig;
+		if (g_hash_table_lookup_extended (metadata, key, NULL, (gpointer)&orig )) {
+			new_value = g_strconcat (orig, " ", value, NULL);
+		} else {
+			new_value = g_strdup (value);
+		}
+	} else {
+		new_value = g_strdup (value);
+	}
+
+	g_hash_table_insert (metadata, g_strdup (key), new_value);
+}
+
+
+/* We have an array, now recursively iterate over it's children.  Set 'append' to true so that all values of the array are added
+   under one entry. */
+static void
+tracker_xmp_iter_array (XmpPtr xmp, GHashTable *metadata, const gchar *schema, const gchar *path)
+{
+		XmpIteratorPtr iter = xmp_iterator_new (xmp, schema, path, XMP_ITER_JUSTCHILDREN);
+		tracker_xmp_iter (xmp, iter, metadata, TRUE);
+		xmp_iterator_free (iter);
+}
+
+
+/* We have an array, now recursively iterate over it's children.  Set 'append' to false so that only one item is used. */
+static void
+tracker_xmp_iter_alt_text (XmpPtr xmp, GHashTable *metadata, const gchar *schema, const gchar *path)
+{
+		XmpIteratorPtr iter = xmp_iterator_new (xmp, schema, path, XMP_ITER_JUSTCHILDREN);
+		tracker_xmp_iter (xmp, iter, metadata, FALSE);
+		xmp_iterator_free (iter);
+}
+
+
+/* We have a simple element, but need to iterate over the qualifiers */
+static void
+tracker_xmp_iter_simple_qual (XmpPtr xmp, GHashTable *metadata,
+                              const gchar *schema, const gchar *path, const gchar *value, gboolean append)
+{
+	XmpIteratorPtr iter = xmp_iterator_new (xmp, schema, path, XMP_ITER_JUSTCHILDREN | XMP_ITER_JUSTLEAFNAME);
+
+	XmpStringPtr the_path = xmp_string_new ();
+	XmpStringPtr the_prop = xmp_string_new ();
+
+	gchar *locale = setlocale (LC_ALL, NULL);
+	gchar *sep = strchr (locale,'.');
+	if (sep) {
+		locale[sep - locale] = '\0';
+	}
+	sep = strchr (locale, '_');
+	if (sep) {
+		locale[sep - locale] = '-';
+	}
+
+	gboolean ignore_element = FALSE;
+
+	while (xmp_iterator_next (iter, NULL, the_path, the_prop, NULL)) {
+		const gchar *qual_path = xmp_string_cstr (the_path);
+		const gchar *qual_value = xmp_string_cstr (the_prop);
+
+		if (strcmp (qual_path, "xml:lang") == 0) {
+			/* is this a language we should ignore? */
+			if (strcmp (qual_value, "x-default") != 0 && strcmp (qual_value, "x-repair") != 0 && strcmp (qual_value, locale) != 0) {
+				ignore_element = TRUE;
+				break;
+			}
+		}
+	}
+
+	if (!ignore_element) {
+		tracker_xmp_iter_simple (metadata, schema, path, value, append);
+	}
+
+	xmp_string_free (the_prop);
+	xmp_string_free (the_path);
+
+	xmp_iterator_free (iter);
+}
+
+
+/* We have a simple element. Add any metadata we know about to the hash table  */
+static void
+tracker_xmp_iter_simple (GHashTable *metadata,
+                         const gchar *schema, const gchar *path, const gchar *value, gboolean append)
+{
+	gchar *name = g_strdup (strchr (path, ':') + 1);
+	const gchar *index = strrchr (name, '[');
+	if (index) {
+		name[index-name] = '\0';
+	}
+
+	/* Dublin Core */
+	if (strcmp (schema, NS_DC) == 0) {
+		if (strcmp (name, "title") == 0) {
+			tracker_append_string_to_hash_table (metadata, "Image:Title", value, append);
+		}
+		else if (strcmp (name, "rights") == 0) {
+			tracker_append_string_to_hash_table (metadata, "File:Copyright", value, append);
+		}
+		else if (strcmp (name, "creator") == 0) {
+			tracker_append_string_to_hash_table (metadata, "Image:Creator", value, append);
+		}
+		else if (strcmp (name, "description") == 0) {
+			tracker_append_string_to_hash_table (metadata, "Image:Description", value, append);
+		}
+		else if (strcmp (name, "date") == 0) {
+			tracker_append_string_to_hash_table (metadata, "Image:Date", value, append);
+		}
+		else if (strcmp (name, "keywords") == 0) {
+			tracker_append_string_to_hash_table (metadata, "Image:Keywords", value, append);
+		}
+	}
+	/* Creative Commons */
+	else if (strcmp (schema, NS_CC) == 0) {
+		if (strcmp (name, "license") == 0) {
+			tracker_append_string_to_hash_table (metadata, "File:License", value, append);
+		}
+	}
+
+	g_free (name);
+}
+
+
+/* Iterate over the XMP, dispatching to the appropriate element type (simple, simple w/qualifiers, or an array) handler */
+void
+tracker_xmp_iter (XmpPtr xmp, XmpIteratorPtr iter, GHashTable *metadata, gboolean append)
+{
+	XmpStringPtr the_schema = xmp_string_new ();
+	XmpStringPtr the_path = xmp_string_new ();
+	XmpStringPtr the_prop = xmp_string_new ();
+
+	uint32_t opt;
+	while (xmp_iterator_next (iter, the_schema, the_path, the_prop, &opt)) {
+		const gchar *schema = xmp_string_cstr (the_schema);
+		const gchar *path = xmp_string_cstr (the_path);
+		const gchar *value = xmp_string_cstr (the_prop);
+
+		if (XMP_IS_PROP_SIMPLE (opt)) {
+			if (strcmp (path,"") != 0) {
+				if (XMP_HAS_PROP_QUALIFIERS (opt)) {
+					tracker_xmp_iter_simple_qual (xmp, metadata, schema, path, value, append);
+				} else {
+					tracker_xmp_iter_simple (metadata, schema, path, value, append);
+				}
+			}
+		}
+		else if (XMP_IS_PROP_ARRAY (opt)) {
+			if (XMP_IS_ARRAY_ALTTEXT (opt)) {
+				tracker_xmp_iter_alt_text (xmp, metadata, schema, path);
+				xmp_iterator_skip (iter, XMP_ITER_SKIPSUBTREE);
+			} else {
+				tracker_xmp_iter_array (xmp, metadata, schema, path);
+				xmp_iterator_skip (iter, XMP_ITER_SKIPSUBTREE);
+			}
+		}
+	}
+
+	xmp_string_free (the_prop);
+	xmp_string_free (the_path);
+	xmp_string_free (the_schema);
+}
+
+#endif /* HAVE_EXEMPI */
+
+
+void
+tracker_read_xmp (const gchar *buffer, size_t len, GHashTable *metadata)
+{
+#ifdef HAVE_EXEMPI
+	xmp_init ();
+
+	XmpPtr xmp = xmp_new_empty ();
+	xmp_parse (xmp, buffer, len);
+	if (xmp != NULL) {
+		XmpIteratorPtr iter = xmp_iterator_new (xmp, NULL, NULL, XMP_ITER_PROPERTIES);
+		tracker_xmp_iter (xmp, iter, metadata, FALSE);
+		xmp_iterator_free (iter);
+
+		xmp_free (xmp);
+	}
+
+	xmp_terminate ();
+#endif
+}

Added: trunk/src/tracker-extract/tracker-xmp.h
==============================================================================
--- (empty file)
+++ trunk/src/tracker-extract/tracker-xmp.h	Sun Feb  3 22:20:54 2008
@@ -0,0 +1,27 @@
+/* Tracker Xmp - Xmp helper functions
+ * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#ifndef _TRACKER_XMP_H_
+#define _TRACKER_XMP_H_
+
+#include <glib.h>
+
+void tracker_read_xmp (const gchar *buffer, size_t len, GHashTable *metadata);
+
+#endif /* _TRACKER_XMP_H_ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]