Properly clean up when timing out on a keystroke listener
[platform/core/uifw/at-spi2-atk.git] / droute / droute.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2008 Novell, Inc.
6  * Copyright 2008 Codethink Ltd.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 #include <stdlib.h>
25 #include <string.h>
26 #include <stdio.h>
27
28 #include "droute.h"
29 #include "droute-pairhash.h"
30
31 #define CHUNKS_DEFAULT (512)
32
33 #define oom() g_error ("D-Bus out of memory, this message will fail anyway")
34
35 #if defined DROUTE_DEBUG
36     #define _DROUTE_DEBUG(format, args...) g_print (format , ## args)
37 #else
38     #define _DROUTE_DEBUG(format, args...)
39 #endif
40
41 struct _DRouteContext
42 {
43     GPtrArray            *registered_paths;
44
45     gchar                *introspect_string;
46 };
47
48 struct _DRoutePath
49 {
50     DRouteContext        *cnx;
51     gchar *path;
52     gboolean prefix;
53     GStringChunk         *chunks;
54     GPtrArray            *interfaces;
55     GPtrArray            *introspection;
56     GHashTable           *methods;
57     GHashTable           *properties;
58
59     DRouteIntrospectChildrenFunction introspect_children_cb;
60     void *introspect_children_data;
61     void                   *user_data;
62     DRouteGetDatumFunction  get_datum;
63 };
64
65 /*---------------------------------------------------------------------------*/
66
67 typedef struct PropertyPair
68 {
69     DRoutePropertyFunction get;
70     DRoutePropertyFunction set;
71 } PropertyPair;
72
73 /*---------------------------------------------------------------------------*/
74
75 static DBusHandlerResult
76 handle_message (DBusConnection *bus, DBusMessage *message, void *user_data);
77
78 static DBusMessage *
79 droute_object_does_not_exist_error (DBusMessage *message);
80
81 /*---------------------------------------------------------------------------*/
82
83 static DRoutePath *
84 path_new (DRouteContext *cnx,
85           const char *path,
86           gboolean prefix,
87           void    *user_data,
88           DRouteIntrospectChildrenFunction introspect_children_cb,
89           void *introspect_children_data,
90           DRouteGetDatumFunction get_datum)
91 {
92     DRoutePath *new_path;
93
94     new_path = g_new0 (DRoutePath, 1);
95     new_path->cnx = cnx;
96     new_path->path = g_strdup (path);
97     new_path->prefix = prefix;
98     new_path->chunks = g_string_chunk_new (CHUNKS_DEFAULT);
99     new_path->interfaces = g_ptr_array_new ();
100     new_path->introspection = g_ptr_array_new ();
101
102     new_path->methods = g_hash_table_new_full ((GHashFunc)str_pair_hash,
103                                                str_pair_equal,
104                                                g_free,
105                                                NULL);
106
107     new_path->properties = g_hash_table_new_full ((GHashFunc)str_pair_hash,
108                                                   str_pair_equal,
109                                                   g_free,
110                                                   g_free);
111
112     new_path->introspect_children_cb = introspect_children_cb;
113     new_path->introspect_children_data = introspect_children_data;
114     new_path->user_data = user_data;
115     new_path->get_datum = get_datum;
116
117     return new_path;
118 }
119
120 static void
121 path_free (DRoutePath *path, gpointer user_data)
122 {
123     g_free (path->path);
124     g_string_chunk_free  (path->chunks);
125     g_ptr_array_free     (path->interfaces, TRUE);
126     g_free(g_ptr_array_free     (path->introspection, FALSE));
127     g_hash_table_destroy (path->methods);
128     g_hash_table_destroy (path->properties);
129     g_free (path);
130 }
131
132 static void *
133 path_get_datum (DRoutePath *path, const gchar *pathstr)
134 {
135     if (path->get_datum != NULL)
136         return (path->get_datum) (pathstr, path->user_data);
137     else
138         return path->user_data;
139 }
140
141 /*---------------------------------------------------------------------------*/
142
143 DRouteContext *
144 droute_new ()
145 {
146     DRouteContext *cnx;
147
148     cnx = g_new0 (DRouteContext, 1);
149     cnx->registered_paths = g_ptr_array_new ();
150
151     return cnx;
152 }
153
154 void
155 droute_free (DRouteContext *cnx)
156 {
157     g_ptr_array_foreach (cnx->registered_paths, (GFunc) path_free, NULL);
158     g_ptr_array_free (cnx->registered_paths, TRUE);
159     g_free (cnx);
160 }
161
162 /*---------------------------------------------------------------------------*/
163
164 /*---------------------------------------------------------------------------*/
165
166 static DBusObjectPathVTable droute_vtable =
167 {
168   NULL,
169   &handle_message,
170   NULL, NULL, NULL, NULL
171 };
172
173 DRoutePath *
174 droute_add_one (DRouteContext *cnx,
175                 const char    *path,
176                 const void    *data)
177 {
178     DRoutePath *new_path;
179
180     new_path = path_new (cnx, path, FALSE, (void *)data, NULL, NULL, NULL);
181
182     g_ptr_array_add (cnx->registered_paths, new_path);
183     return new_path;
184 }
185
186 DRoutePath *
187 droute_add_many (DRouteContext *cnx,
188                  const char    *path,
189                  const void    *data,
190                  DRouteIntrospectChildrenFunction introspect_children_cb,
191                  void *introspect_children_data,
192                  const DRouteGetDatumFunction get_datum)
193 {
194     DRoutePath *new_path;
195
196     new_path = path_new (cnx, path, TRUE, (void *) data,
197                          introspect_children_cb, introspect_children_data,
198                          get_datum);
199
200     g_ptr_array_add (cnx->registered_paths, new_path);
201     return new_path;
202 }
203
204 /*---------------------------------------------------------------------------*/
205
206 void
207 droute_path_add_interface(DRoutePath *path,
208                           const char *name,
209                           const char *introspect,
210                           const DRouteMethod   *methods,
211                           const DRouteProperty *properties)
212 {
213     gchar *itf;
214
215     g_return_if_fail (name != NULL);
216
217     itf = g_string_chunk_insert (path->chunks, name);
218     g_ptr_array_add (path->interfaces, itf);
219     g_ptr_array_add (path->introspection, (gpointer) introspect);
220
221     for (; methods != NULL && methods->name != NULL; methods++)
222       {
223         gchar *meth;
224
225         meth = g_string_chunk_insert (path->chunks, methods->name);
226         g_hash_table_insert (path->methods, str_pair_new (itf, meth), methods->func);
227       }
228
229     for (; properties != NULL && properties->name != NULL; properties++)
230       {
231         gchar *prop;
232         PropertyPair *pair;
233
234         prop = g_string_chunk_insert (path->chunks, properties->name);
235         pair = g_new (PropertyPair, 1);
236         pair->get = properties->get;
237         pair->set = properties->set;
238         g_hash_table_insert (path->properties, str_pair_new (itf, prop), pair);
239       }
240 }
241
242 /*---------------------------------------------------------------------------*/
243
244 /* The data structures don't support an efficient implementation of GetAll
245  * and I don't really care.
246  */
247 static DBusMessage *
248 impl_prop_GetAll (DBusMessage *message,
249                   DRoutePath  *path,
250                   const char  *pathstr)
251 {
252     DBusMessageIter iter, iter_dict, iter_dict_entry;
253     DBusMessage *reply;
254     DBusError error;
255     GHashTableIter prop_iter;
256
257     StrPair *key;
258     PropertyPair *value;
259     gchar *iface;
260
261     void  *datum = path_get_datum (path, pathstr);
262     if (!datum)
263         return droute_object_does_not_exist_error (message);
264
265     dbus_error_init (&error);
266     if (!dbus_message_get_args
267                 (message, &error, DBUS_TYPE_STRING, &iface, DBUS_TYPE_INVALID))
268       {
269         DBusMessage *ret;
270         ret = dbus_message_new_error (message, DBUS_ERROR_FAILED, error.message);
271         dbus_error_free (&error);
272         return ret;
273       }
274
275     reply = dbus_message_new_method_return (message);
276     if (!reply)
277         oom ();
278
279     dbus_message_iter_init_append (reply, &iter);
280     if (!dbus_message_iter_open_container
281                 (&iter, DBUS_TYPE_ARRAY, "{sv}", &iter_dict))
282         oom ();
283
284     g_hash_table_iter_init (&prop_iter, path->properties);
285     while (g_hash_table_iter_next (&prop_iter, (gpointer*)&key, (gpointer*)&value))
286       {
287         if (!g_strcmp0 (key->one, iface))
288          {
289            if (!value->get)
290               continue;
291            if (!dbus_message_iter_open_container
292                         (&iter_dict, DBUS_TYPE_DICT_ENTRY, NULL, &iter_dict_entry))
293               oom ();
294            dbus_message_iter_append_basic (&iter_dict_entry, DBUS_TYPE_STRING,
295                                            &key->two);
296            (value->get) (&iter_dict_entry, datum);
297            if (!dbus_message_iter_close_container (&iter_dict, &iter_dict_entry))
298                oom ();
299          }
300       }
301
302     if (!dbus_message_iter_close_container (&iter, &iter_dict))
303         oom ();
304     return reply;
305 }
306
307 static DBusMessage *
308 impl_prop_GetSet (DBusMessage *message,
309                   DRoutePath  *path,
310                   const char  *pathstr,
311                   gboolean     get)
312 {
313     DBusMessage *reply = NULL;
314     DBusError error;
315
316     StrPair pair;
317     PropertyPair *prop_funcs = NULL;
318
319     void *datum;
320
321     dbus_error_init (&error);
322     if (!dbus_message_get_args (message,
323                                 &error,
324                                 DBUS_TYPE_STRING,
325                                 &(pair.one),
326                                 DBUS_TYPE_STRING,
327                                 &(pair.two),
328                                 DBUS_TYPE_INVALID))
329       {
330         DBusMessage *ret;
331         ret = dbus_message_new_error (message, DBUS_ERROR_FAILED, error.message);
332         dbus_error_free (&error);
333       }
334
335     _DROUTE_DEBUG ("DRoute (handle prop): %s|%s on %s\n", pair.one, pair.two, pathstr);
336
337     prop_funcs = (PropertyPair *) g_hash_table_lookup (path->properties, &pair);
338     if (!prop_funcs)
339       {
340         DBusMessage *ret;
341 #ifdef DBUS_ERROR_UNKNOWN_PROPERTY
342         ret = dbus_message_new_error (message, DBUS_ERROR_UNKNOWN_PROPERTY, "Property unavailable");
343 #else
344         ret = dbus_message_new_error (message, DBUS_ERROR_FAILED, "Property unavailable");
345 #endif
346         dbus_error_free (&error);
347         return ret;
348       }
349
350     datum = path_get_datum (path, pathstr);
351     if (!datum)
352         return droute_object_does_not_exist_error (message);
353
354     if (get && prop_funcs->get)
355       {
356         
357         DBusMessageIter iter;
358
359         _DROUTE_DEBUG ("DRoute (handle prop Get): %s|%s on %s\n", pair.one, pair.two, pathstr);
360
361         reply = dbus_message_new_method_return (message);
362         dbus_message_iter_init_append (reply, &iter);
363         if (!(prop_funcs->get) (&iter, datum))
364           {
365             dbus_message_unref (reply);
366             reply = dbus_message_new_error (message, DBUS_ERROR_FAILED, "Get failed");
367           }
368       }
369     else if (!get && prop_funcs->set)
370       {
371         DBusMessageIter iter;
372
373         _DROUTE_DEBUG ("DRoute (handle prop Get): %s|%s on %s\n", pair.one, pair.two, pathstr);
374
375         dbus_message_iter_init (message, &iter);
376         /* Skip the interface and property name */
377         dbus_message_iter_next(&iter);
378         dbus_message_iter_next(&iter);
379         (prop_funcs->set) (&iter, datum);
380
381         reply = dbus_message_new_method_return (message);
382       }
383 #ifdef DBUS_ERROR_PROPERTY_READ_ONLY
384     else if (!get)
385       {
386         reply = dbus_message_new_error (message, DBUS_ERROR_PROPERTY_READ_ONLY, "Property is read-only");
387       }
388 #endif
389     else
390       {
391         reply = dbus_message_new_error (message, DBUS_ERROR_FAILED, "Getter or setter unavailable");
392       }
393
394     return reply;
395 }
396
397 static DBusHandlerResult
398 handle_dbus (DBusConnection *bus,
399                    DBusMessage    *message,
400                    const gchar    *iface,
401                    const gchar    *member,
402                    const gchar    *pathstr)
403 {
404   static int id = 1;
405   char *id_str = (char *) g_malloc(40);
406   DBusMessage *reply;
407
408   if (strcmp (iface, DBUS_INTERFACE_DBUS) != 0 ||
409       strcmp (member, "Hello") != 0)
410     {
411       g_free (id_str);
412       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
413     }
414
415     /* TODO: Fix this hack (we don't handle wrap-around, for instance) */
416     sprintf (id_str, ":1.%d", id++);
417     reply = dbus_message_new_method_return (message);
418     dbus_message_append_args (reply, DBUS_TYPE_STRING, &id_str, DBUS_TYPE_INVALID);
419     dbus_connection_send (bus, reply, NULL);
420   dbus_connection_flush (bus);
421     dbus_message_unref (reply);
422   g_free (id_str);
423     return DBUS_HANDLER_RESULT_HANDLED;
424 }
425
426 static DBusHandlerResult
427 handle_properties (DBusConnection *bus,
428                    DBusMessage    *message,
429                    DRoutePath     *path,
430                    const gchar    *iface,
431                    const gchar    *member,
432                    const gchar    *pathstr)
433 {
434     DBusMessage *reply = NULL;
435     DBusHandlerResult result = DBUS_HANDLER_RESULT_HANDLED;
436
437     if (!g_strcmp0(member, "GetAll"))
438        reply = impl_prop_GetAll (message, path, pathstr);
439     else if (!g_strcmp0 (member, "Get"))
440        reply = impl_prop_GetSet (message, path, pathstr, TRUE);
441     else if (!g_strcmp0 (member, "Set"))
442        reply = impl_prop_GetSet (message, path, pathstr, FALSE);
443     else
444        result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
445
446     if (reply)
447       {
448         dbus_connection_send (bus, reply, NULL);
449         dbus_message_unref (reply);
450       }
451
452     return result;
453 }
454
455 /*---------------------------------------------------------------------------*/
456
457 static const char *introspection_header =
458 "<?xml version=\"1.0\"?>\n";
459
460 static const char *introspection_node_element =
461 "<node name=\"%s\">\n";
462
463 static const char *introspection_footer =
464 "</node>";
465
466 static DBusHandlerResult
467 handle_introspection (DBusConnection *bus,
468                       DBusMessage    *message,
469                       DRoutePath     *path,
470                       const gchar    *iface,
471                       const gchar    *member,
472                       const gchar    *pathstr)
473 {
474     GString *output;
475     gchar *final;
476     gint i;
477
478     DBusMessage *reply;
479
480     _DROUTE_DEBUG ("DRoute (handle introspection): %s\n", pathstr);
481
482     if (g_strcmp0 (member, "Introspect"))
483         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
484
485     output = g_string_new(introspection_header);
486
487     g_string_append_printf(output, introspection_node_element, pathstr);
488
489     if (!path->get_datum || path_get_datum (path, pathstr))
490       {
491         for (i=0; i < path->introspection->len; i++)
492           {
493             gchar *introspect = (gchar *) g_ptr_array_index (path->introspection, i);
494             g_string_append (output, introspect);
495           }
496       }
497
498     if (path->introspect_children_cb)
499       {
500         gchar *children = (*path->introspect_children_cb) (pathstr, path->introspect_children_data);
501         if (children)
502           {
503             g_string_append (output, children);
504             g_free (children);
505           }
506       }
507
508     g_string_append(output, introspection_footer);
509     final = g_string_free(output, FALSE);
510
511     reply = dbus_message_new_method_return (message);
512     if (!reply)
513         oom ();
514     dbus_message_append_args(reply, DBUS_TYPE_STRING, &final,
515                              DBUS_TYPE_INVALID);
516     dbus_connection_send (bus, reply, NULL);
517
518     dbus_message_unref (reply);
519     g_free(final);
520     return DBUS_HANDLER_RESULT_HANDLED;
521 }
522
523 /*---------------------------------------------------------------------------*/
524
525 static DBusHandlerResult
526 handle_other (DBusConnection *bus,
527               DBusMessage    *message,
528               DRoutePath     *path,
529               const gchar    *iface,
530               const gchar    *member,
531               const gchar    *pathstr)
532 {
533     gint result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
534
535     StrPair pair;
536     DRouteFunction func;
537     DBusMessage *reply = NULL;
538
539     void *datum;
540
541     pair.one = iface;
542     pair.two = member;
543
544     _DROUTE_DEBUG ("DRoute (handle other): %s|%s on %s\n", member, iface, pathstr);
545
546     func = (DRouteFunction) g_hash_table_lookup (path->methods, &pair);
547     if (func != NULL)
548       {
549         datum = path_get_datum (path, pathstr);
550         if (!datum)
551             reply = droute_object_does_not_exist_error (message);
552         else
553             reply = (func) (bus, message, datum);
554
555         /* All D-Bus method calls must have a reply.
556          * If one is not provided presume that the caller has already
557          * sent one.
558          */
559         if (reply)
560           {
561             dbus_connection_send (bus, reply, NULL);
562             dbus_message_unref (reply);
563           }
564         result = DBUS_HANDLER_RESULT_HANDLED;
565       }
566
567     _DROUTE_DEBUG ("DRoute (handle other) (reply): type %d\n",
568                    dbus_message_get_type(reply));
569     return result;
570 }
571
572 /*---------------------------------------------------------------------------*/
573
574 static DBusHandlerResult
575 handle_message (DBusConnection *bus, DBusMessage *message, void *user_data)
576 {
577     DRoutePath *path = (DRoutePath *) user_data;
578     const gchar *iface   = dbus_message_get_interface (message);
579     const gchar *member  = dbus_message_get_member (message);
580     const gint   type    = dbus_message_get_type (message);
581     const gchar *pathstr = dbus_message_get_path (message);
582
583     DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
584
585     _DROUTE_DEBUG ("DRoute (handle message): %s|%s of type %d on %s\n", member, iface, type, pathstr);
586
587     /* Check for basic reasons not to handle */
588     if (type   != DBUS_MESSAGE_TYPE_METHOD_CALL ||
589         member == NULL ||
590         iface  == NULL)
591         return result;
592
593     if (!strcmp (pathstr, DBUS_PATH_DBUS))
594         result = handle_dbus (bus, message, iface, member, pathstr);
595     else if (!strcmp (iface, "org.freedesktop.DBus.Properties"))
596         result = handle_properties (bus, message, path, iface, member, pathstr);
597     else if (!strcmp (iface, "org.freedesktop.DBus.Introspectable"))
598         result = handle_introspection (bus, message, path, iface, member, pathstr);
599     else
600         result = handle_other (bus, message, path, iface, member, pathstr);
601 #if 0
602     if (result == DBUS_HANDLER_RESULT_NOT_YET_HANDLED)
603         g_print ("DRoute | Unhandled message: %s|%s of type %d on %s\n", member, iface, type, pathstr);
604 #endif
605       
606     return result;
607 }
608
609 /*---------------------------------------------------------------------------*/
610
611 static DBusMessage *
612 droute_object_does_not_exist_error (DBusMessage *message)
613 {
614     DBusMessage *reply;
615     gchar       *errmsg;
616
617     errmsg= g_strdup_printf (
618             "Method \"%s\" with signature \"%s\" on interface \"%s\" could not be processed as object %s does not exist\n",
619             dbus_message_get_member (message),
620             dbus_message_get_signature (message),
621             dbus_message_get_interface (message),
622             dbus_message_get_path (message));
623 #ifdef DBUS_ERROR_UNKNOWN_OBJECT
624     reply = dbus_message_new_error (message,
625                                     DBUS_ERROR_UNKNOWN_OBJECT,
626                                     errmsg);
627 #else
628     reply = dbus_message_new_error (message,
629                                     DBUS_ERROR_FAILED,
630                                     errmsg);
631 #endif
632     g_free (errmsg);
633     return reply;
634 }
635
636 /*---------------------------------------------------------------------------*/
637
638 DBusMessage *
639 droute_not_yet_handled_error (DBusMessage *message)
640 {
641     DBusMessage *reply;
642     gchar       *errmsg;
643
644     errmsg= g_strdup_printf (
645             "Method \"%s\" with signature \"%s\" on interface \"%s\" doesn't exist\n",
646             dbus_message_get_member (message),
647             dbus_message_get_signature (message),
648             dbus_message_get_interface (message));
649     reply = dbus_message_new_error (message,
650                                     DBUS_ERROR_UNKNOWN_METHOD,
651                                     errmsg);
652     g_free (errmsg);
653     return reply;
654 }
655
656 DBusMessage *
657 droute_out_of_memory_error (DBusMessage *message)
658 {
659     DBusMessage *reply;
660     gchar       *errmsg;
661
662     errmsg= g_strdup_printf (
663             "Method \"%s\" with signature \"%s\" on interface \"%s\" could not be processed due to lack of memory\n",
664             dbus_message_get_member (message),
665             dbus_message_get_signature (message),
666             dbus_message_get_interface (message));
667     reply = dbus_message_new_error (message,
668                                     DBUS_ERROR_NO_MEMORY,
669                                     errmsg);
670     g_free (errmsg);
671     return reply;
672 }
673
674 DBusMessage *
675 droute_invalid_arguments_error (DBusMessage *message)
676 {
677     DBusMessage *reply;
678     gchar       *errmsg;
679
680     errmsg= g_strdup_printf (
681             "Method \"%s\" with signature \"%s\" on interface \"%s\" was supplied with invalid arguments\n",
682             dbus_message_get_member (message),
683             dbus_message_get_signature (message),
684             dbus_message_get_interface (message));
685     reply = dbus_message_new_error (message,
686                                     DBUS_ERROR_INVALID_ARGS,
687                                     errmsg);
688     g_free (errmsg);
689     return reply;
690 }
691
692 void
693 droute_path_register (DRoutePath *path, DBusConnection *bus)
694 {
695     if (path->prefix)
696       dbus_connection_register_fallback (bus, path->path, &droute_vtable, path);
697     else
698       dbus_connection_register_object_path (bus, path->path,
699                                             &droute_vtable, path);
700 }
701
702 void
703 droute_path_unregister (DRoutePath *path, DBusConnection *bus)
704 {
705   dbus_connection_unregister_object_path (bus, path->path);
706 }
707
708 void
709 droute_context_register (DRouteContext *cnx, DBusConnection *bus)
710 {
711     g_ptr_array_foreach (cnx->registered_paths, (GFunc) droute_path_register,
712                          bus);
713 }
714
715 void
716 droute_context_unregister (DRouteContext *cnx, DBusConnection *bus)
717 {
718     g_ptr_array_foreach (cnx->registered_paths, (GFunc) droute_path_unregister,
719                          bus);
720 }
721
722 void
723 droute_context_deregister (DRouteContext *cnx, DBusConnection *bus)
724 {
725     g_ptr_array_foreach (cnx->registered_paths, (GFunc) droute_path_unregister,
726                          bus);
727 }
728
729 void
730 droute_intercept_dbus (DBusConnection *bus)
731 {
732     dbus_connection_register_object_path (bus, DBUS_PATH_DBUS,
733                                           &droute_vtable, NULL);
734 }
735
736 void
737 droute_unintercept_dbus (DBusConnection *bus)
738 {
739     dbus_connection_unregister_object_path (bus, DBUS_PATH_DBUS);
740 }
741
742 /*END------------------------------------------------------------------------*/