1
/*
2
 * AT-SPI - Assistive Technology Service Provider Interface
3
 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4
 *
5
 * Copyright 2008, 2009 Codethink Ltd.
6
 * Copyright 2001, 2002, 2003 Sun Microsystems Inc.,
7
 * Copyright 2001, 2002, 2003 Ximian, Inc.
8
 *
9
 * This library is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU Lesser General Public
11
 * License as published by the Free Software Foundation; either
12
 * version 2.1 of the License, or (at your option) any later version.
13
 *
14
 * This library is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 * Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public
20
 * License along with this library; if not, write to the
21
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22
 * Boston, MA 02110-1301, USA.
23
 */
24

            
25
#include "config.h"
26

            
27
#include <atk/atk.h>
28
#include <stdarg.h>
29
#include <stdio.h>
30
#include <stdlib.h>
31
#include <string.h>
32
#include <strings.h>
33
#include <sys/stat.h>
34
#include <unistd.h>
35

            
36
#include <atk-bridge.h>
37
#include <atspi/atspi.h>
38
#include <droute/droute.h>
39

            
40
#include "accessible-stateset.h"
41
#include "adaptors.h"
42
#include "bridge.h"
43
#include "event.h"
44
#include "object.h"
45

            
46
#include "accessible-cache.h"
47
#include "accessible-leasing.h"
48
#include "accessible-register.h"
49

            
50
#include "spi-dbus.h"
51

            
52
/*---------------------------------------------------------------------------*/
53

            
54
static DBusHandlerResult
55
signal_filter (DBusConnection *bus, DBusMessage *message, void *user_data);
56

            
57
SpiBridge *spi_global_app_data = NULL;
58

            
59
static gboolean inited = FALSE;
60
static gboolean atexit_added = FALSE;
61

            
62
/*---------------------------------------------------------------------------*/
63

            
64
static event_data *
65
161
add_event (const char *bus_name, const char *event)
66
{
67
  event_data *evdata;
68
  gchar **data;
69

            
70
161
  spi_atk_add_client (bus_name);
71
161
  evdata = g_new0 (event_data, 1);
72
161
  data = g_strsplit (event, ":", 3);
73
161
  if (!data)
74
    {
75
      g_free (evdata);
76
      return NULL;
77
    }
78
161
  evdata->bus_name = g_strdup (bus_name);
79
161
  evdata->data = data;
80
161
  spi_global_app_data->events = g_list_append (spi_global_app_data->events, evdata);
81
161
  return evdata;
82
}
83

            
84
static GSList *clients = NULL;
85

            
86
static void
87
322
tally_event_reply ()
88
{
89
322
  if (!spi_global_app_data)
90
    return;
91

            
92
322
  spi_global_app_data->replies_received++;
93
322
  if (spi_global_app_data->replies_received == 3)
94
    {
95
      if (!clients)
96
        spi_atk_deregister_event_listeners ();
97
      spi_global_app_data->events_initialized = TRUE;
98
    }
99
}
100

            
101
GType
102
_atk_bridge_type_from_iface (const char *iface)
103
{
104
  if (!strcmp (iface, ATSPI_DBUS_INTERFACE_ACCESSIBLE))
105
    return ATK_TYPE_OBJECT;
106
  if (!strcmp (iface, ATSPI_DBUS_INTERFACE_ACTION))
107
    return ATK_TYPE_ACTION;
108
  if (!strcmp (iface, ATSPI_DBUS_INTERFACE_COMPONENT))
109
    return ATK_TYPE_COMPONENT;
110
  if (!strcmp (iface, ATSPI_DBUS_INTERFACE_DOCUMENT))
111
    return ATK_TYPE_DOCUMENT;
112
  if (!strcmp (iface, ATSPI_DBUS_INTERFACE_HYPERTEXT))
113
    return ATK_TYPE_HYPERTEXT;
114
  if (!strcmp (iface, ATSPI_DBUS_INTERFACE_HYPERLINK))
115
    return ATK_TYPE_HYPERLINK;
116
  if (!strcmp (iface, ATSPI_DBUS_INTERFACE_IMAGE))
117
    return ATK_TYPE_IMAGE;
118
  if (!strcmp (iface, ATSPI_DBUS_INTERFACE_SELECTION))
119
    return ATK_TYPE_SELECTION;
120
  if (!strcmp (iface, ATSPI_DBUS_INTERFACE_TABLE))
121
    return ATK_TYPE_TABLE;
122
  if (!strcmp (iface, ATSPI_DBUS_INTERFACE_TEXT))
123
    return ATK_TYPE_TEXT;
124
  if (!strcmp (iface, ATSPI_DBUS_INTERFACE_VALUE))
125
    return ATK_TYPE_VALUE;
126
  return 0;
127
}
128

            
129
DRoutePropertyFunction
130
_atk_bridge_find_property_func (const char *property, GType *type)
131
{
132
  const char *iface;
133
  const char *member;
134
  DRouteProperty *dp;
135

            
136
  if (!strncasecmp (property, "action.", 7))
137
    {
138
      iface = ATSPI_DBUS_INTERFACE_ACTION;
139
      member = property + 7;
140
    }
141
  else if (!strncasecmp (property, "component.", 10))
142
    {
143
      iface = ATSPI_DBUS_INTERFACE_COMPONENT;
144
      member = property + 10;
145
    }
146
  else if (!strncasecmp (property, "selection.", 10))
147
    {
148
      iface = ATSPI_DBUS_INTERFACE_SELECTION;
149
      member = property + 10;
150
    }
151
  else if (!strncasecmp (property, "table.", 6))
152
    {
153
      iface = ATSPI_DBUS_INTERFACE_TABLE;
154
      member = property + 6;
155
    }
156
  else if (!strncasecmp (property, "text.", 5))
157
    {
158
      iface = ATSPI_DBUS_INTERFACE_TEXT;
159
      member = property + 5;
160
    }
161
  else if (!strncasecmp (property, "value.", 6))
162
    {
163
      iface = ATSPI_DBUS_INTERFACE_VALUE;
164
      member = property + 6;
165
    }
166
  else
167
    {
168
      iface = ATSPI_DBUS_INTERFACE_ACCESSIBLE;
169
      member = property;
170
    }
171

            
172
  *type = _atk_bridge_type_from_iface (iface);
173

            
174
  dp = g_hash_table_lookup (spi_global_app_data->property_hash, iface);
175

            
176
  if (!dp)
177
    return NULL;
178

            
179
  for (; dp->name; dp++)
180
    {
181
      if (!strcasecmp (dp->name, member))
182
        {
183
          return dp->get;
184
        }
185
    }
186
  return NULL;
187
}
188

            
189
static void
190
add_property_to_event (event_data *evdata, const char *property)
191
{
192
  AtspiPropertyDefinition *prop = g_new0 (AtspiPropertyDefinition, 1);
193
  prop->func = _atk_bridge_find_property_func (property, &prop->type);
194
  if (!prop->func)
195
    {
196
      g_warning ("atk-bridge: Request for unknown property '%s'", property);
197
      g_free (prop);
198
      return;
199
    }
200

            
201
  prop->name = g_strdup (property);
202
  evdata->properties = g_slist_append (evdata->properties, prop);
203
}
204

            
205
static void
206
161
add_event_from_iter (DBusMessageIter *iter)
207
{
208
  const char *bus_name, *event;
209
  event_data *evdata;
210

            
211
161
  dbus_message_iter_get_basic (iter, &bus_name);
212
161
  dbus_message_iter_next (iter);
213
161
  dbus_message_iter_get_basic (iter, &event);
214
161
  dbus_message_iter_next (iter);
215
161
  evdata = add_event (bus_name, event);
216
161
  if (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_ARRAY)
217
    {
218
      DBusMessageIter iter_sub_array;
219
      dbus_message_iter_recurse (iter, &iter_sub_array);
220
      while (dbus_message_iter_get_arg_type (&iter_sub_array) != DBUS_TYPE_INVALID)
221
        {
222
          const char *property;
223
          dbus_message_iter_get_basic (&iter_sub_array, &property);
224
          add_property_to_event (evdata, property);
225
          dbus_message_iter_next (&iter_sub_array);
226
        }
227
    }
228
161
}
229

            
230
static void
231
161
get_events_reply (DBusPendingCall *pending, void *user_data)
232
{
233
161
  DBusMessage *reply = dbus_pending_call_steal_reply (pending);
234
  DBusMessageIter iter, iter_array, iter_struct;
235

            
236
161
  if (!reply || !spi_global_app_data)
237
    goto done;
238

            
239
161
  if (strcmp (dbus_message_get_signature (reply), "a(ss)") != 0 &&
240
      strcmp (dbus_message_get_signature (reply), "a(ssas)") != 0)
241
    {
242
      g_warning ("atk-bridge: GetRegisteredEvents returned message with unknown signature");
243
      goto done;
244
    }
245

            
246
161
  dbus_message_iter_init (reply, &iter);
247
161
  dbus_message_iter_recurse (&iter, &iter_array);
248
322
  while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
249
    {
250
161
      dbus_message_iter_recurse (&iter_array, &iter_struct);
251
161
      add_event_from_iter (&iter_struct);
252
161
      dbus_message_iter_next (&iter_array);
253
    }
254

            
255
161
done:
256
161
  if (reply)
257
161
    dbus_message_unref (reply);
258
161
  if (pending)
259
161
    dbus_pending_call_unref (pending);
260

            
261
161
  tally_event_reply ();
262
161
}
263

            
264
static void
265
161
get_device_events_reply (DBusPendingCall *pending, void *user_data)
266
{
267
161
  DBusMessage *reply = dbus_pending_call_steal_reply (pending);
268
  DBusMessageIter iter, iter_array, iter_struct;
269

            
270
161
  if (!reply)
271
    goto done;
272

            
273
161
  if (strncmp (dbus_message_get_signature (reply), "a(s", 3) != 0)
274
    {
275
      g_warning ("atk-bridge: get_device_events_reply: unknown signature");
276
      goto done;
277
    }
278

            
279
161
  dbus_message_iter_init (reply, &iter);
280
161
  dbus_message_iter_recurse (&iter, &iter_array);
281
161
  while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
282
    {
283
      char *bus_name;
284
      dbus_message_iter_recurse (&iter_array, &iter_struct);
285
      dbus_message_iter_get_basic (&iter_struct, &bus_name);
286
      spi_atk_add_client (bus_name);
287
      dbus_message_iter_next (&iter_array);
288
    }
289

            
290
161
done:
291
161
  if (reply)
292
161
    dbus_message_unref (reply);
293
161
  if (pending)
294
161
    dbus_pending_call_unref (pending);
295

            
296
161
  tally_event_reply ();
297
161
}
298

            
299
static void
300
161
get_registered_event_listeners (SpiBridge *app)
301
{
302
  DBusMessage *message;
303
161
  DBusPendingCall *pending = NULL;
304

            
305
161
  message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
306
                                          ATSPI_DBUS_PATH_REGISTRY,
307
                                          ATSPI_DBUS_INTERFACE_REGISTRY,
308
                                          "GetRegisteredEvents");
