plug-in-message.c 24.8 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1
2
3
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
4
5
 * plug-in-message.c
 *
Elliot Lee's avatar
Elliot Lee committed
6
7
8
9
10
11
12
13
14
15
16
17
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
19
 */
20

Elliot Lee's avatar
Elliot Lee committed
21
#include "config.h"
Tor Lillqvist's avatar
Tor Lillqvist committed
22

Elliot Lee's avatar
Elliot Lee committed
23
#include <string.h>
Tor Lillqvist's avatar
Tor Lillqvist committed
24

25
#include <glib-object.h>
26

27
28
29
#include "libgimpbase/gimpbase.h"
#include "libgimpbase/gimpprotocol.h"
#include "libgimpbase/gimpwire.h"
30

Michael Natterer's avatar
Michael Natterer committed
31
#include "plug-in-types.h"
32

Michael Natterer's avatar
Michael Natterer committed
33
34
35
#include "base/tile.h"
#include "base/tile-manager.h"

36
#include "core/gimp.h"
37
#include "core/gimpdrawable.h"
38

Michael Natterer's avatar
Michael Natterer committed
39
#include "plug-in.h"
40
41
42
#include "plug-ins.h"
#include "plug-in-def.h"
#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;
Elliot Lee's avatar
Elliot Lee committed
48
49
50
51

struct _PlugInBlocked
{
  PlugIn *plug_in;
52
  gchar  *proc_name;
Elliot Lee's avatar
Elliot Lee committed
53
54
55
};


56
57
58
59
60
61
62
63
/*  local function prototypes  */

static void plug_in_handle_quit             (PlugIn          *plug_in);
static void plug_in_handle_tile_req         (PlugIn          *plug_in,
                                             GPTileReq       *tile_req);
static void plug_in_handle_proc_run         (PlugIn          *plug_in,
                                             GPProcRun       *proc_run);
static void plug_in_handle_proc_return_priv (PlugIn          *plug_in,
Michael Natterer's avatar
Michael Natterer committed
64
65
                                             GPProcReturn    *proc_return,
                                             gboolean         temp_proc);
66
67
68
69
70
71
72
73
74
75
static void plug_in_handle_proc_return      (PlugIn          *plug_in,
                                             GPProcReturn    *proc_return);
static void plug_in_handle_temp_proc_return (PlugIn          *plug_in,
                                             GPProcReturn    *proc_return);
static void plug_in_handle_proc_install     (PlugIn          *plug_in,
                                             GPProcInstall   *proc_install);
static void plug_in_handle_proc_uninstall   (PlugIn          *plug_in,
                                             GPProcUninstall *proc_uninstall);
static void plug_in_handle_extension_ack    (PlugIn          *plug_in);
static void plug_in_handle_has_init         (PlugIn          *plug_in);
Tor Lillqvist's avatar
Tor Lillqvist committed
76

77

78
/*  private variables  */
79

80
static GSList *blocked_plug_ins = NULL;
81

82

83
/*  public functions  */
Elliot Lee's avatar
Elliot Lee committed
84
85

void
86
87
plug_in_handle_message (PlugIn      *plug_in,
                        WireMessage *msg)
