~ubuntu-branches/ubuntu/maverick/gimp/maverick-updates

« back to all changes in this revision

Viewing changes to app/plug-in/plug-in-message.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-12-09 19:44:52 UTC
  • Revision ID: james.westby@ubuntu.com-20051209194452-yggpemjlofpjqyf4
Tags: upstream-2.2.9
ImportĀ upstreamĀ versionĀ 2.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* The GIMP -- an image manipulation program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * plug-in-message.c
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include <string.h>
 
24
 
 
25
#include <glib-object.h>
 
26
 
 
27
#include "libgimpbase/gimpbase.h"
 
28
#include "libgimpbase/gimpprotocol.h"
 
29
#include "libgimpbase/gimpwire.h"
 
30
 
 
31
#include "plug-in-types.h"
 
32
 
 
33
#include "base/tile.h"
 
34
#include "base/tile-manager.h"
 
35
 
 
36
#include "core/gimp.h"
 
37
#include "core/gimpdrawable.h"
 
38
 
 
39
#include "plug-in.h"
 
40
#include "plug-ins.h"
 
41
#include "plug-in-def.h"
 
42
#include "plug-in-params.h"
 
43
#include "plug-in-proc-def.h"
 
44
#include "plug-in-shm.h"
 
45
 
 
46
 
 
47
typedef struct _PlugInBlocked PlugInBlocked;
 
48
 
 
49
struct _PlugInBlocked
 
50
{
 
51
  PlugIn *plug_in;
 
52
  gchar  *proc_name;
 
53
};
 
54
 
 
55
 
 
56
/*  local function prototypes  */
 
57
 
 
58
static void plug_in_handle_quit             (PlugIn          *plug_in);
 
59
static void plug_in_handle_tile_req         (PlugIn          *plug_in,
 
60
                                             GPTileReq       *tile_req);
 
61
static void plug_in_handle_proc_run         (PlugIn          *plug_in,
 
62
                                             GPProcRun       *proc_run);
 
63
static void plug_in_handle_proc_return_priv (PlugIn          *plug_in,
 
64
                                             GPProcReturn    *proc_return,
 
65
                                             gboolean         temp_proc);
 
66
static void plug_in_handle_proc_return      (PlugIn          *plug_in,
 
67
                                             GPProcReturn    *proc_return);
 
68
static void plug_in_handle_temp_proc_return (PlugIn          *plug_in,
 
69
                                             GPProcReturn    *proc_return);
 
70
static void plug_in_handle_proc_install     (PlugIn          *plug_in,
 
71
                                             GPProcInstall   *proc_install);
 
72
static void plug_in_handle_proc_uninstall   (PlugIn          *plug_in,
 
73
                                             GPProcUninstall *proc_uninstall);
 
74
static void plug_in_handle_extension_ack    (PlugIn          *plug_in);
 
75
static void plug_in_handle_has_init         (PlugIn          *plug_in);
 
76
 
 
77
 
 
78
/*  private variables  */
 
79
 
 
80
static GSList *blocked_plug_ins = NULL;
 
81
 
 
82
 
 
83
/*  public functions  */
 
84
 
 
85
void
 
86
plug_in_handle_message (PlugIn      *plug_in,
 
87
                        WireMessage *msg)
 