309
161
  if (!message)
310
    return;
311

            
312
161
  dbus_connection_send_with_reply (app->bus, message, &pending, -1);
313
161
  dbus_message_unref (message);
314
161
  if (!pending)
315
    {
316
      spi_global_app_data->events_initialized = TRUE;
317
      return;
318
    }
319
161
  dbus_pending_call_set_notify (pending, get_events_reply, NULL, NULL);
320

            
321
161
  message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
322
                                          ATSPI_DBUS_PATH_DEC,
323
                                          ATSPI_DBUS_INTERFACE_DEC,
324
                                          "GetKeystrokeListeners");
325
161
  if (!message)
326
    return;
327
161
  pending = NULL;
328
161
  dbus_connection_send_with_reply (app->bus, message, &pending, -1);
329
161
  dbus_message_unref (message);
330
161
  if (!pending)
331
    {
332
      spi_global_app_data->events_initialized = TRUE;
333
      return;
334
    }
335
161
  dbus_pending_call_set_notify (pending, get_device_events_reply, NULL, NULL);
336
}
337

            
338
static void
339
161
register_reply (DBusPendingCall *pending, void *user_data)
340
{
341
  DBusMessage *reply;
342
161
  SpiBridge *app = user_data;
343

            
344
161
  reply = dbus_pending_call_steal_reply (pending);
345
161
  dbus_pending_call_unref (pending);
346

            
347
161
  if (!spi_global_app_data)
348
    {
349
      if (reply)
350
        dbus_message_unref (reply);
351
      return;
352
    }
353

            
354
161
  if (reply)
355
    {
356
      gchar *app_name, *obj_path;
357

            
358
161
      if (strcmp (dbus_message_get_signature (reply), "(so)") != 0)
359
        {
360
          g_warning ("AT-SPI: Could not obtain desktop path or name\n");
361
        }
362
      else
363
        {
364
          DBusMessageIter iter, iter_struct;
365
161
          dbus_message_iter_init (reply, &iter);
366
161
          dbus_message_iter_recurse (&iter, &iter_struct);
367
161
          dbus_message_iter_get_basic (&iter_struct, &app_name);
368
161
          dbus_message_iter_next (&iter_struct);
369
161
          dbus_message_iter_get_basic (&iter_struct, &obj_path);
370

            
371
161
          g_free (app->desktop_name);
372
161
          app->desktop_name = g_strdup (app_name);
373
161
          g_free (app->desktop_path);
374
161
          app->desktop_path = g_strdup (obj_path);
375
        }
376
    }
377
  else
378
    {
379
      g_warning ("AT-SPI: Could not embed inside desktop");
380
      return;
381
    }
382
161
  dbus_message_unref (reply);
383

            
384
161
  if (!spi_global_app_data->events_initialized)
385
161
    get_registered_event_listeners (spi_global_app_data);
386
}
387

            
388
static gboolean
389
161
register_application (gpointer data)
390
{
391
161
  SpiBridge *app = data;
392
  DBusMessage *message;
393
  DBusMessageIter iter;
394
  DBusPendingCall *pending;
395

            
396
161
  spi_global_app_data->registration_pending = 0;
397

            
398
161
  message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
399
                                          ATSPI_DBUS_PATH_ROOT,
400
                                          ATSPI_DBUS_INTERFACE_SOCKET,
401
                                          "Embed");