Elliot Lee's avatar
Elliot Lee committed
88
89
90
91
{
  switch (msg->type)
    {
    case GP_QUIT:
92
      plug_in_handle_quit (plug_in);
Elliot Lee's avatar
Elliot Lee committed
93
      break;
Michael Natterer's avatar
Michael Natterer committed
94

Elliot Lee's avatar
Elliot Lee committed
95
    case GP_CONFIG:
Michael Natterer's avatar
Michael Natterer committed
96
97
      g_message ("Plug-In \"%s\"\n(%s)\n\n"
		 "sent a CONFIG message (should not happen)",
98
99
                 gimp_filename_to_utf8 (plug_in->name),
		 gimp_filename_to_utf8 (plug_in->prog));
100
      plug_in_close (plug_in, TRUE);
Elliot Lee's avatar
Elliot Lee committed
101
      break;
Michael Natterer's avatar
Michael Natterer committed
102

Elliot Lee's avatar
Elliot Lee committed
103
    case GP_TILE_REQ:
104
      plug_in_handle_tile_req (plug_in, msg->data);
Elliot Lee's avatar
Elliot Lee committed
105
      break;
Michael Natterer's avatar
Michael Natterer committed
106

Elliot Lee's avatar
Elliot Lee committed
107
    case GP_TILE_ACK:
Michael Natterer's avatar
Michael Natterer committed
108
109
      g_message ("Plug-In \"%s\"\n(%s)\n\n"
		 "sent a TILE_ACK message (should not happen)",
110
111
                 gimp_filename_to_utf8 (plug_in->name),
		 gimp_filename_to_utf8 (plug_in->prog));
112
      plug_in_close (plug_in, TRUE);
Elliot Lee's avatar
Elliot Lee committed
113
      break;
Michael Natterer's avatar
Michael Natterer committed
114

Elliot Lee's avatar
Elliot Lee committed
115
    case GP_TILE_DATA:
Michael Natterer's avatar
Michael Natterer committed
116
117
      g_message ("Plug-In \"%s\"\n(%s)\n\n"
		 "sent a TILE_DATA message (should not happen)",
118
119
                 gimp_filename_to_utf8 (plug_in->name),
		 gimp_filename_to_utf8 (plug_in->prog));
120
      plug_in_close (plug_in, TRUE);
Elliot Lee's avatar
Elliot Lee committed
121
      break;
Michael Natterer's avatar
Michael Natterer committed
122

Elliot Lee's avatar
Elliot Lee committed
123
    case GP_PROC_RUN:
124
      plug_in_handle_proc_run (plug_in, msg->data);
Elliot Lee's avatar
Elliot Lee committed
125
      break;
Michael Natterer's avatar
Michael Natterer committed
126

Elliot Lee's avatar
Elliot Lee committed
127
    case GP_PROC_RETURN:
128
      plug_in_handle_proc_return (plug_in, msg->data);
Elliot Lee's avatar
Elliot Lee committed
129
      break;
Michael Natterer's avatar
Michael Natterer committed
130

Elliot Lee's avatar
Elliot Lee committed
131
    case GP_TEMP_PROC_RUN:
Michael Natterer's avatar
Michael Natterer committed
132
133
      g_message ("Plug-In \"%s\"\n(%s)\n\n"
		 "sent a TEMP_PROC_RUN message (should not happen)",
134
135
                 gimp_filename_to_utf8 (plug_in->name),
		 gimp_filename_to_utf8 (plug_in->prog));
136
      plug_in_close (plug_in, TRUE);
Elliot Lee's avatar
Elliot Lee committed
137
      break;
Michael Natterer's avatar
Michael Natterer committed
138

Elliot Lee's avatar
Elliot Lee committed
139
    case GP_TEMP_PROC_RETURN:
140
      plug_in_handle_temp_proc_return (plug_in, msg->data);
Elliot Lee's avatar
Elliot Lee committed
141
      break;
Michael Natterer's avatar
Michael Natterer committed
142

Elliot Lee's avatar
Elliot Lee committed
143
    case GP_PROC_INSTALL:
144
      plug_in_handle_proc_install (plug_in, msg->data);
Elliot Lee's avatar
Elliot Lee committed
145
      break;
Michael Natterer's avatar
Michael Natterer committed
146

Elliot Lee's avatar
Elliot Lee committed
147
    case GP_PROC_UNINSTALL:
148
      plug_in_handle_proc_uninstall (plug_in, msg->data);
Elliot Lee's avatar
Elliot Lee committed
149
      break;
Michael Natterer's avatar
Michael Natterer committed
150

Elliot Lee's avatar
Elliot Lee committed
151
    case GP_EXTENSION_ACK:
Michael Natterer's avatar
Michael Natterer committed
152
      plug_in_handle_extension_ack (plug_in);
Elliot Lee's avatar
Elliot Lee committed
153
      break;
Michael Natterer's avatar
Michael Natterer committed
154

155
    case GP_HAS_INIT:
156
      plug_in_handle_has_init (plug_in);
Michael Natterer's avatar
Michael Natterer committed
157
      break;
Elliot Lee's avatar
Elliot Lee committed
158
159
160
    }
}

161
162
163

/*  private functions  */

Elliot Lee's avatar
Elliot Lee committed
164
static void
165
plug_in_handle_quit (PlugIn *plug_in)
Elliot Lee's avatar
Elliot Lee committed
166
{
167
  plug_in_close (plug_in, FALSE);
Elliot Lee's avatar
Elliot Lee committed
168
169
170
}

static void
171
172
plug_in_handle_tile_req (PlugIn    *plug_in,
                         GPTileReq *tile_req)
