[tracker/libtracker-extract-fixes: 3/9] libtracker-extract: Add tracker_iptc_new/free().



commit ecf587c5e4b185dda9d5d03fa042f2e4491c417e
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Apr 8 13:44:18 2010 +0200

    libtracker-extract: Add tracker_iptc_new/free().
    
    These functions deprecate tracker_iptc_read().

 src/libtracker-extract/tracker-iptc.c |  122 +++++++++++++++++++++++++++------
 src/libtracker-extract/tracker-iptc.h |   13 +++-
 2 files changed, 114 insertions(+), 21 deletions(-)
---
diff --git a/src/libtracker-extract/tracker-iptc.c b/src/libtracker-extract/tracker-iptc.c
index b8e3ca3..771cf6b 100644
--- a/src/libtracker-extract/tracker-iptc.c
+++ b/src/libtracker-extract/tracker-iptc.c
@@ -180,6 +180,40 @@ foreach_dataset (IptcDataSet *dataset,
 
 #endif /* HAVE_LIBIPTCDATA */
 
+static gboolean
+tracker_iptc_parse (const unsigned char *buffer,
+                    size_t               len,
+                    const gchar         *uri,
+                    TrackerIptcData     *data)
+{
+#ifdef HAVE_LIBIPTCDATA
+	IptcData *iptc;
+#endif /* HAVE_LIBIPTCDATA */
+
+	memset (data, 0, sizeof (TrackerIptcData));
+
+#ifdef HAVE_LIBIPTCDATA
+
+	/* FIXME According to valgrind this is leaking (together with the unref).
+	 * Problem in libiptc (I replaced this with the _free equivalent) */
+
+	iptc = iptc_data_new ();
+
+	if (!iptc)
+		return FALSE;
+
+	if (iptc_data_load (iptc, buffer, len) < 0) {
+		iptc_data_free (iptc);
+		return FALSE;
+	}
+
+	iptc_data_foreach_dataset (iptc, foreach_dataset, data);
+	iptc_data_free (iptc);
+#endif /* HAVE_LIBIPTCDATA */
+
+	return TRUE;
+}
+
 /**
  * tracker_iptc_read:
  * @buffer: a chunk of data with iptc data in it.
@@ -195,6 +229,8 @@ foreach_dataset (IptcDataSet *dataset,
  * %FALSE is returned.
  *
  * Since: 0.8
+ *
+ * Deprecated: 0.9. Use tracker_iptc_new() instead.
  **/
 gboolean
 tracker_iptc_read (const unsigned char *buffer,
@@ -202,35 +238,81 @@ tracker_iptc_read (const unsigned char *buffer,
                    const gchar         *uri,
                    TrackerIptcData     *data)
 {
-#ifdef HAVE_LIBIPTCDATA
-	IptcData *iptc;
-#endif /* HAVE_LIBIPTCDATA */
-
 	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 (TrackerIptcData));
-
-#ifdef HAVE_LIBIPTCDATA
+        return tracker_iptc_parse (buffer, len, uri, data);
+}
 
-	/* FIXME According to valgrind this is leaking (together with the unref).
-	 * Problem in libiptc (I replaced this with the _free equivalent) */
+/**
+ * tracker_iptc_new:
+ * @buffer: a chunk of data with iptc data in it.
+ * @len: the size of @buffer.
+ * @uri: the URI this is related to.
+ * @data: a pointer to a TrackerIptcData struture to populate.
+ *
+ * This function takes @len bytes of @buffer and runs it through the
+ * IPTC library.
+ *
+ * Returns: a newly allocated #TrackerIptcData struct if IPTC data was
+ *          found, %NULL otherwise. Free the returned struct with
+ *          tracker_iptc_free().
+ *
+ * Since: 0.9
+ **/
+TrackerIptcData *
+tracker_iptc_new (const guchar *buffer,
+                  gsize         len,
+                  const gchar  *uri)
+{
+        TrackerIptcData *data;
 
-	iptc = iptc_data_new ();
+        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 (!iptc)
-		return FALSE;
+        data = g_new0 (TrackerIptcData, 1);
 
-	if (iptc_data_load (iptc, buffer, len) < 0) {
-		iptc_data_free (iptc);
-		return FALSE;
-	}
+        if (!tracker_iptc_parse (buffer, len, uri, data)) {
+                tracker_iptc_free (data, TRUE);
+                return NULL;
+        }
 
-	iptc_data_foreach_dataset (iptc, foreach_dataset, data);
-	iptc_data_free (iptc);
-#endif /* HAVE_LIBIPTCDATA */
+        return data;
+}
 
-	return TRUE;
+/**
+ * tracker_iptc_free:
+ * @data: a #TrackerIptcData
+ * @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_iptc_free (TrackerIptcData *data,
+                   gboolean         free_members)
+{
+        g_return_if_fail (data != NULL);
+
+        if (free_members) {
+                g_free (data->keywords);
+                g_free (data->date_created);
+                g_free (data->byline);
+                g_free (data->credit);
+                g_free (data->copyright_notice);
+                g_free (data->image_orientation);
+                g_free (data->byline_title);
+                g_free (data->city);
+                g_free (data->state);
+                g_free (data->sublocation);
+                g_free (data->country_name);
+                g_free (data->contact);
+        }
+
+        g_free (data);
 }
diff --git a/src/libtracker-extract/tracker-iptc.h b/src/libtracker-extract/tracker-iptc.h
index ef2fb6a..f364127 100644
--- a/src/libtracker-extract/tracker-iptc.h
+++ b/src/libtracker-extract/tracker-iptc.h
@@ -45,10 +45,21 @@ typedef struct {
 	gchar *contact;
 } TrackerIptcData;
 
+#ifndef TRACKER_DISABLE_DEPRECATED
+
 gboolean tracker_iptc_read (const unsigned char *buffer,
                             size_t               len,
                             const gchar         *uri,
-                            TrackerIptcData     *data);
+                            TrackerIptcData     *data) G_GNUC_DEPRECATED;
+
+#endif /* TRACKER_DISABLE_DEPRECATED */
+
+TrackerIptcData * tracker_iptc_new (const guchar *buffer,
+                                    gsize         len,
+                                    const gchar  *uri);
+
+void tracker_iptc_free (TrackerIptcData *data,
+                        gboolean         free_members);
 
 G_END_DECLS
 



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