402

            
403
161
  dbus_message_iter_init_append (message, &iter);
404
161
  spi_object_append_reference (&iter, app->root);
405

            
406
161
  if (!dbus_connection_send_with_reply (app->bus, message, &pending, -1) || !pending)
407
    {
408
      if (pending)
409
        dbus_pending_call_unref (pending);
410

            
411
      dbus_message_unref (message);
412
      return FALSE;
413
    }
414

            
415
161
  dbus_pending_call_set_notify (pending, register_reply, app, NULL);
416

            
417
161
  if (message)
418
161
    dbus_message_unref (message);
419

            
420
161
  return FALSE;
421
}
422

            
423
void
424
161
_atk_bridge_schedule_application_registration (SpiBridge *app)
425
{
426
  /* We need the callback to be called first thing, before any other of ours
427
   * (and possibly of client apps), so use a high priority and a short timeout
428
   * to try and be called first by the main loop. */
429
161
  if (!app->registration_pending)
430
161
    app->registration_pending = spi_timeout_add_full (G_PRIORITY_HIGH, 0,
431
                                                      register_application,
432
                                                      app, NULL);
433
161
}
434

            
435
gboolean
436
161
_atk_bridge_remove_pending_application_registration (SpiBridge *app)
437
{
438
161
  if (app->registration_pending)
439
    {
440
      g_source_remove (app->registration_pending);
441
      app->registration_pending = 0;
442
      return TRUE;
443
    }
444

            
445
161
  return FALSE;
446
}
447

            
448
/*---------------------------------------------------------------------------*/
449

            
450
static void
451
322
remove_socket ()
452
{
453
322
  if (!spi_global_app_data)
454
161
    return;
455

            
456
161
  if (spi_global_app_data->app_bus_addr &&
457
161
      !strncmp (spi_global_app_data->app_bus_addr, "unix:path=", 10))
458
    {
459
161
      unlink (spi_global_app_data->app_bus_addr + 10);
460
161
      g_free (spi_global_app_data->app_bus_addr);
461
161
      spi_global_app_data->app_bus_addr = NULL;
462
    }
463

            
464
161
  if (spi_global_app_data->app_tmp_dir)
465
    {
466
      rmdir (spi_global_app_data->app_tmp_dir);
467
      g_free (spi_global_app_data->app_tmp_dir);
468
      spi_global_app_data->app_tmp_dir = NULL;
469
    }
470
}
471

            
472
static void
473
161
deregister_application (SpiBridge *app)
474
{
475
  DBusMessage *message;
476
  DBusMessageIter iter;
477
  const char *uname;
478

            
479
161
  if (_atk_bridge_remove_pending_application_registration (spi_global_app_data))
480
    return;
481

            
482
161
  message = dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
483
                                          ATSPI_DBUS_PATH_REGISTRY,
484
                                          ATSPI_DBUS_INTERFACE_REGISTRY,
485
                                          "DeregisterApplication");
486
161
  dbus_message_set_no_reply (message, TRUE);
487

            
488
161
  uname = dbus_bus_get_unique_name (app->bus);
489

            
490
161
  dbus_message_iter_init_append (message, &iter);
491
161
  dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &uname);
492
161
  dbus_connection_send (app->bus, message, NULL);
493
161
  if (message)
494
161
    dbus_message_unref (message);
495

            
496
161
  remove_socket ();
497

            
498
161
  g_free (app->desktop_name);
499
161
  app->desktop_name = NULL;
500
161
  g_free (app->desktop_path);
501
161
  app->desktop_path = NULL;