Elliot Lee's avatar
Elliot Lee committed
173
{
Michael Natterer's avatar
Michael Natterer committed
174
175
176
177
178
179
180
  GPTileData    tile_data;
  GPTileData   *tile_info;
  WireMessage   msg;
  GimpDrawable *drawable;
  TileManager  *tm;
  Tile         *tile;
  gint          shm_ID;
181
182

  shm_ID = plug_in_shm_get_ID (plug_in->gimp);
Elliot Lee's avatar
Elliot Lee committed
183
184
185

  if (tile_req->drawable_ID == -1)
    {
Michael Natterer's avatar
Michael Natterer committed
186
187
      /*  this branch communicates with libgimp/gimptile.c:gimp_tile_put()  */

Elliot Lee's avatar
Elliot Lee committed
188
      tile_data.drawable_ID = -1;
189
190
191
192
193
194
195
      tile_data.tile_num    = 0;
      tile_data.shadow      = 0;
      tile_data.bpp         = 0;
      tile_data.width       = 0;
      tile_data.height      = 0;
      tile_data.use_shm     = (shm_ID == -1) ? FALSE : TRUE;
      tile_data.data        = NULL;
Elliot Lee's avatar
Elliot Lee committed
196

197
      if (! gp_tile_data_write (plug_in->my_write, &tile_data, plug_in))
Elliot Lee's avatar
Elliot Lee committed
198
	{
199
	  g_warning ("plug_in_handle_tile_req: ERROR");
200
	  plug_in_close (plug_in, TRUE);
Elliot Lee's avatar
Elliot Lee committed
201
202
203
	  return;
	}

204
      if (! wire_read_msg (plug_in->my_read, &msg, plug_in))
Elliot Lee's avatar
Elliot Lee committed
205
	{
206
	  g_warning ("plug_in_handle_tile_req: ERROR");
207
	  plug_in_close (plug_in, TRUE);
Elliot Lee's avatar
Elliot Lee committed
208
209
210
211
212
	  return;
	}

      if (msg.type != GP_TILE_DATA)
	{
213
	  g_warning ("expected tile data and received: %d", msg.type);
214
	  plug_in_close (plug_in, TRUE);
Elliot Lee's avatar
Elliot Lee committed
215
216
217
218
219
	  return;
	}

      tile_info = msg.data;

Michael Natterer's avatar
Michael Natterer committed
220
221
      drawable = (GimpDrawable *) gimp_item_get_by_ID (plug_in->gimp,
                                                       tile_info->drawable_ID);
Elliot Lee's avatar
Elliot Lee committed
222

Michael Natterer's avatar
Michael Natterer committed
223
      if (! drawable)
Elliot Lee's avatar
Elliot Lee committed
224
	{
Michael Natterer's avatar
Michael Natterer committed
225
226
          g_message ("Plug-In \"%s\"\n(%s)\n\n"
                     "requested invalid drawable (killing)",
227
228
                     gimp_filename_to_utf8 (plug_in->name),
		     gimp_filename_to_utf8 (plug_in->prog));
229
	  plug_in_close (plug_in, TRUE);
Elliot Lee's avatar
Elliot Lee committed
230
231
232
	  return;
	}

Michael Natterer's avatar
Michael Natterer committed
233
234
235
236
237
      if (tile_info->shadow)
	tm = gimp_drawable_shadow (drawable);
      else
	tm = gimp_drawable_data (drawable);

238
      tile = tile_manager_get (tm, tile_info->tile_num, TRUE, TRUE);
Michael Natterer's avatar
Michael Natterer committed
239
240

      if (! tile)
Elliot Lee's avatar
Elliot Lee committed
241
	{
Michael Natterer's avatar
Michael Natterer committed
242
243
          g_message ("Plug-In \"%s\"\n(%s)\n\n"
                     "requested invalid tile (killing)",
244
245
                     gimp_filename_to_utf8 (plug_in->name),
		     gimp_filename_to_utf8 (plug_in->prog));
246
	  plug_in_close (plug_in, TRUE);
Elliot Lee's avatar
Elliot Lee committed
247
248
249
250
	  return;
	}

      if (tile_data.use_shm)
251
252
253
	memcpy (tile_data_pointer (tile, 0, 0),
                plug_in_shm_get_addr (plug_in->gimp),
                tile_size (tile));
Elliot Lee's avatar
Elliot Lee committed
254
      else
255
256
257
	memcpy (tile_data_pointer (tile, 0, 0),
                tile_info->data,
                tile_size (tile));
Elliot Lee's avatar
Elliot Lee committed
258

259
      tile_release (tile, TRUE);
Elliot Lee's avatar
Elliot Lee committed
260
261

      wire_destroy (&msg);
262
      if (! gp_tile_ack_write (plug_in->my_write, plug_in))
Elliot Lee's avatar
Elliot Lee committed
263
	{
264
	  g_warning ("plug_in_handle_tile_req: ERROR");
265
	  plug_in_close (plug_in, TRUE);
Elliot Lee's avatar
Elliot Lee committed
266
267
268
269
270
	  return;
	}
    }
  else
    {
Michael Natterer's avatar
Michael Natterer committed
271
272
      /*  this branch communicates with libgimp/gimptile.c:gimp_tile_get()  */

Michael Natterer's avatar
Michael Natterer committed
273
274
      drawable = (GimpDrawable *) gimp_item_get_by_ID (plug_in->gimp,
                                                       tile_req->drawable_ID);
Elliot Lee's avatar
Elliot Lee committed
275

Michael Natterer's avatar
Michael Natterer committed
276
      if (! drawable)
Elliot Lee's avatar
Elliot Lee committed
277
	{
Michael Natterer's avatar
Michael Natterer committed
278
279
          g_message ("Plug-In \"%s\"\n(%s)\n\n"
                     "requested invalid drawable (killing)",
280
281
                     gimp_filename_to_utf8 (plug_in->name),
		     gimp_filename_to_utf8 (plug_in->prog));
282
	  plug_in_close (plug_in, TRUE);
Elliot Lee's avatar
Elliot Lee committed
283
284
285
	  return;
	}

Michael Natterer's avatar
Michael Natterer committed
286
287
288
289
290
      if (tile_req->shadow)
	tm = gimp_drawable_shadow (drawable);
      else
	tm = gimp_drawable_data (drawable);

291
      tile = tile_manager_get (tm, tile_req->tile_num, TRUE, FALSE);
Michael Natterer's avatar
Michael Natterer committed
292

293
      if (! tile)
Elliot Lee's avatar
Elliot Lee committed
294
	{
Michael Natterer's avatar
Michael Natterer committed
295
296
          g_message ("Plug-In \"%s\"\n(%s)\n\n"
                     "requested invalid tile (killing)",
297
298
                     gimp_filename_to_utf8 (plug_in->name),
		     gimp_filename_to_utf8 (plug_in->prog));
299
	  plug_in_close (plug_in, TRUE);
Elliot Lee's avatar
Elliot Lee committed
300
301
302
303
	  return;
	}

      tile_data.drawable_ID = tile_req->drawable_ID;
304
305
306
307
308
309
      tile_data.tile_num    = tile_req->tile_num;
      tile_data.shadow      = tile_req->shadow;
      tile_data.bpp         = tile_bpp (tile);
      tile_data.width       = tile_ewidth (tile);
      tile_data.height      = tile_eheight (tile);
      tile_data.use_shm     = (shm_ID == -1) ? FALSE : TRUE;
Elliot Lee's avatar
Elliot Lee committed
310
311

      if (tile_data.use_shm)
312
313
314
	memcpy (plug_in_shm_get_addr (plug_in->gimp),
                tile_data_pointer (tile, 0, 0),
                tile_size (tile));
Elliot Lee's avatar
Elliot Lee committed
315
      else
scott's avatar
scott committed
316
	tile_data.data = tile_data_pointer (tile, 0, 0);
Elliot Lee's avatar
Elliot Lee committed
317

318
      if (! gp_tile_data_write (plug_in->my_write, &tile_data, plug_in))
Elliot Lee's avatar
Elliot Lee committed
319
	{
320
	  g_message ("plug_in_handle_tile_req: ERROR");
321
	  plug_in_close (plug_in, TRUE);
Elliot Lee's avatar
Elliot Lee committed
322
323
324
	  return;
	}

325
      tile_release (tile, FALSE);
Elliot Lee's avatar
Elliot Lee committed
326

327
      if (! wire_read_msg (plug_in->my_read, &msg, plug_in))
Elliot Lee's avatar
Elliot Lee committed
328
	{
329
	  g_message ("plug_in_handle_tile_req: ERROR");
330
	  plug_in_close (plug_in, TRUE);
Elliot Lee's avatar
Elliot Lee committed
331
332
333
334
335
	  return;
	}

      if (msg.type != GP_TILE_ACK)
	{
336
	  g_warning ("expected tile ack and received: %d", msg.type);
337
	  plug_in_close (plug_in, TRUE);
Elliot Lee's avatar
Elliot Lee committed
338
339
340
341
342
343
344
345
	  return;
	}

      wire_destroy (&msg);
    }
}