88
{
 
89
  switch (msg->type)
 
90
    {
 
91
    case GP_QUIT:
 
92
      plug_in_handle_quit (plug_in);
 
93
      break;
 
94
 
 
95
    case GP_CONFIG:
 
96
      g_message ("Plug-In \"%s\"\n(%s)\n\n"
 
97
                 "sent a CONFIG message (should not happen)",
 
98
                 gimp_filename_to_utf8 (plug_in->name),
 
99
                 gimp_filename_to_utf8 (plug_in->prog));
 
100
      plug_in_close (plug_in, TRUE);
 
101
      break;
 
102
 
 
103
    case GP_TILE_REQ:
 
104
      plug_in_handle_tile_req (plug_in, msg->data);
 
105
      break;
 
106
 
 
107
    case GP_TILE_ACK:
 
108
      g_message ("Plug-In \"%s\"\n(%s)\n\n"
 
109
                 "sent a TILE_ACK message (should not happen)",
 
110
                 gimp_filename_to_utf8 (plug_in->name),
 
111
                 gimp_filename_to_utf8 (plug_in->prog));
 
112
      plug_in_close (plug_in, TRUE);
 
113
      break;
 
114
 
 
115
    case GP_TILE_DATA:
 
116
      g_message ("Plug-In \"%s\"\n(%s)\n\n"
 
117
                 "sent a TILE_DATA message (should not happen)",
 
118
                 gimp_filename_to_utf8 (plug_in->name),
 
119
                 gimp_filename_to_utf8 (plug_in->prog));
 
120
      plug_in_close (plug_in, TRUE);
 
121
      break;
 
122
 
 
123
    case GP_PROC_RUN:
 
124
      plug_in_handle_proc_run (plug_in, msg->data);
 
125
      break;
 
126
 
 
127
    case GP_PROC_RETURN:
 
128
      plug_in_handle_proc_return (plug_in, msg->data);
 
129
      break;
 
130
 
 
131
    case GP_TEMP_PROC_RUN:
 
132
      g_message ("Plug-In \"%s\"\n(%s)\n\n"
 
133
                 "sent a TEMP_PROC_RUN message (should not happen)",
 
134
                 gimp_filename_to_utf8 (plug_in->name),
 
135
                 gimp_filename_to_utf8 (plug_in->prog));
 
136
      plug_in_close (plug_in, TRUE);
 
137
      break;
 
138
 
 
139
    case GP_TEMP_PROC_RETURN:
 
140
      plug_in_handle_temp_proc_return (plug_in, msg->data);
 
141
      break;
 
142
 
 
143
    case GP_PROC_INSTALL:
 
144
      plug_in_handle_proc_install (plug_in, msg->data);
 
145
      break;
 
146
 
 
147
    case GP_PROC_UNINSTALL:
 
148
      plug_in_handle_proc_uninstall (plug_in, msg->data);
 
149
      break;
 
150
 
 
151
    case GP_EXTENSION_ACK:
 
152
      plug_in_handle_extension_ack (plug_in);
 
153
      break;
 
154
 
 
155
    case GP_HAS_INIT:
 
156
      plug_in_handle_has_init (plug_in);
 
157
      break;
 
158
    }
 
159
}
 
160
 
 
161
 
 
162
/*  private functions  */
 
163
 
 
164
static void
 
165
plug_in_handle_quit (PlugIn *plug_in)
 
166
{
 
167
  plug_in_close (plug_in, FALSE);
 
168
}
 
169
 
 
170
static void
 
171
plug_in_handle_tile_req (PlugIn    *plug_in,
 
172
                         GPTileReq *tile_req)
 
