1 /* LIBGIMP - The GIMP Library
2  * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
3  *
4  * This library is free software: you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 3 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library.  If not, see
16  * <https://www.gnu.org/licenses/>.
17  */
18 
19 #include "config.h"
20 
21 #include <glib-object.h>
22 
23 #include "gimpbasetypes.h"
24 
25 #include "gimpparasite.h"
26 #include "gimpprotocol.h"
27 #include "gimpwire.h"
28 
29 
30 static void _gp_quit_read                (GIOChannel       *channel,
31                                           GimpWireMessage  *msg,
32                                           gpointer          user_data);
33 static void _gp_quit_write               (GIOChannel       *channel,
34                                           GimpWireMessage  *msg,
35                                           gpointer          user_data);
36 static void _gp_quit_destroy             (GimpWireMessage  *msg);
37 
38 static void _gp_config_read              (GIOChannel       *channel,
39                                           GimpWireMessage  *msg,
40                                           gpointer          user_data);
41 static void _gp_config_write             (GIOChannel       *channel,
42                                           GimpWireMessage  *msg,
43                                           gpointer          user_data);
44 static void _gp_config_destroy           (GimpWireMessage  *msg);
45 
46 static void _gp_tile_req_read            (GIOChannel       *channel,
47                                           GimpWireMessage  *msg,
48                                           gpointer          user_data);
49 static void _gp_tile_req_write           (GIOChannel       *channel,
50                                           GimpWireMessage  *msg,
51                                           gpointer          user_data);
52 static void _gp_tile_req_destroy         (GimpWireMessage  *msg);
53 
54 static void _gp_tile_ack_read            (GIOChannel       *channel,
55                                           GimpWireMessage  *msg,
56                                           gpointer          user_data);
57 static void _gp_tile_ack_write           (GIOChannel       *channel,
58                                           GimpWireMessage  *msg,
59                                           gpointer          user_data);
60 static void _gp_tile_ack_destroy         (GimpWireMessage  *msg);
61 
62 static void _gp_tile_data_read           (GIOChannel       *channel,
63                                           GimpWireMessage  *msg,
64                                           gpointer          user_data);
65 static void _gp_tile_data_write          (GIOChannel       *channel,
66                                           GimpWireMessage  *msg,
67                                           gpointer          user_data);
68 static void _gp_tile_data_destroy        (GimpWireMessage  *msg);
69 
70 static void _gp_proc_run_read            (GIOChannel       *channel,
71                                           GimpWireMessage  *msg,
72                                           gpointer          user_data);
73 static void _gp_proc_run_write           (GIOChannel       *channel,
74                                           GimpWireMessage  *msg,
75                                           gpointer          user_data);
76 static void _gp_proc_run_destroy         (GimpWireMessage  *msg);
77 
78 static void _gp_proc_return_read         (GIOChannel       *channel,
79                                           GimpWireMessage  *msg,
80                                           gpointer          user_data);
81 static void _gp_proc_return_write        (GIOChannel       *channel,
82                                           GimpWireMessage  *msg,
83                                           gpointer          user_data);
84 static void _gp_proc_return_destroy      (GimpWireMessage  *msg);
85 
86 static void _gp_temp_proc_run_read       (GIOChannel       *channel,
87                                           GimpWireMessage  *msg,
88                                           gpointer          user_data);
89 static void _gp_temp_proc_run_write      (GIOChannel       *channel,
90                                           GimpWireMessage  *msg,
91                                           gpointer          user_data);
92 static void _gp_temp_proc_run_destroy    (GimpWireMessage  *msg);
93 
94 static void _gp_temp_proc_return_read    (GIOChannel       *channel,
95                                           GimpWireMessage  *msg,
96                                           gpointer          user_data);
97 static void _gp_temp_proc_return_write   (GIOChannel       *channel,
98                                           GimpWireMessage  *msg,
99                                           gpointer          user_data);
100 static void _gp_temp_proc_return_destroy (GimpWireMessage  *msg);
101 
102 static void _gp_proc_install_read        (GIOChannel       *channel,
103                                           GimpWireMessage  *msg,
104                                           gpointer          user_data);
105 static void _gp_proc_install_write       (GIOChannel       *channel,
106                                           GimpWireMessage  *msg,
107                                           gpointer          user_data);
108 static void _gp_proc_install_destroy     (GimpWireMessage  *msg);
109 
110 static void _gp_proc_uninstall_read      (GIOChannel       *channel,
111                                           GimpWireMessage  *msg,
112                                           gpointer          user_data);
113 static void _gp_proc_uninstall_write     (GIOChannel       *channel,
114                                           GimpWireMessage  *msg,
115                                           gpointer          user_data);
116 static void _gp_proc_uninstall_destroy   (GimpWireMessage  *msg);
117 
118 static void _gp_extension_ack_read       (GIOChannel       *channel,
119                                           GimpWireMessage  *msg,
120                                           gpointer          user_data);
121 static void _gp_extension_ack_write      (GIOChannel       *channel,
122                                           GimpWireMessage  *msg,
123                                           gpointer          user_data);
124 static void _gp_extension_ack_destroy    (GimpWireMessage  *msg);
125 
126 static void _gp_params_read              (GIOChannel       *channel,
127                                           GPParam         **params,
128                                           guint            *nparams,
129                                           gpointer          user_data);
130 static void _gp_params_write             (GIOChannel       *channel,
131                                           GPParam          *params,
132                                           gint              nparams,
133                                           gpointer          user_data);
134 
135 static void _gp_has_init_read            (GIOChannel       *channel,
136                                           GimpWireMessage  *msg,
137                                           gpointer          user_data);
138 static void _gp_has_init_write           (GIOChannel       *channel,
139                                           GimpWireMessage  *msg,
140                                           gpointer          user_data);
141 static void _gp_has_init_destroy         (GimpWireMessage  *msg);
142 
143 
144 
145 void
gp_init(void)146 gp_init (void)
147 {
148   gimp_wire_register (GP_QUIT,
149                       _gp_quit_read,
150                       _gp_quit_write,
151                       _gp_quit_destroy);
152   gimp_wire_register (GP_CONFIG,
153                       _gp_config_read,
154                       _gp_config_write,
155                       _gp_config_destroy);
156   gimp_wire_register (GP_TILE_REQ,
157                       _gp_tile_req_read,
158                       _gp_tile_req_write,
159                       _gp_tile_req_destroy);
160   gimp_wire_register (GP_TILE_ACK,
161                       _gp_tile_ack_read,
162                       _gp_tile_ack_write,
163                       _gp_tile_ack_destroy);
164   gimp_wire_register (GP_TILE_DATA,
165                       _gp_tile_data_read,
166                       _gp_tile_data_write,
167                       _gp_tile_data_destroy);
168   gimp_wire_register (GP_PROC_RUN,
169                       _gp_proc_run_read,
170                       _gp_proc_run_write,
171                       _gp_proc_run_destroy);
172   gimp_wire_register (GP_PROC_RETURN,
173                       _gp_proc_return_read,
174                       _gp_proc_return_write,
175                       _gp_proc_return_destroy);
176   gimp_wire_register (GP_TEMP_PROC_RUN,
177                       _gp_temp_proc_run_read,
178                       _gp_temp_proc_run_write,
179                       _gp_temp_proc_run_destroy);
180   gimp_wire_register (GP_TEMP_PROC_RETURN,
181                       _gp_temp_proc_return_read,
182                       _gp_temp_proc_return_write,
183                       _gp_temp_proc_return_destroy);
184   gimp_wire_register (GP_PROC_INSTALL,
185                       _gp_proc_install_read,
186                       _gp_proc_install_write,
187                       _gp_proc_install_destroy);
188   gimp_wire_register (GP_PROC_UNINSTALL,
189                       _gp_proc_uninstall_read,
190                       _gp_proc_uninstall_write,
191                       _gp_proc_uninstall_destroy);
192   gimp_wire_register (GP_EXTENSION_ACK,
193                       _gp_extension_ack_read,
194                       _gp_extension_ack_write,
195                       _gp_extension_ack_destroy);
196   gimp_wire_register (GP_HAS_INIT,
197                       _gp_has_init_read,
198                       _gp_has_init_write,
199                       _gp_has_init_destroy);
200 }
201 
202 gboolean
gp_quit_write(GIOChannel * channel,gpointer user_data)203 gp_quit_write (GIOChannel *channel,
204                gpointer    user_data)
205 {
206   GimpWireMessage msg;
207 
208   msg.type = GP_QUIT;
209   msg.data = NULL;
210 
211   if (! gimp_wire_write_msg (channel, &msg, user_data))
212     return FALSE;
213 
214   if (! gimp_wire_flush (channel, user_data))
215     return FALSE;
216 
217   return TRUE;
218 }
219 
220 gboolean
gp_config_write(GIOChannel * channel,GPConfig * config,gpointer user_data)221 gp_config_write (GIOChannel *channel,
222                  GPConfig   *config,
223                  gpointer    user_data)
224 {
225   GimpWireMessage msg;
226 
227   msg.type = GP_CONFIG;
228   msg.data = config;
229 
230   if (! gimp_wire_write_msg (channel, &msg, user_data))
231     return FALSE;
232 
233   if (! gimp_wire_flush (channel, user_data))
234     return FALSE;
235 
236   return TRUE;
237 }
238 
239 gboolean
gp_tile_req_write(GIOChannel * channel,GPTileReq * tile_req,gpointer user_data)240 gp_tile_req_write (GIOChannel *channel,
241                    GPTileReq  *tile_req,
242                    gpointer    user_data)
243 {
244   GimpWireMessage msg;
245 
246   msg.type = GP_TILE_REQ;
247   msg.data = tile_req;
248 
249   if (! gimp_wire_write_msg (channel, &msg, user_data))
250     return FALSE;
251 
252   if (! gimp_wire_flush (channel, user_data))
253     return FALSE;
254 
255   return TRUE;
256 }
257 
258 gboolean
gp_tile_ack_write(GIOChannel * channel,gpointer user_data)259 gp_tile_ack_write (GIOChannel *channel,
260                    gpointer    user_data)
261 {
262   GimpWireMessage msg;
263 
264   msg.type = GP_TILE_ACK;
265   msg.data = NULL;
266 
267   if (! gimp_wire_write_msg (channel, &msg, user_data))
268     return FALSE;
269 
270   if (! gimp_wire_flush (channel, user_data))
271     return FALSE;
272 
273   return TRUE;
274 }
275 
276 gboolean
gp_tile_data_write(GIOChannel * channel,GPTileData * tile_data,gpointer user_data)277 gp_tile_data_write (GIOChannel *channel,
278                     GPTileData *tile_data,
279                     gpointer    user_data)
280 {
281   GimpWireMessage msg;
282 
283   msg.type = GP_TILE_DATA;
284   msg.data = tile_data;
285 
286   if (! gimp_wire_write_msg (channel, &msg, user_data))
287     return FALSE;
288 
289   if (! gimp_wire_flush (channel, user_data))
290     return FALSE;
291 
292   return TRUE;
293 }
294 
295 gboolean
gp_proc_run_write(GIOChannel * channel,GPProcRun * proc_run,gpointer user_data)296 gp_proc_run_write (GIOChannel *channel,
297                    GPProcRun  *proc_run,
298                    gpointer    user_data)
299 {
300   GimpWireMessage msg;
301 
302   msg.type = GP_PROC_RUN;
303   msg.data = proc_run;
304 
305   if (! gimp_wire_write_msg (channel, &msg, user_data))
306     return FALSE;
307 
308   if (! gimp_wire_flush (channel, user_data))
309     return FALSE;
310 
311   return TRUE;
312 }
313 
314 gboolean
gp_proc_return_write(GIOChannel * channel,GPProcReturn * proc_return,gpointer user_data)315 gp_proc_return_write (GIOChannel   *channel,
316                       GPProcReturn *proc_return,
317                       gpointer      user_data)
318 {
319   GimpWireMessage msg;
320 
321   msg.type = GP_PROC_RETURN;
322   msg.data = proc_return;
323 
324   if (! gimp_wire_write_msg (channel, &msg, user_data))
325     return FALSE;
326 
327   if (! gimp_wire_flush (channel, user_data))
328     return FALSE;
329 
330   return TRUE;
331 }
332 
333 gboolean
gp_temp_proc_run_write(GIOChannel * channel,GPProcRun * proc_run,gpointer user_data)334 gp_temp_proc_run_write (GIOChannel *channel,
335                         GPProcRun  *proc_run,
336                         gpointer    user_data)
337 {
338   GimpWireMessage msg;
339 
340   msg.type = GP_TEMP_PROC_RUN;
341   msg.data = proc_run;
342 
343   if (! gimp_wire_write_msg (channel, &msg, user_data))
344     return FALSE;
345 
346   if (! gimp_wire_flush (channel, user_data))
347     return FALSE;
348 
349   return TRUE;
350 }
351 
352 gboolean
gp_temp_proc_return_write(GIOChannel * channel,GPProcReturn * proc_return,gpointer user_data)353 gp_temp_proc_return_write (GIOChannel   *channel,
354                            GPProcReturn *proc_return,
355                            gpointer      user_data)
356 {
357   GimpWireMessage msg;
358 
359   msg.type = GP_TEMP_PROC_RETURN;
360   msg.data = proc_return;
361 
362   if (! gimp_wire_write_msg (channel, &msg, user_data))
363     return FALSE;
364 
365   if (! gimp_wire_flush (channel, user_data))
366     return FALSE;
367 
368   return TRUE;
369 }
370 
371 gboolean
gp_proc_install_write(GIOChannel * channel,GPProcInstall * proc_install,gpointer user_data)372 gp_proc_install_write (GIOChannel    *channel,
373                        GPProcInstall *proc_install,
374                        gpointer       user_data)
375 {
376   GimpWireMessage msg;
377 
378   msg.type = GP_PROC_INSTALL;
379   msg.data = proc_install;
380 
381   if (! gimp_wire_write_msg (channel, &msg, user_data))
382     return FALSE;
383 
384   if (! gimp_wire_flush (channel, user_data))
385     return FALSE;
386 
387   return TRUE;
388 }
389 
390 gboolean
gp_proc_uninstall_write(GIOChannel * channel,GPProcUninstall * proc_uninstall,gpointer user_data)391 gp_proc_uninstall_write (GIOChannel      *channel,
392                          GPProcUninstall *proc_uninstall,
393                          gpointer         user_data)
394 {
395   GimpWireMessage msg;
396 
397   msg.type = GP_PROC_UNINSTALL;
398   msg.data = proc_uninstall;
399 
400   if (! gimp_wire_write_msg (channel, &msg, user_data))
401     return FALSE;
402 
403   if (! gimp_wire_flush (channel, user_data))
404     return FALSE;
405 
406   return TRUE;
407 }
408 
409 gboolean
gp_extension_ack_write(GIOChannel * channel,gpointer user_data)410 gp_extension_ack_write (GIOChannel *channel,
411                         gpointer    user_data)
412 {
413   GimpWireMessage msg;
414 
415   msg.type = GP_EXTENSION_ACK;
416   msg.data = NULL;
417 
418   if (! gimp_wire_write_msg (channel, &msg, user_data))
419     return FALSE;
420 
421   if (! gimp_wire_flush (channel, user_data))
422     return FALSE;
423 
424   return TRUE;
425 }
426 
427 gboolean
gp_has_init_write(GIOChannel * channel,gpointer user_data)428 gp_has_init_write (GIOChannel *channel,
429                    gpointer    user_data)
430 {
431   GimpWireMessage msg;
432 
433   msg.type = GP_HAS_INIT;
434   msg.data = NULL;
435 
436   if (! gimp_wire_write_msg (channel, &msg, user_data))
437     return FALSE;
438 
439   if (! gimp_wire_flush (channel, user_data))
440     return FALSE;
441 
442   return TRUE;
443 }
444 
445 /*  quit  */
446 
447 static void
_gp_quit_read(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)448 _gp_quit_read (GIOChannel      *channel,
449                GimpWireMessage *msg,
450                gpointer         user_data)
451 {
452 }
453 
454 static void
_gp_quit_write(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)455 _gp_quit_write (GIOChannel      *channel,
456                 GimpWireMessage *msg,
457                 gpointer         user_data)
458 {
459 }
460 
461 static void
_gp_quit_destroy(GimpWireMessage * msg)462 _gp_quit_destroy (GimpWireMessage *msg)
463 {
464 }
465 
466 /*  config  */
467 
468 static void
_gp_config_read(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)469 _gp_config_read (GIOChannel      *channel,
470                  GimpWireMessage *msg,
471                  gpointer         user_data)
472 {
473   GPConfig *config = g_slice_new0 (GPConfig);
474 
475   if (! _gimp_wire_read_int32 (channel,
476                                &config->version, 1, user_data))
477     goto cleanup;
478   if (! _gimp_wire_read_int32 (channel,
479                                &config->tile_width, 1, user_data))
480     goto cleanup;
481   if (! _gimp_wire_read_int32 (channel,
482                                &config->tile_height, 1, user_data))
483     goto cleanup;
484   if (! _gimp_wire_read_int32 (channel,
485                                (guint32 *) &config->shm_ID, 1, user_data))
486     goto cleanup;
487   if (! _gimp_wire_read_int8 (channel,
488                               (guint8 *) &config->check_size, 1, user_data))
489     goto cleanup;
490   if (! _gimp_wire_read_int8 (channel,
491                               (guint8 *) &config->check_type, 1, user_data))
492     goto cleanup;
493   if (! _gimp_wire_read_int8 (channel,
494                               (guint8 *) &config->show_help_button, 1,
495                               user_data))
496     goto cleanup;
497   if (! _gimp_wire_read_int8 (channel,
498                               (guint8 *) &config->use_cpu_accel, 1,
499                               user_data))
500     goto cleanup;
501   if (! _gimp_wire_read_int8 (channel,
502                               (guint8 *) &config->use_opencl, 1,
503                               user_data))
504     goto cleanup;
505   if (! _gimp_wire_read_int8 (channel,
506                               (guint8 *) &config->export_exif, 1,
507                               user_data))
508     goto cleanup;
509   if (! _gimp_wire_read_int8 (channel,
510                               (guint8 *) &config->export_xmp, 1,
511                               user_data))
512     goto cleanup;
513   if (! _gimp_wire_read_int8 (channel,
514                               (guint8 *) &config->export_iptc, 1,
515                               user_data))
516     goto cleanup;
517   if (! _gimp_wire_read_int8 (channel,
518                               (guint8 *) &config->export_profile, 1,
519                               user_data))
520     goto cleanup;
521   if (! _gimp_wire_read_int8 (channel,
522                               (guint8 *) &config->show_tooltips, 1, user_data))
523     goto cleanup;
524   if (! _gimp_wire_read_int32 (channel,
525                                (guint32 *) &config->min_colors, 1, user_data))
526     goto cleanup;
527   if (! _gimp_wire_read_int32 (channel,
528                                (guint32 *) &config->gdisp_ID, 1, user_data))
529     goto cleanup;
530 
531   if (! _gimp_wire_read_string (channel,
532                                 &config->app_name, 1, user_data))
533     goto cleanup;
534   if (! _gimp_wire_read_string (channel,
535                                 &config->wm_class, 1, user_data))
536     goto cleanup;
537   if (! _gimp_wire_read_string (channel,
538                                 &config->display_name, 1, user_data))
539     goto cleanup;
540   if (! _gimp_wire_read_int32 (channel,
541                                (guint32 *) &config->monitor_number, 1,
542                                user_data))
543     goto cleanup;
544   if (! _gimp_wire_read_int32 (channel,
545                                &config->timestamp, 1, user_data))
546     goto cleanup;
547 
548   if (config->version < 0x0017)
549     goto end;
550 
551   if (! _gimp_wire_read_string (channel,
552                                 &config->icon_theme_dir, 1, user_data))
553     goto cleanup;
554 
555   if (config->version < 0x0019)
556     goto end;
557 
558   if (! _gimp_wire_read_int64 (channel,
559                                &config->tile_cache_size, 1, user_data))
560     goto cleanup;
561   if (! _gimp_wire_read_string (channel,
562                                 &config->swap_path, 1, user_data))
563     goto cleanup;
564   if (! _gimp_wire_read_int32 (channel,
565                                (guint32 *) &config->num_processors, 1,
566                                user_data))
567     goto cleanup;
568 
569   if (config->version < 0x001A)
570     goto end;
571 
572   if (! _gimp_wire_read_string (channel,
573                                 &config->swap_compression, 1, user_data))
574     goto cleanup;
575 
576  end:
577   msg->data = config;
578   return;
579 
580  cleanup:
581   g_free (config->app_name);
582   g_free (config->wm_class);
583   g_free (config->display_name);
584   g_free (config->icon_theme_dir);
585   g_free (config->swap_path);
586   g_free (config->swap_compression);
587   g_slice_free (GPConfig, config);
588 }
589 
590 static void
_gp_config_write(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)591 _gp_config_write (GIOChannel      *channel,
592                   GimpWireMessage *msg,
593                   gpointer         user_data)
594 {
595   GPConfig *config = msg->data;
596 
597   if (! _gimp_wire_write_int32 (channel,
598                                 &config->version, 1, user_data))
599     return;
600   if (! _gimp_wire_write_int32 (channel,
601                                 &config->tile_width, 1, user_data))
602     return;
603   if (! _gimp_wire_write_int32 (channel,
604                                 &config->tile_height, 1, user_data))
605     return;
606   if (! _gimp_wire_write_int32 (channel,
607                                 (const guint32 *) &config->shm_ID, 1,
608                                 user_data))
609     return;
610   if (! _gimp_wire_write_int8 (channel,
611                                (const guint8 *) &config->check_size, 1,
612                                user_data))
613     return;
614   if (! _gimp_wire_write_int8 (channel,
615                                (const guint8 *) &config->check_type, 1,
616                                user_data))
617     return;
618   if (! _gimp_wire_write_int8 (channel,
619                                (const guint8 *) &config->show_help_button, 1,
620                                user_data))
621     return;
622   if (! _gimp_wire_write_int8 (channel,
623                                (const guint8 *) &config->use_cpu_accel, 1,
624                                user_data))
625     return;
626   if (! _gimp_wire_write_int8 (channel,
627                                (const guint8 *) &config->use_opencl, 1,
628                                user_data))
629     return;
630   if (! _gimp_wire_write_int8 (channel,
631                                (const guint8 *) &config->export_exif, 1,
632                                user_data))
633     return;
634   if (! _gimp_wire_write_int8 (channel,
635                                (const guint8 *) &config->export_xmp, 1,
636                                user_data))
637     return;
638   if (! _gimp_wire_write_int8 (channel,
639                                (const guint8 *) &config->export_iptc, 1,
640                                user_data))
641     return;
642   if (! _gimp_wire_write_int8 (channel,
643                                (const guint8 *) &config->export_profile, 1,
644                                user_data))
645     return;
646   if (! _gimp_wire_write_int8 (channel,
647                                (const guint8 *) &config->show_tooltips, 1,
648                                user_data))
649     return;
650   if (! _gimp_wire_write_int32 (channel,
651                                 (const guint32 *) &config->min_colors, 1,
652                                 user_data))
653     return;
654   if (! _gimp_wire_write_int32 (channel,
655                                 (const guint32 *) &config->gdisp_ID, 1,
656                                 user_data))
657     return;
658   if (! _gimp_wire_write_string (channel,
659                                  &config->app_name, 1, user_data))
660     return;
661   if (! _gimp_wire_write_string (channel,
662                                  &config->wm_class, 1, user_data))
663     return;
664   if (! _gimp_wire_write_string (channel,
665                                  &config->display_name, 1, user_data))
666     return;
667   if (! _gimp_wire_write_int32 (channel,
668                                 (const guint32 *) &config->monitor_number, 1,
669                                 user_data))
670     return;
671   if (! _gimp_wire_write_int32 (channel,
672                                 (const guint32 *) &config->timestamp, 1,
673                                 user_data))
674     return;
675 
676   if (config->version < 0x0017)
677     return;
678 
679   if (! _gimp_wire_write_string (channel,
680                                  &config->icon_theme_dir, 1, user_data))
681     return;
682 
683   if (config->version < 0x0019)
684     return;
685 
686   if (! _gimp_wire_write_int64 (channel,
687                                 &config->tile_cache_size, 1, user_data))
688     return;
689   if (! _gimp_wire_write_string (channel,
690                                  &config->swap_path, 1, user_data))
691     return;
692   if (! _gimp_wire_write_int32 (channel,
693                                 (const guint32 *) &config->num_processors, 1,
694                                 user_data))
695     return;
696 
697   if (config->version < 0x001A)
698     return;
699 
700   if (! _gimp_wire_write_string (channel,
701                                  &config->swap_compression, 1, user_data))
702     return;
703 }
704 
705 static void
_gp_config_destroy(GimpWireMessage * msg)706 _gp_config_destroy (GimpWireMessage *msg)
707 {
708   GPConfig *config = msg->data;
709 
710   if (config)
711     {
712       g_free (config->app_name);
713       g_free (config->wm_class);
714       g_free (config->display_name);
715       g_free (config->icon_theme_dir);
716       g_free (config->swap_path);
717       g_free (config->swap_compression);
718       g_slice_free (GPConfig, config);
719     }
720 }
721 
722 /*  tile_req  */
723 
724 static void
_gp_tile_req_read(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)725 _gp_tile_req_read (GIOChannel      *channel,
726                    GimpWireMessage *msg,
727                    gpointer         user_data)
728 {
729   GPTileReq *tile_req = g_slice_new0 (GPTileReq);
730 
731   if (! _gimp_wire_read_int32 (channel,
732                                (guint32 *) &tile_req->drawable_ID, 1,
733                                user_data))
734     goto cleanup;
735   if (! _gimp_wire_read_int32 (channel,
736                                &tile_req->tile_num, 1, user_data))
737     goto cleanup;
738   if (! _gimp_wire_read_int32 (channel,
739                                &tile_req->shadow, 1, user_data))
740     goto cleanup;
741 
742   msg->data = tile_req;
743   return;
744 
745  cleanup:
746   g_slice_free (GPTileReq, tile_req);
747   msg->data = NULL;
748 }
749 
750 static void
_gp_tile_req_write(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)751 _gp_tile_req_write (GIOChannel      *channel,
752                     GimpWireMessage *msg,
753                     gpointer         user_data)
754 {
755   GPTileReq *tile_req = msg->data;
756 
757   if (! _gimp_wire_write_int32 (channel,
758                                 (const guint32 *) &tile_req->drawable_ID, 1,
759                                 user_data))
760     return;
761   if (! _gimp_wire_write_int32 (channel,
762                                 &tile_req->tile_num, 1, user_data))
763     return;
764   if (! _gimp_wire_write_int32 (channel,
765                                 &tile_req->shadow, 1, user_data))
766     return;
767 }
768 
769 static void
_gp_tile_req_destroy(GimpWireMessage * msg)770 _gp_tile_req_destroy (GimpWireMessage *msg)
771 {
772   GPTileReq *tile_req = msg->data;
773 
774   if (tile_req)
775     g_slice_free (GPTileReq, msg->data);
776 }
777 
778 /*  tile_ack  */
779 
780 static void
_gp_tile_ack_read(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)781 _gp_tile_ack_read (GIOChannel      *channel,
782                    GimpWireMessage *msg,
783                    gpointer         user_data)
784 {
785 }
786 
787 static void
_gp_tile_ack_write(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)788 _gp_tile_ack_write (GIOChannel      *channel,
789                     GimpWireMessage *msg,
790                     gpointer         user_data)
791 {
792 }
793 
794 static void
_gp_tile_ack_destroy(GimpWireMessage * msg)795 _gp_tile_ack_destroy (GimpWireMessage *msg)
796 {
797 }
798 
799 /*  tile_data  */
800 
801 static void
_gp_tile_data_read(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)802 _gp_tile_data_read (GIOChannel      *channel,
803                     GimpWireMessage *msg,
804                     gpointer         user_data)
805 {
806   GPTileData *tile_data = g_slice_new0 (GPTileData);
807 
808   if (! _gimp_wire_read_int32 (channel,
809                                (guint32 *) &tile_data->drawable_ID, 1,
810                                user_data))
811     goto cleanup;
812   if (! _gimp_wire_read_int32 (channel,
813                                &tile_data->tile_num, 1, user_data))
814     goto cleanup;
815   if (! _gimp_wire_read_int32 (channel,
816                                &tile_data->shadow, 1, user_data))
817     goto cleanup;
818   if (! _gimp_wire_read_int32 (channel,
819                                &tile_data->bpp, 1, user_data))
820     goto cleanup;
821   if (! _gimp_wire_read_int32 (channel,
822                                &tile_data->width, 1, user_data))
823     goto cleanup;
824   if (! _gimp_wire_read_int32 (channel,
825                                &tile_data->height, 1, user_data))
826     goto cleanup;
827   if (! _gimp_wire_read_int32 (channel,
828                                &tile_data->use_shm, 1, user_data))
829     goto cleanup;
830 
831   if (!tile_data->use_shm)
832     {
833       guint length = tile_data->width * tile_data->height * tile_data->bpp;
834 
835       tile_data->data = g_new (guchar, length);
836 
837       if (! _gimp_wire_read_int8 (channel,
838                                   (guint8 *) tile_data->data, length,
839                                   user_data))
840         goto cleanup;
841     }
842 
843   msg->data = tile_data;
844   return;
845 
846  cleanup:
847   g_free (tile_data->data);
848   g_slice_free (GPTileData, tile_data);
849   msg->data = NULL;
850 }
851 
852 static void
_gp_tile_data_write(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)853 _gp_tile_data_write (GIOChannel      *channel,
854                      GimpWireMessage *msg,
855                      gpointer         user_data)
856 {
857   GPTileData *tile_data = msg->data;
858 
859   if (! _gimp_wire_write_int32 (channel,
860                                 (const guint32 *) &tile_data->drawable_ID, 1,
861                                 user_data))
862     return;
863   if (! _gimp_wire_write_int32 (channel,
864                                 &tile_data->tile_num, 1, user_data))
865     return;
866   if (! _gimp_wire_write_int32 (channel,
867                                 &tile_data->shadow, 1, user_data))
868     return;
869   if (! _gimp_wire_write_int32 (channel,
870                                 &tile_data->bpp, 1, user_data))
871     return;
872   if (! _gimp_wire_write_int32 (channel,
873                                 &tile_data->width, 1, user_data))
874     return;
875   if (! _gimp_wire_write_int32 (channel,
876                                 &tile_data->height, 1, user_data))
877     return;
878   if (! _gimp_wire_write_int32 (channel,
879                                 &tile_data->use_shm, 1, user_data))
880     return;
881 
882   if (!tile_data->use_shm)
883     {
884       guint length = tile_data->width * tile_data->height * tile_data->bpp;
885 
886       if (! _gimp_wire_write_int8 (channel,
887                                    (const guint8 *) tile_data->data, length,
888                                    user_data))
889         return;
890     }
891 }
892 
893 static void
_gp_tile_data_destroy(GimpWireMessage * msg)894 _gp_tile_data_destroy (GimpWireMessage *msg)
895 {
896   GPTileData *tile_data = msg->data;
897 
898   if  (tile_data)
899     {
900       if (tile_data->data)
901         {
902           g_free (tile_data->data);
903           tile_data->data = NULL;
904         }
905 
906       g_slice_free (GPTileData, tile_data);
907     }
908 }
909 
910 /*  proc_run  */
911 
912 static void
_gp_proc_run_read(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)913 _gp_proc_run_read (GIOChannel      *channel,
914                    GimpWireMessage *msg,
915                    gpointer         user_data)
916 {
917   GPProcRun *proc_run = g_slice_new0 (GPProcRun);
918 
919   if (! _gimp_wire_read_string (channel, &proc_run->name, 1, user_data))
920     goto cleanup;
921 
922   _gp_params_read (channel,
923                    &proc_run->params, (guint *) &proc_run->nparams,
924                    user_data);
925 
926   msg->data = proc_run;
927   return;
928 
929  cleanup:
930   g_slice_free (GPProcRun, proc_run);
931   msg->data = NULL;
932 }
933 
934 static void
_gp_proc_run_write(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)935 _gp_proc_run_write (GIOChannel      *channel,
936                     GimpWireMessage *msg,
937                     gpointer         user_data)
938 {
939   GPProcRun *proc_run = msg->data;
940 
941   if (! _gimp_wire_write_string (channel, &proc_run->name, 1, user_data))
942     return;
943 
944   _gp_params_write (channel, proc_run->params, proc_run->nparams, user_data);
945 }
946 
947 static void
_gp_proc_run_destroy(GimpWireMessage * msg)948 _gp_proc_run_destroy (GimpWireMessage *msg)
949 {
950   GPProcRun *proc_run = msg->data;
951 
952   if (proc_run)
953     {
954       gp_params_destroy (proc_run->params, proc_run->nparams);
955 
956       g_free (proc_run->name);
957       g_slice_free (GPProcRun, proc_run);
958     }
959 }
960 
961 /*  proc_return  */
962 
963 static void
_gp_proc_return_read(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)964 _gp_proc_return_read (GIOChannel      *channel,
965                       GimpWireMessage *msg,
966                       gpointer         user_data)
967 {
968   GPProcReturn *proc_return = g_slice_new0 (GPProcReturn);
969 
970   if (! _gimp_wire_read_string (channel, &proc_return->name, 1, user_data))
971     goto cleanup;
972 
973   _gp_params_read (channel,
974                    &proc_return->params, (guint *) &proc_return->nparams,
975                    user_data);
976 
977   msg->data = proc_return;
978   return;
979 
980  cleanup:
981   g_slice_free (GPProcReturn, proc_return);
982   msg->data = NULL;
983 }
984 
985 static void
_gp_proc_return_write(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)986 _gp_proc_return_write (GIOChannel      *channel,
987                        GimpWireMessage *msg,
988                        gpointer         user_data)
989 {
990   GPProcReturn *proc_return = msg->data;
991 
992   if (! _gimp_wire_write_string (channel, &proc_return->name, 1, user_data))
993     return;
994 
995   _gp_params_write (channel,
996                     proc_return->params, proc_return->nparams, user_data);
997 }
998 
999 static void
_gp_proc_return_destroy(GimpWireMessage * msg)1000 _gp_proc_return_destroy (GimpWireMessage *msg)
1001 {
1002   GPProcReturn *proc_return = msg->data;
1003 
1004   if (proc_return)
1005     {
1006       gp_params_destroy (proc_return->params, proc_return->nparams);
1007 
1008       g_free (proc_return->name);
1009       g_slice_free (GPProcReturn, proc_return);
1010     }
1011 }
1012 
1013 /*  temp_proc_run  */
1014 
1015 static void
_gp_temp_proc_run_read(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)1016 _gp_temp_proc_run_read (GIOChannel      *channel,
1017                         GimpWireMessage *msg,
1018                         gpointer         user_data)
1019 {
1020   _gp_proc_run_read (channel, msg, user_data);
1021 }
1022 
1023 static void
_gp_temp_proc_run_write(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)1024 _gp_temp_proc_run_write (GIOChannel      *channel,
1025                          GimpWireMessage *msg,
1026                          gpointer         user_data)
1027 {
1028   _gp_proc_run_write (channel, msg, user_data);
1029 }
1030 
1031 static void
_gp_temp_proc_run_destroy(GimpWireMessage * msg)1032 _gp_temp_proc_run_destroy (GimpWireMessage *msg)
1033 {
1034   _gp_proc_run_destroy (msg);
1035 }
1036 
1037 /*  temp_proc_return  */
1038 
1039 static void
_gp_temp_proc_return_read(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)1040 _gp_temp_proc_return_read (GIOChannel      *channel,
1041                            GimpWireMessage *msg,
1042                            gpointer         user_data)
1043 {
1044   _gp_proc_return_read (channel, msg, user_data);
1045 }
1046 
1047 static void
_gp_temp_proc_return_write(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)1048 _gp_temp_proc_return_write (GIOChannel      *channel,
1049                             GimpWireMessage *msg,
1050                             gpointer         user_data)
1051 {
1052   _gp_proc_return_write (channel, msg, user_data);
1053 }
1054 
1055 static void
_gp_temp_proc_return_destroy(GimpWireMessage * msg)1056 _gp_temp_proc_return_destroy (GimpWireMessage *msg)
1057 {
1058   _gp_proc_return_destroy (msg);
1059 }
1060 
1061 /*  proc_install  */
1062 
1063 static void
_gp_proc_install_read(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)1064 _gp_proc_install_read (GIOChannel      *channel,
1065                        GimpWireMessage *msg,
1066                        gpointer         user_data)
1067 {
1068   GPProcInstall *proc_install = g_slice_new0 (GPProcInstall);
1069   gint           i;
1070 
1071   if (! _gimp_wire_read_string (channel,
1072                                 &proc_install->name, 1, user_data))
1073     goto cleanup;
1074   if (! _gimp_wire_read_string (channel,
1075                                 &proc_install->blurb, 1, user_data))
1076     goto cleanup;
1077   if (! _gimp_wire_read_string (channel,
1078                                 &proc_install->help, 1, user_data))
1079     goto cleanup;
1080   if (! _gimp_wire_read_string (channel,
1081                                 &proc_install->author, 1, user_data))
1082     goto cleanup;
1083   if (! _gimp_wire_read_string (channel,
1084                                 &proc_install->copyright, 1, user_data))
1085     goto cleanup;
1086   if (! _gimp_wire_read_string (channel,
1087                                 &proc_install->date, 1, user_data))
1088     goto cleanup;
1089   if (! _gimp_wire_read_string (channel,
1090                                 &proc_install->menu_path, 1, user_data))
1091     goto cleanup;
1092   if (! _gimp_wire_read_string (channel,
1093                                 &proc_install->image_types, 1, user_data))
1094     goto cleanup;
1095 
1096   if (! _gimp_wire_read_int32 (channel,
1097                                &proc_install->type, 1, user_data))
1098     goto cleanup;
1099   if (! _gimp_wire_read_int32 (channel,
1100                                &proc_install->nparams, 1, user_data))
1101     goto cleanup;
1102   if (! _gimp_wire_read_int32 (channel,
1103                                &proc_install->nreturn_vals, 1, user_data))
1104     goto cleanup;
1105 
1106   proc_install->params = g_new0 (GPParamDef, proc_install->nparams);
1107 
1108   for (i = 0; i < proc_install->nparams; i++)
1109     {
1110       if (! _gimp_wire_read_int32 (channel,
1111                                    (guint32 *) &proc_install->params[i].type, 1,
1112                                    user_data))
1113         goto cleanup;
1114       if (! _gimp_wire_read_string (channel,
1115                                     &proc_install->params[i].name, 1,
1116                                     user_data))
1117         goto cleanup;
1118       if (! _gimp_wire_read_string (channel,
1119                                     &proc_install->params[i].description, 1,
1120                                     user_data))
1121         goto cleanup;
1122     }
1123 
1124   proc_install->return_vals = g_new0 (GPParamDef, proc_install->nreturn_vals);
1125 
1126   for (i = 0; i < proc_install->nreturn_vals; i++)
1127     {
1128       if (! _gimp_wire_read_int32 (channel,
1129                                    (guint32 *) &proc_install->return_vals[i].type, 1,
1130                                    user_data))
1131         goto cleanup;
1132       if (! _gimp_wire_read_string (channel,
1133                                     &proc_install->return_vals[i].name, 1,
1134                                     user_data))
1135         goto cleanup;
1136       if (! _gimp_wire_read_string (channel,
1137                                     &proc_install->return_vals[i].description, 1,
1138                                     user_data))
1139         goto cleanup;
1140     }
1141 
1142   msg->data = proc_install;
1143   return;
1144 
1145  cleanup:
1146   g_free (proc_install->name);
1147   g_free (proc_install->blurb);
1148   g_free (proc_install->help);
1149   g_free (proc_install->author);
1150   g_free (proc_install->copyright);
1151   g_free (proc_install->date);
1152   g_free (proc_install->menu_path);
1153   g_free (proc_install->image_types);
1154 
1155   if (proc_install->params)
1156     {
1157       for (i = 0; i < proc_install->nparams; i++)
1158         {
1159           if (!proc_install->params[i].name)
1160             break;
1161 
1162           g_free (proc_install->params[i].name);
1163           g_free (proc_install->params[i].description);
1164         }
1165 
1166       g_free (proc_install->params);
1167     }
1168 
1169   if (proc_install->return_vals)
1170     {
1171       for (i = 0; i < proc_install->nreturn_vals; i++)
1172         {
1173           if (!proc_install->return_vals[i].name)
1174             break;
1175 
1176           g_free (proc_install->return_vals[i].name);
1177           g_free (proc_install->return_vals[i].description);
1178         }
1179 
1180       g_free (proc_install->return_vals);
1181     }
1182 
1183   g_slice_free (GPProcInstall, proc_install);
1184   msg->data = NULL;
1185 }
1186 
1187 static void
_gp_proc_install_write(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)1188 _gp_proc_install_write (GIOChannel      *channel,
1189                         GimpWireMessage *msg,
1190                         gpointer         user_data)
1191 {
1192   GPProcInstall *proc_install = msg->data;
1193   gint           i;
1194 
1195   if (! _gimp_wire_write_string (channel,
1196                                  &proc_install->name, 1, user_data))
1197     return;
1198   if (! _gimp_wire_write_string (channel,
1199                                  &proc_install->blurb, 1, user_data))
1200     return;
1201   if (! _gimp_wire_write_string (channel,
1202                                  &proc_install->help, 1, user_data))
1203     return;
1204   if (! _gimp_wire_write_string (channel,
1205                                  &proc_install->author, 1, user_data))
1206     return;
1207   if (! _gimp_wire_write_string (channel,
1208                                  &proc_install->copyright, 1, user_data))
1209     return;
1210   if (! _gimp_wire_write_string (channel,
1211                                  &proc_install->date, 1, user_data))
1212     return;
1213   if (! _gimp_wire_write_string (channel,
1214                                  &proc_install->menu_path, 1, user_data))
1215     return;
1216   if (! _gimp_wire_write_string (channel,
1217                                  &proc_install->image_types, 1, user_data))
1218     return;
1219 
1220   if (! _gimp_wire_write_int32 (channel,
1221                                 &proc_install->type, 1, user_data))
1222     return;
1223   if (! _gimp_wire_write_int32 (channel,
1224                                 &proc_install->nparams, 1, user_data))
1225     return;
1226   if (! _gimp_wire_write_int32 (channel,
1227                                 &proc_install->nreturn_vals, 1, user_data))
1228     return;
1229 
1230   for (i = 0; i < proc_install->nparams; i++)
1231     {
1232       if (! _gimp_wire_write_int32 (channel,
1233                                     (guint32 *) &proc_install->params[i].type, 1,
1234                                     user_data))
1235         return;
1236       if (! _gimp_wire_write_string (channel,
1237                                      &proc_install->params[i].name, 1,
1238                                      user_data))
1239         return;
1240       if (! _gimp_wire_write_string (channel,
1241                                      &proc_install->params[i].description, 1,
1242                                      user_data))
1243         return;
1244     }
1245 
1246   for (i = 0; i < proc_install->nreturn_vals; i++)
1247     {
1248       if (! _gimp_wire_write_int32 (channel,
1249                                     (guint32 *) &proc_install->return_vals[i].type, 1,
1250                                     user_data))
1251         return;
1252       if (! _gimp_wire_write_string (channel,
1253                                      &proc_install->return_vals[i].name, 1,
1254                                      user_data))
1255         return;
1256       if (! _gimp_wire_write_string (channel,
1257                                      &proc_install->return_vals[i].description, 1,
1258                                      user_data))
1259         return;
1260     }
1261 }
1262 
1263 static void
_gp_proc_install_destroy(GimpWireMessage * msg)1264 _gp_proc_install_destroy (GimpWireMessage *msg)
1265 {
1266   GPProcInstall *proc_install = msg->data;
1267 
1268   if (proc_install)
1269     {
1270       gint i;
1271 
1272       g_free (proc_install->name);
1273       g_free (proc_install->blurb);
1274       g_free (proc_install->help);
1275       g_free (proc_install->author);
1276       g_free (proc_install->copyright);
1277       g_free (proc_install->date);
1278       g_free (proc_install->menu_path);
1279       g_free (proc_install->image_types);
1280 
1281       for (i = 0; i < proc_install->nparams; i++)
1282         {
1283           g_free (proc_install->params[i].name);
1284           g_free (proc_install->params[i].description);
1285         }
1286 
1287       for (i = 0; i < proc_install->nreturn_vals; i++)
1288         {
1289           g_free (proc_install->return_vals[i].name);
1290           g_free (proc_install->return_vals[i].description);
1291         }
1292 
1293       g_free (proc_install->params);
1294       g_free (proc_install->return_vals);
1295       g_slice_free (GPProcInstall, proc_install);
1296     }
1297 }
1298 
1299 /*  proc_uninstall  */
1300 
1301 static void
_gp_proc_uninstall_read(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)1302 _gp_proc_uninstall_read (GIOChannel      *channel,
1303                          GimpWireMessage *msg,
1304                          gpointer         user_data)
1305 {
1306   GPProcUninstall *proc_uninstall = g_slice_new0 (GPProcUninstall);
1307 
1308   if (! _gimp_wire_read_string (channel, &proc_uninstall->name, 1, user_data))
1309     goto cleanup;
1310 
1311   msg->data = proc_uninstall;
1312   return;
1313 
1314  cleanup:
1315   g_slice_free (GPProcUninstall, proc_uninstall);
1316 }
1317 
1318 static void
_gp_proc_uninstall_write(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)1319 _gp_proc_uninstall_write (GIOChannel      *channel,
1320                           GimpWireMessage *msg,
1321                           gpointer         user_data)
1322 {
1323   GPProcUninstall *proc_uninstall = msg->data;
1324 
1325   if (! _gimp_wire_write_string (channel, &proc_uninstall->name, 1, user_data))
1326     return;
1327 }
1328 
1329 static void
_gp_proc_uninstall_destroy(GimpWireMessage * msg)1330 _gp_proc_uninstall_destroy (GimpWireMessage *msg)
1331 {
1332   GPProcUninstall *proc_uninstall = msg->data;
1333 
1334   if (proc_uninstall)
1335     {
1336       g_free (proc_uninstall->name);
1337       g_slice_free (GPProcUninstall, proc_uninstall);
1338     }
1339 }
1340 
1341 /*  extension_ack  */
1342 
1343 static void
_gp_extension_ack_read(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)1344 _gp_extension_ack_read (GIOChannel      *channel,
1345                         GimpWireMessage *msg,
1346                         gpointer         user_data)
1347 {
1348 }
1349 
1350 static void
_gp_extension_ack_write(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)1351 _gp_extension_ack_write (GIOChannel      *channel,
1352                          GimpWireMessage *msg,
1353                          gpointer         user_data)
1354 {
1355 }
1356 
1357 static void
_gp_extension_ack_destroy(GimpWireMessage * msg)1358 _gp_extension_ack_destroy (GimpWireMessage *msg)
1359 {
1360 }
1361 
1362 /*  params  */
1363 
1364 static void
_gp_params_read(GIOChannel * channel,GPParam ** params,guint * nparams,gpointer user_data)1365 _gp_params_read (GIOChannel  *channel,
1366                  GPParam    **params,
1367                  guint       *nparams,
1368                  gpointer     user_data)
1369 {
1370   gint i, j;
1371 
1372   if (! _gimp_wire_read_int32 (channel, (guint32 *) nparams, 1, user_data))
1373     return;
1374 
1375   if (*nparams == 0)
1376     {
1377       *params = NULL;
1378       return;
1379     }
1380 
1381   *params = g_new0 (GPParam, *nparams);
1382 
1383   for (i = 0; i < *nparams; i++)
1384     {
1385       if (! _gimp_wire_read_int32 (channel,
1386                                    (guint32 *) &(*params)[i].type, 1,
1387                                    user_data))
1388         goto cleanup;
1389 
1390       switch ((*params)[i].type)
1391         {
1392         case GIMP_PDB_INT32:
1393           if (! _gimp_wire_read_int32 (channel,
1394                                        (guint32 *) &(*params)[i].data.d_int32, 1,
1395                                        user_data))
1396             goto cleanup;
1397           break;
1398 
1399         case GIMP_PDB_INT16:
1400           if (! _gimp_wire_read_int16 (channel,
1401                                        (guint16 *) &(*params)[i].data.d_int16, 1,
1402                                        user_data))
1403             goto cleanup;
1404           break;
1405 
1406         case GIMP_PDB_INT8:
1407           if (! _gimp_wire_read_int8 (channel,
1408                                       &(*params)[i].data.d_int8, 1,
1409                                       user_data))
1410             goto cleanup;
1411           break;
1412 
1413         case GIMP_PDB_FLOAT:
1414           if (! _gimp_wire_read_double (channel,
1415                                         &(*params)[i].data.d_float, 1,
1416                                         user_data))
1417             goto cleanup;
1418           break;
1419 
1420         case GIMP_PDB_STRING:
1421           if (! _gimp_wire_read_string (channel,
1422                                         &(*params)[i].data.d_string, 1,
1423                                         user_data))
1424             goto cleanup;
1425           break;
1426 
1427         case GIMP_PDB_INT32ARRAY:
1428           (*params)[i-1].data.d_int32 = MAX (0, (*params)[i-1].data.d_int32);
1429           (*params)[i].data.d_int32array = g_new (gint32,
1430                                                   (*params)[i-1].data.d_int32);
1431 
1432           if (! _gimp_wire_read_int32 (channel,
1433                                        (guint32 *) (*params)[i].data.d_int32array,
1434                                        (*params)[i-1].data.d_int32,
1435                                        user_data))
1436             {
1437               g_free ((*params)[i].data.d_int32array);
1438               goto cleanup;
1439             }
1440           break;
1441 
1442         case GIMP_PDB_INT16ARRAY:
1443           (*params)[i-1].data.d_int32 = MAX (0, (*params)[i-1].data.d_int32);
1444           (*params)[i].data.d_int16array = g_new (gint16,
1445                                                   (*params)[i-1].data.d_int32);
1446           if (! _gimp_wire_read_int16 (channel,
1447                                        (guint16 *) (*params)[i].data.d_int16array,
1448                                        (*params)[i-1].data.d_int32,
1449                                        user_data))
1450             {
1451               g_free ((*params)[i].data.d_int16array);
1452               goto cleanup;
1453             }
1454           break;
1455 
1456         case GIMP_PDB_INT8ARRAY:
1457           (*params)[i-1].data.d_int32 = MAX (0, (*params)[i-1].data.d_int32);
1458           (*params)[i].data.d_int8array = g_new (guint8,
1459                                                  (*params)[i-1].data.d_int32);
1460           if (! _gimp_wire_read_int8 (channel,
1461                                       (*params)[i].data.d_int8array,
1462                                       (*params)[i-1].data.d_int32,
1463                                       user_data))
1464             {
1465               g_free ((*params)[i].data.d_int8array);
1466               goto cleanup;
1467             }
1468           break;
1469 
1470         case GIMP_PDB_FLOATARRAY:
1471           (*params)[i-1].data.d_int32 = MAX (0, (*params)[i-1].data.d_int32);
1472           (*params)[i].data.d_floatarray = g_new (gdouble,
1473                                                   (*params)[i-1].data.d_int32);
1474           if (! _gimp_wire_read_double (channel,
1475                                         (*params)[i].data.d_floatarray,
1476                                         (*params)[i-1].data.d_int32,
1477                                         user_data))
1478             {
1479               g_free ((*params)[i].data.d_floatarray);
1480               goto cleanup;
1481             }
1482           break;
1483 
1484         case GIMP_PDB_STRINGARRAY:
1485           (*params)[i-1].data.d_int32 = MAX (0, (*params)[i-1].data.d_int32);
1486           (*params)[i].data.d_stringarray = g_new0 (gchar *,
1487                                                     (*params)[i-1].data.d_int32);
1488           if (! _gimp_wire_read_string (channel,
1489                                         (*params)[i].data.d_stringarray,
1490                                         (*params)[i-1].data.d_int32,
1491                                         user_data))
1492             {
1493               for (j = 0; j < (*params)[i-1].data.d_int32; j++)
1494                 g_free (((*params)[i].data.d_stringarray)[j]);
1495               g_free ((*params)[i].data.d_stringarray);
1496               goto cleanup;
1497             }
1498           break;
1499 
1500         case GIMP_PDB_COLOR:
1501           if (! _gimp_wire_read_color (channel,
1502                                        &(*params)[i].data.d_color, 1,
1503                                        user_data))
1504             goto cleanup;
1505           break;
1506 
1507         case GIMP_PDB_ITEM:
1508           if (! _gimp_wire_read_int32 (channel,
1509                                        (guint32 *) &(*params)[i].data.d_item, 1,
1510                                        user_data))
1511             goto cleanup;
1512           break;
1513 
1514         case GIMP_PDB_DISPLAY:
1515           if (! _gimp_wire_read_int32 (channel,
1516                                        (guint32 *) &(*params)[i].data.d_display, 1,
1517                                        user_data))
1518             goto cleanup;
1519           break;
1520 
1521         case GIMP_PDB_IMAGE:
1522           if (! _gimp_wire_read_int32 (channel,
1523                                        (guint32 *) &(*params)[i].data.d_image, 1,
1524                                        user_data))
1525             goto cleanup;
1526           break;
1527 
1528         case GIMP_PDB_LAYER:
1529           if (! _gimp_wire_read_int32 (channel,
1530                                        (guint32 *) &(*params)[i].data.d_layer, 1,
1531                                        user_data))
1532             goto cleanup;
1533           break;
1534 
1535         case GIMP_PDB_CHANNEL:
1536           if (! _gimp_wire_read_int32 (channel,
1537                                        (guint32 *) &(*params)[i].data.d_channel, 1,
1538                                        user_data))
1539             goto cleanup;
1540           break;
1541 
1542         case GIMP_PDB_DRAWABLE:
1543           if (! _gimp_wire_read_int32 (channel,
1544                                        (guint32 *) &(*params)[i].data.d_drawable, 1,
1545                                        user_data))
1546             goto cleanup;
1547           break;
1548 
1549         case GIMP_PDB_SELECTION:
1550           if (! _gimp_wire_read_int32 (channel,
1551                                        (guint32 *) &(*params)[i].data.d_selection, 1,
1552                                        user_data))
1553             goto cleanup;
1554           break;
1555 
1556         case GIMP_PDB_COLORARRAY:
1557           (*params)[i].data.d_colorarray = g_new (GimpRGB,
1558                                                   (*params)[i-1].data.d_int32);
1559           if (! _gimp_wire_read_color (channel,
1560                                        (*params)[i].data.d_colorarray,
1561                                        (*params)[i-1].data.d_int32,
1562                                        user_data))
1563             {
1564               g_free ((*params)[i].data.d_colorarray);
1565               goto cleanup;
1566             }
1567           break;
1568 
1569         case GIMP_PDB_VECTORS:
1570           if (! _gimp_wire_read_int32 (channel,
1571                                        (guint32 *) &(*params)[i].data.d_vectors, 1,
1572                                        user_data))
1573             goto cleanup;
1574           break;
1575 
1576         case GIMP_PDB_PARASITE:
1577           if (! _gimp_wire_read_string (channel,
1578                                         &(*params)[i].data.d_parasite.name, 1,
1579                                         user_data))
1580             goto cleanup;
1581           if ((*params)[i].data.d_parasite.name == NULL)
1582             {
1583               /* we have a null parasite */
1584               (*params)[i].data.d_parasite.data = NULL;
1585               break;
1586             }
1587           if (! _gimp_wire_read_int32 (channel,
1588                                        &((*params)[i].data.d_parasite.flags), 1,
1589                                        user_data))
1590             goto cleanup;
1591           if (! _gimp_wire_read_int32 (channel,
1592                                        &((*params)[i].data.d_parasite.size), 1,
1593                                        user_data))
1594             goto cleanup;
1595           if ((*params)[i].data.d_parasite.size > 0)
1596             {
1597               (*params)[i].data.d_parasite.data =
1598                 g_malloc ((*params)[i].data.d_parasite.size);
1599               if (! _gimp_wire_read_int8 (channel,
1600                                           (*params)[i].data.d_parasite.data,
1601                                           (*params)[i].data.d_parasite.size,
1602                                           user_data))
1603                 {
1604                   g_free ((*params)[i].data.d_parasite.data);
1605                   goto cleanup;
1606                 }
1607             }
1608           else
1609             (*params)[i].data.d_parasite.data = NULL;
1610           break;
1611 
1612         case GIMP_PDB_STATUS:
1613           if (! _gimp_wire_read_int32 (channel,
1614                                        (guint32 *) &(*params)[i].data.d_status, 1,
1615                                        user_data))
1616             goto cleanup;
1617           break;
1618 
1619         case GIMP_PDB_END:
1620           break;
1621         }
1622     }
1623 
1624   return;
1625 
1626  cleanup:
1627   *nparams = 0;
1628   g_free (*params);
1629   *params = NULL;
1630 }
1631 
1632 static void
_gp_params_write(GIOChannel * channel,GPParam * params,gint nparams,gpointer user_data)1633 _gp_params_write (GIOChannel *channel,
1634                   GPParam    *params,
1635                   gint        nparams,
1636                   gpointer    user_data)
1637 {
1638   gint i;
1639 
1640   if (! _gimp_wire_write_int32 (channel,
1641                                 (const guint32 *) &nparams, 1, user_data))
1642     return;
1643 
1644   for (i = 0; i < nparams; i++)
1645     {
1646       if (! _gimp_wire_write_int32 (channel,
1647                                     (const guint32 *) &params[i].type, 1,
1648                                     user_data))
1649         return;
1650 
1651       switch (params[i].type)
1652         {
1653         case GIMP_PDB_INT32:
1654           if (! _gimp_wire_write_int32 (channel,
1655                                         (const guint32 *) &params[i].data.d_int32, 1,
1656                                         user_data))
1657             return;
1658           break;
1659 
1660         case GIMP_PDB_INT16:
1661           if (! _gimp_wire_write_int16 (channel,
1662                                         (const guint16 *) &params[i].data.d_int16, 1,
1663                                         user_data))
1664             return;
1665           break;
1666 
1667         case GIMP_PDB_INT8:
1668           if (! _gimp_wire_write_int8 (channel,
1669                                        (const guint8 *) &params[i].data.d_int8, 1,
1670                                        user_data))
1671             return;
1672           break;
1673 
1674         case GIMP_PDB_FLOAT:
1675           if (! _gimp_wire_write_double (channel,
1676                                          &params[i].data.d_float, 1,
1677                                          user_data))
1678             return;
1679           break;
1680 
1681         case GIMP_PDB_STRING:
1682           if (! _gimp_wire_write_string (channel,
1683                                          &params[i].data.d_string, 1,
1684                                          user_data))
1685             return;
1686           break;
1687 
1688         case GIMP_PDB_INT32ARRAY:
1689           if (! _gimp_wire_write_int32 (channel,
1690                                         (const guint32 *) params[i].data.d_int32array,
1691                                         params[i-1].data.d_int32,
1692                                         user_data))
1693             return;
1694           break;
1695 
1696         case GIMP_PDB_INT16ARRAY:
1697           if (! _gimp_wire_write_int16 (channel,
1698                                         (const guint16 *) params[i].data.d_int16array,
1699                                         params[i-1].data.d_int32,
1700                                         user_data))
1701             return;
1702           break;
1703 
1704         case GIMP_PDB_INT8ARRAY:
1705           if (! _gimp_wire_write_int8 (channel,
1706                                        (const guint8 *) params[i].data.d_int8array,
1707                                        params[i-1].data.d_int32,
1708                                        user_data))
1709             return;
1710           break;
1711 
1712         case GIMP_PDB_FLOATARRAY:
1713           if (! _gimp_wire_write_double (channel,
1714                                          params[i].data.d_floatarray,
1715                                          params[i-1].data.d_int32,
1716                                          user_data))
1717             return;
1718           break;
1719 
1720         case GIMP_PDB_STRINGARRAY:
1721           if (! _gimp_wire_write_string (channel,
1722                                          params[i].data.d_stringarray,
1723                                          params[i-1].data.d_int32,
1724                                          user_data))
1725             return;
1726           break;
1727 
1728         case GIMP_PDB_COLOR:
1729           if (! _gimp_wire_write_color (channel,
1730                                         &params[i].data.d_color, 1, user_data))
1731             return;
1732           break;
1733 
1734         case GIMP_PDB_ITEM:
1735           if (! _gimp_wire_write_int32 (channel,
1736                                         (const guint32 *) &params[i].data.d_item, 1,
1737                                         user_data))
1738             return;
1739           break;
1740 
1741         case GIMP_PDB_DISPLAY:
1742           if (! _gimp_wire_write_int32 (channel,
1743                                         (const guint32 *) &params[i].data.d_display, 1,
1744                                         user_data))
1745             return;
1746           break;
1747 
1748         case GIMP_PDB_IMAGE:
1749           if (! _gimp_wire_write_int32 (channel,
1750                                         (const guint32 *) &params[i].data.d_image, 1,
1751                                         user_data))
1752             return;
1753           break;
1754 
1755         case GIMP_PDB_LAYER:
1756           if (! _gimp_wire_write_int32 (channel,
1757                                         (const guint32 *) &params[i].data.d_layer, 1,
1758                                         user_data))
1759             return;
1760           break;
1761 
1762         case GIMP_PDB_CHANNEL:
1763           if (! _gimp_wire_write_int32 (channel,
1764                                         (const guint32 *) &params[i].data.d_channel, 1,
1765                                         user_data))
1766             return;
1767           break;
1768 
1769         case GIMP_PDB_DRAWABLE:
1770           if (! _gimp_wire_write_int32 (channel,
1771                                         (const guint32 *) &params[i].data.d_drawable, 1,
1772                                         user_data))
1773             return;
1774           break;
1775 
1776         case GIMP_PDB_SELECTION:
1777           if (! _gimp_wire_write_int32 (channel,
1778                                         (const guint32 *) &params[i].data.d_selection, 1,
1779                                         user_data))
1780             return;
1781           break;
1782 
1783         case GIMP_PDB_COLORARRAY:
1784           if (! _gimp_wire_write_color (channel,
1785                                         params[i].data.d_colorarray,
1786                                         params[i-1].data.d_int32,
1787                                         user_data))
1788             return;
1789           break;
1790 
1791         case GIMP_PDB_VECTORS:
1792           if (! _gimp_wire_write_int32 (channel,
1793                                         (const guint32 *) &params[i].data.d_vectors, 1,
1794                                         user_data))
1795             return;
1796           break;
1797 
1798         case GIMP_PDB_PARASITE:
1799           {
1800             GimpParasite *p = &params[i].data.d_parasite;
1801 
1802             if (p->name == NULL)
1803               {
1804                 /* write a null string to signal a null parasite */
1805                 _gimp_wire_write_string (channel,  &p->name, 1, user_data);
1806                 break;
1807               }
1808 
1809             if (! _gimp_wire_write_string (channel, &p->name, 1, user_data))
1810               return;
1811             if (! _gimp_wire_write_int32 (channel, &p->flags, 1, user_data))
1812               return;
1813             if (! _gimp_wire_write_int32 (channel, &p->size, 1, user_data))
1814               return;
1815             if (p->size > 0)
1816               {
1817                 if (! _gimp_wire_write_int8 (channel,
1818                                              p->data, p->size, user_data))
1819                   return;
1820               }
1821           }
1822           break;
1823 
1824         case GIMP_PDB_STATUS:
1825           if (! _gimp_wire_write_int32 (channel,
1826                                         (const guint32 *) &params[i].data.d_status, 1,
1827                                         user_data))
1828             return;
1829           break;
1830 
1831         case GIMP_PDB_END:
1832           break;
1833         }
1834     }
1835 }
1836 
1837 void
gp_params_destroy(GPParam * params,gint nparams)1838 gp_params_destroy (GPParam *params,
1839                    gint     nparams)
1840 {
1841   gint i;
1842 
1843   for (i = 0; i < nparams; i++)
1844     {
1845       switch (params[i].type)
1846         {
1847         case GIMP_PDB_INT32:
1848         case GIMP_PDB_INT16:
1849         case GIMP_PDB_INT8:
1850         case GIMP_PDB_FLOAT:
1851         case GIMP_PDB_COLOR:
1852         case GIMP_PDB_ITEM:
1853         case GIMP_PDB_DISPLAY:
1854         case GIMP_PDB_IMAGE:
1855         case GIMP_PDB_LAYER:
1856         case GIMP_PDB_CHANNEL:
1857         case GIMP_PDB_DRAWABLE:
1858         case GIMP_PDB_SELECTION:
1859         case GIMP_PDB_VECTORS:
1860         case GIMP_PDB_STATUS:
1861           break;
1862 
1863         case GIMP_PDB_STRING:
1864           g_free (params[i].data.d_string);
1865           break;
1866 
1867         case GIMP_PDB_INT32ARRAY:
1868           g_free (params[i].data.d_int32array);
1869           break;
1870 
1871         case GIMP_PDB_INT16ARRAY:
1872           g_free (params[i].data.d_int16array);
1873           break;
1874 
1875         case GIMP_PDB_INT8ARRAY:
1876           g_free (params[i].data.d_int8array);
1877           break;
1878 
1879         case GIMP_PDB_FLOATARRAY:
1880           g_free (params[i].data.d_floatarray);
1881           break;
1882 
1883         case GIMP_PDB_STRINGARRAY:
1884           if ((i > 0) && (params[i-1].type == GIMP_PDB_INT32))
1885             {
1886               gint count = params[i-1].data.d_int32;
1887               gint j;
1888 
1889               for (j = 0; j < count; j++)
1890                 g_free (params[i].data.d_stringarray[j]);
1891 
1892               g_free (params[i].data.d_stringarray);
1893             }
1894           break;
1895 
1896         case GIMP_PDB_COLORARRAY:
1897           g_free (params[i].data.d_colorarray);
1898           break;
1899 
1900         case GIMP_PDB_PARASITE:
1901           if (params[i].data.d_parasite.name)
1902             g_free (params[i].data.d_parasite.name);
1903           if (params[i].data.d_parasite.data)
1904             g_free (params[i].data.d_parasite.data);
1905           break;
1906 
1907         case GIMP_PDB_END:
1908           break;
1909         }
1910     }
1911 
1912   g_free (params);
1913 }
1914 
1915 /* has_init */
1916 
1917 static void
_gp_has_init_read(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)1918 _gp_has_init_read (GIOChannel      *channel,
1919                    GimpWireMessage *msg,
1920                    gpointer         user_data)
1921 {
1922 }
1923 
1924 static void
_gp_has_init_write(GIOChannel * channel,GimpWireMessage * msg,gpointer user_data)1925 _gp_has_init_write (GIOChannel      *channel,
1926                     GimpWireMessage *msg,
1927                     gpointer         user_data)
1928 {
1929 }
1930 
1931 static void
_gp_has_init_destroy(GimpWireMessage * msg)1932 _gp_has_init_destroy (GimpWireMessage *msg)
1933 {
1934 }
1935