static void
346
plug_in_handle_proc_run (PlugIn    *plug_in,
347
                         GPProcRun *proc_run)
Elliot Lee's avatar
Elliot Lee committed
348
{
349
350
351
352
353
354
  PlugInProcFrame *proc_frame;
  const gchar     *proc_name = NULL;
  ProcRecord      *proc_rec;
  Argument        *args;
  Argument        *return_vals;

355
  proc_frame = plug_in_get_proc_frame (plug_in);
Elliot Lee's avatar
Elliot Lee committed
356

357
  proc_rec = procedural_db_lookup (plug_in->gimp, proc_run->name);
Elliot Lee's avatar
Elliot Lee committed
358

359
360
361
362
363
364
  if (! proc_rec)
    {
      proc_name = g_hash_table_lookup (plug_in->gimp->procedural_compat_ht,
                                       proc_run->name);

      if (proc_name)
365
366
367
368
369
        {
          proc_rec = procedural_db_lookup (plug_in->gimp, proc_name);

          if (plug_in->gimp->pdb_compat_mode == GIMP_PDB_COMPAT_WARN)
            {
370
              g_message ("WARNING: Plug-In \"%s\"\n(%s)\n"
371
372
                         "called deprecated procedure '%s'.\n"
                         "It should call '%s' instead!",
373
374
                         gimp_filename_to_utf8 (plug_in->name),
			 gimp_filename_to_utf8 (plug_in->prog),
375
376
377
                         proc_run->name, proc_name);
            }
        }
378
    }
379
380
381
382
  else if (proc_rec->deprecated)
    {
      if (plug_in->gimp->pdb_compat_mode == GIMP_PDB_COMPAT_WARN)
        {
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
          if (! strcmp (proc_rec->deprecated, "NONE"))
            {
              g_message ("WARNING: Plug-In \"%s\"\n(%s)\n"
                         "called deprecated procedure '%s'.",
                         gimp_filename_to_utf8 (plug_in->name),
                         gimp_filename_to_utf8 (plug_in->prog),
                         proc_run->name);
            }
          else
            {
              g_message ("WARNING: Plug-In \"%s\"\n(%s)\n"
                         "called deprecated procedure '%s'.\n"
                         "It should call '%s' instead!",
                         gimp_filename_to_utf8 (plug_in->name),
                         gimp_filename_to_utf8 (plug_in->prog),
                         proc_run->name, proc_rec->deprecated);
            }
400
401
402
403
404
405
        }
      else if (plug_in->gimp->pdb_compat_mode == GIMP_PDB_COMPAT_OFF)
        {
          proc_rec = NULL;
        }
    }
406
407
408
409
410
411

  if (! proc_name)
    proc_name = proc_run->name;

  args = plug_in_params_to_args (proc_run->params, proc_run->nparams, FALSE);

412
  plug_in_push (plug_in->gimp, plug_in);
413
414
415
416

  /*  Execute the procedure even if procedural_db_lookup() returned NULL,
   *  procedural_db_execute() will return appropriate error return_vals.
   */
417
418
419
420
  return_vals = procedural_db_execute (plug_in->gimp,
                                       proc_frame->context_stack ?
                                       proc_frame->context_stack->data :
                                       proc_frame->main_context,
421
                                       proc_frame->progress,
422
                                       proc_name, args);
423

424
  plug_in_pop (plug_in->gimp);
Elliot Lee's avatar
Elliot Lee committed
425
426
427

  if (return_vals)
    {
428
429
      GPProcReturn proc_return;

Michael Natterer's avatar
Michael Natterer committed
430
431
432
      /*  Return the name we got called with, *not* proc_name, since
       *  proc_name may have been remapped by gimp->procedural_compat_ht
       */
Elliot Lee's avatar
Elliot Lee committed
433
434
435
436
437
      proc_return.name = proc_run->name;

      if (proc_rec)
	{
	  proc_return.nparams = proc_rec->num_values + 1;
438
439
440
	  proc_return.params  = plug_in_args_to_params (return_vals,
                                                        proc_return.nparams,
                                                        FALSE);
Elliot Lee's avatar
Elliot Lee committed
441
442
443
444
	}
      else
	{
	  proc_return.nparams = 1;
445
	  proc_return.params  = plug_in_args_to_params (return_vals, 1, FALSE);
Elliot Lee's avatar
Elliot Lee committed
446
447
	}

448
      if (! gp_proc_return_write (plug_in->my_write, &proc_return, plug_in))
Elliot Lee's avatar
Elliot Lee committed
449
	{
450
	  g_warning ("plug_in_handle_proc_run: ERROR");
451
	  plug_in_close (plug_in, TRUE);
Elliot Lee's avatar
Elliot Lee committed
452
453
454
455
	  return;
	}

      plug_in_args_destroy (args, proc_run->nparams, FALSE);
456
457
458
459
460
461

      if (proc_rec)
        plug_in_args_destroy (return_vals, proc_rec->num_values + 1, TRUE);
      else
        plug_in_args_destroy (return_vals, 1, TRUE);

Elliot Lee's avatar
Elliot Lee committed
462
463
464
465
      plug_in_params_destroy (proc_return.params, proc_return.nparams, FALSE);
    }
  else
    {
466
467
      PlugInBlocked *blocked;

468
469
470
471
472
      g_warning ("%s: EEEEEEEEEK! \n"
                 "You managed to trigger a code path that \n"
                 "should be dead. Please report this to bugs.gimp.org.",
                 G_STRFUNC);

473
474
      blocked = g_new0 (PlugInBlocked, 1);

475
      blocked->plug_in   = plug_in;
Elliot Lee's avatar
Elliot Lee committed
476
      blocked->proc_name = g_strdup (proc_run->name);
477

Elliot Lee's avatar
Elliot Lee committed
478
479
480
481
482
      blocked_plug_ins = g_slist_prepend (blocked_plug_ins, blocked);
    }
}