173
{
 
174
  GPTileData    tile_data;
 
175
  GPTileData   *tile_info;
 
176
  WireMessage   msg;
 
177
  GimpDrawable *drawable;
 
178
  TileManager  *tm;
 
179
  Tile         *tile;
 
180
  gint          shm_ID;
 
181
 
 
182
  shm_ID = plug_in_shm_get_ID (plug_in->gimp);
 
183
 
 
184
  if (tile_req->drawable_ID == -1)
 
185
    {
 
186
      /*  this branch communicates with libgimp/gimptile.c:gimp_tile_put()  */
 
187
 
 
188
      tile_data.drawable_ID = -1;
 
189
      tile_data.tile_num    = 0;
 
190
      tile_data.shadow      = 0;
 
191
      tile_data.bpp         = 0;
 
192
      tile_data.width       = 0;
 
193
      tile_data.height      = 0;
 
194
      tile_data.use_shm     = (shm_ID == -1) ? FALSE : TRUE;
 
195
      tile_data.data        = NULL;
 
196
 
 
197
      if (! gp_tile_data_write (plug_in->my_write, &tile_data, plug_in))
 
198
        {
 
199
          g_warning ("plug_in_handle_tile_req: ERROR");
 
200
          plug_in_close (plug_in, TRUE);
 
201
          return;
 
202
        }
 
203
 
 
204
      if (! wire_read_msg (plug_in->my_read, &msg, plug_in))
 
205
        {
 
206
          g_warning ("plug_in_handle_tile_req: ERROR");
 
207
          plug_in_close (plug_in, TRUE);
 
208
          return;
 
209
        }
 
210
 
 
211
      if (msg.type != GP_TILE_DATA)
 
212
        {
 
213
          g_warning ("expected tile data and received: %d", msg.type);
 
214
          plug_in_close (plug_in, TRUE);
 
215
          return;
 
216
        }
 
217
 
 
218
      tile_info = msg.data;
 
219
 
 
220
      drawable = (GimpDrawable *) gimp_item_get_by_ID (plug_in->gimp,
 
221
                                                       tile_info->drawable_ID);
 
222
 
 
223
      if (! drawable)
 
224
        {
 
225
          g_message ("Plug-In \"%s\"\n(%s)\n\n"
 
226
                     "requested invalid drawable (killing)",
 
227
                     gimp_filename_to_utf8 (plug_in->name),
 
228
                     gimp_filename_to_utf8 (plug_in->prog));
 
229
          plug_in_close (plug_in, TRUE);
 
230
          return;
 
231
        }
 
232
 
 
233
      if (tile_info->shadow)
 
234
        tm = gimp_drawable_shadow (drawable);
 
235
      else
 
236
        tm = gimp_drawable_data (drawable);
 
237
 
 
238
      tile = tile_manager_get (tm, tile_info->tile_num, TRUE, TRUE);
 
239
 
 
240
      if (! tile)
 
241
        {
 
242
          g_message ("Plug-In \"%s\"\n(%s)\n\n"
 
243
                     "requested invalid tile (killing)",
 
244
                     gimp_filename_to_utf8 (plug_in->name),
 
245
                     gimp_filename_to_utf8 (plug_in->prog));
 
246
          plug_in_close (plug_in, TRUE);
 
247
          return;
 
248
        }
 
249
 
 
250
      if (tile_data.use_shm)
 
251
        memcpy (tile_data_pointer (tile, 0, 0),
 
252
                plug_in_shm_get_addr (plug_in->gimp),
 
253
                tile_size (tile));
 
254
      else
 
255
        memcpy (tile_data_pointer (tile, 0, 0),
 
256
                tile_info->data,
 
257
                tile_size (tile));
 
258
 
 
259
      tile_release (tile, TRUE);
 
260
 
 
261
      wire_destroy (&msg);
 
262
      if (! gp_tile_ack_write (plug_in->my_write, plug_in))
 
263
        {
 
264
          g_warning ("plug_in_handle_tile_req: ERROR");
 
265
          plug_in_close (plug_in, TRUE);
 
266
          return;
 
267
        }
 
268
    }
 
269
  else
 
270
    {
 
271
      /*  this branch communicates with libgimp/gimptile.c:gimp_tile_get()  */
 
272
 
 
273
      drawable = (GimpDrawable *) gimp_item_get_by_ID (plug_in->gimp,
 
274
                                                       tile_req->drawable_ID);
 
275
 
 
276
      if (! drawable)
 
277
        {
 
278
          g_message ("Plug-In \"%s\"\n(%s)\n\n"
 
279
                     "requested invalid drawable (killing)",
 
280
                     gimp_filename_to_utf8 (plug_in->name),
 
281
                     gimp_filename_to_utf8 (plug_in->prog));
 
282
          plug_in_close (plug_in, TRUE);
 
283
          return;
 
284
        }
 
285
 
 
286
      if (tile_req->shadow)
 
287
        tm = gimp_drawable_shadow (drawable);
 
288
      else
 
289
        tm = gimp_drawable_data (drawable);
 
290
 
 
291
      tile = tile_manager_get (tm, tile_req->tile_num, TRUE, FALSE);
 
292
 
 
293
      if (! tile)
 
294
        {
 
295
          g_message ("Plug-In \"%s\"\n(%s)\n\n"
 
296
                     "requested invalid tile (killing)",
 
297
                     gimp_filename_to_utf8 (plug_in->name),
 
298
                     gimp_filename_to_utf8 (plug_in->prog));
 
299
          plug_in_close (plug_in, TRUE);
 
300
          return;
 
301
        }
 
302
 
 
303
      tile_data.drawable_ID = tile_req->drawable_ID;
 
304
      tile_data.tile_num    = tile_req->tile_num;
 
305
      tile_data.shadow      = tile_req->shadow;
 
306
      tile_data.bpp         = tile_bpp (tile);
 
307
      tile_data.width       = tile_ewidth (tile);
 
308
      tile_data.height      = tile_eheight (tile);
 
309
      tile_data.use_shm     = (shm_ID == -1) ? FALSE : TRUE;
 
310
 
 
311
      if (tile_data.use_shm)
 
312
        memcpy (plug_in_shm_get_addr (plug_in->gimp),
 
313
                tile_data_pointer (tile, 0, 0),
 
314
                tile_size (tile));
 
315
      else
 
316
        tile_data.data = tile_data_pointer (tile, 0, 0);
 
317
 
 
318
      if (! gp_tile_data_write (plug_in->my_write, &tile_data, plug_in))
 
319
        {
 
320
          g_message ("plug_in_handle_tile_req: ERROR");
 
321
          plug_in_close (plug_in, TRUE);
 
322
          return;
 
323
        }
 
324
 
 
325
      tile_release (tile, FALSE);
 
326
 
 
327
      if (! wire_read_msg (plug_in->my_read, &msg, plug_in))
 
328
        {
 
329
          g_message ("plug_in_handle_tile_req: ERROR");
 
330
          plug_in_close (plug_in, TRUE);
 
331
          return;
 
332
        }
 
333
 
 
334
      if (msg.type != GP_TILE_ACK)
 
335
        {
 
336
          g_warning ("expected tile ack and received: %d", msg.type);
 
337
          plug_in_close (plug_in, TRUE);
 
338
          return;
 
339
        }
 
340
 
 
341
      wire_destroy (&msg);
 
342
    }
 
343
}
 
