gimp r27323 - in trunk: . plug-ins/metadata
- From: neo svn gnome org
- To: svn-commits-list gnome org
- Subject: gimp r27323 - in trunk: . plug-ins/metadata
- Date: Sun, 19 Oct 2008 13:29:35 +0000 (UTC)
Author: neo
Date: Sun Oct 19 13:29:35 2008
New Revision: 27323
URL: http://svn.gnome.org/viewvc/gimp?rev=27323&view=rev
Log:
2008-10-19 Sven Neumann <sven gimp org>
Bug 493778 â metadata plug-in crashes on some images
* plug-ins/metadata/xmp-encode.c (gen_property): introduced a
utility function to create XML elements. Deal gracefully with
NULL
and empty values. Does not fix the crash, but fixes a warning
that
has been reported in the same bug report.
Modified:
trunk/ChangeLog
trunk/plug-ins/metadata/xmp-encode.c
Modified: trunk/plug-ins/metadata/xmp-encode.c
==============================================================================
--- trunk/plug-ins/metadata/xmp-encode.c (original)
+++ trunk/plug-ins/metadata/xmp-encode.c Sun Oct 19 13:29:35 2008
@@ -32,6 +32,15 @@
#include "xmp-encode.h"
#include "xmp-schemas.h"
+
+static void gen_element (GString *buffer,
+ gint indent,
+ const gchar *prefix,
+ const gchar *name,
+ const gchar *value,
+ ...) G_GNUC_NULL_TERMINATED;
+
+
static void
gen_schema_start (GString *buffer,
const XMPSchema *schema)
@@ -47,6 +56,48 @@
}
static void
+gen_element (GString *buffer,
+ gint indent,
+ const gchar *prefix,
+ const gchar *name,
+ const gchar *value,
+ ...)
+{
+ const gchar *attr_name;
+ const gchar *attr_value;
+ va_list args;
+
+ while (indent--)
+ g_string_append_c (buffer, ' ');
+
+ g_string_append_printf (buffer, "<%s:%s", prefix, name);
+
+ va_start (args, value);
+
+ while ((attr_name = va_arg (args, const gchar *)) != NULL &&
+ (attr_value = va_arg (args, const gchar *)) != NULL)
+ {
+ if (*attr_name && *attr_value)
+ g_string_append_printf (buffer, " %s='%s'", attr_name, attr_value);
+ }
+
+ va_end (args);
+
+ if (value && *value)
+ {
+ gchar *escaped_value = g_markup_escape_text (value, -1);
+
+ g_string_append_printf (buffer, ">%s</%s:%s>\n",
+ escaped_value, prefix, name);
+ g_free (escaped_value);
+ }
+ else
+ {
+ g_string_append (buffer, " />\n");
+ }
+}
+
+static void
gen_property (GString *buffer,
const XMPSchema *schema,
const XMPProperty *property,
@@ -54,7 +105,6 @@
{
gint i;
const gchar *ns_prefix;
- gchar *escaped_value;
switch (property->type)
{
@@ -65,12 +115,8 @@
case XMP_TYPE_MIME_TYPE:
case XMP_TYPE_TEXT:
case XMP_TYPE_RATIONAL:
- escaped_value = g_markup_escape_text (value_array[0], -1);
- g_string_append_printf (buffer, " <%s:%s>%s</%s:%s>\n",
- schema->prefix, property->name,
- escaped_value,
- schema->prefix, property->name);
- g_free (escaped_value);
+ gen_element (buffer, 2,
+ schema->prefix, property->name, value_array[0], NULL);
break;
case XMP_TYPE_LOCALE_BAG:
@@ -81,10 +127,8 @@
schema->prefix, property->name);
for (i = 0; value_array[i] != NULL; i++)
{
- escaped_value = g_markup_escape_text (value_array[i], -1);
- g_string_append_printf (buffer, " <rdf:li>%s</rdf:li>\n",
- escaped_value);
- g_free (escaped_value);
+ gen_element (buffer, 4,
+ "rdf", "li", value_array[i], NULL);
}
g_string_append_printf (buffer, " </rdf:Bag>\n </%s:%s>\n",
schema->prefix, property->name);
@@ -98,10 +142,8 @@
schema->prefix, property->name);
for (i = 0; value_array[i] != NULL; i++)
{
- escaped_value = g_markup_escape_text (value_array[i], -1);
- g_string_append_printf (buffer, " <rdf:li>%s</rdf:li>\n",
- escaped_value);
- g_free (escaped_value);
+ gen_element (buffer, 4,
+ "rdf", "li", value_array[i], NULL);
}
g_string_append_printf (buffer, " </rdf:Seq>\n </%s:%s>\n",
schema->prefix, property->name);
@@ -112,19 +154,20 @@
schema->prefix, property->name);
for (i = 0; value_array[i] != NULL; i += 2)
{
- escaped_value = g_markup_escape_text (value_array[i + 1], -1);
- g_string_append_printf (buffer,
- " <rdf:li xml:lang='%s'>%s</rdf:li>\n",
- value_array[i], escaped_value);
- g_free (escaped_value);
+ gen_element (buffer, 4,
+ "rdf", "li", value_array[i + 1],
+ "xml:lang", value_array[i],
+ NULL);
}
g_string_append_printf (buffer, " </rdf:Alt>\n </%s:%s>\n",
schema->prefix, property->name);
break;
case XMP_TYPE_URI:
- g_string_append_printf (buffer, " <%s:%s rdf:resource='%s' />\n",
- schema->prefix, property->name, value_array[0]);
+ gen_element (buffer, 2,
+ schema->prefix, property->name, NULL,
+ "rdf:resource", value_array[0],
+ NULL);
break;
case XMP_TYPE_RESOURCE_REF:
@@ -156,12 +199,8 @@
if (value_array[0] && value_array[1])
for (i = 2; value_array[i] != NULL; i += 2)
{
- escaped_value = g_markup_escape_text (value_array[i + 1], -1);
- g_string_append_printf (buffer, " <%s:%s>%s</%s:%s>\n",
- ns_prefix, value_array[i],
- escaped_value,
- ns_prefix, value_array[i]);
- g_free (escaped_value);
+ gen_element (buffer, 3,
+ ns_prefix, value_array[i], value_array[i + 1], NULL);
}
g_string_append_printf (buffer, " </%s:%s>\n",
schema->prefix, property->name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]