static void
483
plug_in_handle_proc_return_priv (PlugIn       *plug_in,
Michael Natterer's avatar
Michael Natterer committed
484
485
                                 GPProcReturn *proc_return,
                                 gboolean      temp_proc)
Elliot Lee's avatar
Elliot Lee committed
486
{
Michael Natterer's avatar
Michael Natterer committed
487
488
489
490
491
492
493
494
  PlugInProcFrame *proc_frame;

  if (temp_proc)
    proc_frame = plug_in->temp_proc_frames->data;
  else
    proc_frame = &plug_in->main_proc_frame;

  if (proc_frame->main_loop)
Elliot Lee's avatar
Elliot Lee committed
495
    {
Michael Natterer's avatar
Michael Natterer committed
496
497
498
499
      proc_frame->return_vals = plug_in_params_to_args (proc_return->params,
                                                        proc_return->nparams,
                                                        TRUE);
      proc_frame->n_return_vals = proc_return->nparams;
Elliot Lee's avatar
Elliot Lee committed
500
501
502
    }
  else
    {
503
504
505
      GSList *list;

      for (list = blocked_plug_ins; list; list = g_slist_next (list))
Elliot Lee's avatar
Elliot Lee committed
506
	{
507
508
509
          PlugInBlocked *blocked;

	  blocked = (PlugInBlocked *) list->data;
Elliot Lee's avatar
Elliot Lee committed
510

511
	  if (blocked->proc_name && proc_return->name &&
Sven Neumann's avatar
Sven Neumann committed
512
	      strcmp (blocked->proc_name, proc_return->name) == 0)
Elliot Lee's avatar
Elliot Lee committed
513
	    {
514
	      if (! gp_proc_return_write (blocked->plug_in->my_write,
515
516
                                          proc_return,
                                          blocked->plug_in))
Elliot Lee's avatar
Elliot Lee committed
517
		{
518
		  g_message ("plug_in_handle_proc_run: ERROR");
519
		  plug_in_close (blocked->plug_in, TRUE);
Elliot Lee's avatar
Elliot Lee committed
520
521
		  return;
		}
522

Elliot Lee's avatar
Elliot Lee committed
523
524
525
526
527
528
529
530
531
	      blocked_plug_ins = g_slist_remove (blocked_plug_ins, blocked);
	      g_free (blocked->proc_name);
	      g_free (blocked);
	      break;
	    }
	}
    }
}