344
 
 
345
static void
 
346
plug_in_handle_proc_run (PlugIn    *plug_in,
 
347
                         GPProcRun *proc_run)
 
348
{
 
349
  PlugInProcFrame *proc_frame;
 
350
  const gchar     *proc_name = NULL;
 
351
  ProcRecord      *proc_rec;
 
352
  Argument        *args;
 
353
  Argument        *return_vals;
 
354
 
 
355
  proc_frame = plug_in_get_proc_frame (plug_in);
 
356
 
 
357
  proc_rec = procedural_db_lookup (plug_in->gimp, proc_run->name);
 
358
 
 
359
  if (! proc_rec)
 
360
    {
 
361
      proc_name = g_hash_table_lookup (plug_in->gimp->procedural_compat_ht,
 
362
                                       proc_run->name);
 
363
 
 
364
      if (proc_name)
 
365
        {
 
366
          proc_rec = procedural_db_lookup (plug_in->gimp, proc_name);
 
367
 
 
368
          if (plug_in->gimp->pdb_compat_mode == GIMP_PDB_COMPAT_WARN)
 
369
            {
 
370
              g_message ("WARNING: Plug-In \"%s\"\n(%s)\n"
 
371
                         "called deprecated procedure '%s'.\n"
 
372
                         "It should call '%s' instead!",
 
373
                         gimp_filename_to_utf8 (plug_in->name),
 
374
                         gimp_filename_to_utf8 (plug_in->prog),
 
375
                         proc_run->name, proc_name);
 
376
            }
 
377
        }
 
378
    }
 
379
  else if (proc_rec->deprecated)
 
380
    {
 
381
      if (plug_in->gimp->pdb_compat_mode == GIMP_PDB_COMPAT_WARN)
 
382
        {
 
383
          if (! strcmp (proc_rec->deprecated, "NONE"))
 
384
            {
 
385
              g_message ("WARNING: Plug-In \"%s\"\n(%s)\n"
 
386
                         "called deprecated procedure '%s'.",
 
387
                         gimp_filename_to_utf8 (plug_in->name),
 
388
                         gimp_filename_to_utf8 (plug_in->prog),
 
389
                         proc_run->name);
 
390
            }
 
391
          else
 
392
            {
 
393
              g_message ("WARNING: Plug-In \"%s\"\n(%s)\n"
 
394
                         "called deprecated procedure '%s'.\n"
 
395
                         "It should call '%s' instead!",
 
396
                         gimp_filename_to_utf8 (plug_in->name),
 
397
                         gimp_filename_to_utf8 (plug_in->prog),
 
398
                         proc_run->name, proc_rec->deprecated);
 
399
            }
 
400
        }
 
401
      else if (plug_in->gimp->pdb_compat_mode == GIMP_PDB_COMPAT_OFF)
 
402
        {
 
403
          proc_rec = NULL;
 
404
        }
 
405
    }
 
406
 
 
407
  if (! proc_name)
 
408
    proc_name = proc_run->name;
 
409
 
 
410
  args = plug_in_params_to_args (proc_run->params, proc_run->nparams, FALSE);
 
411
 
 
412
  plug_in_push (plug_in->gimp, plug_in);
 
413
 
 
414
  /*  Execute the procedure even if procedural_db_lookup() returned NULL,
 
415
   *  procedural_db_execute() will return appropriate error return_vals.
 
416
   */
 
417
  return_vals = procedural_db_execute (plug_in->gimp,
 
418
                                       proc_frame->context_stack ?
 
419
                                       proc_frame->context_stack->data :
 
420
                                       proc_frame->main_context,
 
421
                                       proc_frame->progress,
 
422
                                       proc_name, args);
 
423
 
 
424
  plug_in_pop (plug_in->gimp);
 
425
 
 
426
  if (return_vals)
 
427
    {
 
428
      GPProcReturn proc_return;
 
429
 
 
430
      /*  Return the name we got called with, *not* proc_name, since
 
431
       *  proc_name may have been remapped by gimp->procedural_compat_ht
 
432
       */
 
433
      proc_return.name = proc_run->name;
 
434
 
 
435
      if (proc_rec)
 
436
        {
 
437
          proc_return.nparams = proc_rec->num_values + 1;
 
438
          proc_return.params  = plug_in_args_to_params (return_vals,
 
439
                                                        proc_return.nparams,
 
440
                                                        FALSE);
 
441
        }
 
442
      else
 
443
        {
 
444
          proc_return.nparams = 1;
 
445
          proc_return.params  = plug_in_args_to_params (return_vals, 1, FALSE);
 
446
        }
 
447
 
 
448
      if (! gp_proc_return_write (plug_in->my_write, &proc_return, plug_in))
 
449
        {
 
450
          g_warning ("plug_in_handle_proc_run: ERROR");
 
451
          plug_in_close (plug_in, TRUE);
 
452
          return;
 
453
        }
 
454
 
 
455
      plug_in_args_destroy (args, proc_run->nparams, FALSE);
 
456
 
 
457
      if (proc_rec)
 
458
        plug_in_args_destroy (return_vals, proc_rec->num_values + 1, TRUE);
 
459
      else
 
460
        plug_in_args_destroy (return_vals, 1, TRUE);
 
461
 
 
462
      plug_in_params_destroy (proc_return.params, proc_return.nparams, FALSE);
 
463
    }
 
464
  else
 
465
    {
 
466
      PlugInBlocked *blocked;
 
467
 
 
468
      g_warning ("%s: EEEEEEEEEK! \n"
 
469
                 "You managed to trigger a code path that \n"
 
470
                 "should be dead. Please report this to bugs.gimp.org.",
 
471
                 G_STRFUNC);
 
472
 
 
473
      blocked = g_new0 (PlugInBlocked, 1);
 
474
 
 
475
      blocked->plug_in   = plug_in;
 
476
      blocked->proc_name = g_strdup (proc_run->name);
 
477
 
 
478
      blocked_plug_ins = g_slist_prepend (blocked_plug_ins, blocked);
 
479
    }
 
480
}
 
