mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-10-06 01:12:40 +02:00
pdb: Extract GEGL operation validation into its own function
A follow-up commit will make use of it in multiple places.
This commit is contained in:
@@ -50,6 +50,58 @@
|
||||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
static gboolean
|
||||
validate_operation_name (const gchar *operation_name,
|
||||
GError **error)
|
||||
{
|
||||
GType op_type;
|
||||
|
||||
/* Comes from gegl/operation/gegl-operations.h which is not public. */
|
||||
GType gegl_operation_gtype_from_name (const gchar *name);
|
||||
|
||||
op_type = gegl_operation_gtype_from_name (operation_name);
|
||||
|
||||
/* Using the same rules as in xcf_load_effect() for plug-in created
|
||||
* effects.
|
||||
*/
|
||||
if (g_type_is_a (op_type, GEGL_TYPE_OPERATION_SINK))
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
"%s: the filter \"%s\" is unsafe.",
|
||||
G_STRFUNC, operation_name);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
else if (g_strcmp0 (operation_name, "gegl:gegl") == 0 &&
|
||||
g_getenv ("GIMP_ALLOW_GEGL_GRAPH_LAYER_EFFECT") == NULL)
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
"%s: the filter \"gegl:gegl\" is unsafe.\n"
|
||||
"For development purpose, set environment variable GIMP_ALLOW_GEGL_GRAPH_LAYER_EFFECT.",
|
||||
G_STRFUNC);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (g_strcmp0 (operation_name, "gegl:nop") == 0)
|
||||
{
|
||||
g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
"The filter \"gegl:nop\" is useless and not allowed.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (! gegl_has_operation (operation_name))
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
"%s: the filter \"%s\" is not installed.",
|
||||
G_STRFUNC, operation_name);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GimpValueArray *
|
||||
drawable_filter_id_is_valid_invoker (GimpProcedure *procedure,
|
||||
Gimp *gimp,
|
||||
@@ -100,48 +152,7 @@ drawable_filter_new_invoker (GimpProcedure *procedure,
|
||||
|
||||
if (success)
|
||||
{
|
||||
GType op_type;
|
||||
|
||||
/* Comes from gegl/operation/gegl-operations.h which is not public. */
|
||||
GType gegl_operation_gtype_from_name (const gchar *name);
|
||||
|
||||
op_type = gegl_operation_gtype_from_name (operation_name);
|
||||
/* Using the same rules as in xcf_load_effect() for plug-in created
|
||||
* effects.
|
||||
*/
|
||||
if (g_type_is_a (op_type, GEGL_TYPE_OPERATION_SINK))
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
"%s: the filter \"%s\" is unsafe.",
|
||||
G_STRFUNC, operation_name);
|
||||
|
||||
success = FALSE;
|
||||
}
|
||||
else if (g_strcmp0 (operation_name, "gegl:gegl") == 0 &&
|
||||
g_getenv ("GIMP_ALLOW_GEGL_GRAPH_LAYER_EFFECT") == NULL)
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
"%s: the filter \"gegl:gegl\" is unsafe.\n"
|
||||
"For development purpose, set environment variable GIMP_ALLOW_GEGL_GRAPH_LAYER_EFFECT.",
|
||||
G_STRFUNC);
|
||||
|
||||
success = FALSE;
|
||||
}
|
||||
|
||||
if (! gegl_has_operation (operation_name) || ! g_strcmp0 (operation_name, "gegl:nop"))
|
||||
{
|
||||
if (! g_strcmp0 (operation_name, "gegl:nop"))
|
||||
g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
"The filter \"gegl:nop\" is useless and not allowed.");
|
||||
else
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
"%s: the filter \"%s\" is not installed.",
|
||||
G_STRFUNC, operation_name);
|
||||
|
||||
success = FALSE;
|
||||
}
|
||||
|
||||
if (success)
|
||||
if (validate_operation_name (operation_name, error))
|
||||
{
|
||||
GeglNode *operation = gegl_node_new ();
|
||||
|
||||
@@ -158,6 +169,10 @@ drawable_filter_new_invoker (GimpProcedure *procedure,
|
||||
gimp_drawable_filter_set_clip (filter, FALSE);
|
||||
g_clear_object (&operation);
|
||||
}
|
||||
else
|
||||
{
|
||||
success = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return_vals = gimp_procedure_get_return_values (procedure, success,
|
||||
|
@@ -75,48 +75,7 @@ HELP
|
||||
%invoke = (
|
||||
code => <<'CODE'
|
||||
{
|
||||
GType op_type;
|
||||
|
||||
/* Comes from gegl/operation/gegl-operations.h which is not public. */
|
||||
GType gegl_operation_gtype_from_name (const gchar *name);
|
||||
|
||||
op_type = gegl_operation_gtype_from_name (operation_name);
|
||||
/* Using the same rules as in xcf_load_effect() for plug-in created
|
||||
* effects.
|
||||
*/
|
||||
if (g_type_is_a (op_type, GEGL_TYPE_OPERATION_SINK))
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
"%s: the filter \"%s\" is unsafe.",
|
||||
G_STRFUNC, operation_name);
|
||||
|
||||
success = FALSE;
|
||||
}
|
||||
else if (g_strcmp0 (operation_name, "gegl:gegl") == 0 &&
|
||||
g_getenv ("GIMP_ALLOW_GEGL_GRAPH_LAYER_EFFECT") == NULL)
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
"%s: the filter \"gegl:gegl\" is unsafe.\n"
|
||||
"For development purpose, set environment variable GIMP_ALLOW_GEGL_GRAPH_LAYER_EFFECT.",
|
||||
G_STRFUNC);
|
||||
|
||||
success = FALSE;
|
||||
}
|
||||
|
||||
if (! gegl_has_operation (operation_name) || ! g_strcmp0 (operation_name, "gegl:nop"))
|
||||
{
|
||||
if (! g_strcmp0 (operation_name, "gegl:nop"))
|
||||
g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
"The filter \"gegl:nop\" is useless and not allowed.");
|
||||
else
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
"%s: the filter \"%s\" is not installed.",
|
||||
G_STRFUNC, operation_name);
|
||||
|
||||
success = FALSE;
|
||||
}
|
||||
|
||||
if (success)
|
||||
if (validate_operation_name (operation_name, error))
|
||||
{
|
||||
GeglNode *operation = gegl_node_new ();
|
||||
|
||||
@@ -133,6 +92,10 @@ HELP
|
||||
gimp_drawable_filter_set_clip (filter, FALSE);
|
||||
g_clear_object (&operation);
|
||||
}
|
||||
else
|
||||
{
|
||||
success = FALSE;
|
||||
}
|
||||
}
|
||||
CODE
|
||||
);
|
||||
@@ -682,6 +645,60 @@ CODE
|
||||
);
|
||||
}
|
||||
|
||||
$extra{app}->{code} = <<'CODE';
|
||||
static gboolean
|
||||
validate_operation_name (const gchar *operation_name,
|
||||
GError **error)
|
||||
{
|
||||
GType op_type;
|
||||
|
||||
/* Comes from gegl/operation/gegl-operations.h which is not public. */
|
||||
GType gegl_operation_gtype_from_name (const gchar *name);
|
||||
|
||||
op_type = gegl_operation_gtype_from_name (operation_name);
|
||||
|
||||
/* Using the same rules as in xcf_load_effect() for plug-in created
|
||||
* effects.
|
||||
*/
|
||||
if (g_type_is_a (op_type, GEGL_TYPE_OPERATION_SINK))
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
"%s: the filter \"%s\" is unsafe.",
|
||||
G_STRFUNC, operation_name);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
else if (g_strcmp0 (operation_name, "gegl:gegl") == 0 &&
|
||||
g_getenv ("GIMP_ALLOW_GEGL_GRAPH_LAYER_EFFECT") == NULL)
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
"%s: the filter \"gegl:gegl\" is unsafe.\n"
|
||||
"For development purpose, set environment variable GIMP_ALLOW_GEGL_GRAPH_LAYER_EFFECT.",
|
||||
G_STRFUNC);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (g_strcmp0 (operation_name, "gegl:nop") == 0)
|
||||
{
|
||||
g_set_error_literal (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
"The filter \"gegl:nop\" is useless and not allowed.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (! gegl_has_operation (operation_name))
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
|
||||
"%s: the filter \"%s\" is not installed.",
|
||||
G_STRFUNC, operation_name);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
CODE
|
||||
|
||||
@headers = qw(<gegl.h>
|
||||
<gegl-plugin.h>
|
||||
"core/gimpcontainer.h"
|
||||
|
Reference in New Issue
Block a user