502
}
503

            
504
/*---------------------------------------------------------------------------*/
505

            
506
/*---------------------------------------------------------------------------*/
507

            
508
static AtkPlugClass *plug_class;
509
static AtkSocketClass *socket_class;
510

            
511
static gchar *
512
get_plug_id (AtkPlug *plug)
513
{
514
  const char *uname;
515
  gchar *path;
516
  GString *str;
517

            
518
  if (!spi_global_app_data || !spi_global_app_data->bus)
519
    return NULL;
520

            
521
  str = g_string_new (NULL);
522
  uname = dbus_bus_get_unique_name (spi_global_app_data->bus);
523
  path = spi_register_object_to_path (spi_global_register, G_OBJECT (plug));
524
  g_string_printf (str, "%s:%s", uname, path);
525
  g_free (path);
526
  return g_string_free (str, FALSE);
527
}
528

            
529
AtkStateSet *
530
socket_ref_state_set (AtkObject *accessible)
531
{
532
  char *child_name, *child_path;
533
  AtkSocket *socket = ATK_SOCKET (accessible);
534
  int count = 0;
535
  int j;
536
  int v;
537
  DBusMessage *message, *reply;
538
  DBusMessageIter iter, iter_array;
539
  AtkStateSet *set;
540

            
541
  set = atk_state_set_new ();
542

            
543
  if (!socket->embedded_plug_id)
544
    return set;
545

            
546
  child_name = g_strdup (socket->embedded_plug_id);
547
  if (!child_name)
548
    return set;
549
  child_path = g_utf8_strchr (child_name + 1, -1, ':');
550
  if (!child_path)
551
    {
552
      g_free (child_name);
553
      return set;
554
    }
555
  *(child_path++) = '\0';
556
  message = dbus_message_new_method_call (child_name, child_path, ATSPI_DBUS_INTERFACE_ACCESSIBLE, "GetState");
557
  g_free (child_name);
558
  reply = dbus_connection_send_with_reply_and_block (spi_global_app_data->bus, message, 1, NULL);
559
  dbus_message_unref (message);
560
  if (reply == NULL)
561
    return set;
562
  if (strcmp (dbus_message_get_signature (reply), "au") != 0)
563
    {
564
      dbus_message_unref (reply);
565
      return set;
566
    }
567

            
568
  dbus_message_iter_init (reply, &iter);
569
  dbus_message_iter_recurse (&iter, &iter_array);
570
  do
571
    {
572
      dbus_message_iter_get_basic (&iter_array, &v);
573
      for (j = 0; j < 32; j++)
574
        {
575
          if (v & (1 << j))
576
            {
577
              AtkState state = spi_atk_state_from_spi_state ((count << 5) + j);
578
              atk_state_set_add_state (set, state);
579
            }
580
        }
581
      count++;
582
    }
583
  while (dbus_message_iter_next (&iter_array));
584
  dbus_message_unref (reply);
585
  return set;
586
}
587

            
588
static void
589
socket_embed_hook (AtkSocket *socket, const gchar *plug_id)
590
{
591
  g_return_if_fail (spi_global_register != NULL);
592

            
593
  AtkObject *accessible = ATK_OBJECT (socket);
594
  gchar *plug_name, *plug_path;
595
  AtkObjectClass *klass;
596

            
597
  /* Force registration */
598
  gchar *path = spi_register_object_to_path (spi_global_register, G_OBJECT (accessible));
599
  /* Let the plug know that it has been embedded */
600
  plug_name = g_strdup (plug_id);
601
  if (!plug_name)
602
    {
603
      g_free (path);
604
      return;
605
    }
606
  plug_path = g_utf8_strchr (plug_name + 1, -1, ':');
607
  if (plug_path)
608
    {
609
      DBusMessage *message;
610
      *(plug_path++) = '\0';
611
      message = dbus_message_new_method_call (plug_name, plug_path, ATSPI_DBUS_INTERFACE_SOCKET, "Embedded");
612
      dbus_message_append_args (message, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID);
613
      dbus_connection_send (spi_global_app_data->bus, message, NULL);
614
    }
615
  g_free (plug_name);
616
  g_free (path);
617

            
618
  klass = ATK_OBJECT_GET_CLASS (accessible);
619
  klass->ref_state_set = socket_ref_state_set;
620
}
621

            
622
static void
623
161
install_plug_hooks ()
624
{
625
  gpointer data;
626

            
627
161
  data = g_type_class_ref (ATK_TYPE_PLUG);
628
161
  plug_class = ATK_PLUG_CLASS (data);
629
161
  data = g_type_class_ref (ATK_TYPE_SOCKET);
630
161
  socket_class = ATK_SOCKET_CLASS (data);
631
161
  plug_class->get_object_id = get_plug_id;
632
161
  socket_class->embed = socket_embed_hook;
633
161
}
634

            
635
static guint
636
get_ancestral_uid (guint pid)
637
{
638
  FILE *fp;
639
  char buf[80];
640
  int ppid = 0;
641
  int uid = 0;
642
  gboolean got_ppid = 0;
643
  gboolean got_uid = 0;
644

            
645
  sprintf (buf, "/proc/%d/status", pid);
646
  fp = fopen (buf, "r");
647
  if (!fp)
648
    return 0;
649
  while ((!got_ppid || !got_uid) && fgets (buf, sizeof (buf), fp))
650
    {
651
      if (sscanf (buf, "PPid:\t%d", &ppid) == 1)
652
        got_ppid = TRUE;
653
      else if (sscanf (buf, "Uid:\t%d", &uid) == 1)
654
        got_uid = TRUE;
655
    }
656
  fclose (fp);
657

            
658
  if (!got_ppid || !got_uid)
659
    return 0;
660
  if (uid != 0)
661
    return uid;
662
  if (ppid == 0 || ppid == 1)
663
    return 0;
664
  return get_ancestral_uid (ppid);
665
}
666

            
667
static dbus_bool_t
668
131
user_check (DBusConnection *bus, unsigned long uid, void *data)
669
{
670
131
  if (uid == getuid () || uid == geteuid ())
671
131
    return TRUE;
672
  if (getuid () == 0)
673
    {
674
      guint ancestor = get_ancestral_uid (getpid ());
675
      return (ancestor == uid || ancestor == 1 || ancestor == 0);
676
    }
677
  return FALSE;
678
}
679

            
680
static void
681
157
new_connection_cb (DBusServer *server, DBusConnection *con, void *data)
682
{
683
157
  dbus_connection_set_unix_user_function (con, user_check, NULL, NULL);
684
157
  dbus_connection_ref (con);
685
157
  atspi_dbus_connection_setup_with_g_main (con, spi_context);
686
157
  droute_intercept_dbus (con);
687
157
  droute_context_register (spi_global_app_data->droute, con);
688

            
689
157
  spi_global_app_data->direct_connections = g_list_append (spi_global_app_data->direct_connections, con);
690
157
}
691

            
692
static gchar *atspi_dbus_name = NULL;
693
static gboolean atspi_no_register = FALSE;
694

            
695
static GOptionEntry atspi_option_entries[] = {
696
  { "atspi-dbus-name", 0, 0, G_OPTION_ARG_STRING, &atspi_dbus_name,
697
    "D-Bus bus name to register as", NULL },
698
  { "atspi-no-register", 0, 0, G_OPTION_ARG_NONE, &atspi_no_register,
699
    "Do not register with Registry Daemon", NULL },
700
  { NULL }
701
};
702

            
703
static void
704
add_objects_for_introspection (AtkObject *obj, GString *str)
705
{
706
  gchar *path;
707
  AtkStateSet *set;
708
  char *p;
709
  gint i;
710
  gint count;
711

            
712
  if (!obj)
713
    return;
714

            
715
  path = spi_register_object_to_path (spi_global_register, G_OBJECT (obj));
716
  p = strrchr (path, '/') + 1;
717
  g_string_append_printf (str, "<node name=\"%s\"/>\n", p);
718
  g_free (path);
719

            
720
  if (ATK_IS_SOCKET (obj))
721
    return;
722

            
723
  set = atk_object_ref_state_set (obj);
724
  if (atk_state_set_contains_state (set, ATK_STATE_MANAGES_DESCENDANTS))
725
    {
726
      g_object_unref (set);
727
      return;
728
    }
729
  g_object_unref (set);
730

            
731
  count = atk_object_get_n_accessible_children (obj);
732
  for (i = 0; i < count; i++)
733
    {
734
      AtkObject *child = atk_object_ref_accessible_child (obj, i);
735
      add_objects_for_introspection (child, str);
736
      g_object_unref (child);
737
    }
738
}
739

            
740
static gchar *
741
introspect_children_cb (const char *path, void *data)
742
{
743
  if (!strcmp (path, "/org/a11y/atspi/accessible"))
744
    {
745
      GString *str = g_string_new (NULL);
746
      add_objects_for_introspection (spi_global_app_data->root, str);
747
      return g_string_free (str, FALSE);
748
    }
749

            
750
  return NULL;
751
}
752

            
753
static void
754
handle_event_listener_registered (DBusConnection *bus, DBusMessage *message, void *user_data)
755
{
756
  DBusMessageIter iter;
757
  const char *signature = dbus_message_get_signature (message);
758

            
759
  if (strcmp (signature, "ssas") != 0 &&
760
      strcmp (signature, "ss") != 0)
761
    {
762
      g_warning ("got RegisterEvent with invalid signature '%s'", signature);
763
      return;
764
    }
765

            
766
  dbus_message_iter_init (message, &iter);
767
  add_event_from_iter (&iter);
768
}
769

            
770
static void
771
free_property_definition (void *data)
772
{
773
  AtspiPropertyDefinition *pd = data;
774

            
775
  g_free (pd->name);
776
  g_free (pd);
777
}
778

            
779
static void
780
remove_events (const char *bus_name, const char *event)
781
{
782
  gchar **remove_data;
783
  GList *list;
784

            
785
  remove_data = g_strsplit (event, ":", 3);
786
  if (!remove_data)
787
    {
788
      return;
789
    }
790

            
791
  for (list = spi_global_app_data->events; list;)
792
    {
793
      event_data *evdata = list->data;
794
      if (!g_strcmp0 (evdata->bus_name, bus_name) &&
795
          spi_event_is_subtype (evdata->data, remove_data))
796
        {
797
          GList *next;
798
          GList *events = spi_global_app_data->events;
799

            
800
          g_strfreev (evdata->data);
801
          g_free (evdata->bus_name);
802
          g_slist_free_full (evdata->properties, free_property_definition);
803
          g_free (evdata);
804

            
805
          next = list->next;
806
          spi_global_app_data->events = g_list_delete_link (events, list);
807
          list = next;
808
        }
809
      else
810
        {
811
          list = list->next;
812
        }
813
    }
814

            
815
  g_strfreev (remove_data);
816
}
817

            
818
static void
819
handle_event_listener_deregistered (DBusConnection *bus, DBusMessage *message, void *user_data)
820
{
821
  gchar *name;
822
  char *sender;
823

            
824
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &sender,
825
                              DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID))