481
 
 
482
static void
 
483
plug_in_handle_proc_return_priv (PlugIn       *plug_in,
 
484
                                 GPProcReturn *proc_return,
 
485
                                 gboolean      temp_proc)
 
486
{
 
487
  PlugInProcFrame *proc_frame;
 
488
 
 
489
  if (temp_proc)
 
490
    proc_frame = plug_in->temp_proc_frames->data;
 
491
  else
 
492
    proc_frame = &plug_in->main_proc_frame;
 
493
 
 
494
  if (proc_frame->main_loop)
 
495
    {
 
496
      proc_frame->return_vals = plug_in_params_to_args (proc_return->params,
 
497
                                                        proc_return->nparams,
 
498
                                                        TRUE);
 
499
      proc_frame->n_return_vals = proc_return->nparams;
 
500
    }
 
501
  else
 
502
    {
 
503
      GSList *list;
 
504
 
 
505
      for (list = blocked_plug_ins; list; list = g_slist_next (list))
 
506
        {
 
507
          PlugInBlocked *blocked;
 
508
 
 
509
          blocked = (PlugInBlocked *) list->data;
 
510
 
 
511
          if (blocked->proc_name && proc_return->name &&
 
512
              strcmp (blocked->proc_name, proc_return->name) == 0)
 
513
            {
 
514
              if (! gp_proc_return_write (blocked->plug_in->my_write,
 
515
                                          proc_return,
 
516
                                          blocked->plug_in))
 
517
                {
 
518
                  g_message ("plug_in_handle_proc_run: ERROR");
 
519
                  plug_in_close (blocked->plug_in, TRUE);
 
520
                  return;
 
521
                }
 
522
 
 
523
              blocked_plug_ins = g_slist_remove (blocked_plug_ins, blocked);
 
524
              g_free (blocked->proc_name);
 
525
              g_free (blocked);
 
526
              break;
 
527
            }
 
528
        }
 
529
    }
 
530
}
 
531
 
 
532
static void
 
533
plug_in_handle_proc_return (PlugIn       *plug_in,
 
534
                            GPProcReturn *proc_return)
 
535
{
 
536
  plug_in_handle_proc_return_priv (plug_in, proc_return, FALSE);
 
537
 
 
538
  if (plug_in->main_proc_frame.main_loop)
 
539
    g_main_loop_quit (plug_in->main_proc_frame.main_loop);
 
540
 
 
541
  plug_in_close (plug_in, FALSE);
 
542
}
 
