[gimp] app: add a small infrastructure to validate known parasites
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: add a small infrastructure to validate known parasites
- Date: Fri, 21 Mar 2014 23:21:18 +0000 (UTC)
commit 60f23afde2aee28ebacdf52cf088be79e35c47d3
Author: Michael Natterer <mitch gimp org>
Date: Sat Mar 22 00:11:15 2014 +0100
app: add a small infrastructure to validate known parasites
when they are added to items, images or globally, from the PDF or an
XCF file. None of the validation functions does anything currently,
they simply return TRUE.
app/core/gimp-parasites.c | 12 ++++++++
app/core/gimp-parasites.h | 3 ++
app/core/gimpimage.c | 12 ++++++++
app/core/gimpimage.h | 3 ++
app/core/gimpitem.c | 12 ++++++++
app/core/gimpitem.h | 3 ++
app/pdb/gimp-cmds.c | 5 ++-
app/pdb/image-cmds.c | 5 ++-
app/pdb/item-cmds.c | 5 ++-
app/xcf/xcf-load.c | 67 +++++++++++++++++++++++++++++++++++++++----
tools/pdbgen/pdb/gimp.pdb | 5 ++-
tools/pdbgen/pdb/image.pdb | 5 ++-
tools/pdbgen/pdb/item.pdb | 5 ++-
13 files changed, 129 insertions(+), 13 deletions(-)
---
diff --git a/app/core/gimp-parasites.c b/app/core/gimp-parasites.c
index ab1f4cc..639bff6 100644
--- a/app/core/gimp-parasites.c
+++ b/app/core/gimp-parasites.c
@@ -28,6 +28,18 @@
#include "gimpparasitelist.h"
+gboolean
+gimp_parasite_validate (Gimp *gimp,
+ const GimpParasite *parasite,
+ GError **error)
+{
+ g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
+ g_return_val_if_fail (parasite != NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ return TRUE;
+}
+
void
gimp_parasite_attach (Gimp *gimp,
const GimpParasite *parasite)
diff --git a/app/core/gimp-parasites.h b/app/core/gimp-parasites.h
index 9607f4c..506aba6 100644
--- a/app/core/gimp-parasites.h
+++ b/app/core/gimp-parasites.h
@@ -20,6 +20,9 @@
/* some wrappers to access gimp->parasites, mainly for the PDB */
+gboolean gimp_parasite_validate (Gimp *gimp,
+ const GimpParasite *parasite,
+ GError **error);
void gimp_parasite_attach (Gimp *gimp,
const GimpParasite *parasite);
void gimp_parasite_detach (Gimp *gimp,
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index f18da62..eebef2f 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -3050,6 +3050,18 @@ gimp_image_parasite_list (const GimpImage *image,
return list;
}
+gboolean
+gimp_image_parasite_validate (GimpImage *image,
+ const GimpParasite *parasite,
+ GError **error)
+{
+ g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
+ g_return_val_if_fail (parasite != NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ return TRUE;
+}
+
void
gimp_image_parasite_attach (GimpImage *image,
const GimpParasite *parasite)
diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h
index 3cd6a1e..68c6edf 100644
--- a/app/core/gimpimage.h
+++ b/app/core/gimpimage.h
@@ -286,6 +286,9 @@ const GimpParasite * gimp_image_parasite_find (const GimpImage *image,
const gchar *name);
gchar ** gimp_image_parasite_list (const GimpImage *image,
gint *count);
+gboolean gimp_image_parasite_validate (GimpImage *image,
+ const GimpParasite *parasite,
+ GError **error);
void gimp_image_parasite_attach (GimpImage *image,
const GimpParasite *parasite);
void gimp_image_parasite_detach (GimpImage *image,
diff --git a/app/core/gimpitem.c b/app/core/gimpitem.c
index fb77010..649a23f 100644
--- a/app/core/gimpitem.c
+++ b/app/core/gimpitem.c
@@ -1798,6 +1798,18 @@ gimp_item_get_parasites (const GimpItem *item)
return GET_PRIVATE (item)->parasites;
}
+gboolean
+gimp_item_parasite_validate (GimpItem *item,
+ const GimpParasite *parasite,
+ GError **error)
+{
+ g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
+ g_return_val_if_fail (parasite != NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ return TRUE;
+}
+
void
gimp_item_parasite_attach (GimpItem *item,
const GimpParasite *parasite,
diff --git a/app/core/gimpitem.h b/app/core/gimpitem.h
index 7291365..a8ef116 100644
--- a/app/core/gimpitem.h
+++ b/app/core/gimpitem.h
@@ -274,6 +274,9 @@ void gimp_item_set_parasites (GimpItem *item,
GimpParasiteList *parasites);
GimpParasiteList * gimp_item_get_parasites (const GimpItem *item);
+gboolean gimp_item_parasite_validate (GimpItem *item,
+ const GimpParasite *parasite,
+ GError **error);
void gimp_item_parasite_attach (GimpItem *item,
const GimpParasite *parasite,
gboolean push_undo);
diff --git a/app/pdb/gimp-cmds.c b/app/pdb/gimp-cmds.c
index a431520..cc3cd8c 100644
--- a/app/pdb/gimp-cmds.c
+++ b/app/pdb/gimp-cmds.c
@@ -114,7 +114,10 @@ attach_parasite_invoker (GimpProcedure *procedure,
if (success)
{
- gimp_parasite_attach (gimp, parasite);
+ if (gimp_parasite_validate (gimp, parasite, error))
+ gimp_parasite_attach (gimp, parasite);
+ else
+ success = FALSE;
}
return gimp_procedure_get_return_values (procedure, success,
diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c
index 7a74054..f30a256 100644
--- a/app/pdb/image-cmds.c
+++ b/app/pdb/image-cmds.c
@@ -2833,7 +2833,10 @@ image_attach_parasite_invoker (GimpProcedure *procedure,
if (success)
{
- gimp_image_parasite_attach (image, parasite);
+ if (gimp_image_parasite_validate (image, parasite, error))
+ gimp_image_parasite_attach (image, parasite);
+ else
+ success = FALSE;
}
return gimp_procedure_get_return_values (procedure, success,
diff --git a/app/pdb/item-cmds.c b/app/pdb/item-cmds.c
index 0addf69..6194593 100644
--- a/app/pdb/item-cmds.c
+++ b/app/pdb/item-cmds.c
@@ -785,7 +785,10 @@ item_attach_parasite_invoker (GimpProcedure *procedure,
if (success)
{
- gimp_item_parasite_attach (item, parasite, TRUE);
+ if (gimp_item_parasite_validate (item, parasite, error))
+ gimp_item_parasite_attach (item, parasite, TRUE);
+ else
+ success = FALSE;
}
return gimp_procedure_get_return_values (procedure, success,
diff --git a/app/xcf/xcf-load.c b/app/xcf/xcf-load.c
index a0476fa..29aa33a 100644
--- a/app/xcf/xcf-load.c
+++ b/app/xcf/xcf-load.c
@@ -753,12 +753,25 @@ xcf_load_image_props (XcfInfo *info,
while (info->cp - base < prop_size)
{
- GimpParasite *p = xcf_load_parasite (info);
+ GimpParasite *p = xcf_load_parasite (info);
+ GError *error = NULL;
if (! p)
return FALSE;
- gimp_image_parasite_attach (image, p);
+ if (! gimp_image_parasite_validate (image, p, &error))
+ {
+ gimp_message (info->gimp, G_OBJECT (info->progress),
+ GIMP_MESSAGE_WARNING,
+ "Warning, invalid image parasite in XCF file: %s",
+ error->message);
+ g_clear_error (&error);
+ }
+ else
+ {
+ gimp_image_parasite_attach (image, p);
+ }
+
gimp_parasite_free (p);
}
@@ -1026,12 +1039,25 @@ xcf_load_layer_props (XcfInfo *info,
while (info->cp - base < prop_size)
{
- GimpParasite *p = xcf_load_parasite (info);
+ GimpParasite *p = xcf_load_parasite (info);
+ GError *error = NULL;
if (! p)
return FALSE;
- gimp_item_parasite_attach (GIMP_ITEM (*layer), p, FALSE);
+ if (! gimp_item_parasite_validate (GIMP_ITEM (*layer), p, &error))
+ {
+ gimp_message (info->gimp, G_OBJECT (info->progress),
+ GIMP_MESSAGE_WARNING,
+ "Warning, invalid layer parasite in XCF file: %s",
+ error->message);
+ g_clear_error (&error);
+ }
+ else
+ {
+ gimp_item_parasite_attach (GIMP_ITEM (*layer), p, FALSE);
+ }
+
gimp_parasite_free (p);
}
@@ -1222,12 +1248,26 @@ xcf_load_channel_props (XcfInfo *info,
while ((info->cp - base) < prop_size)
{
- GimpParasite *p = xcf_load_parasite (info);
+ GimpParasite *p = xcf_load_parasite (info);
+ GError *error = NULL;
if (! p)
return FALSE;
- gimp_item_parasite_attach (GIMP_ITEM (*channel), p, FALSE);
+ if (! gimp_item_parasite_validate (GIMP_ITEM (*channel), p,
+ &error))
+ {
+ gimp_message (info->gimp, G_OBJECT (info->progress),
+ GIMP_MESSAGE_WARNING,
+ "Warning, invalid channel parasite in XCF file: %s",
+ error->message);
+ g_clear_error (&error);
+ }
+ else
+ {
+ gimp_item_parasite_attach (GIMP_ITEM (*channel), p, FALSE);
+ }
+
gimp_parasite_free (p);
}
@@ -2148,11 +2188,24 @@ xcf_load_vector (XcfInfo *info,
for (i = 0; i < num_parasites; i++)
{
GimpParasite *parasite = xcf_load_parasite (info);
+ GError *error = NULL;
if (! parasite)
return FALSE;
- gimp_item_parasite_attach (GIMP_ITEM (vectors), parasite, FALSE);
+ if (! gimp_item_parasite_validate (GIMP_ITEM (vectors), parasite, &error))
+ {
+ gimp_message (info->gimp, G_OBJECT (info->progress),
+ GIMP_MESSAGE_WARNING,
+ "Warning, invalid vectors parasite in XCF file: %s",
+ error->message);
+ g_clear_error (&error);
+ }
+ else
+ {
+ gimp_item_parasite_attach (GIMP_ITEM (vectors), parasite, FALSE);
+ }
+
gimp_parasite_free (parasite);
}
diff --git a/tools/pdbgen/pdb/gimp.pdb b/tools/pdbgen/pdb/gimp.pdb
index 98d6f8f..0021161 100644
--- a/tools/pdbgen/pdb/gimp.pdb
+++ b/tools/pdbgen/pdb/gimp.pdb
@@ -106,7 +106,10 @@ HELP
%invoke = (
code => <<'CODE'
{
- gimp_parasite_attach (gimp, parasite);
+ if (gimp_parasite_validate (gimp, parasite, error))
+ gimp_parasite_attach (gimp, parasite);
+ else
+ success = FALSE;
}
CODE
);
diff --git a/tools/pdbgen/pdb/image.pdb b/tools/pdbgen/pdb/image.pdb
index b6b8eaf..a3f2b0a 100644
--- a/tools/pdbgen/pdb/image.pdb
+++ b/tools/pdbgen/pdb/image.pdb
@@ -2862,7 +2862,10 @@ HELP
%invoke = (
code => <<'CODE'
{
- gimp_image_parasite_attach (image, parasite);
+ if (gimp_image_parasite_validate (image, parasite, error))
+ gimp_image_parasite_attach (image, parasite);
+ else
+ success = FALSE;
}
CODE
);
diff --git a/tools/pdbgen/pdb/item.pdb b/tools/pdbgen/pdb/item.pdb
index de868ac..6d99a51 100644
--- a/tools/pdbgen/pdb/item.pdb
+++ b/tools/pdbgen/pdb/item.pdb
@@ -753,7 +753,10 @@ HELP
%invoke = (
code => <<'CODE'
{
- gimp_item_parasite_attach (item, parasite, TRUE);
+ if (gimp_item_parasite_validate (item, parasite, error))
+ gimp_item_parasite_attach (item, parasite, TRUE);
+ else
+ success = FALSE;
}
CODE
);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]