826
    return;
827

            
828
  remove_events (sender, name);
829
}
830

            
831
static void
832
handle_device_listener_registered (DBusConnection *bus, DBusMessage *message, void *user_data)
833
{
834
  char *sender;
835
  DBusMessageIter iter, iter_struct;
836

            
837
  if (strncmp (dbus_message_get_signature (message), "(s", 2) != 0)
838
    {
839
      g_warning ("atk-bridge: handle_device_listener_register: unknown signature");
840
      return;
841
    }
842

            
843
  dbus_message_iter_init (message, &iter);
844
  dbus_message_iter_recurse (&iter, &iter_struct);
845
  dbus_message_iter_get_basic (&iter_struct, &sender);
846
  spi_atk_add_client (sender);
847
}
848

            
849
static DBusHandlerResult
850
962
signal_filter (DBusConnection *bus, DBusMessage *message, void *user_data)
851
{
852
962
  const char *interface = dbus_message_get_interface (message);
853
962
  const char *member = dbus_message_get_member (message);
854
962
  DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
855
  static gboolean registry_lost = FALSE;
856

            
857
962
  if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_SIGNAL)
858
640
    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
859

            
860
322
  if (!strcmp (interface, ATSPI_DBUS_INTERFACE_REGISTRY))
861
    {
862
      result = DBUS_HANDLER_RESULT_HANDLED;
863
      if (!strcmp (member, "EventListenerRegistered"))
864
        handle_event_listener_registered (bus, message, user_data);
865
      else if (!strcmp (member, "EventListenerDeregistered"))
866
        handle_event_listener_deregistered (bus, message, user_data);
867
      else
868
        result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
869
    }
870
322
  else if (!strcmp (interface, ATSPI_DBUS_INTERFACE_DEVICE_EVENT_LISTENER))
871
    {
872
      result = DBUS_HANDLER_RESULT_HANDLED;
873
      if (!strcmp (member, "KeystrokeListenerRegistered"))
874
        handle_device_listener_registered (bus, message, user_data);
875
      else
876
        result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
877
    }
878

            
879
644
  if (!g_strcmp0 (interface, DBUS_INTERFACE_DBUS) &&
880
322
      !g_strcmp0 (member, "NameOwnerChanged"))