543
 
 
544
static void
 
545
plug_in_handle_temp_proc_return (PlugIn       *plug_in,
 
546
                                 GPProcReturn *proc_return)
 
547
{
 
548
  if (plug_in->temp_proc_frames)
 
549
    {
 
550
      plug_in_handle_proc_return_priv (plug_in, proc_return, TRUE);
 
551
 
 
552
      plug_in_main_loop_quit (plug_in);
 
553
      plug_in_proc_frame_pop (plug_in);
 
554
    }
 
555
  else
 
556
    {
 
557
      g_message ("Plug-In \"%s\"\n(%s)\n\n"
 
558
                 "sent a TEMP_PROC_RETURN message while not running "
 
559
                 "a temp proc (should not happen)",
 
560
                 gimp_filename_to_utf8 (plug_in->name),
 
561
                 gimp_filename_to_utf8 (plug_in->prog));
 
562
      plug_in_close (plug_in, TRUE);
 
563
    }
 
564
}
 
565
 
 
566
static void
 
567
plug_in_handle_proc_install (PlugIn        *plug_in,
 
568
                             GPProcInstall *proc_install)
 
569
{
 
570
  PlugInDef     *plug_in_def = NULL;
 
571
  PlugInProcDef *proc_def    = NULL;
 
572
  ProcRecord    *proc        = NULL;
 
573
  GSList        *tmp         = NULL;
 
574
  gchar         *prog        = NULL;
 
575
  gboolean       valid_utf8  = FALSE;
 
576
  gint           i;
 
577
 
 
578
  /*  Argument checking
 
579
   *   --only sanity check arguments when the procedure requests a menu path
 
580
   */
 
581
 
 
582
  if (proc_install->menu_path && proc_install->menu_path[0] == '<')
 
583
    {
 
584
      GError *error = NULL;
 
585
 
 
586
      if (! plug_in_param_defs_check (plug_in->name,
 
587
                                      plug_in->prog,
 
588
                                      proc_install->name,
 
589
                                      proc_install->menu_path,
 
590
                                      proc_install->params,
 
591
                                      proc_install->nparams,
 
592
                                      proc_install->return_vals,
 
593
                                      proc_install->nreturn_vals,
 
594
                                      &error))
 
595
        {
 
596
          g_message (error->message);
 
597
          g_clear_error (&error);
 
598
 
 
599
          return;
 
600
        }
 
601
    }
 
602
 
 
603
  /*  Sanity check for array arguments  */
 
604
 
 
605
  for (i = 1; i < proc_install->nparams; i++)
 
606
    {
 
607
      if ((proc_install->params[i].type == GIMP_PDB_INT32ARRAY ||
 
608
           proc_install->params[i].type == GIMP_PDB_INT8ARRAY  ||
 
609
           proc_install->params[i].type == GIMP_PDB_FLOATARRAY ||
 
610
           proc_install->params[i].type == GIMP_PDB_STRINGARRAY)
 
611
          &&
 
612
          proc_install->params[i-1].type != GIMP_PDB_INT32)
 
613
        {
 
614
          g_message ("Plug-In \"%s\"\n(%s)\n\n"
 
615
                     "attempted to install procedure \"%s\" "
 
616
                     "which fails to comply with the array parameter "
 
617
                     "passing standard.  Argument %d is noncompliant.",
 
618
                     gimp_filename_to_utf8 (plug_in->name),
 
619
                     gimp_filename_to_utf8 (plug_in->prog),
 
620
                     proc_install->name, i);
 
621
          return;
 
622
        }
 
623
    }
 
624
 
 
625
  /*  Sanity check strings for UTF-8 validity  */
 
626
 
 
627
  if ((proc_install->menu_path == NULL ||
 
628
       g_utf8_validate (proc_install->menu_path, -1, NULL)) &&
 
629
      (g_utf8_validate (proc_install->name, -1, NULL))      &&
 
630
      (proc_install->blurb == NULL ||
 
631
       g_utf8_validate (proc_install->blurb, -1, NULL))     &&
 
632
      (proc_install->help == NULL ||
 
633
       g_utf8_validate (proc_install->help, -1, NULL))      &&
 
634
      (proc_install->author == NULL ||
 
635
       g_utf8_validate (proc_install->author, -1, NULL))    &&
 
636
      (proc_install->copyright == NULL ||
 
637
       g_utf8_validate (proc_install->copyright, -1, NULL)) &&
 
638
      (proc_install->date == NULL ||
 
639
       g_utf8_validate (proc_install->date, -1, NULL)))
 
640
    {
 
641
      valid_utf8 = TRUE;
 
642
 
 
643
      for (i = 0; i < proc_install->nparams && valid_utf8; i++)
 
644
        {
 
645
          if (! (g_utf8_validate (proc_install->params[i].name, -1, NULL) &&
 
646
                 (proc_install->params[i].description == NULL ||
 
647
                  g_utf8_validate (proc_install->params[i].description, -1, NULL))))
 
648
            valid_utf8 = FALSE;
 
649
        }
 
650
 
 
651
      for (i = 0; i < proc_install->nreturn_vals && valid_utf8; i++)
 
652
        {
 
653
          if (! (g_utf8_validate (proc_install->return_vals[i].name, -1, NULL) &&
 
654
                 (proc_install->return_vals[i].description == NULL ||
 
655
                  g_utf8_validate (proc_install->return_vals[i].description, -1, NULL))))
 
656
            valid_utf8 = FALSE;
 
657
        }
 
658
    }
 
659
 
 
660
  if (! valid_utf8)
 
661
    {
 
662
      g_message ("Plug-In \"%s\"\n(%s)\n\n"
 
663
                 "attempted to install a procedure with invalid UTF-8 strings.",
 
664
                 gimp_filename_to_utf8 (plug_in->name),
 
665
                 gimp_filename_to_utf8 (plug_in->prog));
 
666
      return;
 
667
    }
 
668
 
 
669
  /*  Initialization  */
 
670
 
 
671
  switch (proc_install->type)
 
672
    {
 
673
    case GIMP_PLUGIN:
 
674
    case GIMP_EXTENSION:
 
675
      plug_in_def = plug_in->plug_in_def;
 
676
      prog        = plug_in_def->prog;
 
677
 
 
678
      tmp = plug_in_def->proc_defs;
 
679
      break;
 
680
 
 
681
    case GIMP_TEMPORARY:
 
682
      plug_in_def = NULL;
 
683
      prog        = "none";
 
684
 
 
685
      tmp = plug_in->temp_proc_defs;
 
686
      break;
 
687
    }
 
688
 
 
689
  while (tmp)
 
690
    {
 
691
      proc_def = tmp->data;
 
692
      tmp = tmp->next;
 
693
 
 
694
      if (strcmp (proc_def->db_info.name, proc_install->name) == 0)
 
695
        {
 
696
          switch (proc_install->type)
 
697
            {
 
698
            case GIMP_PLUGIN:
 
699
            case GIMP_EXTENSION:
 
700
              plug_in_def->proc_defs = g_slist_remove (plug_in_def->proc_defs,
 
701
                                                       proc_def);
 
702
              plug_in_proc_def_free (proc_def);
 
703
              break;
 
704
 
 
705
            case GIMP_TEMPORARY:
 
706
              plug_in->temp_proc_defs = g_slist_remove (plug_in->temp_proc_defs,
 
707
                                                        proc_def);
 
708
              plug_ins_temp_proc_def_remove (plug_in->gimp, proc_def);
 
709
              break;
 
710
            }
 
711
 
 
712
          break;
 
713
        }
 
714
    }
 
715
 
 
716
  proc_def = plug_in_proc_def_new ();
 
717
 
 
718
  if (proc_install->menu_path)
 
719
    {
 
720
      if (proc_install->menu_path[0] == '<')
 
721
        proc_def->menu_paths =
 
722
          g_list_append (proc_def->menu_paths,
 
723
                         g_strdup (proc_install->menu_path));
 
724
      else
 
725
        proc_def->menu_label = g_strdup (proc_install->menu_path);
 
726
    }
 
727
 
 
728
  proc_def->prog            = g_strdup (prog);
 
729
  proc_def->extensions      = NULL;
 
730
  proc_def->prefixes        = NULL;
 
731
  proc_def->magics          = NULL;
 
732
  proc_def->image_types     = g_strdup (proc_install->image_types);
 
733
  proc_def->image_types_val = plug_ins_image_types_parse (proc_def->image_types);
 
734
  /* Install temp one use todays time */
 
735
  proc_def->mtime           = time (NULL);
 
736
 
 
737
  /* Remember if this proc was installed while initing a plug-in */
 
738
  proc_def->installed_during_init = plug_in->init;
 
739
 
 
740
  /*  The procedural database procedure  */
 
741
 
 
742
  proc = &proc_def->db_info;
 
743
 
 
744
  proc->name      = g_strdup (proc_install->name);
 
745
  proc->blurb     = g_strdup (proc_install->blurb);
 
746
  proc->help      = g_strdup (proc_install->help);
 
747
  proc->author    = g_strdup (proc_install->author);
 
748
  proc->copyright = g_strdup (proc_install->copyright);
 
749
  proc->date      = g_strdup (proc_install->date);
 
750
  proc->proc_type = proc_install->type;
 
751
 
 
752
  proc->num_args   = proc_install->nparams;
 
753
  proc->num_values = proc_install->nreturn_vals;
 
754
 
 
755
  proc->args   = g_new0 (ProcArg, proc->num_args);
 
756
  proc->values = g_new0 (ProcArg, proc->num_values);
 
757
 
 
758
  for (i = 0; i < proc->num_args; i++)
 
759
    {
 
760
      proc->args[i].arg_type    = proc_install->params[i].type;
 
761
      proc->args[i].name        = g_strdup (proc_install->params[i].name);
 
762
      proc->args[i].description = g_strdup (proc_install->params[i].description);
 
763
    }
 
764
 
 
765
  for (i = 0; i < proc->num_values; i++)
 
766
    {
 
767
      proc->values[i].arg_type    = proc_install->return_vals[i].type;
 
768
      proc->values[i].name        = g_strdup (proc_install->return_vals[i].name);
 
769
      proc->values[i].description = g_strdup (proc_install->return_vals[i].description);
 
770
    }
 
771
 
 
772
  switch (proc_install->type)
 
773
    {
 
774
    case GIMP_PLUGIN:
 
775
    case GIMP_EXTENSION:
 
776
      plug_in_def->proc_defs = g_slist_prepend (plug_in_def->proc_defs,
 
777
                                                proc_def);
 
778
      break;
 
779
 
 
780
    case GIMP_TEMPORARY:
 
781
      plug_in->temp_proc_defs = g_slist_prepend (plug_in->temp_proc_defs,
 
782
                                                 proc_def);
 
783
 
 
784
      proc->exec_method.temporary.plug_in = plug_in;
 
785
 
 
786
      plug_ins_temp_proc_def_add (plug_in->gimp, proc_def);
 
787
      break;
 
788
    }
 
789
}
 