532
533
534
535
static void
plug_in_handle_proc_return (PlugIn       *plug_in,
                            GPProcReturn *proc_return)
{
Michael Natterer's avatar
Michael Natterer committed
536
  plug_in_handle_proc_return_priv (plug_in, proc_return, FALSE);
537

Michael Natterer's avatar
Michael Natterer committed
538
539
  if (plug_in->main_proc_frame.main_loop)
    g_main_loop_quit (plug_in->main_proc_frame.main_loop);
540
541
542
543
544
545
546
547

  plug_in_close (plug_in, FALSE);
}

static void
plug_in_handle_temp_proc_return (PlugIn       *plug_in,
                                 GPProcReturn *proc_return)
{
Michael Natterer's avatar
Michael Natterer committed
548
  if (plug_in->temp_proc_frames)
549
    {
Michael Natterer's avatar
Michael Natterer committed
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
    {
Michael Natterer's avatar
Michael Natterer committed
557
558
559
      g_message ("Plug-In \"%s\"\n(%s)\n\n"
		 "sent a TEMP_PROC_RETURN message while not running "
                 "a temp proc (should not happen)",
560
561
                 gimp_filename_to_utf8 (plug_in->name),
		 gimp_filename_to_utf8 (plug_in->prog));
562
563
564
565
      plug_in_close (plug_in, TRUE);
    }
}

Elliot Lee's avatar
Elliot Lee committed
566
static void
567
plug_in_handle_proc_install (PlugIn        *plug_in,
568
                             GPProcInstall *proc_install)
Elliot Lee's avatar
Elliot Lee committed
569
{
570
  PlugInDef     *plug_in_def = NULL;
571
572
573
574
  PlugInProcDef *proc_def    = NULL;
  ProcRecord    *proc        = NULL;
  gchar         *prog        = NULL;
  gboolean       valid_utf8  = FALSE;
575
  gint           i;
Elliot Lee's avatar
Elliot Lee committed
576

577
  /*  Argument checking
Elliot Lee's avatar
Elliot Lee committed
578
579
580
   *   --only sanity check arguments when the procedure requests a menu path
   */

581
  if (proc_install->menu_path && proc_install->menu_path[0] == '<')
Elliot Lee's avatar
Elliot Lee committed
582
    {
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
      GError *error = NULL;

      if (! plug_in_param_defs_check (plug_in->name,
                                      plug_in->prog,
                                      proc_install->name,
                                      proc_install->menu_path,
                                      proc_install->params,
                                      proc_install->nparams,
                                      proc_install->return_vals,
                                      proc_install->nreturn_vals,
                                      &error))
        {
          g_message (error->message);
          g_clear_error (&error);

          return;
        }
Elliot Lee's avatar
Elliot Lee committed
600
601
    }

602
  /*  Sanity check for array arguments  */
Elliot Lee's avatar
Elliot Lee committed
603

604
  for (i = 1; i < proc_install->nparams; i++)
Elliot Lee's avatar
Elliot Lee committed
605
    {
606
      if ((proc_install->params[i].type == GIMP_PDB_INT32ARRAY ||
607
	   proc_install->params[i].type == GIMP_PDB_INT8ARRAY  ||
608
	   proc_install->params[i].type == GIMP_PDB_FLOATARRAY ||
609
	   proc_install->params[i].type == GIMP_PDB_STRINGARRAY)
610
          &&
611
	  proc_install->params[i-1].type != GIMP_PDB_INT32)
Elliot Lee's avatar
Elliot Lee committed
612
	{
Michael Natterer's avatar
Michael Natterer committed
613
614
615
616
	  g_message ("Plug-In \"%s\"\n(%s)\n\n"
                     "attempted to install procedure \"%s\" "
                     "which fails to comply with the array parameter "
                     "passing standard.  Argument %d is noncompliant.",
617
618
                     gimp_filename_to_utf8 (plug_in->name),
		     gimp_filename_to_utf8 (plug_in->prog),
Michael Natterer's avatar
Michael Natterer committed
619
                     proc_install->name, i);
Elliot Lee's avatar
Elliot Lee committed
620
621
622
	  return;
	}
    }
623
624
625

  /*  Sanity check strings for UTF-8 validity  */

626
  if ((proc_install->menu_path == NULL ||
627
628
       g_utf8_validate (proc_install->menu_path, -1, NULL)) &&
      (g_utf8_validate (proc_install->name, -1, NULL))      &&
629
      (proc_install->blurb == NULL ||
630
       g_utf8_validate (proc_install->blurb, -1, NULL))     &&
631
      (proc_install->help == NULL ||
632
633
634
       g_utf8_validate (proc_install->help, -1, NULL))      &&
      (proc_install->author == NULL ||
       g_utf8_validate (proc_install->author, -1, NULL))    &&
635
      (proc_install->copyright == NULL ||
636
637
638
639
       g_utf8_validate (proc_install->copyright, -1, NULL)) &&
      (proc_install->date == NULL ||
       g_utf8_validate (proc_install->date, -1, NULL)))
    {
640
      valid_utf8 = TRUE;
641

642
      for (i = 0; i < proc_install->nparams && valid_utf8; i++)
643
644
        {
          if (! (g_utf8_validate (proc_install->params[i].name, -1, NULL) &&
645
                 (proc_install->params[i].description == NULL ||
646
                  g_utf8_validate (proc_install->params[i].description, -1, NULL))))
647
            valid_utf8 = FALSE;
648
        }
649

650
      for (i = 0; i < proc_install->nreturn_vals && valid_utf8; i++)
651
652
653
654
        {
          if (! (g_utf8_validate (proc_install->return_vals[i].name, -1, NULL) &&
                 (proc_install->return_vals[i].description == NULL ||
                  g_utf8_validate (proc_install->return_vals[i].description, -1, NULL))))
655
            valid_utf8 = FALSE;
656
657
        }
    }
658

659
  if (! valid_utf8)
660
    {
Michael Natterer's avatar
Michael Natterer committed
661
      g_message ("Plug-In \"%s\"\n(%s)\n\n"
662
                 "attempted to install a procedure with invalid UTF-8 strings.",
663
664
                 gimp_filename_to_utf8 (plug_in->name),
		 gimp_filename_to_utf8 (plug_in->prog));
665
666
      return;
    }
Elliot Lee's avatar
Elliot Lee committed
667

668
669
  /*  Initialization  */

Elliot Lee's avatar
Elliot Lee committed
670
671
  switch (proc_install->type)
    {
672
673
    case GIMP_PLUGIN:
    case GIMP_EXTENSION:
674
675
      plug_in_def = plug_in->plug_in_def;
      prog        = plug_in_def->prog;
Elliot Lee's avatar
Elliot Lee committed
676

677
678
679
680
681
682
683
684
      proc_def = plug_in_proc_def_find (plug_in_def->proc_defs,
                                        proc_install->name);
      if (proc_def)
        {
          plug_in_def->proc_defs = g_slist_remove (plug_in_def->proc_defs,
                                                   proc_def);
          plug_in_proc_def_free (proc_def);
        }
Elliot Lee's avatar
Elliot Lee committed
685
686
      break;

687
    case GIMP_TEMPORARY:
688
689
      plug_in_def = NULL;
      prog        = "none";
Elliot Lee's avatar
Elliot Lee committed
690

691
692
693
694
695
696
697
698
      proc_def = plug_in_proc_def_find (plug_in->temp_proc_defs,
                                        proc_install->name);
      if (proc_def)
        {
          plug_in->temp_proc_defs = g_slist_remove (plug_in->temp_proc_defs,
                                                    proc_def);
          plug_ins_temp_proc_def_remove (plug_in->gimp, proc_def);
        }
Elliot Lee's avatar
Elliot Lee committed
699
700
701
      break;
    }

702
  proc_def = plug_in_proc_def_new ();
Elliot Lee's avatar
Elliot Lee committed
703

704
  if (proc_install->menu_path)
705
706
707
708
709
710
711
712
    {
      if (proc_install->menu_path[0] == '<')
        proc_def->menu_paths =
          g_list_append (proc_def->menu_paths,
                         g_strdup (proc_install->menu_path));
      else
        proc_def->menu_label = g_strdup (proc_install->menu_path);
    }
713

714
  proc_def->prog            = g_strdup (prog);
715
716
717
718
  proc_def->extensions      = NULL;
  proc_def->prefixes        = NULL;
  proc_def->magics          = NULL;
  proc_def->image_types     = g_strdup (proc_install->image_types);
719
  proc_def->image_types_val = plug_ins_image_types_parse (proc_def->image_types);
GMT 1999 Andy Thomas's avatar
GMT 1999 Andy Thomas committed
720
  /* Install temp one use todays time */
721
  proc_def->mtime           = time (NULL);
Elliot Lee's avatar
Elliot Lee committed
722

723
724
725
  /* Remember if this proc was installed while initing a plug-in */
  proc_def->installed_during_init = plug_in->init;

726
727
  /*  The procedural database procedure  */

728
729
  proc = &proc_def->db_info;

730
731
732
733
  proc->name      = g_strdup (proc_install->name);
  proc->blurb     = g_strdup (proc_install->blurb);
  proc->help      = g_strdup (proc_install->help);
  proc->author    = g_strdup (proc_install->author);
Elliot Lee's avatar
Elliot Lee committed
734
  proc->copyright = g_strdup (proc_install->copyright);
735
  proc->date      = g_strdup (proc_install->date);
Elliot Lee's avatar
Elliot Lee committed
736
737
  proc->proc_type = proc_install->type;

738
  proc->num_args   = proc_install->nparams;
Elliot Lee's avatar
Elliot Lee committed
739
740
  proc->num_values = proc_install->nreturn_vals;

741
742
  proc->args   = g_new0 (ProcArg, proc->num_args);
  proc->values = g_new0 (ProcArg, proc->num_values);
Elliot Lee's avatar
Elliot Lee committed
743
744
745

  for (i = 0; i < proc->num_args; i++)
    {
746
747
      proc->args[i].arg_type    = proc_install->params[i].type;
      proc->args[i].name        = g_strdup (proc_install->params[i].name);
Elliot Lee's avatar
Elliot Lee committed
748
749
750
751
752
      proc->args[i].description = g_strdup (proc_install->params[i].description);
    }

  for (i = 0; i < proc->num_values; i++)
    {
753
754
      proc->values[i].arg_type    = proc_install->return_vals[i].type;
      proc->values[i].name        = g_strdup (proc_install->return_vals[i].name);
Elliot Lee's avatar
Elliot Lee committed
755
756
757
758
759
      proc->values[i].description = g_strdup (proc_install->return_vals[i].description);
    }

  switch (proc_install->type)
    {
760
761
    case GIMP_PLUGIN:
    case GIMP_EXTENSION:
762
763
      plug_in_def->proc_defs = g_slist_prepend (plug_in_def->proc_defs,
                                                proc_def);
Elliot Lee's avatar
Elliot Lee committed
764
765
      break;

766
    case GIMP_TEMPORARY:
767
768
      plug_in->temp_proc_defs = g_slist_prepend (plug_in->temp_proc_defs,
                                                 proc_def);
Elliot Lee's avatar
Elliot Lee committed
769

770
      proc->exec_method.temporary.plug_in = plug_in;
Elliot Lee's avatar
Elliot Lee committed
771

772
      plug_ins_temp_proc_def_add (plug_in->gimp, proc_def);
Elliot Lee's avatar
Elliot Lee committed
773
774
775
776
777
      break;
    }
}

static void
778
plug_in_handle_proc_uninstall (PlugIn          *plug_in,
779
                               GPProcUninstall *proc_uninstall)
Elliot Lee's avatar
Elliot Lee committed
780
{
781
  PlugInProcDef *proc_def;
Elliot Lee's avatar
Elliot Lee committed
782

783
784
785
  proc_def = plug_in_proc_def_find (plug_in->temp_proc_defs,
                                    proc_uninstall->name);
  if (proc_def)
Elliot Lee's avatar
Elliot Lee committed
786
    {
787
788
789
      plug_in->temp_proc_defs = g_slist_remove (plug_in->temp_proc_defs,
                                                proc_def);
      plug_ins_temp_proc_def_remove (plug_in->gimp, proc_def);
Elliot Lee's avatar
Elliot Lee committed
790
791
    }
}
792

Michael Natterer's avatar
Michael Natterer committed
793
794
795
static void
plug_in_handle_extension_ack (PlugIn *plug_in)
{
796
  if (plug_in->ext_main_loop)
797
    {
798
      g_main_loop_quit (plug_in->ext_main_loop);
799
800
801
    }
  else
    {
Michael Natterer's avatar
Michael Natterer committed
802
803
804
      g_message ("Plug-In \"%s\"\n(%s)\n\n"
		 "sent an EXTENSION_ACK message while not being started "
                 "as extension (should not happen)",
805
806
                 gimp_filename_to_utf8 (plug_in->name),
		 gimp_filename_to_utf8 (plug_in->prog));
807
808
      plug_in_close (plug_in, TRUE);
    }
Michael Natterer's avatar
Michael Natterer committed
809
810
}

811
static void
812
plug_in_handle_has_init (PlugIn *plug_in)
813
{
814
  if (plug_in->query)
815
816
817
818
819
    {
      plug_in_def_set_has_init (plug_in->plug_in_def, TRUE);
    }
  else
    {
Michael Natterer's avatar
Michael Natterer committed
820
821
822
      g_message ("Plug-In \"%s\"\n(%s)\n\n"
		 "sent an HAS_INIT message while not in query() "
                 "(should not happen)",
823
824
                 gimp_filename_to_utf8 (plug_in->name),
		 gimp_filename_to_utf8 (plug_in->prog));
825
826
      plug_in_close (plug_in, TRUE);
    }
827
}