881
    {
882
      char *name, *old, *new;
883
      if (dbus_message_get_args (message, NULL,
884
                                 DBUS_TYPE_STRING, &name,
885
                                 DBUS_TYPE_STRING, &old,
886
                                 DBUS_TYPE_STRING, &new,
887
                                 DBUS_TYPE_INVALID))
888
        {
889
          if (!strcmp (name, "org.a11y.atspi.Registry"))
890
            {
891
              if (registry_lost && !old[0])
892
                {
893
                  register_application (spi_global_app_data);
894
                  registry_lost = FALSE;
895
                }
896
              else if (!new[0])
897
                registry_lost = TRUE;
898
            }
899
          else if (*old != '\0' && *new == '\0')
900
            spi_atk_remove_client (old);
901
        }
902
    }
903

            
904
322
  return result;
905
}
906

            
907
int
908
161
spi_atk_create_socket (SpiBridge *app)
909
{
910
  DBusServer *server;
911
  DBusError error;
912
161
  const gchar *user_runtime_dir = g_get_user_runtime_dir ();
913
  char *socket_path;
914
  char *escaped_socket_path;
915
  const char *disable_p2p;
916

            
917
161
  disable_p2p = g_getenv ("ATSPI_DISABLE_P2P");
918
161
  if (disable_p2p && atoi (disable_p2p) > 0)
919
    return 0;
920

            
921
161
  if (g_mkdir_with_parents (user_runtime_dir, 0700) != 0)
922
    return -1;
923

            
924
161
  if (getuid () != 0)
925
    {
926
      app->app_tmp_dir = g_build_filename (user_runtime_dir,
927
                                           "at-spi2-XXXXXX", NULL);
928
      if (!g_mkdtemp (app->app_tmp_dir))
929
        {
930
          g_free (app->app_tmp_dir);
931
          app->app_tmp_dir = NULL;
932
          return -1;
933
        }
934
    }
935

            
936
161
  if (app->app_tmp_dir)
937
    {
938
      socket_path = g_strdup_printf ("%s/socket", app->app_tmp_dir);
939
    }
940
  else
941
    {
942
161
      socket_path = g_strdup_printf ("%s/at-spi2-socket-%d",
943
                                     user_runtime_dir, getpid ());
944
    }
945

            
946
161
  escaped_socket_path = dbus_address_escape_value (socket_path);
947
161
  g_free (socket_path);
948

            
949
161
  app->app_bus_addr = g_strconcat ("unix:path=", escaped_socket_path, NULL);
950
161
  dbus_free (escaped_socket_path);
951

            
952
161
  dbus_error_init (&error);
953
161
  server = dbus_server_listen (app->app_bus_addr, &error);
954
161
  if (server == NULL)
955
    {
956
      g_warning ("atk-bridge: Couldn't listen on dbus server: %s", error.message);
957
      dbus_error_free (&error);
958
      app->app_bus_addr[0] = '\0';
959
      return -1;
960
    }
961

            
962
161
  atspi_dbus_server_setup_with_g_main (server, spi_context);
963
161
  dbus_server_set_new_connection_function (server, new_connection_cb, NULL, NULL);
964

            
965
161
  app->server = server;
966

            
967
161
  return 0;
968
}
969

            
970
/*
971
 * Checks the status of the environment variables
972
 *
973
 * At this moment it only checks NO_AT_BRIDGE
974
 *
975
 * Returns TRUE if there isn't anything on the environment preventing
976
 * you to load the bridge, FALSE otherwise
977
 */