790
 
 
791
static void
 
792
plug_in_handle_proc_uninstall (PlugIn          *plug_in,
 
793
                               GPProcUninstall *proc_uninstall)
 
794
{
 
795
  GSList *tmp;
 
796
 
 
797
  for (tmp = plug_in->temp_proc_defs; tmp; tmp = g_slist_next (tmp))
 
798
    {
 
799
      PlugInProcDef *proc_def;
 
800
 
 
801
      proc_def = tmp->data;
 
802
 
 
803
      if (! strcmp (proc_def->db_info.name, proc_uninstall->name))
 
804
        {
 
805
          plug_in->temp_proc_defs = g_slist_remove (plug_in->temp_proc_defs,
 
806
                                                    proc_def);
 
807
          plug_ins_temp_proc_def_remove (plug_in->gimp, proc_def);
 
808
          break;
 
809
        }
 
810
    }
 
811
}
 
812
 
 
813
static void
 
814
plug_in_handle_extension_ack (PlugIn *plug_in)
 
815
{
 
816
  if (plug_in->ext_main_loop)
 
817
    {
 
818
      g_main_loop_quit (plug_in->ext_main_loop);
 
819
    }
 
820
  else
 
821
    {
 
822
      g_message ("Plug-In \"%s\"\n(%s)\n\n"
 
823
                 "sent an EXTENSION_ACK message while not being started "
 
824
                 "as extension (should not happen)",
 
825
                 gimp_filename_to_utf8 (plug_in->name),
 
826
                 gimp_filename_to_utf8 (plug_in->prog));
 
827
      plug_in_close (plug_in, TRUE);
 
828
    }
 
829
}
 
830
 
 
831
static void
 
832
plug_in_handle_has_init (PlugIn *plug_in)
 
833
{
 
834
  if (plug_in->query)
 
835
    {
 
836
      plug_in_def_set_has_init (plug_in->plug_in_def, TRUE);
 
837
    }
 
838
  else
 
839
    {
 
840
      g_message ("Plug-In \"%s\"\n(%s)\n\n"
 
841
                 "sent an HAS_INIT message while not in query() "
 
842
                 "(should not happen)",
 
843
                 gimp_filename_to_utf8 (plug_in->name),
 
844
                 gimp_filename_to_utf8 (plug_in->prog));
 
845
      plug_in_close (plug_in, TRUE);
 
846
    }
 
847
}