[tracker/libtracker-extract-fixes: 2/11] libtracker-extract: Add tracker_xmp_new/free().
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/libtracker-extract-fixes: 2/11] libtracker-extract: Add tracker_xmp_new/free().
- Date: Tue, 13 Apr 2010 16:07:54 +0000 (UTC)
commit 4a45d1bf4c4ce8a7d7f7f5ad7917a448103f4e77
Author: Carlos Garnacho <carlosg gnome org>
Date: Thu Apr 8 13:43:34 2010 +0200
libtracker-extract: Add tracker_xmp_new/free().
These functions deprecate tracker_xmp_read().
src/libtracker-extract/tracker-xmp.c | 144 +++++++++++++++++++++++++++++----
src/libtracker-extract/tracker-xmp.h | 14 +++-
2 files changed, 139 insertions(+), 19 deletions(-)
---
diff --git a/src/libtracker-extract/tracker-xmp.c b/src/libtracker-extract/tracker-xmp.c
index 2eb62fd..afd7ab4 100644
--- a/src/libtracker-extract/tracker-xmp.c
+++ b/src/libtracker-extract/tracker-xmp.c
@@ -449,6 +449,40 @@ iterate (XmpPtr xmp,
#endif /* HAVE_EXEMPI */
+static gboolean
+parse_xmp (const gchar *buffer,
+ size_t len,
+ const gchar *uri,
+ TrackerXmpData *data)
+{
+#ifdef HAVE_EXEMPI
+ XmpPtr xmp;
+#endif /* HAVE_EXEMPI */
+
+ memset (data, 0, sizeof (TrackerXmpData));
+
+#ifdef HAVE_EXEMPI
+
+ xmp_init ();
+
+ xmp = xmp_new_empty ();
+ xmp_parse (xmp, buffer, len);
+
+ if (xmp != NULL) {
+ XmpIteratorPtr iter;
+
+ iter = xmp_iterator_new (xmp, NULL, NULL, XMP_ITER_PROPERTIES);
+ iterate (xmp, iter, uri, data, FALSE);
+ xmp_iterator_free (iter);
+ xmp_free (xmp);
+ }
+
+ xmp_terminate ();
+#endif /* HAVE_EXEMPI */
+
+ return TRUE;
+}
+
/**
* tracker_xmp_read:
* @buffer: a chunk of data with xmp data in it.
@@ -464,6 +498,8 @@ iterate (XmpPtr xmp,
* %FALSE is returned.
*
* Since: 0.8
+ *
+ * Deprecated: 0.9. Use tracker_xmp_new() instead.
**/
gboolean
tracker_xmp_read (const gchar *buffer,
@@ -471,36 +507,108 @@ tracker_xmp_read (const gchar *buffer,
const gchar *uri,
TrackerXmpData *data)
{
-#ifdef HAVE_EXEMPI
- XmpPtr xmp;
-#endif /* HAVE_EXEMPI */
g_return_val_if_fail (buffer != NULL, FALSE);
g_return_val_if_fail (len > 0, FALSE);
g_return_val_if_fail (uri != NULL, FALSE);
g_return_val_if_fail (data != NULL, FALSE);
- memset (data, 0, sizeof (TrackerXmpData));
-
-#ifdef HAVE_EXEMPI
+ return parse_xmp (buffer, len, uri, data);
+}
- xmp_init ();
+/**
+ * tracker_xmp_new:
+ * @buffer: a chunk of data with xmp data in it.
+ * @len: the size of @buffer.
+ * @uri: the URI this is related to.
+ *
+ * This function takes @len bytes of @buffer and runs it through the
+ * XMP library.
+ *
+ * Returns: a newly allocated #TrackerXmpData struct if XMP data was
+ * found, %NULL otherwise. Free the returned struct with
+ * tracker_xmp_free().
+ *
+ * Since: 0.9
+ **/
+TrackerXmpData *
+tracker_xmp_new (const gchar *buffer,
+ gsize len,
+ const gchar *uri)
+{
+ TrackerXmpData *data;
- xmp = xmp_new_empty ();
- xmp_parse (xmp, buffer, len);
+ g_return_val_if_fail (buffer != NULL, NULL);
+ g_return_val_if_fail (len > 0, NULL);
+ g_return_val_if_fail (uri != NULL, NULL);
- if (xmp != NULL) {
- XmpIteratorPtr iter;
+ data = g_new0 (TrackerXmpData, 1);
- iter = xmp_iterator_new (xmp, NULL, NULL, XMP_ITER_PROPERTIES);
- iterate (xmp, iter, uri, data, FALSE);
- xmp_iterator_free (iter);
- xmp_free (xmp);
+ if (!parse_xmp (buffer, len, uri, data)) {
+ tracker_xmp_free (data, TRUE);
+ return NULL;
}
- xmp_terminate ();
-#endif /* HAVE_EXEMPI */
+ return data;
+}
- return TRUE;
+/**
+ * tracker_xmp_free:
+ * @data: a #TrackerXmpData struct
+ * @free_members: %TRUE to free all struct members
+ *
+ * Frees @data, and optionally all struct members if @free_members
+ * is %TRUE.
+ *
+ * Since: 0.9
+ **/
+void
+tracker_xmp_free (TrackerXmpData *data,
+ gboolean free_members)
+{
+ g_return_if_fail (data != NULL);
+
+ if (free_members) {
+ g_free (data->title);
+ g_free (data->rights);
+ g_free (data->creator);
+ g_free (data->description);
+ g_free (data->date);
+ g_free (data->keywords);
+ g_free (data->subject);
+ g_free (data->publisher);
+ g_free (data->contributor);
+ g_free (data->type);
+ g_free (data->format);
+ g_free (data->identifier);
+ g_free (data->source);
+ g_free (data->language);
+ g_free (data->relation);
+ g_free (data->coverage);
+ g_free (data->license);
+ g_free (data->pdf_title);
+ g_free (data->pdf_keywords);
+ g_free (data->title2);
+ g_free (data->time_original);
+ g_free (data->artist);
+ g_free (data->make);
+ g_free (data->model);
+ g_free (data->orientation);
+ g_free (data->flash);
+ g_free (data->metering_mode);
+ g_free (data->exposure_time);
+ g_free (data->fnumber);
+ g_free (data->focal_length);
+ g_free (data->iso_speed_ratings);
+ g_free (data->white_balance);
+ g_free (data->copyright);
+ g_free (data->rating);
+ g_free (data->address);
+ g_free (data->country);
+ g_free (data->state);
+ g_free (data->city);
+ }
+
+ g_free (data);
}
static void
diff --git a/src/libtracker-extract/tracker-xmp.h b/src/libtracker-extract/tracker-xmp.h
index 0ec3459..7382173 100644
--- a/src/libtracker-extract/tracker-xmp.h
+++ b/src/libtracker-extract/tracker-xmp.h
@@ -84,10 +84,22 @@ typedef struct {
gchar *city;
} TrackerXmpData;
+#ifndef TRACKER_DISABLE_DEPRECATED
+
gboolean tracker_xmp_read (const gchar *buffer,
size_t len,
const gchar *uri,
- TrackerXmpData *data);
+ TrackerXmpData *data) G_GNUC_DEPRECATED;
+
+#endif /* TRACKER_DISABLE_DEPRECATED */
+
+TrackerXmpData * tracker_xmp_new (const gchar *buffer,
+ gsize len,
+ const gchar *uri);
+
+void tracker_xmp_free (TrackerXmpData *data,
+ gboolean free_members);
+
gboolean tracker_xmp_apply (TrackerSparqlBuilder *metadata,
const gchar *uri,
TrackerXmpData *data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]