978
static gboolean
979
161
check_envvar (void)
980
{
981
  const gchar *envvar;
982

            
983
161
  envvar = g_getenv ("NO_AT_BRIDGE");
984

            
985
161
  if (envvar && atoi (envvar) == 1)
986
    return FALSE;
987
  else
988
161
    return TRUE;
989
}
990

            
991
void
992
161
spi_atk_activate ()
993
{
994
  DRoutePath *treepath;
995

            
996
161
  spi_atk_register_event_listeners ();
997
161
  if (!spi_global_cache)
998
    {
999
161
      spi_global_cache = g_object_new (SPI_CACHE_TYPE, NULL);
161
      treepath = droute_add_one (spi_global_app_data->droute,
                                 "/org/a11y/atspi/cache", spi_global_cache);
161
      if (!treepath)
        {
          g_warning ("atk-bridge: Error in droute_add_one().  Already running?");
          return;
        }
161
      spi_initialize_cache (treepath);
161
      if (spi_global_app_data->bus)
161
        droute_path_register (treepath, spi_global_app_data->bus);
    }
}
static gboolean
spi_object_has_dbus_interface (void *obj, const char *interface)
{
  if (!strcmp (interface, ATSPI_DBUS_INTERFACE_ACCESSIBLE))
    return TRUE;
  if (!strcmp (interface, ATSPI_DBUS_INTERFACE_ACTION))
    return ATK_IS_ACTION (obj);
  if (!strcmp (interface, ATSPI_DBUS_INTERFACE_APPLICATION))
      return ATK_IS_OBJECT(obj) && (atk_object_get_role (obj) == ATK_ROLE_APPLICATION);
  if (!strcmp (interface, ATSPI_DBUS_INTERFACE_COLLECTION))
    return TRUE;
  if (!strcmp (interface, ATSPI_DBUS_INTERFACE_COMPONENT))
    return ATK_IS_COMPONENT (obj);
  if (!strcmp (interface, ATSPI_DBUS_INTERFACE_DOCUMENT))
    return ATK_IS_DOCUMENT (obj);
  if (!strcmp (interface, ATSPI_DBUS_INTERFACE_EDITABLE_TEXT))
    return ATK_IS_EDITABLE_TEXT (obj);
  if (!strcmp (interface, ATSPI_DBUS_INTERFACE_HYPERLINK))
    return ATK_IS_HYPERLINK (obj);
  if (!strcmp (interface, ATSPI_DBUS_INTERFACE_HYPERTEXT))
    return ATK_IS_HYPERTEXT (obj);
  if (!strcmp (interface, ATSPI_DBUS_INTERFACE_IMAGE))
    return ATK_IS_IMAGE (obj);
  if (!strcmp (interface, ATSPI_DBUS_INTERFACE_SELECTION))
    return ATK_IS_SELECTION (obj);
  if (!strcmp (interface, ATSPI_DBUS_INTERFACE_SOCKET))
    return TRUE;
  if (!strcmp (interface, ATSPI_DBUS_INTERFACE_TABLE))
    return ATK_IS_TABLE (obj);
  if (!strcmp (interface, ATSPI_DBUS_INTERFACE_TABLE_CELL))
    return ATK_IS_TABLE_CELL (obj);
  if (!strcmp (interface, ATSPI_DBUS_INTERFACE_TEXT))
    return ATK_IS_TEXT (obj);
  if (!strcmp (interface, ATSPI_DBUS_INTERFACE_VALUE))
    return ATK_IS_VALUE (obj);
  return FALSE;
}
static gboolean
161
init_bus ()
{
  DBusError error;
  /* Set up D-Bus connection and register bus name */
161
  dbus_error_init (&error);
161
  spi_global_app_data->bus = atspi_get_a11y_bus ();
161
  if (!spi_global_app_data->bus)
    return FALSE;
161
  if (atspi_dbus_name != NULL)
    {
161
      if (dbus_bus_request_name (spi_global_app_data->bus, atspi_dbus_name, 0, &error))
        {
161
          g_print ("AT-SPI Received D-Bus name - %s\n", atspi_dbus_name);
        }
      else
        {
          g_print ("AT-SPI D-Bus name requested but could not be allocated - %s\n",
                   atspi_dbus_name);
        }
    }
161
  atspi_dbus_connection_setup_with_g_main (spi_global_app_data->bus, NULL);
161
  droute_context_register (spi_global_app_data->droute,
161
                           spi_global_app_data->bus);
  /* Set up filter and match rules to catch signals */
161
  dbus_bus_add_match (spi_global_app_data->bus, "type='signal', interface='org.a11y.atspi.Registry', sender='org.a11y.atspi.Registry'", NULL);
161
  dbus_bus_add_match (spi_global_app_data->bus, "type='signal', interface='org.a11y.atspi.DeviceEventListener', sender='org.a11y.atspi.Registry'", NULL);
161
  dbus_bus_add_match (spi_global_app_data->bus, "type='signal', arg0='org.a11y.atspi.Registry', interface='org.freedesktop.DBus', member='NameOwnerChanged'", NULL);
161
  dbus_connection_add_filter (spi_global_app_data->bus, signal_filter, NULL,
                              NULL);
  /* Register this app by sending a signal out to AT-SPI registry daemon */
161
  if (!atspi_no_register && !ATK_IS_PLUG (spi_global_app_data->root))
161
    _atk_bridge_schedule_application_registration (spi_global_app_data);
  else
    get_registered_event_listeners (spi_global_app_data);
161
  dbus_error_free (&error);
161
  return TRUE;
}
static void
161
deactivate_bus ()
{
161
  if (!spi_global_app_data->bus)
    return;
161
  dbus_connection_remove_filter (spi_global_app_data->bus, signal_filter, NULL);
161
  droute_context_unregister (spi_global_app_data->droute, spi_global_app_data->bus);
161
  if (atspi_dbus_name != NULL)
    {
      DBusError error;
      int result;
161
      dbus_error_init (&error);
161
      result = dbus_bus_release_name (spi_global_app_data->bus, atspi_dbus_name, &error);
161
      if (result == -1)
        {
          g_warning ("atk-bridge: could not release dbus name: %s", error.message);
        }
      else
        {
161
          g_print ("bridge: released name, result %d\n", result);
        }
161
      dbus_error_free (&error);
    }
161
  dbus_connection_close (spi_global_app_data->bus);
161
  dbus_connection_unref (spi_global_app_data->bus);
161
  spi_global_app_data->bus = NULL;
}
static void
on_session_name_owner_changed (GDBusConnection *connection,
                               const gchar *sender_name,
                               const gchar *object_path,
                               const gchar *interface_name,
                               const gchar *signal_name,
                               GVariant *parameters,
                               gpointer user_data)
{
  const gchar *old_owner;
  const gchar *new_owner;
  g_variant_get (parameters,
                 "(&s&s&s)",
                 NULL,
                 &old_owner,
                 &new_owner);
  if (strlen (new_owner) == 0)
    {
      spi_atk_deregister_event_listeners ();
      deactivate_bus ();
    }
  else
    {
      init_bus ();
      spi_atk_register_event_listeners ();
    }
}
/**
 * atk_bridge_adaptor_init: initializes the atk bridge adaptor
 *
 * The following needs to be initialized.
 *
 * - DRoute for routing message to their accessible objects.
 * - Event handlers for emmitting signals on specific ATK events.
 * - setup the bus for p2p communication
 * - Application registration with the AT-SPI registry.
 *
 * Returns: 0 if the bridge gets or was already initialized
 * succesfully, -1 otherwise
 */
int
161
atk_bridge_adaptor_init (gint *argc, gchar **argv[])
{
  GOptionContext *opt;
161
  GError *err = NULL;
  AtkObject *root;
  gboolean load_bridge;
  DRoutePath *accpath;
161
  load_bridge = check_envvar ();
161
  if (inited && !load_bridge)
    g_warning ("ATK Bridge is disabled but a11y has already been enabled.");
161
  if (inited)
    return 0;
161
  if (!load_bridge)
    return -1;
161
  inited = TRUE;
161
  root = atk_get_root ();
161
  g_warn_if_fail (root);
161
  if (!root)
    {
      inited = FALSE;
      return -1;
    }
  /* Parse command line options */
161
  opt = g_option_context_new (NULL);
161
  g_option_context_add_main_entries (opt, atspi_option_entries, NULL);
161
  g_option_context_set_ignore_unknown_options (opt, TRUE);
161
  if (!g_option_context_parse (opt, argc, argv, &err))
    {
      g_warning ("AT-SPI Option parsing failed: %s\n", err->message);
      g_error_free (err);
    }
161
  g_option_context_free (opt);
  /* Allocate global data and do ATK initializations */
161
  spi_global_app_data = g_new0 (SpiBridge, 1);
161
  spi_global_app_data->root = g_object_ref (root);
161
  spi_global_app_data->desktop_name = g_strdup (ATSPI_DBUS_NAME_REGISTRY);
161
  spi_global_app_data->desktop_path = g_strdup (ATSPI_DBUS_PATH_ROOT);
  /* Hook our plug-and socket functions */
161
  install_plug_hooks ();
  /*
   * Create the leasing, register and cache objects.
   * The order is important here, the cache depends on the
   * register object.
   */
161
  spi_global_register = g_object_new (SPI_REGISTER_TYPE, NULL);
161
  spi_global_leasing = g_object_new (SPI_LEASING_TYPE, NULL);
  /* Register droute for routing AT-SPI messages */
322
  spi_global_app_data->droute =
161
      droute_new ();
161
  accpath = droute_add_many (spi_global_app_data->droute,
                             "/org/a11y/atspi/accessible",
                             NULL,
                             introspect_children_cb,
                             NULL,
                             (DRouteGetDatumFunction)
                                 spi_global_register_path_to_object,
                             spi_object_has_dbus_interface);
  /* Register all interfaces with droute and set up application accessible db */
161
  spi_initialize_accessible (accpath);
161
  spi_initialize_application (accpath);
161
  spi_initialize_action (accpath);
161
  spi_initialize_collection (accpath);
161
  spi_initialize_component (accpath);
161
  spi_initialize_document (accpath);
161
  spi_initialize_editabletext (accpath);
161
  spi_initialize_hyperlink (accpath);
161
  spi_initialize_hypertext (accpath);
161
  spi_initialize_image (accpath);
161
  spi_initialize_selection (accpath);
161
  spi_initialize_socket (accpath);
161
  spi_initialize_table (accpath);
161
  spi_initialize_table_cell (accpath);
161
  spi_initialize_text (accpath);
161
  spi_initialize_value (accpath);
161
  if (!init_bus ())
    {
      g_object_unref (spi_global_app_data->root);
      g_free (spi_global_app_data->desktop_name);
      g_free (spi_global_app_data->desktop_path);
      droute_free (spi_global_app_data->droute);
      if (spi_global_app_data->property_hash)
        g_hash_table_destroy (spi_global_app_data->property_hash);
      g_free (spi_global_app_data);
      spi_global_app_data = NULL;
      inited = FALSE;
      return -1;
    }
161
  spi_global_app_data->main_context = g_main_context_new ();
  /* Register methods to send D-Bus signals on certain ATK events */
161
  if (clients)
    spi_atk_activate ();
161
  if (!atexit_added)
161
    atexit (remove_socket);
161
  atexit_added = TRUE;
161
  spi_global_app_data->session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
161
  if (spi_global_app_data->session_bus)
    {
161
      spi_global_app_data->name_owner_changed_subscription_id =
161
          g_dbus_connection_signal_subscribe (spi_global_app_data->session_bus,
                                              "org.freedesktop.DBus",  /* name */
                                              "org.freedesktop.DBus",  /* interface */
                                              "NameOwnerChanged",      /* signal name */
                                              "/org/freedesktop/DBus", /* path */
                                              "org.a11y.Bus",          /* arg0 */
                                              G_DBUS_SIGNAL_FLAGS_NONE,
                                              on_session_name_owner_changed,
                                              NULL,
                                              (GDestroyNotify) NULL);
    }
161
  return 0;
}
void
161
atk_bridge_adaptor_cleanup (void)
{
  GList *l;
  GSList *ls;
161
  if (!inited)
    return;
161
  if (!spi_global_app_data)
    return;
161
  spi_atk_tidy_windows ();
161
  spi_atk_deregister_event_listeners ();
161
  deregister_application (spi_global_app_data);
161
  deactivate_bus ();
318
  for (l = spi_global_app_data->direct_connections; l; l = l->next)
    {
      DBusConnection *connection;
157
      connection = l->data;
157
      droute_context_unregister (spi_global_app_data->droute, connection);
157
      droute_unintercept_dbus (connection);
157
      dbus_connection_close (connection);
157
      dbus_connection_unref (connection);
    }
161
  g_list_free (spi_global_app_data->direct_connections);
161
  spi_global_app_data->direct_connections = NULL;
322
  for (ls = clients; ls; ls = ls->next)
161
    g_free (ls->data);
161
  g_slist_free (clients);
161
  clients = NULL;
161
  g_clear_object (&spi_global_cache);
161
  g_clear_object (&spi_global_leasing);
161
  g_clear_object (&spi_global_register);
161
  if (spi_global_app_data->main_context)
161
    g_main_context_unref (spi_global_app_data->main_context);
161
  droute_free (spi_global_app_data->droute);
161
  g_clear_object (&spi_global_app_data->session_bus);
161
  if (spi_global_app_data->property_hash)
161
    g_hash_table_destroy (spi_global_app_data->property_hash);
161
  g_free (spi_global_app_data);
161
  spi_global_app_data = NULL;
161
  inited = FALSE;
}
/*---------------------------------------------------------------------------*/
static gchar *name_match_tmpl =
    "type='signal', interface='org.freedesktop.DBus', member='NameOwnerChanged', arg0='%s'";
void
322
spi_atk_add_client (const char *bus_name)
{
  GSList *l;
  gchar *match;
322
  for (l = clients; l; l = l->next)
    {
161
      if (!g_strcmp0 (l->data, bus_name))
161
        return;
    }
161
  if (!clients)
161
    spi_atk_activate ();
161
  clients = g_slist_append (clients, g_strdup (bus_name));
161
  match = g_strdup_printf (name_match_tmpl, bus_name);
161
  dbus_bus_add_match (spi_global_app_data->bus, match, NULL);
161
  g_free (match);
}
void
spi_atk_remove_client (const char *bus_name)
{
  GSList *l;
  GSList *next_node;
  l = clients;
  while (l)
    {
      next_node = l->next;
      if (!g_strcmp0 (l->data, bus_name))
        {
          gchar *match = g_strdup_printf (name_match_tmpl, l->data);
          dbus_bus_remove_match (spi_global_app_data->bus, match, NULL);
          g_free (match);
          g_free (l->data);
          clients = g_slist_delete_link (clients, l);
          if (!clients)
            spi_atk_deregister_event_listeners ();
          return;
        }
      l = next_node;
    }
}
void
1932
spi_atk_add_interface (DRoutePath *path,
                       const char *name,
                       const char *introspect,
                       const DRouteMethod *methods,
                       const DRouteProperty *properties)
{
1932
  droute_path_add_interface (path, name, introspect, methods, properties);
1932
  if (properties)
    {
1932
      if (!spi_global_app_data->property_hash)
161
        spi_global_app_data->property_hash = g_hash_table_new_full (g_str_hash,
                                                                    g_str_equal,
                                                                    g_free, NULL);
1932
      g_hash_table_insert (spi_global_app_data->property_hash, g_strdup (name),
                           (gpointer) properties);
    }
1932
}
/*END------------------------------------------------------------------------*/